Access to flat fields through VarHandles is performed with the code generated in VarHandleValues.java. In this generated code, there's a pattern of testing the value returned by Unsafe.getValue() against null to substitute null with the all-zero default value.
Exemple:
@ForceInline
static Object get(VarHandle ob) {
FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
Object value = UNSAFE.getValue(handle.base,
handle.fieldOffset, handle.fieldType);
if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
return ValueClass.zeroInstance(handle.fieldType);
}
return value;
}
~~While this is a required practice when accessing reference fields (which include non-flat value fields), this check is useless for flat value fields. Unsafe.getValue() will never return null for a null-free flat field.~~
Note: Now with verifier-enforced null restriction, this check is useless for any read access.
Exemple:
@ForceInline
static Object get(VarHandle ob) {
FieldStaticReadOnly handle = (FieldStaticReadOnly) ob.target();
Object value = UNSAFE.getValue(handle.base,
handle.fieldOffset, handle.fieldType);
if (value == null && handle.checkedFieldType instanceof NullRestrictedCheckedType) {
return ValueClass.zeroInstance(handle.fieldType);
}
return value;
}
~~While this is a required practice when accessing reference fields (which include non-flat value fields), this check is useless for flat value fields. Unsafe.getValue() will never return null for a null-free flat field.~~
Note: Now with verifier-enforced null restriction, this check is useless for any read access.
- causes
-
JDK-8350961 [lworld] Some VarHandles tests fail when field flattening is not applied
-
- Resolved
-
- links to
-
Commit(lworld) openjdk/valhalla/ab4ae37b
-
Review(lworld) openjdk/valhalla/1340