JDK-8323058 : Revisit j.l.classfile.CodeBuilder API surface
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • Submitted: 2024-01-05
  • Updated: 2024-05-09
  • Resolved: 2024-05-02
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availability Release.

To download the current JDK release, click here.
JDK 23
23 b22Fixed
Related Reports
CSR :  
Description
j.l.classfile.CodeBuilder API consist of >230 methods.
The majority of the API methods may be split into three main categories:
- methods building low level bytecode instructions according to JVMS chapter 6.5 (aaload, aastore, aconst_null...)
- methods reconstructing individual subtypes of j.l.classfile.Instruction from given arguments (loadInstruction, storeInstruction, incrementInstruction, branchInstruction...)
- methods modeling high level code blocks (block, ifThen, ifThenElse, trying...)

Existing ClassFile API use cases proved the concept one big CodeBuilder is comfortable. However there are some redundancies, glitches in the naming conventions, some frequently used methods are hard to find and some methods have low practical use.

This enhancement would like to revisit j.l.classfile.CodeBuilder API methods, remove redundancies, fix naming conventions, highlight the most frequently used methods and remove methods with low practical use.
Comments
Changeset: ae82405f Author: Adam Sotona <asotona@openjdk.org> Date: 2024-05-02 10:08:29 +0000 URL: https://git.openjdk.org/jdk/commit/ae82405ff7a48bc6e61b1d05bf74839b7ed50c11
02-05-2024

A pull request was submitted for review. URL: https://git.openjdk.org/jdk/pull/17282 Date: 2024-01-05 15:17:13 +0000
01-02-2024

Following methods are redundant and should be removed: - incrementInstruction -> iinc - lookupSwitchInstruction -> lookupswitch - tableSwitchInstruction -> tableswitch - throwInstruction -> athrow - invokeDynamicInstruction -> invokedynamic - stackInstruction has no practical use and can be replaced as with(StackInstruction.of(...)) - monitorInstruction has no practical use and can be replaced directly by monitorenter or monitorexit - nopInstruction -> nop - typecheckInstruction has no practical use and can be replaced directly by checkcast or instanceof Remaining xyzInstruction methods should be renamed: - loadInstruction -> loadLocal - storeInstruction -> storeLocal - branchInstruction -> branch - invokeInstruction -> invoke - newObjectInstruction -> newObject - newPrimitiveArrayInstruction -> newPrimitiveArray - newReferenceArrayInstruction -> newReferenceArray - newMultidimensionalArrayInstruction -> newMultidimensionalArray - arrayLoadInstruction -> arrayLoad - arrayStoreInstruction -> arrayStore - convertInstruction -> conversion - operatorInstruction -> operator - constantInstruction -> loadConstant - fieldInstruction -> fieldAccess - instanceof_ -> instanceOf - returnInstruction -> return_ Any existing transformations depending on XyzInstruction <-> CodeBuilder.xyzInstruction(...) relation between Instruction subtype and relevant CodeBuilder methods can be converted to CodeBuilder.with(XyzInstruction.of(...)) pattern.
05-01-2024