lsub 0x65

Subtracts two longs on top of the stack; pushes the result.

Opcode
0x65 (101)
Family
Arithmetic and bitwise
Operands
none
Length
1 byte
Operand stack
…, value1 (long), value2 (long) → …, result (long)
Can throw
nothing at run time (beyond linking errors)

What it does

a - b on two longs: pops b, then a, and pushes the result.

Overflow wraps around silently, as in Java. Math.subtractExact is the version that throws.

How often javac uses it

In JDK 25.0.5's java.base module, lsub appears 1,631 times in 293 of its 7,391 classes: 0.08% of all instructions, the 97th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedReader.skip, java.io.FileInputStream.readAllBytes, java.io.InputStream.skip, java.io.LineNumberInputStream.skip.

Examples

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

static long longs(long a, long b) in Tour, compiled by javac 25
… 1 instruction before
17long x = a + b - a * b;
1lload_2 // b
3lload_0 // a
4lload_2 // b
7lstore 4// x
18x = x / b % 7;
9lload 4// x
11lload_2 // b
12ldiv
13ldc2_w #7// 7L
16lrem
… 22 instructions after

Open in the viewer

static long mix(long a, int b, short c, byte d, double e, float f, char g, boolean h) in Numbers, compiled by javac 25
… 4 instructions before
30long r = a * b + c - d;
4iload_3 // c
5i2l
7iload 4// d
9i2l
10lsub
11lstore 10// r
31r ^= (long) (e * f);
13lload 10// r
15dload 5// e
17fload 7// f
19f2d
20dmul
… 53 instructions after

Open in the viewer

Related instructions

isub Subtracts two ints on top of the stack; pushes the result.fsub Subtracts two floats on top of the stack; pushes the result.dsub Subtracts two doubles on top of the stack; pushes the result.

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