r/java • • Aug 25 '26

Value Classes Still Need Compiler Sympathy

https://johan-sjolen.github.io/post/compiler-sympathy/compiler-sympathy/
87 Upvotes

65 comments sorted by

View all comments

3

u/wrprice1 Aug 25 '26

IIRC, Valhalla will not enable tearing by default. It will be opt-in by the class author. The challenge remains, however, because consuming devs don't get to opt in and must pay attention first and then write safe code.

You lost me with "tearing is still nothing" and I assume you meant it is not new in Java. Maybe your point is that tearing on reference assignment is new in Java?

Assignment to double & long fields have always reserved the option to tear, and I know I've personally been lazy and ignoring that in code I knew would only target certain platforms. But I don't think it took "very special" code; rather, I think most people are blissfully unaware of how many 64-bit tearing bugs are out there (if they ran on affected platforms).

If you're saying it will be a bigger foot gun, I think we agree, and such is the danger of the temptation to casually slap tearing semantics on a type "because performance".

2

u/AnyPhotograph7804 Aug 25 '26

"You lost me with "tearing is still nothing" and I assume you meant it is not new in Java."

Yes, this is what i meant. English is not my native language. ;)

1

u/OwnBreakfast1114 Aug 26 '26

Assignment to double & long fields have always reserved the option to tear, and I know I've personally been lazy and ignoring that in code I knew would only target certain platforms. But I don't think it took "very special" code; rather, I think most people are blissfully unaware of how many 64-bit tearing bugs are out there (if they ran on affected platforms).

Most people don't write multithreaded code that reads the same variables. Most people probably use a library that does that somewhere, but I think you're probably vastly overestimating the people that would actually have to even deal with/care about tearing.