1 salcianu 1.1.2.1 // CachingSCCLBBFactory.java, created Thu Mar 23 19:51:21 2000 by salcianu 2 cananian 1.1.2.4 // Copyright (C) 2000 Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 3 salcianu 1.1.2.1 // Licensed under the terms of the GNU GPL; see COPYING for details. 4 salcianu 1.1.2.1 package harpoon.Util.LightBasicBlocks; 5 salcianu 1.1.2.1 6 salcianu 1.1.2.1 import java.util.Map; 7 salcianu 1.1.2.1 import java.util.HashMap; 8 salcianu 1.1.2.1 import harpoon.ClassFile.HMethod; 9 salcianu 1.3 import harpoon.Util.Graphs.TopSortedCompDiGraph; 10 salcianu 1.1.2.1 11 salcianu 1.1.2.1 12 salcianu 1.1.2.1 /** 13 salcianu 1.1.2.1 * <code>CachingSCCLBBFactory</code> adds some caching to 14 salcianu 1.1.2.1 <code>SCCLBBFactory</code>. 15 salcianu 1.1.2.1 * 16 cananian 1.1.2.4 * @author Alexandru SALCIANU <salcianu@retezat.lcs.mit.edu> 17 salcianu 1.4 * @version $Id: CachingSCCLBBFactory.java,v 1.4 2004/03/05 15:38:16 salcianu Exp $ 18 salcianu 1.1.2.1 */ 19 salcianu 1.1.2.3 public class CachingSCCLBBFactory extends SCCLBBFactory 20 salcianu 1.1.2.3 implements java.io.Serializable { 21 salcianu 1.1.2.1 22 salcianu 1.1.2.1 /** Creates a <code>CachingSCCLBBFactory</code>. */ 23 salcianu 1.1.2.1 public CachingSCCLBBFactory(LBBConverter lbbconv){ 24 salcianu 1.1.2.1 super(lbbconv); 25 salcianu 1.1.2.1 } 26 salcianu 1.1.2.1 27 salcianu 1.4 private Map<HMethod,TopSortedCompDiGraph<LightBasicBlock>> cache = 28 salcianu 1.4 new HashMap(); 29 salcianu 1.3 30 salcianu 1.1.2.1 /** Computes the topologically sorted graph of all the light basic blocks 31 salcianu 1.1.2.1 of the <code>hm</code> method. All the results are cached so that the 32 salcianu 1.1.2.1 computation occurs only once for each method (of course, unless 33 salcianu 1.1.2.1 <code>clear</code> is called). */ 34 salcianu 1.4 public TopSortedCompDiGraph<LightBasicBlock> computeSCCLBB(HMethod hm) { 35 salcianu 1.1.2.1 if(cache.containsKey(hm)) 36 salcianu 1.4 return cache.get(hm); 37 salcianu 1.4 TopSortedCompDiGraph<LightBasicBlock> sccg = super.computeSCCLBB(hm); 38 salcianu 1.1.2.1 cache.put(hm,sccg); 39 salcianu 1.1.2.1 return sccg; 40 salcianu 1.1.2.1 } 41 salcianu 1.1.2.1 42 salcianu 1.1.2.1 /** Clears the cache of previously computed results. */ 43 salcianu 1.1.2.1 public void clear(){ 44 salcianu 1.1.2.1 cache.clear(); 45 salcianu 1.1.2.1 } 46 salcianu 1.1.2.1 47 cananian 1.2 }