Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 2003 John Jorgensen
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Library General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version.
   * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * Library General Public License for more details.
  * You should have received a copy of the GNU Library General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
 package soot.toolkits.exceptions;
 import java.util.Map;
 import soot.Body;
 import soot.G;
 import soot.Trap;
 import soot.Unit;
A soot.BodyTransformer that shrinks the protected area covered by each soot.Trap in the soot.Body so that it begins at the first of the soot.Body's soot.Units which might throw an exception caught by the soot.Trap and ends just after the last soot.Unit which might throw an exception caught by the soot.Trap. In the case where none of the soot.Units protected by a soot.Trap can throw the exception it catches, the soot.Trap's protected area is left completely empty, which will likely cause the UnreachableCodeEliminator to remove the soot.Trap completely. The TrapTightener is used to reduce the risk of unverifiable code which can result from the use of soot.toolkits.graph.ExceptionalUnitGraphs from which unrealizable exceptional control flow edges have been removed.
 public final class TrapTightener extends BodyTransformer {
     public TrapTightenerSingletons.Global g ) {}
     public static TrapTightener v() { return soot.G.v().soot_toolkits_exceptions_TrapTightener(); }
     protected void internalTransform(Body bodyString phaseNameMap options) {
             G.v()..println("[" + body.getMethod().getName() + "] Tightening trap boundaries...");
 	Chain trapChain = body.getTraps();
 	Chain unitChain = body.getUnits();
 	if (trapChain.size() > 0) {
 	    ExceptionalUnitGraph graph = new ExceptionalUnitGraph(body);
 	    for (Iterator trapIt = trapChain.iterator(); trapIt.hasNext(); ) {
 		Trap trap = (;
 		Unit firstTrappedUnit = trap.getBeginUnit();
 		Unit firstTrappedThrower = null;
 		Unit firstUntrappedUnit = trap.getEndUnit();
 		Unit lastTrappedUnit = 
 		Unit lastTrappedThrower = null;
 		for (Unit u = firstTrappedUnit
 		     u != null && u != firstUntrappedUnit
 		     u = (UnitunitChain.getSuccOf(u)) {
 			if (mightThrowTo(graphutrap)) {
 			    firstTrappedThrower = u;
 		if (firstTrappedThrower != null) {
 		    for (Unit u = lastTrappedUnit;
 			 u != nullu = (UnitunitChain.getPredOf(u)) {
 			if (mightThrowTo(graphutrap)) {
 			    lastTrappedThrower = u;
 		if (firstTrappedThrower != null &&
 		    firstTrappedUnit != firstTrappedThrower) {
 		if (lastTrappedThrower == null) {
 		    lastTrappedThrower = firstTrappedUnit;
 		if (lastTrappedUnit != lastTrappedThrower) {

A utility routine which determines if a particular soot.Unit might throw an exception to a particular soot.Trap, according to the information supplied by a particular control flow graph.

g The control flow graph providing information about exceptions.
u The unit being inquired about.
t The trap being inquired about.
true if u might throw an exception caught by t, according to g
    protected boolean mightThrowTo(ExceptionalUnitGraph gUnit uTrap t) {
	for (Iterator destIt = dests.iterator(); destIt.hasNext(); ) {
	    if (dest.getTrap() == t) {
		return true;
	return false;
New to GrepCode? Check out our FAQ X