8217345: [TESTBUG] JFR TestShutdownEvent fails due to improper use of Unsafe

Added proper use of Unsafe

Reviewed-by: egahlin
This commit is contained in:
Mikhailo Seledtsov 2019-01-24 11:14:51 -08:00
parent 78651809c5
commit b499798c25
2 changed files with 6 additions and 15 deletions

View File

@ -876,4 +876,3 @@ javax/rmi/ssl/SSLSocketParametersTest.sh 8162906 generic-
# jdk_jfr
jdk/jfr/event/io/TestInstrumentation.java 8202142 generic-all
jdk/jfr/event/runtime/TestShutdownEvent.java 8217345 generic-all

View File

@ -31,6 +31,7 @@ import java.util.Comparator;
import java.util.List;
import java.util.stream.Collectors;
import jdk.internal.misc.Unsafe;
import jdk.jfr.consumer.RecordedEvent;
import jdk.jfr.consumer.RecordedFrame;
import jdk.jfr.consumer.RecordedStackTrace;
@ -41,7 +42,7 @@ import jdk.test.lib.process.OutputAnalyzer;
import jdk.test.lib.process.ProcessTools;
import jdk.test.lib.jfr.EventNames;
import jdk.test.lib.jfr.Events;
import sun.misc.Unsafe;
/**
* @test
@ -50,7 +51,8 @@ import sun.misc.Unsafe;
* @requires vm.hasJFR
* @library /test/lib
* @modules jdk.jfr
* @run main jdk.jfr.event.runtime.TestShutdownEvent
* java.base/jdk.internal.misc
* @run main/othervm jdk.jfr.event.runtime.TestShutdownEvent
*/
public class TestShutdownEvent {
private static ShutdownEventSubTest subTests[] = {
@ -77,6 +79,7 @@ public class TestShutdownEvent {
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(true,
"-Xlog:jfr=debug",
"-XX:-CreateCoredumpOnCrash",
"--add-exports=java.base/jdk.internal.misc=ALL-UNNAMED",
"-XX:StartFlightRecording=filename=./dumped.jfr,dumponexit=true,settings=default",
"jdk.jfr.event.runtime.TestShutdownEvent$TestMain",
String.valueOf(subTestIndex));
@ -117,17 +120,6 @@ public class TestShutdownEvent {
void verifyEvents(RecordedEvent event);
}
public static Unsafe getUnsafe() {
try {
Field f = Unsafe.class.getDeclaredField("theUnsafe");
f.setAccessible(true);
return (Unsafe)f.get(null);
} catch (Exception e) {
Asserts.fail("Could not access Unsafe");
}
return null;
}
// Basic stack trace validation, checking that the runTest method is part of the stack
static void validateStackTrace(RecordedStackTrace stackTrace) {
List<RecordedFrame> frames = stackTrace.getFrames();
@ -169,7 +161,7 @@ public class TestShutdownEvent {
@Override
public void runTest() {
System.out.println("Attempting to crash");
getUnsafe().putInt(0L, 0);
Unsafe.getUnsafe().putInt(0L, 0);
}
@Override