[lworld] RFR: 8294312: [lworld] Add java.util.Objects.isIdentityObject

Mandy Chung mchung at openjdk.org
Thu Sep 29 17:13:41 UTC 2022


On Wed, 28 Sep 2022 15:49:05 GMT, Roger Riggs <rriggs 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);
}

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

PR: https://git.openjdk.org/valhalla/pull/770



More information about the valhalla-dev mailing list