Hi,

Module system implementation refresh 2017/2 (JDK-8173393) introduced new API method AccessibleObject::canAccess which can be used to test if the caller has access to the reflected member (with possible target object argument for instance members). The implementation of this method, after some parameter validation checks, delegates directly to jdk.internal.reflect.Reflection::verifyMemberAccess. This is sub-optimal. Co-located internal method AccessibleObject::checkAccess also delegates to Reflection::verifyMemberAccess, but it also uses a one-element cache of access-check decision, which greatly speeds up repeated calls by the same caller to the same reflected member. The cache could be shared between those two methods which would improve performance of code idioms like this:

if (member.canAccess(target) || member.trySetAccessible()) {
  member.invoke(....);
    ...
} else {
   ...
}

Here's a proposed patch to improve this new method's performance:

http://cr.openjdk.java.net/~plevart/jdk9-dev/8177086_AccessibleObject.canAccess.cache/webrev.01/

The corresponding jira issue is:

https://bugs.openjdk.java.net/browse/JDK-8177086


I don't know whether this should go to jdk9 or perhaps later to jdk9u, since this is new API that only came into existence 1 month ago and this patch improves its implementation. Should It perhaps go to jake repo 1st? Presented patch is made against current jdk9/jdk repo.


Regards, Peter

Reply via email to