jdk8/jdk8/nashorn: 5759f600fcf7 (original) (raw)
--- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Wed Mar 06 22:38:18 2013 +0530 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Sat Mar 09 21:49:32 2013 +0530 @@ -28,12 +28,12 @@ import java.lang.invoke.MethodHandle; import java.lang.reflect.Method; import jdk.internal.org.objectweb.asm.Type; +import jdk.nashorn.internal.lookup.Lookup; import jdk.nashorn.internal.objects.PrototypeObject; import jdk.nashorn.internal.objects.ScriptFunctionImpl; import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptObject; -import jdk.nashorn.internal.runtime.linker.Lookup; /**
--- a/make/java.security.override Wed Mar 06 22:38:18 2013 +0530 +++ b/make/java.security.override Sat Mar 09 21:49:32 2013 +0530 @@ -11,4 +11,4 @@
passed to checkPackageAccess unless the
corresponding RuntimePermission ("accessClassInPackage."+package) has
been granted.
-package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.glassfish.external.,com.sun.org.glassfish.gmbal.,jdk.internal.,jdk.nashorn.internal.ir., jdk.nashorn.internal.codegen., jdk.nashorn.internal.parser. +package.access=sun.,com.sun.xml.internal.ws.,com.sun.xml.internal.bind.,com.sun.imageio.,com.sun.org.apache.xerces.internal.utils.,com.sun.org.apache.xalan.internal.utils.,com.sun.org.glassfish.external.,com.sun.org.glassfish.gmbal.,jdk.internal.,jdk.nashorn.internal.ir., jdk.nashorn.internal.codegen., jdk.nashorn.internal.lookup., jdk.nashorn.internal.parser.
--- a/src/jdk/internal/dynalink/beans/CheckRestrictedPackage.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/internal/dynalink/beans/CheckRestrictedPackage.java Sat Mar 09 21:49:32 2013 +0530 @@ -84,26 +84,55 @@ package jdk.internal.dynalink.beans; import java.lang.reflect.Modifier; +import java.security.AccessControlContext; +import java.security.AccessController; +import java.security.Permissions; +import java.security.PrivilegedAction; +import java.security.ProtectionDomain; /**
+ /** * Returns true if the class is either not public, or it resides in a package with restricted access. * @param clazz the class to test * @return true if the class is either not public, or it resides in a package with restricted access. */ static boolean isRestrictedClass(Class<?> clazz) {
return !Modifier.isPublic(clazz.getModifiers()) ||[](#l3.27)
(System.getSecurityManager() != null && isRestrictedPackage(clazz.getPackage()));[](#l3.28)
if(!Modifier.isPublic(clazz.getModifiers())) {[](#l3.29)
// Non-public classes are always restricted[](#l3.30)
return true;[](#l3.31)
}[](#l3.32)
final SecurityManager sm = System.getSecurityManager();[](#l3.33)
if(sm == null) {[](#l3.34)
// No further restrictions if we don't have a security manager[](#l3.35)
return false;[](#l3.36)
}[](#l3.37)
final String name = clazz.getName();[](#l3.38)
final int i = name.lastIndexOf('.');[](#l3.39)
if (i == -1) {[](#l3.40)
// Classes in default package are never restricted[](#l3.41)
return false;[](#l3.42)
}[](#l3.43)
// Do a package access check from within an access control context with no permissions[](#l3.44)
try {[](#l3.45)
AccessController.doPrivileged(new PrivilegedAction<Void>() {[](#l3.46)
@Override[](#l3.47)
public Void run() {[](#l3.48)
sm.checkPackageAccess(name.substring(0, i));[](#l3.49)
return null;[](#l3.50)
}[](#l3.51)
}, NO_PERMISSIONS_CONTEXT);[](#l3.52)
} catch(SecurityException e) {[](#l3.53)
return true;[](#l3.54)
}[](#l3.55)
}return false;[](#l3.56)
- private static boolean isRestrictedPackage(Package pkg) {
// Note: we broke out the actual implementation into CheckRestrictedPackageInternal, so we only load it when[](#l3.60)
// needed - that is, if we need to check a non-public class with a non-null package, in presence of a security[](#l3.61)
// manager.[](#l3.62)
return pkg == null ? false : CheckRestrictedPackageInternal.isRestrictedPackageName(pkg.getName());[](#l3.63)
- private static AccessControlContext createNoPermissionsContext() {
} }return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) });[](#l3.65)
--- a/src/jdk/internal/dynalink/beans/CheckRestrictedPackageInternal.java Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,252 +0,0 @@ -/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / - -/
- / -/
- Copyright 2009-2013 Attila Szegedi -
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. -
- You may not use this file except in compliance with either the Apache
- License or the BSD License. -
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: -
You may obtain a copy of the Apache License at[](#l4.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l4.51)
Unless required by applicable law or agreed to in writing, software[](#l4.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l4.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l4.55)
implied. See the License for the specific language governing[](#l4.56)
permissions and limitations under the License.[](#l4.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: -
Redistribution and use in source and binary forms, with or without[](#l4.62)
modification, are permitted provided that the following conditions are[](#l4.63)
met:[](#l4.64)
* Redistributions of source code must retain the above copyright[](#l4.65)
notice, this list of conditions and the following disclaimer.[](#l4.66)
* Redistributions in binary form must reproduce the above copyright[](#l4.67)
notice, this list of conditions and the following disclaimer in the[](#l4.68)
documentation and/or other materials provided with the distribution.[](#l4.69)
* Neither the name of the copyright holder nor the names of[](#l4.70)
contributors may be used to endorse or promote products derived from[](#l4.71)
this software without specific prior written permission.[](#l4.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l4.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l4.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l4.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l4.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l4.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l4.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l4.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l4.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l4.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l4.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l4.84)
-*/ - -package jdk.internal.dynalink.beans; - -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.reflect.Method; -import java.security.AccessController; -import java.security.Permissions; -import java.security.PrivilegedAction; -import java.security.ProtectionDomain; -import java.security.SecureClassLoader; - -/**
- *
- *
- *
- *
- *
- */ -class CheckRestrictedPackageInternal {
- private static final MethodHandle PACKAGE_ACCESS_CHECK = getPackageAccessCheckMethod();
- private static final String TESTER_CLASS_NAME = "jdk.internal.dynalink.beans.RestrictedPackageTester";
- /**
* Returns true if the specified package has restricted access.[](#l4.139)
* @param pkgName the name of the package to check.[](#l4.140)
* @return true if the specified package has restricted access, false otherwise.[](#l4.141)
* @throws NullPointerException if pkgName is null, or if there is {@link System#getSecurityManager()} returns null[](#l4.142)
* as this method is only expected to be invoked in the presence of a security manager.[](#l4.143)
*/[](#l4.144)
- static boolean isRestrictedPackageName(String pkgName) {
try {[](#l4.146)
if(PACKAGE_ACCESS_CHECK != null) {[](#l4.147)
// If we were able to load our unprivileged tester class, use it to check package access[](#l4.148)
try {[](#l4.149)
PACKAGE_ACCESS_CHECK.invokeExact(pkgName);[](#l4.150)
} catch(Error|RuntimeException e) {[](#l4.151)
throw e;[](#l4.152)
} catch(Throwable t) {[](#l4.153)
throw new RuntimeException(t);[](#l4.154)
}[](#l4.155)
} else {[](#l4.156)
// If we didn't have sufficient permissions to load our unprivileged tester class, we're definitely not[](#l4.157)
// running in a privileged class path, so invoking SecurityManager.checkPackageAccess() directly should[](#l4.158)
// have the same effect as going through an unprivileged tester.[](#l4.159)
System.getSecurityManager().checkPackageAccess(pkgName);[](#l4.160)
}[](#l4.161)
return false;[](#l4.162)
} catch(SecurityException e) {[](#l4.163)
return true;[](#l4.164)
}[](#l4.165)
- }
- private static MethodHandle getPackageAccessCheckMethod() {
try {[](#l4.169)
return AccessController.doPrivileged(new PrivilegedAction<MethodHandle>() {[](#l4.170)
@Override[](#l4.171)
public MethodHandle run() {[](#l4.172)
return getPackageAccessCheckMethodInternal();[](#l4.173)
}[](#l4.174)
});[](#l4.175)
} catch(SecurityException e) {[](#l4.176)
// We don't have sufficient privileges to load our tester class into a separate protection domain, so just[](#l4.177)
// return null so isRestrictedPackageName() will default to itself invoking[](#l4.178)
// SecurityManager.checkPackageAccess().[](#l4.179)
return null;[](#l4.180)
}[](#l4.181)
- }
- static MethodHandle getPackageAccessCheckMethodInternal() {
try {[](#l4.185)
// Can't use MethodHandles.lookup().findStatic() -- even though both this class and the loaded class are in[](#l4.186)
// the same package, findStatic() will throw an IllegalAccessException since they have different class[](#l4.187)
// loaders. That's why we have to use unreflect with a setAccessible(true)...[](#l4.188)
final Method m = getTesterClass().getDeclaredMethod("checkPackageAccess", String.class);[](#l4.189)
m.setAccessible(true);[](#l4.190)
return MethodHandles.lookup().unreflect(m);[](#l4.191)
} catch(IllegalAccessException|NoSuchMethodException e) {[](#l4.192)
throw new AssertionError(e);[](#l4.193)
}[](#l4.194)
- }
- private static Class<?> getTesterClass() {
final ClassLoader loader = getTesterClassLoader();[](#l4.198)
try {[](#l4.199)
final Class<?> checkerClass = Class.forName(TESTER_CLASS_NAME, true, loader);[](#l4.200)
// Sanity check to ensure we didn't accidentally pick up the class from elsewhere[](#l4.201)
if(checkerClass.getClassLoader() != loader) {[](#l4.202)
throw new AssertionError(TESTER_CLASS_NAME + " was loaded from a different class loader");[](#l4.203)
}[](#l4.204)
return checkerClass;[](#l4.205)
} catch(ClassNotFoundException e) {[](#l4.206)
throw new AssertionError(e);[](#l4.207)
}[](#l4.208)
- }
- private static ClassLoader getTesterClassLoader() {
// We deliberately override loadClass instead of findClass so that we don't give a chance to finding this[](#l4.212)
// class already loaded anywhere else. Not that there's a big possibility for this, especially since the parent[](#l4.213)
// class loader is the bootstrap class loader, but still...[](#l4.214)
return new SecureClassLoader(null) {[](#l4.215)
@Override[](#l4.217)
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {[](#l4.218)
if(name.equals(TESTER_CLASS_NAME)) {[](#l4.219)
final byte[] bytes = getTesterClassBytes();[](#l4.220)
// Define the class with a protection domain that grants no permissions.[](#l4.221)
Class<?> clazz = defineClass(name, bytes, 0, bytes.length, new ProtectionDomain(null,[](#l4.222)
new Permissions()));[](#l4.223)
if(resolve) {[](#l4.224)
resolveClass(clazz);[](#l4.225)
}[](#l4.226)
return clazz;[](#l4.227)
}[](#l4.228)
- static byte[] getTesterClassBytes() {
try {[](#l4.236)
final InputStream in = CheckRestrictedPackage.class.getResourceAsStream("RestrictedPackageTester.class");[](#l4.237)
try {[](#l4.238)
final ByteArrayOutputStream out = new ByteArrayOutputStream(2048);[](#l4.239)
for(;;) {[](#l4.240)
final int b = in.read();[](#l4.241)
if(b == -1) {[](#l4.242)
break;[](#l4.243)
}[](#l4.244)
out.write(b);[](#l4.245)
}[](#l4.246)
return out.toByteArray();[](#l4.247)
} finally {[](#l4.248)
in.close();[](#l4.249)
}[](#l4.250)
} catch(IOException e) {[](#l4.251)
throw new RuntimeException(e);[](#l4.252)
}[](#l4.253)
- }
--- a/src/jdk/internal/dynalink/beans/FacetIntrospector.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/internal/dynalink/beans/FacetIntrospector.java Sat Mar 09 21:49:32 2013 +0530 @@ -92,7 +92,6 @@ import java.util.Collection; import java.util.Collections; import java.util.Map; -import jdk.internal.dynalink.support.Lookup; /**
- Base for classes that expose class field and method information to an {@link AbstractJavaLinker}. There are @@ -161,15 +160,15 @@
MethodHandle unreflectGetter(Field field) {
return editMethodHandle(Lookup.PUBLIC.unreflectGetter(field));[](#l5.15)
} MethodHandle unreflectSetter(Field field) {return editMethodHandle(SafeUnreflector.unreflectGetter(field));[](#l5.16)
return editMethodHandle(Lookup.PUBLIC.unreflectSetter(field));[](#l5.20)
} MethodHandle unreflect(Method method) {return editMethodHandle(SafeUnreflector.unreflectSetter(field));[](#l5.21)
return editMethodHandle(Lookup.PUBLIC.unreflect(method));[](#l5.25)
--- a/src/jdk/internal/dynalink/beans/RestrictedPackageTester.java Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,113 +0,0 @@ -/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / - -/
- / -/
- Copyright 2009-2013 Attila Szegedi -
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. -
- You may not use this file except in compliance with either the Apache
- License or the BSD License. -
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: -
You may obtain a copy of the Apache License at[](#l6.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l6.51)
Unless required by applicable law or agreed to in writing, software[](#l6.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l6.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l6.55)
implied. See the License for the specific language governing[](#l6.56)
permissions and limitations under the License.[](#l6.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: -
Redistribution and use in source and binary forms, with or without[](#l6.62)
modification, are permitted provided that the following conditions are[](#l6.63)
met:[](#l6.64)
* Redistributions of source code must retain the above copyright[](#l6.65)
notice, this list of conditions and the following disclaimer.[](#l6.66)
* Redistributions in binary form must reproduce the above copyright[](#l6.67)
notice, this list of conditions and the following disclaimer in the[](#l6.68)
documentation and/or other materials provided with the distribution.[](#l6.69)
* Neither the name of the copyright holder nor the names of[](#l6.70)
contributors may be used to endorse or promote products derived from[](#l6.71)
this software without specific prior written permission.[](#l6.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l6.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l6.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l6.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l6.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l6.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l6.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l6.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l6.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l6.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l6.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l6.84)
-*/ - -package jdk.internal.dynalink.beans; - -import java.security.AccessController; -import java.security.PrivilegedAction; - -/**
- static void checkPackageAccess(String pkgName) {
AccessController.doPrivileged(new RestrictedPackageTester(pkgName));[](#l6.108)
- }
- @Override
- public Void run() {
System.getSecurityManager().checkPackageAccess(pkgName);[](#l6.113)
return null;[](#l6.114)
- }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/internal/dynalink/beans/SafeUnreflector.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,156 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / + +/
- / +/
- Copyright 2009-2013 Attila Szegedi +
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. +
- You may not use this file except in compliance with either the Apache
- License or the BSD License. +
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: +
You may obtain a copy of the Apache License at[](#l7.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l7.51)
Unless required by applicable law or agreed to in writing, software[](#l7.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l7.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l7.55)
implied. See the License for the specific language governing[](#l7.56)
permissions and limitations under the License.[](#l7.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: +
Redistribution and use in source and binary forms, with or without[](#l7.62)
modification, are permitted provided that the following conditions are[](#l7.63)
met:[](#l7.64)
* Redistributions of source code must retain the above copyright[](#l7.65)
notice, this list of conditions and the following disclaimer.[](#l7.66)
* Redistributions in binary form must reproduce the above copyright[](#l7.67)
notice, this list of conditions and the following disclaimer in the[](#l7.68)
documentation and/or other materials provided with the distribution.[](#l7.69)
* Neither the name of the copyright holder nor the names of[](#l7.70)
contributors may be used to endorse or promote products derived from[](#l7.71)
this software without specific prior written permission.[](#l7.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l7.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l7.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l7.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l7.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l7.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l7.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l7.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l7.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l7.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l7.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l7.84)
+*/ + +package jdk.internal.dynalink.beans; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import java.security.AccessController; +import java.security.PrivilegedAction; +import jdk.internal.dynalink.beans.sandbox.Unreflector; + +/**
- */ +final class SafeUnreflector {
- private static final String UNREFLECTOR_IMPL_CLASS_NAME = "jdk.internal.dynalink.beans.SafeUnreflectorImpl";
- private static final Unreflector impl = createImpl();
- /**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}, converting any encountered[](#l7.110)
* {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l7.111)
*[](#l7.112)
* @param m the method to unreflect[](#l7.113)
* @return the unreflected method handle.[](#l7.114)
*/[](#l7.115)
- static MethodHandle unreflect(Method m) {
return impl.unreflect(m);[](#l7.117)
- }
- /**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)}, converting any encountered[](#l7.121)
* {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l7.122)
*[](#l7.123)
* @param f the field for which a getter is unreflected[](#l7.124)
* @return the unreflected field getter handle.[](#l7.125)
*/[](#l7.126)
- static MethodHandle unreflectGetter(Field f) {
return impl.unreflectGetter(f);[](#l7.128)
- }
- /**
* Performs a {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)}, converting any encountered[](#l7.132)
* {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l7.133)
*[](#l7.134)
* @param f the field for which a setter is unreflected[](#l7.135)
* @return the unreflected field setter handle.[](#l7.136)
*/[](#l7.137)
- static MethodHandle unreflectSetter(Field f) {
return impl.unreflectSetter(f);[](#l7.139)
- }
- static MethodHandle unreflectConstructor(Constructor<?> c) {
return impl.unreflectConstructor(c);[](#l7.143)
- }
- private static Unreflector createImpl() {
final Class<?> unreflectorImplClass = AccessController.doPrivileged(new PrivilegedAction<Class<?>>() {[](#l7.147)
@Override[](#l7.148)
public Class<?> run() {[](#l7.149)
return SandboxClassLoader.loadClass(UNREFLECTOR_IMPL_CLASS_NAME);[](#l7.150)
}[](#l7.151)
});[](#l7.152)
try {[](#l7.153)
return (Unreflector)unreflectorImplClass.newInstance();[](#l7.154)
} catch(InstantiationException | IllegalAccessException e) {[](#l7.155)
throw new RuntimeException(e.getMessage(), e);[](#l7.156)
}[](#l7.157)
- }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/internal/dynalink/beans/SafeUnreflectorImpl.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,146 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / + +/
- / +/
- Copyright 2009-2013 Attila Szegedi +
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. +
- You may not use this file except in compliance with either the Apache
- License or the BSD License. +
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: +
You may obtain a copy of the Apache License at[](#l8.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l8.51)
Unless required by applicable law or agreed to in writing, software[](#l8.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l8.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l8.55)
implied. See the License for the specific language governing[](#l8.56)
permissions and limitations under the License.[](#l8.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: +
Redistribution and use in source and binary forms, with or without[](#l8.62)
modification, are permitted provided that the following conditions are[](#l8.63)
met:[](#l8.64)
* Redistributions of source code must retain the above copyright[](#l8.65)
notice, this list of conditions and the following disclaimer.[](#l8.66)
* Redistributions in binary form must reproduce the above copyright[](#l8.67)
notice, this list of conditions and the following disclaimer in the[](#l8.68)
documentation and/or other materials provided with the distribution.[](#l8.69)
* Neither the name of the copyright holder nor the names of[](#l8.70)
contributors may be used to endorse or promote products derived from[](#l8.71)
this software without specific prior written permission.[](#l8.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l8.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l8.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l8.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l8.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l8.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l8.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l8.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l8.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l8.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l8.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l8.84)
+*/ + +package jdk.internal.dynalink.beans; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; +import jdk.internal.dynalink.beans.sandbox.Unreflector; + +/**
- @Override
- public MethodHandle unreflect(Method m) {
try {[](#l8.108)
return MethodHandles.lookup().unreflect(m);[](#l8.109)
} catch(IllegalAccessException e) {[](#l8.110)
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect method " + m);[](#l8.111)
ee.initCause(e);[](#l8.112)
throw ee;[](#l8.113)
}[](#l8.114)
- }
- @Override
- public MethodHandle unreflectGetter(Field f) {
try {[](#l8.119)
return MethodHandles.lookup().unreflectGetter(f);[](#l8.120)
} catch(IllegalAccessException e) {[](#l8.121)
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect getter for field " + f);[](#l8.122)
ee.initCause(e);[](#l8.123)
throw ee;[](#l8.124)
}[](#l8.125)
- }
- @Override
- public MethodHandle unreflectSetter(Field f) {
try {[](#l8.130)
return MethodHandles.lookup().unreflectSetter(f);[](#l8.131)
} catch(IllegalAccessException e) {[](#l8.132)
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect setter for field " + f);[](#l8.133)
ee.initCause(e);[](#l8.134)
throw ee;[](#l8.135)
}[](#l8.136)
- }
- @Override
- public MethodHandle unreflectConstructor(Constructor<?> c) {
try {[](#l8.141)
return MethodHandles.lookup().unreflectConstructor(c);[](#l8.142)
} catch(IllegalAccessException e) {[](#l8.143)
final IllegalAccessError ee = new IllegalAccessError("Failed to unreflect constructor " + c);[](#l8.144)
ee.initCause(e);[](#l8.145)
throw ee;[](#l8.146)
}[](#l8.147)
- }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/internal/dynalink/beans/SandboxClassLoader.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,228 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / + +/
- / +/
- Copyright 2009-2013 Attila Szegedi +
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. +
- You may not use this file except in compliance with either the Apache
- License or the BSD License. +
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: +
You may obtain a copy of the Apache License at[](#l9.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l9.51)
Unless required by applicable law or agreed to in writing, software[](#l9.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l9.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l9.55)
implied. See the License for the specific language governing[](#l9.56)
permissions and limitations under the License.[](#l9.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: +
Redistribution and use in source and binary forms, with or without[](#l9.62)
modification, are permitted provided that the following conditions are[](#l9.63)
met:[](#l9.64)
* Redistributions of source code must retain the above copyright[](#l9.65)
notice, this list of conditions and the following disclaimer.[](#l9.66)
* Redistributions in binary form must reproduce the above copyright[](#l9.67)
notice, this list of conditions and the following disclaimer in the[](#l9.68)
documentation and/or other materials provided with the distribution.[](#l9.69)
* Neither the name of the copyright holder nor the names of[](#l9.70)
contributors may be used to endorse or promote products derived from[](#l9.71)
this software without specific prior written permission.[](#l9.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l9.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l9.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l9.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l9.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l9.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l9.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l9.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l9.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l9.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l9.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l9.84)
+*/ + +package jdk.internal.dynalink.beans; + +import static jdk.internal.org.objectweb.asm.Opcodes.ACC_PUBLIC; +import static jdk.internal.org.objectweb.asm.Opcodes.ASM4; + +import java.io.IOException; +import java.io.InputStream; +import java.security.Permissions; +import java.security.ProtectionDomain; +import java.security.SecureClassLoader; +import java.security.SecureRandom; +import jdk.internal.org.objectweb.asm.ClassReader; +import jdk.internal.org.objectweb.asm.ClassVisitor; +import jdk.internal.org.objectweb.asm.ClassWriter; +import jdk.internal.org.objectweb.asm.MethodVisitor; + +/**
- */ +final class SandboxClassLoader {
- private final String className;
- private final String randomizedClassName;
- private SandboxClassLoader(String className) {
this.className = className;[](#l9.115)
final String simpleClassName = className.substring(className.lastIndexOf('.') + 1);[](#l9.116)
this.randomizedClassName = "randomPackage" + Long.toHexString(new SecureRandom().nextLong()) + "." + simpleClassName;[](#l9.117)
- }
- /**
* Load the named class into a zero-permissions protection domain. Even if the class is already loaded into the[](#l9.121)
* Dynalink's class loader, an independent class is created from the same bytecode, thus the returned class will[](#l9.122)
* never be identical with the one that might already be loaded. The class to be loaded is supposed to be package[](#l9.123)
* private and have no public constructors. This is not a functional requirement, but it is enforced to ensure that[](#l9.124)
* the original class was made adequately inaccessible. The returned class will be public and its constructors will[](#l9.125)
* be changed to public. The only permission given to the returned class will be[](#l9.126)
* {@code accessClassInPackage.jdk.internal.dynalink.beans.sandbox}. That package should be used solely to define[](#l9.127)
* SPI interfaces implemented by the loaded class.[](#l9.128)
* @param className the fully qualified name of the class to load[](#l9.129)
* @return the loaded class, renamed to a random package, made public, its constructors made public, and lacking any[](#l9.130)
* permissions except access to the sandbox package.[](#l9.131)
* @throws SecurityException if the calling code lacks the {@code createClassLoader} runtime permission. This[](#l9.132)
* normally means that Dynalink itself is running as untrusted code, and whatever functionality was meant to be[](#l9.133)
* isolated into an unprivileged class is likely okay to be used directly too.[](#l9.134)
*/[](#l9.135)
- static Class<?> loadClass(String className) throws SecurityException {
return new SandboxClassLoader(className).loadClass();[](#l9.137)
- }
- private Class<?> loadClass() throws SecurityException {
final ClassLoader loader = createClassLoader();[](#l9.141)
try {[](#l9.142)
final Class<?> clazz = Class.forName(randomizedClassName, true, loader);[](#l9.143)
// Sanity check to ensure we didn't accidentally pick up the class from elsewhere[](#l9.144)
if(clazz.getClassLoader() != loader) {[](#l9.145)
throw new AssertionError(randomizedClassName + " was loaded from a different class loader");[](#l9.146)
}[](#l9.147)
return clazz;[](#l9.148)
} catch(ClassNotFoundException e) {[](#l9.149)
throw new AssertionError(e);[](#l9.150)
}[](#l9.151)
- }
- private ClassLoader createClassLoader() throws SecurityException {
final String lclassName = this.randomizedClassName;[](#l9.155)
// We deliberately override loadClass instead of findClass so that we don't give a chance to finding this[](#l9.156)
// class already loaded anywhere else. We use this class' loader as the parent class loader as the loaded class[](#l9.157)
// needs to be able to access implemented interfaces from the sandbox package.[](#l9.158)
return new SecureClassLoader(getClass().getClassLoader()) {[](#l9.159)
@Override[](#l9.160)
protected Class<?> loadClass(String name, boolean resolve) throws ClassNotFoundException {[](#l9.161)
if(name.equals(lclassName)) {[](#l9.162)
final byte[] bytes = getClassBytes();[](#l9.163)
// Define the class with a protection domain that grants (almost) no permissions.[](#l9.164)
Class<?> clazz = defineClass(name, bytes, 0, bytes.length, createMinimalPermissionsDomain());[](#l9.165)
if(resolve) {[](#l9.166)
resolveClass(clazz);[](#l9.167)
}[](#l9.168)
return clazz;[](#l9.169)
}[](#l9.170)
final int i = name.lastIndexOf('.');[](#l9.172)
if (i != -1) {[](#l9.173)
final SecurityManager sm = System.getSecurityManager();[](#l9.174)
if (sm != null) {[](#l9.175)
sm.checkPackageAccess(name.substring(0, i));[](#l9.176)
}[](#l9.177)
}[](#l9.178)
return super.loadClass(name, resolve);[](#l9.179)
}[](#l9.180)
};[](#l9.181)
- }
- /**
* Create a no-permissions protection domain. Except, it's not really a no-permissions protection domain, since we[](#l9.185)
* need to give the protection domain the permission to access the sandbox package where the interop interfaces are[](#l9.186)
* defined.[](#l9.187)
* @return a new (almost) no-permission protection domain.[](#l9.188)
*/[](#l9.189)
- private static ProtectionDomain createMinimalPermissionsDomain() {
final Permissions p = new Permissions();[](#l9.191)
p.add(new RuntimePermission("accessClassInPackage.jdk.internal.dynalink.beans.sandbox"));[](#l9.192)
return new ProtectionDomain(null, p);[](#l9.193)
- }
- private byte[] getClassBytes() {
try(final InputStream in = getClass().getResourceAsStream("/" + className.replace('.', '/') + ".class")) {[](#l9.197)
final ClassReader cr = new ClassReader(in);[](#l9.198)
final ClassWriter cw = new ClassWriter(cr, 0);[](#l9.199)
cr.accept(new ClassVisitor(ASM4, cw) {[](#l9.200)
@Override[](#l9.201)
public void visit(int version, int access, String name, String signature, String superName,[](#l9.202)
String[] interfaces) {[](#l9.203)
// Rename the class to its random name, and make it public (otherwise we won't be able to[](#l9.204)
// instantiate it). The privileged template class is package-private.[](#l9.205)
if((access & ACC_PUBLIC) != 0) {[](#l9.206)
throw new IllegalArgumentException("Class " + className + " must be package-private");[](#l9.207)
}[](#l9.208)
super.visit(version, access | ACC_PUBLIC, randomizedClassName.replace('.', '/'),[](#l9.209)
signature, superName, interfaces);[](#l9.210)
}[](#l9.211)
@Override[](#l9.213)
public MethodVisitor visitMethod(int access, String name, String desc, String signature,[](#l9.214)
String[] exceptions) {[](#l9.215)
// Make the constructor(s) public (otherwise we won't be able to instantiate the class). The[](#l9.216)
// privileged template's constructor(s) should not be public.[](#l9.217)
final boolean isCtor = "<init>".equals(name);[](#l9.218)
if(isCtor && ((access & ACC_PUBLIC) != 0)) {[](#l9.219)
throw new IllegalArgumentException("Class " + className + " must have no public constructors");[](#l9.220)
}[](#l9.221)
return super.visitMethod(isCtor ? (access | ACC_PUBLIC) : access, name, desc, signature,[](#l9.222)
exceptions);[](#l9.223)
}[](#l9.224)
}, 0);[](#l9.225)
return cw.toByteArray();[](#l9.226)
} catch(IOException e) {[](#l9.227)
throw new RuntimeException(e);[](#l9.228)
}[](#l9.229)
- }
--- a/src/jdk/internal/dynalink/beans/StaticClassLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/internal/dynalink/beans/StaticClassLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -138,7 +138,7 @@ final Constructor<?>[] ctrs = clazz.getConstructors(); final List mhs = new ArrayList<>(ctrs.length); for(int i = 0; i < ctrs.length; ++i) {
mhs.add(drop(Lookup.PUBLIC.unreflectConstructor(ctrs[i])));[](#l10.7)
mhs.add(drop(SafeUnreflector.unreflectConstructor(ctrs[i])));[](#l10.8) }[](#l10.9) return createDynamicMethod(mhs, clazz, "<init>");[](#l10.10) }[](#l10.11)
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/internal/dynalink/beans/sandbox/Unreflector.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,132 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- / + +/
- / +/
- Copyright 2009-2013 Attila Szegedi +
- Licensed under both the Apache License, Version 2.0 (the "Apache License")
- and the BSD License (the "BSD License"), with licensee being free to
- choose either of the two at their discretion. +
- You may not use this file except in compliance with either the Apache
- License or the BSD License. +
- If you choose to use this file in compliance with the Apache License, the
- following notice applies to you: +
You may obtain a copy of the Apache License at[](#l11.49)
http://www.apache.org/licenses/LICENSE-2.0[](#l11.51)
Unless required by applicable law or agreed to in writing, software[](#l11.53)
distributed under the License is distributed on an "AS IS" BASIS,[](#l11.54)
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or[](#l11.55)
implied. See the License for the specific language governing[](#l11.56)
permissions and limitations under the License.[](#l11.57)
- If you choose to use this file in compliance with the BSD License, the
- following notice applies to you: +
Redistribution and use in source and binary forms, with or without[](#l11.62)
modification, are permitted provided that the following conditions are[](#l11.63)
met:[](#l11.64)
* Redistributions of source code must retain the above copyright[](#l11.65)
notice, this list of conditions and the following disclaimer.[](#l11.66)
* Redistributions in binary form must reproduce the above copyright[](#l11.67)
notice, this list of conditions and the following disclaimer in the[](#l11.68)
documentation and/or other materials provided with the distribution.[](#l11.69)
* Neither the name of the copyright holder nor the names of[](#l11.70)
contributors may be used to endorse or promote products derived from[](#l11.71)
this software without specific prior written permission.[](#l11.72)
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS[](#l11.74)
IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED[](#l11.75)
TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A[](#l11.76)
PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER[](#l11.77)
BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR[](#l11.78)
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF[](#l11.79)
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR[](#l11.80)
BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,[](#l11.81)
WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR[](#l11.82)
OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF[](#l11.83)
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.[](#l11.84)
+*/ + +package jdk.internal.dynalink.beans.sandbox; + +import java.lang.invoke.MethodHandle; +import java.lang.reflect.Constructor; +import java.lang.reflect.Field; +import java.lang.reflect.Method; + +/**
- */ +public interface Unreflector {
- /**
* Performs similarly to {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)} for some lookup object,[](#l11.100)
* also converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l11.101)
*[](#l11.102)
* @param m the method to unreflect[](#l11.103)
* @return the unreflected method handle.[](#l11.104)
*/[](#l11.105)
- public MethodHandle unreflect(Method m);
- /**
* Performs similarly to {@link java.lang.invoke.MethodHandles.Lookup#unreflectGetter(Field)} for some lookup[](#l11.109)
* object, also converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l11.110)
*[](#l11.111)
* @param f the field for which a getter is unreflected[](#l11.112)
* @return the unreflected field getter handle.[](#l11.113)
*/[](#l11.114)
- public MethodHandle unreflectGetter(Field f);
- /**
* Performs similarly to {@link java.lang.invoke.MethodHandles.Lookup#unreflectSetter(Field)} for some lookup[](#l11.118)
* object, also converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l11.119)
*[](#l11.120)
* @param f the field for which a setter is unreflected[](#l11.121)
* @return the unreflected field setter handle.[](#l11.122)
*/[](#l11.123)
- public MethodHandle unreflectSetter(Field f);
- /**
* Performs similarly to {@link java.lang.invoke.MethodHandles.Lookup#unreflectConstructor(Constructor)} for some[](#l11.127)
* lookup object, also converting any encountered {@link IllegalAccessException} into an {@link IllegalAccessError}.[](#l11.128)
*[](#l11.129)
* @param c the constructor to unreflect[](#l11.130)
* @return the unreflected constructor handle.[](#l11.131)
*/[](#l11.132)
- public MethodHandle unreflectConstructor(Constructor<?> c);
--- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.codegen; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/codegen/FunctionSignature.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/codegen/FunctionSignature.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.codegen; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodType; import java.util.ArrayList;
--- a/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Sat Mar 09 21:49:32 2013 +0530 @@ -34,7 +34,7 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.MAP; import static jdk.nashorn.internal.codegen.CompilerConstants.className; import static jdk.nashorn.internal.codegen.CompilerConstants.constructorNoLookup; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/codegen/RuntimeCallSite.java Sat Mar 09 21:49:32 2013 +0530 @@ -28,7 +28,7 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.staticCallNoLookup; import static jdk.nashorn.internal.codegen.types.Type.BOOLEAN; import static jdk.nashorn.internal.codegen.types.Type.INT; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.CallSite; import java.lang.invoke.MethodHandle; @@ -43,8 +43,8 @@ import jdk.nashorn.internal.ir.RuntimeNode.Request; import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.linker.Bootstrap; -import jdk.nashorn.internal.runtime.linker.Lookup; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.Lookup; +import jdk.nashorn.internal.lookup.MethodHandleFactory; /**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/lookup/Lookup.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,212 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ + +package jdk.nashorn.internal.lookup; + +import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import jdk.nashorn.internal.runtime.JSType; +import jdk.nashorn.internal.runtime.Property; +import jdk.nashorn.internal.runtime.PropertyMap; +import jdk.nashorn.internal.runtime.ScriptRuntime; + +/**
- */ +public final class Lookup { +
- /**
* A global singleton that points to the {@link MethodHandleFunctionality}. This is basically[](#l16.48)
* a collection of wrappers to the standard methods in {@link MethodHandle}, {@link MethodHandles} and[](#l16.49)
* {@link java.lang.invoke.MethodHandles.Lookup}, but instrumentation and debugging purposes we need[](#l16.50)
* intercept points.[](#l16.51)
* <p>[](#l16.52)
* All method handle operations in Nashorn should go through this field, not directly to the classes[](#l16.53)
* in {@code java.lang.invoke}[](#l16.54)
*/[](#l16.55)
- public static final MethodHandleFunctionality MH = MethodHandleFactory.getFunctionality();
- /** Method handle to the empty getter */
- public static final MethodHandle EMPTY_GETTER = findOwnMH("emptyGetter", Object.class, Object.class);
- /** Method handle to the empty setter */
- public static final MethodHandle EMPTY_SETTER = findOwnMH("emptySetter", void.class, Object.class, Object.class);
- /** Method handle to a getter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_GETTER = findOwnMH("typeErrorThrowerGetter", Object.class, Object.class);
- /** Method handle to a setter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_SETTER = findOwnMH("typeErrorThrowerSetter", void.class, Object.class, Object.class);
- /** Method handle to the most generic of getters, the one that returns an Object */
- public static final MethodType GET_OBJECT_TYPE = MH.type(Object.class, Object.class);
- /** Method handle to the most generic of setters, the one that takes an Object */
- public static final MethodType SET_OBJECT_TYPE = MH.type(void.class, Object.class, Object.class);
- /**
* Empty getter implementation. Nop[](#l16.80)
* @param self self reference[](#l16.81)
* @return undefined[](#l16.82)
*/[](#l16.83)
- public static Object emptyGetter(final Object self) {
return UNDEFINED;[](#l16.85)
- }
- /**
* Empty setter implementation. Nop[](#l16.89)
* @param self self reference[](#l16.90)
* @param value value (ignored)[](#l16.91)
*/[](#l16.92)
- public static void emptySetter(final Object self, final Object value) {
// do nothing!
- }
- /**
* Return a method handle to the empty getter, with a different[](#l16.98)
* return type value. It will still be undefined cast to whatever[](#l16.99)
* return value property was specified[](#l16.100)
*[](#l16.101)
* @param type return value type[](#l16.102)
*[](#l16.103)
* @return undefined as return value type[](#l16.104)
*/[](#l16.105)
- public static MethodHandle emptyGetter(final Class<?> type) {
return filterReturnType(EMPTY_GETTER, type);[](#l16.107)
- }
- /**
* Getter function that always throws type error[](#l16.111)
*[](#l16.112)
* @param self self reference[](#l16.113)
* @return undefined (but throws error before return point)[](#l16.114)
*/[](#l16.115)
- public static Object typeErrorThrowerGetter(final Object self) {
throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));[](#l16.117)
- }
- /**
* Getter function that always throws type error[](#l16.121)
*[](#l16.122)
* @param self self reference[](#l16.123)
* @param value (ignored)[](#l16.124)
*/[](#l16.125)
- public static void typeErrorThrowerSetter(final Object self, final Object value) {
throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));[](#l16.127)
- }
- /**
* Create a new {@link Property}[](#l16.131)
*[](#l16.132)
* @param map property map[](#l16.133)
* @param key property key[](#l16.134)
* @param flags property flags[](#l16.135)
* @param propertyGetter getter for property if available, null otherwise[](#l16.136)
* @param propertySetter setter for property if available, null otherwise[](#l16.137)
*[](#l16.138)
* @return new property map, representing {@code PropertyMap} with the new property added to it[](#l16.139)
*/[](#l16.140)
- @SuppressWarnings("fallthrough")
- public static PropertyMap newProperty(final PropertyMap map, final String key, final int flags, final MethodHandle propertyGetter, final MethodHandle propertySetter) {
MethodHandle getter = propertyGetter;[](#l16.143)
MethodHandle setter = propertySetter;[](#l16.144)
// TODO: this is temporary code. This code exists to support reflective[](#l16.146)
// field reader/writer handles generated by "unreflect" lookup.[](#l16.147)
switch (getter.type().parameterCount()) {[](#l16.149)
case 0:[](#l16.150)
// A static field reader, so drop the 'self' argument.[](#l16.151)
getter = MH.dropArguments(getter, 0, Object.class);[](#l16.152)
if (setter != null) {[](#l16.153)
setter = MH.dropArguments(setter, 0, Object.class);[](#l16.154)
}[](#l16.155)
// fall through[](#l16.156)
case 1:[](#l16.157)
// standard getter that accepts 'self'.[](#l16.158)
break;[](#l16.159)
default:[](#l16.160)
// Huh!! something wrong..[](#l16.161)
throw new IllegalArgumentException("getter/setter has wrong arguments");[](#l16.162)
}[](#l16.163)
- /**
* This method filters primitive return types using JavaScript semantics. For example,[](#l16.169)
* an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it.[](#l16.170)
* If you are returning values to JavaScript that have to be of a specific type, this is[](#l16.171)
* the correct return value filter to use, as the explicitCastArguments just uses the[](#l16.172)
* Java boxing equivalents[](#l16.173)
*[](#l16.174)
* @param mh method handle for which to filter return value[](#l16.175)
* @param type new return type[](#l16.176)
* @return method handle for appropriate return type conversion[](#l16.177)
*/[](#l16.178)
- public static MethodHandle filterReturnType(final MethodHandle mh, final Class<?> type) {
final Class<?> retType = mh.type().returnType();[](#l16.180)
if (retType == int.class) {[](#l16.182)
//fallthru[](#l16.183)
} else if (retType == long.class) {[](#l16.184)
//fallthru[](#l16.185)
} else if (retType == double.class) {[](#l16.186)
if (type == int.class) {[](#l16.187)
return MH.filterReturnValue(mh, JSType.TO_INT32_D.methodHandle());[](#l16.188)
} else if (type == long.class) {[](#l16.189)
return MH.filterReturnValue(mh, JSType.TO_UINT32_D.methodHandle());[](#l16.190)
}[](#l16.191)
//fallthru[](#l16.192)
} else if (!retType.isPrimitive()) {[](#l16.193)
if (type == int.class) {[](#l16.194)
return MH.filterReturnValue(mh, JSType.TO_INT32.methodHandle());[](#l16.195)
} else if (type == long.class) {[](#l16.196)
return MH.filterReturnValue(mh, JSType.TO_UINT32.methodHandle());[](#l16.197)
} else if (type == double.class) {[](#l16.198)
return MH.filterReturnValue(mh, JSType.TO_NUMBER.methodHandle());[](#l16.199)
} else if (!type.isPrimitive()) {[](#l16.200)
return mh;[](#l16.201)
}[](#l16.202)
assert false : "unsupported Lookup.filterReturnType type " + retType + " -> " + type;[](#l16.204)
}[](#l16.205)
//use a standard cast - we don't need to check JavaScript special cases[](#l16.207)
return MH.explicitCastArguments(mh, mh.type().changeReturnType(type));[](#l16.208)
- }
- private static MethodHandle findOwnMH(final String name, final Class rtype, final Class... types) {
return MH.findStatic(MethodHandles.lookup(), Lookup.class, name, MH.type(rtype, types));[](#l16.212)
- }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/lookup/MethodHandleFactory.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,646 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ + +package jdk.nashorn.internal.lookup; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.invoke.SwitchPoint; +import java.lang.reflect.Method; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.logging.Level; +import jdk.nashorn.internal.runtime.ConsString; +import jdk.nashorn.internal.runtime.Debug; +import jdk.nashorn.internal.runtime.DebugLogger; +import jdk.nashorn.internal.runtime.ScriptObject; +import jdk.nashorn.internal.runtime.options.Options; + +/**
- *
- *
- */ +public final class MethodHandleFactory { +
- private static final MethodHandles.Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup();
- private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
- /**
* Runtime exception that collects every reason that a method handle lookup operation can go wrong[](#l17.69)
*/[](#l17.70)
- @SuppressWarnings("serial")
- public static class LookupException extends RuntimeException {
/**[](#l17.73)
* Constructor[](#l17.74)
* @param e causing exception[](#l17.75)
*/[](#l17.76)
public LookupException(final Exception e) {[](#l17.77)
super(e);[](#l17.78)
}[](#l17.79)
- }
- /**
* Helper function that takes a class or an object with a toString override[](#l17.83)
* and shortens it to notation after last dot. This is used to facilitiate[](#l17.84)
* pretty printouts in various debug loggers - internal only[](#l17.85)
*[](#l17.86)
* @param obj class or object[](#l17.87)
*[](#l17.88)
* @return pretty version of object as string[](#l17.89)
*/[](#l17.90)
- public static String stripName(final Object obj) {
if (obj == null) {[](#l17.92)
return "null";[](#l17.93)
}[](#l17.94)
if (obj instanceof Class) {[](#l17.96)
return ((Class<?>)obj).getSimpleName();[](#l17.97)
}[](#l17.98)
return obj.toString();[](#l17.99)
- }
- private static final MethodHandleFunctionality STANDARD = new StandardMethodHandleFunctionality();
- private static final MethodHandleFunctionality FUNC;
- private static final String DEBUG_PROPERTY = "nashorn.methodhandles.debug";
- private static final DebugLogger LOG = new DebugLogger("methodhandles", DEBUG_PROPERTY);
- static {
if (LOG.isEnabled() || Options.getBooleanProperty(DEBUG_PROPERTY)) {[](#l17.109)
if (Options.getStringProperty(DEBUG_PROPERTY, "").equals("create")) {[](#l17.110)
FUNC = new TraceCreateMethodHandleFunctionality();[](#l17.111)
} else {[](#l17.112)
FUNC = new TraceMethodHandleFunctionality();[](#l17.113)
}[](#l17.114)
} else {[](#l17.115)
FUNC = STANDARD;[](#l17.116)
}[](#l17.117)
- }
- private static final boolean PRINT_STACKTRACE = Options.getBooleanProperty("nashorn.methodhandles.debug.stacktrace");
- /**
* Return the method handle functionality used for all method handle operations[](#l17.124)
* @return a method handle functionality implementation[](#l17.125)
*/[](#l17.126)
- public static MethodHandleFunctionality getFunctionality() {
return FUNC;[](#l17.128)
- }
- private static final MethodHandle TRACE = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class));
- private static final MethodHandle TRACE_RETURN = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class));
- /**
* Tracer that is applied before a value is returned from the traced function. It will output the return[](#l17.135)
* value and its class[](#l17.136)
*[](#l17.137)
* @param value return value for filter[](#l17.138)
* @return return value unmodified[](#l17.139)
*/[](#l17.140)
- static Object traceReturn(final DebugLogger logger, final Object value) {
final String str = "\treturn: " + stripName(value) + " [type=" + (value == null ? "null" : stripName(value.getClass()) + ']');[](#l17.142)
logger.log(str, TRACE_LEVEL);[](#l17.143)
return value;[](#l17.144)
- }
- /**
* Tracer that is applied before a function is called, printing the arguments[](#l17.148)
*[](#l17.149)
* @param tag tag to start the debug printout string[](#l17.150)
* @param paramStart param index to start outputting from[](#l17.151)
* @param args arguments to the function[](#l17.152)
*/[](#l17.153)
- static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) {
final StringBuilder sb = new StringBuilder();[](#l17.155)
sb.append(tag);[](#l17.157)
for (int i = paramStart; i < args.length; i++) {[](#l17.159)
if (i == paramStart) {[](#l17.160)
sb.append(" => args: ");[](#l17.161)
}[](#l17.162)
sb.append('\'').[](#l17.164)
append(stripName(argString(args[i]))).[](#l17.165)
append('\'').[](#l17.166)
append(' ').[](#l17.167)
append('[').[](#l17.168)
append("type=").[](#l17.169)
append(args[i] == null ? "null" : stripName(args[i].getClass())).[](#l17.170)
append(']');[](#l17.171)
if (i + 1 < args.length) {[](#l17.173)
sb.append(", ");[](#l17.174)
}[](#l17.175)
}[](#l17.176)
assert logger != null;[](#l17.178)
logger.log(sb.toString(), TRACE_LEVEL);[](#l17.179)
stacktrace(logger);[](#l17.180)
- }
- private static void stacktrace(final DebugLogger logger) {
if (!PRINT_STACKTRACE) {[](#l17.184)
return;[](#l17.185)
}[](#l17.186)
final ByteArrayOutputStream baos = new ByteArrayOutputStream();[](#l17.187)
final PrintStream ps = new PrintStream(baos);[](#l17.188)
new Throwable().printStackTrace(ps);[](#l17.189)
logger.log(baos.toString(), TRACE_LEVEL);[](#l17.190)
- }
- private static String argString(final Object arg) {
if (arg == null) {[](#l17.194)
return "null";[](#l17.195)
}[](#l17.196)
if (arg.getClass().isArray()) {[](#l17.198)
final List<Object> list = new ArrayList<>();[](#l17.199)
for (final Object elem : (Object[])arg) {[](#l17.200)
list.add('\'' + argString(elem) + '\'');[](#l17.201)
}[](#l17.202)
return list.toString();[](#l17.204)
}[](#l17.205)
if (arg instanceof ScriptObject) {[](#l17.207)
return arg.toString() +[](#l17.208)
" (map=" + Debug.id((((ScriptObject)arg).getMap())) +[](#l17.209)
")";[](#l17.210)
}[](#l17.211)
- /**
* Add a debug printout to a method handle, tracing parameters and return values[](#l17.217)
*[](#l17.218)
* @param logger a specific logger to which to write the output[](#l17.219)
* @param mh method handle to trace[](#l17.220)
* @param tag start of trace message[](#l17.221)
* @return traced method handle[](#l17.222)
*/[](#l17.223)
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final Object tag) {
return addDebugPrintout(logger, mh, 0, true, tag);[](#l17.225)
- }
- /**
* Add a debug printout to a method handle, tracing parameters and return values[](#l17.230)
*[](#l17.231)
* @param logger a specific logger to which to write the output[](#l17.232)
* @param mh method handle to trace[](#l17.233)
* @param paramStart first param to print/trace[](#l17.234)
* @param printReturnValue should we print/trace return value if available?[](#l17.235)
* @param tag start of trace message[](#l17.236)
* @return traced method handle[](#l17.237)
*/[](#l17.238)
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) {
final MethodType type = mh.type();[](#l17.240)
if (logger != null && logger.levelAbove(TRACE_LEVEL)) {[](#l17.242)
return mh;[](#l17.243)
}[](#l17.244)
assert logger != null;[](#l17.246)
assert TRACE != null;[](#l17.247)
MethodHandle trace = MethodHandles.insertArguments(TRACE, 0, logger, tag, paramStart);[](#l17.249)
trace = MethodHandles.foldArguments([](#l17.251)
mh,[](#l17.252)
trace.asCollector([](#l17.253)
Object[].class,[](#l17.254)
type.parameterCount()).[](#l17.255)
asType(type.changeReturnType(void.class)));[](#l17.256)
final Class<?> retType = type.returnType();[](#l17.258)
if (retType != void.class && printReturnValue) {[](#l17.259)
final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);[](#l17.260)
trace = MethodHandles.filterReturnValue(trace,[](#l17.261)
traceReturn.asType([](#l17.262)
traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));[](#l17.263)
}[](#l17.264)
- /**
* The standard class that marshalls all method handle operations to the java.lang.invoke[](#l17.270)
* package. This exists only so that it can be subclassed and method handles created from[](#l17.271)
* Nashorn made possible to instrument.[](#l17.272)
*[](#l17.273)
* All Nashorn classes should use the MethodHandleFactory for their method handle operations[](#l17.274)
*/[](#l17.275)
- private static class StandardMethodHandleFunctionality implements MethodHandleFunctionality {
@Override[](#l17.278)
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {[](#l17.279)
return MethodHandles.filterArguments(target, pos, filters);[](#l17.280)
}[](#l17.281)
@Override[](#l17.283)
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {[](#l17.284)
return MethodHandles.filterReturnValue(target, filter);[](#l17.285)
}[](#l17.286)
@Override[](#l17.288)
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {[](#l17.289)
return MethodHandles.guardWithTest(test, target, fallback);[](#l17.290)
}[](#l17.291)
@Override[](#l17.293)
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {[](#l17.294)
return MethodHandles.insertArguments(target, pos, values);[](#l17.295)
}[](#l17.296)
@Override[](#l17.298)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... valueTypes) {[](#l17.299)
return MethodHandles.dropArguments(target, pos, valueTypes);[](#l17.300)
}[](#l17.301)
@Override[](#l17.303)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> valueTypes) {[](#l17.304)
return MethodHandles.dropArguments(target, pos, valueTypes);[](#l17.305)
}[](#l17.306)
@Override[](#l17.308)
public MethodHandle asType(final MethodHandle handle, final MethodType type) {[](#l17.309)
return handle.asType(type);[](#l17.310)
}[](#l17.311)
@Override[](#l17.313)
public MethodHandle bindTo(final MethodHandle handle, final Object x) {[](#l17.314)
return handle.bindTo(x);[](#l17.315)
}[](#l17.316)
@Override[](#l17.318)
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {[](#l17.319)
return MethodHandles.foldArguments(target, combiner);[](#l17.320)
}[](#l17.321)
@Override[](#l17.323)
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {[](#l17.324)
return MethodHandles.explicitCastArguments(target, type);[](#l17.325)
}[](#l17.326)
@Override[](#l17.328)
public MethodHandle arrayElementGetter(final Class<?> type) {[](#l17.329)
return MethodHandles.arrayElementGetter(type);[](#l17.330)
}[](#l17.331)
@Override[](#l17.333)
public MethodHandle arrayElementSetter(final Class<?> type) {[](#l17.334)
return MethodHandles.arrayElementSetter(type);[](#l17.335)
}[](#l17.336)
@Override[](#l17.338)
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {[](#l17.339)
return MethodHandles.throwException(returnType, exType);[](#l17.340)
}[](#l17.341)
@Override[](#l17.343)
public MethodHandle constant(final Class<?> type, final Object value) {[](#l17.344)
return MethodHandles.constant(type, value);[](#l17.345)
}[](#l17.346)
@Override[](#l17.348)
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l17.349)
return handle.asCollector(arrayType, arrayLength);[](#l17.350)
}[](#l17.351)
@Override[](#l17.353)
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l17.354)
return handle.asSpreader(arrayType, arrayLength);[](#l17.355)
}[](#l17.356)
@Override[](#l17.358)
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.359)
try {[](#l17.360)
return explicitLookup.findGetter(clazz, name, type);[](#l17.361)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l17.362)
throw new LookupException(e);[](#l17.363)
}[](#l17.364)
}[](#l17.365)
@Override[](#l17.367)
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.368)
try {[](#l17.369)
return explicitLookup.findStaticGetter(clazz, name, type);[](#l17.370)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l17.371)
throw new LookupException(e);[](#l17.372)
}[](#l17.373)
}[](#l17.374)
@Override[](#l17.377)
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.378)
try {[](#l17.379)
return explicitLookup.findSetter(clazz, name, type);[](#l17.380)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l17.381)
throw new LookupException(e);[](#l17.382)
}[](#l17.383)
}[](#l17.384)
@Override[](#l17.386)
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.387)
try {[](#l17.388)
return explicitLookup.findStaticSetter(clazz, name, type);[](#l17.389)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l17.390)
throw new LookupException(e);[](#l17.391)
}[](#l17.392)
}[](#l17.393)
@Override[](#l17.395)
public MethodHandle find(final Method method) {[](#l17.396)
try {[](#l17.397)
return PUBLIC_LOOKUP.unreflect(method);[](#l17.398)
} catch (final IllegalAccessException e) {[](#l17.399)
throw new LookupException(e);[](#l17.400)
}[](#l17.401)
}[](#l17.402)
@Override[](#l17.404)
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l17.405)
try {[](#l17.406)
return explicitLookup.findStatic(clazz, name, type);[](#l17.407)
} catch (final NoSuchMethodException | IllegalAccessException e) {[](#l17.408)
throw new LookupException(e);[](#l17.409)
}[](#l17.410)
}[](#l17.411)
@Override[](#l17.413)
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l17.414)
try {[](#l17.415)
return explicitLookup.findVirtual(clazz, name, type);[](#l17.416)
} catch (final NoSuchMethodException | IllegalAccessException e) {[](#l17.417)
throw new LookupException(e);[](#l17.418)
}[](#l17.419)
}[](#l17.420)
@Override[](#l17.422)
public SwitchPoint createSwitchPoint() {[](#l17.423)
return new SwitchPoint();[](#l17.424)
}[](#l17.425)
@Override[](#l17.427)
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {[](#l17.428)
return sp.guardWithTest(before, after);[](#l17.429)
}[](#l17.430)
@Override[](#l17.432)
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {[](#l17.433)
return MethodType.methodType(returnType, paramTypes);[](#l17.434)
}[](#l17.435)
- /**
* Class used for instrumenting and debugging Nashorn generated method handles[](#l17.440)
*/[](#l17.441)
- private static class TraceMethodHandleFunctionality extends StandardMethodHandleFunctionality {
protected static String describe(final Object... data) {[](#l17.444)
final StringBuilder sb = new StringBuilder();[](#l17.445)
for (int i = 0; i < data.length; i++) {[](#l17.447)
final Object d = data[i];[](#l17.448)
if (d == null) {[](#l17.449)
sb.append("<null> ");[](#l17.450)
} else if (d instanceof String || d instanceof ConsString) {[](#l17.451)
sb.append(d.toString());[](#l17.452)
sb.append(' ');[](#l17.453)
} else if (d.getClass().isArray()) {[](#l17.454)
sb.append("[ ");[](#l17.455)
for (final Object da : (Object[])d) {[](#l17.456)
sb.append(describe(new Object[]{ da })).append(' ');[](#l17.457)
}[](#l17.458)
sb.append("] ");[](#l17.459)
} else {[](#l17.460)
sb.append(d)[](#l17.461)
.append('{')[](#l17.462)
.append(Integer.toHexString(System.identityHashCode(d)))[](#l17.463)
.append('}');[](#l17.464)
}[](#l17.465)
if (i + 1 < data.length) {[](#l17.467)
sb.append(", ");[](#l17.468)
}[](#l17.469)
}[](#l17.470)
return sb.toString();[](#l17.472)
}[](#l17.473)
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {[](#l17.475)
return addDebugPrintout(LOG, master, Integer.MAX_VALUE, false, str + ' ' + describe(args));[](#l17.476)
}[](#l17.477)
@Override[](#l17.479)
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {[](#l17.480)
final MethodHandle mh = super.filterArguments(target, pos, filters);[](#l17.481)
return debug(mh, "filterArguments", target, pos, filters);[](#l17.482)
}[](#l17.483)
@Override[](#l17.485)
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {[](#l17.486)
final MethodHandle mh = super.filterReturnValue(target, filter);[](#l17.487)
return debug(mh, "filterReturnValue", target, filter);[](#l17.488)
}[](#l17.489)
@Override[](#l17.491)
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {[](#l17.492)
final MethodHandle mh = super.guardWithTest(test, target, fallback);[](#l17.493)
return debug(mh, "guardWithTest", test, target, fallback);[](#l17.494)
}[](#l17.495)
@Override[](#l17.497)
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {[](#l17.498)
final MethodHandle mh = super.insertArguments(target, pos, values);[](#l17.499)
return debug(mh, "insertArguments", target, pos, values);[](#l17.500)
}[](#l17.501)
@Override[](#l17.503)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... values) {[](#l17.504)
final MethodHandle mh = super.dropArguments(target, pos, values);[](#l17.505)
return debug(mh, "dropArguments", target, pos, values);[](#l17.506)
}[](#l17.507)
@Override[](#l17.509)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> values) {[](#l17.510)
final MethodHandle mh = super.dropArguments(target, pos, values);[](#l17.511)
return debug(mh, "dropArguments", target, pos, values);[](#l17.512)
}[](#l17.513)
@Override[](#l17.515)
public MethodHandle asType(final MethodHandle handle, final MethodType type) {[](#l17.516)
final MethodHandle mh = super.asType(handle, type);[](#l17.517)
return debug(mh, "asType", handle, type);[](#l17.518)
}[](#l17.519)
@Override[](#l17.521)
public MethodHandle bindTo(final MethodHandle handle, final Object x) {[](#l17.522)
final MethodHandle mh = super.bindTo(handle, x);[](#l17.523)
return debug(mh, "bindTo", handle, x);[](#l17.524)
}[](#l17.525)
@Override[](#l17.527)
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {[](#l17.528)
final MethodHandle mh = super.foldArguments(target, combiner);[](#l17.529)
return debug(mh, "foldArguments", target, combiner);[](#l17.530)
}[](#l17.531)
@Override[](#l17.533)
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {[](#l17.534)
final MethodHandle mh = super.explicitCastArguments(target, type);[](#l17.535)
return debug(mh, "explicitCastArguments", target, type);[](#l17.536)
}[](#l17.537)
@Override[](#l17.539)
public MethodHandle arrayElementGetter(final Class<?> type) {[](#l17.540)
final MethodHandle mh = super.arrayElementGetter(type);[](#l17.541)
return debug(mh, "arrayElementGetter", type);[](#l17.542)
}[](#l17.543)
@Override[](#l17.545)
public MethodHandle arrayElementSetter(final Class<?> type) {[](#l17.546)
final MethodHandle mh = super.arrayElementSetter(type);[](#l17.547)
return debug(mh, "arrayElementSetter", type);[](#l17.548)
}[](#l17.549)
@Override[](#l17.551)
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {[](#l17.552)
final MethodHandle mh = super.throwException(returnType, exType);[](#l17.553)
return debug(mh, "throwException", returnType, exType);[](#l17.554)
}[](#l17.555)
@Override[](#l17.557)
public MethodHandle constant(final Class<?> type, final Object value) {[](#l17.558)
final MethodHandle mh = super.constant(type, value);[](#l17.559)
return debug(mh, "constant", type, value);[](#l17.560)
}[](#l17.561)
@Override[](#l17.563)
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l17.564)
final MethodHandle mh = super.asCollector(handle, arrayType, arrayLength);[](#l17.565)
return debug(mh, "asCollector", handle, arrayType, arrayLength);[](#l17.566)
}[](#l17.567)
@Override[](#l17.569)
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l17.570)
final MethodHandle mh = super.asCollector(handle, arrayType, arrayLength);[](#l17.571)
return debug(mh, "asSpreader", handle, arrayType, arrayLength);[](#l17.572)
}[](#l17.573)
@Override[](#l17.575)
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.576)
final MethodHandle mh = super.getter(explicitLookup, clazz, name, type);[](#l17.577)
return debug(mh, "getter", explicitLookup, clazz, name, type);[](#l17.578)
}[](#l17.579)
@Override[](#l17.581)
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.582)
final MethodHandle mh = super.staticGetter(explicitLookup, clazz, name, type);[](#l17.583)
return debug(mh, "static getter", explicitLookup, clazz, name, type);[](#l17.584)
}[](#l17.585)
@Override[](#l17.587)
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.588)
final MethodHandle mh = super.setter(explicitLookup, clazz, name, type);[](#l17.589)
return debug(mh, "setter", explicitLookup, clazz, name, type);[](#l17.590)
}[](#l17.591)
@Override[](#l17.593)
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l17.594)
final MethodHandle mh = super.staticSetter(explicitLookup, clazz, name, type);[](#l17.595)
return debug(mh, "static setter", explicitLookup, clazz, name, type);[](#l17.596)
}[](#l17.597)
@Override[](#l17.599)
public MethodHandle find(final Method method) {[](#l17.600)
final MethodHandle mh = super.find(method);[](#l17.601)
return debug(mh, "find", method);[](#l17.602)
}[](#l17.603)
@Override[](#l17.605)
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l17.606)
final MethodHandle mh = super.findStatic(explicitLookup, clazz, name, type);[](#l17.607)
return debug(mh, "findStatic", explicitLookup, clazz, name, type);[](#l17.608)
}[](#l17.609)
@Override[](#l17.611)
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l17.612)
final MethodHandle mh = super.findVirtual(explicitLookup, clazz, name, type);[](#l17.613)
return debug(mh, "findVirtual", explicitLookup, clazz, name, type);[](#l17.614)
}[](#l17.615)
@Override[](#l17.617)
public SwitchPoint createSwitchPoint() {[](#l17.618)
final SwitchPoint sp = super.createSwitchPoint();[](#l17.619)
LOG.log("createSwitchPoint " + sp, TRACE_LEVEL);[](#l17.620)
return sp;[](#l17.621)
}[](#l17.622)
@Override[](#l17.624)
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {[](#l17.625)
final MethodHandle mh = super.guardWithTest(sp, before, after);[](#l17.626)
return debug(mh, "guardWithTest", sp, before, after);[](#l17.627)
}[](#l17.628)
@Override[](#l17.630)
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {[](#l17.631)
final MethodType mt = super.type(returnType, paramTypes);[](#l17.632)
LOG.log("methodType " + returnType + ' ' + Arrays.toString(paramTypes) + ' ' + mt, TRACE_LEVEL);[](#l17.633)
return mt;[](#l17.634)
}[](#l17.635)
- }
- /**
* Class used for debugging Nashorn generated method handles[](#l17.639)
*/[](#l17.640)
- private static class TraceCreateMethodHandleFunctionality extends TraceMethodHandleFunctionality {
@Override[](#l17.642)
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {[](#l17.643)
LOG.log(str + ' ' + describe(args), TRACE_LEVEL);[](#l17.644)
stacktrace(LOG);[](#l17.645)
return master;[](#l17.646)
}[](#l17.647)
- }
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/jdk/nashorn/internal/lookup/MethodHandleFunctionality.java Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,317 @@ +/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ + +package jdk.nashorn.internal.lookup; + +import java.lang.invoke.MethodHandle; +import java.lang.invoke.MethodHandles; +import java.lang.invoke.MethodType; +import java.lang.invoke.SwitchPoint; +import java.lang.reflect.Method; +import java.util.List; + +/**
- */ + +public interface MethodHandleFunctionality {
- /**
* Wrapper for {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)}[](#l18.45)
*[](#l18.46)
* @param target target method handle[](#l18.47)
* @param pos start argument index[](#l18.48)
* @param filters filters[](#l18.49)
*[](#l18.50)
* @return filtered handle[](#l18.51)
*/[](#l18.52)
- public MethodHandle filterArguments(MethodHandle target, int pos, MethodHandle... filters);
- /**
* Wrapper for {@link MethodHandles#filterReturnValue(MethodHandle, MethodHandle)}[](#l18.56)
*[](#l18.57)
* @param target target method handle[](#l18.58)
* @param filter filter[](#l18.59)
*[](#l18.60)
* @return filtered handle[](#l18.61)
*/[](#l18.62)
- public MethodHandle filterReturnValue(MethodHandle target, MethodHandle filter);
- /**
* Wrapper for {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}[](#l18.66)
*[](#l18.67)
* @param test test method handle[](#l18.68)
* @param target target method handle when test is true[](#l18.69)
* @param fallback fallback method handle when test is false[](#l18.70)
*[](#l18.71)
* @return guarded handles[](#l18.72)
*/[](#l18.73)
- public MethodHandle guardWithTest(MethodHandle test, MethodHandle target, MethodHandle fallback);
- /**
* Wrapper for {@link MethodHandles#insertArguments(MethodHandle, int, Object...)}[](#l18.77)
*[](#l18.78)
* @param target target method handle[](#l18.79)
* @param pos start argument index[](#l18.80)
* @param values values to insert[](#l18.81)
*[](#l18.82)
* @return handle with bound arguments[](#l18.83)
*/[](#l18.84)
- public MethodHandle insertArguments(MethodHandle target, int pos, Object... values);
- /**
* Wrapper for {@link MethodHandles#dropArguments(MethodHandle, int, Class...)}[](#l18.88)
*[](#l18.89)
* @param target target method handle[](#l18.90)
* @param pos start argument index[](#l18.91)
* @param valueTypes valueTypes of arguments to drop[](#l18.92)
*[](#l18.93)
* @return handle with dropped arguments[](#l18.94)
*/[](#l18.95)
- public MethodHandle dropArguments(MethodHandle target, int pos, Class<?>... valueTypes);
- /**
* Wrapper for {@link MethodHandles#dropArguments(MethodHandle, int, List)}[](#l18.99)
*[](#l18.100)
* @param target target method handle[](#l18.101)
* @param pos start argument index[](#l18.102)
* @param valueTypes valueTypes of arguments to drop[](#l18.103)
*[](#l18.104)
* @return handle with dropped arguments[](#l18.105)
*/[](#l18.106)
- public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> valueTypes);
- /**
* Wrapper for {@link MethodHandles#foldArguments(MethodHandle, MethodHandle)}[](#l18.110)
*[](#l18.111)
* @param target target method handle[](#l18.112)
* @param combiner combiner to apply for fold[](#l18.113)
*[](#l18.114)
* @return folded method handle[](#l18.115)
*/[](#l18.116)
- public MethodHandle foldArguments(MethodHandle target, MethodHandle combiner);
- /**
* Wrapper for {@link MethodHandles#explicitCastArguments(MethodHandle, MethodType)}[](#l18.120)
*[](#l18.121)
* @param target target method handle[](#l18.122)
* @param type type to cast to[](#l18.123)
*[](#l18.124)
* @return modified method handle[](#l18.125)
*/[](#l18.126)
- public MethodHandle explicitCastArguments(MethodHandle target, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#arrayElementGetter(Class)}[](#l18.130)
*[](#l18.131)
* @param arrayClass class for array[](#l18.132)
*[](#l18.133)
* @return array element getter[](#l18.134)
*/[](#l18.135)
- public MethodHandle arrayElementGetter(Class<?> arrayClass);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#arrayElementSetter(Class)}[](#l18.139)
*[](#l18.140)
* @param arrayClass class for array[](#l18.141)
*[](#l18.142)
* @return array element setter[](#l18.143)
*/[](#l18.144)
- public MethodHandle arrayElementSetter(Class<?> arrayClass);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#throwException(Class, Class)}[](#l18.148)
*[](#l18.149)
* @param returnType ignored, but method signature will use it[](#l18.150)
* @param exType exception type that will be thrown[](#l18.151)
*[](#l18.152)
* @return exception thrower method handle[](#l18.153)
*/[](#l18.154)
- public MethodHandle throwException(Class<?> returnType, Class<? extends Throwable> exType);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#constant(Class, Object)}[](#l18.158)
*[](#l18.159)
* @param type type of constant[](#l18.160)
* @param value constant value[](#l18.161)
*[](#l18.162)
* @return method handle that returns said constant[](#l18.163)
*/[](#l18.164)
- public MethodHandle constant(Class<?> type, Object value);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asType(MethodType)}[](#l18.168)
*[](#l18.169)
* @param handle method handle for type conversion[](#l18.170)
* @param type type to convert to[](#l18.171)
*[](#l18.172)
* @return method handle with given type conversion applied[](#l18.173)
*/[](#l18.174)
- public MethodHandle asType(MethodHandle handle, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asCollector(Class, int)}[](#l18.178)
*[](#l18.179)
* @param handle handle to convert[](#l18.180)
* @param arrayType array type for collector array[](#l18.181)
* @param arrayLength length of collector array[](#l18.182)
*[](#l18.183)
* @return method handle with collector[](#l18.184)
*/[](#l18.185)
- public MethodHandle asCollector(MethodHandle handle, Class<?> arrayType, int arrayLength);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asSpreader(Class, int)}[](#l18.189)
*[](#l18.190)
* @param handle handle to convert[](#l18.191)
* @param arrayType array type for spread[](#l18.192)
* @param arrayLength length of spreader[](#l18.193)
*[](#l18.194)
* @return method handle as spreader[](#l18.195)
*/[](#l18.196)
- public MethodHandle asSpreader(MethodHandle handle, Class<?> arrayType, int arrayLength);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#bindTo(Object)}[](#l18.200)
*[](#l18.201)
* @param handle a handle to which to bind a receiver[](#l18.202)
* @param x the receiver[](#l18.203)
*[](#l18.204)
* @return the bound handle[](#l18.205)
*/[](#l18.206)
- public MethodHandle bindTo(MethodHandle handle, Object x);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}[](#l18.210)
*[](#l18.211)
* @param explicitLookup explicit lookup to be used[](#l18.212)
* @param clazz class to look in[](#l18.213)
* @param name name of field[](#l18.214)
* @param type type of field[](#l18.215)
*[](#l18.216)
* @return getter method handle for virtual field[](#l18.217)
*/[](#l18.218)
- public MethodHandle getter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStaticGetter(Class, String, Class)}[](#l18.222)
*[](#l18.223)
* @param explicitLookup explicit lookup to be used[](#l18.224)
* @param clazz class to look in[](#l18.225)
* @param name name of field[](#l18.226)
* @param type type of field[](#l18.227)
*[](#l18.228)
* @return getter method handle for static field[](#l18.229)
*/[](#l18.230)
- public MethodHandle staticGetter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findSetter(Class, String, Class)}[](#l18.234)
*[](#l18.235)
* @param explicitLookup explicit lookup to be used[](#l18.236)
* @param clazz class to look in[](#l18.237)
* @param name name of field[](#l18.238)
* @param type type of field[](#l18.239)
*[](#l18.240)
* @return setter method handle for virtual field[](#l18.241)
*/[](#l18.242)
- public MethodHandle setter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStaticSetter(Class, String, Class)}[](#l18.246)
*[](#l18.247)
* @param explicitLookup explicit lookup to be used[](#l18.248)
* @param clazz class to look in[](#l18.249)
* @param name name of field[](#l18.250)
* @param type type of field[](#l18.251)
*[](#l18.252)
* @return setter method handle for static field[](#l18.253)
*/[](#l18.254)
- public MethodHandle staticSetter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}[](#l18.258)
*[](#l18.259)
* Unreflect a method as a method handle[](#l18.260)
*[](#l18.261)
* @param method method to unreflect[](#l18.262)
* @return unreflected method as method handle[](#l18.263)
*/[](#l18.264)
- public MethodHandle find(Method method);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)}[](#l18.268)
*[](#l18.269)
* @param explicitLookup explicit lookup to be used[](#l18.270)
* @param clazz class to look in[](#l18.271)
* @param name name of method[](#l18.272)
* @param type method type[](#l18.273)
*[](#l18.274)
* @return method handle for static method[](#l18.275)
*/[](#l18.276)
- public MethodHandle findStatic(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)}[](#l18.280)
*[](#l18.281)
* @param explicitLookup explicit lookup to be used[](#l18.282)
* @param clazz class to look in[](#l18.283)
* @param name name of method[](#l18.284)
* @param type method type[](#l18.285)
*[](#l18.286)
* @return method handle for virtual method[](#l18.287)
*/[](#l18.288)
- public MethodHandle findVirtual(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type);
- /**
* Wrapper for SwitchPoint creation. Just like {@code new SwitchPoint()} but potentially[](#l18.292)
* tracked[](#l18.293)
*[](#l18.294)
* @return new switch point[](#l18.295)
*/[](#l18.296)
- public SwitchPoint createSwitchPoint();
- /**
* Wrapper for {@link SwitchPoint#guardWithTest(MethodHandle, MethodHandle)}[](#l18.300)
*[](#l18.301)
* @param sp switch point[](#l18.302)
* @param before method handle when switchpoint is valid[](#l18.303)
* @param after method handle when switchpoint is invalidated[](#l18.304)
*[](#l18.305)
* @return guarded method handle[](#l18.306)
*/[](#l18.307)
- public MethodHandle guardWithTest(SwitchPoint sp, MethodHandle before, MethodHandle after);
- /**
* Wrapper for {@link MethodType#methodType(Class, Class...)}[](#l18.311)
*[](#l18.312)
* @param returnType return type for method type[](#l18.313)
* @param paramTypes parameter types for method type[](#l18.314)
*[](#l18.315)
* @return the method type[](#l18.316)
*/[](#l18.317)
- public MethodType type(Class returnType, Class... paramTypes);
--- a/src/jdk/nashorn/internal/objects/Global.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/Global.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.io.IOException; import java.io.PrintWriter;
--- a/src/jdk/nashorn/internal/objects/NativeArguments.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Sat Mar 09 21:49:32 2013 +0530 @@ -28,7 +28,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -42,7 +42,7 @@ import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.arrays.ArrayData; import jdk.nashorn.internal.runtime.arrays.ArrayIndex; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/objects/NativeBoolean.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeBoolean.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.objects; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -39,7 +39,7 @@ import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.runtime.linker.PrimitiveLookup; /**
--- a/src/jdk/nashorn/internal/objects/NativeError.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.objects; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -46,8 +46,8 @@ import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.arrays.ArrayLikeIterator; -import jdk.nashorn.internal.runtime.linker.Lookup; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.Lookup; +import jdk.nashorn.internal.lookup.MethodHandleFactory; /**
- This class is the implementation of the Nashorn-specific global object named {@code JSAdapter}. It can be
--- a/src/jdk/nashorn/internal/objects/NativeNumber.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeNumber.java Sat Mar 09 21:49:32 2013 +0530 @@ -30,7 +30,7 @@ import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt; import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsLong; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -47,7 +47,7 @@ import jdk.nashorn.internal.runtime.JSType; import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.runtime.linker.PrimitiveLookup; /**
--- a/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeStrictArguments.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.objects; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -36,7 +36,7 @@ import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.arrays.ArrayData; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/objects/NativeString.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/NativeString.java Sat Mar 09 21:49:32 2013 +0530 @@ -29,7 +29,7 @@ import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -55,7 +55,7 @@ import jdk.nashorn.internal.runtime.ScriptObject; import jdk.nashorn.internal.runtime.ScriptRuntime; import jdk.nashorn.internal.runtime.arrays.ArrayIndex; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.runtime.linker.NashornGuards; import jdk.nashorn.internal.runtime.linker.PrimitiveLookup;
--- a/src/jdk/nashorn/internal/objects/PrototypeObject.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/PrototypeObject.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.objects; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -34,7 +34,7 @@ import jdk.nashorn.internal.runtime.PropertyMap; import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptObject; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Sat Mar 09 21:49:32 2013 +0530 @@ -34,7 +34,7 @@ import jdk.nashorn.internal.runtime.ScriptFunction; import jdk.nashorn.internal.runtime.ScriptFunctionData; import jdk.nashorn.internal.runtime.ScriptObject; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/objects/ScriptFunctionTrampolineImpl.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/objects/ScriptFunctionTrampolineImpl.java Sat Mar 09 21:49:32 2013 +0530 @@ -1,6 +1,6 @@ package jdk.nashorn.internal.objects; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/AccessorProperty.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/AccessorProperty.java Sat Mar 09 21:49:32 2013 +0530 @@ -36,16 +36,16 @@ import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getAccessorType; import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getAccessorTypeIndex; import static jdk.nashorn.internal.codegen.ObjectClassGenerator.getNumberOfAccessorTypes; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; -import static jdk.nashorn.internal.runtime.linker.MethodHandleFactory.stripName; +import static jdk.nashorn.internal.lookup.Lookup.MH; +import static jdk.nashorn.internal.lookup.MethodHandleFactory.stripName; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; import jdk.nashorn.internal.codegen.ObjectClassGenerator; import jdk.nashorn.internal.codegen.types.Type; -import jdk.nashorn.internal.runtime.linker.Lookup; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.Lookup; +import jdk.nashorn.internal.lookup.MethodHandleFactory; /**
--- a/src/jdk/nashorn/internal/runtime/Context.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/Context.java Sat Mar 09 21:49:32 2013 +0530 @@ -29,7 +29,7 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.STRICT_MODE; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.io.File; import java.io.IOException;
--- a/src/jdk/nashorn/internal/runtime/FindProperty.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/FindProperty.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import jdk.nashorn.internal.codegen.ObjectClassGenerator;
--- a/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/GlobalFunctions.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.runtime.JSType.digit; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Sat Mar 09 21:49:32 2013 +0530 @@ -28,7 +28,7 @@ import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -38,7 +38,7 @@ import jdk.internal.dynalink.linker.LinkRequest; import jdk.nashorn.internal.codegen.CompilerConstants.Call; import jdk.nashorn.internal.objects.annotations.SpecializedFunction; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; import jdk.nashorn.internal.runtime.linker.NashornGuards;
--- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Sat Mar 09 21:49:32 2013 +0530 @@ -39,7 +39,7 @@ import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.getArrayIndexNoThrow; import static jdk.nashorn.internal.runtime.arrays.ArrayIndex.isValidArrayIndex; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -65,8 +65,8 @@ import jdk.nashorn.internal.objects.DataPropertyDescriptor; import jdk.nashorn.internal.runtime.arrays.ArrayData; import jdk.nashorn.internal.runtime.linker.Bootstrap; -import jdk.nashorn.internal.runtime.linker.Lookup; -import jdk.nashorn.internal.runtime.linker.MethodHandleFactory; +import jdk.nashorn.internal.lookup.Lookup; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; import jdk.nashorn.internal.runtime.linker.NashornGuards;
--- a/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/ScriptingFunctions.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.io.BufferedReader; import java.io.File;
--- a/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/SetMethodCreator.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,13 +26,13 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.runtime.ECMAErrors.referenceError; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import jdk.internal.dynalink.CallSiteDescriptor; import jdk.internal.dynalink.linker.GuardedInvocation; import jdk.nashorn.internal.codegen.ObjectClassGenerator; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; import jdk.nashorn.internal.runtime.linker.NashornCallSiteDescriptor; import jdk.nashorn.internal.runtime.linker.NashornGuards;
--- a/src/jdk/nashorn/internal/runtime/SpillProperty.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/SpillProperty.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,11 +25,11 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/runtime/Undefined.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/Undefined.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.runtime; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Sat Mar 09 21:49:32 2013 +0530 @@ -26,7 +26,7 @@ package jdk.nashorn.internal.runtime; import java.lang.invoke.MethodHandle; -import jdk.nashorn.internal.runtime.linker.Lookup; +import jdk.nashorn.internal.lookup.Lookup; /**
--- a/src/jdk/nashorn/internal/runtime/WithObject.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.runtime; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/JSObjectLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,6 +25,8 @@ package jdk.nashorn.internal.runtime.linker; +import jdk.nashorn.internal.lookup.MethodHandleFunctionality; +import jdk.nashorn.internal.lookup.MethodHandleFactory; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodType; @@ -42,7 +44,7 @@
- A Dynalink linker to handle web browser built-in JS (DOM etc.) objects as well
- as ScriptObjects from other Nashorn contexts. */ -public final class JSObjectLinker implements TypeBasedGuardingDynamicLinker { +final class JSObjectLinker implements TypeBasedGuardingDynamicLinker { /**
--- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Sat Mar 09 21:49:32 2013 +0530 @@ -41,7 +41,7 @@ import static jdk.internal.org.objectweb.asm.Opcodes.ISTORE; import static jdk.internal.org.objectweb.asm.Opcodes.RETURN; import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType;
--- a/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaArgumentConverters.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,8 @@ package jdk.nashorn.internal.runtime.linker; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import jdk.nashorn.internal.lookup.MethodHandleFactory; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.io.FileNotFoundException; import java.io.FileOutputStream;
--- a/src/jdk/nashorn/internal/runtime/linker/Lookup.java Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,212 +0,0 @@ -/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ - -package jdk.nashorn.internal.runtime.linker; - -import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; -import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import jdk.nashorn.internal.runtime.JSType; -import jdk.nashorn.internal.runtime.Property; -import jdk.nashorn.internal.runtime.PropertyMap; -import jdk.nashorn.internal.runtime.ScriptRuntime; - -/**
- */ -public final class Lookup { -
- /**
* A global singleton that points to the {@link MethodHandleFunctionality}. This is basically[](#l47.48)
* a collection of wrappers to the standard methods in {@link MethodHandle}, {@link MethodHandles} and[](#l47.49)
* {@link java.lang.invoke.MethodHandles.Lookup}, but instrumentation and debugging purposes we need[](#l47.50)
* intercept points.[](#l47.51)
* <p>[](#l47.52)
* All method handle operations in Nashorn should go through this field, not directly to the classes[](#l47.53)
* in {@code java.lang.invoke}[](#l47.54)
*/[](#l47.55)
- public static final MethodHandleFunctionality MH = MethodHandleFactory.getFunctionality();
- /** Method handle to the empty getter */
- public static final MethodHandle EMPTY_GETTER = findOwnMH("emptyGetter", Object.class, Object.class);
- /** Method handle to the empty setter */
- public static final MethodHandle EMPTY_SETTER = findOwnMH("emptySetter", void.class, Object.class, Object.class);
- /** Method handle to a getter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_GETTER = findOwnMH("typeErrorThrowerGetter", Object.class, Object.class);
- /** Method handle to a setter that only throws type error */
- public static final MethodHandle TYPE_ERROR_THROWER_SETTER = findOwnMH("typeErrorThrowerSetter", void.class, Object.class, Object.class);
- /** Method handle to the most generic of getters, the one that returns an Object */
- public static final MethodType GET_OBJECT_TYPE = MH.type(Object.class, Object.class);
- /** Method handle to the most generic of setters, the one that takes an Object */
- public static final MethodType SET_OBJECT_TYPE = MH.type(void.class, Object.class, Object.class);
- /**
* Empty getter implementation. Nop[](#l47.80)
* @param self self reference[](#l47.81)
* @return undefined[](#l47.82)
*/[](#l47.83)
- public static Object emptyGetter(final Object self) {
return UNDEFINED;[](#l47.85)
- }
- /**
* Empty setter implementation. Nop[](#l47.89)
* @param self self reference[](#l47.90)
* @param value value (ignored)[](#l47.91)
*/[](#l47.92)
- public static void emptySetter(final Object self, final Object value) {
// do nothing!
- }
- /**
* Return a method handle to the empty getter, with a different[](#l47.98)
* return type value. It will still be undefined cast to whatever[](#l47.99)
* return value property was specified[](#l47.100)
*[](#l47.101)
* @param type return value type[](#l47.102)
*[](#l47.103)
* @return undefined as return value type[](#l47.104)
*/[](#l47.105)
- public static MethodHandle emptyGetter(final Class<?> type) {
return filterReturnType(EMPTY_GETTER, type);[](#l47.107)
- }
- /**
* Getter function that always throws type error[](#l47.111)
*[](#l47.112)
* @param self self reference[](#l47.113)
* @return undefined (but throws error before return point)[](#l47.114)
*/[](#l47.115)
- public static Object typeErrorThrowerGetter(final Object self) {
throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));[](#l47.117)
- }
- /**
* Getter function that always throws type error[](#l47.121)
*[](#l47.122)
* @param self self reference[](#l47.123)
* @param value (ignored)[](#l47.124)
*/[](#l47.125)
- public static void typeErrorThrowerSetter(final Object self, final Object value) {
throw typeError("strict.getter.setter.poison", ScriptRuntime.safeToString(self));[](#l47.127)
- }
- /**
* Create a new {@link Property}[](#l47.131)
*[](#l47.132)
* @param map property map[](#l47.133)
* @param key property key[](#l47.134)
* @param flags property flags[](#l47.135)
* @param propertyGetter getter for property if available, null otherwise[](#l47.136)
* @param propertySetter setter for property if available, null otherwise[](#l47.137)
*[](#l47.138)
* @return new property map, representing {@code PropertyMap} with the new property added to it[](#l47.139)
*/[](#l47.140)
- @SuppressWarnings("fallthrough")
- public static PropertyMap newProperty(final PropertyMap map, final String key, final int flags, final MethodHandle propertyGetter, final MethodHandle propertySetter) {
MethodHandle getter = propertyGetter;[](#l47.143)
MethodHandle setter = propertySetter;[](#l47.144)
// TODO: this is temporary code. This code exists to support reflective[](#l47.146)
// field reader/writer handles generated by "unreflect" lookup.[](#l47.147)
switch (getter.type().parameterCount()) {[](#l47.149)
case 0:[](#l47.150)
// A static field reader, so drop the 'self' argument.[](#l47.151)
getter = MH.dropArguments(getter, 0, Object.class);[](#l47.152)
if (setter != null) {[](#l47.153)
setter = MH.dropArguments(setter, 0, Object.class);[](#l47.154)
}[](#l47.155)
// fall through[](#l47.156)
case 1:[](#l47.157)
// standard getter that accepts 'self'.[](#l47.158)
break;[](#l47.159)
default:[](#l47.160)
// Huh!! something wrong..[](#l47.161)
throw new IllegalArgumentException("getter/setter has wrong arguments");[](#l47.162)
}[](#l47.163)
- /**
* This method filters primitive return types using JavaScript semantics. For example,[](#l47.169)
* an (int) cast of a double in Java land is not the same thing as invoking toInt32 on it.[](#l47.170)
* If you are returning values to JavaScript that have to be of a specific type, this is[](#l47.171)
* the correct return value filter to use, as the explicitCastArguments just uses the[](#l47.172)
* Java boxing equivalents[](#l47.173)
*[](#l47.174)
* @param mh method handle for which to filter return value[](#l47.175)
* @param type new return type[](#l47.176)
* @return method handle for appropriate return type conversion[](#l47.177)
*/[](#l47.178)
- public static MethodHandle filterReturnType(final MethodHandle mh, final Class<?> type) {
final Class<?> retType = mh.type().returnType();[](#l47.180)
if (retType == int.class) {[](#l47.182)
//fallthru[](#l47.183)
} else if (retType == long.class) {[](#l47.184)
//fallthru[](#l47.185)
} else if (retType == double.class) {[](#l47.186)
if (type == int.class) {[](#l47.187)
return MH.filterReturnValue(mh, JSType.TO_INT32_D.methodHandle());[](#l47.188)
} else if (type == long.class) {[](#l47.189)
return MH.filterReturnValue(mh, JSType.TO_UINT32_D.methodHandle());[](#l47.190)
}[](#l47.191)
//fallthru[](#l47.192)
} else if (!retType.isPrimitive()) {[](#l47.193)
if (type == int.class) {[](#l47.194)
return MH.filterReturnValue(mh, JSType.TO_INT32.methodHandle());[](#l47.195)
} else if (type == long.class) {[](#l47.196)
return MH.filterReturnValue(mh, JSType.TO_UINT32.methodHandle());[](#l47.197)
} else if (type == double.class) {[](#l47.198)
return MH.filterReturnValue(mh, JSType.TO_NUMBER.methodHandle());[](#l47.199)
} else if (!type.isPrimitive()) {[](#l47.200)
return mh;[](#l47.201)
}[](#l47.202)
assert false : "unsupported Lookup.filterReturnType type " + retType + " -> " + type;[](#l47.204)
}[](#l47.205)
//use a standard cast - we don't need to check JavaScript special cases[](#l47.207)
return MH.explicitCastArguments(mh, mh.type().changeReturnType(type));[](#l47.208)
- }
- private static MethodHandle findOwnMH(final String name, final Class rtype, final Class... types) {
return MH.findStatic(MethodHandles.lookup(), Lookup.class, name, MH.type(rtype, types));[](#l47.212)
- }
--- a/src/jdk/nashorn/internal/runtime/linker/MethodHandleFactory.java Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,646 +0,0 @@ -/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ - -package jdk.nashorn.internal.runtime.linker; - -import java.io.ByteArrayOutputStream; -import java.io.PrintStream; -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.SwitchPoint; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; -import java.util.logging.Level; -import jdk.nashorn.internal.runtime.ConsString; -import jdk.nashorn.internal.runtime.Debug; -import jdk.nashorn.internal.runtime.DebugLogger; -import jdk.nashorn.internal.runtime.ScriptObject; -import jdk.nashorn.internal.runtime.options.Options; - -/**
- *
- *
- */ -public final class MethodHandleFactory { -
- private static final MethodHandles.Lookup PUBLIC_LOOKUP = MethodHandles.publicLookup();
- private static final MethodHandles.Lookup LOOKUP = MethodHandles.lookup();
- /**
* Runtime exception that collects every reason that a method handle lookup operation can go wrong[](#l48.69)
*/[](#l48.70)
- @SuppressWarnings("serial")
- public static class LookupException extends RuntimeException {
/**[](#l48.73)
* Constructor[](#l48.74)
* @param e causing exception[](#l48.75)
*/[](#l48.76)
public LookupException(final Exception e) {[](#l48.77)
super(e);[](#l48.78)
}[](#l48.79)
- }
- /**
* Helper function that takes a class or an object with a toString override[](#l48.83)
* and shortens it to notation after last dot. This is used to facilitiate[](#l48.84)
* pretty printouts in various debug loggers - internal only[](#l48.85)
*[](#l48.86)
* @param obj class or object[](#l48.87)
*[](#l48.88)
* @return pretty version of object as string[](#l48.89)
*/[](#l48.90)
- public static String stripName(final Object obj) {
if (obj == null) {[](#l48.92)
return "null";[](#l48.93)
}[](#l48.94)
if (obj instanceof Class) {[](#l48.96)
return ((Class<?>)obj).getSimpleName();[](#l48.97)
}[](#l48.98)
return obj.toString();[](#l48.99)
- }
- private static final MethodHandleFunctionality STANDARD = new StandardMethodHandleFunctionality();
- private static final MethodHandleFunctionality FUNC;
- private static final String DEBUG_PROPERTY = "nashorn.methodhandles.debug";
- private static final DebugLogger LOG = new DebugLogger("methodhandles", DEBUG_PROPERTY);
- static {
if (LOG.isEnabled() || Options.getBooleanProperty(DEBUG_PROPERTY)) {[](#l48.109)
if (Options.getStringProperty(DEBUG_PROPERTY, "").equals("create")) {[](#l48.110)
FUNC = new TraceCreateMethodHandleFunctionality();[](#l48.111)
} else {[](#l48.112)
FUNC = new TraceMethodHandleFunctionality();[](#l48.113)
}[](#l48.114)
} else {[](#l48.115)
FUNC = STANDARD;[](#l48.116)
}[](#l48.117)
- }
- private static final boolean PRINT_STACKTRACE = Options.getBooleanProperty("nashorn.methodhandles.debug.stacktrace");
- /**
* Return the method handle functionality used for all method handle operations[](#l48.124)
* @return a method handle functionality implementation[](#l48.125)
*/[](#l48.126)
- public static MethodHandleFunctionality getFunctionality() {
return FUNC;[](#l48.128)
- }
- private static final MethodHandle TRACE = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceArgs", MethodType.methodType(void.class, DebugLogger.class, String.class, int.class, Object[].class));
- private static final MethodHandle TRACE_RETURN = STANDARD.findStatic(LOOKUP, MethodHandleFactory.class, "traceReturn", MethodType.methodType(Object.class, DebugLogger.class, Object.class));
- /**
* Tracer that is applied before a value is returned from the traced function. It will output the return[](#l48.135)
* value and its class[](#l48.136)
*[](#l48.137)
* @param value return value for filter[](#l48.138)
* @return return value unmodified[](#l48.139)
*/[](#l48.140)
- static Object traceReturn(final DebugLogger logger, final Object value) {
final String str = "\treturn: " + stripName(value) + " [type=" + (value == null ? "null" : stripName(value.getClass()) + ']');[](#l48.142)
logger.log(str, TRACE_LEVEL);[](#l48.143)
return value;[](#l48.144)
- }
- /**
* Tracer that is applied before a function is called, printing the arguments[](#l48.148)
*[](#l48.149)
* @param tag tag to start the debug printout string[](#l48.150)
* @param paramStart param index to start outputting from[](#l48.151)
* @param args arguments to the function[](#l48.152)
*/[](#l48.153)
- static void traceArgs(final DebugLogger logger, final String tag, final int paramStart, final Object... args) {
final StringBuilder sb = new StringBuilder();[](#l48.155)
sb.append(tag);[](#l48.157)
for (int i = paramStart; i < args.length; i++) {[](#l48.159)
if (i == paramStart) {[](#l48.160)
sb.append(" => args: ");[](#l48.161)
}[](#l48.162)
sb.append('\'').[](#l48.164)
append(stripName(argString(args[i]))).[](#l48.165)
append('\'').[](#l48.166)
append(' ').[](#l48.167)
append('[').[](#l48.168)
append("type=").[](#l48.169)
append(args[i] == null ? "null" : stripName(args[i].getClass())).[](#l48.170)
append(']');[](#l48.171)
if (i + 1 < args.length) {[](#l48.173)
sb.append(", ");[](#l48.174)
}[](#l48.175)
}[](#l48.176)
assert logger != null;[](#l48.178)
logger.log(sb.toString(), TRACE_LEVEL);[](#l48.179)
stacktrace(logger);[](#l48.180)
- }
- private static void stacktrace(final DebugLogger logger) {
if (!PRINT_STACKTRACE) {[](#l48.184)
return;[](#l48.185)
}[](#l48.186)
final ByteArrayOutputStream baos = new ByteArrayOutputStream();[](#l48.187)
final PrintStream ps = new PrintStream(baos);[](#l48.188)
new Throwable().printStackTrace(ps);[](#l48.189)
logger.log(baos.toString(), TRACE_LEVEL);[](#l48.190)
- }
- private static String argString(final Object arg) {
if (arg == null) {[](#l48.194)
return "null";[](#l48.195)
}[](#l48.196)
if (arg.getClass().isArray()) {[](#l48.198)
final List<Object> list = new ArrayList<>();[](#l48.199)
for (final Object elem : (Object[])arg) {[](#l48.200)
list.add('\'' + argString(elem) + '\'');[](#l48.201)
}[](#l48.202)
return list.toString();[](#l48.204)
}[](#l48.205)
if (arg instanceof ScriptObject) {[](#l48.207)
return arg.toString() +[](#l48.208)
" (map=" + Debug.id((((ScriptObject)arg).getMap())) +[](#l48.209)
")";[](#l48.210)
}[](#l48.211)
- /**
* Add a debug printout to a method handle, tracing parameters and return values[](#l48.217)
*[](#l48.218)
* @param logger a specific logger to which to write the output[](#l48.219)
* @param mh method handle to trace[](#l48.220)
* @param tag start of trace message[](#l48.221)
* @return traced method handle[](#l48.222)
*/[](#l48.223)
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final Object tag) {
return addDebugPrintout(logger, mh, 0, true, tag);[](#l48.225)
- }
- /**
* Add a debug printout to a method handle, tracing parameters and return values[](#l48.230)
*[](#l48.231)
* @param logger a specific logger to which to write the output[](#l48.232)
* @param mh method handle to trace[](#l48.233)
* @param paramStart first param to print/trace[](#l48.234)
* @param printReturnValue should we print/trace return value if available?[](#l48.235)
* @param tag start of trace message[](#l48.236)
* @return traced method handle[](#l48.237)
*/[](#l48.238)
- public static MethodHandle addDebugPrintout(final DebugLogger logger, final MethodHandle mh, final int paramStart, final boolean printReturnValue, final Object tag) {
final MethodType type = mh.type();[](#l48.240)
if (logger != null && logger.levelAbove(TRACE_LEVEL)) {[](#l48.242)
return mh;[](#l48.243)
}[](#l48.244)
assert logger != null;[](#l48.246)
assert TRACE != null;[](#l48.247)
MethodHandle trace = MethodHandles.insertArguments(TRACE, 0, logger, tag, paramStart);[](#l48.249)
trace = MethodHandles.foldArguments([](#l48.251)
mh,[](#l48.252)
trace.asCollector([](#l48.253)
Object[].class,[](#l48.254)
type.parameterCount()).[](#l48.255)
asType(type.changeReturnType(void.class)));[](#l48.256)
final Class<?> retType = type.returnType();[](#l48.258)
if (retType != void.class && printReturnValue) {[](#l48.259)
final MethodHandle traceReturn = MethodHandles.insertArguments(TRACE_RETURN, 0, logger);[](#l48.260)
trace = MethodHandles.filterReturnValue(trace,[](#l48.261)
traceReturn.asType([](#l48.262)
traceReturn.type().changeParameterType(0, retType).changeReturnType(retType)));[](#l48.263)
}[](#l48.264)
- /**
* The standard class that marshalls all method handle operations to the java.lang.invoke[](#l48.270)
* package. This exists only so that it can be subclassed and method handles created from[](#l48.271)
* Nashorn made possible to instrument.[](#l48.272)
*[](#l48.273)
* All Nashorn classes should use the MethodHandleFactory for their method handle operations[](#l48.274)
*/[](#l48.275)
- private static class StandardMethodHandleFunctionality implements MethodHandleFunctionality {
@Override[](#l48.278)
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {[](#l48.279)
return MethodHandles.filterArguments(target, pos, filters);[](#l48.280)
}[](#l48.281)
@Override[](#l48.283)
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {[](#l48.284)
return MethodHandles.filterReturnValue(target, filter);[](#l48.285)
}[](#l48.286)
@Override[](#l48.288)
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {[](#l48.289)
return MethodHandles.guardWithTest(test, target, fallback);[](#l48.290)
}[](#l48.291)
@Override[](#l48.293)
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {[](#l48.294)
return MethodHandles.insertArguments(target, pos, values);[](#l48.295)
}[](#l48.296)
@Override[](#l48.298)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... valueTypes) {[](#l48.299)
return MethodHandles.dropArguments(target, pos, valueTypes);[](#l48.300)
}[](#l48.301)
@Override[](#l48.303)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> valueTypes) {[](#l48.304)
return MethodHandles.dropArguments(target, pos, valueTypes);[](#l48.305)
}[](#l48.306)
@Override[](#l48.308)
public MethodHandle asType(final MethodHandle handle, final MethodType type) {[](#l48.309)
return handle.asType(type);[](#l48.310)
}[](#l48.311)
@Override[](#l48.313)
public MethodHandle bindTo(final MethodHandle handle, final Object x) {[](#l48.314)
return handle.bindTo(x);[](#l48.315)
}[](#l48.316)
@Override[](#l48.318)
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {[](#l48.319)
return MethodHandles.foldArguments(target, combiner);[](#l48.320)
}[](#l48.321)
@Override[](#l48.323)
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {[](#l48.324)
return MethodHandles.explicitCastArguments(target, type);[](#l48.325)
}[](#l48.326)
@Override[](#l48.328)
public MethodHandle arrayElementGetter(final Class<?> type) {[](#l48.329)
return MethodHandles.arrayElementGetter(type);[](#l48.330)
}[](#l48.331)
@Override[](#l48.333)
public MethodHandle arrayElementSetter(final Class<?> type) {[](#l48.334)
return MethodHandles.arrayElementSetter(type);[](#l48.335)
}[](#l48.336)
@Override[](#l48.338)
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {[](#l48.339)
return MethodHandles.throwException(returnType, exType);[](#l48.340)
}[](#l48.341)
@Override[](#l48.343)
public MethodHandle constant(final Class<?> type, final Object value) {[](#l48.344)
return MethodHandles.constant(type, value);[](#l48.345)
}[](#l48.346)
@Override[](#l48.348)
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l48.349)
return handle.asCollector(arrayType, arrayLength);[](#l48.350)
}[](#l48.351)
@Override[](#l48.353)
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l48.354)
return handle.asSpreader(arrayType, arrayLength);[](#l48.355)
}[](#l48.356)
@Override[](#l48.358)
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.359)
try {[](#l48.360)
return explicitLookup.findGetter(clazz, name, type);[](#l48.361)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l48.362)
throw new LookupException(e);[](#l48.363)
}[](#l48.364)
}[](#l48.365)
@Override[](#l48.367)
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.368)
try {[](#l48.369)
return explicitLookup.findStaticGetter(clazz, name, type);[](#l48.370)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l48.371)
throw new LookupException(e);[](#l48.372)
}[](#l48.373)
}[](#l48.374)
@Override[](#l48.377)
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.378)
try {[](#l48.379)
return explicitLookup.findSetter(clazz, name, type);[](#l48.380)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l48.381)
throw new LookupException(e);[](#l48.382)
}[](#l48.383)
}[](#l48.384)
@Override[](#l48.386)
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.387)
try {[](#l48.388)
return explicitLookup.findStaticSetter(clazz, name, type);[](#l48.389)
} catch (final NoSuchFieldException | IllegalAccessException e) {[](#l48.390)
throw new LookupException(e);[](#l48.391)
}[](#l48.392)
}[](#l48.393)
@Override[](#l48.395)
public MethodHandle find(final Method method) {[](#l48.396)
try {[](#l48.397)
return PUBLIC_LOOKUP.unreflect(method);[](#l48.398)
} catch (final IllegalAccessException e) {[](#l48.399)
throw new LookupException(e);[](#l48.400)
}[](#l48.401)
}[](#l48.402)
@Override[](#l48.404)
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l48.405)
try {[](#l48.406)
return explicitLookup.findStatic(clazz, name, type);[](#l48.407)
} catch (final NoSuchMethodException | IllegalAccessException e) {[](#l48.408)
throw new LookupException(e);[](#l48.409)
}[](#l48.410)
}[](#l48.411)
@Override[](#l48.413)
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l48.414)
try {[](#l48.415)
return explicitLookup.findVirtual(clazz, name, type);[](#l48.416)
} catch (final NoSuchMethodException | IllegalAccessException e) {[](#l48.417)
throw new LookupException(e);[](#l48.418)
}[](#l48.419)
}[](#l48.420)
@Override[](#l48.422)
public SwitchPoint createSwitchPoint() {[](#l48.423)
return new SwitchPoint();[](#l48.424)
}[](#l48.425)
@Override[](#l48.427)
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {[](#l48.428)
return sp.guardWithTest(before, after);[](#l48.429)
}[](#l48.430)
@Override[](#l48.432)
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {[](#l48.433)
return MethodType.methodType(returnType, paramTypes);[](#l48.434)
}[](#l48.435)
- /**
* Class used for instrumenting and debugging Nashorn generated method handles[](#l48.440)
*/[](#l48.441)
- private static class TraceMethodHandleFunctionality extends StandardMethodHandleFunctionality {
protected static String describe(final Object... data) {[](#l48.444)
final StringBuilder sb = new StringBuilder();[](#l48.445)
for (int i = 0; i < data.length; i++) {[](#l48.447)
final Object d = data[i];[](#l48.448)
if (d == null) {[](#l48.449)
sb.append("<null> ");[](#l48.450)
} else if (d instanceof String || d instanceof ConsString) {[](#l48.451)
sb.append(d.toString());[](#l48.452)
sb.append(' ');[](#l48.453)
} else if (d.getClass().isArray()) {[](#l48.454)
sb.append("[ ");[](#l48.455)
for (final Object da : (Object[])d) {[](#l48.456)
sb.append(describe(new Object[]{ da })).append(' ');[](#l48.457)
}[](#l48.458)
sb.append("] ");[](#l48.459)
} else {[](#l48.460)
sb.append(d)[](#l48.461)
.append('{')[](#l48.462)
.append(Integer.toHexString(System.identityHashCode(d)))[](#l48.463)
.append('}');[](#l48.464)
}[](#l48.465)
if (i + 1 < data.length) {[](#l48.467)
sb.append(", ");[](#l48.468)
}[](#l48.469)
}[](#l48.470)
return sb.toString();[](#l48.472)
}[](#l48.473)
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {[](#l48.475)
return addDebugPrintout(LOG, master, Integer.MAX_VALUE, false, str + ' ' + describe(args));[](#l48.476)
}[](#l48.477)
@Override[](#l48.479)
public MethodHandle filterArguments(final MethodHandle target, final int pos, final MethodHandle... filters) {[](#l48.480)
final MethodHandle mh = super.filterArguments(target, pos, filters);[](#l48.481)
return debug(mh, "filterArguments", target, pos, filters);[](#l48.482)
}[](#l48.483)
@Override[](#l48.485)
public MethodHandle filterReturnValue(final MethodHandle target, final MethodHandle filter) {[](#l48.486)
final MethodHandle mh = super.filterReturnValue(target, filter);[](#l48.487)
return debug(mh, "filterReturnValue", target, filter);[](#l48.488)
}[](#l48.489)
@Override[](#l48.491)
public MethodHandle guardWithTest(final MethodHandle test, final MethodHandle target, final MethodHandle fallback) {[](#l48.492)
final MethodHandle mh = super.guardWithTest(test, target, fallback);[](#l48.493)
return debug(mh, "guardWithTest", test, target, fallback);[](#l48.494)
}[](#l48.495)
@Override[](#l48.497)
public MethodHandle insertArguments(final MethodHandle target, final int pos, final Object... values) {[](#l48.498)
final MethodHandle mh = super.insertArguments(target, pos, values);[](#l48.499)
return debug(mh, "insertArguments", target, pos, values);[](#l48.500)
}[](#l48.501)
@Override[](#l48.503)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final Class<?>... values) {[](#l48.504)
final MethodHandle mh = super.dropArguments(target, pos, values);[](#l48.505)
return debug(mh, "dropArguments", target, pos, values);[](#l48.506)
}[](#l48.507)
@Override[](#l48.509)
public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> values) {[](#l48.510)
final MethodHandle mh = super.dropArguments(target, pos, values);[](#l48.511)
return debug(mh, "dropArguments", target, pos, values);[](#l48.512)
}[](#l48.513)
@Override[](#l48.515)
public MethodHandle asType(final MethodHandle handle, final MethodType type) {[](#l48.516)
final MethodHandle mh = super.asType(handle, type);[](#l48.517)
return debug(mh, "asType", handle, type);[](#l48.518)
}[](#l48.519)
@Override[](#l48.521)
public MethodHandle bindTo(final MethodHandle handle, final Object x) {[](#l48.522)
final MethodHandle mh = super.bindTo(handle, x);[](#l48.523)
return debug(mh, "bindTo", handle, x);[](#l48.524)
}[](#l48.525)
@Override[](#l48.527)
public MethodHandle foldArguments(final MethodHandle target, final MethodHandle combiner) {[](#l48.528)
final MethodHandle mh = super.foldArguments(target, combiner);[](#l48.529)
return debug(mh, "foldArguments", target, combiner);[](#l48.530)
}[](#l48.531)
@Override[](#l48.533)
public MethodHandle explicitCastArguments(final MethodHandle target, final MethodType type) {[](#l48.534)
final MethodHandle mh = super.explicitCastArguments(target, type);[](#l48.535)
return debug(mh, "explicitCastArguments", target, type);[](#l48.536)
}[](#l48.537)
@Override[](#l48.539)
public MethodHandle arrayElementGetter(final Class<?> type) {[](#l48.540)
final MethodHandle mh = super.arrayElementGetter(type);[](#l48.541)
return debug(mh, "arrayElementGetter", type);[](#l48.542)
}[](#l48.543)
@Override[](#l48.545)
public MethodHandle arrayElementSetter(final Class<?> type) {[](#l48.546)
final MethodHandle mh = super.arrayElementSetter(type);[](#l48.547)
return debug(mh, "arrayElementSetter", type);[](#l48.548)
}[](#l48.549)
@Override[](#l48.551)
public MethodHandle throwException(final Class<?> returnType, final Class<? extends Throwable> exType) {[](#l48.552)
final MethodHandle mh = super.throwException(returnType, exType);[](#l48.553)
return debug(mh, "throwException", returnType, exType);[](#l48.554)
}[](#l48.555)
@Override[](#l48.557)
public MethodHandle constant(final Class<?> type, final Object value) {[](#l48.558)
final MethodHandle mh = super.constant(type, value);[](#l48.559)
return debug(mh, "constant", type, value);[](#l48.560)
}[](#l48.561)
@Override[](#l48.563)
public MethodHandle asCollector(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l48.564)
final MethodHandle mh = super.asCollector(handle, arrayType, arrayLength);[](#l48.565)
return debug(mh, "asCollector", handle, arrayType, arrayLength);[](#l48.566)
}[](#l48.567)
@Override[](#l48.569)
public MethodHandle asSpreader(final MethodHandle handle, final Class<?> arrayType, final int arrayLength) {[](#l48.570)
final MethodHandle mh = super.asCollector(handle, arrayType, arrayLength);[](#l48.571)
return debug(mh, "asSpreader", handle, arrayType, arrayLength);[](#l48.572)
}[](#l48.573)
@Override[](#l48.575)
public MethodHandle getter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.576)
final MethodHandle mh = super.getter(explicitLookup, clazz, name, type);[](#l48.577)
return debug(mh, "getter", explicitLookup, clazz, name, type);[](#l48.578)
}[](#l48.579)
@Override[](#l48.581)
public MethodHandle staticGetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.582)
final MethodHandle mh = super.staticGetter(explicitLookup, clazz, name, type);[](#l48.583)
return debug(mh, "static getter", explicitLookup, clazz, name, type);[](#l48.584)
}[](#l48.585)
@Override[](#l48.587)
public MethodHandle setter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.588)
final MethodHandle mh = super.setter(explicitLookup, clazz, name, type);[](#l48.589)
return debug(mh, "setter", explicitLookup, clazz, name, type);[](#l48.590)
}[](#l48.591)
@Override[](#l48.593)
public MethodHandle staticSetter(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final Class<?> type) {[](#l48.594)
final MethodHandle mh = super.staticSetter(explicitLookup, clazz, name, type);[](#l48.595)
return debug(mh, "static setter", explicitLookup, clazz, name, type);[](#l48.596)
}[](#l48.597)
@Override[](#l48.599)
public MethodHandle find(final Method method) {[](#l48.600)
final MethodHandle mh = super.find(method);[](#l48.601)
return debug(mh, "find", method);[](#l48.602)
}[](#l48.603)
@Override[](#l48.605)
public MethodHandle findStatic(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l48.606)
final MethodHandle mh = super.findStatic(explicitLookup, clazz, name, type);[](#l48.607)
return debug(mh, "findStatic", explicitLookup, clazz, name, type);[](#l48.608)
}[](#l48.609)
@Override[](#l48.611)
public MethodHandle findVirtual(final MethodHandles.Lookup explicitLookup, final Class<?> clazz, final String name, final MethodType type) {[](#l48.612)
final MethodHandle mh = super.findVirtual(explicitLookup, clazz, name, type);[](#l48.613)
return debug(mh, "findVirtual", explicitLookup, clazz, name, type);[](#l48.614)
}[](#l48.615)
@Override[](#l48.617)
public SwitchPoint createSwitchPoint() {[](#l48.618)
final SwitchPoint sp = super.createSwitchPoint();[](#l48.619)
LOG.log("createSwitchPoint " + sp, TRACE_LEVEL);[](#l48.620)
return sp;[](#l48.621)
}[](#l48.622)
@Override[](#l48.624)
public MethodHandle guardWithTest(final SwitchPoint sp, final MethodHandle before, final MethodHandle after) {[](#l48.625)
final MethodHandle mh = super.guardWithTest(sp, before, after);[](#l48.626)
return debug(mh, "guardWithTest", sp, before, after);[](#l48.627)
}[](#l48.628)
@Override[](#l48.630)
public MethodType type(final Class<?> returnType, final Class<?>... paramTypes) {[](#l48.631)
final MethodType mt = super.type(returnType, paramTypes);[](#l48.632)
LOG.log("methodType " + returnType + ' ' + Arrays.toString(paramTypes) + ' ' + mt, TRACE_LEVEL);[](#l48.633)
return mt;[](#l48.634)
}[](#l48.635)
- }
- /**
* Class used for debugging Nashorn generated method handles[](#l48.639)
*/[](#l48.640)
- private static class TraceCreateMethodHandleFunctionality extends TraceMethodHandleFunctionality {
@Override[](#l48.642)
public MethodHandle debug(final MethodHandle master, final String str, final Object... args) {[](#l48.643)
LOG.log(str + ' ' + describe(args), TRACE_LEVEL);[](#l48.644)
stacktrace(LOG);[](#l48.645)
return master;[](#l48.646)
}[](#l48.647)
- }
--- a/src/jdk/nashorn/internal/runtime/linker/MethodHandleFunctionality.java Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,317 +0,0 @@ -/*
- *
- *
- *
- *
- or visit www.oracle.com if you need additional information or have any
- */ - -package jdk.nashorn.internal.runtime.linker; - -import java.lang.invoke.MethodHandle; -import java.lang.invoke.MethodHandles; -import java.lang.invoke.MethodType; -import java.lang.invoke.SwitchPoint; -import java.lang.reflect.Method; -import java.util.List; - -/**
- */ - -public interface MethodHandleFunctionality {
- /**
* Wrapper for {@link MethodHandles#filterArguments(MethodHandle, int, MethodHandle...)}[](#l49.45)
*[](#l49.46)
* @param target target method handle[](#l49.47)
* @param pos start argument index[](#l49.48)
* @param filters filters[](#l49.49)
*[](#l49.50)
* @return filtered handle[](#l49.51)
*/[](#l49.52)
- public MethodHandle filterArguments(MethodHandle target, int pos, MethodHandle... filters);
- /**
* Wrapper for {@link MethodHandles#filterReturnValue(MethodHandle, MethodHandle)}[](#l49.56)
*[](#l49.57)
* @param target target method handle[](#l49.58)
* @param filter filter[](#l49.59)
*[](#l49.60)
* @return filtered handle[](#l49.61)
*/[](#l49.62)
- public MethodHandle filterReturnValue(MethodHandle target, MethodHandle filter);
- /**
* Wrapper for {@link MethodHandles#guardWithTest(MethodHandle, MethodHandle, MethodHandle)}[](#l49.66)
*[](#l49.67)
* @param test test method handle[](#l49.68)
* @param target target method handle when test is true[](#l49.69)
* @param fallback fallback method handle when test is false[](#l49.70)
*[](#l49.71)
* @return guarded handles[](#l49.72)
*/[](#l49.73)
- public MethodHandle guardWithTest(MethodHandle test, MethodHandle target, MethodHandle fallback);
- /**
* Wrapper for {@link MethodHandles#insertArguments(MethodHandle, int, Object...)}[](#l49.77)
*[](#l49.78)
* @param target target method handle[](#l49.79)
* @param pos start argument index[](#l49.80)
* @param values values to insert[](#l49.81)
*[](#l49.82)
* @return handle with bound arguments[](#l49.83)
*/[](#l49.84)
- public MethodHandle insertArguments(MethodHandle target, int pos, Object... values);
- /**
* Wrapper for {@link MethodHandles#dropArguments(MethodHandle, int, Class...)}[](#l49.88)
*[](#l49.89)
* @param target target method handle[](#l49.90)
* @param pos start argument index[](#l49.91)
* @param valueTypes valueTypes of arguments to drop[](#l49.92)
*[](#l49.93)
* @return handle with dropped arguments[](#l49.94)
*/[](#l49.95)
- public MethodHandle dropArguments(MethodHandle target, int pos, Class<?>... valueTypes);
- /**
* Wrapper for {@link MethodHandles#dropArguments(MethodHandle, int, List)}[](#l49.99)
*[](#l49.100)
* @param target target method handle[](#l49.101)
* @param pos start argument index[](#l49.102)
* @param valueTypes valueTypes of arguments to drop[](#l49.103)
*[](#l49.104)
* @return handle with dropped arguments[](#l49.105)
*/[](#l49.106)
- public MethodHandle dropArguments(final MethodHandle target, final int pos, final List<Class<?>> valueTypes);
- /**
* Wrapper for {@link MethodHandles#foldArguments(MethodHandle, MethodHandle)}[](#l49.110)
*[](#l49.111)
* @param target target method handle[](#l49.112)
* @param combiner combiner to apply for fold[](#l49.113)
*[](#l49.114)
* @return folded method handle[](#l49.115)
*/[](#l49.116)
- public MethodHandle foldArguments(MethodHandle target, MethodHandle combiner);
- /**
* Wrapper for {@link MethodHandles#explicitCastArguments(MethodHandle, MethodType)}[](#l49.120)
*[](#l49.121)
* @param target target method handle[](#l49.122)
* @param type type to cast to[](#l49.123)
*[](#l49.124)
* @return modified method handle[](#l49.125)
*/[](#l49.126)
- public MethodHandle explicitCastArguments(MethodHandle target, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#arrayElementGetter(Class)}[](#l49.130)
*[](#l49.131)
* @param arrayClass class for array[](#l49.132)
*[](#l49.133)
* @return array element getter[](#l49.134)
*/[](#l49.135)
- public MethodHandle arrayElementGetter(Class<?> arrayClass);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#arrayElementSetter(Class)}[](#l49.139)
*[](#l49.140)
* @param arrayClass class for array[](#l49.141)
*[](#l49.142)
* @return array element setter[](#l49.143)
*/[](#l49.144)
- public MethodHandle arrayElementSetter(Class<?> arrayClass);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#throwException(Class, Class)}[](#l49.148)
*[](#l49.149)
* @param returnType ignored, but method signature will use it[](#l49.150)
* @param exType exception type that will be thrown[](#l49.151)
*[](#l49.152)
* @return exception thrower method handle[](#l49.153)
*/[](#l49.154)
- public MethodHandle throwException(Class<?> returnType, Class<? extends Throwable> exType);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles#constant(Class, Object)}[](#l49.158)
*[](#l49.159)
* @param type type of constant[](#l49.160)
* @param value constant value[](#l49.161)
*[](#l49.162)
* @return method handle that returns said constant[](#l49.163)
*/[](#l49.164)
- public MethodHandle constant(Class<?> type, Object value);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asType(MethodType)}[](#l49.168)
*[](#l49.169)
* @param handle method handle for type conversion[](#l49.170)
* @param type type to convert to[](#l49.171)
*[](#l49.172)
* @return method handle with given type conversion applied[](#l49.173)
*/[](#l49.174)
- public MethodHandle asType(MethodHandle handle, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asCollector(Class, int)}[](#l49.178)
*[](#l49.179)
* @param handle handle to convert[](#l49.180)
* @param arrayType array type for collector array[](#l49.181)
* @param arrayLength length of collector array[](#l49.182)
*[](#l49.183)
* @return method handle with collector[](#l49.184)
*/[](#l49.185)
- public MethodHandle asCollector(MethodHandle handle, Class<?> arrayType, int arrayLength);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#asSpreader(Class, int)}[](#l49.189)
*[](#l49.190)
* @param handle handle to convert[](#l49.191)
* @param arrayType array type for spread[](#l49.192)
* @param arrayLength length of spreader[](#l49.193)
*[](#l49.194)
* @return method handle as spreader[](#l49.195)
*/[](#l49.196)
- public MethodHandle asSpreader(MethodHandle handle, Class<?> arrayType, int arrayLength);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandle#bindTo(Object)}[](#l49.200)
*[](#l49.201)
* @param handle a handle to which to bind a receiver[](#l49.202)
* @param x the receiver[](#l49.203)
*[](#l49.204)
* @return the bound handle[](#l49.205)
*/[](#l49.206)
- public MethodHandle bindTo(MethodHandle handle, Object x);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findGetter(Class, String, Class)}[](#l49.210)
*[](#l49.211)
* @param explicitLookup explicit lookup to be used[](#l49.212)
* @param clazz class to look in[](#l49.213)
* @param name name of field[](#l49.214)
* @param type type of field[](#l49.215)
*[](#l49.216)
* @return getter method handle for virtual field[](#l49.217)
*/[](#l49.218)
- public MethodHandle getter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStaticGetter(Class, String, Class)}[](#l49.222)
*[](#l49.223)
* @param explicitLookup explicit lookup to be used[](#l49.224)
* @param clazz class to look in[](#l49.225)
* @param name name of field[](#l49.226)
* @param type type of field[](#l49.227)
*[](#l49.228)
* @return getter method handle for static field[](#l49.229)
*/[](#l49.230)
- public MethodHandle staticGetter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findSetter(Class, String, Class)}[](#l49.234)
*[](#l49.235)
* @param explicitLookup explicit lookup to be used[](#l49.236)
* @param clazz class to look in[](#l49.237)
* @param name name of field[](#l49.238)
* @param type type of field[](#l49.239)
*[](#l49.240)
* @return setter method handle for virtual field[](#l49.241)
*/[](#l49.242)
- public MethodHandle setter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStaticSetter(Class, String, Class)}[](#l49.246)
*[](#l49.247)
* @param explicitLookup explicit lookup to be used[](#l49.248)
* @param clazz class to look in[](#l49.249)
* @param name name of field[](#l49.250)
* @param type type of field[](#l49.251)
*[](#l49.252)
* @return setter method handle for static field[](#l49.253)
*/[](#l49.254)
- public MethodHandle staticSetter(MethodHandles.Lookup explicitLookup, Class clazz, String name, Class type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#unreflect(Method)}[](#l49.258)
*[](#l49.259)
* Unreflect a method as a method handle[](#l49.260)
*[](#l49.261)
* @param method method to unreflect[](#l49.262)
* @return unreflected method as method handle[](#l49.263)
*/[](#l49.264)
- public MethodHandle find(Method method);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findStatic(Class, String, MethodType)}[](#l49.268)
*[](#l49.269)
* @param explicitLookup explicit lookup to be used[](#l49.270)
* @param clazz class to look in[](#l49.271)
* @param name name of method[](#l49.272)
* @param type method type[](#l49.273)
*[](#l49.274)
* @return method handle for static method[](#l49.275)
*/[](#l49.276)
- public MethodHandle findStatic(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type);
- /**
* Wrapper for {@link java.lang.invoke.MethodHandles.Lookup#findVirtual(Class, String, MethodType)}[](#l49.280)
*[](#l49.281)
* @param explicitLookup explicit lookup to be used[](#l49.282)
* @param clazz class to look in[](#l49.283)
* @param name name of method[](#l49.284)
* @param type method type[](#l49.285)
*[](#l49.286)
* @return method handle for virtual method[](#l49.287)
*/[](#l49.288)
- public MethodHandle findVirtual(MethodHandles.Lookup explicitLookup, Class<?> clazz, String name, MethodType type);
- /**
* Wrapper for SwitchPoint creation. Just like {@code new SwitchPoint()} but potentially[](#l49.292)
* tracked[](#l49.293)
*[](#l49.294)
* @return new switch point[](#l49.295)
*/[](#l49.296)
- public SwitchPoint createSwitchPoint();
- /**
* Wrapper for {@link SwitchPoint#guardWithTest(MethodHandle, MethodHandle)}[](#l49.300)
*[](#l49.301)
* @param sp switch point[](#l49.302)
* @param before method handle when switchpoint is valid[](#l49.303)
* @param after method handle when switchpoint is invalidated[](#l49.304)
*[](#l49.305)
* @return guarded method handle[](#l49.306)
*/[](#l49.307)
- public MethodHandle guardWithTest(SwitchPoint sp, MethodHandle before, MethodHandle after);
- /**
* Wrapper for {@link MethodType#methodType(Class, Class...)}[](#l49.311)
*[](#l49.312)
* @param returnType return type for method type[](#l49.313)
* @param paramTypes parameter types for method type[](#l49.314)
*[](#l49.315)
* @return the method type[](#l49.316)
*/[](#l49.317)
- public MethodType type(Class returnType, Class... paramTypes);
--- a/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornBottomLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -27,7 +27,7 @@ import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import jdk.internal.dynalink.CallSiteDescriptor; @@ -46,7 +46,7 @@
- setters for Java objects that couldn't be linked by any other linker, and throw appropriate ECMAScript errors for
- attempts to invoke arbitrary Java objects as functions or constructors. */ -class NashornBottomLinker implements GuardingDynamicLinker { +final class NashornBottomLinker implements GuardingDynamicLinker { @Override public GuardedInvocation getGuardedInvocation(final LinkRequest linkRequest, final LinkerServices linkerServices)
--- a/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornGuards.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.runtime.linker; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles;
--- a/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.runtime.linker; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -47,7 +47,7 @@
- language runtimes by being declared in {@code META-INF/services/jdk.internal.dynalink.linker.GuardingDynamicLinker}
- file of Nashorn's distribution. */ -public class NashornLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator { +final class NashornLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator { /**
--- a/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornPrimitiveLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,7 @@ package jdk.nashorn.internal.runtime.linker; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; @@ -45,7 +45,7 @@
- engines. It is used for treatment of strings, boolean, and numbers as JavaScript primitives. Also provides ECMAScript
- primitive type conversions for these types when linking to Java methods. */ -class NashornPrimitiveLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator { +final class NashornPrimitiveLinker implements TypeBasedGuardingDynamicLinker, GuardingTypeConverterFactory, ConversionComparator { @Override public boolean canLinkType(final Class<?> type) { return canLinkTypeStatic(type);
--- a/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/NashornStaticClassLinker.java Sat Mar 09 21:49:32 2013 +0530 @@ -48,7 +48,7 @@
- var r = new Runnable(function() { print("Hello World" })
- */ -class NashornStaticClassLinker implements TypeBasedGuardingDynamicLinker { +final class NashornStaticClassLinker implements TypeBasedGuardingDynamicLinker { private static final GuardingDynamicLinker staticClassLinker = BeansLinker.getLinkerForClass(StaticClass.class); @Override
--- a/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Wed Mar 06 22:38:18 2013 +0530 +++ b/src/jdk/nashorn/internal/runtime/linker/PrimitiveLookup.java Sat Mar 09 21:49:32 2013 +0530 @@ -25,7 +25,8 @@ package jdk.nashorn.internal.runtime.linker; -import static jdk.nashorn.internal.runtime.linker.Lookup.MH; +import jdk.nashorn.internal.lookup.Lookup; +import static jdk.nashorn.internal.lookup.Lookup.MH; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodType;
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/test/script/currently-failing/JDK-8006529.js Sat Mar 09 21:49:32 2013 +0530 @@ -0,0 +1,210 @@ +/*
- or visit www.oracle.com if you need additional information or have any
- */ + +/**
- *
- / + +/
- */
+
+var Parser = Java.type("jdk.nashorn.internal.parser.Parser")
+var Compiler = Java.type("jdk.nashorn.internal.codegen.Compiler")
+var Context = Java.type("jdk.nashorn.internal.runtime.Context")
+var ScriptEnvironment = Java.type("jdk.nashorn.internal.runtime.ScriptEnvironment")
+var Source = Java.type("jdk.nashorn.internal.runtime.Source")
+var FunctionNode = Java.type("jdk.nashorn.internal.ir.FunctionNode")
+
+// Compiler class methods and fields
+var parseMethod = Parser.class.getMethod("parse");
+var compileMethod = Compiler.class.getMethod("compile");
+
+// NOTE: private field. But this is a trusted test
+// Compiler.functionNode +var functionNodeField = Compiler.class.getDeclaredField("functionNode"); +functionNodeField.setAccessible(true); + +// FunctionNode methods + +// FunctionNode.getFunctions method +var getFunctionsMethod = FunctionNode.class.getMethod("getFunctions"); + +// These are method names of methods in FunctionNode class +var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'allVarsInScope', 'isStrictMode'] + +// corresponding Method objects of FunctionNode class +var functionNodeMethods = {}; +// initialize FunctionNode methods +(function() {
- for (var f in allAssertionList) {
var method = allAssertionList[f];[](#l56.74)
functionNodeMethods[method] = FunctionNode.class.getMethod(method);[](#l56.75)
- }
+})(); + +// returns "script" functionNode from Compiler instance +function getScriptNode(compiler) {
+} + +// returns functionNode.getFunctions().get(0) +function getFirstFunction(functionNode) {
+} + +// compile(script) -- compiles a script specified as a string with its +// source code, returns a jdk.nashorn.internal.ir.FunctionNode object +// representing it. +function compile(source) {
- var source = new Source("", source);
- var parser = new Parser(Context.getContext().getEnv(), source, null);
- var func = parseMethod.invoke(parser);
- var compiler = new Compiler(Context.getContext().getEnv(), func);
+}; + +var allAssertions = (function() {
- var allAssertions = {}
- for(var assertion in allAssertionList) {
allAssertions[allAssertionList[assertion]] = true[](#l56.108)
- }
- return allAssertions;
+})(); + + +// test(f[, assertions...]) tests whether all the specified assertions on the +// passed function node are true. +function test(f) {
- var assertions = {}
- for(var i = 1; i < arguments.length; ++i) {
var assertion = arguments[i][](#l56.119)
if(!allAssertions[assertion]) {[](#l56.120)
throw "Unknown assertion " + assertion + " for " + f;[](#l56.121)
}[](#l56.122)
assertions[assertion] = true[](#l56.123)
- }
- for(var assertion in allAssertions) {
var expectedValue = !!assertions[assertion][](#l56.126)
if(functionNodeMethods[assertion].invoke(f) !== expectedValue) {[](#l56.127)
throw "Expected " + assertion + " === " + expectedValue + " for " + f;[](#l56.128)
}[](#l56.129)
- }
+} + +// testFirstFn(script[, assertions...] tests whether all the specified +// assertions are true in the first function in the given script; "script" +// is a string with the source text of the script. +function testFirstFn(script) {
+} + +// ---------------------------------- ACTUAL TESTS START HERE -------------- + +// The simplest possible functions have no attributes set +testFirstFn("function f() { }") +testFirstFn("function f(x) { x }") + +// A function referencing a global needs parent scope, and it needs callee +// (because parent scope is passed through callee) +testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope') + +// A function referencing "arguments" will have to be vararg. It also needs +// the callee, as it needs to fill out "arguments.callee". +testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg') + +// A function referencing "arguments" will have to be vararg. If it is +// strict, it will not have to have a callee, though. +testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode') + +// A function defining "arguments" as a parameter will not be vararg. +testFirstFn("function f(arguments) { arguments }") + +// A function defining "arguments" as a nested function will not be vararg. +testFirstFn("function f() { function arguments() {}; arguments; }") + +// A function defining "arguments" as a local variable will be vararg. +testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee') + +// A self-referencing function defined as a statement doesn't need a self +// symbol, as it'll rather obtain itself from the parent scope. +testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope') + +// A self-referencing function defined as an expression needs a self symbol, +// as it can't obtain itself from the parent scope. +testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol') + +// A child function accessing parent's variable triggers the need for scope +// in parent +testFirstFn("(function f() { var x; function g() { x } })", 'needsScope') + +// A child function accessing parent's parameter triggers the need for scope +// in parent +testFirstFn("(function f(x) { function g() { x } })", 'needsScope') + +// A child function accessing a global variable triggers the need for parent +// scope in parent +testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee') + +// A child function redefining a local variable from its parent should not +// affect the parent function in any way +testFirstFn("(function f() { var x; function g() { var x; x } })") + +// Using "with" unleashes a lot of needs: parent scope, callee, own scope, +// and all variables in scope. Actually, we could make "with" less wasteful, +// and only put those variables in scope that it actually references, similar +// to what nested functions do with variables in their parents. +testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'allVarsInScope') + +// Using "eval" is as bad as using "with" with the added requirement of +// being vararg, 'cause we don't know if eval will be using "arguments". +testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'allVarsInScope') + +// Nested function using "with" is pretty much the same as the parent +// function needing with. +testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'allVarsInScope') +// Nested function using "eval" is almost the same as parent function using +// eval, but at least the parent doesn't have to be vararg. +testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'allVarsInScope') + +// Function with 250 named parameters is ordinary +testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250) { p250 = p249 }") + +// Function with 251 named parameters is variable arguments +testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251) { p250 = p251 }", 'isVarArg')
--- a/test/script/trusted/JDK-8006529.js Wed Mar 06 22:38:18 2013 +0530 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,210 +0,0 @@ -/*
- or visit www.oracle.com if you need additional information or have any
- */ - -/**
- *
- / - -/
- */
-
-var Parser = Java.type("jdk.nashorn.internal.parser.Parser")
-var Compiler = Java.type("jdk.nashorn.internal.codegen.Compiler")
-var Context = Java.type("jdk.nashorn.internal.runtime.Context")
-var ScriptEnvironment = Java.type("jdk.nashorn.internal.runtime.ScriptEnvironment")
-var Source = Java.type("jdk.nashorn.internal.runtime.Source")
-var FunctionNode = Java.type("jdk.nashorn.internal.ir.FunctionNode")
-
-// Compiler class methods and fields
-var parseMethod = Parser.class.getMethod("parse");
-var compileMethod = Compiler.class.getMethod("compile");
-
-// NOTE: private field. But this is a trusted test
-// Compiler.functionNode -var functionNodeField = Compiler.class.getDeclaredField("functionNode"); -functionNodeField.setAccessible(true); - -// FunctionNode methods - -// FunctionNode.getFunctions method -var getFunctionsMethod = FunctionNode.class.getMethod("getFunctions"); - -// These are method names of methods in FunctionNode class -var allAssertionList = ['isVarArg', 'needsParentScope', 'needsCallee', 'needsScope', 'needsSelfSymbol', 'isSplit', 'hasEval', 'hasWith', 'hasDeepWithOrEval', 'allVarsInScope', 'isStrictMode'] - -// corresponding Method objects of FunctionNode class -var functionNodeMethods = {}; -// initialize FunctionNode methods -(function() {
- for (var f in allAssertionList) {
var method = allAssertionList[f];[](#l57.74)
functionNodeMethods[method] = FunctionNode.class.getMethod(method);[](#l57.75)
- }
-})(); - -// returns "script" functionNode from Compiler instance -function getScriptNode(compiler) {
-} - -// returns functionNode.getFunctions().get(0) -function getFirstFunction(functionNode) {
-} - -// compile(script) -- compiles a script specified as a string with its -// source code, returns a jdk.nashorn.internal.ir.FunctionNode object -// representing it. -function compile(source) {
- var source = new Source("", source);
- var parser = new Parser(Context.getContext().getEnv(), source, null);
- var func = parseMethod.invoke(parser);
- var compiler = new Compiler(Context.getContext().getEnv(), func);
-}; - -var allAssertions = (function() {
- var allAssertions = {}
- for(var assertion in allAssertionList) {
allAssertions[allAssertionList[assertion]] = true[](#l57.108)
- }
- return allAssertions;
-})(); - - -// test(f[, assertions...]) tests whether all the specified assertions on the -// passed function node are true. -function test(f) {
- var assertions = {}
- for(var i = 1; i < arguments.length; ++i) {
var assertion = arguments[i][](#l57.119)
if(!allAssertions[assertion]) {[](#l57.120)
throw "Unknown assertion " + assertion + " for " + f;[](#l57.121)
}[](#l57.122)
assertions[assertion] = true[](#l57.123)
- }
- for(var assertion in allAssertions) {
var expectedValue = !!assertions[assertion][](#l57.126)
if(functionNodeMethods[assertion].invoke(f) !== expectedValue) {[](#l57.127)
throw "Expected " + assertion + " === " + expectedValue + " for " + f;[](#l57.128)
}[](#l57.129)
- }
-} - -// testFirstFn(script[, assertions...] tests whether all the specified -// assertions are true in the first function in the given script; "script" -// is a string with the source text of the script. -function testFirstFn(script) {
-} - -// ---------------------------------- ACTUAL TESTS START HERE -------------- - -// The simplest possible functions have no attributes set -testFirstFn("function f() { }") -testFirstFn("function f(x) { x }") - -// A function referencing a global needs parent scope, and it needs callee -// (because parent scope is passed through callee) -testFirstFn("function f() { x }", 'needsCallee', 'needsParentScope') - -// A function referencing "arguments" will have to be vararg. It also needs -// the callee, as it needs to fill out "arguments.callee". -testFirstFn("function f() { arguments }", 'needsCallee', 'isVarArg') - -// A function referencing "arguments" will have to be vararg. If it is -// strict, it will not have to have a callee, though. -testFirstFn("function f() {'use strict'; arguments }", 'isVarArg', 'isStrictMode') - -// A function defining "arguments" as a parameter will not be vararg. -testFirstFn("function f(arguments) { arguments }") - -// A function defining "arguments" as a nested function will not be vararg. -testFirstFn("function f() { function arguments() {}; arguments; }") - -// A function defining "arguments" as a local variable will be vararg. -testFirstFn("function f() { var arguments; arguments; }", 'isVarArg', 'needsCallee') - -// A self-referencing function defined as a statement doesn't need a self -// symbol, as it'll rather obtain itself from the parent scope. -testFirstFn("function f() { f() }", 'needsCallee', 'needsParentScope') - -// A self-referencing function defined as an expression needs a self symbol, -// as it can't obtain itself from the parent scope. -testFirstFn("(function f() { f() })", 'needsCallee', 'needsSelfSymbol') - -// A child function accessing parent's variable triggers the need for scope -// in parent -testFirstFn("(function f() { var x; function g() { x } })", 'needsScope') - -// A child function accessing parent's parameter triggers the need for scope -// in parent -testFirstFn("(function f(x) { function g() { x } })", 'needsScope') - -// A child function accessing a global variable triggers the need for parent -// scope in parent -testFirstFn("(function f() { function g() { x } })", 'needsParentScope', 'needsCallee') - -// A child function redefining a local variable from its parent should not -// affect the parent function in any way -testFirstFn("(function f() { var x; function g() { var x; x } })") - -// Using "with" unleashes a lot of needs: parent scope, callee, own scope, -// and all variables in scope. Actually, we could make "with" less wasteful, -// and only put those variables in scope that it actually references, similar -// to what nested functions do with variables in their parents. -testFirstFn("(function f() { var o; with(o) {} })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasWith', 'hasDeepWithOrEval', 'allVarsInScope') - -// Using "eval" is as bad as using "with" with the added requirement of -// being vararg, 'cause we don't know if eval will be using "arguments". -testFirstFn("(function f() { eval() })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasEval', 'isVarArg', 'hasDeepWithOrEval', 'allVarsInScope') - -// Nested function using "with" is pretty much the same as the parent -// function needing with. -testFirstFn("(function f() { function g() { var o; with(o) {} } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'allVarsInScope') -// Nested function using "eval" is almost the same as parent function using -// eval, but at least the parent doesn't have to be vararg. -testFirstFn("(function f() { function g() { eval() } })", 'needsParentScope', 'needsCallee', 'needsScope', 'hasDeepWithOrEval', 'allVarsInScope') - -// Function with 250 named parameters is ordinary -testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250) { p250 = p249 }") - -// Function with 251 named parameters is variable arguments -testFirstFn("function f(p1, p2, p3, p4, p5, p6, p7, p8, p9, p10, p11, p12, p13, p14, p15, p16, p17, p18, p19, p20, p21, p22, p23, p24, p25, p26, p27, p28, p29, p30, p31, p32, p33, p34, p35, p36, p37, p38, p39, p40, p41, p42, p43, p44, p45, p46, p47, p48, p49, p50, p51, p52, p53, p54, p55, p56, p57, p58, p59, p60, p61, p62, p63, p64, p65, p66, p67, p68, p69, p70, p71, p72, p73, p74, p75, p76, p77, p78, p79, p80, p81, p82, p83, p84, p85, p86, p87, p88, p89, p90, p91, p92, p93, p94, p95, p96, p97, p98, p99, p100, p101, p102, p103, p104, p105, p106, p107, p108, p109, p110, p111, p112, p113, p114, p115, p116, p117, p118, p119, p120, p121, p122, p123, p124, p125, p126, p127, p128, p129, p130, p131, p132, p133, p134, p135, p136, p137, p138, p139, p140, p141, p142, p143, p144, p145, p146, p147, p148, p149, p150, p151, p152, p153, p154, p155, p156, p157, p158, p159, p160, p161, p162, p163, p164, p165, p166, p167, p168, p169, p170, p171, p172, p173, p174, p175, p176, p177, p178, p179, p180, p181, p182, p183, p184, p185, p186, p187, p188, p189, p190, p191, p192, p193, p194, p195, p196, p197, p198, p199, p200, p201, p202, p203, p204, p205, p206, p207, p208, p209, p210, p211, p212, p213, p214, p215, p216, p217, p218, p219, p220, p221, p222, p223, p224, p225, p226, p227, p228, p229, p230, p231, p232, p233, p234, p235, p236, p237, p238, p239, p240, p241, p242, p243, p244, p245, p246, p247, p248, p249, p250, p251) { p250 = p251 }", 'isVarArg')