Segmentation Fault Between Java and C
0 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   Juan_Atan
Posted On:   Monday, June 15, 2009 09:39 AM

Before I do anything else I'll describe what I'm doing. My project has a back end written in a proprietary language, which only offers interoperability with ANSI C. So we built an SDK (in C) which interfaces with the back end just fine. The issue now, is that I need to provide interoperability with Java. The obvious solution to to use the JNI. Wasn't a big problem, the documentation was very complete, but I've now run into an issue. I did all of my development in a win32 environment, and my JNI bindings work under all test cases in said environment. I was recently asked to provide an OS X build of my JNI bindings. Here's where the problem manifests itself. My code looks roughly like this: JNIEXPORT void JNICALL    More>>

Before I do anything else I'll describe what I'm doing. My project has a back end written in a proprietary language, which only offers interoperability with ANSI C. So we built an SDK (in C) which interfaces with the back end just fine. The issue now, is that I need to provide interoperability with Java.

The obvious solution to to use the JNI. Wasn't a big problem, the documentation was very complete, but I've now run into an issue. I did all of my development in a win32 environment, and my JNI bindings work under all test cases in said environment. I was recently asked to provide an OS X build of my JNI bindings. Here's where the problem manifests itself.

My code looks roughly like this:

			
JNIEXPORT void JNICALL Java_JavaSDK_Foo(JNIEnv *env, jobject thisJ, jint numStringsJ) {
int numStirngs;
jobjectArray oarr;
jclass objCls;

// convert jint to int
numStrings = (int)numStringsJ;
.
.
.
// A reference to a java object
objCls = (*env)->FindClass(env, "Ljava/lang/Object;");
.
.
.
// Array of JNI objects
oarr = (*env)->NewObjectArray(env, numStrings, objCls, NULL);
// If array construction fails then return
if (oarr == NULL) {
debug("Array construction failure, Returning: void
");
return; /* out of memory error thrown */
}
.
.
.
}


When making a call to NewObjectArray() it returns a null pointer, which as documented means that it experienced an out of memory error. The issue is that (A) I'm using extremely small test cases right now (numStrings is equal to 24), there is no way it could be running out of memory (B) I do not get this behavior when testing in a win32 environment, only in an OS X environment. What is really strange is that after NewObjectArray() returns a null pointer, my conditional branch is taken and my debugging message is printed, the program seg faults. Which means that I'm getting the seg fault after returning from my native code, before control is passed back to my java code.

Does anyone have any idea what could be happening? Are there any documented issues with the JNI when running on OS X?

Any and all help is very much appreciated.    <<Less
About | Sitemap | Contact