java memory leak with native code -
i'm working on old java program includes native library fortran calls.
so, have java calls c via jni, , calls fortran.
in production have out of memory error :
native memory allocation (malloc) failed allocate 120000 bytes jfloat in c:\build_area\jdk6_37\hotspot\src\share\vm\prims\jni.cpp
i suspect it's memory leak.
i'm new in company, , work on linux have me working on windows :( under production using .so file because on solaris, , use dll on windows (logical.)
first, tried reproduce production problem. so, created unit test loads dll , calls java class calls native method many times. when did that, saw processexplorer.exe memory grew 2mb every 2 seconds. , have exception in production.
i'm happy reproduced problem, , problem came c or fortran code.
next, tried remove call fortran, , java called c (without fortran, test permitted me see if problem coming c or fortran.)
and result memory did't move! cool! didn't have problem malloc/free in c.
so, decided learn little fortran through code. :)
i learned in fortran can use allocate , deallocate keywords play memory. , code doesn't contains these keywords. :(
after of this, give me access on solaris launch junit test calls java->jni->c=>fortran , use .so instead of dll.
and surprise - memory didn't move!!! don't have problem under solaris or redhat.
i'm stuck because problem exists on production, can't reproduce clearly. :(
why see difference between dll , so? code (java/c/fortran) same because it's me compiles it.
how can investigate more?
i have try memory dump under windows reproduced problem, don't see anything.
is problem in jvm? or can problem in object passed c via jni?
thanks lot helping me problem.
info: i'm using windows 7 64bits
ps: i'm french, excuse english. try best each time. ;)
here header f c code:
#ifndef unix __mingw_import void modlin_om(float pmt[], float abaque[][], float don[][], float cond[], float res[][], int flag[]) ; #else extern void modlin_om_(float * pmt, float * abaque, float * don, float * cond, float * res, int * flag) ; #endif
and after method:
jniexport jint jnicall java_trtmodlin_modlin_1om (jnienv * env, jobject obj, jfloatarray pmtpar, jobjectarray abaquepar, jobjectarray donpar, jfloatarray condpar, jobjectarray respar, jintarray flagpar) {
some code, , method call fortran
#ifndef unix modlin_om(pmt, abaque, don, cond, res, & iflag) ; #else modlin_om_(pmt, abaque, don, cond, res, & iflag) ; #endif
as said before, test call c removing these lines , memory did't grow :( test removing line free(somevar) , memory grows because free not done in case. that's why conclude c ok free/malloc.
analyse memory trouble complex. experience there 2 ways:
1) try reproduce. supposes have source code , idea of root cause. 2) observe production crashes: frequency, correlation other events, etc.
this can determine if memory leak or not (it high consumtion under business load...)
in particular case, notice following points:
the behavior of code can different on different os. it's rare java code (jvm bug). frequent native code (for example, forget close zip causes memory leak on linux not on windows...)
in c header (*.h): abaque, don , res 'float * *' on windows , 'float *' on unix. bug in c headers, or means c implementations not expect same argument types depending on operating system (that strange me...)
in second case, fact compile c headers on windows (that not target) explain don't generate correct jni stubs (typical cross-compilation issue)... here can make many assumptions, simple or complex...
good luck!
Comments
Post a Comment