From: pcm <pcm...@us...> - 2005-08-25 17:06:09
|
Update of /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/tools In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv2988/src/gov/nasa/jpf/tools Modified Files: HeapTracker.java Log Message: updated HeapTracker to use properties instead of command line args for its parameters, and derived it from PropertyListenerAdapter Index: HeapTracker.java =================================================================== RCS file: /cvsroot/javapathfinder/javapathfinder/src/gov/nasa/jpf/tools/HeapTracker.java,v retrieving revision 1.1.1.1 retrieving revision 1.2 diff -u -d -r1.1.1.1 -r1.2 --- HeapTracker.java 26 Apr 2005 19:44:21 -0000 1.1.1.1 +++ HeapTracker.java 25 Aug 2005 17:06:00 -0000 1.2 @@ -19,9 +19,7 @@ package gov.nasa.jpf.tools; -import gov.nasa.jpf.GenericProperty; -import gov.nasa.jpf.VMListener; -import gov.nasa.jpf.SearchListener; +import gov.nasa.jpf.PropertyListenerAdapter; import gov.nasa.jpf.VM; import gov.nasa.jpf.jvm.ElementInfo; @@ -41,14 +39,10 @@ import java.util.regex.Pattern; /** - * HeapTracker - listener class to check heap utilization along all - * execution paths (e.g. to verify heap bounds). HeapTracker is a drop-in - * replacement for JPF (which is called by it). - *. - * This listener also shows how to terminate JPF in case of a property violation - * by registering itself as a JPF Property instance + * HeapTracker - property-listener class to check heap utilization along all + * execution paths (e.g. to verify heap bounds) */ -public class HeapTracker extends GenericProperty implements VMListener, SearchListener { +public class HeapTracker extends PropertyListenerAdapter { class PathStat implements Cloneable { int nNew = 0; @@ -63,8 +57,7 @@ } } } - - + PathStat stat = new PathStat(); Stack pathStats = new Stack(); @@ -108,8 +101,8 @@ int initAlive = 0; // used as a property check - int maxHeapSizeLimit = -1; - int maxLiveLimit = -1; + int maxHeapSizeLimit; + int maxLiveLimit; boolean throwOutOfMemory = false; Pattern classPattern = null; @@ -132,15 +125,26 @@ } } + public HeapTracker (Config config) { + maxHeapSizeLimit = config.getInt("heap.size_limit", -1); + maxLiveLimit = config.getInt("heap.live_limit", -1); + throwOutOfMemory = config.getBoolean("heap.throw_exception"); + + String regEx = config.getString("heap.classes"); + if (regEx != null) { + classPattern = Pattern.compile(regEx); + } + } + /******************************************* abstract Property *****/ /** - * return 'true' if property is violated + * return 'false' if property is violated */ public boolean check (VM vm, Object arg) { if (throwOutOfMemory) { // in this case we don't want to stop the program, but see if it - // behaves gracefully + // behaves gracefully - don't report a property violation return true; } else { if ((maxHeapSizeLimit >= 0) && (stat.heapSize > maxHeapSizeLimit)) { @@ -160,6 +164,8 @@ /******************************************* SearchListener interface *****/ public void searchStarted(Search search) { + super.searchStarted(search); + updateMaxPathValues(); pathStats.push(stat); @@ -186,10 +192,6 @@ } } - public void stateProcessed (Search search) { - // nothing to do - } - public void stateBacktracked(Search search) { nBacktrack++; @@ -233,35 +235,8 @@ System.out.println(" / " + (maxPathReleased - initReleased)); } - public void searchConstraintHit(Search search) { - // TODO - } - - public void stateRestored(Search search) { - // TODO - } - - public void propertyViolated(Search search) { - // TODO - } - /******************************************* VMListener interface *********/ - public void exceptionThrown(VM vm) { - // not interested - } - public void threadStarted(VM vm) { - } - public void threadTerminated(VM vm) { - } - - public void classLoaded(VM vm) { - // not interested - } - public void instructionExecuted(VM vm) { - } - - /***** the processed notifications ****************/ public void gcBegin(VM vm) { JVM jvm = (JVM)vm; /** @@ -407,42 +382,13 @@ } - void filterArgs (String[] args) { - for (int i=0; i<args.length; i++) { - if (args[i].equals("-heapSizeLimit")) { - args[i++] = null; - if (i < args.length) { - maxHeapSizeLimit = Integer.parseInt(args[i]); - args[i] = null; - } - } else if (args[i].equals("-liveLimit")) { - args[i++] = null; - if (i < args.length) { - maxLiveLimit = Integer.parseInt(args[i]); - args[i] = null; - } - } else if (args[i].equals("-classPattern")) { - args[i++] = null; - if (i < args.length) { - String regEx = args[i]; - args[i] = null; - - classPattern = Pattern.compile(regEx); - } - }else if (args[i].equals("-throwOutOfMemory")) { - args[i] = null; - throwOutOfMemory = true; - } - } - } - static void printUsage () { System.out.println("HeapTracker - a JPF listener tool to report and check heap utilization"); System.out.println("usage: java gov.nasa.jpf.tools.HeapTracker <jpf-options> <heapTracker-options> <class>"); - System.out.println(" -heapSizeLimit <num> : report property violation if heap exceeds <num> bytes"); - System.out.println(" -liveLimit <num> : report property violation if more than <num> live objects"); - System.out.println(" -classPattern <regEx> : only report instances of classes matching <regEx>"); - System.out.println(" -throwOutOfMemory: throw a OutOfMemoryError instead of reporting property violation"); + System.out.println(" +heap.size_limit=<num> : report property violation if heap exceeds <num> bytes"); + System.out.println(" +heap.live_limit=<num> : report property violation if more than <num> live objects"); + System.out.println(" +heap.classes=<regEx> : only report instances of classes matching <regEx>"); + System.out.println(" +heap.throw_exception=<bool>: throw a OutOfMemoryError instead of reporting property violation"); } @@ -451,13 +397,11 @@ printUsage(); return; } - - HeapTracker listener = new HeapTracker(); - listener.filterArgs(args); - Config conf = JPF.createConfig(args); // set own options here.. + HeapTracker listener = new HeapTracker(conf); + JPF jpf = new JPF(conf); jpf.addSearchListener(listener); jpf.addVMListener(listener); |