Mon, 12 Aug 2013 14:43:53 +0530
8022782: publicLookup access failures in ScriptObject, ScriptFunction and ScriptFunction
Reviewed-by: lagergren, attila, hannesw
1.1 --- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Fri Aug 09 20:48:44 2013 +0530 1.2 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Mon Aug 12 14:43:53 2013 +0530 1.3 @@ -489,20 +489,6 @@ 1.4 } 1.5 1.6 /** 1.7 - * Create a static call, looking up the method handle for it at the same time 1.8 - * 1.9 - * @param clazz the class 1.10 - * @param name the name of the method 1.11 - * @param rtype the return type of the method 1.12 - * @param ptypes the parameter types of the method 1.13 - * 1.14 - * @return the call object representing the static call 1.15 - */ 1.16 - public static Call staticCall(final Class<?> clazz, final String name, final Class<?> rtype, final Class<?>... ptypes) { 1.17 - return staticCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); 1.18 - } 1.19 - 1.20 - /** 1.21 * Create a static call, given an explicit lookup, looking up the method handle for it at the same time 1.22 * 1.23 * @param lookup the lookup 1.24 @@ -523,20 +509,6 @@ 1.25 } 1.26 1.27 /** 1.28 - * Create a virtual call, looking up the method handle for it at the same time 1.29 - * 1.30 - * @param clazz the class 1.31 - * @param name the name of the method 1.32 - * @param rtype the return type of the method 1.33 - * @param ptypes the parameter types of the method 1.34 - * 1.35 - * @return the call object representing the virtual call 1.36 - */ 1.37 - public static Call virtualCall(final Class<?> clazz, final String name, final Class<?> rtype, final Class<?>... ptypes) { 1.38 - return virtualCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); 1.39 - } 1.40 - 1.41 - /** 1.42 * Create a virtual call, given an explicit lookup, looking up the method handle for it at the same time 1.43 * 1.44 * @param lookup the lookup
2.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Fri Aug 09 20:48:44 2013 +0530 2.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Mon Aug 12 14:43:53 2013 +0530 2.3 @@ -28,6 +28,7 @@ 2.4 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; 2.5 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 2.6 2.7 +import java.lang.invoke.MethodHandles; 2.8 import java.util.Locale; 2.9 import jdk.internal.dynalink.beans.BeansLinker; 2.10 import jdk.internal.dynalink.beans.StaticClass; 2.11 @@ -63,47 +64,49 @@ 2.12 /** Max value for an uint32 in JavaScript */ 2.13 public static final long MAX_UINT = 0xFFFF_FFFFL; 2.14 2.15 + private static final MethodHandles.Lookup myLookup = MethodHandles.lookup(); 2.16 + 2.17 /** JavaScript compliant conversion function from Object to boolean */ 2.18 - public static final Call TO_BOOLEAN = staticCall(JSType.class, "toBoolean", boolean.class, Object.class); 2.19 + public static final Call TO_BOOLEAN = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, Object.class); 2.20 2.21 /** JavaScript compliant conversion function from number to boolean */ 2.22 - public static final Call TO_BOOLEAN_D = staticCall(JSType.class, "toBoolean", boolean.class, double.class); 2.23 + public static final Call TO_BOOLEAN_D = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, double.class); 2.24 2.25 /** JavaScript compliant conversion function from Object to integer */ 2.26 - public static final Call TO_INTEGER = staticCall(JSType.class, "toInteger", int.class, Object.class); 2.27 + public static final Call TO_INTEGER = staticCall(myLookup, JSType.class, "toInteger", int.class, Object.class); 2.28 2.29 /** JavaScript compliant conversion function from Object to long */ 2.30 - public static final Call TO_LONG = staticCall(JSType.class, "toLong", long.class, Object.class); 2.31 + public static final Call TO_LONG = staticCall(myLookup, JSType.class, "toLong", long.class, Object.class); 2.32 2.33 /** JavaScript compliant conversion function from Object to number */ 2.34 - public static final Call TO_NUMBER = staticCall(JSType.class, "toNumber", double.class, Object.class); 2.35 + public static final Call TO_NUMBER = staticCall(myLookup, JSType.class, "toNumber", double.class, Object.class); 2.36 2.37 /** JavaScript compliant conversion function from Object to int32 */ 2.38 - public static final Call TO_INT32 = staticCall(JSType.class, "toInt32", int.class, Object.class); 2.39 + public static final Call TO_INT32 = staticCall(myLookup, JSType.class, "toInt32", int.class, Object.class); 2.40 2.41 /** JavaScript compliant conversion function from double to int32 */ 2.42 - public static final Call TO_INT32_D = staticCall(JSType.class, "toInt32", int.class, double.class); 2.43 + public static final Call TO_INT32_D = staticCall(myLookup, JSType.class, "toInt32", int.class, double.class); 2.44 2.45 /** JavaScript compliant conversion function from Object to uint32 */ 2.46 - public static final Call TO_UINT32 = staticCall(JSType.class, "toUint32", long.class, Object.class); 2.47 + public static final Call TO_UINT32 = staticCall(myLookup, JSType.class, "toUint32", long.class, Object.class); 2.48 2.49 /** JavaScript compliant conversion function from number to uint32 */ 2.50 - public static final Call TO_UINT32_D = staticCall(JSType.class, "toUint32", long.class, double.class); 2.51 + public static final Call TO_UINT32_D = staticCall(myLookup, JSType.class, "toUint32", long.class, double.class); 2.52 2.53 /** JavaScript compliant conversion function from Object to int64 */ 2.54 - public static final Call TO_INT64 = staticCall(JSType.class, "toInt64", long.class, Object.class); 2.55 + public static final Call TO_INT64 = staticCall(myLookup, JSType.class, "toInt64", long.class, Object.class); 2.56 2.57 /** JavaScript compliant conversion function from number to int64 */ 2.58 - public static final Call TO_INT64_D = staticCall(JSType.class, "toInt64", long.class, double.class); 2.59 + public static final Call TO_INT64_D = staticCall(myLookup, JSType.class, "toInt64", long.class, double.class); 2.60 2.61 /** JavaScript compliant conversion function from Object to String */ 2.62 - public static final Call TO_STRING = staticCall(JSType.class, "toString", String.class, Object.class); 2.63 + public static final Call TO_STRING = staticCall(myLookup, JSType.class, "toString", String.class, Object.class); 2.64 2.65 /** JavaScript compliant conversion function from number to String */ 2.66 - public static final Call TO_STRING_D = staticCall(JSType.class, "toString", String.class, double.class); 2.67 + public static final Call TO_STRING_D = staticCall(myLookup, JSType.class, "toString", String.class, double.class); 2.68 2.69 /** JavaScript compliant conversion function from Object to primitive */ 2.70 - public static final Call TO_PRIMITIVE = staticCall(JSType.class, "toPrimitive", Object.class, Object.class); 2.71 + public static final Call TO_PRIMITIVE = staticCall(myLookup, JSType.class, "toPrimitive", Object.class, Object.class); 2.72 2.73 private static final double INT32_LIMIT = 4294967296.0; 2.74
3.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Aug 09 20:48:44 2013 +0530 3.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Aug 12 14:43:53 2013 +0530 3.3 @@ -138,10 +138,10 @@ 3.4 private static final MethodHandle KNOWNFUNCPROPGUARD = findOwnMH("knownFunctionPropertyGuard", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, Object.class, ScriptFunction.class); 3.5 3.6 /** Method handle for getting a function argument at a given index. Used from MapCreator */ 3.7 - public static final Call GET_ARGUMENT = virtualCall(ScriptObject.class, "getArgument", Object.class, int.class); 3.8 + public static final Call GET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArgument", Object.class, int.class); 3.9 3.10 /** Method handle for setting a function argument at a given index. Used from MapCreator */ 3.11 - public static final Call SET_ARGUMENT = virtualCall(ScriptObject.class, "setArgument", void.class, int.class, Object.class); 3.12 + public static final Call SET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setArgument", void.class, int.class, Object.class); 3.13 3.14 /** Method handle for getting the proto of a ScriptObject */ 3.15 public static final Call GET_PROTO = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class); 3.16 @@ -150,7 +150,7 @@ 3.17 public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class); 3.18 3.19 /** Method handle for setting the user accessors of a ScriptObject */ 3.20 - public static final Call SET_USER_ACCESSORS = virtualCall(ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 3.21 + public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 3.22 3.23 /** 3.24 * Constructor
4.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Fri Aug 09 20:48:44 2013 +0530 4.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Mon Aug 12 14:43:53 2013 +0530 4.3 @@ -33,6 +33,7 @@ 4.4 import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt; 4.5 4.6 import java.lang.invoke.MethodHandle; 4.7 +import java.lang.invoke.MethodHandles; 4.8 import java.lang.reflect.Array; 4.9 import java.util.Collections; 4.10 import java.util.Iterator; 4.11 @@ -100,7 +101,7 @@ 4.12 * call sites that are known to be megamorphic. Using an invoke dynamic here would 4.13 * lead to the JVM deoptimizing itself to death 4.14 */ 4.15 - public static final Call APPLY = staticCall(ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); 4.16 + public static final Call APPLY = staticCall(MethodHandles.lookup(), ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); 4.17 4.18 /** 4.19 * Converts a switch tag value to a simple integer. deflt value if it can't.