RFR: 8327156: Avoid copying in StringTable::intern(oop, TRAPS)
Casper Norrbin
cnorrbin at openjdk.org
Fri Oct 11 13:56:58 UTC 2024
On Thu, 3 Oct 2024 13:54:02 GMT, Casper Norrbin <cnorrbin at openjdk.org> wrote:
> Hi everyone,
>
> String interning can be done on 4 different types of strings:
> - oop-strings (unicode)
> - oop-strings (latin1)
> - Symbols (non-null-terminated utf8)
> - null-terminated utf8 char arrays
>
> Currently, when doing interning, all 4 types are first converted to unicode and copied to a jchar array. This array is used when looking in the CDS- and interning tables. If an existing string does not exist, this array is converted to a new string object, which is then inserted into the interning table.
>
> This is less efficient than it has to be. As strings are likely to exist in the table(s), it would be beneficial to avoid the initial jchar array allocation. When inserting into the interning table, there is also a possibility to reuse the original string object, avoiding another allocation.
>
> This change makes it possible to search in the tables using the different string types, avoiding that initial allocation. This is done by wrapping the string and tagging it with a type, with helper functions directing to the correct hashing/lookup/equal functions. When inserting into the table, we can now reuse the original object or go directly from the input type to an object. To do this, functionality had to be added to hash utf8-strings and to compare oop-strings with utf8. These convert utf8 into unicode character by character and operates on those, thus avoiding needing extra allocations.
>
> Some quick rudimentary JMH benchmarks show a ~20% increase in throughput when interning the same string repeatedly, and a ~5% increase in throughput interning only unique strings. (Only tested on my local mac aarch debug build)
>
> 2 new tests have also been added. The first test tests that hash codes and string equality remain consistent when converting between different string types. The second test tests that string interning works as expected when equal strings are interned from different string types.
> Also tested and passes tiers 1-3.
Thank you for the early comments! All your points have been adressed
-------------
PR Comment: https://git.openjdk.org/jdk/pull/21325#issuecomment-2407463606
More information about the hotspot-dev
mailing list