My platform is AIX.
Could the problem be related to ld options?
What follows is
1. the Java code. Removing the comment on the line marked with
//SIGSEGV causes the SIGSEGV
2. JNI written in Clanguage
3. Makefile
The platform is
njros1un648: /java/TestJNIAL> uname -a
AIX njros1un648 3 4 000101898100
njros1un648: /java/TestJNIAL> oslevel
4.3.2.0
Please send a response directly to me.
==================Java code ====================
import java.util.ArrayList;
class TestJNIAL {
static{
System.loadLibrary("retAL");
}
public native ArrayList func(String w, int n);
public static void main(String[] args)
{
String word = args[0];
int num = Integer.parseInt(args[1]);
System.out.println("word=" + word);
System.out.println("num=" + num);
TestJNIAL test = new TestJNIAL();
ArrayList al = test.func(word, num);
System.out.println("al.size()=" + al.size() );
for(int i=0; i<al.size(); i++){
Three aThree = (Three)al.get(i);
//System.out.println(i + ": " + aThree.getW() + ","
+ aThree.getN1() + "," + aThree.getN2() );
}
}
}
class Three{
private String w;
private int n1;
private int n2;
Three(String ww,int nn1,int nn2)
{
w = ww;
n1 = nn1;
n2 = nn2;
//System.out.println("Three(" + w + "," + n1 + "," + n2 +")" );
//SIGSEGV
}
// ...
}
===================JNI C language===================
#include <jni.h>
#include "TestJNIAL.h"
#include <stdio.h>
JNIEXPORT jobject JNICALL
Java_TestJNIAL_func
(JNIEnv *env, jobject obj, jstring jsW, jint jsN1)
{
const char *w = (*env)->GetStringUTFChars(env, jsW, 0);
jclass alClz;
jmethodID midALCon;
jobject newobjAL;
jmethodID midALAdd;
jclass threeClz;
jmethodID midThreeCon;
jobject newobjThree;
jboolean boolRetVal;
int i;
int N1 = jsN1;
/* allocate ArrayList */
alClz = (*env)->FindClass(env, "java/util/ArrayList");
fprintf(stderr, "After FindClass alClz=%p\n", alClz);
midALCon = (*env)->GetMethodID(env, alClz, "<init>",
"()V" );
fprintf(stderr, "After GetMethodID midALCon=%p\n", midALCon);
newobjAL = (*env)->NewObject(env, alClz,
midALCon );
/* Get method for ArrayList Add(Object) */
midALAdd = (*env)->GetMethodID(env, alClz, "add",
"(Ljava/lang/Object;)Z" );
fprintf(stderr, "After GetMethodID midALAdd=%p\n", midALAdd);
/* Allocate one Three class object */
threeClz = (*env)->FindClass(env, "Three");
fprintf(stderr, "After FindClass threeClz=%p\n", threeClz);
midThreeCon = (*env)->GetMethodID(env, threeClz, "<init>",
"(Ljava/lang/String;II)V" );
fprintf(stderr, "After GetMethodID midThreeCon=%p\n", midThreeCon);
for(i=0; i<10; i++){
newobjThree = (*env)->NewObject(env, threeClz,
midThreeCon, w, N1, 5 );
fprintf(stderr, "After NewOject newobjThree=%p\n", newobjThree);
/* Add Three class object to ArrayList */
boolRetVal = (*env)->CallBooleanMethod(env, newobjAL,
midALAdd, newobjThree);
}
return newobjAL;
}
===========================Makefile======================
# jni_example/Makefile
# This definition makes JAVA_HOME refer to the JDK specified in your
PATH.
# You can change this to refer to a specific directory, such as
/usr/lpp/J1.1.1
JAVA_HOME=/usr/java130
LIBPATH=$LIBPATH:.
CLASSPATH=$CLASSPATH:$JAVA_HOME:.
TestJNIAL: TestJNIAL.class libretAL.so #Running of "java
TestJNIAL"
java TestJNIAL "hello" 1
TestJNIAL.class: TestJNIAL.java
${JAVA_HOME}/bin/javac TestJNIAL.java
${JAVA_HOME}/bin/javah -jni TestJNIAL
libretAL.so: TestJNIALImp.o
# rm -f TestJNIALImp.so
ld -o libretAL.so TestJNIALImp.o -bnoentry -bM:SRE
-bE:TestJNIALImp.exp \
-blibpath:/lib:/usr/lib -lc_r \
-L${JAVA_HOME}/jre/bin -ljava
# -L${JAVA_HOME}/lib/aix/native_threads -ljava
TestJNIALImp.o: TestJNIALImp.c
# -D_AIX43 to eliminate duplicate typdef-s
xlc_r -D_AIX43 -c -I. -I${JAVA_HOME}/include
-I${JAVA_HOME}/include/aix \
-I${HOME}/rso/include \
-o TestJNIALImp.o TestJNIALImp.c
clean:
rm -f *.class TestJNIALImp.o TestJNIAL.h libretAL.so
Jeffrey...@prudential.com (Jeff Gitlin) wrote in message news:<611aeceb.02042...@posting.google.com>...