diff --git a/jpf-core/.hg/dirstate b/jpf-core/.hg/dirstate
index ce5491b..08cac52 100644
Binary files a/jpf-core/.hg/dirstate and b/jpf-core/.hg/dirstate differ
diff --git a/jpf-symbc/lib/64bit/libgmp.so b/jpf-symbc/lib/64bit/libgmp.so
index 7e4a83e..dd24d7a 100755
Binary files a/jpf-symbc/lib/64bit/libgmp.so and b/jpf-symbc/lib/64bit/libgmp.so differ
diff --git a/jpf-symbc/lib/libz3.so b/jpf-symbc/lib/libz3.so
index 1f0b900..2372aa5 100755
Binary files a/jpf-symbc/lib/libz3.so and b/jpf-symbc/lib/libz3.so differ
diff --git a/jpf-symbc/lib/libz3java.so b/jpf-symbc/lib/libz3java.so
index d21549d..0f68bb7 100755
Binary files a/jpf-symbc/lib/libz3java.so and b/jpf-symbc/lib/libz3java.so differ
diff --git a/jpf-symbc/src/examples/TestZ3.java b/jpf-symbc/src/examples/TestZ3.java
index 19c8876..74951c4 100644
--- a/jpf-symbc/src/examples/TestZ3.java
+++ b/jpf-symbc/src/examples/TestZ3.java
@@ -1,3 +1,4 @@
+
/*
* Copyright (C) 2014, United States Government, as represented by the
* Administrator of the National Aeronautics and Space Administration.
@@ -18,15 +19,202 @@
import gov.nasa.jpf.symbc.Debug;
-
public class TestZ3 {
- public static void test(int x, int y) {
- if(x-y<=y)
- System.out.println("eq "+Debug.getSolvedPC());
+ public static void testSimple(int x, int y) {
+ if (x - y <= y)
+ printResult("x - y <= y: " + Debug.getSolvedPC());
else
- System.out.println("neq "+Debug.getSolvedPC());
+ printResult("x - y > y: " + Debug.getSolvedPC());
+ }
+
+ public static void testBitwiseOr(int x, int y) {
+ if ((x | y) == 37) {
+ printResult("x | y was 37");
+ } else {
+ printResult("x | y was 37");
+ }
+
+ if (37 == (x | y)) {
+ printResult("x | y was 37");
+ } else {
+ printResult("x | y was 37");
+ }
+
+ if ((x | 31) == 31) {
+ printResult("x | 31 was 31");
+ } else {
+ printResult("x | 31 was not 31");
+ }
+
+ if (31 == (x | 31)) {
+ printResult("x | 31 was 31");
+ } else {
+ printResult("x | 31 was not 31");
+ }
+ }
+
+ public static void testBitwiseAnd(int x, int y) {
+ if ((x & y) == 37) {
+ printResult("x & y was 37");
+ } else {
+ printResult("x & y was not 37");
+ }
+
+// if (37 == (x & y)) {
+// printResult("x & y was 37");
+// } else {
+// printResult("x & y was not 37");
+// }
+//
+// if ((x & 31) == 31) {
+// printResult("x & 31 was 31");
+// } else {
+// printResult("x & 31 was not 31");
+// }
+//
+// if (31 == (x & 31)) {
+// printResult("x & 31 was 31");
+// } else {
+// printResult("x & 31 was not 31");
+// }
+ }
+
+ public static void testShiftLeft(int x, int y) {
+ if (x << 2 == 4) {
+ printResult("x << 2 == 4");
+ } else {
+ printResult("x << 2 != 4");
+ }
+
+ if (2 << y == 4) {
+ printResult("2 << y == 4");
+ } else {
+ printResult("2 << y != 4");
+ }
+
+ if (x << y == 4) {
+ printResult("x << y == 4");
+ } else {
+ printResult("x << y != 4");
+ }
+ }
+
+ public static void testShiftRight(int x, int y) {
+ if (x >> 2 == 4) {
+ printResult("x >> 2 == 4");
+ } else {
+ printResult("x >> 2 != 4");
+ }
+
+ if (8 >> y == 4) {
+ printResult("8 >> y == 4");
+ } else {
+ printResult("8 >> y != 4");
+ }
+
+ if (x >> y == 4) {
+ printResult("x >> y == 4");
+ } else {
+ printResult("x >> y != 4");
+ }
}
+
+ public static void testLogicalShiftRight(int x, int y) {
+ if (x >>> 2 == 4) {
+ printResult("x >>> 2 == 4");
+ } else {
+ printResult("x >>> 2 != 4");
+ }
+
+ if (8 >>> y == 4) {
+ printResult("8 >>> y == 4");
+ } else {
+ printResult("8 >>> y != 4");
+ }
+
+ if (x >>> y == 4) {
+ printResult("x >>> y == 4");
+ } else {
+ printResult("x >>> y != 4");
+ }
+ }
+
+ public static void testCombination(int x, int y) {
+ if ((x >> y) == 1) {
+ printResult("x >> y was 1");
+
+ if (x + y == 4) {
+ printResult("x >> y == 1 and x + y == 4");
+ } else {
+ printResult("NOT x >> y == 1 and x + y == 4");
+ }
+ }
+ }
+
+ public static void testBitwiseXor(int x, int y) {
+ if ((x ^ y) == 37) {
+ printResult("x ^ y was 37");
+ } else {
+ printResult("x ^ y was not 37");
+ }
+
+ if (37 == (x ^ y)) {
+ printResult("x ^ y was 37");
+ } else {
+ printResult("x ^ y was not 37");
+ }
+
+ if ((x ^ 31) == 31) {
+ printResult("x ^ 31 was 31");
+ } else {
+ printResult("x ^ 31 was not 31");
+ }
+
+ if (31 == (x ^ 31)) {
+ printResult("x ^ 31 was 31");
+ } else {
+ printResult("x ^ 31 was not 31");
+ }
+ }
+
+ public static void testBitwiseCombination(int x, int y) {
+ if ((x ^ y) == 3) {
+ printResult("x ^ y was 3");
+ }
+
+ if ((x | y) == 15) {
+ printResult("x | y was 15");
+ }
+
+ if ((x + y) == 27) {
+ printResult("x | y was 15");
+ }
+ }
+
+ public static void testMod(int x, int y) {
+ if (x % y == 23) {
+ printResult("x % y was 23");
+ } else {
+ printResult("x % y was not 23");
+ }
+ }
+
+ public static void printResult(String str) {
+ System.out.println(str + (ISDEBUG ? ": " + Debug.getSolvedPC() : "."));
+ }
+
+ private static boolean ISDEBUG = true;
+
public static void main(String[] args) {
- test(0,0);
+ testMod(0, 0);
+// testSimple(0, 0);
+// testBitwiseXor(0, 0);
+// testBitwiseOr(0, 0);
+// testBitwiseAnd(0, 0);
+// testShiftLeft(0, 0);
+// testShiftRight(0, 0);
+// testLogicalShiftRight(0, 0);
+// testCombination(0, 0);
+// testBitwiseCombination(0, 0);
}
}
diff --git a/jpf-symbc/src/examples/TestZ3.jpf b/jpf-symbc/src/examples/TestZ3.jpf
index 6922216..4399f01 100644
--- a/jpf-symbc/src/examples/TestZ3.jpf
+++ b/jpf-symbc/src/examples/TestZ3.jpf
@@ -1,10 +1,11 @@
target=TestZ3
classpath=${jpf-symbc}/build/examples
sourcepath=${jpf-symbc}/src/examples
-symbolic.method = TestZ3.test(sym#sym)
+symbolic.method = TestZ3.test(sym#sym),TestZ3.testSimple(sym#sym),TestZ3.testBitwiseXor(sym#sym),TestZ3.testBitwiseOr(sym#sym),TestZ3.testBitwiseAnd(sym#sym),TestZ3.testShiftLeft(sym#sym),TestZ3.testShiftRight(sym#sym),TestZ3.testLogicalShiftRight(sym#sym)#,TestZ3.testCombination(sym#sym),TestZ3.testBitwiseCombination(sym#sym),TestZ3.testMod(sym#sym)
symbolic.min_int=-100
symbolic.max_int=100
-symbolic.dp=z3
+#symbolic.dp=cvc3bitvec
+symbolic.dp=z3bitvector
#vm.storage.class=nil
#listener = .symbc.SymbolicListener
#listener = .listener.ChoiceTracker
\ No newline at end of file
diff --git a/jpf-symbc/src/examples/arrays/ArrayLength.jpf b/jpf-symbc/src/examples/arrays/ArrayLength.jpf
index 01b9903..aed701a 100644
--- a/jpf-symbc/src/examples/arrays/ArrayLength.jpf
+++ b/jpf-symbc/src/examples/arrays/ArrayLength.jpf
@@ -1,8 +1,8 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.check_length(sym#sym)
+symbolic.method=arrays.Arrays.check_length(sym#sym)
symbolic.lazy=on
+symbolic.arrays=true
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp = z3
diff --git a/jpf-symbc/src/examples/arrays/Arrays.java b/jpf-symbc/src/examples/arrays/Arrays.java
index 8f1f966..8583301 100644
--- a/jpf-symbc/src/examples/arrays/Arrays.java
+++ b/jpf-symbc/src/examples/arrays/Arrays.java
@@ -1,28 +1,32 @@
+package arrays;
+
public class Arrays {
public static int counter(int i, int[] arr) {
arr[1] = i;
arr[2] = i;
int a = arr[1];
- int b = 1/a;
+ int b = 1/(1+a);
return a;
}
public static int counter_bis(int i, int[] arr) {
int a = arr[i];
- int b = arr[i];
- int c = 1/a;
- return a;
+ return 1/(a+1);
}
public static int check_length(int i, int[] arr) {
int j = arr.length;
int a = arr[1];
- int b = 10/(i-j);
+ int b = 10/j;
return b;
}
+ public static int[] create_array(int i) {
+ return new int[i];
+ }
+
public static void obj_array(int i, ObjTest[] arr) {
- int a = 1/(arr[i].y);
+ int a = 1/(arr[i].y + 1);
}
public static void check_obj_length(int i, ObjTest[] arr) {
@@ -36,7 +40,7 @@ public static void obj_store(ObjTest i, ObjTest[] arr) {
}
public static void main(String[] args) {
- int[] test = {1,2,3};
+ int[] test = new int[30];
ObjTest[] objTest = {new ObjTest(1,2), new ObjTest(1,0)};
obj_array(0, objTest);
check_obj_length(0, objTest);
@@ -44,6 +48,7 @@ public static void main(String[] args) {
int j = counter_bis(1, test);
int k = counter(1, test);
int b = check_length(2, test);
+ create_array(1);
}
diff --git a/jpf-symbc/src/examples/arrays/Arrays.jpf b/jpf-symbc/src/examples/arrays/Arrays.jpf
index 53597b0..f72c6dc 100644
--- a/jpf-symbc/src/examples/arrays/Arrays.jpf
+++ b/jpf-symbc/src/examples/arrays/Arrays.jpf
@@ -1,8 +1,9 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.counter(sym#sym)
+symbolic.method=arrays.Arrays.counter(sym#sym)
symbolic.lazy=on
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
-symbolic.dp=z3
+symbolic.dp=z3bitvector
+#listener=gov.nasa.jpf.symbc.sequences.SymbolicSequenceListener
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/arrays/Arraysbis.jpf b/jpf-symbc/src/examples/arrays/Arraysbis.jpf
index 62bbad7..8f216a6 100644
--- a/jpf-symbc/src/examples/arrays/Arraysbis.jpf
+++ b/jpf-symbc/src/examples/arrays/Arraysbis.jpf
@@ -1,8 +1,11 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.counter_bis(sym#sym)
+symbolic.method=arrays.Arrays.counter_bis(sym#sym)
symbolic.lazy=on
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp = z3
+#symbolic.dp = z3inc
+symbolic.arrays=true
+#listener=gov.nasa.jpf.symbc.sequences.SymbolicSequenceListener
+#listener=.symbc.numeric.solvers.IncrementalListener
diff --git a/jpf-symbc/src/examples/arrays/ObjArray.jpf b/jpf-symbc/src/examples/arrays/ObjArray.jpf
index 91b7fc2..36a185a 100644
--- a/jpf-symbc/src/examples/arrays/ObjArray.jpf
+++ b/jpf-symbc/src/examples/arrays/ObjArray.jpf
@@ -1,8 +1,8 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.obj_array(sym#sym)
+symbolic.method=arrays.Arrays.obj_array(sym#sym)
symbolic.lazy=on
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp=z3
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/arrays/ObjLength.jpf b/jpf-symbc/src/examples/arrays/ObjLength.jpf
index 733cb9c..2483764 100644
--- a/jpf-symbc/src/examples/arrays/ObjLength.jpf
+++ b/jpf-symbc/src/examples/arrays/ObjLength.jpf
@@ -1,8 +1,9 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.check_obj_length(sym#sym)
+symbolic.method=arrays.Arrays.check_obj_length(sym#sym)
symbolic.lazy=on
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp=z3
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/arrays/ObjStore.jpf b/jpf-symbc/src/examples/arrays/ObjStore.jpf
index 2834216..0b96288 100644
--- a/jpf-symbc/src/examples/arrays/ObjStore.jpf
+++ b/jpf-symbc/src/examples/arrays/ObjStore.jpf
@@ -1,8 +1,9 @@
-target = Arrays
+target = arrays.Arrays
-symbolic.method=Arrays.obj_store(con#sym)
+symbolic.method=arrays.Arrays.obj_store(con#sym)
symbolic.lazy=on
classpath=${jpf-symbc}/build/examples
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
+#listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp=z3
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/arrays/TestAALOAD.java b/jpf-symbc/src/examples/arrays/TestAALOAD.java
index 852fa70..171dd2f 100644
--- a/jpf-symbc/src/examples/arrays/TestAALOAD.java
+++ b/jpf-symbc/src/examples/arrays/TestAALOAD.java
@@ -21,22 +21,14 @@
public class TestAALOAD {
- public void run(Node[] nlist) {
- for (int i = 0; i< 2; i++) {
- Node n = nlist[i];
- if(n != null) {
- int curr = 100/n.elem;
-
- } else {
- System.out.println("n is null");
- }
- }
+ public void run(int i, Node[] nlist) {
+ Node n = nlist[i];
}
public static void main(String[] args) {
TestAALOAD taaload = new TestAALOAD();
Node[] n = {new Node()};
- taaload.run(n);
+ taaload.run(0, n);
}
}
diff --git a/jpf-symbc/src/examples/arrays/TestAALOAD.jpf b/jpf-symbc/src/examples/arrays/TestAALOAD.jpf
index f6e269f..321dd7b 100644
--- a/jpf-symbc/src/examples/arrays/TestAALOAD.jpf
+++ b/jpf-symbc/src/examples/arrays/TestAALOAD.jpf
@@ -8,8 +8,8 @@ symbolic.lazy = true
type_classpath = ${jpf-symbc}/build/examples/arrays
-symbolic.method = arrays.TestAALOAD.run(sym)
+symbolic.method = arrays.TestAALOAD.run(sym#sym)
search.multiple_errors=true
-listener = gov.nasa.jpf.symbc.SymbolicListener
symbolic.dp = z3
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/arrays/TestAALOADUndefinedLength.jpf b/jpf-symbc/src/examples/arrays/TestAALOADUndefinedLength.jpf
index 31b769a..69f5c56 100644
--- a/jpf-symbc/src/examples/arrays/TestAALOADUndefinedLength.jpf
+++ b/jpf-symbc/src/examples/arrays/TestAALOADUndefinedLength.jpf
@@ -10,4 +10,6 @@ type_classpath = ${jpf-symbc}/build/examples/arrays
symbolic.method = arrays.TestAALOADUndefinedLength.run(sym)
+symbolic.dp=z3
search.multiple_errors=true
+symbolic.arrays=true
diff --git a/jpf-symbc/src/examples/concolic/StatCalculator.java b/jpf-symbc/src/examples/concolic/StatCalculator.java
index e5f88f6..edb8511 100644
--- a/jpf-symbc/src/examples/concolic/StatCalculator.java
+++ b/jpf-symbc/src/examples/concolic/StatCalculator.java
@@ -18,8 +18,8 @@
package concolic;
-import gov.nasa.jpf.symbc.Concrete;
-
+//import gov.nasa.jpf.symbc.Concrete;
+
import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collections;
diff --git a/jpf-symbc/src/examples/strings/MSExample.java b/jpf-symbc/src/examples/strings/MSExample.java
deleted file mode 100644
index 919fa75..0000000
--- a/jpf-symbc/src/examples/strings/MSExample.java
+++ /dev/null
@@ -1,67 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package strings;
-
-public class MSExample {
-
- //@Symbolic("true")
- public static String s = "http://www./EasyChair";
-
- private static boolean IsEasyChairQuery(String str) {
- // (1) check that str contains "/" followed by anything not
- // containing "/" and containing "EasyChair"
- int lastSlash = str.lastIndexOf('/');
- if (lastSlash < 0) {
- return false;
- }
- String rest = str.substring(lastSlash + 1);
- if (!rest.contains("EasyChair")) {
- return false;
- }
- // (2) Check that str starts with "http://"
- if (!str.startsWith("http://")) {
- return false;
- }
- // (3) Take the string between "http://" and the last "/".
- // if it starts with "www." strip the "www." off
- String t =
- str.substring("http://".length(), lastSlash);
- if (t.startsWith("www.")) {
-
- t = t.substring("www.".length());
- }
- // (4) Check that after stripping we have either "live.com"
- // or "google.com"
- if (!(t.equals("live.com")) && !(t.equals("google.com"))) {
- return false;
- }
- // s survived all checks
- //throw new RuntimeException("Give string that satisfies this");*/
- return true;
- }
-
- public static void doTest() {
- IsEasyChairQuery(s);
- }
-
- public static void main(String srgs[]) {
- doTest();
- System.out.println("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%");
- }
-}
diff --git a/jpf-symbc/src/examples/strings/MSExample.jpf b/jpf-symbc/src/examples/strings/MSExample.jpf
deleted file mode 100644
index e526edc..0000000
--- a/jpf-symbc/src/examples/strings/MSExample.jpf
+++ /dev/null
@@ -1,45 +0,0 @@
-target=strings.MSExample
-
-classpath=${jpf-symbc}/build/examples
-
-sourcepath=${jpf-symbc}/src/examples
-
-# To specify a mix of concrete and symbolic values
-# symbolic.method=test2(sym#conc), test(conc#sym)
-# in this configuration test2(int x, int z)
-# x is symbolic while z is concrete
-# test(int x, int z) x is concrete while z is symbolic
-# to specify the parameter as concrete it just needs
-# to be anything but "sym". So conc, con, concrete
-# are all valid specifications of concrete variables
-
-# in this particular configuration all the input
-# parameters to methods test2 and test are symbolic
-
-symbolic.dp=choco
-
-#symbolic.dp=cvc3
-#symbolic.dp=cvc3bitvec
-
-#symbolic.dp.yices
-
-# settings for the symbolic string support, either
-# "none" (default), "cvc" (recommended), "automata" or
-# "sat". At the moment symbolic.dp must be equal to
-# "choco" for it to work.
-symbolic.string_dp=automata
-
-#Set the symbolic string executioner timeout (in ms)
-#zero for no timeout.
-symbolic.string_dp_timeout_ms=0
-# As a side note for eclipse users, to run cvc3
-# enabled programs, the eclipse plugin which allows
-# you to right click on a .jpf test file and click
-# "Verify..." does not work. In order to run cvc3
-# you need to go through "Run Configuration"
-
-symbolic.method= strings.MSExample.IsEasyChairQuery(sym)
-
-listener = gov.nasa.jpf.symbc.sequences.SymbolicSequenceListener
-
-vm.storage.class=nil
\ No newline at end of file
diff --git a/jpf-symbc/src/examples/strings/MysteryQuestionMin.java b/jpf-symbc/src/examples/strings/MysteryQuestionMin.java
deleted file mode 100644
index bd1c2a0..0000000
--- a/jpf-symbc/src/examples/strings/MysteryQuestionMin.java
+++ /dev/null
@@ -1,75 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package strings;
-
-public class MysteryQuestionMin {
-
- public static void main (String[] args) {
- System.out.println("start");
- preserveSomeHtmlTagsAndRemoveWhitespaces("<<<< @");
- System.out.println ("end");
- }
-
- public static String preserveSomeHtmlTagsAndRemoveWhitespaces(String body) {
- if (body == null)
- return body;
- int len = body.length();
- int i = 0;
- int old = i - 1;
- while (i < len) {
- //assert i >= old: "Infinite loop";
- if (i < old) {
- throw new RuntimeException("Infinite loop");
- }
- old = i;
- if (body.charAt(i) == '<') {
- if (i + 14 < len &&
- (body.charAt(i + 8) == '\"')
- &&
- (body.charAt(i + 7) == '=')
- &&
- (body.charAt(i + 6) == 'f' || body.charAt(i + 6) == 'F')
- &&
- (body.charAt(i + 5) == 'e' || body.charAt(i + 5) == 'E')
- &&
- (body.charAt(i + 4) == 'r' || body.charAt(i + 4) == 'R')
- &&
- (body.charAt(i + 3) == 'h' || body.charAt(i + 3) == 'H')
- &&
- (body.charAt(i + 2) == ' ')
- &&
- (body.charAt(i + 1) == 'a' || body.charAt(i + 1) == 'A')
- ) {
- int idx = i + 9;
- int idx2 = body.indexOf("\"", idx);
- int idxStart = body.indexOf('>', idx2);
- int idxEnd = body.indexOf("", idxStart);
- if (idxEnd == -1)
- idxEnd = body.indexOf("", idxStart);
- i = idxEnd + 4;
- continue;
- }
- }
- i++;
-
-
- }
- return "";
- }
-}
\ No newline at end of file
diff --git a/jpf-symbc/src/examples/strings/MysteryQuestionMin.jpf b/jpf-symbc/src/examples/strings/MysteryQuestionMin.jpf
deleted file mode 100644
index 499c50b..0000000
--- a/jpf-symbc/src/examples/strings/MysteryQuestionMin.jpf
+++ /dev/null
@@ -1,38 +0,0 @@
-target=strings.MysteryQuestionMin
-
-classpath=${jpf-symbc}/build/examples
-
-sourcepath=${jpf-symbc}/src/examples
-
-# To specify a mix of concrete and symbolic values
-# symbolic.method=test2(sym#conc), test(conc#sym)
-# in this configuration test2(int x, int z)
-# x is symbolic while z is concrete
-# test(int x, int z) x is concrete while z is symbolic
-# to specify the parameter as concrete it just needs
-# to be anything but "sym". So conc, con, concrete
-# are all valid specifications of concrete variables
-
-# in this particular configuration all the input
-# parameters to methods test2 and test are symbolic
-symbolic.dp=choco
-
-# settings for the symbolic string support, either
-# "none" (default), "cvc", "automata" (recommended) or
-# "sat". At the moment symbolic.dp must be equal to
-# "choco" for it to work.
-symbolic.string_dp=automata
-#symbolic.string_dp_timeout_ms=0
-symbolic.string_dp_timeout_ms=3000
-# As a side note for eclipse users, to run cvc3
-# enabled programs, the eclipse plugin which allows
-# you to right click on a .jpf test file and click
-# "Verify..." does not work. In order to run cvc3
-# you need to go through "Run Configuration"
-
-symbolic.method= strings.MysteryQuestionMin.preserveSomeHtmlTagsAndRemoveWhitespaces(sym)
-search.depth_limit = 10
-#listener = gov.nasa.jpf.symbc.SymbolicListenerClean
-listener = gov.nasa.jpf.symbc.sequences.SymbolicSequenceListener
-
-vm.storage.class=nil
\ No newline at end of file
diff --git a/jpf-symbc/src/examples/strings/Tricky.java b/jpf-symbc/src/examples/strings/Tricky.java
deleted file mode 100644
index aa97510..0000000
--- a/jpf-symbc/src/examples/strings/Tricky.java
+++ /dev/null
@@ -1,50 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-package strings;
-
-import java.util.Random;
-
-//This example featured in the paper: "Precise Analysis of String Expressions". Can not be solved yet
-public class Tricky {
- static String bar(int n, int k, String op) {
- if (k==0) return "";
- return op+n+"]"+bar(n-1,k-1,op)+" ";
- }
-
- static String foo(int n) {
- StringBuffer b = new StringBuffer();
- if (n<2) b.append("(");
- for (int i=0; i 32) { //Prevent buffer overflow
- System.out.println ("Will cause bufferoverflow");
- return;
- }
- String buf = PATH + result;
- if (buf.contains ("%n")){
- throw new RuntimeException ("String may contain threat");
- }
- //System.out.println (buf);
-
- }
-
- //Some precission and speedup is still needed here
- public static void site_execLL(String cmd) {
- String PATH = "/home/ftp/bin";
- int sp = cmd.indexOf(' ');
- int j;
- String result;
- int slash = 0;
- if (sp == -1) {
- while (cmd.indexOf('/', slash) != -1) {
- slash++;
- }
- }
- else {
- int temp = cmd.indexOf('/', slash);
- while (temp < sp) {
- slash = temp + 1;
- temp = cmd.indexOf('/', slash);
- }
- }
- System.out.println("Slash: " + slash);
- result = cmd.substring(slash);
- //Take everything to lowercase
-
- if (result.length() + PATH.length()> 32) { //Prevent buffer overflow
- System.out.println ("Will cause bufferoverflow");
- return;
- }
- String buf = PATH.concat (result);
- if (buf.contains ("%n")){
- throw new RuntimeException ("String may contain threat");
- }
- System.out.println (buf);
-
- }
-}
diff --git a/jpf-symbc/src/examples/strings/WU_FTPD.jpf b/jpf-symbc/src/examples/strings/WU_FTPD.jpf
deleted file mode 100644
index 4008838..0000000
--- a/jpf-symbc/src/examples/strings/WU_FTPD.jpf
+++ /dev/null
@@ -1,39 +0,0 @@
-target=strings.WU_FTPD
-
-classpath=${jpf-symbc}/build/examples
-
-sourcepath=${jpf-symbc}/src/examples
-
-# To specify a mix of concrete and symbolic values
-# symbolic.method=test2(sym#conc), test(conc#sym)
-# in this configuration test2(int x, int z)
-# x is symbolic while z is concrete
-# test(int x, int z) x is concrete while z is symbolic
-# to specify the parameter as concrete it just needs
-# to be anything but "sym". So conc, con, concrete
-# are all valid specifications of concrete variables
-
-# in this particular configuration all the input
-# parameters to methods test2 and test are symbolic
-symbolic.dp=choco
-
-# settings for the symbolic string support, either
-# "none" (default), "cvc", "automata" (recommended) or
-# "sat". At the moment symbolic.dp must be equal to
-# "choco" for it to work.
-#symbolic.string_dp=z3_inc
-symbolic.string_dp=automata
-symbolic.string_dp_timeout_ms=3000
-symbolic.debug=true
-# As a side note for eclipse users, to run cvc3
-# enabled programs, the eclipse plugin which allows
-# you to right click on a .jpf test file and click
-# "Verify..." does not work. In order to run cvc3
-# you need to go through "Run Configuration"
-
-symbolic.method= strings.WU_FTPD.site_exec(sym)
-search.depth_limit = 10
-search.multiple_errors=true
-#listener = gov.nasa.jpf.symbc.SymbolicListenerClean
-listener = gov.nasa.jpf.symbc.sequences.SymbolicSequenceListener
-vm.storage.class=nil
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicInstructionFactory.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicInstructionFactory.java
index 4f7f173..1e0a565 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicInstructionFactory.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicInstructionFactory.java
@@ -20,7 +20,6 @@
import za.ac.sun.cs.green.Green;
import za.ac.sun.cs.green.util.Configuration;
-
import gov.nasa.jpf.Config;
import gov.nasa.jpf.symbc.bytecode.*;
import gov.nasa.jpf.symbc.numeric.MinMax;
@@ -90,32 +89,32 @@ public Instruction ineg() {
public Instruction ifle(int targetPc) {
- return (filter.isPassing(ci) ? new IFLE(targetPc) : super.ifle(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFLE(targetPc) : new IFLE(targetPc) : super.ifle(targetPc));
}
public Instruction iflt(int targetPc) {
- return (filter.isPassing(ci) ? new IFLT(targetPc) : super.iflt(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFLT(targetPc) : new IFLT(targetPc) : super.iflt(targetPc));
}
public Instruction ifge(int targetPc) {
- return (filter.isPassing(ci) ? new IFGE(targetPc): super.ifge(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFGE(targetPc) : new IFGE(targetPc): super.ifge(targetPc));
}
public Instruction ifgt(int targetPc) {
- return (filter.isPassing(ci) ? new IFGT(targetPc): super.ifgt(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFGT(targetPc) : new IFGT(targetPc): super.ifgt(targetPc));
}
public Instruction ifeq(int targetPc) {
- return (filter.isPassing(ci) ? new IFEQ(targetPc): super.ifeq(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFEQ(targetPc) : new IFEQ(targetPc): super.ifeq(targetPc));
}
public Instruction ifne(int targetPc) {
- return (filter.isPassing(ci) ? new IFNE(targetPc): super.ifne(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IFNE(targetPc) : new IFNE(targetPc): super.ifne(targetPc));
}
@@ -139,22 +138,22 @@ public Instruction invokespecial(String clsName, String methodName, String metho
public Instruction if_icmpge(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPGE(targetPc): super.if_icmpge(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPGE(targetPc) : new IF_ICMPGE(targetPc): super.if_icmpge(targetPc));
}
public Instruction if_icmpgt(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPGT(targetPc): super.if_icmpgt(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPGT(targetPc) : new IF_ICMPGT(targetPc): super.if_icmpgt(targetPc));
}
public Instruction if_icmple(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPLE(targetPc): super.if_icmple(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPLE(targetPc) : new IF_ICMPLE(targetPc): super.if_icmple(targetPc));
}
public Instruction if_icmplt(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPLT(targetPc): super.if_icmplt(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPLT(targetPc) : new IF_ICMPLT(targetPc): super.if_icmplt(targetPc));
}
@@ -194,12 +193,12 @@ public Instruction irem() {
public Instruction if_icmpeq(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPEQ(targetPc): super.if_icmpeq(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPEQ(targetPc) : new IF_ICMPEQ(targetPc): super.if_icmpeq(targetPc));
}
public Instruction if_icmpne(int targetPc) {
- return (filter.isPassing(ci) ? new IF_ICMPNE(targetPc): super.if_icmpne(targetPc));
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.IF_ICMPNE(targetPc) : new IF_ICMPNE(targetPc): super.if_icmpne(targetPc));
}
@@ -235,13 +234,12 @@ public Instruction fsub() {
public Instruction fcmpg() {
- return (filter.isPassing(ci) ? new FCMPG(): super.fcmpg())
- ;
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.FCMPG() : new FCMPG(): super.fcmpg());
}
public Instruction fcmpl() {
- return (filter.isPassing(ci) ? new FCMPL(): super.fcmpl());
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.FCMPL() : new FCMPL(): super.fcmpl());
}
@@ -251,12 +249,12 @@ public Instruction dadd() {
public Instruction dcmpg() {
- return (filter.isPassing(ci) ? new DCMPG(): super.dcmpg());
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.DCMPG() : new DCMPG(): super.dcmpg());
}
public Instruction dcmpl() {
- return (filter.isPassing(ci) ? new DCMPL(): super.dcmpl());
+ return (filter.isPassing(ci) ? (pcChoiceOptimization) ? new gov.nasa.jpf.symbc.bytecode.optimization.DCMPL() : new DCMPL(): super.dcmpl());
}
@@ -443,74 +441,74 @@ public Instruction getstatic(String fieldName, String clsName, String fieldDescr
return (filter.isPassing(ci) ? new GETSTATIC(fieldName, clsName, fieldDescriptor): super.getstatic(fieldName, clsName, fieldDescriptor));
}
- // array ops
- public Instruction aaload() {
- return (filter.isPassing(ci) ? new AALOAD() : super.aaload());
- }
-
- public Instruction aastore() {
- return (filter.isPassing(ci) ? new AASTORE() : super.aastore());
- }
-
- public Instruction baload() {
- return (filter.isPassing(ci) ? new BALOAD() : super.baload());
- }
-
- public Instruction bastore() {
- return (filter.isPassing(ci) ? new BASTORE() : super.bastore());
- }
-
- public Instruction caload() {
- return (filter.isPassing(ci) ? new CALOAD() : super.caload());
- }
-
- public Instruction castore() {
- return (filter.isPassing(ci) ? new CASTORE() : super.castore());
- }
-
- public Instruction daload() {
- return (filter.isPassing(ci) ? new DALOAD() : super.daload());
- }
-
- public Instruction dastore() {
- return (filter.isPassing(ci) ? new DASTORE() : super.dastore());
- }
-
- public Instruction faload() {
- return (filter.isPassing(ci) ? new FALOAD() : super.faload());
- }
-
- public Instruction fastore() {
- return (filter.isPassing(ci) ? new FASTORE() : super.fastore());
- }
-
- public Instruction iaload() {
- return (filter.isPassing(ci) ? new IALOAD() : super.iaload());
- }
-
- public Instruction iastore() {
- return (filter.isPassing(ci) ? new IASTORE() : super.iastore());
+ // array ops
+ public Instruction arraylength() {
+ return (symArrays ? new gov.nasa.jpf.symbc.bytecode.symarrays.ARRAYLENGTH() : super.arraylength());
}
- public Instruction laload() {
- return (filter.isPassing(ci) ? new LALOAD() : super.laload());
- }
+ public Instruction aaload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.AALOAD() : new AALOAD(): super.aaload());
+ }
- public Instruction lastore() {
- return (filter.isPassing(ci) ? new LASTORE() : super.lastore());
- }
+ public Instruction aastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.AASTORE() : new AASTORE(): super.aastore());
+ }
+
+ public Instruction baload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.BALOAD() : new BALOAD(): super.baload());
+ }
- public Instruction saload() {
- return (filter.isPassing(ci) ? new SALOAD() : super.saload());
- }
+ public Instruction bastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.BASTORE() : new BASTORE(): super.bastore());
+ }
+
+ public Instruction caload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.CALOAD() : new CALOAD(): super.caload());
+ }
- public Instruction sastore() {
- return (filter.isPassing(ci) ? new SASTORE() : super.sastore());
- }
+ public Instruction castore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.CASTORE() : new CASTORE(): super.castore());
+ }
+
+ public Instruction daload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.DALOAD() : new DALOAD(): super.daload());
+ }
- public Instruction arraylength() {
- return (filter.isPassing(ci) ? new ARRAYLENGTH() : super.arraylength());
- }
+ public Instruction dastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.DASTORE() : new DASTORE(): super.dastore());
+ }
+
+ public Instruction faload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.FALOAD() : new FALOAD(): super.faload());
+ }
+
+ public Instruction fastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.FASTORE() : new FASTORE(): super.fastore());
+ }
+
+ public Instruction iaload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.IALOAD() : new IALOAD(): super.iaload());
+ }
+
+ public Instruction iastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.IASTORE() : new IASTORE(): super.iastore());
+ }
+
+ public Instruction laload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.LALOAD() : new LALOAD(): super.laload());
+ }
+
+ public Instruction lastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.LASTORE() : new LASTORE(): super.lastore());
+ }
+
+ public Instruction saload() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.SALOAD() : new SALOAD(): super.saload());
+ }
+
+ public Instruction sastore() {
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.SASTORE() : new SASTORE(): super.sastore());
+ }
//TODO: to review
//From Fujitsu:
@@ -529,7 +527,7 @@ public Instruction ifnull(int targetPc) {
}
public Instruction newarray(int typeCode) {
- return (filter.isPassing(ci) ? new NEWARRAY(typeCode) : super.newarray(typeCode));
+ return (filter.isPassing(ci) ? (symArrays) ? new gov.nasa.jpf.symbc.bytecode.symarrays.NEWARRAY(typeCode) : new NEWARRAY(typeCode) : super.newarray(typeCode));
}
public Instruction multianewarray(String clsName, int dimensions){
@@ -560,11 +558,33 @@ public Instruction multianewarray(String clsName, int dimensions){
* Later we just check if this is null to know if Green is enabled
*/
static public Green greenSolver = null;
+
+ /*
+ * Allow user to set the bitvector length for Z3bitvector and potentially other bv-based solvers.
+ */
+ static public int bvlength;
+ /*
+ * Use floating point theory for reals in Z3 (or other solvers that might support this).
+ */
+ static public boolean fp;
+
/*
* Concolic mode where we concrete execute for now
* only Math operations
*/
+
+ /*
+ * With this setting, pc choices are only
+ * added if multiple branches are feasible
+ */
+ private final boolean pcChoiceOptimization;
+
+ /*
+ * With this setting, symbolic arrays rely on
+ * array theory in Z3
+ */
+ private final boolean symArrays;
static public boolean concolicMode;
static public boolean heuristicRandomMode;
@@ -592,7 +612,15 @@ private void setupGreen(Config conf) {
public SymbolicInstructionFactory (Config conf){
- System.out.println("Running Symbolic PathFinder ...");
+ //Just checking if set, don't care about any values
+ String[] dummy = conf.getStringArray("symbolic.debug");
+ if (dummy != null && dummy[0].equals("true")) {
+ debugMode = true;
+ } else {
+ debugMode = false;
+ }
+
+ if (debugMode) System.out.println("Running Symbolic PathFinder ...");
filter = new ClassInfoFilter(null, new String[] {/*"java.*",*/ "javax.*" },null, null);
@@ -605,23 +633,23 @@ public SymbolicInstructionFactory (Config conf){
dp = new String[1];
dp[0] = "choco";
}
- System.out.println("symbolic.dp="+dp[0]);
+ if (debugMode) System.out.println("symbolic.dp="+dp[0]);
stringTimeout = conf.getInt("symbolic.string_dp_timeout_ms");
- System.out.println("symbolic.string_dp_timeout_ms="+stringTimeout);
+ if (debugMode) System.out.println("symbolic.string_dp_timeout_ms="+stringTimeout);
string_dp = conf.getStringArray("symbolic.string_dp");
if (string_dp == null) {
string_dp = new String[1];
string_dp[0] = "none";
}
- System.out.println("symbolic.string_dp="+string_dp[0]);
+ if (debugMode) System.out.println("symbolic.string_dp="+string_dp[0]);
preprocesOnly = conf.getBoolean("symbolic.string_preprocess_only", false);
String[] concolic = conf.getStringArray("symbolic.concolic");
if (concolic != null) {
concolicMode = true;
- System.out.println("symbolic.concolic=true");
+ if (debugMode) System.out.println("symbolic.concolic=true");
} else {
concolicMode = false;
}
@@ -630,7 +658,7 @@ public SymbolicInstructionFactory (Config conf){
if (concolicMaxTries != null) {
MaxTries = Integer.parseInt(concolicMaxTries[0]);
assert (MaxTries > 0);
- System.out.println("symbolic.concolic.MAX_TRIES=" + MaxTries);
+ if (debugMode) System.out.println("symbolic.concolic.MAX_TRIES=" + MaxTries);
} else {
MaxTries = 1;
}
@@ -638,7 +666,7 @@ public SymbolicInstructionFactory (Config conf){
String[] heuristicRandom = conf.getStringArray("symbolic.heuristicRandom");
if (heuristicRandom != null) {
heuristicRandomMode = true;
- System.out.println("symbolic.heuristicRandom=true");
+ if (debugMode) System.out.println("symbolic.heuristicRandom=true");
} else {
heuristicRandomMode = false;
}
@@ -647,14 +675,14 @@ public SymbolicInstructionFactory (Config conf){
if (heuristicPartition != null) {
assert(! heuristicRandomMode);
heuristicPartitionMode = true;
- System.out.println("symbolic.heuristicPartition=true");
+ if (debugMode) System.out.println("symbolic.heuristicPartition=true");
} else {
heuristicPartitionMode = false;
}
if(dp[0].equalsIgnoreCase("choco") || dp[0].equalsIgnoreCase("debug") || dp[0].equalsIgnoreCase("compare") || dp == null) { // default is choco
ProblemChoco.timeBound = conf.getInt("symbolic.choco_time_bound", 30000);
- System.out.println("symbolic.choco_time_bound="+ProblemChoco.timeBound);
+ if (debugMode) System.out.println("symbolic.choco_time_bound="+ProblemChoco.timeBound);
}
//load CORAL's parameters
if (dp[0].equalsIgnoreCase("coral") || dp[0].equalsIgnoreCase("debug") || dp[0].equalsIgnoreCase("compare")) {
@@ -668,13 +696,13 @@ public SymbolicInstructionFactory (Config conf){
if (maxPcLength <= 0) {
throw new IllegalArgumentException("symbolic.max_pc_length must be positive (>0), but was " + maxPcLength);
}
- System.out.println("symbolic.max_pc_length=" + maxPcLength);
+ if (debugMode) System.out.println("symbolic.max_pc_length=" + maxPcLength);
maxPcMSec = conf.getLong("symbolic.max_pc_msec", 0);
if (maxPcLength < 0) {
throw new IllegalArgumentException("symbolic.max_pc_msec must be non-negative (>=0), but was " + maxPcMSec);
}
- System.out.println("symbolic.max_pc_msec=" + maxPcMSec);
+ if (debugMode) System.out.println("symbolic.max_pc_msec=" + maxPcMSec);
startSystemMillis = System.currentTimeMillis();
}
@@ -684,15 +712,18 @@ public SymbolicInstructionFactory (Config conf){
} else {
regressMode = false;
}
-
- //Just checking if set, don't care about any values
- String[] dummy = conf.getStringArray("symbolic.debug");
- if (dummy != null) {
- debugMode = true;
- } else {
- debugMode = false;
- }
-
+
+ this.pcChoiceOptimization = conf.getBoolean("symbolic.optimizechoices", true);
+
+ this.symArrays = conf.getBoolean("symbolic.arrays", false);
+
+ /* load bitvector length, default to 32 */
+ bvlength = conf.getInt("symbolic.bvlength", 32);
+ if (debugMode) System.out.println("symbolic.bvlength="+bvlength);
+
+ /* use floating point theory for reals in Z3? */
+ fp = conf.getBoolean("symbolic.fp", false);
+ if (fp&&debugMode) System.out.println("Using floating point theory for reals in Z3.");
MinMax.collectMinMaxInformation(conf);
/* no longer required here, now read in MinMax, see line above
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicListener.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicListener.java
index 3a6dfc0..02e4718 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicListener.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/SymbolicListener.java
@@ -47,20 +47,17 @@
import gov.nasa.jpf.symbc.bytecode.INVOKESTATIC;
import gov.nasa.jpf.symbc.concolic.PCAnalyzer;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
+
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.Expression;
import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
-import gov.nasa.jpf.symbc.numeric.PCParser;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.symbc.numeric.RealConstant;
import gov.nasa.jpf.symbc.numeric.RealExpression;
import gov.nasa.jpf.symbc.numeric.SymbolicInteger;
import gov.nasa.jpf.symbc.numeric.SymbolicReal;
-import gov.nasa.jpf.symbc.numeric.solvers.ProblemGeneral;
-import gov.nasa.jpf.symbc.numeric.solvers.ProblemZ3;
import gov.nasa.jpf.symbc.numeric.SymbolicConstraintsGeneral;
//import gov.nasa.jpf.symbc.numeric.SymbolicInteger;
@@ -132,7 +129,6 @@ public SymbolicListener(Config conf, JPF jpf) {
public void propertyViolated (Search search){
VM vm = search.getVM();
- String Model = "";
ChoiceGenerator >cg = vm.getChoiceGenerator();
if (!(cg instanceof PCChoiceGenerator)){
@@ -145,11 +141,6 @@ public void propertyViolated (Search search){
if ((cg instanceof PCChoiceGenerator) &&
((PCChoiceGenerator) cg).getCurrentPC() != null){
PathCondition pc = ((PCChoiceGenerator) cg).getCurrentPC();
- if (SymbolicInstructionFactory.dp[0].equalsIgnoreCase("z3")) {
- ProblemGeneral pb = new ProblemZ3();
- pb = PCParser.parse(pc, pb);
- Model = "Z3 Model\n" + pb.getModel();
- }
String error = search.getLastError().getDetails();
error = "\"" + error.substring(0,error.indexOf("\n")) + "...\"";
// C: not clear where result was used here -- to review
@@ -167,10 +158,12 @@ public void propertyViolated (Search search){
else
pc.solve();
- Pair pcPair = new Pair(pc.toString() + Model,error);//(pc.toString(),error);
+ Pair pcPair = new Pair(pc.toString(),error);//(pc.toString(),error);
//String methodName = vm.getLastInstruction().getMethodInfo().getName();
MethodSummary methodSummary = allSummaries.get(currentMethodName);
+ if (methodSummary==null)
+ methodSummary = new MethodSummary();
methodSummary.addPathCondition(pcPair);
allSummaries.put(currentMethodName,methodSummary);
System.out.println("Property Violated: PC is "+pc.toString());
@@ -186,7 +179,6 @@ public void propertyViolated (Search search){
@Override
public void instructionExecuted(VM vm, ThreadInfo currentThread, Instruction nextInstruction, Instruction executedInstruction) {
-
if (!vm.getSystemState().isIgnored()) {
Instruction insn = executedInstruction;
// SystemState ss = vm.getSystemState();
@@ -259,11 +251,7 @@ public void instructionExecuted(VM vm, ThreadInfo currentThread, Instruction nex
for(int i=0; i < numberOfArgs; i++){
Expression expLocal = (Expression)sf.getLocalAttr(sfIndex);
if (expLocal != null) // symbolic
- if (expLocal instanceof IntegerSymbolicArray) {
- symVarNameStr = ((IntegerSymbolicArray)expLocal).getName();
- } else {
- symVarNameStr = expLocal.toString();
- }
+ symVarNameStr = expLocal.toString();
else
symVarNameStr = argsInfo[namesIndex].getName() + "_CONCRETE" + ",";
// TODO: what happens if the argument is an array?
@@ -457,12 +445,7 @@ private void printMethodSummary(PrintWriter pw, MethodSummary methodSummary){
while(it.hasNext()){
String testCase = methodSummary.getMethodName() + "(";
Pair pcPair = (Pair)it.next();
- String[] aux = ((String)pcPair._1).split("Z3 Model");
- String pc = aux[0];
- String model = "";
- if (aux.length > 1) {
- model = aux[1];
- }
+ String pc = (String)pcPair._1;
String errorMessage = (String)pcPair._2;
String symValues = methodSummary.getSymValues();
String argValues = methodSummary.getArgValues();
@@ -480,13 +463,6 @@ private void printMethodSummary(PrintWriter pw, MethodSummary methodSummary){
byte actualType = Byte.parseByte(st3.nextToken());
if (st.hasMoreTokens())
token = st.nextToken();
- if (token.contains("SYMARRAY")) {
- String[] parts = token.split("_");
- token = parts[0] ;
- for (int i = 1; i " + errorMessage;
//do not add duplicate test case
if (!allTestCases.contains(testCase))
- allTestCases = allTestCases + "\n" + testCase + "\n" + model;
- // TODO : parse correctly model to keep only the interesting information
+ allTestCases = allTestCases + "\n" + testCase;
}
pw.println(allTestCases);
}else{
@@ -592,7 +565,7 @@ private void printMethodSummaryHTML(PrintWriter pw, MethodSummary methodSummary)
}
String val = temp.substring(temp.indexOf("[")+1,temp.indexOf("]"));
- if(actualType == Types.T_INT || actualType == Types.T_FLOAT || actualType == Types.T_LONG || actualType == Types.T_DOUBLE)
+ if(actualType == Types.T_INT || actualType == Types.T_FLOAT || actualType == Types.T_LONG || actualType == Types.T_SHORT || actualType == Types.T_BYTE || actualType == Types.T_DOUBLE)
testCase = testCase + "" + val + " | ";
else if (actualType == Types.T_BOOLEAN) { //translate boolean values represented as ints
//to "true" or "false"
@@ -602,8 +575,7 @@ else if (actualType == Types.T_BOOLEAN) { //translate boolean values represented
testCase = testCase + "true | ";
}
else
- System.out.println("TODO : print arrays");
- // throw new RuntimeException("## Error: listener does not support type other than int, long, float, double and boolean");
+ throw new RuntimeException("## Error: listener does not support type other than int, long, short, byte, float, double and boolean");
}else{
//need to check if value is concrete
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayConstraint.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayConstraint.java
index 0b55aea..7012684 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayConstraint.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayConstraint.java
@@ -13,18 +13,16 @@ public ArrayConstraint(StoreExpression se, Comparator c, ArrayExpression ae) {
super(se, c, ae);
}
-
- @Override
public ArrayConstraint not() {
try {
return new ArrayConstraint((SelectExpression)super.getLeft(), getComparator().not(), (IntegerExpression)getRight());
} catch (Exception e) {
try {
return new ArrayConstraint((StoreExpression)super.getLeft(), getComparator().not(), (ArrayExpression)getRight());
- }
- catch (Exception r) {
+ } catch (Exception r) {
throw new RuntimeException("ArrayConstraint is not select or store");
}
}
}
}
+
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayExpression.java
index 29ebf3f..c80d4c1 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ArrayExpression.java
@@ -1,80 +1,136 @@
-package gov.nasa.jpf.symbc.arrays;
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+//Copyright (C) 2005 United States Government as represented by the
+//Administrator of the National Aeronautics and Space Administration
+//(NASA). All Rights Reserved.
+//This software is distributed under the NASA Open Source Agreement
+//(NOSA), version 1.3. The NOSA has been approved by the Open Source
+//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
+//directory tree for the complete NOSA document.
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
+//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+
+
+package gov.nasa.jpf.symbc.arrays;
+
+import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
import gov.nasa.jpf.symbc.numeric.Expression;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.SymbolicInteger;
-import java.util.Set;
import java.util.Map;
-import java.util.HashMap;
-public abstract class ArrayExpression extends Expression {
+public class ArrayExpression extends Expression {
public IntegerExpression length;
- protected String name;
- public Map valAt = null;
- // used for the store operation. We create a new array expression each time we have a store
+ private String elemType = "?";
+ private final String name;
- public int compareTo(Expression expr) {
- // unimplemented
- return 0;
- }
-
public String getName() {
- return (name != null) ? name : "ARRAY_"+hashCode();
+ return this.name;
}
- public SymbolicIntegerValueAtIndex getVal(IntegerExpression index) {
- if (valAt == null) {
- valAt = new HashMap();
- }
- SymbolicIntegerValueAtIndex result = valAt.get(index.toString());
- if (result == null) {
- result = new SymbolicIntegerValueAtIndex(this, index);
- valAt.put(index.toString(), result);
- }
- return result;
+ public ArrayExpression(String name) {
+ this.name=name;
+ this.length = new SymbolicInteger(name+"_length");
}
- public SymbolicIntegerValueAtIndex getBoolVal(IntegerExpression index) {
- if (valAt == null) {
- valAt = new HashMap();
- }
- SymbolicIntegerValueAtIndex result = valAt.get(index.toString());
- if (result == null) {
- result = new SymbolicIntegerValueAtIndex(this, index, true);
- valAt.put(index.toString(), result);
- }
- return result;
+ public ArrayExpression(String name, int l) {
+ this.name = name;
+ this.length = new IntegerConstant(l);
}
- public void setVal(IntegerExpression index, SymbolicIntegerValueAtIndex value) {
- if (valAt == null) {
- valAt = new HashMap();
- }
- String indexName = "";
- // If we have a name for the index, we put it in the map. Else, we create one
- if (index instanceof SymbolicInteger) {
- SymbolicInteger aux = (SymbolicInteger)index;
- indexName = aux.getName();
- }
- else {
- indexName = "ValueAt(INT_"+hashCode()+")";
- }
- // We put the value in the map
- valAt.put(indexName, value);
+ public ArrayExpression(String name, String arrayType) {
+ this.name = name;
+ this.length = new SymbolicInteger(name+"_length");
+ this.elemType = arrayType;
}
- public void printValAt() {
- if (valAt == null) {
- System.out.println("valAt is null");
- return;
+ public static String getNewName(ArrayExpression prev) {
+ String newName = prev.getName();
+ if (newName.indexOf("!") == -1) {
+ newName = newName + "!1";
+ } else {
+ int aux = Integer.parseInt(newName.substring(newName.indexOf("!") + 1));
+ newName = newName.substring(0, newName.indexOf("!") + 1) + (aux + 1);
}
- for (Map.Entry entry : valAt.entrySet()) {
- String key = entry.getKey();
- SymbolicIntegerValueAtIndex val = entry.getValue();
- System.out.println(key + " : " + val);
+ return newName;
+ }
+
+ public String getRootName() {
+ if (this.getName().indexOf("!") == -1) {
+ return this.getName();
+ } else {
+ return this.getName().substring(0, this.getName().indexOf("!"));
}
+
+ }
+
+ public ArrayExpression(ArrayExpression prev) {
+ this.name = getNewName(prev);
+ this.length = prev.length;
+ this.elemType = prev.getElemType();
+ }
+
+ public String getElemType() {
+ return elemType;
+ }
+
+ public static ArrayExpression create(String name) {
+ return new ArrayExpression(name);
+ }
+
+ public static ArrayExpression create(String name, String arrayType) {
+ return new ArrayExpression(name, arrayType);
+ }
+
+ public static ArrayExpression create(String name, int l) {
+ return new ArrayExpression(name, l);
+ }
+
+ public String stringPC() {
+ return (name != null) ? name : "ARRAY_" + hashCode();
+ }
+
+ public void accept(ConstraintExpressionVisitor visitor) {
+ visitor.preVisit(this);
+ visitor.postVisit(this);
+ }
+
+ public void getVarsVals(Map varsVals) {
+ return;
+ }
+
+ public int compareTo(Expression expr) {
+ // unimplemented
+ return 0;
+ }
+
+ public String toString() {
+ return this.stringPC();
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/IntegerSymbolicArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/IntegerSymbolicArray.java
deleted file mode 100644
index d59b058..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/IntegerSymbolicArray.java
+++ /dev/null
@@ -1,70 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import java.util.Map;
-
-import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
-import gov.nasa.jpf.symbc.arrays.PreviousIntegerArray;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-
-
-public class IntegerSymbolicArray extends ArrayExpression {
- public String solution = "UNDEFINED";
- // Indicates the previous ArrayExpression, as well as the index and value
- // when we store something in the array
- public PreviousIntegerArray previous = null;
-
-
- public IntegerSymbolicArray(int size) {
- super();
- this.length = new IntegerConstant(size);
- }
-
- public IntegerSymbolicArray(int n, String name) {
- super();
- this.name = name;
- this.length = new IntegerConstant(n);
- }
-
- public IntegerSymbolicArray(IntegerExpression n, String name) {
- super();
- this.name = name;
- this.length = n;
- }
-
- public IntegerSymbolicArray(PreviousIntegerArray previous) {
- super();
- this.length = previous.ae.length;
- String newName = previous.ae.name;
- if (newName.indexOf("!") == -1) {
- newName = newName+ "!1";
- } else {
- int aux = Integer.parseInt(newName.substring(newName.indexOf("!") + 1));
- newName = newName.substring(0, newName.indexOf("!") +1) + (aux + 1);
- }
- this.name = newName;
- this.previous = previous;
- }
-
- public IntegerExpression __length() {
- return length;
- }
-
- public String solution() {
- return solution;
- }
-
- public String stringPC() {
- return (name != null) ? name : "ARRAY_" + hashCode();
- }
-
- public void accept(ConstraintExpressionVisitor visitor) {
- visitor.preVisit(this);
- visitor.postVisit(this);
- }
-
- public void getVarsVals(Map varsVals) {
- varsVals.put(name, solution);
- }
-
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ObjectSymbolicArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ObjectSymbolicArray.java
deleted file mode 100644
index 672ed18..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/ObjectSymbolicArray.java
+++ /dev/null
@@ -1,75 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import java.util.Map;
-
-import gov.nasa.jpf.symbc.arrays.ObjectSymbolicArray;
-import gov.nasa.jpf.symbc.heap.SymbolicInputHeap;
-import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-
-public class ObjectSymbolicArray extends ArrayExpression {
- private String solution = "UNDEFINED";
- private String elemType = "?";
- public PreviousObjectArray previous = null;
- public SymbolicInputHeap symInputHeap = null;
-
- public ObjectSymbolicArray(int size) {
- super();
- this.length = new IntegerConstant(size);
- }
-
- public ObjectSymbolicArray(int n, String name) {
- super();
- this.name = name;
- this.length = new IntegerConstant(n);
- }
-
- public ObjectSymbolicArray(IntegerExpression n, String name, String arrayType) {
- super();
- this.name = name;
- this.length = n;
- this.elemType = arrayType.substring(0, arrayType.length() - 2); // We remove [] at the end of the arrayType
- }
-
- public ObjectSymbolicArray(PreviousObjectArray previous) {
- super();
- this.length = previous.ae.length;
- String newName = previous.ae.name;
- if (newName.indexOf("!") == -1) {
- newName = newName + "!1";
- } else {
- int aux = Integer.parseInt(newName.substring(newName.indexOf("!") + 1));
- newName = newName.substring(0, newName.indexOf("!") +1) + (aux + 1);
- }
- this.name = newName;
- this.elemType = previous.ae.elemType;
- this.previous = previous;
- }
-
- public IntegerExpression __length() {
- return length;
- }
-
- public String getElemType() {
- return elemType;
- }
-
- public String solution() {
- return solution;
- }
-
- public String stringPC() {
- return (name != null) ? name : "ARRAY_" + hashCode();
- }
-
- public void accept(ConstraintExpressionVisitor visitor) {
- visitor.preVisit(this);
- visitor.postVisit(this);
- }
-
- public void getVarsVals(Map varsVals) {
- varsVals.put(name, solution);
- }
-}
-
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousIntegerArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousIntegerArray.java
deleted file mode 100644
index 49538a7..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousIntegerArray.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-
-public class PreviousIntegerArray {
- IntegerSymbolicArray ae;
- IntegerExpression index;
- IntegerExpression value;
-
- public PreviousIntegerArray(IntegerSymbolicArray ae, IntegerExpression index, IntegerExpression value) {
- this.ae = ae;
- this.index = index;
- this.value = value;
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousObjectArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousObjectArray.java
deleted file mode 100644
index 7d47524..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousObjectArray.java
+++ /dev/null
@@ -1,16 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import gov.nasa.jpf.symbc.arrays.ObjectSymbolicArray;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-
-public class PreviousObjectArray {
- ObjectSymbolicArray ae;
- IntegerExpression index;
- IntegerExpression value;
-
- public PreviousObjectArray(ObjectSymbolicArray ae, IntegerExpression index, IntegerExpression value) {
- this.ae = ae;
- this.index = index;
- this.value = value;
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousRealArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousRealArray.java
deleted file mode 100644
index b55f6bf..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/PreviousRealArray.java
+++ /dev/null
@@ -1,17 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import gov.nasa.jpf.symbc.arrays.RealSymbolicArray;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.RealExpression;
-
-public class PreviousRealArray {
- RealSymbolicArray ae;
- IntegerExpression index;
- RealExpression value;
-
- public PreviousRealArray(RealSymbolicArray ae, IntegerExpression index, RealExpression value) {
- this.ae = ae;
- this.index = index;
- this.value = value;
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealArrayConstraint.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealArrayConstraint.java
index 05fa0ab..c2a91bf 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealArrayConstraint.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealArrayConstraint.java
@@ -2,7 +2,6 @@
import gov.nasa.jpf.symbc.numeric.Constraint;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.RealExpression;
public class RealArrayConstraint extends Constraint {
@@ -14,18 +13,16 @@ public RealArrayConstraint(RealStoreExpression se, Comparator c, ArrayExpression
super(se, c, ae);
}
-
- @Override
public RealArrayConstraint not() {
try {
return new RealArrayConstraint((SelectExpression)super.getLeft(), getComparator().not(), (RealExpression)getRight());
} catch (Exception e) {
try {
return new RealArrayConstraint((RealStoreExpression)super.getLeft(), getComparator().not(), (ArrayExpression)getRight());
- }
- catch (Exception r) {
+ } catch (Exception r) {
throw new RuntimeException("ArrayConstraint is not select or store");
}
}
}
}
+
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealStoreExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealStoreExpression.java
index 5ef43fe..e653865 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealStoreExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealStoreExpression.java
@@ -1,40 +1,59 @@
-package gov.nasa.jpf.symbc.arrays;
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+//Copyright (C) 2005 United States Government as represented by the
+//Administrator of the National Aeronautics and Space Administration
+//(NASA). All Rights Reserved.
+//
+//This software is distributed under the NASA Open Source Agreement
+//(NOSA), version 1.3. The NOSA has been approved by the Open Source
+//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
+//directory tree for the complete NOSA document.
+//
+//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+
+package gov.nasa.jpf.symbc.arrays;
import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
+import gov.nasa.jpf.symbc.numeric.Expression;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.RealExpression;
-import gov.nasa.jpf.symbc.numeric.RealConstant;
-import gov.nasa.jpf.symbc.numeric.Expression;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import java.util.Map;
public class RealStoreExpression extends Expression {
- public ArrayExpression ae;
- public IntegerExpression index;
- public RealExpression value;
-
- public RealStoreExpression(ArrayExpression ae, IntegerExpression ie, RealExpression value) {
- this.ae = ae;
- this.index = ie;
- this.value = value;
- }
+ public ArrayExpression arrayExpression;
+ public IntegerExpression indexExpression;
- public RealStoreExpression(ArrayExpression ae, int index, RealExpression value) {
- this(ae, new IntegerConstant(index), value);
- }
-
- public RealStoreExpression(ArrayExpression ae, IntegerExpression ie, float value) {
- this(ae, ie, new RealConstant(value));
- }
-
- public RealStoreExpression(ArrayExpression ae, int index, float value) {
- this(ae, new IntegerConstant(index), new RealConstant(value));
- }
+ public RealExpression value;
- public int compareTo(Expression expr) {
- // unimplemented
- return 0;
+ public RealStoreExpression(ArrayExpression ae, IntegerExpression ie, RealExpression val) {
+ this.arrayExpression = ae;
+ this.indexExpression = ie;
+ this.value = val;
}
public void accept(ConstraintExpressionVisitor visitor) {
@@ -47,7 +66,15 @@ public void getVarsVals(Map varsVals) {
}
public String stringPC() {
- return ("store "+ae.stringPC() + " " + index.stringPC() + " " + value.stringPC());
+ return arrayExpression.stringPC() + "[" + indexExpression.stringPC() + "] <- " + value.stringPC();
+ }
+
+ public int compareTo(Expression expr) {
+ // unimplemented
+ return 0;
}
+ public String toString() {
+ return this.stringPC();
+ }
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealSymbolicArray.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealSymbolicArray.java
deleted file mode 100644
index 0053b6a..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/RealSymbolicArray.java
+++ /dev/null
@@ -1,91 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import java.util.HashMap;
-import java.util.Map;
-
-import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
-import gov.nasa.jpf.symbc.numeric.RealConstant;
-import gov.nasa.jpf.symbc.arrays.PreviousIntegerArray;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.RealExpression;
-
-
-public class RealSymbolicArray extends ArrayExpression {
- private String name;
- public String solution = "UNDEFINED";
- // Indicates the previous ArrayExpression, as well as the index and value
- // when we store something in the array
- public PreviousRealArray previous = null;
- public Map realValAt = null;
-
-
- public RealSymbolicArray(int size) {
- super();
- this.length = new IntegerConstant(size);
- }
-
- public RealSymbolicArray(int n, String name) {
- super();
- this.name = name;
- this.length = new IntegerConstant(n);
- }
-
- public RealSymbolicArray(IntegerExpression n, String name) {
- super();
- this.name = name;
- this.length = n;
- }
-
- public RealSymbolicArray(PreviousRealArray previous) {
- super();
- this.length = previous.ae.length;
- String newName = previous.ae.name;
- if (newName.indexOf("!") == -1) {
- newName = newName+ "!1";
- } else {
- int aux = Integer.parseInt(newName.substring(newName.indexOf("!") + 1));
- newName = newName.substring(0, newName.indexOf("!") +1) + (aux + 1);
- }
- this.name = newName;
- this.previous = previous;
- }
-
-
- public IntegerExpression __length() {
- return length;
- }
-
- public String getName() {
- return (name!=null) ? name : "ARRAY_" + hashCode();
- }
-
- public String solution() {
- return solution;
- }
-
- public String stringPC() {
- return (name != null) ? name : "ARRAY_" + hashCode();
- }
-
- public void accept(ConstraintExpressionVisitor visitor) {
- visitor.preVisit(this);
- visitor.postVisit(this);
- }
-
- public void getVarsVals(Map varsVals) {
- varsVals.put(name, solution);
- }
-
- public SymbolicRealValueAtIndex getRealVal(IntegerExpression index) {
- if (realValAt == null) {
- realValAt = new HashMap();
- }
- SymbolicRealValueAtIndex result = realValAt.get(index.toString());
- if (result == null) {
- result = new SymbolicRealValueAtIndex(this, index);
- realValAt.put(index.toString(), result);
- }
- return result;
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SelectExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SelectExpression.java
index 5e5860e..113e1cf 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SelectExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SelectExpression.java
@@ -1,29 +1,55 @@
-package gov.nasa.jpf.symbc.arrays;
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+//Copyright (C) 2005 United States Government as represented by the
+//Administrator of the National Aeronautics and Space Administration
+//(NASA). All Rights Reserved.
+//
+//This software is distributed under the NASA Open Source Agreement
+//(NOSA), version 1.3. The NOSA has been approved by the Open Source
+//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
+//directory tree for the complete NOSA document.
+//
+//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+
+package gov.nasa.jpf.symbc.arrays;
import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.Expression;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
+import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import java.util.Map;
public class SelectExpression extends Expression {
- public ArrayExpression ae;
- public IntegerExpression index;
+ public ArrayExpression arrayExpression;
+ public IntegerExpression indexExpression;
public SelectExpression(ArrayExpression ae, IntegerExpression ie) {
- this.ae = ae;
- this.index = ie;
- }
-
- public SelectExpression(ArrayExpression ae, int index) {
- this.ae = ae;
- this.index = new IntegerConstant(index);
- }
-
- public int compareTo(Expression expr) {
- // unimplemented
- return 0;
+ this.arrayExpression = ae;
+ this.indexExpression = ie;
}
public void accept(ConstraintExpressionVisitor visitor) {
@@ -36,7 +62,15 @@ public void getVarsVals(Map varsVals) {
}
public String stringPC() {
- return ("select "+ae.stringPC() + " " + index.stringPC());
+ return arrayExpression.stringPC() + "[" + indexExpression.stringPC() + "]";
+ }
+
+ public int compareTo(Expression expr) {
+ // unimplemented
+ return 0;
}
+ public String toString() {
+ return this.stringPC();
+ }
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/StoreExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/StoreExpression.java
index 023a2ca..d9eb7a4 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/StoreExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/StoreExpression.java
@@ -1,38 +1,58 @@
-package gov.nasa.jpf.symbc.arrays;
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+//
+//Copyright (C) 2005 United States Government as represented by the
+//Administrator of the National Aeronautics and Space Administration
+//(NASA). All Rights Reserved.
+//
+//This software is distributed under the NASA Open Source Agreement
+//(NOSA), version 1.3. The NOSA has been approved by the Open Source
+//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
+//directory tree for the complete NOSA document.
+//
+//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+//
+
+package gov.nasa.jpf.symbc.arrays;
import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.Expression;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
+import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import java.util.Map;
public class StoreExpression extends Expression {
- public ArrayExpression ae;
- public IntegerExpression index;
- public IntegerExpression value;
-
- public StoreExpression(ArrayExpression ae, IntegerExpression ie, IntegerExpression value) {
- this.ae = ae;
- this.index = ie;
- this.value = value;
- }
+ public ArrayExpression arrayExpression;
+ public IntegerExpression indexExpression;
- public StoreExpression(ArrayExpression ae, int index, IntegerExpression value) {
- this(ae, new IntegerConstant(index), value);
- }
-
- public StoreExpression(ArrayExpression ae, IntegerExpression ie, int value) {
- this(ae, ie, new IntegerConstant(value));
- }
-
- public StoreExpression(ArrayExpression ae, int index, int value) {
- this(ae, new IntegerConstant(index), new IntegerConstant(value));
- }
+ public IntegerExpression value;
- public int compareTo(Expression expr) {
- // unimplemented
- return 0;
+ public StoreExpression(ArrayExpression ae, IntegerExpression ie, IntegerExpression val) {
+ this.arrayExpression = ae;
+ this.indexExpression = ie;
+ this.value = val;
}
public void accept(ConstraintExpressionVisitor visitor) {
@@ -45,7 +65,15 @@ public void getVarsVals(Map varsVals) {
}
public String stringPC() {
- return ("store "+ae.stringPC() + " " + index.stringPC() + " " + value.stringPC());
+ return arrayExpression.stringPC() + "[" + indexExpression.stringPC() + "] <- " + value.stringPC();
+ }
+
+ public int compareTo(Expression expr) {
+ // unimplemented
+ return 0;
}
+ public String toString() {
+ return this.stringPC();
+ }
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicIntegerValueAtIndex.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicIntegerValueAtIndex.java
deleted file mode 100644
index d8cc427..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicIntegerValueAtIndex.java
+++ /dev/null
@@ -1,39 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.SymbolicInteger;
-
-public class SymbolicIntegerValueAtIndex {
- public ArrayExpression ae;
- public IntegerExpression index;
- public IntegerExpression value;
-
- public SymbolicIntegerValueAtIndex(ArrayExpression ae, IntegerExpression index) {
- IntegerExpression value = new SymbolicInteger("ValueAt("+index.toString()+")");
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
-
- public SymbolicIntegerValueAtIndex(ArrayExpression ae, IntegerExpression index, IntegerExpression value) {
- this.ae = ae;
- this.index = index;
- this.value = value;
- }
-
- public SymbolicIntegerValueAtIndex(ArrayExpression ae, IntegerExpression index, boolean isBool) {
- if (isBool) {
- IntegerExpression value = new SymbolicInteger("ValueAt("+index.toString()+")", 0, 1);
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
- else {
- IntegerExpression value = new SymbolicInteger("ValueAt("+index.toString()+")");
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicRealValueAtIndex.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicRealValueAtIndex.java
deleted file mode 100644
index 605880f..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/arrays/SymbolicRealValueAtIndex.java
+++ /dev/null
@@ -1,40 +0,0 @@
-package gov.nasa.jpf.symbc.arrays;
-
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.RealExpression;
-import gov.nasa.jpf.symbc.numeric.SymbolicReal;
-
-public class SymbolicRealValueAtIndex {
- public ArrayExpression ae;
- public IntegerExpression index;
- public RealExpression value;
-
- public SymbolicRealValueAtIndex(ArrayExpression ae, IntegerExpression index) {
- RealExpression value = new SymbolicReal("ValueAt("+index.toString()+")");
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
-
- public SymbolicRealValueAtIndex(ArrayExpression ae, IntegerExpression index, RealExpression value) {
- this.ae = ae;
- this.index = index;
- this.value = value;
- }
-
- public SymbolicRealValueAtIndex(ArrayExpression ae, IntegerExpression index, boolean isBool) {
- if (isBool) {
- RealExpression value = new SymbolicReal("ValueAt("+index.toString()+")", 0, 1);
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
- else {
- RealExpression value = new SymbolicReal("ValueAt("+index.toString()+")");
- this.value = value;
- this.ae = ae;
- this.index = index;
- }
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/AALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/AALOAD.java
index 936877b..4a4a3c0 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/AALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/AALOAD.java
@@ -21,25 +21,15 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.ArrayHeapNode;
-import gov.nasa.jpf.symbc.arrays.HelperResult;
-import gov.nasa.jpf.symbc.arrays.ObjectSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
import gov.nasa.jpf.symbc.heap.HeapChoiceGenerator;
-import gov.nasa.jpf.symbc.heap.HeapNode;
-import gov.nasa.jpf.symbc.heap.Helper;
import gov.nasa.jpf.symbc.heap.SymbolicInputHeap;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayFields;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
import gov.nasa.jpf.vm.ChoiceGenerator;
-import gov.nasa.jpf.vm.ClassInfo;
-import gov.nasa.jpf.vm.ClassLoaderInfo;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -56,267 +46,117 @@ public class AALOAD extends gov.nasa.jpf.jvm.bytecode.AALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- boolean abstractClass = false;
- ObjectSymbolicArray arrayAttr = null;
- ArrayHeapNode[] prevSymRefs = null; // previously initialized objects of same type
- int numSymRefs = 0; // number of previously initialized objects
- ChoiceGenerator> prevHeapCG = null;
- ChoiceGenerator> cg;
- int currentChoice;
- IntegerExpression indexAttr = null;
- StackFrame frame = ti.getModifiableTopFrame();
- arrayRef = frame.peek(1); // ..,arrayRef,idx
- if (peekArrayAttr(ti) == null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints about the elements of the array and perform the select
- // We will need to get information about the type of the elements as well
- // We need to add the information in PC after it is declared.
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(arrayInfo.arrayLength() + 2);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- currentChoice = (Integer)cg.getNextChoice();
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
-
- if (currentChoice < arrayInfo.arrayLength()) {
- // For each possible index, we check if the symbolic index can be equal to it. If so, we return the value at this index
-
- pc._addDet(Comparator.EQ, indexAttr, new IntegerConstant(currentChoice));
- if (pc.simplify()) { // satisfiable
- frame.pop(2);
- arrayInfo.checkArrayBounds(currentChoice); // should not fail
- int value = arrayInfo.getReferenceElement(currentChoice);
- frame.pushRef(value);
- Object elementAttr = arrayInfo.getElementAttr(currentChoice);
- if (elementAttr != null) {
- frame.setOperandAttr(elementAttr);
- }
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if (currentChoice == arrayInfo.arrayLength()) {
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(arrayInfo.arrayLength()));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if (currentChoice == arrayInfo.arrayLength() +1) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- throw new RuntimeException("We shouldn't end here in AALOAD");
- }
- } else {
- arrayAttr = (ObjectSymbolicArray)peekArrayAttr(ti);
- }
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
- String typeElemArray = arrayAttr.getElemType();
-
- if (typeElemArray.equals("?")) {
- throw new RuntimeException("Type of array elements unknown");
- }
-
- ClassInfo typeClassInfo = ClassLoaderInfo.getCurrentResolvedClassInfo(typeElemArray);
-
- ChoiceGenerator> thisHeapCG;
-
- if (!ti.isFirstStepInsn()) {
- // We add the HeapChoiceGenerator that will be required if we can load an element
- numSymRefs = 0;
- prevSymRefs = null;
- prevHeapCG = ti.getVM().getLastChoiceGeneratorOfType(HeapChoiceGenerator.class);
-
- if (prevHeapCG != null) {
- SymbolicInputHeap symInputHeap = ((HeapChoiceGenerator)prevHeapCG).getCurrentSymInputHeap();
- // We get only the previously initialized elements for this array
- prevSymRefs = symInputHeap.getArrayNodesOfType(typeClassInfo, arrayRef);
- numSymRefs = prevSymRefs.length;
- }
-
- int increment = 2;
- if (typeClassInfo.isAbstract()) {
- abstractClass =true;
- increment = 1;
- }
- thisHeapCG = new HeapChoiceGenerator(numSymRefs + increment);
- ti.getVM().setNextChoiceGenerator(thisHeapCG);
-
- // We now add the PCChoiceGenerator that will be used first to detemrine if we are in bounds
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
return this;
- } else {
- cg = ti.getVM().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
- thisHeapCG = ti.getVM().getLastChoiceGeneratorOfType(HeapChoiceGenerator.class);
- assert (thisHeapCG instanceof HeapChoiceGenerator) : "expected HeapChoiceGenerator, got: " + thisHeapCG;
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- currentChoice = (Integer)cg.getNextChoice();
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // The index is not symbolic
- index = frame.peek();
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
-
- if (currentChoice == 1) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if (currentChoice == 2) {
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- // TODO deal with actual load
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- PathCondition pcHeap;
- SymbolicInputHeap symInputHeap;
-
- prevHeapCG = thisHeapCG.getPreviousChoiceGeneratorOfType(HeapChoiceGenerator.class);
-
- if (prevHeapCG == null) {
- pcHeap = new PathCondition();
- symInputHeap = new SymbolicInputHeap();
- } else {
- pcHeap = ((HeapChoiceGenerator)prevHeapCG).getCurrentPCheap();
- symInputHeap = ((HeapChoiceGenerator) prevHeapCG).getCurrentSymInputHeap();
- }
-
- assert pcHeap != null;
- assert symInputHeap != null;
-
- SelectExpression se = null;
-
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case the index isn't symbolic
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
-
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
- int daIndex = 0; // index into JPF's dynamic area
- currentChoice = ((HeapChoiceGenerator) thisHeapCG).getNextChoice();
-
- if (currentChoice < numSymRefs) {
- // We load a previously initialized object
- ArrayHeapNode candidateNode = prevSymRefs[currentChoice];
- pc._addDet(Comparator.EQ, indexAttr, candidateNode.arrayIndex);
- if (pc.simplify()) {
- // The index is the same than the previous one
- pc._addDet(Comparator.EQ, se, candidateNode.getSymbolic());
- daIndex = candidateNode.getIndex();
- frame.pop(2); // We pop the array and the index
- frame.push(daIndex, true); // We have instantiated an object, and added the constraints in the PC
-
- ((HeapChoiceGenerator)thisHeapCG).setCurrentPCheap(pcHeap);
- ((HeapChoiceGenerator)thisHeapCG).setCurrentSymInputHeap(symInputHeap);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if (currentChoice == (numSymRefs)) { // null object
- if (pc.simplify()) { // satisfiable
- pcHeap._addDet(Comparator.EQ, se, new IntegerConstant(-1));
- daIndex = MJIEnv.NULL;
- frame.pop(2); // We pop the index and the array;
- frame.push(daIndex, true);
-
- ((HeapChoiceGenerator)thisHeapCG).setCurrentPCheap(pcHeap);
- ((HeapChoiceGenerator)thisHeapCG).setCurrentSymInputHeap(symInputHeap);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- if (pc.simplify()) { // satisfiable
- HelperResult hpResult = Helper.addNewArrayHeapNode(typeClassInfo, ti, arrayAttr, pcHeap, symInputHeap, numSymRefs, prevSymRefs, false, indexAttr, arrayRef);
- daIndex = hpResult.idx;
- HeapNode candidateNode = hpResult.n;
- // Since the object is different from all the previously initialized ones, we don't need to add constraints
- // on the index, it will be inferred from Z3 array theory
- pcHeap._addDet(Comparator.EQ, se, candidateNode.getSymbolic());
- frame.pop(2); // We pop the array and the index
- frame.push(daIndex, true);
- ((HeapChoiceGenerator) thisHeapCG).setCurrentPCheap(pcHeap);
- ((HeapChoiceGenerator) thisHeapCG).setCurrentSymInputHeap(symInputHeap);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
-
- if (peekArrayAttr(ti) == null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // The symbolic object was concretized during AALOAD or ALOAD, so nothing is symbolic here
- return super.execute(ti);
- } else {
- // The array is not symbolic, but the index is.
- // We try to store the object in each possible slot
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(arrayInfo.arrayLength() +2);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- indexAttr = (IntegerExpression) peekIndexAttr(ti); // We know that the index is here symbolic
-
- assert (indexAttr != null) : "indexAttr shouldn't be null in AASTORE instruction";
-
- int currentChoice = (Integer)cg.getNextChoice();
-
- if (currentChoice < arrayInfo.arrayLength()) {
- pc._addDet(Comparator.EQ, indexAttr, new IntegerConstant(currentChoice));
- if (pc.simplify()) { // We can store at this index
- int value = frame.peek();
- arrayRef = frame.peek(2);
- ElementInfo eiArray = ti.getModifiableElementInfo(arrayRef);
- eiArray.setReferenceElement(currentChoice, value);
-
- frame.pop(3);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if (currentChoice == arrayInfo.arrayLength()) {
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(arrayInfo.arrayLength()));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) {
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
- }
-
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in AASTORE instruction";
-
- if (peekArrayAttr(ti) == null || !(peekArrayAttr(ti) instanceof ObjectSymbolicArray)) {
- // In this case the array isn't symbolic, and we checked earlier that the index was symbolic
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- // We need to add information about the type of the elements in the array as well
- arrayAttr = new ObjectSymbolicArray(arrayInfo.arrayLength());
- // We should add the constraints about the elements of the array here
- // TODO
- throw new RuntimeException("constant object array with symbolic index not implemented");
- } else {
- arrayAttr = (ObjectSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in AASTORE instruction";
-
- if (arrayRef == MJIEnv.NULL) {
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ALOAD.java
index 2daf300..1a2ce49 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ALOAD.java
@@ -19,8 +19,8 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.Config;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
+import gov.nasa.jpf.symbc.arrays.ArrayExpression;
import gov.nasa.jpf.symbc.heap.HeapChoiceGenerator;
import gov.nasa.jpf.symbc.heap.HeapNode;
import gov.nasa.jpf.symbc.heap.Helper;
@@ -38,7 +38,6 @@
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.KernelState;
-import gov.nasa.jpf.vm.MJIEnv;
import gov.nasa.jpf.vm.StackFrame;
import gov.nasa.jpf.vm.SystemState;
//import gov.nasa.jpf.symbc.uberlazy.TypeHierarchy;
@@ -58,7 +57,6 @@ public ALOAD(int localVarIndex) {
@Override
public Instruction execute (ThreadInfo th) {
-
HeapNode[] prevSymRefs = null; // previously initialized objects of same type: candidates for lazy init
int numSymRefs = 0; // # of prev. initialized objects
ChoiceGenerator> prevHeapCG = null;
@@ -70,6 +68,7 @@ public Instruction execute (ThreadInfo th) {
// TODO: fix handle polymorphism
+
StackFrame sf = th.getModifiableTopFrame();
int objRef = sf.peek();
ElementInfo ei = th.getElementInfo(objRef);
@@ -154,7 +153,7 @@ public Instruction execute (ThreadInfo th) {
}
else if (currentChoice == numSymRefs && !(((IntegerExpression)attr).toString()).contains("this")){ //null object
pcHeap._addDet(Comparator.EQ, (SymbolicInteger) attr, new IntegerConstant(-1));
- daIndex = MJIEnv.NULL;
+ daIndex = -1;
}
else if ((currentChoice == (numSymRefs + 1) && !abstractClass) | (currentChoice == numSymRefs && (((IntegerExpression)attr).toString()).contains("this"))) {
//creates a new object with all fields symbolic
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ARRAYLENGTH.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ARRAYLENGTH.java
deleted file mode 100644
index ad5f79d..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ARRAYLENGTH.java
+++ /dev/null
@@ -1,52 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package gov.nasa.jpf.symbc.bytecode;
-
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.numeric.*;
-import gov.nasa.jpf.vm.ChoiceGenerator;
-import gov.nasa.jpf.vm.Instruction;
-import gov.nasa.jpf.vm.StackFrame;
-import gov.nasa.jpf.vm.ThreadInfo;
-
-public class ARRAYLENGTH extends gov.nasa.jpf.jvm.bytecode.ARRAYLENGTH {
-
- public Object peekArrayAttr(ThreadInfo ti) {
- return ti.getTopFrame().getOperandAttr(0);
- }
-
- @Override
- public Instruction execute (ThreadInfo th) {
- StackFrame frame = th.getModifiableTopFrame();
-
- if (peekArrayAttr(th) == null || !(peekArrayAttr(th) instanceof ArrayExpression)) {
- return super.execute(th);
- }
-
- ArrayExpression arrayAttr = (ArrayExpression)peekArrayAttr(th);
- frame.pop(1); // We pop the array
- frame.push(0, false); // The concrete value does not matter
- frame.setOperandAttr(arrayAttr.length);
-
- return getNext(th);
- }
-}
-
-
-
-
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BALOAD.java
index b6bb2df..5b404cd 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BALOAD.java
@@ -23,17 +23,11 @@
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -49,124 +43,117 @@ public class BALOAD extends gov.nasa.jpf.jvm.bytecode.BALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- IntegerSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
- StackFrame frame = ti.getModifiableTopFrame();
- arrayRef = frame.peek(1); // ..., arrayRef, idx
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints about the elements of the array, and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- byte arrValue = arrayInfo.getByteElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
-
- else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
-
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
-
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
-
- if ((Integer)cg.getNextChoice()==1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice()==2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { //satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
- // We update the Symbolic Array with the get information
- SymbolicIntegerValueAtIndex result = arrayAttr.getBoolVal(indexAttr);
- frame.pop(2); // We pop the array and the index
- frame.push(0, false);
- frame.setOperandAttr(result.value);
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-}
+
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ //System.out.println("array index "+index);
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in IASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- byte arrValue = arrayInfo.getByteElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in IASTORE instruction";
-
- if (arrayRef == MJIEnv.NULL) {
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
+
+
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
-
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- IntegerExpression sym_value = null;
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- int value = frame.pop();
- sym_value = new IntegerConstant(value);
- }
- else {
- // The value is symbolic.
- sym_value = (IntegerExpression)frame.getOperandAttr(0);
- frame.pop();
- }
- PreviousIntegerArray previous = new PreviousIntegerArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- IntegerSymbolicArray newArrayAttr = new IntegerSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
-
- StoreExpression se = new StoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BytecodeUtils.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BytecodeUtils.java
index 83f3ef0..9010859 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BytecodeUtils.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/BytecodeUtils.java
@@ -21,13 +21,14 @@
import gov.nasa.jpf.Config;
-
import gov.nasa.jpf.jvm.bytecode.JVMInvokeInstruction;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.ObjectSymbolicArray;
+import gov.nasa.jpf.symbc.arrays.ArrayExpression;
import gov.nasa.jpf.symbc.heap.Helper;
+import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.Expression;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
+import gov.nasa.jpf.symbc.numeric.MinMax;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.symbc.numeric.PreCondition;
@@ -44,10 +45,11 @@
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.LocalVarInfo;
import gov.nasa.jpf.vm.MethodInfo;
+import gov.nasa.jpf.vm.MJIEnv;
import gov.nasa.jpf.vm.StackFrame;
import gov.nasa.jpf.vm.SystemState;
import gov.nasa.jpf.vm.ThreadInfo;
-
+
import java.util.Arrays;
import java.util.HashMap;
import java.util.Iterator;
@@ -210,14 +212,19 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
Vector args = new Vector();
Config conf = th.getVM().getConfig();
-
- // Start string handling
+
+ // Start string handling: TODO corina it needs reviewing as it does not seem to be correct
/**** This is where we branch off to handle symbolic string variables *******/
- SymbolicStringHandler a = new SymbolicStringHandler();
- Instruction handled = a.handleSymbolicStrings(invInst, th);
- if(handled != null){ // go to next instruction as symbolic string operation was done
- System.out.println("Symbolic string analysis");
+ String[] symstrings = conf.getStringArray("symbolic.strings");
+ boolean symstrings_flag = (symstrings != null && symstrings[0].equalsIgnoreCase("true"))? true : false;
+ if(symstrings_flag) {
+
+ SymbolicStringHandler a = new SymbolicStringHandler();
+ Instruction handled = a.handleSymbolicStrings(invInst, th);
+ if(handled != null){ // go to next instruction as symbolic string operation was done
+// System.out.println("Symbolic string analysis!!!"+invInst);
return new InstructionOrSuper(false, handled);
+ }
}
// End string handling
@@ -231,7 +238,6 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
// create a choice generator to associate the precondition with it
ChoiceGenerator> cg = null;
- if (invInst.getInvokedMethod().getAnnotation("gov.nasa.jpf.symbc.Preconditions") != null) {
if (!th.isFirstStepInsn()) { // first time around
cg = new PCChoiceGenerator(1);
th.getVM().setNextChoiceGenerator(cg);
@@ -241,7 +247,6 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
if (!(cg instanceof PCChoiceGenerator)) // the choice comes from super
return new InstructionOrSuper(true, null);
}
- }
String outputString = "\n***Execute symbolic " + bytecodeName + ": " + mname + " (";
@@ -270,6 +275,11 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
// special treatment of "this"
String lazy[] = conf.getStringArray("symbolic.lazy");
+ String symarrays[] = conf.getStringArray("symbolic.arrays");
+ boolean symarray = false;
+ if (symarrays != null) {
+ symarray = symarrays[0].equalsIgnoreCase("true");
+ }
//TODO: to review
// if(lazy != null) {
// if(lazy[0].equalsIgnoreCase("true")) {
@@ -286,13 +296,38 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
for (int j = 0; j < argSize; j++) { // j ranges over actual arguments
if (symClass || args.get(j).equalsIgnoreCase("SYM")) {
String name = argsInfo[localVarsIdx].getName();
- if (argTypes[j].equalsIgnoreCase("int") || argTypes[j].equalsIgnoreCase("long")) {
+ if (argTypes[j].equalsIgnoreCase("int")) {
IntegerExpression sym_v = new SymbolicInteger(varName(name, VarType.INT));
expressionMap.put(name, sym_v);
sf.setOperandAttr(stackIdx, sym_v);
- outputString = outputString.concat(" " + sym_v + ",");
+ outputString = outputString.concat(" " + sym_v + ",");
+ } else if (argTypes[j].equalsIgnoreCase("long")) {
+ String varname = varName(name, VarType.INT);
+ IntegerExpression sym_v = new SymbolicInteger(varname, MinMax.getVarMinLong(varname), MinMax.getVarMaxLong(varname));
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ } else if (argTypes[j].equalsIgnoreCase("short")) {
+ String varname = varName(name, VarType.INT);
+ IntegerExpression sym_v = new SymbolicInteger(varname, MinMax.getVarMinShort(varname), MinMax.getVarMaxShort(varname));
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ } else if (argTypes[j].equalsIgnoreCase("byte")) {
+ String varname = varName(name, VarType.INT);
+ IntegerExpression sym_v = new SymbolicInteger(varname, MinMax.getVarMinByte(varname), MinMax.getVarMaxByte(varname));
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ } else if (argTypes[j].equalsIgnoreCase("char")) {
+ String varname = varName(name, VarType.INT);
+ IntegerExpression sym_v = new SymbolicInteger(varname, MinMax.getVarMinChar(varname), MinMax.getVarMaxChar(varname));
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
} else if (argTypes[j].equalsIgnoreCase("float") || argTypes[j].equalsIgnoreCase("double")) {
- RealExpression sym_v = new SymbolicReal(varName(name, VarType.REAL));
+ String varname = varName(name, VarType.REAL);
+ RealExpression sym_v = new SymbolicReal(varname, MinMax.getVarMinDouble(varname), MinMax.getVarMaxDouble(varname));
expressionMap.put(name, sym_v);
sf.setOperandAttr(stackIdx, sym_v);
outputString = outputString.concat(" " + sym_v + ",");
@@ -307,45 +342,117 @@ public static InstructionOrSuper execute(JVMInvokeInstruction invInst, ThreadInf
expressionMap.put(name, sym_v);
sf.setOperandAttr(stackIdx, sym_v);
outputString = outputString.concat(" " + sym_v + ",");
- } else if(argTypes[j].equalsIgnoreCase("int[]") || argTypes[j].equalsIgnoreCase("long[]")){
- Object[] argValues = invInst.getArgumentValues(th);
- ElementInfo eiArray = (ElementInfo)argValues[j];
-
- IntegerSymbolicArray sym_v = new IntegerSymbolicArray(new SymbolicInteger(name + "!length"), varName(name, VarType.ARRAY));
- expressionMap.put(name, sym_v);
- sf.setOperandAttr(stackIdx, sym_v);
- outputString = outputString.concat(" " + sym_v + ",");
+ } else if(argTypes[j].equalsIgnoreCase("int[]") || argTypes[j].equalsIgnoreCase("long[]") || argTypes[j].equalsIgnoreCase("byte[]")){
+ if (symarray) {
+ ArrayExpression sym_v = new ArrayExpression(name);
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ PCChoiceGenerator prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+ PathCondition pc;
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+ pc._addDet(Comparator.GE, sym_v.length, new IntegerConstant(0));
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ } else {
+ Object[] argValues = invInst.getArgumentValues(th);
+ ElementInfo eiArray = (ElementInfo)argValues[j];
+
+ if(eiArray!=null)
+ for(int i =0; i< eiArray.arrayLength(); i++) {
+ IntegerExpression sym_v = new SymbolicInteger(varName(name+i, VarType.INT));
+ expressionMap.put(name+i, sym_v);
+ eiArray.addElementAttr(i, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ }
+ else
+ System.out.println("Warning: input array empty! "+name);
+ }
} else if(argTypes[j].equalsIgnoreCase("float[]") || argTypes[j].equalsIgnoreCase("double[]")){
- Object[] argValues = invInst.getArgumentValues(th);
- ElementInfo eiArray = (ElementInfo)argValues[j];
-
- for(int i =0; i< eiArray.arrayLength(); i++) {
- RealExpression sym_v = new SymbolicReal(varName(name+i, VarType.REAL));
- expressionMap.put(name+i, sym_v);
- eiArray.addElementAttr(i, sym_v);
- outputString = outputString.concat(" " + sym_v + ",");
- }
+ if (symarray) {
+ ArrayExpression sym_v = new ArrayExpression(name);
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+
+
PCChoiceGenerator prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+ PathCondition pc;
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ pc._addDet(Comparator.GE, sym_v.length, new IntegerConstant(0));
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ } else {
+ Object[] argValues = invInst.getArgumentValues(th);
+ ElementInfo eiArray = (ElementInfo)argValues[j];
+
+ if(eiArray!=null)
+ for(int i =0; i< eiArray.arrayLength(); i++) {
+ RealExpression sym_v = new SymbolicReal(varName(name+i, VarType.REAL));
+ expressionMap.put(name+i, sym_v);
+ eiArray.addElementAttr(i, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ }
+ else
+ System.out.println("Warning: input array empty! "+name);
+ }
} else if(argTypes[j].equalsIgnoreCase("boolean[]")){
- Object[] argValues = invInst.getArgumentValues(th);
- ElementInfo eiArray = (ElementInfo)argValues[j];
-
- IntegerSymbolicArray sym_v = new IntegerSymbolicArray(new SymbolicInteger(name + "!length"), varName(name, VarType.ARRAY));
- expressionMap.put(name, sym_v);
- sf.setOperandAttr(stackIdx, sym_v);
- outputString = outputString.concat(" " + sym_v + ",");
+ if (symarray) {
+ ArrayExpression sym_v = new ArrayExpression(name);
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+
+
PCChoiceGenerator prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+ PathCondition pc;
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+ pc._addDet(Comparator.GE, sym_v.length, new IntegerConstant(0));
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ } else {
+ Object[] argValues = invInst.getArgumentValues(th);
+ ElementInfo eiArray = (ElementInfo)argValues[j];
+
+ if(eiArray!=null)
+ for(int i =0; i< eiArray.arrayLength(); i++) {
+ IntegerExpression sym_v = new SymbolicInteger(varName(name+i, VarType.INT),0,1);
+ expressionMap.put(name+i, sym_v);
+ eiArray.addElementAttr(i, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
+ }
+ else
+ System.out.println("Warning: input array empty! "+name);
+ }
} else if (argTypes[j].contains("[]")) {
- // If the type name contains [] but wasn't catched previously, then it is an object array
- Object[] argValues = invInst.getArgumentValues(th);
- ElementInfo eiArray = (ElementInfo)argValues[j];
+ if (symarray) {
+ Object[] argValues = invInst.getArgumentValues(th);
+ ElementInfo eiArray = (ElementInfo)argValues[j];
+ // If the type name contains [] but wasn't catched previously, it is an object array
+ ArrayExpression sym_v = new ArrayExpression(name, argTypes[j].substring(0, argTypes[j].length() - 2));
+ // We remove the [] at the end of the type to keep only the type of the object
+ expressionMap.put(name, sym_v);
+ sf.setOperandAttr(stackIdx, sym_v);
+ outputString = outputString.concat(" " + sym_v + ",");
- ObjectSymbolicArray sym_v = new ObjectSymbolicArray(new SymbolicInteger(name + "!length"), varName(name, VarType.ARRAY), argTypes[j]);
- expressionMap.put(name, sym_v);
- sf.setOperandAttr(stackIdx, sym_v);
- outputString = outputString.concat(" " + sym_v + ",");
-
+
PCChoiceGenerator prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+ PathCondition pc;
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ pc._addDet(Comparator.GE, sym_v.length, new IntegerConstant(0));
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ }
} else {
// the argument is of reference type and it is symbolic
if(lazy != null) {
@@ -399,7 +506,7 @@ else if (s.equalsIgnoreCase("static"))
ei = th.getElementInfo(ci.getClassObjectRef());
} else {
int objRef = th.getCalleeThis(invInst.getArgSize());
- if (objRef == -1) { // NPE
+ if (objRef == MJIEnv.NULL) { // NPE
return new InstructionOrSuper(false,
th.createAndThrowException("java.lang.NullPointerException", "calling '" + mname
+ "' on null object"));
@@ -538,7 +645,7 @@ public static void clearSymVarCounter() {
}
public enum VarType {
- INT, REAL, REF, STRING, ARRAY
+ INT, REAL, REF, STRING
};
@@ -557,9 +664,6 @@ public static String varName(String name, VarType type) {
case STRING:
suffix = "_SYMSTRING";
break;
- case ARRAY:
- suffix = "_SYMARRAY";
- break;
default:
throw new RuntimeException("Unhandled SymVarType: " + type);
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/CALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/CALOAD.java
index e5af0c1..53f300f 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/CALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/CALOAD.java
@@ -21,18 +21,12 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -49,115 +43,115 @@ public class CALOAD extends gov.nasa.jpf.jvm.bytecode.CALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- IntegerSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
- StackFrame frame = ti.getModifiableTopFrame();
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti) == null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getCharElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
-
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ //System.out.println("array index "+index);
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ assert pc != null;
- // Set the result
- // We update the Symbolic Array with the get information
- SymbolicIntegerValueAtIndex result = arrayAttr.getVal(indexAttr);
- // We had a concrete array, and don't know yet where it is from
- frame.pop(2); // We pop the array and the index
- frame.push(0, false);
- frame.setOperandAttr(result.value);
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+ if(index cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in IASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getCharElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in IASTORE instruction";
-
- if (arrayRef == MJIEnv.NULL) {
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
-
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
-
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- IntegerExpression sym_value = null;
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- int value = frame.pop();
- sym_value = new IntegerConstant(value);
- }
- else {
- // The value is symbolic.
- sym_value = (IntegerExpression)frame.getOperandAttr(0);
- frame.pop();
- }
- PreviousIntegerArray previous = new PreviousIntegerArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- IntegerSymbolicArray newArrayAttr = new IntegerSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
-
- StoreExpression se = new StoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
+
+
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DALOAD.java
index 0773bd4..14e8f41 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DALOAD.java
@@ -40,8 +40,6 @@ public class DALOAD extends gov.nasa.jpf.jvm.bytecode.DALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- // This instruction is not yet implemented, Z3 does not support floats
if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
return super.execute(ti);
StackFrame frame = ti.getModifiableTopFrame();
@@ -49,7 +47,109 @@ public Instruction execute (ThreadInfo ti) {
if (arrayRef == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
- throw new RuntimeException("Symbolic float Arrays not handled");
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ //System.out.println("array index "+index);
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
}
-}
+}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPG.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPG.java
index 0733759..d9b7d13 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPG.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPG.java
@@ -18,7 +18,6 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
@@ -41,15 +40,89 @@ public Instruction execute(ThreadInfo th) {
if (sym_v1 == null && sym_v2 == null) { // both conditions are concrete
return super.execute(th);
} else { // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoiceDouble(th,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.EQ,
- Comparator.GT);
-
- return nxtInstr;
+ ChoiceGenerator cg;
+ int conditionValue;
+
+ if (!th.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(3);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ th.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ ChoiceGenerator> curCg = th.getVM().getSystemState().getChoiceGenerator();
+ assert (curCg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + curCg;
+ cg = (PCChoiceGenerator)curCg;
+ conditionValue = cg.getNextChoice().intValue() -1;
+ }
+
+ double v1 = Types.longToDouble(sf.popLong());
+ double v2 = Types.longToDouble(sf.popLong());
+ //System.out.println("Execute DCMPG: " + conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator) prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue == -1) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.LT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else if (conditionValue == 0) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.EQ, sym_v1, sym_v2);
+ } else
+ pc._addDet(Comparator.EQ, sym_v1, v2);
+ } else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.GT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ }
+ sf.push(conditionValue, false);
+ return getNext(th);
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPL.java
index 815551d..8fd636c 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/DCMPL.java
@@ -18,7 +18,6 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
@@ -40,15 +39,91 @@ public Instruction execute(ThreadInfo th) {
if (sym_v1 == null && sym_v2 == null) { // both conditions are concrete
return super.execute(th);
} else { // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoiceDouble(th,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.EQ,
- Comparator.GT);
-
- return nxtInstr;
+ ChoiceGenerator cg;
+ int conditionValue;
+
+ if (!th.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(3);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ th.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ ChoiceGenerator> curCg = th.getVM().getSystemState().getChoiceGenerator();
+ assert (curCg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + curCg;
+ cg = (PCChoiceGenerator)curCg;
+ conditionValue = cg.getNextChoice().intValue() -1;
+ }
+
+ double v1 = Types.longToDouble(sf.popLong());
+ double v2 = Types.longToDouble(sf.popLong());
+ //System.out.println("Execute DCMPL: " + conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator) prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+
+
+ if (conditionValue == -1) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.LT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else if (conditionValue == 0) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.EQ, sym_v1, sym_v2);
+ } else
+ pc._addDet(Comparator.EQ, sym_v1, v2);
+ } else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.GT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ }
+ sf.push(conditionValue, false);
+ return getNext(th);
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FALOAD.java
index 32c16e7..8743483 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FALOAD.java
@@ -21,19 +21,11 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.RealSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicRealValueAtIndex;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.RealConstant;
-import gov.nasa.jpf.symbc.numeric.RealExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -49,127 +41,116 @@ public class FALOAD extends gov.nasa.jpf.jvm.bytecode.FALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
- // This instruction is not implemented for the moment, because of Z3 not supporting floats.
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- RealSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints about the elements of the array, and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new RealSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- float arrValue = arrayInfo.getFloatElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new RealConstant(arrValue));
- }
- }
-
- else {
- arrayAttr = (RealSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
- StackFrame frame = ti.getModifiableTopFrame();
- arrayRef = frame.peek(1); // ..., arrayRef, idx
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
-
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
-
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
-
- if ((Integer)cg.getNextChoice()==1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice()==2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { //satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
- // We update the Symbolic Array with the get information
- SymbolicRealValueAtIndex result = arrayAttr.getRealVal(indexAttr);
- frame.pop(2); // We pop the array and the index
- frame.push(0, false); // For symbolic expressions, the concrete value does not matter
- frame.setOperandAttr(result.value);
- // We add the select instruction in the PathCondition
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ //System.out.println("array index "+index);
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index cg;
- boolean condition;
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in FASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof RealExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new RealSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- float arrValue = arrayInfo.getFloatElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new RealConstant(arrValue));
- }
- }
- } else {
- arrayAttr = (RealSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in FASTORE instruction";
-
-
- int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
-
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
-
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- RealExpression sym_value = null;
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof RealExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- float value = frame.pop();
- sym_value = new RealConstant(value);
- }
- else {
- // The value is symbolic.
- sym_value = (RealExpression)frame.getOperandAttr(0);
- frame.pop();
- }
- PreviousRealArray previous = new PreviousRealArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- RealSymbolicArray newArrayAttr = new RealSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
-
- RealStoreExpression se = new RealStoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
+
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPG.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPG.java
index 59cf0fa..2a21752 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPG.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPG.java
@@ -17,7 +17,6 @@
*/
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
@@ -43,15 +42,78 @@ public Instruction execute(ThreadInfo th) {
if (sym_v1 == null && sym_v2 == null) { // both conditions are concrete
return super.execute( th);
} else { // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoiceFloat(th,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.EQ,
- Comparator.GT);
-
- return nxtInstr;
+ ChoiceGenerator> cg;
+ int conditionValue;
+
+ if (!th.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(3);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ th.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = th.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = ((PCChoiceGenerator) cg).getNextChoice() - 1;
+ }
+
+ float v1 = Types.intToFloat(sf.pop());
+ float v2 = Types.intToFloat(sf.pop());
+
+ PathCondition pc;
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator) prev_cg).getCurrentPC();
+ assert pc != null;
+
+ if (conditionValue == -1) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.LT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, sym_v2, v1);
+
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ }
+ } else if (conditionValue == 0) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.EQ, sym_v1, sym_v2);
+ } else
+ pc._addDet(Comparator.EQ, sym_v1, v2);
+ } else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ }
+ } else { // 1
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.GT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ }
+ }
+
+ sf.push(conditionValue, false);
+ return getNext(th);
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPL.java
index b440eac..72f7de7 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/FCMPL.java
@@ -18,7 +18,6 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
@@ -44,16 +43,90 @@ public Instruction execute(ThreadInfo th) {
if (sym_v1 == null && sym_v2 == null) { // both conditions are concrete
return super.execute(th);
} else { // at least one condition is symbolic
-
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoiceFloat(th,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.EQ,
- Comparator.GT);
-
- return nxtInstr;
+ ChoiceGenerator> cg;
+ int conditionValue;
+
+ if (!th.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(3);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ th.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = th.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = ((PCChoiceGenerator) cg).getNextChoice() -1;
+ }
+
+ float v1 = Types.intToFloat(sf.pop());
+ float v2 = Types.intToFloat(sf.pop());
+
+ // System.out.println("Execute FCMPL: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above get
+ // the path condition from the previous CG of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator) prev_cg).getCurrentPC();
+ assert pc != null;
+
+ if (conditionValue == -1) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.LT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.LT, sym_v2, v1);
+
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else if (conditionValue == 0) {
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.EQ, sym_v1, sym_v2);
+ } else
+ pc._addDet(Comparator.EQ, sym_v1, v2);
+ } else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ } else { // 1
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ pc._addDet(Comparator.GT, sym_v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, v2, sym_v1);
+ } else
+ pc._addDet(Comparator.GT, sym_v2, v1);
+ if (!pc.simplify()) {// not satisfiable
+ th.getVM().getSystemState().setIgnored(true);
+ } else {
+ // pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ }
+
+ sf.push(conditionValue, false);
+
+ //System.out.println("Execute FCMPL: " + ((PCChoiceGenerator) cg).getCurrentPC());
+ return getNext(th);
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETFIELD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETFIELD.java
index 4a78bad..895f573 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETFIELD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETFIELD.java
@@ -20,6 +20,7 @@
import gov.nasa.jpf.Config;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
+import gov.nasa.jpf.symbc.arrays.ArrayExpression;
import gov.nasa.jpf.symbc.heap.HeapChoiceGenerator;
import gov.nasa.jpf.symbc.heap.HeapNode;
import gov.nasa.jpf.symbc.heap.Helper;
@@ -53,7 +54,7 @@ public GETFIELD(String fieldName, String clsName, String fieldDescriptor){
@Override
public Instruction execute (ThreadInfo ti) {
-
+
HeapNode[] prevSymRefs = null; // previously initialized objects of same type: candidates for lazy init
int numSymRefs = 0; // # of prev. initialized objects
ChoiceGenerator> prevHeapCG = null;
@@ -69,7 +70,7 @@ public Instruction execute (ThreadInfo ti) {
StackFrame frame = ti.getModifiableTopFrame();
int objRef = frame.peek(); // don't pop yet, we might re-enter
lastThis = objRef;
- if (objRef == -1) {
+ if (objRef == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException",
"referencing field '" + fname + "' on null object");
}
@@ -90,8 +91,8 @@ public Instruction execute (ThreadInfo ti) {
return super.execute(ti);
}
- if(attr instanceof StringExpression || attr instanceof SymbolicStringBuilder)
- return super.execute(ti); // Strings are handled specially
+ if(attr instanceof StringExpression || attr instanceof SymbolicStringBuilder || attr instanceof ArrayExpression)
+ return super.execute(ti); // Strings and arrays are handled specially
if (SymbolicInstructionFactory.debugMode)
System.out.println("lazy initialization");
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETSTATIC.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETSTATIC.java
index 73c6231..5c50a95 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETSTATIC.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/GETSTATIC.java
@@ -21,6 +21,7 @@
import gov.nasa.jpf.Config;
import gov.nasa.jpf.JPFException;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
+import gov.nasa.jpf.symbc.arrays.ArrayExpression;
import gov.nasa.jpf.symbc.heap.HeapChoiceGenerator;
import gov.nasa.jpf.symbc.heap.HeapNode;
import gov.nasa.jpf.symbc.heap.Helper;
@@ -97,7 +98,7 @@ public Instruction execute (ThreadInfo ti) {
if (!(fi.isReference() && attr != null))
return super.execute(ti);
- if(attr instanceof StringExpression || attr instanceof SymbolicStringBuilder)
+ if(attr instanceof StringExpression || attr instanceof SymbolicStringBuilder || attr instanceof ArrayExpression)
return super.execute(ti); // Strings are handled specially
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IALOAD.java
index fab8265..9c43068 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IALOAD.java
@@ -21,17 +21,11 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -46,125 +40,117 @@ public class IALOAD extends gov.nasa.jpf.jvm.bytecode.IALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- IntegerSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
- StackFrame frame = ti.getModifiableTopFrame();
- arrayRef = frame.peek(1); // ..., arrayRef, idx
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints about the elements of the array, and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getIntElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
-
- else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
-
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
-
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
-
- if ((Integer)cg.getNextChoice()==1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice()==2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { //satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
- // We update the Symbolic Array with the get information
- SymbolicIntegerValueAtIndex result = arrayAttr.getVal(indexAttr);
- frame.pop(2); // We pop the array and the index
- frame.push(0, false); // For symbolic expressions, the concrete value does not matter
- frame.setOperandAttr(result.value);
- // We add the select instruction in the PathCondition
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ //System.out.println("array index "+index);
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in IASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getIntElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in IASTORE instruction";
-
- if (arrayRef == MJIEnv.NULL) {
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
-
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
-
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- IntegerExpression sym_value = null;
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- int value = frame.pop();
- sym_value = new IntegerConstant(value);
- }
- else {
- // The value is symbolic.
- sym_value = (IntegerExpression)frame.getOperandAttr(0);
- frame.pop();
- }
- PreviousIntegerArray previous = new PreviousIntegerArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- IntegerSymbolicArray newArrayAttr = new IntegerSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
-
- StoreExpression se = new StoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFEQ.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFEQ.java
index ff00591..a94bc46 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFEQ.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFEQ.java
@@ -15,29 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -64,16 +45,78 @@ public Instruction execute (ThreadInfo ti) {
return super.execute(ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.EQ,
- Comparator.NE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+
+ String[] dp = SymbolicInstructionFactory.dp;
+
+
+
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ if (dp[0].equalsIgnoreCase("omega")) // hack because omega does not handle not or or correctly
+ cg = new PCChoiceGenerator(3);
+ else
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==1 ? true: false;
+ }
+
+ sf.pop();
+ //System.out.println("Execute IFEQ: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ pc._addDet(Comparator.EQ, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+
+
+ if (dp[0].equalsIgnoreCase("omega")) {// hack
+ if((Integer)cg.getNextChoice()==0)
+ pc._addDet(Comparator.GT, sym_v, 0);
+ else {// ==2
+ assert((Integer)cg.getNextChoice()==2);
+ pc._addDet(Comparator.LT, sym_v, 0);
+ }
+ }
+ else
+ pc._addDet(Comparator.NE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGE.java
index a489300..bbc9f86 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGE.java
@@ -15,29 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
-//Copyright (C) 2006 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -64,16 +44,61 @@ public Instruction execute (ThreadInfo ti) {
return super.execute( ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.GE,
- Comparator.LT);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ sf.pop();
+ //System.out.println("Execute IFGE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ pc._addDet(Comparator.GE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ pc._addDet(Comparator.LT, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGT.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGT.java
index 65ca9d2..41b1d1f 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGT.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFGT.java
@@ -19,7 +19,6 @@
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -46,16 +45,61 @@ public Instruction execute (ThreadInfo ti) {
return super.execute( ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.GT,
- Comparator.LE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ sf.pop();
+ //System.out.println("Execute IFGT: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ pc._addDet(Comparator.GT, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ pc._addDet(Comparator.LE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLE.java
index 8e84231..931684c 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLE.java
@@ -15,29 +15,9 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-
-//Copyright (C) 2006 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -63,16 +43,68 @@ public Instruction execute (ThreadInfo ti) {
return super.execute( ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.LE,
- Comparator.GT);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ //System.out.println("Execute IFLE: The condition is symbolic");
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+
+ sf.pop();
+ //System.out.println("Execute IFLE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null) {
+
+ pc = new PathCondition();
+ }
+ else {
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ }
+ assert pc != null;
+
+ if (conditionValue) {
+ pc._addDet(Comparator.LE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }
+ else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ pc._addDet(Comparator.GT, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }
+ else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLT.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLT.java
index 155a8a7..9f31620 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLT.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFLT.java
@@ -18,7 +18,6 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -42,16 +41,65 @@ public Instruction execute (ThreadInfo ti) {
return super.execute(ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.LT,
- Comparator.GE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ //System.out.println("Execute IFLT: The condition is symbolic");
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCBChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ sf.pop();
+ //System.out.println("Execute IFLT: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ pc._addDet(Comparator.LT, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }
+ else {
+// pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ pc._addDet(Comparator.GE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }
+ else {
+// pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
+
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFNE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFNE.java
index d7fa3b8..1840d31 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFNE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IFNE.java
@@ -15,29 +15,10 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -64,16 +45,75 @@ public Instruction execute (ThreadInfo ti) {
return super.execute(ti);
}
else { // the condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v,
- Comparator.NE,
- Comparator.EQ);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+
+ String[] dp = SymbolicInstructionFactory.dp;
+
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+
+ if (dp[0].equalsIgnoreCase("omega")) // hack because omega does not handle not or or correctly
+ cg = new PCChoiceGenerator(3);
+ else
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ sf.pop();
+ //System.out.println("Execute IFNE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (dp[0].equalsIgnoreCase("omega")) {// hack
+ if((Integer)cg.getNextChoice()==1)
+ pc._addDet(Comparator.GT, sym_v, 0);
+ else {// 2
+ assert((Integer)cg.getNextChoice()==2);
+ pc._addDet(Comparator.LT, sym_v, 0);
+ }
+ }
+ else
+ pc._addDet(Comparator.NE, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ pc._addDet(Comparator.EQ, sym_v, 0);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPEQ.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPEQ.java
index bbeb3ad..17306b2 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPEQ.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPEQ.java
@@ -1,41 +1,22 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -61,17 +42,71 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPEQ: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.EQ,
- Comparator.NE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ //System.out.println("Execute IF_ICMPEQ: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.EQ,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.EQ,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.NE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.NE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.NE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGE.java
index c5e300e..45a1b2b 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGE.java
@@ -1,43 +1,23 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -62,17 +42,75 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPGE: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.GE,
- Comparator.LT);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ //System.out.println("Execute IF_ICMPGE: The conditions are symbolic");
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ //System.out.println("Execute IF_ICMPGE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.GE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.GE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.GE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.LT,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.LT,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.LT, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGT.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGT.java
index 19d6bb2..d15bec3 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGT.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPGT.java
@@ -1,42 +1,23 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -64,17 +45,74 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPGT: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.GT,
- Comparator.LE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ //System.out.println("Execute IF_ICMPGT: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.GT,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.GT,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.GT, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.LE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.LE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.LE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println("IF_ICMPGT: " + ((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLE.java
index 064771f..e1e4b8f 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLE.java
@@ -1,41 +1,22 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -60,17 +41,74 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPLE: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.LE,
- Comparator.GT);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ // System.out.println("Execute IF_ICMPLE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.LE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.LE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.LE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.GT,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.GT,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.GT, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLT.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLT.java
index ab807e9..9b10211 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLT.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPLT.java
@@ -1,41 +1,23 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -60,18 +42,74 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPLT: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
-
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.GE);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ //System.out.println("Execute IF_ICMPLT: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.LT,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.LT,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.LT, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.GE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.GE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.GE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println("IF_ICMPLT: " + ((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPNE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPNE.java
index ff3fb6b..1868fec 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPNE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IF_ICMPNE.java
@@ -1,42 +1,23 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-//Copyright (C) 2007 United States Government as represented by the
-//Administrator of the National Aeronautics and Space Administration
-//(NASA). All Rights Reserved.
-
-//This software is distributed under the NASA Open Source Agreement
-//(NOSA), version 1.3. The NOSA has been approved by the Open Source
-//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
-//directory tree for the complete NOSA document.
-
-//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
-//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
-//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
-//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
-//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
-//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
-//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
-
+/*
+ * Copyright (C) 2014, United States Government, as represented by the
+ * Administrator of the National Aeronautics and Space Administration.
+ * All rights reserved.
+ *
+ * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
+ * Version 2.0 (the "License"); you may not use this file except
+ * in compliance with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0.
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.*;
import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
@@ -61,18 +42,74 @@ public Instruction execute (ThreadInfo ti) {
//System.out.println("Execute IF_ICMPNE: The conditions are concrete");
return super.execute(ti);
}else{ // at least one condition is symbolic
-
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(ti,
- this,
- sym_v1,
- sym_v2,
- Comparator.NE,
- Comparator.EQ);
- if(nxtInstr==getTarget())
- conditionValue=true;
- else
- conditionValue=false;
- return nxtInstr;
+ ChoiceGenerator> cg;
+
+ if (!ti.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ ti.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = ti.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ conditionValue = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+ int v2 = sf.pop();
+ int v1 = sf.pop();
+ //System.out.println("Execute IF_ICMPNE: "+ conditionValue);
+ PathCondition pc;
+
+ // pc is updated with the pc stored in the choice generator above
+ // get the path condition from the
+ // previous choice generator of the same type
+
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if (conditionValue) {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.NE,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.NE,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.NE, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else{
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ // System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getTarget();
+ } else {
+ if (sym_v1 != null){
+ if (sym_v2 != null){ //both are symbolic values
+ pc._addDet(Comparator.EQ,sym_v1,sym_v2);
+ }else
+ pc._addDet(Comparator.EQ,sym_v1,v2);
+ }else
+ pc._addDet(Comparator.EQ, v1, sym_v2);
+ if(!pc.simplify()) {// not satisfiable
+ ti.getVM().getSystemState().setIgnored(true);
+ }else {
+ //pc.solve();
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ //System.out.println(((PCChoiceGenerator) cg).getCurrentPC());
+ }
+ return getNext(ti);
+ }
}
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEINTERFACE.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEINTERFACE.java
index 9f55a83..eb59adf 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEINTERFACE.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEINTERFACE.java
@@ -19,6 +19,7 @@
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MethodInfo;
+import gov.nasa.jpf.vm.MJIEnv;
import gov.nasa.jpf.vm.ThreadInfo;
// need to fix names
@@ -33,7 +34,7 @@ public INVOKEINTERFACE(String clsName, String methodName, String methodSignature
public Instruction execute(ThreadInfo th) {
int objRef = th.getCalleeThis(getArgSize());
- if (objRef == -1) {
+ if (objRef == MJIEnv.NULL) {
lastObj = -1;
return th.createAndThrowException("java.lang.NullPointerException", "Calling '" + mname + "' on null object");
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEVIRTUAL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEVIRTUAL.java
index 8bf498b..a3c208e 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEVIRTUAL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/INVOKEVIRTUAL.java
@@ -20,6 +20,7 @@
import gov.nasa.jpf.vm.ClassInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MethodInfo;
+import gov.nasa.jpf.vm.MJIEnv;
import gov.nasa.jpf.vm.ThreadInfo;
// need to fix names
@@ -34,7 +35,7 @@ public INVOKEVIRTUAL(String clsName, String methodName, String methodSignature)
public Instruction execute( ThreadInfo th) {
int objRef = th.getCalleeThis(getArgSize());
- if (objRef == -1) {
+ if (objRef == MJIEnv.NULL) {
lastObj = -1;
return th.createAndThrowException("java.lang.NullPointerException", "Calling '" + mname + "' on null object");
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHL.java
index 8d4c6f7..6cf4473 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHL.java
@@ -19,6 +19,7 @@
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -41,15 +42,20 @@ public Instruction execute (ThreadInfo th) {
IntegerExpression result = null;
if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftL(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftL(v2);
+ if (sym_v2!=null) {
+ //result = sym_v1._shiftL(sym_v2);
+ result = sym_v2._shiftL(sym_v1);
+ }
+ else { // v2 is concrete
+ //result = sym_v1._shiftL(v2);
+ result = (new IntegerConstant((int) v2))._shiftL(sym_v1);
+ }
}
- else if (sym_v2!=null)
+ else if (sym_v2 != null) {
result = sym_v2._shiftL(v1);
+ }
+
sf.setOperandAttr(result);
-
return getNext(th);
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHR.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHR.java
index 888cc08..32a7d54 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHR.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/ISHR.java
@@ -19,6 +19,7 @@
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -40,16 +41,22 @@ public Instruction execute (ThreadInfo th) {
sf.push(0, false); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
- if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftR(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftR(v2);
+ if (sym_v1 != null) {
+ if (sym_v2!=null) {
+ //result = sym_v1._shiftR(sym_v2);
+ // FIX: it's the second argument right shifted by the first argument
+ result = sym_v2._shiftR(sym_v1);
+ }
+ else {// v2 is concrete
+ //result = sym_v1._shiftR(v2);
+ result = (new IntegerConstant((int) v2))._shiftR(sym_v1);
+ }
}
- else if (sym_v2!=null)
+ else if (sym_v2 != null) {
result = sym_v2._shiftR(v1);
+ }
+
sf.setOperandAttr(result);
-
return getNext(th);
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IUSHR.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IUSHR.java
index b7a4286..77b1c1c 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IUSHR.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/IUSHR.java
@@ -19,6 +19,7 @@
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -40,16 +41,21 @@ public Instruction execute (ThreadInfo th) {
sf.push(0, false); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
- if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftUR(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftUR(v2);
+ if(sym_v1 != null) {
+ if (sym_v2 != null) {
+ //result = sym_v1._shiftUR(sym_v2);
+ result = sym_v2._shiftUR(sym_v1);
+ }
+ else { // v2 is concrete
+ //result = sym_v1._shiftUR(v2);
+ result = (new IntegerConstant((int) v2))._shiftUR(sym_v1);
+ }
}
- else if (sym_v2!=null)
+ else if (sym_v2 != null) {
result = sym_v2._shiftUR(v1);
+ }
+
sf.setOperandAttr(result);
-
return getNext(th);
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LALOAD.java
index 0abccd4..3d504d9 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LALOAD.java
@@ -20,17 +20,11 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -45,125 +39,115 @@ public class LALOAD extends gov.nasa.jpf.jvm.bytecode.LALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- IntegerSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
- StackFrame frame = ti.getModifiableTopFrame();
- arrayRef = frame.peek(1); // ..., arrayRef, idx
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints about the elements of the array, and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- long arrValue = arrayInfo.getLongElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant((int)arrValue));
- }
- }
-
- else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
-
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
-
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
-
- if ((Integer)cg.getNextChoice()==1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice()==2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { //satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
- // We update the Symbolic Array with the get information
- SymbolicIntegerValueAtIndex result = arrayAttr.getVal(indexAttr);
- frame.pop(2); // We pop the array and the index
- frame.push(0, false); // For symbolic expressions, the concrete value does not matter
- frame.setLongOperandAttr(result.value);
- // We add the select instruction in the PathCondition
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index ...
@@ -47,142 +40,128 @@ public class LASTORE extends gov.nasa.jpf.jvm.bytecode.LASTORE {
@Override
- public Instruction execute (ThreadInfo ti) {
- // We may need to add the case where we have a smybolic index and a concrete array
-
- IntegerExpression indexAttr = null;
- IntegerSymbolicArray arrayAttr = null;
- StackFrame frame = ti.getModifiableTopFrame();
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(1) == null || !(frame.getOperandAttr(1) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- }
- }
+ public Instruction execute (ThreadInfo ti) {
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+ } else { //this is what really returns results
+
+
- ChoiceGenerator> cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
+ assert pc != null;
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = peekIndex(ti);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in IASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(1) == null || !(frame.getOperandAttr(1) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- long arrValue = arrayInfo.getLongElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant((int)arrValue));
- }
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in IASTORE instruction";
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- IntegerExpression sym_value = null;
- if (frame.getOperandAttr(1) == null || !(frame.getOperandAttr(1) instanceof IntegerExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- long value = frame.popLong();
- sym_value = new IntegerConstant((int)value);
- }
- else {
- // The value is symbolic.
- sym_value = (IntegerExpression)frame.getOperandAttr(0);
- frame.popLong();
- }
- PreviousIntegerArray previous = new PreviousIntegerArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- IntegerSymbolicArray newArrayAttr = new IntegerSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
+ return getNext(ti);
+ }
+ }
- StoreExpression se = new StoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
-
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LCMP.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LCMP.java
index 1fea5a5..afcb1eb 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LCMP.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LCMP.java
@@ -18,7 +18,6 @@
package gov.nasa.jpf.symbc.bytecode;
-import gov.nasa.jpf.symbc.bytecode.util.IFInstrSymbHelper;
import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
@@ -45,16 +44,8 @@ public Instruction execute (ThreadInfo th) {
if (sym_v1 == null && sym_v2 == null) // both conditions are concrete
return super.execute(th);
else { // at least one condition is symbolic
- Instruction nxtInstr = IFInstrSymbHelper.getNextInstructionAndSetPCChoice(th,
- this,
- sym_v1,
- sym_v2,
- Comparator.LT,
- Comparator.EQ,
- Comparator.GT);
-
- return nxtInstr;
- /*ChoiceGenerator> cg;
+
+ ChoiceGenerator> cg;
int conditionValue;
if (!th.isFirstStepInsn()) { // first time around
@@ -139,7 +130,7 @@ public Instruction execute (ThreadInfo th) {
sf.push(conditionValue, false);
//System.out.println("Execute LCMP: " + ((PCChoiceGenerator) cg).getCurrentPC());
- return getNext(th);*/
+ return getNext(th);
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LMUL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LMUL.java
index 2aefecb..adc9f50 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LMUL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LMUL.java
@@ -45,20 +45,20 @@ public Instruction execute (ThreadInfo th) {
sf.pushLong(0); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
- if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._mul(sym_v2);
- else // v2 is concrete
- result = sym_v1._mul(v2);
- }
- else if (sym_v2!=null)
- result = sym_v2._mul(v1);
+
+ if(sym_v1!=null) {
+ if (sym_v2!=null)
+ result = sym_v1._mul(sym_v2);
+ else // v2 is concrete
+ result = sym_v1._mul(v2);
+ }
+ else if (sym_v2!=null)
+ result = sym_v2._mul(v1);
+ sf.setLongOperandAttr(result);
- sf.setLongOperandAttr(result);
+ //System.out.println("Execute IMUL: "+result);
- //System.out.println("Execute LMUL: "+result);
-
- return getNext(th);
+ return getNext(th);
}
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LREM.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LREM.java
index 1ec8839..bc1786d 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LREM.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LREM.java
@@ -18,7 +18,11 @@
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.Comparator;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
+import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
+import gov.nasa.jpf.symbc.numeric.PathCondition;
+import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
import gov.nasa.jpf.vm.ThreadInfo;
@@ -36,12 +40,101 @@ public Instruction execute (ThreadInfo th) {
IntegerExpression sym_v1 = (IntegerExpression) sf.getOperandAttr(1);
IntegerExpression sym_v2 = (IntegerExpression) sf.getOperandAttr(3);
-
+ long v1, v2;
+
if(sym_v1==null && sym_v2==null)
return super.execute( th);// we'll still do the concrete execution
else {
- throw new RuntimeException("## Error: SYMBOLIC LREM not supported");
- }
+
+ // result is symbolic
+
+ if(sym_v1==null && sym_v2!=null) {
+ v1 = sf.popLong();
+ v2 = sf.popLong();
+ if(v1==0)
+ return th.createAndThrowException("java.lang.ArithmeticException","div by 0");
+ sf.pushLong(0);
+ IntegerExpression result = sym_v2._rem(v1);
+ sf.setLongOperandAttr(result);
+ return getNext(th);
+ }
+
+ // div by zero check affects path condition
+ // sym_v1 is non-null and should be checked against zero
+
+ ChoiceGenerator> cg;
+ boolean condition;
+
+ if (!th.isFirstStepInsn()) { // first time around
+ cg = new PCChoiceGenerator(2);
+ ((PCChoiceGenerator)cg).setOffset(this.position);
+ ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
+ th.getVM().getSystemState().setNextChoiceGenerator(cg);
+ return this;
+ } else { // this is what really returns results
+ cg = th.getVM().getSystemState().getChoiceGenerator();
+ assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
+ condition = (Integer)cg.getNextChoice()==0 ? false: true;
+ }
+
+
+ v1 = sf.popLong();
+ v2 = sf.popLong();
+ sf.pushLong(0);
+
+ PathCondition pc;
+ ChoiceGenerator> prev_cg = cg.getPreviousChoiceGenerator();
+
+ while (!((prev_cg == null) || (prev_cg instanceof PCChoiceGenerator))) {
+ prev_cg = prev_cg.getPreviousChoiceGenerator();
+ }
+ if (prev_cg == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
+
+ assert pc != null;
+
+ if(condition) { // check div by zero
+ pc._addDet(Comparator.EQ, sym_v1, 0);
+ if(pc.simplify()) { // satisfiable
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+
+ return th.createAndThrowException("java.lang.ArithmeticException","rem by 0");
+ }
+ else {
+ th.getVM().getSystemState().setIgnored(true);
+ return getNext(th);
+ }
+ }
+ else {
+ pc._addDet(Comparator.NE, sym_v1, 0);
+ if(pc.simplify()) { // satisfiable
+ ((PCChoiceGenerator) cg).setCurrentPC(pc);
+
+ // set the result
+ IntegerExpression result;
+ if(sym_v2!=null)
+ result = sym_v2._rem(sym_v1);
+ else
+ result = sym_v1._rem_reverse(v2);
+
+ sf = th.getModifiableTopFrame();
+ sf.setLongOperandAttr(result);
+ return getNext(th);
+
+ }
+ else {
+ th.getVM().getSystemState().setIgnored(true);
+ return getNext(th);
+ }
+ }
+
+ }
+
+
+
+
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHL.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHL.java
index dc4fe2d..3dc4d27 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHL.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHL.java
@@ -17,6 +17,7 @@
*/
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -43,20 +44,22 @@ public Instruction execute (ThreadInfo th) {
sf.pushLong(0); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
- if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftL(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftL(v2);
+ if (sym_v1 != null) {
+ if (sym_v2 != null) {
+ //result = sym_v1._shiftL(sym_v2);
+ result = sym_v2._shiftL(sym_v1);
+ }
+ else { // v2 is concrete
+ //result = sym_v1._shiftL(v2);
+ result = (new IntegerConstant((int) v2))._shiftL(sym_v1);
+ }
}
- else if (sym_v2!=null) {
+ else if (sym_v2 != null) {
result = sym_v2._shiftL(v1);
-
}
- sf.setLongOperandAttr(result);
+ sf.setLongOperandAttr(result);
return getNext(th);
}
}
-
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHR.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHR.java
index 7c9656b..dbf3ed9 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHR.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LSHR.java
@@ -18,6 +18,7 @@
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -44,18 +45,21 @@ public Instruction execute (ThreadInfo th) {
sf.pushLong(0); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
- if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftR(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftR(v2);
+ if (sym_v1 != null) {
+ if (sym_v2 != null) {
+ //result = sym_v1._shiftR(sym_v2);
+ result = sym_v2._shiftR(sym_v1);
+ }
+ else { // v2 is concrete
+ //result = sym_v1._shiftR(v2);
+ result = (new IntegerConstant((int) v2))._shiftR(sym_v1);
+ }
}
- else if (sym_v2!=null) {
+ else if (sym_v2 != null) {
result = sym_v2._shiftR(v1);
-
}
- sf.setLongOperandAttr(result);
+ sf.setLongOperandAttr(result);
return getNext(th);
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LUSHR.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LUSHR.java
index ac63988..660a2a8 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LUSHR.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/LUSHR.java
@@ -17,6 +17,7 @@
*/
package gov.nasa.jpf.symbc.bytecode;
+import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.StackFrame;
@@ -38,23 +39,26 @@ public Instruction execute (ThreadInfo th) {
if(sym_v1==null && sym_v2==null)
return super.execute( th);// we'll still do the concrete execution
else {
- long v1 = sf.pop();
+ int v1 = sf.pop();
long v2 = sf.popLong();
sf.pushLong(0); // for symbolic expressions, the concrete value does not matter
IntegerExpression result = null;
if(sym_v1!=null) {
- if (sym_v2!=null)
- result = sym_v1._shiftUR(sym_v2);
- else // v2 is concrete
- result = sym_v1._shiftUR(v2);
+ if (sym_v2!=null) {
+ //result = sym_v1._shiftUR(sym_v2);
+ result = sym_v2._shiftUR(sym_v1);
+ }
+ else { // v2 is concrete
+ result = sym_v1._shiftUR(v2);
+ result = (new IntegerConstant((int) v2))._shiftUR(sym_v1);
+ }
}
- else if (sym_v2!=null) {
- result = sym_v2._shiftUR(v1);
-
+ else if (sym_v2 != null) {
+ result = sym_v2._shiftUR(v1);
}
- sf.setLongOperandAttr(result);
+ sf.setLongOperandAttr(result);
return getNext(th);
}
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/MULTIANEWARRAY.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/MULTIANEWARRAY.java
index 8abc010..4e068ad 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/MULTIANEWARRAY.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/MULTIANEWARRAY.java
@@ -50,11 +50,12 @@ public Instruction execute(ThreadInfo ti) {
Object attr = sf.getOperandAttr();
if(attr instanceof SymbolicLengthInteger) {
- arrayLengths[i] = ((SymbolicLengthInteger) attr).solution;
+ long l = ((SymbolicLengthInteger) attr).solution;
+ assert(l>=0 && l<=Integer.MAX_VALUE) : "Array length must be positive integer";
+ arrayLengths[i] = (int) l;
sf.pop();
} else if(attr instanceof IntegerExpression) {
- arrayLengths[i] = ((IntegerExpression) attr).solution();
- sf.pop();
+ throw new RuntimeException("MULTIANEWARRAY: symbolic array length");
} else {
arrayLengths[i] = sf.pop();
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/NEWARRAY.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/NEWARRAY.java
index 996c39f..dbe863a 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/NEWARRAY.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/NEWARRAY.java
@@ -51,6 +51,7 @@ public NEWARRAY(int typeCode) {
@Override
public Instruction execute( ThreadInfo ti) {
+ /*
StackFrame frame = ti.getModifiableTopFrame();
arrayLength = frame.pop();
@@ -83,28 +84,21 @@ public Instruction execute( ThreadInfo ti) {
frame.pushRef(arrayRef);
return getNext(ti);
-
+ */
// old code
- // Corina: I'll comment it out for the time being
- /*
+ // Corina: incorrect
+
StackFrame sf = ti.getModifiableTopFrame();
Object attr = sf.getOperandAttr();
if(attr instanceof SymbolicLengthInteger) {
- arrayLength = ((SymbolicLengthInteger) attr).solution;
+ long l = ((SymbolicLengthInteger) attr).solution;
+ assert(l>=0 && l<=Integer.MAX_VALUE) : "Array length must be positive integer";
+ arrayLength = (int) l;
sf.pop();
} else if(attr instanceof IntegerExpression) {
- if (!PathCondition.flagSolved) {
- // TODO I don't know what to do in this case; I believe this
- // only happens if the array initialization is
- // located before a program branch.
-
- // Corina: in reality here we should do the equivalent of lazy initialization for arrays
- throw new RuntimeException(
- "Path condition is not solved; Check the comments above this line for more details!");
- }
- arrayLength = ((IntegerExpression) attr).solution();
- sf.pop();
+ throw new RuntimeException("NEWARRAY: symbolic array length");
+
} else {
arrayLength = sf.pop();
}
@@ -120,8 +114,8 @@ public Instruction execute( ThreadInfo ti) {
// there is no clinit for array classes, but we still have to create a class object
// since its a builtin class, we also don't have to bother with NoClassDefFoundErrors
String clsName = "[" + type;
- ClassInfo ci = ClassInfo.getResolvedClassInfo(clsName);
-
+
+ ClassInfo ci = ClassLoaderInfo.getCurrentResolvedClassInfo(clsName);
if (!ci.isRegistered()) {
ci.registerClass(ti);
ci.setInitialized();
@@ -134,12 +128,15 @@ public Instruction execute( ThreadInfo ti) {
"[" + arrayLength + "]");
}
- int arrayRef = heap.newArray(type, arrayLength, ti);
- sf.push(arrayRef, true);
+ ElementInfo eiArray = heap.newArray(type, arrayLength, ti);
+ int arrayRef = eiArray.getObjectRef();
+
+ sf.pushRef(arrayRef);
+
ti.getVM().getSystemState().checkGC(); // has to happen after we push the new object ref
return getNext(ti);
- */
+
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SALOAD.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SALOAD.java
index 1cf0926..d4fa97f 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SALOAD.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SALOAD.java
@@ -21,17 +21,11 @@
package gov.nasa.jpf.symbc.bytecode;
import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
-import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.SelectExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.SymbolicIntegerValueAtIndex;
import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerConstant;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.vm.ArrayIndexOutOfBoundsExecutiveException;
-import gov.nasa.jpf.vm.ChoiceGenerator;
import gov.nasa.jpf.vm.ElementInfo;
import gov.nasa.jpf.vm.Instruction;
import gov.nasa.jpf.vm.MJIEnv;
@@ -46,116 +40,115 @@ public class SALOAD extends gov.nasa.jpf.jvm.bytecode.SALOAD {
@Override
public Instruction execute (ThreadInfo ti) {
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- }
-
- IntegerSymbolicArray arrayAttr = null;
- ChoiceGenerator> cg;
- boolean condition;
- StackFrame frame = ti.getModifiableTopFrame();
+
+ if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression))
+ return super.execute(ti);
+ StackFrame frame = ti.getModifiableTopFrame();
arrayRef = frame.peek(1); // ..,arrayRef,idx
+ if (arrayRef == MJIEnv.NULL) {
+ return ti.createAndThrowException("java.lang.NullPointerException");
+ }
+
+ ElementInfo eiArray = ti.getElementInfo(arrayRef);
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator)cg).setOffset(this.position);
- ((PCChoiceGenerator)cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekArrayAttr(ti) == null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- // In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic either
- return super.execute(ti);
- }
- // We have a concrete array, but a symbolic index. We add all the constraints and perform the select
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getShortElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- IntegerExpression indexAttr = null;
- SelectExpression se = null;
-
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- // In this case, the index isn't symbolic.
- index = frame.peek();
- se = new SelectExpression(arrayAttr, index);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- se = new SelectExpression(arrayAttr, indexAttr);
- }
-
- assert arrayAttr != null;
- assert indexAttr != null;
- assert se != null;
+ } else { //this is what really returns results
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
- if (arrayRef == MJIEnv.NULL) {
- return ti.createAndThrowException("java.lang.NullPointerException");
- }
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, se.index, se.ae.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- } else {
- pc._addDet(Comparator.LT, se.index, se.ae.length);
- pc._addDet(Comparator.GE, se.index, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
+ assert pc != null;
- // Set the result
- // We update the Symbolic Array with the get information
- SymbolicIntegerValueAtIndex result = arrayAttr.getVal(indexAttr);
- frame.pop(2); // We pop the array and the index
- frame.push(0, false); // For symbolic expressions, the concrete value does not matter
- frame.setOperandAttr(result.value);
- // We add the select instruction in the PathCondition
- pc._addDet(Comparator.EQ, se, result.value);
- return getNext(ti);
- } else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+ if(index cg;
- boolean condition;
- int arrayRef = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
-
- if (!ti.isFirstStepInsn()) { // first time around
- cg = new PCChoiceGenerator(3);
- ((PCChoiceGenerator) cg).setOffset(this.position);
- ((PCChoiceGenerator) cg).setMethodName(this.getMethodInfo().getFullName());
- ti.getVM().setNextChoiceGenerator(cg);
- return this;
- } else { // this is what really returns results
- cg = ti.getVM().getChoiceGenerator();
- assert (cg instanceof PCChoiceGenerator) : "expected PCChoiceGenerator, got: " + cg;
- }
-
- PathCondition pc;
- ChoiceGenerator> prev_cg = cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if (prev_cg == null)
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prev_cg).getCurrentPC();
-
- assert pc != null;
-
- if (peekIndexAttr(ti)==null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- int index = ti.getTopFrame().peek(1);
- indexAttr = new IntegerConstant(index);
- } else {
- indexAttr = (IntegerExpression)peekIndexAttr(ti);
- }
- assert (indexAttr != null) : "indexAttr shouldn't be null in IASTORE instruction";
-
- if (peekArrayAttr(ti)==null || !(peekArrayAttr(ti) instanceof ArrayExpression)) {
- //In this case, the array isn't symbolic
- if (peekIndexAttr(ti) == null || !(peekIndexAttr(ti) instanceof IntegerExpression)) {
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // nothing is symbolic here
- return super.execute(ti);
- }
- } else {
- // We create a symbolic array out of the concrete array
- ElementInfo arrayInfo = ti.getElementInfo(arrayRef);
- arrayAttr = new IntegerSymbolicArray(arrayInfo.arrayLength());
- // We add the constraints about all the elements of the array
- for (int i = 0; i < arrayInfo.arrayLength(); i++) {
- int arrValue = arrayInfo.getShortElement(i);
- pc._addDet(Comparator.EQ, new SelectExpression(arrayAttr, i), new IntegerConstant(arrValue));
- }
- }
- } else {
- arrayAttr = (IntegerSymbolicArray)peekArrayAttr(ti);
- }
- assert (arrayAttr != null) : "arrayAttr shouldn't be null in IASTORE instruction";
-
- if (arrayRef == MJIEnv.NULL) {
+ int arrayref = peekArrayRef(ti); // need to be polymorphic, could be LongArrayStore
+ ElementInfo eiArray = ti.getElementInfo(arrayref);
+
+ if (arrayref == MJIEnv.NULL) {
return ti.createAndThrowException("java.lang.NullPointerException");
}
-
-
- if ((Integer)cg.getNextChoice() == 1) { // check bounds of the index
- pc._addDet(Comparator.GE, indexAttr, arrayAttr.length);
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index greater than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else if ((Integer)cg.getNextChoice() == 2) {
- pc._addDet(Comparator.LT, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- return ti.createAndThrowException("java.lang.ArrayIndexOutOfBoundsException", "index smaller than array bounds");
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- else {
- pc._addDet(Comparator.LT, indexAttr, arrayAttr.length);
- pc._addDet(Comparator.GE, indexAttr, new IntegerConstant(0));
- if (pc.simplify()) { // satisfiable
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
-
- // set the result
-
- // We have to check if the value is symbolic or not, create a symbolicIntegerValueatIndex out of it, and
- // call the setVal function, before storing the attr
- IntegerExpression sym_value = null;
- if (frame.getOperandAttr(0) == null || !(frame.getOperandAttr(0) instanceof IntegerExpression)) {
- // The value isn't symbolic. We store a new IntegerConstant in the valAt map, at index indexAttr
- int value = frame.pop();
- sym_value = new IntegerConstant(value);
- }
- else {
- // The value is symbolic.
- sym_value = (IntegerExpression)frame.getOperandAttr(0);
- frame.pop();
- }
- PreviousIntegerArray previous = new PreviousIntegerArray(arrayAttr, indexAttr, sym_value);
- // We create a new arrayAttr, and inherits information from the previous attribute
- IntegerSymbolicArray newArrayAttr = new IntegerSymbolicArray(previous);
- frame.pop(2); // We pop the array and the index
-
- StoreExpression se = new StoreExpression(arrayAttr, indexAttr, sym_value);
- pc._addDet(Comparator.EQ, se, newArrayAttr);
-
- return getNext(ti);
- }
- else {
- ti.getVM().getSystemState().setIgnored(true);
- return getNext(ti);
- }
- }
- }
+
+
+ int len=(eiArray.getArrayFields()).arrayLength(); // assumed concrete
+
+ if(!ti.isFirstStepInsn()){
+ PCChoiceGenerator arrayCG = new PCChoiceGenerator(0,len+1); // add 2 error cases: <0, >=len
+ ti.getVM().getSystemState().setNextChoiceGenerator(arrayCG);
+
+ //ti.reExecuteInstruction();
+ if (SymbolicInstructionFactory.debugMode)
+ System.out.println("# array cg registered: " + arrayCG);
+ return this;
+
+ } else { //this is what really returns results
+
+
+
+ //index = frame.peek();
+ PCChoiceGenerator lastCG=ti.getVM().getSystemState().getLastChoiceGeneratorOfType(PCChoiceGenerator.class);
+ assert(lastCG!=null);
+ PCChoiceGenerator prevCG=lastCG.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
+
+ index=lastCG.getNextChoice();
+ IntegerExpression sym_index=(IntegerExpression)peekIndexAttr(ti);
+ //check the constraint
+
+ PathCondition pc;
+
+ if (prevCG == null)
+ pc = new PathCondition();
+ else
+ pc = ((PCChoiceGenerator)prevCG).getCurrentPC();
+
+ assert pc != null;
+
+ if(index what if the value is the same but not the attr?
+
+ } catch (ArrayIndexOutOfBoundsExecutiveException ex) { // at this point, the AIOBX is already processed
+ return ex.getInstruction();
+ }
+
+ return getNext(ti);
+ }
+ }
+
+
}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SymbolicStringHandler.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SymbolicStringHandler.java
index df04ad9..80bd9b7 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SymbolicStringHandler.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/SymbolicStringHandler.java
@@ -46,8 +46,7 @@
REMEDY FOR ANY SUCH MATTER SHALL BE THE IMMEDIATE, UNILATERAL
TERMINATION OF THIS AGREEMENT. */
-// TODO: to review
-// probably needs to be redone with env methods
+
package gov.nasa.jpf.symbc.bytecode;
@@ -63,11 +62,8 @@
import gov.nasa.jpf.vm.SystemState;
import gov.nasa.jpf.vm.Types;
import gov.nasa.jpf.vm.VM;
-
import gov.nasa.jpf.vm.StackFrame;
-
import gov.nasa.jpf.vm.ThreadInfo;
-
import gov.nasa.jpf.jvm.bytecode.JVMInvokeInstruction;
import gov.nasa.jpf.symbc.mixednumstrg.SpecialRealExpression;
import gov.nasa.jpf.symbc.numeric.IntegerConstant;
@@ -76,14 +72,10 @@
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.RealExpression;
import gov.nasa.jpf.symbc.numeric.PathCondition;
-import gov.nasa.jpf.symbc.numeric.SymbolicInteger;
-
-
import gov.nasa.jpf.symbc.string.*;
import gov.nasa.jpf.symbc.mixednumstrg.*;
-// Corina: this code is strange; I need to revise it carefully
public class SymbolicStringHandler {
static int handlerStep = 0;
static Instruction handlerStepSavedNext = null;
@@ -92,7 +84,7 @@ public class SymbolicStringHandler {
public static final int intValueOffset = 5;
/* this method checks if a method has as argument any symbolic strings */
-
+
public boolean isMethodStringSymbolic(JVMInvokeInstruction invInst, ThreadInfo th) {
String cname = invInst.getInvokedMethodClassName();
@@ -111,30 +103,32 @@ public boolean isMethodStringSymbolic(JVMInvokeInstruction invInst, ThreadInfo t
|| cname.equals("java.lang.Char")
|| cname.equals("java.lang.Boolean")
|| cname.equals("java.lang.Object")) {
- StackFrame sf = th.getModifiableTopFrame();
+
+ StackFrame sf = th.getModifiableTopFrame();
int numStackSlots = invInst.getArgSize();
for (int i = 0; i < numStackSlots; i++) {
Expression sym_v1 = (Expression) sf.getOperandAttr(i);
if (sym_v1 != null) {
-
if (sym_v1 instanceof SymbolicStringBuilder) { // check if
// StringBuilder has
// empty attribute
- if (((SymbolicStringBuilder) sym_v1).getstr() != null)
+ if (((SymbolicStringBuilder) sym_v1).getstr() != null) {
return true;
- } else if (sym_v1 instanceof SymbolicInteger && cname.equals("java.lang.StringBuilder")){
- //concrete stringbuffers won't be handled here
- return false;
- } else {
+ }
+ } else if (sym_v1 instanceof IntegerExpression && cname.equals("java.lang.StringBuilder")){
+ //to revise
return true;
+ } else {
+ return true;
}
+
}
}
return false;
- } else
- return false;
+ }
+ else return false;
}
public Instruction handleSymbolicStrings(JVMInvokeInstruction invInst, ThreadInfo th) {
@@ -212,7 +206,7 @@ public Instruction handleSymbolicStrings(JVMInvokeInstruction invInst, ThreadInf
} else if (shortName.equals("lastIndexOf")) {
handleLastIndexOf(invInst, th);
} else if (shortName.equals("charAt")) {
- handleCharAt (invInst, th);
+ handleCharAt (invInst, th); // returns boolean that is ignored
//return invInst;
} else if (shortName.equals("replace")) {
Instruction handled = handleReplace(invInst, th);
@@ -313,8 +307,8 @@ public Instruction handleSymbolicStrings(JVMInvokeInstruction invInst, ThreadInf
} else if (shortName.equals("booleanValue")) {
handlefloatValue(invInst, th);
} else {
- System.err.println("ERROR: symbolic method not handled: " + shortName);
- return null;
+ throw new RuntimeException("ERROR: symbolic method not handled: " + shortName);
+ //return null;
}
return invInst.getNext(th);
} else {
@@ -329,7 +323,7 @@ private boolean handleCharAt (JVMInvokeInstruction invInst, ThreadInfo th) {
StringExpression sym_v2 = (StringExpression) sf.getOperandAttr(1);
boolean bresult = false;
if ((sym_v1 == null) & (sym_v2 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleSubString1");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleCharAt");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -338,11 +332,8 @@ private boolean handleCharAt (JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v1 == null) { // operand 0 is concrete
int val = s1;
- //System.out.println("[handleCharAt] Mmm...! " + val);
result = sym_v2._charAt(new IntegerConstant(val));
} else {
- //System.out.println("[handleCharAt] YES! " + sym_v1.getClass() + " " + sym_v1.toString());
-
if (sym_v2 == null) {
ElementInfo e1 = th.getElementInfo(s2);
@@ -356,11 +347,10 @@ private boolean handleCharAt (JVMInvokeInstruction invInst, ThreadInfo th) {
//System.out.println("[handleCharAt] Ignoring: " + result.toString());
//th.push(0, false);
}
- //th.push(objRef, true);
sf.push(0, false);
sf.setOperandAttr(result);
}
- return bresult;
+ return bresult; // not used
}
@@ -368,7 +358,7 @@ public void handleLength(JVMInvokeInstruction invInst, ThreadInfo th) {
StackFrame sf = th.getModifiableTopFrame();
StringExpression sym_v1 = (StringExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleLength");
} else {
sf.pop();
sf.push(0, false); /* dont care value for length */
@@ -389,450 +379,308 @@ public void handleIndexOf(JVMInvokeInstruction invInst, ThreadInfo th) {
}
/* two possibilities int, or String in parameter */
- /* currently symbolic values in parameters are ignored */
public void handleIndexOf1(JVMInvokeInstruction invInst, ThreadInfo th) {
StackFrame sf = th.getModifiableTopFrame();
- /* Added by Gideon */
- //StringExpression argument = (StringExpression) sf.getOperandAttr(0);
+
//boolean castException = false;
StringExpression sym_v1 = null;
- StringExpression sym_v2 = null;
- sym_v1 = (StringExpression) sf.getOperandAttr(1);
- /* */
- sym_v2 = (StringExpression) sf.getOperandAttr(0);
+ Expression sym_v2 = null; // could be String or Char
+ sym_v1 = (StringExpression)sf.getOperandAttr(1);
+ sym_v2 = (Expression) sf.getOperandAttr(0);
if (sym_v1 == null && sym_v2 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleIndexOf1");
} else {
- /*int x1 = th.pop();
- int x2 = th.pop();
- System.out.printf("[SymbolicStringHandler] [handleIndexOf1] %d %d\n", x1, x2);
- th.push(0, false);
- IntegerExpression sym_v2 = sym_v1._indexOf();
- sf.setOperandAttr(sym_v2);*/
- // System.out.println("conditionValue: " + conditionValue);
-
-
- boolean s1char = true; //argument is char
+ boolean s2char = true; //argument is char
if (sf.isOperandRef()) {
- s1char = false; //argument is string
+ s2char = false; //argument is string
}
+
int s1 = sf.pop();
int s2 = sf.pop();
IntegerExpression result = null;
- //if (conditionValue) {
- if (sym_v1 != null) {
+ if (sym_v1 != null) {
if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._indexOf(sym_v2);
- } else {
- if (s1char) {
- result = sym_v1._indexOf(new IntegerConstant(s1));
+ if (s2char)
+ result = sym_v1._indexOf((IntegerExpression)sym_v2);
+ else
+ result = sym_v1._indexOf((StringExpression)sym_v2);
+ } else { // sym_v2 is null
+ if (s2char) {
+ result = sym_v1._indexOf(new IntegerConstant(s2));
}
else {
- ElementInfo e2 = th.getElementInfo(s1);
+ ElementInfo e2 = th.getElementInfo(s2);
String val = e2.asString();
result = sym_v1._indexOf(new StringConstant(val));
}
}
- //pc._addDet(Comparator.EQ, result, -1);
- } else {
+ } else { // sym_v1 is null, sym_v2 must be not null
+ assert(sym_v2!=null);
ElementInfo e1 = th.getElementInfo(s2);
String val = e1.asString();
-
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._indexOf(sym_v2);
- } else {
- if (s1char) {
- result = new StringConstant(val)._indexOf(new IntegerConstant(s1));
- }
- else {
- ElementInfo e2 = th.getElementInfo(s1);
- String val2 = e2.asString();
- result = new StringConstant(val)._indexOf(new StringConstant(val2));
- }
- }
- //pc.spc._addDet(comp, val, sym_v2);
- }
- /*} else {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._indexOf(sym_v2);
- } else {
- ElementInfo e2 = th.getElementInfo(s1);
- String val = e2.asString();
- result = sym_v1._indexOf(new StringConstant(val));
- }
- //pc._addDet(Comparator.GE, result, 0);
- } else {
- ElementInfo e1 = th.getElementInfo(s2);
- String val = e1.asString();
- throw new RuntimeException("Not supported yet");
- //pc.spc._addDet(comp, val, sym_v2);
- }
- }*/
- sf.push(0, false);
- sf.setOperandAttr(result);
- /*if (!pc.simplify()) {// not satisfiable
- System.out.println("Not sat");
- ss.setIgnored(true);
- } else {
- System.out.println("Is sat");
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- }*/
-
-
- //assert result != null;
- //th.push(conditionValue ? 1 : 0, true);
-
-
- }
- }
-
- public void handleLastIndexOf(JVMInvokeInstruction invInst, ThreadInfo th) {
- int numStackSlots = invInst.getArgSize();
- if (numStackSlots == 2) {
- handleLastIndexOf1(invInst, th);
- } else {
- handleLastIndexOf2(invInst, th);
- }
- }
-
- public void handleLastIndexOf1(JVMInvokeInstruction invInst, ThreadInfo th) {
- StackFrame sf = th.getModifiableTopFrame();
- /* Added by Gideon */
- //StringExpression argument = (StringExpression) sf.getOperandAttr(0);
- //boolean castException = false;
- StringExpression sym_v1 = null;
- StringExpression sym_v2 = null;
- sym_v1 = (StringExpression) sf.getOperandAttr(1);
- /* */
- sym_v2 = (StringExpression) sf.getOperandAttr(0);
- if (sym_v1 == null && sym_v2 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
- } else {
- /*int x1 = th.pop();
- int x2 = th.pop();
- System.out.printf("[SymbolicStringHandler] [handleIndexOf1] %d %d\n", x1, x2);
- th.push(0, false);
- IntegerExpression sym_v2 = sym_v1._indexOf();
- sf.setOperandAttr(sym_v2);*/
- // System.out.println("conditionValue: " + conditionValue);
-
-
- boolean s1char = true; //argument is char
- if (sf.isOperandRef()) {
- s1char = false; //argument is string
+ if (s2char)
+ result = new StringConstant(val)._indexOf((IntegerExpression)sym_v2);
+ else
+ result = new StringConstant(val)._indexOf((StringExpression)sym_v2);
}
- int s1 = sf.pop();
- int s2 = sf.pop();
-
- IntegerExpression result = null;
- //if (conditionValue) {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._lastIndexOf(sym_v2);
- } else {
- if (s1char) {
- result = sym_v1._lastIndexOf(new IntegerConstant(s1));
- }
- else {
- ElementInfo e2 = th.getElementInfo(s1);
- String val = e2.asString();
- result = sym_v1._lastIndexOf(new StringConstant(val));
- }
- }
- //pc._addDet(Comparator.EQ, result, -1);
- } else {
- ElementInfo e1 = th.getElementInfo(s2);
- String val = e1.asString();
-
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._lastIndexOf(sym_v2);
- } else {
- if (s1char) {
- result = new StringConstant(val)._lastIndexOf(new IntegerConstant(s1));
- }
- else {
- ElementInfo e2 = th.getElementInfo(s1);
- String val2 = e2.asString();
- result = new StringConstant(val)._lastIndexOf(new StringConstant(val2));
- }
- }
- //pc.spc._addDet(comp, val, sym_v2);
- }
- /*} else {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._indexOf(sym_v2);
- } else {
- ElementInfo e2 = th.getElementInfo(s1);
- String val = e2.asString();
- result = sym_v1._indexOf(new StringConstant(val));
- }
- //pc._addDet(Comparator.GE, result, 0);
- } else {
- ElementInfo e1 = th.getElementInfo(s2);
- String val = e1.asString();
- throw new RuntimeException("Not supported yet");
- //pc.spc._addDet(comp, val, sym_v2);
- }
- }*/
sf.push(0, false);
+ assert result != null;
sf.setOperandAttr(result);
- /*if (!pc.simplify()) {// not satisfiable
- System.out.println("Not sat");
- ss.setIgnored(true);
- } else {
- System.out.println("Is sat");
- ((PCChoiceGenerator) cg).setCurrentPC(pc);
- }*/
-
-
- //assert result != null;
- //th.push(conditionValue ? 1 : 0, true);
}
}
- public void handleLastIndexOf2(JVMInvokeInstruction invInst, ThreadInfo th) {
+ /* two possibilities int, int or int, String in parameters */
+ public void handleIndexOf2(JVMInvokeInstruction invInst, ThreadInfo th) {
+
StackFrame sf = th.getModifiableTopFrame();
StringExpression sym_v1 = null;
- StringExpression sym_v2 = null;
+ Expression sym_v2 = null;
IntegerExpression intExp = null;
sym_v1 = (StringExpression) sf.getOperandAttr(2);
intExp = (IntegerExpression) sf.getOperandAttr(0);
- sym_v2 = (StringExpression) sf.getOperandAttr(1);
+ sym_v2 = (Expression) sf.getOperandAttr(1);
if (sym_v1 == null && sym_v2 == null && intExp == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleIndexOf2");
} else {
+
int i1 = sf.pop();
boolean s2char = true;
- if (th.getModifiableTopFrame().isOperandRef()) {
+ if (sf.isOperandRef()) {
//System.out.println("[handleIndexOf2] string detected");
s2char = false;
}
- else {
- //System.out.println("[handleIndexOf2] char detected");
- }
+
int s2 = sf.pop();
int s1 = sf.pop();
IntegerExpression result = null;
if (intExp != null) {
- //System.out.println("[handleIndexOf2] int exp: " + intExp.getClass());
if (sym_v1 != null) {
if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._lastIndexOf(sym_v2, intExp);
- } else {
+ if (s2char)
+ result = sym_v1._indexOf((IntegerExpression)sym_v2, intExp);
+ else
+ result = sym_v1._indexOf((StringExpression)sym_v2, intExp);
+ } else { //sym_v2 is null
if (s2char) {
- result = sym_v1._lastIndexOf(new IntegerConstant(s2), intExp);
+ result = sym_v1._indexOf(new IntegerConstant(s2), intExp);
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val = e2.asString();
- result = sym_v1._lastIndexOf(new StringConstant(val), intExp);
+ result = sym_v1._indexOf(new StringConstant(val), intExp);
}
}
- } else {
+ } else { // sym_v1 is null
ElementInfo e1 = th.getElementInfo(s1);
String val = e1.asString();
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._lastIndexOf(sym_v2, intExp);
+ if (sym_v2 != null) {
+ if(s2char)
+ result = new StringConstant(val)._indexOf((IntegerExpression)sym_v2, intExp);
+ else
+ result = new StringConstant(val)._indexOf((StringExpression)sym_v2, intExp);
} else {
if (s2char) {
- result = new StringConstant(val)._lastIndexOf(new IntegerConstant(s2), intExp);
+ result = new StringConstant(val)._indexOf(new IntegerConstant(s2), intExp);
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val2 = e2.asString();
- result = new StringConstant(val)._lastIndexOf(new StringConstant(val2), intExp);
+ result = new StringConstant(val)._indexOf(new StringConstant(val2), intExp);
}
}
}
}
- else {
+ else { //intExp is null
if (sym_v1 != null) {
if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._lastIndexOf(sym_v2, new IntegerConstant(i1));
- } else {
+ if(s2char)
+ result = sym_v1._indexOf((IntegerExpression)sym_v2, new IntegerConstant(i1));
+ else
+ result = sym_v1._indexOf((StringExpression)sym_v2, new IntegerConstant(i1));
+ } else { //sym_v1 is null
if (s2char) {
- result = sym_v1._lastIndexOf(new IntegerConstant(s2), new IntegerConstant(i1));
+ result = sym_v1._indexOf(new IntegerConstant(s2), new IntegerConstant(i1));
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val = e2.asString();
- result = sym_v1._lastIndexOf(new StringConstant(val), new IntegerConstant(i1));
+ result = sym_v1._indexOf(new StringConstant(val), new IntegerConstant(i1));
//System.out.println("[handleIndexOf2] Special push");
//Special push?
//th.push(s1, true);
}
}
- } else {
+ } else {//sym_v1 is null
ElementInfo e1 = th.getElementInfo(s1);
String val = e1.asString();
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._lastIndexOf(sym_v2, new IntegerConstant(i1));
+ if (sym_v2 != null) {
+ if(s2char)
+ result = new StringConstant(val)._indexOf((IntegerExpression)sym_v2, new IntegerConstant(i1));
+ else
+ result = new StringConstant(val)._indexOf((StringExpression)sym_v2, new IntegerConstant(i1));
} else {
if (s2char) {
- result = new StringConstant(val)._lastIndexOf(new IntegerConstant(s2), new IntegerConstant(i1));
+ result = new StringConstant(val)._indexOf(new IntegerConstant(s2), new IntegerConstant(i1));
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val2 = e2.asString();
- result = new StringConstant(val)._lastIndexOf(new StringConstant(val2), new IntegerConstant(i1));
+ result = new StringConstant(val)._indexOf(new StringConstant(val2), new IntegerConstant(i1));
}
}
}
}
- /* Not quite sure yet why this works */
- //int objRef = th.getVM().getDynamicArea().newString("", th);
- //th.push(objRef, true);
sf.push(0, false);
assert result != null;
sf.setOperandAttr(result);
}
}
+
+ public void handleLastIndexOf(JVMInvokeInstruction invInst, ThreadInfo th) {
+ int numStackSlots = invInst.getArgSize();
+ if (numStackSlots == 2) {
+ handleLastIndexOf1(invInst, th);
+ } else {
+ handleLastIndexOf2(invInst, th);
+ }
+ }
-
- /* two possibilities int, int or int, String in parameters */
- /* currently symbolic values in parameters are ignored */
- public void handleIndexOf2(JVMInvokeInstruction invInst, ThreadInfo th) {
- //This was the Fjitsu way
- /*
+ public void handleLastIndexOf1(JVMInvokeInstruction invInst, ThreadInfo th) {
StackFrame sf = th.getModifiableTopFrame();
- StringExpression sym_v1 = (StringExpression) sf.getOperandAttr(2);
- if (sym_v1 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
+ //boolean castException = false;
+ StringExpression sym_v1 = null;
+ StringExpression sym_v2 = null;
+ sym_v1 = (StringExpression) sf.getOperandAttr(1);
+ /* */
+ sym_v2 = (StringExpression) sf.getOperandAttr(0);
+ if (sym_v1 == null && sym_v2 == null) {
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleLastIndexOf1");
} else {
- th.pop();
- th.pop();
- th.pop();
- th.push(0, false);
- //IntegerExpression sym_v2 = sym_v1._indexOf();
- sf.setOperandAttr(new IntegerConstant(1));
+ boolean s1char = true; //argument is char
+ if (sf.isOperandRef()) {
+ s1char = false; //argument is string
+ }
+ int s1 = sf.pop();
+ int s2 = sf.pop();
+
+ IntegerExpression result = null;
+ if (sym_v1 != null) {
+ if (sym_v2 != null) { // both are symbolic values
+ result = sym_v1._lastIndexOf(sym_v2);
+ } else {
+ if (s1char) {
+ result = sym_v1._lastIndexOf(new IntegerConstant(s1));
+ }
+ else {
+ ElementInfo e2 = th.getElementInfo(s1);
+ String val = e2.asString();
+ result = sym_v1._lastIndexOf(new StringConstant(val));
+ }
+ }
+ } else {//sym_v1 is null
+ ElementInfo e1 = th.getElementInfo(s2);
+ String val = e1.asString();
+ assert(sym_v2!=null);
+ result = new StringConstant(val)._lastIndexOf(sym_v2);
+
+ }
+
+ sf.push(0, false);
+ assert result != null;
+ sf.setOperandAttr(result);
+
}
- */
+ }
- //My way
+ public void handleLastIndexOf2(JVMInvokeInstruction invInst, ThreadInfo th) {
StackFrame sf = th.getModifiableTopFrame();
StringExpression sym_v1 = null;
StringExpression sym_v2 = null;
IntegerExpression intExp = null;
- /*System.out.print("[handleIndexOf2] arguments: ");
- if (sf.getOperandAttr(0) == null) {System.out.print("null");} else {System.out.print(sf.getOperandAttr(0).toString());}
- System.out.print(" ");
- if (sf.getOperandAttr(1) == null) {System.out.print("null");} else {System.out.print(sf.getOperandAttr(1).toString());}
- System.out.print(" ");
- if (sf.getOperandAttr(2) == null) {System.out.print("null");} else {System.out.print(sf.getOperandAttr(2).toString());}
- System.out.println();*/
sym_v1 = (StringExpression) sf.getOperandAttr(2);
intExp = (IntegerExpression) sf.getOperandAttr(0);
sym_v2 = (StringExpression) sf.getOperandAttr(1);
if (sym_v1 == null && sym_v2 == null && intExp == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLength");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleLastIndexOf2");
} else {
-
-
int i1 = sf.pop();
boolean s2char = true;
- if (sf.isOperandRef()) {
- //System.out.println("[handleIndexOf2] string detected");
+ if (th.getModifiableTopFrame().isOperandRef()) {
s2char = false;
}
- else {
- //System.out.println("[handleIndexOf2] char detected");
- }
+
int s2 = sf.pop();
int s1 = sf.pop();
IntegerExpression result = null;
if (intExp != null) {
- //System.out.println("[handleIndexOf2] int exp: " + intExp.getClass());
- if (intExp instanceof SymbolicIndexOf2Integer) {
- SymbolicIndexOf2Integer temp = (SymbolicIndexOf2Integer) intExp;
- //System.out.println("[handleIndexOf2] further on: " + temp.getMinIndex().getClass());
- }
- else if (intExp instanceof SymbolicIndexOfChar2Integer) {
- SymbolicIndexOfChar2Integer temp = (SymbolicIndexOfChar2Integer) intExp;
- //System.out.println("[handleIndexOf2] further on: " + temp.getMinDist().getClass());
- }
if (sym_v1 != null) {
if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._indexOf(sym_v2, intExp);
+ result = sym_v1._lastIndexOf(sym_v2, intExp);
} else {
if (s2char) {
- result = sym_v1._indexOf(new IntegerConstant(s2), intExp);
+ result = sym_v1._lastIndexOf(new IntegerConstant(s2), intExp);
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val = e2.asString();
- result = sym_v1._indexOf(new StringConstant(val), intExp);
+ result = sym_v1._lastIndexOf(new StringConstant(val), intExp);
}
}
- } else {
+ } else { //sym_v1 is null
ElementInfo e1 = th.getElementInfo(s1);
String val = e1.asString();
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._indexOf(sym_v2, intExp);
+ if (sym_v2 != null) {
+ result = new StringConstant(val)._lastIndexOf(sym_v2, intExp);
} else {
if (s2char) {
- result = new StringConstant(val)._indexOf(new IntegerConstant(s2), intExp);
+ result = new StringConstant(val)._lastIndexOf(new IntegerConstant(s2), intExp);
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val2 = e2.asString();
- result = new StringConstant(val)._indexOf(new StringConstant(val2), intExp);
+ result = new StringConstant(val)._lastIndexOf(new StringConstant(val2), intExp);
}
}
}
}
- else {
+ else { // intExp is null
if (sym_v1 != null) {
if (sym_v2 != null) { // both are symbolic values
- result = sym_v1._indexOf(sym_v2, new IntegerConstant(i1));
+ result = sym_v1._lastIndexOf(sym_v2, new IntegerConstant(i1));
} else {
if (s2char) {
- result = sym_v1._indexOf(new IntegerConstant(s2), new IntegerConstant(i1));
+ result = sym_v1._lastIndexOf(new IntegerConstant(s2), new IntegerConstant(i1));
}
else {
ElementInfo e2 = th.getElementInfo(s2);
String val = e2.asString();
- result = sym_v1._indexOf(new StringConstant(val), new IntegerConstant(i1));
+ result = sym_v1._lastIndexOf(new StringConstant(val), new IntegerConstant(i1));
//System.out.println("[handleIndexOf2] Special push");
//Special push?
//th.push(s1, true);
}
}
- } else {
+ } else { // sym_v1 is null
ElementInfo e1 = th.getElementInfo(s1);
String val = e1.asString();
-
- if (sym_v2 != null) { // both are symbolic values
- result = new StringConstant(val)._indexOf(sym_v2, new IntegerConstant(i1));
- } else {
- if (s2char) {
- result = new StringConstant(val)._indexOf(new IntegerConstant(s2), new IntegerConstant(i1));
- }
- else {
- ElementInfo e2 = th.getElementInfo(s2);
- String val2 = e2.asString();
- result = new StringConstant(val)._indexOf(new StringConstant(val2), new IntegerConstant(i1));
- }
- }
+ assert(sym_v2!=null);
+ result = new StringConstant(val)._lastIndexOf(sym_v2, new IntegerConstant(i1));
}
}
- /* Not quite sure yet why this works */
- //int objRef = th.getVM().getDynamicArea().newString("", th);
- //th.push(objRef, true);
+
sf.push(0, false);
assert result != null;
sf.setOperandAttr(result);
@@ -840,12 +688,15 @@ else if (intExp instanceof SymbolicIndexOfChar2Integer) {
}
}
+
+
+
public void handlebooleanValue(JVMInvokeInstruction invInst, SystemState ss, ThreadInfo th) {
StackFrame sf = th.getModifiableTopFrame();
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: handlebooleanValue");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandlebooleanValue");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -853,7 +704,7 @@ public void handlebooleanValue(JVMInvokeInstruction invInst, SystemState ss, Thr
sf.push(0, false);
sf.setOperandAttr(sym_v2);
} else {
- System.err.println("ERROR: operand type not tackled - booleanValue");
+ throw new RuntimeException("ERROR: operand type not tackled - booleanValue");
}
}
@@ -865,7 +716,7 @@ public void handleintValue(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: handleintValue");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleintValue");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -874,7 +725,7 @@ public void handleintValue(JVMInvokeInstruction invInst, ThreadInfo th) {
sf.setOperandAttr(sym_v2);
} else {
th.printStackTrace();
- System.err.println("ERROR: operand type not tackled - intValue");
+ throw new RuntimeException("ERROR: operand type not tackled - intValue");
}
}
}
@@ -884,7 +735,7 @@ public void handlelongValue(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeLongValue");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: hanldeLongValue");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -892,7 +743,7 @@ public void handlelongValue(JVMInvokeInstruction invInst, ThreadInfo th) {
sf.pushLong((long) 0);
sf.setLongOperandAttr(sym_v2);
} else {
- System.err.println("ERROR: operand type not tackled - longValue");
+ throw new RuntimeException("ERROR: operand type not tackled - longValue");
}
}
@@ -904,7 +755,7 @@ public void handlefloatValue(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeFloatValue");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand: hanldeFloatValue");
} else {
if (sym_v3 instanceof RealExpression) {
RealExpression sym_v2 = (RealExpression) sym_v3;
@@ -912,7 +763,7 @@ public void handlefloatValue(JVMInvokeInstruction invInst, ThreadInfo th) {
sf.push(0, false);
sf.setOperandAttr(sym_v2);
} else {
- System.err.println("ERROR: operand type not tackled - floatValue");
+ throw new RuntimeException("ERROR: operand type not tackled - floatValue");
}
}
@@ -924,7 +775,7 @@ public void handledoubleValue(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand: hanldeDoubleValue");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand: hanldeDoubleValue");
} else {
if (sym_v3 instanceof RealExpression) {
RealExpression sym_v2 = (RealExpression) sym_v3;
@@ -932,7 +783,7 @@ public void handledoubleValue(JVMInvokeInstruction invInst, ThreadInfo th) {
sf.pushLong((long) 0);
sf.setLongOperandAttr(sym_v2);
} else {
- System.err.println("ERROR: operand type not tackled - doubleValue");
+ throw new RuntimeException("ERROR: operand type not tackled - doubleValue");
}
}
@@ -952,7 +803,7 @@ public Instruction handleInit(JVMInvokeInstruction invInst, ThreadInfo th) {
StringExpression sym_v1 = (StringExpression) sf.getOperandAttr(0);
SymbolicStringBuilder sym_v2 = (SymbolicStringBuilder) sf.getOperandAttr(1);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic StringBuilder method must have one symbolic operand in Init");
+ throw new RuntimeException("ERROR: symbolic StringBuilder method must have one symbolic operand in Init");
} else {
sf.pop(); /* string object */
sf.pop(); /* one stringBuilder Object */
@@ -962,11 +813,9 @@ public Instruction handleInit(JVMInvokeInstruction invInst, ThreadInfo th) {
}
} else {
// Corina TODO: we should allow symbolic string analysis to kick in only when desired
- System.err.println("Warning Symbolic String Analysis: Initialization type not handled in symbc/bytecode/SymbolicStringHandler init");
+ //throw new RuntimeException("Warning Symbolic String Analysis: Initialization type not handled in symbc/bytecode/SymbolicStringHandler init");
return null;
}
-
- return null;
}
/***************************** Symbolic Big Decimal Routines end ****************/
@@ -978,7 +827,7 @@ private void handleBooleanStringInstructions(JVMInvokeInstruction invInst, Thre
StringExpression sym_v2 = (StringExpression) sf.getOperandAttr(1);
if ((sym_v1 == null) & (sym_v2 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleStartsWith");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleStartsWith");
} else {
ChoiceGenerator> cg;
boolean conditionValue;
@@ -1060,11 +909,11 @@ private void handleBooleanStringInstructions(JVMInvokeInstruction invInst, Thre
}
public void handleEqualsIgnoreCase(JVMInvokeInstruction invInst, ThreadInfo th) {
- System.err.println("ERROR: symbolic string method not Implemented - EqualsIgnoreCase");
+ throw new RuntimeException("ERROR: symbolic string method not Implemented - EqualsIgnoreCase");
}
public void handleEndsWith(JVMInvokeInstruction invInst, ThreadInfo th) {
- //System.err.println("ERROR: symbolic string method not Implemented - EndsWith");
+ //throw new RuntimeException("ERROR: symbolic string method not Implemented - EndsWith");
handleBooleanStringInstructions(invInst, th, StringComparator.ENDSWITH);
}
@@ -1074,7 +923,7 @@ public void handleContains (JVMInvokeInstruction invInst, ThreadInfo th) {
public void handleStartsWith(JVMInvokeInstruction invInst, ThreadInfo th) {
- //System.err.println("ERROR: symbolic string method not Implemented - StartsWith");
+ //throw new RuntimeException("ERROR: symbolic string method not Implemented - StartsWith");
handleBooleanStringInstructions(invInst, th, StringComparator.STARTSWITH);
}
@@ -1086,7 +935,7 @@ public Instruction handleReplace(JVMInvokeInstruction invInst, ThreadInfo th) {
StringExpression sym_v3 = (StringExpression) sf.getOperandAttr(2);
if ((sym_v1 == null) & (sym_v2 == null) & (sym_v3 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleReplace");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleReplace");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -1161,7 +1010,7 @@ public Instruction handleSubString1(JVMInvokeInstruction invInst, ThreadInfo th)
StringExpression sym_v2 = (StringExpression) sf.getOperandAttr(1);
if ((sym_v1 == null) & (sym_v2 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleSubString1");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleSubString1");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -1199,7 +1048,7 @@ public Instruction handleSubString2(JVMInvokeInstruction invInst, ThreadInfo th)
StringExpression sym_v3 = (StringExpression) sf.getOperandAttr(2);
if ((sym_v1 == null) & (sym_v2 == null) & (sym_v3 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleSubString2");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleSubString2");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -1215,7 +1064,7 @@ public Instruction handleSubString2(JVMInvokeInstruction invInst, ThreadInfo th)
/* Only if both arguments are concrete, something else needs
* to be pushed?
*/
- sf.push(s3, true); /* symbolic string element */
+ //sf.push(s3, true); /* symbolic string element */
} else {
if (sym_v3 == null) { // only sym_v2 is symbolic
ElementInfo e3 = th.getElementInfo(s3);
@@ -1266,7 +1115,7 @@ public Instruction handleReplaceFirst(JVMInvokeInstruction invInst, ThreadInfo t
StringExpression sym_v3 = (StringExpression) sf.getOperandAttr(2);
if ((sym_v1 == null) & (sym_v2 == null) & (sym_v3 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HanldeReplaceFirst");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HanldeReplaceFirst");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -1328,7 +1177,7 @@ public Instruction handleReplaceFirst(JVMInvokeInstruction invInst, ThreadInfo t
}
public void handleTrim(JVMInvokeInstruction invInst, ThreadInfo th) {
- // System.err.println("ERROR: symbolic string method not Implemented - Trim");
+ // throw new RuntimeException("ERROR: symbolic string method not Implemented - Trim");
StackFrame sf = th.getModifiableTopFrame();
StringExpression sym_v1 = (StringExpression) sf.getOperandAttr(0);
int s1 = sf.pop();
@@ -1371,7 +1220,7 @@ public Instruction handleValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
} else if (argTypes[0].equals("java.lang.Object")) {
return handleObjectValueOf(invInst, th);
} else {
- System.err.println("ERROR: Input parameter type not handled in Symbolic String ValueOf");
+ throw new RuntimeException("ERROR: Input parameter type not handled in Symbolic String ValueOf");
}
} else { // value of non-string types
if (cname.equals("java.lang.Integer")) {
@@ -1440,7 +1289,7 @@ public Instruction handleValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
handleParseBooleanValueOf(invInst, th);
}
} else {
- System.err.println("ERROR: Type not handled in Symbolic Type ValueOf: " + cname);
+ throw new RuntimeException("ERROR: Type not handled in Symbolic Type ValueOf: " + cname);
}
}
return null;
@@ -1451,7 +1300,7 @@ public void handleParseLongValueOf(JVMInvokeInstruction invInst, ThreadInfo th)
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -1500,9 +1349,9 @@ public void handleParseLongValueOf(JVMInvokeInstruction invInst, ThreadInfo th)
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Long Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
- sf.push(0, true);
+ throw new RuntimeException("ERROR: Long Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true); TODO: needs revision
+ //sf.push(0, true);
}
}
}
@@ -1514,7 +1363,7 @@ public void handleParseBooleanValueOf(JVMInvokeInstruction invInst, ThreadInfo t
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -1563,9 +1412,10 @@ public void handleParseBooleanValueOf(JVMInvokeInstruction invInst, ThreadInfo t
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Boolean Format Type Exception"); // TODO: to review; there should be no backtracking here
- th.getVM().getSystemState().setIgnored(true);
- sf.push(0, true);
+ throw new RuntimeException("ERROR: Boolean Format Type Exception");
+ // TODO: to review; there should be no backtracking here
+ //th.getVM().getSystemState().setIgnored(true);
+ //sf.push(0, true);
}
}
}
@@ -1577,7 +1427,7 @@ public void handleParseIntValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof IntegerExpression) {
IntegerExpression sym_v2 = (IntegerExpression) sym_v3;
@@ -1626,9 +1476,9 @@ public void handleParseIntValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Integer Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
- sf.push(0, true);
+ throw new RuntimeException("ERROR: Integer Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
+ //sf.push(0, true);
}
}
}
@@ -1640,7 +1490,7 @@ public void handleParseInt(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
IntegerExpression result = null;
ChoiceGenerator> cg;
@@ -1680,9 +1530,9 @@ public void handleParseInt(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Integer Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
- sf.push(0, true);
+ throw new RuntimeException("ERROR: Integer Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
+ //sf.push(0, true);
}
}
}
@@ -1694,7 +1544,7 @@ public void handleParseFloat(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
RealExpression result = null;
ChoiceGenerator> cg;
@@ -1733,9 +1583,9 @@ public void handleParseFloat(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Possible Float Format Type Exception - Path Terminated");
- System.out.println("********************************************************");
- th.getVM().getSystemState().setIgnored(true);
+ throw new RuntimeException("ERROR: Possible Float Format Type Exception - Path Terminated");
+
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
}
}
}
@@ -1747,7 +1597,7 @@ public void handleParseFloatValueOf(JVMInvokeInstruction invInst, ThreadInfo th)
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof RealExpression) {
RealExpression sym_v2 = (RealExpression) sym_v3;
@@ -1794,9 +1644,9 @@ public void handleParseFloatValueOf(JVMInvokeInstruction invInst, ThreadInfo th)
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Possible Float Format Type Exception - Path Terminated");
- System.out.println("********************************************************");
- th.getVM().getSystemState().setIgnored(true);
+ throw new RuntimeException("ERROR: Possible Float Format Type Exception - Path Terminated");
+
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
}
}
}
@@ -1809,7 +1659,7 @@ public void handleParseDoubleValueOf(JVMInvokeInstruction invInst, ThreadInfo th
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof RealExpression) {
RealExpression sym_v2 = (RealExpression) sym_v3;
@@ -1857,9 +1707,9 @@ public void handleParseDoubleValueOf(JVMInvokeInstruction invInst, ThreadInfo th
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Double Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
- sf.push(0, true); // TODO: this is very strange code; to review
+ throw new RuntimeException("ERROR: Double Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);
+ //sf.push(0, true); // TODO: to review
}
}
}
@@ -1872,7 +1722,7 @@ public void handleParseDouble(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof RealExpression) {
return;
@@ -1915,8 +1765,8 @@ public void handleParseDouble(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Double Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
+ throw new RuntimeException("ERROR: Double Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
}
}
}
@@ -1928,7 +1778,7 @@ public void handleParseLong(JVMInvokeInstruction invInst, ThreadInfo th) {
Expression sym_v3 = (Expression) sf.getOperandAttr(0);
if (sym_v3 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
if (sym_v3 instanceof IntegerExpression) {
return;
@@ -1971,8 +1821,8 @@ public void handleParseLong(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Long Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
+ throw new RuntimeException("ERROR: Long Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
}
}
}
@@ -1984,7 +1834,7 @@ public void handleParseBoolean(JVMInvokeInstruction invInst, ThreadInfo th) {
StringExpression sym_v1 = (StringExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic method must have symbolic string operand");
+ throw new RuntimeException("ERROR: symbolic method must have symbolic string operand");
} else {
ChoiceGenerator> cg;
boolean conditionValue;
@@ -2023,8 +1873,8 @@ public void handleParseBoolean(JVMInvokeInstruction invInst, ThreadInfo th) {
if (!pc.simplify()) {// not satisfiable
th.getVM().getSystemState().setIgnored(true);
} else {
- System.err.println("ERROR: Boolean Format Type Exception");
- th.getVM().getSystemState().setIgnored(true);
+ throw new RuntimeException("ERROR: Boolean Format Type Exception");
+ //th.getVM().getSystemState().setIgnored(true);TODO: needs revision
}
}
}
@@ -2070,15 +1920,16 @@ public Instruction handleIntValueOf(JVMInvokeInstruction invInst, ThreadInfo th
IntegerExpression sym_v1 = (IntegerExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: handleIntValueOf");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: handleIntValueOf");
} else {
sf.pop();
StringExpression sym_v2 = StringExpression._valueOf(sym_v1);
- int objRef = th.getHeap().newString("", th).getObjectRef(); /*
- * dummy
- * string
- * Object
- */
+ int objRef = th.getHeap().newString("", th).getObjectRef();
+ /*
+ * dummy
+ * string
+ * Object
+ */
sf.push(objRef, true);
sf.setOperandAttr(sym_v2);
}
@@ -2090,7 +1941,7 @@ public Instruction handleFloatValueOf(JVMInvokeInstruction invInst, ThreadInfo t
RealExpression sym_v1 = (RealExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: handleFloatValueOf");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: handleFloatValueOf");
} else {
sf.pop();
StringExpression sym_v2 = StringExpression._valueOf(sym_v1);
@@ -2110,7 +1961,7 @@ public Instruction handleLongValueOf(JVMInvokeInstruction invInst, ThreadInfo th
IntegerExpression sym_v1 = (IntegerExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: handleLongValueOf");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: handleLongValueOf");
} else {
sf.popLong();
StringExpression sym_v2 = StringExpression._valueOf(sym_v1);
@@ -2130,7 +1981,7 @@ public Instruction handleDoubleValueOf(JVMInvokeInstruction invInst, ThreadInfo
RealExpression sym_v1 = (RealExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: handleDoubleValueOf");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: handleDoubleValueOf");
} else {
sf.popLong();
StringExpression sym_v2 = StringExpression._valueOf(sym_v1);
@@ -2150,7 +2001,7 @@ public Instruction handleBooleanValueOf(JVMInvokeInstruction invInst, ThreadInfo
IntegerExpression sym_v1 = (IntegerExpression) sf.getOperandAttr(0);
if (sym_v1 == null) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: handleBooleanValueOf");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: handleBooleanValueOf");
} else {
sf.pop();
StringExpression sym_v2 = StringExpression._valueOf(sym_v1);
@@ -2166,13 +2017,11 @@ public Instruction handleBooleanValueOf(JVMInvokeInstruction invInst, ThreadInfo
}
public Instruction handleCharValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
- System.err.println("ERROR: symbolic string method not Implemented - CharValueOf");
- return null;
+ throw new RuntimeException("ERROR: symbolic string method not Implemented - CharValueOf");
}
public Instruction handleCharArrayValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
- System.err.println("ERROR: symbolic string method not Implemented - CharArrayValueof");
- return null;
+ throw new RuntimeException("ERROR: symbolic string method not Implemented - CharArrayValueof");
}
public Instruction handleObjectValueOf(JVMInvokeInstruction invInst, ThreadInfo th) {
@@ -2200,7 +2049,7 @@ public Instruction handleObjectValueOf(JVMInvokeInstruction invInst, ThreadInfo
sf.push(objRef, true);
sf.setOperandAttr(sym_v2);
} else {
- System.err.println("ERROR: symbolic string method not Implemented - ObjectValueof");
+ throw new RuntimeException("ERROR: symbolic string method not Implemented - ObjectValueof");
}
return null;
}
@@ -2211,7 +2060,7 @@ public Instruction handleConcat(JVMInvokeInstruction invInst, ThreadInfo th) {
StringExpression sym_v2 = (StringExpression) sf.getOperandAttr(1);
if ((sym_v1 == null) & (sym_v2 == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleConcat");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleConcat");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -2229,11 +2078,12 @@ public Instruction handleConcat(JVMInvokeInstruction invInst, ThreadInfo th) {
} else { // both operands are symbolic
result = sym_v2._concat(sym_v1);
}
- int objRef = th.getHeap().newString("", th).getObjectRef(); /*
- * dummy
- * String
- * Object
- */
+ int objRef = th.getHeap().newString("", th).getObjectRef();
+ /*
+ * dummy
+ * String
+ * Object
+ */
sf.push(objRef, true);
sf.setOperandAttr(result);
}
@@ -2248,17 +2098,14 @@ public void handleObjectEquals(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v1 != null) {
// System.out.println("*" + sym_v1.toString());
if (!(sym_v1 instanceof StringExpression)) {
- System.err.println("ERROR: expressiontype not handled: ObjectEquals");
- return;
+ throw new RuntimeException("ERROR: expressiontype not handled: ObjectEquals");
}
}
if (sym_v2 != null) {
// System.out.println("***" + sym_v2.toString());
if (!(sym_v2 instanceof StringExpression)) {
-
- System.err.println("ERROR: expressiontype not handled: ObjectEquals");
- return;
+ throw new RuntimeException("ERROR: expressiontype not handled: ObjectEquals");
}
}
@@ -2322,7 +2169,7 @@ public Instruction handleAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
} else if (argTypes[0].equals("java.lang.Object")) {
handleObjectAppend(invInst, th);
} else {
- System.err.println("ERROR: Input parameter type not handled in Symbolic String Append");
+ throw new RuntimeException("ERROR: Input parameter type not handled in Symbolic String Append");
}
return handled;
@@ -2339,7 +2186,7 @@ public void handleStringAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleStringAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleStringAppend");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -2383,7 +2230,7 @@ public Instruction handleStringAppend3(JVMInvokeInstruction invInst, ThreadInfo
boolean concreteSubstring = (sym_end == null & sym_start == null & sym_string == null);
if (concreteSubstring & sym_builder.getstr() == null) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: HandleStringAppend3");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: HandleStringAppend3");
} else {
int endRef = sf.pop();
int startRef = sf.pop();
@@ -2502,7 +2349,7 @@ public void handleCharAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleCharAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleCharAppend");
} else {
char s1 = (char) sf.pop();
int s2 = sf.pop();
@@ -2535,7 +2382,7 @@ public void handleByteAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleByteAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleByteAppend");
} else {
byte s1 = (byte) sf.pop();
int s2 = sf.pop();
@@ -2568,7 +2415,7 @@ public void handleShortAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleShortAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleShortAppend");
} else {
short s1 = (short) sf.pop();
int s2 = sf.pop();
@@ -2601,7 +2448,7 @@ public void handleIntAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: hanldeIntAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: hanldeIntAppend");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -2634,7 +2481,7 @@ public void handleFloatAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: hanldeFloatAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: hanldeFloatAppend");
} else {
float s1 = Types.intToFloat(sf.pop());
int s2 = sf.pop();
@@ -2666,7 +2513,7 @@ public void handleBooleanAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: hanldeBooleanAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: hanldeBooleanAppend");
} else {
boolean s1 = Types.intToBoolean(sf.pop());
int s2 = sf.pop();
@@ -2709,7 +2556,7 @@ public void handleLongAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleLongAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleLongAppend");
} else {
long s1 = sf.popLong();
int s2 = sf.pop();
@@ -2745,7 +2592,7 @@ public void handleDoubleAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand");
} else {
if (sym_v1 == null) { // operand 0 is concrete
@@ -2784,7 +2631,7 @@ public void handleObjectAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
if (sym_v2 == null)
sym_v2 = new SymbolicStringBuilder();
if ((sym_v1 == null) && (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: handleObjectAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: handleObjectAppend");
} else {
int s1 = sf.pop();
ElementInfo e2 = th.getElementInfo(s1);
@@ -2804,7 +2651,7 @@ public void handleObjectAppend(JVMInvokeInstruction invInst, ThreadInfo th) {
else if (sym_v1 instanceof StringExpression)
sym_v2._append((StringExpression) sym_v1);
else {
- System.err.println("Object not handled in ObjectAppend");
+ throw new RuntimeException("Object not handled in ObjectAppend");
}
// setVariableAttribute(ei, invInst, th, sf, s2, sym_v2); //set the
// value of the attribute of local StringBuilder element as sym_v2
@@ -2815,7 +2662,7 @@ else if (sym_v1 instanceof StringExpression)
else if (sym_v1 instanceof StringExpression)
sym_v2._append((StringExpression) sym_v1);
else {
- System.err.println("Object not handled in ObjectAppend");
+ throw new RuntimeException("Object not handled in ObjectAppend");
}
sf.push(s2, true); /* string Builder element can continue */
@@ -2836,7 +2683,7 @@ public void handleStringBuilderAppend(JVMInvokeInstruction invInst, ThreadInfo t
sym_v1 = new SymbolicStringBuilder();
if ((sym_v1.getstr() == null) & (sym_v2.getstr() == null)) {
- System.err.println("ERROR: symbolic string method must have one symbolic operand: hanldeStringBuilderAppend");
+ throw new RuntimeException("ERROR: symbolic string method must have one symbolic operand: hanldeStringBuilderAppend");
} else {
int s1 = sf.pop();
int s2 = sf.pop();
@@ -2894,8 +2741,7 @@ public String getStringEquiv(ElementInfo ei) {
boolean val = ei.getBooleanField("value");
return Boolean.toString(val);
} else {
- System.err.println("ERROR: Object Type Not Handled in getStringVal");
- return null;
+ throw new RuntimeException("ERROR: Object Type Not Handled in getStringVal");
}
}
@@ -2910,11 +2756,11 @@ public Instruction handletoString(JVMInvokeInstruction invInst, ThreadInfo th)
SymbolicStringBuilder sym_v2 = (SymbolicStringBuilder) sym_obj_v2;
sym_v1 = sym_v2.getstr();
} else {
- System.err.println("ERROR: symbolic type not Handled: toString");
+ throw new RuntimeException("ERROR: symbolic type not Handled: toString");
}
if ((sym_v1 == null)) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: toString");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: toString");
} else {
sf.pop();
ElementInfo ei = th.getHeap().newString("", th);
@@ -2939,7 +2785,7 @@ public void handleprintln(JVMInvokeInstruction invInst, ThreadInfo th, boolean d
}
if ((sym_v1 == null)) {
- System.err.println("ERROR: symbolic string method must have symbolic operand: println");
+ throw new RuntimeException("ERROR: symbolic string method must have symbolic operand: println");
} else {
if (flag)
sf.popLong();
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/IFInstrSymbHelper.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/IFInstrSymbHelper.java
deleted file mode 100644
index e92d99f..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/IFInstrSymbHelper.java
+++ /dev/null
@@ -1,638 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- *
- */
-package gov.nasa.jpf.symbc.bytecode.util;
-
-
-import gov.nasa.jpf.jvm.bytecode.IfInstruction;
-import gov.nasa.jpf.symbc.bytecode.LCMP;
-import gov.nasa.jpf.symbc.numeric.Comparator;
-import gov.nasa.jpf.symbc.numeric.IntegerExpression;
-import gov.nasa.jpf.symbc.numeric.PCChoiceGenerator;
-import gov.nasa.jpf.symbc.numeric.PathCondition;
-import gov.nasa.jpf.symbc.numeric.RealExpression;
-import gov.nasa.jpf.vm.ChoiceGenerator;
-import gov.nasa.jpf.vm.Instruction;
-import gov.nasa.jpf.vm.ThreadInfo;
-import gov.nasa.jpf.vm.Types;
-
-/**
- * @author Kasper S. Luckow
- *
- * Deals with how symbolic conditions are handled. Currently a lot(!!) of redundancy. Furthermore, parts of it
- * are so ugly that my eyes bleed. Should be refactored into a generic method.
- */
-public class IFInstrSymbHelper {
-
- public static Instruction getNextInstructionAndSetPCChoice(ThreadInfo ti,
- LCMP instr,
- IntegerExpression sym_v1,
- IntegerExpression sym_v2,
- Comparator firstComparator,
- Comparator secondComparator,
- Comparator thirdComparator) {
- int conditionValue = -3; //bogus value
- if(!ti.isFirstStepInsn()) { // first time around
- PCChoiceGenerator prevPcGen;
- ChoiceGenerator> cg = ti.getVM().getChoiceGenerator();
- if(cg instanceof PCChoiceGenerator)
- prevPcGen = (PCChoiceGenerator)cg;
- else
- prevPcGen = (PCChoiceGenerator)cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- PathCondition pc;
- if(prevPcGen!=null)
- pc = prevPcGen.getCurrentPC();
- else
- pc = new PathCondition();
-
- PathCondition firstPC = pc.make_copy();
- PathCondition secPC = pc.make_copy();
- PathCondition thirdPC = pc.make_copy();
-
- long v1 = ti.getModifiableTopFrame().peekLong();
- long v2 = ti.getModifiableTopFrame().peekLong(2);
-
- if(sym_v1 != null){
- if(sym_v2 != null){ //both are symbolic values
- firstPC._addDet(firstComparator,sym_v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,sym_v1);
- } else {
- firstPC._addDet(firstComparator,v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,v2);
- thirdPC._addDet(thirdComparator,v2,sym_v1);
- }
- } else {
- firstPC._addDet(firstComparator,sym_v2,v1);
- secPC._addDet(secondComparator,v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,v1);
- }
-
- boolean firstSat = firstPC.simplify();
- boolean secSat = secPC.simplify();
- boolean thirdSat = thirdPC.simplify();
-
- if(firstSat) {
- if(secSat) {
- PCChoiceGenerator newPCChoice;
- if(thirdSat) {
- newPCChoice = new PCChoiceGenerator(3);
- } else {
- //LE (choice 0) == true, EQ (choice 1)== true
- newPCChoice = new PCChoiceGenerator(2);
- }
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else if(thirdSat) {
- //LE (choice 0) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(0, 2, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- prevPcGen.setCurrentPC(firstPC);
- conditionValue = -1;
- }
- } else if(secSat) {
- if(thirdSat) {
- //EQ (choice 1) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(1, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- conditionValue = 0;
- }
- } else if(thirdSat) {
- conditionValue = 1;
- } else {
- System.err.println("***********Warning: everything false");
- ti.getVM().getSystemState().setIgnored(true);
- }
-
- } else { //This branch will only be taken if there is a choice
-
- long v1 = ti.getModifiableTopFrame().peekLong();
- long v2 = ti.getModifiableTopFrame().peekLong(2);
- PathCondition pc;
- PCChoiceGenerator curCg = (PCChoiceGenerator)ti.getVM().getSystemState().getChoiceGenerator();
-
- PCChoiceGenerator prevCg = curCg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if(prevCg == null )
- pc = new PathCondition();
- else
- pc = ((PCChoiceGenerator)prevCg).getCurrentPC();
-
- conditionValue = ((PCChoiceGenerator) curCg).getNextChoice() -1;
- if (conditionValue == -1) {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(firstComparator, sym_v2, sym_v1);
- } else
- pc._addDet(firstComparator, v2, sym_v1);
- } else
- pc._addDet(firstComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else if (conditionValue == 0){
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(secondComparator, sym_v1, sym_v2);
- } else
- pc._addDet(secondComparator, sym_v1, v2);
- } else
- pc._addDet(secondComparator, v1, sym_v2);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else {// 1
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(thirdComparator, sym_v2, sym_v1);
- } else
- pc._addDet(thirdComparator, v2, sym_v1);
- } else
- pc._addDet(thirdComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- }
- }
- ti.getModifiableTopFrame().popLong();
- ti.getModifiableTopFrame().popLong();
- ti.getModifiableTopFrame().push(conditionValue, false);
- return instr.getNext(ti);
- }
-
- public static Instruction getNextInstructionAndSetPCChoiceFloat(ThreadInfo ti,
- Instruction instr,
- RealExpression sym_v1,
- RealExpression sym_v2,
- Comparator firstComparator,
- Comparator secondComparator,
- Comparator thirdComparator) {
- int conditionValue = -3; //bogus value
- if(!ti.isFirstStepInsn()) { // first time around
- PCChoiceGenerator prevPcGen;
- ChoiceGenerator> cg = ti.getVM().getChoiceGenerator();
- if(cg instanceof PCChoiceGenerator)
- prevPcGen = (PCChoiceGenerator)cg;
- else
- prevPcGen = (PCChoiceGenerator)cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- PathCondition pc;
- if(prevPcGen!=null)
- pc = prevPcGen.getCurrentPC();
- else
- pc = new PathCondition();
-
- PathCondition firstPC = pc.make_copy();
- PathCondition secPC = pc.make_copy();
- PathCondition thirdPC = pc.make_copy();
-
- float v1 = Types.intToFloat(ti.getModifiableTopFrame().peek());
- float v2 = Types.intToFloat(ti.getModifiableTopFrame().peek(1));
-
- if(sym_v1 != null){
- if(sym_v2 != null){ //both are symbolic values
- firstPC._addDet(firstComparator,sym_v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,sym_v1);
- } else {
- firstPC._addDet(firstComparator,v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,v2);
- thirdPC._addDet(thirdComparator,v2,sym_v1);
- }
- } else {
- firstPC._addDet(firstComparator,sym_v2,v1);
- secPC._addDet(secondComparator,v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,v1);
- }
-
- boolean firstSat = firstPC.simplify();
- boolean secSat = secPC.simplify();
- boolean thirdSat = thirdPC.simplify();
-
- if(firstSat) {
- if(secSat) {
- PCChoiceGenerator newPCChoice;
- if(thirdSat) {
- newPCChoice = new PCChoiceGenerator(3);
- } else {
- //LE (choice 0) == true, EQ (choice 1)== true
- newPCChoice = new PCChoiceGenerator(2);
- }
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else if(thirdSat) {
- //LE (choice 0) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(0, 2, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- prevPcGen.setCurrentPC(firstPC);
- conditionValue = -1;
- }
- } else if(secSat) {
- if(thirdSat) {
- //EQ (choice 1) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(1, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- conditionValue = 0;
- }
- } else if(thirdSat) {
- conditionValue = 1;
- } else {
- System.err.println("***********Warning: everything false");
- ti.getVM().getSystemState().setIgnored(true);
- }
- } else { //This branch will only be taken if there is a choice
-
- float v1 = Types.intToFloat(ti.getModifiableTopFrame().peek());
- float v2 = Types.intToFloat(ti.getModifiableTopFrame().peek(1));
- PathCondition pc;
- PCChoiceGenerator curCg = (PCChoiceGenerator)ti.getVM().getSystemState().getChoiceGenerator();
-
- PCChoiceGenerator prevCg = curCg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if(prevCg == null )
- pc = new PathCondition();
- else
- pc = prevCg.getCurrentPC();
-
- conditionValue = ((PCChoiceGenerator) curCg).getNextChoice() -1;
- if (conditionValue == -1) {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(firstComparator, sym_v2, sym_v1);
- } else
- pc._addDet(firstComparator, v2, sym_v1);
- } else
- pc._addDet(firstComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else if (conditionValue == 0){
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(secondComparator, sym_v1, sym_v2);
- } else
- pc._addDet(secondComparator, sym_v1, v2);
- } else
- pc._addDet(secondComparator, v1, sym_v2);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else {// 1
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(thirdComparator, sym_v2, sym_v1);
- } else
- pc._addDet(thirdComparator, v2, sym_v1);
- } else
- pc._addDet(thirdComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- }
- }
- ti.getModifiableTopFrame().pop();
- ti.getModifiableTopFrame().pop();
- ti.getModifiableTopFrame().push(conditionValue, false);
- return instr.getNext(ti);
-
- }
-
- public static Instruction getNextInstructionAndSetPCChoiceDouble(ThreadInfo ti,
- Instruction instr,
- RealExpression sym_v1,
- RealExpression sym_v2,
- Comparator firstComparator,
- Comparator secondComparator,
- Comparator thirdComparator) {
- int conditionValue = -3; //bogus value
-
- if(!ti.isFirstStepInsn()) { // first time around
- PCChoiceGenerator prevPcGen;
- ChoiceGenerator> cg = ti.getVM().getChoiceGenerator();
- if(cg instanceof PCChoiceGenerator)
- prevPcGen = (PCChoiceGenerator)cg;
- else
- prevPcGen = (PCChoiceGenerator)cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- PathCondition pc;
- if(prevPcGen!=null)
- pc = prevPcGen.getCurrentPC();
- else
- pc = new PathCondition();
-
- PathCondition firstPC = pc.make_copy();
- PathCondition secPC = pc.make_copy();
- PathCondition thirdPC = pc.make_copy();
-
- double v1 = Types.longToDouble(ti.getModifiableTopFrame().peekLong());
- double v2 = Types.longToDouble(ti.getModifiableTopFrame().peekLong(2));
-
- if(sym_v1 != null){
- if(sym_v2 != null){ //both are symbolic values
- firstPC._addDet(firstComparator,sym_v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,sym_v1);
- } else {
- firstPC._addDet(firstComparator,v2,sym_v1);
- secPC._addDet(secondComparator,sym_v1,v2);
- thirdPC._addDet(thirdComparator,v2,sym_v1);
- }
- } else {
- firstPC._addDet(firstComparator,sym_v2,v1);
- secPC._addDet(secondComparator,v1,sym_v2);
- thirdPC._addDet(thirdComparator,sym_v2,v1);
- }
-
- boolean firstSat = firstPC.simplify();
- boolean secSat = secPC.simplify();
- boolean thirdSat = thirdPC.simplify();
-
- if(firstSat) {
- if(secSat) {
- PCChoiceGenerator newPCChoice;
- if(thirdSat) {
- newPCChoice = new PCChoiceGenerator(3);
- } else {
- //LE (choice 0) == true, EQ (choice 1)== true
- newPCChoice = new PCChoiceGenerator(2);
- }
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else if(thirdSat) {
- //LE (choice 0) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(0, 2, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- conditionValue = -1;
- }
- } else if(secSat) {
- if(thirdSat) {
- //EQ (choice 1) == true, GT (choice 2)== true
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(1, 2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- conditionValue = 0;
- }
- } else if(thirdSat) {
- conditionValue = 1;
- } else {
- System.err.println("***********Warning: everything false");
- ti.getVM().getSystemState().setIgnored(true);
- }
- } else { //This branch will only be taken if there is a choice
-
- double v1 = Types.longToDouble(ti.getModifiableTopFrame().peekLong());
- double v2 = Types.longToDouble(ti.getModifiableTopFrame().peekLong(2));
-
- PathCondition pc;
- PCChoiceGenerator curCg = (PCChoiceGenerator)ti.getVM().getSystemState().getChoiceGenerator();
-
- PCChoiceGenerator prevCg = curCg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if(prevCg == null )
- pc = new PathCondition();
- else
- pc = prevCg.getCurrentPC();
-
- conditionValue = ((PCChoiceGenerator) curCg).getNextChoice() -1;
- if (conditionValue == -1) {
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(firstComparator, sym_v2, sym_v1);
- } else
- pc._addDet(firstComparator, v2, sym_v1);
- } else
- pc._addDet(firstComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else if (conditionValue == 0){
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(secondComparator, sym_v1, sym_v2);
- } else
- pc._addDet(secondComparator, sym_v1, v2);
- } else
- pc._addDet(secondComparator, v1, sym_v2);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- } else {// 1
- if (sym_v1 != null) {
- if (sym_v2 != null) { // both are symbolic values
- pc._addDet(thirdComparator, sym_v2, sym_v1);
- } else
- pc._addDet(thirdComparator, v2, sym_v1);
- } else
- pc._addDet(thirdComparator, sym_v2, v1);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- }
- }
- ti.getModifiableTopFrame().popLong();
- ti.getModifiableTopFrame().popLong();
- ti.getModifiableTopFrame().push(conditionValue, false);
- return instr.getNext(ti);
- }
-
-
-
- public static Instruction getNextInstructionAndSetPCChoice(ThreadInfo ti,
- IfInstruction instr,
- IntegerExpression sym_v,
- Comparator trueComparator,
- Comparator falseComparator) {
-
- //TODO: fix conditionValue
- if(!ti.isFirstStepInsn()) { // first time around
- PCChoiceGenerator prevPcGen;
- ChoiceGenerator> cg = ti.getVM().getChoiceGenerator();
- if(cg instanceof PCChoiceGenerator)
- prevPcGen = (PCChoiceGenerator)cg;
- else
- prevPcGen = (PCChoiceGenerator)cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- PathCondition pc;
- if(prevPcGen!=null)
- pc = prevPcGen.getCurrentPC();
- else
- pc = new PathCondition();
-
- PathCondition eqPC = pc.make_copy();
- PathCondition nePC = pc.make_copy();
- eqPC._addDet(trueComparator, sym_v, 0);
- nePC._addDet(falseComparator, sym_v, 0);
-
- boolean eqSat = eqPC.simplify();
- boolean neSat = nePC.simplify();
-
- if(eqSat) {
- if(neSat) {
- PCChoiceGenerator newPCChoice;
- newPCChoice = new PCChoiceGenerator(2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- ti.getModifiableTopFrame().pop();
- return instr.getTarget();
- }
- } else {
- ti.getModifiableTopFrame().pop();
- return instr.getNext(ti);
- }
- } else {
- ti.getModifiableTopFrame().pop();
- PathCondition pc;
- PCChoiceGenerator curCg = (PCChoiceGenerator)ti.getVM().getSystemState().getChoiceGenerator();
-
- PCChoiceGenerator prevCg = curCg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if(prevCg == null )
- pc = new PathCondition();
- else
- pc = prevCg.getCurrentPC();
- boolean conditionValue = (Integer)curCg.getNextChoice()==1 ? true: false;
- if(conditionValue) {
- pc._addDet(trueComparator, sym_v, 0);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- return instr.getTarget();
- } else {
- pc._addDet(falseComparator, sym_v, 0);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- return instr.getNext(ti);
- }
- }
- }
-
- public static Instruction getNextInstructionAndSetPCChoice(ThreadInfo ti,
- IfInstruction instr,
- IntegerExpression sym_v1,
- IntegerExpression sym_v2,
- Comparator trueComparator,
- Comparator falseComparator) {
-
- //TODO: fix conditionValue
- if(!ti.isFirstStepInsn()) { // first time around
- PCChoiceGenerator prevPcGen;
- ChoiceGenerator> cg = ti.getVM().getChoiceGenerator();
- if(cg instanceof PCChoiceGenerator)
- prevPcGen = (PCChoiceGenerator)cg;
- else
- prevPcGen = (PCChoiceGenerator)cg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- PathCondition pc;
- if(prevPcGen!=null)
- pc = prevPcGen.getCurrentPC();
- else
- pc = new PathCondition();
-
- PathCondition eqPC = pc.make_copy();
- PathCondition nePC = pc.make_copy();
-
- int v2 = ti.getModifiableTopFrame().peek();
- int v1 = ti.getModifiableTopFrame().peek(1);
-
- if(sym_v1 != null){
- if(sym_v2 != null){ //both are symbolic values
- eqPC._addDet(trueComparator,sym_v1,sym_v2);
- nePC._addDet(falseComparator,sym_v1,sym_v2);
- } else {
- eqPC._addDet(trueComparator,sym_v1,v2);
- nePC._addDet(falseComparator,sym_v1,v2);
- }
- } else {
- eqPC._addDet(trueComparator, v1, sym_v2);
- nePC._addDet(falseComparator, v1, sym_v2);
- }
-
- boolean eqSat = eqPC.simplify();
- boolean neSat = nePC.simplify();
-
- if(eqSat) {
- if(neSat) {
- PCChoiceGenerator newPCChoice = new PCChoiceGenerator(2);
- newPCChoice.setOffset(instr.getPosition());
- newPCChoice.setMethodName(instr.getMethodInfo().getFullName());
- ti.getVM().getSystemState().setNextChoiceGenerator(newPCChoice);
- return instr;
- } else {
- ti.getModifiableTopFrame().pop();
- ti.getModifiableTopFrame().pop();
- return instr.getTarget();
- }
- } else {
- ti.getModifiableTopFrame().pop();
- ti.getModifiableTopFrame().pop();
- return instr.getNext(ti);
- }
- } else { //This branch will only be taken if there is a choice
-
- int v2 = ti.getModifiableTopFrame().pop();
- int v1 = ti.getModifiableTopFrame().pop();
- PathCondition pc;
- PCChoiceGenerator curCg = (PCChoiceGenerator)ti.getVM().getSystemState().getChoiceGenerator();
-
- PCChoiceGenerator prevCg = curCg.getPreviousChoiceGeneratorOfType(PCChoiceGenerator.class);
-
- if(prevCg == null )
- pc = new PathCondition();
- else
- pc = prevCg.getCurrentPC();
-
- boolean conditionValue = (Integer)curCg.getNextChoice()==1 ? true: false;
- if(conditionValue) {
- if(sym_v1 != null){
- if(sym_v2 != null){ //both are symbolic values
- pc._addDet(trueComparator,sym_v1,sym_v2);
- } else
- pc._addDet(trueComparator,sym_v1,v2);
- } else
- pc._addDet(trueComparator, v1, sym_v2);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- return instr.getTarget();
- } else {
- if(sym_v1 != null){
- if (sym_v2 != null){ //both are symbolic values
- pc._addDet(falseComparator,sym_v1,sym_v2);
- } else
- pc._addDet(falseComparator,sym_v1,v2);
- } else
- pc._addDet(falseComparator, v1, sym_v2);
- ((PCChoiceGenerator) curCg).setCurrentPC(pc);
- return instr.getNext(ti);
- }
- }
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/PCChoiceGeneratorException.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/PCChoiceGeneratorException.java
deleted file mode 100644
index c49417c..0000000
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/bytecode/util/PCChoiceGeneratorException.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2014, United States Government, as represented by the
- * Administrator of the National Aeronautics and Space Administration.
- * All rights reserved.
- *
- * Symbolic Pathfinder (jpf-symbc) is licensed under the Apache License,
- * Version 2.0 (the "License"); you may not use this file except
- * in compliance with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0.
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-/**
- *
- */
-package gov.nasa.jpf.symbc.bytecode.util;
-
-
-import java.io.PrintStream;
-
-/**
- * @author Kasper S. Luckow
- *
- */
-public class PCChoiceGeneratorException extends RuntimeException {
- public PCChoiceGeneratorException (String details) {
- super(details);
- }
-
- public PCChoiceGeneratorException (Throwable cause) {
- super(cause);
- }
-
- public PCChoiceGeneratorException (String details, Throwable cause){
- super(details, cause);
- }
-
- public void printStackTrace (PrintStream out) {
- out.println("---------------------- Symbc JPF error stack trace ---------------------");
- super.printStackTrace(out);
- }
-}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/concolic/FunctionExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/concolic/FunctionExpression.java
index e80e15a..2d43e36 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/concolic/FunctionExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/concolic/FunctionExpression.java
@@ -38,17 +38,14 @@
package gov.nasa.jpf.symbc.concolic;
// support for arbitrary external functions
-
-import gov.nasa.jpf.symbc.numeric.Constraint;
import gov.nasa.jpf.symbc.numeric.ConstraintExpressionVisitor;
import gov.nasa.jpf.symbc.numeric.Expression;
import gov.nasa.jpf.symbc.numeric.IntegerExpression;
import gov.nasa.jpf.symbc.numeric.PathCondition;
import gov.nasa.jpf.symbc.numeric.RealExpression;
import gov.nasa.jpf.util.FileUtils;
-import gov.nasa.jpf.vm.ClassInfo;
import gov.nasa.jpf.vm.ClassLoaderInfo;
-
+
import java.util.ArrayList;
import java.util.Map;
import java.lang.reflect.*;
@@ -114,7 +111,7 @@ public double solution()
Object[] args = new Object[sym_args.length];
for (int i=0; i 0);
- final RealExpression e = (RealExpression)sym_args[0];// for now assume only real expressions; TODO the integer expressions
+ RealExpression e = (RealExpression)sym_args[0];// for now assume only real expressions; TODO the integer expressions
RealConstraint c = new RealConstraint(e, Comparator.EQ, new RealConstant(e.solution()));
for(int i=1; i {
- public static LinkedList trackedSymVars = new LinkedList();
- public abstract String stringPC();
- public abstract void getVarsVals(Map varsVals);
- public abstract void accept(ConstraintExpressionVisitor visitor);
-}
+
+//Copyright (C) 2005 United States Government as represented by the
+//Administrator of the National Aeronautics and Space Administration
+//(NASA). All Rights Reserved.
+
+//This software is distributed under the NASA Open Source Agreement
+//(NOSA), version 1.3. The NOSA has been approved by the Open Source
+//Initiative. See the file NOSA-1.3-JPF at the top of the distribution
+//directory tree for the complete NOSA document.
+
+//THE SUBJECT SOFTWARE IS PROVIDED "AS IS" WITHOUT ANY WARRANTY OF ANY
+//KIND, EITHER EXPRESSED, IMPLIED, OR STATUTORY, INCLUDING, BUT NOT
+//LIMITED TO, ANY WARRANTY THAT THE SUBJECT SOFTWARE WILL CONFORM TO
+//SPECIFICATIONS, ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR
+//A PARTICULAR PURPOSE, OR FREEDOM FROM INFRINGEMENT, ANY WARRANTY THAT
+//THE SUBJECT SOFTWARE WILL BE ERROR FREE, OR ANY WARRANTY THAT
+//DOCUMENTATION, IF PROVIDED, WILL CONFORM TO THE SUBJECT SOFTWARE.
+
+
+package gov.nasa.jpf.symbc.numeric;
+
+
+import java.util.Map;
+import java.util.LinkedList;
+
+
+public abstract class Expression implements Comparable {
+ public static LinkedList trackedSymVars = new LinkedList();
+ public abstract String stringPC();
+ public abstract void getVarsVals(Map varsVals);
+ public abstract void accept(ConstraintExpressionVisitor visitor);
+ public String prefix_notation() {throw new RuntimeException("error printing");}
+
+}
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerConstant.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerConstant.java
index ef420c9..3462ce8 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerConstant.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerConstant.java
@@ -38,29 +38,25 @@
package gov.nasa.jpf.symbc.numeric;
import java.util.Map;
+
import static gov.nasa.jpf.symbc.numeric.Operator.*;
public class IntegerConstant extends LinearIntegerExpression {
- public int value;
+ public long value;
- public IntegerConstant (int i) {
- value = i;
+ public IntegerConstant (long i) {
+ value = i;
}
- public IntegerExpression _minus (int i) {
- //simplify
+ public IntegerExpression _minus (long i) {
if (i == 0)
return this;
-
- return new IntegerConstant(value - i);
+ return new IntegerConstant(value - i);
}
- public IntegerExpression _minus_reverse (int i) {
+ public IntegerExpression _minus_reverse (long i) {
return new IntegerConstant(i - value);
}
- public IntegerExpression _minus_reverse (long i) {
- return new IntegerConstant((int) i - value);
- }
public IntegerExpression _minus (IntegerExpression e) {
//simplify
@@ -79,7 +75,7 @@ public IntegerExpression _minus (IntegerExpression e) {
}
}
- public IntegerExpression _div (int i) {
+ public IntegerExpression _div (long i) {
//simplify
if (i == 1)
return this;
@@ -87,16 +83,10 @@ public IntegerExpression _div (int i) {
return new IntegerConstant(value / i);
}
- public IntegerExpression _div_reverse (int i) {
- //simplify
- assert (value !=0);
- return new IntegerConstant(i / value);
- }
-
public IntegerExpression _div_reverse (long i) {
- //simplify
+ //simplify
assert (value !=0);
- return new IntegerConstant((int) i / value);
+ return new IntegerConstant(i / value);
}
public IntegerExpression _div (IntegerExpression e) {
@@ -115,7 +105,7 @@ public IntegerExpression _div (IntegerExpression e) {
return super._div(e);
}
- public IntegerExpression _mul (int i) {
+ public IntegerExpression _mul (long i) {
//simplify
if (i == 1)
return this;
@@ -145,7 +135,7 @@ public IntegerExpression _mul (IntegerExpression e) {
}
- public IntegerExpression _plus (int i) {
+ public IntegerExpression _plus (long i) {
//simplify
if (i == 0)
return this;
@@ -176,19 +166,11 @@ public IntegerExpression _neg ()
return super._neg();
}
-
- public IntegerExpression _and (int i) {
- if (i == 0) {
- return new IntegerConstant(0);
- }
- return new IntegerConstant(value & i);
- }
-
public IntegerExpression _and (long i) {
if (i == 0) {
return new IntegerConstant(0);
}
- return new IntegerConstant(value & ((int) i));
+ return new IntegerConstant(value & i);
}
public IntegerExpression _and (IntegerExpression e) {
@@ -201,18 +183,11 @@ public IntegerExpression _and (IntegerExpression e) {
return new BinaryLinearIntegerExpression(this, AND, e);
}
- public IntegerExpression _or (int i) {
- if (i == 0) {
- return this;
- }
- return new IntegerConstant(value | i);
- }
-
public IntegerExpression _or (long i) {
if (i == 0) {
return this;
}
- return new IntegerConstant(value | ((int) i));
+ return new IntegerConstant(value | i);
}
public IntegerExpression _or (IntegerExpression e) {
@@ -225,12 +200,8 @@ public IntegerExpression _or (IntegerExpression e) {
return new BinaryLinearIntegerExpression(this, OR, e);
}
- public IntegerExpression _xor (int i) {
- return new IntegerConstant(value ^ i);
- }
-
public IntegerExpression _xor (long i) {
- return new IntegerConstant(value ^ ((int) i));
+ return new IntegerConstant(value ^ i);
}
public IntegerExpression _xor (IntegerExpression e) {
@@ -241,12 +212,8 @@ public IntegerExpression _xor (IntegerExpression e) {
}
- public IntegerExpression _shiftL (int i) {
- return new IntegerConstant(value << i);
- }
-
public IntegerExpression _shiftL (long i) {
- return new IntegerConstant(value << ((int) i));
+ return new IntegerConstant(value << i);
}
public IntegerExpression _shiftL (IntegerExpression e) {
@@ -256,12 +223,8 @@ public IntegerExpression _shiftL (IntegerExpression e) {
return new BinaryLinearIntegerExpression(this, SHIFTL, e);
}
- public IntegerExpression _shiftR (int i) {
- return new IntegerConstant(value >> i);
- }
-
public IntegerExpression _shiftR (long i) {
- return new IntegerConstant(value >> ((int) i));
+ return new IntegerConstant(value >> i);
}
public IntegerExpression _shiftR (IntegerExpression e) {
@@ -271,12 +234,8 @@ public IntegerExpression _shiftR (IntegerExpression e) {
return new BinaryLinearIntegerExpression(this, SHIFTR, e);
}
- public IntegerExpression _shiftUR (int i) {
- return new IntegerConstant(value >>> i);
- }
-
public IntegerExpression _shiftUR (long i) {
- return new IntegerConstant(value >>> ((int) i));
+ return new IntegerConstant(value >>> i);
}
public IntegerExpression _shiftUR (IntegerExpression e) {
@@ -296,24 +255,49 @@ public boolean equals (Object o) {
}
@Override
- public int hashCode() {
- return value;
+ public int hashCode() { // analogous to java.lang.Long
+ return (int)(this.value^(value>>>32));
}
public String toString () {
return "CONST_" + value + "";
}
-
+
+ public String prefix_notation ()
+ {
+ return ""+value;
+ }
+
public String stringPC () {
return "CONST_" + value + "";
}
public int value () {
- return value;
+ return (int) value;
}
- public int solution() {
- return value;
+ public long solution() { // to be fixed
+ return value;
+ }
+
+ public int solutionInt() {
+ assert(value>=Integer.MIN_VALUE && value<=Integer.MAX_VALUE);
+ return (int) value;
+ }
+
+ public short solutionShort() {
+ assert(value>=Short.MIN_VALUE && value<=Short.MAX_VALUE);
+ return (short) value;
+ }
+
+ public byte solutionByte() {
+ assert(value>=Byte.MIN_VALUE && value<=Byte.MAX_VALUE);
+ return (byte) value;
+ }
+
+ public char solutionChar() {
+ assert(value>=Character.MIN_VALUE && value<=Character.MAX_VALUE);
+ return (char) value;
}
public void getVarsVals(Map varsVals) {}
@@ -329,8 +313,8 @@ public void accept(ConstraintExpressionVisitor visitor) {
public int compareTo(Expression expr) {
if (expr instanceof IntegerConstant) {
IntegerConstant e = (IntegerConstant) expr;
- int a = value();
- int b = e.value();
+ long a = value();
+ long b = e.value();
return (a < b) ? -1 : (a > b) ? 1 : 0;
} else {
return getClass().getCanonicalName().compareTo(expr.getClass().getCanonicalName());
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerExpression.java
index 2f4807e..6211cc2 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/IntegerExpression.java
@@ -45,12 +45,12 @@ public abstract class IntegerExpression extends Expression {
//returns -1 if (this < i), 0 if equal and 1 otherwise
public IntegerExpression _cmp (long i)
{
- return new BinaryNonLinearIntegerExpression(this, CMP, new IntegerConstant((int)i));
+ return new BinaryNonLinearIntegerExpression(this, CMP, new IntegerConstant(i));
}
public IntegerExpression _cmp_reverse (long i)
{
- return new BinaryNonLinearIntegerExpression(new IntegerConstant((int)i), CMP, this);
+ return new BinaryNonLinearIntegerExpression(new IntegerConstant(i), CMP, this);
}
public IntegerExpression _cmp (IntegerExpression e)
@@ -60,12 +60,12 @@ public IntegerExpression _cmp (IntegerExpression e)
//------------------------------------------------------
- public IntegerExpression _minus_reverse (int i)
+ public IntegerExpression _minus_reverse (long i)
{
return new BinaryNonLinearIntegerExpression(new IntegerConstant(i), MINUS, this);
}
- public IntegerExpression _minus (int i)
+ public IntegerExpression _minus (long i)
{
//simplify
if (i == 0)
@@ -87,7 +87,7 @@ public IntegerExpression _minus (IntegerExpression e)
return new BinaryNonLinearIntegerExpression(this, MINUS, e);
}
- public IntegerExpression _mul (int i)
+ public IntegerExpression _mul (long i)
{
//simplify
if (i == 1)
@@ -112,7 +112,7 @@ public IntegerExpression _mul (IntegerExpression e)
return new BinaryNonLinearIntegerExpression(this, MUL, e);
}
- public IntegerExpression _plus (int i)
+ public IntegerExpression _plus (long i)
{
//simplify
if (i == 0)
@@ -189,61 +189,62 @@ public IntegerExpression _xor(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, XOR, e);
}
- public IntegerExpression _shiftR(int i)
+ public IntegerExpression _shiftR(long i)
{
if(i == 0)
return this;
return new BinaryNonLinearIntegerExpression(this, SHIFTR,
- new IntegerConstant((int) i));
+ new IntegerConstant( i));
}
- public IntegerExpression _shiftL(int i) {
+ public IntegerExpression _shiftL(long i) {
if(i == 0)
return this;
return new BinaryNonLinearIntegerExpression(this, SHIFTL,
- new IntegerConstant((int) i));
+ new IntegerConstant( i));
}
- public IntegerExpression _shiftUR(int i) {
+ public IntegerExpression _shiftUR(long i) {
if(i == 0)
return this;
return new BinaryNonLinearIntegerExpression(this, SHIFTUR,
- new IntegerConstant((int) i));
+ new IntegerConstant( i));
}
- public IntegerExpression _and(int i)
+ public IntegerExpression _and(long i)
{
if(i == 0)
return new IntegerConstant(0);
- return new BinaryNonLinearIntegerExpression(this, AND, new IntegerConstant((int)i));
+ return new BinaryNonLinearIntegerExpression(this, AND, new IntegerConstant(i));
}
- public IntegerExpression _or(int i)
+ public IntegerExpression _or(long i)
{
if(i == 0)
return this;
- return new BinaryNonLinearIntegerExpression(this, OR, new IntegerConstant((int) i));
+ return new BinaryNonLinearIntegerExpression(this, OR, new IntegerConstant( i));
}
- public IntegerExpression _xor(int i)
+ public IntegerExpression _xor(long i)
{
- return new BinaryNonLinearIntegerExpression(this, XOR, new IntegerConstant((int) i));
+ return new BinaryNonLinearIntegerExpression(this, XOR, new IntegerConstant( i));
}
- public IntegerExpression _rem(int i)
+ public IntegerExpression _rem(long i)
{
- throw new RuntimeException( "## Error: Operation not supported!" );
- }
+ return new BinaryNonLinearIntegerExpression(this, REM, new IntegerConstant( i));
+ }
- public IntegerExpression _rem_reverse(int i)
- {
- throw new RuntimeException( "## Error: Operation not supported!" );
- }
+ public IntegerExpression _rem_reverse(long i)
+ {
+ //throw new RuntimeException( "## Error: Operation not supported!" );
+ return new BinaryNonLinearIntegerExpression(new IntegerConstant( i), REM, this);
+ }
public IntegerExpression _rem(IntegerExpression i)
{
- throw new RuntimeException( "## Error: Operation not supported!" );
+ return new BinaryNonLinearIntegerExpression(this, REM, i);
}
public IntegerExpression _neg()
@@ -251,45 +252,7 @@ public IntegerExpression _neg()
return new BinaryNonLinearIntegerExpression(new IntegerConstant(0), MINUS, this);
}
- /*
- * Additional support for longs so that we are not downcasting in the
- * individual bytecodes
- */
- public IntegerExpression _minus_reverse (long i)
- {
- return new BinaryNonLinearIntegerExpression(new IntegerConstant((int)i), MINUS, this);
- }
-
- public IntegerExpression _minus (long i)
- {
- //simplify
- if (i == 0)
- return this;
- return new BinaryNonLinearIntegerExpression(this, MINUS, new IntegerConstant((int)i));
- }
-
- public IntegerExpression _mul (long i)
- {
- //simplify
- if (i == 1)
- return this;
- if (i == 0)
- return new IntegerConstant(0);
-
- return new BinaryNonLinearIntegerExpression(this, MUL, new IntegerConstant((int)i));
- }
-
- public IntegerExpression _plus (long i)
- {
- //simplify
- if (i == 0)
- return this;
- return new BinaryNonLinearIntegerExpression(this, PLUS, new IntegerConstant((int)i));
- }
-
-
-
- public IntegerExpression _div (int i)
+ public IntegerExpression _div (long i)
{
// simplify
assert (i != 0);
@@ -313,84 +276,25 @@ public IntegerExpression _div (IntegerExpression e)
return new BinaryNonLinearIntegerExpression(this, DIV, e);
}
- public IntegerExpression _div_reverse (int i)
- {
- if (i == 0)
- return new IntegerConstant(0);
- return new BinaryNonLinearIntegerExpression(new IntegerConstant(i), DIV, this);
- }
-
- public IntegerExpression _div (long i)
- {
- // simplify
- assert (i != 0);
- if (i == 1)
- return this;
- return new BinaryNonLinearIntegerExpression(this, DIV, new IntegerConstant((int)i));
- }
-
public IntegerExpression _div_reverse (long i)
{
if (i == 0)
return new IntegerConstant(0);
- return new BinaryNonLinearIntegerExpression(new IntegerConstant((int)i), DIV, this);
- }
-
- public IntegerExpression _and(long i) {
- if (i == 0)
- return new IntegerConstant(0);
-
- return new BinaryNonLinearIntegerExpression(this, AND, new IntegerConstant((int)i));
- }
-
- public IntegerExpression _or(long i) {
- if (i == 0)
- return this;
-
- return new BinaryNonLinearIntegerExpression(this, OR, new IntegerConstant((int)i));
- }
-
- public IntegerExpression _xor(long i) {
- return new BinaryNonLinearIntegerExpression(this, XOR, new IntegerConstant((int)i));
- }
-
- public IntegerExpression _shiftR(long i) {
- if (i == 0)
- return this;
-
- return new BinaryNonLinearIntegerExpression(this, SHIFTR,
- new IntegerConstant((int)i));
- }
-
- public IntegerExpression _shiftL(long i) {
- if (i == 0)
- return this;
-
- return new BinaryNonLinearIntegerExpression(this, SHIFTL,
- new IntegerConstant((int)i));
- }
-
- public IntegerExpression _shiftUR(long i) {
- if (i == 0)
- return this;
-
- return new BinaryNonLinearIntegerExpression(this, SHIFTUR,
- new IntegerConstant((int)i));
-
- }
-
- public IntegerExpression _rem(long i)
- {
- throw new RuntimeException( "## Error: Operation not supported!" );
+ return new BinaryNonLinearIntegerExpression(new IntegerConstant(i), DIV, this);
}
//TODO test this
- public int solution() {
+ public long solution() {
throw new RuntimeException( "## Error: Expression Solution request Error: " + this);
//System.out.println("Expression Solution request Error: " + this);
//return -666;
}
-
+ public int solutionInt() {
+ throw new RuntimeException( "## Error: Expression Solution request Error: " + this);
+ }
+ public char solutionChar() {
+ throw new RuntimeException( "## Error: Expression Solution request Error: " + this);
+ }
//protected void finalize() throws Throwable {
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/LinearIntegerExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/LinearIntegerExpression.java
index e246910..4c9ab4b 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/LinearIntegerExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/LinearIntegerExpression.java
@@ -39,31 +39,19 @@
import static gov.nasa.jpf.symbc.numeric.Operator.*;
abstract class LinearIntegerExpression extends IntegerExpression
-{
- public IntegerExpression _minus_reverse (int i)
- {
- return new BinaryLinearIntegerExpression(new IntegerConstant(i), MINUS, this);
- }
+{
public IntegerExpression _minus_reverse (long i)
{
- return new BinaryLinearIntegerExpression(new IntegerConstant((int)i), MINUS, this);
+ return new BinaryLinearIntegerExpression(new IntegerConstant(i), MINUS, this);
}
- public IntegerExpression _minus (int i) {
- //simplify
- if (i == 0)
- return this;
-
- return new BinaryLinearIntegerExpression(this, MINUS, new IntegerConstant(i));
- }
-
public IntegerExpression _minus (long i) {
//simplify
if (i == 0)
return this;
- return new BinaryLinearIntegerExpression(this, MINUS, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, MINUS, new IntegerConstant(i));
}
public IntegerExpression _minus (IntegerExpression e) {
@@ -83,16 +71,6 @@ public IntegerExpression _minus (IntegerExpression e) {
}
}
- public IntegerExpression _mul (int i) {
- //simplify
- if (i == 1)
- return this;
- if (i == 0)
- return new IntegerConstant(0);
-
- return new BinaryLinearIntegerExpression(this, MUL, new IntegerConstant(i));
- }
-
public IntegerExpression _mul (long i) {
//simplify
if (i == 1)
@@ -100,12 +78,11 @@ public IntegerExpression _mul (long i) {
if (i == 0)
return new IntegerConstant(0);
- return new BinaryLinearIntegerExpression(this, MUL, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, MUL, new IntegerConstant(i));
}
public IntegerExpression _mul (IntegerExpression e)
- {
-
+ {
//simplify
if (e instanceof IntegerConstant) {
IntegerConstant ic = (IntegerConstant)e;
@@ -123,7 +100,7 @@ public IntegerExpression _mul (IntegerExpression e)
}
- public IntegerExpression _div (int i)
+ public IntegerExpression _div (long i)
{
// simplify
assert (i != 0);
@@ -149,23 +126,6 @@ public IntegerExpression _div (IntegerExpression e)
return super._div(e);
}
- public IntegerExpression _div_reverse (int i)
- {
- if (i == 0)
- return new IntegerConstant(0);
- return super._div(i);
- }
-
- public IntegerExpression _div (long i)
- {
- // simplify
- assert (i != 0);
- if (i == 1)
- return this;
-
- return new BinaryLinearIntegerExpression(this, DIV, new IntegerConstant((int)i));
- }
-
public IntegerExpression _div_reverse (long i)
{
if (i == 0)
@@ -173,20 +133,12 @@ public IntegerExpression _div_reverse (long i)
return super._div(i);
}
- public IntegerExpression _plus (int i) {
- //simplify
- if (i == 0)
- return this;
-
- return new BinaryLinearIntegerExpression(this, PLUS, new IntegerConstant(i));
- }
-
public IntegerExpression _plus (long i) {
//simplify
if (i == 0)
return this;
- return new BinaryLinearIntegerExpression(this, PLUS, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, PLUS, new IntegerConstant(i));
}
public IntegerExpression _plus (IntegerExpression e) {
@@ -209,18 +161,11 @@ public IntegerExpression _neg()
return new BinaryLinearIntegerExpression(new IntegerConstant(0), MINUS, this);
}
- public IntegerExpression _and(int i) {
- if(i == 0) {
- return new IntegerConstant(0);
- }
- return new BinaryLinearIntegerExpression(this, AND, new IntegerConstant(i));
- }
-
public IntegerExpression _and(long i) {
if(i == 0) {
return new IntegerConstant(0);
}
- return new BinaryLinearIntegerExpression(this, AND, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, AND, new IntegerConstant(i));
}
public IntegerExpression _and(IntegerExpression e) {
@@ -237,18 +182,11 @@ public IntegerExpression _and(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, AND, e);
}
- public IntegerExpression _or(int i) {
- if(i == 0) {
- return this;
- }
- return new BinaryLinearIntegerExpression(this, OR, new IntegerConstant(i));
- }
-
public IntegerExpression _or(long i) {
if(i == 0) {
return this;
}
- return new BinaryLinearIntegerExpression(this, OR, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, OR, new IntegerConstant(i));
}
public IntegerExpression _or(IntegerExpression e) {
@@ -265,12 +203,8 @@ public IntegerExpression _or(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, OR, e);
}
- public IntegerExpression _xor(int i) {
- return new BinaryLinearIntegerExpression(this, XOR, new IntegerConstant(i));
- }
-
public IntegerExpression _xor(long i) {
- return new BinaryLinearIntegerExpression(this, XOR, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, XOR, new IntegerConstant(i));
}
public IntegerExpression _xor(IntegerExpression e) {
@@ -283,18 +217,11 @@ public IntegerExpression _xor(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, XOR, e);
}
- public IntegerExpression _shiftR(int i) {
- if(i == 0) {
- return this;
- }
- return new BinaryLinearIntegerExpression(this, SHIFTR, new IntegerConstant(i));
- }
-
public IntegerExpression _shiftR(long i) {
if(i == 0) {
return this;
}
- return new BinaryLinearIntegerExpression(this, SHIFTR, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, SHIFTR, new IntegerConstant(i));
}
public IntegerExpression _shiftR(IntegerExpression e) {
@@ -311,18 +238,11 @@ public IntegerExpression _shiftR(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, SHIFTR, e);
}
- public IntegerExpression _shiftUR(int i) {
- if(i == 0) {
- return this;
- }
- return new BinaryLinearIntegerExpression(this, SHIFTUR, new IntegerConstant(i));
- }
-
public IntegerExpression _shiftUR(long i) {
if(i == 0) {
return this;
}
- return new BinaryLinearIntegerExpression(this, SHIFTUR, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, SHIFTUR, new IntegerConstant(i));
}
public IntegerExpression _shiftUR(IntegerExpression e) {
@@ -339,18 +259,11 @@ public IntegerExpression _shiftUR(IntegerExpression e) {
return new BinaryNonLinearIntegerExpression(this, SHIFTUR, e);
}
- public IntegerExpression _shiftL(int i) {
- if(i == 0) {
- return this;
- }
- return new BinaryLinearIntegerExpression(this, SHIFTL, new IntegerConstant(i));
- }
-
public IntegerExpression _shiftL(long i) {
if(i == 0) {
return this;
}
- return new BinaryLinearIntegerExpression(this, SHIFTL, new IntegerConstant((int)i));
+ return new BinaryLinearIntegerExpression(this, SHIFTL, new IntegerConstant(i));
}
public IntegerExpression _shiftL(IntegerExpression e) {
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MathRealExpression.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MathRealExpression.java
index e9b0f5f..0b07f0c 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MathRealExpression.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MathRealExpression.java
@@ -46,10 +46,9 @@ public class MathRealExpression extends RealExpression
public MathFunction op;
//int exp; // for power
- public MathRealExpression (final MathFunction o, final RealExpression a)
+ public MathRealExpression (MathFunction o, RealExpression a)
{
- assert
- o == MathFunction.ABS || //Added for dReal by Nima
+ assert
o == MathFunction.SIN || o == MathFunction.COS ||
o == MathFunction.EXP ||
o == MathFunction.ASIN || o == MathFunction.ACOS ||
@@ -70,7 +69,7 @@ public MathRealExpression (final MathFunction o, final RealExpression a)
//
// }
- public MathRealExpression (final MathFunction o, final RealExpression a1, final double a2)
+ public MathRealExpression (MathFunction o, RealExpression a1, double a2)
{
assert
o == MathFunction.POW || o == MathFunction.ATAN2;
@@ -80,7 +79,7 @@ public MathRealExpression (final MathFunction o, final RealExpression a1, final
}
- public MathRealExpression (final MathFunction o, final double a1, final RealExpression a2)
+ public MathRealExpression (MathFunction o, double a1, RealExpression a2)
{
assert
o == MathFunction.POW || o == MathFunction.ATAN2;
@@ -89,7 +88,7 @@ public MathRealExpression (final MathFunction o, final double a1, final RealExpr
arg2 = a2;
}
- public MathRealExpression (final MathFunction o, final RealExpression a1, final RealExpression a2)
+ public MathRealExpression (MathFunction o, RealExpression a1, RealExpression a2)
{
assert
o == MathFunction.POW || o == MathFunction.ATAN2;
@@ -111,13 +110,11 @@ public MathFunction getOp() {
return op;
}
- @Override
- public double solution()
+ public double solution()
{
- final double a1 = (arg1==null?0:arg1.solution());
- final double a2 = (arg2==null?0:arg2.solution());
- switch(op){
- case ABS: return Math.abs(a1); // Added for dReal by Nima
+ double a1 = (arg1==null?0:arg1.solution());
+ double a2 = (arg2==null?0:arg2.solution());
+ switch(op){
case COS: return Math.cos(a1);
case SIN: return Math.sin(a1);
case EXP: return Math.exp(a1);
@@ -134,16 +131,13 @@ public double solution()
}
}
- @Override
- public void getVarsVals(final Map varsVals) {
+ public void getVarsVals(Map varsVals) {
if (arg1 != null) arg1.getVarsVals(varsVals);
if (arg2 != null) arg2.getVarsVals(varsVals);
}
- @Override
- public String stringPC() {
- if (op == MathFunction.ABS || //Added for dReal by Nima
- op == MathFunction.SIN || op == MathFunction.COS ||
+ public String stringPC() {
+ if (op == MathFunction.SIN || op == MathFunction.COS ||
op == MathFunction.EXP ||
op == MathFunction.ASIN || op == MathFunction.ACOS ||
op == MathFunction.ATAN || op == MathFunction.LOG ||
@@ -153,10 +147,8 @@ public String stringPC() {
return "(" + op.toString() + "(" + arg1.stringPC() + "," + arg2.stringPC() + "))";
}
- @Override
- public String toString () {
- if (op == MathFunction.ABS || //Added for dReal by Nima
- op == MathFunction.SIN || op == MathFunction.COS ||
+ public String toString () {
+ if (op == MathFunction.SIN || op == MathFunction.COS ||
op == MathFunction.EXP ||
op == MathFunction.ASIN || op == MathFunction.ACOS ||
op == MathFunction.ATAN || op == MathFunction.LOG ||
@@ -167,7 +159,7 @@ public String toString () {
}
@Override
- public void accept(final ConstraintExpressionVisitor visitor) {
+ public void accept(ConstraintExpressionVisitor visitor) {
visitor.preVisit(this);
if (arg1 != null) {
arg1.accept(visitor);
@@ -179,9 +171,9 @@ public void accept(final ConstraintExpressionVisitor visitor) {
}
@Override
- public int compareTo(final Expression expr) {
+ public int compareTo(Expression expr) {
if (expr instanceof MathRealExpression) {
- final MathRealExpression e = (MathRealExpression) expr;
+ MathRealExpression e = (MathRealExpression) expr;
int r = getOp().compareTo(e.getOp());
if (r == 0) {
if (getArg1() != null) {
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MinMax.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MinMax.java
index 3293949..3744aa0 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MinMax.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/MinMax.java
@@ -57,36 +57,77 @@ public class MinMax {
public static void reset() {
UniqueId = 0;
}
-
+
/**
* Lower bound on symbolic integer variables.
*/
- private static int minInt = -1000000;
+ private static int minInt = Integer.MIN_VALUE;
/**
* Upper bound on symbolic integer variables.
*/
- private static int maxInt = 1000000;
+ private static int maxInt = Integer.MAX_VALUE;
+
+ /**
+ * Lower bound on symbolic byte variables.
+ */
+ private static byte minByte = Byte.MIN_VALUE;
+
+ /**
+ * Upper bound on symbolic short variables.
+ */
+ private static byte maxByte = Byte.MAX_VALUE;
+
+
+ /**
+ * Lower bound on symbolic short variables.
+ */
+ private static short minShort = Short.MIN_VALUE;
+
+ /**
+ * Upper bound on symbolic short variables.
+ */
+ private static short maxShort = Short.MAX_VALUE;
+
+ /**
+ * Lower bound on symbolic long variables.
+ */
+ private static long minLong = Long.MIN_VALUE;
+
+ /**
+ * Upper bound on symbolic long variables.
+ */
+ private static long maxLong = Long.MAX_VALUE;
+
+ /**
+ * Lower bound on symbolic integer variables.
+ */
+ private static int minChar = Character.MIN_VALUE;
+ /**
+ * Upper bound on symbolic integer variables.
+ */
+ private static int maxChar = Character.MAX_VALUE;
+
/**
* Lower bound on symbolic real variables.
*/
- private static double minDouble = -8;
+ private static double minDouble = Double.MIN_VALUE; //-8;
/**
* Upper bound on symbolic real variables.
*/
- private static double maxDouble = 7;
+ private static double maxDouble = Double.MAX_VALUE; //7;
/**
* Mapping from variable names to minimum integer values.
*/
- private static Map varMinIntMap;
+ private static Map varMinIntMap;
/**
* Mapping from variable names to maximum integer values.
*/
- private static Map varMaxIntMap;
+ private static Map varMaxIntMap;
/**
* Mapping from variable names to minimum real values.
@@ -134,6 +175,50 @@ public static void collectMinMaxInformation(Config config) {
maxInt = x;
}
assert minInt < maxInt : "Illegal integer range";
+
+ long y = config.getLong("symbolic.min_long", Long.MAX_VALUE);
+ if (y != Long.MAX_VALUE) {
+ minLong = y;
+ }
+
+ y = config.getLong("symbolic.max_long", Long.MIN_VALUE);
+ if (y != Long.MIN_VALUE) {
+ maxLong = y;
+ }
+ assert minLong < maxLong : "Illegal long range";
+
+ short s = (short) config.getInt("symbolic.min_short", Short.MAX_VALUE);
+ if (s != Short.MAX_VALUE) {
+ minShort = s;
+ }
+
+ s = (short) config.getInt("symbolic.max_short", Short.MIN_VALUE);
+ if (s != Short.MIN_VALUE) {
+ maxShort = s;
+ }
+ assert minShort < maxShort : "Illegal short range";
+
+ byte b = (byte) config.getInt("symbolic.min_byte", Byte.MAX_VALUE);
+ if (b != Byte.MAX_VALUE) {
+ minByte = b;
+ }
+
+ b = (byte) config.getInt("symbolic.max_byte", Byte.MIN_VALUE);
+ if (b != Byte.MIN_VALUE) {
+ maxByte = b;
+ }
+ assert minByte < maxByte : "Illegal byte range";
+
+ char c = (char) config.getInt("symbolic.min_char", Character.MAX_VALUE);
+ if (c != Character.MAX_VALUE) {
+ minChar = c;
+ }
+
+ c = (char) config.getInt("symbolic.max_char", Character.MIN_VALUE);
+ if (c != Character.MIN_VALUE) {
+ maxChar = c;
+ }
+ assert minChar < maxChar : "Illegal char range";
double z = config.getDouble("symbolic.min_double", Double.MAX_VALUE);
if (z != Double.MAX_VALUE) {
@@ -147,34 +232,34 @@ public static void collectMinMaxInformation(Config config) {
assert minDouble < maxDouble : "Illegal double range";
// Collect specific integer bounds by variable name
- varMinIntMap = new HashMap();
- varMaxIntMap = new HashMap();
+ varMinIntMap = new HashMap();
+ varMaxIntMap = new HashMap();
int prefixLength = "symbolic.min_int_".length();
for (String k : config.getKeysStartingWith("symbolic.min_int_")) {
String name = k.substring(prefixLength);
- x = config.getInt(k, Integer.MAX_VALUE);
- if (x != Integer.MAX_VALUE) {
- varMinIntMap.put(name, x);
+ y = config.getLong(k, Long.MAX_VALUE);
+ if (y != Long.MAX_VALUE) {
+ varMinIntMap.put(name, y);
}
}
for (String k : config.getKeysStartingWith("symbolic.max_int_")) {
String name = k.substring(prefixLength);
- x = config.getInt(k, Integer.MIN_VALUE);
- if (x != Integer.MIN_VALUE) {
- varMaxIntMap.put(name, x);
+ y = config.getLong(k, Long.MIN_VALUE);
+ if (y != Long.MIN_VALUE) {
+ varMaxIntMap.put(name, y);
}
}
for (String k : varMinIntMap.keySet()) {
- int min = varMinIntMap.get(k);
- int max = maxInt;
+ long min = varMinIntMap.get(k);
+ long max = maxInt;
if (varMaxIntMap.containsKey(k)) {
max = varMaxIntMap.get(k);
}
assert min < max : "Illegal range for \"" + k + "\"";
}
for (String k : varMaxIntMap.keySet()) {
- int min = minInt;
- int max = varMaxIntMap.get(k);
+ long min = minInt;
+ long max = varMaxIntMap.get(k);
if (varMinIntMap.containsKey(k)) {
min = varMinIntMap.get(k);
}
@@ -218,11 +303,19 @@ public static void collectMinMaxInformation(Config config) {
// Display the bounds collected from the configuration
System.out.println("symbolic.min_int=" + minInt);
+ System.out.println("symbolic.min_long=" + minLong);
+ System.out.println("symbolic.min_short=" + minShort);
+ System.out.println("symbolic.min_byte=" + minByte);
+ System.out.println("symbolic.min_char=" + minChar);
for (String k : varMinIntMap.keySet()) {
System.out.println("symbolic.min_int_" + k + "="
+ varMinIntMap.get(k));
}
System.out.println("symbolic.max_int=" + maxInt);
+ System.out.println("symbolic.max_long=" + maxLong);
+ System.out.println("symbolic.max_short=" + maxShort);
+ System.out.println("symbolic.max_byte=" + maxByte);
+ System.out.println("symbolic.max_char=" + maxChar);
for (String k : varMaxIntMap.keySet()) {
System.out.println("symbolic.max_int_" + k + "="
+ varMaxIntMap.get(k));
@@ -239,30 +332,118 @@ public static void collectMinMaxInformation(Config config) {
}
}
+ private static long getVarMin(String varname, long min) {
+ if (varname.endsWith("_SYMINT")) {
+ varname = varname.replaceAll("_[0-9][0-9]*_SYMINT", "");
+ }
+ return varMinIntMap!=null && varMinIntMap.containsKey(varname) ? varMinIntMap.get(varname) : min;
+ }
+
/**
* Return the minimum integer value that a given variable can assume.
*
* @param varname the name of the variable
* @return the minimum value of the variable
*/
- public static int getVarMinInt(String varname) {
+ public static long getVarMinInt(String varname) {
+ return getVarMin(varname,minInt);
+ }
+
+ /**
+ * Return the minimum long value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the minimum value of the variable
+ */
+ public static long getVarMinLong(String varname) {
+ return getVarMin(varname,minLong);
+ }
+
+ /**
+ * Return the minimum short value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the minimum value of the variable
+ */
+ public static long getVarMinShort(String varname) {
+ return getVarMin(varname,minShort);
+ }
+
+ /**
+ * Return the minimum byte value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the minimum value of the variable
+ */
+ public static long getVarMinByte(String varname) {
+ return getVarMin(varname,minByte);
+ }
+
+ /**
+ * Return the minimum char value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the minimum value of the variable
+ */
+ public static long getVarMinChar(String varname) {
+ return getVarMin(varname,minChar);
+ }
+
+ private static long getVarMax(String varname, long max) {
if (varname.endsWith("_SYMINT")) {
varname = varname.replaceAll("_[0-9][0-9]*_SYMINT", "");
}
- return varMinIntMap!=null && varMinIntMap.containsKey(varname) ? varMinIntMap.get(varname) : minInt;
+ return varMaxIntMap!=null && varMaxIntMap.containsKey(varname) ? varMaxIntMap.get(varname) : max;
}
-
+
/**
* Return the maximum integer value that a given variable can assume.
*
* @param varname the name of the variable
* @return the maximum value of the variable
*/
- public static int getVarMaxInt(String varname) {
- if (varname.endsWith("_SYMINT")) {
- varname = varname.replaceAll("_[0-9][0-9]*_SYMINT", "");
- }
- return varMaxIntMap!=null && varMaxIntMap.containsKey(varname) ? varMaxIntMap.get(varname) : maxInt;
+ public static long getVarMaxInt(String varname) {
+ return getVarMax(varname,maxInt);
+ }
+
+ /**
+ * Return the maximum long value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the maximum value of the variable
+ */
+ public static long getVarMaxLong(String varname) {
+ return getVarMax(varname,maxLong);
+ }
+
+ /**
+ * Return the maximum short value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the maximum value of the variable
+ */
+ public static long getVarMaxShort(String varname) {
+ return getVarMax(varname,maxShort);
+ }
+
+ /**
+ * Return the maximum byte value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the maximum value of the variable
+ */
+ public static long getVarMaxByte(String varname) {
+ return getVarMax(varname,maxByte);
+ }
+
+ /**
+ * Return the maximum char value that a given variable can assume.
+ *
+ * @param varname the name of the variable
+ * @return the maximum value of the variable
+ */
+ public static long getVarMaxChar(String varname) {
+ return getVarMax(varname,maxChar);
}
/**
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/Operator.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/Operator.java
index be250e6..10e90f9 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/Operator.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/Operator.java
@@ -49,7 +49,8 @@ public enum Operator{
XOR(" ^ "),
SHIFTL("<<"),
SHIFTR(">>"),
- SHIFTUR(">>>");
+ SHIFTUR(">>>"),
+ REM(" % ");
@@ -62,5 +63,10 @@ public enum Operator{
@Override
public String toString() {
return str;
+ }
+
+ public String prefix_notation() {
+ // TODO Auto-generated method stub
+ return str;
}
}
\ No newline at end of file
diff --git a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/PCParser.java b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/PCParser.java
index bd0be8c..82af05c 100644
--- a/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/PCParser.java
+++ b/jpf-symbc/src/main/gov/nasa/jpf/symbc/numeric/PCParser.java
@@ -37,890 +37,918 @@
package gov.nasa.jpf.symbc.numeric;
-import java.util.ArrayList;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
+import gov.nasa.jpf.symbc.SymbolicInstructionFactory;
import gov.nasa.jpf.symbc.arrays.ArrayConstraint;
import gov.nasa.jpf.symbc.arrays.ArrayExpression;
-import gov.nasa.jpf.symbc.arrays.IntegerSymbolicArray;
-import gov.nasa.jpf.symbc.arrays.RealSymbolicArray;
import gov.nasa.jpf.symbc.arrays.RealArrayConstraint;
import gov.nasa.jpf.symbc.arrays.RealStoreExpression;
import gov.nasa.jpf.symbc.arrays.SelectExpression;
import gov.nasa.jpf.symbc.arrays.StoreExpression;
+import gov.nasa.jpf.symbc.numeric.solvers.IncrementalListener;
+import gov.nasa.jpf.symbc.numeric.solvers.IncrementalSolver;
import gov.nasa.jpf.symbc.numeric.solvers.ProblemCoral;
import gov.nasa.jpf.symbc.numeric.solvers.ProblemGeneral;
+
+
+
+
+
import gov.nasa.jpf.symbc.numeric.solvers.ProblemZ3;
+import gov.nasa.jpf.symbc.numeric.solvers.ProblemZ3BitVector;
+import gov.nasa.jpf.symbc.numeric.solvers.ProblemZ3BitVectorIncremental;
+import gov.nasa.jpf.symbc.numeric.solvers.ProblemZ3Incremental;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import java.util.Map.Entry;
// parses PCs
public class PCParser {
- static ProblemGeneral pb;
- static public Map symRealVar; // a map between symbolic real variables and DP variables
- static Map symIntegerVar; // a map between symbolic variables and DP variables
- //static Boolean result; // tells whether result is satisfiable or not
- static int tempVars = 0; //Used to construct "or" clauses
-
- // Converts IntegerExpression's into DP's IntExp's
- static Object getExpression(final IntegerExpression eRef) {
- assert eRef != null;
- assert !(eRef instanceof IntegerConstant);
-
- if (eRef instanceof SymbolicInteger) {
-
- Object dp_var = symIntegerVar.get(eRef);
- if (dp_var == null) {
- dp_var = pb.makeIntVar(((SymbolicInteger)eRef).getName(),
- ((SymbolicInteger)eRef)._min, ((SymbolicInteger)eRef)._max);
- symIntegerVar.put((SymbolicInteger)eRef, dp_var);
- }
- return dp_var;
- }
-
- Operator opRef;
- IntegerExpression e_leftRef;
- IntegerExpression e_rightRef;
-
- if(eRef instanceof BinaryLinearIntegerExpression) {
- opRef = ((BinaryLinearIntegerExpression)eRef).op;
- e_leftRef = ((BinaryLinearIntegerExpression)eRef).left;
- e_rightRef = ((BinaryLinearIntegerExpression)eRef).right;
- } else { // bin non lin expr
- if(pb instanceof ProblemCoral) {
- opRef = ((BinaryNonLinearIntegerExpression)eRef).op;
- e_leftRef = ((BinaryNonLinearIntegerExpression)eRef).left;
- e_rightRef = ((BinaryNonLinearIntegerExpression)eRef).right;
- }
- else
- throw new RuntimeException("## Error: Binary Non Linear Expression " + eRef);
- }
- switch(opRef){
- case PLUS:
- if (e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.plus(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.plus(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else
- return pb.plus(getExpression(e_leftRef),getExpression(e_rightRef));
- case MINUS:
- if (e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.minus(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.minus(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else
- return pb.minus(getExpression(e_leftRef),getExpression(e_rightRef));
- case MUL:
- if (e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.mult(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.mult(((IntegerConstant)e_rightRef).value,getExpression(e_leftRef));
- else {
- if(pb instanceof ProblemCoral)
- return pb.mult(getExpression(e_leftRef),getExpression(e_rightRef));
- else
- throw new RuntimeException("## Error: Binary Non Linear Operation");
- }
- case DIV:
- if (e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant) // TODO: this might not be linear
- return pb.div(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.div(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else {
- if(pb instanceof ProblemCoral)
- return pb.div(getExpression(e_leftRef),getExpression(e_rightRef));
- else
- throw new RuntimeException("## Error: Binary Non Linear Operation");
- }
- case AND:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.and(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.and(((IntegerConstant)e_rightRef).value,getExpression(e_leftRef));
- else
- return pb.and(getExpression(e_leftRef),getExpression(e_rightRef));
- case OR:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.or(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.or(((IntegerConstant)e_rightRef).value,getExpression(e_leftRef));
- else
- return pb.or(getExpression(e_leftRef),getExpression(e_rightRef));
- case XOR:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.xor(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.xor(((IntegerConstant)e_rightRef).value,getExpression(e_leftRef));
- else
- return pb.xor(getExpression(e_leftRef),getExpression(e_rightRef));
- case SHIFTR:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.shiftR(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.shiftR(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else
- return pb.shiftR(getExpression(e_leftRef),getExpression(e_rightRef));
- case SHIFTUR:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.shiftUR(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.shiftUR(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else
- return pb.shiftUR(getExpression(e_leftRef),getExpression(e_rightRef));
- case SHIFTL:
- if(e_leftRef instanceof IntegerConstant && e_rightRef instanceof IntegerConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof IntegerConstant)
- return pb.shiftL(((IntegerConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof IntegerConstant)
- return pb.shiftL(getExpression(e_leftRef),((IntegerConstant)e_rightRef).value);
- else
- return pb.shiftL(getExpression(e_leftRef),getExpression(e_rightRef));
- default:
- throw new RuntimeException("## Error: Binary Non Linear Operation");
- }
-
-
- }
-
-
- // Converts RealExpression's into DP RealExp's
- static Object getExpression(final RealExpression eRef) {
- assert eRef != null;
- assert !(eRef instanceof RealConstant);
-
- if (eRef instanceof SymbolicReal) {
- Object dp_var = symRealVar.get(eRef);
- if (dp_var == null) {
- dp_var = pb.makeRealVar(((SymbolicReal)eRef).getName(),
- ((SymbolicReal)eRef)._min, ((SymbolicReal)eRef)._max);
- symRealVar.put((SymbolicReal)eRef, dp_var);
- }
- return dp_var;
- }
-
- if(eRef instanceof BinaryRealExpression) {
- Operator opRef;
- RealExpression e_leftRef;
- RealExpression e_rightRef;
- opRef = ((BinaryRealExpression)eRef).op;
- e_leftRef = ((BinaryRealExpression)eRef).left;
- e_rightRef = ((BinaryRealExpression)eRef).right;
-
- switch(opRef){
- case PLUS:
- if (e_leftRef instanceof RealConstant && e_rightRef instanceof RealConstant)
- return pb.constant(((RealConstant)e_leftRef).value + ((RealConstant)e_rightRef).value);
- //throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof RealConstant)
- return pb.plus(((RealConstant)e_leftRef).value, getExpression(e_rightRef));
- else if (e_rightRef instanceof RealConstant)
- return pb.plus(getExpression(e_leftRef),((RealConstant)e_rightRef).value);
- else
- return pb.plus(getExpression(e_leftRef),getExpression(e_rightRef));
- case MINUS:
- if (e_leftRef instanceof RealConstant && e_rightRef instanceof RealConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof RealConstant)
- return pb.minus(((RealConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof RealConstant)
- return pb.minus(getExpression(e_leftRef),((RealConstant)e_rightRef).value);
- else
- return pb.minus(getExpression(e_leftRef),getExpression(e_rightRef));
- case MUL:
- if (e_leftRef instanceof RealConstant && e_rightRef instanceof RealConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof RealConstant)
- return pb.mult(((RealConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof RealConstant)
- return pb.mult(((RealConstant)e_rightRef).value,getExpression(e_leftRef));
- else
- return pb.mult(getExpression(e_leftRef),getExpression(e_rightRef));
- case DIV:
- if (e_leftRef instanceof RealConstant && e_rightRef instanceof RealConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof RealConstant)
- return pb.div(((RealConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof RealConstant)
- return pb.div(getExpression(e_leftRef),((RealConstant)e_rightRef).value);
- else
- return pb.div(getExpression(e_leftRef),getExpression(e_rightRef));
- case AND:
- if (e_leftRef instanceof RealConstant && e_rightRef instanceof RealConstant)
- throw new RuntimeException("## Error: this is not a symbolic expression"); //
- else if (e_leftRef instanceof RealConstant)
- return pb.and(((RealConstant)e_leftRef).value,getExpression(e_rightRef));
- else if (e_rightRef instanceof RealConstant)
- return pb.and(((RealConstant)e_rightRef).value,getExpression(e_leftRef));
- else
- return pb.and(getExpression(e_leftRef),getExpression(e_rightRef));
-
- default:
- throw new RuntimeException("## Error: Expression " + eRef);
- }
- }
-
- if(eRef instanceof MathRealExpression) {
- MathFunction funRef;
- RealExpression e_arg1Ref;
- RealExpression e_arg2Ref;
-
- funRef = ((MathRealExpression)eRef).op;
- e_arg1Ref = ((MathRealExpression)eRef).arg1;
- e_arg2Ref = ((MathRealExpression)eRef).arg2;
- switch(funRef){
- case ABS: return pb.abs(getExpression(e_arg1Ref)); //Added for dReal by Nima
- case SIN: return pb.sin(getExpression(e_arg1Ref));
- case COS: return pb.cos(getExpression(e_arg1Ref));
- case EXP: return pb.exp(getExpression(e_arg1Ref));
- case ASIN: return pb.asin(getExpression(e_arg1Ref));
- case ACOS:return pb.acos(getExpression(e_arg1Ref));
- case ATAN: return pb.atan(getExpression(e_arg1Ref));
- case LOG:return pb.log(getExpression(e_arg1Ref));
- case TAN:return pb.tan(getExpression(e_arg1Ref));
- case SQRT:return pb.sqrt(getExpression(e_arg1Ref));
- case POW:
- if (e_arg2Ref instanceof RealConstant)
- return pb.power(getExpression(e_arg1Ref),((RealConstant)e_arg2Ref).value);
- else if (e_arg1Ref instanceof RealConstant)
- return pb.power(((RealConstant)e_arg1Ref).value,getExpression(e_arg2Ref));
- else
- return pb.power(getExpression(e_arg1Ref),getExpression(e_arg2Ref));
- case ATAN2:
- if (e_arg2Ref instanceof RealConstant)
- return pb.atan2(getExpression(e_arg1Ref),((RealConstant)e_arg2Ref).value);
- else if (e_arg1Ref instanceof RealConstant)
- return pb.atan2(((RealConstant)e_arg1Ref).value,getExpression(e_arg2Ref));
- else
- return pb.atan2(getExpression(e_arg1Ref),getExpression(e_arg2Ref));
- default:
- throw new RuntimeException("## Error: Expression " + eRef);
- }
- }
-
- throw new RuntimeException("## Error: Expression " + eRef);
- }
-
- //public Map getSymRealVar() {
- //return symRealVar;
- //}
-
-
- //public Map getSymIntegerVar() {
- //return symIntegerVar;
- //}
-
-
- static public boolean createDPMixedConstraint(final MixedConstraint cRef) { // TODO
-
- final Comparator c_compRef = cRef.getComparator();
- final RealExpression c_leftRef = (RealExpression)cRef.getLeft();
- final IntegerExpression c_rightRef = (IntegerExpression)cRef.getRight();
- assert (c_compRef == Comparator.EQ);
-
- if (c_leftRef instanceof SymbolicReal && c_rightRef instanceof SymbolicInteger) {
- //pb.post(new MixedEqXY((RealVar)(getExpression(c_leftRef)),(IntDomainVar)(getExpression(c_rightRef))));
- pb.post(pb.mixed(getExpression(c_leftRef),getExpression(c_rightRef)));
- }
- else if (c_leftRef instanceof SymbolicReal) { // c_rightRef is an IntegerExpression
- final Object tmpi = pb.makeIntVar(c_rightRef + "_" + c_rightRef.hashCode(),(int)(((SymbolicReal)c_leftRef)._min), (int)(((SymbolicReal)c_leftRef)._max));
- if (c_rightRef instanceof IntegerConstant)
- pb.post(pb.eq(((IntegerConstant)c_rightRef).value,tmpi));
- else
- pb.post(pb.eq(getExpression(c_rightRef),tmpi));
- //pb.post(new MixedEqXY((RealVar)(getExpression(c_leftRef)),tmpi));
- pb.post(pb.mixed(getExpression(c_leftRef),tmpi));
-
- }
- else if (c_rightRef instanceof SymbolicInteger) { // c_leftRef is a RealExpression
- final Object tmpr = pb.makeRealVar(c_leftRef + "_" + c_leftRef.hashCode(), ((SymbolicInteger)c_rightRef)._min, ((SymbolicInteger)c_rightRef)._max);
- if(c_leftRef instanceof RealConstant)
- pb.post(pb.eq(tmpr, ((RealConstant)c_leftRef).value));
- else
- pb.post(pb.eq(tmpr, getExpression(c_leftRef)));
- //pb.post(new MixedEqXY(tmpr,(IntDomainVar)(getExpression(c_rightRef))));
- pb.post(pb.mixed(tmpr,getExpression(c_rightRef)));
- }
- else
- assert(false); // should not be reachable
-
- return true;
- }
-
- static public boolean createDPRealConstraint(final RealConstraint cRef) {
-
- final Comparator c_compRef = cRef.getComparator();
- final RealExpression c_leftRef = (RealExpression)cRef.getLeft();
- final RealExpression c_rightRef = (RealExpression)cRef.getRight();
-
- switch(c_compRef){
- case EQ:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value == ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.eq(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.eq(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.eq(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- case NE:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value != ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.neq(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.neq(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.neq(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- case LT:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value < ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.lt(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.lt(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.lt(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- case GE:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value >= ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.geq(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.geq(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.geq(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- case LE:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value <= ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.leq(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.leq(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.leq(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- case GT:
- if (c_leftRef instanceof RealConstant && c_rightRef instanceof RealConstant) {
- if (!(((RealConstant) c_leftRef).value > ((RealConstant) c_rightRef).value))
- return false;
- else
- return true;
- }
- else if (c_leftRef instanceof RealConstant) {
- pb.post(pb.gt(((RealConstant)c_leftRef).value,getExpression(c_rightRef)));
- }
- else if (c_rightRef instanceof RealConstant) {
- pb.post(pb.gt(getExpression(c_leftRef),((RealConstant)c_rightRef).value));
- }
- else
- pb.post(pb.gt(getExpression(c_leftRef),getExpression(c_rightRef)));
- break;
- }
- return true;
- }
-
- //Added by Gideon, to handle CNF style constraints???
- static public boolean createDPLinearOrIntegerConstraint (final LogicalORLinearIntegerConstraints c) {
- final List