[Soot-list] Prevent static array fill code getting pessimized to use aload+astore instead of dup?

Patrick Lam plam at sable.mcgill.ca
Fri Jul 11 00:25:26 EDT 2014


Hi Noam,

See the CC 2000 paper about Soot bytecode generation. There should be a 
LoadStoreOptimizer in Baf which may generate dups (or could be modified 
to); it's a peephole optimization. There is also a path for generating 
bytecode from Grimp instead of Baf, but it usually doesn't work as well.

For most VMs, store/load vs dup doesn't make any perf difference, but 
JavaCard may be different. Also, there are weird dup variants that don't 
actually work properly on all VMs.

pat

On 09/07/14 04:45 PM, Noam Postavsky wrote:
> public class StaticArray {
>      static byte[] array = {
>          'a', 'b', 'c'
>      };
> }
>
> javac compiles this into
>
>    static {};
>      Code:
>         0: iconst_3
>         1: newarray       byte
>         3: dup
>         4: iconst_0
>         5: bipush        97
>         7: bastore
>         8: dup
>         9: iconst_1
>        10: bipush        98
>        12: bastore
> ...
>
> After running get
>      java -jar \soot\soot-2.5.0.jar -O -cp . -pp StaticArray
> the resulting class file uses aload+astore instead of dup:
>
>    static {};
>      Code:
>         0: iconst_3
>         1: newarray       byte
>         3: astore_0
>         4: aload_0
>         5: iconst_0
>         6: bipush        97
>         8: bastore
>         9: aload_0
>        10: iconst_1
>        11: bipush        98
>        13: bastore
> ...
>
> I want avoid this not only because it makes the code bigger (and
> probably slower), but also because I'm trying to use soot with
> JavaCard applets, and the JavaCard applet converter only allows
> certain instructions to appear in the static class initializer; aload
> and astore are not allowed.
>
> I'm still trying to figure out how soot works, but if I understand
> correctly, soot would need to "rediscover" the store+load -> dup
> optimization since the original form of the input isn't saved. I tried
> playing with the bb.lso phase options but it didn't seem to help. Any
> suggestions?
> _______________________________________________
> Soot-list mailing list
> Soot-list at CS.McGill.CA
> https://mailman.CS.McGill.CA/mailman/listinfo/soot-list
>



More information about the Soot-list mailing list