<html xmlns:o="urn:schemas-microsoft-com:office:office" xmlns:w="urn:schemas-microsoft-com:office:word" xmlns:m="http://schemas.microsoft.com/office/2004/12/omml" xmlns="http://www.w3.org/TR/REC-html40">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
<meta name="Generator" content="Microsoft Word 15 (filtered medium)">
<style><!--
/* Font Definitions */
@font-face
{font-family:"Cambria Math";
panose-1:2 4 5 3 5 4 6 3 2 4;}
@font-face
{font-family:Calibri;
panose-1:2 15 5 2 2 2 4 3 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0cm;
font-size:10.0pt;
font-family:"Calibri",sans-serif;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:blue;
text-decoration:underline;}
span.EmailStyle19
{mso-style-type:personal-reply;
font-family:"Calibri",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;
font-size:10.0pt;
mso-ligatures:none;}
@page WordSection1
{size:612.0pt 792.0pt;
margin:72.0pt 72.0pt 72.0pt 72.0pt;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="en-CZ" link="blue" vlink="purple" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt;mso-fareast-language:EN-US"><o:p> </o:p></span></p>
<div style="border:none;border-top:solid #B5C4DF 1.0pt;padding:3.0pt 0cm 0cm 0cm">
<p class="MsoNormal" style="margin-bottom:12.0pt"><b><span style="font-size:12.0pt;color:black">From:
</span></b><span style="font-size:12.0pt;color:black">core-libs-dev <core-libs-dev-retn@openjdk.org> on behalf of Brian Goetz <briangoetz@openjdk.org><br>
<br>
</span><span style="font-size:11.0pt"><o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt">Most entities in the system are immutable and therefore freely sharable
<br>
without additional coordination. Some have lazily-inflated single-field <br>
caches that conform to the "benign race" (there is only one possible <br>
non-default value) criteria.<br>
<br>
The main hole is the CHA resolution cache. There are two ways to <br>
address this: protect the cache, or don't share the context.<br>
<br>
Unfortunately now that ClassModel refers back to the context, there's a <br>
risk of unexpected context sharing. Here are a few options:<br>
<br>
- Make the CHA cache thread-safe using, say, CHM;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">This is current solution for the default system CH cache. We may also remove ClassHierarchyResolver::cached() method to force user think about it and always call ClassHierarchyResolver::cached(Supplier<Map<ClassDesc,
ClassHierarchyInfo>> cacheFactory) for all non-default cases.<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">Or we may also use a bit less strict custom semi-synchronization (just enough to be thread safe) instead of fully-synchronized CHM::computeIfAbsent, for example CHM:get
… <compute if absent without lock> ... CHM::put. <o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt"><br>
- Make the CHA cache unshared, by using a ThreadLocal (this brings the <br>
context back to being immutable)<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">This is interesting option for small number of threads, however it makes big footprint for heavy-parallel systems.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt"><br>
- Detect when implicit use of a context happens on a thread other than <br>
the creating thread (currently the only vector for this is <br>
Classfile::transform), and inflate a new context with empty cache in <br>
that case;<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">This would degrade the caching completely by triggering a new context for each transformed method in case there are two threads working synchronously.
<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt"><br>
- Always create a fresh context with an empty cache in <br>
Classfile::transform<o:p></o:p></span></p>
<p class="MsoNormal" style="margin-bottom:12.0pt"><span lang="EN-US" style="font-size:11.0pt">This would destroy the caching. Such cache would work only in scope of one method.<o:p></o:p></span></p>
<p class="MsoNormal" style="mso-margin-top-alt:0cm;margin-right:0cm;margin-bottom:12.0pt;margin-left:36.0pt">
<span style="font-size:11.0pt"><br>
<br>
<br>
<br>
<br>
<br>
On 6/8/2023 9:24 AM, Adam Sotona wrote:<br>
><br>
> Unfortunately thread-unsafe context makes sharing of it in tests <br>
> executed in parallel a nightmare.<br>
> I can fix our Corpus tests and hope the race condition won't raise <br>
> also somewhere else later.<br>
> However how to explain this limitation to users?<br>
><br>
> I suggest to make it always thread-safe (as the context is primary <br>
> expected to be shared in multi-threaded environment) and users may <br>
> make it faster in specific cases by providing non-synchronized map.<br>
><br>
> —<br>
> Reply to this email directly, view it on GitHub <br>
> <<a href="https://github.com/openjdk/jdk/pull/14180#issuecomment-1582576426">https://github.com/openjdk/jdk/pull/14180#issuecomment-1582576426</a>>,
<br>
> or unsubscribe <br>
> <<a href="https://github.com/notifications/unsubscribe-auth/AABJ4RHSMWR5Q3ANYK3RPSLXKHG7RANCNFSM6AAAAAAYQLACYQ">https://github.com/notifications/unsubscribe-auth/AABJ4RHSMWR5Q3ANYK3RPSLXKHG7RANCNFSM6AAAAAAYQLACYQ</a>>.<br>
> You are receiving this because you commented.Message ID: <br>
> ***@***.***><br>
><br>
<br>
-------------<br>
<br>
PR Comment: <a href="https://git.openjdk.org/jdk/pull/14180#issuecomment-1582643016">
https://git.openjdk.org/jdk/pull/14180#issuecomment-1582643016</a><o:p></o:p></span></p>
</div>
</div>
</body>
</html>