8145550: Megamorphic invoke should use CompiledFunction variants without any LinkLogic
Reviewed-by: jlaskey, hannesw, attila
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java Wed Dec 16 16:42:03 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/objects/NativeFunction.java Thu Dec 17 08:31:24 2015 +0530
@@ -98,6 +98,10 @@
public static Object apply(final Object self, final Object thiz, final Object array) {
checkCallable(self);
+ System.out.println("self " + self);
+ System.out.println("thiz " + thiz);
+ System.out.println("array " + array);
+
final Object[] args = toApplyArgs(array);
if (self instanceof ScriptFunction) {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Wed Dec 16 16:42:03 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/FinalScriptFunctionData.java Thu Dec 17 08:31:24 2015 +0530
@@ -89,11 +89,16 @@
}
@Override
- CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) {
+ CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, boolean linkLogicOkay) {
assert isValidCallSite(callSiteType) : callSiteType;
CompiledFunction best = null;
for (final CompiledFunction candidate: code) {
+ if (!linkLogicOkay && candidate.hasLinkLogic()) {
+ // Skip! Version with no link logic is desired, but this one has link logic!
+ continue;
+ }
+
if (!forbidden.contains(candidate) && candidate.betterThanFinal(best, callSiteType)) {
best = candidate;
}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Wed Dec 16 16:42:03 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/RecompilableScriptFunctionData.java Thu Dec 17 08:31:24 2015 +0530
@@ -886,7 +886,7 @@
}
@Override
- synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) {
+ synchronized CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, final boolean linkLogicOkay) {
assert isValidCallSite(callSiteType) : callSiteType;
CompiledFunction existingBest = pickFunction(callSiteType, false);
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunctionData.java Wed Dec 16 16:42:03 2015 +0530
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/runtime/ScriptFunctionData.java Thu Dec 17 08:31:24 2015 +0530
@@ -373,9 +373,23 @@
* @param runtimeScope the runtime scope. It can be used to evaluate types of scoped variables to guide the
* optimistic compilation, should the call to this method trigger code compilation. Can be null if current runtime
* scope is not known, but that might cause compilation of code that will need more deoptimization passes.
+ * @param linkLogicOkay is a CompiledFunction with a LinkLogic acceptable?
* @return the best function for the specified call site type.
*/
- abstract CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden);
+ abstract CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden, final boolean linkLogicOkay);
+
+ /**
+ * Returns the best function for the specified call site type.
+ * @param callSiteType The call site type. Call site types are expected to have the form
+ * {@code (callee, this[, args...])}.
+ * @param runtimeScope the runtime scope. It can be used to evaluate types of scoped variables to guide the
+ * optimistic compilation, should the call to this method trigger code compilation. Can be null if current runtime
+ * scope is not known, but that might cause compilation of code that will need more deoptimization passes.
+ * @return the best function for the specified call site type.
+ */
+ final CompiledFunction getBest(final MethodType callSiteType, final ScriptObject runtimeScope, final Collection<CompiledFunction> forbidden) {
+ return getBest(callSiteType, runtimeScope, forbidden, true);
+ }
boolean isValidCallSite(final MethodType callSiteType) {
return callSiteType.parameterCount() >= 2 && // Must have at least (callee, this)
@@ -383,7 +397,7 @@
}
CompiledFunction getGeneric(final ScriptObject runtimeScope) {
- return getBest(getGenericType(), runtimeScope, CompiledFunction.NO_FUNCTIONS);
+ return getBest(getGenericType(), runtimeScope, CompiledFunction.NO_FUNCTIONS, false);
}
/**
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/test/script/basic/JDK-8145550.js Thu Dec 17 08:31:24 2015 +0530
@@ -0,0 +1,32 @@
+/*
+ * Copyright (c) 2015, Oracle and/or its affiliates. All rights reserved.
+ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
+ *
+ * This code is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License version 2 only, as
+ * published by the Free Software Foundation.
+ *
+ * This code is distributed in the hope that it will be useful, but WITHOUT
+ * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+ * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * version 2 for more details (a copy is included in the LICENSE file that
+ * accompanied this code).
+ *
+ * You should have received a copy of the GNU General Public License version
+ * 2 along with this work; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
+ *
+ * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
+ * or visit www.oracle.com if you need additional information or have any
+ * questions.
+ */
+
+/**
+ * JDK-8141537: Megamorphic invoke should use CompiledFunction variants without any LinkLogic
+ *
+ * @test
+ * @option --unstable-relink-threshold=1
+ * @run
+ */
+
+load(__DIR__ + "NASHORN-421.js")