Skip to content
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions src/java.se/share/data/jdwp/jdwp.spec
Original file line number Diff line number Diff line change
Expand Up @@ -1801,6 +1801,33 @@ JDWP "Java(tm) Debug Wire Protocol"
(Error VM_DEAD)
)
)
(Command IsSameObject=11
"Determines whether two objects refer to the same Java object."
(Out
(object object1 "The object ID")
(object object2 "The object ID")
)
(Reply
(boolean isSameObject "true if the objects refer to the same Java object; false otherwise")
)
(ErrorSet
(Error INVALID_OBJECT)
(Error VM_DEAD)
)
)
(Command ObjectHashCode=12
"Returns hash code for an object."
(Out
(object object "The object ID")
)
(Reply
(int hashCode "hash code value for the object")
)
(ErrorSet
(Error INVALID_OBJECT)
(Error VM_DEAD)
)
)
)

(CommandSet StringReference=10
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -147,8 +147,16 @@ public boolean vmNotSuspended(VMAction action) {

public boolean equals(Object obj) {
if (obj instanceof ObjectReferenceImpl other) {
return (ref() == other.ref()) &&
super.equals(obj);
if (ref() == other.ref() && super.equals(obj)) {
return true;
}
// We can get equal value objects with different IDs.
// TODO: do it only for value objects.
try {
return JDWP.ObjectReference.IsSameObject.process(vm, this, other).isSameObject;
} catch (JDWPException exc) {
throw exc.toJDIException();
}
} else {
return false;
}
Expand Down
61 changes: 60 additions & 1 deletion src/jdk.jdwp.agent/share/native/libjdwp/ObjectReferenceImpl.c
Original file line number Diff line number Diff line change
Expand Up @@ -357,6 +357,63 @@ referringObjects(PacketInputStream *in, PacketOutputStream *out)
return JNI_TRUE;
}

static jboolean
isSameObjectImpl(PacketInputStream *in, PacketOutputStream *out)
{
jlong id1;
jlong id2;
jobject ref1;
jobject ref2;
JNIEnv *env;

env = getEnv();
id1 = inStream_readObjectID(in);
id2 = inStream_readObjectID(in);
if (inStream_error(in)) {
return JNI_TRUE;
}

if (id1 == NULL_OBJECT_ID || id2 == NULL_OBJECT_ID) {
outStream_setError(out, JDWP_ERROR(INVALID_OBJECT));
return JNI_TRUE;
}

ref1 = commonRef_idToRef(env, id1);
ref2 = commonRef_idToRef(env, id2);
(void)outStream_writeBoolean(out, isSameObject(env, ref1, ref2));

commonRef_idToRef_delete(env, ref1);
commonRef_idToRef_delete(env, ref2);

return JNI_TRUE;
}

static jboolean
objectHashCodeImpl(PacketInputStream *in, PacketOutputStream *out)
{
jlong id;
jobject ref;
JNIEnv *env;

env = getEnv();
id = inStream_readObjectID(in);
if (inStream_error(in)) {
return JNI_TRUE;
}

if (id == NULL_OBJECT_ID) {
outStream_setError(out, JDWP_ERROR(INVALID_OBJECT));
return JNI_TRUE;
}

ref = commonRef_idToRef(env, id);
(void)outStream_writeInt(out, objectHashCode(ref));

commonRef_idToRef_delete(env, ref);

return JNI_TRUE;
}

Command ObjectReference_Commands[] = {
{referenceType, "ReferenceType"},
{getValues, "GetValues"},
Expand All @@ -367,7 +424,9 @@ Command ObjectReference_Commands[] = {
{disableCollection, "DisableCollection"},
{enableCollection, "EnableCollection"},
{isCollected, "IsCollected"},
{referringObjects, "ReferringObjects"}
{referringObjects, "ReferringObjects"},
{isSameObjectImpl, "IsSameObject"},
{objectHashCodeImpl, "ObjectHashCode"}
};

DEBUG_DISPATCH_DEFINE_CMDSET(ObjectReference)
Loading