-
CSR
-
Resolution: Approved
-
P4
-
None
-
minimal
-
New additions have no compatibility concerns
-
Java API
-
SE
Summary
Add int
, long
, float
, double
overloads to CodeBuilder::loadConstant
.
Problem
Currently loadConstant
goes through a megamorphic call site of ConstantDesc
. If users are just passing primitive numbers, they have to go through redundant boxing and pattern matching. In addition, if the user messed up the type of ConstantDesc
, they may have wrong types pushed to the bytecode stack.
Solution
Provide primitive overloads to loadConstant
. This avoids boxing for those cases, and the instruction optimization checks in those overloads are simpler. By specifying the type at the bytecode generator call site, we can ensure we push the right constants in the generated code, such as loadConstant(1)
vs loadConstant(1L)
.
Specification
/**
* Generate an instruction pushing a constant int value onto the operand stack.
* This is equivalent to {@link #loadConstant(ConstantDesc) loadConstant(Integer.valueOf(value))}.
* @param value the int value
* @return this builder
* @since 24
*/
default CodeBuilder loadConstant(int value) {
/**
* Generate an instruction pushing a constant long value onto the operand stack.
* This is equivalent to {@link #loadConstant(ConstantDesc) loadConstant(Long.valueOf(value))}.
* @param value the long value
* @return this builder
* @since 24
*/
default CodeBuilder loadConstant(long value) {
/**
* Generate an instruction pushing a constant float value onto the operand stack.
* This is equivalent to {@link #loadConstant(ConstantDesc) loadConstant(Float.valueOf(value))}.
* @param value the float value
* @return this builder
* @since 24
*/
default CodeBuilder loadConstant(float value) {
/**
* Generate an instruction pushing a constant double value onto the operand stack.
* This is equivalent to {@link #loadConstant(ConstantDesc) loadConstant(Double.valueOf(value))}.
* @param value the double value
* @return this builder
* @since 24
*/
default CodeBuilder loadConstant(double value) {
- csr of
-
JDK-8339217 Optimize ClassFile API loadConstant
-
- Resolved
-
- relates to
-
JDK-8334712 JEP 484: Class-File API
-
- Closed
-