changeset 1413:0ee4c3b61e45

8135075: Reorder short-circuit tests in ApplySpecialization to run cheapest first Reviewed-by: hannesw, mhaupt, sundar
author attila
date Mon, 07 Sep 2015 11:11:41 +0200
parents bfe6bd5d57bf
children 37a9addb8c8d
files src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java
diffstat 1 files changed, 22 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java	Fri Sep 04 17:11:06 2015 +0530
+++ b/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/ApplySpecialization.java	Mon Sep 07 11:11:41 2015 +0200
@@ -298,7 +298,28 @@
 
     @Override
     public boolean enterFunctionNode(final FunctionNode functionNode) {
-        if (!USE_APPLY2CALL) {
+        // Cheap tests first
+        if (!(
+                // is the transform globally enabled?
+                USE_APPLY2CALL
+
+                // Are we compiling lazily? We can't known the number and types of the actual parameters at
+                // the caller when compiling eagerly, so this only works with on-demand compilation.
+                && compiler.isOnDemandCompilation()
+
+                // Does the function even reference the "arguments" identifier (without redefining it)? If not,
+                // it trivially can't have an expression of form "f.apply(self, arguments)" that this transform
+                // is targeting.
+                && functionNode.needsArguments()
+
+                // Does the function have eval? If so, it can arbitrarily modify arguments so we can't touch it.
+                && !functionNode.hasEval()
+
+                // Finally, does the function declare any parameters explicitly? We don't support that. It could
+                // be done, but has some complications. Therefore only a function with no explicit parameters
+                // is considered.
+                && functionNode.getNumOfParams() == 0))
+        {
             return false;
         }
 
@@ -308,18 +329,6 @@
             return false;
         }
 
-        if (!compiler.isOnDemandCompilation()) {
-            return false;
-        }
-
-        if (functionNode.getNumOfParams() != 0) {
-            return false;
-        }
-
-        if (functionNode.hasEval()) {
-            return false;
-        }
-
         if (!hasApplies(functionNode)) {
             return false;
         }