*not part of the build*

fix for 86789
This commit is contained in:
idk%eng.sun.com 2001-06-26 10:54:44 +00:00
parent 311f761ff7
commit 566b142858
16 changed files with 185 additions and 61 deletions

View File

@ -34,6 +34,28 @@ class bcICall {
virtual bcIUnMarshaler * GetUnMarshaler() = 0;
virtual bcIORB * GetORB() = 0;
};
#define INVOKE_ADDREF(oid,iid,orb) \
do { \
bcICall * call; \
call = GET_ADDREF_CALL((oid),(iid),(orb)); \
(orb)->SendReceive(call); \
delete call; \
} while(0)
#define INVOKE_RELEASE(oid,iid,orb) \
do { \
bcICall * call; \
call = GET_RELEASE_CALL((oid),(iid),(orb)); \
(orb)->SendReceive(call); \
delete call; \
} while(0)
#define GET_ADDREF_CALL(oid,iid,orb) \
(orb)->CreateCall((iid),(oid),1)
#define GET_RELEASE_CALL(oid,iid,orb) \
(orb)->CreateCall((iid),(oid),2)
#endif

View File

@ -31,6 +31,7 @@ class bcIORB {
public:
virtual bcOID RegisterStub(bcIStub *stub) = 0;
virtual void RegisterStubWithOID(bcIStub *stub, bcOID *oid) = 0;
virtual void UnregisterStub(bcOID oid) = 0;
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID) = 0;
virtual int SendReceive(bcICall *) = 0;
//virtual IThread * GetThread(TID) = 0;

View File

@ -26,6 +26,7 @@
class bcIStub {
public:
virtual void Dispatch(bcICall *call) = 0;
//nb shortcut
virtual void SetORB(bcIORB *orb) = 0;
virtual void SetOID(bcOID oid) = 0;
};
#endif

View File

@ -57,12 +57,21 @@ ORB::~ORB() {
bcOID ORB::RegisterStub(bcIStub *stub) {
bcOID oid = GenerateOID();
stubs->Put(new bcOIDKey(oid),stub);
RegisterStubWithOID(stub,&oid);
return oid;
}
void ORB:: RegisterStubWithOID(bcIStub *stub, bcOID *oid) {
void ORB::RegisterStubWithOID(bcIStub *stub, bcOID *oid) {
stubs->Put(new bcOIDKey(*oid),stub);
stub->SetORB(this);
stub->SetOID(*oid);
return;
}
void ORB::UnregisterStub(bcOID oid) {
bcOIDKey *oidKey = new bcOIDKey(oid);
stubs->Remove(oidKey);
delete oidKey;
return;
}
@ -91,12 +100,11 @@ bcIStub * ORB::GetStub(bcOID *oid) {
return (bcIStub*)tmp;
}
struct bcOIDstruct {
PRUint16 high;
PRUint16 low;
};
bcOID ORB::GenerateOID() {
bcOID oid;
bcOIDstruct oidStruct;
@ -104,7 +112,6 @@ bcOID ORB::GenerateOID() {
oidStruct.high = ((PRUint32)this);
oid = *(bcOID*)&oidStruct;
return oid;
}

View File

@ -31,6 +31,7 @@ public:
virtual ~ORB();
virtual bcOID RegisterStub(bcIStub *stub);
virtual void RegisterStubWithOID(bcIStub *stub, bcOID *oid);
virtual void UnregisterStub(bcOID oid);
virtual bcICall * CreateCall(bcIID *, bcOID *, bcMID);
virtual int SendReceive(bcICall *);
private:

View File

@ -1,4 +1,4 @@
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
/* -*- Mode: java; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*-
* The contents of this file are subject to the Mozilla Public
* License Version 1.1 (the "License"); you may not use this file
* except in compliance with the License. You may obtain a copy of
@ -27,20 +27,20 @@ import java.lang.ref.*;
class ProxyKey {
ProxyKey(long _oid, IID _iid) {
oid = new Long(_oid);
iid = _iid;
oid = new Long(_oid);
iid = _iid;
}
public boolean equals(Object obj) {
if (! (obj instanceof ProxyKey)) {
return false;
}
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
if (! (obj instanceof ProxyKey)) {
return false;
}
return (oid.equals(((ProxyKey)obj).oid) && iid.equals(((ProxyKey)obj).iid));
}
public int hashCode() {
return oid.hashCode();
return oid.hashCode();
}
public String toString() {
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
return "org.mozilla.xpcom.ProxyFactory.ProxyKey "+oid+" "+iid;
}
Long oid;
IID iid;
@ -51,34 +51,34 @@ public class ProxyFactory {
Debug.log("--[java] ProxyFactory.getInterface "+iid);
return InterfaceRegistry.getInterface(iid);
}
public static Object getProxy(long oid, IID iid, long orb) {
try {
Debug.log("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
Debug.log("--[java] ProxyFactory.getProxy "+iid);
ProxyKey key = new ProxyKey(oid, iid);
Object obj = null;
Object result = null;
if (proxies != null) {
obj = proxies.get(key);
if (obj != null
&& (obj instanceof Reference)) {
result = ((Reference)obj).get();
}
} else {
proxies = new Hashtable();
}
} else {
proxies = new Hashtable();
}
if (result == null) {
Class inter = getInterface(iid);
if (inter == null) {
Debug.log("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
return null;
if (result == null) {
Class inter = getInterface(iid);
if (inter == null) {
Debug.log("--[java] ProxyFactory.getProxy we did not find interface for iid="+iid+"returing null");
return null;
}
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
InvocationHandler handler = new ProxyHandler(oid, iid, orb);
result = Proxy.newProxyInstance(inter.getClassLoader(), new Class[] {inter},handler);
proxies.put(new WeakReference(result), key);
}
Debug.log("--[java] ProxyFactory.getProxy we got proxy "+result);
return result;
Debug.log("--[java] ProxyFactory.getProxy we got proxy "+result);
return result;
} catch (Exception e) {
Debug.log("--[java] ProxyFactory.getProxy we got exception "+e);
}

View File

@ -25,9 +25,10 @@ import java.lang.reflect.*;
class ProxyHandler implements InvocationHandler {
ProxyHandler(long _oid, IID _iid, long _orb) {
oid = _oid;
iid = _iid;
orb = _orb;
oid = _oid;
iid = _iid;
orb = _orb;
Utilities.callMethod(oid, null, iid, orb, null); //it is hack method = null means addref
}
public Object invoke(Object proxy,
Method method,
@ -39,6 +40,7 @@ class ProxyHandler implements InvocationHandler {
} else if (str.equals("clone")) {
throw new java.lang.CloneNotSupportedException();
} else if (str.equals("finalize")) {
Utilities.callMethod(oid, method, iid, orb, args);
finalize();
} else if (str.equals("equals")) {
if (args[0] instanceof ProxyHandler) {
@ -64,3 +66,5 @@ class ProxyHandler implements InvocationHandler {
private long orb;
}

View File

@ -74,7 +74,14 @@ public class Utilities {
static Object callMethod(long oid, Method method, IID iid, long orb , Object[] args) {
Debug.log("--[java]Utilities.callMethod "+method);
int mid = InterfaceRegistry.getIndexByMethod(method, iid);
int mid;
if (method == null) {
mid = 1; //it is hack method = null means addref
} else if ("finalize".equals(method.getName())) {
mid = 2;
} else {
mid = InterfaceRegistry.getIndexByMethod(method, iid);
}
if (mid < 0) {
Debug.log("--[java]Utilities.callMethod we do not have implementation for "+method);
return null;

View File

@ -34,7 +34,7 @@ jclass bcJavaStub::objectClass = NULL;
jclass bcJavaStub::utilitiesClass = NULL;
jmethodID bcJavaStub::callMethodByIndexMID = NULL;
bcJavaStub::bcJavaStub(jobject obj) {
bcJavaStub::bcJavaStub(jobject obj) : orb(NULL) {
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub \n"));
if (!obj) {
@ -43,11 +43,24 @@ bcJavaStub::bcJavaStub(jobject obj) {
}
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
object = env->NewGlobalRef(obj);
refCounter = 0;
}
bcJavaStub::~bcJavaStub() {
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
if (orb != NULL) {
orb->UnregisterStub(oid);
}
}
void bcJavaStub::SetORB(bcIORB *_orb) {
orb = _orb;
}
void bcJavaStub::SetOID(bcOID _oid) {
oid = _oid;
}
void bcJavaStub::Dispatch(bcICall *call) {
@ -57,6 +70,20 @@ void bcJavaStub::Dispatch(bcICall *call) {
bcIID iid; bcOID oid; bcMID mid;
jobjectArray args;
call->GetParams(&iid, &oid, &mid);
if (mid == 1) { //AddRef
refCounter++;
return;
} else if (mid == 2) { //Release
refCounter--;
printf("-java mid==2\n");
if (refCounter <= 0) {
printf("-java delete\n");
delete this;
return;
}
}
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {

View File

@ -31,8 +31,13 @@ class bcJavaStub : public bcIStub {
bcJavaStub(jobject obj);
virtual ~bcJavaStub();
virtual void Dispatch(bcICall *call) ;
virtual void SetORB(bcIORB *orb);
virtual void SetOID(bcOID oid);
private:
bcIORB *orb;
bcOID oid;
jobject object;
PRUint32 refCounter;
static jclass objectClass;
static jclass utilitiesClass;
static jmethodID callMethodByIndexMID;

View File

@ -52,8 +52,15 @@ JNIEXPORT jobject JNICALL Java_org_mozilla_xpcom_Utilities_callMethodByIndex
str = env->GetStringUTFChars(jiid,NULL);
iid.Parse(str);
env->ReleaseStringUTFChars(jiid,str);
if (mid == 2) {
INVOKE_RELEASE(&oid,&iid,orb);
return NULL;
} else if (mid == 1) {
INVOKE_ADDREF(&oid,&iid,orb);
return NULL;
}
bcICall *call = orb->CreateCall(&iid, &oid, mid);
/*****/
nsIInterfaceInfo *interfaceInfo;
nsIInterfaceInfoManager* iimgr;

View File

@ -31,7 +31,7 @@ static NS_DEFINE_CID(kXPCOMStubsAndProxies,BC_XPCOMSTUBSANDPROXIES_CID);
static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
bcXPCOMMarshalToolkit::bcXPCOMMarshalToolkit(PRUint16 _methodIndex, nsIInterfaceInfo *_interfaceInfo,
nsXPTCMiniVariant* _params, bcIORB *_orb) {
nsXPTCMiniVariant* _params, bcIORB *_orb) {
callSide = onClient;
orb = _orb;
methodIndex = _methodIndex;

View File

@ -49,10 +49,12 @@ bcXPCOMProxy::bcXPCOMProxy(bcOID _oid, const nsIID &_iid, bcIORB *_orb) {
orb = _orb;
interfaceInfo = NULL;
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] bcXPCOMProxy::bcXPCOMProxy this: %p iid: %s\n",this, iid.ToString()));
INVOKE_ADDREF(&oid,&iid,orb);
}
bcXPCOMProxy::~bcXPCOMProxy() {
NS_IF_RELEASE(interfaceInfo);
INVOKE_RELEASE(&oid,&iid,orb);
}
@ -174,7 +176,7 @@ nsrefcnt bcXPCOMProxy::Release(void) {
nsrefcnt cnt = (nsrefcnt) PR_AtomicDecrement((PRInt32*)&mRefCnt);
PR_LOG(log, PR_LOG_DEBUG, ("--[c++] bcXPCOMProxy::Release %d\n",(unsigned)cnt));
if(0 == cnt) {
delete this;
delete this;
}
return cnt;
}

View File

@ -52,10 +52,11 @@ struct CallInfo {
PRBool completed;
};
bcXPCOMStub::bcXPCOMStub(nsISupports *o) : object(o) {
bcXPCOMStub::bcXPCOMStub(nsISupports *o) : object(o), orb(NULL) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::bcXPCOMStub\n"));
NS_ADDREF(object);
refCounter = 0;
nsresult rv;
_mOwningThread = PR_CurrentThread();
eventQService = do_GetService(kEventQueueServiceCID);
@ -75,6 +76,9 @@ bcXPCOMStub::bcXPCOMStub(nsISupports *o) : object(o) {
bcXPCOMStub::~bcXPCOMStub() {
NS_RELEASE(object);
if (orb != NULL) {
orb->UnregisterStub(oid);
}
}
void bcXPCOMStub::DispatchAndSaveThread(bcICall *call, nsIEventQueue *eventQueue) {
@ -109,25 +113,47 @@ void bcXPCOMStub::DispatchAndSaveThread(bcICall *call, nsIEventQueue *eventQueue
nsCOMPtr<bcIXPCOMStubsAndProxies> stubsAndProxiesService;
stubsAndProxiesService = do_GetService(kStubsAndProxies);
stubsAndProxiesService->PushEventQueue(eventQueue);
//nb return value; excepion handling
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade about to XPTC_InvokeByIndex\n"));
nsresult result = XPTC_InvokeByIndex(object, mid, paramCount, params);
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade after XPTC_InvokeByIndex\n"));
bcIMarshaler * m = call->GetMarshaler();
m->WriteSimple(&result, bc_T_U32);
if (NS_SUCCEEDED(result)
&& mt != NULL) {
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade about to mt->Marshal\n"));
mt->Marshal(m);
delete m;
if (mid == 2) { //Release
if (refCounter <= 0) {
NS_DELETEXPCOM(this);
}
} else {
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade about to XPTC_InvokeByIndex\n"));
nsresult result = XPTC_InvokeByIndex(object, mid, paramCount, params);
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade after XPTC_InvokeByIndex\n"));
bcIMarshaler * m = call->GetMarshaler();
m->WriteSimple(&result, bc_T_U32);
if (NS_SUCCEEDED(result)
&& mt != NULL) {
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStub::DispatchAndSaveThreade about to mt->Marshal\n"));
mt->Marshal(m);
delete m;
}
delete mt;
}
delete mt;
//pop caller eventQueue
stubsAndProxiesService->PopEventQueue(NULL);
return;
}
void bcXPCOMStub::Dispatch(bcICall *call) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
/* AddRef Release handling is here.
*/
bcIID iid; bcOID oid; bcMID mid;
call->GetParams(&iid, &oid, &mid);
if (mid == 1) { //AddRef
refCounter++;
return;
} else if (mid == 2) { //Release
refCounter--;
if (refCounter > 0) {
// if refCounter <= 0 wrapped object has to be released.
// That release should happen in the appropriate thread
return;
}
}
if (_mOwningThread == PR_CurrentThread()
|| NULL == (void*)owningEventQ) {
DispatchAndSaveThread(call);
@ -176,6 +202,13 @@ void bcXPCOMStub::Dispatch(bcICall *call) {
}
void bcXPCOMStub::SetORB(bcIORB *_orb) {
orb = _orb;
}
void bcXPCOMStub::SetOID(bcOID _oid) {
oid = _oid;
}
static void* EventHandler(PLEvent *self) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();

View File

@ -32,13 +32,19 @@ public:
bcXPCOMStub(nsISupports *obj);
virtual ~bcXPCOMStub();
virtual void Dispatch(bcICall *call) ;
virtual void SetORB(bcIORB *orb);
virtual void SetOID(bcOID oid);
void DispatchAndSaveThread(bcICall *call, nsIEventQueue *q = NULL);
private:
nsISupports *object;
bcIORB *orb;
bcOID oid;
void* _mOwningThread;
nsCOMPtr<nsIEventQueue> owningEventQ;
nsCOMPtr<nsIEventQueueService> eventQService;
PRUint32 refCounter;
};
#endif

View File

@ -150,6 +150,7 @@ NS_IMETHODIMP bcXPCOMStubsAndProxies::GetEventQueue(nsIEventQueue **eventQueue)
}
return NS_OK;
}
NS_IMETHODIMP bcXPCOMStubsAndProxies::PopEventQueue(nsIEventQueue **_eventQueue) {
PRLogModuleInfo *log = bcXPCOMLog::GetLog();
PR_LOG(log, PR_LOG_DEBUG, ("--bcXPCOMStubsAndProxies::PopEventQueue\n"));