Mercurial > hg > release > icedtea7-forest-2.2 > jdk
changeset 5372:3dbf2807f49e
8009424: Adapt Nashorn to JSR-292 implementation change
Reviewed-by: jrose, twisti, jdn, mchung
author | andrew |
---|---|
date | Tue, 18 Jun 2013 08:07:03 -0500 |
parents | 3202c8ef7d0c |
children | c13072c37f69 |
files | src/share/classes/java/lang/invoke/MethodHandles.java |
diffstat | 1 files changed, 29 insertions(+), 46 deletions(-) [+] |
line wrap: on
line diff
--- a/src/share/classes/java/lang/invoke/MethodHandles.java Tue Jun 18 06:01:18 2013 -0500 +++ b/src/share/classes/java/lang/invoke/MethodHandles.java Tue Jun 18 08:07:03 2013 -0500 @@ -35,7 +35,7 @@ import sun.reflect.CallerSensitive; import sun.reflect.Reflection; import sun.reflect.misc.ReflectUtil; -import sun.security.util.SecurityConstants; + import static java.lang.invoke.MethodHandleStatics.*; import static java.lang.invoke.MethodHandleNatives.Constants.*; import sun.security.util.SecurityConstants; @@ -565,13 +565,11 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findStatic(Class<?> refc, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { MemberName method = resolveOrFail(refc, name, type, true); - Class<?> callerClass = Reflection.getCallerClass(); - checkSecurityManager(refc, method, callerClass); - return accessStatic(refc, method, findBoundCallerClass(method, callerClass)); + checkSecurityManager(refc, method); + return accessStatic(refc, method, findBoundCallerClass(method)); } private MethodHandle accessStatic(Class<?> refc, MemberName method, Class<?> callerClass) throws IllegalAccessException { @@ -624,12 +622,10 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findVirtual(Class<?> refc, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { MemberName method = resolveOrFail(refc, name, type, false); - Class<?> callerClass = Reflection.getCallerClass(); - checkSecurityManager(refc, method, callerClass); - return accessVirtual(refc, method, findBoundCallerClass(method, callerClass)); + checkSecurityManager(refc, method); + return accessVirtual(refc, method, findBoundCallerClass(method)); } private MethodHandle resolveVirtual(Class<?> refc, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { MemberName method = resolveOrFail(refc, name, type, false); @@ -668,11 +664,10 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findConstructor(Class<?> refc, MethodType type) throws NoSuchMethodException, IllegalAccessException { String name = "<init>"; MemberName ctor = resolveOrFail(refc, name, type, false, false, lookupClassOrNull()); - checkSecurityManager(refc, ctor, Reflection.getCallerClass()); + checkSecurityManager(refc, ctor); return accessConstructor(refc, ctor); } private MethodHandle accessConstructor(Class<?> refc, MemberName ctor) throws IllegalAccessException { @@ -738,14 +733,12 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findSpecial(Class<?> refc, String name, MethodType type, Class<?> specialCaller) throws NoSuchMethodException, IllegalAccessException { checkSpecialCaller(specialCaller); MemberName method = resolveOrFail(refc, name, type, false, false, specialCaller); - Class<?> callerClass = Reflection.getCallerClass(); - checkSecurityManager(refc, method, callerClass); - return accessSpecial(refc, method, findBoundCallerClass(method, callerClass), specialCaller); + checkSecurityManager(refc, method); + return accessSpecial(refc, method, findBoundCallerClass(method), specialCaller); } private MethodHandle accessSpecial(Class<?> refc, MemberName method, Class<?> callerClass, @@ -802,10 +795,9 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { MemberName field = resolveOrFail(refc, name, type, false); - checkSecurityManager(refc, field, Reflection.getCallerClass()); + checkSecurityManager(refc, field); return makeAccessor(refc, field, false, false, 0); } private MethodHandle resolveGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { @@ -830,10 +822,9 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findSetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { MemberName field = resolveOrFail(refc, name, type, false); - checkSecurityManager(refc, field, Reflection.getCallerClass()); + checkSecurityManager(refc, field); return makeAccessor(refc, field, false, true, 0); } private MethodHandle resolveSetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { @@ -857,10 +848,9 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findStaticGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { MemberName field = resolveOrFail(refc, name, type, true); - checkSecurityManager(refc, field, Reflection.getCallerClass()); + checkSecurityManager(refc, field); return makeAccessor(refc, field, false, false, 1); } private MethodHandle resolveStaticGetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { @@ -884,10 +874,9 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle findStaticSetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { MemberName field = resolveOrFail(refc, name, type, true); - checkSecurityManager(refc, field, Reflection.getCallerClass()); + checkSecurityManager(refc, field); return makeAccessor(refc, field, false, true, 1); } private MethodHandle resolveStaticSetter(Class<?> refc, String name, Class<?> type) throws NoSuchFieldException, IllegalAccessException { @@ -941,15 +930,13 @@ * <a href="MethodHandles.Lookup.html#secmgr">refuses access</a> * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle bind(Object receiver, String name, MethodType type) throws NoSuchMethodException, IllegalAccessException { Class<? extends Object> refc = receiver.getClass(); // may get NPE MemberName method = resolveOrFail(refc, name, type, false); - Class<?> callerClass = Reflection.getCallerClass(); - checkSecurityManager(refc, method, callerClass); + checkSecurityManager(refc, method); checkMethod(refc, method, false); MethodHandle dmh = MethodHandleImpl.findMethod(method, true, lookupClassOrNull()); - MethodHandle bcmh = maybeBindCaller(method, dmh, findBoundCallerClass(method, callerClass)); + MethodHandle bcmh = maybeBindCaller(method, dmh, findBoundCallerClass(method)); if (bcmh != dmh) return fixVarargs(bcmh.bindTo(receiver), dmh); MethodHandle bmh = MethodHandleImpl.bindReceiver(dmh, receiver); if (bmh == null) @@ -978,7 +965,6 @@ * is set and {@code asVarargsCollector} fails * @throws NullPointerException if the argument is null */ - @CallerSensitive public MethodHandle unreflect(Method m) throws IllegalAccessException { MemberName method = new MemberName(m); assert(method.isMethod()); @@ -986,8 +972,7 @@ return MethodHandleImpl.findMethod(method, true, /*no lookupClass*/ null); checkMethod(method.getDeclaringClass(), method, method.isStatic()); MethodHandle mh = MethodHandleImpl.findMethod(method, true, lookupClassOrNull()); - Class<?> callerClass = Reflection.getCallerClass(); - mh = maybeBindCaller(method, mh, findBoundCallerClass(method, callerClass)); + mh = maybeBindCaller(method, mh, findBoundCallerClass(method)); return restrictProtectedReceiver(method, mh); } @@ -1012,7 +997,6 @@ * is set and {@code asVarargsCollector} fails * @throws NullPointerException if any argument is null */ - @CallerSensitive public MethodHandle unreflectSpecial(Method m, Class<?> specialCaller) throws IllegalAccessException { checkSpecialCaller(specialCaller); MemberName method = new MemberName(m); @@ -1020,7 +1004,7 @@ // ignore m.isAccessible: this is a new kind of access checkMethod(m.getDeclaringClass(), method, false); MethodHandle mh = MethodHandleImpl.findMethod(method, false, lookupClassOrNull()); - mh = maybeBindCaller(method, mh, findBoundCallerClass(method, callerClass)); + mh = maybeBindCaller(method, mh, findBoundCallerClass(method)); return restrictReceiver(method, mh, specialCaller); } @@ -1134,7 +1118,7 @@ * If this lookup object has private access, then the caller class is the lookupClass. * Otherwise, if m is caller-sensitive, throw IllegalAccessException. */ - Class<?> findBoundCallerClass(MemberName m, Class<?> caller) { + Class<?> findBoundCallerClass(MemberName m) throws IllegalAccessException { Class<?> callerClass = null; if (MethodHandleNatives.isCallerSensitive(m)) { // Only full-power lookup is allowed to resolve caller-sensitive methods @@ -1171,7 +1155,7 @@ * Perform necessary <a href="MethodHandles.Lookup.html#secmgr">access checks</a>. * This function performs stack walk magic: do not refactor it. */ - void checkSecurityManager(Class<?> refc, MemberName m, Class<?> caller) { + void checkSecurityManager(Class<?> refc, MemberName m) { SecurityManager smgr = System.getSecurityManager(); if (smgr == null) return; if (allowedModes == TRUSTED) return; @@ -1203,23 +1187,22 @@ // Inline SecurityManager.checkMemberAccess final int which = Member.DECLARED; final Class<?> clazz = defc; - if (!overridden) { - if (!isFullPowerLookup() || - (lookupClass.getClassLoader() != defc.getClassLoader())) { - smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); - } - } else { - // Don't refactor; otherwise break the stack depth for - // checkMemberAccess of subclasses of SecurityManager as specified. - smgr.checkMemberAccess(defc, Member.DECLARED); - } - } + if (!overridden) { + if (!isFullPowerLookup() || + (lookupClass.getClassLoader() != defc.getClassLoader())) { + smgr.checkPermission(SecurityConstants.CHECK_MEMBER_ACCESS_PERMISSION); + } + } else { + // Don't refactor; otherwise break the stack depth for + // checkMemberAccess of subclasses of SecurityManager as specified. + smgr.checkMemberAccess(clazz, which); + } + } // Step 4: if (defc != refc) { ReflectUtil.checkPackageAccess(defc); } - } void checkMethod(Class<?> refc, MemberName m, boolean wantStatic) throws IllegalAccessException {