8056025: CompilationPhase.setStates() is hot in class installation phase
Reviewed-by: jlaskey, sundar
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/AssertsEnabled.java Tue Aug 26 15:52:55 2014 +0200
@@ -0,0 +1,45 @@
+/*
+ * Copyright (c) 2010, 2014, 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. Oracle designates this
+ * particular file as subject to the "Classpath" exception as provided
+ * by Oracle in the LICENSE file that accompanied this code.
+ *
+ * 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.
+ */
+
+package jdk.nashorn.internal;
+
+/**
+ * Class that exposes the current state of asserts.
+ *
+ */
+public final class AssertsEnabled {
+ private static boolean assertsEnabled = false;
+ static {
+ assert assertsEnabled = true; // Intentional side effect
+ }
+
+ /**
+ * Returns true if asserts are enabled
+ * @return true if asserts are enabled
+ */
+ public static boolean assertsEnabled() {
+ return assertsEnabled;
+ }
+}
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Aug 26 15:04:48 2014 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CodeGenerator.java Tue Aug 26 15:52:55 2014 +0200
@@ -75,6 +75,7 @@
import java.util.Set;
import java.util.TreeMap;
import java.util.function.Supplier;
+import jdk.nashorn.internal.AssertsEnabled;
import jdk.nashorn.internal.IntDeque;
import jdk.nashorn.internal.codegen.ClassEmitter.Flag;
import jdk.nashorn.internal.codegen.CompilerConstants.Call;
@@ -237,11 +238,6 @@
/** From what size should we use spill instead of fields for JavaScript objects? */
private static final int OBJECT_SPILL_THRESHOLD = Options.getIntProperty("nashorn.spill.threshold", 256);
- private static boolean assertsEnabled = false;
- static {
- assert assertsEnabled = true; // Intentional side effect
- }
-
private final Set<String> emittedMethods = new HashSet<>();
// Function Id -> ContinuationInfo. Used by compilation of rest-of function only.
@@ -5243,7 +5239,7 @@
}
lvarIndex = nextLvarIndex;
}
- if(assertsEnabled) {
+ if (AssertsEnabled.assertsEnabled()) {
method.load(arrayIndex);
method.invoke(RewriteException.ASSERT_ARRAY_LENGTH);
} else {
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilationPhase.java Tue Aug 26 15:04:48 2014 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/codegen/CompilationPhase.java Tue Aug 26 15:52:55 2014 +0200
@@ -48,6 +48,7 @@
import java.util.Map;
import java.util.Map.Entry;
import java.util.Set;
+import jdk.nashorn.internal.AssertsEnabled;
import jdk.nashorn.internal.codegen.Compiler.CompilationPhases;
import jdk.nashorn.internal.ir.FunctionNode;
import jdk.nashorn.internal.ir.FunctionNode.CompilationState;
@@ -593,12 +594,10 @@
this.pre = pre;
}
- boolean isApplicable(final FunctionNode functionNode) {
- //this means that all in pre are present in state. state can be larger
- return functionNode.hasState(pre);
- }
-
private static FunctionNode setStates(final FunctionNode functionNode, final CompilationState state) {
+ if (!AssertsEnabled.assertsEnabled()) {
+ return functionNode;
+ }
return (FunctionNode)functionNode.accept(new NodeVisitor<LexicalContext>(new LexicalContext()) {
@Override
public Node leaveFunctionNode(final FunctionNode fn) {
@@ -618,7 +617,7 @@
assert pre != null;
- if (!isApplicable(functionNode)) {
+ if (!functionNode.hasState(pre)) {
final StringBuilder sb = new StringBuilder("Compilation phase ");
sb.append(this).
append(" is not applicable to ").
--- a/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java Tue Aug 26 15:04:48 2014 +0200
+++ b/nashorn/src/jdk.scripting.nashorn/share/classes/jdk/nashorn/internal/ir/FunctionNode.java Tue Aug 26 15:52:55 2014 +0200
@@ -39,6 +39,7 @@
import java.util.List;
import java.util.Set;
import java.util.function.Function;
+import jdk.nashorn.internal.AssertsEnabled;
import jdk.nashorn.internal.codegen.CompileUnit;
import jdk.nashorn.internal.codegen.Compiler;
import jdk.nashorn.internal.codegen.CompilerConstants;
@@ -57,7 +58,6 @@
*/
@Immutable
public final class FunctionNode extends LexicalContextExpression implements Flags<FunctionNode> {
-
/** Type used for all FunctionNodes */
public static final Type FUNCTION_TYPE = Type.typeFor(ScriptFunction.class);
@@ -517,27 +517,7 @@
* @return true of the node is in the given state
*/
public boolean hasState(final EnumSet<CompilationState> state) {
- //this.compilationState >= state, or we fail
- for (final CompilationState cs : state) {
- if (!hasState(cs)) {
- return false;
- }
- }
- return true;
- }
-
- /**
- * Check whether the state of this FunctionNode contains a given compilation
- * state.
- *
- * A node can be in many states at once, e.g. both lowered and initialized.
- * To check for an exact state, use {@link #hasState(EnumSet)}
- *
- * @param state state to check for
- * @return true if state is present in the total compilation state of this FunctionNode
- */
- public boolean hasState(final CompilationState state) {
- return compilationState.contains(state);
+ return !AssertsEnabled.assertsEnabled() || compilationState.containsAll(state);
}
/**
@@ -550,7 +530,7 @@
* @return function node or a new one if state was changed
*/
public FunctionNode setState(final LexicalContext lc, final CompilationState state) {
- if (this.compilationState.contains(state)) {
+ if (!AssertsEnabled.assertsEnabled() || this.compilationState.contains(state)) {
return this;
}
final EnumSet<CompilationState> newState = EnumSet.copyOf(this.compilationState);