Wed, 09 Sep 2015 17:19:46 +0530
8027137: Merge ScriptFunction and ScriptFunctionImpl
Reviewed-by: attila, hannesw, mhaupt
1.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Thu Sep 10 09:59:23 2015 +0530 1.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ClassGenerator.java Wed Sep 09 17:19:46 2015 +0530 1.3 @@ -54,10 +54,9 @@ 1.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP; 1.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_NEWMAP_DESC; 1.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROPERTYMAP_TYPE; 1.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION; 1.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC; 1.9 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC; 1.10 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_TYPE; 1.11 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_CREATEBUILTIN; 1.12 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_CREATEBUILTIN_DESC; 1.13 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_CREATEBUILTIN_SPECS_DESC; 1.14 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_SETARITY; 1.15 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_SETARITY_DESC; 1.16 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_TYPE; 1.17 @@ -282,9 +281,9 @@ 1.18 assert specs != null; 1.19 if (!specs.isEmpty()) { 1.20 mi.memberInfoArray(className, specs); 1.21 - mi.invokeStatic(SCRIPTFUNCTIONIMPL_TYPE, SCRIPTFUNCTIONIMPL_MAKEFUNCTION, SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC); 1.22 + mi.invokeStatic(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_CREATEBUILTIN, SCRIPTFUNCTION_CREATEBUILTIN_SPECS_DESC); 1.23 } else { 1.24 - mi.invokeStatic(SCRIPTFUNCTIONIMPL_TYPE, SCRIPTFUNCTIONIMPL_MAKEFUNCTION, SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC); 1.25 + mi.invokeStatic(SCRIPTFUNCTION_TYPE, SCRIPTFUNCTION_CREATEBUILTIN, SCRIPTFUNCTION_CREATEBUILTIN_DESC); 1.26 } 1.27 1.28 if (arityFound) {
2.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Thu Sep 10 09:59:23 2015 +0530 2.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/ConstructorGenerator.java Wed Sep 09 17:19:46 2015 +0530 2.3 @@ -38,9 +38,8 @@ 2.4 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR; 2.5 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_SETCONSTRUCTOR_DESC; 2.6 import static jdk.nashorn.internal.tools.nasgen.StringConstants.PROTOTYPEOBJECT_TYPE; 2.7 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_INIT_DESC3; 2.8 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_INIT_DESC4; 2.9 -import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTIONIMPL_TYPE; 2.10 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_INIT_DESC3; 2.11 +import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_INIT_DESC4; 2.12 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_SETARITY; 2.13 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_SETARITY_DESC; 2.14 import static jdk.nashorn.internal.tools.nasgen.StringConstants.SCRIPTFUNCTION_SETPROTOTYPE; 2.15 @@ -76,7 +75,7 @@ 2.16 2.17 byte[] getClassBytes() { 2.18 // new class extending from ScriptObject 2.19 - final String superClass = (constructor != null)? SCRIPTFUNCTIONIMPL_TYPE : SCRIPTOBJECT_TYPE; 2.20 + final String superClass = (constructor != null)? SCRIPTFUNCTION_TYPE : SCRIPTOBJECT_TYPE; 2.21 cw.visit(V1_7, ACC_FINAL, className, null, superClass, null); 2.22 if (memberCount > 0) { 2.23 // add fields 2.24 @@ -182,8 +181,8 @@ 2.25 loadMap(mi); 2.26 } else { 2.27 // call Function.<init> 2.28 - superClass = SCRIPTFUNCTIONIMPL_TYPE; 2.29 - superDesc = (memberCount > 0) ? SCRIPTFUNCTIONIMPL_INIT_DESC4 : SCRIPTFUNCTIONIMPL_INIT_DESC3; 2.30 + superClass = SCRIPTFUNCTION_TYPE; 2.31 + superDesc = (memberCount > 0) ? SCRIPTFUNCTION_INIT_DESC4 : SCRIPTFUNCTION_INIT_DESC3; 2.32 mi.loadLiteral(constructor.getName()); 2.33 mi.visitLdcInsn(new Handle(H_INVOKESTATIC, scriptClassInfo.getJavaName(), constructor.getJavaName(), constructor.getJavaDesc())); 2.34 loadMap(mi);
3.1 --- a/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Thu Sep 10 09:59:23 2015 +0530 3.2 +++ b/buildtools/nasgen/src/jdk/nashorn/internal/tools/nasgen/StringConstants.java Wed Sep 09 17:19:46 2015 +0530 3.3 @@ -31,10 +31,9 @@ 3.4 import java.util.Collections; 3.5 import java.util.List; 3.6 import jdk.internal.org.objectweb.asm.Type; 3.7 -import jdk.nashorn.internal.objects.PrototypeObject; 3.8 -import jdk.nashorn.internal.objects.ScriptFunctionImpl; 3.9 import jdk.nashorn.internal.runtime.AccessorProperty; 3.10 import jdk.nashorn.internal.runtime.PropertyMap; 3.11 +import jdk.nashorn.internal.runtime.PrototypeObject; 3.12 import jdk.nashorn.internal.runtime.ScriptFunction; 3.13 import jdk.nashorn.internal.runtime.ScriptObject; 3.14 import jdk.nashorn.internal.runtime.Specialization; 3.15 @@ -88,7 +87,6 @@ 3.16 static final Type TYPE_PROPERTYMAP = Type.getType(PropertyMap.class); 3.17 static final Type TYPE_PROTOTYPEOBJECT = Type.getType(PrototypeObject.class); 3.18 static final Type TYPE_SCRIPTFUNCTION = Type.getType(ScriptFunction.class); 3.19 - static final Type TYPE_SCRIPTFUNCTIONIMPL = Type.getType(ScriptFunctionImpl.class); 3.20 static final Type TYPE_SCRIPTOBJECT = Type.getType(ScriptObject.class); 3.21 3.22 static final String PROTOTYPE_SUFFIX = "$Prototype"; 3.23 @@ -122,17 +120,14 @@ 3.24 static final String SCRIPTFUNCTION_SETARITY_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, Type.INT_TYPE); 3.25 static final String SCRIPTFUNCTION_SETPROTOTYPE = "setPrototype"; 3.26 static final String SCRIPTFUNCTION_SETPROTOTYPE_DESC = Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_OBJECT); 3.27 - 3.28 - // ScriptFunctionImpl 3.29 - static final String SCRIPTFUNCTIONIMPL_TYPE = TYPE_SCRIPTFUNCTIONIMPL.getInternalName(); 3.30 - static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION = "makeFunction"; 3.31 - static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_DESC = 3.32 + static final String SCRIPTFUNCTION_CREATEBUILTIN = "createBuiltin"; 3.33 + static final String SCRIPTFUNCTION_CREATEBUILTIN_DESC = 3.34 Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE); 3.35 - static final String SCRIPTFUNCTIONIMPL_MAKEFUNCTION_SPECS_DESC = 3.36 + static final String SCRIPTFUNCTION_CREATEBUILTIN_SPECS_DESC = 3.37 Type.getMethodDescriptor(TYPE_SCRIPTFUNCTION, TYPE_STRING, TYPE_METHODHANDLE, TYPE_SPECIALIZATION_ARRAY); 3.38 - static final String SCRIPTFUNCTIONIMPL_INIT_DESC3 = 3.39 + static final String SCRIPTFUNCTION_INIT_DESC3 = 3.40 Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_SPECIALIZATION_ARRAY); 3.41 - static final String SCRIPTFUNCTIONIMPL_INIT_DESC4 = 3.42 + static final String SCRIPTFUNCTION_INIT_DESC4 = 3.43 Type.getMethodDescriptor(Type.VOID_TYPE, TYPE_STRING, TYPE_METHODHANDLE, TYPE_PROPERTYMAP, TYPE_SPECIALIZATION_ARRAY); 3.44 3.45 // ScriptObject
4.1 --- a/src/jdk/nashorn/api/scripting/ScriptUtils.java Thu Sep 10 09:59:23 2015 +0530 4.2 +++ b/src/jdk/nashorn/api/scripting/ScriptUtils.java Wed Sep 09 17:19:46 2015 +0530 4.3 @@ -79,7 +79,7 @@ 4.4 * @return a synchronizing wrapper function 4.5 */ 4.6 public static Object makeSynchronizedFunction(final ScriptFunction func, final Object sync) { 4.7 - return func.makeSynchronizedFunction(unwrap(sync)); 4.8 + return func.createSynchronized(unwrap(sync)); 4.9 } 4.10 4.11 /**
5.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java Thu Sep 10 09:59:23 2015 +0530 5.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java Wed Sep 09 17:19:46 2015 +0530 5.3 @@ -132,7 +132,6 @@ 5.4 import jdk.nashorn.internal.ir.visitor.NodeOperatorVisitor; 5.5 import jdk.nashorn.internal.ir.visitor.NodeVisitor; 5.6 import jdk.nashorn.internal.objects.Global; 5.7 -import jdk.nashorn.internal.objects.ScriptFunctionImpl; 5.8 import jdk.nashorn.internal.parser.Lexer.RegexToken; 5.9 import jdk.nashorn.internal.parser.TokenType; 5.10 import jdk.nashorn.internal.runtime.Context; 5.11 @@ -195,9 +194,9 @@ 5.12 private static final Call ENSURE_NUMBER = CompilerConstants.staticCallNoLookup(OptimisticReturnFilters.class, 5.13 "ensureNumber", double.class, Object.class, int.class); 5.14 5.15 - private static final Call CREATE_FUNCTION_OBJECT = CompilerConstants.staticCallNoLookup(ScriptFunctionImpl.class, 5.16 + private static final Call CREATE_FUNCTION_OBJECT = CompilerConstants.staticCallNoLookup(ScriptFunction.class, 5.17 "create", ScriptFunction.class, Object[].class, int.class, ScriptObject.class); 5.18 - private static final Call CREATE_FUNCTION_OBJECT_NO_SCOPE = CompilerConstants.staticCallNoLookup(ScriptFunctionImpl.class, 5.19 + private static final Call CREATE_FUNCTION_OBJECT_NO_SCOPE = CompilerConstants.staticCallNoLookup(ScriptFunction.class, 5.20 "create", ScriptFunction.class, Object[].class, int.class); 5.21 5.22 private static final Call TO_NUMBER_FOR_EQ = CompilerConstants.staticCallNoLookup(JSType.class,
6.1 --- a/src/jdk/nashorn/internal/objects/BoundScriptFunctionImpl.java Thu Sep 10 09:59:23 2015 +0530 6.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 6.3 @@ -1,51 +0,0 @@ 6.4 -/* 6.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 6.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 6.7 - * 6.8 - * This code is free software; you can redistribute it and/or modify it 6.9 - * under the terms of the GNU General Public License version 2 only, as 6.10 - * published by the Free Software Foundation. Oracle designates this 6.11 - * particular file as subject to the "Classpath" exception as provided 6.12 - * by Oracle in the LICENSE file that accompanied this code. 6.13 - * 6.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 6.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 6.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 6.17 - * version 2 for more details (a copy is included in the LICENSE file that 6.18 - * accompanied this code). 6.19 - * 6.20 - * You should have received a copy of the GNU General Public License version 6.21 - * 2 along with this work; if not, write to the Free Software Foundation, 6.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 6.23 - * 6.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 6.25 - * or visit www.oracle.com if you need additional information or have any 6.26 - * questions. 6.27 - */ 6.28 - 6.29 -package jdk.nashorn.internal.objects; 6.30 - 6.31 -import jdk.nashorn.internal.runtime.ScriptFunction; 6.32 -import jdk.nashorn.internal.runtime.ScriptFunctionData; 6.33 -import jdk.nashorn.internal.runtime.ScriptObject; 6.34 -import jdk.nashorn.internal.runtime.ScriptRuntime; 6.35 - 6.36 -/** 6.37 - * A {@code ScriptFunctionImpl} subclass for functions created using {@code Function.prototype.bind}. Such functions 6.38 - * must track their {@code [[TargetFunction]]} property for purposes of correctly implementing {@code [[HasInstance]]}; 6.39 - * see {@link ScriptFunction#isInstance(ScriptObject)}. 6.40 - */ 6.41 -final class BoundScriptFunctionImpl extends ScriptFunctionImpl { 6.42 - private final ScriptFunction targetFunction; 6.43 - 6.44 - BoundScriptFunctionImpl(final ScriptFunctionData data, final ScriptFunction targetFunction) { 6.45 - super(data, Global.instance()); 6.46 - setPrototype(ScriptRuntime.UNDEFINED); 6.47 - this.targetFunction = targetFunction; 6.48 - } 6.49 - 6.50 - @Override 6.51 - protected ScriptFunction getTargetFunction() { 6.52 - return targetFunction; 6.53 - } 6.54 -}
7.1 --- a/src/jdk/nashorn/internal/objects/Global.java Thu Sep 10 09:59:23 2015 +0530 7.2 +++ b/src/jdk/nashorn/internal/objects/Global.java Wed Sep 09 17:19:46 2015 +0530 7.3 @@ -1583,7 +1583,11 @@ 7.4 return ScriptFunction.getPrototype(builtinObject); 7.5 } 7.6 7.7 - ScriptObject getFunctionPrototype() { 7.8 + /** 7.9 + * Get the builtin Function prototype. 7.10 + * @return the Function.prototype. 7.11 + */ 7.12 + public ScriptObject getFunctionPrototype() { 7.13 return ScriptFunction.getPrototype(builtinFunction); 7.14 } 7.15 7.16 @@ -1768,7 +1772,12 @@ 7.17 return ScriptFunction.getPrototype(getBuiltinFloat64Array()); 7.18 } 7.19 7.20 - ScriptFunction getTypeErrorThrower() { 7.21 + /** 7.22 + * Return the function that throws TypeError unconditionally. Used as "poison" methods for certain Function properties. 7.23 + * 7.24 + * @return the TypeError throwing function 7.25 + */ 7.26 + public ScriptFunction getTypeErrorThrower() { 7.27 return typeErrorThrower; 7.28 } 7.29 7.30 @@ -2202,10 +2211,10 @@ 7.31 * Adds jjs shell interactive mode builtin functions to global scope. 7.32 */ 7.33 public void addShellBuiltins() { 7.34 - Object value = ScriptFunctionImpl.makeFunction("input", ShellFunctions.INPUT); 7.35 + Object value = ScriptFunction.createBuiltin("input", ShellFunctions.INPUT); 7.36 addOwnProperty("input", Attribute.NOT_ENUMERABLE, value); 7.37 7.38 - value = ScriptFunctionImpl.makeFunction("evalinput", ShellFunctions.EVALINPUT); 7.39 + value = ScriptFunction.createBuiltin("evalinput", ShellFunctions.EVALINPUT); 7.40 addOwnProperty("evalinput", Attribute.NOT_ENUMERABLE, value); 7.41 } 7.42 7.43 @@ -2252,35 +2261,35 @@ 7.44 this.setInitialProto(getObjectPrototype()); 7.45 7.46 // initialize global function properties 7.47 - this.eval = this.builtinEval = ScriptFunctionImpl.makeFunction("eval", EVAL); 7.48 - 7.49 - this.parseInt = ScriptFunctionImpl.makeFunction("parseInt", GlobalFunctions.PARSEINT, 7.50 + this.eval = this.builtinEval = ScriptFunction.createBuiltin("eval", EVAL); 7.51 + 7.52 + this.parseInt = ScriptFunction.createBuiltin("parseInt", GlobalFunctions.PARSEINT, 7.53 new Specialization[] { 7.54 new Specialization(GlobalFunctions.PARSEINT_Z), 7.55 new Specialization(GlobalFunctions.PARSEINT_I), 7.56 new Specialization(GlobalFunctions.PARSEINT_J), 7.57 new Specialization(GlobalFunctions.PARSEINT_OI), 7.58 new Specialization(GlobalFunctions.PARSEINT_O) }); 7.59 - this.parseFloat = ScriptFunctionImpl.makeFunction("parseFloat", GlobalFunctions.PARSEFLOAT); 7.60 - this.isNaN = ScriptFunctionImpl.makeFunction("isNaN", GlobalFunctions.IS_NAN, 7.61 + this.parseFloat = ScriptFunction.createBuiltin("parseFloat", GlobalFunctions.PARSEFLOAT); 7.62 + this.isNaN = ScriptFunction.createBuiltin("isNaN", GlobalFunctions.IS_NAN, 7.63 new Specialization[] { 7.64 new Specialization(GlobalFunctions.IS_NAN_I), 7.65 new Specialization(GlobalFunctions.IS_NAN_J), 7.66 new Specialization(GlobalFunctions.IS_NAN_D) }); 7.67 - this.parseFloat = ScriptFunctionImpl.makeFunction("parseFloat", GlobalFunctions.PARSEFLOAT); 7.68 - this.isNaN = ScriptFunctionImpl.makeFunction("isNaN", GlobalFunctions.IS_NAN); 7.69 - this.isFinite = ScriptFunctionImpl.makeFunction("isFinite", GlobalFunctions.IS_FINITE); 7.70 - this.encodeURI = ScriptFunctionImpl.makeFunction("encodeURI", GlobalFunctions.ENCODE_URI); 7.71 - this.encodeURIComponent = ScriptFunctionImpl.makeFunction("encodeURIComponent", GlobalFunctions.ENCODE_URICOMPONENT); 7.72 - this.decodeURI = ScriptFunctionImpl.makeFunction("decodeURI", GlobalFunctions.DECODE_URI); 7.73 - this.decodeURIComponent = ScriptFunctionImpl.makeFunction("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT); 7.74 - this.escape = ScriptFunctionImpl.makeFunction("escape", GlobalFunctions.ESCAPE); 7.75 - this.unescape = ScriptFunctionImpl.makeFunction("unescape", GlobalFunctions.UNESCAPE); 7.76 - this.print = ScriptFunctionImpl.makeFunction("print", env._print_no_newline ? PRINT : PRINTLN); 7.77 - this.load = ScriptFunctionImpl.makeFunction("load", LOAD); 7.78 - this.loadWithNewGlobal = ScriptFunctionImpl.makeFunction("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL); 7.79 - this.exit = ScriptFunctionImpl.makeFunction("exit", EXIT); 7.80 - this.quit = ScriptFunctionImpl.makeFunction("quit", EXIT); 7.81 + this.parseFloat = ScriptFunction.createBuiltin("parseFloat", GlobalFunctions.PARSEFLOAT); 7.82 + this.isNaN = ScriptFunction.createBuiltin("isNaN", GlobalFunctions.IS_NAN); 7.83 + this.isFinite = ScriptFunction.createBuiltin("isFinite", GlobalFunctions.IS_FINITE); 7.84 + this.encodeURI = ScriptFunction.createBuiltin("encodeURI", GlobalFunctions.ENCODE_URI); 7.85 + this.encodeURIComponent = ScriptFunction.createBuiltin("encodeURIComponent", GlobalFunctions.ENCODE_URICOMPONENT); 7.86 + this.decodeURI = ScriptFunction.createBuiltin("decodeURI", GlobalFunctions.DECODE_URI); 7.87 + this.decodeURIComponent = ScriptFunction.createBuiltin("decodeURIComponent", GlobalFunctions.DECODE_URICOMPONENT); 7.88 + this.escape = ScriptFunction.createBuiltin("escape", GlobalFunctions.ESCAPE); 7.89 + this.unescape = ScriptFunction.createBuiltin("unescape", GlobalFunctions.UNESCAPE); 7.90 + this.print = ScriptFunction.createBuiltin("print", env._print_no_newline ? PRINT : PRINTLN); 7.91 + this.load = ScriptFunction.createBuiltin("load", LOAD); 7.92 + this.loadWithNewGlobal = ScriptFunction.createBuiltin("loadWithNewGlobal", LOAD_WITH_NEW_GLOBAL); 7.93 + this.exit = ScriptFunction.createBuiltin("exit", EXIT); 7.94 + this.quit = ScriptFunction.createBuiltin("quit", EXIT); 7.95 7.96 // built-in constructors 7.97 this.builtinArray = initConstructorAndSwitchPoint("Array", ScriptFunction.class); 7.98 @@ -2360,7 +2369,7 @@ 7.99 // default file name 7.100 addOwnProperty(ScriptEngine.FILENAME, Attribute.NOT_ENUMERABLE, null); 7.101 // __noSuchProperty__ hook for ScriptContext search of missing variables 7.102 - final ScriptFunction noSuchProp = ScriptFunctionImpl.makeStrictFunction(NO_SUCH_PROPERTY_NAME, NO_SUCH_PROPERTY); 7.103 + final ScriptFunction noSuchProp = ScriptFunction.createStrictBuiltin(NO_SUCH_PROPERTY_NAME, NO_SUCH_PROPERTY); 7.104 addOwnProperty(NO_SUCH_PROPERTY_NAME, Attribute.NOT_ENUMERABLE, noSuchProp); 7.105 } 7.106 } 7.107 @@ -2371,17 +2380,17 @@ 7.108 final ScriptObject errorProto = getErrorPrototype(); 7.109 7.110 // Nashorn specific accessors on Error.prototype - stack, lineNumber, columnNumber and fileName 7.111 - final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", NativeError.GET_STACK); 7.112 - final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", NativeError.SET_STACK); 7.113 + final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", NativeError.GET_STACK); 7.114 + final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", NativeError.SET_STACK); 7.115 errorProto.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); 7.116 - final ScriptFunction getLineNumber = ScriptFunctionImpl.makeFunction("getLineNumber", NativeError.GET_LINENUMBER); 7.117 - final ScriptFunction setLineNumber = ScriptFunctionImpl.makeFunction("setLineNumber", NativeError.SET_LINENUMBER); 7.118 + final ScriptFunction getLineNumber = ScriptFunction.createBuiltin("getLineNumber", NativeError.GET_LINENUMBER); 7.119 + final ScriptFunction setLineNumber = ScriptFunction.createBuiltin("setLineNumber", NativeError.SET_LINENUMBER); 7.120 errorProto.addOwnProperty("lineNumber", Attribute.NOT_ENUMERABLE, getLineNumber, setLineNumber); 7.121 - final ScriptFunction getColumnNumber = ScriptFunctionImpl.makeFunction("getColumnNumber", NativeError.GET_COLUMNNUMBER); 7.122 - final ScriptFunction setColumnNumber = ScriptFunctionImpl.makeFunction("setColumnNumber", NativeError.SET_COLUMNNUMBER); 7.123 + final ScriptFunction getColumnNumber = ScriptFunction.createBuiltin("getColumnNumber", NativeError.GET_COLUMNNUMBER); 7.124 + final ScriptFunction setColumnNumber = ScriptFunction.createBuiltin("setColumnNumber", NativeError.SET_COLUMNNUMBER); 7.125 errorProto.addOwnProperty("columnNumber", Attribute.NOT_ENUMERABLE, getColumnNumber, setColumnNumber); 7.126 - final ScriptFunction getFileName = ScriptFunctionImpl.makeFunction("getFileName", NativeError.GET_FILENAME); 7.127 - final ScriptFunction setFileName = ScriptFunctionImpl.makeFunction("setFileName", NativeError.SET_FILENAME); 7.128 + final ScriptFunction getFileName = ScriptFunction.createBuiltin("getFileName", NativeError.GET_FILENAME); 7.129 + final ScriptFunction setFileName = ScriptFunction.createBuiltin("setFileName", NativeError.SET_FILENAME); 7.130 errorProto.addOwnProperty("fileName", Attribute.NOT_ENUMERABLE, getFileName, setFileName); 7.131 7.132 // ECMA 15.11.4.2 Error.prototype.name 7.133 @@ -2421,14 +2430,14 @@ 7.134 7.135 private void initScripting(final ScriptEnvironment scriptEnv) { 7.136 ScriptObject value; 7.137 - value = ScriptFunctionImpl.makeFunction("readLine", ScriptingFunctions.READLINE); 7.138 + value = ScriptFunction.createBuiltin("readLine", ScriptingFunctions.READLINE); 7.139 addOwnProperty("readLine", Attribute.NOT_ENUMERABLE, value); 7.140 7.141 - value = ScriptFunctionImpl.makeFunction("readFully", ScriptingFunctions.READFULLY); 7.142 + value = ScriptFunction.createBuiltin("readFully", ScriptingFunctions.READFULLY); 7.143 addOwnProperty("readFully", Attribute.NOT_ENUMERABLE, value); 7.144 7.145 final String execName = ScriptingFunctions.EXEC_NAME; 7.146 - value = ScriptFunctionImpl.makeFunction(execName, ScriptingFunctions.EXEC); 7.147 + value = ScriptFunction.createBuiltin(execName, ScriptingFunctions.EXEC); 7.148 value.addOwnProperty(ScriptingFunctions.THROW_ON_ERROR_NAME, Attribute.NOT_ENUMERABLE, false); 7.149 7.150 addOwnProperty(execName, Attribute.NOT_ENUMERABLE, value); 7.151 @@ -2611,7 +2620,7 @@ 7.152 this.builtinFunction = initConstructor("Function", ScriptFunction.class); 7.153 7.154 // create global anonymous function 7.155 - final ScriptFunction anon = ScriptFunctionImpl.newAnonymousFunction(); 7.156 + final ScriptFunction anon = ScriptFunction.createAnonymous(); 7.157 // need to copy over members of Function.prototype to anon function 7.158 anon.addBoundProperties(getFunctionPrototype()); 7.159 7.160 @@ -2623,10 +2632,7 @@ 7.161 anon.deleteOwnProperty(anon.getMap().findProperty("prototype")); 7.162 7.163 // use "getter" so that [[ThrowTypeError]] function's arity is 0 - as specified in step 10 of section 13.2.3 7.164 - this.typeErrorThrower = new ScriptFunctionImpl("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER, null, null, 0); 7.165 - typeErrorThrower.setPrototype(UNDEFINED); 7.166 - // Non-constructor built-in functions do not have "prototype" property 7.167 - typeErrorThrower.deleteOwnProperty(typeErrorThrower.getMap().findProperty("prototype")); 7.168 + this.typeErrorThrower = ScriptFunction.createBuiltin("TypeErrorThrower", Lookup.TYPE_ERROR_THROWER_GETTER); 7.169 typeErrorThrower.preventExtensions(); 7.170 7.171 // now initialize Object 7.172 @@ -2637,8 +2643,8 @@ 7.173 7.174 // ES6 draft compliant __proto__ property of Object.prototype 7.175 // accessors on Object.prototype for "__proto__" 7.176 - final ScriptFunction getProto = ScriptFunctionImpl.makeFunction("getProto", NativeObject.GET__PROTO__); 7.177 - final ScriptFunction setProto = ScriptFunctionImpl.makeFunction("setProto", NativeObject.SET__PROTO__); 7.178 + final ScriptFunction getProto = ScriptFunction.createBuiltin("getProto", NativeObject.GET__PROTO__); 7.179 + final ScriptFunction setProto = ScriptFunction.createBuiltin("setProto", NativeObject.SET__PROTO__); 7.180 ObjectPrototype.addOwnProperty("__proto__", Attribute.NOT_ENUMERABLE, getProto, setProto); 7.181 7.182 // Function valued properties of Function.prototype were not properly
8.1 --- a/src/jdk/nashorn/internal/objects/NativeError.java Thu Sep 10 09:59:23 2015 +0530 8.2 +++ b/src/jdk/nashorn/internal/objects/NativeError.java Wed Sep 09 17:19:46 2015 +0530 8.3 @@ -150,8 +150,8 @@ 8.4 initException(sobj); 8.5 sobj.delete(STACK, false); 8.6 if (! sobj.has("stack")) { 8.7 - final ScriptFunction getStack = ScriptFunctionImpl.makeFunction("getStack", GET_STACK); 8.8 - final ScriptFunction setStack = ScriptFunctionImpl.makeFunction("setStack", SET_STACK); 8.9 + final ScriptFunction getStack = ScriptFunction.createBuiltin("getStack", GET_STACK); 8.10 + final ScriptFunction setStack = ScriptFunction.createBuiltin("setStack", SET_STACK); 8.11 sobj.addOwnProperty("stack", Attribute.NOT_ENUMERABLE, getStack, setStack); 8.12 } 8.13 return UNDEFINED;
9.1 --- a/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Thu Sep 10 09:59:23 2015 +0530 9.2 +++ b/src/jdk/nashorn/internal/objects/NativeJSAdapter.java Wed Sep 09 17:19:46 2015 +0530 9.3 @@ -621,11 +621,11 @@ 9.4 if (find != null) { 9.5 final Object value = find.getObjectValue(); 9.6 if (value instanceof ScriptFunction) { 9.7 - final ScriptFunctionImpl func = (ScriptFunctionImpl)value; 9.8 + final ScriptFunction func = (ScriptFunction)value; 9.9 // TODO: It's a shame we need to produce a function bound to this and name, when we'd only need it bound 9.10 // to name. Probably not a big deal, but if we can ever make it leaner, it'd be nice. 9.11 return new GuardedInvocation(MH.dropArguments(MH.constant(Object.class, 9.12 - func.makeBoundFunction(this, new Object[] { name })), 0, Object.class), 9.13 + func.createBound(this, new Object[] { name })), 0, Object.class), 9.14 testJSAdaptor(adaptee, null, null, null), 9.15 adaptee.getProtoSwitchPoint(__call__, find.getOwner())); 9.16 }
10.1 --- a/src/jdk/nashorn/internal/objects/NativeJava.java Thu Sep 10 09:59:23 2015 +0530 10.2 +++ b/src/jdk/nashorn/internal/objects/NativeJava.java Wed Sep 09 17:19:46 2015 +0530 10.3 @@ -93,7 +93,7 @@ 10.4 @Function(name="synchronized", attributes = Attribute.NOT_ENUMERABLE, where = Where.CONSTRUCTOR) 10.5 public static Object synchronizedFunc(final Object self, final Object func, final Object obj) { 10.6 if (func instanceof ScriptFunction) { 10.7 - return ((ScriptFunction)func).makeSynchronizedFunction(obj); 10.8 + return ((ScriptFunction)func).createSynchronized(obj); 10.9 } 10.10 10.11 throw typeError("not.a.function", ScriptRuntime.safeToString(func));
11.1 --- a/src/jdk/nashorn/internal/objects/PrototypeObject.java Thu Sep 10 09:59:23 2015 +0530 11.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 11.3 @@ -1,115 +0,0 @@ 11.4 -/* 11.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 11.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 11.7 - * 11.8 - * This code is free software; you can redistribute it and/or modify it 11.9 - * under the terms of the GNU General Public License version 2 only, as 11.10 - * published by the Free Software Foundation. Oracle designates this 11.11 - * particular file as subject to the "Classpath" exception as provided 11.12 - * by Oracle in the LICENSE file that accompanied this code. 11.13 - * 11.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 11.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11.17 - * version 2 for more details (a copy is included in the LICENSE file that 11.18 - * accompanied this code). 11.19 - * 11.20 - * You should have received a copy of the GNU General Public License version 11.21 - * 2 along with this work; if not, write to the Free Software Foundation, 11.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 11.23 - * 11.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 11.25 - * or visit www.oracle.com if you need additional information or have any 11.26 - * questions. 11.27 - */ 11.28 - 11.29 -package jdk.nashorn.internal.objects; 11.30 - 11.31 -import static jdk.nashorn.internal.lookup.Lookup.MH; 11.32 -import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 11.33 - 11.34 -import java.lang.invoke.MethodHandle; 11.35 -import java.lang.invoke.MethodHandles; 11.36 -import java.util.ArrayList; 11.37 -import jdk.nashorn.internal.runtime.AccessorProperty; 11.38 -import jdk.nashorn.internal.runtime.Property; 11.39 -import jdk.nashorn.internal.runtime.PropertyMap; 11.40 -import jdk.nashorn.internal.runtime.ScriptFunction; 11.41 -import jdk.nashorn.internal.runtime.ScriptObject; 11.42 - 11.43 -/** 11.44 - * Instances of this class serve as "prototype" object for script functions. 11.45 - * The purpose is to expose "constructor" property from "prototype". Also, nasgen 11.46 - * generated prototype classes extend from this class. 11.47 - * 11.48 - */ 11.49 -public class PrototypeObject extends ScriptObject { 11.50 - private static final PropertyMap map$; 11.51 - 11.52 - private Object constructor; 11.53 - 11.54 - private static final MethodHandle GET_CONSTRUCTOR = findOwnMH("getConstructor", Object.class, Object.class); 11.55 - private static final MethodHandle SET_CONSTRUCTOR = findOwnMH("setConstructor", void.class, Object.class, Object.class); 11.56 - 11.57 - static { 11.58 - final ArrayList<Property> properties = new ArrayList<>(1); 11.59 - properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR)); 11.60 - map$ = PropertyMap.newMap(properties); 11.61 - } 11.62 - 11.63 - private PrototypeObject(final Global global, final PropertyMap map) { 11.64 - super(global.getObjectPrototype(), map != map$? map.addAll(map$) : map$); 11.65 - } 11.66 - 11.67 - PrototypeObject() { 11.68 - this(Global.instance(), map$); 11.69 - } 11.70 - 11.71 - /** 11.72 - * PropertyObject constructor 11.73 - * 11.74 - * @param map property map 11.75 - */ 11.76 - PrototypeObject(final PropertyMap map) { 11.77 - this(Global.instance(), map); 11.78 - } 11.79 - 11.80 - PrototypeObject(final ScriptFunction func) { 11.81 - this(Global.instance(), map$); 11.82 - this.constructor = func; 11.83 - } 11.84 - 11.85 - /** 11.86 - * Get the constructor for this {@code PrototypeObject} 11.87 - * @param self self reference 11.88 - * @return constructor, probably, but not necessarily, a {@link ScriptFunction} 11.89 - */ 11.90 - static Object getConstructor(final Object self) { 11.91 - return (self instanceof PrototypeObject) ? 11.92 - ((PrototypeObject)self).getConstructor() : 11.93 - UNDEFINED; 11.94 - } 11.95 - 11.96 - /** 11.97 - * Reset the constructor for this {@code PrototypeObject} 11.98 - * @param self self reference 11.99 - * @param constructor constructor, probably, but not necessarily, a {@link ScriptFunction} 11.100 - */ 11.101 - static void setConstructor(final Object self, final Object constructor) { 11.102 - if (self instanceof PrototypeObject) { 11.103 - ((PrototypeObject)self).setConstructor(constructor); 11.104 - } 11.105 - } 11.106 - 11.107 - private Object getConstructor() { 11.108 - return constructor; 11.109 - } 11.110 - 11.111 - private void setConstructor(final Object constructor) { 11.112 - this.constructor = constructor; 11.113 - } 11.114 - 11.115 - private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 11.116 - return MH.findStatic(MethodHandles.lookup(), PrototypeObject.class, name, MH.type(rtype, types)); 11.117 - } 11.118 -}
12.1 --- a/src/jdk/nashorn/internal/objects/ScriptFunctionImpl.java Thu Sep 10 09:59:23 2015 +0530 12.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 12.3 @@ -1,313 +0,0 @@ 12.4 -/* 12.5 - * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 12.6 - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 12.7 - * 12.8 - * This code is free software; you can redistribute it and/or modify it 12.9 - * under the terms of the GNU General Public License version 2 only, as 12.10 - * published by the Free Software Foundation. Oracle designates this 12.11 - * particular file as subject to the "Classpath" exception as provided 12.12 - * by Oracle in the LICENSE file that accompanied this code. 12.13 - * 12.14 - * This code is distributed in the hope that it will be useful, but WITHOUT 12.15 - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12.16 - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12.17 - * version 2 for more details (a copy is included in the LICENSE file that 12.18 - * accompanied this code). 12.19 - * 12.20 - * You should have received a copy of the GNU General Public License version 12.21 - * 2 along with this work; if not, write to the Free Software Foundation, 12.22 - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 12.23 - * 12.24 - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 12.25 - * or visit www.oracle.com if you need additional information or have any 12.26 - * questions. 12.27 - */ 12.28 - 12.29 -package jdk.nashorn.internal.objects; 12.30 - 12.31 -import static jdk.nashorn.internal.lookup.Lookup.MH; 12.32 -import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 12.33 - 12.34 -import java.lang.invoke.MethodHandle; 12.35 -import java.util.ArrayList; 12.36 -import jdk.nashorn.internal.runtime.AccessorProperty; 12.37 -import jdk.nashorn.internal.runtime.GlobalFunctions; 12.38 -import jdk.nashorn.internal.runtime.Property; 12.39 -import jdk.nashorn.internal.runtime.PropertyMap; 12.40 -import jdk.nashorn.internal.runtime.RecompilableScriptFunctionData; 12.41 -import jdk.nashorn.internal.runtime.ScriptFunction; 12.42 -import jdk.nashorn.internal.runtime.ScriptFunctionData; 12.43 -import jdk.nashorn.internal.runtime.ScriptObject; 12.44 -import jdk.nashorn.internal.runtime.Specialization; 12.45 - 12.46 -/** 12.47 - * Concrete implementation of ScriptFunction. This sets correct map for the 12.48 - * function objects -- to expose properties like "prototype", "length" etc. 12.49 - */ 12.50 -public class ScriptFunctionImpl extends ScriptFunction { 12.51 - 12.52 - /** Reference to constructor prototype. */ 12.53 - private Object prototype; 12.54 - 12.55 - // property map for strict mode functions 12.56 - private static final PropertyMap strictmodemap$; 12.57 - // property map for bound functions 12.58 - private static final PropertyMap boundfunctionmap$; 12.59 - // property map for non-strict, non-bound functions. 12.60 - private static final PropertyMap map$; 12.61 - 12.62 - // Marker object for lazily initialized prototype object 12.63 - private static final Object LAZY_PROTOTYPE = new Object(); 12.64 - 12.65 - private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final Specialization[] specs, final Global global) { 12.66 - super(name, invokeHandle, map$, null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR); 12.67 - init(global); 12.68 - } 12.69 - 12.70 - /** 12.71 - * Constructor called by Nasgen generated code, no membercount, use the default map. 12.72 - * Creates builtin functions only. 12.73 - * 12.74 - * @param name name of function 12.75 - * @param invokeHandle handle for invocation 12.76 - * @param specs specialized versions of this method, if available, null otherwise 12.77 - */ 12.78 - ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final Specialization[] specs) { 12.79 - this(name, invokeHandle, specs, Global.instance()); 12.80 - } 12.81 - 12.82 - private ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final PropertyMap map, final Specialization[] specs, final Global global) { 12.83 - super(name, invokeHandle, map.addAll(map$), null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR); 12.84 - init(global); 12.85 - } 12.86 - 12.87 - /** 12.88 - * Constructor called by Nasgen generated code, no membercount, use the map passed as argument. 12.89 - * Creates builtin functions only. 12.90 - * 12.91 - * @param name name of function 12.92 - * @param invokeHandle handle for invocation 12.93 - * @param map initial property map 12.94 - * @param specs specialized versions of this method, if available, null otherwise 12.95 - */ 12.96 - ScriptFunctionImpl(final String name, final MethodHandle invokeHandle, final PropertyMap map, final Specialization[] specs) { 12.97 - this(name, invokeHandle, map, specs, Global.instance()); 12.98 - } 12.99 - 12.100 - private ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final Specialization[] specs, final int flags, final Global global) { 12.101 - super(name, methodHandle, getMap(isStrict(flags)), scope, specs, flags); 12.102 - init(global); 12.103 - } 12.104 - 12.105 - /** 12.106 - * Constructor called by Global.newScriptFunction (runtime). 12.107 - * 12.108 - * @param name name of function 12.109 - * @param methodHandle handle for invocation 12.110 - * @param scope scope object 12.111 - * @param specs specialized versions of this method, if available, null otherwise 12.112 - * @param flags {@link ScriptFunctionData} flags 12.113 - */ 12.114 - ScriptFunctionImpl(final String name, final MethodHandle methodHandle, final ScriptObject scope, final Specialization[] specs, final int flags) { 12.115 - this(name, methodHandle, scope, specs, flags, Global.instance()); 12.116 - } 12.117 - 12.118 - private ScriptFunctionImpl(final RecompilableScriptFunctionData data, final ScriptObject scope, final Global global) { 12.119 - super(data, getMap(data.isStrict()), scope); 12.120 - init(global); 12.121 - } 12.122 - 12.123 - /** 12.124 - * Factory method called by compiler generated code for functions that need parent scope. 12.125 - * 12.126 - * @param constants the generated class' constant array 12.127 - * @param index the index of the {@code RecompilableScriptFunctionData} object in the constants array. 12.128 - * @param scope the parent scope object 12.129 - * @return a newly created function object 12.130 - */ 12.131 - public static ScriptFunction create(final Object[] constants, final int index, final ScriptObject scope) { 12.132 - return new ScriptFunctionImpl((RecompilableScriptFunctionData)constants[index], scope, Global.instance()); 12.133 - } 12.134 - 12.135 - /** 12.136 - * Factory method called by compiler generated code for functions that don't need parent scope. 12.137 - * 12.138 - * @param constants the generated class' constant array 12.139 - * @param index the index of the {@code RecompilableScriptFunctionData} object in the constants array. 12.140 - * @return a newly created function object 12.141 - */ 12.142 - public static ScriptFunction create(final Object[] constants, final int index) { 12.143 - return create(constants, index, null); 12.144 - } 12.145 - 12.146 - /** 12.147 - * Only invoked internally from {@link BoundScriptFunctionImpl} constructor. 12.148 - * @param data the script function data for the bound function. 12.149 - * @param global the global object 12.150 - */ 12.151 - ScriptFunctionImpl(final ScriptFunctionData data, final Global global) { 12.152 - super(data, boundfunctionmap$, null); 12.153 - init(global); 12.154 - } 12.155 - 12.156 - static { 12.157 - final ArrayList<Property> properties = new ArrayList<>(3); 12.158 - properties.add(AccessorProperty.create("prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE)); 12.159 - properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null)); 12.160 - properties.add(AccessorProperty.create("name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null)); 12.161 - map$ = PropertyMap.newMap(properties); 12.162 - strictmodemap$ = createStrictModeMap(map$); 12.163 - boundfunctionmap$ = createBoundFunctionMap(strictmodemap$); 12.164 - } 12.165 - 12.166 - private static PropertyMap createStrictModeMap(final PropertyMap map) { 12.167 - final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; 12.168 - PropertyMap newMap = map; 12.169 - // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors. 12.170 - newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags)); 12.171 - newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags)); 12.172 - return newMap; 12.173 - } 12.174 - 12.175 - private static boolean isStrict(final int flags) { 12.176 - return (flags & ScriptFunctionData.IS_STRICT) != 0; 12.177 - } 12.178 - 12.179 - // Choose the map based on strict mode! 12.180 - private static PropertyMap getMap(final boolean strict) { 12.181 - return strict ? strictmodemap$ : map$; 12.182 - } 12.183 - 12.184 - private static PropertyMap createBoundFunctionMap(final PropertyMap strictModeMap) { 12.185 - // Bound function map is same as strict function map, but additionally lacks the "prototype" property, see 12.186 - // ECMAScript 5.1 section 15.3.4.5 12.187 - return strictModeMap.deleteProperty(strictModeMap.findProperty("prototype")); 12.188 - } 12.189 - 12.190 - // Instance of this class is used as global anonymous function which 12.191 - // serves as Function.prototype object. 12.192 - private static class AnonymousFunction extends ScriptFunctionImpl { 12.193 - private static final PropertyMap anonmap$ = PropertyMap.newMap(); 12.194 - 12.195 - AnonymousFunction() { 12.196 - super("", GlobalFunctions.ANONYMOUS, anonmap$, null); 12.197 - } 12.198 - } 12.199 - 12.200 - static ScriptFunctionImpl newAnonymousFunction() { 12.201 - return new AnonymousFunction(); 12.202 - } 12.203 - 12.204 - private static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final Specialization[] specs, final int flags) { 12.205 - final ScriptFunctionImpl func = new ScriptFunctionImpl(name, methodHandle, null, specs, flags); 12.206 - func.setPrototype(UNDEFINED); 12.207 - // Non-constructor built-in functions do not have "prototype" property 12.208 - func.deleteOwnProperty(func.getMap().findProperty("prototype")); 12.209 - 12.210 - return func; 12.211 - } 12.212 - 12.213 - /** 12.214 - * Factory method for non-constructor built-in functions 12.215 - * 12.216 - * @param name function name 12.217 - * @param methodHandle handle for invocation 12.218 - * @param specs specialized versions of function if available, null otherwise 12.219 - * @return new ScriptFunction 12.220 - */ 12.221 - static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle, final Specialization[] specs) { 12.222 - return makeFunction(name, methodHandle, specs, ScriptFunctionData.IS_BUILTIN); 12.223 - } 12.224 - 12.225 - /** 12.226 - * Factory method for non-constructor built-in, strict functions 12.227 - * 12.228 - * @param name function name 12.229 - * @param methodHandle handle for invocation 12.230 - * @return new ScriptFunction 12.231 - */ 12.232 - static ScriptFunction makeStrictFunction(final String name, final MethodHandle methodHandle) { 12.233 - return makeFunction(name, methodHandle, null, ScriptFunctionData.IS_BUILTIN | ScriptFunctionData.IS_STRICT ); 12.234 - } 12.235 - 12.236 - /** 12.237 - * Factory method for non-constructor built-in functions 12.238 - * 12.239 - * @param name function name 12.240 - * @param methodHandle handle for invocation 12.241 - * @return new ScriptFunction 12.242 - */ 12.243 - static ScriptFunction makeFunction(final String name, final MethodHandle methodHandle) { 12.244 - return makeFunction(name, methodHandle, null); 12.245 - } 12.246 - 12.247 - @Override 12.248 - public ScriptFunction makeSynchronizedFunction(final Object sync) { 12.249 - final MethodHandle mh = MH.insertArguments(ScriptFunction.INVOKE_SYNC, 0, this, sync); 12.250 - return makeFunction(getName(), mh); 12.251 - } 12.252 - 12.253 - /** 12.254 - * Same as {@link ScriptFunction#makeBoundFunction(Object, Object[])}. The only reason we override it is so that we 12.255 - * can expose it. 12.256 - * @param self the self to bind to this function. Can be null (in which case, null is bound as this). 12.257 - * @param args additional arguments to bind to this function. Can be null or empty to not bind additional arguments. 12.258 - * @return a function with the specified self and parameters bound. 12.259 - */ 12.260 - @Override 12.261 - public ScriptFunction makeBoundFunction(final Object self, final Object[] args) { 12.262 - return super.makeBoundFunction(self, args); 12.263 - } 12.264 - 12.265 - /** 12.266 - * This method is used to create a bound function based on this function. 12.267 - * 12.268 - * @param data the {@code ScriptFunctionData} specifying the functions immutable portion. 12.269 - * @return a function initialized from the specified data. Its parent scope will be set to null, therefore the 12.270 - * passed in data should not expect a callee. 12.271 - */ 12.272 - @Override 12.273 - protected ScriptFunction makeBoundFunction(final ScriptFunctionData data) { 12.274 - return new BoundScriptFunctionImpl(data, getTargetFunction()); 12.275 - } 12.276 - 12.277 - // return Object.prototype - used by "allocate" 12.278 - @Override 12.279 - protected final ScriptObject getObjectPrototype() { 12.280 - return Global.objectPrototype(); 12.281 - } 12.282 - 12.283 - @Override 12.284 - public final Object getPrototype() { 12.285 - if (prototype == LAZY_PROTOTYPE) { 12.286 - prototype = new PrototypeObject(this); 12.287 - } 12.288 - return prototype; 12.289 - } 12.290 - 12.291 - @Override 12.292 - public final void setPrototype(final Object newProto) { 12.293 - if (newProto instanceof ScriptObject && newProto != this.prototype && allocatorMap != null) { 12.294 - // Replace our current allocator map with one that is associated with the new prototype. 12.295 - allocatorMap = allocatorMap.changeProto((ScriptObject)newProto); 12.296 - } 12.297 - this.prototype = newProto; 12.298 - } 12.299 - 12.300 - // Internals below.. 12.301 - private void init(final Global global) { 12.302 - this.setInitialProto(global.getFunctionPrototype()); 12.303 - this.prototype = LAZY_PROTOTYPE; 12.304 - 12.305 - // We have to fill user accessor functions late as these are stored 12.306 - // in this object rather than in the PropertyMap of this object. 12.307 - assert objectSpill == null; 12.308 - final ScriptFunction typeErrorThrower = global.getTypeErrorThrower(); 12.309 - if (findProperty("arguments", true) != null) { 12.310 - initUserAccessors("arguments", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower); 12.311 - } 12.312 - if (findProperty("caller", true) != null) { 12.313 - initUserAccessors("caller", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower); 12.314 - } 12.315 - } 12.316 -}
13.1 --- a/src/jdk/nashorn/internal/runtime/PropertyListeners.java Thu Sep 10 09:59:23 2015 +0530 13.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyListeners.java Wed Sep 09 17:19:46 2015 +0530 13.3 @@ -28,6 +28,7 @@ 13.4 import java.util.Map; 13.5 import java.util.Set; 13.6 import java.util.WeakHashMap; 13.7 +import java.util.concurrent.atomic.LongAdder; 13.8 13.9 /** 13.10 * Helper class to manage property listeners and notification. 13.11 @@ -37,8 +38,15 @@ 13.12 private Map<String, WeakPropertyMapSet> listeners; 13.13 13.14 // These counters are updated in debug mode 13.15 - private static int listenersAdded; 13.16 - private static int listenersRemoved; 13.17 + private static LongAdder listenersAdded; 13.18 + private static LongAdder listenersRemoved; 13.19 + 13.20 + static { 13.21 + if (Context.DEBUG) { 13.22 + listenersAdded = new LongAdder(); 13.23 + listenersRemoved = new LongAdder(); 13.24 + } 13.25 + } 13.26 13.27 /** 13.28 * Copy constructor 13.29 @@ -54,16 +62,16 @@ 13.30 * Return aggregate listeners added to all PropertyListenerManagers 13.31 * @return the listenersAdded 13.32 */ 13.33 - public static int getListenersAdded() { 13.34 - return listenersAdded; 13.35 + public static long getListenersAdded() { 13.36 + return listenersAdded.longValue(); 13.37 } 13.38 13.39 /** 13.40 * Return aggregate listeners removed from all PropertyListenerManagers 13.41 * @return the listenersRemoved 13.42 */ 13.43 - public static int getListenersRemoved() { 13.44 - return listenersRemoved; 13.45 + public static long getListenersRemoved() { 13.46 + return listenersRemoved.longValue(); 13.47 } 13.48 13.49 /** 13.50 @@ -122,7 +130,7 @@ 13.51 */ 13.52 synchronized final void addListener(final String key, final PropertyMap propertyMap) { 13.53 if (Context.DEBUG) { 13.54 - listenersAdded++; 13.55 + listenersAdded.increment(); 13.56 } 13.57 if (listeners == null) { 13.58 listeners = new WeakHashMap<>(); 13.59 @@ -151,6 +159,9 @@ 13.60 propertyMap.propertyAdded(prop); 13.61 } 13.62 listeners.remove(prop.getKey()); 13.63 + if (Context.DEBUG) { 13.64 + listenersRemoved.increment(); 13.65 + } 13.66 } 13.67 } 13.68 } 13.69 @@ -168,6 +179,9 @@ 13.70 propertyMap.propertyDeleted(prop); 13.71 } 13.72 listeners.remove(prop.getKey()); 13.73 + if (Context.DEBUG) { 13.74 + listenersRemoved.increment(); 13.75 + } 13.76 } 13.77 } 13.78 } 13.79 @@ -187,6 +201,9 @@ 13.80 propertyMap.propertyModified(oldProp, newProp); 13.81 } 13.82 listeners.remove(oldProp.getKey()); 13.83 + if (Context.DEBUG) { 13.84 + listenersRemoved.increment(); 13.85 + } 13.86 } 13.87 } 13.88 }
14.1 --- a/src/jdk/nashorn/internal/runtime/PropertyMap.java Thu Sep 10 09:59:23 2015 +0530 14.2 +++ b/src/jdk/nashorn/internal/runtime/PropertyMap.java Wed Sep 09 17:19:46 2015 +0530 14.3 @@ -42,6 +42,7 @@ 14.4 import java.util.Iterator; 14.5 import java.util.NoSuchElementException; 14.6 import java.util.WeakHashMap; 14.7 +import java.util.concurrent.atomic.LongAdder; 14.8 import jdk.nashorn.internal.scripts.JO; 14.9 14.10 /** 14.11 @@ -114,7 +115,7 @@ 14.12 } 14.13 14.14 if (Context.DEBUG) { 14.15 - count++; 14.16 + count.increment(); 14.17 } 14.18 } 14.19 14.20 @@ -135,8 +136,8 @@ 14.21 this.freeSlots = propertyMap.freeSlots; 14.22 14.23 if (Context.DEBUG) { 14.24 - count++; 14.25 - clonedCount++; 14.26 + count.increment(); 14.27 + clonedCount.increment(); 14.28 } 14.29 } 14.30 14.31 @@ -328,7 +329,7 @@ 14.32 if (sp != null) { 14.33 protoGetSwitches.remove(key); 14.34 if (Context.DEBUG) { 14.35 - protoInvalidations++; 14.36 + protoInvalidations.increment(); 14.37 } 14.38 SwitchPoint.invalidateAll(new SwitchPoint[] { sp }); 14.39 } 14.40 @@ -343,7 +344,7 @@ 14.41 final int size = protoGetSwitches.size(); 14.42 if (size > 0) { 14.43 if (Context.DEBUG) { 14.44 - protoInvalidations += size; 14.45 + protoInvalidations.add(size); 14.46 } 14.47 SwitchPoint.invalidateAll(protoGetSwitches.values().toArray(new SwitchPoint[size])); 14.48 protoGetSwitches.clear(); 14.49 @@ -704,7 +705,7 @@ 14.50 } 14.51 14.52 if (Context.DEBUG && cachedMap != null) { 14.53 - protoHistoryHit++; 14.54 + protoHistoryHit.increment(); 14.55 } 14.56 14.57 return cachedMap; 14.58 @@ -753,7 +754,7 @@ 14.59 14.60 if (historicMap != null) { 14.61 if (Context.DEBUG) { 14.62 - historyHit++; 14.63 + historyHit.increment(); 14.64 } 14.65 14.66 return historicMap; 14.67 @@ -901,7 +902,7 @@ 14.68 } 14.69 14.70 if (Context.DEBUG) { 14.71 - setProtoNewMapCount++; 14.72 + setProtoNewMapCount.increment(); 14.73 } 14.74 14.75 final PropertyMap newMap = new PropertyMap(this); 14.76 @@ -1021,52 +1022,62 @@ 14.77 } 14.78 14.79 // counters updated only in debug mode 14.80 - private static int count; 14.81 - private static int clonedCount; 14.82 - private static int historyHit; 14.83 - private static int protoInvalidations; 14.84 - private static int protoHistoryHit; 14.85 - private static int setProtoNewMapCount; 14.86 + private static LongAdder count; 14.87 + private static LongAdder clonedCount; 14.88 + private static LongAdder historyHit; 14.89 + private static LongAdder protoInvalidations; 14.90 + private static LongAdder protoHistoryHit; 14.91 + private static LongAdder setProtoNewMapCount; 14.92 + static { 14.93 + if (Context.DEBUG) { 14.94 + count = new LongAdder(); 14.95 + clonedCount = new LongAdder(); 14.96 + historyHit = new LongAdder(); 14.97 + protoInvalidations = new LongAdder(); 14.98 + protoHistoryHit = new LongAdder(); 14.99 + setProtoNewMapCount = new LongAdder(); 14.100 + } 14.101 + } 14.102 14.103 /** 14.104 * @return Total number of maps. 14.105 */ 14.106 - public static int getCount() { 14.107 - return count; 14.108 + public static long getCount() { 14.109 + return count.longValue(); 14.110 } 14.111 14.112 /** 14.113 * @return The number of maps that were cloned. 14.114 */ 14.115 - public static int getClonedCount() { 14.116 - return clonedCount; 14.117 + public static long getClonedCount() { 14.118 + return clonedCount.longValue(); 14.119 } 14.120 14.121 /** 14.122 * @return The number of times history was successfully used. 14.123 */ 14.124 - public static int getHistoryHit() { 14.125 - return historyHit; 14.126 + public static long getHistoryHit() { 14.127 + return historyHit.longValue(); 14.128 } 14.129 14.130 /** 14.131 * @return The number of times prototype changes caused invalidation. 14.132 */ 14.133 - public static int getProtoInvalidations() { 14.134 - return protoInvalidations; 14.135 + public static long getProtoInvalidations() { 14.136 + return protoInvalidations.longValue(); 14.137 } 14.138 14.139 /** 14.140 * @return The number of times proto history was successfully used. 14.141 */ 14.142 - public static int getProtoHistoryHit() { 14.143 - return protoHistoryHit; 14.144 + public static long getProtoHistoryHit() { 14.145 + return protoHistoryHit.longValue(); 14.146 } 14.147 14.148 /** 14.149 * @return The number of times prototypes were modified. 14.150 */ 14.151 - public static int getSetProtoNewMapCount() { 14.152 - return setProtoNewMapCount; 14.153 + public static long getSetProtoNewMapCount() { 14.154 + return setProtoNewMapCount.longValue(); 14.155 } 14.156 }
15.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 15.2 +++ b/src/jdk/nashorn/internal/runtime/PrototypeObject.java Wed Sep 09 17:19:46 2015 +0530 15.3 @@ -0,0 +1,118 @@ 15.4 +/* 15.5 + * Copyright (c) 2010, 2013, Oracle and/or its affiliates. All rights reserved. 15.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 15.7 + * 15.8 + * This code is free software; you can redistribute it and/or modify it 15.9 + * under the terms of the GNU General Public License version 2 only, as 15.10 + * published by the Free Software Foundation. Oracle designates this 15.11 + * particular file as subject to the "Classpath" exception as provided 15.12 + * by Oracle in the LICENSE file that accompanied this code. 15.13 + * 15.14 + * This code is distributed in the hope that it will be useful, but WITHOUT 15.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 15.16 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 15.17 + * version 2 for more details (a copy is included in the LICENSE file that 15.18 + * accompanied this code). 15.19 + * 15.20 + * You should have received a copy of the GNU General Public License version 15.21 + * 2 along with this work; if not, write to the Free Software Foundation, 15.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 15.23 + * 15.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 15.25 + * or visit www.oracle.com if you need additional information or have any 15.26 + * questions. 15.27 + */ 15.28 + 15.29 +package jdk.nashorn.internal.runtime; 15.30 + 15.31 +import static jdk.nashorn.internal.lookup.Lookup.MH; 15.32 +import static jdk.nashorn.internal.runtime.ScriptRuntime.UNDEFINED; 15.33 + 15.34 +import java.lang.invoke.MethodHandle; 15.35 +import java.lang.invoke.MethodHandles; 15.36 +import java.util.ArrayList; 15.37 +import jdk.nashorn.internal.objects.Global; 15.38 + 15.39 +/** 15.40 + * Instances of this class serve as "prototype" object for script functions. 15.41 + * The purpose is to expose "constructor" property from "prototype". Also, nasgen 15.42 + * generated prototype classes extend from this class. 15.43 + */ 15.44 +public class PrototypeObject extends ScriptObject { 15.45 + private static final PropertyMap map$; 15.46 + 15.47 + private Object constructor; 15.48 + 15.49 + private static final MethodHandle GET_CONSTRUCTOR = findOwnMH("getConstructor", Object.class, Object.class); 15.50 + private static final MethodHandle SET_CONSTRUCTOR = findOwnMH("setConstructor", void.class, Object.class, Object.class); 15.51 + 15.52 + static { 15.53 + final ArrayList<Property> properties = new ArrayList<>(1); 15.54 + properties.add(AccessorProperty.create("constructor", Property.NOT_ENUMERABLE, GET_CONSTRUCTOR, SET_CONSTRUCTOR)); 15.55 + map$ = PropertyMap.newMap(properties); 15.56 + } 15.57 + 15.58 + private PrototypeObject(final Global global, final PropertyMap map) { 15.59 + super(global.getObjectPrototype(), map != map$? map.addAll(map$) : map$); 15.60 + } 15.61 + 15.62 + /** 15.63 + * Prototype constructor 15.64 + */ 15.65 + protected PrototypeObject() { 15.66 + this(Global.instance(), map$); 15.67 + } 15.68 + 15.69 + /** 15.70 + * PropertyObject constructor 15.71 + * 15.72 + * @param map property map 15.73 + */ 15.74 + protected PrototypeObject(final PropertyMap map) { 15.75 + this(Global.instance(), map); 15.76 + } 15.77 + 15.78 + /** 15.79 + * PropertyObject constructor 15.80 + * 15.81 + * @param func constructor function 15.82 + */ 15.83 + protected PrototypeObject(final ScriptFunction func) { 15.84 + this(Global.instance(), map$); 15.85 + this.constructor = func; 15.86 + } 15.87 + 15.88 + /** 15.89 + * Get the constructor for this {@code PrototypeObject} 15.90 + * @param self self reference 15.91 + * @return constructor, probably, but not necessarily, a {@link ScriptFunction} 15.92 + */ 15.93 + public static Object getConstructor(final Object self) { 15.94 + return (self instanceof PrototypeObject) ? 15.95 + ((PrototypeObject)self).getConstructor() : 15.96 + UNDEFINED; 15.97 + } 15.98 + 15.99 + /** 15.100 + * Reset the constructor for this {@code PrototypeObject} 15.101 + * @param self self reference 15.102 + * @param constructor constructor, probably, but not necessarily, a {@link ScriptFunction} 15.103 + */ 15.104 + public static void setConstructor(final Object self, final Object constructor) { 15.105 + if (self instanceof PrototypeObject) { 15.106 + ((PrototypeObject)self).setConstructor(constructor); 15.107 + } 15.108 + } 15.109 + 15.110 + private Object getConstructor() { 15.111 + return constructor; 15.112 + } 15.113 + 15.114 + private void setConstructor(final Object constructor) { 15.115 + this.constructor = constructor; 15.116 + } 15.117 + 15.118 + private static MethodHandle findOwnMH(final String name, final Class<?> rtype, final Class<?>... types) { 15.119 + return MH.findStatic(MethodHandles.lookup(), PrototypeObject.class, name, MH.type(rtype, types)); 15.120 + } 15.121 +}
16.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunction.java Thu Sep 10 09:59:23 2015 +0530 16.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunction.java Wed Sep 09 17:19:46 2015 +0530 16.3 @@ -22,7 +22,6 @@ 16.4 * or visit www.oracle.com if you need additional information or have any 16.5 * questions. 16.6 */ 16.7 - 16.8 package jdk.nashorn.internal.runtime; 16.9 16.10 import static jdk.nashorn.internal.codegen.CompilerConstants.virtualCallNoLookup; 16.11 @@ -40,6 +39,7 @@ 16.12 import java.util.Collections; 16.13 import java.util.HashSet; 16.14 import java.util.List; 16.15 +import java.util.concurrent.atomic.LongAdder; 16.16 import jdk.internal.dynalink.CallSiteDescriptor; 16.17 import jdk.internal.dynalink.linker.GuardedInvocation; 16.18 import jdk.internal.dynalink.linker.LinkRequest; 16.19 @@ -55,38 +55,54 @@ 16.20 import jdk.nashorn.internal.runtime.logging.DebugLogger; 16.21 16.22 /** 16.23 - * Runtime representation of a JavaScript function. 16.24 + * Runtime representation of a JavaScript function. This class has only private 16.25 + * and protected constructors. There are no *public* constructors - but only 16.26 + * factory methods that follow the naming pattern "createXYZ". 16.27 */ 16.28 -public abstract class ScriptFunction extends ScriptObject { 16.29 +public class ScriptFunction extends ScriptObject { 16.30 16.31 - /** Method handle for prototype getter for this ScriptFunction */ 16.32 + /** 16.33 + * Method handle for prototype getter for this ScriptFunction 16.34 + */ 16.35 public static final MethodHandle G$PROTOTYPE = findOwnMH_S("G$prototype", Object.class, Object.class); 16.36 16.37 - /** Method handle for prototype setter for this ScriptFunction */ 16.38 + /** 16.39 + * Method handle for prototype setter for this ScriptFunction 16.40 + */ 16.41 public static final MethodHandle S$PROTOTYPE = findOwnMH_S("S$prototype", void.class, Object.class, Object.class); 16.42 16.43 - /** Method handle for length getter for this ScriptFunction */ 16.44 + /** 16.45 + * Method handle for length getter for this ScriptFunction 16.46 + */ 16.47 public static final MethodHandle G$LENGTH = findOwnMH_S("G$length", int.class, Object.class); 16.48 16.49 - /** Method handle for name getter for this ScriptFunction */ 16.50 + /** 16.51 + * Method handle for name getter for this ScriptFunction 16.52 + */ 16.53 public static final MethodHandle G$NAME = findOwnMH_S("G$name", Object.class, Object.class); 16.54 16.55 - /** Method handle used for implementing sync() in mozilla_compat */ 16.56 + /** 16.57 + * Method handle used for implementing sync() in mozilla_compat 16.58 + */ 16.59 public static final MethodHandle INVOKE_SYNC = findOwnMH_S("invokeSync", Object.class, ScriptFunction.class, Object.class, Object.class, Object[].class); 16.60 16.61 - /** Method handle for allocate function for this ScriptFunction */ 16.62 + /** 16.63 + * Method handle for allocate function for this ScriptFunction 16.64 + */ 16.65 static final MethodHandle ALLOCATE = findOwnMH_V("allocate", Object.class); 16.66 16.67 private static final MethodHandle WRAPFILTER = findOwnMH_S("wrapFilter", Object.class, Object.class); 16.68 16.69 private static final MethodHandle SCRIPTFUNCTION_GLOBALFILTER = findOwnMH_S("globalFilter", Object.class, Object.class); 16.70 16.71 - /** method handle to scope getter for this ScriptFunction */ 16.72 + /** 16.73 + * method handle to scope getter for this ScriptFunction 16.74 + */ 16.75 public static final Call GET_SCOPE = virtualCallNoLookup(ScriptFunction.class, "getScope", ScriptObject.class); 16.76 16.77 - private static final MethodHandle IS_FUNCTION_MH = findOwnMH_S("isFunctionMH", boolean.class, Object.class, ScriptFunctionData.class); 16.78 + private static final MethodHandle IS_FUNCTION_MH = findOwnMH_S("isFunctionMH", boolean.class, Object.class, ScriptFunctionData.class); 16.79 16.80 - private static final MethodHandle IS_APPLY_FUNCTION = findOwnMH_S("isApplyFunction", boolean.class, boolean.class, Object.class, Object.class); 16.81 + private static final MethodHandle IS_APPLY_FUNCTION = findOwnMH_S("isApplyFunction", boolean.class, boolean.class, Object.class, Object.class); 16.82 16.83 private static final MethodHandle IS_NONSTRICT_FUNCTION = findOwnMH_S("isNonStrictFunction", boolean.class, Object.class, Object.class, ScriptFunctionData.class); 16.84 16.85 @@ -94,55 +110,301 @@ 16.86 16.87 private static final MethodHandle WRAP_THIS = MH.findStatic(MethodHandles.lookup(), ScriptFunctionData.class, "wrapThis", MH.type(Object.class, Object.class)); 16.88 16.89 - /** The parent scope. */ 16.90 + // various property maps used for different kinds of functions 16.91 + // property map for anonymous function that serves as Function.prototype 16.92 + private static final PropertyMap anonmap$; 16.93 + // property map for strict mode functions 16.94 + private static final PropertyMap strictmodemap$; 16.95 + // property map for bound functions 16.96 + private static final PropertyMap boundfunctionmap$; 16.97 + // property map for non-strict, non-bound functions. 16.98 + private static final PropertyMap map$; 16.99 + 16.100 + // Marker object for lazily initialized prototype object 16.101 + private static final Object LAZY_PROTOTYPE = new Object(); 16.102 + 16.103 + private static PropertyMap createStrictModeMap(final PropertyMap map) { 16.104 + final int flags = Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE; 16.105 + PropertyMap newMap = map; 16.106 + // Need to add properties directly to map since slots are assigned speculatively by newUserAccessors. 16.107 + newMap = newMap.addPropertyNoHistory(map.newUserAccessors("arguments", flags)); 16.108 + newMap = newMap.addPropertyNoHistory(map.newUserAccessors("caller", flags)); 16.109 + return newMap; 16.110 + } 16.111 + 16.112 + private static PropertyMap createBoundFunctionMap(final PropertyMap strictModeMap) { 16.113 + // Bound function map is same as strict function map, but additionally lacks the "prototype" property, see 16.114 + // ECMAScript 5.1 section 15.3.4.5 16.115 + return strictModeMap.deleteProperty(strictModeMap.findProperty("prototype")); 16.116 + } 16.117 + 16.118 + static { 16.119 + anonmap$ = PropertyMap.newMap(); 16.120 + final ArrayList<Property> properties = new ArrayList<>(3); 16.121 + properties.add(AccessorProperty.create("prototype", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE, G$PROTOTYPE, S$PROTOTYPE)); 16.122 + properties.add(AccessorProperty.create("length", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$LENGTH, null)); 16.123 + properties.add(AccessorProperty.create("name", Property.NOT_ENUMERABLE | Property.NOT_CONFIGURABLE | Property.NOT_WRITABLE, G$NAME, null)); 16.124 + map$ = PropertyMap.newMap(properties); 16.125 + strictmodemap$ = createStrictModeMap(map$); 16.126 + boundfunctionmap$ = createBoundFunctionMap(strictmodemap$); 16.127 + } 16.128 + 16.129 + private static boolean isStrict(final int flags) { 16.130 + return (flags & ScriptFunctionData.IS_STRICT) != 0; 16.131 + } 16.132 + 16.133 + // Choose the map based on strict mode! 16.134 + private static PropertyMap getMap(final boolean strict) { 16.135 + return strict ? strictmodemap$ : map$; 16.136 + } 16.137 + 16.138 + /** 16.139 + * The parent scope. 16.140 + */ 16.141 private final ScriptObject scope; 16.142 16.143 private final ScriptFunctionData data; 16.144 16.145 - /** The property map used for newly allocated object when function is used as constructor. */ 16.146 + /** 16.147 + * The property map used for newly allocated object when function is used as 16.148 + * constructor. 16.149 + */ 16.150 protected PropertyMap allocatorMap; 16.151 16.152 /** 16.153 + * Reference to constructor prototype. 16.154 + */ 16.155 + protected Object prototype; 16.156 + 16.157 + /** 16.158 * Constructor 16.159 * 16.160 - * @param name function name 16.161 - * @param methodHandle method handle to function (if specializations are present, assumed to be most generic) 16.162 - * @param map property map 16.163 - * @param scope scope 16.164 - * @param specs specialized version of this function - other method handles 16.165 - * @param flags {@link ScriptFunctionData} flags 16.166 + * @param data static function data 16.167 + * @param map property map 16.168 + * @param scope scope 16.169 */ 16.170 - protected ScriptFunction( 16.171 + private ScriptFunction( 16.172 + final ScriptFunctionData data, 16.173 + final PropertyMap map, 16.174 + final ScriptObject scope, 16.175 + final Global global) { 16.176 + 16.177 + super(map); 16.178 + 16.179 + if (Context.DEBUG) { 16.180 + constructorCount.increment(); 16.181 + } 16.182 + 16.183 + this.data = data; 16.184 + this.scope = scope; 16.185 + this.setInitialProto(global.getFunctionPrototype()); 16.186 + this.prototype = LAZY_PROTOTYPE; 16.187 + 16.188 + // We have to fill user accessor functions late as these are stored 16.189 + // in this object rather than in the PropertyMap of this object. 16.190 + assert objectSpill == null; 16.191 + final ScriptFunction typeErrorThrower = global.getTypeErrorThrower(); 16.192 + if (findProperty("arguments", true) != null) { 16.193 + initUserAccessors("arguments", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower); 16.194 + } 16.195 + 16.196 + if (findProperty("caller", true) != null) { 16.197 + initUserAccessors("caller", Property.NOT_CONFIGURABLE | Property.NOT_ENUMERABLE, typeErrorThrower, typeErrorThrower); 16.198 + } 16.199 + } 16.200 + 16.201 + /** 16.202 + * Constructor 16.203 + * 16.204 + * @param name function name 16.205 + * @param methodHandle method handle to function (if specializations are 16.206 + * present, assumed to be most generic) 16.207 + * @param map property map 16.208 + * @param scope scope 16.209 + * @param specs specialized version of this function - other method handles 16.210 + * @param flags {@link ScriptFunctionData} flags 16.211 + */ 16.212 + private ScriptFunction( 16.213 final String name, 16.214 final MethodHandle methodHandle, 16.215 final PropertyMap map, 16.216 final ScriptObject scope, 16.217 final Specialization[] specs, 16.218 - final int flags) { 16.219 - 16.220 - this(new FinalScriptFunctionData(name, methodHandle, specs, flags), map, scope); 16.221 + final int flags, 16.222 + final Global global) { 16.223 + this(new FinalScriptFunctionData(name, methodHandle, specs, flags), map, scope, global); 16.224 } 16.225 16.226 /** 16.227 * Constructor 16.228 * 16.229 - * @param data static function data 16.230 - * @param map property map 16.231 - * @param scope scope 16.232 + * @param name name of function 16.233 + * @param methodHandle handle for invocation 16.234 + * @param scope scope object 16.235 + * @param specs specialized versions of this method, if available, null 16.236 + * otherwise 16.237 + * @param flags {@link ScriptFunctionData} flags 16.238 */ 16.239 - protected ScriptFunction( 16.240 - final ScriptFunctionData data, 16.241 - final PropertyMap map, 16.242 - final ScriptObject scope) { 16.243 + private ScriptFunction( 16.244 + final String name, 16.245 + final MethodHandle methodHandle, 16.246 + final ScriptObject scope, 16.247 + final Specialization[] specs, 16.248 + final int flags) { 16.249 + this(name, methodHandle, getMap(isStrict(flags)), scope, specs, flags, Global.instance()); 16.250 + } 16.251 16.252 - super(map); 16.253 + /** 16.254 + * Constructor called by Nasgen generated code, zero added members, use the 16.255 + * default map. Creates builtin functions only. 16.256 + * 16.257 + * @param name name of function 16.258 + * @param invokeHandle handle for invocation 16.259 + * @param specs specialized versions of this method, if available, null 16.260 + * otherwise 16.261 + */ 16.262 + protected ScriptFunction(final String name, final MethodHandle invokeHandle, final Specialization[] specs) { 16.263 + this(name, invokeHandle, map$, null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR, Global.instance()); 16.264 + } 16.265 16.266 - if (Context.DEBUG) { 16.267 - constructorCount++; 16.268 + /** 16.269 + * Constructor called by Nasgen generated code, non zero member count, use 16.270 + * the map passed as argument. Creates builtin functions only. 16.271 + * 16.272 + * @param name name of function 16.273 + * @param invokeHandle handle for invocation 16.274 + * @param map initial property map 16.275 + * @param specs specialized versions of this method, if available, null 16.276 + * otherwise 16.277 + */ 16.278 + protected ScriptFunction(final String name, final MethodHandle invokeHandle, final PropertyMap map, final Specialization[] specs) { 16.279 + this(name, invokeHandle, map.addAll(map$), null, specs, ScriptFunctionData.IS_BUILTIN_CONSTRUCTOR, Global.instance()); 16.280 + } 16.281 + 16.282 + // Factory methods to create various functions 16.283 + /** 16.284 + * Factory method called by compiler generated code for functions that need 16.285 + * parent scope. 16.286 + * 16.287 + * @param constants the generated class' constant array 16.288 + * @param index the index of the {@code RecompilableScriptFunctionData} 16.289 + * object in the constants array. 16.290 + * @param scope the parent scope object 16.291 + * @return a newly created function object 16.292 + */ 16.293 + public static ScriptFunction create(final Object[] constants, final int index, final ScriptObject scope) { 16.294 + final RecompilableScriptFunctionData data = (RecompilableScriptFunctionData) constants[index]; 16.295 + return new ScriptFunction(data, getMap(data.isStrict()), scope, Global.instance()); 16.296 + } 16.297 + 16.298 + /** 16.299 + * Factory method called by compiler generated code for functions that don't 16.300 + * need parent scope. 16.301 + * 16.302 + * @param constants the generated class' constant array 16.303 + * @param index the index of the {@code RecompilableScriptFunctionData} 16.304 + * object in the constants array. 16.305 + * @return a newly created function object 16.306 + */ 16.307 + public static ScriptFunction create(final Object[] constants, final int index) { 16.308 + return create(constants, index, null); 16.309 + } 16.310 + 16.311 + /** 16.312 + * Create anonymous function that serves as Function.prototype 16.313 + * 16.314 + * @return anonymous function object 16.315 + */ 16.316 + public static ScriptFunction createAnonymous() { 16.317 + return new ScriptFunction("", GlobalFunctions.ANONYMOUS, anonmap$, null); 16.318 + } 16.319 + 16.320 + // builtin function create helper factory 16.321 + private static ScriptFunction createBuiltin(final String name, final MethodHandle methodHandle, final Specialization[] specs, final int flags) { 16.322 + final ScriptFunction func = new ScriptFunction(name, methodHandle, null, specs, flags); 16.323 + func.setPrototype(UNDEFINED); 16.324 + // Non-constructor built-in functions do not have "prototype" property 16.325 + func.deleteOwnProperty(func.getMap().findProperty("prototype")); 16.326 + 16.327 + return func; 16.328 + } 16.329 + 16.330 + /** 16.331 + * Factory method for non-constructor built-in functions 16.332 + * 16.333 + * @param name function name 16.334 + * @param methodHandle handle for invocation 16.335 + * @param specs specialized versions of function if available, null 16.336 + * otherwise 16.337 + * @return new ScriptFunction 16.338 + */ 16.339 + public static ScriptFunction createBuiltin(final String name, final MethodHandle methodHandle, final Specialization[] specs) { 16.340 + return ScriptFunction.createBuiltin(name, methodHandle, specs, ScriptFunctionData.IS_BUILTIN); 16.341 + } 16.342 + 16.343 + /** 16.344 + * Factory method for non-constructor built-in functions 16.345 + * 16.346 + * @param name function name 16.347 + * @param methodHandle handle for invocation 16.348 + * @return new ScriptFunction 16.349 + */ 16.350 + public static ScriptFunction createBuiltin(final String name, final MethodHandle methodHandle) { 16.351 + return ScriptFunction.createBuiltin(name, methodHandle, null); 16.352 + } 16.353 + 16.354 + /** 16.355 + * Factory method for non-constructor built-in, strict functions 16.356 + * 16.357 + * @param name function name 16.358 + * @param methodHandle handle for invocation 16.359 + * @return new ScriptFunction 16.360 + */ 16.361 + public static ScriptFunction createStrictBuiltin(final String name, final MethodHandle methodHandle) { 16.362 + return ScriptFunction.createBuiltin(name, methodHandle, null, ScriptFunctionData.IS_BUILTIN | ScriptFunctionData.IS_STRICT); 16.363 + } 16.364 + 16.365 + // Subclass to represent bound functions 16.366 + private static class Bound extends ScriptFunction { 16.367 + private final ScriptFunction target; 16.368 + 16.369 + Bound(final ScriptFunctionData boundData, final ScriptFunction target) { 16.370 + super(boundData, boundfunctionmap$, null, Global.instance()); 16.371 + setPrototype(ScriptRuntime.UNDEFINED); 16.372 + this.target = target; 16.373 } 16.374 16.375 - this.data = data; 16.376 - this.scope = scope; 16.377 + @Override 16.378 + protected ScriptFunction getTargetFunction() { 16.379 + return target; 16.380 + } 16.381 + } 16.382 + 16.383 + /** 16.384 + * Creates a version of this function bound to a specific "self" and other 16.385 + * arguments, as per {@code Function.prototype.bind} functionality in 16.386 + * ECMAScript 5.1 section 15.3.4.5. 16.387 + * 16.388 + * @param self the self to bind to this function. Can be null (in which 16.389 + * case, null is bound as this). 16.390 + * @param args additional arguments to bind to this function. Can be null or 16.391 + * empty to not bind additional arguments. 16.392 + * @return a function with the specified self and parameters bound. 16.393 + */ 16.394 + public final ScriptFunction createBound(final Object self, final Object[] args) { 16.395 + return new Bound(data.makeBoundFunctionData(this, self, args), getTargetFunction()); 16.396 + } 16.397 + 16.398 + /** 16.399 + * Create a function that invokes this function synchronized on {@code sync} 16.400 + * or the self object of the invocation. 16.401 + * 16.402 + * @param sync the Object to synchronize on, or undefined 16.403 + * @return synchronized function 16.404 + */ 16.405 + public final ScriptFunction createSynchronized(final Object sync) { 16.406 + final MethodHandle mh = MH.insertArguments(ScriptFunction.INVOKE_SYNC, 0, this, sync); 16.407 + return createBuiltin(getName(), mh); 16.408 } 16.409 16.410 @Override 16.411 @@ -151,8 +413,8 @@ 16.412 } 16.413 16.414 /** 16.415 - * ECMA 15.3.5.3 [[HasInstance]] (V) 16.416 - * Step 3 if "prototype" value is not an Object, throw TypeError 16.417 + * ECMA 15.3.5.3 [[HasInstance]] (V) Step 3 if "prototype" value is not an 16.418 + * Object, throw TypeError 16.419 */ 16.420 @Override 16.421 public boolean isInstance(final ScriptObject instance) { 16.422 @@ -171,22 +433,25 @@ 16.423 } 16.424 16.425 /** 16.426 - * Returns the target function for this function. If the function was not created using 16.427 - * {@link #makeBoundFunction(Object, Object[])}, its target function is itself. If it is bound, its target function 16.428 - * is the target function of the function it was made from (therefore, the target function is always the final, 16.429 - * unbound recipient of the calls). 16.430 + * Returns the target function for this function. If the function was not 16.431 + * created using {@link #createBound(Object, Object[])}, its target 16.432 + * function is itself. If it is bound, its target function is the target 16.433 + * function of the function it was made from (therefore, the target function 16.434 + * is always the final, unbound recipient of the calls). 16.435 + * 16.436 * @return the target function for this function. 16.437 */ 16.438 protected ScriptFunction getTargetFunction() { 16.439 return this; 16.440 } 16.441 16.442 - boolean isBoundFunction() { 16.443 + final boolean isBoundFunction() { 16.444 return getTargetFunction() != this; 16.445 } 16.446 16.447 /** 16.448 * Set the arity of this ScriptFunction 16.449 + * 16.450 * @param arity arity 16.451 */ 16.452 public final void setArity(final int arity) { 16.453 @@ -195,59 +460,66 @@ 16.454 16.455 /** 16.456 * Is this a ECMAScript 'use strict' function? 16.457 + * 16.458 * @return true if function is in strict mode 16.459 */ 16.460 - public boolean isStrict() { 16.461 + public final boolean isStrict() { 16.462 return data.isStrict(); 16.463 } 16.464 16.465 /** 16.466 - * Returns true if this is a non-strict, non-built-in function that requires non-primitive this argument 16.467 - * according to ECMA 10.4.3. 16.468 + * Returns true if this is a non-strict, non-built-in function that requires 16.469 + * non-primitive this argument according to ECMA 10.4.3. 16.470 + * 16.471 * @return true if this argument must be an object 16.472 */ 16.473 - public boolean needsWrappedThis() { 16.474 + public final boolean needsWrappedThis() { 16.475 return data.needsWrappedThis(); 16.476 } 16.477 16.478 private static boolean needsWrappedThis(final Object fn) { 16.479 - return fn instanceof ScriptFunction ? ((ScriptFunction)fn).needsWrappedThis() : false; 16.480 + return fn instanceof ScriptFunction ? ((ScriptFunction) fn).needsWrappedThis() : false; 16.481 } 16.482 16.483 /** 16.484 * Execute this script function. 16.485 - * @param self Target object. 16.486 - * @param arguments Call arguments. 16.487 + * 16.488 + * @param self Target object. 16.489 + * @param arguments Call arguments. 16.490 * @return ScriptFunction result. 16.491 - * @throws Throwable if there is an exception/error with the invocation or thrown from it 16.492 + * @throws Throwable if there is an exception/error with the invocation or 16.493 + * thrown from it 16.494 */ 16.495 - Object invoke(final Object self, final Object... arguments) throws Throwable { 16.496 + final Object invoke(final Object self, final Object... arguments) throws Throwable { 16.497 if (Context.DEBUG) { 16.498 - invokes++; 16.499 + invokes.increment(); 16.500 } 16.501 return data.invoke(this, self, arguments); 16.502 } 16.503 16.504 /** 16.505 * Execute this script function as a constructor. 16.506 - * @param arguments Call arguments. 16.507 + * 16.508 + * @param arguments Call arguments. 16.509 * @return Newly constructed result. 16.510 - * @throws Throwable if there is an exception/error with the invocation or thrown from it 16.511 + * @throws Throwable if there is an exception/error with the invocation or 16.512 + * thrown from it 16.513 */ 16.514 - Object construct(final Object... arguments) throws Throwable { 16.515 + final Object construct(final Object... arguments) throws Throwable { 16.516 return data.construct(this, arguments); 16.517 } 16.518 16.519 /** 16.520 - * Allocate function. Called from generated {@link ScriptObject} code 16.521 - * for allocation as a factory method 16.522 + * Allocate function. Called from generated {@link ScriptObject} code for 16.523 + * allocation as a factory method 16.524 * 16.525 - * @return a new instance of the {@link ScriptObject} whose allocator this is 16.526 + * @return a new instance of the {@link ScriptObject} whose allocator this 16.527 + * is 16.528 */ 16.529 @SuppressWarnings("unused") 16.530 private Object allocate() { 16.531 if (Context.DEBUG) { 16.532 - allocations++; 16.533 + allocations.increment(); 16.534 } 16.535 16.536 assert !isBoundFunction(); // allocate never invoked on bound functions 16.537 @@ -257,7 +529,7 @@ 16.538 if (object != null) { 16.539 final Object prototype = getPrototype(); 16.540 if (prototype instanceof ScriptObject) { 16.541 - object.setInitialProto((ScriptObject)prototype); 16.542 + object.setInitialProto((ScriptObject) prototype); 16.543 } 16.544 16.545 if (object.getProto() == null) { 16.546 @@ -277,43 +549,28 @@ 16.547 16.548 /** 16.549 * Return Object.prototype - used by "allocate" 16.550 + * 16.551 * @return Object.prototype 16.552 */ 16.553 - protected abstract ScriptObject getObjectPrototype(); 16.554 - 16.555 - /** 16.556 - * Creates a version of this function bound to a specific "self" and other arguments, as per 16.557 - * {@code Function.prototype.bind} functionality in ECMAScript 5.1 section 15.3.4.5. 16.558 - * @param self the self to bind to this function. Can be null (in which case, null is bound as this). 16.559 - * @param args additional arguments to bind to this function. Can be null or empty to not bind additional arguments. 16.560 - * @return a function with the specified self and parameters bound. 16.561 - */ 16.562 - protected ScriptFunction makeBoundFunction(final Object self, final Object[] args) { 16.563 - return makeBoundFunction(data.makeBoundFunctionData(this, self, args)); 16.564 + protected final ScriptObject getObjectPrototype() { 16.565 + return Global.objectPrototype(); 16.566 } 16.567 16.568 - /** 16.569 - * Create a version of this function as in {@link ScriptFunction#makeBoundFunction(Object, Object[])}, 16.570 - * but using a {@link ScriptFunctionData} for the bound data. 16.571 - * 16.572 - * @param boundData ScriptFuntionData for the bound function 16.573 - * @return a function with the bindings performed according to the given data 16.574 - */ 16.575 - protected abstract ScriptFunction makeBoundFunction(ScriptFunctionData boundData); 16.576 - 16.577 @Override 16.578 public final String safeToString() { 16.579 return toSource(); 16.580 } 16.581 16.582 @Override 16.583 - public String toString() { 16.584 + public final String toString() { 16.585 return data.toString(); 16.586 } 16.587 16.588 /** 16.589 - * Get this function as a String containing its source code. If no source code 16.590 - * exists in this ScriptFunction, its contents will be displayed as {@code [native code]} 16.591 + * Get this function as a String containing its source code. If no source 16.592 + * code exists in this ScriptFunction, its contents will be displayed as 16.593 + * {@code [native code]} 16.594 + * 16.595 * @return string representation of this function's source 16.596 */ 16.597 public final String toSource() { 16.598 @@ -322,27 +579,32 @@ 16.599 16.600 /** 16.601 * Get the prototype object for this function 16.602 + * 16.603 * @return prototype 16.604 */ 16.605 - public abstract Object getPrototype(); 16.606 + public final Object getPrototype() { 16.607 + if (prototype == LAZY_PROTOTYPE) { 16.608 + prototype = new PrototypeObject(this); 16.609 + } 16.610 + return prototype; 16.611 + } 16.612 16.613 /** 16.614 * Set the prototype object for this function 16.615 - * @param prototype new prototype object 16.616 + * 16.617 + * @param newPrototype new prototype object 16.618 */ 16.619 - public abstract void setPrototype(Object prototype); 16.620 + public final void setPrototype(Object newPrototype) { 16.621 + if (newPrototype instanceof ScriptObject && newPrototype != this.prototype && allocatorMap != null) { 16.622 + // Replace our current allocator map with one that is associated with the new prototype. 16.623 + allocatorMap = allocatorMap.changeProto((ScriptObject) newPrototype); 16.624 + } 16.625 + this.prototype = newPrototype; 16.626 + } 16.627 16.628 /** 16.629 - * Create a function that invokes this function synchronized on {@code sync} or the self object 16.630 - * of the invocation. 16.631 - * @param sync the Object to synchronize on, or undefined 16.632 - * @return synchronized function 16.633 - */ 16.634 - public abstract ScriptFunction makeSynchronizedFunction(Object sync); 16.635 - 16.636 - /** 16.637 - * Return the invoke handle bound to a given ScriptObject self reference. 16.638 - * If callee parameter is required result is rebound to this. 16.639 + * Return the invoke handle bound to a given ScriptObject self reference. If 16.640 + * callee parameter is required result is rebound to this. 16.641 * 16.642 * @param self self reference 16.643 * @return bound invoke handle 16.644 @@ -352,9 +614,12 @@ 16.645 } 16.646 16.647 /** 16.648 - * Bind the method handle to this {@code ScriptFunction} instance if it needs a callee parameter. If this function's 16.649 - * method handles don't have a callee parameter, the handle is returned unchanged. 16.650 - * @param methodHandle the method handle to potentially bind to this function instance. 16.651 + * Bind the method handle to this {@code ScriptFunction} instance if it 16.652 + * needs a callee parameter. If this function's method handles don't have a 16.653 + * callee parameter, the handle is returned unchanged. 16.654 + * 16.655 + * @param methodHandle the method handle to potentially bind to this 16.656 + * function instance. 16.657 * @return the potentially bound method handle 16.658 */ 16.659 private MethodHandle bindToCalleeIfNeeded(final MethodHandle methodHandle) { 16.660 @@ -364,15 +629,16 @@ 16.661 16.662 /** 16.663 * Get the name for this function 16.664 + * 16.665 * @return the name 16.666 */ 16.667 public final String getName() { 16.668 return data.getName(); 16.669 } 16.670 16.671 - 16.672 /** 16.673 * Get the scope for this function 16.674 + * 16.675 * @return the scope 16.676 */ 16.677 public final ScriptObject getScope() { 16.678 @@ -383,36 +649,37 @@ 16.679 * Prototype getter for this ScriptFunction - follows the naming convention 16.680 * used by Nasgen and the code generator 16.681 * 16.682 - * @param self self reference 16.683 + * @param self self reference 16.684 * @return self's prototype 16.685 */ 16.686 public static Object G$prototype(final Object self) { 16.687 - return self instanceof ScriptFunction ? 16.688 - ((ScriptFunction)self).getPrototype() : 16.689 - UNDEFINED; 16.690 + return self instanceof ScriptFunction 16.691 + ? ((ScriptFunction) self).getPrototype() 16.692 + : UNDEFINED; 16.693 } 16.694 16.695 /** 16.696 * Prototype setter for this ScriptFunction - follows the naming convention 16.697 * used by Nasgen and the code generator 16.698 * 16.699 - * @param self self reference 16.700 + * @param self self reference 16.701 * @param prototype prototype to set 16.702 */ 16.703 public static void S$prototype(final Object self, final Object prototype) { 16.704 if (self instanceof ScriptFunction) { 16.705 - ((ScriptFunction)self).setPrototype(prototype); 16.706 + ((ScriptFunction) self).setPrototype(prototype); 16.707 } 16.708 } 16.709 16.710 /** 16.711 * Length getter - ECMA 15.3.3.2: Function.length 16.712 + * 16.713 * @param self self reference 16.714 * @return length 16.715 */ 16.716 public static int G$length(final Object self) { 16.717 if (self instanceof ScriptFunction) { 16.718 - return ((ScriptFunction)self).data.getArity(); 16.719 + return ((ScriptFunction) self).data.getArity(); 16.720 } 16.721 16.722 return 0; 16.723 @@ -420,12 +687,13 @@ 16.724 16.725 /** 16.726 * Name getter - ECMA Function.name 16.727 + * 16.728 * @param self self refence 16.729 * @return the name, or undefined if none 16.730 */ 16.731 public static Object G$name(final Object self) { 16.732 if (self instanceof ScriptFunction) { 16.733 - return ((ScriptFunction)self).getName(); 16.734 + return ((ScriptFunction) self).getName(); 16.735 } 16.736 16.737 return UNDEFINED; 16.738 @@ -433,6 +701,7 @@ 16.739 16.740 /** 16.741 * Get the prototype for this ScriptFunction 16.742 + * 16.743 * @param constructor constructor 16.744 * @return prototype, or null if given constructor is not a ScriptFunction 16.745 */ 16.746 @@ -440,7 +709,7 @@ 16.747 if (constructor != null) { 16.748 final Object proto = constructor.getPrototype(); 16.749 if (proto instanceof ScriptObject) { 16.750 - return (ScriptObject)proto; 16.751 + return (ScriptObject) proto; 16.752 } 16.753 } 16.754 16.755 @@ -448,29 +717,37 @@ 16.756 } 16.757 16.758 // These counters are updated only in debug mode. 16.759 - private static int constructorCount; 16.760 - private static int invokes; 16.761 - private static int allocations; 16.762 + private static LongAdder constructorCount; 16.763 + private static LongAdder invokes; 16.764 + private static LongAdder allocations; 16.765 + 16.766 + static { 16.767 + if (Context.DEBUG) { 16.768 + constructorCount = new LongAdder(); 16.769 + invokes = new LongAdder(); 16.770 + allocations = new LongAdder(); 16.771 + } 16.772 + } 16.773 16.774 /** 16.775 * @return the constructorCount 16.776 */ 16.777 - public static int getConstructorCount() { 16.778 - return constructorCount; 16.779 + public static long getConstructorCount() { 16.780 + return constructorCount.longValue(); 16.781 } 16.782 16.783 /** 16.784 * @return the invokes 16.785 */ 16.786 - public static int getInvokes() { 16.787 - return invokes; 16.788 + public static long getInvokes() { 16.789 + return invokes.longValue(); 16.790 } 16.791 16.792 /** 16.793 * @return the allocations 16.794 */ 16.795 - public static int getAllocations() { 16.796 - return allocations; 16.797 + public static long getAllocations() { 16.798 + return allocations.longValue(); 16.799 } 16.800 16.801 @Override 16.802 @@ -490,7 +767,6 @@ 16.803 return Context.getGlobal().wrapAsObject(obj); 16.804 } 16.805 16.806 - 16.807 @SuppressWarnings("unused") 16.808 private static Object globalFilter(final Object object) { 16.809 // replace whatever we get with the current global object 16.810 @@ -498,14 +774,16 @@ 16.811 } 16.812 16.813 /** 16.814 - * Some receivers are primitive, in that case, according to the Spec we create a new 16.815 - * native object per callsite with the wrap filter. We can only apply optimistic builtins 16.816 - * if there is no per instance state saved for these wrapped objects (e.g. currently NativeStrings), 16.817 - * otherwise we can't create optimistic versions 16.818 + * Some receivers are primitive, in that case, according to the Spec we 16.819 + * create a new native object per callsite with the wrap filter. We can only 16.820 + * apply optimistic builtins if there is no per instance state saved for 16.821 + * these wrapped objects (e.g. currently NativeStrings), otherwise we can't 16.822 + * create optimistic versions 16.823 * 16.824 - * @param self receiver 16.825 - * @param linkLogicClass linkLogicClass, or null if no link logic exists 16.826 - * @return link logic instance, or null if one could not be constructed for this receiver 16.827 + * @param self receiver 16.828 + * @param linkLogicClass linkLogicClass, or null if no link logic exists 16.829 + * @return link logic instance, or null if one could not be constructed for 16.830 + * this receiver 16.831 */ 16.832 private static LinkLogic getLinkLogic(final Object self, final Class<? extends LinkLogic> linkLogicClass) { 16.833 if (linkLogicClass == null) { 16.834 @@ -518,25 +796,25 @@ 16.835 16.836 final Object wrappedSelf = wrapFilter(self); 16.837 if (wrappedSelf instanceof OptimisticBuiltins) { 16.838 - if (wrappedSelf != self && ((OptimisticBuiltins)wrappedSelf).hasPerInstanceAssumptions()) { 16.839 + if (wrappedSelf != self && ((OptimisticBuiltins) wrappedSelf).hasPerInstanceAssumptions()) { 16.840 return null; //pessimistic - we created a wrapped object different from the primitive, but the assumptions have instance state 16.841 } 16.842 - return ((OptimisticBuiltins)wrappedSelf).getLinkLogic(linkLogicClass); 16.843 + return ((OptimisticBuiltins) wrappedSelf).getLinkLogic(linkLogicClass); 16.844 } 16.845 return null; 16.846 } 16.847 16.848 /** 16.849 - * dyn:call call site signature: (callee, thiz, [args...]) 16.850 - * generated method signature: (callee, thiz, [args...]) 16.851 + * dyn:call call site signature: (callee, thiz, [args...]) generated method 16.852 + * signature: (callee, thiz, [args...]) 16.853 * 16.854 * cases: 16.855 * (a) method has callee parameter 16.856 - * (1) for local/scope calls, we just bind thiz and drop the second argument. 16.857 - * (2) for normal this-calls, we have to swap thiz and callee to get matching signatures. 16.858 + * (1) for local/scope calls, we just bind thiz and drop the second argument. 16.859 + * (2) for normal this-calls, we have to swap thiz and callee to get matching signatures. 16.860 * (b) method doesn't have callee parameter (builtin functions) 16.861 - * (3) for local/scope calls, bind thiz and drop both callee and thiz. 16.862 - * (4) for normal this-calls, drop callee. 16.863 + * (3) for local/scope calls, bind thiz and drop both callee and thiz. 16.864 + * (4) for normal this-calls, drop callee. 16.865 * 16.866 * @return guarded invocation for call 16.867 */ 16.868 @@ -544,11 +822,11 @@ 16.869 protected GuardedInvocation findCallMethod(final CallSiteDescriptor desc, final LinkRequest request) { 16.870 final MethodType type = desc.getMethodType(); 16.871 16.872 - final String name = getName(); 16.873 + final String name = getName(); 16.874 final boolean isUnstable = request.isCallSiteUnstable(); 16.875 - final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 16.876 - final boolean isCall = !scopeCall && data.isBuiltin() && "call".equals(name); 16.877 - final boolean isApply = !scopeCall && data.isBuiltin() && "apply".equals(name); 16.878 + final boolean scopeCall = NashornCallSiteDescriptor.isScope(desc); 16.879 + final boolean isCall = !scopeCall && data.isBuiltin() && "call".equals(name); 16.880 + final boolean isApply = !scopeCall && data.isBuiltin() && "apply".equals(name); 16.881 16.882 final boolean isApplyOrCall = isCall | isApply; 16.883 16.884 @@ -569,7 +847,7 @@ 16.885 return new GuardedInvocation( 16.886 handle, 16.887 null, 16.888 - (SwitchPoint)null, 16.889 + (SwitchPoint) null, 16.890 ClassCastException.class); 16.891 } 16.892 16.893 @@ -672,14 +950,14 @@ 16.894 this, 16.895 cf.getFlags()) : 16.896 guard, 16.897 - spsArray, 16.898 + spsArray, 16.899 exceptionGuard); 16.900 } 16.901 16.902 private GuardedInvocation createApplyOrCallCall(final boolean isApply, final CallSiteDescriptor desc, final LinkRequest request, final Object[] args) { 16.903 final MethodType descType = desc.getMethodType(); 16.904 final int paramCount = descType.parameterCount(); 16.905 - if(descType.parameterType(paramCount - 1).isArray()) { 16.906 + if (descType.parameterType(paramCount - 1).isArray()) { 16.907 // This is vararg invocation of apply or call. This can normally only happen when we do a recursive 16.908 // invocation of createApplyOrCallCall (because we're doing apply-of-apply). In this case, create delegate 16.909 // linkage by unpacking the vararg invocation and use pairArguments to introduce the necessary spreader. 16.910 @@ -786,7 +1064,7 @@ 16.911 inv = MH.filterArguments(inv, 2, NativeFunction.TO_APPLY_ARGS); 16.912 } else { 16.913 // If the original call site doesn't pass argArray, pass in an empty array 16.914 - inv = MH.insertArguments(inv, 2, (Object)ScriptRuntime.EMPTY_ARRAY); 16.915 + inv = MH.insertArguments(inv, 2, (Object) ScriptRuntime.EMPTY_ARRAY); 16.916 } 16.917 } 16.918 16.919 @@ -851,7 +1129,7 @@ 16.920 final LinkRequest request, final Object[] args) { 16.921 final MethodType descType = desc.getMethodType(); 16.922 final int paramCount = descType.parameterCount(); 16.923 - final Object[] varArgs = (Object[])args[paramCount - 1]; 16.924 + final Object[] varArgs = (Object[]) args[paramCount - 1]; 16.925 // -1 'cause we're not passing the vararg array itself 16.926 final int copiedArgCount = args.length - 1; 16.927 final int varArgCount = varArgs.length; 16.928 @@ -893,7 +1171,7 @@ 16.929 // If the last parameter type of the guard is an array, then it is already itself a guard for a vararg apply 16.930 // invocation. We must filter the last argument with toApplyArgs otherwise deeper levels of nesting will fail 16.931 // with ClassCastException of NativeArray to Object[]. 16.932 - if(guardType.parameterType(guardParamCount - 1).isArray()) { 16.933 + if (guardType.parameterType(guardParamCount - 1).isArray()) { 16.934 arrayConvertingGuard = MH.filterArguments(guard, guardParamCount - 1, NativeFunction.TO_APPLY_ARGS); 16.935 } else { 16.936 arrayConvertingGuard = guard; 16.937 @@ -903,19 +1181,20 @@ 16.938 } 16.939 16.940 private static MethodHandle bindImplicitThis(final Object fn, final MethodHandle mh) { 16.941 - final MethodHandle bound; 16.942 - if(fn instanceof ScriptFunction && ((ScriptFunction)fn).needsWrappedThis()) { 16.943 - bound = MH.filterArguments(mh, 1, SCRIPTFUNCTION_GLOBALFILTER); 16.944 - } else { 16.945 - bound = mh; 16.946 - } 16.947 - return MH.insertArguments(bound, 1, ScriptRuntime.UNDEFINED); 16.948 - } 16.949 + final MethodHandle bound; 16.950 + if (fn instanceof ScriptFunction && ((ScriptFunction) fn).needsWrappedThis()) { 16.951 + bound = MH.filterArguments(mh, 1, SCRIPTFUNCTION_GLOBALFILTER); 16.952 + } else { 16.953 + bound = mh; 16.954 + } 16.955 + return MH.insertArguments(bound, 1, ScriptRuntime.UNDEFINED); 16.956 + } 16.957 16.958 /** 16.959 * Used for noSuchMethod/noSuchProperty and JSAdapter hooks. 16.960 * 16.961 - * These don't want a callee parameter, so bind that. Name binding is optional. 16.962 + * These don't want a callee parameter, so bind that. Name binding is 16.963 + * optional. 16.964 */ 16.965 MethodHandle getCallMethodHandle(final MethodType type, final String bindName) { 16.966 return pairArguments(bindToNameIfNeeded(bindToCalleeIfNeeded(data.getGenericInvoker(scope)), bindName), type); 16.967 @@ -939,10 +1218,11 @@ 16.968 } 16.969 16.970 /** 16.971 - * Get the guard that checks if a {@link ScriptFunction} is equal to 16.972 - * a known ScriptFunction, using reference comparison 16.973 + * Get the guard that checks if a {@link ScriptFunction} is equal to a known 16.974 + * ScriptFunction, using reference comparison 16.975 * 16.976 - * @param function The ScriptFunction to check against. This will be bound to the guard method handle 16.977 + * @param function The ScriptFunction to check against. This will be bound 16.978 + * to the guard method handle 16.979 * 16.980 * @return method handle for guard 16.981 */ 16.982 @@ -957,11 +1237,12 @@ 16.983 } 16.984 16.985 /** 16.986 - * Get a guard that checks if a {@link ScriptFunction} is equal to 16.987 - * a known ScriptFunction using reference comparison, and whether the type of 16.988 - * the second argument (this-object) is not a JavaScript primitive type. 16.989 + * Get a guard that checks if a {@link ScriptFunction} is equal to a known 16.990 + * ScriptFunction using reference comparison, and whether the type of the 16.991 + * second argument (this-object) is not a JavaScript primitive type. 16.992 * 16.993 - * @param function The ScriptFunction to check against. This will be bound to the guard method handle 16.994 + * @param function The ScriptFunction to check against. This will be bound 16.995 + * to the guard method handle 16.996 * 16.997 * @return method handle for guard 16.998 */ 16.999 @@ -972,12 +1253,12 @@ 16.1000 16.1001 @SuppressWarnings("unused") 16.1002 private static boolean isFunctionMH(final Object self, final ScriptFunctionData data) { 16.1003 - return self instanceof ScriptFunction && ((ScriptFunction)self).data == data; 16.1004 + return self instanceof ScriptFunction && ((ScriptFunction) self).data == data; 16.1005 } 16.1006 16.1007 @SuppressWarnings("unused") 16.1008 private static boolean isNonStrictFunction(final Object self, final Object arg, final ScriptFunctionData data) { 16.1009 - return self instanceof ScriptFunction && ((ScriptFunction)self).data == data && arg instanceof ScriptObject; 16.1010 + return self instanceof ScriptFunction && ((ScriptFunction) self).data == data && arg instanceof ScriptObject; 16.1011 } 16.1012 16.1013 //TODO this can probably be removed given that we have builtin switchpoints in the context 16.1014 @@ -990,7 +1271,7 @@ 16.1015 @SuppressWarnings("unused") 16.1016 private static Object[] addZerothElement(final Object[] args, final Object value) { 16.1017 // extends input array with by adding new zeroth element 16.1018 - final Object[] src = args == null? ScriptRuntime.EMPTY_ARRAY : args; 16.1019 + final Object[] src = args == null ? ScriptRuntime.EMPTY_ARRAY : args; 16.1020 final Object[] result = new Object[src.length + 1]; 16.1021 System.arraycopy(src, 0, result, 1, src.length); 16.1022 result[0] = value; 16.1023 @@ -1014,4 +1295,3 @@ 16.1024 return MH.findVirtual(MethodHandles.lookup(), ScriptFunction.class, name, MH.type(rtype, types)); 16.1025 } 16.1026 } 16.1027 -
17.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Thu Sep 10 09:59:23 2015 +0530 17.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Sep 09 17:19:46 2015 +0530 17.3 @@ -397,7 +397,7 @@ 17.4 17.5 /** 17.6 * This method is used to create the immutable portion of a bound function. 17.7 - * See {@link ScriptFunction#makeBoundFunction(Object, Object[])} 17.8 + * See {@link ScriptFunction#createBound(Object, Object[])} 17.9 * 17.10 * @param fn the original function being bound 17.11 * @param self this reference to bind. Can be null.
18.1 --- a/src/jdk/nashorn/internal/runtime/ScriptObject.java Thu Sep 10 09:59:23 2015 +0530 18.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptObject.java Wed Sep 09 17:19:46 2015 +0530 18.3 @@ -64,6 +64,7 @@ 18.4 import java.util.List; 18.5 import java.util.Map; 18.6 import java.util.Set; 18.7 +import java.util.concurrent.atomic.LongAdder; 18.8 import jdk.internal.dynalink.CallSiteDescriptor; 18.9 import jdk.internal.dynalink.linker.GuardedInvocation; 18.10 import jdk.internal.dynalink.linker.LinkRequest; 18.11 @@ -211,7 +212,7 @@ 18.12 */ 18.13 public ScriptObject(final PropertyMap map) { 18.14 if (Context.DEBUG) { 18.15 - ScriptObject.count++; 18.16 + ScriptObject.count.increment(); 18.17 } 18.18 this.arrayData = ArrayData.EMPTY_ARRAY; 18.19 this.setMap(map == null ? PropertyMap.newMap() : map); 18.20 @@ -2301,7 +2302,7 @@ 18.21 MH.dropArguments( 18.22 MH.constant( 18.23 ScriptFunction.class, 18.24 - func.makeBoundFunction(thiz, new Object[] { name })), 18.25 + func.createBound(thiz, new Object[] { name })), 18.26 0, 18.27 Object.class), 18.28 NashornGuards.combineGuards( 18.29 @@ -2407,7 +2408,7 @@ 18.30 return UNDEFINED; 18.31 } 18.32 18.33 - return ((ScriptFunction)value).makeBoundFunction(this, new Object[] {name}); 18.34 + return ((ScriptFunction)value).createBound(this, new Object[] {name}); 18.35 } 18.36 18.37 private GuardedInvocation createEmptyGetter(final CallSiteDescriptor desc, final boolean explicitInstanceOfCheck, final String name) { 18.38 @@ -3796,15 +3797,20 @@ 18.39 } 18.40 18.41 /** This is updated only in debug mode - counts number of {@code ScriptObject} instances created */ 18.42 - private static int count; 18.43 - 18.44 + private static LongAdder count; 18.45 + 18.46 + static { 18.47 + if (Context.DEBUG) { 18.48 + count = new LongAdder(); 18.49 + } 18.50 + } 18.51 /** 18.52 * Get number of {@code ScriptObject} instances created. If not running in debug 18.53 * mode this is always 0 18.54 * 18.55 * @return number of ScriptObjects created 18.56 */ 18.57 - public static int getCount() { 18.58 - return count; 18.59 + public static long getCount() { 18.60 + return count.longValue(); 18.61 } 18.62 }
19.1 --- a/src/jdk/nashorn/internal/runtime/WithObject.java Thu Sep 10 09:59:23 2015 +0530 19.2 +++ b/src/jdk/nashorn/internal/runtime/WithObject.java Wed Sep 09 17:19:46 2015 +0530 19.3 @@ -352,7 +352,7 @@ 19.4 } 19.5 19.6 private static Object bindToExpression(final ScriptFunction fn, final Object receiver) { 19.7 - return fn.makeBoundFunction(withFilterExpression(receiver), ScriptRuntime.EMPTY_ARRAY); 19.8 + return fn.createBound(withFilterExpression(receiver), ScriptRuntime.EMPTY_ARRAY); 19.9 } 19.10 19.11 private MethodHandle expressionGuard(final String name, final ScriptObject owner) {
20.1 --- a/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Thu Sep 10 09:59:23 2015 +0530 20.2 +++ b/src/jdk/nashorn/internal/runtime/linker/Bootstrap.java Wed Sep 09 17:19:46 2015 +0530 20.3 @@ -50,7 +50,6 @@ 20.4 import jdk.nashorn.internal.codegen.ObjectClassGenerator; 20.5 import jdk.nashorn.internal.lookup.MethodHandleFactory; 20.6 import jdk.nashorn.internal.lookup.MethodHandleFunctionality; 20.7 -import jdk.nashorn.internal.objects.ScriptFunctionImpl; 20.8 import jdk.nashorn.internal.runtime.ECMAException; 20.9 import jdk.nashorn.internal.runtime.JSType; 20.10 import jdk.nashorn.internal.runtime.OptimisticReturnFilters; 20.11 @@ -397,8 +396,8 @@ 20.12 * @throws ECMAException with {@code TypeError} if the object is not a callable. 20.13 */ 20.14 public static Object bindCallable(final Object callable, final Object boundThis, final Object[] boundArgs) { 20.15 - if (callable instanceof ScriptFunctionImpl) { 20.16 - return ((ScriptFunctionImpl)callable).makeBoundFunction(boundThis, boundArgs); 20.17 + if (callable instanceof ScriptFunction) { 20.18 + return ((ScriptFunction)callable).createBound(boundThis, boundArgs); 20.19 } else if (callable instanceof BoundCallable) { 20.20 return ((BoundCallable)callable).bind(boundArgs); 20.21 } else if (isCallable(callable)) {
21.1 --- a/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Thu Sep 10 09:59:23 2015 +0530 21.2 +++ b/src/jdk/nashorn/internal/runtime/linker/LinkerCallSite.java Wed Sep 09 17:19:46 2015 +0530 21.3 @@ -43,6 +43,7 @@ 21.4 import java.util.Random; 21.5 import java.util.Set; 21.6 import java.util.concurrent.atomic.AtomicInteger; 21.7 +import java.util.concurrent.atomic.LongAdder; 21.8 import jdk.internal.dynalink.ChainedCallSite; 21.9 import jdk.internal.dynalink.DynamicLinker; 21.10 import jdk.internal.dynalink.linker.GuardedInvocation; 21.11 @@ -70,7 +71,7 @@ 21.12 LinkerCallSite(final NashornCallSiteDescriptor descriptor) { 21.13 super(descriptor); 21.14 if (Context.DEBUG) { 21.15 - LinkerCallSite.count++; 21.16 + LinkerCallSite.count.increment(); 21.17 } 21.18 } 21.19 21.20 @@ -173,7 +174,7 @@ 21.21 * @return self reference 21.22 */ 21.23 public static Object increaseMissCount(final String desc, final Object self) { 21.24 - ++missCount; 21.25 + missCount.increment(); 21.26 if (r.nextInt(100) < missSamplingPercentage) { 21.27 final AtomicInteger i = missCounts.get(desc); 21.28 if (i == null) { 21.29 @@ -509,12 +510,19 @@ 21.30 } 21.31 21.32 // counters updated in debug mode 21.33 - private static int count; 21.34 + private static LongAdder count; 21.35 private static final HashMap<String, AtomicInteger> missCounts = new HashMap<>(); 21.36 - private static int missCount; 21.37 + private static LongAdder missCount; 21.38 private static final Random r = new Random(); 21.39 private static final int missSamplingPercentage = Options.getIntProperty("nashorn.tcs.miss.samplePercent", 1); 21.40 21.41 + static { 21.42 + if (Context.DEBUG) { 21.43 + count = new LongAdder(); 21.44 + missCount = new LongAdder(); 21.45 + } 21.46 + } 21.47 + 21.48 @Override 21.49 protected int getMaxChainLength() { 21.50 return 8; 21.51 @@ -524,16 +532,16 @@ 21.52 * Get the callsite count 21.53 * @return the count 21.54 */ 21.55 - public static int getCount() { 21.56 - return count; 21.57 + public static long getCount() { 21.58 + return count.longValue(); 21.59 } 21.60 21.61 /** 21.62 * Get the callsite miss count 21.63 * @return the missCount 21.64 */ 21.65 - public static int getMissCount() { 21.66 - return missCount; 21.67 + public static long getMissCount() { 21.68 + return missCount.longValue(); 21.69 } 21.70 21.71 /**