8225209: jdk/jfr/event/compiler/TestCodeSweeper.java fails

Reviewed-by: mgronlun
This commit is contained in:
Erik Gahlin 2024-08-08 10:57:43 +00:00
parent ddbd7a78f1
commit 4b740d87ee
2 changed files with 39 additions and 18 deletions
test/jdk

@ -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

@ -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<RecordedEvent> 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<RecordedEvent> 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 {