∟What Is JVM Bytecode

This section provides a quick introduction of JVM bytecode, which refers to the JVM instruction set and programs compiled in those instructions.

What Is JVM Bytecode? JVM bytecode refers to:

In JVM instruction set, opcodes (operation codes) are coded in one byte. This is why it is called bytecode.

The latest version of JVM bytecode has about 200 opcodes, which are mapped to about 200 out of 256 possible one-byte values. Here are some examples:

Mnemonic   Opcode   Actions on the operand stack
--------   ------   ----------------------------
iload_1    0x1B     load an integer from variable #1
iload_2    0x1C     load an integer from variable #2
iadd       0x60     pop off 2 integers, add them, push result back
ireturn    0xAC     pop off an integer and return it to caller

To see a bytecode program (.class file) example, you can compile the following Java program.

herong> more Add.java
  class Add {
    public int add(int a, int b) {
      return a + b;
    }
  }

herong> javac Add.java
herong> ls -l Add.*
  -rw-r--r--  1 herong  staff  236 Nov  5 09:40 Add.class
  -rwxrwxr-x  1 herong  staff   72 Nov  5 09:40 Add.java

Then view the .class file generated by the compiler in hex format.

herong> od -t x1 -An Add.class

ca  fe  ba  be  00  00  00  41  00  0f  0a  00  02  00  03  07
00  04  0c  00  05  00  06  01  00  10  6a  61  76  61  2f  6c
61  6e  67  2f  4f  62  6a  65  63  74  01  00  06  3c  69  6e
69  74  3e  01  00  03  28  29  56  07  00  08  01  00  03  41
64  64  01  00  04  43  6f  64  65  01  00  0f  4c  69  6e  65
4e  75  6d  62  65  72  54  61  62  6c  65  01  00  03  61  64
64  01  00  05  28  49  49  29  49  01  00  0a  53  6f  75  72
63  65  46  69  6c  65  01  00  08  41  64  64  2e  6a  61  76
61  00  20  00  07  00  02  00  00  00  00  00  02  00  00  00
05  00  06  00  01  00  09  00  00  00  1d  00  01  00  01  00
00  00  05  2a  b7  00  01  b1  00  00  00  01  00  0a  00  00
00  06  00  01  00  00  00  01  00  01  00  0b  00  0c  00  01
00  09  00  00  00  1c  00  02  00  03  00  00  00  04  1b  1c
60  ac  00  00  00  01  00  0a  00  00  00  06  00  01  00  00
00  03  00  01  00  0d  00  00  00  02  00  0e

You can see that there is a sequence of opcodes "1b 1c 60 ac" in the bytecode. It represents 4 JVM instructions generated from the return statement in the Java source code:

As Java statement in Add.java:
  return a + b;

As JVM instructions in Add.class:
  1b 1c 60 ac

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