How does a JVM process allocate its memory?

Asked
Active3 hr before
Viewed126 times

4 Answers

90%

You may want to use Java HotSpot Native Memory Tracking (NMT).,This may give you an exact list of memory allocated by the JVM, splitted up into the different areas heap, classes, threads, code, GC, compiler, internal, symbols, memory tracking, pooled free chunks, and unknown.,You can start your application with -XX:NativeMemoryTracking=summary.,This gives a detailed overview of the different memory areas used by the JVM, and also shows the reserved and commited memory.

By just running jcmd without any parameter, you get a list of running Java applications.

user @pc: ~$ / usr / bin / jcmd
5169 Main < --5169 is the pid
88%

Garbage collection can have a negative and unpredictable impact on Java application performance if it is improperly tuned. For instance, when full collection events happen too often, they cause high CPU usage on the application server, resulting in poor application request processing.,The following list describes three important components of JVM memory:,The next article in this series covers the different garbage collectors and guidelines for choosing the best one for your application.,Parameters affecting the memory available to the JVM include:

You can calculate the memory used by a JVM process as follows:

JVM memory = Heap memory + Metaspace + CodeCache + (ThreadStackSize * Number of Threads) + DirectByteBuffers + Jvm - native
load more v
72%

During the sweep phase the heap is traversed to find the gaps between the live objects. These gaps are recorded in a free list and are made available for new object allocation. , Initial marking, where the root set of live objects is identified. This is done while the Java threads are paused., Garbage collection is the process of freeing space in the heap or the nursery for allocation of new objects. This section describes the garbage collection in the JRockit JVM. , Final marking, where changes during the precleaning phase are identified and any additional live objects are found and marked. This is done while the Java threads are paused.

Object Allocation

During object allocation, the JRockit JVM distinguishes between small and large objects. The limit for when an object is considered large depends on the JVM version, the heap size, the garbage collection strategy and the platform used, but is usually somewhere between 2 and 128 kB. Please see the documentation for -XXtlaSize and -XXlargeObjectLimit for more information.

-XXtlaSize

Object Allocation

During object allocation, the JRockit JVM distinguishes between small and large objects. The limit for when an object is considered large depends on the JVM version, the heap size, the garbage collection strategy and the platform used, but is usually somewhere between 2 and 128 kB. Please see the documentation for -XXtlaSize and -XXlargeObjectLimit for more information.

-XXlargeObjectLimit
load more v
65%

Thread: memory used by threads in the JVM. A function of the number of threads that are running.,Internal: stores other internal data that does not fit into any of the other areas.,Configuring the JVM to make efficient use of a given amount of available RAM isn’t easy. If you launch the JVM with -Xmx16M and expect it to use, at most, 16MB of RAM you are in for a nasty surprise.,VMware offers training and certification to turbo-charge your progress.

The JVM divides its memory into two main categories: heap memory and non-heap memory. Heap memory is the part with which people are typically the most familiar. It’s where objects that are created by the application are stored. They remain there until they are no longer referenced and are garbage collected. Typically, the amount of heap that an application is using will fluctuate as a function of the current load.

The JVM’s non-heap memory is divided into several different areas. We can use the HotSpot VM’s native memory tracking (NMT) to examine its memory usage across these areas. Note that, while NMT does not track all native memory usage (it does not track third party native code memory allocations, for example), it is sufficient for a large class of typical Spring applications. NMT can be used by starting the application with -XX:NativeMemoryTracking=summary and then using jcmd <pid> VM.native_memory summary to display the memory usage summary.

-XX: NativeMemoryTracking = summary

The JVM divides its memory into two main categories: heap memory and non-heap memory. Heap memory is the part with which people are typically the most familiar. It’s where objects that are created by the application are stored. They remain there until they are no longer referenced and are garbage collected. Typically, the amount of heap that an application is using will fluctuate as a function of the current load.

The JVM’s non-heap memory is divided into several different areas. We can use the HotSpot VM’s native memory tracking (NMT) to examine its memory usage across these areas. Note that, while NMT does not track all native memory usage (it does not track third party native code memory allocations, for example), it is sufficient for a large class of typical Spring applications. NMT can be used by starting the application with -XX:NativeMemoryTracking=summary and then using jcmd <pid> VM.native_memory summary to display the memory usage summary.

jcmd <pid> VM.native_memory summary
load more v

Other "undefined-undefined" queries related to "How does a JVM process allocate its memory?"