[lworld] RFR: 8294312: [lworld] Add java.util.Objects.isIdentityObject
Mandy Chung
mchung at openjdk.org
Thu Sep 29 18:09:41 UTC 2022
On Thu, 29 Sep 2022 17:33:14 GMT, Roger Riggs <rriggs at openjdk.org> wrote:
>> 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.
Alternatively, we could use `getClassAccessFlagsRaw` to return the VM specific flags to indicate that.
I think checking `isArray` is a good interim solution.
-------------
PR: https://git.openjdk.org/valhalla/pull/770
More information about the valhalla-dev
mailing list