mirror of
https://github.com/mozilla/gecko-dev.git
synced 2024-10-09 19:35:51 +00:00
*not part of the build*
fix for 88176
This commit is contained in:
parent
40203a34c1
commit
54ccc7b9f5
@ -27,6 +27,6 @@ srcdir = @srcdir@
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
DIRS= xpidl src jni loader import classes components test
|
||||
DIRS= xpidl src jni loader import classes components
|
||||
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
|
@ -32,7 +32,7 @@ public class Utilities {
|
||||
Debug.log("--[java]callMethodByIndex args["+i+"] = "+args[i]);
|
||||
}
|
||||
Method method = InterfaceRegistry.getMethodByIndex(mid,iid);
|
||||
Debug.log("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method);
|
||||
Debug.log("--[java] org.mozilla.xpcom.Utilities.callMethodByIndex method "+method+" object "+obj);
|
||||
try {
|
||||
|
||||
if (method != null) {
|
||||
|
@ -44,13 +44,17 @@ JNIEXPORT void JNICALL Java_org_mozilla_xpcom_Components_initXPCOM
|
||||
nsIServiceManager* servMgr;
|
||||
rv = NS_InitXPCOM(&servMgr, NULL);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG_idk
|
||||
printf("--Components::initXPCOM failed \n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
rv = nsComponentManager::AutoRegister(nsIComponentManager::NS_Startup,
|
||||
NULL /* default */);
|
||||
if (NS_FAILED(rv)) {
|
||||
#ifdef DEBUG_idk
|
||||
printf("--Components::initXPCOM failed \n");
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -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 (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->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;
|
||||
}
|
||||
|
||||
|
@ -25,6 +25,8 @@
|
||||
#include "nsIModule.h"
|
||||
#include "nsIEnumerator.h"
|
||||
#include "stdlib.h"
|
||||
#include "prthread.h"
|
||||
#include "prmon.h"
|
||||
|
||||
#define BC_JAVA_SAMPLE_CID \
|
||||
{0x072fa586, 0x1dd2, 0x11b2, \
|
||||
@ -132,6 +134,26 @@ NS_IMETHODIMP bcJavaSample::Test9(nsIID * *po) {
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
|
||||
static bcIJavaSample * javaSample = NULL;
|
||||
|
||||
void thread_start( void *arg ) {
|
||||
printf("--thread_start currentThread=%p\n",PR_GetCurrentThread());
|
||||
if (javaSample == NULL) {
|
||||
nsresult r;
|
||||
r = nsComponentManager::CreateInstance("bcJavaSample",
|
||||
nsnull,
|
||||
NS_GET_IID(bcIJavaSample),
|
||||
(void**)&javaSample);
|
||||
// } else {
|
||||
bcIJavaSample *t;
|
||||
javaSample->Test1((int)PR_GetCurrentThread());
|
||||
printf("--thread_start after first invocation \n");
|
||||
javaSample->Test1((int)PR_GetCurrentThread());
|
||||
printf("--thread_start after second invocation \n");
|
||||
}
|
||||
}
|
||||
|
||||
void test() {
|
||||
printf("--BlackConnect test start\n");
|
||||
nsresult r;
|
||||
@ -148,6 +170,21 @@ void test() {
|
||||
//sigsend(P_PID, getpid(),SIGINT);
|
||||
//test->Test1(2000);
|
||||
#if 1
|
||||
{
|
||||
for (int i = 0; i < 1; i++) {
|
||||
printf("\n--we are creating threads i=%d\n",i);
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start,
|
||||
test,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_LOCAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0);
|
||||
PR_JoinThread(thr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
test->Test1(1000);
|
||||
bcIJavaSample *test1;
|
||||
if (NS_FAILED(r)) {
|
||||
@ -158,7 +195,6 @@ void test() {
|
||||
test->QueryInterface(NS_GET_IID(bcIJavaSample),(void**)&test1);
|
||||
int intArray[] = {1,2,3};
|
||||
test->Test3(3, intArray);
|
||||
#endif
|
||||
{
|
||||
char ** valueArray = (char **)malloc(sizeof(char*)*4);
|
||||
valueArray[0] = "hi";
|
||||
|
@ -48,8 +48,10 @@ public class bcJavaSample implements bcIJavaSample {
|
||||
}
|
||||
public void test1(int l) {
|
||||
System.out.println("--[java]bcJavaSample.test1 "+l+"\n");
|
||||
|
||||
|
||||
try {
|
||||
Thread.currentThread().sleep(1000);
|
||||
} catch (java.lang.InterruptedException e) {
|
||||
};
|
||||
}
|
||||
public void test2(bcIJavaSample o) {
|
||||
System.out.println("--[java]bcJavaSample.test2");
|
||||
|
Loading…
Reference in New Issue
Block a user