4

As shown in the image, Permgen is further divided into several parts.

enter image description here

Runtime constant pool stores constants pertaining to each type that is loaded by class loader.

Method area stores method information such as method return type, method name. (correct me if I am wrong here.)

And Reserved area is the part which is reserved if more memory is required by permgen.

But what I don't understand is, what is code area in the image? Any code is stored in this space(seems vague to me)?

Community
  • 1
  • 1
codingenious
  • 8,385
  • 12
  • 60
  • 90

5 Answers5

2
Any code is stored in this space(seems vague to me)?

Any specific reason for that ?

The possible answer could be : Code area stores the byte code of the classes loaded into your memory.

But then the question comes, Why class is not loaded directly in RAM ?

Because we have a JVM to provide interoperability, Since JVM is an intermediary between java code and the machine , we need some place to store the code statements until JVM is scheduled by OS to execute its code.(for OS JVM is a process). So, It loads the byte code in Code area(if i am right) and when scheduled, further interprets code(.class) into underlying machine instructions.

The answer to me is "Code area holds the byte code of the classes".

To back the idea mentioned above ., here are some concepts copied as it is from Oracle blog which says:

So the Java classes are stored in the permanent generation. What all does that entail? Besides the basic fields of a Java class there are:

  1. Methods of a class (including the bytecodes)
  2. Names of the classes (in the form of an object that points to a string also in the permanent generation)
  3. Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details).
  4. Object arrays and type arrays associated with a class (e.g., an object array containing references to methods).
  5. Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)
  6. Information used for optimization by the compilers (JITs)

Hope it clears.

Aman Arora
  • 1,232
  • 1
  • 10
  • 26
  • Are you sure, code is placed here? Because if all code is placed here, I think 64MB of permgen won't be sufficient. Give it another thought. :) – codingenious Nov 21 '13 at 12:00
  • According to the [Java Language Specs](http://docs.oracle.com/javase/specs/jvms/se7/html/jvms-2.html#jvms-2.4),one of the run-time data areas is **Method Area**, which holds the method code, constructor code , method data and run-time constant pool. So in the picture shared by you, i feel that method area is splitted into three parts for visualisation purpose only. And code contains your class code (constructor and method statements). *About 64 MB permgen space ?* Is there a limitation on the maximum size of permgen? – Aman Arora Nov 21 '13 at 12:28
0

From an interesting article on the problems of PermGen: Will Java 8 Solve PermGen OutOfMemoryError?:

Jon Masamitsu, JVM developer at Oracle, explained 2006 in his blog the purpose of the permanent generation: The permanent generation contains information about classes, such as bytecode, names and JIT information. It is stored in a separate space, because it is mostly static and garbage collection can be much more optimized by separating it.

Andrey Chaschev
  • 16,160
  • 5
  • 51
  • 68
0

Actually the PermGen store all your static code. i think this makes sense to you why there is a code area in PermGen.

codingenious
  • 8,385
  • 12
  • 60
  • 90
Salah
  • 8,567
  • 3
  • 26
  • 43
0

I will venture to guess, based on the following article, by Jon Masamitsu, from which the following quote is taken, that the figure above is a misrepresentation (or rephrased - a misleading representation):

So the Java classes are stored in the permanent generation. What all does that entail? Besides the basic fields of a Java class there are

Methods of a class (including the bytecodes)

Names of the classes (in the form of an object that points to a string also in the permanent generation)

Constant pool information (data read from the class file, see chapter 4 of the JVM specification for all the details).

Object arrays and type arrays associated with a class (e.g., an object array containing references to methods).

Internal objects created by the JVM (java/lang/Object or java/lang/exception for instance)

Information used for optimization by the compilers (JITs)

Yaneeve
  • 4,751
  • 10
  • 49
  • 87
  • No I mean, that, as best as I can tell, there should have been a square/rectangle/area within the graph above for each of the six entity types + the one for the Reserved space. But again, I do not know for sure and have not been able to ascertain any more than that. Also, this is probably more relevant for hotspot, than for another JVM implementation – Yaneeve Nov 21 '13 at 12:40
0

The bytecode of all classes that have been resolved live in permgen. Just because a library has 1.2MB of classes doesn't they will be loaded by the JVM from the JAR. It it possible, even likely, that only a small fraction of those classes are used by a particular application.

You can run many large application servers whose sum total JAR size is >1GB using only 64MB permgen, because only a fraction of the classes are ever used.

Also take this example:

class A {
   // ... code
}

class B {
   void method1() {
      // something
   }

   void method2() {
      A a = new A();
   }
}

While these classes may reside in the same JAR, merely creating an instance of B does not cause class A to be loaded. If you never call method2(), class A will never be loaded by the JVM. Additionally, contrary to popular belief, permgen can be garbage collected, and if space gets low, and there are no instances on the heap referring to class A anymore, then class A can be removed from permgen.

brettw
  • 10,664
  • 2
  • 42
  • 59