It is currently Thu, 25 Feb 2021 06:08:50 GMT

Author Message
 SIGSEGV gotten when JNI written in C calls contructor having a println on AIX platform
In JNI, I am creating an ArrayList and also an object
which is being added to the ArrayList.
When I place a println in the constructor of the object,
I get a SIGSEGV.

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

Please send a response directly to me.
==================Java code ====================
 import java.util.ArrayList;

 class TestJNIAL {


 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 +")" );

  // ...
===================JNI C language===================
 #include <jni.h>
 #include "TestJNIAL.h"
 #include <stdio.h>

   (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;

 # jni_example/Makefile

 # This definition makes JAVA_HOME refer to the JDK specified in your
 # You can change this to refer to a specific directory, such as

  TestJNIAL:   TestJNIAL.class #Running of "java
          java TestJNIAL "hello" 1

          ${JAVA_HOME}/bin/javah -jni TestJNIAL TestJNIALImp.o
  #       rm -f
          ld -o 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

          rm -f *.class TestJNIALImp.o TestJNIAL.h

 Tue, 12 Oct 2004 23:52:05 GMT   
 SIGSEGV gotten when JNI written in C calls contructor having a println on AIX platform
A soul from Sandia Labs
sent me an email stating that I was calling the constructor forclass
Three with a char * rather than a String.
This was the cause of the SIGSEGV

 Fri, 15 Oct 2004 11:06:26 GMT   
   [ 2 post ] 

Similar Threads

1. Q: C++ - contructor not called for object in shared lib

2. Need help on SIGSEGV error in a g++/JNI application

3. HELP: Having big trouble getting sendmail 8.8.4 going with AIX 4.1.4

4. AIX fortran calling character function written in C

5. Writing System Calls for AIX

6. static constructor from shared library not getting called on aix when loaded by Apache Web Server

7. call JNI function crash

8. jni GetMethodID error on getting File Class

9. [ (Javier H. Seen): **System call routines NONEXISTENT???**]

10. Using JNI under AIX

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software