[jdk21u-dev] RFR: 8337994: [REDO] Native memory leak when not recording any events
Boris Ulasevich
bulasevich at openjdk.org
Mon Nov 4 17:30:37 UTC 2024
On Thu, 24 Oct 2024 13:54:06 GMT, Boris Ulasevich <bulasevich at openjdk.org> wrote:
> (not a clean backport)
> Reworked to avoid https://github.com/openjdk/jdk/pull/17328/files backport
Reproducer:
import jdk.jfr.consumer.RecordingStream;
/**
* Stress test to provoke the memory leak:
* starts 1M empty threads in VM with jfr recording
*/
public class PinnedThreadTracker implements AutoCloseable
{
private final RecordingStream recordingStream;
public PinnedThreadTracker() {
recordingStream = new RecordingStream();
recordingStream.startAsync();
System.out.println("start recording..");
}
@Override
public void close() {
recordingStream.close();
}
class MyThread extends Thread {
public void run() {
}
}
public void runThreads() {
for (int i = 0; i < 100; i++) {
for (int j = 0; j < 100; j++) {
for (int k = 0; k < 100; k++) {
new MyThread().start();
}
MyThread thr = new MyThread(); thr.start();
try {
thr.join();
} catch (Exception ex) {}
}
System.out.print(".");
}
}
public static void main(String a[]) {
PinnedThreadTracker ptt = new PinnedThreadTracker();
ptt.runThreads();
ptt.close();
}
}
Manual testing results on jdk21u:
$ for i in {0..60}; do
export PID=`ps -ax | grep java | grep PinnedThreadTracker | sed "s/^ *// ; s/ .*//"`
jcmd $PID VM.native_memory | grep Tracing.*reserved
sleep 1s
done
Before the change (jcmd VM.native_memory output once a second):
- Tracing (reserved=17355KB, committed=17355KB)
- Tracing (reserved=21646KB, committed=21646KB)
- Tracing (reserved=25870KB, committed=25870KB)
- Tracing (reserved=30065KB, committed=30065KB)
...
- Tracing (reserved=240567KB, committed=240567KB)
- Tracing (reserved=244519KB, committed=244519KB)
- Tracing (reserved=248525KB, committed=248525KB)
- Tracing (reserved=252527KB, committed=252527KB)
With the fix:
- Tracing (reserved=17655KB, committed=17655KB)
- Tracing (reserved=18125KB, committed=18125KB)
- Tracing (reserved=18449KB, committed=18449KB)
- Tracing (reserved=18961KB, committed=18961KB)
...
- Tracing (reserved=17443KB, committed=17443KB)
- Tracing (reserved=17958KB, committed=17958KB)
- Tracing (reserved=18491KB, committed=18491KB)
- Tracing (reserved=18970KB, committed=18970KB)
-------------
PR Comment: https://git.openjdk.org/jdk21u-dev/pull/1095#issuecomment-2455300319
More information about the jdk-updates-dev
mailing list