RFR: 8269957: facilitate alternate impls of NameTable and Name [v4]

Vicente Romero vromero at openjdk.org
Fri Aug 25 23:03:00 UTC 2023


On Thu, 24 Aug 2023 18:12:04 GMT, Archie Cobbs <acobbs at openjdk.org> wrote:

>> The `Name.Table` class is used by the compiler to hold unique instances of strings as `Name` objects.
>> 
>> In theory the `Name` superclass supports alternate implementations beyond the two existing implementations (`SharedNameTable` and `UnsharedNameTable`), but its current design presumes that strings are stored as UTF-8 byte arrays, which discourages other approaches.
>> 
>> The goal of this PR is to refactor things to allow for more flexibility in alternate `Name` implementations.
>> 
>> As a simple test case of this idea, it should be relatively simple to implement a `Name.Table` that stores `String`s in a hash table. This patch includes such an example in the new class `StringNameTable`, which can be enabled via the `-XDuseStringTable=true` command line flag.  A simple performance test with this class enabled ([JavacNameTable.java.txt](https://github.com/openjdk/jdk/files/11602852/JavacNameTable.java.txt)) shows a 17% speedup.
>> 
>> Changes:
>> * Remove all byte-oriented methods from the `Name` and `Name.Table` API's, except for those that import/export Modified UTF-8.
>> * Change the semantics of `Name.subName()` so the offset is a character offset, not a byte offset.
>> * Consolidate the common UTF-8 machinery of `SharedNameTable` and `UnsharedNameTable` into a new common superclass `Utf8NameTable`.
>> * Rename `Name.lastIndexOf()` -> `Name.lastIndexOfAscii()` to more accurately reflect its expected behavior.
>> * Add new `StringNameTable` implementation.
>
> Archie Cobbs has updated the pull request with a new target base due to a merge or a rebase. The pull request now contains 11 commits:
> 
>  - Merge branch 'master' into JDK-8269957
>  - Merge branch 'master' into JDK-8269957
>  - Merge branch 'master' into JDK-8269957
>  - Merge branch 'master' into JDK-8269957
>  - Move equals() table check into common superclass.
>  - Add Name.Table factory methods to Names class.
>  - Add StringNameTable as a new (optional) Name.Table implementation.
>  - Add a few more default method implementations to Name superclass.
>  - Revert some unnecessary changes.
>  - Merge branch 'master' into JDK-8269957
>  - ... and 1 more: https://git.openjdk.org/jdk/compare/f2399546...e386ea3e

src/jdk.compiler/share/classes/com/sun/tools/javac/util/Utf8NameTable.java line 2:

> 1: /*
> 2:  * Copyright (c) 1999, 2021, Oracle and/or its affiliates. All rights reserved.

nit: copyright year should only be 2023

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/13282#discussion_r1306201837


More information about the compiler-dev mailing list