mirror of
https://github.com/openjdk/jdk.git
synced 2026-02-05 07:58:40 +00:00
8079349: Eliminate dead code around Nashorn code generator
Reviewed-by: hannesw, lagergren
This commit is contained in:
parent
dbcd4aef5f
commit
79086bc842
@ -31,6 +31,7 @@ import static jdk.nashorn.internal.codegen.Condition.GT;
|
||||
import static jdk.nashorn.internal.codegen.Condition.LE;
|
||||
import static jdk.nashorn.internal.codegen.Condition.LT;
|
||||
import static jdk.nashorn.internal.codegen.Condition.NE;
|
||||
import static jdk.nashorn.internal.parser.TokenType.NOT;
|
||||
|
||||
import jdk.nashorn.internal.ir.BinaryNode;
|
||||
import jdk.nashorn.internal.ir.Expression;
|
||||
@ -57,21 +58,11 @@ final class BranchOptimizer {
|
||||
}
|
||||
|
||||
private void branchOptimizer(final UnaryNode unaryNode, final Label label, final boolean state) {
|
||||
final Expression rhs = unaryNode.getExpression();
|
||||
|
||||
switch (unaryNode.tokenType()) {
|
||||
case NOT:
|
||||
branchOptimizer(rhs, label, !state);
|
||||
return;
|
||||
default:
|
||||
if (unaryNode.getType().isBoolean()) {
|
||||
branchOptimizer(rhs, label, state);
|
||||
return;
|
||||
}
|
||||
break;
|
||||
if (unaryNode.isTokenType(NOT)) {
|
||||
branchOptimizer(unaryNode.getExpression(), label, !state);
|
||||
} else {
|
||||
loadTestAndJump(unaryNode, label, state);
|
||||
}
|
||||
|
||||
loadTestAndJump(unaryNode, label, state);
|
||||
}
|
||||
|
||||
private void branchOptimizer(final BinaryNode binaryNode, final Label label, final boolean state) {
|
||||
|
||||
@ -101,13 +101,10 @@ import jdk.nashorn.internal.runtime.Source;
|
||||
* bytecodes that have been written. This is enabled by setting the
|
||||
* environment "nashorn.codegen.debug" to true, or --log=codegen:{@literal <level>}
|
||||
* <p>
|
||||
* A ClassEmitter implements an Emitter - i.e. it needs to have
|
||||
* well defined start and end calls for whatever it is generating. Assertions
|
||||
* detect if this is not true
|
||||
*
|
||||
* @see Compiler
|
||||
*/
|
||||
public class ClassEmitter implements Emitter {
|
||||
public class ClassEmitter {
|
||||
/** Default flags for class generation - public class */
|
||||
private static final EnumSet<Flag> DEFAULT_METHOD_FLAGS = EnumSet.of(Flag.PUBLIC);
|
||||
|
||||
@ -397,18 +394,14 @@ public class ClassEmitter implements Emitter {
|
||||
|
||||
/**
|
||||
* Call at beginning of class emission
|
||||
* @see Emitter
|
||||
*/
|
||||
@Override
|
||||
public void begin() {
|
||||
classStarted = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Call at end of class emission
|
||||
* @see Emitter
|
||||
*/
|
||||
@Override
|
||||
public void end() {
|
||||
assert classStarted : "class not started for " + unitClassName;
|
||||
|
||||
|
||||
@ -174,8 +174,7 @@ import jdk.nashorn.internal.runtime.options.Options;
|
||||
* This quickly became apparent when the code generator was generalized to work
|
||||
* with all types, and not just numbers or objects.
|
||||
* <p>
|
||||
* The CodeGenerator visits nodes only once, tags them as resolved and emits
|
||||
* bytecode for them.
|
||||
* The CodeGenerator visits nodes only once and emits bytecode for them.
|
||||
*/
|
||||
@Logger(name="codegen")
|
||||
final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContext> implements Loggable {
|
||||
@ -1714,11 +1713,7 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
|
||||
@Override
|
||||
public boolean enterEmptyNode(final EmptyNode emptyNode) {
|
||||
if(!method.isReachable()) {
|
||||
return false;
|
||||
}
|
||||
enterStatement(emptyNode);
|
||||
|
||||
// Don't even record the line number, it's irrelevant as there's no code.
|
||||
return false;
|
||||
}
|
||||
|
||||
@ -2647,8 +2642,6 @@ final class CodeGenerator extends NodeOperatorVisitor<CodeGeneratorLexicalContex
|
||||
}
|
||||
enterStatement(returnNode);
|
||||
|
||||
method.registerReturn();
|
||||
|
||||
final Type returnType = lc.getCurrentFunction().getReturnType();
|
||||
|
||||
final Expression expression = returnNode.getExpression();
|
||||
|
||||
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* Copyright (c) 2010, 2013, 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.codegen;
|
||||
|
||||
/**
|
||||
* Interface for anything that interacts with a low level bytecode
|
||||
* generation module, for example ASM.
|
||||
* <p>
|
||||
* This is pretty generic, i.e. it can be a ClassEmitter, MethodEmitter
|
||||
* or potentially even more fine grained stuff.
|
||||
*
|
||||
*/
|
||||
public interface Emitter {
|
||||
|
||||
/**
|
||||
* Register the start of emission for this CodeEmitter
|
||||
*/
|
||||
public void begin();
|
||||
|
||||
/**
|
||||
* Register the end of emission for this CodeEmitter.
|
||||
* This is typically required before generated code can
|
||||
* be requested from it
|
||||
*/
|
||||
public void end();
|
||||
}
|
||||
@ -123,7 +123,7 @@ import jdk.nashorn.internal.runtime.options.Options;
|
||||
* all generated bytecode and labels to stderr, for easier debugging,
|
||||
* including bytecode stack contents
|
||||
*/
|
||||
public class MethodEmitter implements Emitter {
|
||||
public class MethodEmitter {
|
||||
/** The ASM MethodVisitor we are plugged into */
|
||||
private final MethodVisitor method;
|
||||
|
||||
@ -136,9 +136,6 @@ public class MethodEmitter implements Emitter {
|
||||
/** Current type stack for current evaluation */
|
||||
private Label.Stack stack;
|
||||
|
||||
/** Check whether this emitter ever has a function return point */
|
||||
private boolean hasReturn;
|
||||
|
||||
private boolean preventUndefinedLoad;
|
||||
|
||||
/**
|
||||
@ -207,9 +204,7 @@ public class MethodEmitter implements Emitter {
|
||||
|
||||
/**
|
||||
* Begin a method
|
||||
* @see Emitter
|
||||
*/
|
||||
@Override
|
||||
public void begin() {
|
||||
classEmitter.beginMethod(this);
|
||||
newStack();
|
||||
@ -218,9 +213,7 @@ public class MethodEmitter implements Emitter {
|
||||
|
||||
/**
|
||||
* End a method
|
||||
* @see Emitter
|
||||
*/
|
||||
@Override
|
||||
public void end() {
|
||||
method.visitMaxs(0, 0);
|
||||
method.visitEnd();
|
||||
@ -1615,15 +1608,6 @@ public class MethodEmitter implements Emitter {
|
||||
}
|
||||
}
|
||||
|
||||
MethodEmitter registerReturn() {
|
||||
setHasReturn();
|
||||
return this;
|
||||
}
|
||||
|
||||
void setHasReturn() {
|
||||
this.hasReturn = true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Perform a non void return, popping the type from the stack
|
||||
*
|
||||
@ -2724,10 +2708,6 @@ public class MethodEmitter implements Emitter {
|
||||
this.functionNode = functionNode;
|
||||
}
|
||||
|
||||
boolean hasReturn() {
|
||||
return hasReturn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke to enforce assertions preventing load from a local variable slot that's known to not have been written to.
|
||||
* Used by CodeGenerator, as it strictly enforces tracking of stores. Simpler uses of MethodEmitter, e.g. those
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user