if (gJavaXPCOMLock) { nsAutoLock lock(gJavaXPCOMLock);
if (gJavaXPCOMMonitor) { nsAutoMonitor mon(gJavaXPCOMMonitor);
JAVAPROXY_NATIVE(finalizeProxy) (JNIEnv *env, jclass that, jobject aJavaProxy){  // Due to Java's garbage collection, this finalize statement may get called  // after FreeJavaGlobals().  So check to make sure that everything is still  // initialized.  if (gJavaXPCOMLock) {    nsAutoLock lock(gJavaXPCOMLock);    // Get native XPCOM instance    void* xpcom_obj;    nsresult rv = GetXPCOMInstFromProxy(env, aJavaProxy, &xpcom_obj);    if (NS_SUCCEEDED(rv)) {      JavaXPCOMInstance* inst = NS_STATIC_CAST(JavaXPCOMInstance*, xpcom_obj);      nsIID* iid;      rv = inst->InterfaceInfo()->GetInterfaceIID(&iid);      if (NS_SUCCEEDED(rv)) {        rv = gNativeToJavaProxyMap->Remove(env, inst->GetInstance(), *iid);#ifdef DEBUG_JAVAXPCOM        char* iid_str = iid->ToString();        LOG(("- Finalize (Java=%08x | XPCOM=%08x | IID=%s)\n",             env->CallIntMethod(aJavaProxy, hashCodeMID),             (int) inst->GetInstance(), iid_str));        PR_Free(iid_str);#endif        nsMemory::Free(iid);      }      NS_ASSERTION(NS_SUCCEEDED(rv), "Failed to RemoveJavaProxy");      delete inst;    }  }}