*not part of the build*
fix for 88176 git-svn-id: svn://10.0.0.236/trunk@98775 18797224-902f-48f8-a5cc-f745e15eee43
This commit is contained in:
@@ -29,41 +29,59 @@ jmethodID bcIIDJava::getStringMID = NULL;
|
||||
static nsID nullID = {0, 0, 0, {0, 0, 0, 0, 0, 0, 0, 0}};
|
||||
|
||||
void bcIIDJava::Init(void) {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
if (env) {
|
||||
if (!(iidClass = env->FindClass("org/mozilla/xpcom/IID"))
|
||||
|| !(iidClass = (jclass) env->NewGlobalRef(iidClass))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(iidInitMID = env->GetMethodID(iidClass,"<init>","(Ljava/lang/String;)V"))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!(getStringMID = env->GetMethodID(iidClass,"getString","()Ljava/lang/String;"))) {
|
||||
env->ExceptionDescribe();
|
||||
Destroy();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
void bcIIDJava::Destroy() {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
if (env) {
|
||||
if (iidClass) {
|
||||
env->DeleteGlobalRef(iidClass);
|
||||
iidClass = NULL;
|
||||
}
|
||||
if (iidClass) {
|
||||
env->DeleteGlobalRef(iidClass);
|
||||
iidClass = NULL;
|
||||
}
|
||||
}
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
}
|
||||
|
||||
jobject bcIIDJava::GetObject(nsIID *iid) {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
if (!iid
|
||||
|| !env
|
||||
|| nullID.Equals(*iid)) {
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
if (!iidClass) {
|
||||
@@ -76,7 +94,11 @@ jobject bcIIDJava::GetObject(nsIID *iid) {
|
||||
siid[strlen(siid)-1] = 0;
|
||||
jstr = env->NewStringUTF((const char *)siid);
|
||||
}
|
||||
return env->NewObject(iidClass,iidInitMID,jstr);
|
||||
jobject ret = env->NewObject(iidClass,iidInitMID,jstr);
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
jclass bcIIDJava::GetClass() {
|
||||
@@ -85,7 +107,8 @@ jclass bcIIDJava::GetClass() {
|
||||
|
||||
nsIID bcIIDJava::GetIID(jobject obj) {
|
||||
nsIID iid;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
if (env) {
|
||||
if (!iidClass) {
|
||||
Init();
|
||||
@@ -100,5 +123,8 @@ nsIID bcIIDJava::GetIID(jobject obj) {
|
||||
iid = nullID;
|
||||
}
|
||||
}
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return iid;
|
||||
}
|
||||
|
||||
@@ -37,18 +37,38 @@ PRLogModuleInfo* bcJavaGlobal::log = NULL;
|
||||
#define JNIENV (void**)
|
||||
#endif
|
||||
|
||||
JNIEnv * bcJavaGlobal::GetJNIEnv(void) {
|
||||
static int counter = 0;
|
||||
|
||||
JNIEnv * bcJavaGlobal::GetJNIEnv(int *detachRequired) {
|
||||
JNIEnv * env;
|
||||
int res;
|
||||
*detachRequired = 1;
|
||||
if (!jvm) {
|
||||
StartJVM();
|
||||
}
|
||||
if (jvm) {
|
||||
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
|
||||
res = jvm->GetEnv(JNIENV &env, JNI_VERSION_1_2);
|
||||
if (res == JNI_OK) {
|
||||
*detachRequired = 0;
|
||||
} else {
|
||||
res = jvm->AttachCurrentThread(JNIENV &env,NULL);
|
||||
#ifdef DEBUG_idk
|
||||
printf("--bcJavaGlobal::GetJNIEnv ++counter %d\n",++counter);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
return env;
|
||||
}
|
||||
|
||||
void bcJavaGlobal::ReleaseJNIEnv() {
|
||||
int res;
|
||||
if (jvm) {
|
||||
res = jvm->DetachCurrentThread();
|
||||
#ifdef DEBUG_idk
|
||||
printf("--bcJavaGlobal::ReleaseJNIEnv --counter %d\n",--counter);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
|
||||
void bcJavaGlobal::StartJVM() {
|
||||
PRLogModuleInfo * l = GetLog();
|
||||
|
||||
@@ -37,7 +37,8 @@
|
||||
|
||||
class bcJavaGlobal {
|
||||
public:
|
||||
static JNIEnv * GetJNIEnv(void);
|
||||
static JNIEnv * GetJNIEnv(int *detachRequired);
|
||||
static void ReleaseJNIEnv();
|
||||
static PRLogModuleInfo * GetLog();
|
||||
private:
|
||||
static PRLogModuleInfo* log;
|
||||
|
||||
@@ -41,17 +41,26 @@ bcJavaStub::bcJavaStub(jobject obj) : orb(NULL) {
|
||||
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStub::bcJavaStub obj== 0\n"));
|
||||
return;
|
||||
}
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
object = env->NewGlobalRef(obj);
|
||||
refCounter = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
bcJavaStub::~bcJavaStub() {
|
||||
bcJavaGlobal::GetJNIEnv()->DeleteGlobalRef(object);
|
||||
int detachRequired;
|
||||
JNIEnv *env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
env->DeleteGlobalRef(object);
|
||||
if (orb != NULL) {
|
||||
orb->UnregisterStub(oid);
|
||||
}
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -66,13 +75,17 @@ void bcJavaStub::SetOID(bcOID _oid) {
|
||||
void bcJavaStub::Dispatch(bcICall *call) {
|
||||
//sigsend(P_PID, getpid(),SIGINT);
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
bcIID iid; bcOID oid; bcMID mid;
|
||||
jobjectArray args;
|
||||
call->GetParams(&iid, &oid, &mid);
|
||||
|
||||
if (mid == 1) { //AddRef
|
||||
refCounter++;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
} else if (mid == 2) { //Release
|
||||
refCounter--;
|
||||
@@ -80,6 +93,9 @@ void bcJavaStub::Dispatch(bcICall *call) {
|
||||
if (refCounter <= 0) {
|
||||
printf("-java delete\n");
|
||||
delete this;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -88,15 +104,24 @@ void bcJavaStub::Dispatch(bcICall *call) {
|
||||
nsIInterfaceInfoManager* iimgr;
|
||||
if((iimgr = XPTI_GetInterfaceInfoManager()) != NULL) {
|
||||
if (NS_FAILED(iimgr->GetInfoForIID(&iid, &interfaceInfo))) {
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return; //nb exception handling
|
||||
}
|
||||
NS_RELEASE(iimgr);
|
||||
} else {
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!objectClass) {
|
||||
Init();
|
||||
if (!objectClass) {
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -124,26 +149,39 @@ void bcJavaStub::Dispatch(bcICall *call) {
|
||||
mt->Marshal(m, retval);
|
||||
}
|
||||
delete m; delete um; delete mt;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
void bcJavaStub::Init() {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
objectClass = (jclass)env->NewGlobalRef(env->FindClass("java/lang/Object"));
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
utilitiesClass = (jclass)env->NewGlobalRef(env->FindClass("org/mozilla/xpcom/Utilities"));
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
callMethodByIndexMID = env->GetStaticMethodID(utilitiesClass,"callMethodByIndex","(Ljava/lang/Object;Lorg/mozilla/xpcom/IID;I[Ljava/lang/Object;)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -118,10 +118,14 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetProxy(bcOID oid, const nsIID &iid, bcIOR
|
||||
*proxy = (jobject)tmp;
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("\n--bcJavaStubsAndProxies::GetProxy we have shortcut for oid=%d\n",oid));
|
||||
} else {
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*proxy = env->CallStaticObjectMethod(proxyFactory,getProxyID, (jlong)oid, jiid, (jlong)orb);
|
||||
EXCEPTION_CHECKING(env);
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
@@ -135,16 +139,21 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetInterface(const nsIID &iid, jclass *cla
|
||||
if (!componentLoader) {
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
jobject jiid = bcIIDJava::GetObject((nsIID*)&iid);
|
||||
*clazz = (jclass)env->CallStaticObjectMethod(proxyFactory,getInterfaceID, jiid);
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID *oid) {
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
nsresult rv = NS_OK;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
if (env->IsInstanceOf(object,java_lang_reflect_Proxy)) {
|
||||
EXCEPTION_CHECKING(env);
|
||||
jobject handler = env->CallStaticObjectMethod(java_lang_reflect_Proxy,getInvocationHandlerID,object);
|
||||
@@ -154,12 +163,18 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID
|
||||
EXCEPTION_CHECKING(env);
|
||||
*oid = env->CallLongMethod(handler,getOIDID);
|
||||
PR_LOG(log, PR_LOG_DEBUG, ("--bcJavaStubsAndProxies::GetOID we are using old oid %d\n",*oid));
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return rv;
|
||||
}
|
||||
}
|
||||
bcIStub *stub = new bcJavaStub(object);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
oid2objectMap->Put(new bcOIDKey(*oid),object);
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return rv;
|
||||
|
||||
}
|
||||
@@ -167,13 +182,17 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(jobject object, bcIORB *orb, bcOID
|
||||
NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID %s\n",location));
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
nsresult result;
|
||||
|
||||
if (!componentLoader) {
|
||||
Init();
|
||||
}
|
||||
if (!componentLoader) {
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return NS_ERROR_FAILURE;
|
||||
}
|
||||
//location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
|
||||
@@ -184,59 +203,87 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
|
||||
NS_WITH_SERVICE(bcIORBComponent,_orb,kORBComponent,&result);
|
||||
if (NS_FAILED(result)) {
|
||||
PR_LOG(log,PR_LOG_DEBUG,("--bcJavaStubsAndProxies::GetOID failed\n"));
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bcIORB *orb;
|
||||
_orb->GetORB(&orb);
|
||||
*oid = orb->RegisterStub(stub);
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
void bcJavaStubsAndProxies::Init(void) {
|
||||
PRLogModuleInfo *log = bcJavaGlobal::GetLog();
|
||||
PR_LOG(log, PR_LOG_DEBUG,("--[c++]bcJavaStubsAndProxies::Init\n"));
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv();
|
||||
int detachRequired;
|
||||
JNIEnv * env = bcJavaGlobal::GetJNIEnv(&detachRequired);
|
||||
componentLoader = env->FindClass("org/mozilla/xpcom/ComponentLoader");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
PR_LOG(log,PR_LOG_ALWAYS,("--Did you set CLASSPATH correctly\n"));
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
componentLoader = (jclass)env->NewGlobalRef(componentLoader);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
loadComponentID = env->GetStaticMethodID(componentLoader,"loadComponent","(Ljava/lang/String;)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
proxyFactory = env->FindClass("org/mozilla/xpcom/ProxyFactory");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
proxyFactory = (jclass)env->NewGlobalRef(proxyFactory);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
getProxyID = env->GetStaticMethodID(proxyFactory, "getProxy","(JLorg/mozilla/xpcom/IID;J)Ljava/lang/Object;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
getInterfaceID = env->GetStaticMethodID(proxyFactory, "getInterface","(Lorg/mozilla/xpcom/IID;)Ljava/lang/Class;");
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -244,6 +291,9 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -253,6 +303,9 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -260,6 +313,9 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -267,12 +323,18 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
org_mozilla_xpcom_ProxyHandler = (jclass)env->NewGlobalRef(org_mozilla_xpcom_ProxyHandler);
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -280,6 +342,9 @@ void bcJavaStubsAndProxies::Init(void) {
|
||||
if (env->ExceptionOccurred()) {
|
||||
env->ExceptionDescribe();
|
||||
componentLoader = 0;
|
||||
if (detachRequired) {
|
||||
bcJavaGlobal::ReleaseJNIEnv();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user