Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How the sun.reflect.GeneratedSerializationConstructorAccessor class generated

In order to print the GC logs of a web application,Before the tomcat startup,add the following parameters:

-Xms256m 
-Xmx512m 
-XX:PermSize=128M 
-XX:MaxPermSize=512M
-Xloggc:D:/TomcatGc.log

However, the following information is printed on the Terminal continuously.

[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor339]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor336]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor341]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor342]
[Unloading class sun.reflect.GeneratedSerializationConstructorAccessor340]

My questions are:

  1. Why are these classes generated? I'd like to understand this concept, but can't find any information about it.

  2. How can I prevent the GC unloading them?

like image 802
Felix Avatar asked May 05 '26 05:05

Felix


2 Answers

this is because (may be you are using reflection in your application) heap is running out of space and GC is trying to free some memory by unloading unused objects, that is why you see Unloading class sun.reflect.GeneratedSerializationConstructorAccessor

More info --> http://coding.derkeiler.com/Archive/Java/comp.lang.java.programmer/2006-11/msg00122.html

like image 128
Mohammad Adil Avatar answered May 06 '26 18:05

Mohammad Adil


Different type of accessors

The method accessor and constructor accessors are either native or generated. This means that either we use NativeMethodAccessorImpl or GeneratedMethodAccessor for Methods and NativeConstructorAccessorImpl and GeneratedConstructorAccessor for Constructors. The accessor would be a native or generated and is controlled and decided by two system properties:

  1. sun.reflect.noInflation = false (default value is false)
  2. sun.reflect.inflationThreshold = 15 (default value is 15)

When the sun.reflect.noInflation is set to true then the accessor used will always be generated and there is no meaning for the system property sun.reflect.inflationThreshold. When the sun.reflect.noInflation is false and the sun.reflect.inflationThreshold is set to 15 (thats the default behavior if not specified) then it means that for the first 15 accesses to the constructor (or methods), a native generator will be used and thereafter a generated accessor will be supplied (from ReflectionFactory) for use.

The Native accessor uses native calls to access information, whereas the generated accessor is all byte code and hence very fast. On the other hand generated accessor needs time to instantiate and load (basically inflates and hence the system properties controlling it has names including 'inflation' word).

More details can be found at the original blog

like image 32
Maxim Kirilov Avatar answered May 06 '26 19:05

Maxim Kirilov