зеркало из https://github.com/mozilla/pjs.git
Родитель
752362081c
Коммит
2ce095c68d
|
@ -1,148 +0,0 @@
|
|||
/* -*- Mode: C++; 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
|
||||
* the License at http://www.mozilla.org/MPL/
|
||||
*
|
||||
* Software distributed under the License is distributed on an "AS
|
||||
* IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
* implied. See the License for the specific language governing
|
||||
* rights and limitations under the License.
|
||||
*
|
||||
* The Original Code is mozilla.org code.
|
||||
*
|
||||
* The Initial Developer of the Original Code is Sun Microsystems,
|
||||
* Inc. Portions created by Sun are
|
||||
* Copyright (C) 1999 Sun Microsystems, Inc. All
|
||||
* Rights Reserved.
|
||||
*
|
||||
* Contributor(s):
|
||||
* Igor Kushnirskiy <idk@eng.sun.com>
|
||||
*/
|
||||
#include "bcJavaGlobal.h"
|
||||
#include "prenv.h"
|
||||
|
||||
|
||||
JavaVM *bcJavaGlobal::jvm = NULL;
|
||||
PRLogModuleInfo* bcJavaGlobal::log = NULL;
|
||||
#ifdef XP_PC
|
||||
#define PATH_SEPARATOR ';'
|
||||
#else
|
||||
#define PATH_SEPARATOR ':'
|
||||
#endif
|
||||
|
||||
#ifdef JRI_MD_H //we are using jni.h from netscape
|
||||
#define JNIENV
|
||||
#else
|
||||
#define JNIENV (void**)
|
||||
#endif
|
||||
|
||||
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();
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM begin\n"));
|
||||
JNIEnv *env = NULL;
|
||||
jint res;
|
||||
jsize jvmCount;
|
||||
JNI_GetCreatedJavaVMs(&jvm, 1, &jvmCount);
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM after GetCreatedJavaVMs\n"));
|
||||
if (jvmCount) {
|
||||
return;
|
||||
}
|
||||
#if 0
|
||||
JDK1_1InitArgs vm_args;
|
||||
char classpath[1024];
|
||||
JNI_GetDefaultJavaVMInitArgs(&vm_args);
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--[c++] version %d",(int)vm_args.version));
|
||||
vm_args.version = 0x00010001;
|
||||
/* Append USER_CLASSPATH to the default system class path */
|
||||
sprintf(classpath, "%s%c%s",
|
||||
vm_args.classpath, PATH_SEPARATOR, PR_GetEnv("CLASSPATH"));
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--[c++] classpath %s\n",classpath));
|
||||
char **props = new char*[2];
|
||||
props[0]="java.compiler=NONE";
|
||||
props[1]=0;
|
||||
vm_args.properties = props;
|
||||
vm_args.classpath = classpath;
|
||||
/* Create the Java VM */
|
||||
res = JNI_CreateJavaVM(&jvm, JNIENV &env, &vm_args);
|
||||
#else
|
||||
char classpath[1024];
|
||||
JavaVMInitArgs vm_args;
|
||||
JavaVMOption options[2];
|
||||
char * classpathEnv = PR_GetEnv("CLASSPATH");
|
||||
if (classpathEnv != NULL) {
|
||||
sprintf(classpath, "-Djava.class.path=%s",classpathEnv);
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--[c++] classpath %s\n",classpath));
|
||||
options[0].optionString = classpath;
|
||||
options[1].optionString=""; //-Djava.compiler=NONE";
|
||||
vm_args.options = options;
|
||||
vm_args.nOptions = 2;
|
||||
} else {
|
||||
vm_args.nOptions = 0;
|
||||
}
|
||||
|
||||
vm_args.version = 0x00010002;
|
||||
vm_args.ignoreUnrecognized = JNI_TRUE;
|
||||
/* Create the Java VM */
|
||||
res = JNI_CreateJavaVM(&jvm, (void**)&env, &vm_args);
|
||||
#endif
|
||||
|
||||
PR_LOG(l,PR_LOG_DEBUG,("--bcJavaGlobal::StartJVM jvm started res %d\n",res));
|
||||
}
|
||||
|
||||
|
||||
PRLogModuleInfo* bcJavaGlobal::GetLog() {
|
||||
if (log == NULL) {
|
||||
log = PR_NewLogModule(LOG_MODULE);
|
||||
}
|
||||
return log;
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -198,6 +198,7 @@ NS_IMETHODIMP bcJavaStubsAndProxies::GetOID(char *location, bcOID *oid) {
|
|||
//location[strlen(location)-5] = 0; //nb dirty hack. location is xyz.jar.info
|
||||
strcpy(location + strlen(location)-4,"comp");
|
||||
jstring jstr = env->NewStringUTF(location);
|
||||
strcpy(location + strlen(location)-4,"info");
|
||||
jobject object = env->CallStaticObjectMethod(componentLoader, loadComponentID, jstr);
|
||||
bcIStub *stub = new bcJavaStub(object);
|
||||
NS_WITH_SERVICE(bcIORBComponent,_orb,kORBComponent,&result);
|
||||
|
|
|
@ -1,60 +0,0 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1998 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
|
||||
DEPTH = ../../../..
|
||||
topsrcdir = ../../../..
|
||||
srcdir = .
|
||||
VPATH = .
|
||||
|
||||
include $(DEPTH)/config/autoconf.mk
|
||||
|
||||
MODULE = javaSample
|
||||
LIBRARY_NAME = javaSample
|
||||
IS_COMPONENT = 1
|
||||
XPIDL_MODULE = javaSample
|
||||
XPIDLSRCS = bcIJavaSample.idl
|
||||
CPPSRCS = bcJavaSample.cpp
|
||||
include $(topsrcdir)/config/rules.mk
|
||||
include ../config/rules.mk
|
||||
|
||||
DSO_LDOPTS += \
|
||||
$(XPCOM_LIBS) \
|
||||
$(NULL)
|
||||
|
||||
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
|
||||
$(JDKHOME)/bin/jar cvfm bcJavaSample.jar.comp manifest *.class
|
||||
.java.class:
|
||||
$(JDKHOME)/bin/javac -classpath .:../classes:$(DIST)/classes $<
|
||||
|
||||
bcIJavaSample.java : bcIJavaSample.idl
|
||||
|
||||
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info
|
||||
cp bcJavaSample.jar.comp bcJavaSample.jar.info $(DEPTH)/dist/bin/components/
|
||||
|
||||
clobber-java:
|
||||
rm -f *.class *.jar
|
||||
clobber:: clobber-java
|
||||
clobber_all:: clobber-java
|
||||
install:: install-component
|
||||
|
|
@ -137,28 +137,40 @@ NS_IMETHODIMP bcJavaSample::Test9(nsIID * *po) {
|
|||
|
||||
static bcIJavaSample * javaSample = NULL;
|
||||
|
||||
#if 1
|
||||
void thread_start( void *arg ) {
|
||||
printf("--thread_start currentThread=%p\n",PR_GetCurrentThread());
|
||||
printf("--thread_start currentThread=%d\n",PR_GetCurrentThread());
|
||||
nsresult r;
|
||||
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");
|
||||
}
|
||||
javaSample->Test1((int)PR_GetCurrentThread());
|
||||
printf("--thread_start after first invocation \n");
|
||||
javaSample->Test1((int)PR_GetCurrentThread());
|
||||
printf("--thread_start after second invocation \n");
|
||||
}
|
||||
#endif
|
||||
|
||||
#if 0
|
||||
void thread_start( void *arg ) {
|
||||
printf("--thread_start currentThread=%p\n",PR_GetCurrentThread());
|
||||
nsresult r;
|
||||
bcIJavaSample *t;
|
||||
javaSample->Test1((int)PR_GetCurrentThread());
|
||||
printf("--thread_start after first invocation \n");
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
void test() {
|
||||
printf("--BlackConnect test start\n");
|
||||
nsresult r;
|
||||
bcIJavaSample *test;
|
||||
bcIJavaSample *a = new bcJavaSample();
|
||||
#if 0
|
||||
r = nsComponentManager::CreateInstance("bcJavaSample",
|
||||
nsnull,
|
||||
NS_GET_IID(bcIJavaSample),
|
||||
|
@ -167,11 +179,22 @@ void test() {
|
|||
printf("--[debug] can not load bcJavaSample\n");
|
||||
return;
|
||||
}
|
||||
#endif
|
||||
//sigsend(P_PID, getpid(),SIGINT);
|
||||
//test->Test1(2000);
|
||||
|
||||
#if 1
|
||||
{
|
||||
for (int i = 0; i < 1; i++) {
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start,
|
||||
test,
|
||||
PR_PRIORITY_NORMAL,
|
||||
PR_LOCAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0);
|
||||
PR_JoinThread(thr);
|
||||
|
||||
for (int i = 0; i < 200; i++) {
|
||||
printf("\n--we are creating threads i=%d\n",i);
|
||||
PRThread *thr = PR_CreateThread( PR_USER_THREAD,
|
||||
thread_start,
|
||||
|
@ -180,12 +203,17 @@ void test() {
|
|||
PR_LOCAL_THREAD,
|
||||
PR_JOINABLE_THREAD,
|
||||
0);
|
||||
PR_JoinThread(thr);
|
||||
//PR_JoinThread(thr);
|
||||
}
|
||||
}
|
||||
return;
|
||||
#endif
|
||||
test->Test1(1000);
|
||||
//thread_start(test);
|
||||
if (javaSample == NULL) {
|
||||
return;
|
||||
}
|
||||
test = javaSample;
|
||||
test->Test1((int)PR_GetCurrentThread());
|
||||
return;
|
||||
bcIJavaSample *test1;
|
||||
if (NS_FAILED(r)) {
|
||||
printf("failed to get component. try to restart test\n");
|
||||
|
|
|
@ -1,65 +0,0 @@
|
|||
#!gmake
|
||||
#
|
||||
# The contents of this file are subject to the Netscape 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
|
||||
# the License at http://www.mozilla.org/NPL/
|
||||
#
|
||||
# Software distributed under the License is distributed on an "AS
|
||||
# IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
|
||||
# implied. See the License for the specific language governing
|
||||
# rights and limitations under the License.
|
||||
#
|
||||
# The Original Code is mozilla.org code.
|
||||
#
|
||||
# The Initial Developer of the Original Code is Netscape
|
||||
# Communications Corporation. Portions created by Netscape are
|
||||
# Copyright (C) 1999 Netscape Communications Corporation. All
|
||||
# Rights Reserved.
|
||||
#
|
||||
# Contributor(s):
|
||||
# Igor Kushnirskiy <idk@eng.sun.com>
|
||||
#
|
||||
|
||||
|
||||
DEPTH = ..\..\..\..
|
||||
topsrcdir = ..\..\..\..
|
||||
srcdir = .
|
||||
VPATH = .
|
||||
|
||||
MAKE_OBJ_TYPE=DLL
|
||||
MODULE=javaSample
|
||||
COMPONENT=1
|
||||
DLLNAME=$(MODULE)
|
||||
DLL=.\$(OBJDIR)\$(DLLNAME).dll
|
||||
|
||||
XPIDLSRCS = \
|
||||
.\bcIJavaSample.idl \
|
||||
$(NULL)
|
||||
|
||||
OBJS = .\$(OBJDIR)\bcJavaSample.obj
|
||||
LLIBS=$(LLIBS) $(LIBNSPR) $(DIST)\lib\xpcom.lib
|
||||
|
||||
include <$(DEPTH)\config\rules.mak>
|
||||
include ..\config\rules.mak
|
||||
|
||||
bcJavaSample.jar.comp: manifest bcIJavaSample.class bcJavaSample.class
|
||||
$(JDKHOME)\bin\jar cvfm bcJavaSample.jar.comp manifest *.class
|
||||
|
||||
|
||||
.java.class:
|
||||
$(JDKHOME)\bin\javac -classpath .;..\classes;$(DEPTH)\dist\classes $<
|
||||
|
||||
bcIJavaSample.java : bcIJavaSample.idl
|
||||
|
||||
install-component: bcJavaSample.jar.comp bcJavaSample.jar.info $(DLL)
|
||||
copy bcJavaSample.jar* $(DIST)\bin\components
|
||||
copy $(DLL) $(DIST)\bin\components
|
||||
|
||||
clobber-java:
|
||||
-del *.class *.jar.comp
|
||||
clobber:: clobber-java
|
||||
rm -f "$(DIST)\bin\components\$(DLLNAME).dll"
|
||||
rm -f "$(DIST)\bin\components\bcJavaSample.jar.*"
|
||||
clobber_all:: clobber-java
|
||||
install:: install-component
|
Загрузка…
Ссылка в новой задаче