< prev index next >

src/java.base/share/classes/java/lang/invoke/LambdaFormEditor.java

Print this page
*** 36,10 ***
--- 36,11 ---
  import static java.lang.invoke.LambdaForm.*;
  import static java.lang.invoke.LambdaForm.BasicType.*;
  import static java.lang.invoke.MethodHandleImpl.Intrinsic;
  import static java.lang.invoke.MethodHandleImpl.NF_loop;
  import static java.lang.invoke.MethodHandleImpl.makeIntrinsic;
+ import static java.lang.invoke.MethodHandleStatics.NO_SOFT_CACHE;
  
  /** Transforms on LFs.
   *  A lambda-form editor can derive new LFs from its base LF.
   *  The editor can cache derived LFs, which simplifies the reuse of their underlying bytecodes.
   *  To support this caching, a LF has an optional pointer to its editor.

*** 87,16 ***
       * Sequences that are simple (short enough and with small enough values) pack into a 64-bit long.
       *
       * Tightly coupled with the TransformKey class, which is used to lookup existing
       * Transforms.
       */
!     private static final class Transform extends SoftReference<LambdaForm> {
          final long packedBytes;
          final byte[] fullBytes;
  
          private Transform(long packedBytes, byte[] fullBytes, LambdaForm result) {
!             super(result);
              this.packedBytes = packedBytes;
              this.fullBytes = fullBytes;
          }
  
          @Override
--- 88,21 ---
       * Sequences that are simple (short enough and with small enough values) pack into a 64-bit long.
       *
       * Tightly coupled with the TransformKey class, which is used to lookup existing
       * Transforms.
       */
!     private static final class Transform {
+         final Object cache;
          final long packedBytes;
          final byte[] fullBytes;
  
          private Transform(long packedBytes, byte[] fullBytes, LambdaForm result) {
!             if (NO_SOFT_CACHE) {
+                 cache = result;
+             } else {
+                 cache = new SoftReference<LambdaForm>(result);
+             }
              this.packedBytes = packedBytes;
              this.fullBytes = fullBytes;
          }
  
          @Override

*** 133,10 ***
--- 139,19 ---
                  buf.append(" result=");
                  buf.append(result);
              }
              return buf.toString();
          }
+ 
+         @SuppressWarnings({"rawtypes", "unchecked"})
+         public LambdaForm get() {
+             if (cache instanceof LambdaForm) {
+                 return (LambdaForm)cache;
+             } else {
+                 return ((SoftReference<LambdaForm>)cache).get();
+             }
+         }
      }
  
      /**
       * Used as a lookup key to find existing Transforms
       */
< prev index next >