3 ms·
Java doesn't have it yet, but they are making progress, https://jdk.java.net/valhalla/ https://jdk.java.net/valhalla/ Yes, it was a bummer that Java didn't ta
by pjmlp 2y ago
Java doesn't have it yet, but they are making progress,
https://jdk.java.net/valhalla/ https://jdk.java.net/valhalla/
Yes, it was a bummer that Java didn't take up on the ideas of Cedar, Oberon linage, Modula-3, Eiffel,... even though some are quoted as its influences.
Still I am confident that it might be getting value types, before C++ reflection, networking, senders/receivers, or safety gets sorted out. Or even that we can finally write portable C++ code using C++20 modules.
- pizlonator 2y agoThat is really cool! It’s a dang hard feature to retrofit into the way the JVM works. I wish those folks the best of luck.
- pjmlp 2y agoYes, that is the biggest engineering effort of the whole thing, how to add the value types concept into the JVM, without breaking the ecosystem. JARs and modules that work on the JVM before value types introduction should keep running, and how can new code interoperate with such jars.
- dzaima 2y agoUnfortunately, it doesn't look like there's much of a guarantee that value objects wouldn't result in heap allocations. https://openjdk.org/jeps/401 https://openjdk.org/jeps/401 even contains: > So while many small value classes can be flattened, classes that declare, say, 2 int fields or a double field, might have to be encoded as ordinary heap objects. There's a further comment about potential of opting out of atomicity guarantees to not have that problem, but then there are more problems - looks like pre-JIT would still allocate, and who knows how consistent would JIT be about scalarization. IIRC there was also some mention somewhere about just forcing large enough value objects to always be heap allocations.
- elygre 2y agoThat’s some very selective quoting there. Let’s do the full thing: > Heap flattening must maintain the integrity of objects. For example, the flattened data must be small enough to read and write atomically, or else it may become corrupted. On common platforms, "small enough" may mean as few as 64 bits, including the null flag. So while many small value classes can be flattened, classes that declare, say, 2 int fields or a double field, might have to be encoded as ordinary heap objects. And maybe the end of the next paragraph is even more relevant: > In the future, 128-bit flattened encodings should be possible on platforms that support atomic reads and writes of that size. And the Null-Restricted Value Types JEP will enable heap flattening for even larger value classes in use cases that are willing to opt out of atomicity guarantees.
- pizlonator 2y agoIf value types still require allocation for stuff larger than 128 bits then that really sucks! That’s not how value types usually work.
- bremac 2y agoValue types still require allocation for types larger than 128 bits if the value is either nullable or atomic — that seems like a reasonable trade-off to me.
- pizlonator 2y agoOh! Reasonable trade-off indeed. Thank you for clarifying.
- dzaima 2y agoYeah, had edited my comment to expand a bit on that. Nevertheless, this is just one place where allocation of value objects may appear; and it looks like eliding allocations is still generally in the "optimization" category, rather than "guarantee".
- deleted 2y ago[deleted]
- astrange 2y agoWhen are they going to finish making progress? I've been hearing about this for years now and it doesn't seem to have happened. Which means Java continues with just about the worst design for memory efficiency you could have.
- pjmlp 2y agoWhen they are sure the design is sound enough not to do a Python 2/Python 3. If it was easy it would be done by now. There are plenty of long time efforts on other language ecosystem that have also taken decades and still not fully done, e.g. C++ modules, contracts, reflection,... If you really need value type like objects today, it is possible in Panama, even without language syntax for them.
- saagarjha 2y agoDon't worry, Python is always there to do a worse job.