Java Reference
In-Depth Information
10.2.3 JVM Instructions
While an exhaustive list of the JVM's instructions appears elsewhere [Mey,
JVM], we describe members of various families of instructions to provide an
overview of the JVM instruction set.
Arithmetic
JVM instructions that compute results based on simple mathematical functions
operate by popping their required number of operands (typically 2) from the
runtime stack, computing the required result, and finally pushing the result
on TOS.
iadd
The iadd instruction pops the top two elements o
of
the stack and pushes their sum onto the stack. The
instruction expects the operands to be primitive int
types, and the result is also int type. All operations
involving int types are performed using 32-bit, two's
complement arithmetic. Such arithmetic never throws
any exceptions: overflow or underflow occur silently.
ff
5
7
12
Before
After
Instructions that perform addition on other primitive types are fadd (float),
ladd (long), and dadd (double). There are no instructions for integer types that
are shorter than int,suchasbyte and short. Such arithmetic is performed on
int types with precision lost as data are stored. Instructions are available for
performing the usual arithmetic operations such as subtraction, multiplication,
division, and remainder.
Register Traffic
As is frequently the case with IRs, the JVM has (practically) an unlimited
number of virtual registers it can reference. Each method declares how many
registers it can reference, and the JVM sets aside space for those registers for
each invocation of the method. Such space is usually allocated in a method's
stack frame (see Section 12.2 on page 447).
JVM registers typically host a method's local variables , which are simi-
lar to a machine's architected registers (Section 13.3 on page 505). Registers
starting from 0 are set aside for a method's parameters. For static methods,
register 0 holds the method's first declared parameter. For instance-based
methods, register 0 holds this (the object's self-reference) and register 1 holds
the method's first declared parameter. When a method is invoked, parameter
 
 
Search WWH ::




Custom Search