Add javap option to show the original source code lines intermingled with the bytecode like objdump -S

Ciro Santilli ciro.santilli at gmail.com
Fri Jun 26 09:12:41 UTC 2015


Sample input:

    public class New {
        public static void main(String[] args) {
            System.out.println(new Integer(1));
        }
    }

Actual `javap` output:

       0: getstatic     #2                  // Field
java/lang/System.out:Ljava/io/PrintStream;
       3: new           #3                  // class java/lang/Integer
       6: dup
       7: iconst_1
       8: invokespecial #4                  // Method
java/lang/Integer."<init>":(I)V
      11: invokevirtual #5                  // Method
java/io/PrintStream.println:(Ljava/lang/Object;)V
      14: return
    LineNumberTable:
      line 3: 0
      line 4: 14

Desired javap output with the new option:

           System.out.println(new Integer(1));
       0: getstatic     #2                  // Field
java/lang/System.out:Ljava/io/PrintStream;
       3: new           #3                  // class java/lang/Integer
       6: dup
       7: iconst_1
       8: invokespecial #4                  // Method
java/lang/Integer."<init>":(I)V
      11: invokevirtual #5                  // Method
java/io/PrintStream.println:(Ljava/lang/Object;)V
        }
      14: return
    LineNumberTable:
      line 3: 0
      line 4: 14

That would make it much easier to interpret `javap` output.

I know that this debug information is contained in the .class file
when compiling
with:

    javac -g Main.java

and can be observed manually from the `LineNumberTable:` section of:

    javap -c -constants -private -verbose '$<' > '$@'


More information about the jdk9-dev mailing list