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:42] – franck | jpf-native:start [2009/05/14 21:03] (current) – franck | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== Handling Native Code ====== | ====== Handling Native Code ====== | ||
| - | |||
| - | JPF has two ways to handle native code: | ||
| - | * model class | ||
| - | * native peer class | ||
| Consider, for example, the following app. | Consider, for example, the following app. | ||
| Line 17: | Line 13: | ||
| } | } | ||
| } | } | ||
| + | </ | ||
| + | If we run JPF on this app, we get something like | ||
| + | < | ||
| + | JavaPathfinder v4.1 - (C) 1999-2007 RIACS/NASA Ames Research Center | ||
| + | |||
| + | |||
| + | ====================================================== system under test | ||
| + | application: | ||
| + | |||
| + | ====================================================== search started: 5/14/09 4:43 PM | ||
| + | |||
| + | ====================================================== error #1 | ||
| + | gov.nasa.jpf.jvm.NoUncaughtExceptionsProperty | ||
| + | java.lang.UnsatisfiedLinkError: | ||
| + | at sun.misc.VM.< | ||
| + | at java.nio.charset.Charset.atBugLevel(Charset.java: | ||
| + | at java.nio.charset.Charset.checkName(Charset.java: | ||
| + | at java.nio.charset.Charset.< | ||
| + | at sun.nio.cs.Unicode.< | ||
| + | at sun.nio.cs.UTF_8.< | ||
| + | at sun.nio.cs.FastCharsetProvider.lookup(FastCharsetProvider.java: | ||
| + | at sun.nio.cs.FastCharsetProvider.charsetForName(FastCharsetProvider.java: | ||
| + | at java.nio.charset.Charset.lookup2(Charset.java: | ||
| + | at java.nio.charset.Charset.lookup(Charset.java: | ||
| + | at java.nio.charset.Charset.isSupported(Charset.java: | ||
| + | at java.lang.StringCoding.lookupCharset(StringCoding.java: | ||
| + | at java.lang.StringCoding.decode(StringCoding.java: | ||
| + | at java.lang.String.< | ||
| + | at sun.util.calendar.ZoneInfoFile.getZoneAliases(ZoneInfoFile.java: | ||
| + | at sun.util.calendar.ZoneInfo.getAliasTable(ZoneInfo.java: | ||
| + | at sun.util.calendar.ZoneInfo.getTimeZone(ZoneInfo.java: | ||
| + | at java.util.TimeZone.getTimeZone(TimeZone.java: | ||
| + | at java.util.TimeZone.setDefaultZone(TimeZone.java: | ||
| + | at java.util.TimeZone.getDefaultRef(TimeZone.java: | ||
| + | at java.util.Date.normalize(Date.java: | ||
| + | at java.util.Date.toString(Date.java: | ||
| + | at gov.nasa.jpf.ConsoleOutputStream.println(ConsoleOutputStream.java: | ||
| + | |||
| + | |||
| + | ====================================================== trace #1 | ||
| + | ------------------------------------------------------ transition #0 thread: 0 | ||
| + | gov.nasa.jpf.jvm.choice.ThreadChoiceFromSet {>main} | ||
| + | [17631 insn w/o sources] | ||
| + | |||
| + | ====================================================== snapshot #1 | ||
| + | thread index=0, | ||
| + | owned locks: | ||
| + | call stack: | ||
| + | at sun.misc.VM.< | ||
| + | at java.nio.charset.Charset.atBugLevel(Charset.java: | ||
| + | at java.nio.charset.Charset.checkName(Charset.java: | ||
| + | at java.nio.charset.Charset.< | ||
| + | at sun.nio.cs.Unicode.< | ||
| + | at sun.nio.cs.UTF_8.< | ||
| + | at sun.nio.cs.FastCharsetProvider.lookup(FastCharsetProvider.java: | ||
| + | at sun.nio.cs.FastCharsetProvider.charsetForName(FastCharsetProvider.java: | ||
| + | at java.nio.charset.Charset.lookup2(Charset.java: | ||
| + | at java.nio.charset.Charset.lookup(Charset.java: | ||
| + | at java.nio.charset.Charset.isSupported(Charset.java: | ||
| + | at java.lang.StringCoding.lookupCharset(StringCoding.java: | ||
| + | at java.lang.StringCoding.decode(StringCoding.java: | ||
| + | at java.lang.String.< | ||
| + | at sun.util.calendar.ZoneInfoFile.getZoneAliases(ZoneInfoFile.java: | ||
| + | at sun.util.calendar.ZoneInfo.getAliasTable(ZoneInfo.java: | ||
| + | at sun.util.calendar.ZoneInfo.getTimeZone(ZoneInfo.java: | ||
| + | at java.util.TimeZone.getTimeZone(TimeZone.java: | ||
| + | at java.util.TimeZone.setDefaultZone(TimeZone.java: | ||
| + | at java.util.TimeZone.getDefaultRef(TimeZone.java: | ||
| + | at java.util.Date.normalize(Date.java: | ||
| + | at java.util.Date.toString(Date.java: | ||
| + | at gov.nasa.jpf.ConsoleOutputStream.println(ConsoleOutputStream.java: | ||
| + | |||
| + | |||
| + | ====================================================== results | ||
| + | error #1: gov.nasa.jpf.jvm.NoUncaughtExceptionsProperty " | ||
| + | |||
| + | ====================================================== statistics | ||
| + | elapsed time: | ||
| + | states: | ||
| + | search: | ||
| + | choice generators: | ||
| + | heap: gc=1, new=1842, free=48 | ||
| + | instructions: | ||
| + | max memory: | ||
| + | loaded code: classes=137, | ||
| + | |||
| + | ====================================================== search finished: 5/14/09 4:43 PM | ||
| + | </ | ||
| + | During the model checking of the app, JPF encounters some native code. | ||
| + | |||
| + | JPF has two ways to handle native code: | ||
| + | * model class | ||
| + | * native peer 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.1242333762.txt.gz · Last modified: by franck
