JNI on AIX.

Hello Guys,

We have received some c code from our client their encryption/decryption algorithams from our client which we have to integrate in our java code. I have written a java class with some native methods. And a c program which is called from java using JNI and this c program calls the functions from the code provided by our client. Taking togather my own c program and the progs provided by the client i create a dll file on windows and i can call all the functions properly. So no problems till this point. Now we have to deploy the project on AIX, I take the same code to AIX and now i am creating a .so file insted of dll, compilation and library creation is fine( I am using C for AIX Compiler, Version 5), i am creating the library with the command

cc -g -G -I/usr/WebSphere/AppServer/java/include/ *.c -o libVMD.so

invoking some of the native methods in my java class from a test program also works fine but with a couple of other functions the JVM is crashing

This is the output that i get on my command window

SIGILL 4 (*) illegal instruction (not reset when caught)

si_signo [4]: SIGILL: (*) illegal instruction (not reset when caught)

si_errno [0]: Error 0

si_code [30]: ILL_ILLOPC [addr: 0x0]

stackpointer=2ff21ca8

Writing java dump to /usr/dev/cookie/src/javacore22492.1004125181.txt... OK

Illegal instruction(coredump)

and here is the core dump.

Fri Oct 26 15:39:41 2001

SIGILL received at d4d4d1d8 in /usr/lib/libVMD.so. Processing terminated.

J2RE 1.3.0 IBM build ca130-20010615a

/usr/WebSphere/AppServer/java/bin/java com.nubase.vmd.core.util.VmdHelper em manon4

System Properties

--

Java Home Dir:/usr/WebSphere/AppServer/java/jre

Java DLL Dir:/usr/WebSphere/AppServer/java/jre/bin

Sys Classpath:/usr/WebSphere/AppServer/java/jre/lib/rt.jar:/usr/WebSphere/AppServer/java/jre/lib/i18n.jar:/usr/WebSphere/AppServer/java/jre/classes

User Args:

-Djava.class.path=:/opt/db2inst1/sqllib/java/sqlj.zip:/opt/db2inst1/sqllib/java/db2java.zip:/opt/db2inst1/sqllib/java/runtime.zip:.

Current Thread Details

-

"main" (TID:0x300987e0, sys_thread_t:0x3000d7d8, state:R, native ID:0x1) prio=5

at com.nubase.vmd.core.util.VmdHelper.encryptPassword(Native Method)

at com.nubase.vmd.core.util.VmdHelper.main(VmdHelper.java:172)

-- Native Stack --

VmdEncrypteMotDePasse

Java_com_nubase_vmd_core_util_VmdHelper_encryptPassword

mmisInvoke_O_OHelper

_OHelper0 ?!?|^H^B?^C?^E^H`?

-

Operating Environment

Host: VMD:192.168.0.253

OS Level: AIX 4.3.3.0

Processors -

Architecture: POWER_PC (impl: POWER_604, ver: PV_604)

How Many: 1

Enabled: 1

User Limits (in bytes except for NOFILE and NPROC) -

RLIMIT_FSIZE: 1073741312

RLIMIT_DATA: 2147483645

RLIMIT_STACK: 33554432

RLIMIT_CORE: 1073741312

RLIMIT_NOFILE: 2000

NPROC(max): 262144

Page Space (in blocks) -

/dev/hd6: size=524288, free=523755

Application Environment

--

Signal Handlers -

SIGQUIT: intrDispatchMD (libhpi.a)

SIGILL: intrDispatchMD (libhpi.a)

SIGTRAP: unknown handler (libjitc.a)

SIGABRT: intrDispatchMD (libhpi.a)

SIGEMT: intrDispatchMD (libhpi.a)

SIGFPE: intrDispatchMD (libhpi.a)

SIGBUS: intrDispatchMD (libhpi.a)

SIGSEGV: intrDispatchMD (libhpi.a)

SIGSYS: intrDispatchMD (libhpi.a)

SIGPIPE: ignored

SIGUSR2: unknown handler (libjitc.a)

Environment Variables -

_=/usr/WebSphere/AppServer/java/bin/java

LANG=en_US

LOGIN=root

IMQCONFIGCL=/etc/IMNSearch/dbcshelp

PATH=/usr/bin:/etc:/usr/sbin:/usr/ucb:/opt/root/bin:/usr/bin/X11:/sbin:.:/opt/db2inst1/sqllib/bin:/opt/db2inst1/sqllib/adm:/opt/db2inst1/sqllib/misc

LC__FASTMSG=true

IMQCONFIGSRV=/etc/IMNSearch

CGI_DIRECTORY=/var/docsearch/cgi-bin

CLASSPATH=:/opt/db2inst1/sqllib/java/sqlj.zip:/opt/db2inst1/sqllib/java/db2java.zip:/opt/db2inst1/sqllib/java/runtime.zip:.

LOGNAME=root

MAIL=/usr/spool/mail/root

LOCPATH=/usr/lib/nls/loc

DOCUMENT_SERVER_MACHINE_NAME=localhost

USER=root

AUTHSTATE=compat

SHELL=/bin/ksh

ODMDIR=/etc/objrepos

DOCUMENT_SERVER_PORT=49213

HOME=/opt/root

DB2INSTANCE=db2inst1

LD_LIBRARY_PATH=/usr/lib

TERM=vt100

MAILMSG=[YOU HAVE NEW MAIL]

PWD=/usr/dev/cookie/src

DOCUMENT_DIRECTORY=/usr/docsearch/html

TZ=EST5EDT

A__z=! LOGNAME

XFILESEARCHPATH=/usr/WebSphere/AppServer/java/jre/lib/locale/%L/%T/%N%S:/usr/WebSphere/AppServer/java/jre/lib/locale/%L/%T/%N%S:

MALLOCMULTIHEAP=1

AIXTHREAD_SCOPE=S

AIXTHREAD_MUTEX_DEBUG=OFF

AIXTHREAD_RWLOCK_DEBUG=OFF

AIXTHREAD_COND_DEBUG=OFF

LIBPATH=/usr/WebSphere/AppServer/java/jre/bin:/usr/WebSphere/AppServer/java/jre/bin/classic:/opt/db2inst1/sqllib/lib

NLSPATH=/usr/lib/nls/msg/%L/%N:/usr/lib/nls/msg/%L/%N.cat

IBM_JAVA_COMMAND_LINE=/usr/WebSphere/AppServer/java/bin/java com.nubase.vmd.core.util.VmdHelper em manon4

JAVA_MAIN_VM=805392576

Loaded Libraries (sizes in bytes)

/usr/lib/libVMD.so

filesize: 111802

text start: d4d48000

text size: aa17

data start: 34d6e928

data size: 20f8

/usr/WebSphere/AppServer/java/jre/bin/libjitc.a

filesize: 2262001

text start: d3785000

text size: 1c53f3

data start: 34452570

data size: b020

/usr/lib/libiconv.a

filesize: 377832

text start: d0034100

text size: 13f3a

data start: 34404da0

data size: a574

/usr/lib/libi18n.a

filesize: 122601

text start: d002c100

text size: 78b4

data start: 344104b0

data size: 1124

/usr/lib/nls/loc/en_US

filesize: 14340

text start: d0026000

text size: 2d71

data start: d0029130

data size: 2324

/usr/WebSphere/AppServer/java/jre/bin/libzip.a

filesize: 106943

text start: d3771000

text size: 133ab

data start: 34291c70

data size: 1fdc

/usr/WebSphere/AppServer/java/jre/bin/libhpi.a

filesize: 111461

text start: d3761000

text size: fe2b

data start: 3003f340

data size: d20

/usr/WebSphere/AppServer/java/jre/bin/libxhpi.a

filesize: 10041

text start: d375f000

text size: 134a

data start: 3003ed50

data size: 1c8

/usr/WebSphere/AppServer/java/jre/bin/libjava.a

filesize: 398297

text start: d371f000

text size: 3fbf5

data start: 30036b18

data size: 6d18

/usr/WebSphere/AppServer/java/jre/bin/classic/libjvm.a

filesize: 1721315

text start: d35ed000

text size: 131aaf

data start: 300111d8

data size: 24e08

/usr/lib/libbsd.a

filesize: 62186

text start: d00d24e0

text size: 7deb

data start: f010ab28

data size: 1460

/usr/lib/libC.a

filesize: 2610937

text start: d080c360

text size: 5982

data start: f01d4760

data size: a08

/usr/lib/libC.a

filesize: 2610937

text start: d0798660

text size: 5fca

data start: f01d3460

data size: 83c

/usr/lib/libC.a

filesize: 2610937

text start: d079f7c0

text size: 6c174

data start: f01c0dc0

data size: 113c4

/usr/lib/libC.a

filesize: 2610937

text start: d078c070

text size: b756

data start: f01bf31c

data size: 1c

/usr/lib/libpthreads.a

filesize: 713478

text start: d0001000

text size: 22b4

data start: f0082000

data size: 41004

/usr/lib/libpthreads.a

filesize: 713478

text start: d0004000

text size: 202a1

data start: f00c4000

data size: 400c

/usr/lib/libC.a

filesize: 2610937

text start: d0757100

text size: 33653

data start: f01bad00

data size: 411c

/usr/lib/libcrypt.a

filesize: 11167

text start: d00250f8

text size: 87a

data start: f0081528

data size: 13c

/usr/lib/libc.a

filesize: 6409580

text start: d015f720

text size: 1c26a3

data start: f0000a20

data size: 7f908

"Finalizer" (TID:0x30098708, sys_thread_t:0x342f6d38, state:CW, native ID:0x304) prio=8

at java.lang.Object.wait(Native Method)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:114)

at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:129)

at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:168)

-- Native Stack --

unavailable - iar 3008ffe8 not in text area

-

"Reference Handler" (TID:0x30098750, sys_thread_t:0x342f0c58, state:CW, native ID:0x203) prio=10

at java.lang.Object.wait(Native Method)

at java.lang.Object.wait(Object.java:421)

at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:116)

-- Native Stack --

unavailable - iar 0 not in text area

-

"Signal dispatcher" (TID:0x30098798, sys_thread_t:0x342ebf98, state:CW, native ID:0x102) prio=5

-- Native Stack --

unavailable - iar 0 not in text area

-

"main" (TID:0x300987e0, sys_thread_t:0x3000d7d8, state:R, native ID:0x1) prio=5

at com.nubase.vmd.core.util.VmdHelper.encryptPassword(Native Method)

at com.nubase.vmd.core.util.VmdHelper.main(VmdHelper.java:172)

-- Native Stack --

VmdEncrypteMotDePasse

Java_com_nubase_vmd_core_util_VmdHelper_encryptPassword

mmisInvoke_O_OHelper

_OHelper0 ?!?|^H^B?^C?^E^H`?

-

Monitor pool info:

Initial monitor count: 32

Minimum number of free monitors before expansion: 5

Pool will next be expanded by: 16

Current total number of monitors: 32

Current number of free monitors: 28

Monitor Pool Dump (inflated object-monitors):

sys_mon_t:0x30009de8 infl_mon_t: 0x300099f8:

java.lang.ref.Reference$Lock@3009DB38/3009DB40: <unowned>

Waiting to be notified:

"Reference Handler" (0x342f0c58)

sys_mon_t:0x30009ee8 infl_mon_t: 0x30009a38:

java.lang.ref.ReferenceQueue$Lock@3009D748/3009D750: <unowned>

Waiting to be notified:

"Finalizer" (0x342f6d38)

JVM System Monitor Dump (registered monitors):

Integer lock access-lock: <unowned>

ACS Heap lock: <unowned>

System Heap lock: <unowned>

Sleep lock: <unowned>

Method trace lock: <unowned>

UTF8 Cache lock: <unowned>

Heap lock: <unowned>

Rewrite Code lock: <unowned>

Monitor Cache lock: owner "main" (0x3000d7d8) 1 entry

JNI Pinning lock: <unowned>

JNI Global Reference lock: <unowned>

Classloader lock: <unowned>

Linking class lock: <unowned>

Binclass lock: <unowned>

Monitor Registry lock: owner "main" (0x3000d7d8) 1 entry

Thread queue lock: owner "main" (0x3000d7d8) 1 entry

Thread identifiers (as used in flat monitors):

ident 5 "Finalizer" (0x342f6d38) ee 0x342f6b6c

ident 4 "Reference Handler" (0x342f0c58) ee 0x342f0a8c

ident 3 "Signal dispatcher" (0x342ebf98) ee 0x342ebdcc

ident 2 "main" (0x3000d7d8) ee 0x3000d60c

Java Object Monitor Dump (flat & inflated object-monitors):

java.lang.ref.ReferenceQueue$Lock@3009D748/3009D750

locknflags 80000400 Monitor inflated infl_mon 0x30009a38

java.lang.ref.Reference$Lock@3009DB38/3009DB40

locknflags 80000200 Monitor inflated infl_mon 0x300099f8

what i am doing wrong here? or if there are any other issues while using JNI on AIX.

All the help appreciated.

Thanks

[11989 byte] By [mali_jr] at [2007-9-26 10:48:37]
# 1

You have to specify some special switches on the cc command so you create shared libraries on AIX. We use JNI to communicate from a servlet with a formerly host application.

First you should call the Compiler and the Linker in to different steps of compilation. Then the Linker needs some informations from command line and some files to make your functions in the library accessible:

cc -c -g -G -I/usr/WebSphere/AppServer/java/include/ *.c -o libVMD.o

ld -o libVMD.so libVMD.o $(LIBALL) -bnoentry -bM:SRE -bE:libVMD.exp -blibpath:/usr/lib/threads:/usr/lib:/lib -G

where the cc command generates the libVMD.o file and the file libVMD.exp is a text file containing the names of all functions visible outside the library and $(LIBALL) should be a list of all libraries used within your functions. The commands are taken from a Makefile so be carefull in using the parameters right!

Hope this will help you !

WHolzner at 2007-7-1 23:26:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 2

Hi,

I am also facing a similar kind of problem on AIX as described in your mail.In my case, my Java application with JNI calls to C++ libraries is working fine on Solaris and HP. But on AIX, while loading the C++ libraries JVM is crashing. I have played around with MAXDATA and Xmx variables to make sure there is enough Java and Native heap available to the application. Can you tell me how did you solve your problem that might give me some clue.

Thanking in advance.

tmohanta at 2007-7-1 23:26:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 3

Hi,

I am also facing a similar kind of problem on AIX as described in your mail.In my case, my Java application with JNI calls to C++ libraries is working fine on Solaris and HP. But on AIX, while loading the C++ libraries JVM is crashing. I have played around with MAXDATA and Xmx variables to make sure there is enough Java and Native heap available to the application. Can you tell me how did you solve your problem that might give me some clue.

Thanking in advance.

tmohanta at 2007-7-1 23:26:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 4
Was anybody able to fix this problem? I always get a stackpointer error when I try to use jni in aixThanks
vibhavg at 2007-7-1 23:26:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...
# 5

Hi,

I am trying to build a native JNI library on AIX. Following is the script that I am using:

xlC_r -g -G *.cpp -I../include -I/usr/java131/include -qexpfile=JavaLMSDK.exp

xlC_r *.o -bE:JavaLMSDK.exp -bM:SRE -bnoentry -o ../lib/libJavaLMApi.a -L../lib -L/usr/java131/jre/bin/classic -ljvm -lACE -lglobalcS -lpmdec -lpminfapi -lpmser -ltls4dshr -lpmasrt -lpmi18n -lpmICE -lpmlmapi -lpmuti -lC_r -lpthread

The library gets built properly. But when I try to load the library from a C program using dlopen, it fails daying "Exec Format Error". I tried building the HelloWorld jni library using the same flags and its working fine. Any idea what am I doing wrong. Any pointers will be very helpful. I am using jdk 1.3.1 provided by IBM on AIX 4.3

Thanks,

Rashmi

Rashmi_Agrawal at 2007-7-1 23:26:01 > top of Java-index,Java HotSpot Virtual Machine,Specifications...