Reputation:
I analysed simple heap dump from Java program containing only this in main method.
public static void main(String[] args) throws IOException {
System.in.read();
}
Using HPROF parser library, my output is that:
Done, found:
Classes: 473
Instances: 13161
Namespace java
Classes: 251
Instances: 9033
How is that possible that there are so many instances without me creating any of them. Are these java runtime instances?
Upvotes: 3
Views: 103
Reputation: 98630
The JVM starts execution of Java bytecode long before entering application's main
method. The significant part of the JVM bootstrap procedure is written in Java. In particular, this includes:
This initialization code, having been written in Java, sometimes allocates Java objects, of course. And some of these objects stay alive for the entire lifespan of the JVM.
This answer describes an approach to find out, what these objects are, and where they are allocated.
Here is a clickable Flame Graph of objects allocated during the JVM bootstrap:
Upvotes: 1
Reputation: 121048
JVM needs a lot of classes to be loaded to run your code. One way to see them would be to use jmcd
utility for this:
jcmd <YOUR_PID> VM.class_hierarchy
And you will see just how many are there. You can also do:
jcmd <YOUR_PID> GC.class_histogram
and find out how many instances of what is now in the heap and how much space it takes.
Upvotes: 0