0 Replies Latest reply on Apr 14, 2006 5:50 PM by matty1

    easy way to parse out opcode operands?

    matty1

      Total javassist/bytecode newbie here. I'm writing a program to list bytecode instructions from a classfile, akin to what "javap -c -p CLASSFILE" gives you. Somthing like:

      0: aload_0
      1: invokespecial #15; //Method java/lang/O
      4: aload_0
      5: ldc2_w #16; //double 99.0d
      8: putfield #19; //Field size:D

      This snippet from the tutorial lists the index & opcodes but no operands:

      CodeIterator ci = ... ;
      while (ci.hasNext()) {
      int index = ci.next();
      int op = ci.byteAt(index);
      System.out.println(index + ": " +Mnemonic.OPCODE[op]);
      }


      Result of this code is something like:

      0: aload_0
      1: invokespecial <--no operand!!!
      4: aload_0
      5: ldc2_w <--no operand!!!

      The "hasNext" call seems to move the iterator to the next opcode, skipping past operands. So how do I parse out operands for things like control flow or method call opcodes? Since # of operands varies based on the particular opcode, is there an easy way to know how many bytes to parse out per instruction?