JVM Tutorials - Herong's Tutorial Examples - v5.14, by Herong Yang
JVM Method Frame Architecture
This section provides a quick introduction of JVM method frame architecture and components: local variable array and operand stack.
One of the key elements of the JVM design is the method frame architecture. As we learned earlier in this book, whenever an execution thread invokes a method, it will create a new method frame in memory to manage data for the invoked method. The new method frame will pushed onto the frame stack of the current thread.
There are 2 main components in a method frame: local variable array and operand stack as shown in the diagram below:
What Is Local Variable Array? Local variable array is an array of 4-byte data elements (also called slots) in the a method frame. It is used to store local variables of the current method, including:
Note that variables of "long" and "double" data types (8-byte data types) are occupying 2 slots in the local variable array instead of 1.
JVM instructions can access any element in the local variable array by its index. Here are some examples:
iinc 2, 1 // increment local variable 2 by 1 aload_0 // load address from local variable 0 to stack istore_1 // remove int from stack, store it to variable 1
What Is Operand Stack? Operand stack is a FILO (First-In, Last-Out) stack of 4-byte data elements in a method frame. It is used to store operands to be consumed by upcoming JVM instructions and/or their result.
JVM instructions can push/pop values to/from the operand stack. Here are some examples:
iload_1 // load int from local variable 1 to stack iload_2 // load int from local variable 2 to stack iadd // remove 2 operands, add them, push result to stack istore_1 // remove int from stack, store it to variable 1
Table of Contents
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 Stack, Frame and Stack Overflow
Thread Testing Program and Result
CPU Impact of Multi-Thread Applications
I/O Impact of Multi-Thread Applications
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
JRockit JVM 28.2.7 by Oracle Corporation
►JVM Bytecode and Instruction Set
Walkthrough of "javap -c -v" Command Output
►JVM Method Frame Architecture
Local Variable Array Instructions
Arithmetic Operation Instructions
Bitwise Operation Instructions
Method Invocation Instructions