Search code examples
javajvmjit

JVM : Bytecode Confusion and JIT


So here's a question that came to my mind when I was studying Java. We know (please correct me if I am wrong!) that the Bytecode runs atop JVM. So does the JVM convert the Bytecode to the native machine code it's(JVM) written for? If that is so, isn't it less secure?

Also what exactly is a just-in-time compiler? It compiles when it is asked to do so...I studied some resources, but still didn't get the just-in-time part clear.

Thanks for any help !


Solution

  • So does the JVM convert the Bytecode to the native machine code it's(JVM) written for?

    No, not necessarily. Though, nowadays it is state of the art to do so by default.

    If that is so, isn't it less secure?

    Less secure than what? Just because one can do insecure operations in machine code (like dereferencing an unitialized pointer or accessing unallocated memory) does not mean the JIT generates such insecure code.

    Also what exactly is a just-in-time compiler?

    It's that part of the JVM that converts bytecode to native machine code. The name "just in time" means that the code is compiled (in a separate thread) while it is executed. Once completely compiled, the JVM takes notice that certain methods are compiled and can be invoked on the machine level.