From 4b740d87ee50ba49305add4aae6490bebb6963ba Mon Sep 17 00:00:00 2001 From: Erik Gahlin Date: Thu, 8 Aug 2024 10:57:43 +0000 Subject: [PATCH] 8225209: jdk/jfr/event/compiler/TestCodeSweeper.java fails Reviewed-by: mgronlun --- test/jdk/ProblemList.txt | 1 - .../jfr/event/compiler/TestCodeSweeper.java | 56 +++++++++++++------ 2 files changed, 39 insertions(+), 18 deletions(-) diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 3b8421eb9cc..8aedbc77931 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -744,7 +744,6 @@ jdk/incubator/vector/LoadJsvmlTest.java 8305390 windows- # jdk_jfr -jdk/jfr/event/compiler/TestCodeSweeper.java 8225209 generic-all jdk/jfr/event/runtime/TestResidentSetSizeEvent.java 8309846 aix-ppc64 jdk/jfr/startupargs/TestStartName.java 8214685 windows-x64 jdk/jfr/startupargs/TestStartDuration.java 8214685 windows-x64 diff --git a/test/jdk/jdk/jfr/event/compiler/TestCodeSweeper.java b/test/jdk/jdk/jfr/event/compiler/TestCodeSweeper.java index cb2a3f41b55..df95af5b9be 100644 --- a/test/jdk/jdk/jfr/event/compiler/TestCodeSweeper.java +++ b/test/jdk/jdk/jfr/event/compiler/TestCodeSweeper.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2022, Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2024, 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 @@ -27,9 +27,11 @@ import java.lang.management.MemoryPoolMXBean; import java.lang.reflect.Method; import java.time.Instant; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import jdk.jfr.Recording; +import jdk.jfr.Event; +import jdk.jfr.consumer.RecordingStream; import jdk.jfr.consumer.RecordedEvent; import jdk.test.lib.Asserts; import jdk.test.lib.jfr.EventNames; @@ -39,7 +41,7 @@ import jdk.test.whitebox.code.BlobType; import jdk.test.whitebox.code.CodeBlob; /** - * Test for events: vm/code_cache/full vm/compiler/failure + * Test for events: jdk.CodeCacheFull jdk.CompilationFailure * * We verify that we should get at least one of each of the events listed above. * @@ -58,13 +60,15 @@ import jdk.test.whitebox.code.CodeBlob; */ public class TestCodeSweeper { + static class ProvocationEvent extends Event { + } private static final WhiteBox WHITE_BOX = WhiteBox.getWhiteBox(); private static final int COMP_LEVEL_SIMPLE = 1; private static final int COMP_LEVEL_FULL_OPTIMIZATION = 4; private static final int SIZE = 1; private static final String METHOD_NAME = "verifyFullEvent"; - private static final String pathFull = EventNames.CodeCacheFull; - private static final String pathFailure = EventNames.CompilationFailure; + private static final String EVENT_CODE_CACHE_FULL = EventNames.CodeCacheFull; + private static final String EVENT_COMPILATION_FAILURE = EventNames.CompilationFailure; public static final long SEGMENT_SIZE = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheSegmentSize"); public static final long MIN_BLOCK_LENGTH = WhiteBox.getWhiteBox().getUintxVMFlag("CodeCacheMinBlockLength"); public static final long MIN_ALLOCATION = SEGMENT_SIZE * MIN_BLOCK_LENGTH; @@ -77,26 +81,41 @@ public class TestCodeSweeper { System.out.println("This test will warn that the code cache is full."); System.out.println("That is expected and is the purpose of the test."); System.out.println("************************************************"); - - Recording r = new Recording(); - r.enable(pathFull); - r.enable(pathFailure); - r.start(); - provokeEvents(); - r.stop(); + List events = Collections.synchronizedList(new ArrayList<>()); + try (RecordingStream rs = new RecordingStream()) { + rs.setReuse(false); + rs.enable(EVENT_CODE_CACHE_FULL); + rs.enable(EVENT_COMPILATION_FAILURE); + rs.onEvent(EVENT_CODE_CACHE_FULL, events::add); + rs.onEvent(EVENT_COMPILATION_FAILURE, events::add); + rs.onEvent(ProvocationEvent.class.getName(), e -> { + if (!events.isEmpty()) { + rs.close(); + return; + } + // Retry if CodeCacheFull or CompilationFailure events weren't provoked + try { + provokeEvents(); + } catch (Exception ex) { + ex.printStackTrace(); + rs.close(); + } + }); + rs.startAsync(); + provokeEvents(); + rs.awaitTermination(); + } int countEventFull = 0; int countEventFailure = 0; - - List events = Events.fromRecording(r); Events.hasEvents(events); - for (RecordedEvent event : events) { + for (RecordedEvent event : new ArrayList<>(events)) { switch (event.getEventType().getName()) { - case pathFull: + case EVENT_CODE_CACHE_FULL: countEventFull++; verifyFullEvent(event); break; - case pathFailure: + case EVENT_COMPILATION_FAILURE: countEventFailure++; verifyFailureEvent(event); break; @@ -115,6 +134,8 @@ public class TestCodeSweeper { } private static void provokeEvents() throws NoSuchMethodException, InterruptedException { + System.out.println("provokeEvents()"); + ProvocationEvent provocationEvent = new ProvocationEvent(); // Prepare for later, since we don't want to trigger any compilation // setting this up. Method method = TestCodeSweeper.class.getDeclaredMethod(METHOD_NAME, new Class[] { RecordedEvent.class }); @@ -159,6 +180,7 @@ public class TestCodeSweeper { for (Long blob : blobs) { WHITE_BOX.freeCodeBlob(blob); } + provocationEvent.commit(); } private static void verifyFullEvent(RecordedEvent event) throws Throwable {