• Post Reply Bookmark Topic Watch Topic
  • New Topic

Code execution compatability between 32bit and 64 bit JDK  RSS feed

 
Safi Khan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone !

Let's say i have two jdk installations in my machine, One is JDK(64 bit) and other is JDK(32 bit).

Now, if i compile the code with 64bit jdk and execute the generated .class file with 32bit Jdk then, will the file run successfully ? or it is not possible ?
and what if we reverse the scenario ?

Regards,
SDK
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I suggest you write a tiny class, compile it with each of the JDKs in turn and print its bytecode with javap -c Foo
Then see if you can see any differences in the bytecode. That should answer your question.
 
Safi Khan
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have tried this and it executes successfully , byte code is same as well for both files generated by 32bit and 64bit jdk,

But what is the reason of the same byte code ?
 
Jesper de Jong
Java Cowboy
Sheriff
Posts: 16060
88
Android IntelliJ IDE Java Scala Spring
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Java bytecode is platform-independent, that's one of the main features of Java - "write once, run anywhere".

Whether the underlying operating system is 32-bit, 64-bit or something else does not matter for the bytecode. The JIT (Just-In-Time) compiler converts bytecode to native machine code at runtime. If you are using a 32-bit JVM, it will produce native code for 32-bit processors, if you use a 64-bit JVM it will produce code for 64-bit processors.
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I thought the JVM interpreted the bytecode, using exactly the same bytecode on every platform. That is why one of the ten eleven buzzwords in the original white paper (which I found a copy of here) is interpreted.
I thought the JIT compiler only runs to create machine code when there is frequent repetition of anything.

And architecture neutral appears among the buzzwords, so you can run the same bytecode on 32 bit and 64 bit machines without any difference in the output.
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Campbell Ritchie wrote:I thought the JVM interpreted the bytecode, using exactly the same bytecode on every platform. That is why one of the ten eleven buzzwords in the original white paper (which I found a copy of here) is interpreted.
I thought the JIT compiler only runs to create machine code when there is frequent repetition of anything.

And architecture neutral appears among the buzzwords, so you can run the same bytecode on 32 bit and 64 bit machines without any difference in the output.



Obviously, the interpreted word of the description was before the JIT compiler was invented. If memory serves... With the client configuration, the byte code is immediately sent to the JIT compiler. With the server configuration, the byte code is initially interpreted, until enough profiling data is gathered -- and then it is sent to the JIT compiler, which optimizes based on the profile. Additionally, there is also a new tiered configuration, which uses the client JIT compiler to compile a profiling version; and then when enough data is gathered, uses the server JIT compiler to generate optimized code.

Henry
 
Campbell Ritchie
Marshal
Posts: 56599
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you. I never knew that.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!