<div dir="ltr"><div>Hi,</div><div><br></div>I have been agonizing over this issue for the past few days. In the end, I may have come up with a way to make flattening work. In exchange, we need to lock the field so the stores are serialized. My aim is that the loads keep being lock-free, and for the stores, the supposedly common case of storing a non-null into a non-null does not require locking. At the moment, I am starting to implement a prototype and doing some benchmarking to see if locking would be prohibitively expensive. My proposal and reasoning can be found in the description of the JBS issue <a href="https://bugs.openjdk.org/browse/JDK-8371199">https://bugs.openjdk.org/browse/JDK-8371199</a>. Please take a look and let me know what you think.<div><br></div><div>Cheers,</div><div>Quan Anh</div></div><br><div class="gmail_quote gmail_quote_container"><div dir="ltr" class="gmail_attr">On Sat, 8 Nov 2025 at 00:06, Quân Anh Mai <<a href="mailto:anhmdq@gmail.com">anhmdq@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div dir="auto">Hi,</div><div dir="auto"><br></div><div dir="auto">Thanks a lot for your answer. After thinking about it for a while, I think it is true that this approach will not work. While it is true that a field load must act as if it observes 1 of the concurrent stores, I forgot to take into consideration the possibility that such store may be rendered invalid due to a store of null happens after it. It seems that for atomicity to hold, the store must be atomic, and there is no way around that. How unfortunate!<br></div><div dir="auto"><br></div><div>Regards,</div><div>Quan Anh</div><div><br></div></div><div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Thu, 6 Nov 2025 at 20:02, Remi Forax <<a href="mailto:forax@univ-mlv.fr" target="_blank">forax@univ-mlv.fr</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex"><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div style="font-family:arial,helvetica,sans-serif">Hello,</div><div style="font-family:arial,helvetica,sans-serif">as far as i remember, the problem is that you can resurrect a value,</div><div style="font-family:arial,helvetica,sans-serif">for example with a Long</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Thread1</div><div style="font-family:arial,helvetica,sans-serif"> a.x = new Long(12);</div><div style="font-family:arial,helvetica,sans-serif"> a.x = null;</div><div style="font-family:arial,helvetica,sans-serif"> IO.println(a.x); //12</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">Thread2</div><div style="font-family:arial,helvetica,sans-serif"> IO.println(a.x); // null</div><div style="font-family:arial,helvetica,sans-serif"> a.x = new Long(77); // descheduled in between writing the maker and writing the long</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">The thread1 can see the Long(12) to be resurrected, something that is not possible with references.</div><div style="font-family:arial,helvetica,sans-serif"><br></div><div style="font-family:arial,helvetica,sans-serif">regards,</div><div style="font-family:arial,helvetica,sans-serif">Rémi</div><div style="font-family:arial,helvetica,sans-serif"><br></div><hr id="m_-4776246547737592423m_7197131063560643665m_-8802309212657566255m_-296030883158804807zwchr" style="font-family:arial,helvetica,sans-serif"></div></div><div><div style="font-family:arial,helvetica,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div style="font-family:arial,helvetica,sans-serif"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;color:rgb(0,0,0)"><b style="font-family:Helvetica,Arial,sans-serif">From: </b>"Quân Anh Mai" <<a href="mailto:anhmdq@gmail.com" style="font-family:Helvetica,Arial,sans-serif" target="_blank">anhmdq@gmail.com</a>><br><b style="font-family:Helvetica,Arial,sans-serif">To: </b>"David Alayachew" <<a href="mailto:davidalayachew@gmail.com" style="font-family:Helvetica,Arial,sans-serif" target="_blank">davidalayachew@gmail.com</a>><br><b style="font-family:Helvetica,Arial,sans-serif">Cc: </b>"valhalla-dev" <<a href="mailto:valhalla-dev@openjdk.org" style="font-family:Helvetica,Arial,sans-serif" target="_blank">valhalla-dev@openjdk.org</a>><br><b style="font-family:Helvetica,Arial,sans-serif">Sent: </b>Thursday, November 6, 2025 3:52:41 AM<br><b style="font-family:Helvetica,Arial,sans-serif">Subject: </b>Re: About flattening a nullable j.l.Long<br></blockquote></div><div style="font-family:arial,helvetica,sans-serif"><blockquote style="border-left:2px solid rgb(16,16,255);margin-left:5px;padding-left:5px;font-weight:normal;font-style:normal;text-decoration:none;font-family:Helvetica,Arial,sans-serif;font-size:12pt;color:rgb(0,0,0)"><div dir="ltr" style="font-family:Helvetica,Arial,sans-serif">Ah yes, my bad, it is <a href="https://github.com/openjdk/valhalla/pull/1720" style="font-family:Helvetica,Arial,sans-serif" target="_blank">https://github.com/openjdk/valhalla/pull/1720</a><br></div><br><div class="gmail_quote" style="font-family:Helvetica,Arial,sans-serif"><div dir="ltr" class="gmail_attr" style="font-family:Helvetica,Arial,sans-serif">On Thu, 6 Nov 2025 at 07:26, David Alayachew <<a href="mailto:davidalayachew@gmail.com" style="font-family:Helvetica,Arial,sans-serif" target="_blank">davidalayachew@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;font-family:Helvetica,Arial,sans-serif"><div dir="auto" style="font-family:Helvetica,Arial,sans-serif">Just a heads up, your [1] is a dead link. Can you try to put the url in again?</div><br><div class="gmail_quote" style="font-family:Helvetica,Arial,sans-serif"><div dir="ltr" class="gmail_attr" style="font-family:Helvetica,Arial,sans-serif">On Wed, Nov 5, 2025, 2:06 PM Quân Anh Mai <<a href="mailto:anhmdq@gmail.com" style="font-family:Helvetica,Arial,sans-serif" target="_blank">anhmdq@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex;font-family:Helvetica,Arial,sans-serif"><div dir="ltr" style="font-family:Helvetica,Arial,sans-serif">Hi,<br><div style="font-family:Helvetica,Arial,sans-serif">Currently, I'm having a PR that allows flattening of a nullable value class with a 64-bit payload [1]. Dan Smith told me that some ideas along these lines were discussed a few years ago, and the consensus was that it was a dead end. May I ask what the concerns were, and whether they are still relevant now?</div><br><div style="font-family:Helvetica,Arial,sans-serif">Thanks a lot,</div><div style="font-family:Helvetica,Arial,sans-serif">Quan Anh</div></div>
</blockquote></div>
</blockquote></div><br></blockquote></div></div></div></blockquote></div></div>
</blockquote></div>