/** * Remove the dead code - or unreachable code - from a method. * * @param method the method to be updated */ private void removeDeadCode(MethodNode method) { try { // Analyze the method using the BasicInterpreter. // As a result, the computed frames are null for instructions // that cannot be reached. Analyzer analyzer = new Analyzer(new BasicInterpreter()); analyzer.analyze(specializedClassName, method); Frame[] frames = analyzer.getFrames(); AbstractInsnNode[] insns = method.instructions.toArray(); for (int i = 0; i < frames.length; i++) { AbstractInsnNode insn = insns[i]; if (frames[i] == null && insn.getType() != AbstractInsnNode.LABEL) { // This instruction was not reached by the analyzer method.instructions.remove(insn); insns[i] = null; } } } catch (AnalyzerException e) { // Ignore error } }
Analyzer analyzer = new Analyzer(new BasicInterpreter()) { @Override protected void newControlFlowEdge(int insn, int successor) {
Analyzer analyzer = new Analyzer(new BasicInterpreter()) { @Override protected void newControlFlowEdge(int insn, int successor) {
BasicInterpreter interpreter = new BasicInterpreter() { @Override public BasicValue newValue(Type type) {
= new BasicInterpreter(); final Analyzer<BasicValue> analyzer = new Analyzer<>(basicInterpreter);