lneg 0x75

Negates the long on top of the stack.

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

What it does

Negates the long 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, lneg appears 157 times in 50 of its 7,391 classes: <0.01% of all instructions, the 150th most common of 194 opcodes in use. Some of the methods that use it: java.lang.Long.toString, java.lang.Math.round, java.math.BigDecimal.<init>, java.math.BigInteger.valueOf.

Examples

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

static long longs(long a, long b) in Tour, compiled by javac 25
… 10 instructions before
18x = x / b % 7;
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
27lshl
28lload 4// x
… 13 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
… 22 instructions before
32r += g;
30ladd
31lstore 10// r
33if (h) r = -r;
33iload 9// h
38lload 10// r
40lneg
41lstore 10// r
34int[][] grid = new int[3][4];
45multianewarray #56, 2// int[][]
49astore 12// grid
35grid[1][2] = (int) r;
51aload 12// grid
… 35 instructions after

Open in the viewer

Related instructions

ineg Negates the int 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, lneg (Java SE 25).