Thu, 08 Aug 2013 18:19:29 +0530
Merge
src/jdk/internal/dynalink/support/Backport.java | file | annotate | diff | comparison | revisions |
1.1 --- a/make/project.properties Tue Aug 06 17:01:56 2013 -0700 1.2 +++ b/make/project.properties Thu Aug 08 18:19:29 2013 +0530 1.3 @@ -223,9 +223,9 @@ 1.4 run.test.user.country=TR 1.5 1.6 # -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods 1.7 -run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country} 1.8 +run.test.jvmargs.main=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -ea -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country} -XX:+HeapDumpOnOutOfMemoryError 1.9 1.10 -#-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M 1.11 +#-XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M 1.12 run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs.main} 1.13 1.14 run.test.jvmsecurityargs=-Xverify:all -Djava.security.properties=${basedir}/make/java.security.override -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy
2.1 --- a/src/jdk/internal/dynalink/ChainedCallSite.java Tue Aug 06 17:01:56 2013 -0700 2.2 +++ b/src/jdk/internal/dynalink/ChainedCallSite.java Thu Aug 08 18:19:29 2013 +0530 2.3 @@ -85,12 +85,12 @@ 2.4 2.5 import java.lang.invoke.MethodHandle; 2.6 import java.lang.invoke.MethodHandles; 2.7 -import java.lang.invoke.MethodType; 2.8 import java.util.Iterator; 2.9 import java.util.LinkedList; 2.10 import java.util.concurrent.atomic.AtomicReference; 2.11 import jdk.internal.dynalink.linker.GuardedInvocation; 2.12 import jdk.internal.dynalink.support.AbstractRelinkableCallSite; 2.13 +import jdk.internal.dynalink.support.Lookup; 2.14 2.15 /** 2.16 * A relinkable call site that maintains a chain of linked method handles. In the default implementation, up to 8 method 2.17 @@ -103,6 +103,9 @@ 2.18 * handle is always at the start of the chain. 2.19 */ 2.20 public class ChainedCallSite extends AbstractRelinkableCallSite { 2.21 + private static final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class, 2.22 + MethodHandle.class); 2.23 + 2.24 private final AtomicReference<LinkedList<GuardedInvocation>> invocations = new AtomicReference<>(); 2.25 2.26 /** 2.27 @@ -194,18 +197,4 @@ 2.28 private MethodHandle prune(MethodHandle relink) { 2.29 return relinkInternal(null, relink, false); 2.30 } 2.31 - 2.32 - private static final MethodHandle PRUNE; 2.33 - static { 2.34 - try { 2.35 - PRUNE = MethodHandles.lookup().findSpecial(ChainedCallSite.class, "prune", MethodType.methodType( 2.36 - MethodHandle.class, MethodHandle.class), ChainedCallSite.class); 2.37 - // NOTE: using two catch blocks so we don't introduce a reference to 1.7 ReflectiveOperationException, allowing 2.38 - // Dynalink to be used on 1.6 JVMs with Remi's backport library. 2.39 - } catch(IllegalAccessException e) { 2.40 - throw new AssertionError(e.getMessage(), e); // Can not happen 2.41 - } catch(NoSuchMethodException e) { 2.42 - throw new AssertionError(e.getMessage(), e); // Can not happen 2.43 - } 2.44 - } 2.45 }
3.1 --- a/src/jdk/internal/dynalink/DynamicLinkerFactory.java Tue Aug 06 17:01:56 2013 -0700 3.2 +++ b/src/jdk/internal/dynalink/DynamicLinkerFactory.java Thu Aug 08 18:19:29 2013 +0530 3.3 @@ -84,6 +84,8 @@ 3.4 package jdk.internal.dynalink; 3.5 3.6 import java.lang.invoke.MutableCallSite; 3.7 +import java.security.AccessController; 3.8 +import java.security.PrivilegedAction; 3.9 import java.util.ArrayList; 3.10 import java.util.Arrays; 3.11 import java.util.Collections; 3.12 @@ -117,7 +119,9 @@ 3.13 */ 3.14 public static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8; 3.15 3.16 - private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 3.17 + private boolean classLoaderExplicitlySet = false; 3.18 + private ClassLoader classLoader; 3.19 + 3.20 private List<? extends GuardingDynamicLinker> prioritizedLinkers; 3.21 private List<? extends GuardingDynamicLinker> fallbackLinkers; 3.22 private int runtimeContextArgCount = 0; 3.23 @@ -126,12 +130,13 @@ 3.24 3.25 /** 3.26 * Sets the class loader for automatic discovery of available linkers. If not set explicitly, then the thread 3.27 - * context class loader at the time of the constructor invocation will be used. 3.28 + * context class loader at the time of {@link #createLinker()} invocation will be used. 3.29 * 3.30 * @param classLoader the class loader used for the autodiscovery of available linkers. 3.31 */ 3.32 public void setClassLoader(ClassLoader classLoader) { 3.33 this.classLoader = classLoader; 3.34 + classLoaderExplicitlySet = true; 3.35 } 3.36 3.37 /** 3.38 @@ -260,7 +265,8 @@ 3.39 addClasses(knownLinkerClasses, prioritizedLinkers); 3.40 addClasses(knownLinkerClasses, fallbackLinkers); 3.41 3.42 - final List<GuardingDynamicLinker> discovered = AutoDiscovery.loadLinkers(classLoader); 3.43 + final ClassLoader effectiveClassLoader = classLoaderExplicitlySet ? classLoader : getThreadContextClassLoader(); 3.44 + final List<GuardingDynamicLinker> discovered = AutoDiscovery.loadLinkers(effectiveClassLoader); 3.45 // Now, concatenate ... 3.46 final List<GuardingDynamicLinker> linkers = 3.47 new ArrayList<>(prioritizedLinkers.size() + discovered.size() 3.48 @@ -303,6 +309,15 @@ 3.49 runtimeContextArgCount, syncOnRelink, unstableRelinkThreshold); 3.50 } 3.51 3.52 + private static ClassLoader getThreadContextClassLoader() { 3.53 + return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 3.54 + @Override 3.55 + public ClassLoader run() { 3.56 + return Thread.currentThread().getContextClassLoader(); 3.57 + } 3.58 + }); 3.59 + } 3.60 + 3.61 private static void addClasses(Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses, 3.62 List<? extends GuardingDynamicLinker> linkers) { 3.63 for(GuardingDynamicLinker linker: linkers) {
4.1 --- a/src/jdk/internal/dynalink/beans/ClassString.java Tue Aug 06 17:01:56 2013 -0700 4.2 +++ b/src/jdk/internal/dynalink/beans/ClassString.java Thu Aug 08 18:19:29 2013 +0530 4.3 @@ -112,10 +112,6 @@ 4.4 this(type.parameterArray()); 4.5 } 4.6 4.7 - Class<?>[] getClasses() { 4.8 - return classes; 4.9 - } 4.10 - 4.11 @Override 4.12 public boolean equals(Object other) { 4.13 if(!(other instanceof ClassString)) {
5.1 --- a/src/jdk/internal/dynalink/beans/StaticClassLinker.java Tue Aug 06 17:01:56 2013 -0700 5.2 +++ b/src/jdk/internal/dynalink/beans/StaticClassLinker.java Thu Aug 08 18:19:29 2013 +0530 5.3 @@ -189,15 +189,17 @@ 5.4 return type == StaticClass.class; 5.5 } 5.6 5.7 - /*private*/ static final MethodHandle GET_CLASS = new Lookup(MethodHandles.lookup()).findVirtual(StaticClass.class, 5.8 - "getRepresentedClass", MethodType.methodType(Class.class)); 5.9 - 5.10 - /*private*/ static final MethodHandle IS_CLASS = new Lookup(MethodHandles.lookup()).findStatic(StaticClassLinker.class, 5.11 - "isClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class)); 5.12 - 5.13 + /*private*/ static final MethodHandle GET_CLASS; 5.14 + /*private*/ static final MethodHandle IS_CLASS; 5.15 /*private*/ static final MethodHandle ARRAY_CTOR = Lookup.PUBLIC.findStatic(Array.class, "newInstance", 5.16 MethodType.methodType(Object.class, Class.class, int.class)); 5.17 5.18 + static { 5.19 + final Lookup lookup = new Lookup(MethodHandles.lookup()); 5.20 + GET_CLASS = lookup.findVirtual(StaticClass.class, "getRepresentedClass", MethodType.methodType(Class.class)); 5.21 + IS_CLASS = lookup.findOwnStatic("isClass", Boolean.TYPE, Class.class, Object.class); 5.22 + } 5.23 + 5.24 @SuppressWarnings("unused") 5.25 private static boolean isClass(Class<?> clazz, Object obj) { 5.26 return obj instanceof StaticClass && ((StaticClass)obj).getRepresentedClass() == clazz;
6.1 --- a/src/jdk/internal/dynalink/support/Backport.java Tue Aug 06 17:01:56 2013 -0700 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,99 +0,0 @@ 6.4 -/* 6.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 - * 6.8 - * This code is free software; you can redistribute it and/or modify it 6.9 - * under the terms of the GNU General Public License version 2 only, as 6.10 - * published by the Free Software Foundation. Oracle designates this 6.11 - * particular file as subject to the "Classpath" exception as provided 6.12 - * by Oracle in the LICENSE file that accompanied this code. 6.13 - * 6.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 6.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 - * version 2 for more details (a copy is included in the LICENSE file that 6.18 - * accompanied this code). 6.19 - * 6.20 - * You should have received a copy of the GNU General Public License version 6.21 - * 2 along with this work; if not, write to the Free Software Foundation, 6.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 - * 6.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.25 - * or visit www.oracle.com if you need additional information or have any 6.26 - * questions. 6.27 - */ 6.28 - 6.29 -/* 6.30 - * This file is available under and governed by the GNU General Public 6.31 - * License version 2 only, as published by the Free Software Foundation. 6.32 - * However, the following notice accompanied the original version of this 6.33 - * file, and Oracle licenses the original version of this file under the BSD 6.34 - * license: 6.35 - */ 6.36 -/* 6.37 - Copyright 2009-2013 Attila Szegedi 6.38 - 6.39 - Licensed under both the Apache License, Version 2.0 (the "Apache License") 6.40 - and the BSD License (the "BSD License"), with licensee being free to 6.41 - choose either of the two at their discretion. 6.42 - 6.43 - You may not use this file except in compliance with either the Apache 6.44 - License or the BSD License. 6.45 - 6.46 - If you choose to use this file in compliance with the Apache License, the 6.47 - following notice applies to you: 6.48 - 6.49 - You may obtain a copy of the Apache License at 6.50 - 6.51 - http://www.apache.org/licenses/LICENSE-2.0 6.52 - 6.53 - Unless required by applicable law or agreed to in writing, software 6.54 - distributed under the License is distributed on an "AS IS" BASIS, 6.55 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 6.56 - implied. See the License for the specific language governing 6.57 - permissions and limitations under the License. 6.58 - 6.59 - If you choose to use this file in compliance with the BSD License, the 6.60 - following notice applies to you: 6.61 - 6.62 - Redistribution and use in source and binary forms, with or without 6.63 - modification, are permitted provided that the following conditions are 6.64 - met: 6.65 - * Redistributions of source code must retain the above copyright 6.66 - notice, this list of conditions and the following disclaimer. 6.67 - * Redistributions in binary form must reproduce the above copyright 6.68 - notice, this list of conditions and the following disclaimer in the 6.69 - documentation and/or other materials provided with the distribution. 6.70 - * Neither the name of the copyright holder nor the names of 6.71 - contributors may be used to endorse or promote products derived from 6.72 - this software without specific prior written permission. 6.73 - 6.74 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 6.75 - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 6.76 - TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 6.77 - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER 6.78 - BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 6.79 - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 6.80 - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 6.81 - BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 6.82 - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 6.83 - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 6.84 - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 6.85 -*/ 6.86 - 6.87 -package jdk.internal.dynalink.support; 6.88 - 6.89 -import java.lang.invoke.MethodHandles; 6.90 - 6.91 -/** 6.92 - * @author Attila Szegedi 6.93 - */ 6.94 -public class Backport { 6.95 - /** 6.96 - * True if Remi's JSR-292 backport agent is active; false if we're using native OpenJDK JSR-292 support. 6.97 - */ 6.98 - public static final boolean inUse = MethodHandles.class.getName().startsWith("jsr292"); 6.99 - 6.100 - private Backport() { 6.101 - } 6.102 -}
7.1 --- a/src/jdk/internal/dynalink/support/ClassMap.java Tue Aug 06 17:01:56 2013 -0700 7.2 +++ b/src/jdk/internal/dynalink/support/ClassMap.java Thu Aug 08 18:19:29 2013 +0530 7.3 @@ -85,6 +85,8 @@ 7.4 7.5 import java.lang.ref.Reference; 7.6 import java.lang.ref.SoftReference; 7.7 +import java.security.AccessController; 7.8 +import java.security.PrivilegedAction; 7.9 import java.util.Map; 7.10 import java.util.WeakHashMap; 7.11 import java.util.concurrent.ConcurrentHashMap; 7.12 @@ -122,21 +124,12 @@ 7.13 protected abstract T computeValue(Class<?> clazz); 7.14 7.15 /** 7.16 - * Returns the class loader that governs the strong referenceability of this class map. 7.17 - * 7.18 - * @return the class loader that governs the strong referenceability of this class map. 7.19 - */ 7.20 - public ClassLoader getClassLoader() { 7.21 - return classLoader; 7.22 - } 7.23 - 7.24 - /** 7.25 * Returns the value associated with the class 7.26 * 7.27 * @param clazz the class 7.28 * @return the value associated with the class 7.29 */ 7.30 - public T get(Class<?> clazz) { 7.31 + public T get(final Class<?> clazz) { 7.32 // Check in fastest first - objects we're allowed to strongly reference 7.33 final T v = map.get(clazz); 7.34 if(v != null) { 7.35 @@ -156,8 +149,16 @@ 7.36 // Not found in either place; create a new value 7.37 final T newV = computeValue(clazz); 7.38 assert newV != null; 7.39 + 7.40 + final ClassLoader clazzLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 7.41 + @Override 7.42 + public ClassLoader run() { 7.43 + return clazz.getClassLoader(); 7.44 + } 7.45 + }); 7.46 + 7.47 // If allowed to strongly reference, put it in the fast map 7.48 - if(Guards.canReferenceDirectly(classLoader, clazz.getClassLoader())) { 7.49 + if(Guards.canReferenceDirectly(classLoader, clazzLoader)) { 7.50 final T oldV = map.putIfAbsent(clazz, newV); 7.51 return oldV != null ? oldV : newV; 7.52 }
8.1 --- a/src/jdk/internal/dynalink/support/Guards.java Tue Aug 06 17:01:56 2013 -0700 8.2 +++ b/src/jdk/internal/dynalink/support/Guards.java Thu Aug 08 18:19:29 2013 +0530 8.3 @@ -258,23 +258,24 @@ 8.4 type.changeReturnType(Boolean.TYPE), new int[] { pos }); 8.5 } 8.6 8.7 - private static final MethodHandle IS_OF_CLASS = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 8.8 - "isOfClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class)); 8.9 - 8.10 private static final MethodHandle IS_INSTANCE = Lookup.PUBLIC.findVirtual(Class.class, "isInstance", 8.11 MethodType.methodType(Boolean.TYPE, Object.class)); 8.12 8.13 - private static final MethodHandle IS_ARRAY = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, "isArray", 8.14 - MethodType.methodType(Boolean.TYPE, Object.class)); 8.15 + private static final MethodHandle IS_OF_CLASS; 8.16 + private static final MethodHandle IS_ARRAY; 8.17 + private static final MethodHandle IS_IDENTICAL; 8.18 + private static final MethodHandle IS_NULL; 8.19 + private static final MethodHandle IS_NOT_NULL; 8.20 8.21 - private static final MethodHandle IS_IDENTICAL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 8.22 - "isIdentical", MethodType.methodType(Boolean.TYPE, Object.class, Object.class)); 8.23 + static { 8.24 + final Lookup lookup = new Lookup(MethodHandles.lookup()); 8.25 8.26 - private static final MethodHandle IS_NULL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 8.27 - "isNull", MethodType.methodType(Boolean.TYPE, Object.class)); 8.28 - 8.29 - private static final MethodHandle IS_NOT_NULL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 8.30 - "isNotNull", MethodType.methodType(Boolean.TYPE, Object.class)); 8.31 + IS_OF_CLASS = lookup.findOwnStatic("isOfClass", Boolean.TYPE, Class.class, Object.class); 8.32 + IS_ARRAY = lookup.findOwnStatic("isArray", Boolean.TYPE, Object.class); 8.33 + IS_IDENTICAL = lookup.findOwnStatic("isIdentical", Boolean.TYPE, Object.class, Object.class); 8.34 + IS_NULL = lookup.findOwnStatic("isNull", Boolean.TYPE, Object.class); 8.35 + IS_NOT_NULL = lookup.findOwnStatic("isNotNull", Boolean.TYPE, Object.class); 8.36 + } 8.37 8.38 /** 8.39 * Creates a guard method that tests its only argument for being of an exact particular class.
9.1 --- a/src/jdk/internal/dynalink/support/Lookup.java Tue Aug 06 17:01:56 2013 -0700 9.2 +++ b/src/jdk/internal/dynalink/support/Lookup.java Thu Aug 08 18:19:29 2013 +0530 9.3 @@ -89,7 +89,6 @@ 9.4 import java.lang.reflect.Constructor; 9.5 import java.lang.reflect.Field; 9.6 import java.lang.reflect.Method; 9.7 -import java.lang.reflect.Modifier; 9.8 9.9 /** 9.10 * A wrapper around MethodHandles.Lookup that masks checked exceptions in those cases when you're looking up methods 9.11 @@ -235,9 +234,8 @@ 9.12 } 9.13 9.14 /** 9.15 - * Performs a findSpecial on the underlying lookup, except for the backport where it rather uses unreflect. Converts 9.16 - * any encountered {@link IllegalAccessException} into an {@link IllegalAccessError} and a 9.17 - * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. 9.18 + * Performs a findSpecial on the underlying lookup. Converts any encountered {@link IllegalAccessException} into an 9.19 + * {@link IllegalAccessError} and a {@link NoSuchMethodException} into a {@link NoSuchMethodError}. 9.20 * 9.21 * @param declaringClass class declaring the method 9.22 * @param name the name of the method 9.23 @@ -248,13 +246,6 @@ 9.24 */ 9.25 public MethodHandle findSpecial(Class<?> declaringClass, String name, MethodType type) { 9.26 try { 9.27 - if(Backport.inUse) { 9.28 - final Method m = declaringClass.getDeclaredMethod(name, type.parameterArray()); 9.29 - if(!Modifier.isPublic(declaringClass.getModifiers()) || !Modifier.isPublic(m.getModifiers())) { 9.30 - m.setAccessible(true); 9.31 - } 9.32 - return unreflect(m); 9.33 - } 9.34 return lookup.findSpecial(declaringClass, name, type, declaringClass); 9.35 } catch(IllegalAccessException e) { 9.36 final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription(
10.1 --- a/src/jdk/internal/dynalink/support/TypeConverterFactory.java Tue Aug 06 17:01:56 2013 -0700 10.2 +++ b/src/jdk/internal/dynalink/support/TypeConverterFactory.java Thu Aug 08 18:19:29 2013 +0530 10.3 @@ -87,6 +87,8 @@ 10.4 import java.lang.invoke.MethodHandles; 10.5 import java.lang.invoke.MethodType; 10.6 import java.lang.invoke.WrongMethodTypeException; 10.7 +import java.security.AccessController; 10.8 +import java.security.PrivilegedAction; 10.9 import java.util.LinkedList; 10.10 import java.util.List; 10.11 import jdk.internal.dynalink.linker.ConversionComparator; 10.12 @@ -110,7 +112,7 @@ 10.13 private final ClassValue<ClassMap<MethodHandle>> converterMap = new ClassValue<ClassMap<MethodHandle>>() { 10.14 @Override 10.15 protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) { 10.16 - return new ClassMap<MethodHandle>(sourceType.getClassLoader()) { 10.17 + return new ClassMap<MethodHandle>(getClassLoader(sourceType)) { 10.18 @Override 10.19 protected MethodHandle computeValue(Class<?> targetType) { 10.20 try { 10.21 @@ -128,7 +130,7 @@ 10.22 private final ClassValue<ClassMap<MethodHandle>> converterIdentityMap = new ClassValue<ClassMap<MethodHandle>>() { 10.23 @Override 10.24 protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) { 10.25 - return new ClassMap<MethodHandle>(sourceType.getClassLoader()) { 10.26 + return new ClassMap<MethodHandle>(getClassLoader(sourceType)) { 10.27 @Override 10.28 protected MethodHandle computeValue(Class<?> targetType) { 10.29 if(!canAutoConvert(sourceType, targetType)) { 10.30 @@ -143,6 +145,15 @@ 10.31 } 10.32 }; 10.33 10.34 + private static final ClassLoader getClassLoader(final Class<?> clazz) { 10.35 + return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 10.36 + @Override 10.37 + public ClassLoader run() { 10.38 + return clazz.getClassLoader(); 10.39 + } 10.40 + }); 10.41 + } 10.42 + 10.43 /** 10.44 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances. 10.45 *
11.1 --- a/src/jdk/nashorn/internal/codegen/CompileUnit.java Tue Aug 06 17:01:56 2013 -0700 11.2 +++ b/src/jdk/nashorn/internal/codegen/CompileUnit.java Thu Aug 08 18:19:29 2013 +0530 11.3 @@ -33,7 +33,7 @@ 11.4 private final String className; 11.5 11.6 /** Current class generator */ 11.7 - private final ClassEmitter classEmitter; 11.8 + private ClassEmitter classEmitter; 11.9 11.10 private long weight; 11.11 11.12 @@ -64,7 +64,11 @@ 11.13 * @param clazz class with code for this compile unit 11.14 */ 11.15 void setCode(final Class<?> clazz) { 11.16 + clazz.getClass(); // null check 11.17 this.clazz = clazz; 11.18 + // Revisit this - refactor to avoid null-ed out non-final fields 11.19 + // null out emitter 11.20 + this.classEmitter = null; 11.21 } 11.22 11.23 /**
12.1 --- a/src/jdk/nashorn/internal/objects/Global.java Tue Aug 06 17:01:56 2013 -0700 12.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Thu Aug 08 18:19:29 2013 +0530 12.3 @@ -41,6 +41,8 @@ 12.4 import java.util.LinkedHashMap; 12.5 import java.util.List; 12.6 import java.util.Map; 12.7 +import java.util.concurrent.Callable; 12.8 +import java.util.concurrent.ConcurrentHashMap; 12.9 import jdk.internal.dynalink.linker.GuardedInvocation; 12.10 import jdk.internal.dynalink.linker.LinkRequest; 12.11 import jdk.nashorn.internal.objects.annotations.Attribute; 12.12 @@ -72,8 +74,8 @@ 12.13 */ 12.14 @ScriptClass("Global") 12.15 public final class Global extends ScriptObject implements GlobalObject, Scope { 12.16 - private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 12.17 - private static final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 12.18 + private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 12.19 + private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 12.20 12.21 /** ECMA 15.1.2.2 parseInt (string , radix) */ 12.22 @Property(attributes = Attribute.NOT_ENUMERABLE) 12.23 @@ -709,6 +711,35 @@ 12.24 classCache.put(source, new SoftReference<Class<?>>(clazz)); 12.25 } 12.26 12.27 + private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) { 12.28 + final T obj = map.get(key); 12.29 + if (obj != null) { 12.30 + return obj; 12.31 + } 12.32 + 12.33 + try { 12.34 + final T newObj = creator.call(); 12.35 + final T existingObj = map.putIfAbsent(key, newObj); 12.36 + return existingObj != null ? existingObj : newObj; 12.37 + } catch (final Exception exp) { 12.38 + throw new RuntimeException(exp); 12.39 + } 12.40 + } 12.41 + 12.42 + private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>(); 12.43 + 12.44 + @Override 12.45 + public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) { 12.46 + return getLazilyCreatedValue(key, creator, namedInvokers); 12.47 + } 12.48 + 12.49 + private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>(); 12.50 + 12.51 + @Override 12.52 + public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 12.53 + return getLazilyCreatedValue(key, creator, dynamicInvokers); 12.54 + } 12.55 + 12.56 /** 12.57 * This is the eval used when 'indirect' eval call is made. 12.58 *
13.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Tue Aug 06 17:01:56 2013 -0700 13.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Thu Aug 08 18:19:29 2013 +0530 13.3 @@ -39,6 +39,7 @@ 13.4 import java.util.Comparator; 13.5 import java.util.Iterator; 13.6 import java.util.List; 13.7 +import java.util.concurrent.Callable; 13.8 import jdk.nashorn.api.scripting.ScriptObjectMirror; 13.9 import jdk.nashorn.internal.objects.annotations.Attribute; 13.10 import jdk.nashorn.internal.objects.annotations.Constructor; 13.11 @@ -68,20 +69,88 @@ 13.12 */ 13.13 @ScriptClass("Array") 13.14 public final class NativeArray extends ScriptObject { 13.15 - private static final InvokeByName JOIN = new InvokeByName("join", ScriptObject.class); 13.16 + private static final Object JOIN = new Object(); 13.17 + private static final Object EVERY_CALLBACK_INVOKER = new Object(); 13.18 + private static final Object SOME_CALLBACK_INVOKER = new Object(); 13.19 + private static final Object FOREACH_CALLBACK_INVOKER = new Object(); 13.20 + private static final Object MAP_CALLBACK_INVOKER = new Object(); 13.21 + private static final Object FILTER_CALLBACK_INVOKER = new Object(); 13.22 + private static final Object REDUCE_CALLBACK_INVOKER = new Object(); 13.23 + private static final Object CALL_CMP = new Object(); 13.24 + private static final Object TO_LOCALE_STRING = new Object(); 13.25 13.26 - private static final MethodHandle EVERY_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 13.27 - private static final MethodHandle SOME_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 13.28 - private static final MethodHandle FOREACH_CALLBACK_INVOKER = createIteratorCallbackInvoker(void.class); 13.29 - private static final MethodHandle MAP_CALLBACK_INVOKER = createIteratorCallbackInvoker(Object.class); 13.30 - private static final MethodHandle FILTER_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 13.31 + private static InvokeByName getJOIN() { 13.32 + return Global.instance().getInvokeByName(JOIN, 13.33 + new Callable<InvokeByName>() { 13.34 + @Override 13.35 + public InvokeByName call() { 13.36 + return new InvokeByName("join", ScriptObject.class); 13.37 + } 13.38 + }); 13.39 + } 13.40 13.41 - private static final MethodHandle REDUCE_CALLBACK_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 13.42 - Object.class, Undefined.class, Object.class, Object.class, long.class, Object.class); 13.43 - private static final MethodHandle CALL_CMP = Bootstrap.createDynamicInvoker("dyn:call", double.class, 13.44 - ScriptFunction.class, Object.class, Object.class, Object.class); 13.45 + private static MethodHandle createIteratorCallbackInvoker(final Object key, final Class<?> rtype) { 13.46 + return Global.instance().getDynamicInvoker(key, 13.47 + new Callable<MethodHandle>() { 13.48 + @Override 13.49 + public MethodHandle call() { 13.50 + return Bootstrap.createDynamicInvoker("dyn:call", rtype, Object.class, Object.class, Object.class, 13.51 + long.class, Object.class); 13.52 + } 13.53 + }); 13.54 + } 13.55 13.56 - private static final InvokeByName TO_LOCALE_STRING = new InvokeByName("toLocaleString", ScriptObject.class, String.class); 13.57 + private static MethodHandle getEVERY_CALLBACK_INVOKER() { 13.58 + return createIteratorCallbackInvoker(EVERY_CALLBACK_INVOKER, boolean.class); 13.59 + } 13.60 + 13.61 + private static MethodHandle getSOME_CALLBACK_INVOKER() { 13.62 + return createIteratorCallbackInvoker(SOME_CALLBACK_INVOKER, boolean.class); 13.63 + } 13.64 + 13.65 + private static MethodHandle getFOREACH_CALLBACK_INVOKER() { 13.66 + return createIteratorCallbackInvoker(FOREACH_CALLBACK_INVOKER, void.class); 13.67 + } 13.68 + 13.69 + private static MethodHandle getMAP_CALLBACK_INVOKER() { 13.70 + return createIteratorCallbackInvoker(MAP_CALLBACK_INVOKER, Object.class); 13.71 + } 13.72 + 13.73 + private static MethodHandle getFILTER_CALLBACK_INVOKER() { 13.74 + return createIteratorCallbackInvoker(FILTER_CALLBACK_INVOKER, boolean.class); 13.75 + } 13.76 + 13.77 + private static MethodHandle getREDUCE_CALLBACK_INVOKER() { 13.78 + return Global.instance().getDynamicInvoker(REDUCE_CALLBACK_INVOKER, 13.79 + new Callable<MethodHandle>() { 13.80 + @Override 13.81 + public MethodHandle call() { 13.82 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, Object.class, 13.83 + Undefined.class, Object.class, Object.class, long.class, Object.class); 13.84 + } 13.85 + }); 13.86 + } 13.87 + 13.88 + private static MethodHandle getCALL_CMP() { 13.89 + return Global.instance().getDynamicInvoker(CALL_CMP, 13.90 + new Callable<MethodHandle>() { 13.91 + @Override 13.92 + public MethodHandle call() { 13.93 + return Bootstrap.createDynamicInvoker("dyn:call", double.class, 13.94 + ScriptFunction.class, Object.class, Object.class, Object.class); 13.95 + } 13.96 + }); 13.97 + } 13.98 + 13.99 + private static InvokeByName getTO_LOCALE_STRING() { 13.100 + return Global.instance().getInvokeByName(TO_LOCALE_STRING, 13.101 + new Callable<InvokeByName>() { 13.102 + @Override 13.103 + public InvokeByName call() { 13.104 + return new InvokeByName("toLocaleString", ScriptObject.class, String.class); 13.105 + } 13.106 + }); 13.107 + } 13.108 13.109 // initialized by nasgen 13.110 private static PropertyMap $nasgenmap$; 13.111 @@ -357,11 +426,12 @@ 13.112 public static Object toString(final Object self) { 13.113 final Object obj = Global.toObject(self); 13.114 if (obj instanceof ScriptObject) { 13.115 + final InvokeByName joinInvoker = getJOIN(); 13.116 final ScriptObject sobj = (ScriptObject)obj; 13.117 try { 13.118 - final Object join = JOIN.getGetter().invokeExact(sobj); 13.119 + final Object join = joinInvoker.getGetter().invokeExact(sobj); 13.120 if (Bootstrap.isCallable(join)) { 13.121 - return JOIN.getInvoker().invokeExact(join, sobj); 13.122 + return joinInvoker.getInvoker().invokeExact(join, sobj); 13.123 } 13.124 } catch (final RuntimeException | Error e) { 13.125 throw e; 13.126 @@ -393,11 +463,12 @@ 13.127 13.128 try { 13.129 if (val instanceof ScriptObject) { 13.130 + final InvokeByName localeInvoker = getTO_LOCALE_STRING(); 13.131 final ScriptObject sobj = (ScriptObject)val; 13.132 - final Object toLocaleString = TO_LOCALE_STRING.getGetter().invokeExact(sobj); 13.133 + final Object toLocaleString = localeInvoker.getGetter().invokeExact(sobj); 13.134 13.135 if (Bootstrap.isCallable(toLocaleString)) { 13.136 - sb.append((String)TO_LOCALE_STRING.getInvoker().invokeExact(toLocaleString, sobj)); 13.137 + sb.append((String)localeInvoker.getInvoker().invokeExact(toLocaleString, sobj)); 13.138 } else { 13.139 throw typeError("not.a.function", "toLocaleString"); 13.140 } 13.141 @@ -814,6 +885,7 @@ 13.142 final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance(); 13.143 13.144 Collections.sort(list, new Comparator<Object>() { 13.145 + private final MethodHandle call_cmp = getCALL_CMP(); 13.146 @Override 13.147 public int compare(final Object x, final Object y) { 13.148 if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) { 13.149 @@ -826,7 +898,7 @@ 13.150 13.151 if (cmp != null) { 13.152 try { 13.153 - return (int)Math.signum((double)CALL_CMP.invokeExact(cmp, cmpThis, x, y)); 13.154 + return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y)); 13.155 } catch (final RuntimeException | Error e) { 13.156 throw e; 13.157 } catch (final Throwable t) { 13.158 @@ -1103,9 +1175,11 @@ 13.159 13.160 private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) { 13.161 return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) { 13.162 + private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER(); 13.163 + 13.164 @Override 13.165 protected boolean forEach(final Object val, final long i) throws Throwable { 13.166 - return (result = (boolean)EVERY_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)); 13.167 + return (result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self)); 13.168 } 13.169 }.apply(); 13.170 } 13.171 @@ -1121,9 +1195,11 @@ 13.172 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 13.173 public static Object some(final Object self, final Object callbackfn, final Object thisArg) { 13.174 return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) { 13.175 + private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER(); 13.176 + 13.177 @Override 13.178 protected boolean forEach(final Object val, final long i) throws Throwable { 13.179 - return !(result = (boolean)SOME_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)); 13.180 + return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self)); 13.181 } 13.182 }.apply(); 13.183 } 13.184 @@ -1139,9 +1215,11 @@ 13.185 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 13.186 public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) { 13.187 return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) { 13.188 + private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER(); 13.189 + 13.190 @Override 13.191 protected boolean forEach(final Object val, final long i) throws Throwable { 13.192 - FOREACH_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self); 13.193 + forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self); 13.194 return true; 13.195 } 13.196 }.apply(); 13.197 @@ -1158,9 +1236,11 @@ 13.198 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 13.199 public static Object map(final Object self, final Object callbackfn, final Object thisArg) { 13.200 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) { 13.201 + private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER(); 13.202 + 13.203 @Override 13.204 protected boolean forEach(final Object val, final long i) throws Throwable { 13.205 - final Object r = MAP_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self); 13.206 + final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self); 13.207 result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r); 13.208 return true; 13.209 } 13.210 @@ -1186,10 +1266,11 @@ 13.211 public static Object filter(final Object self, final Object callbackfn, final Object thisArg) { 13.212 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) { 13.213 private long to = 0; 13.214 + private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER(); 13.215 13.216 @Override 13.217 protected boolean forEach(final Object val, final long i) throws Throwable { 13.218 - if ((boolean)FILTER_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)) { 13.219 + if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) { 13.220 result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val); 13.221 } 13.222 return true; 13.223 @@ -1217,10 +1298,12 @@ 13.224 13.225 //if initial value is ScriptRuntime.UNDEFINED - step forward once. 13.226 return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) { 13.227 + private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER(); 13.228 + 13.229 @Override 13.230 protected boolean forEach(final Object val, final long i) throws Throwable { 13.231 // TODO: why can't I declare the second arg as Undefined.class? 13.232 - result = REDUCE_CALLBACK_INVOKER.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self); 13.233 + result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self); 13.234 return true; 13.235 } 13.236 }.apply(); 13.237 @@ -1273,10 +1356,4 @@ 13.238 13.239 return false; 13.240 } 13.241 - 13.242 - private static MethodHandle createIteratorCallbackInvoker(final Class<?> rtype) { 13.243 - return Bootstrap.createDynamicInvoker("dyn:call", rtype, Object.class, Object.class, Object.class, 13.244 - long.class, Object.class); 13.245 - 13.246 - } 13.247 }
14.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Tue Aug 06 17:01:56 2013 -0700 14.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Thu Aug 08 18:19:29 2013 +0530 14.3 @@ -33,6 +33,7 @@ 14.4 14.5 import java.util.Locale; 14.6 import java.util.TimeZone; 14.7 +import java.util.concurrent.Callable; 14.8 import jdk.nashorn.internal.objects.annotations.Attribute; 14.9 import jdk.nashorn.internal.objects.annotations.Constructor; 14.10 import jdk.nashorn.internal.objects.annotations.Function; 14.11 @@ -95,8 +96,17 @@ 14.12 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 14.13 }; 14.14 14.15 - private static final InvokeByName TO_ISO_STRING = new InvokeByName("toISOString", ScriptObject.class, Object.class, 14.16 - Object.class); 14.17 + private static final Object TO_ISO_STRING = new Object(); 14.18 + 14.19 + private static InvokeByName getTO_ISO_STRING() { 14.20 + return Global.instance().getInvokeByName(TO_ISO_STRING, 14.21 + new Callable<InvokeByName>() { 14.22 + @Override 14.23 + public InvokeByName call() { 14.24 + return new InvokeByName("toISOString", ScriptObject.class, Object.class, Object.class); 14.25 + } 14.26 + }); 14.27 + } 14.28 14.29 private double time; 14.30 private final TimeZone timezone; 14.31 @@ -861,9 +871,10 @@ 14.32 } 14.33 14.34 try { 14.35 - final Object func = TO_ISO_STRING.getGetter().invokeExact(sobj); 14.36 + final InvokeByName toIsoString = getTO_ISO_STRING(); 14.37 + final Object func = toIsoString.getGetter().invokeExact(sobj); 14.38 if (Bootstrap.isCallable(func)) { 14.39 - return TO_ISO_STRING.getInvoker().invokeExact(func, sobj, key); 14.40 + return toIsoString.getInvoker().invokeExact(func, sobj, key); 14.41 } 14.42 throw typeError("not.a.function", ScriptRuntime.safeToString(func)); 14.43 } catch (final RuntimeException | Error e) {
15.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java Tue Aug 06 17:01:56 2013 -0700 15.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java Thu Aug 08 18:19:29 2013 +0530 15.3 @@ -35,6 +35,7 @@ 15.4 import java.util.Iterator; 15.5 import java.util.List; 15.6 import java.util.Map; 15.7 +import java.util.concurrent.Callable; 15.8 import jdk.nashorn.internal.objects.annotations.Attribute; 15.9 import jdk.nashorn.internal.objects.annotations.Function; 15.10 import jdk.nashorn.internal.objects.annotations.ScriptClass; 15.11 @@ -55,9 +56,31 @@ 15.12 */ 15.13 @ScriptClass("JSON") 15.14 public final class NativeJSON extends ScriptObject { 15.15 - private static final InvokeByName TO_JSON = new InvokeByName("toJSON", ScriptObject.class, Object.class, Object.class); 15.16 - private static final MethodHandle REPLACER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 15.17 - ScriptFunction.class, ScriptObject.class, Object.class, Object.class); 15.18 + private static final Object TO_JSON = new Object(); 15.19 + 15.20 + private static InvokeByName getTO_JSON() { 15.21 + return Global.instance().getInvokeByName(TO_JSON, 15.22 + new Callable<InvokeByName>() { 15.23 + @Override 15.24 + public InvokeByName call() { 15.25 + return new InvokeByName("toJSON", ScriptObject.class, Object.class, Object.class); 15.26 + } 15.27 + }); 15.28 + } 15.29 + 15.30 + 15.31 + private static final Object REPLACER_INVOKER = new Object(); 15.32 + 15.33 + private static MethodHandle getREPLACER_INVOKER() { 15.34 + return Global.instance().getDynamicInvoker(REPLACER_INVOKER, 15.35 + new Callable<MethodHandle>() { 15.36 + @Override 15.37 + public MethodHandle call() { 15.38 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 15.39 + ScriptFunction.class, ScriptObject.class, Object.class, Object.class); 15.40 + } 15.41 + }); 15.42 + } 15.43 15.44 // initialized by nasgen 15.45 @SuppressWarnings("unused") 15.46 @@ -187,15 +210,16 @@ 15.47 15.48 try { 15.49 if (value instanceof ScriptObject) { 15.50 + final InvokeByName toJSONInvoker = getTO_JSON(); 15.51 final ScriptObject svalue = (ScriptObject)value; 15.52 - final Object toJSON = TO_JSON.getGetter().invokeExact(svalue); 15.53 + final Object toJSON = toJSONInvoker.getGetter().invokeExact(svalue); 15.54 if (Bootstrap.isCallable(toJSON)) { 15.55 - value = TO_JSON.getInvoker().invokeExact(toJSON, svalue, key); 15.56 + value = toJSONInvoker.getInvoker().invokeExact(toJSON, svalue, key); 15.57 } 15.58 } 15.59 15.60 if (state.replacerFunction != null) { 15.61 - value = REPLACER_INVOKER.invokeExact(state.replacerFunction, holder, key, value); 15.62 + value = getREPLACER_INVOKER().invokeExact(state.replacerFunction, holder, key, value); 15.63 } 15.64 } catch(Error|RuntimeException t) { 15.65 throw t;
16.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Tue Aug 06 17:01:56 2013 -0700 16.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Thu Aug 08 18:19:29 2013 +0530 16.3 @@ -36,6 +36,7 @@ 16.4 import java.util.HashSet; 16.5 import java.util.List; 16.6 import java.util.Set; 16.7 +import java.util.concurrent.Callable; 16.8 import jdk.internal.dynalink.beans.BeansLinker; 16.9 import jdk.internal.dynalink.beans.StaticClass; 16.10 import jdk.internal.dynalink.linker.GuardedInvocation; 16.11 @@ -70,7 +71,18 @@ 16.12 */ 16.13 @ScriptClass("Object") 16.14 public final class NativeObject { 16.15 - private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 16.16 + private static final Object TO_STRING = new Object(); 16.17 + 16.18 + private static InvokeByName getTO_STRING() { 16.19 + return Global.instance().getInvokeByName(TO_STRING, 16.20 + new Callable<InvokeByName>() { 16.21 + @Override 16.22 + public InvokeByName call() { 16.23 + return new InvokeByName("toString", ScriptObject.class); 16.24 + } 16.25 + }); 16.26 + } 16.27 + 16.28 private static final MethodType MIRROR_GETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class); 16.29 private static final MethodType MIRROR_SETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class, Object.class); 16.30 16.31 @@ -402,12 +414,13 @@ 16.32 public static Object toLocaleString(final Object self) { 16.33 final Object obj = JSType.toScriptObject(self); 16.34 if (obj instanceof ScriptObject) { 16.35 + final InvokeByName toStringInvoker = getTO_STRING(); 16.36 final ScriptObject sobj = (ScriptObject)self; 16.37 try { 16.38 - final Object toString = TO_STRING.getGetter().invokeExact(sobj); 16.39 + final Object toString = toStringInvoker.getGetter().invokeExact(sobj); 16.40 16.41 if (Bootstrap.isCallable(toString)) { 16.42 - return TO_STRING.getInvoker().invokeExact(toString, sobj); 16.43 + return toStringInvoker.getInvoker().invokeExact(toString, sobj); 16.44 } 16.45 } catch (final RuntimeException | Error e) { 16.46 throw e;
17.1 --- a/src/jdk/nashorn/internal/runtime/GlobalObject.java Tue Aug 06 17:01:56 2013 -0700 17.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalObject.java Thu Aug 08 18:19:29 2013 +0530 17.3 @@ -26,8 +26,10 @@ 17.4 package jdk.nashorn.internal.runtime; 17.5 17.6 import java.lang.invoke.MethodHandle; 17.7 +import java.util.concurrent.Callable; 17.8 import jdk.internal.dynalink.linker.GuardedInvocation; 17.9 import jdk.internal.dynalink.linker.LinkRequest; 17.10 +import jdk.nashorn.internal.runtime.linker.InvokeByName; 17.11 17.12 /** 17.13 * Runtime interface to the global scope objects. 17.14 @@ -210,4 +212,20 @@ 17.15 * @param clazz compiled Class object for the source 17.16 */ 17.17 public void cacheClass(Source source, Class<?> clazz); 17.18 + 17.19 + /** 17.20 + * Get cached InvokeByName object for the given key 17.21 + * @param key key to be associated with InvokeByName object 17.22 + * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init) 17.23 + * @return InvokeByName object associated with the key. 17.24 + */ 17.25 + public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator); 17.26 + 17.27 + /** 17.28 + * Get cached dynamic method handle for the given key 17.29 + * @param key key to be associated with dynamic method handle 17.30 + * @param creator if method handle is absent 'creator' is called to make one (lazy init) 17.31 + * @return dynamic method handle associated with the key. 17.32 + */ 17.33 + public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator); 17.34 }
18.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java Tue Aug 06 17:01:56 2013 -0700 18.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java Thu Aug 08 18:19:29 2013 +0530 18.3 @@ -27,6 +27,7 @@ 18.4 18.5 import java.lang.invoke.MethodHandle; 18.6 import java.util.Iterator; 18.7 +import java.util.concurrent.Callable; 18.8 import jdk.nashorn.internal.ir.LiteralNode; 18.9 import jdk.nashorn.internal.ir.Node; 18.10 import jdk.nashorn.internal.ir.ObjectNode; 18.11 @@ -42,8 +43,19 @@ 18.12 */ 18.13 public final class JSONFunctions { 18.14 private JSONFunctions() {} 18.15 - private static final MethodHandle REVIVER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 18.16 - ScriptFunction.class, ScriptObject.class, String.class, Object.class); 18.17 + 18.18 + private static final Object REVIVER_INVOKER = new Object(); 18.19 + 18.20 + private static MethodHandle getREVIVER_INVOKER() { 18.21 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(REVIVER_INVOKER, 18.22 + new Callable<MethodHandle>() { 18.23 + @Override 18.24 + public MethodHandle call() { 18.25 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 18.26 + ScriptFunction.class, ScriptObject.class, String.class, Object.class); 18.27 + } 18.28 + }); 18.29 + } 18.30 18.31 /** 18.32 * Returns JSON-compatible quoted version of the given string. 18.33 @@ -117,7 +129,7 @@ 18.34 18.35 try { 18.36 // Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class); 18.37 - return REVIVER_INVOKER.invokeExact(reviver, holder, JSType.toString(name), val); 18.38 + return getREVIVER_INVOKER().invokeExact(reviver, holder, JSType.toString(name), val); 18.39 } catch(Error|RuntimeException t) { 18.40 throw t; 18.41 } catch(final Throwable t) {
19.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Tue Aug 06 17:01:56 2013 -0700 19.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Thu Aug 08 18:19:29 2013 +0530 19.3 @@ -31,6 +31,7 @@ 19.4 import java.util.ListIterator; 19.5 import java.util.NoSuchElementException; 19.6 import java.util.RandomAccess; 19.7 +import java.util.concurrent.Callable; 19.8 import jdk.nashorn.internal.runtime.linker.Bootstrap; 19.9 import jdk.nashorn.internal.runtime.linker.InvokeByName; 19.10 19.11 @@ -49,16 +50,73 @@ 19.12 */ 19.13 public final class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 19.14 // These add to the back and front of the list 19.15 - private static final InvokeByName PUSH = new InvokeByName("push", ScriptObject.class, void.class, Object.class); 19.16 - private static final InvokeByName UNSHIFT = new InvokeByName("unshift", ScriptObject.class, void.class, Object.class); 19.17 + private static final Object PUSH = new Object(); 19.18 + private static InvokeByName getPUSH() { 19.19 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(PUSH, 19.20 + new Callable<InvokeByName>() { 19.21 + @Override 19.22 + public InvokeByName call() { 19.23 + return new InvokeByName("push", ScriptObject.class, void.class, Object.class); 19.24 + } 19.25 + }); 19.26 + } 19.27 + 19.28 + private static final Object UNSHIFT = new Object(); 19.29 + private static InvokeByName getUNSHIFT() { 19.30 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(UNSHIFT, 19.31 + new Callable<InvokeByName>() { 19.32 + @Override 19.33 + public InvokeByName call() { 19.34 + return new InvokeByName("unshift", ScriptObject.class, void.class, Object.class); 19.35 + } 19.36 + }); 19.37 + } 19.38 19.39 // These remove from the back and front of the list 19.40 - private static final InvokeByName POP = new InvokeByName("pop", ScriptObject.class, Object.class); 19.41 - private static final InvokeByName SHIFT = new InvokeByName("shift", ScriptObject.class, Object.class); 19.42 + private static final Object POP = new Object(); 19.43 + private static InvokeByName getPOP() { 19.44 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(POP, 19.45 + new Callable<InvokeByName>() { 19.46 + @Override 19.47 + public InvokeByName call() { 19.48 + return new InvokeByName("pop", ScriptObject.class, Object.class); 19.49 + } 19.50 + }); 19.51 + } 19.52 + 19.53 + private static final Object SHIFT = new Object(); 19.54 + private static InvokeByName getSHIFT() { 19.55 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SHIFT, 19.56 + new Callable<InvokeByName>() { 19.57 + @Override 19.58 + public InvokeByName call() { 19.59 + return new InvokeByName("shift", ScriptObject.class, Object.class); 19.60 + } 19.61 + }); 19.62 + } 19.63 19.64 // These insert and remove in the middle of the list 19.65 - private static final InvokeByName SPLICE_ADD = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class, Object.class); 19.66 - private static final InvokeByName SPLICE_REMOVE = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class); 19.67 + private static final Object SPLICE_ADD = new Object(); 19.68 + private static InvokeByName getSPLICE_ADD() { 19.69 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_ADD, 19.70 + new Callable<InvokeByName>() { 19.71 + @Override 19.72 + public InvokeByName call() { 19.73 + return new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class, Object.class); 19.74 + } 19.75 + }); 19.76 + } 19.77 + 19.78 + private static final Object SPLICE_REMOVE = new Object(); 19.79 + private static InvokeByName getSPLICE_REMOVE() { 19.80 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_REMOVE, 19.81 + new Callable<InvokeByName>() { 19.82 + @Override 19.83 + public InvokeByName call() { 19.84 + return new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class); 19.85 + } 19.86 + }); 19.87 + } 19.88 19.89 private final ScriptObject obj; 19.90 19.91 @@ -109,9 +167,10 @@ 19.92 @Override 19.93 public void addFirst(Object e) { 19.94 try { 19.95 - final Object fn = UNSHIFT.getGetter().invokeExact(obj); 19.96 - checkFunction(fn, UNSHIFT); 19.97 - UNSHIFT.getInvoker().invokeExact(fn, obj, e); 19.98 + final InvokeByName unshiftInvoker = getUNSHIFT(); 19.99 + final Object fn = unshiftInvoker.getGetter().invokeExact(obj); 19.100 + checkFunction(fn, unshiftInvoker); 19.101 + unshiftInvoker.getInvoker().invokeExact(fn, obj, e); 19.102 } catch(RuntimeException | Error ex) { 19.103 throw ex; 19.104 } catch(Throwable t) { 19.105 @@ -122,9 +181,10 @@ 19.106 @Override 19.107 public void addLast(Object e) { 19.108 try { 19.109 - final Object fn = PUSH.getGetter().invokeExact(obj); 19.110 - checkFunction(fn, PUSH); 19.111 - PUSH.getInvoker().invokeExact(fn, obj, e); 19.112 + final InvokeByName pushInvoker = getPUSH(); 19.113 + final Object fn = pushInvoker.getGetter().invokeExact(obj); 19.114 + checkFunction(fn, pushInvoker); 19.115 + pushInvoker.getInvoker().invokeExact(fn, obj, e); 19.116 } catch(RuntimeException | Error ex) { 19.117 throw ex; 19.118 } catch(Throwable t) { 19.119 @@ -142,9 +202,10 @@ 19.120 } else { 19.121 final int size = size(); 19.122 if(index < size) { 19.123 - final Object fn = SPLICE_ADD.getGetter().invokeExact(obj); 19.124 - checkFunction(fn, SPLICE_ADD); 19.125 - SPLICE_ADD.getInvoker().invokeExact(fn, obj, index, 0, e); 19.126 + final InvokeByName spliceAddInvoker = getSPLICE_ADD(); 19.127 + final Object fn = spliceAddInvoker.getGetter().invokeExact(obj); 19.128 + checkFunction(fn, spliceAddInvoker); 19.129 + spliceAddInvoker.getInvoker().invokeExact(fn, obj, index, 0, e); 19.130 } else if(index == size) { 19.131 addLast(e); 19.132 } else { 19.133 @@ -234,9 +295,10 @@ 19.134 19.135 private Object invokeShift() { 19.136 try { 19.137 - final Object fn = SHIFT.getGetter().invokeExact(obj); 19.138 - checkFunction(fn, SHIFT); 19.139 - return SHIFT.getInvoker().invokeExact(fn, obj); 19.140 + final InvokeByName shiftInvoker = getSHIFT(); 19.141 + final Object fn = shiftInvoker.getGetter().invokeExact(obj); 19.142 + checkFunction(fn, shiftInvoker); 19.143 + return shiftInvoker.getInvoker().invokeExact(fn, obj); 19.144 } catch(RuntimeException | Error ex) { 19.145 throw ex; 19.146 } catch(Throwable t) { 19.147 @@ -246,9 +308,10 @@ 19.148 19.149 private Object invokePop() { 19.150 try { 19.151 - final Object fn = POP.getGetter().invokeExact(obj); 19.152 - checkFunction(fn, POP); 19.153 - return POP.getInvoker().invokeExact(fn, obj); 19.154 + final InvokeByName popInvoker = getPOP(); 19.155 + final Object fn = popInvoker.getGetter().invokeExact(obj); 19.156 + checkFunction(fn, popInvoker); 19.157 + return popInvoker.getInvoker().invokeExact(fn, obj); 19.158 } catch(RuntimeException | Error ex) { 19.159 throw ex; 19.160 } catch(Throwable t) { 19.161 @@ -263,9 +326,10 @@ 19.162 19.163 private void invokeSpliceRemove(int fromIndex, int count) { 19.164 try { 19.165 - final Object fn = SPLICE_REMOVE.getGetter().invokeExact(obj); 19.166 - checkFunction(fn, SPLICE_REMOVE); 19.167 - SPLICE_REMOVE.getInvoker().invokeExact(fn, obj, fromIndex, count); 19.168 + final InvokeByName spliceRemoveInvoker = getSPLICE_REMOVE(); 19.169 + final Object fn = spliceRemoveInvoker.getGetter().invokeExact(obj); 19.170 + checkFunction(fn, spliceRemoveInvoker); 19.171 + spliceRemoveInvoker.getInvoker().invokeExact(fn, obj, fromIndex, count); 19.172 } catch(RuntimeException | Error ex) { 19.173 throw ex; 19.174 } catch(Throwable t) {
20.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue Aug 06 17:01:56 2013 -0700 20.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Aug 08 18:19:29 2013 +0530 20.3 @@ -52,13 +52,19 @@ 20.4 public final class RecompilableScriptFunctionData extends ScriptFunctionData { 20.5 20.6 /** FunctionNode with the code for this ScriptFunction */ 20.7 - private FunctionNode functionNode; 20.8 + private volatile FunctionNode functionNode; 20.9 + 20.10 + /** Source from which FunctionNode was parsed. */ 20.11 + private final Source source; 20.12 + 20.13 + /** Token of this function within the source. */ 20.14 + private final long token; 20.15 20.16 /** Allocator map from makeMap() */ 20.17 private final PropertyMap allocatorMap; 20.18 20.19 /** Code installer used for all further recompilation/specialization of this ScriptFunction */ 20.20 - private final CodeInstaller<ScriptEnvironment> installer; 20.21 + private volatile CodeInstaller<ScriptEnvironment> installer; 20.22 20.23 /** Name of class where allocator function resides */ 20.24 private final String allocatorClassName; 20.25 @@ -103,6 +109,8 @@ 20.26 true); 20.27 20.28 this.functionNode = functionNode; 20.29 + this.source = functionNode.getSource(); 20.30 + this.token = tokenFor(functionNode); 20.31 this.installer = installer; 20.32 this.allocatorClassName = allocatorClassName; 20.33 this.allocatorMap = allocatorMap; 20.34 @@ -110,9 +118,6 @@ 20.35 20.36 @Override 20.37 String toSource() { 20.38 - final Source source = functionNode.getSource(); 20.39 - final long token = tokenFor(functionNode); 20.40 - 20.41 if (source != null && token != 0) { 20.42 return source.getString(Token.descPosition(token), Token.descLength(token)); 20.43 } 20.44 @@ -123,8 +128,6 @@ 20.45 @Override 20.46 public String toString() { 20.47 final StringBuilder sb = new StringBuilder(); 20.48 - final Source source = functionNode.getSource(); 20.49 - final long token = tokenFor(functionNode); 20.50 20.51 if (source != null) { 20.52 sb.append(source.getName()) 20.53 @@ -190,6 +193,12 @@ 20.54 20.55 // code exists - look it up and add it into the automatically sorted invoker list 20.56 addCode(functionNode); 20.57 + 20.58 + if (! functionNode.canSpecialize()) { 20.59 + // allow GC to claim IR stuff that is not needed anymore 20.60 + functionNode = null; 20.61 + installer = null; 20.62 + } 20.63 } 20.64 20.65 private MethodHandle addCode(final FunctionNode fn) { 20.66 @@ -325,7 +334,7 @@ 20.67 * footprint too large to store a parse snapshot, or if it is meaningless 20.68 * to do so, such as e.g. for runScript 20.69 */ 20.70 - if (!functionNode.canSpecialize()) { 20.71 + if (functionNode == null || !functionNode.canSpecialize()) { 20.72 return mh; 20.73 } 20.74
21.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Aug 06 17:01:56 2013 -0700 21.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Thu Aug 08 18:19:29 2013 +0530 21.3 @@ -496,32 +496,24 @@ 21.4 MethodHandle boundHandle; 21.5 MethodHandle guard = null; 21.6 21.7 + final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 21.8 + 21.9 if (data.needsCallee()) { 21.10 final MethodHandle callHandle = getBestInvoker(type, request.getArguments()); 21.11 - if (NashornCallSiteDescriptor.isScope(desc)) { 21.12 + if (scopeCall) { 21.13 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 21.14 // (callee, this, args...) => (callee, args...) 21.15 boundHandle = MH.insertArguments(callHandle, 1, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 21.16 // (callee, args...) => (callee, [this], args...) 21.17 boundHandle = MH.dropArguments(boundHandle, 1, Object.class); 21.18 + 21.19 } else { 21.20 // It's already (callee, this, args...), just what we need 21.21 boundHandle = callHandle; 21.22 - 21.23 - // For non-strict functions, check whether this-object is primitive type. 21.24 - // If so add a to-object-wrapper argument filter. 21.25 - // Else install a guard that will trigger a relink when the argument becomes primitive. 21.26 - if (needsWrappedThis()) { 21.27 - if (ScriptFunctionData.isPrimitiveThis(request.getArguments()[1])) { 21.28 - boundHandle = MH.filterArguments(boundHandle, 1, WRAPFILTER); 21.29 - } else { 21.30 - guard = getNonStrictFunctionGuard(this); 21.31 - } 21.32 - } 21.33 } 21.34 } else { 21.35 final MethodHandle callHandle = getBestInvoker(type.dropParameterTypes(0, 1), request.getArguments()); 21.36 - if (NashornCallSiteDescriptor.isScope(desc)) { 21.37 + if (scopeCall) { 21.38 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 21.39 // (this, args...) => (args...) 21.40 boundHandle = MH.bindTo(callHandle, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 21.41 @@ -533,6 +525,17 @@ 21.42 } 21.43 } 21.44 21.45 + // For non-strict functions, check whether this-object is primitive type. 21.46 + // If so add a to-object-wrapper argument filter. 21.47 + // Else install a guard that will trigger a relink when the argument becomes primitive. 21.48 + if (!scopeCall && needsWrappedThis()) { 21.49 + if (ScriptFunctionData.isPrimitiveThis(request.getArguments()[1])) { 21.50 + boundHandle = MH.filterArguments(boundHandle, 1, WRAPFILTER); 21.51 + } else { 21.52 + guard = getNonStrictFunctionGuard(this); 21.53 + } 21.54 + } 21.55 + 21.56 boundHandle = pairArguments(boundHandle, type); 21.57 21.58 return new GuardedInvocation(boundHandle, guard == null ? getFunctionGuard(this) : guard);
22.1 --- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Tue Aug 06 17:01:56 2013 -0700 22.2 +++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Thu Aug 08 18:19:29 2013 +0530 22.3 @@ -27,6 +27,7 @@ 22.4 22.5 import java.lang.invoke.MethodHandle; 22.6 import java.lang.invoke.MethodHandles; 22.7 +import java.util.concurrent.Callable; 22.8 22.9 import jdk.nashorn.internal.codegen.CompilerConstants; 22.10 import jdk.nashorn.internal.lookup.Lookup; 22.11 @@ -68,12 +69,32 @@ 22.12 "userAccessorSetter", void.class, ScriptObject.class, int.class, String.class, Object.class, Object.class); 22.13 22.14 /** Dynamic invoker for getter */ 22.15 - private static final MethodHandle INVOKE_UA_GETTER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 22.16 - Object.class, Object.class); 22.17 + private static final Object INVOKE_UA_GETTER = new Object(); 22.18 + 22.19 + private static MethodHandle getINVOKE_UA_GETTER() { 22.20 + 22.21 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_GETTER, 22.22 + new Callable<MethodHandle>() { 22.23 + @Override 22.24 + public MethodHandle call() { 22.25 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 22.26 + Object.class, Object.class); 22.27 + } 22.28 + }); 22.29 + } 22.30 22.31 /** Dynamic invoker for setter */ 22.32 - private static final MethodHandle INVOKE_UA_SETTER = Bootstrap.createDynamicInvoker("dyn:call", void.class, 22.33 - Object.class, Object.class, Object.class); 22.34 + private static Object INVOKE_UA_SETTER = new Object(); 22.35 + private static MethodHandle getINVOKE_UA_SETTER() { 22.36 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_SETTER, 22.37 + new Callable<MethodHandle>() { 22.38 + @Override 22.39 + public MethodHandle call() { 22.40 + return Bootstrap.createDynamicInvoker("dyn:call", void.class, 22.41 + Object.class, Object.class, Object.class); 22.42 + } 22.43 + }); 22.44 + } 22.45 22.46 /** 22.47 * Constructor 22.48 @@ -191,7 +212,7 @@ 22.49 22.50 if (func instanceof ScriptFunction) { 22.51 try { 22.52 - return INVOKE_UA_GETTER.invokeExact(func, self); 22.53 + return getINVOKE_UA_GETTER().invokeExact(func, self); 22.54 } catch(final Error|RuntimeException t) { 22.55 throw t; 22.56 } catch(final Throwable t) { 22.57 @@ -208,7 +229,7 @@ 22.58 22.59 if (func instanceof ScriptFunction) { 22.60 try { 22.61 - INVOKE_UA_SETTER.invokeExact(func, self, value); 22.62 + getINVOKE_UA_SETTER().invokeExact(func, self, value); 22.63 } catch(final Error|RuntimeException t) { 22.64 throw t; 22.65 } catch(final Throwable t) {
23.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Tue Aug 06 17:01:56 2013 -0700 23.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Thu Aug 08 18:19:29 2013 +0530 23.3 @@ -68,6 +68,10 @@ 23.4 if (relinkThreshold > -1) { 23.5 factory.setUnstableRelinkThreshold(relinkThreshold); 23.6 } 23.7 + 23.8 + // Linkers for any additional language runtimes deployed alongside Nashorn will be picked up by the factory. 23.9 + factory.setClassLoader(Bootstrap.class.getClassLoader()); 23.10 + 23.11 dynamicLinker = factory.createLinker(); 23.12 } 23.13
24.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Tue Aug 06 17:01:56 2013 -0700 24.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Thu Aug 08 18:19:29 2013 +0530 24.3 @@ -48,7 +48,7 @@ 24.4 private static final ProtectionDomain GENERATED_PROTECTION_DOMAIN = createGeneratedProtectionDomain(); 24.5 24.6 private final String className; 24.7 - private final byte[] classBytes; 24.8 + private volatile byte[] classBytes; 24.9 24.10 JavaAdapterClassLoader(String className, byte[] classBytes) { 24.11 this.className = className.replace('/', '.'); 24.12 @@ -56,6 +56,13 @@ 24.13 } 24.14 24.15 /** 24.16 + * clear classBytes after loading class. 24.17 + */ 24.18 + void clearClassBytes() { 24.19 + this.classBytes = null; 24.20 + } 24.21 + 24.22 + /** 24.23 * Loads the generated adapter class into the JVM. 24.24 * @param parentLoader the parent class loader for the generated class loader 24.25 * @return the generated adapter class 24.26 @@ -103,6 +110,7 @@ 24.27 @Override 24.28 protected Class<?> findClass(final String name) throws ClassNotFoundException { 24.29 if(name.equals(className)) { 24.30 + assert classBytes != null : "what? already cleared .class bytes!!"; 24.31 return defineClass(name, classBytes, 0, classBytes.length, GENERATED_PROTECTION_DOMAIN); 24.32 } else { 24.33 throw new ClassNotFoundException(name);
25.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Tue Aug 06 17:01:56 2013 -0700 25.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Thu Aug 08 18:19:29 2013 +0530 25.3 @@ -224,7 +224,10 @@ 25.4 this.commonLoader = findCommonLoader(definingLoader); 25.5 final JavaAdapterBytecodeGenerator gen = new JavaAdapterBytecodeGenerator(superClass, interfaces, commonLoader, false); 25.6 this.autoConvertibleFromFunction = gen.isAutoConvertibleFromFunction(); 25.7 - this.instanceAdapterClass = gen.createAdapterClassLoader().generateClass(commonLoader); 25.8 + final JavaAdapterClassLoader jacl = gen.createAdapterClassLoader(); 25.9 + this.instanceAdapterClass = jacl.generateClass(commonLoader); 25.10 + // loaded Class - no need to keep class bytes around 25.11 + jacl.clearClassBytes(); 25.12 this.adapterGenerator = new JavaAdapterBytecodeGenerator(superClass, interfaces, commonLoader, true).createAdapterClassLoader(); 25.13 this.adaptationResult = AdaptationResult.SUCCESSFUL_RESULT; 25.14 }
26.1 --- a/test/script/basic/JDK-8020357.js Tue Aug 06 17:01:56 2013 -0700 26.2 +++ b/test/script/basic/JDK-8020357.js Thu Aug 08 18:19:29 2013 +0530 26.3 @@ -33,17 +33,6 @@ 26.4 26.5 var limit = Math.pow(2, UNSIGNED_INT_BITS)/BYTES_PER_INT_32 26.6 26.7 -try { 26.8 - // A value at or under the limit should either succeed if we have 26.9 - // enough heap, or throw an OutOfMemoryError if we don't. 26.10 - Int32Array(limit - 1) 26.11 -} catch(e) { 26.12 - if(!(e instanceof java.lang.OutOfMemoryError)) { 26.13 - // Only print an unexpected result; OutOfMemoryError is expected 26.14 - print(e) 26.15 - } 26.16 -} 26.17 - 26.18 // A value over the limit should throw a RangeError. 26.19 try { 26.20 Int32Array(limit)
27.1 --- a/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Tue Aug 06 17:01:56 2013 -0700 27.2 +++ b/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Thu Aug 08 18:19:29 2013 +0530 27.3 @@ -33,6 +33,7 @@ 27.4 import javax.script.ScriptEngineManager; 27.5 import javax.script.ScriptException; 27.6 import org.testng.TestNG; 27.7 +import org.testng.annotations.AfterClass; 27.8 import org.testng.annotations.BeforeClass; 27.9 import org.testng.annotations.Test; 27.10 27.11 @@ -44,7 +45,7 @@ 27.12 public class BooleanAccessTest { 27.13 27.14 private static ScriptEngine e = null; 27.15 - private static SharedObject o = new SharedObject(); 27.16 + private static SharedObject o = null; 27.17 27.18 public static void main(final String[] args) { 27.19 TestNG.main(args); 27.20 @@ -54,10 +55,17 @@ 27.21 public static void setUpClass() throws ScriptException { 27.22 final ScriptEngineManager m = new ScriptEngineManager(); 27.23 e = m.getEngineByName("nashorn"); 27.24 + o = new SharedObject(); 27.25 e.put("o", o); 27.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 27.27 } 27.28 27.29 + @AfterClass 27.30 + public static void tearDownClass() { 27.31 + e = null; 27.32 + o = null; 27.33 + } 27.34 + 27.35 @Test 27.36 public void accessFieldBoolean() throws ScriptException { 27.37 e.eval("var p_boolean = o.publicBoolean;");
28.1 --- a/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Tue Aug 06 17:01:56 2013 -0700 28.2 +++ b/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Thu Aug 08 18:19:29 2013 +0530 28.3 @@ -36,6 +36,7 @@ 28.4 import javax.script.ScriptEngineManager; 28.5 import javax.script.ScriptException; 28.6 import org.testng.TestNG; 28.7 +import org.testng.annotations.AfterClass; 28.8 import org.testng.annotations.BeforeClass; 28.9 import org.testng.annotations.Test; 28.10 28.11 @@ -47,7 +48,7 @@ 28.12 public class MethodAccessTest { 28.13 28.14 private static ScriptEngine e = null; 28.15 - private static SharedObject o = new SharedObject(); 28.16 + private static SharedObject o = null; 28.17 28.18 public static void main(final String[] args) { 28.19 TestNG.main(args); 28.20 @@ -57,12 +58,19 @@ 28.21 public static void setUpClass() throws ScriptException { 28.22 final ScriptEngineManager m = new ScriptEngineManager(); 28.23 e = m.getEngineByName("nashorn"); 28.24 + o = new SharedObject(); 28.25 o.setEngine(e); 28.26 e.put("o", o); 28.27 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 28.28 e.eval("var Person = Packages.jdk.nashorn.api.javaaccess.Person;"); 28.29 } 28.30 28.31 + @AfterClass 28.32 + public static void tearDownClass() { 28.33 + e = null; 28.34 + o = null; 28.35 + } 28.36 + 28.37 @Test 28.38 public void accessMethodthrowsCheckedException() throws ScriptException { 28.39 e.eval("try {" +
29.1 --- a/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Tue Aug 06 17:01:56 2013 -0700 29.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Thu Aug 08 18:19:29 2013 +0530 29.3 @@ -33,6 +33,7 @@ 29.4 import javax.script.ScriptEngineManager; 29.5 import javax.script.ScriptException; 29.6 import org.testng.TestNG; 29.7 +import org.testng.annotations.AfterClass; 29.8 import org.testng.annotations.BeforeClass; 29.9 import org.testng.annotations.Test; 29.10 29.11 @@ -44,7 +45,7 @@ 29.12 public class NumberAccessTest { 29.13 29.14 private static ScriptEngine e = null; 29.15 - private static SharedObject o = new SharedObject(); 29.16 + private static SharedObject o = null; 29.17 29.18 public static void main(final String[] args) { 29.19 TestNG.main(args); 29.20 @@ -54,10 +55,17 @@ 29.21 public static void setUpClass() throws ScriptException { 29.22 final ScriptEngineManager m = new ScriptEngineManager(); 29.23 e = m.getEngineByName("nashorn"); 29.24 + o = new SharedObject(); 29.25 e.put("o", o); 29.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 29.27 } 29.28 29.29 + @AfterClass 29.30 + public static void tearDownClass() { 29.31 + e = null; 29.32 + o = null; 29.33 + } 29.34 + 29.35 // --------------------------------long 29.36 // tests------------------------------------ 29.37 @Test
30.1 --- a/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Tue Aug 06 17:01:56 2013 -0700 30.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Thu Aug 08 18:19:29 2013 +0530 30.3 @@ -32,6 +32,7 @@ 30.4 import javax.script.ScriptEngineManager; 30.5 import javax.script.ScriptException; 30.6 import org.testng.TestNG; 30.7 +import org.testng.annotations.AfterClass; 30.8 import org.testng.annotations.BeforeClass; 30.9 import org.testng.annotations.Test; 30.10 30.11 @@ -43,7 +44,7 @@ 30.12 public class NumberBoxingTest { 30.13 30.14 private static ScriptEngine e = null; 30.15 - private static SharedObject o = new SharedObject(); 30.16 + private static SharedObject o = null; 30.17 30.18 public static void main(final String[] args) { 30.19 TestNG.main(args); 30.20 @@ -53,10 +54,17 @@ 30.21 public static void setUpClass() throws ScriptException { 30.22 final ScriptEngineManager m = new ScriptEngineManager(); 30.23 e = m.getEngineByName("nashorn"); 30.24 + o = new SharedObject(); 30.25 e.put("o", o); 30.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 30.27 } 30.28 30.29 + @AfterClass 30.30 + public static void tearDownClass() { 30.31 + e = null; 30.32 + o = null; 30.33 + } 30.34 + 30.35 // --------------------------------long 30.36 // tests------------------------------------ 30.37 @Test
31.1 --- a/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Tue Aug 06 17:01:56 2013 -0700 31.2 +++ b/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Thu Aug 08 18:19:29 2013 +0530 31.3 @@ -32,6 +32,7 @@ 31.4 import javax.script.ScriptEngineManager; 31.5 import javax.script.ScriptException; 31.6 import org.testng.TestNG; 31.7 +import org.testng.annotations.AfterClass; 31.8 import org.testng.annotations.BeforeClass; 31.9 import org.testng.annotations.Test; 31.10 31.11 @@ -43,7 +44,7 @@ 31.12 public class ObjectAccessTest { 31.13 31.14 private static ScriptEngine e = null; 31.15 - private static SharedObject o = new SharedObject(); 31.16 + private static SharedObject o = null; 31.17 31.18 public static void main(final String[] args) { 31.19 TestNG.main(args); 31.20 @@ -53,11 +54,18 @@ 31.21 public static void setUpClass() throws ScriptException { 31.22 final ScriptEngineManager m = new ScriptEngineManager(); 31.23 e = m.getEngineByName("nashorn"); 31.24 + o = new SharedObject(); 31.25 e.put("o", o); 31.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 31.27 e.eval("var Person = Packages.jdk.nashorn.api.javaaccess.Person;"); 31.28 } 31.29 31.30 + @AfterClass 31.31 + public static void tearDownClass() { 31.32 + e = null; 31.33 + o = null; 31.34 + } 31.35 + 31.36 @Test 31.37 public void accessFieldObject() throws ScriptException { 31.38 e.eval("var p_object = o.publicObject;");
32.1 --- a/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Tue Aug 06 17:01:56 2013 -0700 32.2 +++ b/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Thu Aug 08 18:19:29 2013 +0530 32.3 @@ -32,6 +32,7 @@ 32.4 import javax.script.ScriptEngineManager; 32.5 import javax.script.ScriptException; 32.6 import org.testng.TestNG; 32.7 +import org.testng.annotations.AfterClass; 32.8 import org.testng.annotations.BeforeClass; 32.9 import org.testng.annotations.Test; 32.10 32.11 @@ -43,7 +44,7 @@ 32.12 public class StringAccessTest { 32.13 32.14 private static ScriptEngine e = null; 32.15 - private static SharedObject o = new SharedObject(); 32.16 + private static SharedObject o = null; 32.17 32.18 public static void main(final String[] args) { 32.19 TestNG.main(args); 32.20 @@ -53,10 +54,17 @@ 32.21 public static void setUpClass() throws ScriptException { 32.22 final ScriptEngineManager m = new ScriptEngineManager(); 32.23 e = m.getEngineByName("nashorn"); 32.24 + o = new SharedObject(); 32.25 e.put("o", o); 32.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 32.27 } 32.28 32.29 + @AfterClass 32.30 + public static void tearDownClass() { 32.31 + e = null; 32.32 + o = null; 32.33 + } 32.34 + 32.35 @Test 32.36 public void accessFieldString() throws ScriptException { 32.37 e.eval("var p_string = o.publicString;");
33.1 --- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Tue Aug 06 17:01:56 2013 -0700 33.2 +++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Thu Aug 08 18:19:29 2013 +0530 33.3 @@ -35,6 +35,8 @@ 33.4 import jdk.nashorn.internal.runtime.Source; 33.5 import jdk.nashorn.internal.runtime.options.Options; 33.6 import org.testng.Assert; 33.7 +import org.testng.annotations.AfterClass; 33.8 +import org.testng.annotations.BeforeClass; 33.9 import org.testng.annotations.Test; 33.10 33.11 /** 33.12 @@ -58,7 +60,8 @@ 33.13 private Context context; 33.14 private ScriptObject global; 33.15 33.16 - public CompilerTest() { 33.17 + @BeforeClass 33.18 + public void setupTest() { 33.19 final Options options = new Options("nashorn"); 33.20 options.set("anon.functions", true); 33.21 options.set("compile.only", true); 33.22 @@ -79,6 +82,12 @@ 33.23 this.global = context.createGlobal(); 33.24 } 33.25 33.26 + @AfterClass 33.27 + public void tearDownTest() { 33.28 + this.context = null; 33.29 + this.global = null; 33.30 + } 33.31 + 33.32 @Test 33.33 public void compileAllTests() { 33.34 if (TEST262) {
34.1 --- a/test/src/jdk/nashorn/internal/parser/ParserTest.java Tue Aug 06 17:01:56 2013 -0700 34.2 +++ b/test/src/jdk/nashorn/internal/parser/ParserTest.java Thu Aug 08 18:19:29 2013 +0530 34.3 @@ -28,10 +28,11 @@ 34.4 import java.io.File; 34.5 import jdk.nashorn.internal.runtime.Context; 34.6 import jdk.nashorn.internal.runtime.ErrorManager; 34.7 -import jdk.nashorn.internal.runtime.ScriptObject; 34.8 import jdk.nashorn.internal.runtime.Source; 34.9 import jdk.nashorn.internal.runtime.options.Options; 34.10 import org.testng.Assert; 34.11 +import org.testng.annotations.AfterClass; 34.12 +import org.testng.annotations.BeforeClass; 34.13 import org.testng.annotations.Test; 34.14 34.15 /** 34.16 @@ -54,9 +55,9 @@ 34.17 } 34.18 34.19 private Context context; 34.20 - private ScriptObject global; 34.21 34.22 - public ParserTest() { 34.23 + @BeforeClass 34.24 + public void setupTest() { 34.25 final Options options = new Options("nashorn"); 34.26 options.set("anon.functions", true); 34.27 options.set("parse.only", true); 34.28 @@ -64,7 +65,11 @@ 34.29 34.30 ErrorManager errors = new ErrorManager(); 34.31 this.context = new Context(options, errors, Thread.currentThread().getContextClassLoader()); 34.32 - this.global = context.createGlobal(); 34.33 + } 34.34 + 34.35 + @AfterClass 34.36 + public void tearDownTest() { 34.37 + this.context = null; 34.38 } 34.39 34.40 @Test 34.41 @@ -125,8 +130,6 @@ 34.42 log("Begin parsing " + file.getAbsolutePath()); 34.43 } 34.44 34.45 - final ScriptObject oldGlobal = Context.getGlobal(); 34.46 - final boolean globalChanged = (oldGlobal != global); 34.47 try { 34.48 final char[] buffer = Source.readFully(file); 34.49 boolean excluded = false; 34.50 @@ -150,9 +153,6 @@ 34.51 } 34.52 }; 34.53 errors.setLimit(0); 34.54 - if (globalChanged) { 34.55 - Context.setGlobal(global); 34.56 - } 34.57 final Source source = new Source(file.getAbsolutePath(), buffer); 34.58 new Parser(context.getEnv(), source, errors).parse(); 34.59 if (errors.getNumberOfErrors() > 0) { 34.60 @@ -167,10 +167,6 @@ 34.61 exp.printStackTrace(System.out); 34.62 } 34.63 failed++; 34.64 - } finally { 34.65 - if (globalChanged) { 34.66 - Context.setGlobal(oldGlobal); 34.67 - } 34.68 } 34.69 34.70 if (VERBOSE) {