src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java
Index Unified diffs Context diffs Sdiffs Patch New Old Previous File Next File
*** old/src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java	Tue Dec  2 20:15:05 2014
--- new/src/java.base/share/classes/java/lang/invoke/MethodTypeForm.java	Tue Dec  2 20:15:05 2014

*** 24,36 **** --- 24,35 ---- */ package java.lang.invoke; import sun.invoke.util.Wrapper; + import java.lang.ref.SoftReference; 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.
*** 49,68 **** --- 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 **** --- 105,156 ---- return true; } public MethodHandle cachedMethodHandle(int which) { assert(assertIsBasicType()); ! return methodHandles[which]; ! 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. ! MethodHandle prev = methodHandles[which]; ! if (prev != null) return prev; ! return methodHandles[which] = mh; ! 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()); ! return lambdaForms[which]; ! 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. ! LambdaForm prev = lambdaForms[which]; ! if (prev != null) return prev; ! return lambdaForms[which] = form; ! 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 **** --- 246,257 ---- 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]; ! 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 **** --- 421,426 ---- @Override public String toString() { return "Form"+erasedType; } }

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