Replace the primitive class with a more general null safety?

Remi Forax forax at univ-mlv.fr
Sat Dec 3 08:19:33 UTC 2022


> From: "Glavo" <zjx001202 at gmail.com>
> To: "valhalla-dev" <valhalla-dev at openjdk.java.net>
> Sent: Monday, November 28, 2022 11:10:18 AM
> Subject: Replace the primitive class with a more general null safety?

> After I read the JEP and related documents of Project Valhalla, I doubted the
> necessity of the existence of primitive classes.

> It is impossible to migrate from identity class to primitive class, which will
> break binary compatibility.
> This is a big obstacle for third-party libraries to support Valhalla.

[...] 

yes, it's something we are working on. 
Obviously, it will never be fully backward compatible because the default value of a value class and a primitive class are different (null and zeroes respectively). 

> At the same time, in order to support non null types, the universal generics
> draft also greatly undermines compatibility.

?? 

> Although the value class is more compatible, it may not be inlined when it is a
> field or array member.
> Therefore, sometimes value objects are repeatedly boxed, which may have worse
> performance than non value classes.

The VM goes into great length to avoid that, by re-using the box. 
If the box escapes the inlining horizon, yes, you will see the allocation, but it's the same issue with a lot of the other optimizations today, outside of the inline horizon the JIT is almost blind. 

> Providing both value class and primitive class may also make it more difficult
> for users to choose.

Yes, we tried really hard, for several years in fact, to have only one kind of value classes. 
But the physics of those two is different enough that trying to unify them or disguise one as the other is a worst than exposing that choice to the user. 

> I don't like the current draft very much. In particular, I am very dissatisfied
> with the huge cost of providing null safety only for primitive types.

Java null safety is a separate discussion ... 

[...] 

> If we do, we no longer need the primitive class. It is enough to mark the value
> class as non null.
> The problem that prevents us from migrating to the primitive class no longer
> exists, because we don't need the primitive class and Q type anymore.

I think you are mixing the syntax and the semantics here. 

The is an early access build that you can test, so you will get a better idea of how things work 
[ https://jdk.java.net/valhalla/ | https://jdk.java.net/valhalla/ ] 

By default, you only have value class [1] and if you want primitive class [2] you have to enable it at compile time and runtime. 

We know that primitive classes as describe in the JEP [2], do not fully integrate with the rest of the ecosystem that's a work in progress. 

regards, 
Rémi 

[1] [ https://openjdk.org/jeps/8277163 | https://openjdk.org/jeps/8277163 ] 
[2] [ https://openjdk.org/jeps/401 | https://openjdk.org/jeps/401 ] 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-dev/attachments/20221203/b013b75c/attachment.htm>


More information about the valhalla-dev mailing list