∟Compare HelloWorld.j with "javap" Output

This section provides a comparison of Jasmin assembly source code and its generated bytecode.

Since Jasmin assembly is considered as a low-level language for JVM, let's see the difference between the Jasmin source code and the generated bytecode.

1. Run "javap" to convert the generated bytecode into a readable form.

herong> javap -c -v HelloWorld

Classfile ./HelloWorld.class
  Last modified Nov 4, 2026; size 377 bytes
  SHA-256 checksum b73ebffb74c7632d...
  Compiled from "HelloWorld.j"
public class HelloWorld
  minor version: 3
  major version: 45
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #14                         // HelloWorld
  super_class: #6                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 2, attributes: 1
Constant pool:
   #1 = NameAndType        #25:#27        // out:Ljava/io/PrintStream;
   #2 = Utf8               ([Ljava/lang/String;)V
   #3 = Utf8               java/lang/Object
   #4 = Utf8               <init>
   #5 = Utf8               Hello World!
   #6 = Class              #3             // java/lang/Object
   #7 = NameAndType        #4:#9          // "<init>":()V
   #8 = Class              #19            // java/io/PrintStream
   #9 = Utf8               ()V
  #10 = String             #5             // Hello World!
  #11 = Class              #22            // java/lang/System
  #12 = Utf8               Code
  #13 = Utf8               main
  #14 = Class              #18            // HelloWorld
  #15 = Fieldref           #11.#1         // java/lang/System.out:...
  #16 = Utf8               SourceFile
  #17 = NameAndType        #20:#26        // println:(...)V
  #18 = Utf8               HelloWorld
  #19 = Utf8               java/io/PrintStream
  #20 = Utf8               println
  #21 = Methodref          #6.#7          // java/lang/Object....
  #22 = Utf8               java/lang/System
  #23 = Utf8               HelloWorld.j
  #24 = Methodref          #8.#17         // java/io/PrintStream....
  #25 = Utf8               out
  #26 = Utf8               (Ljava/lang/String;)V
  #27 = Utf8               Ljava/io/PrintStream;
{
  public HelloWorld();
    Code:
       0: aload_0
       1: invokespecial #21   // Method java/lang/Object."<init>":()V
       4: return

  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #15   // java/lang/System.out:L.../PrintStream;
       3: ldc           #10   // Hello World!
       5: invokevirtual #24   // java/io/PrintStream.println:(...)V
       8: return
}

As you can see from the output, Jasmin creates the constant pool in the same way as the "javac" compiler. It contains mostly method and field references.

If you look at the execution code part of the output, it's almost identical to the Jasmin assembly code.

Here is the comparison of the class initialization code. The constructor of HelloWorld calls the java.lang.Object constructor.

HelloWorld.j:
  .method public <init>()V
    aload_0
    invokenonvirtual java/lang/Object/<init>()V
    return
  .end method

"javap" output:
  public HelloWorld();
    Code:
       0: aload_0
       1: invokespecial #21   // java/lang/Object."<init>":()V
       4: return

Here is the comparison of the main() method code.

HelloWorld.j:
  .method public static main([Ljava/lang/String;)V
    .limit stack 2
    getstatic java/lang/System/out Ljava/io/PrintStream;
    ldc "Hello World!"
    invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V
    return
  .end method

"javap" output:
  public static void main(java.lang.String[]);
    Code:
       0: getstatic     #15   // java/lang/System.out:L.../PrintStream;
       3: ldc           #10   // Hello World!
       5: invokevirtual #24   // java/io/PrintStream.println:(...)V
       8: return

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

►JVM Assembler/Disassembler Tools

 What Is JVM Assembler

 What Is Jasmin

►Compare HelloWorld.j with "javap" Output

 Jasmin Assembly Statements

 Jasmin Example - Empty.j

 Jasmin Example - Calculator.j

 What Is JASM

 JASM Assembly Statements

 JASM Example - Calculator.jasm

 JASM Disassembler: "jasm -d"

 What Is AsmTools

 AsmTools/JASM Assembly Statements

 AsmTools/JASM Example - Calculator.jasm

 AsmTools/JASM Disassembler: "jdis"

 AsmTools/JCOD Assembly File Format

 AsmTools/JCOD Example - HelloWorld.jcod

 AsmTools/JCOD Disassembler: "jdec"

 What Is Lilac

 Lilac Assembly Statements

 Lilac Macro Example - HelloWorldMacro.jasm

 Lilac Disassembler: "jdasm"

 Archived Tutorials

 References

 Index

 Full Version in PDF/EPUB