lcmp 0x94
Compares two longs and pushes -1, 0 or 1.
- Opcode
0x94(148)- Family
- Comparisons
- Operands
- none
- Length
- 1 byte
- Operand stack
…, value1 (long), value2 (long) → …, result (int)- Can throw
- nothing at run time (beyond linking errors)
What it does
Compares two longs: pushes 1 if the first is greater, 0 if they are equal, -1 if it is less. Long.compare returns the same values.
There are no long branch instructions, so if (a < b) on longs is lcmp followed by an int branch on the result. javac branches past the then-part when the condition is false, so for a < b it emits lcmp and ifge.
How often javac uses it
In JDK 25.0.5's java.base module, lcmp appears 3,104 times in 598 of its 7,391 classes: 0.16% of all instructions, the 72nd most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.skip, java.io.BufferedReader.skip, java.io.ByteArrayInputStream.skip, java.io.CharArrayReader.skip.
Example
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; lcmp is highlighted.
static boolean longLess(long a, long b) in Compare, compiled by javac 25Related instructions
fcmpl Compares two floats and pushes -1, 0 or 1; NaN gives -1.dcmpg Compares two doubles and pushes -1, 0 or 1; NaN gives 1.ifge Pops an int; jumps if it is greater than or equal to zero.
Specification: JVMS §6.5, lcmp (Java SE 25).