From b0d3f3940bf761b4a04af0052c39527a62a5204d Mon Sep 17 00:00:00 2001 From: "pedemont%us.ibm.com" Date: Wed, 27 Sep 2006 15:18:30 +0000 Subject: [PATCH] Store the key in the hash entry struct so that it works better with stub hash functions. Not part of default build. Original committer: pedemont%us.ibm.com Original revision: 1.5 Original date: 2004/09/30 23:20:34 --- extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp b/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp index 4b639d34d2cb..37ae4fbee525 100644 --- a/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp +++ b/extensions/java/xpcom/src/nsJavaXPCOMBindingUtils.cpp @@ -108,6 +108,9 @@ jclass exceptionClass = nsnull; class JavaXPCOMBindingEntry : public PLDHashEntryHdr { public: + // mKey will either be a Java hash of the Java object, or the address of + // the XPCOM object, depending on which hash table this entry is used in. + const void* mKey; jobject mJavaObject; void* mXPCOMInstance; }; @@ -123,6 +126,7 @@ InitJAVAtoXPCOMBindingEntry(PLDHashTable *table, PLDHashEntryHdr *entry, NS_CONST_CAST(JavaXPCOMBindingEntry *, NS_STATIC_CAST(const JavaXPCOMBindingEntry *, entry)); + e->mKey = key; e->mJavaObject = NS_CONST_CAST(jobject, NS_STATIC_CAST(const __jobject*, key)); e->mXPCOMInstance = nsnull; @@ -138,6 +142,7 @@ InitXPCOMtoJAVABindingEntry(PLDHashTable *table, PLDHashEntryHdr *entry, NS_CONST_CAST(JavaXPCOMBindingEntry *, NS_STATIC_CAST(const JavaXPCOMBindingEntry *, entry)); + e->mKey = key; e->mXPCOMInstance = NS_CONST_CAST(void*, key); e->mJavaObject = nsnull; @@ -147,6 +152,9 @@ InitXPCOMtoJAVABindingEntry(PLDHashTable *table, PLDHashEntryHdr *entry, void AddJavaXPCOMBinding(JNIEnv* env, jobject aJavaObject, void* aXPCOMObject) { + // We use a Java hash of the Java object as a key since the JVM can return + // different "addresses" for the same Java object, but the hash code (the + // result of calling |hashCode()| on the Java object) will always be the same. jint hash = env->CallIntMethod(aJavaObject, hashCodeMID); JavaXPCOMBindingEntry *entry =