∟JASM Assembly Statements

This section provides a quick introduction on JASM assembly statements.

The JASM assembly language consists of 3 types of statements: structural statements, instructions and labels.

Structural Statements - Structural statements use Java syntax to declare classes, fields, methods, and try-catch blocks. Here are some examples:

// declares a public class called "HelloWorld"
public class HelloWorld {...}

// declares a public static method called "main"
public static main([java/lang/String)V {...}

// specifies a try-catch block
try {...} catch (...)

JVM Instructions - Statements to be translated in 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.

// 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.
invokespecial 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 java/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(java/lang/String)V

// Switch to different labels based some sequential integers
// The starting integer is specified next to the opcode.
// Labels for switching targets and default target are specified one per line.
tableswitch 11 to 15 {
    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 and default target are specified one per line,
lookupswitch Label_Others {
  11: Label_l1,
  17: Label_17,
  ...
}

Note that some opcodes with hardcoded parameters needs to be separated. JASM assembler will compile them back hardcoded opcodes. For example:

iload 0    // for iload_0
aload 0    // for aload_0
iconst 0   // for iconst_0
dconst 0   // for dconst_0

More JASM 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