From 979f72351da7fb7562aabc4fc837aa116391ddfb Mon Sep 17 00:00:00 2001 From: Daniel Hu Date: Tue, 3 Sep 2024 21:41:29 +0000 Subject: [PATCH] Backport f6be922952642f40dcf0d27b7896c9a6acdd6378 --- .../jfr/event/oldobject/TestListenerLeak.java | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/jdk/test/jdk/jfr/event/oldobject/TestListenerLeak.java b/jdk/test/jdk/jfr/event/oldobject/TestListenerLeak.java index 7500ecd3067..11ef66e3b7d 100644 --- a/jdk/test/jdk/jfr/event/oldobject/TestListenerLeak.java +++ b/jdk/test/jdk/jfr/event/oldobject/TestListenerLeak.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2018, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2018, 2023, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it @@ -74,15 +74,17 @@ public void onListen() { public static void main(String[] args) throws Exception { WhiteBox.setWriteAllObjectSamples(true); - - try (Recording r = new Recording()) { - r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity"); - r.start(); - listenerLeak(); - r.stop(); - List events = Events.fromRecording(r); - if (OldObjects.countMatchingEvents(events, Stuff[].class, null, null, -1, "listenerLeak") == 0) { - throw new Exception("Could not find leak with " + Stuff[].class); + while (true) { + try (Recording r = new Recording()) { + r.enable(EventNames.OldObjectSample).withStackTrace().with("cutoff", "infinity"); + r.start(); + listenerLeak(); + r.stop(); + List events = Events.fromRecording(r); + if (OldObjects.countMatchingEvents(events, Stuff[].class, null, null, -1, "listenerLeak") != 0) { + return; // Success + } + System.out.println("Could not find leak with " + Stuff[].class + ". Retrying."); } } }