8135075: Reorder short-circuit tests in ApplySpecialization to run cheapest first

Mon, 07 Sep 2015 11:11:41 +0200

author
attila
date
Mon, 07 Sep 2015 11:11:41 +0200
changeset 1540
5678c4914917
parent 1539
684d430470f6
child 1541
e4a553f79ebd

8135075: Reorder short-circuit tests in ApplySpecialization to run cheapest first
Reviewed-by: hannesw, mhaupt, sundar

src/jdk/nashorn/internal/codegen/ApplySpecialization.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/jdk/nashorn/internal/codegen/ApplySpecialization.java	Wed Sep 02 16:35:14 2015 +0200
     1.2 +++ b/src/jdk/nashorn/internal/codegen/ApplySpecialization.java	Mon Sep 07 11:11:41 2015 +0200
     1.3 @@ -297,7 +297,28 @@
     1.4  
     1.5      @Override
     1.6      public boolean enterFunctionNode(final FunctionNode functionNode) {
     1.7 -        if (!USE_APPLY2CALL) {
     1.8 +        // Cheap tests first
     1.9 +        if (!(
    1.10 +                // is the transform globally enabled?
    1.11 +                USE_APPLY2CALL
    1.12 +
    1.13 +                // Are we compiling lazily? We can't known the number and types of the actual parameters at
    1.14 +                // the caller when compiling eagerly, so this only works with on-demand compilation.
    1.15 +                && compiler.isOnDemandCompilation()
    1.16 +
    1.17 +                // Does the function even reference the "arguments" identifier (without redefining it)? If not,
    1.18 +                // it trivially can't have an expression of form "f.apply(self, arguments)" that this transform
    1.19 +                // is targeting.
    1.20 +                && functionNode.needsArguments()
    1.21 +
    1.22 +                // Does the function have eval? If so, it can arbitrarily modify arguments so we can't touch it.
    1.23 +                && !functionNode.hasEval()
    1.24 +
    1.25 +                // Finally, does the function declare any parameters explicitly? We don't support that. It could
    1.26 +                // be done, but has some complications. Therefore only a function with no explicit parameters
    1.27 +                // is considered.
    1.28 +                && functionNode.getNumOfParams() == 0))
    1.29 +        {
    1.30              return false;
    1.31          }
    1.32  
    1.33 @@ -307,18 +328,6 @@
    1.34              return false;
    1.35          }
    1.36  
    1.37 -        if (!compiler.isOnDemandCompilation()) {
    1.38 -            return false;
    1.39 -        }
    1.40 -
    1.41 -        if (functionNode.getNumOfParams() != 0) {
    1.42 -            return false;
    1.43 -        }
    1.44 -
    1.45 -        if (functionNode.hasEval()) {
    1.46 -            return false;
    1.47 -        }
    1.48 -
    1.49          if (!hasApplies(functionNode)) {
    1.50              return false;
    1.51          }

mercurial