∟Walkthrough of "javap -c -v" Command Output

This section provides a walkthrough on the 'javap -c -v' command output from an example JVM bytecode file.

In order to get a more complex JVM bytecode, let's prepare another Java program, Sum.java:

class Sum {
  public static void main(String[] a) {
    int sum = 0;
    for (int i=1; i<=100; i++) sum += i;
    System.out.print("Summation of 100 = ");
    System.out.println(sum);
  }
}

Then compile it to get the bytecode file Sum.class:

herong> javac Sum.java

herong> ls -l Sum.*
  -rw-r--r--  1 herong  staff   515 Nov  5 17:55 Sum.class
  -rw-r--r--@ 1 herong  staff   203 Nov  5 17:55 Sum.java

Run it to make sure that it works:

herong> java Sum

Summation of 100 = 5050

Finally, run the "javap" command:

Classfile ./Sum.class
  Last modified Nov 5, 2026; size 515 bytes
  SHA-256 checksum 2bd083b9493658ca...
  Compiled from "Sum.java"
class Sum
  minor version: 0
  major version: 65
  flags: (0x0020) ACC_SUPER
  this_class: #25                     // Sum
  super_class: #2                     // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 1
Constant pool:
   #1 = Methodref          #2.#3      // java/lang/Object."<init>":()V
   #2 = Class              #4         // java/lang/Object
   #3 = NameAndType        #5:#6      // "<init>":()V
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Fieldref           #8.#9      // java/lang/System.out:Ljava...
   #8 = Class              #10        // java/lang/System
   #9 = NameAndType        #11:#12    // out:Ljava/io/PrintStream;
  #10 = Utf8               java/lang/System
  #11 = Utf8               out
  #12 = Utf8               Ljava/io/PrintStream;
  #13 = String             #14        // Summation of 100 =
  #14 = Utf8               Summation of 100 =
  #15 = Methodref          #16.#17    // java/io/PrintStream.print:(...
  #16 = Class              #18        // java/io/PrintStream
  #17 = NameAndType        #19:#20    // print:(Ljava/lang/String;)V
  #18 = Utf8               java/io/PrintStream
  #19 = Utf8               print
  #20 = Utf8               (Ljava/lang/String;)V
  #21 = Methodref          #16.#22    // java/io/PrintStream.println:(I)V
  #22 = NameAndType        #23:#24    // println:(I)V
  #23 = Utf8               println
  #24 = Utf8               (I)V
  #25 = Class              #26        // Sum
  #26 = Utf8               Sum
  #27 = Utf8               Code
  #28 = Utf8               LineNumberTable
  #29 = Utf8               main
  #30 = Utf8               ([Ljava/lang/String;)V
  #31 = Utf8               StackMapTable
  #32 = Utf8               SourceFile
  #33 = Utf8               Sum.java
{
  Sum();
    descriptor: ()V
    flags: (0x0000)
    Code:
      stack=1, locals=1, args_size=1
         0: aload_0
         1: invokespecial #1          // java/lang/Object."<init>":()V
         4: return
      LineNumberTable:
        line 1: 0

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=3, args_size=1
         0: iconst_0
         1: istore_1
         2: iconst_1
         3: istore_2
         4: iload_2
         5: bipush        100
         7: if_icmpgt     20
        10: iload_1
        11: iload_2
        12: iadd
        13: istore_1
        14: iinc          2, 1
        17: goto          4
        20: getstatic     #7              // java/lang/System.out:...
        23: ldc           #13             // Summation of 100 =
        25: invokevirtual #15             // java/io/PrintStream....
        28: getstatic     #7              // java/lang/System.out:...
        31: iload_1
        32: invokevirtual #21             // java/io/PrintStream....
        35: return
      LineNumberTable:
        line 3: 0
        line 4: 2
        line 5: 20
        line 6: 28
        line 7: 35
      StackMapTable: number_of_entries = 2
        frame_type = 253 /* append */
          offset_delta = 4
          locals = [ int, int ]
        frame_type = 250 /* chop */
          offset_delta = 15
}
SourceFile: "Sum.java"

Now let's walkthrough the output.

.class file information - This part shows the name, modification date and size of the class file, followed by the checksum and the Java source file name.

Classfile ./Sum.class
  Last modified Nov 5, 2026; size 515 bytes
  SHA-256 checksum 2bd083b9493658ca...
  Compiled from "Sum.java"

Class information - This part shows the name of the class defined in bytecode, followed by the targeted JVM version number (65 means JVM 21 release). Then you see the class access flags, this class name, super class name, and various counts. Note that #25 and #2 are references to values stored in the constant pool. Those values are also displayed after the comment marker //.

class Sum
  minor version: 0
  major version: 65
  flags: (0x0020) ACC_SUPER
  this_class: #25                     // Sum
  super_class: #2                     // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 1

Constant Pool - This part lists all values stored in the constant pool with value types. Note that some values may contain references to other values in the constant pool.

Constant pool:
   #1 = Methodref          #2.#3      // java/lang/Object."<init>":()V
   #2 = Class              #4         // java/lang/Object
   #3 = NameAndType        #5:#6      // "<init>":()V
   #4 = Utf8               java/lang/Object
   #5 = Utf8               <init>
   #6 = Utf8               ()V
   #7 = Fieldref           #8.#9      // java/lang/System.out:Ljava...
   #8 = Class              #10        // java/lang/System
   #9 = NameAndType        #11:#12    // out:Ljava/io/PrintStream;
  ...

The Constructor Method - Since there is no constructor method defined in the Java source code, the compiler added a default constructor method automatically in the bytecode.

The header portion shows the name, descriptor and access flags of the method, followed by memory allocation limits for operand stack, local variables, and method arguments.

  Sum();
    descriptor: ()V
    flags: (0x0000)
    Code:
      stack=1, locals=1, args_size=1

The instruction portion shows the execution sequence of JVM instructions. Each instruction is listed with its byte offset from the start of the method.

         0: aload_0
         1: invokespecial #1          // java/lang/Object."<init>":()V
         4: return

The first instruction, "aload_0", loads an object address from local variable 0 to the operand stack. Note that variable 0 always holds "this" object in an instance method.

The second instruction, "invokespecial #1", occupies 3 bytes in the bytecode: the opcode byte 0xB7 and the two-byte parameter #1 0x0001 referring to the #1 value in the constant pool. It tells the JVM to:

The third instruction, "return", simply ends the execution of this Sum() method and returns to the caller.

The "LineNumberTable" portion maps line numbers of statements in source code to byte offsets of corresponding JVM instructions.

      LineNumberTable:
        line 1: 0

The main() Method - This method has the same bytecode structure as the Sum() method. You can follow the execution sequence of JVM instructions by reading embedded comments:

  public static void main(java.lang.String[]);
    descriptor: ([Ljava/lang/String;)V
    flags: (0x0009) ACC_PUBLIC, ACC_STATIC
    Code:
      stack=2, locals=3, args_size=1
         0: iconst_0             // load int 0
         1: istore_1             // store int 0 to var 1 as "sum"
         2: iconst_1             // load int 1
         3: istore_2             // store int 1 to var 2 as "i"
         4: iload_2              // load "i"
         5: bipush        100    // load int 100
         7: if_icmpgt     20     // go to offset 20, if operand #1 > #2
        10: iload_1              // load "sum"
        11: iload_2              // load "i"
        12: iadd                 // add "I" to "sum"
        13: istore_1             // store "sum"
        14: iinc          2, 1   // increment "i" by 1
        17: goto          4      // go to offset 4
        20: getstatic     #7     // load java/lang/System.out
        23: ldc           #13    // load "Summation of 100 = "
        25: invokevirtual #15    // invoke out.println()
        28: getstatic     #7     // load java/lang/System.out
        31: iload_1              // load "sum"
        32: invokevirtual #21    // invoke out.println()
        35: return               // end execution and return
      LineNumberTable:
        line 3: 0
        line 4: 2
        line 5: 20
        line 6: 28
        line 7: 35
      StackMapTable: number_of_entries = 2
        frame_type = 253 /* append */
          offset_delta = 4
          locals = [ int, int ]
        frame_type = 250 /* chop */
          offset_delta = 15

Table of Contents

 About This Book

 JVM (Java Virtual Machine) Specification

 Java HotSpot VM - JVM by Oracle/Sun

 java.lang.Runtime Class - The JVM Instance

 java.lang.System Class - The Operating System

 ClassLoader Class - Class Loaders

 Class Class - Class Reflections

 JVM Runtime Data Areas

 JVM Stack, Frame and Stack Overflow

 Thread Testing Program and Result

 CPU Impact of Multi-Thread Applications

 I/O Impact of Multi-Thread Applications

 CDS (Class Data Sharing)

 Micro Benchmark Runner and JVM Options

 Micro Benchmark Tests on "int" Operations

 Micro Benchmark Tests on "long" Operations

 Micro Benchmark Tests in JIT Compilation Mode

 Micro Benchmark Tests on "float" and "double" Operations

 OpenJ9 by Eclipse Foundation

 JRockit JVM 28.2.7 by Oracle Corporation

►JVM Bytecode and Instruction Set

 What Is JVM Bytecode

 What Is "javap" Command

►Walkthrough of "javap -c -v" Command Output

 JVM Method Frame Architecture

 What Is Constant Pool

 JVM Instruction Set

 Constant Loading Instructions

 Local Variable Array Instructions

 Shared Memory Instructions

 Arithmetic Operation Instructions

 Bitwise Operation Instructions

 Type Conversion Instructions

 Flow Control Instructions

 Method Invocation Instructions

 Miscellaneous Instructions

 JVM Assembler/Disassembler Tools

 Archived Tutorials

 References

 Index

 Full Version in PDF/EPUB