3.11. Operations on the Operand Stack

The Java Virtual Machine has a large complement of instructions that manipulate the contents of the operand stack as untyped values. These are useful because of the Java Virtual Machine’s reliance on deft manipulation of its operand stack. For instance:

public long nextIndex() {    return index++;}private long index = 0;

is compiled to:

Method long nextIndex()0   aload_0        // Push this1   dup            // Make a copy of it2   getfield #4    // One of the copies of this is consumed                   // pushing long field index,                   // above the original this5   dup2_x1        // The long on top of the operand stack is                   // inserted into the operand stack below the                   // ...

Get The Java® Virtual Machine Specification, Java SE 7 Edition, Third Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.