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

MethodHandle.Lookup functionality to define a nestmate class

XMLWordPrintable

      The method Unsafe.defineAnonymousClass:

          public Class<?> defineAnonymousClass(Class<?> hostClass, byte[] data, Object[] cpPatches) {

      is used in a few areas to define anonymous classes such as LambdaMetaFactory (although only one use leverages the constant pool patch ing).

      The defining of a class (anonymous or otherwise) within the context of a hosted class can be referred to as defining a "nest mate" class.

      A subset of such functionality could be supported as a method on MethodHandle.Lookup:

        public Class<?> defineNestmate(boolean anonymous, byte[] bytes)

      Where the lookup class is the context for the nest, and where the method only functions if the lookup supports private access.

      Code in LambdaMethodFactory and StringConcatFactory could be updated to use the public method.

            mchung Mandy Chung
            psandoz Paul Sandoz
            Votes:
            0 Vote for this issue
            Watchers:
            14 Start watching this issue

              Created:
              Updated:
              Resolved: