src/java.base/share/classes/java/security/AccessController.java
changeset 53068 7496df94b3b7
parent 52431 b0af758a092c
child 53435 ea254e9fc587
--- a/src/java.base/share/classes/java/security/AccessController.java	Tue Dec 18 15:18:44 2018 -0800
+++ b/src/java.base/share/classes/java/security/AccessController.java	Tue Dec 18 16:36:26 2018 -0800
@@ -710,6 +710,13 @@
     }
 
     /**
+     * The value needs to be physically located in the frame, so that it
+     * can be found by a stack walk.
+     */
+    @Hidden
+    private static native void ensureMaterializedForStackWalk(Object o);
+
+    /**
      * Sanity check that the caller context is indeed privileged.
      *
      * Used by executePrivileged to make sure the frame is properly
@@ -734,6 +741,11 @@
                           AccessControlContext context,
                           Class<?> caller)
     {
+        // Ensure context has a physical value in the frame
+        if (context != null) {
+            ensureMaterializedForStackWalk(context);
+        }
+
         assert isPrivileged(); // sanity check invariant
         T result = action.run();
         assert isPrivileged(); // sanity check invariant
@@ -742,7 +754,6 @@
         // retrieved by getStackAccessControlContext().
         Reference.reachabilityFence(context);
         Reference.reachabilityFence(caller);
-        Reference.reachabilityFence(action);
         return result;
     }
 
@@ -761,6 +772,11 @@
                           Class<?> caller)
         throws Exception
     {
+        // Ensure context has a physical value in the frame
+        if (context != null) {
+            ensureMaterializedForStackWalk(context);
+        }
+
         assert isPrivileged(); // sanity check invariant
         T result = action.run();
         assert isPrivileged(); // sanity check invariant
@@ -769,7 +785,6 @@
         // retrieved by getStackAccessControlContext().
         Reference.reachabilityFence(context);
         Reference.reachabilityFence(caller);
-        Reference.reachabilityFence(action);
         return result;
     }