Why does my Oracle JVM create all these objects for a simple 'Hello World' program?

前端 未结 3 1215
既然无缘
既然无缘 2021-02-04 15:01

I was playing around with jmap and found that simple \"Hello World\" Java program creates thousands of objects. Here is truncated list of objects Oracle JVM

3条回答
  •  被撕碎了的回忆
    2021-02-04 15:18

    You can find the answer yourself by running the application with -XX:+TraceBytecodes flag.
    This flag is available in debug builds of HotSpot JVM.

    Here is the detailed Flame Graph (clickable SVG) showing the stack traces where the allocated objects come from.

    In my case the main sources of start-up allocations were

    • URLClassLoader and Extension ClassLoader
    • Locale cache
    • UsageTrackerClient
    • MetaIndex registry
    • System Properties
    • Charset initialization

    P.S. The script used to generate the Flame Graph from TraceBytecodes output.

提交回复
热议问题