How the sun.reflect.GeneratedSerializationConstructorAccessor class generated

12,399

Solution 1

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

Solution 2

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

Solution 3

Your first question has been answered by @pXL, but:

  1. How can I prevent the GC unloading them?

You can't. Why on earth would you want to? They're no longer referenced, which implies there are no reachable instances, so they are eligible for garbage collection, so they are being garbage-collected, which implies unloading.

Preventing that would be both pointless and counter-productive.

Share:
12,399
Felix
Author by

Felix

Code Farmer!

Updated on June 05, 2022

Comments

  • Felix
    Felix almost 2 years

    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?