Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to statically analyze reference types passed to each bytecode instruction?
    primarykey
    data
    text
    <p>I have rewritten the question (the question remains the same, just with less background noise) in hopes of creating less confusion directed at all the wrong things - due to this, some of the comments below may seem out of context.</p> <p>Analyzing Java bytecode, what is the easiest way to find all the possible reference types given as parameters for a given Java bytecode instruction? I'm interested in the type of the reference, that is, that a given putfield instruction will receive an Integer, or that it might receive an Integer or a Float, etc.</p> <p>For example, consider this code block:</p> <pre><code> 0: aload_1 1: invokestatic #21; //Method java/lang/Integer.valueOf:(Ljava/lang/String;)Ljava/lang/Integer; 4: astore_2 5: aload_2 6: ifnull 17 9: aload_0 10: aload_2 11: putfield #27; //Field value:Ljava/lang/Number; 14: goto 25 17: aload_0 18: iconst_0 19: invokestatic #29; //Method java/lang/Integer.valueOf:(I)Ljava/lang/Integer; 22: putfield #27; //Field value:Ljava/lang/Number; 25: return </code></pre> <p>We can deduce that the putfield instruction at pc 11 will receive a ref type of <strong>Integer</strong>.</p> <pre><code>0: aload pushes ref type of String (the method param) 1: invokestatic pops the ref type and pushes a ref type of Integer (invoked method return type) 4: astore pops the ref type of Integer and stores it in local variable 2 5: aload pushes the ref type of Integer from local variable 2 6: ifnull pops the ref type of Integer and conditionally jumps to pc 17 9: aload pushes "this" 10: aload pushes the ref type of Integer 11: putfield: we know we have a ref type of Integer that the instruction will put in field </code></pre> <p>Do any of the bytecode/code analysis libraries do this for me, or do I have to write this myself? The <a href="http://asm.ow2.org/" rel="nofollow">ASM project</a> has an <a href="http://asm.ow2.org/asm33/javadoc/user/org/objectweb/asm/tree/analysis/Analyzer.html" rel="nofollow">Analyzer</a>, which seems like it might do part of the work for me, but really not enough to justify switching to using it.</p> <p>EDIT: I have done my homework and have studied the <a href="http://java.sun.com/docs/books/jvms/second_edition/html/VMSpecTOC.doc.html" rel="nofollow">Java VM Spec</a>.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload