diff --git a/test/jdk/jdk/jfr/event/compiler/TestJitRestart.java b/test/jdk/jdk/jfr/event/compiler/TestJitRestart.java index da517a5eaf1..711eb6317a6 100644 --- a/test/jdk/jdk/jfr/event/compiler/TestJitRestart.java +++ b/test/jdk/jdk/jfr/event/compiler/TestJitRestart.java @@ -24,6 +24,7 @@ package jdk.jfr.event.compiler; import java.util.List; +import java.util.Comparator; import jdk.jfr.Recording; import jdk.jfr.consumer.RecordedEvent; @@ -50,15 +51,15 @@ public class TestJitRestart { public static void main(String[] args) throws Exception { - boolean foundJitRestart = false; + boolean checkJitRestartCompilation = false; for (BlobType btype : BlobType.getAvailable()) { boolean jr = testWithBlobType(btype, calculateAvailableSize(btype)); if (jr) { - System.out.println("JIT restart event found for BlobType " + btype); - foundJitRestart = true; + System.out.println("JIT restart event / Compilation event check for BlobType " + btype + " was successful"); + checkJitRestartCompilation = true; } } - Asserts.assertTrue(foundJitRestart, "No JIT restart event found"); + Asserts.assertTrue(checkJitRestartCompilation, "No JIT restart event found and unexpected compilation seen"); } private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); @@ -66,6 +67,7 @@ public static void main(String[] args) throws Exception { private static boolean testWithBlobType(BlobType btype, long availableSize) throws Exception { Recording r = new Recording(); r.enable(EventNames.CodeCacheFull); + r.enable(EventNames.Compilation); r.enable(EventNames.JitRestart); r.start(); long addr = WHITE_BOX.allocateCodeBlob(availableSize, btype.id); @@ -74,18 +76,34 @@ private static boolean testWithBlobType(BlobType btype, long availableSize) thro r.stop(); List events = Events.fromRecording(r); + System.out.println("---------------------------------------------"); System.out.println("# events:" + events.size()); Events.hasEvents(events); + events.sort(Comparator.comparing(RecordedEvent::getStartTime)); + boolean compilationCanHappen = true; for (RecordedEvent evt: events) { System.out.println(evt); + if (evt.getEventType().getName().equals("jdk.CodeCacheFull")) { + System.out.println("--> jdk.CodeCacheFull found"); + compilationCanHappen = false; + } + if (evt.getEventType().getName().equals("jdk.Compilation") && !compilationCanHappen) { + return false; + } if (evt.getEventType().getName().equals("jdk.JitRestart")) { + System.out.println("--> jdk.JitRestart found"); Events.assertField(evt, "codeCacheMaxCapacity").notEqual(0L); Events.assertField(evt, "freedMemory").notEqual(0L); + System.out.println("JIT restart event found for BlobType " + btype); return true; } } - return false; + System.out.println("---------------------------------------------"); + + // in some seldom cases we do not see the JitRestart event; but then + // do not fail (as long as no compilation happened before) + return true; } // Compute the available size for this BlobType by taking into account