Minor refactoring: analyze-method added

This commit is contained in:
Denis Zharkov
2014-07-08 17:06:08 +04:00
committed by Alexander Udalov
parent a412a96ff3
commit 498e5ec192
3 changed files with 13 additions and 13 deletions
@@ -26,7 +26,6 @@ import org.jetbrains.org.objectweb.asm.Opcodes;
import org.jetbrains.org.objectweb.asm.Type; import org.jetbrains.org.objectweb.asm.Type;
import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter; import org.jetbrains.org.objectweb.asm.commons.InstructionAdapter;
import org.jetbrains.org.objectweb.asm.tree.*; import org.jetbrains.org.objectweb.asm.tree.*;
import org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer;
import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue; import org.jetbrains.org.objectweb.asm.tree.analysis.BasicValue;
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame; import org.jetbrains.org.objectweb.asm.tree.analysis.Frame;
@@ -40,9 +39,8 @@ public class RedundantBoxingMethodTransformer extends MethodTransformer {
@Override @Override
public void transform(@NotNull String internalClassName, @NotNull MethodNode node) { public void transform(@NotNull String internalClassName, @NotNull MethodNode node) {
RedundantBoxingInterpreter interpreter = new RedundantBoxingInterpreter(node.instructions); RedundantBoxingInterpreter interpreter = new RedundantBoxingInterpreter(node.instructions);
Frame<BasicValue>[] frames = runAnalyzer( Frame<BasicValue>[] frames = analyze(
new Analyzer<BasicValue>(interpreter), internalClassName, node, interpreter
internalClassName, node
); );
interpretPopInstructionsForBoxedValues(interpreter, node, frames); interpretPopInstructionsForBoxedValues(interpreter, node, frames);
@@ -44,11 +44,9 @@ public class RedundantNullCheckMethodTransformer extends MethodTransformer {
private static boolean removeRedundantNullCheckPass(@NotNull String internalClassName, @NotNull MethodNode methodNode) { private static boolean removeRedundantNullCheckPass(@NotNull String internalClassName, @NotNull MethodNode methodNode) {
InsnList insnList = methodNode.instructions; InsnList insnList = methodNode.instructions;
Frame<BasicValue>[] frames = runAnalyzer( Frame<BasicValue>[] frames = analyze(
new Analyzer<BasicValue>( internalClassName, methodNode,
new BoxingInterpreter(insnList) new BoxingInterpreter(insnList)
),
internalClassName, methodNode
); );
List<AbstractInsnNode> insnsToOptimize = new ArrayList<AbstractInsnNode>(); List<AbstractInsnNode> insnsToOptimize = new ArrayList<AbstractInsnNode>();
@@ -18,10 +18,7 @@ package org.jetbrains.jet.codegen.optimization.transformer;
import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.NotNull;
import org.jetbrains.org.objectweb.asm.tree.MethodNode; import org.jetbrains.org.objectweb.asm.tree.MethodNode;
import org.jetbrains.org.objectweb.asm.tree.analysis.Analyzer; import org.jetbrains.org.objectweb.asm.tree.analysis.*;
import org.jetbrains.org.objectweb.asm.tree.analysis.AnalyzerException;
import org.jetbrains.org.objectweb.asm.tree.analysis.Frame;
import org.jetbrains.org.objectweb.asm.tree.analysis.Value;
public abstract class MethodTransformer { public abstract class MethodTransformer {
private final MethodTransformer delegate; private final MethodTransformer delegate;
@@ -42,6 +39,13 @@ public abstract class MethodTransformer {
throw new RuntimeException(e); throw new RuntimeException(e);
} }
} }
protected static <V extends Value> Frame<V>[] analyze(
@NotNull String internalClassName,
@NotNull MethodNode node,
@NotNull Interpreter<V> interpreter
) {
return runAnalyzer(new Analyzer<V>(interpreter), internalClassName, node);
}
public void transform(@NotNull String internalClassName, @NotNull MethodNode methodNode) { public void transform(@NotNull String internalClassName, @NotNull MethodNode methodNode) {
if (delegate != null) { if (delegate != null) {