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

Convenience method to check if a ClassEntry matches a ClassDesc

XMLWordPrintable

    • Icon: CSR CSR
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • core-libs
    • None
    • source
    • minimal
    • Addition of a new method in a sealed hierarchy has minimal compatibility risk.
    • Java API
    • SE

      Summary

      Add a new utility method, ClassEntry::equalsSymbol(ClassDesc), to facilitate easy comparison of ClassEntry with ClassDesc constants.

      Problem

      ClassEntry is often compared against desired classes during bytecode transformation, such as ce.name().equalsString("java/lang/System") if we want to detect if a call is to System::exit.

      However, we intend to reduce the use of "internal names" which is a legacy baggage. Such internal names are not available as constants, so writing them manually is error-prone.

      We have constants for ClassDesc, but the current way to compare ClassEntry to ClassDesc is ce.asSymbol().equals(cd). This approach has a few problems:

      1. The conversion of ClassEntry to ClassDesc via asSymbol involves unnecessary transformations and is performance-wise undesirable.
      2. If the ClassEntry points to a Utf8Entry with invalid content, asSymbol will unexpectedly fail.

      Solution

      To facilitate good programming habits with the ClassFile API, we need a new ClassEntry::equalsSymbol(ClassDesc), which:

      1. Allows usage of known constants, such as equalsSymbol(CD_System);
      2. Is as efficient as name().equalsString("java/lang/System");
      3. Does not fail if the ClassEntry itself is invalid.

      Specification

          /**
           * {@return whether this class entry describes the same class as the provided symbol}
           *
           * @param symbol the symbol to compare to
           */
          boolean equalsSymbol(ClassDesc symbol);

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

              Created:
              Updated: