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

Consider Lookup::ensureInitialized(Class target, MethodHandle mh)

    XMLWordPrintable

Details

    • Enhancement
    • Status: Open
    • P4
    • Resolution: Unresolved
    • None
    • None
    • core-libs
    • None

    Description

      See https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066991.html and
      https://mail.openjdk.java.net/pipermail/core-libs-dev/2020-June/066994.html

      /**
       * To the given method handle, prepend an action, if necessary, to trigger
       * initialization of the given class the first time the method handle is called.
       * If it would be illegal to call ensureInitialized on the given class from this lookup,
       * immediately report an error. Otherwise, if the class is already fully initialized
       * return the method handle unchanged. Otherwise, return a new method handle
       * (of the same type) which incorporates the necessary initialization action,
       * as if by a call to ensureInitialized.
       */
      MethodHandle ensureInitialized(Class target, MethodHandle mh) {
        checkAccess(target);
        if (isFullyInitialized(target)) return mh;
        // we need to tack a “before action” onto mh to trigger inits:
       MethodHandle before = MH_ensureInit.bindTo(target);
       return collectArguments(mh, 0, before);
      }

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              mchung Mandy Chung
              Votes:
              1 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated: