[Soot-list] Bad use of primitive type when performing transformations needed
Zeinab Lashkaripour
lashkaripour at yahoo.com
Sun Jun 9 10:38:25 EDT 2013
Thanks a lot Quentin for your quick and also very nice reply.
> There are several problems with this code: ....
Yes, you are right and the problems that you mentioned do exist, but as a last question do you think that the exception I get is not related to line 3 (j = virtualinvoke var1.<java.lang.String: int length()>()) at all and the other problems somehow caused that exception?
Regards,
Zeinab
________________________________
From: Quentin Sabah <quentin.sabah at inria.fr>
To: "soot-list at sable.mcgill.ca list" <soot-list at sable.mcgill.ca>
Sent: Sunday, June 9, 2013 6:56 PM
Subject: Re: [Soot-list] Bad use of primitive type when performing transformations needed
> 1 tmpInt = new java.lang.Integer
> 2 specialinvoke tmpInt.<java.lang.Integer: void <init>(int)>(17)
> 3 j = virtualinvoke var1.<java.lang.String: int length()>()
> 4 tmpInt = tmpInt + j
> 5 tmpInt = staticinvoke <java.lang.Integer: java.lang.Integer valueOf(int)>(tmpInt)
> 6 virtualinvoke info.<java.util.ArrayList: boolean add(java.lang.Object)>(tmpInt)
There are several problems with this code:
- Line 4, you cannot add an Integer (tmpInt) and an int, first you need to convert the Integer into an int with Integer.intValue(). And the result of line 4 should be stored in an int variable.
- At line 5, you cannot invoke valueOf(int) with an Integer parameter.
You should have something like:
4a k = virtualinvoke tmpInt.<java.lang.Integer: int intValue()>()
4b j = k + j
5 tmpInt = staticinvoke <java.lang.Integer: java.lang.Integer valueOf(int)>(j)
Of course, when you write pure Java code, these conversions are done automatically by javac, but in jimple you must generate these yourself.
When you encounter this kind of problems,
I suggest you to write a small example in pure Java like:
public static void main(String [] args) {
Integer i = new Integer(17);
int j = 14;
i = i + j;
}
Then compile it with javac, and observe the produced bytecode with "javap -c". You'll observe the various conversions added by the compiler:
public static void main(java.lang.String[]);
Code:
0: new #2 // class java/lang/Integer
3: dup
4: bipush 17
6: invokespecial #3 // Method java/lang/Integer."<init>":(I)V
9: astore_1
10: bipush 14
12: istore_2
13: aload_1
14: invokevirtual #4 // Method java/lang/Integer.intValue:()I
17: iload_2
18: iadd
19: invokestatic #5 // Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer;
22: astore_1
23: return
--
Quentin Sabah, CIFRE Ph.D. student
Grenoble University
INRIA-SARDES | STMicroelectronics/AST
Montbonnot, France | Grenoble, France
mailto:quentin.sabah at inria.fr | mailto:quentin.sabah at st.com
phone: +33 476 61 52 42 | phone: +33 476 58 44 14
_______________________________________________
Soot-list mailing list
Soot-list at sable.mcgill.ca
http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.cs.mcgill.ca/pipermail/soot-list/attachments/20130609/5e705300/attachment.html
More information about the Soot-list
mailing list