java - Debugging JVM memory leak -
i have java application uses native library of functionality. uses jni control native library , receives asynchronous callback library. can think of java frontend , native backend communicate each other.
i facing memory leak. shortly after start application, memory steadily increases. tried cause leak.
first, tried replacing java frontend simple c++ text interface. way, application doesn't use java in way - , leaks stopped. problem must in java frontend.
so fired jvisualvm see if heap increases - , turned out doesn't. java heap size constant. launched program xmx32m, memory kept increasing past 100m without outofmemoryerror
s. in fact, jvisualvm showed java heap @ 7m.
so dug deeper program windbg. analyzed heap patterns !heap -s
command , got this:
heaps on freshly run program:
0:059> !heap -s lfh key : 0x382288b9 termination on corruption : enabled heap flags reserv commit virt free list ucr virt lock fast (k) (k) (k) (k) length blocks cont. heap ----------------------------------------------------------------------------- 00330000 00000002 2048 1704 2048 22 71 2 0 0 lfh 005b0000 00001002 1088 212 1088 68 3 2 0 0 lfh 00aa0000 00001002 1088 108 1088 15 7 2 0 0 lfh 004f0000 00001002 15424 12876 15424 1372 89 9 0 1 lfh ... 0:059> !heap -stat -h 004f0000 heap @ 004f0000 group-by: totsize max-display: 20 size #blocks total ( %) (percent of total busy bytes) 2b110 20 - 562200 (60.36) 98 166e - d5150 (9.33) 6cd20 1 - 6cd20 (4.77) ...
heaps on program has been running half hour:
0:046> !heap -s lfh key : 0x5e47ba72 termination on corruption : enabled heap flags reserv commit virt free list ucr virt lock fast (k) (k) (k) (k) length blocks cont. heap ----------------------------------------------------------------------------- 006b0000 00000002 2048 1744 2048 46 92 2 0 0 lfh 00200000 00001002 1088 220 1088 68 3 2 0 0 lfh 00950000 00001002 1088 108 1088 15 7 2 0 0 lfh 001b0000 00001002 47808 31936 47808 1855 102 12 0 0 lfh ... 0:046> !heap -stat -h 001b0000 heap @ 001b0000 group-by: totsize max-display: 20 size #blocks total ( %) (percent of total busy bytes) 98 59d1 - 355418 (36.67) 2b110 10 - 2b1100 (29.61) 6cd20 1 - 6cd20 (4.68) ...
now can seen leaks caused growing number of blocks size 98. when try analyze 1 of blocks !heap -p -a
, get:
*** error: symbol file not found. defaulted export symbols jvm.dll
without stack trace. blocks allocated somewhere inside jvm.dll, , because there no pdbs jvm, cannot debug leak further.
i managed pinpoint leak occuring in code. callbacs java frontend pass through 1 function:
void callback(jnienv *env, int stream, double value, char *callbackname){ jclass jni = env->findclass("nativ/callbacks"); jmethodid callbackmethodid = env->getstaticmethodid(jni, callbackname, "(id)v"); jvalue params[2]; params[0].i = (long)(stream); params[1].d = value; env->callstaticvoidmethoda(jni, callbackmethodid, params); //commenting out stops leaks }
when comment out last command, leaks stop, no feedback frontend.
could jvm bug? how find out?
malloc() internally calls heapalloc(). guess need 'release' method release memory allocated jvm, long library hold reference jvm's internal state.
Comments
Post a Comment