Tue, 20 Aug 2013 17:46:45 -0700
Merge
src/jdk/internal/dynalink/support/Backport.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/MapIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java | file | annotate | diff | comparison | revisions | |
src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java | file | annotate | diff | comparison | revisions |
1.1 --- a/exclude/exclude_list_cc.txt Thu Aug 15 09:26:02 2013 -0700 1.2 +++ b/exclude/exclude_list_cc.txt Tue Aug 20 17:46:45 2013 -0700 1.3 @@ -3,4 +3,5 @@ 1.4 <excludeList> 1.5 <test id="JDK-8014647.js" /> 1.6 <test id="javaclassoverrides.js" /> 1.7 + <test id="JDK-8020809.js" /> 1.8 </excludeList>
2.1 --- a/make/project.properties Thu Aug 15 09:26:02 2013 -0700 2.2 +++ b/make/project.properties Tue Aug 20 17:46:45 2013 -0700 2.3 @@ -222,11 +222,16 @@ 2.4 run.test.user.language=tr 2.5 run.test.user.country=TR 2.6 2.7 -# -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods 2.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} 2.9 +run.test.jvmargs.common=-server -Xmx${run.test.xmx} -XX:+TieredCompilation -Dfile.encoding=UTF-8 -Duser.language=${run.test.user.language} -Duser.country=${run.test.user.country} -XX:+HeapDumpOnOutOfMemoryError 2.10 2.11 -#-XX:+HeapDumpOnOutOfMemoryError -XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M 2.12 -run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs.main} 2.13 +#-XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M 2.14 +# -XX:+PrintCompilation -XX:+UnlockDiagnosticVMOptions -XX:+PrintNMethods 2.15 + 2.16 +# turn on assertions for tests 2.17 +run.test.jvmargs.main=${run.test.jvmargs.common} -ea 2.18 + 2.19 +#-XX:-UseCompressedKlassPointers -XX:+PrintHeapAtGC -XX:ClassMetaspaceSize=300M 2.20 +run.test.jvmargs.octane.main=-Xms${run.test.xms} ${run.test.jvmargs.common} 2.21 2.22 run.test.jvmsecurityargs=-Xverify:all -Djava.security.properties=${basedir}/make/java.security.override -Djava.security.manager -Djava.security.policy=${basedir}/build/nashorn.policy 2.23
3.1 --- a/src/jdk/internal/dynalink/ChainedCallSite.java Thu Aug 15 09:26:02 2013 -0700 3.2 +++ b/src/jdk/internal/dynalink/ChainedCallSite.java Tue Aug 20 17:46:45 2013 -0700 3.3 @@ -85,12 +85,12 @@ 3.4 3.5 import java.lang.invoke.MethodHandle; 3.6 import java.lang.invoke.MethodHandles; 3.7 -import java.lang.invoke.MethodType; 3.8 import java.util.Iterator; 3.9 import java.util.LinkedList; 3.10 import java.util.concurrent.atomic.AtomicReference; 3.11 import jdk.internal.dynalink.linker.GuardedInvocation; 3.12 import jdk.internal.dynalink.support.AbstractRelinkableCallSite; 3.13 +import jdk.internal.dynalink.support.Lookup; 3.14 3.15 /** 3.16 * A relinkable call site that maintains a chain of linked method handles. In the default implementation, up to 8 method 3.17 @@ -103,6 +103,9 @@ 3.18 * handle is always at the start of the chain. 3.19 */ 3.20 public class ChainedCallSite extends AbstractRelinkableCallSite { 3.21 + private static final MethodHandle PRUNE = Lookup.findOwnSpecial(MethodHandles.lookup(), "prune", MethodHandle.class, 3.22 + MethodHandle.class); 3.23 + 3.24 private final AtomicReference<LinkedList<GuardedInvocation>> invocations = new AtomicReference<>(); 3.25 3.26 /** 3.27 @@ -194,18 +197,4 @@ 3.28 private MethodHandle prune(MethodHandle relink) { 3.29 return relinkInternal(null, relink, false); 3.30 } 3.31 - 3.32 - private static final MethodHandle PRUNE; 3.33 - static { 3.34 - try { 3.35 - PRUNE = MethodHandles.lookup().findSpecial(ChainedCallSite.class, "prune", MethodType.methodType( 3.36 - MethodHandle.class, MethodHandle.class), ChainedCallSite.class); 3.37 - // NOTE: using two catch blocks so we don't introduce a reference to 1.7 ReflectiveOperationException, allowing 3.38 - // Dynalink to be used on 1.6 JVMs with Remi's backport library. 3.39 - } catch(IllegalAccessException e) { 3.40 - throw new AssertionError(e.getMessage(), e); // Can not happen 3.41 - } catch(NoSuchMethodException e) { 3.42 - throw new AssertionError(e.getMessage(), e); // Can not happen 3.43 - } 3.44 - } 3.45 }
4.1 --- a/src/jdk/internal/dynalink/DynamicLinkerFactory.java Thu Aug 15 09:26:02 2013 -0700 4.2 +++ b/src/jdk/internal/dynalink/DynamicLinkerFactory.java Tue Aug 20 17:46:45 2013 -0700 4.3 @@ -84,6 +84,8 @@ 4.4 package jdk.internal.dynalink; 4.5 4.6 import java.lang.invoke.MutableCallSite; 4.7 +import java.security.AccessController; 4.8 +import java.security.PrivilegedAction; 4.9 import java.util.ArrayList; 4.10 import java.util.Arrays; 4.11 import java.util.Collections; 4.12 @@ -97,6 +99,7 @@ 4.13 import jdk.internal.dynalink.linker.LinkRequest; 4.14 import jdk.internal.dynalink.support.AutoDiscovery; 4.15 import jdk.internal.dynalink.support.BottomGuardingDynamicLinker; 4.16 +import jdk.internal.dynalink.support.ClassLoaderGetterContextProvider; 4.17 import jdk.internal.dynalink.support.CompositeGuardingDynamicLinker; 4.18 import jdk.internal.dynalink.support.CompositeTypeBasedGuardingDynamicLinker; 4.19 import jdk.internal.dynalink.support.LinkerServicesImpl; 4.20 @@ -117,7 +120,9 @@ 4.21 */ 4.22 public static final int DEFAULT_UNSTABLE_RELINK_THRESHOLD = 8; 4.23 4.24 - private ClassLoader classLoader = Thread.currentThread().getContextClassLoader(); 4.25 + private boolean classLoaderExplicitlySet = false; 4.26 + private ClassLoader classLoader; 4.27 + 4.28 private List<? extends GuardingDynamicLinker> prioritizedLinkers; 4.29 private List<? extends GuardingDynamicLinker> fallbackLinkers; 4.30 private int runtimeContextArgCount = 0; 4.31 @@ -126,12 +131,13 @@ 4.32 4.33 /** 4.34 * Sets the class loader for automatic discovery of available linkers. If not set explicitly, then the thread 4.35 - * context class loader at the time of the constructor invocation will be used. 4.36 + * context class loader at the time of {@link #createLinker()} invocation will be used. 4.37 * 4.38 * @param classLoader the class loader used for the autodiscovery of available linkers. 4.39 */ 4.40 public void setClassLoader(ClassLoader classLoader) { 4.41 this.classLoader = classLoader; 4.42 + classLoaderExplicitlySet = true; 4.43 } 4.44 4.45 /** 4.46 @@ -260,7 +266,8 @@ 4.47 addClasses(knownLinkerClasses, prioritizedLinkers); 4.48 addClasses(knownLinkerClasses, fallbackLinkers); 4.49 4.50 - final List<GuardingDynamicLinker> discovered = AutoDiscovery.loadLinkers(classLoader); 4.51 + final ClassLoader effectiveClassLoader = classLoaderExplicitlySet ? classLoader : getThreadContextClassLoader(); 4.52 + final List<GuardingDynamicLinker> discovered = AutoDiscovery.loadLinkers(effectiveClassLoader); 4.53 // Now, concatenate ... 4.54 final List<GuardingDynamicLinker> linkers = 4.55 new ArrayList<>(prioritizedLinkers.size() + discovered.size() 4.56 @@ -303,6 +310,15 @@ 4.57 runtimeContextArgCount, syncOnRelink, unstableRelinkThreshold); 4.58 } 4.59 4.60 + private static ClassLoader getThreadContextClassLoader() { 4.61 + return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 4.62 + @Override 4.63 + public ClassLoader run() { 4.64 + return Thread.currentThread().getContextClassLoader(); 4.65 + } 4.66 + }, ClassLoaderGetterContextProvider.GET_CLASS_LOADER_CONTEXT); 4.67 + } 4.68 + 4.69 private static void addClasses(Set<Class<? extends GuardingDynamicLinker>> knownLinkerClasses, 4.70 List<? extends GuardingDynamicLinker> linkers) { 4.71 for(GuardingDynamicLinker linker: linkers) {
5.1 --- a/src/jdk/internal/dynalink/beans/ClassString.java Thu Aug 15 09:26:02 2013 -0700 5.2 +++ b/src/jdk/internal/dynalink/beans/ClassString.java Tue Aug 20 17:46:45 2013 -0700 5.3 @@ -112,10 +112,6 @@ 5.4 this(type.parameterArray()); 5.5 } 5.6 5.7 - Class<?>[] getClasses() { 5.8 - return classes; 5.9 - } 5.10 - 5.11 @Override 5.12 public boolean equals(Object other) { 5.13 if(!(other instanceof ClassString)) {
6.1 --- a/src/jdk/internal/dynalink/beans/StaticClassLinker.java Thu Aug 15 09:26:02 2013 -0700 6.2 +++ b/src/jdk/internal/dynalink/beans/StaticClassLinker.java Tue Aug 20 17:46:45 2013 -0700 6.3 @@ -189,15 +189,17 @@ 6.4 return type == StaticClass.class; 6.5 } 6.6 6.7 - /*private*/ static final MethodHandle GET_CLASS = new Lookup(MethodHandles.lookup()).findVirtual(StaticClass.class, 6.8 - "getRepresentedClass", MethodType.methodType(Class.class)); 6.9 - 6.10 - /*private*/ static final MethodHandle IS_CLASS = new Lookup(MethodHandles.lookup()).findStatic(StaticClassLinker.class, 6.11 - "isClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class)); 6.12 - 6.13 + /*private*/ static final MethodHandle GET_CLASS; 6.14 + /*private*/ static final MethodHandle IS_CLASS; 6.15 /*private*/ static final MethodHandle ARRAY_CTOR = Lookup.PUBLIC.findStatic(Array.class, "newInstance", 6.16 MethodType.methodType(Object.class, Class.class, int.class)); 6.17 6.18 + static { 6.19 + final Lookup lookup = new Lookup(MethodHandles.lookup()); 6.20 + GET_CLASS = lookup.findVirtual(StaticClass.class, "getRepresentedClass", MethodType.methodType(Class.class)); 6.21 + IS_CLASS = lookup.findOwnStatic("isClass", Boolean.TYPE, Class.class, Object.class); 6.22 + } 6.23 + 6.24 @SuppressWarnings("unused") 6.25 private static boolean isClass(Class<?> clazz, Object obj) { 6.26 return obj instanceof StaticClass && ((StaticClass)obj).getRepresentedClass() == clazz;
7.1 --- a/src/jdk/internal/dynalink/support/Backport.java Thu Aug 15 09:26:02 2013 -0700 7.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 7.3 @@ -1,99 +0,0 @@ 7.4 -/* 7.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 7.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 7.7 - * 7.8 - * This code is free software; you can redistribute it and/or modify it 7.9 - * under the terms of the GNU General Public License version 2 only, as 7.10 - * published by the Free Software Foundation. Oracle designates this 7.11 - * particular file as subject to the "Classpath" exception as provided 7.12 - * by Oracle in the LICENSE file that accompanied this code. 7.13 - * 7.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 7.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 7.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 7.17 - * version 2 for more details (a copy is included in the LICENSE file that 7.18 - * accompanied this code). 7.19 - * 7.20 - * You should have received a copy of the GNU General Public License version 7.21 - * 2 along with this work; if not, write to the Free Software Foundation, 7.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 7.23 - * 7.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 7.25 - * or visit www.oracle.com if you need additional information or have any 7.26 - * questions. 7.27 - */ 7.28 - 7.29 -/* 7.30 - * This file is available under and governed by the GNU General Public 7.31 - * License version 2 only, as published by the Free Software Foundation. 7.32 - * However, the following notice accompanied the original version of this 7.33 - * file, and Oracle licenses the original version of this file under the BSD 7.34 - * license: 7.35 - */ 7.36 -/* 7.37 - Copyright 2009-2013 Attila Szegedi 7.38 - 7.39 - Licensed under both the Apache License, Version 2.0 (the "Apache License") 7.40 - and the BSD License (the "BSD License"), with licensee being free to 7.41 - choose either of the two at their discretion. 7.42 - 7.43 - You may not use this file except in compliance with either the Apache 7.44 - License or the BSD License. 7.45 - 7.46 - If you choose to use this file in compliance with the Apache License, the 7.47 - following notice applies to you: 7.48 - 7.49 - You may obtain a copy of the Apache License at 7.50 - 7.51 - http://www.apache.org/licenses/LICENSE-2.0 7.52 - 7.53 - Unless required by applicable law or agreed to in writing, software 7.54 - distributed under the License is distributed on an "AS IS" BASIS, 7.55 - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 7.56 - implied. See the License for the specific language governing 7.57 - permissions and limitations under the License. 7.58 - 7.59 - If you choose to use this file in compliance with the BSD License, the 7.60 - following notice applies to you: 7.61 - 7.62 - Redistribution and use in source and binary forms, with or without 7.63 - modification, are permitted provided that the following conditions are 7.64 - met: 7.65 - * Redistributions of source code must retain the above copyright 7.66 - notice, this list of conditions and the following disclaimer. 7.67 - * Redistributions in binary form must reproduce the above copyright 7.68 - notice, this list of conditions and the following disclaimer in the 7.69 - documentation and/or other materials provided with the distribution. 7.70 - * Neither the name of the copyright holder nor the names of 7.71 - contributors may be used to endorse or promote products derived from 7.72 - this software without specific prior written permission. 7.73 - 7.74 - THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 7.75 - IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 7.76 - TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 7.77 - PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER 7.78 - BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 7.79 - CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 7.80 - SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 7.81 - BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 7.82 - WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 7.83 - OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 7.84 - ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 7.85 -*/ 7.86 - 7.87 -package jdk.internal.dynalink.support; 7.88 - 7.89 -import java.lang.invoke.MethodHandles; 7.90 - 7.91 -/** 7.92 - * @author Attila Szegedi 7.93 - */ 7.94 -public class Backport { 7.95 - /** 7.96 - * True if Remi's JSR-292 backport agent is active; false if we're using native OpenJDK JSR-292 support. 7.97 - */ 7.98 - public static final boolean inUse = MethodHandles.class.getName().startsWith("jsr292"); 7.99 - 7.100 - private Backport() { 7.101 - } 7.102 -}
8.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 8.2 +++ b/src/jdk/internal/dynalink/support/ClassLoaderGetterContextProvider.java Tue Aug 20 17:46:45 2013 -0700 8.3 @@ -0,0 +1,107 @@ 8.4 +/* 8.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 8.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 8.7 + * 8.8 + * This code is free software; you can redistribute it and/or modify it 8.9 + * under the terms of the GNU General Public License version 2 only, as 8.10 + * published by the Free Software Foundation. Oracle designates this 8.11 + * particular file as subject to the "Classpath" exception as provided 8.12 + * by Oracle in the LICENSE file that accompanied this code. 8.13 + * 8.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 8.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 8.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 8.17 + * version 2 for more details (a copy is included in the LICENSE file that 8.18 + * accompanied this code). 8.19 + * 8.20 + * You should have received a copy of the GNU General Public License version 8.21 + * 2 along with this work; if not, write to the Free Software Foundation, 8.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 8.23 + * 8.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 8.25 + * or visit www.oracle.com if you need additional information or have any 8.26 + * questions. 8.27 + */ 8.28 + 8.29 +/* 8.30 + * This file is available under and governed by the GNU General Public 8.31 + * License version 2 only, as published by the Free Software Foundation. 8.32 + * However, the following notice accompanied the original version of this 8.33 + * file, and Oracle licenses the original version of this file under the BSD 8.34 + * license: 8.35 + */ 8.36 +/* 8.37 + Copyright 2009-2013 Attila Szegedi 8.38 + 8.39 + Licensed under both the Apache License, Version 2.0 (the "Apache License") 8.40 + and the BSD License (the "BSD License"), with licensee being free to 8.41 + choose either of the two at their discretion. 8.42 + 8.43 + You may not use this file except in compliance with either the Apache 8.44 + License or the BSD License. 8.45 + 8.46 + If you choose to use this file in compliance with the Apache License, the 8.47 + following notice applies to you: 8.48 + 8.49 + You may obtain a copy of the Apache License at 8.50 + 8.51 + http://www.apache.org/licenses/LICENSE-2.0 8.52 + 8.53 + Unless required by applicable law or agreed to in writing, software 8.54 + distributed under the License is distributed on an "AS IS" BASIS, 8.55 + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 8.56 + implied. See the License for the specific language governing 8.57 + permissions and limitations under the License. 8.58 + 8.59 + If you choose to use this file in compliance with the BSD License, the 8.60 + following notice applies to you: 8.61 + 8.62 + Redistribution and use in source and binary forms, with or without 8.63 + modification, are permitted provided that the following conditions are 8.64 + met: 8.65 + * Redistributions of source code must retain the above copyright 8.66 + notice, this list of conditions and the following disclaimer. 8.67 + * Redistributions in binary form must reproduce the above copyright 8.68 + notice, this list of conditions and the following disclaimer in the 8.69 + documentation and/or other materials provided with the distribution. 8.70 + * Neither the name of the copyright holder nor the names of 8.71 + contributors may be used to endorse or promote products derived from 8.72 + this software without specific prior written permission. 8.73 + 8.74 + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 8.75 + IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 8.76 + TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A 8.77 + PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL COPYRIGHT HOLDER 8.78 + BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 8.79 + CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 8.80 + SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR 8.81 + BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 8.82 + WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR 8.83 + OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 8.84 + ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 8.85 +*/ 8.86 + 8.87 +package jdk.internal.dynalink.support; 8.88 + 8.89 +import java.security.AccessControlContext; 8.90 +import java.security.Permissions; 8.91 +import java.security.ProtectionDomain; 8.92 + 8.93 +/** 8.94 + * This class exposes a canonical {@link AccessControlContext} with a single {@link RuntimePermission} for 8.95 + * {@code "getClassLoader"} permission that is used by other parts of the code to narrow their set of permissions when 8.96 + * they're retrieving class loaders in privileged blocks. 8.97 + */ 8.98 +public class ClassLoaderGetterContextProvider { 8.99 + /** 8.100 + * Canonical instance of {@link AccessControlContext} with a single {@link RuntimePermission} for 8.101 + * {@code "getClassLoader"} permission. 8.102 + */ 8.103 + public static final AccessControlContext GET_CLASS_LOADER_CONTEXT; 8.104 + static { 8.105 + final Permissions perms = new Permissions(); 8.106 + perms.add(new RuntimePermission("getClassLoader")); 8.107 + GET_CLASS_LOADER_CONTEXT = new AccessControlContext( 8.108 + new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 8.109 + } 8.110 +}
9.1 --- a/src/jdk/internal/dynalink/support/ClassMap.java Thu Aug 15 09:26:02 2013 -0700 9.2 +++ b/src/jdk/internal/dynalink/support/ClassMap.java Tue Aug 20 17:46:45 2013 -0700 9.3 @@ -85,6 +85,8 @@ 9.4 9.5 import java.lang.ref.Reference; 9.6 import java.lang.ref.SoftReference; 9.7 +import java.security.AccessController; 9.8 +import java.security.PrivilegedAction; 9.9 import java.util.Map; 9.10 import java.util.WeakHashMap; 9.11 import java.util.concurrent.ConcurrentHashMap; 9.12 @@ -122,21 +124,12 @@ 9.13 protected abstract T computeValue(Class<?> clazz); 9.14 9.15 /** 9.16 - * Returns the class loader that governs the strong referenceability of this class map. 9.17 - * 9.18 - * @return the class loader that governs the strong referenceability of this class map. 9.19 - */ 9.20 - public ClassLoader getClassLoader() { 9.21 - return classLoader; 9.22 - } 9.23 - 9.24 - /** 9.25 * Returns the value associated with the class 9.26 * 9.27 * @param clazz the class 9.28 * @return the value associated with the class 9.29 */ 9.30 - public T get(Class<?> clazz) { 9.31 + public T get(final Class<?> clazz) { 9.32 // Check in fastest first - objects we're allowed to strongly reference 9.33 final T v = map.get(clazz); 9.34 if(v != null) { 9.35 @@ -156,8 +149,16 @@ 9.36 // Not found in either place; create a new value 9.37 final T newV = computeValue(clazz); 9.38 assert newV != null; 9.39 + 9.40 + final ClassLoader clazzLoader = AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 9.41 + @Override 9.42 + public ClassLoader run() { 9.43 + return clazz.getClassLoader(); 9.44 + } 9.45 + }, ClassLoaderGetterContextProvider.GET_CLASS_LOADER_CONTEXT); 9.46 + 9.47 // If allowed to strongly reference, put it in the fast map 9.48 - if(Guards.canReferenceDirectly(classLoader, clazz.getClassLoader())) { 9.49 + if(Guards.canReferenceDirectly(classLoader, clazzLoader)) { 9.50 final T oldV = map.putIfAbsent(clazz, newV); 9.51 return oldV != null ? oldV : newV; 9.52 }
10.1 --- a/src/jdk/internal/dynalink/support/Guards.java Thu Aug 15 09:26:02 2013 -0700 10.2 +++ b/src/jdk/internal/dynalink/support/Guards.java Tue Aug 20 17:46:45 2013 -0700 10.3 @@ -258,23 +258,24 @@ 10.4 type.changeReturnType(Boolean.TYPE), new int[] { pos }); 10.5 } 10.6 10.7 - private static final MethodHandle IS_OF_CLASS = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 10.8 - "isOfClass", MethodType.methodType(Boolean.TYPE, Class.class, Object.class)); 10.9 - 10.10 private static final MethodHandle IS_INSTANCE = Lookup.PUBLIC.findVirtual(Class.class, "isInstance", 10.11 MethodType.methodType(Boolean.TYPE, Object.class)); 10.12 10.13 - private static final MethodHandle IS_ARRAY = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, "isArray", 10.14 - MethodType.methodType(Boolean.TYPE, Object.class)); 10.15 + private static final MethodHandle IS_OF_CLASS; 10.16 + private static final MethodHandle IS_ARRAY; 10.17 + private static final MethodHandle IS_IDENTICAL; 10.18 + private static final MethodHandle IS_NULL; 10.19 + private static final MethodHandle IS_NOT_NULL; 10.20 10.21 - private static final MethodHandle IS_IDENTICAL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 10.22 - "isIdentical", MethodType.methodType(Boolean.TYPE, Object.class, Object.class)); 10.23 + static { 10.24 + final Lookup lookup = new Lookup(MethodHandles.lookup()); 10.25 10.26 - private static final MethodHandle IS_NULL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 10.27 - "isNull", MethodType.methodType(Boolean.TYPE, Object.class)); 10.28 - 10.29 - private static final MethodHandle IS_NOT_NULL = new Lookup(MethodHandles.lookup()).findStatic(Guards.class, 10.30 - "isNotNull", MethodType.methodType(Boolean.TYPE, Object.class)); 10.31 + IS_OF_CLASS = lookup.findOwnStatic("isOfClass", Boolean.TYPE, Class.class, Object.class); 10.32 + IS_ARRAY = lookup.findOwnStatic("isArray", Boolean.TYPE, Object.class); 10.33 + IS_IDENTICAL = lookup.findOwnStatic("isIdentical", Boolean.TYPE, Object.class, Object.class); 10.34 + IS_NULL = lookup.findOwnStatic("isNull", Boolean.TYPE, Object.class); 10.35 + IS_NOT_NULL = lookup.findOwnStatic("isNotNull", Boolean.TYPE, Object.class); 10.36 + } 10.37 10.38 /** 10.39 * Creates a guard method that tests its only argument for being of an exact particular class.
11.1 --- a/src/jdk/internal/dynalink/support/Lookup.java Thu Aug 15 09:26:02 2013 -0700 11.2 +++ b/src/jdk/internal/dynalink/support/Lookup.java Tue Aug 20 17:46:45 2013 -0700 11.3 @@ -89,7 +89,6 @@ 11.4 import java.lang.reflect.Constructor; 11.5 import java.lang.reflect.Field; 11.6 import java.lang.reflect.Method; 11.7 -import java.lang.reflect.Modifier; 11.8 11.9 /** 11.10 * A wrapper around MethodHandles.Lookup that masks checked exceptions in those cases when you're looking up methods 11.11 @@ -235,9 +234,8 @@ 11.12 } 11.13 11.14 /** 11.15 - * Performs a findSpecial on the underlying lookup, except for the backport where it rather uses unreflect. Converts 11.16 - * any encountered {@link IllegalAccessException} into an {@link IllegalAccessError} and a 11.17 - * {@link NoSuchMethodException} into a {@link NoSuchMethodError}. 11.18 + * Performs a findSpecial on the underlying lookup. Converts any encountered {@link IllegalAccessException} into an 11.19 + * {@link IllegalAccessError} and a {@link NoSuchMethodException} into a {@link NoSuchMethodError}. 11.20 * 11.21 * @param declaringClass class declaring the method 11.22 * @param name the name of the method 11.23 @@ -248,13 +246,6 @@ 11.24 */ 11.25 public MethodHandle findSpecial(Class<?> declaringClass, String name, MethodType type) { 11.26 try { 11.27 - if(Backport.inUse) { 11.28 - final Method m = declaringClass.getDeclaredMethod(name, type.parameterArray()); 11.29 - if(!Modifier.isPublic(declaringClass.getModifiers()) || !Modifier.isPublic(m.getModifiers())) { 11.30 - m.setAccessible(true); 11.31 - } 11.32 - return unreflect(m); 11.33 - } 11.34 return lookup.findSpecial(declaringClass, name, type, declaringClass); 11.35 } catch(IllegalAccessException e) { 11.36 final IllegalAccessError ee = new IllegalAccessError("Failed to access special method " + methodDescription(
12.1 --- a/src/jdk/internal/dynalink/support/TypeConverterFactory.java Thu Aug 15 09:26:02 2013 -0700 12.2 +++ b/src/jdk/internal/dynalink/support/TypeConverterFactory.java Tue Aug 20 17:46:45 2013 -0700 12.3 @@ -87,6 +87,8 @@ 12.4 import java.lang.invoke.MethodHandles; 12.5 import java.lang.invoke.MethodType; 12.6 import java.lang.invoke.WrongMethodTypeException; 12.7 +import java.security.AccessController; 12.8 +import java.security.PrivilegedAction; 12.9 import java.util.LinkedList; 12.10 import java.util.List; 12.11 import jdk.internal.dynalink.linker.ConversionComparator; 12.12 @@ -110,7 +112,7 @@ 12.13 private final ClassValue<ClassMap<MethodHandle>> converterMap = new ClassValue<ClassMap<MethodHandle>>() { 12.14 @Override 12.15 protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) { 12.16 - return new ClassMap<MethodHandle>(sourceType.getClassLoader()) { 12.17 + return new ClassMap<MethodHandle>(getClassLoader(sourceType)) { 12.18 @Override 12.19 protected MethodHandle computeValue(Class<?> targetType) { 12.20 try { 12.21 @@ -128,7 +130,7 @@ 12.22 private final ClassValue<ClassMap<MethodHandle>> converterIdentityMap = new ClassValue<ClassMap<MethodHandle>>() { 12.23 @Override 12.24 protected ClassMap<MethodHandle> computeValue(final Class<?> sourceType) { 12.25 - return new ClassMap<MethodHandle>(sourceType.getClassLoader()) { 12.26 + return new ClassMap<MethodHandle>(getClassLoader(sourceType)) { 12.27 @Override 12.28 protected MethodHandle computeValue(Class<?> targetType) { 12.29 if(!canAutoConvert(sourceType, targetType)) { 12.30 @@ -143,6 +145,15 @@ 12.31 } 12.32 }; 12.33 12.34 + private static final ClassLoader getClassLoader(final Class<?> clazz) { 12.35 + return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>() { 12.36 + @Override 12.37 + public ClassLoader run() { 12.38 + return clazz.getClassLoader(); 12.39 + } 12.40 + }, ClassLoaderGetterContextProvider.GET_CLASS_LOADER_CONTEXT); 12.41 + } 12.42 + 12.43 /** 12.44 * Creates a new type converter factory from the available {@link GuardingTypeConverterFactory} instances. 12.45 *
13.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Thu Aug 15 09:26:02 2013 -0700 13.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngine.java Tue Aug 20 17:46:45 2013 -0700 13.3 @@ -36,10 +36,13 @@ 13.4 import java.lang.reflect.Modifier; 13.5 import java.net.URL; 13.6 import java.nio.charset.Charset; 13.7 +import java.security.AccessControlContext; 13.8 import java.security.AccessController; 13.9 +import java.security.Permissions; 13.10 import java.security.PrivilegedAction; 13.11 import java.security.PrivilegedActionException; 13.12 import java.security.PrivilegedExceptionAction; 13.13 +import java.security.ProtectionDomain; 13.14 import java.text.MessageFormat; 13.15 import java.util.Locale; 13.16 import java.util.ResourceBundle; 13.17 @@ -71,6 +74,14 @@ 13.18 */ 13.19 13.20 public final class NashornScriptEngine extends AbstractScriptEngine implements Compilable, Invocable { 13.21 + private static AccessControlContext createPermAccCtxt(final String permName) { 13.22 + final Permissions perms = new Permissions(); 13.23 + perms.add(new RuntimePermission(permName)); 13.24 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 13.25 + } 13.26 + 13.27 + private static final AccessControlContext CREATE_CONTEXT_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_CONTEXT); 13.28 + private static final AccessControlContext CREATE_GLOBAL_ACC_CTXT = createPermAccCtxt(Context.NASHORN_CREATE_GLOBAL); 13.29 13.30 private final ScriptEngineFactory factory; 13.31 private final Context nashornContext; 13.32 @@ -84,16 +95,9 @@ 13.33 13.34 private static final String MESSAGES_RESOURCE = "jdk.nashorn.api.scripting.resources.Messages"; 13.35 13.36 - // Without do privileged, under security manager messages can not be loaded. 13.37 private static final ResourceBundle MESSAGES_BUNDLE; 13.38 static { 13.39 - MESSAGES_BUNDLE = AccessController.doPrivileged( 13.40 - new PrivilegedAction<ResourceBundle>() { 13.41 - @Override 13.42 - public ResourceBundle run() { 13.43 - return ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault()); 13.44 - } 13.45 - }); 13.46 + MESSAGES_BUNDLE = ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault()); 13.47 } 13.48 13.49 private static String getMessage(final String msgId, final String... args) { 13.50 @@ -128,7 +132,7 @@ 13.51 throw e; 13.52 } 13.53 } 13.54 - }); 13.55 + }, CREATE_CONTEXT_ACC_CTXT); 13.56 13.57 // create new global object 13.58 this.global = createNashornGlobal(); 13.59 @@ -340,7 +344,7 @@ 13.60 throw e; 13.61 } 13.62 } 13.63 - }); 13.64 + }, CREATE_GLOBAL_ACC_CTXT); 13.65 13.66 nashornContext.initGlobal(newGlobal); 13.67 13.68 @@ -362,10 +366,8 @@ 13.69 } 13.70 13.71 private void evalEngineScript() throws ScriptException { 13.72 - evalSupportScript("resources/engine.js", NashornException.ENGINE_SCRIPT_SOURCE_NAME); 13.73 - } 13.74 - 13.75 - private void evalSupportScript(final String script, final String name) throws ScriptException { 13.76 + final String script = "resources/engine.js"; 13.77 + final String name = NashornException.ENGINE_SCRIPT_SOURCE_NAME; 13.78 try { 13.79 final InputStream is = AccessController.doPrivileged( 13.80 new PrivilegedExceptionAction<InputStream>() { 13.81 @@ -380,6 +382,9 @@ 13.82 eval(isr); 13.83 } 13.84 } catch (final PrivilegedActionException | IOException e) { 13.85 + if (Context.DEBUG) { 13.86 + e.printStackTrace(); 13.87 + } 13.88 throw new ScriptException(e); 13.89 } finally { 13.90 put(ScriptEngine.FILENAME, null);
14.1 --- a/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Thu Aug 15 09:26:02 2013 -0700 14.2 +++ b/src/jdk/nashorn/api/scripting/NashornScriptEngineFactory.java Tue Aug 20 17:46:45 2013 -0700 14.3 @@ -30,6 +30,7 @@ 14.4 import java.util.List; 14.5 import javax.script.ScriptEngine; 14.6 import javax.script.ScriptEngineFactory; 14.7 +import jdk.nashorn.internal.runtime.Context; 14.8 import jdk.nashorn.internal.runtime.Version; 14.9 14.10 /** 14.11 @@ -136,7 +137,14 @@ 14.12 14.13 @Override 14.14 public ScriptEngine getScriptEngine() { 14.15 - return new NashornScriptEngine(this, getAppClassLoader()); 14.16 + try { 14.17 + return new NashornScriptEngine(this, getAppClassLoader()); 14.18 + } catch (final RuntimeException e) { 14.19 + if (Context.DEBUG) { 14.20 + e.printStackTrace(); 14.21 + } 14.22 + throw e; 14.23 + } 14.24 } 14.25 14.26 /** 14.27 @@ -178,7 +186,7 @@ 14.28 private static void checkConfigPermission() { 14.29 final SecurityManager sm = System.getSecurityManager(); 14.30 if (sm != null) { 14.31 - sm.checkPermission(new RuntimePermission("nashorn.setConfig")); 14.32 + sm.checkPermission(new RuntimePermission(Context.NASHORN_SET_CONFIG)); 14.33 } 14.34 } 14.35
15.1 --- a/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Thu Aug 15 09:26:02 2013 -0700 15.2 +++ b/src/jdk/nashorn/api/scripting/ScriptObjectMirror.java Tue Aug 20 17:46:45 2013 -0700 15.3 @@ -25,14 +25,17 @@ 15.4 15.5 package jdk.nashorn.api.scripting; 15.6 15.7 +import java.security.AccessControlContext; 15.8 import java.security.AccessController; 15.9 +import java.security.Permissions; 15.10 import java.security.PrivilegedAction; 15.11 +import java.security.ProtectionDomain; 15.12 import java.util.AbstractMap; 15.13 import java.util.ArrayList; 15.14 import java.util.Collection; 15.15 import java.util.Collections; 15.16 +import java.util.Iterator; 15.17 import java.util.LinkedHashSet; 15.18 -import java.util.Iterator; 15.19 import java.util.List; 15.20 import java.util.Map; 15.21 import java.util.Set; 15.22 @@ -49,6 +52,14 @@ 15.23 * netscape.javascript.JSObject interface. 15.24 */ 15.25 public final class ScriptObjectMirror extends JSObject implements Bindings { 15.26 + private static AccessControlContext getContextAccCtxt() { 15.27 + final Permissions perms = new Permissions(); 15.28 + perms.add(new RuntimePermission(Context.NASHORN_GET_CONTEXT)); 15.29 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 15.30 + } 15.31 + 15.32 + private static final AccessControlContext GET_CONTEXT_ACC_CTXT = getContextAccCtxt(); 15.33 + 15.34 private final ScriptObject sobj; 15.35 private final ScriptObject global; 15.36 15.37 @@ -144,7 +155,7 @@ 15.38 public Context run() { 15.39 return Context.getContext(); 15.40 } 15.41 - }); 15.42 + }, GET_CONTEXT_ACC_CTXT); 15.43 return wrap(context.eval(global, s, null, null, false), global); 15.44 } 15.45 });
16.1 --- a/src/jdk/nashorn/internal/codegen/CompileUnit.java Thu Aug 15 09:26:02 2013 -0700 16.2 +++ b/src/jdk/nashorn/internal/codegen/CompileUnit.java Tue Aug 20 17:46:45 2013 -0700 16.3 @@ -33,7 +33,7 @@ 16.4 private final String className; 16.5 16.6 /** Current class generator */ 16.7 - private final ClassEmitter classEmitter; 16.8 + private ClassEmitter classEmitter; 16.9 16.10 private long weight; 16.11 16.12 @@ -64,7 +64,11 @@ 16.13 * @param clazz class with code for this compile unit 16.14 */ 16.15 void setCode(final Class<?> clazz) { 16.16 + clazz.getClass(); // null check 16.17 this.clazz = clazz; 16.18 + // Revisit this - refactor to avoid null-ed out non-final fields 16.19 + // null out emitter 16.20 + this.classEmitter = null; 16.21 } 16.22 16.23 /**
17.1 --- a/src/jdk/nashorn/internal/codegen/CompilerConstants.java Thu Aug 15 09:26:02 2013 -0700 17.2 +++ b/src/jdk/nashorn/internal/codegen/CompilerConstants.java Tue Aug 20 17:46:45 2013 -0700 17.3 @@ -489,20 +489,6 @@ 17.4 } 17.5 17.6 /** 17.7 - * Create a static call, looking up the method handle for it at the same time 17.8 - * 17.9 - * @param clazz the class 17.10 - * @param name the name of the method 17.11 - * @param rtype the return type of the method 17.12 - * @param ptypes the parameter types of the method 17.13 - * 17.14 - * @return the call object representing the static call 17.15 - */ 17.16 - public static Call staticCall(final Class<?> clazz, final String name, final Class<?> rtype, final Class<?>... ptypes) { 17.17 - return staticCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); 17.18 - } 17.19 - 17.20 - /** 17.21 * Create a static call, given an explicit lookup, looking up the method handle for it at the same time 17.22 * 17.23 * @param lookup the lookup 17.24 @@ -523,20 +509,6 @@ 17.25 } 17.26 17.27 /** 17.28 - * Create a virtual call, looking up the method handle for it at the same time 17.29 - * 17.30 - * @param clazz the class 17.31 - * @param name the name of the method 17.32 - * @param rtype the return type of the method 17.33 - * @param ptypes the parameter types of the method 17.34 - * 17.35 - * @return the call object representing the virtual call 17.36 - */ 17.37 - public static Call virtualCall(final Class<?> clazz, final String name, final Class<?> rtype, final Class<?>... ptypes) { 17.38 - return virtualCall(MethodHandles.publicLookup(), clazz, name, rtype, ptypes); 17.39 - } 17.40 - 17.41 - /** 17.42 * Create a virtual call, given an explicit lookup, looking up the method handle for it at the same time 17.43 * 17.44 * @param lookup the lookup
18.1 --- a/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Thu Aug 15 09:26:02 2013 -0700 18.2 +++ b/src/jdk/nashorn/internal/codegen/ObjectClassGenerator.java Tue Aug 20 17:46:45 2013 -0700 18.3 @@ -317,7 +317,8 @@ 18.4 final String className = getClassName(fieldCount); 18.5 final String superName = className(ScriptObject.class); 18.6 final ClassEmitter classEmitter = newClassEmitter(className, superName); 18.7 - final List<String> initFields = addFields(classEmitter, fieldCount); 18.8 + 18.9 + addFields(classEmitter, fieldCount); 18.10 18.11 final MethodEmitter init = newInitMethod(classEmitter); 18.12 init.returnVoid();
19.1 --- a/src/jdk/nashorn/internal/codegen/ObjectCreator.java Thu Aug 15 09:26:02 2013 -0700 19.2 +++ b/src/jdk/nashorn/internal/codegen/ObjectCreator.java Tue Aug 20 17:46:45 2013 -0700 19.3 @@ -45,9 +45,11 @@ 19.4 /** Code generator */ 19.5 protected final CodeGenerator codegen; 19.6 19.7 - private final boolean isScope; 19.8 - private final boolean hasArguments; 19.9 - protected PropertyMap propertyMap; 19.10 + /** Property map */ 19.11 + protected PropertyMap propertyMap; 19.12 + 19.13 + private final boolean isScope; 19.14 + private final boolean hasArguments; 19.15 19.16 /** 19.17 * Constructor
20.1 --- a/src/jdk/nashorn/internal/ir/BinaryNode.java Thu Aug 15 09:26:02 2013 -0700 20.2 +++ b/src/jdk/nashorn/internal/ir/BinaryNode.java Tue Aug 20 17:46:45 2013 -0700 20.3 @@ -99,6 +99,7 @@ 20.4 case DIV: 20.5 case MOD: 20.6 case MUL: 20.7 + case SUB: 20.8 case ASSIGN_DIV: 20.9 case ASSIGN_MOD: 20.10 case ASSIGN_MUL:
21.1 --- a/src/jdk/nashorn/internal/ir/BreakableNode.java Thu Aug 15 09:26:02 2013 -0700 21.2 +++ b/src/jdk/nashorn/internal/ir/BreakableNode.java Tue Aug 20 17:46:45 2013 -0700 21.3 @@ -33,6 +33,14 @@ 21.4 * a {@code break} statement 21.5 */ 21.6 public interface BreakableNode extends LexicalContextNode { 21.7 + /** 21.8 + * Ensure that any labels in this breakable node are unique so 21.9 + * that new jumps won't go to old parts of the tree. Used for 21.10 + * example for cloning finally blocks 21.11 + * 21.12 + * @param lc the lexical context 21.13 + * @return node after labels have been made unique 21.14 + */ 21.15 public abstract Node ensureUniqueLabels(final LexicalContext lc); 21.16 21.17 /**
22.1 --- a/src/jdk/nashorn/internal/ir/IdentNode.java Thu Aug 15 09:26:02 2013 -0700 22.2 +++ b/src/jdk/nashorn/internal/ir/IdentNode.java Tue Aug 20 17:46:45 2013 -0700 22.3 @@ -161,13 +161,13 @@ 22.4 * converting to object, for example if the symbol is used as the left hand side of an 22.5 * assignment such as in the code below.</p> 22.6 * 22.7 - * <pre>{@code 22.8 + * <pre> 22.9 * try { 22.10 * return 2; 22.11 * } finally { 22.12 * return 3; 22.13 * } 22.14 - * }</pre> 22.15 + * } 22.16 * 22.17 * @return true if can have callsite type 22.18 */
23.1 --- a/src/jdk/nashorn/internal/ir/LexicalContextNode.java Thu Aug 15 09:26:02 2013 -0700 23.2 +++ b/src/jdk/nashorn/internal/ir/LexicalContextNode.java Tue Aug 20 17:46:45 2013 -0700 23.3 @@ -44,8 +44,14 @@ 23.4 Node accept(final LexicalContext lc, final NodeVisitor<? extends LexicalContext> visitor); 23.5 23.6 // Would be a default method on Java 8 23.7 + /** 23.8 + * Helper class for accept for items of this lexical context, delegates to the 23.9 + * subclass accept and makes sure that the node is on the context before accepting 23.10 + * and gets popped after accepting (and that the stack is consistent in that the 23.11 + * node has been replaced with the possible new node resulting in visitation) 23.12 + */ 23.13 static class Acceptor { 23.14 - static Node accept(LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { 23.15 + static Node accept(final LexicalContextNode node, final NodeVisitor<? extends LexicalContext> visitor) { 23.16 final LexicalContext lc = visitor.getLexicalContext(); 23.17 lc.push(node); 23.18 final LexicalContextNode newNode = (LexicalContextNode)node.accept(lc, visitor);
24.1 --- a/src/jdk/nashorn/internal/objects/Global.java Thu Aug 15 09:26:02 2013 -0700 24.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Tue Aug 20 17:46:45 2013 -0700 24.3 @@ -35,12 +35,12 @@ 24.4 import java.lang.invoke.MethodHandles; 24.5 import java.lang.ref.SoftReference; 24.6 import java.lang.reflect.Field; 24.7 -import java.security.AccessController; 24.8 -import java.security.PrivilegedAction; 24.9 import java.util.Arrays; 24.10 import java.util.LinkedHashMap; 24.11 import java.util.List; 24.12 import java.util.Map; 24.13 +import java.util.concurrent.Callable; 24.14 +import java.util.concurrent.ConcurrentHashMap; 24.15 import jdk.internal.dynalink.linker.GuardedInvocation; 24.16 import jdk.internal.dynalink.linker.LinkRequest; 24.17 import jdk.nashorn.internal.objects.annotations.Attribute; 24.18 @@ -72,8 +72,8 @@ 24.19 */ 24.20 @ScriptClass("Global") 24.21 public final class Global extends ScriptObject implements GlobalObject, Scope { 24.22 - private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 24.23 - private static final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 24.24 + private final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 24.25 + private final InvokeByName VALUE_OF = new InvokeByName("valueOf", ScriptObject.class); 24.26 24.27 /** ECMA 15.1.2.2 parseInt (string , radix) */ 24.28 @Property(attributes = Attribute.NOT_ENUMERABLE) 24.29 @@ -418,7 +418,7 @@ 24.30 // security check first 24.31 final SecurityManager sm = System.getSecurityManager(); 24.32 if (sm != null) { 24.33 - sm.checkPermission(new RuntimePermission("nashorn.newGlobal")); 24.34 + sm.checkPermission(new RuntimePermission(Context.NASHORN_CREATE_GLOBAL)); 24.35 } 24.36 24.37 // null check on context 24.38 @@ -709,6 +709,35 @@ 24.39 classCache.put(source, new SoftReference<Class<?>>(clazz)); 24.40 } 24.41 24.42 + private static <T> T getLazilyCreatedValue(final Object key, final Callable<T> creator, final Map<Object, T> map) { 24.43 + final T obj = map.get(key); 24.44 + if (obj != null) { 24.45 + return obj; 24.46 + } 24.47 + 24.48 + try { 24.49 + final T newObj = creator.call(); 24.50 + final T existingObj = map.putIfAbsent(key, newObj); 24.51 + return existingObj != null ? existingObj : newObj; 24.52 + } catch (final Exception exp) { 24.53 + throw new RuntimeException(exp); 24.54 + } 24.55 + } 24.56 + 24.57 + private final Map<Object, InvokeByName> namedInvokers = new ConcurrentHashMap<>(); 24.58 + 24.59 + @Override 24.60 + public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator) { 24.61 + return getLazilyCreatedValue(key, creator, namedInvokers); 24.62 + } 24.63 + 24.64 + private final Map<Object, MethodHandle> dynamicInvokers = new ConcurrentHashMap<>(); 24.65 + 24.66 + @Override 24.67 + public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator) { 24.68 + return getLazilyCreatedValue(key, creator, dynamicInvokers); 24.69 + } 24.70 + 24.71 /** 24.72 * This is the eval used when 'indirect' eval call is made. 24.73 * 24.74 @@ -1749,19 +1778,13 @@ 24.75 } 24.76 24.77 private static void copyOptions(final ScriptObject options, final ScriptEnvironment scriptEnv) { 24.78 - AccessController.doPrivileged(new PrivilegedAction<Void>() { 24.79 - @Override 24.80 - public Void run() { 24.81 - for (Field f : scriptEnv.getClass().getFields()) { 24.82 - try { 24.83 - options.set(f.getName(), f.get(scriptEnv), false); 24.84 - } catch (final IllegalArgumentException | IllegalAccessException exp) { 24.85 - throw new RuntimeException(exp); 24.86 - } 24.87 - } 24.88 - return null; 24.89 + for (Field f : scriptEnv.getClass().getFields()) { 24.90 + try { 24.91 + options.set(f.getName(), f.get(scriptEnv), false); 24.92 + } catch (final IllegalArgumentException | IllegalAccessException exp) { 24.93 + throw new RuntimeException(exp); 24.94 } 24.95 - }); 24.96 + } 24.97 } 24.98 24.99 private void initTypedArray() {
25.1 --- a/src/jdk/nashorn/internal/objects/NativeArguments.java Thu Aug 15 09:26:02 2013 -0700 25.2 +++ b/src/jdk/nashorn/internal/objects/NativeArguments.java Tue Aug 20 17:46:45 2013 -0700 25.3 @@ -76,36 +76,21 @@ 25.4 25.5 private Object length; 25.6 private Object callee; 25.7 - private ArrayData namedArgs; 25.8 - // This is lazily initialized - only when delete is invoked at all 25.9 + private final int numMapped; 25.10 + private final int numParams; 25.11 + 25.12 + // These are lazily initialized when delete is invoked on a mapped arg or an unmapped argument is set. 25.13 + private ArrayData unmappedArgs; 25.14 private BitSet deleted; 25.15 25.16 NativeArguments(final Object[] arguments, final Object callee, final int numParams, final ScriptObject proto, final PropertyMap map) { 25.17 super(proto, map); 25.18 setIsArguments(); 25.19 - 25.20 setArray(ArrayData.allocate(arguments)); 25.21 this.length = arguments.length; 25.22 this.callee = callee; 25.23 - 25.24 - /** 25.25 - * Declared number of parameters may be more or less than the actual passed 25.26 - * runtime arguments count. We need to truncate or extend with undefined values. 25.27 - * 25.28 - * Example: 25.29 - * 25.30 - * // less declared params 25.31 - * (function (x) { print(arguments); })(20, 44); 25.32 - * 25.33 - * // more declared params 25.34 - * (function (x, y) { print(arguments); })(3); 25.35 - */ 25.36 - final Object[] newValues = new Object[numParams]; 25.37 - if (numParams > arguments.length) { 25.38 - Arrays.fill(newValues, UNDEFINED); 25.39 - } 25.40 - System.arraycopy(arguments, 0, newValues, 0, Math.min(newValues.length, arguments.length)); 25.41 - this.namedArgs = ArrayData.allocate(newValues); 25.42 + this.numMapped = Math.min(numParams, arguments.length); 25.43 + this.numParams = numParams; 25.44 } 25.45 25.46 @Override 25.47 @@ -118,7 +103,8 @@ 25.48 */ 25.49 @Override 25.50 public Object getArgument(final int key) { 25.51 - return namedArgs.has(key) ? namedArgs.getObject(key) : UNDEFINED; 25.52 + assert key >= 0 && key < numParams : "invalid argument index"; 25.53 + return isMapped(key) ? getArray().getObject(key) : getUnmappedArg(key); 25.54 } 25.55 25.56 /** 25.57 @@ -126,353 +112,36 @@ 25.58 */ 25.59 @Override 25.60 public void setArgument(final int key, final Object value) { 25.61 - if (namedArgs.has(key)) { 25.62 - namedArgs = namedArgs.set(key, value, false); 25.63 + assert key >= 0 && key < numParams : "invalid argument index"; 25.64 + if (isMapped(key)) { 25.65 + setArray(getArray().set(key, value, false)); 25.66 + } else { 25.67 + setUnmappedArg(key, value); 25.68 } 25.69 } 25.70 25.71 @Override 25.72 - public int getInt(final Object key) { 25.73 - final int index = ArrayIndex.getArrayIndex(key); 25.74 - return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); 25.75 - } 25.76 - 25.77 - @Override 25.78 - public int getInt(final double key) { 25.79 - final int index = ArrayIndex.getArrayIndex(key); 25.80 - return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); 25.81 - } 25.82 - 25.83 - @Override 25.84 - public int getInt(final long key) { 25.85 - final int index = ArrayIndex.getArrayIndex(key); 25.86 - return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); 25.87 - } 25.88 - 25.89 - @Override 25.90 - public int getInt(final int key) { 25.91 - final int index = ArrayIndex.getArrayIndex(key); 25.92 - return isMapped(index) ? namedArgs.getInt(index) : super.getInt(key); 25.93 - } 25.94 - 25.95 - @Override 25.96 - public long getLong(final Object key) { 25.97 - final int index = ArrayIndex.getArrayIndex(key); 25.98 - return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); 25.99 - } 25.100 - 25.101 - @Override 25.102 - public long getLong(final double key) { 25.103 - final int index = ArrayIndex.getArrayIndex(key); 25.104 - return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); 25.105 - } 25.106 - 25.107 - @Override 25.108 - public long getLong(final long key) { 25.109 - final int index = ArrayIndex.getArrayIndex(key); 25.110 - return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); 25.111 - } 25.112 - 25.113 - @Override 25.114 - public long getLong(final int key) { 25.115 - final int index = ArrayIndex.getArrayIndex(key); 25.116 - return isMapped(index) ? namedArgs.getLong(index) : super.getLong(key); 25.117 - } 25.118 - 25.119 - @Override 25.120 - public double getDouble(final Object key) { 25.121 - final int index = ArrayIndex.getArrayIndex(key); 25.122 - return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); 25.123 - } 25.124 - 25.125 - @Override 25.126 - public double getDouble(final double key) { 25.127 - final int index = ArrayIndex.getArrayIndex(key); 25.128 - return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); 25.129 - } 25.130 - 25.131 - @Override 25.132 - public double getDouble(final long key) { 25.133 - final int index = ArrayIndex.getArrayIndex(key); 25.134 - return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); 25.135 - } 25.136 - 25.137 - @Override 25.138 - public double getDouble(final int key) { 25.139 - final int index = ArrayIndex.getArrayIndex(key); 25.140 - return isMapped(index) ? namedArgs.getDouble(index) : super.getDouble(key); 25.141 - } 25.142 - 25.143 - @Override 25.144 - public Object get(final Object key) { 25.145 - final int index = ArrayIndex.getArrayIndex(key); 25.146 - return isMapped(index) ? namedArgs.getObject(index) : super.get(key); 25.147 - } 25.148 - 25.149 - @Override 25.150 - public Object get(final double key) { 25.151 - final int index = ArrayIndex.getArrayIndex(key); 25.152 - return isMapped(index) ? namedArgs.getObject(index) : super.get(key); 25.153 - } 25.154 - 25.155 - @Override 25.156 - public Object get(final long key) { 25.157 - final int index = ArrayIndex.getArrayIndex(key); 25.158 - return isMapped(index) ? namedArgs.getObject(index) : super.get(key); 25.159 - } 25.160 - 25.161 - @Override 25.162 - public Object get(final int key) { 25.163 - final int index = ArrayIndex.getArrayIndex(key); 25.164 - return isMapped(index) ? namedArgs.getObject(index) : super.get(key); 25.165 - } 25.166 - 25.167 - @Override 25.168 - public void set(final Object key, final int value, final boolean strict) { 25.169 - final int index = ArrayIndex.getArrayIndex(key); 25.170 - if (isMapped(index)) { 25.171 - namedArgs = namedArgs.set(index, value, strict); 25.172 - } else { 25.173 - super.set(key, value, strict); 25.174 - } 25.175 - } 25.176 - 25.177 - @Override 25.178 - public void set(final Object key, final long value, final boolean strict) { 25.179 - final int index = ArrayIndex.getArrayIndex(key); 25.180 - if (isMapped(index)) { 25.181 - namedArgs = namedArgs.set(index, value, strict); 25.182 - } else { 25.183 - super.set(key, value, strict); 25.184 - } 25.185 - } 25.186 - 25.187 - @Override 25.188 - public void set(final Object key, final double value, final boolean strict) { 25.189 - final int index = ArrayIndex.getArrayIndex(key); 25.190 - if (isMapped(index)) { 25.191 - namedArgs = namedArgs.set(index, value, strict); 25.192 - } else { 25.193 - super.set(key, value, strict); 25.194 - } 25.195 - } 25.196 - 25.197 - @Override 25.198 - public void set(final Object key, final Object value, final boolean strict) { 25.199 - final int index = ArrayIndex.getArrayIndex(key); 25.200 - if (isMapped(index)) { 25.201 - namedArgs = namedArgs.set(index, value, strict); 25.202 - } else { 25.203 - super.set(key, value, strict); 25.204 - } 25.205 - } 25.206 - 25.207 - @Override 25.208 - public void set(final double key, final int value, final boolean strict) { 25.209 - final int index = ArrayIndex.getArrayIndex(key); 25.210 - if (isMapped(index)) { 25.211 - namedArgs = namedArgs.set(index, value, strict); 25.212 - } else { 25.213 - super.set(key, value, strict); 25.214 - } 25.215 - } 25.216 - 25.217 - @Override 25.218 - public void set(final double key, final long value, final boolean strict) { 25.219 - final int index = ArrayIndex.getArrayIndex(key); 25.220 - if (isMapped(index)) { 25.221 - namedArgs = namedArgs.set(index, value, strict); 25.222 - } else { 25.223 - super.set(key, value, strict); 25.224 - } 25.225 - } 25.226 - 25.227 - @Override 25.228 - public void set(final double key, final double value, final boolean strict) { 25.229 - final int index = ArrayIndex.getArrayIndex(key); 25.230 - if (isMapped(index)) { 25.231 - namedArgs = namedArgs.set(index, value, strict); 25.232 - } else { 25.233 - super.set(key, value, strict); 25.234 - } 25.235 - } 25.236 - 25.237 - @Override 25.238 - public void set(final double key, final Object value, final boolean strict) { 25.239 - final int index = ArrayIndex.getArrayIndex(key); 25.240 - if (isMapped(index)) { 25.241 - namedArgs = namedArgs.set(index, value, strict); 25.242 - } else { 25.243 - super.set(key, value, strict); 25.244 - } 25.245 - } 25.246 - 25.247 - @Override 25.248 - public void set(final long key, final int value, final boolean strict) { 25.249 - final int index = ArrayIndex.getArrayIndex(key); 25.250 - if (isMapped(index)) { 25.251 - namedArgs = namedArgs.set(index, value, strict); 25.252 - } else { 25.253 - super.set(key, value, strict); 25.254 - } 25.255 - } 25.256 - 25.257 - @Override 25.258 - public void set(final long key, final long value, final boolean strict) { 25.259 - final int index = ArrayIndex.getArrayIndex(key); 25.260 - if (isMapped(index)) { 25.261 - namedArgs = namedArgs.set(index, value, strict); 25.262 - } else { 25.263 - super.set(key, value, strict); 25.264 - } 25.265 - } 25.266 - 25.267 - @Override 25.268 - public void set(final long key, final double value, final boolean strict) { 25.269 - final int index = ArrayIndex.getArrayIndex(key); 25.270 - if (isMapped(index)) { 25.271 - namedArgs = namedArgs.set(index, value, strict); 25.272 - } else { 25.273 - super.set(key, value, strict); 25.274 - } 25.275 - } 25.276 - 25.277 - @Override 25.278 - public void set(final long key, final Object value, final boolean strict) { 25.279 - final int index = ArrayIndex.getArrayIndex(key); 25.280 - if (isMapped(index)) { 25.281 - namedArgs = namedArgs.set(index, value, strict); 25.282 - } else { 25.283 - super.set(key, value, strict); 25.284 - } 25.285 - } 25.286 - 25.287 - @Override 25.288 - public void set(final int key, final int value, final boolean strict) { 25.289 - final int index = ArrayIndex.getArrayIndex(key); 25.290 - if (isMapped(index)) { 25.291 - namedArgs = namedArgs.set(index, value, strict); 25.292 - } else { 25.293 - super.set(key, value, strict); 25.294 - } 25.295 - } 25.296 - 25.297 - @Override 25.298 - public void set(final int key, final long value, final boolean strict) { 25.299 - final int index = ArrayIndex.getArrayIndex(key); 25.300 - if (isMapped(index)) { 25.301 - namedArgs = namedArgs.set(index, value, strict); 25.302 - } else { 25.303 - super.set(key, value, strict); 25.304 - } 25.305 - } 25.306 - 25.307 - @Override 25.308 - public void set(final int key, final double value, final boolean strict) { 25.309 - final int index = ArrayIndex.getArrayIndex(key); 25.310 - if (isMapped(index)) { 25.311 - namedArgs = namedArgs.set(index, value, strict); 25.312 - } else { 25.313 - super.set(key, value, strict); 25.314 - } 25.315 - } 25.316 - 25.317 - @Override 25.318 - public void set(final int key, final Object value, final boolean strict) { 25.319 - final int index = ArrayIndex.getArrayIndex(key); 25.320 - if (isMapped(index)) { 25.321 - namedArgs = namedArgs.set(index, value, strict); 25.322 - } else { 25.323 - super.set(key, value, strict); 25.324 - } 25.325 - } 25.326 - 25.327 - @Override 25.328 - public boolean has(final Object key) { 25.329 - final int index = ArrayIndex.getArrayIndex(key); 25.330 - return isMapped(index) || super.has(key); 25.331 - } 25.332 - 25.333 - @Override 25.334 - public boolean has(final double key) { 25.335 - final int index = ArrayIndex.getArrayIndex(key); 25.336 - return isMapped(index) || super.has(key); 25.337 - } 25.338 - 25.339 - @Override 25.340 - public boolean has(final long key) { 25.341 - final int index = ArrayIndex.getArrayIndex(key); 25.342 - return isMapped(index) || super.has(key); 25.343 - } 25.344 - 25.345 - @Override 25.346 - public boolean has(final int key) { 25.347 - final int index = ArrayIndex.getArrayIndex(key); 25.348 - return isMapped(index) || super.has(key); 25.349 - } 25.350 - 25.351 - @Override 25.352 - public boolean hasOwnProperty(final Object key) { 25.353 - final int index = ArrayIndex.getArrayIndex(key); 25.354 - return isMapped(index) || super.hasOwnProperty(key); 25.355 - } 25.356 - 25.357 - @Override 25.358 - public boolean hasOwnProperty(final int key) { 25.359 - final int index = ArrayIndex.getArrayIndex(key); 25.360 - return isMapped(index) || super.hasOwnProperty(key); 25.361 - } 25.362 - 25.363 - @Override 25.364 - public boolean hasOwnProperty(final long key) { 25.365 - final int index = ArrayIndex.getArrayIndex(key); 25.366 - return isMapped(index) || super.hasOwnProperty(key); 25.367 - } 25.368 - 25.369 - @Override 25.370 - public boolean hasOwnProperty(final double key) { 25.371 - final int index = ArrayIndex.getArrayIndex(key); 25.372 - return isMapped(index) || super.hasOwnProperty(key); 25.373 - } 25.374 - 25.375 - @Override 25.376 public boolean delete(final int key, final boolean strict) { 25.377 final int index = ArrayIndex.getArrayIndex(key); 25.378 - final boolean success = super.delete(key, strict); 25.379 - if (success && namedArgs.has(index)) { 25.380 - setDeleted(index); 25.381 - } 25.382 - return success; 25.383 + return isMapped(index) ? deleteMapped(index, strict) : super.delete(key, strict); 25.384 } 25.385 25.386 @Override 25.387 public boolean delete(final long key, final boolean strict) { 25.388 final int index = ArrayIndex.getArrayIndex(key); 25.389 - final boolean success = super.delete(key, strict); 25.390 - if (success && namedArgs.has(index)) { 25.391 - setDeleted(index); 25.392 - } 25.393 - return success; 25.394 + return isMapped(index) ? deleteMapped(index, strict) : super.delete(key, strict); 25.395 } 25.396 25.397 @Override 25.398 public boolean delete(final double key, final boolean strict) { 25.399 final int index = ArrayIndex.getArrayIndex(key); 25.400 - final boolean success = super.delete(key, strict); 25.401 - if (success && namedArgs.has(index)) { 25.402 - setDeleted(index); 25.403 - } 25.404 - return success; 25.405 + return isMapped(index) ? deleteMapped(index, strict) : super.delete(key, strict); 25.406 } 25.407 25.408 @Override 25.409 public boolean delete(final Object key, final boolean strict) { 25.410 final int index = ArrayIndex.getArrayIndex(key); 25.411 - final boolean success = super.delete(key, strict); 25.412 - if (success && namedArgs.has(index)) { 25.413 - setDeleted(index); 25.414 - } 25.415 - return success; 25.416 + return isMapped(index) ? deleteMapped(index, strict) : super.delete(key, strict); 25.417 } 25.418 25.419 /** 25.420 @@ -483,29 +152,27 @@ 25.421 public boolean defineOwnProperty(final String key, final Object propertyDesc, final boolean reject) { 25.422 final int index = ArrayIndex.getArrayIndex(key); 25.423 if (index >= 0) { 25.424 - final boolean allowed = super.defineOwnProperty(key, propertyDesc, false); 25.425 - if (!allowed) { 25.426 + final boolean isMapped = isMapped(index); 25.427 + final Object oldValue = isMapped ? getArray().getObject(index) : null; 25.428 + 25.429 + if (!super.defineOwnProperty(key, propertyDesc, false)) { 25.430 if (reject) { 25.431 throw typeError("cant.redefine.property", key, ScriptRuntime.safeToString(this)); 25.432 } 25.433 return false; 25.434 } 25.435 25.436 - if (isMapped(index)) { 25.437 + if (isMapped) { 25.438 // When mapped argument is redefined, if new descriptor is accessor property 25.439 // or data-non-writable property, we have to "unmap" (unlink). 25.440 final PropertyDescriptor desc = toPropertyDescriptor(Global.instance(), propertyDesc); 25.441 if (desc.type() == PropertyDescriptor.ACCESSOR) { 25.442 - setDeleted(index); 25.443 - } else { 25.444 - // set "value" from new descriptor to named args 25.445 - if (desc.has(PropertyDescriptor.VALUE)) { 25.446 - namedArgs = namedArgs.set(index, desc.getValue(), false); 25.447 - } 25.448 - 25.449 - if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) { 25.450 - setDeleted(index); 25.451 - } 25.452 + setDeleted(index, oldValue); 25.453 + } else if (desc.has(PropertyDescriptor.WRITABLE) && !desc.isWritable()) { 25.454 + // delete and set value from new descriptor if it has one, otherwise use old value 25.455 + setDeleted(index, desc.has(PropertyDescriptor.VALUE) ? desc.getValue() : oldValue); 25.456 + } else if (desc.has(PropertyDescriptor.VALUE)) { 25.457 + setArray(getArray().set(index, desc.getValue(), false)); 25.458 } 25.459 } 25.460 25.461 @@ -519,31 +186,72 @@ 25.462 25.463 // We track deletions using a bit set (delete arguments[index]) 25.464 private boolean isDeleted(final int index) { 25.465 - return (deleted != null) ? deleted.get(index) : false; 25.466 + return deleted != null && deleted.get(index); 25.467 } 25.468 25.469 - private void setDeleted(final int index) { 25.470 + private void setDeleted(final int index, final Object unmappedValue) { 25.471 if (deleted == null) { 25.472 - deleted = new BitSet((int)namedArgs.length()); 25.473 + deleted = new BitSet(numMapped); 25.474 } 25.475 deleted.set(index, true); 25.476 + setUnmappedArg(index, unmappedValue); 25.477 + } 25.478 + 25.479 + private boolean deleteMapped(final int index, final boolean strict) { 25.480 + final Object value = getArray().getObject(index); 25.481 + final boolean success = super.delete(index, strict); 25.482 + if (success) { 25.483 + setDeleted(index, value); 25.484 + } 25.485 + return success; 25.486 + } 25.487 + 25.488 + private Object getUnmappedArg(final int key) { 25.489 + assert key >= 0 && key < numParams; 25.490 + return unmappedArgs == null ? UNDEFINED : unmappedArgs.getObject(key); 25.491 + } 25.492 + 25.493 + private void setUnmappedArg(final int key, final Object value) { 25.494 + assert key >= 0 && key < numParams; 25.495 + if (unmappedArgs == null) { 25.496 + /* 25.497 + * Declared number of parameters may be more or less than the actual passed 25.498 + * runtime arguments count. We need to truncate or extend with undefined values. 25.499 + * 25.500 + * Example: 25.501 + * 25.502 + * // less declared params 25.503 + * (function (x) { print(arguments); })(20, 44); 25.504 + * 25.505 + * // more declared params 25.506 + * (function (x, y) { print(arguments); })(3); 25.507 + */ 25.508 + final Object[] newValues = new Object[numParams]; 25.509 + System.arraycopy(getArray().asObjectArray(), 0, newValues, 0, numMapped); 25.510 + if (numMapped < numParams) { 25.511 + Arrays.fill(newValues, numMapped, numParams, UNDEFINED); 25.512 + } 25.513 + this.unmappedArgs = ArrayData.allocate(newValues); 25.514 + } 25.515 + // Set value of argument 25.516 + unmappedArgs = unmappedArgs.set(key, value, false); 25.517 } 25.518 25.519 /** 25.520 * Are arguments[index] and corresponding named parameter linked? 25.521 * 25.522 - * In non-strict mode, arguments[index] and corresponding named param 25.523 - * are "linked" or "mapped". Modifications are tacked b/w each other - till 25.524 - * (delete arguments[index]) is used. Once deleted, the corresponding arg 25.525 - * is no longer 'mapped'. Please note that delete can happen only through 25.526 - * the arguments array - named param can not be deleted. (delete is one-way). 25.527 + * In non-strict mode, arguments[index] and corresponding named param are "linked" or "mapped" 25.528 + * if the argument is provided by the caller. Modifications are tacked b/w each other - until 25.529 + * (delete arguments[index]) is used. Once deleted, the corresponding arg is no longer 'mapped'. 25.530 + * Please note that delete can happen only through the arguments array - named param can not 25.531 + * be deleted. (delete is one-way). 25.532 */ 25.533 private boolean isMapped(final int index) { 25.534 - // in named args and not marked as "deleted" 25.535 - return namedArgs.has(index) && !isDeleted(index); 25.536 + // in mapped named args and not marked as "deleted" 25.537 + return index >= 0 && index < numMapped && !isDeleted(index); 25.538 } 25.539 25.540 - /** 25.541 + /** 25.542 * Factory to create correct Arguments object based on strict mode. 25.543 * 25.544 * @param arguments the actual arguments array passed 25.545 @@ -558,9 +266,8 @@ 25.546 final ScriptObject proto = global.getObjectPrototype(); 25.547 if (isStrict) { 25.548 return new NativeStrictArguments(arguments, numParams, proto, global.getStrictArgumentsMap()); 25.549 - } else { 25.550 - return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); 25.551 } 25.552 + return new NativeArguments(arguments, callee, numParams, proto, global.getArgumentsMap()); 25.553 } 25.554 25.555 /**
26.1 --- a/src/jdk/nashorn/internal/objects/NativeArray.java Thu Aug 15 09:26:02 2013 -0700 26.2 +++ b/src/jdk/nashorn/internal/objects/NativeArray.java Tue Aug 20 17:46:45 2013 -0700 26.3 @@ -39,6 +39,7 @@ 26.4 import java.util.Comparator; 26.5 import java.util.Iterator; 26.6 import java.util.List; 26.7 +import java.util.concurrent.Callable; 26.8 import jdk.nashorn.api.scripting.ScriptObjectMirror; 26.9 import jdk.nashorn.internal.objects.annotations.Attribute; 26.10 import jdk.nashorn.internal.objects.annotations.Constructor; 26.11 @@ -68,20 +69,88 @@ 26.12 */ 26.13 @ScriptClass("Array") 26.14 public final class NativeArray extends ScriptObject { 26.15 - private static final InvokeByName JOIN = new InvokeByName("join", ScriptObject.class); 26.16 + private static final Object JOIN = new Object(); 26.17 + private static final Object EVERY_CALLBACK_INVOKER = new Object(); 26.18 + private static final Object SOME_CALLBACK_INVOKER = new Object(); 26.19 + private static final Object FOREACH_CALLBACK_INVOKER = new Object(); 26.20 + private static final Object MAP_CALLBACK_INVOKER = new Object(); 26.21 + private static final Object FILTER_CALLBACK_INVOKER = new Object(); 26.22 + private static final Object REDUCE_CALLBACK_INVOKER = new Object(); 26.23 + private static final Object CALL_CMP = new Object(); 26.24 + private static final Object TO_LOCALE_STRING = new Object(); 26.25 26.26 - private static final MethodHandle EVERY_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 26.27 - private static final MethodHandle SOME_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 26.28 - private static final MethodHandle FOREACH_CALLBACK_INVOKER = createIteratorCallbackInvoker(void.class); 26.29 - private static final MethodHandle MAP_CALLBACK_INVOKER = createIteratorCallbackInvoker(Object.class); 26.30 - private static final MethodHandle FILTER_CALLBACK_INVOKER = createIteratorCallbackInvoker(boolean.class); 26.31 + private static InvokeByName getJOIN() { 26.32 + return Global.instance().getInvokeByName(JOIN, 26.33 + new Callable<InvokeByName>() { 26.34 + @Override 26.35 + public InvokeByName call() { 26.36 + return new InvokeByName("join", ScriptObject.class); 26.37 + } 26.38 + }); 26.39 + } 26.40 26.41 - private static final MethodHandle REDUCE_CALLBACK_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 26.42 - Object.class, Undefined.class, Object.class, Object.class, long.class, Object.class); 26.43 - private static final MethodHandle CALL_CMP = Bootstrap.createDynamicInvoker("dyn:call", double.class, 26.44 - ScriptFunction.class, Object.class, Object.class, Object.class); 26.45 + private static MethodHandle createIteratorCallbackInvoker(final Object key, final Class<?> rtype) { 26.46 + return Global.instance().getDynamicInvoker(key, 26.47 + new Callable<MethodHandle>() { 26.48 + @Override 26.49 + public MethodHandle call() { 26.50 + return Bootstrap.createDynamicInvoker("dyn:call", rtype, Object.class, Object.class, Object.class, 26.51 + long.class, Object.class); 26.52 + } 26.53 + }); 26.54 + } 26.55 26.56 - private static final InvokeByName TO_LOCALE_STRING = new InvokeByName("toLocaleString", ScriptObject.class, String.class); 26.57 + private static MethodHandle getEVERY_CALLBACK_INVOKER() { 26.58 + return createIteratorCallbackInvoker(EVERY_CALLBACK_INVOKER, boolean.class); 26.59 + } 26.60 + 26.61 + private static MethodHandle getSOME_CALLBACK_INVOKER() { 26.62 + return createIteratorCallbackInvoker(SOME_CALLBACK_INVOKER, boolean.class); 26.63 + } 26.64 + 26.65 + private static MethodHandle getFOREACH_CALLBACK_INVOKER() { 26.66 + return createIteratorCallbackInvoker(FOREACH_CALLBACK_INVOKER, void.class); 26.67 + } 26.68 + 26.69 + private static MethodHandle getMAP_CALLBACK_INVOKER() { 26.70 + return createIteratorCallbackInvoker(MAP_CALLBACK_INVOKER, Object.class); 26.71 + } 26.72 + 26.73 + private static MethodHandle getFILTER_CALLBACK_INVOKER() { 26.74 + return createIteratorCallbackInvoker(FILTER_CALLBACK_INVOKER, boolean.class); 26.75 + } 26.76 + 26.77 + private static MethodHandle getREDUCE_CALLBACK_INVOKER() { 26.78 + return Global.instance().getDynamicInvoker(REDUCE_CALLBACK_INVOKER, 26.79 + new Callable<MethodHandle>() { 26.80 + @Override 26.81 + public MethodHandle call() { 26.82 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, Object.class, 26.83 + Undefined.class, Object.class, Object.class, long.class, Object.class); 26.84 + } 26.85 + }); 26.86 + } 26.87 + 26.88 + private static MethodHandle getCALL_CMP() { 26.89 + return Global.instance().getDynamicInvoker(CALL_CMP, 26.90 + new Callable<MethodHandle>() { 26.91 + @Override 26.92 + public MethodHandle call() { 26.93 + return Bootstrap.createDynamicInvoker("dyn:call", double.class, 26.94 + ScriptFunction.class, Object.class, Object.class, Object.class); 26.95 + } 26.96 + }); 26.97 + } 26.98 + 26.99 + private static InvokeByName getTO_LOCALE_STRING() { 26.100 + return Global.instance().getInvokeByName(TO_LOCALE_STRING, 26.101 + new Callable<InvokeByName>() { 26.102 + @Override 26.103 + public InvokeByName call() { 26.104 + return new InvokeByName("toLocaleString", ScriptObject.class, String.class); 26.105 + } 26.106 + }); 26.107 + } 26.108 26.109 // initialized by nasgen 26.110 private static PropertyMap $nasgenmap$; 26.111 @@ -357,11 +426,12 @@ 26.112 public static Object toString(final Object self) { 26.113 final Object obj = Global.toObject(self); 26.114 if (obj instanceof ScriptObject) { 26.115 + final InvokeByName joinInvoker = getJOIN(); 26.116 final ScriptObject sobj = (ScriptObject)obj; 26.117 try { 26.118 - final Object join = JOIN.getGetter().invokeExact(sobj); 26.119 + final Object join = joinInvoker.getGetter().invokeExact(sobj); 26.120 if (Bootstrap.isCallable(join)) { 26.121 - return JOIN.getInvoker().invokeExact(join, sobj); 26.122 + return joinInvoker.getInvoker().invokeExact(join, sobj); 26.123 } 26.124 } catch (final RuntimeException | Error e) { 26.125 throw e; 26.126 @@ -393,11 +463,12 @@ 26.127 26.128 try { 26.129 if (val instanceof ScriptObject) { 26.130 + final InvokeByName localeInvoker = getTO_LOCALE_STRING(); 26.131 final ScriptObject sobj = (ScriptObject)val; 26.132 - final Object toLocaleString = TO_LOCALE_STRING.getGetter().invokeExact(sobj); 26.133 + final Object toLocaleString = localeInvoker.getGetter().invokeExact(sobj); 26.134 26.135 if (Bootstrap.isCallable(toLocaleString)) { 26.136 - sb.append((String)TO_LOCALE_STRING.getInvoker().invokeExact(toLocaleString, sobj)); 26.137 + sb.append((String)localeInvoker.getInvoker().invokeExact(toLocaleString, sobj)); 26.138 } else { 26.139 throw typeError("not.a.function", "toLocaleString"); 26.140 } 26.141 @@ -567,9 +638,9 @@ 26.142 if (isScriptArray || obj instanceof Iterable || (obj != null && obj.getClass().isArray())) { 26.143 final Iterator<Object> iter = arrayLikeIterator(obj, true); 26.144 if (iter.hasNext()) { 26.145 - for(int i = 0; iter.hasNext(); ++i) { 26.146 + for (int i = 0; iter.hasNext(); ++i) { 26.147 final Object value = iter.next(); 26.148 - if(value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { 26.149 + if (value == ScriptRuntime.UNDEFINED && isScriptObject && !((ScriptObject)obj).has(i)) { 26.150 // TODO: eventually rewrite arrayLikeIterator to use a three-state enum for handling 26.151 // UNDEFINED instead of an "includeUndefined" boolean with states SKIP, INCLUDE, 26.152 // RETURN_EMPTY. Until then, this is how we'll make sure that empty elements don't make it 26.153 @@ -814,6 +885,7 @@ 26.154 final Object cmpThis = cmp == null || cmp.isStrict() ? ScriptRuntime.UNDEFINED : Global.instance(); 26.155 26.156 Collections.sort(list, new Comparator<Object>() { 26.157 + private final MethodHandle call_cmp = getCALL_CMP(); 26.158 @Override 26.159 public int compare(final Object x, final Object y) { 26.160 if (x == ScriptRuntime.UNDEFINED && y == ScriptRuntime.UNDEFINED) { 26.161 @@ -826,7 +898,7 @@ 26.162 26.163 if (cmp != null) { 26.164 try { 26.165 - return (int)Math.signum((double)CALL_CMP.invokeExact(cmp, cmpThis, x, y)); 26.166 + return (int)Math.signum((double)call_cmp.invokeExact(cmp, cmpThis, x, y)); 26.167 } catch (final RuntimeException | Error e) { 26.168 throw e; 26.169 } catch (final Throwable t) { 26.170 @@ -1103,9 +1175,11 @@ 26.171 26.172 private static boolean applyEvery(final Object self, final Object callbackfn, final Object thisArg) { 26.173 return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, true) { 26.174 + private final MethodHandle everyInvoker = getEVERY_CALLBACK_INVOKER(); 26.175 + 26.176 @Override 26.177 protected boolean forEach(final Object val, final long i) throws Throwable { 26.178 - return (result = (boolean)EVERY_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)); 26.179 + return (result = (boolean)everyInvoker.invokeExact(callbackfn, thisArg, val, i, self)); 26.180 } 26.181 }.apply(); 26.182 } 26.183 @@ -1121,9 +1195,11 @@ 26.184 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 26.185 public static Object some(final Object self, final Object callbackfn, final Object thisArg) { 26.186 return new IteratorAction<Boolean>(Global.toObject(self), callbackfn, thisArg, false) { 26.187 + private final MethodHandle someInvoker = getSOME_CALLBACK_INVOKER(); 26.188 + 26.189 @Override 26.190 protected boolean forEach(final Object val, final long i) throws Throwable { 26.191 - return !(result = (boolean)SOME_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)); 26.192 + return !(result = (boolean)someInvoker.invokeExact(callbackfn, thisArg, val, i, self)); 26.193 } 26.194 }.apply(); 26.195 } 26.196 @@ -1139,9 +1215,11 @@ 26.197 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 26.198 public static Object forEach(final Object self, final Object callbackfn, final Object thisArg) { 26.199 return new IteratorAction<Object>(Global.toObject(self), callbackfn, thisArg, ScriptRuntime.UNDEFINED) { 26.200 + private final MethodHandle forEachInvoker = getFOREACH_CALLBACK_INVOKER(); 26.201 + 26.202 @Override 26.203 protected boolean forEach(final Object val, final long i) throws Throwable { 26.204 - FOREACH_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self); 26.205 + forEachInvoker.invokeExact(callbackfn, thisArg, val, i, self); 26.206 return true; 26.207 } 26.208 }.apply(); 26.209 @@ -1158,9 +1236,11 @@ 26.210 @Function(attributes = Attribute.NOT_ENUMERABLE, arity = 1) 26.211 public static Object map(final Object self, final Object callbackfn, final Object thisArg) { 26.212 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, null) { 26.213 + private final MethodHandle mapInvoker = getMAP_CALLBACK_INVOKER(); 26.214 + 26.215 @Override 26.216 protected boolean forEach(final Object val, final long i) throws Throwable { 26.217 - final Object r = MAP_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self); 26.218 + final Object r = mapInvoker.invokeExact(callbackfn, thisArg, val, i, self); 26.219 result.defineOwnProperty(ArrayIndex.getArrayIndex(index), r); 26.220 return true; 26.221 } 26.222 @@ -1186,10 +1266,11 @@ 26.223 public static Object filter(final Object self, final Object callbackfn, final Object thisArg) { 26.224 return new IteratorAction<NativeArray>(Global.toObject(self), callbackfn, thisArg, new NativeArray()) { 26.225 private long to = 0; 26.226 + private final MethodHandle filterInvoker = getFILTER_CALLBACK_INVOKER(); 26.227 26.228 @Override 26.229 protected boolean forEach(final Object val, final long i) throws Throwable { 26.230 - if ((boolean)FILTER_CALLBACK_INVOKER.invokeExact(callbackfn, thisArg, val, i, self)) { 26.231 + if ((boolean)filterInvoker.invokeExact(callbackfn, thisArg, val, i, self)) { 26.232 result.defineOwnProperty(ArrayIndex.getArrayIndex(to++), val); 26.233 } 26.234 return true; 26.235 @@ -1217,10 +1298,12 @@ 26.236 26.237 //if initial value is ScriptRuntime.UNDEFINED - step forward once. 26.238 return new IteratorAction<Object>(Global.toObject(self), callbackfn, ScriptRuntime.UNDEFINED, initialValue, iter) { 26.239 + private final MethodHandle reduceInvoker = getREDUCE_CALLBACK_INVOKER(); 26.240 + 26.241 @Override 26.242 protected boolean forEach(final Object val, final long i) throws Throwable { 26.243 // TODO: why can't I declare the second arg as Undefined.class? 26.244 - result = REDUCE_CALLBACK_INVOKER.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self); 26.245 + result = reduceInvoker.invokeExact(callbackfn, ScriptRuntime.UNDEFINED, result, val, i, self); 26.246 return true; 26.247 } 26.248 }.apply(); 26.249 @@ -1273,10 +1356,4 @@ 26.250 26.251 return false; 26.252 } 26.253 - 26.254 - private static MethodHandle createIteratorCallbackInvoker(final Class<?> rtype) { 26.255 - return Bootstrap.createDynamicInvoker("dyn:call", rtype, Object.class, Object.class, Object.class, 26.256 - long.class, Object.class); 26.257 - 26.258 - } 26.259 }
27.1 --- a/src/jdk/nashorn/internal/objects/NativeDate.java Thu Aug 15 09:26:02 2013 -0700 27.2 +++ b/src/jdk/nashorn/internal/objects/NativeDate.java Tue Aug 20 17:46:45 2013 -0700 27.3 @@ -33,6 +33,7 @@ 27.4 27.5 import java.util.Locale; 27.6 import java.util.TimeZone; 27.7 +import java.util.concurrent.Callable; 27.8 import jdk.nashorn.internal.objects.annotations.Attribute; 27.9 import jdk.nashorn.internal.objects.annotations.Constructor; 27.10 import jdk.nashorn.internal.objects.annotations.Function; 27.11 @@ -95,8 +96,17 @@ 27.12 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" 27.13 }; 27.14 27.15 - private static final InvokeByName TO_ISO_STRING = new InvokeByName("toISOString", ScriptObject.class, Object.class, 27.16 - Object.class); 27.17 + private static final Object TO_ISO_STRING = new Object(); 27.18 + 27.19 + private static InvokeByName getTO_ISO_STRING() { 27.20 + return Global.instance().getInvokeByName(TO_ISO_STRING, 27.21 + new Callable<InvokeByName>() { 27.22 + @Override 27.23 + public InvokeByName call() { 27.24 + return new InvokeByName("toISOString", ScriptObject.class, Object.class, Object.class); 27.25 + } 27.26 + }); 27.27 + } 27.28 27.29 private double time; 27.30 private final TimeZone timezone; 27.31 @@ -861,9 +871,10 @@ 27.32 } 27.33 27.34 try { 27.35 - final Object func = TO_ISO_STRING.getGetter().invokeExact(sobj); 27.36 + final InvokeByName toIsoString = getTO_ISO_STRING(); 27.37 + final Object func = toIsoString.getGetter().invokeExact(sobj); 27.38 if (Bootstrap.isCallable(func)) { 27.39 - return TO_ISO_STRING.getInvoker().invokeExact(func, sobj, key); 27.40 + return toIsoString.getInvoker().invokeExact(func, sobj, key); 27.41 } 27.42 throw typeError("not.a.function", ScriptRuntime.safeToString(func)); 27.43 } catch (final RuntimeException | Error e) {
28.1 --- a/src/jdk/nashorn/internal/objects/NativeDebug.java Thu Aug 15 09:26:02 2013 -0700 28.2 +++ b/src/jdk/nashorn/internal/objects/NativeDebug.java Tue Aug 20 17:46:45 2013 -0700 28.3 @@ -72,7 +72,7 @@ 28.4 public static Object getContext(final Object self) { 28.5 final SecurityManager sm = System.getSecurityManager(); 28.6 if (sm != null) { 28.7 - sm.checkPermission(new RuntimePermission("nashorn.getContext")); 28.8 + sm.checkPermission(new RuntimePermission(Context.NASHORN_GET_CONTEXT)); 28.9 } 28.10 return Global.getThisContext(); 28.11 }
29.1 --- a/src/jdk/nashorn/internal/objects/NativeJSON.java Thu Aug 15 09:26:02 2013 -0700 29.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSON.java Tue Aug 20 17:46:45 2013 -0700 29.3 @@ -35,6 +35,7 @@ 29.4 import java.util.Iterator; 29.5 import java.util.List; 29.6 import java.util.Map; 29.7 +import java.util.concurrent.Callable; 29.8 import jdk.nashorn.internal.objects.annotations.Attribute; 29.9 import jdk.nashorn.internal.objects.annotations.Function; 29.10 import jdk.nashorn.internal.objects.annotations.ScriptClass; 29.11 @@ -55,9 +56,31 @@ 29.12 */ 29.13 @ScriptClass("JSON") 29.14 public final class NativeJSON extends ScriptObject { 29.15 - private static final InvokeByName TO_JSON = new InvokeByName("toJSON", ScriptObject.class, Object.class, Object.class); 29.16 - private static final MethodHandle REPLACER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 29.17 - ScriptFunction.class, ScriptObject.class, Object.class, Object.class); 29.18 + private static final Object TO_JSON = new Object(); 29.19 + 29.20 + private static InvokeByName getTO_JSON() { 29.21 + return Global.instance().getInvokeByName(TO_JSON, 29.22 + new Callable<InvokeByName>() { 29.23 + @Override 29.24 + public InvokeByName call() { 29.25 + return new InvokeByName("toJSON", ScriptObject.class, Object.class, Object.class); 29.26 + } 29.27 + }); 29.28 + } 29.29 + 29.30 + 29.31 + private static final Object REPLACER_INVOKER = new Object(); 29.32 + 29.33 + private static MethodHandle getREPLACER_INVOKER() { 29.34 + return Global.instance().getDynamicInvoker(REPLACER_INVOKER, 29.35 + new Callable<MethodHandle>() { 29.36 + @Override 29.37 + public MethodHandle call() { 29.38 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 29.39 + ScriptFunction.class, ScriptObject.class, Object.class, Object.class); 29.40 + } 29.41 + }); 29.42 + } 29.43 29.44 // initialized by nasgen 29.45 @SuppressWarnings("unused") 29.46 @@ -187,15 +210,16 @@ 29.47 29.48 try { 29.49 if (value instanceof ScriptObject) { 29.50 + final InvokeByName toJSONInvoker = getTO_JSON(); 29.51 final ScriptObject svalue = (ScriptObject)value; 29.52 - final Object toJSON = TO_JSON.getGetter().invokeExact(svalue); 29.53 + final Object toJSON = toJSONInvoker.getGetter().invokeExact(svalue); 29.54 if (Bootstrap.isCallable(toJSON)) { 29.55 - value = TO_JSON.getInvoker().invokeExact(toJSON, svalue, key); 29.56 + value = toJSONInvoker.getInvoker().invokeExact(toJSON, svalue, key); 29.57 } 29.58 } 29.59 29.60 if (state.replacerFunction != null) { 29.61 - value = REPLACER_INVOKER.invokeExact(state.replacerFunction, holder, key, value); 29.62 + value = getREPLACER_INVOKER().invokeExact(state.replacerFunction, holder, key, value); 29.63 } 29.64 } catch(Error|RuntimeException t) { 29.65 throw t;
30.1 --- a/src/jdk/nashorn/internal/objects/NativeObject.java Thu Aug 15 09:26:02 2013 -0700 30.2 +++ b/src/jdk/nashorn/internal/objects/NativeObject.java Tue Aug 20 17:46:45 2013 -0700 30.3 @@ -36,6 +36,7 @@ 30.4 import java.util.HashSet; 30.5 import java.util.List; 30.6 import java.util.Set; 30.7 +import java.util.concurrent.Callable; 30.8 import jdk.internal.dynalink.beans.BeansLinker; 30.9 import jdk.internal.dynalink.beans.StaticClass; 30.10 import jdk.internal.dynalink.linker.GuardedInvocation; 30.11 @@ -70,7 +71,18 @@ 30.12 */ 30.13 @ScriptClass("Object") 30.14 public final class NativeObject { 30.15 - private static final InvokeByName TO_STRING = new InvokeByName("toString", ScriptObject.class); 30.16 + private static final Object TO_STRING = new Object(); 30.17 + 30.18 + private static InvokeByName getTO_STRING() { 30.19 + return Global.instance().getInvokeByName(TO_STRING, 30.20 + new Callable<InvokeByName>() { 30.21 + @Override 30.22 + public InvokeByName call() { 30.23 + return new InvokeByName("toString", ScriptObject.class); 30.24 + } 30.25 + }); 30.26 + } 30.27 + 30.28 private static final MethodType MIRROR_GETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class); 30.29 private static final MethodType MIRROR_SETTER_TYPE = MethodType.methodType(Object.class, ScriptObjectMirror.class, Object.class); 30.30 30.31 @@ -101,6 +113,13 @@ 30.32 } else if (obj instanceof ScriptObjectMirror) { 30.33 return ((ScriptObjectMirror)obj).getProto(); 30.34 } else { 30.35 + final JSType type = JSType.of(obj); 30.36 + if (type == JSType.OBJECT) { 30.37 + // host (Java) objects have null __proto__ 30.38 + return null; 30.39 + } 30.40 + 30.41 + // must be some JS primitive 30.42 throw notAnObject(obj); 30.43 } 30.44 } 30.45 @@ -402,12 +421,13 @@ 30.46 public static Object toLocaleString(final Object self) { 30.47 final Object obj = JSType.toScriptObject(self); 30.48 if (obj instanceof ScriptObject) { 30.49 + final InvokeByName toStringInvoker = getTO_STRING(); 30.50 final ScriptObject sobj = (ScriptObject)self; 30.51 try { 30.52 - final Object toString = TO_STRING.getGetter().invokeExact(sobj); 30.53 + final Object toString = toStringInvoker.getGetter().invokeExact(sobj); 30.54 30.55 if (Bootstrap.isCallable(toString)) { 30.56 - return TO_STRING.getInvoker().invokeExact(toString, sobj); 30.57 + return toStringInvoker.getInvoker().invokeExact(toString, sobj); 30.58 } 30.59 } catch (final RuntimeException | Error e) { 30.60 throw e;
31.1 --- a/src/jdk/nashorn/internal/parser/DateParser.java Thu Aug 15 09:26:02 2013 -0700 31.2 +++ b/src/jdk/nashorn/internal/parser/DateParser.java Tue Aug 20 17:46:45 2013 -0700 31.3 @@ -141,7 +141,7 @@ 31.4 * Try parsing the date string according to the rules laid out in ES5 15.9.1.15. 31.5 * The date string must conform to the following format: 31.6 * 31.7 - * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][hh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> 31.8 + * <pre> [('-'|'+')yy]yyyy[-MM[-dd]][Thh:mm[:ss[.sss]][Z|(+|-)hh:mm]] </pre> 31.9 * 31.10 * <p>If the string does not contain a time zone offset, the <tt>TIMEZONE</tt> field 31.11 * is set to <tt>0</tt> (GMT).</p> 31.12 @@ -249,7 +249,7 @@ 31.13 31.14 switch (token) { 31.15 case NUMBER: 31.16 - if (skip(':')) { 31.17 + if (skipDelimiter(':')) { 31.18 // A number followed by ':' is parsed as time 31.19 if (!setTimeField(numValue)) { 31.20 return false; 31.21 @@ -260,14 +260,14 @@ 31.22 if (token != Token.NUMBER || !setTimeField(numValue)) { 31.23 return false; 31.24 } 31.25 - } while (skip(isSet(SECOND) ? '.' : ':')); 31.26 + } while (skipDelimiter(isSet(SECOND) ? '.' : ':')); 31.27 31.28 } else { 31.29 // Parse as date token 31.30 if (!setDateField(numValue)) { 31.31 return false; 31.32 } 31.33 - skip('-'); 31.34 + skipDelimiter('-'); 31.35 } 31.36 break; 31.37 31.38 @@ -297,7 +297,7 @@ 31.39 break; 31.40 } 31.41 if (nameValue.type != Name.TIMEZONE_ID) { 31.42 - skip('-'); 31.43 + skipDelimiter('-'); 31.44 } 31.45 break; 31.46 31.47 @@ -359,7 +359,18 @@ 31.48 return pos < length ? string.charAt(pos) : -1; 31.49 } 31.50 31.51 - private boolean skip(final char c) { 31.52 + // Skip delimiter if followed by a number. Used for ISO 8601 formatted dates 31.53 + private boolean skipNumberDelimiter(final char c) { 31.54 + if (pos < length - 1 && string.charAt(pos) == c 31.55 + && Character.getType(string.charAt(pos + 1)) == DECIMAL_DIGIT_NUMBER) { 31.56 + token = null; 31.57 + pos++; 31.58 + return true; 31.59 + } 31.60 + return false; 31.61 + } 31.62 + 31.63 + private boolean skipDelimiter(final char c) { 31.64 if (pos < length && string.charAt(pos) == c) { 31.65 token = null; 31.66 pos++; 31.67 @@ -452,14 +463,14 @@ 31.68 switch (currentField) { 31.69 case YEAR: 31.70 case MONTH: 31.71 - return skip('-') || peek() == 'T' || peek() == -1; 31.72 + return skipNumberDelimiter('-') || peek() == 'T' || peek() == -1; 31.73 case DAY: 31.74 return peek() == 'T' || peek() == -1; 31.75 case HOUR: 31.76 case MINUTE: 31.77 - return skip(':') || endOfTime(); 31.78 + return skipNumberDelimiter(':') || endOfTime(); 31.79 case SECOND: 31.80 - return skip('.') || endOfTime(); 31.81 + return skipNumberDelimiter('.') || endOfTime(); 31.82 default: 31.83 return true; 31.84 } 31.85 @@ -515,7 +526,7 @@ 31.86 private int readTimeZoneOffset() { 31.87 final int sign = string.charAt(pos - 1) == '+' ? 1 : -1; 31.88 int offset = readNumber(2); 31.89 - skip(':'); 31.90 + skipDelimiter(':'); 31.91 offset = offset * 60 + readNumber(2); 31.92 return sign * offset; 31.93 }
32.1 --- a/src/jdk/nashorn/internal/parser/Parser.java Thu Aug 15 09:26:02 2013 -0700 32.2 +++ b/src/jdk/nashorn/internal/parser/Parser.java Tue Aug 20 17:46:45 2013 -0700 32.3 @@ -160,10 +160,10 @@ 32.4 if (this.scripting) { 32.5 this.lineInfoReceiver = new Lexer.LineInfoReceiver() { 32.6 @Override 32.7 - public void lineInfo(final int line, final int linePosition) { 32.8 + public void lineInfo(final int receiverLine, final int receiverLinePosition) { 32.9 // update the parser maintained line information 32.10 - Parser.this.line = line; 32.11 - Parser.this.linePosition = linePosition; 32.12 + Parser.this.line = receiverLine; 32.13 + Parser.this.linePosition = receiverLinePosition; 32.14 } 32.15 }; 32.16 } else {
33.1 --- a/src/jdk/nashorn/internal/runtime/Context.java Thu Aug 15 09:26:02 2013 -0700 33.2 +++ b/src/jdk/nashorn/internal/runtime/Context.java Tue Aug 20 17:46:45 2013 -0700 33.3 @@ -48,6 +48,7 @@ 33.4 import java.security.PrivilegedAction; 33.5 import java.security.ProtectionDomain; 33.6 import java.util.Map; 33.7 + 33.8 import jdk.internal.org.objectweb.asm.ClassReader; 33.9 import jdk.internal.org.objectweb.asm.util.CheckClassAdapter; 33.10 import jdk.nashorn.api.scripting.ScriptObjectMirror; 33.11 @@ -64,6 +65,31 @@ 33.12 * This class manages the global state of execution. Context is immutable. 33.13 */ 33.14 public final class Context { 33.15 + // nashorn specific security runtime access permission names 33.16 + /** 33.17 + * Permission needed to pass arbitrary nashorn command line options when creating Context. 33.18 + */ 33.19 + public static final String NASHORN_SET_CONFIG = "nashorn.setConfig"; 33.20 + 33.21 + /** 33.22 + * Permission needed to create Nashorn Context instance. 33.23 + */ 33.24 + public static final String NASHORN_CREATE_CONTEXT = "nashorn.createContext"; 33.25 + 33.26 + /** 33.27 + * Permission needed to create Nashorn Global instance. 33.28 + */ 33.29 + public static final String NASHORN_CREATE_GLOBAL = "nashorn.createGlobal"; 33.30 + 33.31 + /** 33.32 + * Permission to get current Nashorn Context from thread local storage. 33.33 + */ 33.34 + public static final String NASHORN_GET_CONTEXT = "nashorn.getContext"; 33.35 + 33.36 + /** 33.37 + * Permission to use Java reflection/jsr292 from script code. 33.38 + */ 33.39 + public static final String NASHORN_JAVA_REFLECTION = "nashorn.JavaReflection"; 33.40 33.41 /** 33.42 * ContextCodeInstaller that has the privilege of installing classes in the Context. 33.43 @@ -139,7 +165,7 @@ 33.44 public static Context getContext() { 33.45 final SecurityManager sm = System.getSecurityManager(); 33.46 if (sm != null) { 33.47 - sm.checkPermission(new RuntimePermission("nashorn.getContext")); 33.48 + sm.checkPermission(new RuntimePermission(NASHORN_GET_CONTEXT)); 33.49 } 33.50 return getContextTrusted(); 33.51 } 33.52 @@ -204,7 +230,20 @@ 33.53 33.54 private static final ClassLoader myLoader = Context.class.getClassLoader(); 33.55 private static final StructureLoader sharedLoader; 33.56 - private static final AccessControlContext NO_PERMISSIONS_CONTEXT; 33.57 + 33.58 + private static AccessControlContext createNoPermAccCtxt() { 33.59 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) }); 33.60 + } 33.61 + 33.62 + private static AccessControlContext createPermAccCtxt(final String permName) { 33.63 + final Permissions perms = new Permissions(); 33.64 + perms.add(new RuntimePermission(permName)); 33.65 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 33.66 + } 33.67 + 33.68 + private static final AccessControlContext NO_PERMISSIONS_ACC_CTXT = createNoPermAccCtxt(); 33.69 + private static final AccessControlContext CREATE_LOADER_ACC_CTXT = createPermAccCtxt("createClassLoader"); 33.70 + private static final AccessControlContext CREATE_GLOBAL_ACC_CTXT = createPermAccCtxt(NASHORN_CREATE_GLOBAL); 33.71 33.72 static { 33.73 sharedLoader = AccessController.doPrivileged(new PrivilegedAction<StructureLoader>() { 33.74 @@ -212,8 +251,7 @@ 33.75 public StructureLoader run() { 33.76 return new StructureLoader(myLoader, null); 33.77 } 33.78 - }); 33.79 - NO_PERMISSIONS_CONTEXT = new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, new Permissions()) }); 33.80 + }, CREATE_LOADER_ACC_CTXT); 33.81 } 33.82 33.83 /** 33.84 @@ -254,7 +292,7 @@ 33.85 public Context(final Options options, final ErrorManager errors, final PrintWriter out, final PrintWriter err, final ClassLoader appLoader) { 33.86 final SecurityManager sm = System.getSecurityManager(); 33.87 if (sm != null) { 33.88 - sm.checkPermission(new RuntimePermission("nashorn.createContext")); 33.89 + sm.checkPermission(new RuntimePermission(NASHORN_CREATE_CONTEXT)); 33.90 } 33.91 33.92 this.env = new ScriptEnvironment(options, out, err); 33.93 @@ -516,7 +554,7 @@ 33.94 @Override 33.95 public ScriptObject run() { 33.96 try { 33.97 - return createGlobal(); 33.98 + return newGlobal(); 33.99 } catch (final RuntimeException e) { 33.100 if (Context.DEBUG) { 33.101 e.printStackTrace(); 33.102 @@ -524,7 +562,9 @@ 33.103 throw e; 33.104 } 33.105 } 33.106 - }); 33.107 + }, CREATE_GLOBAL_ACC_CTXT); 33.108 + // initialize newly created Global instance 33.109 + initGlobal(newGlobal); 33.110 setGlobalTrusted(newGlobal); 33.111 33.112 final Object[] wrapped = args == null? ScriptRuntime.EMPTY_ARRAY : ScriptObjectMirror.wrapArray(args, oldGlobal); 33.113 @@ -577,7 +617,7 @@ 33.114 sm.checkPackageAccess(fullName.substring(0, index)); 33.115 return null; 33.116 } 33.117 - }, NO_PERMISSIONS_CONTEXT); 33.118 + }, NO_PERMISSIONS_ACC_CTXT); 33.119 } 33.120 } 33.121 } 33.122 @@ -849,6 +889,7 @@ 33.123 return script; 33.124 } 33.125 33.126 + @SuppressWarnings("static-method") 33.127 private ScriptLoader createNewLoader() { 33.128 return AccessController.doPrivileged( 33.129 new PrivilegedAction<ScriptLoader>() { 33.130 @@ -856,7 +897,7 @@ 33.131 public ScriptLoader run() { 33.132 return new ScriptLoader(sharedLoader, Context.this); 33.133 } 33.134 - }); 33.135 + }, CREATE_LOADER_ACC_CTXT); 33.136 } 33.137 33.138 private long getUniqueScriptId() {
34.1 --- a/src/jdk/nashorn/internal/runtime/ECMAErrors.java Thu Aug 15 09:26:02 2013 -0700 34.2 +++ b/src/jdk/nashorn/internal/runtime/ECMAErrors.java Tue Aug 20 17:46:45 2013 -0700 34.3 @@ -25,8 +25,6 @@ 34.4 34.5 package jdk.nashorn.internal.runtime; 34.6 34.7 -import java.security.AccessController; 34.8 -import java.security.PrivilegedAction; 34.9 import java.text.MessageFormat; 34.10 import java.util.Locale; 34.11 import java.util.ResourceBundle; 34.12 @@ -40,16 +38,9 @@ 34.13 public final class ECMAErrors { 34.14 private static final String MESSAGES_RESOURCE = "jdk.nashorn.internal.runtime.resources.Messages"; 34.15 34.16 - // Without do privileged, under security manager messages can not be loaded. 34.17 private static final ResourceBundle MESSAGES_BUNDLE; 34.18 static { 34.19 - MESSAGES_BUNDLE = AccessController.doPrivileged( 34.20 - new PrivilegedAction<ResourceBundle>() { 34.21 - @Override 34.22 - public ResourceBundle run() { 34.23 - return ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault()); 34.24 - } 34.25 - }); 34.26 + MESSAGES_BUNDLE = ResourceBundle.getBundle(MESSAGES_RESOURCE, Locale.getDefault()); 34.27 } 34.28 34.29 /** We assume that compiler generates script classes into the known package. */
35.1 --- a/src/jdk/nashorn/internal/runtime/GlobalObject.java Thu Aug 15 09:26:02 2013 -0700 35.2 +++ b/src/jdk/nashorn/internal/runtime/GlobalObject.java Tue Aug 20 17:46:45 2013 -0700 35.3 @@ -26,8 +26,10 @@ 35.4 package jdk.nashorn.internal.runtime; 35.5 35.6 import java.lang.invoke.MethodHandle; 35.7 +import java.util.concurrent.Callable; 35.8 import jdk.internal.dynalink.linker.GuardedInvocation; 35.9 import jdk.internal.dynalink.linker.LinkRequest; 35.10 +import jdk.nashorn.internal.runtime.linker.InvokeByName; 35.11 35.12 /** 35.13 * Runtime interface to the global scope objects. 35.14 @@ -210,4 +212,20 @@ 35.15 * @param clazz compiled Class object for the source 35.16 */ 35.17 public void cacheClass(Source source, Class<?> clazz); 35.18 + 35.19 + /** 35.20 + * Get cached InvokeByName object for the given key 35.21 + * @param key key to be associated with InvokeByName object 35.22 + * @param creator if InvokeByName is absent 'creator' is called to make one (lazy init) 35.23 + * @return InvokeByName object associated with the key. 35.24 + */ 35.25 + public InvokeByName getInvokeByName(final Object key, final Callable<InvokeByName> creator); 35.26 + 35.27 + /** 35.28 + * Get cached dynamic method handle for the given key 35.29 + * @param key key to be associated with dynamic method handle 35.30 + * @param creator if method handle is absent 'creator' is called to make one (lazy init) 35.31 + * @return dynamic method handle associated with the key. 35.32 + */ 35.33 + public MethodHandle getDynamicInvoker(final Object key, final Callable<MethodHandle> creator); 35.34 }
36.1 --- a/src/jdk/nashorn/internal/runtime/JSONFunctions.java Thu Aug 15 09:26:02 2013 -0700 36.2 +++ b/src/jdk/nashorn/internal/runtime/JSONFunctions.java Tue Aug 20 17:46:45 2013 -0700 36.3 @@ -27,6 +27,7 @@ 36.4 36.5 import java.lang.invoke.MethodHandle; 36.6 import java.util.Iterator; 36.7 +import java.util.concurrent.Callable; 36.8 import jdk.nashorn.internal.ir.LiteralNode; 36.9 import jdk.nashorn.internal.ir.Node; 36.10 import jdk.nashorn.internal.ir.ObjectNode; 36.11 @@ -42,8 +43,19 @@ 36.12 */ 36.13 public final class JSONFunctions { 36.14 private JSONFunctions() {} 36.15 - private static final MethodHandle REVIVER_INVOKER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 36.16 - ScriptFunction.class, ScriptObject.class, String.class, Object.class); 36.17 + 36.18 + private static final Object REVIVER_INVOKER = new Object(); 36.19 + 36.20 + private static MethodHandle getREVIVER_INVOKER() { 36.21 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(REVIVER_INVOKER, 36.22 + new Callable<MethodHandle>() { 36.23 + @Override 36.24 + public MethodHandle call() { 36.25 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 36.26 + ScriptFunction.class, ScriptObject.class, String.class, Object.class); 36.27 + } 36.28 + }); 36.29 + } 36.30 36.31 /** 36.32 * Returns JSON-compatible quoted version of the given string. 36.33 @@ -117,7 +129,7 @@ 36.34 36.35 try { 36.36 // Object.class, ScriptFunction.class, ScriptObject.class, String.class, Object.class); 36.37 - return REVIVER_INVOKER.invokeExact(reviver, holder, JSType.toString(name), val); 36.38 + return getREVIVER_INVOKER().invokeExact(reviver, holder, JSType.toString(name), val); 36.39 } catch(Error|RuntimeException t) { 36.40 throw t; 36.41 } catch(final Throwable t) {
37.1 --- a/src/jdk/nashorn/internal/runtime/JSType.java Thu Aug 15 09:26:02 2013 -0700 37.2 +++ b/src/jdk/nashorn/internal/runtime/JSType.java Tue Aug 20 17:46:45 2013 -0700 37.3 @@ -28,6 +28,7 @@ 37.4 import static jdk.nashorn.internal.codegen.CompilerConstants.staticCall; 37.5 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 37.6 37.7 +import java.lang.invoke.MethodHandles; 37.8 import java.util.Locale; 37.9 import jdk.internal.dynalink.beans.BeansLinker; 37.10 import jdk.internal.dynalink.beans.StaticClass; 37.11 @@ -63,47 +64,49 @@ 37.12 /** Max value for an uint32 in JavaScript */ 37.13 public static final long MAX_UINT = 0xFFFF_FFFFL; 37.14 37.15 + private static final MethodHandles.Lookup myLookup = MethodHandles.lookup(); 37.16 + 37.17 /** JavaScript compliant conversion function from Object to boolean */ 37.18 - public static final Call TO_BOOLEAN = staticCall(JSType.class, "toBoolean", boolean.class, Object.class); 37.19 + public static final Call TO_BOOLEAN = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, Object.class); 37.20 37.21 /** JavaScript compliant conversion function from number to boolean */ 37.22 - public static final Call TO_BOOLEAN_D = staticCall(JSType.class, "toBoolean", boolean.class, double.class); 37.23 + public static final Call TO_BOOLEAN_D = staticCall(myLookup, JSType.class, "toBoolean", boolean.class, double.class); 37.24 37.25 /** JavaScript compliant conversion function from Object to integer */ 37.26 - public static final Call TO_INTEGER = staticCall(JSType.class, "toInteger", int.class, Object.class); 37.27 + public static final Call TO_INTEGER = staticCall(myLookup, JSType.class, "toInteger", int.class, Object.class); 37.28 37.29 /** JavaScript compliant conversion function from Object to long */ 37.30 - public static final Call TO_LONG = staticCall(JSType.class, "toLong", long.class, Object.class); 37.31 + public static final Call TO_LONG = staticCall(myLookup, JSType.class, "toLong", long.class, Object.class); 37.32 37.33 /** JavaScript compliant conversion function from Object to number */ 37.34 - public static final Call TO_NUMBER = staticCall(JSType.class, "toNumber", double.class, Object.class); 37.35 + public static final Call TO_NUMBER = staticCall(myLookup, JSType.class, "toNumber", double.class, Object.class); 37.36 37.37 /** JavaScript compliant conversion function from Object to int32 */ 37.38 - public static final Call TO_INT32 = staticCall(JSType.class, "toInt32", int.class, Object.class); 37.39 + public static final Call TO_INT32 = staticCall(myLookup, JSType.class, "toInt32", int.class, Object.class); 37.40 37.41 /** JavaScript compliant conversion function from double to int32 */ 37.42 - public static final Call TO_INT32_D = staticCall(JSType.class, "toInt32", int.class, double.class); 37.43 + public static final Call TO_INT32_D = staticCall(myLookup, JSType.class, "toInt32", int.class, double.class); 37.44 37.45 /** JavaScript compliant conversion function from Object to uint32 */ 37.46 - public static final Call TO_UINT32 = staticCall(JSType.class, "toUint32", long.class, Object.class); 37.47 + public static final Call TO_UINT32 = staticCall(myLookup, JSType.class, "toUint32", long.class, Object.class); 37.48 37.49 /** JavaScript compliant conversion function from number to uint32 */ 37.50 - public static final Call TO_UINT32_D = staticCall(JSType.class, "toUint32", long.class, double.class); 37.51 + public static final Call TO_UINT32_D = staticCall(myLookup, JSType.class, "toUint32", long.class, double.class); 37.52 37.53 /** JavaScript compliant conversion function from Object to int64 */ 37.54 - public static final Call TO_INT64 = staticCall(JSType.class, "toInt64", long.class, Object.class); 37.55 + public static final Call TO_INT64 = staticCall(myLookup, JSType.class, "toInt64", long.class, Object.class); 37.56 37.57 /** JavaScript compliant conversion function from number to int64 */ 37.58 - public static final Call TO_INT64_D = staticCall(JSType.class, "toInt64", long.class, double.class); 37.59 + public static final Call TO_INT64_D = staticCall(myLookup, JSType.class, "toInt64", long.class, double.class); 37.60 37.61 /** JavaScript compliant conversion function from Object to String */ 37.62 - public static final Call TO_STRING = staticCall(JSType.class, "toString", String.class, Object.class); 37.63 + public static final Call TO_STRING = staticCall(myLookup, JSType.class, "toString", String.class, Object.class); 37.64 37.65 /** JavaScript compliant conversion function from number to String */ 37.66 - public static final Call TO_STRING_D = staticCall(JSType.class, "toString", String.class, double.class); 37.67 + public static final Call TO_STRING_D = staticCall(myLookup, JSType.class, "toString", String.class, double.class); 37.68 37.69 /** JavaScript compliant conversion function from Object to primitive */ 37.70 - public static final Call TO_PRIMITIVE = staticCall(JSType.class, "toPrimitive", Object.class, Object.class); 37.71 + public static final Call TO_PRIMITIVE = staticCall(myLookup, JSType.class, "toPrimitive", Object.class, Object.class); 37.72 37.73 private static final double INT32_LIMIT = 4294967296.0; 37.74
38.1 --- a/src/jdk/nashorn/internal/runtime/ListAdapter.java Thu Aug 15 09:26:02 2013 -0700 38.2 +++ b/src/jdk/nashorn/internal/runtime/ListAdapter.java Tue Aug 20 17:46:45 2013 -0700 38.3 @@ -31,6 +31,7 @@ 38.4 import java.util.ListIterator; 38.5 import java.util.NoSuchElementException; 38.6 import java.util.RandomAccess; 38.7 +import java.util.concurrent.Callable; 38.8 import jdk.nashorn.internal.runtime.linker.Bootstrap; 38.9 import jdk.nashorn.internal.runtime.linker.InvokeByName; 38.10 38.11 @@ -49,16 +50,73 @@ 38.12 */ 38.13 public final class ListAdapter extends AbstractList<Object> implements RandomAccess, Deque<Object> { 38.14 // These add to the back and front of the list 38.15 - private static final InvokeByName PUSH = new InvokeByName("push", ScriptObject.class, void.class, Object.class); 38.16 - private static final InvokeByName UNSHIFT = new InvokeByName("unshift", ScriptObject.class, void.class, Object.class); 38.17 + private static final Object PUSH = new Object(); 38.18 + private static InvokeByName getPUSH() { 38.19 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(PUSH, 38.20 + new Callable<InvokeByName>() { 38.21 + @Override 38.22 + public InvokeByName call() { 38.23 + return new InvokeByName("push", ScriptObject.class, void.class, Object.class); 38.24 + } 38.25 + }); 38.26 + } 38.27 + 38.28 + private static final Object UNSHIFT = new Object(); 38.29 + private static InvokeByName getUNSHIFT() { 38.30 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(UNSHIFT, 38.31 + new Callable<InvokeByName>() { 38.32 + @Override 38.33 + public InvokeByName call() { 38.34 + return new InvokeByName("unshift", ScriptObject.class, void.class, Object.class); 38.35 + } 38.36 + }); 38.37 + } 38.38 38.39 // These remove from the back and front of the list 38.40 - private static final InvokeByName POP = new InvokeByName("pop", ScriptObject.class, Object.class); 38.41 - private static final InvokeByName SHIFT = new InvokeByName("shift", ScriptObject.class, Object.class); 38.42 + private static final Object POP = new Object(); 38.43 + private static InvokeByName getPOP() { 38.44 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(POP, 38.45 + new Callable<InvokeByName>() { 38.46 + @Override 38.47 + public InvokeByName call() { 38.48 + return new InvokeByName("pop", ScriptObject.class, Object.class); 38.49 + } 38.50 + }); 38.51 + } 38.52 + 38.53 + private static final Object SHIFT = new Object(); 38.54 + private static InvokeByName getSHIFT() { 38.55 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SHIFT, 38.56 + new Callable<InvokeByName>() { 38.57 + @Override 38.58 + public InvokeByName call() { 38.59 + return new InvokeByName("shift", ScriptObject.class, Object.class); 38.60 + } 38.61 + }); 38.62 + } 38.63 38.64 // These insert and remove in the middle of the list 38.65 - private static final InvokeByName SPLICE_ADD = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class, Object.class); 38.66 - private static final InvokeByName SPLICE_REMOVE = new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class); 38.67 + private static final Object SPLICE_ADD = new Object(); 38.68 + private static InvokeByName getSPLICE_ADD() { 38.69 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_ADD, 38.70 + new Callable<InvokeByName>() { 38.71 + @Override 38.72 + public InvokeByName call() { 38.73 + return new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class, Object.class); 38.74 + } 38.75 + }); 38.76 + } 38.77 + 38.78 + private static final Object SPLICE_REMOVE = new Object(); 38.79 + private static InvokeByName getSPLICE_REMOVE() { 38.80 + return ((GlobalObject)Context.getGlobal()).getInvokeByName(SPLICE_REMOVE, 38.81 + new Callable<InvokeByName>() { 38.82 + @Override 38.83 + public InvokeByName call() { 38.84 + return new InvokeByName("splice", ScriptObject.class, void.class, int.class, int.class); 38.85 + } 38.86 + }); 38.87 + } 38.88 38.89 private final ScriptObject obj; 38.90 38.91 @@ -109,9 +167,10 @@ 38.92 @Override 38.93 public void addFirst(Object e) { 38.94 try { 38.95 - final Object fn = UNSHIFT.getGetter().invokeExact(obj); 38.96 - checkFunction(fn, UNSHIFT); 38.97 - UNSHIFT.getInvoker().invokeExact(fn, obj, e); 38.98 + final InvokeByName unshiftInvoker = getUNSHIFT(); 38.99 + final Object fn = unshiftInvoker.getGetter().invokeExact(obj); 38.100 + checkFunction(fn, unshiftInvoker); 38.101 + unshiftInvoker.getInvoker().invokeExact(fn, obj, e); 38.102 } catch(RuntimeException | Error ex) { 38.103 throw ex; 38.104 } catch(Throwable t) { 38.105 @@ -122,9 +181,10 @@ 38.106 @Override 38.107 public void addLast(Object e) { 38.108 try { 38.109 - final Object fn = PUSH.getGetter().invokeExact(obj); 38.110 - checkFunction(fn, PUSH); 38.111 - PUSH.getInvoker().invokeExact(fn, obj, e); 38.112 + final InvokeByName pushInvoker = getPUSH(); 38.113 + final Object fn = pushInvoker.getGetter().invokeExact(obj); 38.114 + checkFunction(fn, pushInvoker); 38.115 + pushInvoker.getInvoker().invokeExact(fn, obj, e); 38.116 } catch(RuntimeException | Error ex) { 38.117 throw ex; 38.118 } catch(Throwable t) { 38.119 @@ -142,9 +202,10 @@ 38.120 } else { 38.121 final int size = size(); 38.122 if(index < size) { 38.123 - final Object fn = SPLICE_ADD.getGetter().invokeExact(obj); 38.124 - checkFunction(fn, SPLICE_ADD); 38.125 - SPLICE_ADD.getInvoker().invokeExact(fn, obj, index, 0, e); 38.126 + final InvokeByName spliceAddInvoker = getSPLICE_ADD(); 38.127 + final Object fn = spliceAddInvoker.getGetter().invokeExact(obj); 38.128 + checkFunction(fn, spliceAddInvoker); 38.129 + spliceAddInvoker.getInvoker().invokeExact(fn, obj, index, 0, e); 38.130 } else if(index == size) { 38.131 addLast(e); 38.132 } else { 38.133 @@ -234,9 +295,10 @@ 38.134 38.135 private Object invokeShift() { 38.136 try { 38.137 - final Object fn = SHIFT.getGetter().invokeExact(obj); 38.138 - checkFunction(fn, SHIFT); 38.139 - return SHIFT.getInvoker().invokeExact(fn, obj); 38.140 + final InvokeByName shiftInvoker = getSHIFT(); 38.141 + final Object fn = shiftInvoker.getGetter().invokeExact(obj); 38.142 + checkFunction(fn, shiftInvoker); 38.143 + return shiftInvoker.getInvoker().invokeExact(fn, obj); 38.144 } catch(RuntimeException | Error ex) { 38.145 throw ex; 38.146 } catch(Throwable t) { 38.147 @@ -246,9 +308,10 @@ 38.148 38.149 private Object invokePop() { 38.150 try { 38.151 - final Object fn = POP.getGetter().invokeExact(obj); 38.152 - checkFunction(fn, POP); 38.153 - return POP.getInvoker().invokeExact(fn, obj); 38.154 + final InvokeByName popInvoker = getPOP(); 38.155 + final Object fn = popInvoker.getGetter().invokeExact(obj); 38.156 + checkFunction(fn, popInvoker); 38.157 + return popInvoker.getInvoker().invokeExact(fn, obj); 38.158 } catch(RuntimeException | Error ex) { 38.159 throw ex; 38.160 } catch(Throwable t) { 38.161 @@ -263,9 +326,10 @@ 38.162 38.163 private void invokeSpliceRemove(int fromIndex, int count) { 38.164 try { 38.165 - final Object fn = SPLICE_REMOVE.getGetter().invokeExact(obj); 38.166 - checkFunction(fn, SPLICE_REMOVE); 38.167 - SPLICE_REMOVE.getInvoker().invokeExact(fn, obj, fromIndex, count); 38.168 + final InvokeByName spliceRemoveInvoker = getSPLICE_REMOVE(); 38.169 + final Object fn = spliceRemoveInvoker.getGetter().invokeExact(obj); 38.170 + checkFunction(fn, spliceRemoveInvoker); 38.171 + spliceRemoveInvoker.getInvoker().invokeExact(fn, obj, fromIndex, count); 38.172 } catch(RuntimeException | Error ex) { 38.173 throw ex; 38.174 } catch(Throwable t) {
39.1 --- a/src/jdk/nashorn/internal/runtime/Logging.java Thu Aug 15 09:26:02 2013 -0700 39.2 +++ b/src/jdk/nashorn/internal/runtime/Logging.java Tue Aug 20 17:46:45 2013 -0700 39.3 @@ -25,6 +25,11 @@ 39.4 39.5 package jdk.nashorn.internal.runtime; 39.6 39.7 +import java.security.AccessControlContext; 39.8 +import java.security.AccessController; 39.9 +import java.security.Permissions; 39.10 +import java.security.PrivilegedAction; 39.11 +import java.security.ProtectionDomain; 39.12 import java.util.HashMap; 39.13 import java.util.Locale; 39.14 import java.util.Map; 39.15 @@ -35,6 +40,7 @@ 39.16 import java.util.logging.Level; 39.17 import java.util.logging.LogRecord; 39.18 import java.util.logging.Logger; 39.19 +import java.util.logging.LoggingPermission; 39.20 39.21 /** 39.22 * Logging system for getting loggers for arbitrary subsystems as 39.23 @@ -50,12 +56,20 @@ 39.24 39.25 private static final Logger disabledLogger = Logger.getLogger("disabled"); 39.26 39.27 + private static AccessControlContext createLoggerControlAccCtxt() { 39.28 + final Permissions perms = new Permissions(); 39.29 + perms.add(new LoggingPermission("control", null)); 39.30 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 39.31 + } 39.32 + 39.33 static { 39.34 - try { 39.35 - Logging.disabledLogger.setLevel(Level.OFF); 39.36 - } catch (final SecurityException e) { 39.37 - //ignored 39.38 - } 39.39 + AccessController.doPrivileged(new PrivilegedAction<Void>() { 39.40 + @Override 39.41 + public Void run() { 39.42 + Logging.disabledLogger.setLevel(Level.OFF); 39.43 + return null; 39.44 + } 39.45 + }, createLoggerControlAccCtxt()); 39.46 } 39.47 39.48 /** Maps logger name to loggers. Names are typically per package */
40.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Aug 15 09:26:02 2013 -0700 40.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Tue Aug 20 17:46:45 2013 -0700 40.3 @@ -47,18 +47,24 @@ 40.4 * This is a subclass that represents a script function that may be regenerated, 40.5 * for example with specialization based on call site types, or lazily generated. 40.6 * The common denominator is that it can get new invokers during its lifespan, 40.7 - * unlike {@link FinalScriptFunctionData} 40.8 + * unlike {@code FinalScriptFunctionData} 40.9 */ 40.10 public final class RecompilableScriptFunctionData extends ScriptFunctionData { 40.11 40.12 /** FunctionNode with the code for this ScriptFunction */ 40.13 - private FunctionNode functionNode; 40.14 + private volatile FunctionNode functionNode; 40.15 + 40.16 + /** Source from which FunctionNode was parsed. */ 40.17 + private final Source source; 40.18 + 40.19 + /** Token of this function within the source. */ 40.20 + private final long token; 40.21 40.22 /** Allocator map from makeMap() */ 40.23 private final PropertyMap allocatorMap; 40.24 40.25 /** Code installer used for all further recompilation/specialization of this ScriptFunction */ 40.26 - private final CodeInstaller<ScriptEnvironment> installer; 40.27 + private volatile CodeInstaller<ScriptEnvironment> installer; 40.28 40.29 /** Name of class where allocator function resides */ 40.30 private final String allocatorClassName; 40.31 @@ -103,6 +109,8 @@ 40.32 true); 40.33 40.34 this.functionNode = functionNode; 40.35 + this.source = functionNode.getSource(); 40.36 + this.token = tokenFor(functionNode); 40.37 this.installer = installer; 40.38 this.allocatorClassName = allocatorClassName; 40.39 this.allocatorMap = allocatorMap; 40.40 @@ -110,9 +118,6 @@ 40.41 40.42 @Override 40.43 String toSource() { 40.44 - final Source source = functionNode.getSource(); 40.45 - final long token = tokenFor(functionNode); 40.46 - 40.47 if (source != null && token != 0) { 40.48 return source.getString(Token.descPosition(token), Token.descLength(token)); 40.49 } 40.50 @@ -123,8 +128,6 @@ 40.51 @Override 40.52 public String toString() { 40.53 final StringBuilder sb = new StringBuilder(); 40.54 - final Source source = functionNode.getSource(); 40.55 - final long token = tokenFor(functionNode); 40.56 40.57 if (source != null) { 40.58 sb.append(source.getName()) 40.59 @@ -190,6 +193,12 @@ 40.60 40.61 // code exists - look it up and add it into the automatically sorted invoker list 40.62 addCode(functionNode); 40.63 + 40.64 + if (! functionNode.canSpecialize()) { 40.65 + // allow GC to claim IR stuff that is not needed anymore 40.66 + functionNode = null; 40.67 + installer = null; 40.68 + } 40.69 } 40.70 40.71 private MethodHandle addCode(final FunctionNode fn) { 40.72 @@ -325,7 +334,7 @@ 40.73 * footprint too large to store a parse snapshot, or if it is meaningless 40.74 * to do so, such as e.g. for runScript 40.75 */ 40.76 - if (!functionNode.canSpecialize()) { 40.77 + if (functionNode == null || !functionNode.canSpecialize()) { 40.78 return mh; 40.79 } 40.80
41.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Thu Aug 15 09:26:02 2013 -0700 41.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Tue Aug 20 17:46:45 2013 -0700 41.3 @@ -496,32 +496,24 @@ 41.4 MethodHandle boundHandle; 41.5 MethodHandle guard = null; 41.6 41.7 + final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 41.8 + 41.9 if (data.needsCallee()) { 41.10 final MethodHandle callHandle = getBestInvoker(type, request.getArguments()); 41.11 - if (NashornCallSiteDescriptor.isScope(desc)) { 41.12 + if (scopeCall) { 41.13 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 41.14 // (callee, this, args...) => (callee, args...) 41.15 boundHandle = MH.insertArguments(callHandle, 1, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 41.16 // (callee, args...) => (callee, [this], args...) 41.17 boundHandle = MH.dropArguments(boundHandle, 1, Object.class); 41.18 + 41.19 } else { 41.20 // It's already (callee, this, args...), just what we need 41.21 boundHandle = callHandle; 41.22 - 41.23 - // For non-strict functions, check whether this-object is primitive type. 41.24 - // If so add a to-object-wrapper argument filter. 41.25 - // Else install a guard that will trigger a relink when the argument becomes primitive. 41.26 - if (needsWrappedThis()) { 41.27 - if (ScriptFunctionData.isPrimitiveThis(request.getArguments()[1])) { 41.28 - boundHandle = MH.filterArguments(boundHandle, 1, WRAPFILTER); 41.29 - } else { 41.30 - guard = getNonStrictFunctionGuard(this); 41.31 - } 41.32 - } 41.33 } 41.34 } else { 41.35 final MethodHandle callHandle = getBestInvoker(type.dropParameterTypes(0, 1), request.getArguments()); 41.36 - if (NashornCallSiteDescriptor.isScope(desc)) { 41.37 + if (scopeCall) { 41.38 // Make a handle that drops the passed "this" argument and substitutes either Global or Undefined 41.39 // (this, args...) => (args...) 41.40 boundHandle = MH.bindTo(callHandle, needsWrappedThis() ? Context.getGlobalTrusted() : ScriptRuntime.UNDEFINED); 41.41 @@ -533,6 +525,17 @@ 41.42 } 41.43 } 41.44 41.45 + // For non-strict functions, check whether this-object is primitive type. 41.46 + // If so add a to-object-wrapper argument filter. 41.47 + // Else install a guard that will trigger a relink when the argument becomes primitive. 41.48 + if (!scopeCall && needsWrappedThis()) { 41.49 + if (ScriptFunctionData.isPrimitiveThis(request.getArguments()[1])) { 41.50 + boundHandle = MH.filterArguments(boundHandle, 1, WRAPFILTER); 41.51 + } else { 41.52 + guard = getNonStrictFunctionGuard(this); 41.53 + } 41.54 + } 41.55 + 41.56 boundHandle = pairArguments(boundHandle, type); 41.57 41.58 return new GuardedInvocation(boundHandle, guard == null ? getFunctionGuard(this) : guard); 41.59 @@ -550,19 +553,18 @@ 41.60 private static MethodHandle bindToNameIfNeeded(final MethodHandle methodHandle, final String bindName) { 41.61 if (bindName == null) { 41.62 return methodHandle; 41.63 - } else { 41.64 - // if it is vararg method, we need to extend argument array with 41.65 - // a new zeroth element that is set to bindName value. 41.66 - final MethodType methodType = methodHandle.type(); 41.67 - final int parameterCount = methodType.parameterCount(); 41.68 - final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); 41.69 + } 41.70 41.71 - if (isVarArg) { 41.72 - return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); 41.73 - } else { 41.74 - return MH.insertArguments(methodHandle, 1, bindName); 41.75 - } 41.76 + // if it is vararg method, we need to extend argument array with 41.77 + // a new zeroth element that is set to bindName value. 41.78 + final MethodType methodType = methodHandle.type(); 41.79 + final int parameterCount = methodType.parameterCount(); 41.80 + final boolean isVarArg = parameterCount > 0 && methodType.parameterType(parameterCount - 1).isArray(); 41.81 + 41.82 + if (isVarArg) { 41.83 + return MH.filterArguments(methodHandle, 1, MH.insertArguments(ADD_ZEROTH_ELEMENT, 1, bindName)); 41.84 } 41.85 + return MH.insertArguments(methodHandle, 1, bindName); 41.86 } 41.87 41.88 /**
42.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Thu Aug 15 09:26:02 2013 -0700 42.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Tue Aug 20 17:46:45 2013 -0700 42.3 @@ -250,9 +250,18 @@ 42.4 final int length = args == null ? 0 : args.length; 42.5 42.6 CompiledFunctions boundList = new CompiledFunctions(); 42.7 - for (final CompiledFunction inv : code) { 42.8 + if (code.size() == 1) { 42.9 + // only one variant - bind that 42.10 + boundList.add(bind(code.first(), fn, self, allArgs)); 42.11 + } else { 42.12 + // There are specialized versions. Get the most generic one. 42.13 + // This is to avoid ambiguous overloaded versions of bound and 42.14 + // specialized variants and choosing wrong overload. 42.15 + final MethodHandle genInvoker = getGenericInvoker(); 42.16 + final CompiledFunction inv = new CompiledFunction(genInvoker.type(), genInvoker, getGenericConstructor()); 42.17 boundList.add(bind(inv, fn, self, allArgs)); 42.18 } 42.19 + 42.20 ScriptFunctionData boundData = new FinalScriptFunctionData(name, arity == -1 ? -1 : Math.max(0, arity - length), boundList, isStrict(), isBuiltin(), isConstructor()); 42.21 return boundData; 42.22 }
43.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Aug 15 09:26:02 2013 -0700 43.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Tue Aug 20 17:46:45 2013 -0700 43.3 @@ -138,10 +138,10 @@ 43.4 private static final MethodHandle KNOWNFUNCPROPGUARD = findOwnMH("knownFunctionPropertyGuard", boolean.class, Object.class, PropertyMap.class, MethodHandle.class, Object.class, ScriptFunction.class); 43.5 43.6 /** Method handle for getting a function argument at a given index. Used from MapCreator */ 43.7 - public static final Call GET_ARGUMENT = virtualCall(ScriptObject.class, "getArgument", Object.class, int.class); 43.8 + public static final Call GET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "getArgument", Object.class, int.class); 43.9 43.10 /** Method handle for setting a function argument at a given index. Used from MapCreator */ 43.11 - public static final Call SET_ARGUMENT = virtualCall(ScriptObject.class, "setArgument", void.class, int.class, Object.class); 43.12 + public static final Call SET_ARGUMENT = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setArgument", void.class, int.class, Object.class); 43.13 43.14 /** Method handle for getting the proto of a ScriptObject */ 43.15 public static final Call GET_PROTO = virtualCallNoLookup(ScriptObject.class, "getProto", ScriptObject.class); 43.16 @@ -150,7 +150,7 @@ 43.17 public static final Call SET_PROTO = virtualCallNoLookup(ScriptObject.class, "setProto", void.class, ScriptObject.class); 43.18 43.19 /** Method handle for setting the user accessors of a ScriptObject */ 43.20 - public static final Call SET_USER_ACCESSORS = virtualCall(ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 43.21 + public static final Call SET_USER_ACCESSORS = virtualCall(MethodHandles.lookup(), ScriptObject.class, "setUserAccessors", void.class, String.class, ScriptFunction.class, ScriptFunction.class); 43.22 43.23 /** 43.24 * Constructor 43.25 @@ -2012,9 +2012,10 @@ 43.26 final boolean scopeAccess = isScope() && NashornCallSiteDescriptor.isScope(desc); 43.27 43.28 if (find != null) { 43.29 - final Object value = getObjectValue(find); 43.30 - ScriptFunction func = null; 43.31 - MethodHandle methodHandle = null; 43.32 + final Object value = getObjectValue(find); 43.33 + ScriptFunction func = null; 43.34 + MethodHandle methodHandle = null; 43.35 + 43.36 if (value instanceof ScriptFunction) { 43.37 func = (ScriptFunction)value; 43.38 methodHandle = getCallMethodHandle(func, desc.getMethodType(), name); 43.39 @@ -3219,6 +3220,11 @@ 43.40 return property; 43.41 } 43.42 43.43 + /** 43.44 + * Write a value to a spill slot 43.45 + * @param slot the slot index 43.46 + * @param value the value 43.47 + */ 43.48 protected final void setSpill(final int slot, final Object value) { 43.49 if (spill == null) { 43.50 // create new spill. 43.51 @@ -3233,6 +3239,11 @@ 43.52 spill[slot] = value; 43.53 } 43.54 43.55 + /** 43.56 + * Get a value from a spill slot 43.57 + * @param slot the slot index 43.58 + * @return the value in the spill slot with the given index 43.59 + */ 43.60 protected Object getSpill(final int slot) { 43.61 return spill != null && slot < spill.length ? spill[slot] : null; 43.62 }
44.1 --- a/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Thu Aug 15 09:26:02 2013 -0700 44.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptRuntime.java Tue Aug 20 17:46:45 2013 -0700 44.3 @@ -33,6 +33,7 @@ 44.4 import static jdk.nashorn.internal.runtime.JSType.isRepresentableAsInt; 44.5 44.6 import java.lang.invoke.MethodHandle; 44.7 +import java.lang.invoke.MethodHandles; 44.8 import java.lang.reflect.Array; 44.9 import java.util.Collections; 44.10 import java.util.Iterator; 44.11 @@ -100,7 +101,7 @@ 44.12 * call sites that are known to be megamorphic. Using an invoke dynamic here would 44.13 * lead to the JVM deoptimizing itself to death 44.14 */ 44.15 - public static final Call APPLY = staticCall(ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); 44.16 + public static final Call APPLY = staticCall(MethodHandles.lookup(), ScriptRuntime.class, "apply", Object.class, ScriptFunction.class, Object.class, Object[].class); 44.17 44.18 /** 44.19 * Converts a switch tag value to a simple integer. deflt value if it can't.
45.1 --- a/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Thu Aug 15 09:26:02 2013 -0700 45.2 +++ b/src/jdk/nashorn/internal/runtime/UserAccessorProperty.java Tue Aug 20 17:46:45 2013 -0700 45.3 @@ -27,6 +27,7 @@ 45.4 45.5 import java.lang.invoke.MethodHandle; 45.6 import java.lang.invoke.MethodHandles; 45.7 +import java.util.concurrent.Callable; 45.8 45.9 import jdk.nashorn.internal.codegen.CompilerConstants; 45.10 import jdk.nashorn.internal.lookup.Lookup; 45.11 @@ -68,12 +69,32 @@ 45.12 "userAccessorSetter", void.class, ScriptObject.class, int.class, String.class, Object.class, Object.class); 45.13 45.14 /** Dynamic invoker for getter */ 45.15 - private static final MethodHandle INVOKE_UA_GETTER = Bootstrap.createDynamicInvoker("dyn:call", Object.class, 45.16 - Object.class, Object.class); 45.17 + private static final Object INVOKE_UA_GETTER = new Object(); 45.18 + 45.19 + private static MethodHandle getINVOKE_UA_GETTER() { 45.20 + 45.21 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_GETTER, 45.22 + new Callable<MethodHandle>() { 45.23 + @Override 45.24 + public MethodHandle call() { 45.25 + return Bootstrap.createDynamicInvoker("dyn:call", Object.class, 45.26 + Object.class, Object.class); 45.27 + } 45.28 + }); 45.29 + } 45.30 45.31 /** Dynamic invoker for setter */ 45.32 - private static final MethodHandle INVOKE_UA_SETTER = Bootstrap.createDynamicInvoker("dyn:call", void.class, 45.33 - Object.class, Object.class, Object.class); 45.34 + private static Object INVOKE_UA_SETTER = new Object(); 45.35 + private static MethodHandle getINVOKE_UA_SETTER() { 45.36 + return ((GlobalObject)Context.getGlobal()).getDynamicInvoker(INVOKE_UA_SETTER, 45.37 + new Callable<MethodHandle>() { 45.38 + @Override 45.39 + public MethodHandle call() { 45.40 + return Bootstrap.createDynamicInvoker("dyn:call", void.class, 45.41 + Object.class, Object.class, Object.class); 45.42 + } 45.43 + }); 45.44 + } 45.45 45.46 /** 45.47 * Constructor 45.48 @@ -191,7 +212,7 @@ 45.49 45.50 if (func instanceof ScriptFunction) { 45.51 try { 45.52 - return INVOKE_UA_GETTER.invokeExact(func, self); 45.53 + return getINVOKE_UA_GETTER().invokeExact(func, self); 45.54 } catch(final Error|RuntimeException t) { 45.55 throw t; 45.56 } catch(final Throwable t) { 45.57 @@ -208,7 +229,7 @@ 45.58 45.59 if (func instanceof ScriptFunction) { 45.60 try { 45.61 - INVOKE_UA_SETTER.invokeExact(func, self, value); 45.62 + getINVOKE_UA_SETTER().invokeExact(func, self, value); 45.63 } catch(final Error|RuntimeException t) { 45.64 throw t; 45.65 } catch(final Throwable t) {
46.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayIterator.java Thu Aug 15 09:26:02 2013 -0700 46.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 46.3 @@ -1,88 +0,0 @@ 46.4 -/* 46.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 46.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 46.7 - * 46.8 - * This code is free software; you can redistribute it and/or modify it 46.9 - * under the terms of the GNU General Public License version 2 only, as 46.10 - * published by the Free Software Foundation. Oracle designates this 46.11 - * particular file as subject to the "Classpath" exception as provided 46.12 - * by Oracle in the LICENSE file that accompanied this code. 46.13 - * 46.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 46.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 46.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 46.17 - * version 2 for more details (a copy is included in the LICENSE file that 46.18 - * accompanied this code). 46.19 - * 46.20 - * You should have received a copy of the GNU General Public License version 46.21 - * 2 along with this work; if not, write to the Free Software Foundation, 46.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 46.23 - * 46.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 46.25 - * or visit www.oracle.com if you need additional information or have any 46.26 - * questions. 46.27 - */ 46.28 - 46.29 -package jdk.nashorn.internal.runtime.arrays; 46.30 - 46.31 -import jdk.nashorn.internal.runtime.ScriptObject; 46.32 - 46.33 -/** 46.34 - * Iterator over a NativeArray 46.35 - */ 46.36 -class ArrayIterator extends ArrayLikeIterator<Object> { 46.37 - 46.38 - /** Array {@link ScriptObject} to iterate over */ 46.39 - protected final ScriptObject array; 46.40 - 46.41 - /** length of array */ 46.42 - protected final long length; 46.43 - 46.44 - /** 46.45 - * Constructor 46.46 - * @param array array to iterate over 46.47 - * @param includeUndefined should undefined elements be included in iteration 46.48 - */ 46.49 - protected ArrayIterator(final ScriptObject array, final boolean includeUndefined) { 46.50 - super(includeUndefined); 46.51 - this.array = array; 46.52 - this.length = array.getArray().length(); 46.53 - } 46.54 - 46.55 - /** 46.56 - * Is the current index still inside the array 46.57 - * @return true if inside the array 46.58 - */ 46.59 - protected boolean indexInArray() { 46.60 - return index < length; 46.61 - } 46.62 - 46.63 - @Override 46.64 - public Object next() { 46.65 - return array.get(bumpIndex()); 46.66 - } 46.67 - 46.68 - @Override 46.69 - public long getLength() { 46.70 - return length; 46.71 - } 46.72 - 46.73 - @Override 46.74 - public boolean hasNext() { 46.75 - if (!includeUndefined) { 46.76 - while (indexInArray()) { 46.77 - if (array.has(index)) { 46.78 - break; 46.79 - } 46.80 - bumpIndex(); 46.81 - } 46.82 - } 46.83 - 46.84 - return indexInArray(); 46.85 - } 46.86 - 46.87 - @Override 46.88 - public void remove() { 46.89 - array.delete(index, false); 46.90 - } 46.91 -}
47.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Thu Aug 15 09:26:02 2013 -0700 47.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ArrayLikeIterator.java Tue Aug 20 17:46:45 2013 -0700 47.3 @@ -26,6 +26,7 @@ 47.4 package jdk.nashorn.internal.runtime.arrays; 47.5 47.6 import java.util.Iterator; 47.7 +import java.util.List; 47.8 import jdk.nashorn.api.scripting.ScriptObjectMirror; 47.9 import jdk.nashorn.internal.runtime.JSType; 47.10 import jdk.nashorn.internal.runtime.ScriptObject; 47.11 @@ -49,7 +50,7 @@ 47.12 * 47.13 * @param includeUndefined should undefined elements be included in the iteration? 47.14 */ 47.15 - protected ArrayLikeIterator(final boolean includeUndefined) { 47.16 + ArrayLikeIterator(final boolean includeUndefined) { 47.17 this.includeUndefined = includeUndefined; 47.18 this.index = 0; 47.19 } 47.20 @@ -118,18 +119,26 @@ 47.21 Object obj = object; 47.22 47.23 if (ScriptObject.isArray(obj)) { 47.24 - return new ArrayIterator((ScriptObject) obj, includeUndefined); 47.25 + return new ScriptArrayIterator((ScriptObject) obj, includeUndefined); 47.26 } 47.27 47.28 obj = JSType.toScriptObject(obj); 47.29 if (obj instanceof ScriptObject) { 47.30 - return new MapIterator((ScriptObject)obj, includeUndefined); 47.31 + return new ScriptObjectIterator((ScriptObject)obj, includeUndefined); 47.32 } 47.33 47.34 if (obj instanceof ScriptObjectMirror) { 47.35 return new ScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); 47.36 } 47.37 47.38 + if (obj instanceof List) { 47.39 + return new JavaListIterator((List<?>)obj, includeUndefined); 47.40 + } 47.41 + 47.42 + if (obj != null && obj.getClass().isArray()) { 47.43 + return new JavaArrayIterator(obj, includeUndefined); 47.44 + } 47.45 + 47.46 return new EmptyArrayLikeIterator(); 47.47 } 47.48 47.49 @@ -143,19 +152,25 @@ 47.50 Object obj = object; 47.51 47.52 if (ScriptObject.isArray(obj)) { 47.53 - return new ReverseArrayIterator((ScriptObject) obj, includeUndefined); 47.54 + return new ReverseScriptArrayIterator((ScriptObject) obj, includeUndefined); 47.55 } 47.56 47.57 obj = JSType.toScriptObject(obj); 47.58 if (obj instanceof ScriptObject) { 47.59 - return new ReverseMapIterator((ScriptObject)obj, includeUndefined); 47.60 + return new ReverseScriptObjectIterator((ScriptObject)obj, includeUndefined); 47.61 } 47.62 47.63 if (obj instanceof ScriptObjectMirror) { 47.64 return new ReverseScriptObjectMirrorIterator((ScriptObjectMirror)obj, includeUndefined); 47.65 } 47.66 47.67 - assert !obj.getClass().isArray(); 47.68 + if (obj instanceof List) { 47.69 + return new ReverseJavaListIterator((List<?>)obj, includeUndefined); 47.70 + } 47.71 + 47.72 + if (obj != null && obj.getClass().isArray()) { 47.73 + return new ReverseJavaArrayIterator(obj, includeUndefined); 47.74 + } 47.75 47.76 return new EmptyArrayLikeIterator(); 47.77 }
48.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 48.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaArrayIterator.java Tue Aug 20 17:46:45 2013 -0700 48.3 @@ -0,0 +1,80 @@ 48.4 +/* 48.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 48.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 48.7 + * 48.8 + * This code is free software; you can redistribute it and/or modify it 48.9 + * under the terms of the GNU General Public License version 2 only, as 48.10 + * published by the Free Software Foundation. Oracle designates this 48.11 + * particular file as subject to the "Classpath" exception as provided 48.12 + * by Oracle in the LICENSE file that accompanied this code. 48.13 + * 48.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 48.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 48.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 48.17 + * version 2 for more details (a copy is included in the LICENSE file that 48.18 + * accompanied this code). 48.19 + * 48.20 + * You should have received a copy of the GNU General Public License version 48.21 + * 2 along with this work; if not, write to the Free Software Foundation, 48.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 48.23 + * 48.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 48.25 + * or visit www.oracle.com if you need additional information or have any 48.26 + * questions. 48.27 + */ 48.28 + 48.29 +package jdk.nashorn.internal.runtime.arrays; 48.30 + 48.31 +import java.lang.reflect.Array; 48.32 + 48.33 +/** 48.34 + * Iterator over a Java List. 48.35 + */ 48.36 +class JavaArrayIterator extends ArrayLikeIterator<Object> { 48.37 + 48.38 + /** Array to iterate over */ 48.39 + protected final Object array; 48.40 + 48.41 + /** length of array */ 48.42 + protected final long length; 48.43 + 48.44 + /** 48.45 + * Constructor 48.46 + * @param array array to iterate over 48.47 + * @param includeUndefined should undefined elements be included in iteration 48.48 + */ 48.49 + protected JavaArrayIterator(final Object array, final boolean includeUndefined) { 48.50 + super(includeUndefined); 48.51 + assert array.getClass().isArray() : "expecting Java array object"; 48.52 + this.array = array; 48.53 + this.length = Array.getLength(array); 48.54 + } 48.55 + 48.56 + /** 48.57 + * Is the current index still inside the array 48.58 + * @return true if inside the array 48.59 + */ 48.60 + protected boolean indexInArray() { 48.61 + return index < length; 48.62 + } 48.63 + 48.64 + @Override 48.65 + public Object next() { 48.66 + return Array.get(array, (int)bumpIndex()); 48.67 + } 48.68 + 48.69 + @Override 48.70 + public long getLength() { 48.71 + return length; 48.72 + } 48.73 + 48.74 + @Override 48.75 + public boolean hasNext() { 48.76 + return indexInArray(); 48.77 + } 48.78 + 48.79 + @Override 48.80 + public void remove() { 48.81 + throw new UnsupportedOperationException("remove"); 48.82 + } 48.83 +} 48.84 \ No newline at end of file
49.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 49.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/JavaListIterator.java Tue Aug 20 17:46:45 2013 -0700 49.3 @@ -0,0 +1,79 @@ 49.4 +/* 49.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 49.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 49.7 + * 49.8 + * This code is free software; you can redistribute it and/or modify it 49.9 + * under the terms of the GNU General Public License version 2 only, as 49.10 + * published by the Free Software Foundation. Oracle designates this 49.11 + * particular file as subject to the "Classpath" exception as provided 49.12 + * by Oracle in the LICENSE file that accompanied this code. 49.13 + * 49.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 49.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 49.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 49.17 + * version 2 for more details (a copy is included in the LICENSE file that 49.18 + * accompanied this code). 49.19 + * 49.20 + * You should have received a copy of the GNU General Public License version 49.21 + * 2 along with this work; if not, write to the Free Software Foundation, 49.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 49.23 + * 49.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 49.25 + * or visit www.oracle.com if you need additional information or have any 49.26 + * questions. 49.27 + */ 49.28 + 49.29 +package jdk.nashorn.internal.runtime.arrays; 49.30 + 49.31 +import java.util.List; 49.32 + 49.33 +/** 49.34 + * Iterator over a Java List. 49.35 + */ 49.36 +class JavaListIterator extends ArrayLikeIterator<Object> { 49.37 + 49.38 + /** {@link java.util.List} to iterate over */ 49.39 + protected final List<?> list; 49.40 + 49.41 + /** length of array */ 49.42 + protected final long length; 49.43 + 49.44 + /** 49.45 + * Constructor 49.46 + * @param list list to iterate over 49.47 + * @param includeUndefined should undefined elements be included in iteration 49.48 + */ 49.49 + protected JavaListIterator(final List<?> list, final boolean includeUndefined) { 49.50 + super(includeUndefined); 49.51 + this.list = list; 49.52 + this.length = list.size(); 49.53 + } 49.54 + 49.55 + /** 49.56 + * Is the current index still inside the array 49.57 + * @return true if inside the array 49.58 + */ 49.59 + protected boolean indexInArray() { 49.60 + return index < length; 49.61 + } 49.62 + 49.63 + @Override 49.64 + public Object next() { 49.65 + return list.get((int)bumpIndex()); 49.66 + } 49.67 + 49.68 + @Override 49.69 + public long getLength() { 49.70 + return length; 49.71 + } 49.72 + 49.73 + @Override 49.74 + public boolean hasNext() { 49.75 + return indexInArray(); 49.76 + } 49.77 + 49.78 + @Override 49.79 + public void remove() { 49.80 + list.remove(index); 49.81 + } 49.82 +}
50.1 --- a/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Thu Aug 15 09:26:02 2013 -0700 50.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/LongArrayData.java Tue Aug 20 17:46:45 2013 -0700 50.3 @@ -98,9 +98,8 @@ 50.4 final int length = (int) length(); 50.5 if (type == Double.class) { 50.6 return new NumberArrayData(LongArrayData.toDoubleArray(array, length), length); 50.7 - } else { 50.8 - return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); 50.9 } 50.10 + return new ObjectArrayData(LongArrayData.toObjectArray(array, length), length); 50.11 } 50.12 50.13 @Override
51.1 --- a/src/jdk/nashorn/internal/runtime/arrays/MapIterator.java Thu Aug 15 09:26:02 2013 -0700 51.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 51.3 @@ -1,80 +0,0 @@ 51.4 -/* 51.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 51.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 51.7 - * 51.8 - * This code is free software; you can redistribute it and/or modify it 51.9 - * under the terms of the GNU General Public License version 2 only, as 51.10 - * published by the Free Software Foundation. Oracle designates this 51.11 - * particular file as subject to the "Classpath" exception as provided 51.12 - * by Oracle in the LICENSE file that accompanied this code. 51.13 - * 51.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 51.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 51.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 51.17 - * version 2 for more details (a copy is included in the LICENSE file that 51.18 - * accompanied this code). 51.19 - * 51.20 - * You should have received a copy of the GNU General Public License version 51.21 - * 2 along with this work; if not, write to the Free Software Foundation, 51.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 51.23 - * 51.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 51.25 - * or visit www.oracle.com if you need additional information or have any 51.26 - * questions. 51.27 - */ 51.28 - 51.29 -package jdk.nashorn.internal.runtime.arrays; 51.30 - 51.31 -import java.util.NoSuchElementException; 51.32 -import jdk.nashorn.internal.runtime.JSType; 51.33 -import jdk.nashorn.internal.runtime.ScriptObject; 51.34 - 51.35 -/** 51.36 - * Iterator over a map 51.37 - */ 51.38 -class MapIterator extends ArrayLikeIterator<Object> { 51.39 - 51.40 - protected final ScriptObject obj; 51.41 - private final long length; 51.42 - 51.43 - MapIterator(final ScriptObject obj, final boolean includeUndefined) { 51.44 - super(includeUndefined); 51.45 - this.obj = obj; 51.46 - this.length = JSType.toUint32(obj.getLength()); 51.47 - this.index = 0; 51.48 - } 51.49 - 51.50 - protected boolean indexInArray() { 51.51 - return index < length; 51.52 - } 51.53 - 51.54 - @Override 51.55 - public long getLength() { 51.56 - return length; 51.57 - } 51.58 - 51.59 - @Override 51.60 - public boolean hasNext() { 51.61 - if (length == 0L) { 51.62 - return false; //return empty string if toUint32(length) == 0 51.63 - } 51.64 - 51.65 - while (indexInArray()) { 51.66 - if (obj.has(index) || includeUndefined) { 51.67 - break; 51.68 - } 51.69 - bumpIndex(); 51.70 - } 51.71 - 51.72 - return indexInArray(); 51.73 - } 51.74 - 51.75 - @Override 51.76 - public Object next() { 51.77 - if (indexInArray()) { 51.78 - return obj.get(bumpIndex()); 51.79 - } 51.80 - 51.81 - throw new NoSuchElementException(); 51.82 - } 51.83 -}
52.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ReverseArrayIterator.java Thu Aug 15 09:26:02 2013 -0700 52.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 52.3 @@ -1,59 +0,0 @@ 52.4 -/* 52.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 52.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 52.7 - * 52.8 - * This code is free software; you can redistribute it and/or modify it 52.9 - * under the terms of the GNU General Public License version 2 only, as 52.10 - * published by the Free Software Foundation. Oracle designates this 52.11 - * particular file as subject to the "Classpath" exception as provided 52.12 - * by Oracle in the LICENSE file that accompanied this code. 52.13 - * 52.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 52.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 52.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 52.17 - * version 2 for more details (a copy is included in the LICENSE file that 52.18 - * accompanied this code). 52.19 - * 52.20 - * You should have received a copy of the GNU General Public License version 52.21 - * 2 along with this work; if not, write to the Free Software Foundation, 52.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 52.23 - * 52.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 52.25 - * or visit www.oracle.com if you need additional information or have any 52.26 - * questions. 52.27 - */ 52.28 - 52.29 -package jdk.nashorn.internal.runtime.arrays; 52.30 - 52.31 -import jdk.nashorn.internal.runtime.ScriptObject; 52.32 - 52.33 -/** 52.34 - * Reverse iterator over a NativeArray 52.35 - */ 52.36 -final class ReverseArrayIterator extends ArrayIterator { 52.37 - 52.38 - /** 52.39 - * Constructor 52.40 - * @param array array to iterate over 52.41 - * @param includeUndefined should undefined elements be included in iteration 52.42 - */ 52.43 - public ReverseArrayIterator(final ScriptObject array, final boolean includeUndefined) { 52.44 - super(array, includeUndefined); 52.45 - this.index = array.getArray().length() - 1; 52.46 - } 52.47 - 52.48 - @Override 52.49 - public boolean isReverse() { 52.50 - return true; 52.51 - } 52.52 - 52.53 - @Override 52.54 - protected boolean indexInArray() { 52.55 - return index >= 0; 52.56 - } 52.57 - 52.58 - @Override 52.59 - protected long bumpIndex() { 52.60 - return index--; 52.61 - } 52.62 -}
53.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 53.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaArrayIterator.java Tue Aug 20 17:46:45 2013 -0700 53.3 @@ -0,0 +1,58 @@ 53.4 +/* 53.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 53.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 53.7 + * 53.8 + * This code is free software; you can redistribute it and/or modify it 53.9 + * under the terms of the GNU General Public License version 2 only, as 53.10 + * published by the Free Software Foundation. Oracle designates this 53.11 + * particular file as subject to the "Classpath" exception as provided 53.12 + * by Oracle in the LICENSE file that accompanied this code. 53.13 + * 53.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 53.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 53.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 53.17 + * version 2 for more details (a copy is included in the LICENSE file that 53.18 + * accompanied this code). 53.19 + * 53.20 + * You should have received a copy of the GNU General Public License version 53.21 + * 2 along with this work; if not, write to the Free Software Foundation, 53.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 53.23 + * 53.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 53.25 + * or visit www.oracle.com if you need additional information or have any 53.26 + * questions. 53.27 + */ 53.28 + 53.29 +package jdk.nashorn.internal.runtime.arrays; 53.30 + 53.31 +import java.lang.reflect.Array; 53.32 + 53.33 +/** 53.34 + * Reverse iterator over a array 53.35 + */ 53.36 +final class ReverseJavaArrayIterator extends JavaArrayIterator { 53.37 + /** 53.38 + * Constructor 53.39 + * @param array array to iterate over 53.40 + * @param includeUndefined should undefined elements be included in iteration 53.41 + */ 53.42 + public ReverseJavaArrayIterator(final Object array, final boolean includeUndefined) { 53.43 + super(array, includeUndefined); 53.44 + this.index = Array.getLength(array) - 1; 53.45 + } 53.46 + 53.47 + @Override 53.48 + public boolean isReverse() { 53.49 + return true; 53.50 + } 53.51 + 53.52 + @Override 53.53 + protected boolean indexInArray() { 53.54 + return index >= 0; 53.55 + } 53.56 + 53.57 + @Override 53.58 + protected long bumpIndex() { 53.59 + return index--; 53.60 + } 53.61 +} 53.62 \ No newline at end of file
54.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 54.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseJavaListIterator.java Tue Aug 20 17:46:45 2013 -0700 54.3 @@ -0,0 +1,58 @@ 54.4 +/* 54.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 54.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 54.7 + * 54.8 + * This code is free software; you can redistribute it and/or modify it 54.9 + * under the terms of the GNU General Public License version 2 only, as 54.10 + * published by the Free Software Foundation. Oracle designates this 54.11 + * particular file as subject to the "Classpath" exception as provided 54.12 + * by Oracle in the LICENSE file that accompanied this code. 54.13 + * 54.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 54.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 54.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 54.17 + * version 2 for more details (a copy is included in the LICENSE file that 54.18 + * accompanied this code). 54.19 + * 54.20 + * You should have received a copy of the GNU General Public License version 54.21 + * 2 along with this work; if not, write to the Free Software Foundation, 54.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 54.23 + * 54.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 54.25 + * or visit www.oracle.com if you need additional information or have any 54.26 + * questions. 54.27 + */ 54.28 + 54.29 +package jdk.nashorn.internal.runtime.arrays; 54.30 + 54.31 +import java.util.List; 54.32 + 54.33 +/** 54.34 + * Reverse iterator over a List 54.35 + */ 54.36 +final class ReverseJavaListIterator extends JavaListIterator { 54.37 + /** 54.38 + * Constructor 54.39 + * @param list list to iterate over 54.40 + * @param includeUndefined should undefined elements be included in iteration 54.41 + */ 54.42 + public ReverseJavaListIterator(final List<?> list, final boolean includeUndefined) { 54.43 + super(list, includeUndefined); 54.44 + this.index = list.size() - 1; 54.45 + } 54.46 + 54.47 + @Override 54.48 + public boolean isReverse() { 54.49 + return true; 54.50 + } 54.51 + 54.52 + @Override 54.53 + protected boolean indexInArray() { 54.54 + return index >= 0; 54.55 + } 54.56 + 54.57 + @Override 54.58 + protected long bumpIndex() { 54.59 + return index--; 54.60 + } 54.61 +}
55.1 --- a/src/jdk/nashorn/internal/runtime/arrays/ReverseMapIterator.java Thu Aug 15 09:26:02 2013 -0700 55.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 55.3 @@ -1,55 +0,0 @@ 55.4 -/* 55.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 55.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 55.7 - * 55.8 - * This code is free software; you can redistribute it and/or modify it 55.9 - * under the terms of the GNU General Public License version 2 only, as 55.10 - * published by the Free Software Foundation. Oracle designates this 55.11 - * particular file as subject to the "Classpath" exception as provided 55.12 - * by Oracle in the LICENSE file that accompanied this code. 55.13 - * 55.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 55.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 55.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 55.17 - * version 2 for more details (a copy is included in the LICENSE file that 55.18 - * accompanied this code). 55.19 - * 55.20 - * You should have received a copy of the GNU General Public License version 55.21 - * 2 along with this work; if not, write to the Free Software Foundation, 55.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 55.23 - * 55.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 55.25 - * or visit www.oracle.com if you need additional information or have any 55.26 - * questions. 55.27 - */ 55.28 - 55.29 -package jdk.nashorn.internal.runtime.arrays; 55.30 - 55.31 -import jdk.nashorn.internal.runtime.JSType; 55.32 -import jdk.nashorn.internal.runtime.ScriptObject; 55.33 - 55.34 -/** 55.35 - * Reverse iterator over a map 55.36 - */ 55.37 -final class ReverseMapIterator extends MapIterator { 55.38 - 55.39 - ReverseMapIterator(final ScriptObject obj, final boolean includeUndefined) { 55.40 - super(obj, includeUndefined); 55.41 - this.index = JSType.toUint32(obj.getLength()) - 1; 55.42 - } 55.43 - 55.44 - @Override 55.45 - public boolean isReverse() { 55.46 - return true; 55.47 - } 55.48 - 55.49 - @Override 55.50 - protected boolean indexInArray() { 55.51 - return index >= 0; 55.52 - } 55.53 - 55.54 - @Override 55.55 - protected long bumpIndex() { 55.56 - return index--; 55.57 - } 55.58 -}
56.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 56.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptArrayIterator.java Tue Aug 20 17:46:45 2013 -0700 56.3 @@ -0,0 +1,59 @@ 56.4 +/* 56.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 56.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 56.7 + * 56.8 + * This code is free software; you can redistribute it and/or modify it 56.9 + * under the terms of the GNU General Public License version 2 only, as 56.10 + * published by the Free Software Foundation. Oracle designates this 56.11 + * particular file as subject to the "Classpath" exception as provided 56.12 + * by Oracle in the LICENSE file that accompanied this code. 56.13 + * 56.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 56.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 56.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 56.17 + * version 2 for more details (a copy is included in the LICENSE file that 56.18 + * accompanied this code). 56.19 + * 56.20 + * You should have received a copy of the GNU General Public License version 56.21 + * 2 along with this work; if not, write to the Free Software Foundation, 56.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 56.23 + * 56.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 56.25 + * or visit www.oracle.com if you need additional information or have any 56.26 + * questions. 56.27 + */ 56.28 + 56.29 +package jdk.nashorn.internal.runtime.arrays; 56.30 + 56.31 +import jdk.nashorn.internal.runtime.ScriptObject; 56.32 + 56.33 +/** 56.34 + * Reverse iterator over a NativeArray 56.35 + */ 56.36 +final class ReverseScriptArrayIterator extends ScriptArrayIterator { 56.37 + 56.38 + /** 56.39 + * Constructor 56.40 + * @param array array to iterate over 56.41 + * @param includeUndefined should undefined elements be included in iteration 56.42 + */ 56.43 + public ReverseScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { 56.44 + super(array, includeUndefined); 56.45 + this.index = array.getArray().length() - 1; 56.46 + } 56.47 + 56.48 + @Override 56.49 + public boolean isReverse() { 56.50 + return true; 56.51 + } 56.52 + 56.53 + @Override 56.54 + protected boolean indexInArray() { 56.55 + return index >= 0; 56.56 + } 56.57 + 56.58 + @Override 56.59 + protected long bumpIndex() { 56.60 + return index--; 56.61 + } 56.62 +}
57.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 57.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ReverseScriptObjectIterator.java Tue Aug 20 17:46:45 2013 -0700 57.3 @@ -0,0 +1,55 @@ 57.4 +/* 57.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 57.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 57.7 + * 57.8 + * This code is free software; you can redistribute it and/or modify it 57.9 + * under the terms of the GNU General Public License version 2 only, as 57.10 + * published by the Free Software Foundation. Oracle designates this 57.11 + * particular file as subject to the "Classpath" exception as provided 57.12 + * by Oracle in the LICENSE file that accompanied this code. 57.13 + * 57.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 57.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 57.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 57.17 + * version 2 for more details (a copy is included in the LICENSE file that 57.18 + * accompanied this code). 57.19 + * 57.20 + * You should have received a copy of the GNU General Public License version 57.21 + * 2 along with this work; if not, write to the Free Software Foundation, 57.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 57.23 + * 57.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 57.25 + * or visit www.oracle.com if you need additional information or have any 57.26 + * questions. 57.27 + */ 57.28 + 57.29 +package jdk.nashorn.internal.runtime.arrays; 57.30 + 57.31 +import jdk.nashorn.internal.runtime.JSType; 57.32 +import jdk.nashorn.internal.runtime.ScriptObject; 57.33 + 57.34 +/** 57.35 + * Reverse iterator over a map 57.36 + */ 57.37 +final class ReverseScriptObjectIterator extends ScriptObjectIterator { 57.38 + 57.39 + ReverseScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { 57.40 + super(obj, includeUndefined); 57.41 + this.index = JSType.toUint32(obj.getLength()) - 1; 57.42 + } 57.43 + 57.44 + @Override 57.45 + public boolean isReverse() { 57.46 + return true; 57.47 + } 57.48 + 57.49 + @Override 57.50 + protected boolean indexInArray() { 57.51 + return index >= 0; 57.52 + } 57.53 + 57.54 + @Override 57.55 + protected long bumpIndex() { 57.56 + return index--; 57.57 + } 57.58 +}
58.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 58.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptArrayIterator.java Tue Aug 20 17:46:45 2013 -0700 58.3 @@ -0,0 +1,88 @@ 58.4 +/* 58.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 58.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 58.7 + * 58.8 + * This code is free software; you can redistribute it and/or modify it 58.9 + * under the terms of the GNU General Public License version 2 only, as 58.10 + * published by the Free Software Foundation. Oracle designates this 58.11 + * particular file as subject to the "Classpath" exception as provided 58.12 + * by Oracle in the LICENSE file that accompanied this code. 58.13 + * 58.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 58.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 58.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 58.17 + * version 2 for more details (a copy is included in the LICENSE file that 58.18 + * accompanied this code). 58.19 + * 58.20 + * You should have received a copy of the GNU General Public License version 58.21 + * 2 along with this work; if not, write to the Free Software Foundation, 58.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 58.23 + * 58.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 58.25 + * or visit www.oracle.com if you need additional information or have any 58.26 + * questions. 58.27 + */ 58.28 + 58.29 +package jdk.nashorn.internal.runtime.arrays; 58.30 + 58.31 +import jdk.nashorn.internal.runtime.ScriptObject; 58.32 + 58.33 +/** 58.34 + * Iterator over a NativeArray 58.35 + */ 58.36 +class ScriptArrayIterator extends ArrayLikeIterator<Object> { 58.37 + 58.38 + /** Array {@link ScriptObject} to iterate over */ 58.39 + protected final ScriptObject array; 58.40 + 58.41 + /** length of array */ 58.42 + protected final long length; 58.43 + 58.44 + /** 58.45 + * Constructor 58.46 + * @param array array to iterate over 58.47 + * @param includeUndefined should undefined elements be included in iteration 58.48 + */ 58.49 + protected ScriptArrayIterator(final ScriptObject array, final boolean includeUndefined) { 58.50 + super(includeUndefined); 58.51 + this.array = array; 58.52 + this.length = array.getArray().length(); 58.53 + } 58.54 + 58.55 + /** 58.56 + * Is the current index still inside the array 58.57 + * @return true if inside the array 58.58 + */ 58.59 + protected boolean indexInArray() { 58.60 + return index < length; 58.61 + } 58.62 + 58.63 + @Override 58.64 + public Object next() { 58.65 + return array.get(bumpIndex()); 58.66 + } 58.67 + 58.68 + @Override 58.69 + public long getLength() { 58.70 + return length; 58.71 + } 58.72 + 58.73 + @Override 58.74 + public boolean hasNext() { 58.75 + if (!includeUndefined) { 58.76 + while (indexInArray()) { 58.77 + if (array.has(index)) { 58.78 + break; 58.79 + } 58.80 + bumpIndex(); 58.81 + } 58.82 + } 58.83 + 58.84 + return indexInArray(); 58.85 + } 58.86 + 58.87 + @Override 58.88 + public void remove() { 58.89 + array.delete(index, false); 58.90 + } 58.91 +}
59.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 59.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/ScriptObjectIterator.java Tue Aug 20 17:46:45 2013 -0700 59.3 @@ -0,0 +1,80 @@ 59.4 +/* 59.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 59.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 59.7 + * 59.8 + * This code is free software; you can redistribute it and/or modify it 59.9 + * under the terms of the GNU General Public License version 2 only, as 59.10 + * published by the Free Software Foundation. Oracle designates this 59.11 + * particular file as subject to the "Classpath" exception as provided 59.12 + * by Oracle in the LICENSE file that accompanied this code. 59.13 + * 59.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 59.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 59.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 59.17 + * version 2 for more details (a copy is included in the LICENSE file that 59.18 + * accompanied this code). 59.19 + * 59.20 + * You should have received a copy of the GNU General Public License version 59.21 + * 2 along with this work; if not, write to the Free Software Foundation, 59.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 59.23 + * 59.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 59.25 + * or visit www.oracle.com if you need additional information or have any 59.26 + * questions. 59.27 + */ 59.28 + 59.29 +package jdk.nashorn.internal.runtime.arrays; 59.30 + 59.31 +import java.util.NoSuchElementException; 59.32 +import jdk.nashorn.internal.runtime.JSType; 59.33 +import jdk.nashorn.internal.runtime.ScriptObject; 59.34 + 59.35 +/** 59.36 + * Iterator over a map 59.37 + */ 59.38 +class ScriptObjectIterator extends ArrayLikeIterator<Object> { 59.39 + 59.40 + protected final ScriptObject obj; 59.41 + private final long length; 59.42 + 59.43 + ScriptObjectIterator(final ScriptObject obj, final boolean includeUndefined) { 59.44 + super(includeUndefined); 59.45 + this.obj = obj; 59.46 + this.length = JSType.toUint32(obj.getLength()); 59.47 + this.index = 0; 59.48 + } 59.49 + 59.50 + protected boolean indexInArray() { 59.51 + return index < length; 59.52 + } 59.53 + 59.54 + @Override 59.55 + public long getLength() { 59.56 + return length; 59.57 + } 59.58 + 59.59 + @Override 59.60 + public boolean hasNext() { 59.61 + if (length == 0L) { 59.62 + return false; //return empty string if toUint32(length) == 0 59.63 + } 59.64 + 59.65 + while (indexInArray()) { 59.66 + if (obj.has(index) || includeUndefined) { 59.67 + break; 59.68 + } 59.69 + bumpIndex(); 59.70 + } 59.71 + 59.72 + return indexInArray(); 59.73 + } 59.74 + 59.75 + @Override 59.76 + public Object next() { 59.77 + if (indexInArray()) { 59.78 + return obj.get(bumpIndex()); 59.79 + } 59.80 + 59.81 + throw new NoSuchElementException(); 59.82 + } 59.83 +}
60.1 --- a/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Thu Aug 15 09:26:02 2013 -0700 60.2 +++ b/src/jdk/nashorn/internal/runtime/arrays/SparseArrayData.java Tue Aug 20 17:46:45 2013 -0700 60.3 @@ -60,7 +60,7 @@ 60.4 60.5 @Override 60.6 public ArrayData copy() { 60.7 - return new SparseArrayData(underlying.copy(), length(), new TreeMap<Long, Object>(sparseMap)); 60.8 + return new SparseArrayData(underlying.copy(), length(), new TreeMap<>(sparseMap)); 60.9 } 60.10 60.11 @Override
61.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Thu Aug 15 09:26:02 2013 -0700 61.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Tue Aug 20 17:46:45 2013 -0700 61.3 @@ -68,6 +68,10 @@ 61.4 if (relinkThreshold > -1) { 61.5 factory.setUnstableRelinkThreshold(relinkThreshold); 61.6 } 61.7 + 61.8 + // Linkers for any additional language runtimes deployed alongside Nashorn will be picked up by the factory. 61.9 + factory.setClassLoader(Bootstrap.class.getClassLoader()); 61.10 + 61.11 dynamicLinker = factory.createLinker(); 61.12 } 61.13
62.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Thu Aug 15 09:26:02 2013 -0700 62.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethod.java Tue Aug 20 17:46:45 2013 -0700 62.3 @@ -29,7 +29,7 @@ 62.4 62.5 /** 62.6 * Represents a Dynalink dynamic method bound to a receiver. Note that objects of this class are just the tuples of 62.7 - * a method and a bound this, without any behavior. All the behavior is defined in the {@link BoundDynamicMethodLinker}. 62.8 + * a method and a bound this, without any behavior. All the behavior is defined in the {@code BoundDynamicMethodLinker}. 62.9 */ 62.10 final class BoundDynamicMethod { 62.11 private final Object dynamicMethod;
63.1 --- a/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Thu Aug 15 09:26:02 2013 -0700 63.2 +++ b/src/jdk/nashorn/internal/runtime/linker/BoundDynamicMethodLinker.java Tue Aug 20 17:46:45 2013 -0700 63.3 @@ -37,7 +37,7 @@ 63.4 import jdk.internal.dynalink.support.Guards; 63.5 63.6 /** 63.7 - * Links {@link BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method 63.8 + * Links {@code BoundDynamicMethod} objects. Passes through to Dynalink's BeansLinker for linking a dynamic method 63.9 * (they only respond to "dyn:call"), and modifies the returned invocation to deal with the receiver binding. 63.10 */ 63.11 final class BoundDynamicMethodLinker implements TypeBasedGuardingDynamicLinker {
64.1 --- a/src/jdk/nashorn/internal/runtime/linker/ClassAndLoader.java Thu Aug 15 09:26:02 2013 -0700 64.2 +++ b/src/jdk/nashorn/internal/runtime/linker/ClassAndLoader.java Tue Aug 20 17:46:45 2013 -0700 64.3 @@ -27,8 +27,11 @@ 64.4 64.5 import static jdk.nashorn.internal.runtime.ECMAErrors.typeError; 64.6 64.7 +import java.security.AccessControlContext; 64.8 import java.security.AccessController; 64.9 +import java.security.Permissions; 64.10 import java.security.PrivilegedAction; 64.11 +import java.security.ProtectionDomain; 64.12 import java.util.Collection; 64.13 import java.util.Iterator; 64.14 import java.util.LinkedHashMap; 64.15 @@ -43,6 +46,16 @@ 64.16 * used to determine if one loader can see the other loader's classes. 64.17 */ 64.18 final class ClassAndLoader { 64.19 + static AccessControlContext createPermAccCtxt(final String... permNames) { 64.20 + final Permissions perms = new Permissions(); 64.21 + for (final String permName : permNames) { 64.22 + perms.add(new RuntimePermission(permName)); 64.23 + } 64.24 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 64.25 + } 64.26 + 64.27 + private static final AccessControlContext GET_LOADER_ACC_CTXT = createPermAccCtxt("getClassLoader"); 64.28 + 64.29 private final Class<?> representativeClass; 64.30 // Don't access this directly; most of the time, use getRetrievedLoader(), or if you know what you're doing, 64.31 // getLoader(). 64.32 @@ -116,7 +129,7 @@ 64.33 public ClassAndLoader run() { 64.34 return getDefiningClassAndLoaderPrivileged(types); 64.35 } 64.36 - }); 64.37 + }, GET_LOADER_ACC_CTXT); 64.38 } 64.39 64.40 static ClassAndLoader getDefiningClassAndLoaderPrivileged(final Class<?>[] types) {
65.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Thu Aug 15 09:26:02 2013 -0700 65.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterBytecodeGenerator.java Tue Aug 20 17:46:45 2013 -0700 65.3 @@ -49,6 +49,7 @@ 65.4 import java.lang.reflect.Constructor; 65.5 import java.lang.reflect.Method; 65.6 import java.lang.reflect.Modifier; 65.7 +import java.security.AccessControlContext; 65.8 import java.security.AccessController; 65.9 import java.security.PrivilegedAction; 65.10 import java.util.Arrays; 65.11 @@ -868,6 +869,8 @@ 65.12 } 65.13 } 65.14 65.15 + private static final AccessControlContext GET_DECLARED_MEMBERS_ACC_CTXT = ClassAndLoader.createPermAccCtxt("accessDeclaredMembers"); 65.16 + 65.17 /** 65.18 * Creates a collection of methods that are not final, but we still never allow them to be overridden in adapters, 65.19 * as explicitly declaring them automatically is a bad idea. Currently, this means {@code Object.finalize()} and 65.20 @@ -886,7 +889,7 @@ 65.21 throw new AssertionError(e); 65.22 } 65.23 } 65.24 - }); 65.25 + }, GET_DECLARED_MEMBERS_ACC_CTXT); 65.26 } 65.27 65.28 private String getCommonSuperClass(final String type1, final String type2) {
66.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Thu Aug 15 09:26:02 2013 -0700 66.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterClassLoader.java Tue Aug 20 17:46:45 2013 -0700 66.3 @@ -25,6 +25,7 @@ 66.4 66.5 package jdk.nashorn.internal.runtime.linker; 66.6 66.7 +import java.security.AccessControlContext; 66.8 import java.security.AccessController; 66.9 import java.security.AllPermission; 66.10 import java.security.CodeSigner; 66.11 @@ -46,9 +47,10 @@ 66.12 @SuppressWarnings("javadoc") 66.13 final class JavaAdapterClassLoader { 66.14 private static final ProtectionDomain GENERATED_PROTECTION_DOMAIN = createGeneratedProtectionDomain(); 66.15 + private static final AccessControlContext CREATE_LOADER_ACC_CTXT = ClassAndLoader.createPermAccCtxt("createClassLoader"); 66.16 66.17 private final String className; 66.18 - private final byte[] classBytes; 66.19 + private volatile byte[] classBytes; 66.20 66.21 JavaAdapterClassLoader(String className, byte[] classBytes) { 66.22 this.className = className.replace('/', '.'); 66.23 @@ -56,6 +58,13 @@ 66.24 } 66.25 66.26 /** 66.27 + * clear classBytes after loading class. 66.28 + */ 66.29 + void clearClassBytes() { 66.30 + this.classBytes = null; 66.31 + } 66.32 + 66.33 + /** 66.34 * Loads the generated adapter class into the JVM. 66.35 * @param parentLoader the parent class loader for the generated class loader 66.36 * @return the generated adapter class 66.37 @@ -70,7 +79,7 @@ 66.38 throw new AssertionError(e); // cannot happen 66.39 } 66.40 } 66.41 - }); 66.42 + }, CREATE_LOADER_ACC_CTXT); 66.43 } 66.44 66.45 // Note that the adapter class is created in the protection domain of the class/interface being 66.46 @@ -103,10 +112,10 @@ 66.47 @Override 66.48 protected Class<?> findClass(final String name) throws ClassNotFoundException { 66.49 if(name.equals(className)) { 66.50 + assert classBytes != null : "what? already cleared .class bytes!!"; 66.51 return defineClass(name, classBytes, 0, classBytes.length, GENERATED_PROTECTION_DOMAIN); 66.52 - } else { 66.53 - throw new ClassNotFoundException(name); 66.54 } 66.55 + throw new ClassNotFoundException(name); 66.56 } 66.57 }; 66.58 }
67.1 --- a/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Thu Aug 15 09:26:02 2013 -0700 67.2 +++ b/src/jdk/nashorn/internal/runtime/linker/JavaAdapterFactory.java Tue Aug 20 17:46:45 2013 -0700 67.3 @@ -31,9 +31,9 @@ 67.4 import java.lang.invoke.MethodHandles; 67.5 import java.lang.invoke.MethodType; 67.6 import java.lang.reflect.Modifier; 67.7 +import java.security.AccessControlContext; 67.8 import java.security.AccessController; 67.9 import java.security.PrivilegedAction; 67.10 -import java.security.PrivilegedExceptionAction; 67.11 import java.util.ArrayList; 67.12 import java.util.Arrays; 67.13 import java.util.Collections; 67.14 @@ -70,6 +70,11 @@ 67.15 67.16 @SuppressWarnings("javadoc") 67.17 public final class JavaAdapterFactory { 67.18 + // context with permissions needs for AdapterInfo creation 67.19 + private static final AccessControlContext CREATE_ADAPTER_INFO_ACC_CTXT = 67.20 + ClassAndLoader.createPermAccCtxt("createClassLoader", "getClassLoader", 67.21 + "accessDeclaredMembers", "accessClassInPackage.jdk.nashorn.internal.runtime"); 67.22 + 67.23 /** 67.24 * A mapping from an original Class object to AdapterInfo representing the adapter for the class it represents. 67.25 */ 67.26 @@ -124,17 +129,10 @@ 67.27 */ 67.28 public static MethodHandle getConstructor(final Class<?> sourceType, final Class<?> targetType) throws Exception { 67.29 final StaticClass adapterClass = getAdapterClassFor(new Class<?>[] { targetType }, null); 67.30 - return AccessController.doPrivileged(new PrivilegedExceptionAction<MethodHandle>() { 67.31 - @Override 67.32 - public MethodHandle run() throws Exception { 67.33 - // NOTE: we use publicLookup(), but none of our adapter constructors are caller sensitive, so this is 67.34 - // okay, we won't artificially limit access. 67.35 - return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl( 67.36 - NashornCallSiteDescriptor.get(MethodHandles.publicLookup(), "dyn:new", 67.37 - MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false, 67.38 - adapterClass, null)).getInvocation(), adapterClass); 67.39 - } 67.40 - }); 67.41 + return MH.bindTo(Bootstrap.getLinkerServices().getGuardedInvocation(new LinkRequestImpl( 67.42 + NashornCallSiteDescriptor.get(MethodHandles.publicLookup(), "dyn:new", 67.43 + MethodType.methodType(targetType, StaticClass.class, sourceType), 0), false, 67.44 + adapterClass, null)).getInvocation(), adapterClass); 67.45 } 67.46 67.47 /** 67.48 @@ -171,7 +169,7 @@ 67.49 return (List)Collections.singletonList(clazz); 67.50 } 67.51 67.52 - /** 67.53 + /** 67.54 * For a given class, create its adapter class and associated info. 67.55 * @param type the class for which the adapter is created 67.56 * @return the adapter info for the class. 67.57 @@ -190,12 +188,19 @@ 67.58 } 67.59 superClass = t; 67.60 } else { 67.61 + if (interfaces.size() > 65535) { 67.62 + throw new IllegalArgumentException("interface limit exceeded"); 67.63 + } 67.64 + 67.65 interfaces.add(t); 67.66 } 67.67 + 67.68 if(!Modifier.isPublic(mod)) { 67.69 return new AdapterInfo(AdaptationResult.Outcome.ERROR_NON_PUBLIC_CLASS, t.getCanonicalName()); 67.70 } 67.71 } 67.72 + 67.73 + 67.74 final Class<?> effectiveSuperClass = superClass == null ? Object.class : superClass; 67.75 return AccessController.doPrivileged(new PrivilegedAction<AdapterInfo>() { 67.76 @Override 67.77 @@ -206,7 +211,7 @@ 67.78 return new AdapterInfo(e.getAdaptationResult()); 67.79 } 67.80 } 67.81 - }); 67.82 + }, CREATE_ADAPTER_INFO_ACC_CTXT); 67.83 } 67.84 67.85 private static class AdapterInfo { 67.86 @@ -224,7 +229,10 @@ 67.87 this.commonLoader = findCommonLoader(definingLoader); 67.88 final JavaAdapterBytecodeGenerator gen = new JavaAdapterBytecodeGenerator(superClass, interfaces, commonLoader, false); 67.89 this.autoConvertibleFromFunction = gen.isAutoConvertibleFromFunction(); 67.90 - this.instanceAdapterClass = gen.createAdapterClassLoader().generateClass(commonLoader); 67.91 + final JavaAdapterClassLoader jacl = gen.createAdapterClassLoader(); 67.92 + this.instanceAdapterClass = jacl.generateClass(commonLoader); 67.93 + // loaded Class - no need to keep class bytes around 67.94 + jacl.clearClassBytes(); 67.95 this.adapterGenerator = new JavaAdapterBytecodeGenerator(superClass, interfaces, commonLoader, true).createAdapterClassLoader(); 67.96 this.adaptationResult = AdaptationResult.SUCCESSFUL_RESULT; 67.97 }
68.1 --- a/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java Thu Aug 15 09:26:02 2013 -0700 68.2 +++ b/src/jdk/nashorn/internal/runtime/linker/ReflectionCheckLinker.java Tue Aug 20 17:46:45 2013 -0700 68.3 @@ -88,6 +88,6 @@ 68.4 } 68.5 68.6 private static void checkReflectionPermission(final SecurityManager sm) { 68.7 - sm.checkPermission(new RuntimePermission("nashorn.JavaReflection")); 68.8 + sm.checkPermission(new RuntimePermission(Context.NASHORN_JAVA_REFLECTION)); 68.9 } 68.10 }
69.1 --- a/src/jdk/nashorn/internal/runtime/options/Options.java Thu Aug 15 09:26:02 2013 -0700 69.2 +++ b/src/jdk/nashorn/internal/runtime/options/Options.java Tue Aug 20 17:46:45 2013 -0700 69.3 @@ -26,8 +26,11 @@ 69.4 package jdk.nashorn.internal.runtime.options; 69.5 69.6 import java.io.PrintWriter; 69.7 +import java.security.AccessControlContext; 69.8 import java.security.AccessController; 69.9 +import java.security.Permissions; 69.10 import java.security.PrivilegedAction; 69.11 +import java.security.ProtectionDomain; 69.12 import java.text.MessageFormat; 69.13 import java.util.ArrayList; 69.14 import java.util.Collection; 69.15 @@ -39,6 +42,7 @@ 69.16 import java.util.Locale; 69.17 import java.util.Map; 69.18 import java.util.MissingResourceException; 69.19 +import java.util.PropertyPermission; 69.20 import java.util.ResourceBundle; 69.21 import java.util.StringTokenizer; 69.22 import java.util.TimeZone; 69.23 @@ -51,6 +55,15 @@ 69.24 * Manages global runtime options. 69.25 */ 69.26 public final class Options { 69.27 + // permission to just read nashorn.* System properties 69.28 + private static AccessControlContext createPropertyReadAccCtxt() { 69.29 + final Permissions perms = new Permissions(); 69.30 + perms.add(new PropertyPermission("nashorn.*", "read")); 69.31 + return new AccessControlContext(new ProtectionDomain[] { new ProtectionDomain(null, perms) }); 69.32 + } 69.33 + 69.34 + private static final AccessControlContext READ_PROPERTY_ACC_CTXT = createPropertyReadAccCtxt(); 69.35 + 69.36 /** Resource tag. */ 69.37 private final String resource; 69.38 69.39 @@ -144,7 +157,7 @@ 69.40 return false; 69.41 } 69.42 } 69.43 - }); 69.44 + }, READ_PROPERTY_ACC_CTXT); 69.45 } 69.46 69.47 /** 69.48 @@ -171,7 +184,7 @@ 69.49 return defValue; 69.50 } 69.51 } 69.52 - }); 69.53 + }, READ_PROPERTY_ACC_CTXT); 69.54 } 69.55 69.56 /** 69.57 @@ -198,7 +211,7 @@ 69.58 return defValue; 69.59 } 69.60 } 69.61 - }); 69.62 + }, READ_PROPERTY_ACC_CTXT); 69.63 } 69.64 69.65 /** 69.66 @@ -395,13 +408,13 @@ 69.67 final LinkedList<String> argList = new LinkedList<>(); 69.68 Collections.addAll(argList, args); 69.69 69.70 - final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); 69.71 - if (extra != null) { 69.72 - final StringTokenizer st = new StringTokenizer(extra); 69.73 - while (st.hasMoreTokens()) { 69.74 - argList.add(st.nextToken()); 69.75 + final String extra = getStringProperty(NASHORN_ARGS_PROPERTY, null); 69.76 + if (extra != null) { 69.77 + final StringTokenizer st = new StringTokenizer(extra); 69.78 + while (st.hasMoreTokens()) { 69.79 + argList.add(st.nextToken()); 69.80 + } 69.81 } 69.82 - } 69.83 69.84 while (!argList.isEmpty()) { 69.85 final String arg = argList.remove(0); 69.86 @@ -418,8 +431,9 @@ 69.87 continue; 69.88 } 69.89 69.90 - // if it doesn't start with -, it's a file 69.91 - if (!arg.startsWith("-")) { 69.92 + // If it doesn't start with -, it's a file. But, if it is just "-", 69.93 + // then it is a file representing standard input. 69.94 + if (!arg.startsWith("-") || arg.length() == 1) { 69.95 files.add(arg); 69.96 continue; 69.97 } 69.98 @@ -567,15 +581,7 @@ 69.99 private static String definePropPrefix; 69.100 69.101 static { 69.102 - // Without do privileged, under security manager messages can not be 69.103 - // loaded. 69.104 - Options.bundle = AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() { 69.105 - @Override 69.106 - public ResourceBundle run() { 69.107 - return ResourceBundle.getBundle(Options.MESSAGES_RESOURCE, Locale.getDefault()); 69.108 - } 69.109 - }); 69.110 - 69.111 + Options.bundle = ResourceBundle.getBundle(Options.MESSAGES_RESOURCE, Locale.getDefault()); 69.112 Options.validOptions = new TreeSet<>(); 69.113 Options.usage = new HashMap<>(); 69.114
70.1 --- a/src/jdk/nashorn/internal/runtime/resources/Messages.properties Thu Aug 15 09:26:02 2013 -0700 70.2 +++ b/src/jdk/nashorn/internal/runtime/resources/Messages.properties Tue Aug 20 17:46:45 2013 -0700 70.3 @@ -100,7 +100,7 @@ 70.4 type.error.inconsistent.property.descriptor=inconsistent property descriptor 70.5 type.error.bad.default.value=bad default value: {0} 70.6 type.error.function.apply.expects.array=Function.prototype.apply expects an Array for second argument 70.7 -type.error.instanceof.on.non.object=instanceof cannot be used on objects without [[HasInstance]] 70.8 +type.error.instanceof.on.non.object=instanceof must be called with a javascript or java object as the right-hand argument 70.9 type.error.cannot.convert.to.interface=object {0} cannot be converted to {1} due to "{2}" 70.10 type.error.array.reduce.invalid.init=invalid initialValue for Array.prototype.reduce 70.11 type.error.array.reduceright.invalid.init=invalid initialValue for Array.prototype.reduceRight
71.1 --- a/src/jdk/nashorn/tools/Shell.java Thu Aug 15 09:26:02 2013 -0700 71.2 +++ b/src/jdk/nashorn/tools/Shell.java Tue Aug 20 17:46:45 2013 -0700 71.3 @@ -34,8 +34,6 @@ 71.4 import java.io.OutputStream; 71.5 import java.io.PrintStream; 71.6 import java.io.PrintWriter; 71.7 -import java.security.AccessController; 71.8 -import java.security.PrivilegedAction; 71.9 import java.util.List; 71.10 import java.util.Locale; 71.11 import java.util.ResourceBundle; 71.12 @@ -68,18 +66,7 @@ 71.13 /** 71.14 * Shell message bundle. 71.15 */ 71.16 - private static ResourceBundle bundle; 71.17 - 71.18 - static { 71.19 - // Without do privileged, under security manager messages can not be 71.20 - // loaded. 71.21 - bundle = AccessController.doPrivileged(new PrivilegedAction<ResourceBundle>() { 71.22 - @Override 71.23 - public ResourceBundle run() { 71.24 - return ResourceBundle.getBundle(MESSAGE_RESOURCE, Locale.getDefault()); 71.25 - } 71.26 - }); 71.27 - } 71.28 + private static final ResourceBundle bundle = ResourceBundle.getBundle(MESSAGE_RESOURCE, Locale.getDefault()); 71.29 71.30 /** 71.31 * Exit code for command line tool - successful 71.32 @@ -305,6 +292,14 @@ 71.33 71.34 // For each file on the command line. 71.35 for (final String fileName : files) { 71.36 + if ("-".equals(fileName)) { 71.37 + final int res = readEvalPrint(context, global); 71.38 + if (res != SUCCESS) { 71.39 + return res; 71.40 + } 71.41 + continue; 71.42 + } 71.43 + 71.44 final File file = new File(fileName); 71.45 final ScriptFunction script = context.compileScript(new Source(fileName, file.toURI().toURL()), global); 71.46 if (script == null || errors.getNumberOfErrors() != 0) {
72.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 72.2 +++ b/test/script/basic/JDK-8019985.js Tue Aug 20 17:46:45 2013 -0700 72.3 @@ -0,0 +1,50 @@ 72.4 +/* 72.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 72.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 72.7 + * 72.8 + * This code is free software; you can redistribute it and/or modify it 72.9 + * under the terms of the GNU General Public License version 2 only, as 72.10 + * published by the Free Software Foundation. 72.11 + * 72.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 72.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 72.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 72.15 + * version 2 for more details (a copy is included in the LICENSE file that 72.16 + * accompanied this code). 72.17 + * 72.18 + * You should have received a copy of the GNU General Public License version 72.19 + * 2 along with this work; if not, write to the Free Software Foundation, 72.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 72.21 + * 72.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 72.23 + * or visit www.oracle.com if you need additional information or have any 72.24 + * questions. 72.25 + */ 72.26 + 72.27 +/** 72.28 + * JDK-8019985: Date.parse("2000-01-01T00:00:00.Z") should return NaN 72.29 + * 72.30 + * @test 72.31 + * @run 72.32 + */ 72.33 + 72.34 +function testFail(str) { 72.35 + if (!isNaN(Date.parse(str))) { 72.36 + throw new Error("Parsed invalid date string: " + str); 72.37 + } 72.38 +} 72.39 + 72.40 +function testOk(str) { 72.41 + if (isNaN(Date.parse(str))) { 72.42 + throw new Error("Failed to parse valid date string: " + str); 72.43 + } 72.44 +} 72.45 + 72.46 +testFail("2000-01-01T00:00:00.Z"); 72.47 +testFail("2000-01-01T00:00:Z"); 72.48 +testFail("2000-01-01T00:Z"); 72.49 +testFail("2000-01-01T00Z"); 72.50 +testOk("2000-01-01T00:00:00.000Z"); 72.51 +testOk("2000-01-01T00:00:00.0Z"); 72.52 +testOk("2000-01-01T00:00:00Z"); 72.53 +testOk("2000-01-01T00:00Z");
73.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 73.2 +++ b/test/script/basic/JDK-8020355.js Tue Aug 20 17:46:45 2013 -0700 73.3 @@ -0,0 +1,63 @@ 73.4 +/* 73.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 73.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 73.7 + * 73.8 + * This code is free software; you can redistribute it and/or modify it 73.9 + * under the terms of the GNU General Public License version 2 only, as 73.10 + * published by the Free Software Foundation. 73.11 + * 73.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 73.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 73.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 73.15 + * version 2 for more details (a copy is included in the LICENSE file that 73.16 + * accompanied this code). 73.17 + * 73.18 + * You should have received a copy of the GNU General Public License version 73.19 + * 2 along with this work; if not, write to the Free Software Foundation, 73.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 73.21 + * 73.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 73.23 + * or visit www.oracle.com if you need additional information or have any 73.24 + * questions. 73.25 + */ 73.26 + 73.27 +/** 73.28 + * JDK-8020355: bind on built-in constructors don't use bound argument values 73.29 + * 73.30 + * @test 73.31 + * @run 73.32 + */ 73.33 + 73.34 +if (Array.bind(null, 2)().length != 2) { 73.35 + fail("Expected Array.bind(null, 2)().length to be 2"); 73.36 +} 73.37 + 73.38 +if (RegExp.bind(null, "a")().source.length != 1) { 73.39 + fail("Expected RegExp.bind(null, 'a')().source.length to be 1"); 73.40 +} 73.41 + 73.42 +// check user defined functions as well 73.43 + 73.44 +var res = (function(x, y) { return x*y }).bind(null, 20, 30)(); 73.45 +if (res != 600) { 73.46 + fail("Expected 600, but got " + res); 73.47 +} 73.48 + 73.49 +var obj = new ((function(x, y) { this.foo = x*y }).bind({}, 20, 30))(); 73.50 +if (obj.foo != 600) { 73.51 + fail("Expected this.foo = 600, but got " + res); 73.52 +} 73.53 + 73.54 +// try variadic function as well 73.55 + 73.56 +var res = (function() { return arguments[0]*arguments[1] }).bind(null, 20, 30)(); 73.57 +if (res != 600) { 73.58 + fail("Expected 600, but got " + res); 73.59 +} 73.60 + 73.61 +var obj = new ((function(x, y) { this.foo = arguments[0]*arguments[1] }).bind({}, 20, 30))(); 73.62 +if (obj.foo != 600) { 73.63 + fail("Expected this.foo = 600, but got " + res); 73.64 +} 73.65 + 73.66 +
74.1 --- a/test/script/basic/JDK-8020357.js Thu Aug 15 09:26:02 2013 -0700 74.2 +++ b/test/script/basic/JDK-8020357.js Tue Aug 20 17:46:45 2013 -0700 74.3 @@ -33,17 +33,6 @@ 74.4 74.5 var limit = Math.pow(2, UNSIGNED_INT_BITS)/BYTES_PER_INT_32 74.6 74.7 -try { 74.8 - // A value at or under the limit should either succeed if we have 74.9 - // enough heap, or throw an OutOfMemoryError if we don't. 74.10 - Int32Array(limit - 1) 74.11 -} catch(e) { 74.12 - if(!(e instanceof java.lang.OutOfMemoryError)) { 74.13 - // Only print an unexpected result; OutOfMemoryError is expected 74.14 - print(e) 74.15 - } 74.16 -} 74.17 - 74.18 // A value over the limit should throw a RangeError. 74.19 try { 74.20 Int32Array(limit)
75.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 75.2 +++ b/test/script/basic/JDK-8022598.js Tue Aug 20 17:46:45 2013 -0700 75.3 @@ -0,0 +1,56 @@ 75.4 +/* 75.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 75.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 75.7 + * 75.8 + * This code is free software; you can redistribute it and/or modify it 75.9 + * under the terms of the GNU General Public License version 2 only, as 75.10 + * published by the Free Software Foundation. 75.11 + * 75.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 75.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 75.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 75.15 + * version 2 for more details (a copy is included in the LICENSE file that 75.16 + * accompanied this code). 75.17 + * 75.18 + * You should have received a copy of the GNU General Public License version 75.19 + * 2 along with this work; if not, write to the Free Software Foundation, 75.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 75.21 + * 75.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 75.23 + * or visit www.oracle.com if you need additional information or have any 75.24 + * questions. 75.25 + */ 75.26 + 75.27 +/** 75.28 + * JDK-8022598: Object.getPrototypeOf should return null for host objects rather than throwing TypeError 75.29 + * 75.30 + * @test 75.31 + * @run 75.32 + */ 75.33 + 75.34 +// the following should not throw TypeError, just return null instead 75.35 + 75.36 +var proto = Object.getPrototypeOf(new java.lang.Object()); 75.37 +if (proto !== null) { 75.38 + fail("Expected 'null' __proto__ for host objects"); 75.39 +} 75.40 + 75.41 +// on primitive should result in TypeError 75.42 + 75.43 +function checkTypeError(obj) { 75.44 + try { 75.45 + Object.getPrototypeOf(obj); 75.46 + fail("Expected TypeError for Object.getPrototypeOf on " + obj); 75.47 + } catch (e) { 75.48 + if (! (e instanceof TypeError)) { 75.49 + fail("Expected TypeError, but got " + e); 75.50 + } 75.51 + } 75.52 +} 75.53 + 75.54 +checkTypeError(undefined); 75.55 +checkTypeError(null); 75.56 +checkTypeError(3.1415); 75.57 +checkTypeError("hello"); 75.58 +checkTypeError(false); 75.59 +checkTypeError(true);
76.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 76.2 +++ b/test/script/basic/JDK-8022731.js Tue Aug 20 17:46:45 2013 -0700 76.3 @@ -0,0 +1,93 @@ 76.4 +/* 76.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 76.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 76.7 + * 76.8 + * This code is free software; you can redistribute it and/or modify it 76.9 + * under the terms of the GNU General Public License version 2 only, as 76.10 + * published by the Free Software Foundation. 76.11 + * 76.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 76.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 76.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 76.15 + * version 2 for more details (a copy is included in the LICENSE file that 76.16 + * accompanied this code). 76.17 + * 76.18 + * You should have received a copy of the GNU General Public License version 76.19 + * 2 along with this work; if not, write to the Free Software Foundation, 76.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 76.21 + * 76.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 76.23 + * or visit www.oracle.com if you need additional information or have any 76.24 + * questions. 76.25 + */ 76.26 + 76.27 +/** 76.28 + * JDK-8022731: NativeArguments has wrong implementation of isMapped() 76.29 + * 76.30 + * @test 76.31 + * @run 76.32 + */ 76.33 + 76.34 +Object.defineProperty(Object.prototype, "0", {value: "proto"}); 76.35 + 76.36 +function test0(a, b) { 76.37 + Object.defineProperty(arguments, "1", {get: function() { return "get" }}); 76.38 + return arguments[0]; 76.39 +} 76.40 + 76.41 +function test1(a, b) { 76.42 + Object.defineProperty(arguments, "0", {get: function() { return "get" }}); 76.43 + return a; 76.44 +} 76.45 + 76.46 +function test2(a, b) { 76.47 + Object.defineProperty(arguments, "0", {value: "value"}); 76.48 + delete arguments[0]; 76.49 + return a; 76.50 +} 76.51 + 76.52 +function test3(a, b) { 76.53 + arguments[1] = "arg1"; 76.54 + return b; 76.55 +} 76.56 + 76.57 +function test4(a, b) { 76.58 + b = "b"; 76.59 + return arguments[1]; 76.60 +} 76.61 + 76.62 +function test5(a, b) { 76.63 + Object.defineProperty(arguments, "0", {value: "value"}); 76.64 + arguments[0] = "new"; 76.65 + return a; 76.66 +} 76.67 + 76.68 +function test6(a, b) { 76.69 + Object.defineProperty(arguments, "0", {value: "value"}); 76.70 + arguments[0] = "new"; 76.71 + delete arguments[0]; 76.72 + return a; 76.73 +} 76.74 + 76.75 +function test7(a, b) { 76.76 + Object.defineProperty(arguments, "0", {value: "value", writable: false}); 76.77 + arguments[0] = "new"; 76.78 + return a; 76.79 +} 76.80 + 76.81 +print(test0()); 76.82 +print(test0("p1", "p2")); 76.83 +print(test1()); 76.84 +print(test1("p1")); 76.85 +print(test2()); 76.86 +print(test2("p1")); 76.87 +print(test3()); 76.88 +print(test3(1, 2)); 76.89 +print(test4()); 76.90 +print(test4("p1", "p2")); 76.91 +print(test5()); 76.92 +print(test5("p1")); 76.93 +print(test6()); 76.94 +print(test6("p1")); 76.95 +print(test7()); 76.96 +print(test7("p1"));
77.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 77.2 +++ b/test/script/basic/JDK-8022731.js.EXPECTED Tue Aug 20 17:46:45 2013 -0700 77.3 @@ -0,0 +1,16 @@ 77.4 +proto 77.5 +p1 77.6 +undefined 77.7 +p1 77.8 +undefined 77.9 +value 77.10 +undefined 77.11 +arg1 77.12 +undefined 77.13 +b 77.14 +undefined 77.15 +new 77.16 +undefined 77.17 +new 77.18 +undefined 77.19 +value
78.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 78.2 +++ b/test/script/basic/JDK-8023026.js Tue Aug 20 17:46:45 2013 -0700 78.3 @@ -0,0 +1,71 @@ 78.4 +/* 78.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 78.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 78.7 + * 78.8 + * This code is free software; you can redistribute it and/or modify it 78.9 + * under the terms of the GNU General Public License version 2 only, as 78.10 + * published by the Free Software Foundation. 78.11 + * 78.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 78.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 78.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 78.15 + * version 2 for more details (a copy is included in the LICENSE file that 78.16 + * accompanied this code). 78.17 + * 78.18 + * You should have received a copy of the GNU General Public License version 78.19 + * 2 along with this work; if not, write to the Free Software Foundation, 78.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 78.21 + * 78.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 78.23 + * or visit www.oracle.com if you need additional information or have any 78.24 + * questions. 78.25 + */ 78.26 + 78.27 +/** 78.28 + * JDK-8023026: Array.prototype iterator functions like forEach, reduce should work for Java arrays, lists 78.29 + * 78.30 + * @test 78.31 + * @run 78.32 + */ 78.33 + 78.34 +function checkIterations(obj) { 78.35 + if (typeof obj.getClass == 'function') { 78.36 + print("iterating on an object of " + obj.getClass()); 78.37 + } else { 78.38 + print("iterating on " + String(obj)); 78.39 + } 78.40 + 78.41 + Array.prototype.forEach.call(obj, 78.42 + function(x) { print("forEach " + x); }); 78.43 + 78.44 + print("left sum " + Array.prototype.reduce.call(obj, 78.45 + function(x, y) { print("reduce", x, y); return x + y; })); 78.46 + 78.47 + print("right sum " + Array.prototype.reduceRight.call(obj, 78.48 + function(x, y) { print("reduceRight", x, y); return x + y; })); 78.49 + 78.50 + print("squared " + Array.prototype.map.call(obj, 78.51 + function(x) x*x)); 78.52 +} 78.53 + 78.54 +var array = new (Java.type("[I"))(4); 78.55 +for (var i in array) { 78.56 + array[i] = i; 78.57 +} 78.58 + 78.59 +checkIterations(array); 78.60 + 78.61 +var list = new java.util.ArrayList(); 78.62 +list.add(1); 78.63 +list.add(3); 78.64 +list.add(5); 78.65 +list.add(7); 78.66 + 78.67 +checkIterations(list); 78.68 + 78.69 +var mirror = loadWithNewGlobal({ 78.70 + name: "test", 78.71 + script: "[2, 4, 6, 8]" 78.72 +}); 78.73 + 78.74 +checkIterations(mirror);
79.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 79.2 +++ b/test/script/basic/JDK-8023026.js.EXPECTED Tue Aug 20 17:46:45 2013 -0700 79.3 @@ -0,0 +1,42 @@ 79.4 +iterating on an object of class [I 79.5 +forEach 0 79.6 +forEach 1 79.7 +forEach 2 79.8 +forEach 3 79.9 +reduce 0 1 79.10 +reduce 1 2 79.11 +reduce 3 3 79.12 +left sum 6 79.13 +reduceRight 3 2 79.14 +reduceRight 5 1 79.15 +reduceRight 6 0 79.16 +right sum 6 79.17 +squared 0,1,4,9 79.18 +iterating on an object of class java.util.ArrayList 79.19 +forEach 1 79.20 +forEach 3 79.21 +forEach 5 79.22 +forEach 7 79.23 +reduce 1 3 79.24 +reduce 4 5 79.25 +reduce 9 7 79.26 +left sum 16 79.27 +reduceRight 7 5 79.28 +reduceRight 12 3 79.29 +reduceRight 15 1 79.30 +right sum 16 79.31 +squared 1,9,25,49 79.32 +iterating on [object Array] 79.33 +forEach 2 79.34 +forEach 4 79.35 +forEach 6 79.36 +forEach 8 79.37 +reduce 2 4 79.38 +reduce 6 6 79.39 +reduce 12 8 79.40 +left sum 20 79.41 +reduceRight 8 6 79.42 +reduceRight 14 4 79.43 +reduceRight 18 2 79.44 +right sum 20 79.45 +squared 4,16,36,64
80.1 --- a/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Thu Aug 15 09:26:02 2013 -0700 80.2 +++ b/test/src/jdk/nashorn/api/javaaccess/BooleanAccessTest.java Tue Aug 20 17:46:45 2013 -0700 80.3 @@ -33,6 +33,7 @@ 80.4 import javax.script.ScriptEngineManager; 80.5 import javax.script.ScriptException; 80.6 import org.testng.TestNG; 80.7 +import org.testng.annotations.AfterClass; 80.8 import org.testng.annotations.BeforeClass; 80.9 import org.testng.annotations.Test; 80.10 80.11 @@ -44,7 +45,7 @@ 80.12 public class BooleanAccessTest { 80.13 80.14 private static ScriptEngine e = null; 80.15 - private static SharedObject o = new SharedObject(); 80.16 + private static SharedObject o = null; 80.17 80.18 public static void main(final String[] args) { 80.19 TestNG.main(args); 80.20 @@ -54,10 +55,17 @@ 80.21 public static void setUpClass() throws ScriptException { 80.22 final ScriptEngineManager m = new ScriptEngineManager(); 80.23 e = m.getEngineByName("nashorn"); 80.24 + o = new SharedObject(); 80.25 e.put("o", o); 80.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 80.27 } 80.28 80.29 + @AfterClass 80.30 + public static void tearDownClass() { 80.31 + e = null; 80.32 + o = null; 80.33 + } 80.34 + 80.35 @Test 80.36 public void accessFieldBoolean() throws ScriptException { 80.37 e.eval("var p_boolean = o.publicBoolean;");
81.1 --- a/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Thu Aug 15 09:26:02 2013 -0700 81.2 +++ b/test/src/jdk/nashorn/api/javaaccess/MethodAccessTest.java Tue Aug 20 17:46:45 2013 -0700 81.3 @@ -36,6 +36,7 @@ 81.4 import javax.script.ScriptEngineManager; 81.5 import javax.script.ScriptException; 81.6 import org.testng.TestNG; 81.7 +import org.testng.annotations.AfterClass; 81.8 import org.testng.annotations.BeforeClass; 81.9 import org.testng.annotations.Test; 81.10 81.11 @@ -47,7 +48,7 @@ 81.12 public class MethodAccessTest { 81.13 81.14 private static ScriptEngine e = null; 81.15 - private static SharedObject o = new SharedObject(); 81.16 + private static SharedObject o = null; 81.17 81.18 public static void main(final String[] args) { 81.19 TestNG.main(args); 81.20 @@ -57,12 +58,19 @@ 81.21 public static void setUpClass() throws ScriptException { 81.22 final ScriptEngineManager m = new ScriptEngineManager(); 81.23 e = m.getEngineByName("nashorn"); 81.24 + o = new SharedObject(); 81.25 o.setEngine(e); 81.26 e.put("o", o); 81.27 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 81.28 e.eval("var Person = Packages.jdk.nashorn.api.javaaccess.Person;"); 81.29 } 81.30 81.31 + @AfterClass 81.32 + public static void tearDownClass() { 81.33 + e = null; 81.34 + o = null; 81.35 + } 81.36 + 81.37 @Test 81.38 public void accessMethodthrowsCheckedException() throws ScriptException { 81.39 e.eval("try {" +
82.1 --- a/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Thu Aug 15 09:26:02 2013 -0700 82.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberAccessTest.java Tue Aug 20 17:46:45 2013 -0700 82.3 @@ -33,6 +33,7 @@ 82.4 import javax.script.ScriptEngineManager; 82.5 import javax.script.ScriptException; 82.6 import org.testng.TestNG; 82.7 +import org.testng.annotations.AfterClass; 82.8 import org.testng.annotations.BeforeClass; 82.9 import org.testng.annotations.Test; 82.10 82.11 @@ -44,7 +45,7 @@ 82.12 public class NumberAccessTest { 82.13 82.14 private static ScriptEngine e = null; 82.15 - private static SharedObject o = new SharedObject(); 82.16 + private static SharedObject o = null; 82.17 82.18 public static void main(final String[] args) { 82.19 TestNG.main(args); 82.20 @@ -54,10 +55,17 @@ 82.21 public static void setUpClass() throws ScriptException { 82.22 final ScriptEngineManager m = new ScriptEngineManager(); 82.23 e = m.getEngineByName("nashorn"); 82.24 + o = new SharedObject(); 82.25 e.put("o", o); 82.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 82.27 } 82.28 82.29 + @AfterClass 82.30 + public static void tearDownClass() { 82.31 + e = null; 82.32 + o = null; 82.33 + } 82.34 + 82.35 // --------------------------------long 82.36 // tests------------------------------------ 82.37 @Test
83.1 --- a/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Thu Aug 15 09:26:02 2013 -0700 83.2 +++ b/test/src/jdk/nashorn/api/javaaccess/NumberBoxingTest.java Tue Aug 20 17:46:45 2013 -0700 83.3 @@ -32,6 +32,7 @@ 83.4 import javax.script.ScriptEngineManager; 83.5 import javax.script.ScriptException; 83.6 import org.testng.TestNG; 83.7 +import org.testng.annotations.AfterClass; 83.8 import org.testng.annotations.BeforeClass; 83.9 import org.testng.annotations.Test; 83.10 83.11 @@ -43,7 +44,7 @@ 83.12 public class NumberBoxingTest { 83.13 83.14 private static ScriptEngine e = null; 83.15 - private static SharedObject o = new SharedObject(); 83.16 + private static SharedObject o = null; 83.17 83.18 public static void main(final String[] args) { 83.19 TestNG.main(args); 83.20 @@ -53,10 +54,17 @@ 83.21 public static void setUpClass() throws ScriptException { 83.22 final ScriptEngineManager m = new ScriptEngineManager(); 83.23 e = m.getEngineByName("nashorn"); 83.24 + o = new SharedObject(); 83.25 e.put("o", o); 83.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 83.27 } 83.28 83.29 + @AfterClass 83.30 + public static void tearDownClass() { 83.31 + e = null; 83.32 + o = null; 83.33 + } 83.34 + 83.35 // --------------------------------long 83.36 // tests------------------------------------ 83.37 @Test
84.1 --- a/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Thu Aug 15 09:26:02 2013 -0700 84.2 +++ b/test/src/jdk/nashorn/api/javaaccess/ObjectAccessTest.java Tue Aug 20 17:46:45 2013 -0700 84.3 @@ -32,6 +32,7 @@ 84.4 import javax.script.ScriptEngineManager; 84.5 import javax.script.ScriptException; 84.6 import org.testng.TestNG; 84.7 +import org.testng.annotations.AfterClass; 84.8 import org.testng.annotations.BeforeClass; 84.9 import org.testng.annotations.Test; 84.10 84.11 @@ -43,7 +44,7 @@ 84.12 public class ObjectAccessTest { 84.13 84.14 private static ScriptEngine e = null; 84.15 - private static SharedObject o = new SharedObject(); 84.16 + private static SharedObject o = null; 84.17 84.18 public static void main(final String[] args) { 84.19 TestNG.main(args); 84.20 @@ -53,11 +54,18 @@ 84.21 public static void setUpClass() throws ScriptException { 84.22 final ScriptEngineManager m = new ScriptEngineManager(); 84.23 e = m.getEngineByName("nashorn"); 84.24 + o = new SharedObject(); 84.25 e.put("o", o); 84.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 84.27 e.eval("var Person = Packages.jdk.nashorn.api.javaaccess.Person;"); 84.28 } 84.29 84.30 + @AfterClass 84.31 + public static void tearDownClass() { 84.32 + e = null; 84.33 + o = null; 84.34 + } 84.35 + 84.36 @Test 84.37 public void accessFieldObject() throws ScriptException { 84.38 e.eval("var p_object = o.publicObject;");
85.1 --- a/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Thu Aug 15 09:26:02 2013 -0700 85.2 +++ b/test/src/jdk/nashorn/api/javaaccess/StringAccessTest.java Tue Aug 20 17:46:45 2013 -0700 85.3 @@ -32,6 +32,7 @@ 85.4 import javax.script.ScriptEngineManager; 85.5 import javax.script.ScriptException; 85.6 import org.testng.TestNG; 85.7 +import org.testng.annotations.AfterClass; 85.8 import org.testng.annotations.BeforeClass; 85.9 import org.testng.annotations.Test; 85.10 85.11 @@ -43,7 +44,7 @@ 85.12 public class StringAccessTest { 85.13 85.14 private static ScriptEngine e = null; 85.15 - private static SharedObject o = new SharedObject(); 85.16 + private static SharedObject o = null; 85.17 85.18 public static void main(final String[] args) { 85.19 TestNG.main(args); 85.20 @@ -53,10 +54,17 @@ 85.21 public static void setUpClass() throws ScriptException { 85.22 final ScriptEngineManager m = new ScriptEngineManager(); 85.23 e = m.getEngineByName("nashorn"); 85.24 + o = new SharedObject(); 85.25 e.put("o", o); 85.26 e.eval("var SharedObject = Packages.jdk.nashorn.api.javaaccess.SharedObject;"); 85.27 } 85.28 85.29 + @AfterClass 85.30 + public static void tearDownClass() { 85.31 + e = null; 85.32 + o = null; 85.33 + } 85.34 + 85.35 @Test 85.36 public void accessFieldString() throws ScriptException { 85.37 e.eval("var p_string = o.publicString;");
86.1 --- a/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java Thu Aug 15 09:26:02 2013 -0700 86.2 +++ b/test/src/jdk/nashorn/api/scripting/ScriptEngineTest.java Tue Aug 20 17:46:45 2013 -0700 86.3 @@ -1235,7 +1235,8 @@ 86.4 fail(t.getMessage()); 86.5 } 86.6 86.7 - assertEquals(sw.toString(), "hello\n"); 86.8 + // dos2unix - fix line endings if running on windows 86.9 + assertEquals(sw.toString().replaceAll("\r", ""), "hello\n"); 86.10 } 86.11 86.12 @Test 86.13 @@ -1252,6 +1253,7 @@ 86.14 fail(t.getMessage()); 86.15 } 86.16 86.17 - assertEquals(sw.toString(), "34 true hello\n"); 86.18 + // dos2unix - fix line endings if running on windows 86.19 + assertEquals(sw.toString().replaceAll("\r", ""), "34 true hello\n"); 86.20 } 86.21 }
87.1 --- a/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Thu Aug 15 09:26:02 2013 -0700 87.2 +++ b/test/src/jdk/nashorn/internal/codegen/CompilerTest.java Tue Aug 20 17:46:45 2013 -0700 87.3 @@ -35,6 +35,8 @@ 87.4 import jdk.nashorn.internal.runtime.Source; 87.5 import jdk.nashorn.internal.runtime.options.Options; 87.6 import org.testng.Assert; 87.7 +import org.testng.annotations.AfterClass; 87.8 +import org.testng.annotations.BeforeClass; 87.9 import org.testng.annotations.Test; 87.10 87.11 /** 87.12 @@ -58,7 +60,8 @@ 87.13 private Context context; 87.14 private ScriptObject global; 87.15 87.16 - public CompilerTest() { 87.17 + @BeforeClass 87.18 + public void setupTest() { 87.19 final Options options = new Options("nashorn"); 87.20 options.set("anon.functions", true); 87.21 options.set("compile.only", true); 87.22 @@ -79,6 +82,12 @@ 87.23 this.global = context.createGlobal(); 87.24 } 87.25 87.26 + @AfterClass 87.27 + public void tearDownTest() { 87.28 + this.context = null; 87.29 + this.global = null; 87.30 + } 87.31 + 87.32 @Test 87.33 public void compileAllTests() { 87.34 if (TEST262) {
88.1 --- a/test/src/jdk/nashorn/internal/parser/ParserTest.java Thu Aug 15 09:26:02 2013 -0700 88.2 +++ b/test/src/jdk/nashorn/internal/parser/ParserTest.java Tue Aug 20 17:46:45 2013 -0700 88.3 @@ -28,10 +28,11 @@ 88.4 import java.io.File; 88.5 import jdk.nashorn.internal.runtime.Context; 88.6 import jdk.nashorn.internal.runtime.ErrorManager; 88.7 -import jdk.nashorn.internal.runtime.ScriptObject; 88.8 import jdk.nashorn.internal.runtime.Source; 88.9 import jdk.nashorn.internal.runtime.options.Options; 88.10 import org.testng.Assert; 88.11 +import org.testng.annotations.AfterClass; 88.12 +import org.testng.annotations.BeforeClass; 88.13 import org.testng.annotations.Test; 88.14 88.15 /** 88.16 @@ -54,9 +55,9 @@ 88.17 } 88.18 88.19 private Context context; 88.20 - private ScriptObject global; 88.21 88.22 - public ParserTest() { 88.23 + @BeforeClass 88.24 + public void setupTest() { 88.25 final Options options = new Options("nashorn"); 88.26 options.set("anon.functions", true); 88.27 options.set("parse.only", true); 88.28 @@ -64,7 +65,11 @@ 88.29 88.30 ErrorManager errors = new ErrorManager(); 88.31 this.context = new Context(options, errors, Thread.currentThread().getContextClassLoader()); 88.32 - this.global = context.createGlobal(); 88.33 + } 88.34 + 88.35 + @AfterClass 88.36 + public void tearDownTest() { 88.37 + this.context = null; 88.38 } 88.39 88.40 @Test 88.41 @@ -125,8 +130,6 @@ 88.42 log("Begin parsing " + file.getAbsolutePath()); 88.43 } 88.44 88.45 - final ScriptObject oldGlobal = Context.getGlobal(); 88.46 - final boolean globalChanged = (oldGlobal != global); 88.47 try { 88.48 final char[] buffer = Source.readFully(file); 88.49 boolean excluded = false; 88.50 @@ -150,9 +153,6 @@ 88.51 } 88.52 }; 88.53 errors.setLimit(0); 88.54 - if (globalChanged) { 88.55 - Context.setGlobal(global); 88.56 - } 88.57 final Source source = new Source(file.getAbsolutePath(), buffer); 88.58 new Parser(context.getEnv(), source, errors).parse(); 88.59 if (errors.getNumberOfErrors() > 0) { 88.60 @@ -167,10 +167,6 @@ 88.61 exp.printStackTrace(System.out); 88.62 } 88.63 failed++; 88.64 - } finally { 88.65 - if (globalChanged) { 88.66 - Context.setGlobal(oldGlobal); 88.67 - } 88.68 } 88.69 88.70 if (VERBOSE) {