
$ docker exec -privileged -ti hello-jvm $ jcmd To do so, first we need to enable native memory tracking in our java app:

But there are many other non-heap memory regions the JVM will use. It's where the JVM will store class definitions, static variables, methods, classloaders and other metadata. If you have ever written a non-trivial java application with jdk8 you have probably heard of Metaspace. In the previous section I ran through what objects are loaded into the heap for our HelloWorld program, so what about non-heap memory? List s = new ArrayList() will create an ArrayList object on the heap, and s will point to this.

Specifically, it contains objects that have been initialized - e.g. If we zoom in, the heap has different areas within which we can talk about, depending on what we want to discuss - there is the Eden space, where most new objects are initially created, the Survivor space, where objects go if they survive an Eden space garbage collection (GC) and the Old Generation which contains objects that have lived in Survivor space for a while.

If we take a high level view first we have two segments - memory used for objects on the heap and non-heap memory. The JVM can be divided into many different memory segments (segments/regions/areas, I'll use these words interchangeably, but generally they mean the same thing), I mentioned other memory regions in the JVM earlier, what are these? That's a quick overview of one way to look at what's loaded on the heap.

Enter fullscreen mode Exit fullscreen mode
