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

前端 未结 3 1267
既然无缘
既然无缘 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:13

    There are a lot of maintenance data structures. E.g. every initialized JVM has these system properties, which is a subtype of Hashtable, hence, explains the Hashtable.Entry instances.

    Also, core classes like java.lang.Character know the Unicode properties of all characters, also, you see Locale-specific classes in you stats, as these have to be properly initialized at startup. What makes these examples so interesting, is, that they are loading these information from files or embedded resources, so their initialization involves I/O and caching mechanisms, whose artifacts you see in your output.

    Also, other objects created during the startup process might not have been garbage collected yet. There are a lot of operations, like processing the class path and the jar files specified by it or parsing the command line options, which are more complex than the “Hello World” program that will be executed at the end. Mind that you can create a heap dump instead of just a histogram, so you can see who is holding a reference to the existing objects.

提交回复
热议问题