1.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Thu Aug 08 11:20:14 2013 -0300 1.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Fri Aug 09 20:48:44 2013 +0530 1.3 @@ -31,9 +31,9 @@ 1.4 import java.lang.invoke.MethodHandles; 1.5 import java.lang.invoke.MethodType; 1.6 import java.lang.reflect.Modifier; 1.7 +import java.security.AccessControlContext; 1.8 import java.security.AccessController; 1.9 import java.security.PrivilegedAction; 1.10 -import java.security.PrivilegedExceptionAction; 1.11 import java.util.ArrayList; 1.12 import java.util.Arrays; 1.13 import java.util.Collections; 1.14 @@ -70,6 +70,11 @@ 1.15 1.16 @SuppressWarnings("javadoc") 1.17 public final class JavaAdapterFactory { 1.18 + // context with permissions needs for AdapterInfo creation 1.19 + private static final AccessControlContext CREATE_ADAPTER_INFO_ACC_CTXT = 1.20 + ClassAndLoader.createPermAccCtxt("createClassLoader", "getClassLoader", 1.21 + "accessDeclaredMembers", "accessClassInPackage.jdk.nashorn.internal.runtime"); 1.22 + 1.23 /** 1.24 * A mapping from an original Class object to AdapterInfo representing the adapter for the class it represents. 1.25 */ 1.26 @@ -124,17 +129,10 @@ 1.27 */ 1.28 public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType) throws Exception { 1.29 final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null); 1.30 - return AccessController.doPrivileged(new PrivilegedExceptionAction<MethodHandle>() { 1.31 - @Override 1.32 - public MethodHandle run() throws Exception { 1.33 - // NOTE: we use publicLookup(), but none of our adapter constructors are caller sensitive, so this is 1.34 - // okay, we won't artificially limit access. 1.35 - return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl( 1.36 - NashornCallSiteDescriptor.get(MethodHandles.publicLookup(), "dyn:new", 1.37 - MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false, 1.38 - adapterClass, null)).getInvocation(), adapterClass); 1.39 - } 1.40 - }); 1.41 + return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl( 1.42 + NashornCallSiteDescriptor.get(MethodHandles.publicLookup(), "dyn:new", 1.43 + MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false, 1.44 + adapterClass, null)).getInvocation(), adapterClass); 1.45 } 1.46 1.47 /** 1.48 @@ -171,7 +169,7 @@ 1.49 return (List)Collections.singletonList(clazz); 1.50 } 1.51 1.52 - /** 1.53 + /** 1.54 * For a given class, create its adapter class and associated info. 1.55 * @param type the class for which the adapter is created 1.56 * @return the adapter info for the class. 1.57 @@ -190,12 +188,19 @@ 1.58 } 1.59 superClass = t; 1.60 } else { 1.61 + if (interfaces.size() > 65535) { 1.62 + throw new IllegalArgumentException("interface limit exceeded"); 1.63 + } 1.64 + 1.65 interfaces.add(t); 1.66 } 1.67 + 1.68 if(!Modifier.isPublic(mod)) { 1.69 return new AdapterInfo(AdaptationResult.Outcome.ERROR_NON_PUBLIC_CLASS, t.getCanonicalName()); 1.70 } 1.71 } 1.72 + 1.73 + 1.74 final Class<?> effectiveSuperClass = superClass == null ? Object.class : superClass; 1.75 return AccessController.doPrivileged(new PrivilegedAction<AdapterInfo>() { 1.76 @Override 1.77 @@ -206,7 +211,7 @@ 1.78 return new AdapterInfo(e.getAdaptationResult()); 1.79 } 1.80 } 1.81 - }); 1.82 + }, CREATE_ADAPTER_INFO_ACC_CTXT); 1.83 } 1.84 1.85 private static class AdapterInfo {