JDK-8339287 : Remove rarely-used accessor methods from Opcode
  • Type: CSR
  • Component: core-libs
  • Sub-Component: java.lang.classfile
  • Priority: P4
  • Status: Closed
  • Resolution: Approved
  • Fix Versions: 24
  • Submitted: 2024-08-29
  • Updated: 2024-08-30
  • Resolved: 2024-08-30
Related Reports
CSR :  
Relates :  
Description
Summary
-------

Remove accessor methods on `Opcode` that provides access to non-generic attributes.

Problem
-------

Many attributes of `Opcode` are not universal, such as the type it interacts with (which may or may not be an output type), the constant value it loads, the local variable slot it interacts with. They take up fields in the enum and make the `Opcode` enum deviate from a data-oriented model.

Solution
--------

Remove these specific accessors. These specific attributes are already accessible if these singleton intrinsic `Instruction`s are parsed from a `Code` attribute in a `CodeModel`. The remainder of the attributes, including `Kind`, `bytecode`, and `sizeIfFixed`, are helpful for general-purpose Opcode processing, such as validation or writing class files.

Specification
-------------
    --- a/src/java.base/share/classes/java/lang/classfile/Opcode.java
    +++ b/src/java.base/share/classes/java/lang/classfile/Opcode.java
         /**
    -     * {@return bytecode}
    +     * {@return the opcode value} For {@linkplain #isWide() wide} pseudo-opcodes, returns the
    +     * first 2 bytes of the instruction, which are the {@code wide} opcode and the functional
    +     * local variable opcode, as a U2 value.
          */
         public int bytecode() { return bytecode; }
     
         /**
    -     * {@return true if the instruction has extended local variable index by additional bytes}
    +     * {@return true if this is a pseudo-opcode modified by {@code wide}}
    +     *
    +     * @see #ILOAD_W
    +     * @see #LLOAD_W
    +     * @see #FLOAD_W
    +     * @see #DLOAD_W
    +     * @see #ALOAD_W
    +     * @see #ISTORE_W
    +     * @see #LSTORE_W
    +     * @see #FSTORE_W
    +     * @see #DSTORE_W
    +     * @see #ASTORE_W
    +     * @see #RET_W
    +     * @see #IINC_W
          */
         public boolean isWide() { return bytecode > 255; }
     
         /**
    -     * {@return size of the instruction if fixed, or -1 otherwise}
    +     * {@return size of the instruction in bytes if fixed, or -1 otherwise} This size includes
    +     * the opcode itself.
          */
         public int sizeIfFixed() { return sizeIfFixed; }
     
    @@ -1138,42 +1118,4 @@ public static enum Kind {
          * {@return instruction kind}
          */
         public Kind kind() { return kind; }
    -
    -    /**
    -     * {@return primary type kind for instructions operating with at least one type, or null otherwise}
    -     */
    -    public TypeKind primaryTypeKind() {
    -
    -    /**
    -     * {@return secondary type kind for instructions operating with two types, or null otherwise}
    -     */
    -    public TypeKind secondaryTypeKind() {
    -
    -    /**
    -     * {@return local variable slot for instructions operating with local variable, or -1 otherwise}
    -     */
    -    public int slot() {
    -
    -    /**
    -     * {@return constant value for constant instructions, or null otherwise}
    -     */
    -    public ConstantDesc constantValue() {
    -
    -    /**
    -     * {@return true if the instruction represents an unconditional branch}
    -     */
    -    public boolean isUnconditionalBranch() {
     }
    
Comments
Moving to Approved.
30-08-2024