Operating System - HP-UX
1825552 Members
2494 Online
109681 Solutions
New Discussion юеВ

JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

 
siba
Advisor

JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Hi,
I am using JDK 1.4 and Apache 1.3.33 On HPUX V2 ia64.
An external module in Apache Uses JNI to communicate with the JAR's.

The problem is that the JNI Code(written in C) works fine as an independent process but when integrated with Apache (in the child process Initialization), it doesnt return from JNI_CreateJavaVM resulting in kill of the apache process.

This results in too many processes getting spawned and killed by apache.
There are no log entry in the error log which can provide any clue.

Path for libjvm.so used to build the JNI: ~JAVAHOME/jre/lib/IA64W/hotspot

Any clue would be of great help.

thanks and regards
shiva
5 REPLIES 5
Arunvijai_4
Honored Contributor

Re: JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Hi Shiva,

Here is a guide to "Using Java 2 JNI on HP-UX"
http://www.hp.com/products1/unix/java/infolibrary/prog_guide/JNI_java2.html

Also, a similar problem reported in ITRC,
http://forums1.itrc.hp.com/service/forums/questionanswer.do?threadId=68956&admit=-682735245+1135241173844+28353475

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
siba
Advisor

Re: JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Hi Arun,

Thanks for the document. But i am afraid my problem still persists.(Though using the document creation of JVM in non-main thread was possible).

In case i am trying to create JVM using native code in the child process(in an multi process environment), the child process simply hangs. (dont have much hands on in java also)

any clues how to fix the same!!!

thanks and regards
shiva


Arunvijai_4
Honored Contributor

Re: JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Hi Shiva, You can use "tusc" to find out where it goes wrong. http://hpux.connect.org.uk/hppd/hpux/Sysadmin/tusc-7.8/

-Arun
"A ship in the harbor is safe, but that is not what ships are built for"
siba
Advisor

Re: JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Hi Arun,

One more observation. It doesnt work in the main process itself(sorry for not finding it earlier). there is no response once the call to create JVM is made.

I had a sample program which calls the native code to create the JVM. Find the portions of code below

SamProcess.c
===========================
int nRet=-1;
nRet=InitJNI();

libJNI.c
====================================================
typedef int (*JNI_CreateJavaVM_t)(JavaVM**, void**, void*);

JavaVM* g_JVM = NULL;
JNI_CreateJavaVM_t func = NULL;

shl_t libsym = shl_load("libjvm.so", BIND_IMMEDIATE|DYNAMIC_PATH, 0L);
if (libsym == 0) {

l_Result = VM_INIT_ERROR;
goto end;
}
else
printf("shl_loaded libjvm.so successfully!\n");


l_Result = shl_findsym(&libsym, "JNI_CreateJavaVM", TYPE_PROCEDURE, &func);
if (l_Result == 0)
printf( "Found symbol JNI_CreateJavaVM!\n");
else {
printf( "Unable to find symbol JNI_CreateJavaVM!\n");
l_Result = VM_INIT_ERROR;
goto end;
}

// load and init a java vm, return a JNI interface ptr in env
printf ("before CreateJavaVM\n");
l_Result = (*func)(&jvm, (void **)&l_JNIEnv, (void *)&l_JVMInitArgs);
if (l_Result != 0) {
printf ("JNI_CreateJavaVM failed.\n");
l_Result = VM_INIT_ERROR;
goto end;
}
else
printf("after CreateJavaVM \n");
=====================================================
No response is observed while executing this line...l_Result = (*func)(&jvm, (void **)&l_JNIEnv, (void *)&l_JVMInitArgs);

Following is the truss result
===============================
12241: open("/opt/java1.4/jre/lib/IA64W/hotspot/libm.so.1", O_RDONLY|0x800, 0) ERR#2 ENOENT
12241: open("/home/secure/libs/libm.so.1", O_RDONLY|0x800, 0) ERR#2 ENOENT
12241: open("/opt/java1.4/jre/lib/IA64W/libm.so.1", O_RDONLY|0x800, 0) ERR#2 ENOENT
12241: open("/usr/lib/hpux64/libm.so.1", O_RDONLY|0x800, 0) = 6
12241: fstat(6, 0x9fffffffffffe6c0) = 0
12241: read(6, "7fE L F 0202010101\0\0\0\0\0\0\0".., 64) = 64
12241: close(6) = 0
12241: brk(0x6000000000068000) = 0
12241: getpid() = 12241 (12240)
12241: getuid() = 105 (105)
12241: open("/var/spool/pwgr/status", O_RDONLY|0x800, 0) = 6
12241: mmap(NULL, 532, PROT_READ, MAP_SHARED|MAP_VARIABLE|MAP_FILE|MAP_ADDR32, 6, 0) = 0xc09d2000
12241: close(6) = 0
12241: socket(AF_UNIX, SOCK_DGRAM, 0) = 6
12241: getpid() = 12241 (12240)
12241: unlink("/var/spool/sockets/pwgr/client12241") ERR#2 ENOENT
12241: bind(6, 0x9fffffffef7cdfe0, 38) = 0
12241: fcntl(6, F_SETFD, 1) = 0
12241: time(NULL) = 1135679111
12241: poll(0x9fffffffffffdf08, 1, 0) = 1
12241: sendto(6, "\0\0\00 \0\0\001\0\0\0\0\0\0\001".., 48, 0, 0x9fffffffef7ce040, 0x19) = 48
12241: poll(0x9fffffffffffdf08, 1, 1000) = 1
12241: recvfrom(6, "\0\0\0C \0\0\0\0\0\0\0\0\0\0\03 ".., 2064, 0, 0x9fffffffffffdf10, 0x9fffffffffffdf00) = 67
12241: open("/var/tmp/hsperfdata_secure", O_RDONLY|0x800|0x200000, 035) = 7
12241: fstat(7, 0x9ffffffffffff100) = 0
12241: fcntl(7, F_SETFD, 1) = 0
12241: sysfs(GETFSIND, 0xc000000000170bf0, 0x9fffffffef7c6c40) = 9
12241: brk(0x600000000006c000) = 0
12241: lstat("/var/tmp/hsperfdata_secure", 0x9ffffffffffff100) = 0
12241: pathconf("/var/tmp/hsperfdata_secure", _PC_NAME_MAX) = 255
12241: getdents(7, 0x6000000000067650, 16384) = 96
12241: getpid() = 12241 (12240)
12241: kill(26712, SIG#0) ERR#3 ESRCH
12241: unlink("/var/tmp/hsperfdata_secure/26712") = 0
12241: getdents(7, 0x6000000000067650, 16384) = 0
12241: close(7) = 0
12241: mkdir("/var/tmp/hsperfdata_secure", 0755) ERR#17 EEXIST
12241: lstat("/var/tmp/hsperfdata_secure", 0x9ffffffffffff120) = 0
12241: open("/var/tmp/hsperfdata_secure/12241", O_RDWR|O_CREAT|O_TRUNC|0x800, 0600) = 7
12241: ftruncate(7, 16384) = 0
12241: mmap(NULL, 16384, PROT_READ|PROT_WRITE, MAP_SHARED, 7, 0) = 0xc00000000283c000
12241: close(7) = 0
12241: In user-mode [running]

Thanks and regards
shiva
siba
Advisor

Re: JNI call JNI_CreateJavaVM hangs when used in Apache Child Init

Passing -Xusealtsigs as an argument to JNI_CreateJavaVM call solves the issue.