tableswitch 0xaa

Jumps through a table indexed by an int (dense case values).

Opcode
0xaa (170)
Family
Branches and switches
Operands
  • 0–3 bytes: padding to a multiple of 4
  • 4 bytes: default offset
  • 4 bytes: low
  • 4 bytes: high
  • 4 × (high − low + 1) bytes: offsets
Length
variable
Operand stack
…, index (int) → …
Can throw
nothing at run time (beyond linking errors)

What it does

Jumps through a table of offsets: one per value from low to high, plus a default. After the opcode, 0 to 3 padding bytes align the table to a multiple of four bytes from the start of the method's code.

javac chooses between tableswitch and lookupswitch by estimating the size and speed of each: dense case values make a table, sparse ones a sorted lookup. Gaps in a table point at the default.

A switch on a String switches on its hashCode() first; a switch on an enum switches on its ordinal() or on a lookup table; a pattern switch switches on the result of an invokedynamic that picks the case.

How often javac uses it

In JDK 25.0.5's java.base module, tableswitch appears 659 times in 329 of its 7,391 classes: 0.03% of all instructions, the 117th most common of 194 opcodes in use. Some of the methods that use it: java.io.DataInputStream.readUTF, java.io.FilePermission.initNb, java.io.ObjectInputStream.readObject0, java.io.ObjectInputStream$BlockDataInputStream.readBlockHeader.

Examples

From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; tableswitch is highlighted.

static int dense(int day) in Tour, compiled by javac 25
112switch (day) {
0iload_0 // day
1tableswitch { 1→32, 2→35, 3→38, 4→41, default→44 }
113case 1: return 10;
32bipush 10
114case 2: return 20;
35bipush 20
115case 3: return 30;
38bipush 30
116case 4: return 40;
41bipush 40
117default: return 0;

Open in the viewer

static int dense(int n) in Switches, compiled by javac 25
9switch (n) {
0iload_0 // n
1tableswitch { 0→32, 1→35, 2→38, 3→41, default→44 }
10case 0: return 10;
32bipush 10
11case 1: return 11;
35bipush 11
12case 2: return 12;
38bipush 12
13case 3: return 13;
41bipush 13
14default: return -1;

Open in the viewer

Related instructions

lookupswitch Jumps through sorted match/offset pairs (sparse case values).goto Jumps unconditionally.

Specification: JVMS §6.5, tableswitch (Java SE 25).