News for hackers. Stuff that matters.
Re:Advancing Memory Safety by o11c on Tuesday October 15, 2024 @04:10PM (#41852602)
For reference:

* JIT was added in Java 1.1 for Windows, and 1.2 for everyone else. But in the early days it sucked.

* Generics, autoboxing, and enums were added in Java [1.]5 (2004). Prior to that, APIs had to use `Object` everywhere, explicitly wrap primitives when needed, and use plain ints for constants.

* It's $CURRENTYEAR and Java still doesn't support structs, and it's not clear they actually understand the problem (since e.g. they force everything to be `final`).

Re:Advancing Memory Safety by cogman10 on Tuesday October 15, 2024 @04:29PM (#41852772)
> It's $CURRENTYEAR and Java still doesn't support structs, and it's not clear they actually understand the problem (since e.g. they force everything to be `final`)

I think they do. The problem they are solving is removing indirection and flattening the memory representation of data. Making all the fields final opens up the JVM to some really neat optimizations you can't get with mutable fields.

By the time you get something with enough fields in it that the immutability limitation becomes problematic, you likely would benefit from just having a regular class. Structs won't always be strictly faster than regular classes.

Re:Advancing Memory Safety by fiedzia on Tuesday October 15, 2024 @04:47PM (#41852937)
>It's $CURRENTYEAR and Java still doesn't support structs

they call it records, added recently. Depending on where you work, you may see them in a decade

Re:Advancing Memory Safety by cogman10 on Tuesday October 15, 2024 @05:02PM (#41853084)
records aren't the structs OP is referring to. Instead, they are thinking of value classes. (at least, that's effectively what a struct means in C#).

You will see `value record Point(int x, int y)` which is different from `record Point(int x, int y)`. The key difference being that `record Point` will create a reference to the x/y data with identity whereas `value record Point` will instead represent that data inline without a reference.

I suspect that `value record` will be the way pretty much everyone starts using `record` as there's basically no reason not to.

Re:Advancing Memory Safety by pjmlp on Wednesday October 16, 2024 @02:53AM (#41856287)
Java doesn't want to do a Python 2, a JAR compiled in 2000 has to still work in a Valhala enabled runtime, assuming it didn't use any of the now deprecated APIs.

You can play with early releases, https://jdk.java.net/valhalla/