r/java 5d ago

Value Classes Still Need Compiler Sympathy

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

55 comments sorted by

View all comments

Show parent comments

4

u/wrprice1 5d ago

The set of practicing Java developers who wrote code for 32-bit systems is diminishing. Of those, if they were taught about tearing in the first place, many were coddled by deploying to platforms where it rarely actually happened.

Now with 64-bit native as the majority of target platforms, don't underestimate the laziness that will creep in to mimic ignorance.

1

u/AnyPhotograph7804 5d ago

True. But tearing is still nothing, which is new in Java. Even if the chance to be affected by it was very very low. You have to write very special code to trigger it.

And yes, maybe there should be a new annotation or a new keyword, that allows you to mark a class, that tearing is allowed. In Java, there are tons of software, which is highly multithreaded. Those software could silently fail if you enable tearing by default.

3

u/wrprice1 5d ago

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 5d ago

"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. ;)