bug-glibc
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

popen and JNI


From: Markus Troebensberger FPR1
Subject: popen and JNI
Date: Mon, 17 Dec 2001 09:25:35 +0100

Hi

System is a Pentium III  800 MHz with SUSE Linux 7.2 Kernel 2.4.4
glibc is 2.2.2-38
JDK is 1.1.8v1-9

If i open a JavaVM (using JNI) in a c-program after i used popen, then the program will freeze
while opening the JavaVM.

On the other side:
If i use popen after i created a JavaVM, then the program will freeze during popen.
 
 

-- 
#  Markus Troebensberger           phone: +49-7191-930-1457
##  Tesat-Spacecom GmbH & Co.KG    fax:   +49-7191-930-21457
###  TE/FPR1
####  Gerberstr. 49
#####  D-71522 Backnang
######  Germany             mailto:address@hidden
 

Attachment: a
Description: Binary data

#include <jni.h>
#include <stdlib.h>
#include <stdio.h>

int CheckJ(JNIEnv * env, const struct JNINativeInterface_ * jni)
{
  int retVal = 0;

  jthrowable e = NULL;
  
  e = jni->ExceptionOccurred(env);
  if(NULL != e)
    {  
      jni->ExceptionDescribe(env);
      jni->ExceptionClear(env);
      retVal = -1;
    }
  
  return(retVal);
}

int main(int argc, char * argv[])
{
  int retVal = 0;

  FILE * fp;
  JDK1_1InitArgs vm_args;
  JavaVM * jvm = NULL;
  JNIEnv * env = NULL;
  const struct JNINativeInterface_ * jni = NULL;
  const struct JNIInvokeInterface_ * vmi = NULL;
  jclass cls = NULL;
  jmethodID mid = NULL;
  jstring jhelloQ = NULL;
  jstring jhelloA = NULL;
  const char * hello = NULL;

  /* try this ... */
  /*   fp = popen("echo hallo", "r"); */
  /*   pclose(fp); */

  if(0 == retVal)
    {
      printf("JNI_GetDefaultJavaVMInitArgs\n");
      retVal = JNI_GetDefaultJavaVMInitArgs(&vm_args);
    }

  if(0 == retVal)
    {
      printf("JNI_CreateJavaVM\n");
      vm_args.classpath = 
        "/usr/lib/java/lib/classes.zip"
        ":/opt/java/lib/classes.zip"
        ":.";
      retVal = JNI_CreateJavaVM(&jvm, &env, &vm_args);
    }
  
  if(0 == retVal)
    {
      printf("FindClass\n");
      jni = *env;
      vmi = *jvm;
      cls = jni->FindClass(env, "hello");
      retVal = CheckJ(env, jni);
    }

  if(0 == retVal)
    {
      printf("GetStaticMethodID\n");
      mid = jni->GetStaticMethodID(env, cls, "Hello",
                                   "(Ljava/lang/String;)Ljava/lang/String;");
      retVal = CheckJ(env, jni);
    }

  if(0 == retVal)
    {
      printf("CallStaticObjectMethod\n");
      jhelloQ = jni->NewStringUTF(env, "Hello Java");
      jhelloA = jni->CallStaticObjectMethod(env, cls, mid, jhelloQ);
      retVal = CheckJ(env, jni);
    }

  if(0 == retVal)
    {
      printf("GetStringUTFChars\n");
      hello = jni->GetStringUTFChars(env, jhelloA, NULL);
      printf("   JAVA says: '%s'\n", hello);
    }  

  /* ... or this */
  /*   fp = popen("echo hallo", "r"); */
  /*   pclose(fp); */

  return(retVal);  
}

gcc -I /usr/lib/java/include -I /usr/lib/java/include/linux  a.c  -L 
/usr/lib/java/lib/i686/green_threads -ljava -o a

Attachment: hello.class
Description: Binary data


public class hello
{
    public static String Hello(String helloQ)
    {
        System.out.println(helloQ);
        return("Hello, here is Java speaking");
    }
    
    public static void main(String args[])
    {
        String xmlString = "";
        
        try
            {
                xmlString = Hello(args[0]);
                System.out.println(xmlString);
                System.exit(0);
            }
        catch(Throwable e)  
            {
                System.err.println(e);
                System.exit(1);
            }
    }
}


reply via email to

[Prev in Thread] Current Thread [Next in Thread]