∟Jasmin Example - Empty.j

This section provides a tutorial example on how to write the smallest Jasmin program, Empty.j.

Let's try to create the smallest Jasmin program:

1. Enter the following Jasmin program in a file called Empty.j with only 2 directive statements:

.class public Empty
.super java/lang/Object

2. Compile it:

herong> java -jar jasmin-2.4/jasmin.jar Empty.j
  Generated: Empty.class

herong> ls -l Empty.*
  -rw-r--r--  1 herong  staff    88 Nov 10 08:05 Empty.class
  -rw-r--r--@ 1 herong  staff    44 Nov 10 07:49 Empty.j

Very nice. I have created a valid Jasmin program with 44 bytes in source code and 88 bytes in bytecode.

3. View the bytecode with "javap" command:

Classfile .../Empty.class
  Last modified Nov 10, 2026; size 88 bytes
  SHA-256 checksum d924923b0963dbf9...
  Compiled from "Empty.j"
public class Empty
  minor version: 3
  major version: 45
  flags: (0x0021) ACC_PUBLIC, ACC_SUPER
  this_class: #4                          // Empty
  super_class: #1                         // java/lang/Object
  interfaces: 0, fields: 0, methods: 0, attributes: 1
Constant pool:
  #1 = Class              #5              // java/lang/Object
  #2 = Utf8               Empty.j
  #3 = Utf8               Empty
  #4 = Class              #3              // Empty
  #5 = Utf8               java/lang/Object
  #6 = Utf8               SourceFile
{
}
SourceFile: "Empty.j"

As you can see from the output, the bytecode contains the class declaration, a small constant pool, and no method.

4. Try to run it on JVM. You will get an error, because it does not have the required main() method.

herong> java Empty

Error: Main method not found in class Empty, please define
the main method as:
   public static void main(String[] args)

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