3.2. Use of Constants, Local Variables, and Control Constructs

Java Virtual Machine code exhibits a set of general characteristics imposed by the Java Virtual Machine’s design and use of types. In the first example we encounter many of these, and we consider them in some detail.

The spin method simply spins around an empty for loop 100 times:

void spin() {     int i;     for (i = 0; i < 100; i++) {         ;    // Loop body is empty     } }

A compiler might compile spin to:

0   iconst_0        // Push int constant 0 1   istore_1        // Store into local variable 1 (i=0) 2   goto 8          // First time through don't increment 5   iinc 1 1        // Increment local variable 1 by 1 (i++) 8   iload_1         // Push local variable 1 (i) 9    ...

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

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.