User model stacking: current status [Observer discussion]

João Mendonça jf.mend at gmail.com
Sun Jun 19 07:29:53 UTC 2022


Hi Tim,


Thank you very much for all your excellent explanations. The main take away
for me was:

It's gonna be next to impossible to guarantee that illigal zero-values are
kept hidden.

But, if I understood you correctly, for no-zero types, the compiler can
still enforce definite-assignment as it does for final-fields and locals,
if it determines, albeit in a limited way,  that the shared-mutable
(non-final field or array) is used before initialization. Did I get this
right?

So here is another, parhaps dumb, question: why is it so bad that sensless
zero-values may be leaked?
If the language cannot guarantee  that illegal zero-values won't be seen,
then Java users will need to keep one rule in mind when creating/reading a
value-class:

*No invariant can exclude the zero-value.*

For example: if the constructor of Rational throws on a zero denominator,
that is not an invariant. It's just a fail-fast that works for most
situations. This is certainly not ideal, but is it a big problem? Or is
there something else that I'm still missing?


Now, here's the main question:
Why can't shared-mutables be inlined by the runtime in an opaque/automatic
way? I.e. when encountering a shared-mutable, why can't the runtime decide
the encoding-mode based on something similar to this ternary expression:

var encodingMode =
        hasIdentity(varType) ? reference
    :   tooBig(varType.bitSize) ? reference
    :   atomicWrite(varType.bitSize) ? inline
    :   atomicClass(varType) ? reference
    :   inline;

With varType.bitSize depending on nullability I.e. a nullable Rational
would be less likely to be inlined than a non-nullable Rational!, simply
due to the extra bits required to also represent null. The predicates
tooBig and atomicWrite would depend on the hardware specs.

If this could be done, users would not have to know about ref-projections
or val-projections or about inlining or references. The only Valhalla
related concepts that would matter for users would be:

- object identity
- variable nullability
- object write atomicity


João
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.org/pipermail/valhalla-spec-observers/attachments/20220619/e87b0cbc/attachment.htm>


More information about the valhalla-spec-observers mailing list