8214583: AccessController.getContext may return wrong value after JDK-8212605

Reviewed-by: mchung, redestad
This commit is contained in:
Dean Long 2018-12-18 16:36:26 -08:00
parent ad47b4c4cc
commit 57dc039131
6 changed files with 167 additions and 4 deletions

View file

@ -709,6 +709,13 @@ public final class AccessController {
return context;
}
/**
* 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.
*
@ -734,6 +741,11 @@ public final class AccessController {
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 @@ public final class AccessController {
// retrieved by getStackAccessControlContext().
Reference.reachabilityFence(context);
Reference.reachabilityFence(caller);
Reference.reachabilityFence(action);
return result;
}
@ -761,6 +772,11 @@ public final class AccessController {
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 @@ public final class AccessController {
// retrieved by getStackAccessControlContext().
Reference.reachabilityFence(context);
Reference.reachabilityFence(caller);
Reference.reachabilityFence(action);
return result;
}