• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JVM operation

 
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
Please correct me if I am wrong
As we know we have separate JVM for separate platform and our byte code gets converted to binary code at runtime whenever JVM needs to execute particular code it searches for it, interpret Java byte code and translate this into actions or Operating System calls using JIT compiler.
If this is true then my question is why don’t JVM uses same binary file which it already created (obviously we can maintain version of those) and will is not improve application performance?
 
Sheriff
Posts: 22821
132
Eclipse IDE Spring Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Because that means you will have to compile your code for each platform. That's exactly what's going on for programs written in C for instance. Just look on the Internet and see how many applications have different versions for Windows and Linux, for 32-bit and 64-bit, etc.

Or perhaps I understood you wrong. Did you mean that the JVM uses byte-code for each class, but compiles that internally and stores that somewhere to use it for future use? If so, then that has some overhead too. If the class changes the JVM would need to check if the compiled data is still up-to-date. And what about the storage required if the JVM has encountered hundreds of classes? And what would the storage be based on, the class name? A class called "Test" may have two different class files, in different locations. Does that mean that the compiled version storage would need to store based on class name plus location? And what if a class then is moved, do you store that data twice?

The way it works now is pretty good. It does compile the byte-code internally, but when the JVM exits that data is discarded again.
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks for reply

Rob Spoor wrote:The way it works now is pretty good.


Thats absolutely perfect and we all aware of this.

Rob Spoor wrote:It does compile the byte-code internally, but when the JVM exits that data is discarded again.


Now here is my confusion does it compile every time when particular resource is demanded for or does it do it only for once or how?

Rob Spoor wrote:Because that means you will have to compile your code for each platform.


This is what JVM does for us for any platform, thats fine. Now the same question again does it compile code every time for same resource again and again e.g. if we create String Object 100 times will JVM convert byte-code for String to binary 100 times?

Rob Spoor wrote:Or perhaps I understood you wrong. Did you mean that the JVM uses byte-code for each class, but compiles that internally and stores that somewhere to use it for future use?


thats the question for which i am searching answer for.

Rob Spoor wrote: If so, then that has some overhead too. If the class changes the JVM would need to check if the compiled data is still up-to-date.


wont those overheads will be lesser than converting byte-code to binary, if it does this again and again?

Rob Spoor wrote:And what about the storage required if the JVM has encountered hundreds of classes?


True i had not thought of this.
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
any suggestions please.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As far as I know, the JIT does not store the generated native machine code anywhere. So, every time you run a Java program, it will need to JIT-compile the code of classes, including the standard Java classes, into native machine code again. In Java 5 something called class data sharing was added to the JVM to make it start up faster. I don't think that saves the actual generated machine code, though.

These questions are really about the low-level details of how Oracle's HotSpot JVM works. If you're really interested to learn about the details of how the JVM works internally, and what sophisticated optimizations it does to make your code run fast, you could try looking at the source code (in C) which you can find in the OpenJDK project. It will not be easy to understand it, however, because the JVM is a large and very sophisticated piece of software that has been under development for 15 years.
 
Rupesh Mhatre
Ranch Hand
Posts: 35
Hibernate jQuery Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Jesper de Jong wrote: It will not be easy to understand it, however, because the JVM is a large and very sophisticated piece of software that has been under development for 15 years.


Thats the real trouble but thanks anyways i will make this thread as resolved.
 
I just had the craziest dream. This tiny ad was in it.
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic