Thu, 18 Jul 2013 18:08:26 +0530
8020731: Revisit checkPermission calls in Context class
Reviewed-by: attila, hannesw
1.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Wed Jul 17 18:20:40 2013 +0200 1.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Thu Jul 18 18:08:26 2013 +0530 1.3 @@ -209,10 +209,10 @@ 1.4 } 1.5 1.6 try { 1.7 - final ScriptObject oldGlobal = getNashornGlobal(); 1.8 + final ScriptObject oldGlobal = Context.getGlobal(); 1.9 try { 1.10 if(oldGlobal != ctxtGlobal) { 1.11 - setNashornGlobal(ctxtGlobal); 1.12 + Context.setGlobal(ctxtGlobal); 1.13 } 1.14 1.15 if (! isInterfaceImplemented(clazz, realSelf)) { 1.16 @@ -221,7 +221,7 @@ 1.17 return clazz.cast(JavaAdapterFactory.getConstructor(realSelf.getClass(), clazz).invoke(realSelf)); 1.18 } finally { 1.19 if(oldGlobal != ctxtGlobal) { 1.20 - setNashornGlobal(oldGlobal); 1.21 + Context.setGlobal(oldGlobal); 1.22 } 1.23 } 1.24 } catch(final RuntimeException|Error e) { 1.25 @@ -357,7 +357,7 @@ 1.26 } 1.27 1.28 private Object invokeImpl(final Object selfObject, final String name, final Object... args) throws ScriptException, NoSuchMethodException { 1.29 - final ScriptObject oldGlobal = getNashornGlobal(); 1.30 + final ScriptObject oldGlobal = Context.getGlobal(); 1.31 final ScriptObject ctxtGlobal = getNashornGlobalFrom(context); 1.32 final boolean globalChanged = (oldGlobal != ctxtGlobal); 1.33 1.34 @@ -365,7 +365,7 @@ 1.35 1.36 try { 1.37 if (globalChanged) { 1.38 - setNashornGlobal(ctxtGlobal); 1.39 + Context.setGlobal(ctxtGlobal); 1.40 } 1.41 1.42 ScriptObject sobj; 1.43 @@ -398,7 +398,7 @@ 1.44 throw new NoSuchMethodException(name); 1.45 } finally { 1.46 if (globalChanged) { 1.47 - setNashornGlobal(oldGlobal); 1.48 + Context.setGlobal(oldGlobal); 1.49 } 1.50 } 1.51 } 1.52 @@ -411,12 +411,12 @@ 1.53 if (script == null) { 1.54 return null; 1.55 } 1.56 - final ScriptObject oldGlobal = getNashornGlobal(); 1.57 + final ScriptObject oldGlobal = Context.getGlobal(); 1.58 final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt); 1.59 final boolean globalChanged = (oldGlobal != ctxtGlobal); 1.60 try { 1.61 if (globalChanged) { 1.62 - setNashornGlobal(ctxtGlobal); 1.63 + Context.setGlobal(ctxtGlobal); 1.64 } 1.65 1.66 setContextVariables(ctxt); 1.67 @@ -426,7 +426,7 @@ 1.68 throw new AssertionError("should not reach here"); 1.69 } finally { 1.70 if (globalChanged) { 1.71 - setNashornGlobal(oldGlobal); 1.72 + Context.setGlobal(oldGlobal); 1.73 } 1.74 } 1.75 } 1.76 @@ -469,12 +469,12 @@ 1.77 } 1.78 1.79 private ScriptFunction compileImpl(final Source source, final ScriptContext ctxt) throws ScriptException { 1.80 - final ScriptObject oldGlobal = getNashornGlobal(); 1.81 + final ScriptObject oldGlobal = Context.getGlobal(); 1.82 final ScriptObject ctxtGlobal = getNashornGlobalFrom(ctxt); 1.83 final boolean globalChanged = (oldGlobal != ctxtGlobal); 1.84 try { 1.85 if (globalChanged) { 1.86 - setNashornGlobal(ctxtGlobal); 1.87 + Context.setGlobal(ctxtGlobal); 1.88 } 1.89 1.90 return nashornContext.compileScript(source, ctxtGlobal); 1.91 @@ -483,7 +483,7 @@ 1.92 throw new AssertionError("should not reach here"); 1.93 } finally { 1.94 if (globalChanged) { 1.95 - setNashornGlobal(oldGlobal); 1.96 + Context.setGlobal(oldGlobal); 1.97 } 1.98 } 1.99 } 1.100 @@ -502,19 +502,4 @@ 1.101 } 1.102 return true; 1.103 } 1.104 - 1.105 - // don't make this public!! 1.106 - static ScriptObject getNashornGlobal() { 1.107 - return Context.getGlobal(); 1.108 - } 1.109 - 1.110 - static void setNashornGlobal(final ScriptObject newGlobal) { 1.111 - AccessController.doPrivileged(new PrivilegedAction<Void>() { 1.112 - @Override 1.113 - public Void run() { 1.114 - Context.setGlobal(newGlobal); 1.115 - return null; 1.116 - } 1.117 - }); 1.118 - } 1.119 }
2.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Wed Jul 17 18:20:40 2013 +0200 2.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Jul 18 18:08:26 2013 +0530 2.3 @@ -79,12 +79,12 @@ 2.4 // JSObject methods 2.5 @Override 2.6 public Object call(final String functionName, final Object... args) { 2.7 - final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal(); 2.8 + final ScriptObject oldGlobal = Context.getGlobal(); 2.9 final boolean globalChanged = (oldGlobal != global); 2.10 2.11 try { 2.12 if (globalChanged) { 2.13 - NashornScriptEngine.setNashornGlobal(global); 2.14 + Context.setGlobal(global); 2.15 } 2.16 2.17 final Object val = functionName == null? sobj : sobj.get(functionName); 2.18 @@ -100,19 +100,19 @@ 2.19 throw new RuntimeException(t); 2.20 } finally { 2.21 if (globalChanged) { 2.22 - NashornScriptEngine.setNashornGlobal(oldGlobal); 2.23 + Context.setGlobal(oldGlobal); 2.24 } 2.25 } 2.26 } 2.27 2.28 @Override 2.29 public Object newObject(final String functionName, final Object... args) { 2.30 - final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal(); 2.31 + final ScriptObject oldGlobal = Context.getGlobal(); 2.32 final boolean globalChanged = (oldGlobal != global); 2.33 2.34 try { 2.35 if (globalChanged) { 2.36 - NashornScriptEngine.setNashornGlobal(global); 2.37 + Context.setGlobal(global); 2.38 } 2.39 2.40 final Object val = functionName == null? sobj : sobj.get(functionName); 2.41 @@ -128,7 +128,7 @@ 2.42 throw new RuntimeException(t); 2.43 } finally { 2.44 if (globalChanged) { 2.45 - NashornScriptEngine.setNashornGlobal(oldGlobal); 2.46 + Context.setGlobal(oldGlobal); 2.47 } 2.48 } 2.49 } 2.50 @@ -272,7 +272,7 @@ 2.51 2.52 @Override 2.53 public Object put(final String key, final Object value) { 2.54 - final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal(); 2.55 + final ScriptObject oldGlobal = Context.getGlobal(); 2.56 final boolean globalChanged = (oldGlobal != global); 2.57 return inGlobal(new Callable<Object>() { 2.58 @Override public Object call() { 2.59 @@ -284,7 +284,7 @@ 2.60 2.61 @Override 2.62 public void putAll(final Map<? extends String, ? extends Object> map) { 2.63 - final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal(); 2.64 + final ScriptObject oldGlobal = Context.getGlobal(); 2.65 final boolean globalChanged = (oldGlobal != global); 2.66 inGlobal(new Callable<Object>() { 2.67 @Override public Object call() { 2.68 @@ -535,7 +535,7 @@ 2.69 * @return wrapped object 2.70 */ 2.71 public static Object wrap(final Object obj, final ScriptObject homeGlobal) { 2.72 - return (obj instanceof ScriptObject) ? new ScriptObjectMirror((ScriptObject)obj, homeGlobal) : obj; 2.73 + return (obj instanceof ScriptObject && homeGlobal != null) ? new ScriptObjectMirror((ScriptObject)obj, homeGlobal) : obj; 2.74 } 2.75 2.76 /** 2.77 @@ -613,10 +613,10 @@ 2.78 2.79 // internals only below this. 2.80 private <V> V inGlobal(final Callable<V> callable) { 2.81 - final ScriptObject oldGlobal = NashornScriptEngine.getNashornGlobal(); 2.82 + final ScriptObject oldGlobal = Context.getGlobal(); 2.83 final boolean globalChanged = (oldGlobal != global); 2.84 if (globalChanged) { 2.85 - NashornScriptEngine.setNashornGlobal(global); 2.86 + Context.setGlobal(global); 2.87 } 2.88 try { 2.89 return callable.call(); 2.90 @@ -626,7 +626,7 @@ 2.91 throw new AssertionError("Cannot happen", e); 2.92 } finally { 2.93 if (globalChanged) { 2.94 - NashornScriptEngine.setNashornGlobal(oldGlobal); 2.95 + Context.setGlobal(oldGlobal); 2.96 } 2.97 } 2.98 }
3.1 --- a/src/jdk/nashorn/internal/objects/Global.java Wed Jul 17 18:20:40 2013 +0200 3.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Jul 18 18:08:26 2013 +0530 3.3 @@ -411,18 +411,33 @@ 3.4 // initialized by nasgen 3.5 private static PropertyMap $nasgenmap$; 3.6 3.7 + // performs initialization checks for Global constructor and returns the 3.8 + // PropertyMap, if everything is fine. 3.9 + private static PropertyMap checkAndGetMap(final Context context) { 3.10 + // security check first 3.11 + final SecurityManager sm = System.getSecurityManager(); 3.12 + if (sm != null) { 3.13 + sm.checkPermission(new RuntimePermission("nashorn.newGlobal")); 3.14 + } 3.15 + 3.16 + // null check on context 3.17 + context.getClass(); 3.18 + 3.19 + /* 3.20 + * Duplicate global's map and use it. This way the initial Map filled 3.21 + * by nasgen (referenced from static field in this class) is retained 3.22 + * 'as is' (as that one is process wide singleton. 3.23 + */ 3.24 + return $nasgenmap$.duplicate(); 3.25 + } 3.26 + 3.27 /** 3.28 * Constructor 3.29 * 3.30 * @param context the context 3.31 */ 3.32 public Global(final Context context) { 3.33 - /* 3.34 - * Duplicate global's map and use it. This way the initial Map filled 3.35 - * by nasgen (referenced from static field in this class) is retained 3.36 - * 'as is' (as that one is process wide singleton. 3.37 - */ 3.38 - super($nasgenmap$.duplicate()); 3.39 + super(checkAndGetMap(context)); 3.40 this.setContext(context); 3.41 this.setIsScope(); 3.42
4.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Wed Jul 17 18:20:40 2013 +0200 4.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Thu Jul 18 18:08:26 2013 +0530 4.3 @@ -121,11 +121,6 @@ 4.4 * @param global the global scope 4.5 */ 4.6 public static void setGlobal(final ScriptObject global) { 4.7 - final SecurityManager sm = System.getSecurityManager(); 4.8 - if (sm != null) { 4.9 - sm.checkPermission(new RuntimePermission("nashorn.setGlobal")); 4.10 - } 4.11 - 4.12 if (global != null && !(global instanceof Global)) { 4.13 throw new IllegalArgumentException("global is not an instance of Global!"); 4.14 } 4.15 @@ -645,12 +640,7 @@ 4.16 * @return the global script object 4.17 */ 4.18 public ScriptObject newGlobal() { 4.19 - final SecurityManager sm = System.getSecurityManager(); 4.20 - if (sm != null) { 4.21 - sm.checkPermission(new RuntimePermission("nashorn.newGlobal")); 4.22 - } 4.23 - 4.24 - return newGlobalTrusted(); 4.25 + return new Global(this); 4.26 } 4.27 4.28 /** 4.29 @@ -828,10 +818,6 @@ 4.30 }); 4.31 } 4.32 4.33 - private ScriptObject newGlobalTrusted() { 4.34 - return new Global(this); 4.35 - } 4.36 - 4.37 private long getUniqueScriptId() { 4.38 return uniqueScriptId.getAndIncrement(); 4.39 }
5.1 --- a/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Wed Jul 17 18:20:40 2013 +0200 5.2 +++ b/src/jdk/nashorn/internal/runtime/NativeJavaPackage.java Thu Jul 18 18:08:26 2013 +0530 5.3 @@ -84,8 +84,8 @@ 5.4 * @param proto proto 5.5 */ 5.6 public NativeJavaPackage(final String name, final ScriptObject proto) { 5.7 + super(proto, null); 5.8 this.name = name; 5.9 - this.setProto(proto); 5.10 } 5.11 5.12 @Override
6.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Wed Jul 17 18:20:40 2013 +0200 6.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Thu Jul 18 18:08:26 2013 +0530 6.3 @@ -335,9 +335,7 @@ 6.4 */ 6.5 public static Object checkAndApply(final ScriptFunction target, final Object self, final Object... args) { 6.6 final ScriptObject global = Context.getGlobalTrusted(); 6.7 - if (! (global instanceof GlobalObject)) { 6.8 - throw new IllegalStateException("No current global set"); 6.9 - } 6.10 + assert (global instanceof GlobalObject): "No current global set"; 6.11 6.12 if (target.getContext() != global.getContext()) { 6.13 throw new IllegalArgumentException("'target' function is not from current Context");
7.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Jul 17 18:20:40 2013 +0200 7.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Thu Jul 18 18:08:26 2013 +0530 7.3 @@ -58,10 +58,8 @@ 7.4 * @param expression with expression 7.5 */ 7.6 public WithObject(final ScriptObject scope, final Object expression) { 7.7 - super(); 7.8 - 7.9 + super(scope, null); 7.10 setIsScope(); 7.11 - setProto(scope); 7.12 this.expression = expression; 7.13 } 7.14
8.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Wed Jul 17 18:20:40 2013 +0200 8.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Thu Jul 18 18:08:26 2013 +0530 8.3 @@ -121,7 +121,23 @@ 8.4 * constructor's trailing position and thus provide further instance-specific overrides. The order of invocation is 8.5 * always instance-specified method, then a class-specified method, and finally the superclass method. 8.6 */ 8.7 -final class JavaAdapterBytecodeGenerator extends JavaAdapterGeneratorBase { 8.8 +final class JavaAdapterBytecodeGenerator { 8.9 + static final Type CONTEXT_TYPE = Type.getType(Context.class); 8.10 + static final Type OBJECT_TYPE = Type.getType(Object.class); 8.11 + static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class); 8.12 + 8.13 + static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName(); 8.14 + static final String OBJECT_TYPE_NAME = OBJECT_TYPE.getInternalName(); 8.15 + 8.16 + static final String INIT = "<init>"; 8.17 + 8.18 + static final String GLOBAL_FIELD_NAME = "global"; 8.19 + 8.20 + static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor(); 8.21 + 8.22 + static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, SCRIPT_OBJECT_TYPE); 8.23 + static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE); 8.24 + 8.25 private static final Type SCRIPT_FUNCTION_TYPE = Type.getType(ScriptFunction.class); 8.26 private static final Type STRING_TYPE = Type.getType(String.class); 8.27 private static final Type METHOD_TYPE_TYPE = Type.getType(MethodType.class); 8.28 @@ -151,7 +167,7 @@ 8.29 // Class name suffix used to append to the adaptee class name, when it can be defined in the adaptee's package. 8.30 private static final String ADAPTER_CLASS_NAME_SUFFIX = "$$NashornJavaAdapter"; 8.31 private static final String JAVA_PACKAGE_PREFIX = "java/"; 8.32 - private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 238; //255 - 17; 17 is the maximum possible length for the global setter inner class suffix 8.33 + private static final int MAX_GENERATED_TYPE_NAME_LENGTH = 255; 8.34 8.35 private static final String CLASS_INIT = "<clinit>"; 8.36 private static final String STATIC_GLOBAL_FIELD_NAME = "staticGlobal"; 8.37 @@ -175,8 +191,6 @@ 8.38 private final String superClassName; 8.39 // Binary name of the generated class. 8.40 private final String generatedClassName; 8.41 - // Binary name of the PrivilegedAction inner class that is used to 8.42 - private final String globalSetterClassName; 8.43 private final Set<String> usedFieldNames = new HashSet<>(); 8.44 private final Set<String> abstractMethodNames = new HashSet<>(); 8.45 private final String samName; 8.46 @@ -220,9 +234,6 @@ 8.47 l = random.nextLong(); 8.48 } 8.49 8.50 - // NOTE: they way this class name is calculated affects the value of MAX_GENERATED_TYPE_NAME_LENGTH constant. If 8.51 - // you change the calculation of globalSetterClassName, adjust the constant too. 8.52 - globalSetterClassName = generatedClassName.concat("$" + Long.toHexString(l & Long.MAX_VALUE)); 8.53 cw.visit(Opcodes.V1_7, ACC_PUBLIC | ACC_SUPER | ACC_FINAL, generatedClassName, null, superClassName, getInternalTypeNames(interfaces)); 8.54 8.55 generateGlobalFields(); 8.56 @@ -250,7 +261,7 @@ 8.57 } 8.58 8.59 JavaAdapterClassLoader createAdapterClassLoader() { 8.60 - return new JavaAdapterClassLoader(generatedClassName, cw.toByteArray(), globalSetterClassName); 8.61 + return new JavaAdapterClassLoader(generatedClassName, cw.toByteArray()); 8.62 } 8.63 8.64 boolean isAutoConvertibleFromFunction() { 8.65 @@ -511,8 +522,8 @@ 8.66 mv.invokestatic(CONTEXT_TYPE_NAME, "getGlobal", GET_GLOBAL_METHOD_DESCRIPTOR); 8.67 } 8.68 8.69 - private void invokeSetGlobal(final InstructionAdapter mv) { 8.70 - mv.invokestatic(globalSetterClassName, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR); 8.71 + private static void invokeSetGlobal(final InstructionAdapter mv) { 8.72 + mv.invokestatic(CONTEXT_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR); 8.73 } 8.74 8.75 /** 8.76 @@ -794,7 +805,7 @@ 8.77 * entry. 8.78 * @param globalsDifferVar index of the boolean local variable that is true if the global needs to be restored. 8.79 */ 8.80 - private void emitFinally(final InstructionAdapter mv, final int currentGlobalVar, final int globalsDifferVar) { 8.81 + private static void emitFinally(final InstructionAdapter mv, final int currentGlobalVar, final int globalsDifferVar) { 8.82 // Emit code to restore the previous Nashorn global if needed 8.83 mv.visitVarInsn(ILOAD, globalsDifferVar); 8.84 final Label skip = new Label();
9.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Wed Jul 17 18:20:40 2013 +0200 9.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Thu Jul 18 18:08:26 2013 +0530 9.3 @@ -25,16 +25,6 @@ 9.4 9.5 package jdk.nashorn.internal.runtime.linker; 9.6 9.7 -import static jdk.internal.org.objectweb.asm.Opcodes.ACC_FINAL; 9.8 -import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PRIVATE; 9.9 -import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC; 9.10 -import static jdk.internal.org.objectweb.asm.Opcodes.ACC_STATIC; 9.11 -import static jdk.internal.org.objectweb.asm.Opcodes.ACC_SUPER; 9.12 -import static jdk.internal.org.objectweb.asm.Opcodes.ACONST_NULL; 9.13 -import static jdk.internal.org.objectweb.asm.Opcodes.ALOAD; 9.14 -import static jdk.internal.org.objectweb.asm.Opcodes.ARETURN; 9.15 -import static jdk.internal.org.objectweb.asm.Opcodes.RETURN; 9.16 - 9.17 import java.security.AccessController; 9.18 import java.security.AllPermission; 9.19 import java.security.CodeSigner; 9.20 @@ -45,12 +35,6 @@ 9.21 import java.security.SecureClassLoader; 9.22 9.23 import jdk.internal.dynalink.beans.StaticClass; 9.24 -import jdk.internal.org.objectweb.asm.ClassWriter; 9.25 -import jdk.internal.org.objectweb.asm.Opcodes; 9.26 -import jdk.internal.org.objectweb.asm.Type; 9.27 -import jdk.internal.org.objectweb.asm.commons.InstructionAdapter; 9.28 -import jdk.nashorn.internal.runtime.Context; 9.29 -import jdk.nashorn.internal.runtime.ScriptObject; 9.30 9.31 /** 9.32 * This class encapsulates the bytecode of the adapter class and can be used to load it into the JVM as an actual Class. 9.33 @@ -60,22 +44,15 @@ 9.34 * class are normally created by {@link JavaAdapterBytecodeGenerator}. 9.35 */ 9.36 @SuppressWarnings("javadoc") 9.37 -class JavaAdapterClassLoader extends JavaAdapterGeneratorBase { 9.38 - private static final Type PRIVILEGED_ACTION_TYPE = Type.getType(PrivilegedAction.class); 9.39 - 9.40 - private static final String PRIVILEGED_ACTION_TYPE_NAME = PRIVILEGED_ACTION_TYPE.getInternalName(); 9.41 - private static final String PRIVILEGED_RUN_METHOD_DESCRIPTOR = Type.getMethodDescriptor(OBJECT_TYPE); 9.42 - 9.43 +final class JavaAdapterClassLoader { 9.44 private static final ProtectionDomain GENERATED_PROTECTION_DOMAIN = createGeneratedProtectionDomain(); 9.45 9.46 private final String className; 9.47 private final byte[] classBytes; 9.48 - private final String globalSetterClassName; 9.49 9.50 - JavaAdapterClassLoader(String className, byte[] classBytes, String globalSetterClassName) { 9.51 + JavaAdapterClassLoader(String className, byte[] classBytes) { 9.52 this.className = className.replace('/', '.'); 9.53 this.classBytes = classBytes; 9.54 - this.globalSetterClassName = globalSetterClassName.replace('/', '.'); 9.55 } 9.56 9.57 /** 9.58 @@ -116,7 +93,6 @@ 9.59 private ClassLoader createClassLoader(final ClassLoader parentLoader) { 9.60 return new AdapterLoader(parentLoader) { 9.61 private final ClassLoader myLoader = getClass().getClassLoader(); 9.62 - private final ProtectionDomain myProtectionDomain = getClass().getProtectionDomain(); 9.63 9.64 @Override 9.65 public Class<?> loadClass(final String name, final boolean resolve) throws ClassNotFoundException { 9.66 @@ -138,9 +114,6 @@ 9.67 protected Class<?> findClass(final String name) throws ClassNotFoundException { 9.68 if(name.equals(className)) { 9.69 return defineClass(name, classBytes, 0, classBytes.length, GENERATED_PROTECTION_DOMAIN); 9.70 - } else if(name.equals(globalSetterClassName)) { 9.71 - final byte[] bytes = generatePrivilegedActionClassBytes(globalSetterClassName.replace('.', '/')); 9.72 - return defineClass(name, bytes, 0, bytes.length, myProtectionDomain); 9.73 } else { 9.74 throw new ClassNotFoundException(name); 9.75 } 9.76 @@ -158,70 +131,4 @@ 9.77 permissions.add(new AllPermission()); 9.78 return new ProtectionDomain(new CodeSource(null, (CodeSigner[])null), permissions); 9.79 } 9.80 - 9.81 - /** 9.82 - * Generates a PrivilegedAction implementation class for invoking {@link Context#setGlobal(ScriptObject)} from the 9.83 - * adapter class. 9.84 - */ 9.85 - private static byte[] generatePrivilegedActionClassBytes(final String className) { 9.86 - final ClassWriter w = new ClassWriter(ClassWriter.COMPUTE_FRAMES | ClassWriter.COMPUTE_MAXS); 9.87 - // class GlobalSetter implements PrivilegedAction { 9.88 - w.visit(Opcodes.V1_7, ACC_SUPER | ACC_FINAL, className, null, OBJECT_TYPE_NAME, new String[] { 9.89 - PRIVILEGED_ACTION_TYPE_NAME 9.90 - }); 9.91 - 9.92 - // private final ScriptObject global; 9.93 - w.visitField(ACC_PRIVATE | ACC_FINAL, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR, null, null).visitEnd(); 9.94 - 9.95 - // private GlobalSetter(ScriptObject global) { 9.96 - InstructionAdapter mv = new InstructionAdapter(w.visitMethod(ACC_PRIVATE, INIT, 9.97 - SET_GLOBAL_METHOD_DESCRIPTOR, null, new String[0])); 9.98 - mv.visitCode(); 9.99 - // super(); 9.100 - mv.visitVarInsn(ALOAD, 0); 9.101 - mv.invokespecial(OBJECT_TYPE_NAME, INIT, VOID_NOARG_METHOD_DESCRIPTOR); 9.102 - // this.global = global; 9.103 - mv.visitVarInsn(ALOAD, 0); 9.104 - mv.visitVarInsn(ALOAD, 1); 9.105 - mv.putfield(className, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 9.106 - 9.107 - mv.visitInsn(RETURN); 9.108 - mv.visitEnd(); 9.109 - mv.visitMaxs(0, 0); 9.110 - 9.111 - // public Object run() { 9.112 - mv = new InstructionAdapter(w.visitMethod(ACC_PUBLIC, "run", PRIVILEGED_RUN_METHOD_DESCRIPTOR, null, 9.113 - new String[0])); 9.114 - mv.visitCode(); 9.115 - // Context.setGlobal(this.global); 9.116 - mv.visitVarInsn(ALOAD, 0); 9.117 - mv.getfield(className, GLOBAL_FIELD_NAME, SCRIPT_OBJECT_TYPE_DESCRIPTOR); 9.118 - mv.invokestatic(CONTEXT_TYPE_NAME, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR); 9.119 - // return null; 9.120 - mv.visitInsn(ACONST_NULL); 9.121 - mv.visitInsn(ARETURN); 9.122 - 9.123 - mv.visitEnd(); 9.124 - mv.visitMaxs(0, 0); 9.125 - 9.126 - // static void setGlobal(ScriptObject global) { 9.127 - mv = new InstructionAdapter(w.visitMethod(ACC_STATIC, "setGlobal", SET_GLOBAL_METHOD_DESCRIPTOR, null, 9.128 - new String[0])); 9.129 - mv.visitCode(); 9.130 - // new GlobalSetter(ScriptObject global) 9.131 - mv.anew(Type.getType("L" + className + ";")); 9.132 - mv.dup(); 9.133 - mv.visitVarInsn(ALOAD, 0); 9.134 - mv.invokespecial(className, INIT, SET_GLOBAL_METHOD_DESCRIPTOR); 9.135 - // AccessController.doPrivileged(...) 9.136 - mv.invokestatic(Type.getInternalName(AccessController.class), "doPrivileged", Type.getMethodDescriptor( 9.137 - OBJECT_TYPE, PRIVILEGED_ACTION_TYPE)); 9.138 - mv.pop(); 9.139 - mv.visitInsn(RETURN); 9.140 - 9.141 - mv.visitEnd(); 9.142 - mv.visitMaxs(0, 0); 9.143 - 9.144 - return w.toByteArray(); 9.145 - } 9.146 }
10.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterGeneratorBase.java Wed Jul 17 18:20:40 2013 +0200 10.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 10.3 @@ -1,56 +0,0 @@ 10.4 -/* 10.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 10.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 10.7 - * 10.8 - * This code is free software; you can redistribute it and/or modify it 10.9 - * under the terms of the GNU General Public License version 2 only, as 10.10 - * published by the Free Software Foundation. Oracle designates this 10.11 - * particular file as subject to the "Classpath" exception as provided 10.12 - * by Oracle in the LICENSE file that accompanied this code. 10.13 - * 10.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 10.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 10.17 - * version 2 for more details (a copy is included in the LICENSE file that 10.18 - * accompanied this code). 10.19 - * 10.20 - * You should have received a copy of the GNU General Public License version 10.21 - * 2 along with this work; if not, write to the Free Software Foundation, 10.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 10.23 - * 10.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 10.25 - * or visit www.oracle.com if you need additional information or have any 10.26 - * questions. 10.27 - */ 10.28 - 10.29 -package jdk.nashorn.internal.runtime.linker; 10.30 - 10.31 -import jdk.internal.org.objectweb.asm.Type; 10.32 -import jdk.nashorn.internal.runtime.Context; 10.33 -import jdk.nashorn.internal.runtime.ScriptObject; 10.34 - 10.35 -/** 10.36 - * Base class for both {@link JavaAdapterBytecodeGenerator} and {@link JavaAdapterClassLoader}, containing those 10.37 - * bytecode types, type names and method descriptor that are used by both. 10.38 - */ 10.39 -@SuppressWarnings("javadoc") 10.40 -abstract class JavaAdapterGeneratorBase { 10.41 - static final Type CONTEXT_TYPE = Type.getType(Context.class); 10.42 - static final Type OBJECT_TYPE = Type.getType(Object.class); 10.43 - static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class); 10.44 - 10.45 - static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName(); 10.46 - static final String OBJECT_TYPE_NAME = OBJECT_TYPE.getInternalName(); 10.47 - 10.48 - static final String INIT = "<init>"; 10.49 - 10.50 - static final String GLOBAL_FIELD_NAME = "global"; 10.51 - 10.52 - static final String SCRIPT_OBJECT_TYPE_DESCRIPTOR = SCRIPT_OBJECT_TYPE.getDescriptor(); 10.53 - 10.54 - static final String SET_GLOBAL_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE, SCRIPT_OBJECT_TYPE); 10.55 - static final String VOID_NOARG_METHOD_DESCRIPTOR = Type.getMethodDescriptor(Type.VOID_TYPE); 10.56 - 10.57 - protected JavaAdapterGeneratorBase() { 10.58 - } 10.59 -}