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

Optimize Tokens' use of Names

    XMLWordPrintable

    Details

    • Type: Enhancement
    • Status: Resolved
    • Priority: P4
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: 17
    • Component/s: tools
    • Labels:
    • Subcomponent:
    • Resolved In Build:
      b07

      Description

      From compiler-dev


      When I read the code at `jdk.compiler/com.sun.tools.javac.parser.Tokens` and ``jdk.compiler/com.sun.tools.javac.util.Names`, I find a point which can be possibly improved.

      The constructor of the class `Tokens` invokes `Names.instance(context)` to initialize `Names` which would initialize many unrelated names. Then, this constructor uses the method `enterKeyword` to initialize the names about `TokenKind` and to set `maxKey`. Because `Names.instance(context)` initializes many unrelated names, the `Name.index` becomes very large so that the `maxKey` also becomes very large. Then, the constructor creates an array `key` by using the code `key = new TokenKind[maxKey+1]`. We can identify that the variable `key` is unnecessary to be so large.

      I would like to initialize the related names, which are about `TokenKind`, at the beginning of the constructor of the class `Names` to improve the code. The complete patch is shown at the end of this email.

      When using the code of the master branch, the length of the array `Tokens.key` is 4280. When using my patch, the length of the array `Tokens.key` is 383. The improvement is obvious.

        Attachments

          Issue Links

            Activity

              People

              Assignee:
              mcimadamore Maurizio Cimadamore
              Reporter:
              jjg Jonathan Gibbons
              Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

                Dates

                Created:
                Updated:
                Resolved: