8056025: CompilationPhase.setStates() is hot in class installation phase

Tue, 26 Aug 2014 15:52:55 +0200

author
attila
date
Tue, 26 Aug 2014 15:52:55 +0200
changeset 980
44b69fb3b031
parent 979
2bcc21c5d5da
child 981
d93eabe28080

8056025: CompilationPhase.setStates() is hot in class installation phase
Reviewed-by: jlaskey, sundar

src/jdk/nashorn/internal/AssertsEnabled.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/CodeGenerator.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/codegen/CompilationPhase.java file | annotate | diff | comparison | revisions
src/jdk/nashorn/internal/ir/FunctionNode.java file | annotate | diff | comparison | revisions
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/jdk/nashorn/internal/AssertsEnabled.java	Tue Aug 26 15:52:55 2014 +0200
     1.3 @@ -0,0 +1,45 @@
     1.4 +/*
     1.5 + * Copyright (c) 2010, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.  Oracle designates this
    1.11 + * particular file as subject to the "Classpath" exception as provided
    1.12 + * by Oracle in the LICENSE file that accompanied this code.
    1.13 + *
    1.14 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.15 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.16 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.17 + * version 2 for more details (a copy is included in the LICENSE file that
    1.18 + * accompanied this code).
    1.19 + *
    1.20 + * You should have received a copy of the GNU General Public License version
    1.21 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.22 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.23 + *
    1.24 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.25 + * or visit www.oracle.com if you need additional information or have any
    1.26 + * questions.
    1.27 + */
    1.28 +
    1.29 +package jdk.nashorn.internal;
    1.30 +
    1.31 +/**
    1.32 + * Class that exposes the current state of asserts.
    1.33 + *
    1.34 + */
    1.35 +public final class AssertsEnabled {
    1.36 +    private static boolean assertsEnabled = false;
    1.37 +    static {
    1.38 +        assert assertsEnabled = true; // Intentional side effect
    1.39 +    }
    1.40 +
    1.41 +    /**
    1.42 +     * Returns true if asserts are enabled
    1.43 +     * @return true if asserts are enabled
    1.44 +     */
    1.45 +    public static boolean assertsEnabled() {
    1.46 +        return assertsEnabled;
    1.47 +    }
    1.48 +}
     2.1 --- a/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Aug 26 15:04:48 2014 +0200
     2.2 +++ b/src/jdk/nashorn/internal/codegen/CodeGenerator.java	Tue Aug 26 15:52:55 2014 +0200
     2.3 @@ -75,6 +75,7 @@
     2.4  import java.util.Set;
     2.5  import java.util.TreeMap;
     2.6  import java.util.function.Supplier;
     2.7 +import jdk.nashorn.internal.AssertsEnabled;
     2.8  import jdk.nashorn.internal.IntDeque;
     2.9  import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
    2.10  import jdk.nashorn.internal.codegen.CompilerConstants.Call;
    2.11 @@ -237,11 +238,6 @@
    2.12      /** From what size should we use spill instead of fields for JavaScript objects? */
    2.13      private static final int OBJECT_SPILL_THRESHOLD = Options.getIntProperty("nashorn.spill.threshold", 256);
    2.14  
    2.15 -    private static boolean assertsEnabled = false;
    2.16 -    static {
    2.17 -        assert assertsEnabled = true; // Intentional side effect
    2.18 -    }
    2.19 -
    2.20      private final Set<String> emittedMethods = new HashSet<>();
    2.21  
    2.22      // Function Id -> ContinuationInfo. Used by compilation of rest-of function only.
    2.23 @@ -5243,7 +5239,7 @@
    2.24              }
    2.25              lvarIndex = nextLvarIndex;
    2.26          }
    2.27 -        if(assertsEnabled) {
    2.28 +        if (AssertsEnabled.assertsEnabled()) {
    2.29              method.load(arrayIndex);
    2.30              method.invoke(RewriteException.ASSERT_ARRAY_LENGTH);
    2.31          } else {
     3.1 --- a/src/jdk/nashorn/internal/codegen/CompilationPhase.java	Tue Aug 26 15:04:48 2014 +0200
     3.2 +++ b/src/jdk/nashorn/internal/codegen/CompilationPhase.java	Tue Aug 26 15:52:55 2014 +0200
     3.3 @@ -48,6 +48,7 @@
     3.4  import java.util.Map;
     3.5  import java.util.Map.Entry;
     3.6  import java.util.Set;
     3.7 +import jdk.nashorn.internal.AssertsEnabled;
     3.8  import jdk.nashorn.internal.codegen.Compiler.CompilationPhases;
     3.9  import jdk.nashorn.internal.ir.FunctionNode;
    3.10  import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
    3.11 @@ -593,12 +594,10 @@
    3.12          this.pre = pre;
    3.13      }
    3.14  
    3.15 -    boolean isApplicable(final FunctionNode functionNode) {
    3.16 -        //this means that all in pre are present in state. state can be larger
    3.17 -        return functionNode.hasState(pre);
    3.18 -    }
    3.19 -
    3.20      private static FunctionNode setStates(final FunctionNode functionNode, final CompilationState state) {
    3.21 +        if (!AssertsEnabled.assertsEnabled()) {
    3.22 +            return functionNode;
    3.23 +        }
    3.24          return (FunctionNode)functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
    3.25              @Override
    3.26              public Node leaveFunctionNode(final FunctionNode fn) {
    3.27 @@ -618,7 +617,7 @@
    3.28  
    3.29          assert pre != null;
    3.30  
    3.31 -        if (!isApplicable(functionNode)) {
    3.32 +        if (!functionNode.hasState(pre)) {
    3.33              final StringBuilder sb = new StringBuilder("Compilation phase ");
    3.34              sb.append(this).
    3.35                  append(" is not applicable to ").
     4.1 --- a/src/jdk/nashorn/internal/ir/FunctionNode.java	Tue Aug 26 15:04:48 2014 +0200
     4.2 +++ b/src/jdk/nashorn/internal/ir/FunctionNode.java	Tue Aug 26 15:52:55 2014 +0200
     4.3 @@ -39,6 +39,7 @@
     4.4  import java.util.List;
     4.5  import java.util.Set;
     4.6  import java.util.function.Function;
     4.7 +import jdk.nashorn.internal.AssertsEnabled;
     4.8  import jdk.nashorn.internal.codegen.CompileUnit;
     4.9  import jdk.nashorn.internal.codegen.Compiler;
    4.10  import jdk.nashorn.internal.codegen.CompilerConstants;
    4.11 @@ -57,7 +58,6 @@
    4.12   */
    4.13  @Immutable
    4.14  public final class FunctionNode extends LexicalContextExpression implements Flags<FunctionNode> {
    4.15 -
    4.16      /** Type used for all FunctionNodes */
    4.17      public static final Type FUNCTION_TYPE = Type.typeFor(ScriptFunction.class);
    4.18  
    4.19 @@ -517,27 +517,7 @@
    4.20       * @return true of the node is in the given state
    4.21       */
    4.22      public boolean hasState(final EnumSet<CompilationState> state) {
    4.23 -        //this.compilationState >= state, or we fail
    4.24 -        for (final CompilationState cs : state) {
    4.25 -            if (!hasState(cs)) {
    4.26 -                return false;
    4.27 -            }
    4.28 -        }
    4.29 -        return true;
    4.30 -    }
    4.31 -
    4.32 -    /**
    4.33 -     * Check whether the state of this FunctionNode contains a given compilation
    4.34 -     * state.
    4.35 -     *
    4.36 -     * A node can be in many states at once, e.g. both lowered and initialized.
    4.37 -     * To check for an exact state, use {@link #hasState(EnumSet)}
    4.38 -     *
    4.39 -     * @param state state to check for
    4.40 -     * @return true if state is present in the total compilation state of this FunctionNode
    4.41 -     */
    4.42 -    public boolean hasState(final CompilationState state) {
    4.43 -        return compilationState.contains(state);
    4.44 +        return !AssertsEnabled.assertsEnabled() || compilationState.containsAll(state);
    4.45      }
    4.46  
    4.47      /**
    4.48 @@ -550,7 +530,7 @@
    4.49       * @return function node or a new one if state was changed
    4.50       */
    4.51      public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
    4.52 -        if (this.compilationState.contains(state)) {
    4.53 +        if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) {
    4.54              return this;
    4.55          }
    4.56          final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);

mercurial