Earlier quoted context omitted.
The heap is an implementation detail. With escape analysis, the compiler can allocate the data on the heap, stack, or even stick it in registers. https://www.beyondjava.net/escape-analysis-java https://shipilev.net/jvm/anatomy-quarks/18-scalar-replacemen... https://www.javaadvent.com/2020/12/seeing-escape-analysis-wo...
Can you have an array of 1 million structs, not pointers to structs?
Java's records, Lombok's data, and Kotlin's data classes
51–60 of 294 posts
Re: Java's records, Lombok's data, and Kotlin's data classes
#52Earlier quoted context omitted.
Well it means that the second you need a setter you can't use records so all the boilerplate remains.
You are supposed to create a new copy with some of the fields changed. Just like you do it with the java.time.* classes and others.
Well, they have to obey Wirth's law, I guess.
Re: Java's records, Lombok's data, and Kotlin's data classes
#53Earlier quoted context omitted.
You are supposed to create a new copy with some of the fields changed. Just like you do it with the java.time.* classes and others.
Instead of changing few bytes, now I have to copy hundreds of bytes around and add more stuff for GC to collect. Well, they have to obey Wirth's law, I guess.
Re: Java's records, Lombok's data, and Kotlin's data classes
#54Earlier quoted context omitted.
You are supposed to create a new copy with some of the fields changed. Just like you do it with the java.time.* classes and others.
Instead of changing few bytes, now I have to copy hundreds of bytes around and add more stuff for GC to collect. Well, they have to obey Wirth's law, I guess.
Re: Java's records, Lombok's data, and Kotlin's data classes
#55Trying to read in Safari iOS but most of the article text seems to be missing.
Re: Java's records, Lombok's data, and Kotlin's data classes
#56Using Dark Reader extension for Chrome, all of the sample code text goes to the same color as the background so I thought I was scrolling over huge chunks of blank space.
Blanks out the content again. Seems rather odd behaviour to me so definitely interested if anyone figures it out, even if this is kind of derailing the discussion.
Re: Java's records, Lombok's data, and Kotlin's data classes
#57Earlier quoted context omitted.
The first question is "through static analysis, can you guarantee that the structs do not leave the scope?" The second question to look at is "which JVM are you using?" Different JVMs may implement this differently. This isn't something that one can say about Java . It is something that one might be able to say about HotSpot, Zulu, or GraalVM.
You’re technically correct that this stuff is all possible in principle, but the answer in practice right now is “no”.
> Something that Graal can do that C2 cannot, and a key advantage of GraalVM, is partial escape analysis. Instead of determining a binary value of whether an object escapes the compilation unit or not, this can determine on which branches an object escapes it, and move allocation of the object to only those branches where it escapes.
And from https://docs.oracle.com/en/java/javase/11/vm/java-hotspot-vi...
> The Java HotSpot Server Compiler implements the flow-insensitive escape analysis algorithm described in:
> ...
> After escape analysis, the server compiler eliminates the scalar replaceable object allocations and the associated locks from generated code. The server compiler also eliminates locks for objects that do not globally escape. It does not replace a heap allocation with a stack allocation for objects that do not globally escape.
----
So, some JVMs implement, others only do a limited subset of the optimizations available with escape analysis.
I would not say that the answer of "is it used in practice" is "no."
Re: Java's records, Lombok's data, and Kotlin's data classes
#58Scala's case classes are missing in the comparison (only mentioned briefly at the very end). They offer everything that records do and more. Good to see that Java finally catches up a bit.
Scala is usually omitted for one reason or another when Kotlin is compared against Java as a better alternative, which is a shame.
Re: Java's records, Lombok's data, and Kotlin's data classes
#59Earlier quoted context omitted.
You are supposed to create a new copy with some of the fields changed. Just like you do it with the java.time.* classes and others.
Instead of changing few bytes, now I have to copy hundreds of bytes around and add more stuff for GC to collect. Well, they have to obey Wirth's law, I guess.
Re: Java's records, Lombok's data, and Kotlin's data classes
#60They are still classes, still live on the heap and still need to be garbage collected. Compare with value types that live on the stack in other languages such as Swift, Go and Julia.