Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-8356991

Store javac synthetic enum switch map in an immutable list

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Rejected
    • Icon: P4 P4
    • None
    • None
    • tools
    • None

      To ensure enum compatibility with separate compilation, when an enum switch operates on an enum not in the same compilation unit, javac generates a synthetic class containing the switch map for all non-local enums switched. Examples include `jdk.internal.classfile.impl.BytecodeHelper$1` that stores switch data for `java.lang.classfile.Opcode` and `java.lang.classfile.TypeKind`.

      Currently, this map uses an int array for each enum. Such an array is fine, but it is mutable, and as a result, JIT compilers cannot trust the contents of these arrays.

      A solution to this lack of trusting can be to move the int array to an immutable list returned by `List.of`. The shortcoming would be that boxing and unboxing would increase code size; however, an examination to javap output for initialization of the Opcode switch map for BytecodeHelpers see the code size grow from 2.6k bytes to 2.8k bytes, and there seems not have been requests to shrink these maps (as opposed to many requests to shrink <clinit> for enum themselves to allow more constants), so the risk from this change should be low.

            liach Chen Liang
            liach Chen Liang
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: