# HG changeset patch # User sundar # Date 1376298833 -19800 # Node ID 01304b0550fbbbb74b3b469b90955b4e36ae2bf0 # Parent 47e2b609fe3141bd1b4beea79f61ebc1cd383b5c 8022782: publicLookup access failures in ScriptObject, ScriptFunction and ScriptFunction Reviewed-by: lagergren, attila, hannesw diff -r 47e2b609fe31 -r 01304b0550fb src/jdk/nashorn/internal/codegen/CompilerConstants.java --- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Fri Aug 09 20:48:44 2013 +0530 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Mon Aug 12 14:43:53 2013 +0530 @@ -489,20 +489,6 @@ } /** - * Create a static call, looking up the method handle for it at the same time - * - * @param clazz the class - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * - * @return the call object representing the static call - */ - public static Call staticCall(final Class clazz, final String name, final Class rtype, final Class... ptypes) { - return staticCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); - } - - /** * Create a static call, given an explicit lookup, looking up the method handle for it at the same time * * @param lookup the lookup @@ -523,20 +509,6 @@ } /** - * Create a virtual call, looking up the method handle for it at the same time - * - * @param clazz the class - * @param name the name of the method - * @param rtype the return type of the method - * @param ptypes the parameter types of the method - * - * @return the call object representing the virtual call - */ - public static Call virtualCall(final Class clazz, final String name, final Class rtype, final Class... ptypes) { - return virtualCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); - } - - /** * Create a virtual call, given an explicit lookup, looking up the method handle for it at the same time * * @param lookup the lookup diff -r 47e2b609fe31 -r 01304b0550fb src/jdk/nashorn/internal/runtime/JSType.java --- a/src/jdk/nashorn/internal/runtime/JSType.java Fri Aug 09 20:48:44 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Mon Aug 12 14:43:53 2013 +0530 @@ -28,6 +28,7 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; +import java.lang.invoke.MethodHandles; import java.util.Locale; import jdk.internal.dynalink.beans.BeansLinker; import jdk.internal.dynalink.beans.StaticClass; @@ -63,47 +64,49 @@ /** Max value for an uint32 in JavaScript */ public static final long MAX_UINT = 0xFFFF_FFFFL; + private static final MethodHandles.Lookup myLookup = MethodHandles.lookup(); + /** JavaScript compliant conversion function from Object to boolean */ - public static final Call TO_BOOLEAN = staticCall(JSType.class, "toBoolean", boolean.class, Object.class); + public static final Call TO_BOOLEAN = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, Object.class); /** JavaScript compliant conversion function from number to boolean */ - public static final Call TO_BOOLEAN_D = staticCall(JSType.class, "toBoolean", boolean.class, double.class); + public static final Call TO_BOOLEAN_D = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, double.class); /** JavaScript compliant conversion function from Object to integer */ - public static final Call TO_INTEGER = staticCall(JSType.class, "toInteger", int.class, Object.class); + public static final Call TO_INTEGER = staticCall(myLookup, JSType.class, "toInteger", int.class, Object.class); /** JavaScript compliant conversion function from Object to long */ - public static final Call TO_LONG = staticCall(JSType.class, "toLong", long.class, Object.class); + public static final Call TO_LONG = staticCall(myLookup, JSType.class, "toLong", long.class, Object.class); /** JavaScript compliant conversion function from Object to number */ - public static final Call TO_NUMBER = staticCall(JSType.class, "toNumber", double.class, Object.class); + public static final Call TO_NUMBER = staticCall(myLookup, JSType.class, "toNumber", double.class, Object.class); /** JavaScript compliant conversion function from Object to int32 */ - public static final Call TO_INT32 = staticCall(JSType.class, "toInt32", int.class, Object.class); + public static final Call TO_INT32 = staticCall(myLookup, JSType.class, "toInt32", int.class, Object.class); /** JavaScript compliant conversion function from double to int32 */ - public static final Call TO_INT32_D = staticCall(JSType.class, "toInt32", int.class, double.class); + public static final Call TO_INT32_D = staticCall(myLookup, JSType.class, "toInt32", int.class, double.class); /** JavaScript compliant conversion function from Object to uint32 */ - public static final Call TO_UINT32 = staticCall(JSType.class, "toUint32", long.class, Object.class); + public static final Call TO_UINT32 = staticCall(myLookup, JSType.class, "toUint32", long.class, Object.class); /** JavaScript compliant conversion function from number to uint32 */ - public static final Call TO_UINT32_D = staticCall(JSType.class, "toUint32", long.class, double.class); + public static final Call TO_UINT32_D = staticCall(myLookup, JSType.class, "toUint32", long.class, double.class); /** JavaScript compliant conversion function from Object to int64 */ - public static final Call TO_INT64 = staticCall(JSType.class, "toInt64", long.class, Object.class); + public static final Call TO_INT64 = staticCall(myLookup, JSType.class, "toInt64", long.class, Object.class); /** JavaScript compliant conversion function from number to int64 */ - public static final Call TO_INT64_D = staticCall(JSType.class, "toInt64", long.class, double.class); + public static final Call TO_INT64_D = staticCall(myLookup, JSType.class, "toInt64", long.class, double.class); /** JavaScript compliant conversion function from Object to String */ - public static final Call TO_STRING = staticCall(JSType.class, "toString", String.class, Object.class); + public static final Call TO_STRING = staticCall(myLookup, JSType.class, "toString", String.class, Object.class); /** JavaScript compliant conversion function from number to String */ - public static final Call TO_STRING_D = staticCall(JSType.class, "toString", String.class, double.class); + public static final Call TO_STRING_D = staticCall(myLookup, JSType.class, "toString", String.class, double.class); /** JavaScript compliant conversion function from Object to primitive */ - public static final Call TO_PRIMITIVE = staticCall(JSType.class, "toPrimitive", Object.class, Object.class); + public static final Call TO_PRIMITIVE = staticCall(myLookup, JSType.class, "toPrimitive", Object.class, Object.class); private static final double INT32_LIMIT = 4294967296.0; diff -r 47e2b609fe31 -r 01304b0550fb src/jdk/nashorn/internal/runtime/ScriptObject.java --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Fri Aug 09 20:48:44 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Mon Aug 12 14:43:53 2013 +0530 @@ -138,10 +138,10 @@ private static final MethodHandle KNOWNFUNCPROPGUARD = findOwnMH("knownFunctionPropertyGuard", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, Object.class, ScriptFunction.class); /** Method handle for getting a function argument at a given index. Used from MapCreator */ - public static final Call GET_ARGUMENT = virtualCall(ScriptObject.class, "getArgument", Object.class, int.class); + public static final Call GET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArgument", Object.class, int.class); /** Method handle for setting a function argument at a given index. Used from MapCreator */ - public static final Call SET_ARGUMENT = virtualCall(ScriptObject.class, "setArgument", void.class, int.class, Object.class); + public static final Call SET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setArgument", void.class, int.class, Object.class); /** Method handle for getting the proto of a ScriptObject */ public static final Call GET_PROTO = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class); @@ -150,7 +150,7 @@ public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class); /** Method handle for setting the user accessors of a ScriptObject */ - public static final Call SET_USER_ACCESSORS = virtualCall(ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); + public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); /** * Constructor diff -r 47e2b609fe31 -r 01304b0550fb src/jdk/nashorn/internal/runtime/ScriptRuntime.java --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Fri Aug 09 20:48:44 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Mon Aug 12 14:43:53 2013 +0530 @@ -33,6 +33,7 @@ import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt; import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; import java.lang.reflect.Array; import java.util.Collections; import java.util.Iterator; @@ -100,7 +101,7 @@ * call sites that are known to be megamorphic. Using an invoke dynamic here would * lead to the JVM deoptimizing itself to death */ - public static final Call APPLY = staticCall(ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); + public static final Call APPLY = staticCall(MethodHandles.lookup(), ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); /** * Converts a switch tag value to a simple integer. deflt value if it can't.