[Soot-list] Unwanted optimization by soot?
Dharmendra Singh
mailme.dsingh63 at gmail.com
Sun Oct 30 05:05:29 EDT 2016
I was trying to implement ball larus path profiling on the following java
program using soot.
1 package test1;
2 public class Main {
3 public static void main(String args[]) {
4 int x = args[0].length();
5 try {
6 int b = x / 0;
7 System.err.println("Here");
8 System.err.println(b);
9 } catch (ArithmeticException e1) {
10 if (x < 5)
11 x++;
12 else
13 x--;
14 System.err.println("Exception: e1");
15 } catch (Exception e5) {
16 x += 10;
17 } finally {
18 System.err.println("Finally");
19 }
20 System.err.println(x);
21 return;
22 }
23 }
There is java.lang.ArithmeticException divide by zero on line 6. When I run
the program without instrumentation through soot, the exception is thrown
at line 6 and "Here" of line 7 is not printed. But when I run the
instrumented code, than exception is thrown after line 7 ( print "Here" ).
javap -c output of uninstrumented class file
3: invokevirtual #2 // Method java/lang/String.length:()I
6: istore_1
7: iload_1
8: iconst_0
9: idiv
10: istore_2
11: getstatic #3 // Field java/lang/System.err:Ljava/io/PrintStream;
14: ldc #4 // String Here
16: invokevirtual #5 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
division is at line 9 and print "Here" at 16
javap -c output of instrumented class file
27: getstatic #47 // Field java/lang/System.err:Ljava/io/PrintStream;
30: ldc #23 // String Here
32: invokevirtual #17 // Method
java/io/PrintStream.println:(Ljava/lang/String;)V
35: lload_3
36: ldc2_w #52 // long 15l
39: ladd
40: ldc2_w #52 // long 15l
43: ladd
44: lstore_3
45: getstatic #47 // Field java/lang/System.err:Ljava/io/PrintStream;
48: iload_0
49: iconst_0
50: idiv
51: invokevirtual #39 // Method java/io/PrintStream.println:(I)V
Here line 30 is print "Here" and line 50 is division. (Ignore the extra
adds, they are for BL path profiling.)
I'm not doing any rearrangement of instructions during Transformation. Why
is this happening?
#java version
java version "1.7.0_95"
OpenJDK Runtime Environment (IcedTea 2.6.4) (7u95-2.6.4-3)
OpenJDK 64-Bit Server VM (build 24.95-b01, mixed mode)
#javac
javac 1.7.0_95
#soot
soot-nightly-05082016
-------------- next part --------------
An HTML attachment was scrubbed...
URL: https://mailman.CS.McGill.CA/pipermail/soot-list/attachments/20161030/56e09166/attachment.html
More information about the Soot-list
mailing list