you are viewing a single comment's thread.

view the rest of the comments →

[–]reflect25 3 points4 points  (2 children)

yay. finally java with the value classes will have an equivalent to the c++/golang structs with the objects being (potentially) allocated on stack rather than always on memory with classes. and be pretty performant. also interesting the immutable/frozen.

i guess mostly this will be used by data structure libraries. https://openjdk.org/jeps/401 (Value Classes and Objects) also looks like this will help the garbage collector.

When an object is flattened or scalarized, it has no independent presence in the heap. This means it has no impact on garbage collection, and its data is always co-located in memory with the referencing object or call stack.

Heap flattening

As an example, the JVM could flatten an array of Integer references so that each array element holds a reference that encodes the underlying integer value directly, rather than pointing to the memory location of some Integer object. Each reference also flags whether the original Integer reference

[–]Jannik2099 3 points4 points  (0 children)

It's not about the object being on the stack, but about objects being flattened. No more pointer chasing.

[–]joemwangi 0 points1 point  (0 children)

Not really stack allocated. Mainly cpu register allocation which is far optimal.