Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed adding to JNI pinned array ref table (1024 entries)

I copied a multidimensional array from java, but i am having some problems to free the memory after using it.

what i did is:

jfieldID h_valID = (*env)->GetFieldID(env, h_cls, "val", "[[I");
jobjectArray h_val_obj = (*env)->GetObjectField(env, h, h_valID);
int h_val_local[xdim][ydim];
for(i=0; i<xdim; i++)
{
    h_val_one_dim = (jintArray) (*env)->GetObjectArrayElement(env, h_val_obj, i);
    h_val_elem = (*env)->GetIntArrayElements(env, h_val_one_dim, 0);
    for(j=0; j<ydim; j++)
    {
        h_val_local[i][j] = h_val_elem[j];
    }
    (*env)->ReleaseIntArrayElements(env, h_val_one_dim, h_val_elem, 0);
    (*env)->DeleteLocalRef(env, h_val_one_dim);
}
(*env)->DeleteLocalRef(env, h_val_obj);

I have 4 more arrays on that method, all on the parameters, i'm getting the pointer then releasing after using it.

int *x = (*env)->GetIntArrayElements(env,x_p,0);
int *y = (*env)->GetIntArrayElements(env,y_p,0);
int *v = (*env)->GetIntArrayElements(env,v_p,0);
int *w = (*env)->GetIntArrayElements(env,w_p,0);

...

(*env)->ReleaseIntArrayElements(env, x_p, x, 0);
(*env)->ReleaseIntArrayElements(env, y_p, y, 0);
(*env)->ReleaseIntArrayElements(env, v_p, v, 0);
(*env)->ReleaseIntArrayElements(env, w_p, w, 0);

For bigger files, i'm getting overflow on the reference table. What i'm forgetting to free or how do i fix this?

Log:

10-02 14:18:58.885: W/dalvikvm(23598): ReferenceTable overflow (max=1024)

10-02 14:18:58.885: W/dalvikvm(23598): Last 10 entries in JNI pinned array reference table:

10-02 14:18:58.885: W/dalvikvm(23598): 1014: 0x46109fe8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1015: 0x4610a008 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1016: 0x46109fa8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1017: 0x46109fc8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1018: 0x46109fe8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1019: 0x4610a008 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1020: 0x46109fa8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1021: 0x46109fc8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1022: 0x46109fe8 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): 1023: 0x4610a008 cls=[I (24 bytes)

10-02 14:18:58.885: W/dalvikvm(23598): JNI pinned array reference table summary (1024 entries):

10-02 14:18:58.885: W/dalvikvm(23598): 1024 of [I 24B (4 unique)

10-02 14:18:58.885: W/dalvikvm(23598): Memory held directly by tracked refs is 96 bytes

10-02 14:18:58.885: E/dalvikvm(23598): Failed adding to JNI pinned array ref table (1024 entries)

thx

like image 954
Deadlock Avatar asked Oct 02 '12 17:10

Deadlock


2 Answers

I found out what i was doing wrong, better, what i forgot to do. I have another return point in the code, but i forgot to release the arrays before returning in that case, i was only releasing it at the end of the function.

like image 132
Deadlock Avatar answered Sep 29 '22 06:09

Deadlock


Looks like a bug in the JNI implementation to me. One obvious workaround is to use a one-dimensional array instead. The array is not jagged on Java side, it seems, so it would be pretty straightforward to convert back and forth. The index of the element (i,j) in the 1D array would be i*xdim + j.

like image 23
Seva Alekseyev Avatar answered Sep 29 '22 06:09

Seva Alekseyev