"javap -v" - Verbose Mode

Q

How to "javap" command use verbose mode to print additional information about the selected class.

✍: FYIcenter

A

You can use the "-v" or "-verbose" option of the "javap" command to print additional information about the specified class bytecode.

1. Compile HelloWorldFrame.java used in the last tutorial into a bytecode file, HelloWorldFrame.class:

> javac HelloWorldFrame.java 

2. Disassemble it using "javap" command with the "-v" option

> javap -v HelloWorldFrame.class 

Classfile HelloWorldFrame.class
  Last modified 2021; size 634 bytes
  SHA-256 checksum 9d6d07fecb3045d8b27d071419e34d02532ea1e1db9f27707d9e7ab474ff45a4
  Compiled from "HelloWorldFrame.java"
public class HelloWorldFrame extends javax.swing.JFrame
  minor version: 0
  major version: 59
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #10                         // HelloWorldFrame
  super_class: #2                         // javax/swing/JFrame
  interfaces: 0, fields: 1, methods: 2, attributes: 3
Constant pool:
   #1 = Methodref          #2.#3          // javax/swing/JFrame."<init>":()V
   #2 = Class              #4             // javax/swing/JFrame
   #3 = NameAndType        #5:#6          // "<init>":()V
   #4 = Utf8               javax/swing/JFrame
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = String             #8             // Hello World!
   #8 = Utf8               Hello World!
   #9 = Fieldref           #10.#11        // HelloWorldFrame.message:Ljava/lang/String;
  #10 = Class              #12            // HelloWorldFrame
  #11 = NameAndType        #13:#14        // message:Ljava/lang/String;
  #12 = Utf8               HelloWorldFrame
  #13 = Utf8               message
  #14 = Utf8               Ljava/lang/String;
  #15 = Class              #16            // HelloWorldFrame$1
  #16 = Utf8               HelloWorldFrame$1
  #17 = Methodref          #15.#18        // HelloWorldFrame$1."<init>":(LHelloWorldFrame;)V
  #18 = NameAndType        #5:#19         // "<init>":(LHelloWorldFrame;)V
  #19 = Utf8               (LHelloWorldFrame;)V
  #20 = Methodref          #10.#21        // HelloWorldFrame.setContentPane:(Ljava/awt/Container;)V
  #21 = NameAndType        #22:#23        // setContentPane:(Ljava/awt/Container;)V
  #22 = Utf8               setContentPane
  #23 = Utf8               (Ljava/awt/Container;)V
  #24 = Methodref          #10.#25        // HelloWorldFrame.setSize:(II)V
  #25 = NameAndType        #26:#27        // setSize:(II)V
  #26 = Utf8               setSize
  #27 = Utf8               (II)V
  #28 = Methodref          #10.#3         // HelloWorldFrame."<init>":()V
  #29 = Methodref          #10.#30        // HelloWorldFrame.setVisible:(Z)V
  #30 = NameAndType        #31:#32        // setVisible:(Z)V
  #31 = Utf8               setVisible
  #32 = Utf8               (Z)V
  #33 = Utf8               Code
  #34 = Utf8               LineNumberTable
  #35 = Utf8               main
  #36 = Utf8               ([Ljava/lang/String;)V
  #37 = Utf8               SourceFile
  #38 = Utf8               HelloWorldFrame.java
  #39 = Utf8               NestMembers
  #40 = Utf8               InnerClasses
{
  java.lang.String message;
    descriptor: Ljava/lang/String;
    flags: (0x0000)

  public HelloWorldFrame();
    descriptor: ()V
    flags: (0x0001) ACC_PUBLIC
    Code:
      stack=4, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1                  // Method javax/swing/JFrame."<init>":()V
         4: aload_0
         5: ldc           #7                  // String Hello World!
         7: putfield      #9                  // Field message:Ljava/lang/String;
        10: aload_0
        11: new           #15                 // class HelloWorldFrame$1
        14: dup
        15: aload_0
        16: invokespecial #17                 // Method HelloWorldFrame$1."<init>":(LHelloWorldFrame;)V
        19: invokevirtual #20                 // Method setContentPane:(Ljava/awt/Container;)V
        22: aload_0
        23: bipush        100
        25: bipush        100
        27: invokevirtual #24                 // Method setSize:(II)V
        30: return
      LineNumberTable:
        line 8: 0
        line 6: 4
        line 9: 10
        line 15: 22
        line 16: 30

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=2, args_size=1
         0: new           #10                 // class HelloWorldFrame
         3: dup
         4: invokespecial #28                 // Method "<init>":()V
         7: astore_1
         8: aload_1
         9: iconst_1
        10: invokevirtual #29                 // Method setVisible:(Z)V
        13: return
      LineNumberTable:
        line 18: 0
        line 19: 8
        line 20: 13
}
SourceFile: "HelloWorldFrame.java"
NestMembers:
  HelloWorldFrame$1
InnerClasses:
  #15;                                    // class HelloWorldFrame$1

 

"javap -v" - Major Version Code

"javap -c" - Generate Assembler Instructions

JDK "javap" Command

⇑⇑ Java Bytecode Tools

2021-09-09, 994🔥, 0💬