changeset 54558:8f785877c008

8217345: [TESTBUG] JFR TestShutdownEvent fails due to improper use of Unsafe Summary: Added proper use of Unsafe Reviewed-by: egahlin
author mseledtsov
date Thu, 24 Jan 2019 11:14:51 -0800
parents 6c636747ec55
children 0716631b907f
files test/jdk/ProblemList.txt test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java
diffstat 2 files changed, 6 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/test/jdk/ProblemList.txt	Thu Jan 24 11:10:13 2019 -0800
+++ b/test/jdk/ProblemList.txt	Thu Jan 24 11:14:51 2019 -0800
@@ -876,4 +876,3 @@
 # jdk_jfr
 
 jdk/jfr/event/io/TestInstrumentation.java                       8202142    generic-all
-jdk/jfr/event/runtime/TestShutdownEvent.java                    8217345    generic-all
--- a/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java	Thu Jan 24 11:10:13 2019 -0800
+++ b/test/jdk/jdk/jfr/event/runtime/TestShutdownEvent.java	Thu Jan 24 11:14:51 2019 -0800
@@ -31,6 +31,7 @@
 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.ProcessTools;
 import jdk.test.lib.jfr.EventNames;
 import jdk.test.lib.jfr.Events;
-import sun.misc.Unsafe;
+
 
 /**
  * @test
@@ -50,7 +51,8 @@
  * @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 @@
         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 @@
         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 @@
         @Override
         public void runTest() {
             System.out.println("Attempting to crash");
-            getUnsafe().putInt(0L, 0);
+            Unsafe.getUnsafe().putInt(0L, 0);
         }
 
         @Override