Thu, 17 Dec 2015 20:04:46 +0530
8145550: Megamorphic invoke should use CompiledFunction variants without any LinkLogic
Reviewed-by: jlaskey, hannesw, attila
1.1 --- a/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Mon Nov 23 10:08:15 2015 +0100 1.2 +++ b/src/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Thu Dec 17 20:04:46 2015 +0530 1.3 @@ -89,11 +89,16 @@ 1.4 } 1.5 1.6 @Override 1.7 - CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) { 1.8 + CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, boolean linkLogicOkay) { 1.9 assert isValidCallSite(callSiteType) : callSiteType; 1.10 1.11 CompiledFunction best = null; 1.12 for (final CompiledFunction candidate: code) { 1.13 + if (!linkLogicOkay && candidate.hasLinkLogic()) { 1.14 + // Skip! Version with no link logic is desired, but this one has link logic! 1.15 + continue; 1.16 + } 1.17 + 1.18 if (!forbidden.contains(candidate) && candidate.betterThanFinal(best, callSiteType)) { 1.19 best = candidate; 1.20 }
2.1 --- a/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Mon Nov 23 10:08:15 2015 +0100 2.2 +++ b/src/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Dec 17 20:04:46 2015 +0530 2.3 @@ -894,7 +894,7 @@ 2.4 } 2.5 2.6 @Override 2.7 - synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) { 2.8 + synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, final boolean linkLogicOkay) { 2.9 assert isValidCallSite(callSiteType) : callSiteType; 2.10 2.11 CompiledFunction existingBest = pickFunction(callSiteType, false);
3.1 --- a/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Mon Nov 23 10:08:15 2015 +0100 3.2 +++ b/src/jdk/nashorn/internal/runtime/ScriptFunctionData.java Thu Dec 17 20:04:46 2015 +0530 3.3 @@ -357,9 +357,23 @@ 3.4 * @param runtimeScope the runtime scope. It can be used to evaluate types of scoped variables to guide the 3.5 * optimistic compilation, should the call to this method trigger code compilation. Can be null if current runtime 3.6 * scope is not known, but that might cause compilation of code that will need more deoptimization passes. 3.7 + * @param linkLogicOkay is a CompiledFunction with a LinkLogic acceptable? 3.8 * @return the best function for the specified call site type. 3.9 */ 3.10 - abstract CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden); 3.11 + abstract CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, final boolean linkLogicOkay); 3.12 + 3.13 + /** 3.14 + * Returns the best function for the specified call site type. 3.15 + * @param callSiteType The call site type. Call site types are expected to have the form 3.16 + * {@code (callee, this[, args...])}. 3.17 + * @param runtimeScope the runtime scope. It can be used to evaluate types of scoped variables to guide the 3.18 + * optimistic compilation, should the call to this method trigger code compilation. Can be null if current runtime 3.19 + * scope is not known, but that might cause compilation of code that will need more deoptimization passes. 3.20 + * @return the best function for the specified call site type. 3.21 + */ 3.22 + final CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) { 3.23 + return getBest(callSiteType, runtimeScope, forbidden, true); 3.24 + } 3.25 3.26 boolean isValidCallSite(final MethodType callSiteType) { 3.27 return callSiteType.parameterCount() >= 2 && // Must have at least (callee, this) 3.28 @@ -367,7 +381,7 @@ 3.29 } 3.30 3.31 CompiledFunction getGeneric(final ScriptObject runtimeScope) { 3.32 - return getBest(getGenericType(), runtimeScope, CompiledFunction.NO_FUNCTIONS); 3.33 + return getBest(getGenericType(), runtimeScope, CompiledFunction.NO_FUNCTIONS, false); 3.34 } 3.35 3.36 /**
4.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 4.2 +++ b/test/script/basic/JDK-8145550.js Thu Dec 17 20:04:46 2015 +0530 4.3 @@ -0,0 +1,33 @@ 4.4 +/* 4.5 + * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved. 4.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4.7 + * 4.8 + * This code is free software; you can redistribute it and/or modify it 4.9 + * under the terms of the GNU General Public License version 2 only, as 4.10 + * published by the Free Software Foundation. 4.11 + * 4.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 4.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 4.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 4.15 + * version 2 for more details (a copy is included in the LICENSE file that 4.16 + * accompanied this code). 4.17 + * 4.18 + * You should have received a copy of the GNU General Public License version 4.19 + * 2 along with this work; if not, write to the Free Software Foundation, 4.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 4.21 + * 4.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 4.23 + * or visit www.oracle.com if you need additional information or have any 4.24 + * questions. 4.25 + */ 4.26 + 4.27 +/** 4.28 + * JDK-8141537: Megamorphic invoke should use CompiledFunction variants without any LinkLogic 4.29 + * 4.30 + * @test 4.31 + * @option -Dnashorn.unstable.relink.threshold=1 4.32 + * @fork 4.33 + * @run 4.34 + */ 4.35 + 4.36 +load(__DIR__ + "NASHORN-421.js")