Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is the Java .class file stored in JVM memory

Tags:

java

jvm

I read on the JVM memory model and got confused with the follows:

  1. Does the JVM store the .class instance in its memory. If yes then in which area.
  2. Is it like as soon as the class is loaded,the JVM generated machine level code and then starts executing the machine code instructions and then only the objects are created on heap and method area is populated.
  3. The perm gen etc areas store the byte code or the machine level code?
  4. perm gen vs method area

I would really appreciate any help on the topic.

Thanks.

like image 702
user1649415 Avatar asked Sep 05 '12 15:09

user1649415


2 Answers

1) .class file will be store in permgen memory area on load.

2) Objects on HEAP will be created while program run, when you explicitly create, not on load. The JVM compiles methods 'lazily', that is it emits small stubs in place of the compiled machine code of the method that will trigger the compilation of each method. This means that methods that are not used are never compiled.

3) perm gen stores bytes code (.class file will be loaded), not sure about machine level code.

like image 192
kosa Avatar answered Oct 26 '22 20:10

kosa


Does the JVM store the .class instance in its memory.If yes then in which area

PermGen

Is it like as soon as the class is loaded

You can load the class without reading the .class

,the JVM generated machine level code and then starts executing the machine code instructions

The byte code is interpreted or potentially compiled to native machine code some time later.

The perm gen etc areas store the byte code or the machine level code?

Both. They are inseparable.

like image 33
Peter Lawrey Avatar answered Oct 26 '22 20:10

Peter Lawrey