< prev index next >

src/jdk.jdi/share/classes/com/sun/tools/jdi/ObjectReferenceImpl.java

Print this page
*** 143,21 ***
                  return true;
              }
          }
      }
  
      public boolean equals(Object obj) {
          if (obj instanceof ObjectReferenceImpl other) {
!             return (ref() == other.ref()) &&
!                    super.equals(obj);
!         } else {
!             return false;
          }
      }
  
      @Override
      public int hashCode() {
          return Long.hashCode(ref());
      }
  
      public Type type() {
          return referenceType();
--- 143,46 ---
                  return true;
              }
          }
      }
  
+     boolean isValueObject() {
+         if (referenceType() instanceof ClassTypeImpl classType) {
+             return classType.isValueClass();
+         }
+         return false;
+     }
+ 
      public boolean equals(Object obj) {
          if (obj instanceof ObjectReferenceImpl other) {
!             if (!super.equals(obj)) { // checks if the references belong to the same VM
!                 return false;
!             }
!             if (ref() == other.ref()) {
+                 return true;
+             }
+             // We can get equal value objects with different IDs.
+             if (isValueObject()) {
+                 try {
+                     return JDWP.ObjectReference.IsSameObject.process(vm, this, other).isSameObject;
+                 } catch (JDWPException exc) {
+                     throw exc.toJDIException();
+                 }
+             }
          }
+         return false;
      }
  
      @Override
      public int hashCode() {
+         if (isValueObject()) {
+             try {
+                 return JDWP.ObjectReference.ObjectHashCode.process(vm, this).hashCode;
+             } catch (JDWPException exc) {
+                 throw exc.toJDIException();
+             }
+         }
          return Long.hashCode(ref());
      }
  
      public Type type() {
          return referenceType();
< prev index next >