∟Jasmin Assembly Statements

This section provides a quick introduction on Jasmin assembly statements.

The Jasmin assembly language consists of 3 types of statements: directives, instructions and labels.

Directives - Statements to help Jasmin assembler to compile the assembly code. Here are the main directives and their usage examples:

; declares a public class called "HelloWorld"
.class public HelloWorld

; specifies the superclass of the declared class
.super java/lang/Object

; declares a class field (variable)
.field public static final PI F = 3.14

; declares a method called main() in the declared class
.method public static main([Ljava/lang/String;)V

; sets the maximum size of the operand stack of the method
.limit stack 2

; sets the maximum number of local variables of the method
.limit locals 3

; specifies a name to local variable #0
; used in debug printout, no impact on execution
.var 0 is Count I from Label1 to Label2

; specifies a try-catch block with 3 labels
.catch java/io/IOException from L1 to L2 using IO_Handler

; adds the throws clause to the method declaration
.throws java/io/IOException

; ends the method declaration
.end method

JVM Instructions - Statements to be translated to JVM instructions. Each instruction statement starts with the mnemonic of a JVM opcode. If operation parameters are needed, they are provided after the mnemonic. Here are some Examples.

; Load the value from variable slot 0,
; which holds the address of "this" object in an instance method
; No parameter is needed
aload_0

; Invoke the constructor of the base class.
; The method reference is provided as a single parameter
; which will be moved to the constant pool by the compiler.
; invokenonvirtual is alias of opcode invokespecial
invokenonvirtual java/lang/Object/<init>()V

; End the the current method with no return value.
return

; Load the value from the System.out static variable
; 2 parameters are required: the first identifies the variable,
; the second specify the type of the variable.
; Both parameters will be moved to the constant pool by the compiler.
getstatic java/lang/System/out Ljava/io/PrintStream;

; Load a string constant.
; The string is provided as a parameter,
; which will be moved to the constant pool by the compiler.
ldc "Hello World!"

; Invoke the System.out.println() method.
; The method reference is provided as a single parameter
; which will be moved to the constant pool
invokevirtual java/io/PrintStream/println(Ljava/lang/String;)V

; Switch to different labels based some sequential integers
; The starting integer is specified next to the opcode.
; Labels for switching targets are specified one per line.
tableswitch 11
    Label_l1
    Label_l2
    ...
  default : Label_Others

; Switch to different labels based some non-sequential integers
; The starting integer is specified next to the opcode.
; Labels for switching targets are specified one per line.
lookupswitch
  11 : Label_l1
  17 : Label_17
  ...
  default : Label_Others

More Jasmin statement examples are provided later in this chapter.

Labels - Statements to mark offsets in bytecode to be used by flow control instructions. Labels are also used to help source readability. Here are some Examples.

LoopCondition:         ; mark the loop condition
  iload_1              ; load the counter i from variable 1
  ifeq LoopEnd         ; go to label "LoopEnd", if i==0
LoopBody:              ; mark the loop body, not really needed
  ...
  iinc 1 -1            ; decrement the counter: i--
  goto LoopCondition   ; repeat the loop block
LoopEnd:               ; mark the loop end
  ...

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