L7ColWinters
L7ColWinters

Reputation: 1362

thread spin off failures after invoking native call

ok so my java code:

private static native void setNativeFiles(mFileDescriptor[] r);
public void setFiles(mFileDescriptor[] files){
    setNativeFiles(files);
}

static class mFileDescriptor{
    private FileDescriptor fd;
    private long offset;
    private long size;

    public FileDescriptor getFd() {
        return fd;
    }
    public void setFd(FileDescriptor fd) {
        this.fd = fd;
    }
    public long getOffset() {
        return offset;
    }
    public void setOffset(long offset) {
        this.offset = offset;
    }
    public long getSize() {
        return size;
    }
    public void setSize(long size) {
        this.size = size;
    }
}

mFileDescriptor is an innerclass btw...

my c code:

void Java_com_ultrasound_JNIinterface_setNativeFiles(JNIEnv* env, jclass mclass, jobjectArray arr){
LOGI("Setting Native files");
jclass filedescriptor = env->FindClass("com/ultrasound/JNIinterface/mFileDescriptor");
int length = env->GetArrayLength(arr);
for(int index = 0; index < length; index++)
{
    //jclass mvclass = env->GetObjectClass(obj);
    jmethodID mid = env->GetMethodID(filedescriptor, "getFd", "()Ljava/io/FileDescriptor;");
    jobject temp = env->CallObjectMethod( arr, mid);
    int mvdata0 = reinterpret_cast<int>(&temp);

    mid = env->GetMethodID(filedescriptor, "getOffset", "()L");
    temp = env->CallObjectMethod( arr, mid);
    long mvdata1 = reinterpret_cast<long>(&temp);

    mid = env->GetMethodID(filedescriptor, "getSize", "()L");
    temp = env->CallObjectMethod( arr, mid);
    long mvdata2 = reinterpret_cast<long>(&temp);

    mFileDescriptor * fp;
    switch(index){
    case 0:
        fp = &ch0Descript;
        fp->fd = mvdata0;
        fp->offset = mvdata1;
        fp->size = mvdata2;
        break;
    case 1:
        fp = &ch1Descript;
        fp->fd = mvdata0;
        fp->offset = mvdata1;
        fp->size = mvdata2;
        break;
    case 2:
        fp = &ch2Descript;
        fp->fd = mvdata0;
        fp->offset = mvdata1;
        fp->size = mvdata2;
        break;
    default:
        LOGE("Native file indexing failed");
    }
}
LOGI("Native files set");

}

whenever I call setFiles I get this:

03-23 00:13:11.080: I/(9879): Setting Native files
03-23 00:13:11.080: I/(9879): Right before loop
03-23 00:13:11.080: I/(9879): IN FOR LOOP
03-23 00:13:11.501: W/ActivityManager(175): Activity pause timeout for HistoryRecord{406814b8 com.ultrasound/.UltraSoundJNIActivity}
03-23 00:13:12.241: W/dalvikvm(9879): threadid=10: spin on suspend #1 threadid=1 (pcf=0)
03-23 00:13:12.982: W/dalvikvm(9879): threadid=10: spin on suspend #2 threadid=1 (pcf=0)
03-23 00:13:12.982: I/dalvikvm(9879): "Thread-10" prio=5 tid=10 RUNNABLE
03-23 00:13:12.982: I/dalvikvm(9879):   | group="main" sCount=0 dsCount=0 obj=0x40651440 self=0x136c48
03-23 00:13:12.982: I/dalvikvm(9879):   | sysTid=9892 nice=0 sched=0/0 cgrp=default handle=1279040
03-23 00:13:12.982: I/dalvikvm(9879):   | schedstat=( 1495360 488283 24 )
03-23 00:13:12.982: I/dalvikvm(9879):   at com.ultrasound.JNIinterface$1.run(JNIinterface.java:~31)
03-23 00:13:12.982: I/dalvikvm(9879):   at java.lang.Thread.run(Thread.java:1019)
03-23 00:13:12.982: I/dalvikvm(9879): "main" prio=5 tid=1 RUNNABLE
03-23 00:13:12.982: I/dalvikvm(9879):   | group="main" sCount=1 dsCount=0 obj=0x40161190 self=0xce68
03-23 00:13:12.982: I/dalvikvm(9879):   | sysTid=9879 nice=0 sched=0/0 cgrp=default handle=-1345002432
03-23 00:13:12.982: I/dalvikvm(9879):   | schedstat=( 64514163 45135496 61 )
03-23 00:13:12.992: I/dalvikvm(9879):   at com.ultrasound.JNIinterface.setNativeFiles(Native Method)
03-23 00:13:12.992: I/dalvikvm(9879):   at com.ultrasound.JNIinterface.setFiles(JNIinterface.java:105)
03-23 00:13:12.992: I/dalvikvm(9879):   at com.ultrasound.UltraSoundJNIActivity.onCreate(UltraSoundJNIActivity.java:59)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1047)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1722)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1784)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.ActivityThread.access$1500(ActivityThread.java:123)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.ActivityThread$H.handleMessage(ActivityThread.java:939)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.os.Handler.dispatchMessage(Handler.java:99)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.os.Looper.loop(Looper.java:130)
03-23 00:13:12.992: I/dalvikvm(9879):   at android.app.ActivityThread.main(ActivityThread.java:3835)
03-23 00:13:12.992: I/dalvikvm(9879):   at java.lang.reflect.Method.invokeNative(Native Method)
03-23 00:13:12.992: I/dalvikvm(9879):   at java.lang.reflect.Method.invoke(Method.java:507)
03-23 00:13:12.992: I/dalvikvm(9879):   at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
03-23 00:13:12.992: I/dalvikvm(9879):   at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
03-23 00:13:12.992: I/dalvikvm(9879):   at dalvik.system.NativeStart.main(Native Method)
03-23 00:13:13.743: W/dalvikvm(9879): threadid=10: spin on suspend #3 threadid=1 (pcf=0)
03-23 00:13:13.743: I/dalvikvm(9879): "Thread-10" prio=5 tid=10 RUNNABLE

which eventually led to "Fatal spin-on-suspend: dumping threads"

I think its the getObjectMethod call since i put a log in right before the for loop and after the first data. Any help??

Upvotes: 0

Views: 1004

Answers (1)

beetoom
beetoom

Reputation: 489

Your code has several problems:

  1. com/ultrasound/JNIinterface/mFileDescriptor -> com/ultrasound/JNIinterface$mFileDescriptor

  2. Piece of code that casts address (!) of a jobject returned from getFd to long is just wrong

  3. ()L in getOffset and getSize methods must be ()J

  4. CallLongMethod must be used instead of CallObjectMethod

  5. temp is not needed, result of CallLongMethod should be assigned directly to mvdata variables (which must be of type jlong)

Upvotes: 1

Related Questions