Java memory diagnostics
Java memory diagnostics scans a Java process and its pod when memory usage is high but the cause is unclear. It breaks down memory from both the JVM perspective and actual process memory occupation.
Scope
-
Regions
Currently available only in the Chinese mainland and China (Hong Kong).
-
Permission limits
If you use a Resource Access Management (RAM) user, ensure the Alibaba Cloud account has granted the
AliyunECSReadOnlyAccessandAliyunSysomFullAccesssystem policies to the RAM user. Only console-managed instances can be diagnosed. -
Operating systems
Architecture
Operating system
x86 architecture
-
Rocky Linux 9.5
-
Rocky Linux 9.1
-
Ubuntu 20.04
-
Alibaba Cloud Linux 3 Container Optimized
-
Rocky Linux 8.8
-
Ubuntu 22.04
-
Alibaba Cloud Linux 3 Pro
-
Alibaba Cloud Linux 2/3
-
CentOS 7.6 or later, or CentOS 8
-
Anolis OS 7/8
-
Ubuntu 24.04
ARM architecture
Not supported.
-
Procedure
-
Log on to the Cloud Monitor console. Select the target workspace. In the navigation pane on the left, click All Features.
-
On the All Features page, click CloudLens for ECS.
-
At the top of the page, click System Diagnosis (SysOM).
-
Set Diagnosis Mode to Node Diagnosis. From the Type of diagnosis drop-down list, select Memory Diagnostics. From the Diagnostic Item drop-down list, select Java Memory Diagnosis.
-
Select a Java memory diagnosis mode:
-
Diagnose Java Process: Select this mode and enter the PID of the target Java process.
-
Diagnose Pod of Java Process: Select this mode and enter the pod name.
Supports only single-container pods where the Java process is PID 1.
-
-
Click Execute Diagnosis. In the Diagnosis Records area, click View Report.
Diagnostic report
-
Basic information
Includes the instance ID (resource ID), diagnosis item, report ID, and start time.
-
Diagnostic conclusion
Displays details about detected memory anomalies.
-
Diagnostic suggestions
Provides troubleshooting suggestions when abnormal memory usage is detected.
Diagnostic details
-
Overview of Java process information & Information about the pod/container of the Java process
Shows the process PID, JVM memory usage, actual process memory, anonymous memory, and file-backed memory.
In Diagnose Pod of Java Process mode, also shows Resident Set Size (RSS) and WorkingSet for the pod and container.
-
Java process memory details
Three pie charts show Java heap usage (JVM perspective), non-heap usage (JVM perspective), and actual process memory. Use these to identify which areas consume the most memory.
-
Top 10 heap objects by memory usage
Lists the top 10 classes in the JVM heap by memory usage, with class name, instance count, and total size.
-
Top 10 class loaders by number of loaded classes
Lists the top 10 class loaders by loaded class count, with loader name, class count, and loader instance count.
-
Java Native Interface (JNI) memory allocation flame graph
Shows a flame graph of JNI memory allocation calls when JNI profiling is enabled. Displays all call paths that allocate JNI memory. Because data is sampled, sizes do not represent actual allocations.
-
JNI memory leak flame graph
Shows a flame graph of potential JNI memory leaks when JNI profiling is enabled. Displays allocation call paths with suspected leaks. Because data is sampled, sizes do not represent actual allocations.
Flame graph data appears only if JNI memory allocation profiling is enabled at diagnosis start and the profiling duration completes before viewing the report.
Use case
This example demonstrates diagnosing common Java memory issues: pod OOM errors, high pod memory, or high process memory when JVM monitoring reports low usage.
Symptoms
A Java pod's RSS memory in a Kubernetes cluster keeps increasing until OOM occurs. JVM monitoring shows heap and non-heap usage is ~100 MB lower than the RSS reported by container monitoring. The cause of this discrepancy must be identified.
Diagnostic analysis
Run a Java memory diagnosis on the pod and review the results:
The diagnostic conclusion shows that JNI memory usage is too high. The report suggests checking the JNI memory allocation flame graph for potential memory leaks.
This indicates a JNI memory leak — a primary reason for RSS exceeding JVM-reported memory, because JNI allocations are not tracked by the JVM.
Solution
Run another diagnosis with JNI memory profiling enabled. After the profiling duration completes, view the report. The JNI flame graphs reveal that many java.util.zip.Deflater objects were created but never released, causing the leak. The issue was resolved by fixing the code to properly release these objects.