new 0xbb
Allocates an object (uninitialised until its constructor runs).
- Opcode
0xbb(187)- Family
- Objects and types
- Operands
- 2 bytes: constant pool index
- Length
- 3 bytes
- Operand stack
… → …, objectref (uninitialised)- Can throw
InstantiationError
What it does
Allocates an object of a class, with every field zero, and pushes a reference to it. The object cannot be used until a constructor runs: the verifier tracks it as "uninitialised" until invokespecial <init> consumes it.
That is why new Foo(x) is always new, dup, the arguments, then invokespecial: one copy for the constructor, one for the result. The first new of a class initialises it.
How often javac uses it
In JDK 25.0.5's java.base module, new appears 33,545 times in 4,295 of its 7,391 classes: 1.7% of all instructions, the 20th most common of 194 opcodes in use. Some of the methods that use it: java.io.BufferedInputStream.getInIfOpen, java.io.BufferedOutputStream.<init>, java.io.BufferedReader.<init>, java.io.BufferedReader$1.hasNext.
Examples
From the sample classes, compiled by javac 25 with -g. Each Java line is shown above the bytecode it compiled to; new is highlighted.
static List make() in Bridge, compiled by javac 25public Sync() in Sync, compiled by javac 25Related instructions
dup Duplicates the top of the stack.invokespecial Calls a constructor, a private method or a superclass method directly.anewarray Pops a length; pushes a new array of references.
Specification: JVMS §6.5, new (Java SE 25).