From owner-freebsd-java Thu Feb 14 12:16: 4 2002 Delivered-To: freebsd-java@freebsd.org Received: from daedalus.cs.brandeis.edu (daedalus.cs.brandeis.edu [129.64.3.179]) by hub.freebsd.org (Postfix) with ESMTP id 9D1FE37B417 for ; Thu, 14 Feb 2002 12:16:00 -0800 (PST) Received: from localhost (meshko@localhost) by daedalus.cs.brandeis.edu (8.9.3/8.9.3) with ESMTP id PAA14450; Thu, 14 Feb 2002 15:15:56 -0500 Date: Thu, 14 Feb 2002 15:15:56 -0500 (EST) From: Mikhail Kruk To: Bill Huey Cc: Guerry Semones , Subject: Re: Need info for compiling JDK1.3.1 on FreeBSD with Native Threads In-Reply-To: <20020214194925.GA1818@gnuppy.monkey.org> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Sender: owner-freebsd-java@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org > Uh, you can't really call the normal IO functions, read()/write(), etc... > without it piping through the thread system in some way. If it's green threads, > then any function like that the coexistent program uses must go through > that layer of thread-managed wrapped functions and not the normal functions > in libc, etc... I'm not sure of the linking conventions off hand so I don't > know how to export those wrapped functions to a companion program. I don't know much, sorry. I know that you can create JVM, it will run in its own thread and it will be possible to attach your native C thread to it. Here is the tutorial http://developer.java.sun.com/developer/onlineTraining/Programming/JDCBook/jniref.html and here is an example of how it is done: #include #include JavaVM *jvm; void *native_thread(void *arg) { JNIEnv *env; jclass cls; jmethodID mid; jfieldID fid; jint result; jobject jobj; JavaVMAttachArgs args; jint asize; args.version= JNI_VERSION_1_2; args.name="user"; args.group=NULL; result=(*jvm)->AttachCurrentThread( jvm, (void **)&env, &args); cls = (*env)->FindClass(env,"ArrayHandler"); if( cls == NULL ) { printf("can't find class ArrayHandler\n"); exit (-1); } (*env)->ExceptionClear(env); mid=(*env)->GetMethodID(env, cls, "", "()V"); jobj=(*env)->NewObject(env, cls, mid); fid=(*env)->GetFieldID(env, cls, "arraySize", "I"); asize=(*env)->GetIntField(env, jobj, fid); printf("size of array is %d\n",asize); (*jvm)->DetachCurrentThread(jvm); } void main(int argc, char *argv[], char **envp) { JavaVMOption *options; JavaVMInitArgs vm_args; JNIEnv *env; jint result; pthread_t tid; int thr_id; int i; options = (void *)malloc(3 * sizeof(JavaVMOption)); options[0].optionString = "-Djava.class.path=."; options[1].optionString = "-Djava.compiler=NONE"; vm_args.version = JNI_VERSION_1_2; vm_args.options = options; vm_args.nOptions = 2; vm_args.ignoreUnrecognized = JNI_FALSE; result = JNI_CreateJavaVM(&jvm,(void **)&env, &vm_args); if(result == JNI_ERR ) { printf("Error invoking the JVM"); exit (-1); } thr_id=pthread_create(&tid, NULL, native_thread, NULL); // If you don't have join, sleep instead //sleep(1000); pthread_join(tid, NULL); (*jvm)->DestroyJavaVM(jvm); exit(0); } To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-java" in the body of the message