∟Constant Loading Instructions

This section describes JVM instructions that load a constant onto the operand stack: ldc*, *push and *const_*.

What Are Constant Loading Instructions? Constant loading instructions load constants of different types onto the operand stack. Their mnemonics have a pattern of ldc*, *push or *const_*.

The table below describes constant loading instructions. P. is the count of bytes following the opcode as operation parameters. I. is the count elements consumed from the operand stack as operation input. O. is the count elements added to the operand stack as operation output.

Mnemonic       C.  P.  I.  O.  Description
-------------  --  --  --  --  ----------------------------------------
iconst_m1      02   0   0   1  Load int -1
iconst_0       03   0   0   1  Load int 0
iconst_1       04   0   0   1  Load int 1
iconst_2       05   0   0   1  Load int 2
iconst_3       06   0   0   1  Load int 3
iconst_4       07   0   0   1  Load int 4
iconst_5       08   0   0   1  Load int 5
lconst_0       09   0   0   2  Load long 0
lconst_1       0A   0   0   2  Load long 1
fconst_0       0B   0   0   1  Load float 0.0
fconst_1       0C   0   0   1  Load float 1.0
fconst_2       0D   0   0   1  Load float 2.0
fconst_0       0B   0   0   1  Load float 0.0
fconst_1       0C   0   0   1  Load float 1.0
fconst_2       0D   0   0   1  Load float 2.0
dconst_0       0E   0   0   1  Load double 0.0
dconst_1       0F   0   0   1  Load double 1.0
aconst_null    01   0   0   1  Load null
bipush         10   1   0   1  Push parameter as byte onto stack
sipush         11   2   0   1  Push 2 parameters as short onto stack
ldc            12   1   0   1  Load constant with parameter as index
ldc_w          13   2   0   1  = ldc + with 2 parameters as wide index
ldc2_w         14   2   0   2  = ldc_w + for 2-slot (64-bit) constant

As you can see from the table, for a *const_* instruction, the constant to be loaded onto the stack is hardcoded in the opcode.

For bipush or sipush, the constant to be loaded onto the stack is provided 1 parameter or 2 parameters.

For ldc, ldc_w or ldc2_w, the constant to be loaded onto the stack is stored in the constant pool. It takes 1 parameter or 2 parameter as the index to fetch the constant from the constant pool.

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