Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Memory details of JVM as a process

I'm new to this topic, so, apologies if my question is obvious but here it is-
Whenever we start a Java application, a new instance of JVM is created. JVM itself is a process which runs on OS and like any other process, it has memory requirements of its own.
I'm aware of heap and non-heap memory structure and how they can be configured and manipulated. What I'm looking for is memory details of jvm process itself, How the overall memory is divided i.e. jvm's own memory requirements+heap+non-heap+native stack
How many segments are there?
How much memory OS allocates to JVM and how does jvm use it further?
Is there any command or utility to check these details while running an application?
I've googled a lot but not finding anything concrete in this direction, almost everywhere articles explain the heap and non-heap memory structure (eden / old / meta etc.). I've also visited below links-
JVM Memory Types
How is the java memory pool divided?
JVM Memory segments allocation
https://blog.codecentric.de/en/2010/01/the-java-memory-architecture-1-act/
JVM memory mapping over a Linux Process
Understanding JVM Memory Allocation and Java Out of Memory: Heap Space
It seems I'm stuck here, any pointer on this topic would be great so that I can start looking in that direction.

like image 476
meexplorer Avatar asked Mar 11 '23 11:03

meexplorer


2 Answers

Native Memory Tracking (NMT) feature of Java 8 helps to answer your questions.

Run Java with the option -XX:NativeMemoryTracking=summary
Then at run time execute the following command to print JVM memory statistics:

jcmd <pid> VM.native_memory summary

The output will look like:

Total:  reserved=664192KB,  committed=253120KB

-                 Java Heap (reserved=516096KB, committed=204800KB)
                            (mmap: reserved=516096KB, committed=204800KB)

-                     Class (reserved=6568KB, committed=4140KB)
                            (classes #665)
                            (malloc=424KB, #1000)
                            (mmap: reserved=6144KB, committed=3716KB)

-                    Thread (reserved=6868KB, committed=6868KB)
                            (thread #15)
                            (stack: reserved=6780KB, committed=6780KB)
                            (malloc=27KB, #66)
                            (arena=61KB, #30)

-                      Code (reserved=102414KB, committed=6314KB)
                            (malloc=2574KB, #74316)
                            (mmap: reserved=99840KB, committed=3740KB)

-                        GC (reserved=26154KB, committed=24938KB)
                            (malloc=486KB, #110)
                            (mmap: reserved=25668KB, committed=24452KB)

-                  Compiler (reserved=106KB, committed=106KB)
                            (malloc=7KB, #90)
                            (arena=99KB, #3)

-                  Internal (reserved=586KB, committed=554KB)
                            (malloc=554KB, #1677)
                            (mmap: reserved=32KB, committed=0KB)

-                    Symbol (reserved=906KB, committed=906KB)
                            (malloc=514KB, #2736)
                            (arena=392KB, #1)

-           Memory Tracking (reserved=3184KB, committed=3184KB)
                            (malloc=3184KB, #300)

-        Pooled Free Chunks (reserved=1276KB, committed=1276KB)
                            (malloc=1276KB)

-                   Unknown (reserved=33KB, committed=33KB)
                            (arena=33KB, #1)

More information here and here.

like image 101
apangin Avatar answered Mar 24 '23 14:03

apangin


If you are looking for command line utilities start from jps that just prints PIDs of all running java processes. Then choose one that you want to discover and use jmap with its PID.

JDK arrives with visual tools also. The old one JConsoke and the newer and better one VisualVM.

like image 25
AlexR Avatar answered Mar 24 '23 13:03

AlexR