idiv 0x6c

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

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

What it does

a / b on two ints: 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.

How often javac uses it

In JDK 25.0.5's java.base module, idiv appears 485 times in 175 of its 7,391 classes: 0.02% of all instructions, the 123rd most common of 194 opcodes in use. Some of the methods that use it: java.io.LineNumberInputStream.available, java.lang.AbstractStringBuilder.repeat, java.lang.Character$UnicodeBlock.of, java.lang.CharacterData00.findInCharMap.

Examples

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

static int doWhile(int n) in Loops, compiled by javac 25
21int digits = 0;
1istore_1 // digits
23n /= 10;
2iload_0 // n
3bipush 10
6istore_0 // n
24digits++;
7iinc 1, 1// digits
25} while (n != 0);
10iload_0 // n
26return digits;
14iload_1 // digits

Open in the viewer

static int half(int n) in Asserts, compiled by javac 25
4assert n % 2 == 0 : "odd: " + n;
0getstatic #7// Asserts.$assertionsDisabled : boolean
6iload_0 // n
12new #13// AssertionError
15dup
16iload_0 // n
17invokedynamic #15// makeConcatWithConstants(int) : String ⇐ StringConcatFactory.makeConcatWithConstants "odd: \1"
22invokespecial #19// new AssertionError(Object)
5return n / 2;
26iload_0 // n
28idiv

Open in the viewer

Related instructions

ldiv Divides two longs on top of the stack; pushes the result.fdiv Divides two floats on top of the stack; pushes the result.ddiv Divides two doubles on top of the stack; pushes the result.

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