ineg 0x74

Negates the int on top of the stack.

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

What it does

Negates the int on top of the stack: -x in Java. Negating the minimum value gives the minimum value back, because the result wraps around.

How often javac uses it

In JDK 25.0.5's java.base module, ineg appears 279 times in 77 of its 7,391 classes: 0.01% of all instructions, the 138th most common of 194 opcodes in use. Some of the methods that use it: java.io.Reader$2.skip, java.lang.AbstractStringBuilder.delete, java.lang.Character$UnicodeScript.of, java.lang.FdLibm$IEEEremainder.__ieee754_fmod.

Example

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

static int ints(int a, int b) in Tour, compiled by javac 25
… 10 instructions before
10x = x / b % 7;
10idiv
11bipush 7
13irem
14istore_2 // x
11x = -x;
15iload_2 // x
16ineg
17istore_2 // x
12x = (x << 3) | (x >> 2) ^ (x >>> 1) & 0xff;
18iload_2 // x
20ishl
21iload_2 // x
… 13 instructions after

Open in the viewer

Related instructions

lneg Negates the long on top of the stack.fneg Negates the float on top of the stack.dneg Negates the double on top of the stack.

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