Kohsuke Kawaguchi wrote:

Another possible approach could be to use results of DataflowInterpeter to find an instructions that are consuming given stack value and then cast to the type required by this instruction, but I am not sure if there are some gaps in this approach, e.g. if locals will cause issues...

I don't think it's possible. The same variable maybe assigned to, say, java.lang.Comparable and java.io.Serializable. Consider the following code:

SomeMiddleClass x;
if(...)
  x = new ClassX();
else
  x = new ClassY();

  [1]
someFunctionCall();

if(...) {
    [2]
  methodThatTakesSerializable(x);
} else {
    [3]
  methodThatTakesComparable(x);
}

Given that bytecode doesn't have the type for 'x', correctly restoring 'x' at someFunctionCall requires us to really find the common base type as described in the JVM spec.

Actually your above example should be quite simple, especially if we can assume that we know local variable types (e.g. debug information is available):

-- for [1] we have to cast restored variable x to SomeMiddleClass, for
-- for [2] we can cast method parameter (stack value) to Serializable
-- for [3] we can cast method parameter (stack value) to Comparable

Though more complicated case would be the case when restoring stack not directly used by the currently restoring method. Probably something similar to what happening for NEW opcodes. And for this we will have to always search for common super class or interface.

In any case this approach should allow to eliminate second analysis step and use only dataflow analyzer to move new opcodes and also to find types of the stack and locals.

It shouldn't be too difficult; BCEL does that. As I wrote in the commit message, all we need is a resolver that can get you the byte code image of those referenced classes (like ClassX and ClassY.)

We have code for this within ASM test cases. It is in MUSTANG_SUPPORT branch in org.objectweb.asm.ClassWriterTest3 class. If you like I can try to put this code into SimpleVerifier subclass already used in javaflow.

  regards,
  Eugene


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to