[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Jimple and bytecode length



When java bytecode is generated from Jimple instructions, the bytecode
sequence may be too long and breaks the limit specified by JVM spec. I can
writing a code transformer using Soot to add additional Jimple instructions
to methods in a classfile. I need to make sure that the modified class file
is still compliant. Is there any easy way I can easily estimate the bytecode
size of the method from the Jimple instructions?

I have thought of a few possible solutions, but none of them struck me as a
good idea:
1. Get Soot to actually generate the bytecode sequence, and fail if the
bytecode length exceeds limits. This approach is impractical in my
application, as the transformation involves quite a few steps. It would be
too expensive to generate the bytecode from the Jimple instructions after
each step.

2. Use a worse case estimate. Lets say we know a Jimple instruction can
never generate more than X number of bytes of bytecode, then we can estimate
the length of the bytecodes by using the multiplication factor.

What do you think? Has anyone come across this problem before and what is
your solution?

Thanks,
Stephen