I have the understanding that perm size is used to store meta data, that would include byte code, static stuff etc.
My question how does usage of reflection affect the perm size, if it ever does. I mean if Program-A uses normal way of running objects and Program-B uses reflection all over, how will the perm-sizes of the two programs compare?
The perm size should be set to 1024 Megabytes. The maximum perm size should be set to 1024 Megabytes. Oracle recommends that -Xmn and -Xmx be set to the same value. This eliminates potentially costly heap reallocations, and can reduce the amount of heap fragmentation that can occur.
It's is initial value of Permanent Space which is allocated at startup of JVM. It's maximum value of Permanent Space that JVM can allot up to. Examples of using -XX:PermSize VM (JVM) option in java > Example1 of using -XX:PermSize VM (JVM) option in java > java -XX:PermSize=512m MyJavaProgram.
The main reason for removing PermGen in Java 8 is: It is very hard to predict the required size of PermGen. It is fixed size at startup, so difficult to tune. Future improvements were limited by PermGen space.
The perm space will grow when you execute code that will load new classes or internalize strings. The reflection classes have to be loaded that's for sure. I'm not sure if the reflection API does use internalized strings heavily but it should not be to hard to find out.
For example for the method getDeclaredMethod(String name, Class<?>... parameterTypes)
the name parameter will be internalized.
This snippet will nicely fills up the perm space:
Random random = new Random();
while(true){
try {
X.class.getDeclaredMethod(toBinaryString(random.nextLong()));
} catch (Exception e) {
}
}
alt text http://img4.imageshack.us/img4/9725/permgen.jpg
In a real world application it will make no difference.
Reflection can generate classes, depending upon implementation. You may, for instance, need to use a reflection artifact thousands of times before it is compiled to bytecode.
As ever, the advice is: Profile your code in realistic situations.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With