r/java • • Aug 25 '26

Value Classes Still Need Compiler Sympathy

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

65 comments sorted by

View all comments

Show parent comment

4

u/wrprice1 Aug 25 '26

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.

3

u/umlcat Aug 25 '26

We are lucky. Gosling originally wanted the JVM to run on 16 bit systems, when we already had 32 cpu in offices !!!

3

u/AnyPhotograph7804 Aug 25 '26

I still want a JVM for my Amiga 500!

2

u/umlcat Aug 26 '26

Commodore Amiga. I learned programming in a C64.

There's a few companies that have some 16 bits pcs around or programs running on a 64 bits PC with a 16 bits emulator.

It would be interesting to see a Java ecosystem running in those 16 bits machines too ...

2

u/vytah Aug 28 '26

https://github.com/kaffe/kaffe Not legally a JVM, but who cares.

Of you might want to recompile Java bytecode into native m68k code: https://www.mikekohn.net/micro/amiga_java.php

2

u/pron98 Aug 25 '26

Note that tearing can only impact how a data race manifests. If you have a data race, the bug may present itself in one way if there's no tearing and in another if there is. But if there is no bug, the possibility of tearing won't change anything. A program that is buggy without tearing will remain buggy with it (albeit with a different manifestation), and a program that isn't buggy without tearing will not be buggy with it.

1

u/AnyPhotograph7804 Aug 25 '26

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 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.