This is an old revision of the document!
Implement a listener, named ArrayListener, that counts the number of reads and w rites of array cells within the main method of an app. A sample run can be foun d below. It shows what type of output your listener should produce. Here are s ome hints that may be useful for implementing your listener. <ul> <li> Consider the interfaces VMListener and SearchListener, which are part of the pac kages gov.nasa.jpf.vm and gov.nasa.jpf.search, respectively. <li> Consider subclasses of the class Instruction, which is part of the package gov.n asa.jpf.vm. <li> If you cannot count the number of reads and writes of array cells within the mai n method of an app, then count the number of reads and writes of array cells of the entire app. <lI> If you cannot print the total at the end, then print a star (*) every time a rea d or write of an array cell occurs. </ul>
<p>
To compile your listener, use <pre> javac -cp /cs/fac/packages/jpf/jpf-core/build/jpf.jar:. ArrayListener.java </pre> or add /cs/fac/packages/jpf/jpf-core/build/jpf.jar as an external library to Ecl ipse.
<p>
To test your listener, you may want to use the following app. <pre> public class ArraySample {
public static void main(String[] args) { int[] array = new int[2]; array[0] = 1; array[1] = array[0]; array[0]++; array[1] = 2; }
} </pre>
<p>
To run JPF on the above app, use the following configuration file. <pre> target=ArraySample classpath=. listener=ArrayListener native_classpath=/eecs/home/franck/ </pre> where /eecs/home/franck/ is the path to the directory in which ArrayListener.cla ss can be found.
<p>
If the above configuration file is used with the above app, JPF should produce o utput similar to the following. <pre> JavaPathfinder core system v8.0 (rev 29) - (C) 2005-2014 United States Governmen t. All rights reserved.
====================================================== system under test ArraySample.main()
====================================================== search started: 2/5/17 1: 20 PM * Total number of reads and writes of array cells: 6 *
====================================================== results no errors detected
====================================================== statistics elapsed time: 00:00:00 states: new=1,visited=0,backtracked=1,end=1 search: maxDepth=1,constraints=0 choice generators: thread=1 (signal=0,lock=1,sharedRef=0,threadApi=0,reschedule =0), data=0 heap: new=347,released=12,maxLive=0,gcCycles=1 instructions: 3184 max memory: 238MB loaded code: classes=60,methods=1320
====================================================== search finished: 2/5/17 1 :20 PM </pre>
<P>
submit 4315 lab4 ArrayListener.java