0

I studied somewhere that to execute on different processor architectures Java is interpreted. If it would use compiler then there would be some (Machine Code) instructions which would be specific to processor architectures and Java would be platform dependent. But since java use interpreter it is processor architecture independent.

My question is how can the java use JIT (Just In Time) Compiler? Doesn't the processor's architectures affect it? If it doesn't affect it, then why doesn't it affect it?

7
  • I think first you need to understand how JIT works. Refer this ibm.com/support/knowledgecenter/SSYKE2_8.0.0/… Commented Jul 29, 2017 at 2:13
  • @bigbounty Thanks for the link, I had visited it earlier as well. I have already read and understand how jit works. I think you are having problem understanding my issue. Commented Jul 29, 2017 at 2:15
  • JIT compiles code as it is needed, during execution. However, the just-in-time approach still yields a significant performance boost. Even when dynamic compilation is applied to bytecode, the portability and safety features still apply, because the run-time system (which performs the compilation) still is in charge of the execution environment. Commented Jul 29, 2017 at 2:16
  • Doesn't Jit have problem compiling to machine language due to different processor architectures and different instruction sets of these processors??? Commented Jul 29, 2017 at 2:20
  • 2
    The JVM, including the JIT, is custom written for each processor (though of course it shares most of its code). Your Java code is not, nor is the bytecode your code is compiled to. Commented Jul 29, 2017 at 2:28

3 Answers 3

5

There isn't just one JIT compiler. There is a different one for each architecture, so there's one for Windows 32-bit, one for Windows 64-bit etc.

Your Java code is the same across all platforms. That is compiled into byte code by the Java compiler. The byte code is also the same across all platforms.

Now we run your Java program on Windows 32-bit. The JVM starts up and it interprets the byte code and turns that into machine code for that architecture. Note that that JVM is specifically for this architecture.

If we run your program on another architecture, another variation of the JVM will be used to interpret the byte code.

That's why you see all these different download links when you download the JRE:

enter image description here

Sign up to request clarification or add additional context in comments.

Comments

1

Your java code is interpreted to byte code and is not platform dependent. But to run your machine code you need a JVM, the​ JVM is platform dependent, you cannot download an x86 JVM and run it on an ARM processor and vice versa.

The idea is that the JVM is platform dependent but your code is not.

3 Comments

I have asked problem related to processor architecture, not for OS.
You are right, but the same principle applies. I have updated the answer.
@RakeshYadav The answer is the same. And it's a good answer. The JIT compilation occurs inside the JVM, which is specific for the execution environment. That environment includes both processor and OS.
1

The java program life cycle goes as follows. Source code is compiled into Java Byte Code (aka .class files), Java Byte Code is then interpreted by the JVM which performs the Just In Time compilation sending instructions your specific processor architecture can understand.

Its important to understand that compilation is just another way to say "translation", and does not always mean compiling to binary. Also, interpretation is similar, but is done per instruction, as needed by the program.

But more specifically in your question, JIT is the interpretation done by the JVM, which is coded specifically for each processor architecture.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.