Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

finding out memory allocation hotspots in java

Our GC is working hard and we have some pauses that we want to decrease. We have some memory allocation issues that we want to solve before or while we are tweaking with the actual JVM GC args.

I would like to know which objects are making the GC sweat:

  1. is there a way to know which objects are evacuated every time the GC is working?
  2. is there a way to know which objects are moved between areas every time the GC is working?
  3. Is there a way to know which objects are in Eden area?

I am working extensively with Jprofiler and Memory Analyzer. I would like to get this information on a running application in my staging environment.

like image 643
Zamir Avatar asked Nov 12 '12 14:11

Zamir


People also ask

How do I check Java memory usage?

Using VisualVM (jvisualvm) jvisualvm is a tool to analyse the runtime behavior of your Java application. It allows you to trace a running Java program and see its the memory and CPU consumption. You can also use it to create a memory heap dump to analyze the objects in the heap.

Where is the memory allocated in Java?

Memory allocation in java occurs in two ways, mainly, stack and heap space.

How many memory areas are allocated by JVM?

Two kinds of memory. The JVM divides its memory into two main categories: heap memory and non-heap memory.


2 Answers

For 2 and 3, you can use the -XX:+PrintGCDetails and -XX:+PrintGCTimeStamps flags with either Oracle or OpenJDK java executable during a run session of your application

like image 83
higuaro Avatar answered Oct 11 '22 17:10

higuaro


For question 1, Phantom References can be used. This will allow you to be notified when an object is GC'ed (or GC-able).

As to the other two, I don't quite know.

like image 33
cmonkey Avatar answered Oct 11 '22 17:10

cmonkey