On Thu, 8 Jun 2023 13:37:33 GMT, Adam Sotona <asot...@openjdk.org> wrote:

>> Classfile context object and multi-state options have been discussed at 
>> https://mail.openjdk.org/pipermail/classfile-api-dev/2023-May/000321.html
>> This patch implements the proposed changes in Classfile API and fixes all 
>> affected code across JDK sources and tests.
>> 
>> Please review.
>> 
>> Thanks,
>> Adam
>
> Adam Sotona has updated the pull request incrementally with one additional 
> commit since the last revision:
> 
>   Revert "ClassHierarchyResolver::ofSystem is now thread-unsafe"
>   
>   This reverts commit f3099cd5b252924392995bf65edc710c27822d2b.

Most entities in the system are immutable and therefore freely sharable 
without additional coordination.  Some have lazily-inflated single-field 
caches that conform to the "benign race" (there is only one possible 
non-default value) criteria.

The main hole is the CHA resolution cache.  There are two ways to 
address this: protect the cache, or don't share the context.

Unfortunately now that ClassModel refers back to the context, there's a 
risk of unexpected context sharing.  Here are a few options:

  - Make the CHA cache thread-safe using, say, CHM;
  - Make the CHA cache unshared, by using a ThreadLocal (this brings the 
context back to being immutable)
  - Detect when implicit use of a context happens on a thread other than 
the creating thread (currently the only vector for this is 
Classfile::transform), and inflate a new context with empty cache in 
that case;
  - Always create a fresh context with an empty cache in 
Classfile::transform





On 6/8/2023 9:24 AM, Adam Sotona wrote:
>
> Unfortunately thread-unsafe context makes sharing of it in tests 
> executed in parallel a nightmare.
> I can fix our Corpus tests and hope the race condition won't raise 
> also somewhere else later.
> However how to explain this limitation to users?
>
> I suggest to make it always thread-safe (as the context is primary 
> expected to be shared in multi-threaded environment) and users may 
> make it faster in specific cases by providing non-synchronized map.
>
> —
> Reply to this email directly, view it on GitHub 
> <https://github.com/openjdk/jdk/pull/14180#issuecomment-1582576426>, 
> or unsubscribe 
> <https://github.com/notifications/unsubscribe-auth/AABJ4RHSMWR5Q3ANYK3RPSLXKHG7RANCNFSM6AAAAAAYQLACYQ>.
> You are receiving this because you commented.Message ID: 
> ***@***.***>
>

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

PR Comment: https://git.openjdk.org/jdk/pull/14180#issuecomment-1582643016

Reply via email to