[lworld] RFR: 8320437: [lworld] Adding internal null-restricted storage API points [v3]

Frederic Parain fparain at openjdk.org
Mon Nov 27 19:27:36 UTC 2023


On Fri, 24 Nov 2023 09:32:28 GMT, Tobias Hartmann <thartmann at openjdk.org> wrote:

> This test (classes are equivalent to other test) fails only with `-XX:InlineFieldMaxFlatSize=0` but passes with default values:
> 
> ```
> Exception in thread "main" java.lang.RuntimeException: Failed
> 	at Test.main(Test.java:23)
> ```
> 
> ```
>     public static void main(String[] args) {
>         if (new EmptyContainer() != EmptyContainer.default) {
>             throw new RuntimeException("Failed");
>         }
>     }
> ```
> 
> I assume that's because it uses `.default` which will go away?

`.default` will eventually be removed, so its implementation (`aconst_init`) hasn't been changed, even if trying to use the default value on a class without `@ImplicitlyConstructible` is wrong.
But here the problem is different. The newly created EmptyContainer has been created by a constructor which explicitly initialized the empty field with a reference to an instance of MyEmptyValue. The EmptyContainer.default value is the default value created by the VM, and the VM is lazy on null-free non-flat fields. The whole default value is initialized will zeroes, which is equivalent to initializing non-flat fields with a null reference, but on read, the VM substitute this null reference with the default value of the field's type. The Java code used for the substitutability test, called from `if_acmpeq` when two values of the same type are compared, is aware of the VM lazy initialization of null-free non-flat fields and usually recognizes this situation and perform the same substitution. The problem here is that the substitutability code doesn't recognize the field as a non-free non-flat field, because it isn't aware that the `@NullRestricited` annotation has the same effect as a 
 Q-descriptor in the field signature. So, the substitutability code performs a simple comparison between the reference from the initialized field and the null reference of the default value, finds them different and returns a value indicating that the two arguments are different.

-------------

PR Comment: https://git.openjdk.org/valhalla/pull/947#issuecomment-1828471889



More information about the valhalla-dev mailing list