Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8177086

java.lang.reflect.AccessibleObject::canAccess should share access cache with internal method ::checkAccess

    XMLWordPrintable

Details

    • Enhancement
    • Resolution: Fixed
    • P4
    • 9-repo-jigsaw
    • None
    • core-libs
    • None

    Description

      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 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 {
         ...
      }

      Attachments

        Issue Links

          Activity

            People

              plevart Peter Levart
              plevart Peter Levart
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: