lookupswitch 0xab
Jumps through sorted match/offset pairs (sparse case values).
- Opcode
0xab(171)- Family
- Branches and switches
- Operands
- 0–3 bytes: padding to a multiple of 4
- 4 bytes: default offset
- 4 bytes: number of pairs
- 8 × pairs bytes: match and offset pairs, sorted
- Length
- variable
- Operand stack
…, key (int) → …- Can throw
- nothing at run time (beyond linking errors)
What it does
Jumps through sorted pairs of (value, offset), or to the default if none matches. Padding after the opcode aligns the pairs to four bytes, and the sort lets the JVM binary-search them.
javac uses it for sparse case values, where a tableswitch would be mostly gaps. A switch on Strings starts with a lookupswitch on the strings' hash codes.
How often javac uses it
In JDK 25.0.5's java.base module, lookupswitch appears 497 times in 250 of its 7,391 classes: 0.03% of all instructions, the 121st most common of 194 opcodes in use. Some of the methods that use it: java.io.DataInputStream.readLine, java.io.FilePermission.getMask, java.io.LineNumberInputStream.read, java.io.LineNumberReader.read.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; lookupswitch is highlighted.
static int sparse(int code) in Tour, compiled by javac 25static int price(EnumSwitch$Size size) in EnumSwitch, compiled by javac 25Related instructions
tableswitch Jumps through a table indexed by an int (dense case values).goto Jumps unconditionally.
Specification: JVMS §6.5, lookupswitch (Java SE 25).