src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File jdk Cdiff src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java

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

Print this page
rev 11011 : 8057020: LambdaForm caches should support eviction
Reviewed-by: psandoz, ?

*** 24,36 **** */ package java.lang.invoke; import sun.invoke.util.Wrapper; import static java.lang.invoke.MethodHandleStatics.*; - import static java.lang.invoke.MethodHandleNatives.Constants.*; - import static java.lang.invoke.MethodHandles.Lookup.IMPL_LOOKUP; /** * Shared information for a group of method types, which differ * only by reference types, and therefore share a common erasure * and wrapping. --- 24,35 ---- */ package java.lang.invoke; import sun.invoke.util.Wrapper; + import java.lang.ref.SoftReference; import static java.lang.invoke.MethodHandleStatics.*; /** * Shared information for a group of method types, which differ * only by reference types, and therefore share a common erasure * and wrapping.
*** 49,68 **** final long primCounts; // packed prim & double counts final MethodType erasedType; // the canonical erasure final MethodType basicType; // the canonical erasure, with primitives simplified // Cached adapter information: ! @Stable final MethodHandle[] methodHandles; // Indexes into methodHandles: static final int MH_BASIC_INV = 0, // cached instance of MH.invokeBasic MH_NF_INV = 1, // cached helper for LF.NamedFunction MH_UNINIT_CS = 2, // uninitialized call site MH_LIMIT = 3; // Cached lambda form information, for basic types only: ! final @Stable LambdaForm[] lambdaForms; // Indexes into lambdaForms: static final int LF_INVVIRTUAL = 0, // DMH invokeVirtual LF_INVSTATIC = 1, LF_INVSPECIAL = 2, --- 48,67 ---- final long primCounts; // packed prim & double counts final MethodType erasedType; // the canonical erasure final MethodType basicType; // the canonical erasure, with primitives simplified // Cached adapter information: ! @Stable final SoftReference<MethodHandle>[] methodHandles; // Indexes into methodHandles: static final int MH_BASIC_INV = 0, // cached instance of MH.invokeBasic MH_NF_INV = 1, // cached helper for LF.NamedFunction MH_UNINIT_CS = 2, // uninitialized call site MH_LIMIT = 3; // Cached lambda form information, for basic types only: ! final @Stable SoftReference<LambdaForm>[] lambdaForms; // Indexes into lambdaForms: static final int LF_INVVIRTUAL = 0, // DMH invokeVirtual LF_INVSTATIC = 1, LF_INVSPECIAL = 2,
*** 106,142 **** return true; } public MethodHandle cachedMethodHandle(int which) { assert(assertIsBasicType()); ! return methodHandles[which]; } synchronized public MethodHandle setCachedMethodHandle(int which, MethodHandle mh) { // Simulate a CAS, to avoid racy duplication of results. ! MethodHandle prev = methodHandles[which]; ! if (prev != null) return prev; ! return methodHandles[which] = mh; } public LambdaForm cachedLambdaForm(int which) { assert(assertIsBasicType()); ! return lambdaForms[which]; } synchronized public LambdaForm setCachedLambdaForm(int which, LambdaForm form) { // Simulate a CAS, to avoid racy duplication of results. ! LambdaForm prev = lambdaForms[which]; ! if (prev != null) return prev; ! return lambdaForms[which] = form; } /** * Build an MTF for a given type, which must have all references erased to Object. * This MTF will stand for that type and all un-erased variations. * Eagerly compute some basic properties of the type, common to all variations. */ protected MethodTypeForm(MethodType erasedType) { this.erasedType = erasedType; Class<?>[] ptypes = erasedType.ptypes(); int ptypeCount = ptypes.length; --- 105,156 ---- return true; } public MethodHandle cachedMethodHandle(int which) { assert(assertIsBasicType()); ! SoftReference<MethodHandle> entry = methodHandles[which]; ! return (entry != null) ? entry.get() : null; } synchronized public MethodHandle setCachedMethodHandle(int which, MethodHandle mh) { // Simulate a CAS, to avoid racy duplication of results. ! SoftReference<MethodHandle> entry = methodHandles[which]; ! if (entry != null) { ! MethodHandle prev = entry.get(); ! if (prev != null) { ! return prev; ! } ! } ! methodHandles[which] = new SoftReference<>(mh); ! return mh; } public LambdaForm cachedLambdaForm(int which) { assert(assertIsBasicType()); ! SoftReference<LambdaForm> entry = lambdaForms[which]; ! return (entry != null) ? entry.get() : null; } synchronized public LambdaForm setCachedLambdaForm(int which, LambdaForm form) { // Simulate a CAS, to avoid racy duplication of results. ! SoftReference<LambdaForm> entry = lambdaForms[which]; ! if (entry != null) { ! LambdaForm prev = entry.get(); ! if (prev != null) { ! return prev; ! } ! } ! lambdaForms[which] = new SoftReference<>(form); ! return form; } /** * Build an MTF for a given type, which must have all references erased to Object. * This MTF will stand for that type and all un-erased variations. * Eagerly compute some basic properties of the type, common to all variations. */ + @SuppressWarnings({"rawtypes", "unchecked"}) protected MethodTypeForm(MethodType erasedType) { this.erasedType = erasedType; Class<?>[] ptypes = erasedType.ptypes(); int ptypeCount = ptypes.length;
*** 232,243 **** if (pslotCount >= 256) throw newIllegalArgumentException("too many arguments"); // Initialize caches, but only for basic types assert(basicType == erasedType); ! this.lambdaForms = new LambdaForm[LF_LIMIT]; ! this.methodHandles = new MethodHandle[MH_LIMIT]; } private static long pack(int a, int b, int c, int d) { assert(((a|b|c|d) & ~0xFFFF) == 0); long hw = ((a << 16) | b), lw = ((c << 16) | d); --- 246,257 ---- if (pslotCount >= 256) throw newIllegalArgumentException("too many arguments"); // Initialize caches, but only for basic types assert(basicType == erasedType); ! this.lambdaForms = new SoftReference[LF_LIMIT]; ! this.methodHandles = new SoftReference[MH_LIMIT]; } private static long pack(int a, int b, int c, int d) { assert(((a|b|c|d) & ~0xFFFF) == 0); long hw = ((a << 16) | b), lw = ((c << 16) | d);
*** 407,413 **** @Override public String toString() { return "Form"+erasedType; } - } --- 421,426 ----
src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File