[Soot-list] A question about using a subset of optimizaitons directly on bytecode

Eric Bodden eric.bodden at mail.mcgill.ca
Sat Aug 2 11:08:21 EDT 2008


Hi David.

All these optimizations are defined over the Jimple IR. Therefore at
the very least you would have to create a JimpleBody from your byte
array, then optimize that body and convert back to a byte array. Every
BodyTransformer in Soot can easily be applied to a JimpleBody, so you
should have no problem there. The only problem is the conversion
to/from Jimple. Soot uses a bytecode parser called Coffi to convert
bytecode into Jimple. Usually this reads the bytecode from file but I
am pretty sure that you could easily extend it to use a byte array
instead. The opposite conversion happens using Jasmin.

Both Coffi and Jasmin operate on streams (Coffi on an InputStream and
Jasmin on an OutputStream). Therefore it should be easy to just use
ByteArrayInput/OutputStreams instead to get what you want.

Eric

2008/8/2 David Beaumont <dbeaumont at google.com>:
> Hi,
>    I have been playing with soot to do some bytecode optimization but
> was wondering how easy it would be to using a few of the optimizations
> on bytecode directly, rather than going via the main command line
> tool.
>
> Basically I am generating some bytecode and would like to pass _some_
> of the methods through a specific set of Jimple optimizations.
>
> Ideally I'd be looking to write a filter that takes in a byte[] of the
> method's bytecode and returns the optimized bytecode. I believe that
> the optimizations I am looking to perform can be made safe to be
> performed on a per-method basis (with reference to other classes via
> the soot classpath).
>
> Basically some of the code I am generating will contain bytecode equivalent to:
>
> if (false && someCondition) {
>  unreachableCode();
> }
>
> or
>
> if (someConstant < biggerConstant) {
>  unreachableCode();
> }
>
> And I would like to detect and remove the unreachable code sequences.
>
> Basically I think I want to apply:
>
> * jop.cpf - constant propagation
>   "false && x"
>  -->
>   "false"
>
> * jop.cbf - constant branchfolding
>   if (false) {
>     unreachableCode();
>   }
>  -->
>   goto x;
>   unreachableCode();
>   x:
>
> * jop.uce1 - unreachable code elimination
>   goto x;
>   unreachableCode();
>   x:
>  -->
>   goto x;
>   x:
>
> * jop.ubf1 - unconditional branch folding
>   goto x;
>   x:
>  -->
>   <nothing>
>
> But only to a known subset of methods and a subset of classes (this
> has to be as faster as possible).
>
> Many thanks in advance for any help or advice,
>
>  David
>
> --
> David Beaumont :: Mobile Software Engineer :: Google
> Google UK Ltd, Belgrave House, 76 Buckingham Palace Road, London SW1W 9TQ
> Tel +44-20-7031-3000 :: Fax +44-20-7031-3001
> _______________________________________________
> Soot-list mailing list
> Soot-list at sable.mcgill.ca
> http://mailman.cs.mcgill.ca/mailman/listinfo/soot-list
>



-- 
Eric Bodden
Sable Research Group
McGill University, Montréal, Canada


More information about the Soot-list mailing list