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

Convenience method to check if a constant pool entry matches nominal descriptors

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • tbd
    • 24
    • core-libs
    • None

      Currently, to efficiently check if a `ClassEntry`, such as one from an `InvokeInstruction`, is of a particular class, we use such a pattern (as seen in JEP 486 demo):

      inst.owner().name().equalsString("java/lang/System")

      This pattern has a few issues:

      1. This is not straightforward. Users may be tempted to write

      inst.owner().asSymbol().equals(CD_System)

      unaware of the degraded performance from extra conversions.

      2. We aim to reduce the use of "internal names" with encapsulation. Direct use of "java/lang/System" goes against this, and we have no constants offered to reduce such error-prone use of internal name.

      Thus, I propose a new API in ClassEntry:

      boolean equalsSymbol(ClassDesc)

      that can be used conveniently to check the identity of a class entry with a clean syntax and better performance.

      In addition, this applies to Method type/class name matching for UTF8, and other structures; for example, matching a method type for utf8 can be as simple as testing the initial `(` for the fast path. We should add these series of convenience methods to promote better usage habbits.

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

              Created:
              Updated: