jasm.util
Class DeadCodeElimination

java.lang.Object
  extended by jasm.util.DeadCodeElimination

public class DeadCodeElimination
extends java.lang.Object

The purpose of this pass is to eliminate any statically determinable dead-code. This is required to generate correct java bytecode. For example, consider the following Java code:

 void f(...) {
  if(...) {
   return ...;
  else {
   return ...;
  }
 }
 
Then, the front-end will produce the following (pseudo) bytecode:
 void f(...) {
  if(...) goto iftrue0;
  return ...;
  goto ifexit0;
 iftrue0:
   return ...;
 ifexit0:
 }
 
Here, we can see quite clearly that the code after the first return statement, as well as the ifexit label, is dead.

Author:
David J. Pearce

Constructor Summary
DeadCodeElimination()
           
 
Method Summary
 void apply(ClassFile.Method method)
           
 void apply(ClassFile cf)
           
 void apply(Code code)
           
protected  java.util.HashMap<java.lang.String,java.lang.Integer> buildLabelMap(java.util.List<Bytecode> bytecodes)
           
protected  void visit(int index, java.util.HashSet<java.lang.Integer> visited, java.util.HashMap<java.lang.String,java.lang.Integer> labels, java.util.List<Bytecode> bytecodes)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DeadCodeElimination

public DeadCodeElimination()
Method Detail

apply

public void apply(ClassFile cf)

apply

public void apply(ClassFile.Method method)

apply

public void apply(Code code)

visit

protected void visit(int index,
                     java.util.HashSet<java.lang.Integer> visited,
                     java.util.HashMap<java.lang.String,java.lang.Integer> labels,
                     java.util.List<Bytecode> bytecodes)

buildLabelMap

protected java.util.HashMap<java.lang.String,java.lang.Integer> buildLabelMap(java.util.List<Bytecode> bytecodes)


Copyright © 2013 David J. Pearce. All Rights Reserved.