javajvmmetaspace

GeneratedMethodAccessor from JVM_DefineClass loaded 10k times cause oom


enter image description here

added "-verbose:class" in jvm paramerter, and got 10k times log like below, "Loaded sun.reflect.GeneratedMethodAccessor10004 from JVM_DefineClass"

do I have any way to find the origin class and what is the root method of my application caused this?

I know "GeneratedMethodAccessor### are classes generated at runtime by the reflection implementation to call methods and constructors", but I don't what is the specific method or class loaded?


Solution

  • async-profiler can help to find where these MethodAccessors are generated.

    Run

    ./profiler.sh -d 120 -e sun.reflect.MethodAccessorGenerator.generate -f report.html <javaPID>
    

    This will start recording for 120 seconds. All generated MethodAccessors for calling Method.invoke and Constructor.newInstance will be captured and saved as a Flame Graph report under report.html.

    The Flame Graph shows the number of generated accessors with the stack traces of their origin:

    Reflection Flame Graph

    Alternatively to attaching the profiler in runtime, you can start Java with the profiler enabled from the very beginning:

    java -agentpath:/path/to/libasyncProfiler.so=start,event=sun.reflect.MethodAccessorGenerator.generate,file=report.html -jar <your application>