<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=us-ascii">
<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:Aptos;
panose-1:2 11 0 4 2 2 2 2 2 4;}
/* Style Definitions */
p.MsoNormal, li.MsoNormal, div.MsoNormal
{margin:0in;
font-size:12.0pt;
font-family:"Aptos",sans-serif;
mso-ligatures:standardcontextual;}
a:link, span.MsoHyperlink
{mso-style-priority:99;
color:#467886;
text-decoration:underline;}
span.EmailStyle17
{mso-style-type:personal-compose;
font-family:"Aptos",sans-serif;
color:windowtext;}
.MsoChpDefault
{mso-style-type:export-only;}
@page WordSection1
{size:8.5in 11.0in;
margin:1.0in 1.0in 1.0in 1.0in;}
div.WordSection1
{page:WordSection1;}
--></style>
</head>
<body lang="EN-US" link="#467886" vlink="#96607D" style="word-wrap:break-word">
<div class="WordSection1">
<p class="MsoNormal"><span style="font-size:11.0pt">DEFAULT_PADDING_SIZE specifies the padding that should be put before a C++ field to avoid false sharing. For aarch64 it is currently set to the size of a cache line.[1] For aarch64 the size of a cache is
defined to be 64 bytes.[2]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">Similarly, ContendedPaddingWidth specifies the padding that should be put before a Java field to avoid false sharing. For all platforms that is set to 128 bytes, but it can be changed from the java command
line.[3]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">aarch64 has the same potential interaction with pre-fetchers as described for the x86.[4] That is, a pre-fetcher may fetch the _<i>next cache line</i>_ after a requested address. If that next cache line
contains the contended field, then the core that wants to atomically update the field needs to (re)negotiate for exclusive access to the cache line with the field. Padding a contended field into _<i>two</i>_ cache lines avoids this false sharing.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I would like to rationalize the padding for aarch64 C++ fields with the padding for Java fields. The change is easy: double the size of DEFAULT_PADDING_SIZE in globalDefinitions_aarch64.hpp. But I am curious
why the difference exists for aarch64 and not for x86, and if there implications that should be considered before submitting a pull request. Increasing the padding will make C++ data structures with padded fields take more space, possibly causing more page
faults, etc. But avoiding false sharing may improve the performance of C++ atomic operations, lowering latency in places where it might be important.<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">I have built jdk-25+14 with DEFAULT_PADDING_SIZE defined as 128, and things work.[5] I am unable to show significant performance changes. Can someone recommend tests where false sharing of C++ fields in
the JVM might a difference? Or can I submit a pull request just because it seems silly to have different padding for C++ fields and Java fields on aarch64?<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"> ... peter<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt"><o:p> </o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[1] <a href="https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp#L49">
https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp#L49</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[2] <a href="https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp#L46">
https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/aarch64/globalDefinitions_aarch64.hpp#L46</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[3] <a href="https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/globals.hpp#L813">
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/runtime/globals.hpp#L813</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[4] <a href="https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/globalDefinitions_x86.hpp#L46">
https://github.com/openjdk/jdk/blob/master/src/hotspot/cpu/x86/globalDefinitions_x86.hpp#L46</a><o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[5] I also tried various other sizes of DEFAULT_PADDING_SIZE. I can report that some uses of padded fields are prepared for DEFAULT_PADDING_SIZE to be 0, but some uses result in compilation errors because
they do not use the lovely templates that protect against 0-length C++ arrays.[6]<o:p></o:p></span></p>
<p class="MsoNormal"><span style="font-size:11.0pt">[6] <a href="https://github.com/openjdk/jdk/blob/master/src/hotspot/share/memory/padded.hpp#L67">
https://github.com/openjdk/jdk/blob/master/src/hotspot/share/memory/padded.hpp#L67</a><o:p></o:p></span></p>
</div>
</body>
</html>