[lworld] RFR: 8294312: [lworld] Add java.util.Objects.isIdentityObject
Roger Riggs
rriggs at openjdk.org
Thu Sep 29 17:36:28 UTC 2022
On Thu, 29 Sep 2022 17:11:20 GMT, Mandy Chung <mchung at openjdk.org> wrote:
>> Add `java.util.Objects.isIdentityObject(obj)` and update tests.
>>
>> Correct j.l.Class.isIdentity() and .isValue() to correctly identify all arrays as identity objects.
>> (The modifiers for array classes do have not reliable ACC_IDENTITY or ACC_VALUE bits).
>>
>> Updated ValhallaFeaturesTest to use junit.
>
> src/java.base/share/classes/java/lang/Class.java line 645:
>
>> 643: */
>> 644: public boolean isIdentity() {
>> 645: return isArray() || (this.getModifiers() & Modifier.IDENTITY) != 0;
>
> I think Class::getModifiers for an array class should have `IDENTITY` flag set. I think it's a bug in the VM that does not set `IDENTITY`.
>
>
> jint ObjArrayKlass::compute_modifier_flags() const {
> // The modifier for an objectArray is the same as its element
> if (element_klass() == NULL) {
> assert(Universe::is_bootstrapping(), "partial objArray only at startup");
> return JVM_ACC_ABSTRACT | JVM_ACC_FINAL | JVM_ACC_PUBLIC;
> }
> // Return the flags of the bottom element type.
> jint element_flags = bottom_klass()->compute_modifier_flags();
>
> return (element_flags & (JVM_ACC_PUBLIC | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED))
> | (JVM_ACC_ABSTRACT | JVM_ACC_FINAL);
> }
The spec of Class.getModifiers() is explicit for arrays that only a few bits are defined.
The other bits are unspecified and may be implementation specific.
@rose00 thought it risky and too late to specify that now.
I'd suggest making the `Class.isIdentity()` and `Class.isValue()` native methods and have the VM implement the semantics. Then it will not depend on the modifier bits. Mostly likely, these would become intrinsics.
-------------
PR: https://git.openjdk.org/valhalla/pull/770
More information about the valhalla-dev
mailing list