8214287: SpecJbb2005StressModule got uncaught exception
authormgronlun
Tue, 27 Nov 2018 18:14:27 +0100
changeset 52698 ca6b58b8ffc5
parent 52697 605878cd4009
child 52699 44fe5fab538a
8214287: SpecJbb2005StressModule got uncaught exception Reviewed-by: egahlin, jwilhelm
src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java
src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java
src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java	Tue Nov 27 11:07:44 2018 -0500
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/EventInstrumentation.java	Tue Nov 27 18:14:27 2018 +0100
@@ -435,6 +435,10 @@
         // MyEvent#shouldCommit()
         updateMethod(METHOD_EVENT_SHOULD_COMMIT, methodVisitor -> {
             Label fail = new Label();
+            if (guardHandlerReference) {
+                getEventHandler(methodVisitor);
+                methodVisitor.visitJumpInsn(Opcodes.IFNULL, fail);
+            }
             // if (!eventHandler.shouldCommit(duration) goto fail;
             getEventHandler(methodVisitor);
             methodVisitor.visitVarInsn(Opcodes.ALOAD, 0);
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java	Tue Nov 27 11:07:44 2018 -0500
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/SecuritySupport.java	Tue Nov 27 18:14:27 2018 +0100
@@ -79,6 +79,14 @@
     static final SafePath USER_HOME = getPathInProperty("user.home", null);
     static final SafePath JAVA_IO_TMPDIR = getPathInProperty("java.io.tmpdir", null);
 
+    static {
+        // ensure module java.base can read module jdk.jfr as early as possible
+        addReadEdge(Object.class);
+        addHandlerExport(Object.class);
+        addEventsExport(Object.class);
+        addInstrumentExport(Object.class);
+    }
+
     final static class SecureRecorderListener implements FlightRecorderListener {
 
         private final AccessControlContext context;
@@ -262,6 +270,18 @@
         Modules.addExports(JFR_MODULE, Utils.HANDLERS_PACKAGE_NAME, clazz.getModule());
     }
 
+    static void addEventsExport(Class<?> clazz) {
+        Modules.addExports(JFR_MODULE, Utils.EVENTS_PACKAGE_NAME, clazz.getModule());
+    }
+
+    static void addInstrumentExport(Class<?> clazz) {
+        Modules.addExports(JFR_MODULE, Utils.INSTRUMENT_PACKAGE_NAME, clazz.getModule());
+    }
+
+    static void addReadEdge(Class<?> clazz) {
+        Modules.addReads(clazz.getModule(), JFR_MODULE);
+    }
+
     public static void registerEvent(Class<? extends jdk.internal.event.Event> eventClass) {
         doPrivileged(() ->  MetadataRepository.getInstance().register(eventClass), new FlightRecorderPermission(Utils.REGISTER_EVENT));
     }
--- a/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java	Tue Nov 27 11:07:44 2018 -0500
+++ b/src/jdk.jfr/share/classes/jdk/jfr/internal/instrument/JDKEvents.java	Tue Nov 27 18:14:27 2018 +0100
@@ -28,7 +28,6 @@
 import java.util.ArrayList;
 import java.util.List;
 
-import jdk.internal.module.Modules;
 import jdk.jfr.Event;
 import jdk.jfr.FlightRecorder;
 import jdk.jfr.events.ActiveRecordingEvent;
@@ -99,12 +98,6 @@
     public synchronized static void initialize() {
         try {
             if (initializationTriggered == false) {
-                Module jdkJfrModule = Event.class.getModule();
-                Module javaBaseModule = Object.class.getModule();
-                Modules.addReads(javaBaseModule, jdkJfrModule);
-                Modules.addExports(jdkJfrModule, Utils.EVENTS_PACKAGE_NAME, javaBaseModule);
-                Modules.addExports(jdkJfrModule, Utils.INSTRUMENT_PACKAGE_NAME, javaBaseModule);
-                Modules.addExports(jdkJfrModule, Utils.HANDLERS_PACKAGE_NAME, javaBaseModule);
                 for (Class<?> mirrorEventClass : mirrorEventClasses) {
                     SecuritySupport.registerMirror(((Class<? extends Event>)mirrorEventClass));
                 }