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 25static int dense(int n) in Switches, compiled by javac 25Related instructions
lookupswitch Jumps through sorted match/offset pairs (sparse case values).goto Jumps unconditionally.
Specification: JVMS §6.5, tableswitch (Java SE 25).