src/java.base/share/classes/java/security/AccessController.java
changeset 53068 7496df94b3b7
parent 52431 b0af758a092c
child 53435 ea254e9fc587
equal deleted inserted replaced
53067:8a61a04c456c 53068:7496df94b3b7
   708         }
   708         }
   709         return context;
   709         return context;
   710     }
   710     }
   711 
   711 
   712     /**
   712     /**
       
   713      * The value needs to be physically located in the frame, so that it
       
   714      * can be found by a stack walk.
       
   715      */
       
   716     @Hidden
       
   717     private static native void ensureMaterializedForStackWalk(Object o);
       
   718 
       
   719     /**
   713      * Sanity check that the caller context is indeed privileged.
   720      * Sanity check that the caller context is indeed privileged.
   714      *
   721      *
   715      * Used by executePrivileged to make sure the frame is properly
   722      * Used by executePrivileged to make sure the frame is properly
   716      * recognized by the VM.
   723      * recognized by the VM.
   717      */
   724      */
   732     private static <T> T
   739     private static <T> T
   733         executePrivileged(PrivilegedAction<T> action,
   740         executePrivileged(PrivilegedAction<T> action,
   734                           AccessControlContext context,
   741                           AccessControlContext context,
   735                           Class<?> caller)
   742                           Class<?> caller)
   736     {
   743     {
       
   744         // Ensure context has a physical value in the frame
       
   745         if (context != null) {
       
   746             ensureMaterializedForStackWalk(context);
       
   747         }
       
   748 
   737         assert isPrivileged(); // sanity check invariant
   749         assert isPrivileged(); // sanity check invariant
   738         T result = action.run();
   750         T result = action.run();
   739         assert isPrivileged(); // sanity check invariant
   751         assert isPrivileged(); // sanity check invariant
   740 
   752 
   741         // Keep these alive across the run() call so they can be
   753         // Keep these alive across the run() call so they can be
   742         // retrieved by getStackAccessControlContext().
   754         // retrieved by getStackAccessControlContext().
   743         Reference.reachabilityFence(context);
   755         Reference.reachabilityFence(context);
   744         Reference.reachabilityFence(caller);
   756         Reference.reachabilityFence(caller);
   745         Reference.reachabilityFence(action);
       
   746         return result;
   757         return result;
   747     }
   758     }
   748 
   759 
   749     /**
   760     /**
   750      * Execute the action as privileged.
   761      * Execute the action as privileged.
   759         executePrivileged(PrivilegedExceptionAction<T> action,
   770         executePrivileged(PrivilegedExceptionAction<T> action,
   760                           AccessControlContext context,
   771                           AccessControlContext context,
   761                           Class<?> caller)
   772                           Class<?> caller)
   762         throws Exception
   773         throws Exception
   763     {
   774     {
       
   775         // Ensure context has a physical value in the frame
       
   776         if (context != null) {
       
   777             ensureMaterializedForStackWalk(context);
       
   778         }
       
   779 
   764         assert isPrivileged(); // sanity check invariant
   780         assert isPrivileged(); // sanity check invariant
   765         T result = action.run();
   781         T result = action.run();
   766         assert isPrivileged(); // sanity check invariant
   782         assert isPrivileged(); // sanity check invariant
   767 
   783 
   768         // Keep these alive across the run() call so they can be
   784         // Keep these alive across the run() call so they can be
   769         // retrieved by getStackAccessControlContext().
   785         // retrieved by getStackAccessControlContext().
   770         Reference.reachabilityFence(context);
   786         Reference.reachabilityFence(context);
   771         Reference.reachabilityFence(caller);
   787         Reference.reachabilityFence(caller);
   772         Reference.reachabilityFence(action);
       
   773         return result;
   788         return result;
   774     }
   789     }
   775 
   790 
   776 
   791 
   777     /**
   792     /**