Using descriptor than internal name hashes for CP ClassEntry

- liangchenblue at gmail.com
Thu Jan 4 05:19:17 UTC 2024


Unfortunately not yet, and I am busy recently so cannot provide one until
the weekends. I think this approach would work best for cases where we
generate completely new class files, such as j.l.invoke, Proxy, and
MethodHandleProxies. It probably won't make too much of a difference if we
don't pass ClassDesc in directly.

Also, the points you've mentioned before, that MethodType and Class should
have their dedicated, validated fast-paths for Descriptor conversion, would
probably have a similar boosts.
In Class::descriptorString(), there's an extra allocation of the internal
name from String::replace. We might have less allocation and better
performance if we can avoid that allocation by moving the replacement to be
done on the StringBuilder's array instead.

For your previous descriptor to internal name conversion, I think we might
add some fast-path conversions for frequently-occuring ClassDesc like
Object to directly return "java/lang/Object" than to compute substring, to
simulate the existing fast-paths in j.l.invoke generation.

However, all these are speculation; we need benchmark to show their
effectiveness in dedicated scenarios (in addition to the corpus
transformation, say addition of new CF elements, spinning new class files,
removing CF elements)

Chen Liang

On Wed, Jan 3, 2024 at 7:58 AM Adam Sotona <adam.sotona at oracle.com> wrote:

> Hi Chen,
>
> It looks promising, do you have some benchmark numbers?
>
>
>
> Thanks,
>
> Adam
>
>
>
> *From: *classfile-api-dev <classfile-api-dev-retn at openjdk.org> on behalf
> of liangchenblue at gmail.com <liangchenblue at gmail.com>
> *Date: *Sunday, 24 December 2023 at 17:11
> *To: *classfile-api-dev <classfile-api-dev at openjdk.org>
> *Subject: *Using descriptor than internal name hashes for CP ClassEntry
>
> Hi,
>
> Since we are using ClassDesc quite often to represent Class constants in
> Class-File API, yet it's costly to hash them (as they are internal names in
> CP but descriptors in ClassDesc), that Adam has created shortcuts to speed
> up fetching of Object CE from CD_Object, I have thought of a new tactic to
> hash ClassEntry by full descriptor than by internal name alone.
>
>
>
> I have made a prototype at
> https://github.com/liachmodded/jdk/commit/2932a560b0029352f1309883b3c5eecfb3d2c771
>
>
>
> The idea is that hashing CE as descriptors is easier than creating
> substrings for hashing; substring hashing is hard to compute, but appending
> and prepending and hash is much easier.
>
>
>
> Does this look like a good idea? I only included a test to confirm its
> correctness, but haven't got time to bench it against, say, the port of
> java.lang,invoke or ProxyGenerator.
>
>
>
> Chen
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/classfile-api-dev/attachments/20240103/1ddf8582/attachment-0001.htm>


More information about the classfile-api-dev mailing list