imul 0x68

Multiplies two ints on top of the stack; pushes the result.

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

What it does

a * b on two ints: pops b, then a, and pushes the result.

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

How often javac uses it

In JDK 25.0.5's java.base module, imul appears 1,140 times in 363 of its 7,391 classes: 0.06% of all instructions, the 105th most common of 194 opcodes in use. Some of the methods that use it: java.io.DataOutputStream.writeChars, java.io.ObjectStreamClass$DeserializationConstructorsCache$Key.hashCode, java.io.ObjectStreamClass$FieldReflectorKey.<init>, java.io.RandomAccessFile.writeChars.

Examples

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

private static Integer lambda$sumOfSquares$0(Integer x) synthetic in Lambdas, compiled by javac 25
9return xs.stream().map(x -> x * x).reduce(0, Integer::sum);
0aload_0 // x
1invokevirtual #42// Integer.intValue() : int
4aload_0 // x
5invokevirtual #42// Integer.intValue() : int
9invokestatic #29// Integer.valueOf(int) : Integer

Open in the viewer

double length() in Point, compiled by javac 25
9return Math.sqrt(x * x + y * y);
0aload_0 // this
1getfield #14// Point.x : int
4aload_0 // this
5getfield #14// Point.x : int
9aload_0 // this
10getfield #20// Point.y : int
13aload_0 // this
14getfield #20// Point.y : int
17imul
18iadd
19i2d
20invokestatic #23// Math.sqrt(double) : double

Open in the viewer

Related instructions

lmul Multiplies two longs on top of the stack; pushes the result.fmul Multiplies two floats on top of the stack; pushes the result.dmul Multiplies two doubles on top of the stack; pushes the result.

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