Hi, 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 https://bugs.openjdk.org/browse/JDK-8371199. Please take a look and let me know what you think.
Cheers, Quan Anh On Sat, 8 Nov 2025 at 00:06, Quân Anh Mai <[email protected]> wrote: > Hi, > > 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! > > Regards, > Quan Anh > > > On Thu, 6 Nov 2025 at 20:02, Remi Forax <[email protected]> wrote: > >> Hello, >> as far as i remember, the problem is that you can resurrect a value, >> for example with a Long >> >> Thread1 >> a.x = new Long(12); >> a.x = null; >> IO.println(a.x); //12 >> >> Thread2 >> IO.println(a.x); // null >> a.x = new Long(77); // descheduled in between writing the maker and >> writing the long >> >> >> The thread1 can see the Long(12) to be resurrected, something that is not >> possible with references. >> >> regards, >> Rémi >> >> ------------------------------ >> >> *From: *"Quân Anh Mai" <[email protected]> >> *To: *"David Alayachew" <[email protected]> >> *Cc: *"valhalla-dev" <[email protected]> >> *Sent: *Thursday, November 6, 2025 3:52:41 AM >> *Subject: *Re: About flattening a nullable j.l.Long >> >> Ah yes, my bad, it is https://github.com/openjdk/valhalla/pull/1720 >> >> On Thu, 6 Nov 2025 at 07:26, David Alayachew <[email protected]> >> wrote: >> >>> Just a heads up, your [1] is a dead link. Can you try to put the url in >>> again? >>> >>> On Wed, Nov 5, 2025, 2:06 PM Quân Anh Mai <[email protected]> wrote: >>> >>>> Hi, >>>> 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? >>>> >>>> Thanks a lot, >>>> Quan Anh >>>> >>> >>
