jpf-native:start
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
jpf-native:start [2009/05/14 20:45] – franck | jpf-native:start [2009/05/14 21:03] (current) – franck | ||
---|---|---|---|
Line 109: | Line 109: | ||
===== Model Class ===== | ===== Model Class ===== | ||
+ | We can model the toString method of the Date class as follows. | ||
+ | <code java> | ||
+ | package java.util; | ||
+ | |||
+ | /** | ||
+ | * A model class for the toString method of the Date class. | ||
+ | */ | ||
+ | public class Date | ||
+ | { | ||
+ | public String toString() | ||
+ | { | ||
+ | return " | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | To ensure that JPF model checks the above class, rather than the | ||
+ | Date class of the Java standard library, whenever the toString method | ||
+ | is invoked, we add the following to our jpf.properties file. | ||
+ | < | ||
+ | vm.bootclasspath+= , | ||
+ | </ | ||
+ | Note that modeldirectory is the directory in which the model classes can be found. | ||
+ | |||
+ | If we run JPF, we get something like the following. | ||
+ | < | ||
+ | JavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center | ||
+ | | ||
+ | | ||
+ | ====================================================== system under test | ||
+ | application: | ||
+ | | ||
+ | ====================================================== search started: 5/14/09 4:52 PM | ||
+ | string representation of a Date object in the model class | ||
+ | | ||
+ | ====================================================== results | ||
+ | no errors detected | ||
+ | | ||
+ | ====================================================== statistics | ||
+ | elapsed time: | ||
+ | states: | ||
+ | search: | ||
+ | choice generators: | ||
+ | heap: gc=1, new=262, free=12 | ||
+ | instructions: | ||
+ | max memory: | ||
+ | loaded code: classes=66, methods=839 | ||
+ | | ||
+ | ====================================================== search finished: 5/14/09 4:52 PM | ||
+ | </ | ||
+ | |||
+ | ===== Model Class and Native Peer Class ===== | ||
+ | |||
+ | We can also " | ||
+ | <code java> | ||
+ | package java.util; | ||
+ | |||
+ | /** | ||
+ | * Model class of the constructor and the toString method of the Date class. | ||
+ | */ | ||
+ | public class Date | ||
+ | { | ||
+ | private long fastTime; | ||
+ | |||
+ | public Date() | ||
+ | { | ||
+ | this.fastTime = System.currentTimeMillis(); | ||
+ | } | ||
+ | |||
+ | native public String toString(); | ||
+ | } | ||
+ | </ | ||
+ | Note that we also model the constructor. | ||
+ | |||
+ | Whenever JPF encounters a native method, it looks for a corresponding | ||
+ | native peer class. | ||
+ | <code java> | ||
+ | package gov.nasa.jpf.jvm; | ||
+ | |||
+ | /** | ||
+ | * Native peer for the toString method of the Date class. | ||
+ | */ | ||
+ | public class JPF_java_util_Date | ||
+ | { | ||
+ | public static int toString(MJIEnv env, int objref) | ||
+ | { | ||
+ | return env.newString(env.getDateObject(objref).toString()); | ||
+ | } | ||
+ | } | ||
+ | </ | ||
+ | |||
+ | We have to ensure that the native peer class is part of the classpath | ||
+ | used by JPF and set the vm.bootclasspath appropriately for the model class. | ||
+ | |||
+ | If we run JPF, we get something like the following. | ||
+ | < | ||
+ | JavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center | ||
+ | |||
+ | |||
+ | ====================================================== system under test | ||
+ | application: | ||
+ | |||
+ | ====================================================== search started: 5/14/09 5:02 PM | ||
+ | Thu May 14 17:02:54 EDT 2009 | ||
+ | |||
+ | ====================================================== results | ||
+ | no errors detected | ||
+ | |||
+ | ====================================================== statistics | ||
+ | elapsed time: | ||
+ | states: | ||
+ | search: | ||
+ | choice generators: | ||
+ | heap: gc=1, new=262, free=14 | ||
+ | instructions: | ||
+ | max memory: | ||
+ | loaded code: classes=66, methods=839 | ||
+ | |||
+ | ====================================================== search finished: 5/14/09 5:02 PM | ||
+ | </ | ||
jpf-native/start.1242333921.txt.gz · Last modified: 2009/05/14 20:45 by franck