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

Replacement API for Unsafe::ensureClassInitialized

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 15
    • Component/s: core-libs
    • Labels:
      None

      Description

      A class may also be initialized as a result of execution of other bytecodes such as getstatic, new, putstatic, invokestatic etc as specified in JVMS 5.5.

      `Class::forName` and `Unsafe::ensureClassInitialized` are existing workaround to initialize a Class. It's cumbersome to use Class::forName to initialize a class and many JDK classes use `Unsafe::ensureClassInitialized` rather than Class::forName to initialize a class.

      One typical use of `Unsafe::ensureClassInitialized` to force class initialization is to enable JIT inlining as well as the method handle can avoid the class initialization barrier.

      The other use of `Unsafe::ensureClassInitialized` to force class initialization is to ensure that private static members are initialized and published to other classes (outside its nest) to access, e.g. shared secrets.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mchung Mandy Chung
              Reporter:
              mchung Mandy Chung
              Votes:
              0 Vote for this issue
              Watchers:
              5 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: