[kaffe] JNI under ARM
Patrick McNeil
kalfalfa at gmail.com
Mon Sep 11 09:21:37 PDT 2006
This is the C code:
#include "stdafx.h"
#include <stdlib.h>
#include "../cphidget.h"
#include "phidget_jni.h"
#include <stdio.h>
jclass ph_exception_class;
jmethodID ph_exception_cons;
JavaVM *ph_vm = 0;
jint JNICALL
JNI_OnLoad(JavaVM *vm, void *reserved)
{
JNIEnv *env;
jint version = 0;
ph_vm = vm;
if ((*vm)->AttachCurrentThread(vm, (void **)&env, NULL))
{
WARN("Couldn't Attach Thread");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
abort();
}
if(!(version = (*env)->GetVersion(env)))
{
WARN("Couldn't get version");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
abort();
}
WARN("JNI Version: %08x",version);
if (!(ph_exception_class = (*env)->FindClass(env,
"com/phidgets/PhidgetException")))
{
WARN("Coulnd't find class \"com/phidgets/PhidgetException\"");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
abort();
//***** This is where is fails *****//
}
if (!(ph_exception_class = (jclass)(*env)->NewGlobalRef(env,
ph_exception_class)))
{
WARN("Couldn't create global ref ph_exception_class");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
abort();
}
if (!(ph_exception_cons = (*env)->GetMethodID(env,
ph_exception_class, "<init>",
"(ILjava/lang/String;)V")))
{
WARN("Coulnd't get Method ID for init in ph_exception_class");
(*env)->ExceptionDescribe(env);
(*env)->ExceptionClear(env);
abort();
}
return JNI_VERSION_1_2;
}
And this is the java code that invokes it:
public class Phidget
{
static {
System.loadLibrary("phidget21");
}
......
}
It never makes it out of the C function JNI_OnLoad, and either aborts
(explicitly), of seg faults before it gets to the abort call in the
findClass failure path. The exception is nullpointerexception if i
get a chance to read it. I've been working with gdb embedded on the
arm to try and resolve the issues but I'm just not very familiar with
the kaffe sources.
On a side note - where can I put my .jar that contains the libraries
needed by JNI in C to get them to load properly? I've had to place
phidgets.jar in the same directory as rt.jar just to get kaffe to see
it from C. Adding it to the CLASSPATH doean't seem to work (on ARM or
the debian PC).
Thanks for any advice
-Patrick
On 11-Sep-06, at 9:23 AM, Dalibor Topic wrote:
> Patrick McNeil wrote:
>
>> Hi,
>>
>> I have kaffe compiled and working under ARM9, but I'm running
>> into troubles with JNI. Incidentally, I'm having these same
>> problems with the default kaffe install on my Debian PC.
>> Basically, calling findclass in the c library causes a seg fault,
>> on a null pointer exception. This is code that works fine under
>> Sun JRE on the same box so... I just wondering if this is a known
>> issue, and if there is a fix?
>
> Hi Patrick,
>
> could you post a short example that shows the bug?
>
> cheers,
> dalibor topic
More information about the kaffe
mailing list