equal
deleted
inserted
replaced
145 if (smgr != null) smgr.checkPermission(ACCESS_PERMISSION); |
145 if (smgr != null) smgr.checkPermission(ACCESS_PERMISSION); |
146 Lookup lookup = Lookup.IMPL_LOOKUP; // use maximally privileged lookup |
146 Lookup lookup = Lookup.IMPL_LOOKUP; // use maximally privileged lookup |
147 return lookup.revealDirect(target).reflectAs(expected, lookup); |
147 return lookup.revealDirect(target).reflectAs(expected, lookup); |
148 } |
148 } |
149 // Copied from AccessibleObject, as used by Method.setAccessible, etc.: |
149 // Copied from AccessibleObject, as used by Method.setAccessible, etc.: |
150 static final private java.security.Permission ACCESS_PERMISSION = |
150 private static final java.security.Permission ACCESS_PERMISSION = |
151 new ReflectPermission("suppressAccessChecks"); |
151 new ReflectPermission("suppressAccessChecks"); |
152 |
152 |
153 /** |
153 /** |
154 * A <em>lookup object</em> is a factory for creating method handles, |
154 * A <em>lookup object</em> is a factory for creating method handles, |
155 * when the creation requires access checking. |
155 * when the creation requires access checking. |
1882 * @throws IllegalArgumentException if {@code leadingArgCount} is not in |
1882 * @throws IllegalArgumentException if {@code leadingArgCount} is not in |
1883 * the range from 0 to {@code type.parameterCount()} inclusive, |
1883 * the range from 0 to {@code type.parameterCount()} inclusive, |
1884 * or if the resulting method handle's type would have |
1884 * or if the resulting method handle's type would have |
1885 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1885 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1886 */ |
1886 */ |
1887 static public |
1887 public static |
1888 MethodHandle spreadInvoker(MethodType type, int leadingArgCount) { |
1888 MethodHandle spreadInvoker(MethodType type, int leadingArgCount) { |
1889 if (leadingArgCount < 0 || leadingArgCount > type.parameterCount()) |
1889 if (leadingArgCount < 0 || leadingArgCount > type.parameterCount()) |
1890 throw newIllegalArgumentException("bad argument count", leadingArgCount); |
1890 throw newIllegalArgumentException("bad argument count", leadingArgCount); |
1891 type = type.asSpreaderType(Object[].class, type.parameterCount() - leadingArgCount); |
1891 type = type.asSpreaderType(Object[].class, type.parameterCount() - leadingArgCount); |
1892 return type.invokers().spreadInvoker(leadingArgCount); |
1892 return type.invokers().spreadInvoker(leadingArgCount); |
1925 * @param type the desired target type |
1925 * @param type the desired target type |
1926 * @return a method handle suitable for invoking any method handle of the given type |
1926 * @return a method handle suitable for invoking any method handle of the given type |
1927 * @throws IllegalArgumentException if the resulting method handle's type would have |
1927 * @throws IllegalArgumentException if the resulting method handle's type would have |
1928 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1928 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1929 */ |
1929 */ |
1930 static public |
1930 public static |
1931 MethodHandle exactInvoker(MethodType type) { |
1931 MethodHandle exactInvoker(MethodType type) { |
1932 return type.invokers().exactInvoker(); |
1932 return type.invokers().exactInvoker(); |
1933 } |
1933 } |
1934 |
1934 |
1935 /** |
1935 /** |
1964 * @param type the desired target type |
1964 * @param type the desired target type |
1965 * @return a method handle suitable for invoking any method handle convertible to the given type |
1965 * @return a method handle suitable for invoking any method handle convertible to the given type |
1966 * @throws IllegalArgumentException if the resulting method handle's type would have |
1966 * @throws IllegalArgumentException if the resulting method handle's type would have |
1967 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1967 * <a href="MethodHandle.html#maxarity">too many parameters</a> |
1968 */ |
1968 */ |
1969 static public |
1969 public static |
1970 MethodHandle invoker(MethodType type) { |
1970 MethodHandle invoker(MethodType type) { |
1971 return type.invokers().genericInvoker(); |
1971 return type.invokers().genericInvoker(); |
1972 } |
1972 } |
1973 |
1973 |
1974 static /*non-public*/ |
1974 static /*non-public*/ |
2320 MethodType mtype = MethodType.methodType(rtype); |
2320 MethodType mtype = MethodType.methodType(rtype); |
2321 LambdaForm lform = LambdaForm.zeroForm(BasicType.basicType(rtype)); |
2321 LambdaForm lform = LambdaForm.zeroForm(BasicType.basicType(rtype)); |
2322 return MethodHandleImpl.makeIntrinsic(mtype, lform, Intrinsic.ZERO); |
2322 return MethodHandleImpl.makeIntrinsic(mtype, lform, Intrinsic.ZERO); |
2323 } |
2323 } |
2324 |
2324 |
2325 synchronized private static MethodHandle setCachedMethodHandle(MethodHandle[] cache, int pos, MethodHandle value) { |
2325 private static synchronized MethodHandle setCachedMethodHandle(MethodHandle[] cache, int pos, MethodHandle value) { |
2326 // Simulate a CAS, to avoid racy duplication of results. |
2326 // Simulate a CAS, to avoid racy duplication of results. |
2327 MethodHandle prev = cache[pos]; |
2327 MethodHandle prev = cache[pos]; |
2328 if (prev != null) return prev; |
2328 if (prev != null) return prev; |
2329 return cache[pos] = value; |
2329 return cache[pos] = value; |
2330 } |
2330 } |