lrem 0x71

Takes the remainder of two longs on top of the stack; pushes the result.

Opcode
0x71 (113)
Family
Arithmetic and bitwise
Operands
none
Length
1 byte
Operand stack
…, value1 (long), value2 (long) → …, result (long)
Can throw
ArithmeticException

What it does

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

Dividing by zero throws ArithmeticException. Dividing the minimum value by -1 overflows quietly and gives the minimum value (and a remainder of 0).

How often javac uses it

In JDK 25.0.5's java.base module, lrem appears 173 times in 53 of its 7,391 classes: <0.01% of all instructions, the 144th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Integer.remainderUnsigned, java.lang.Long.toString, java.lang.Math.floorMod, java.math.BigDecimal.layoutChars.

Example

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

static long longs(long a, long b) in Tour, compiled by javac 25
… 7 instructions before
17long x = a + b - a * b;
7lstore 4// x
18x = x / b % 7;
9lload 4// x
11lload_2 // b
12ldiv
13ldc2_w #7// 7L
16lrem
17lstore 4// x
19x = -x;
19lload 4// x
21lneg
22lstore 4// x
20x = (x << 3) | (x >> 2) ^ (x >>> 1) & 0xff;
24lload 4// x
… 16 instructions after

Open in the viewer

Related instructions

irem Takes the remainder of two ints on top of the stack; pushes the result.frem Takes the remainder of two floats on top of the stack; pushes the result.drem Takes the remainder of two doubles on top of the stack; pushes the result.

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