Nothing kills Java performance quicker than unhealthy garbage collection (GC). Excess CPU time, poor memory usage, unsatisfactory throughput and long pauses are typical symptoms of struggling GC.
Object promotion analysis helps us identify bottlenecks, and achieve better application responses.
However, aggregating facts from GC logs is slow and tedious work. Can AI help us? How?
In this article, we’ll work through a case study using GCeasy’s Deterministic AI to see how modern technology can provide answers quickly and painlessly.
Java Generational Garbage Collection: Understanding Object Promotion
We can visualize JVM runtime memory like this:

Fig: JVM Runtime Memory
Heap memory is a central storage area for objects from all classes in the application. It’s managed by the GC. Native memory has various memory pools for specialized purposes, and it’s managed by the operating system. For a full explanation of JVM memory management, see JVM Explained in 10 Minutes.
Understanding Young Generation and Old Generation in Java
Let’s look more closely at the heap and how the garbage collector manages it. Most GC algorithms arrange the heap into areas as shown below:

Fig: JVM Heap Memory in Generational GCs
There’s a good reason for this. The Generational Hypothesis postulates that most objects in the heap “die young”. Think of an online sales program. When a user logs in, information about the user is created in memory, and must be kept until the user logs out. It then becomes eligible for GC. Likewise, for each individual transaction, information must be temporarily stored, but it’s no longer needed when the transaction completes. Relatively few objects need to be retained for the entire lifespan of the application.
Most GC algorithms therefore split the heap into the Old Generation (OG) and Young Generation (YG). All new objects are created in YG. YG is cleaned frequently, and because it’s small, these minor GC events happen very quickly. Objects that survive several minor GCs are promoted to the OG.
How Object Promotion Works During Minor GC Events
The YG itself is divided into three areas: Eden, S0, and S1. When an object is created, it’s placed in Eden space. S0 and S1, the survivor spaces, are used alternately to hold GC survivors that have not yet lived long enough to be promoted to the OG.
Every object has an age flag attached to it, which is incremented on each minor GC cycle. When an object reaches an age threshold, it is eligible for promotion to OG. We can control the age threshold using the JVM flag MaxTenuringThreshold.
If there’s not enough free space in the survivor areas to complete a cycle, objects are forced to be promoted to the OG before they reach the tenuring threshold. This is when we start to see unhealthy object promotion.
For more information on heap spaces and object promotion, see Java Heap Generations.
Java Object Promotion Problems: Causes, Symptoms, and Performance Impact
Object promotion analysis gives us deeper insights into whether GC is running as it should. If object promotion is healthy, GC runs efficiently and uses few resources. Unhealthy promotion trends are at the root of a high percentage of Java performance problems.
1. Healthy Java Object Promotion: Characteristics and GC Behavior
In a healthy system, object promotion looks like this:

Fig: Healthy Object Promotion Lifecycle
The key characteristics are:
- Most objects are reclaimed during minor GC events, which work with the YG only;
- The promotion rate is stable;
- Survivor spaces are used, but their capacity is never exceeded;
- OG usage is stable;
- GC pauses are short and consistent in duration.
GC overhead remains low, and there is no danger of OutOfMemory errors in the heap.
2. Unhealthy Java Object Promotion: Symptoms and Warning Signs
Let’s compare that to unhealthy object promotion:

Fig: Unhealthy Object Promotion Lifecycle
The key characteristics are:
- Promotion rate is high and often inconsistent;
- Survivor space is not always sufficient, forcing objects to be promoted to the OG before their normal time;
- OG usage increases, forcing full GC whenever OG is almost full. In the worst-case scenario, OutOfMemoryErrors may occur.
- Mixed and full GCs occur frequently, affecting performance.
Since GC is CPU-intensive, and part of the GC cycle can’t complete while application threads are running, response times become unpredictable, and cloud costs increase.
3. Common Causes of Unhealthy Object Promotion in Java
The purpose of object promotion analysis is to identify the root cause of the problem and determine how to fix it.
The main causes are broken down in the table below.
| Cause | Action | More information |
| Objects retained beyond their useful lifespan | Ensure caches have a valid eviction policy | Killer Antipatterns |
| Declare objects in the right scope | ||
| Avoid large static variables | ||
| Clear all references to short-lived variables from within long-lived objects | ||
| Check for growing collections | ||
| Ensure all resources are closed | ||
| Avoid retaining ThreadLocal variables | How ThreadLocal Variables can Bring Down Your Application | |
| Heap incorrectly sized | Set -Xmx and -Xms accurately | Sizing Your Heap Correctly |
| Sub-optimal tuning | Select correct algorithm | Best GC Algorithm |
| Tune methodically; don’t guess and avoid over-tuning | GC Tuning Guide |
4. Java GC Warning Signs: How Unhealthy Object Promotion Affects Performance
GC events are very CPU-intensive. Some of the work can be done by background threads while the application continues to run. Critical work, such as moving objects to a different memory region, or compacting memory, require all other tasks to be paused. These are known as stop-the-world events. In minor GCs, these pauses are very short, but full GCs, mixed GCs, and compaction take much longer.
Unhealthy promotion triggers excess stop-the-world events and results in:
- Erratic response times;
- Poor throughput;
- High CPU usage;
- Potential OutOfMemory crashes.
5. Monitoring Java GC Performance Using Latency, Throughput, and Footprint
We should monitor logs regularly to make sure GC is behaving as it should, and catch developing issues before they affect performance.
The GCeasy tool simplifies this task by presenting the logs as a set of easy-to-read graphs and charts.
The first thing to monitor is the KPI (key performance indicators) including:
- Latency: the time during which application threads are paused during stop-the-world events;
- Throughput: The percentage of time used by application threads to do actual work, as opposed to GC threads carrying out maintenance;
- Footprint: Resources used by GC.
GCeasy includes a KPI graph, which we can easily compare with previous logs to see if performance is degrading.

Fig: KPI Chart by GCeasy
6. Identifying Unhealthy Heap Usage Patterns Through GC Logs
Heap usage before and after GC is also a good indicator of GC health. GCeasy graphs heap usage over time, with GC events indicated. Healthy GC produces a sawtooth pattern as shown below, as memory builds up and then is cleared back down to a fairly constant level when the GC runs.

Fig: Healthy GC Pattern
For more information about unhealthy GC patterns, see Garbage Collection Patterns.
Using Deterministic AI for Java GC Log and Object Promotion Analysis
To evaluate object promotion health, we need to monitor the GC logs over a fairly long period, which includes both peak and off-peak times. We also need to include the gc+age=trace option when we request GC logging on the command line. This includes an analysis of objects by age for every GC event.
Since the logs are likely to be very long, we need a quick way of pulling out the relevant information; otherwise, the job will take hours. This is where AI can help us.
AI alone has a few drawbacks:
- Since the logs are long, regular analysis could become expensive on tokens;
- AI can make mistakes, especially if it’s not fed the right set of facts;
- Explaining the significance of exact metrics for consideration in the AI prompt requires a high level of user expertise.
GCeasy’s deterministic AI gives us the combination of a reliable set of facts with the flexibility of AI. GCeasy uploads the logs and presents a curated set of summarized and relevant facts to the LLM engine.
For more information about deterministic AI, watch Advantages of Deterministic AI.
Case Study: Analyzing Java Object Promotion Issues Using AI
Let’s see this in action. We wrote a short program that simulates an application retaining variables for longer than necessary. We then ran the program with the following GC logging options on the command line:
-Xlog:gc*,gc+age=trace,gc+heap=debug:file=gc.log:time,uptime,level,tags
After running for a few hours, we submitted the logs to GCeasy’s Deterministic AI configured to use Claude as the LLM, and asked Claude a series of questions regarding object promotion health.
Java Application Setup: Simulating Unhealthy Object Promotion
The application has three parts:
- The main thread loops indefinitely. It creates a long string buffer and adds it to a tree map, which is an instance variable. This map will continue to grow over time. It simulates an object that is retained longer than necessary and will be promoted to the OG;
- Several threads that create clutter variables, simulating short-lived variables that will be cleared during minor GC events, and will not reach the OG. These make sure the YG actually does fill up with young objects, forcing older objects to be promoted.
- A cleardown thread that periodically clears down the tree map.
It mimics an application that keeps large variables that are cleared down from time to time, perhaps during a day-end procedure.
import java.util.TreeMap;public class BuggyProg18 {// This program demonstrates creating both short and long-lived objects// It’s useful for demonstrating GC log analysis// Long-lived objects are cleared down periodically// It accepts parameters controlling the frequency of both object creation// and cleardown threads// =======================================================================// Growing tree map: long-lived object// =================================== TreeMap map = new TreeMap(); static int pause = 1; // Default pause in creation threads (ms) static int clearPause = 45; // Default pause between cleardowns // in minutes public static void main(String[] args){ if(args.length>0) try { pause=Integer.parseInt(args[0]); } catch(Exception e) {} if(args.length>1) try { clearPause=Integer.parseInt(args[1]); } catch(Exception e) {} // Create an object from this class// ================================ BuggyProg18 a = new BuggyProg18(); }// Constructor// =========== public BuggyProg18() { // Start threads to create clutter startClutter();// Start a thread in the background that clears the map startCleardownThread(); long counter = 0;// Loop that has no valid termination condition// ============================================ while (true) { if (counter % 1000 == 0) { System.out.println("Inserted " + counter + " Records to list"); // Delay to ensure there will be time to collect diagnostics before OOM error// ========================================================================== try{Thread.sleep(pause*100);} catch (Exception e) {} }// This map will grow until an OOM error occurs// ============================================ String s = new String("ABCDEFGHIJK"); StringBuffer b = new StringBuffer(s); for(int i=0;i<60;i++) b.append(s); map.put(counter,b.toString()); ++counter; byte[] temp = new byte[16384]; } }// This thread clears the map// ==========================private void startCleardownThread() { Thread backgroundThread = new Thread(() -> { while (true) { try { Thread.sleep(clearPause * 60 * 1000); } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } System.out.println("Clearing"); map.clear(); } }, "backgroundThread"); backgroundThread.setDaemon(true); // Optional backgroundThread.start(); }// These threads create short-lived variables// ==========================================private void startClutterThread() { Thread clutterThread = new Thread(() -> { while (true) { try { byte[] clutter = new byte[500000]; Thread.sleep( 50 * 1000); clutter=null; } catch (InterruptedException e) { Thread.currentThread().interrupt(); break; } } }, "clutterThread"); clutterThread.setDaemon(true); // Optional clutterThread.start(); }// This method controls the clutter threads// ======================================== private void startClutter() { Thread starterThread = new Thread(() -> { for (int i=0;i<20;i++) {// Start a thread in the background that creates some clutter startClutterThread(); try{Thread.sleep(1000);} catch (Exception e) {} } }, "starterThread"); starterThread.start(); }}
We ran this program as follows:
java -Xlog:gc*,gc+age=trace,gc+heap=debug:\file=shared/logs/BuggyProg18.log:time,uptime,level,tags \-Xms128M -Xmx128M BuggyProg18 250 60
After a few hours, we logged into GCeasy and selected deterministic AI. Below are screenshots of the questions we used to carry out our object promotion analysis, and the answers we received from Claude.
Analyzing Java Object Promotion Health Using GC Logs
We chose the Deterministic AI tab, attached the log, and asked the following question:
Please analyze the attached GC log and be ready to answer questions related to object promotion health. Where supplied information is insufficient, please suggest what further diagnostics would be useful, rather than making assumptions.

Fig: Initial Question for LLM
Claude responded with a lengthy analysis, sections of which are shown below.
First, it produced an overview of GC activity.

Fig: Overview
It then goes on to analyze promotion health.

Fig: Promotion Health Analysis: Parts 1 and 2

Fig: Promotion Health: Parts 3 to 5
Claude then analyzes patterns and trends, and makes suggestions on how tuning could be improved.

Fig: Patterns, Trends and Recommendations
Finally, the report ends with a list of diagnostics that would be useful in delving further into root causes, and contains a link to the full GCeasy report.

Fig: Next Steps
Analyzing Old Generation Reclamation and Memory Pressure
Next, we asked Claude the following question:
Is reclamation in the Old Generation effective, and is promotion contributing to increased memory pressure?
We received this answer:

Fig: Old Generation Reclamation and Pressure
Claude identified the following warning signs:
- OG is expanding under load;
- Promotion rate is significantly higher than creation rate.
It also recommended further tuning options.
Assessing Java GC Performance Risks and Potential OutOfMemoryErrors
We then asked the following question:
Assess the likelihood of increased GC overhead, excess full GC events and out of memory errors if current usage patterns continue.
Claude responded with both a risk assessment and suggestions on how risk can be reduced.

Fig: Risk Assessment and Risk Reduction
Identifying GC Pressure Patterns and Prioritizing Troubleshooting Strategies
Our next question was:
Can you identify any timing pattern to when the heap is under severe pressure, and when it appears fairly healthy? Given these patterns, would you recommend prioritizing analyzing the application for retention patterns, or tuning? Can you give any idea of what we should look for in the application code to improve these trends?
Claude responded with patterns and recommended prioritizing leak/retention analysis over tuning.
It recommends using the -XX:+HeapDumpBeforeFullGC option on the command line to obtain a heap dump when the OG is under peak pressure.

Fig: Recommendations Based on GC Patterns
Conclusion
Deterministic AI takes GC log analysis to a new level. For complex tasks such as object promotion analysis, the combination of reliable, curated data produced by GCeasy with the flexibility of LLM saves time without losing accuracy.





Share your thoughts!