Re: [OT] JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chuck, On 10/8/2009 8:27 PM, Caldarale, Charles R wrote: From: Christopher Schultz [mailto:ch...@christopherschultz.net] Subject: Re: [OT] JNI problem C99 allows /dynamic/ size determination: Sounds like a flaw in the article; it can't possibly be true, since there is no standard-defined API to discover the size of a malloc'd item; sizeof is *always* a compile-time operation. Agreed. It sounds like the article's terminology (or our interpretation of it) is incorrect. C99 probably allows this: char s[20]; sizeof s; To yield 20, while strict, old-skool C would yield whatever sizeof char* would. In any case, it's always best to use strlen() to figure out how many chars are in a string. This will also be better when working with different character sets, as one might search for invocations of the strlen() function to change them to, say, wcslen() to handle wide-character strings. It would be awkward and tedious to search for use of the sizeof operator to change from single-byte-character to wide-character strings. The only situation where it is not a compile-time /constant/ is if the size of the array of interest is dependent on the value of a function parameter: int func(int val) { char arr[val + 6]; return sizeof arr; /* returns val + 6 */ } This is not really dynamic allocation. I guess you mean dynamic sizing and not dynamic allocation. I'm honestly surprised that this: #include stdio.h int func(int val) { char arr[val + 6]; return sizeof arr; } int main(int argc, char *argv[]) { printf(%d\n, func(1)); printf(%d\n, func(2)); printf(%d\n, func(3)); } Prints this: 7 8 9 on my system (gcc 4.2.1). It appears that: sizeof arr compiles to the equivalent of: val + sizeof char[6] That's a pretty clever compiler. Whatever happened to the days when compilers found ways to make your life miserable instead of actually helping you out? ;) - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrPYUQACgkQ9CaO5/Lv0PAx/ACfUpt4qIgV/d/VCWpGbYbIgbjf MKMAnje7v2MaP0RuifSOrA1B5P1CjOaC =DDDO -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: [OT] JNI problem
From: Christopher Schultz [mailto:ch...@christopherschultz.net] Subject: Re: [OT] JNI problem C99 probably allows this: char s[20]; sizeof s; To yield 20, while strict, old-skool C would yield whatever sizeof char* would. Not true; all versions of the C standard allowed the above, and all would evaluate to 20 for sizeof. Contrary to popular belief, arrays and pointers are not equivalent, although they can be interchanged in many circumstances - sizeof not being one of them. In any case, it's always best to use strlen() to figure out how many chars are in a string. It's not just best, it's mandatory. I guess you mean dynamic sizing and not dynamic allocation. I said it was not dynamic allocation; dynamic sizing is not quite appropriate either, since the value is fixed for any given invocation of the function. It appears that: sizeof arr compiles to the equivalent of: val + sizeof char[6] Yes, that's what I was pointing out. That's a pretty clever compiler. It's required by the standard; not sure which version it went into, since I've only kept the 1999 one. Whatever happened to the days when compilers found ways to make your life miserable instead of actually helping you out? ;) I believe that Visual Studio has cornered the make-your-life-miserable part of the market. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: JNI problem
Here is one function that always crash. The portion of the code that couse the crash in my opinion is the if which has malloc. I noticed it crash whenever it is called with the same srcFile and dstFile int reduce_quality(const char * srcFile, const char * dstFile, int maxSize){ struct stat info; stat(srcFile, info); if (info.st_size = maxSize){//it is already small enough!! so just copy it return copy_file(srcFile, dstFile); } char * tmpFile = NULL; if (strcmp(srcFile, dstFile)==0){ tmpFile = (char *) malloc(sizeof(srcFile)+1); strcpy(tmpFile, srcFile); strcat(tmpFile,_); copy_file(srcFile, tmpFile); srcFile = tmpFile; } int quality = DEFAULT_QUALITY; long targetSize; long lastTargetSize = 0; int ret = False; do { ret = reduce_quality_to(srcFile, dstFile, quality); if (ret == False) break; stat(dstFile, info); targetSize = info.st_size; if (targetSize == lastTargetSize) { ret = reduce_quality_to(srcFile, dstFile, quality + DECREASE_QUALITY_LEVEL); break; } lastTargetSize = targetSize; quality -= DECREASE_QUALITY_LEVEL; } while (quality 0 targetSize maxSize); if (quality == 0) fprintf(stderr,Couldn't reach desired size %d for %s\n, maxSize, dstFile); if(tmpFile!=NULL){ remove(tmpFile); free(tmpFile); } return ret; } JNIEXPORT jboolean JNICALL Java_com_vehicle_netapp_backend_objects_photo_PhotoOperations_reduceQuality (JNIEnv * env, jobject jobj, jstring src, jstring dst, jint maxSize){ jboolean iscopy; const char *srcFile = (*env)-GetStringUTFChars(env, src, iscopy); const char *dstFile = (*env)-GetStringUTFChars(env, dst, iscopy); int ret = reduce_quality(srcFile, dstFile, maxSize); (*env)-ReleaseStringUTFChars(env, src, srcFile); (*env)-ReleaseStringUTFChars(env, dst, dstFile); return ret; } Thanks, Mohamedin - Original Message - From: Christopher Schultz ch...@christopherschultz.net To: Tomcat Users List users@tomcat.apache.org Sent: Wednesday, October 07, 2009 8:39 PM Subject: Re: JNI problem -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mohamedin, On 10/7/2009 10:40 AM, Mohamedin wrote: Dear all, I am trying to use a JNI library written by me that uses GraphicsMagick wand. It is working fine as a stand alone java application but when I tried to use it in tomcat it give me this error and tomcat crashed. Technically speaking, the JVM has crashed, not Tomcat. I am running on: AMD64 Tomcat 6.0.20 CATALINA_OPTS = -server -Xms512m -Xmx2048m -Djava.library.path=/usr/lib/apache-tomcat-6.0.20/shared/lib/:/usr/local/lib/ Please help *** glibc detected *** /usr/bin/java: malloc(): memory corruption: 0x7f5614455720 *** === Backtrace: = /lib/libc.so.6[0x7f56b0cc7948] /lib/libc.so.6[0x7f56b0cca17c] /lib/libc.so.6(__libc_malloc+0x98)[0x7f56b0ccba78] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(NewMagickWand+0x13)[0x7f561b7068de] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality_to+0x26)[0x7f561b6f71f6] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality+0x88)[0x7f561b6f74e8] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(Java_com_vehicle_netapp_backend_objects_photo_PhotoOperations_reduceQuality+0x68)[0x7f561b6f7688] [0x7f56a95ca542] Since your code is definitely involved, here (the stack trace above shows 4 layers of your code before glibc is involved), I suspect your code is to blame for this problem. Tomcat does not use any native code directly (except for tcnative if you are using that). Are you using tcnative? If so, disable it and re-try to convince yourself that this is not a Tomcat problem. I'm not saying it is definitely /not/ a Tomcat problem, but chances are that it's your code at fault. My experience with native code from Java is that when memory corruption is found in one instance but not another and the code is the same, then there is probably some bug in your code that is sensitive to re-location of your code within memory. That is, you are making assumptions about your environment that are not valid when running from within a JVM (or they work sometimes, but not other times because more code gets loaded when running under an app server). How much of your JNI code are you willing to post? Typically, one develops a native library that has nothing to do with Java, and then writes a Java wrapper around that code which is little more than the plumbing necessary to convert data between Java-style objects, arrays, etc. and C-style data structures. Have you done that? If so, go ahead and post the JNI-specific layer. If not, I think you're playing with fire by writing a native library that does a great deal of Java interaction. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrM4EcACgkQ9CaO5/Lv0PBregCgumcWoLGOm+fOjvV4S79ZHt1P y10AoKqWpMNgMMYKKubd9H+jQPKjIHS2 =rfQZ -END PGP SIGNATURE
Re: JNI problem
2009/10/8 Mohamedin mohame...@easy-dialog.info: Here is one function that always crash. The portion of the code that couse the crash in my opinion is the if which has malloc. I noticed it crash whenever it is called with the same srcFile and dstFile int reduce_quality(const char * srcFile, const char * dstFile, int maxSize){ ... tmpFile = (char *) malloc(sizeof(srcFile)+1); You meant string length there? sizeof(pointer) is - what is the size of pointers on your OS? 8 bytes? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: JNI problem
); if (status == False) { ThrowAPIException(composite_wand); DestroyMagickWand(magick_wand); return False; } int w,h; if (width 0 height 0){ w=width; h=height; MagickResizeImage(composite_wand,width,height,LanczosFilter,1.0); } else{ h = MagickGetImageHeight(composite_wand); w = MagickGetImageWidth(composite_wand); } int imgH = MagickGetImageHeight(magick_wand); int imgW = MagickGetImageWidth(magick_wand); int x=0,y=0; switch(position){ case 1://North west y=0; x=0; break; case 2://North east y=0; x=imgW-w; break; case 3://South west y=imgH -h; x=0; break; case 4://South east y=imgH-h; x=imgW-w; break; case 5://center y=(imgH-h)/2; x=(imgW-w)/2; break; } switch(shiftDirection){ case 1://North y-=shiftAmount; break; case 2://East x+=shiftAmount; break; case 3://South y+=shiftAmount; break; case 4://West x-=shiftAmount; break; } MagickCompositeImage(magick_wand, composite_wand, OverCompositeOp, x, y); status=MagickWriteImages(magick_wand, imageFile,True); if (status == False){ ThrowAPIException(magick_wand); DestroyMagickWand(composite_wand); return False; } DestroyMagickWand(magick_wand); DestroyMagickWand(composite_wand); return True; } JNIEXPORT jboolean JNICALL Java_com_vehicle_netapp_backend_objects_photo_PhotoOperations_compose (JNIEnv * env, jobject jobj, jstring composeImg, jstring image, jint position, jint width, jint height, jint shiftDirection, jint shiftAmount){ jboolean iscopy; const char *composeImgFile = (*env)-GetStringUTFChars(env, composeImg, iscopy); const char *imageFile = (*env)-GetStringUTFChars(env, image, iscopy); int ret = compose(composeImgFile, imageFile, position, width, height, shiftDirection, shiftAmount); (*env)-ReleaseStringUTFChars(env, composeImg, composeImgFile); (*env)-ReleaseStringUTFChars(env, image, imageFile); return ret; } Mohamedin - Original Message - From: Konstantin Kolinko knst.koli...@gmail.com To: Tomcat Users List users@tomcat.apache.org Sent: Thursday, October 08, 2009 10:37 AM Subject: Re: JNI problem 2009/10/8 Mohamedin mohame...@easy-dialog.info: Here is one function that always crash. The portion of the code that couse the crash in my opinion is the if which has malloc. I noticed it crash whenever it is called with the same srcFile and dstFile int reduce_quality(const char * srcFile, const char * dstFile, int maxSize){ ... tmpFile = (char *) malloc(sizeof(srcFile)+1); You meant string length there? sizeof(pointer) is - what is the size of pointers on your OS? 8 bytes? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org __ Information from ESET NOD32 Antivirus, version of virus signature database 4488 (20091007) __ The message was checked by ESET NOD32 Antivirus. http://www.eset.com __ Information from ESET NOD32 Antivirus, version of virus signature database 4488 (20091007) __ The message was checked by ESET NOD32 Antivirus. http://www.eset.com - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: JNI problem
2009/10/8 Mohamedin mohame...@easy-dialog.info: Thanks a lot I have fixed this bug (Long time without coding in C). But still the error. Then I removed all malloc from the code. Still crashing You are using free(..). Thus you need to have malloc()s somewhere. Also, (void) fprintf(stderr,%s %s %d %.1024s\n,GetMagickModule(),description); you have 4 substitutions, but only 2 arguments for them. You really should review/debug your C code, and it likely has nothing to do with Tomcat. Best regards, Konstantin Kolinko - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: [OT] JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Konstantin, On 10/8/2009 4:37 AM, Konstantin Kolinko wrote: 2009/10/8 Mohamedin mohame...@easy-dialog.info: Here is one function that always crash. The portion of the code that couse the crash in my opinion is the if which has malloc. I noticed it crash whenever it is called with the same srcFile and dstFile int reduce_quality(const char * srcFile, const char * dstFile, int maxSize){ ... tmpFile = (char *) malloc(sizeof(srcFile)+1); You meant string length there? I saw the same thing at first glance, but then I looked-up the sizeof() operator and it seems that sizeof /can/ return the number of bytes in an array in C99 (http://en.wikipedia.org/wiki/Sizeof#Using_sizeof_with_arrays), but that might only work with statically-declared arrays, and that's not the case, here. I can see why confusion might have occurred, especially with someone with little C experience. :( - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrOcAcACgkQ9CaO5/Lv0PBPGgCgsu1cwLehuq9fvUp5+iVMgnbm 9EwAnAsD5IZTFw08QYfLuK81qvTSS/OS =RgTy -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: [OT] JNI problem
From: Christopher Schultz [mailto:ch...@christopherschultz.net] Subject: Re: [OT] JNI problem I saw the same thing at first glance, but then I looked-up the sizeof() operator and it seems that sizeof /can/ return the number of bytes in an array in C99 Minor correction: the operator is sizeof, not sizeof() - it is not a function. The parentheses one often sees with sizeof are either unnecessary (when used around a variable name) or a *cast* operator, when used with a type. The sizeof operator always returns the number of bytes occupied by the type of the operand, which is the declared size, not any associated dynamically allocated size. For example: char array[6]; char * ptr; struct string { int len; char body[]; }; struct string sptr = malloc(sizeof (struct string) + 8); sizeof array returns 6 sizeof ptr returns 4 or 8, depending on platform sizeof (struct string) returns 4 (usually; sometimes 8) - the length of the int sizeof sptr returns 4 or 8, depending on platform sizeof *sptr returns the same as sizeof (struct string) - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
Re: JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mohamedin, On 10/8/2009 5:42 AM, Mohamedin wrote: I have fixed this bug (Long time without coding in C). But still the error. You didn't look for all uses of sizeof: while((bytes = read(inF, buff, sizeof(buff))) 0) I think you meant this: while((bytes = read(inF, buff, 1024)) 0) // use any window size Also, as Konstantin points out, you have a free in there somewhere, so you ought to have a malloc, too. The API documentation for MagickGetException does not seem to indicate that the returned object needs to be freed. It looks like you have memory leaks everywhere. For instance: int resize(const char * srcFile, const char * dstFile, int width, int height, int quality){ char *description; ExceptionType severity; MagickWand *magick_wand; unsigned int status; magick_wand = NewMagickWand(); status = MagickReadImage(magick_wand, srcFile); if (status == False) { ThrowAPIException(magick_wand); return False; } What about the magick_wand variable? Shouldn't you free that guy? MagickResizeImage(magick_wand,width,height,LanczosFilter,1.0); MagickSetCompressionQuality(magick_wand, quality); status=MagickWriteImages(magick_wand, dstFile,True); if (status == False){ ThrowAPIException(magick_wand); return False; } What about freeing the memory allocated by MagickReadImage, here? You ought to call this method before every 'return' from your function: DestroyMagickWand(magick_wand); I would highly recommend that you have some with some more C experience read-through your code. It's clear that your code is untrustworthy when it comes to memory being managed by the JVM, and you can really ruin the JVM's day, as you have seen. int resize_with_limits(const char * srcFile, const char * dstFile, int maxDim, int maxSize){ This function has the same problems as above. int crop(const char * srcFile, const char * dstFile, int widthRatio, int heightRatio){ Same here. int compose(const char * composeImgFile, const char * imageFile, int position, int width, int height, int shiftDirection, int shiftAmount){ Guess what? This one is correct! status = MagickReadImage(composite_wand, composeImgFile); if (status == False) { ThrowAPIException(composite_wand); DestroyMagickWand(magick_wand); return False; } The above code is the way to do things. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrOdLcACgkQ9CaO5/Lv0PD3tgCgjmH9/+G+9FIyhwJiApknBWQ2 wbgAnjmuh9Fb8xuAMIsQAUNU9Xm40HYz =dbmW -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: [OT] JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Chuck, On 10/8/2009 7:24 PM, Caldarale, Charles R wrote: char array[6]; ... sizeof array returns 6 This is what I was describing. The Wikipedia article states (I don't have my KR book in front of me... besides, it wouldn't cover this case, anyway) that C99 allows /dynamic/ size determination: sizeof is generally a compile-time operation, although in C99 it can be used at run-time to find the size of a variable length array. Oddly, this statement is contradicted without qualification immediately below: Since argv is a pointer to an array rather than an array itself, sizeof(argv) is equivalent to sizeof(char **) — that is, the size of the pointer type of argv. It will not be the size of the array to which argv points (which consists of a series of char* pointers). sizeof (struct string) returns 4 (usually; sometimes 8) - the length of the int Wouldn't this yield (not return :) sizeof(int) + sizeof(char*)? - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrOd7sACgkQ9CaO5/Lv0PCE2QCfX9y5QoZX8bhd1+Z24e5wmLTq 8eQAoJ4MxvuEiCC/Y7EF/3kTUsT012PP =ngEg -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
RE: [OT] JNI problem
From: Christopher Schultz [mailto:ch...@christopherschultz.net] Subject: Re: [OT] JNI problem C99 allows /dynamic/ size determination: Sounds like a flaw in the article; it can't possibly be true, since there is no standard-defined API to discover the size of a malloc'd item; sizeof is *always* a compile-time operation. The only situation where it is not a compile-time /constant/ is if the size of the array of interest is dependent on the value of a function parameter: int func(int val) { char arr[val + 6]; return sizeof arr; /* returns val + 6 */ } This is not really dynamic allocation. sizeof (struct string) returns 4 (usually; sometimes 8) - the length of the int Wouldn't this yield (not return :) sizeof(int) + sizeof(char*)? (Yield is definitely better terminology than return.) The struct I had was incorrect (it wouldn't compile); it should have been: struct string { int len; char body[0]; }; Since the struct includes a zero-element char array, not a char pointer, the resultant value is 4 + 0. The struct is expected to be malloc'd for an appropriate length, but the sizeof would always return the same value, being unaware of the allocated size of the structure. - Chuck THIS COMMUNICATION MAY CONTAIN CONFIDENTIAL AND/OR OTHERWISE PROPRIETARY MATERIAL and is thus for use only by the intended recipient. If you received this in error, please contact the sender and delete the e-mail and its attachments from all computers.
JNI problem
Dear all, I am trying to use a JNI library written by me that uses GraphicsMagick wand. It is working fine as a stand alone java application but when I tried to use it in tomcat it give me this error and tomcat crashed. I am running on: AMD64 Tomcat 6.0.20 CATALINA_OPTS = -server -Xms512m -Xmx2048m -Djava.library.path=/usr/lib/apache-tomcat-6.0.20/shared/lib/:/usr/local/lib/ Please help *** glibc detected *** /usr/bin/java: malloc(): memory corruption: 0x7f5614455720 *** === Backtrace: = /lib/libc.so.6[0x7f56b0cc7948] /lib/libc.so.6[0x7f56b0cca17c] /lib/libc.so.6(__libc_malloc+0x98)[0x7f56b0ccba78] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(NewMagickWand+0x13)[0x7f561b7068de] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality_to+0x26)[0x7f561b6f71f6] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality+0x88)[0x7f561b6f74e8] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(Java_com_vehicle_netapp_backend_objects_photo_PhotoOperations_reduceQuality+0x68)[0x7f561b6f7688] [0x7f56a95ca542] === Memory map: 4000-4000e000 r-xp 09:05 25206548 /usr/lib/jvm/java-1.5.0-sun-1.5.0.17/jre/bin/java 4010d000-4011 rwxp d000 09:05 25206548 /usr/lib/jvm/java-1.5.0-sun-1.5.0.17/jre/bin/java 4011-402ed000 rwxp 4011 00:00 0 [heap] 402f9000-402fa000 ---p 402f9000 00:00 0 402fa000-403fa000 rwxp 402fa000 00:00 0 403fa000-403fd000 ---p 403fa000 00:00 0 403fd000-404fb000 rwxp 403fd000 00:00 0 404fb000-404fe000 ---p 404fb000 00:00 0 404fe000-405fc000 rwxp 404fe000 00:00 0 405fc000-405ff000 ---p 405fc000 00:00 0 405ff000-406fd000 rwxp 405ff000 00:00 0 40715000-40718000 ---p 40715000 00:00 0 40718000-40816000 rwxp 40718000 00:00 0 40816000-40819000 ---p 40816000 00:00 0 40819000-40917000 rwxp 40819000 00:00 0 40917000-4091a000 ---p 40917000 00:00 0 4091a000-40a18000 rwxp 4091a000 00:00 0 40a18000-40a1b000 ---p 40a18000 00:00 0 40a1b000-40b19000 rwxp 40a1b000 00:00 0 40bf2000-40bf5000 ---p 40bf2000 00:00 0 40bf5000-40cf3000 rwxp 40bf5000 00:00 0 40db4000-40db7000 ---p 40db4000 00:00 0 40db7000-40eb5000 rwxp 40db7000 00:00 0 40eb5000-40eb8000 ---p 40eb5000 00:00 0 40eb8000-40fb6000 rwxp 40eb8000 00:00 0 40ff5000-40ff8000 ---p 40ff5000 00:00 0 40ff8000-410f6000 rwxp 40ff8000 00:00 0 411bc000-411bf000 ---p 411bc000 00:00 0 411bf000-412bd000 rwxp 411bf000 00:00 0 412bd000-412c ---p 412bd000 00:00 0 412c-413be000 rwxp 412c 00:00 0 413be000-413c1000 ---p 413be000 00:00 0 413c1000-414bf000 rwxp 413c1000 00:00 0 414de000-414e1000 ---p 414de000 00:00 0 414e1000-415df000 rwxp 414e1000 00:00 0 4168c000-4168f000 ---p 4168c000 00:00 0 4168f000-4178d000 rwxp 4168f000 00:00 0 4178d000-4179 ---p 4178d000 00:00 0 4179-4188e000 rwxp 4179 00:00 0 4188e000-4188f000 ---p 4188e000 00:00 0 4188f000-4198f000 rwxp 4188f000 00:00 0 41a83000-41a86000 ---p 41a83000 00:00 0 41a86000-41b84000 rwxp 41a86000 00:00 0 41b84000-41b87000 ---p 41b84000 00:00 0 41b87000-41c85000 rwxp 41b87000 00:00 0 41c85000-41c88000 ---p 41c85000 00:00 0 41c88000-41d86000 rwxp 41c88000 00:00 0 41e5-41e53000 ---p 41e5 00:00 0 41e53000-41f51000 rwxp 41e53000 00:00 0 41fab000-41fae000 ---p 41fab000 00:00 0 41fae000-420ac000 rwxp 41fae000 00:00 0 420ac000-420af000 ---p 420ac000 00:00 0 420af000-421ad000 rwxp 420af000 00:00 0 421ad000-421b ---p 421ad000 00:00 0 421b-422ae000 rwxp 421b 00:00 0 422ae000-422b1000 ---p 422ae000 00:00 0 422b1000-423af000 rwxp 422b1000 00:00 0 423af000-423b2000 ---p 423af000 00:00 0 423b2000-424b rwxp 423b2000 00:00 0 424b-424b3000 ---p 424b 00:00 0 424b3000-425b1000 rwxp 424b3000 00:00 0 425b1000-425b4000 ---p 425b1000 00:00 0 425b4000-426b2000 rwxp 425b4000 00:00 0 426b2000-426b5000 ---p 426b2000 00:00 0 426b5000-427b3000 rwxp 426b5000 00:00 0 427b3000-427b6000 ---p 427b3000 00:00 0 427b6000-428b4000 rwxp 427b6000 00:00 0 428b4000-428b7000 ---p 428b4000 00:00 0 428b7000-429b5000 rwxp 428b7000 00:00 0 429b5000-429b8000 ---p 429b5000 00:00 0 429b8000-42ab6000 rwxp 429b8000 00:00 0 42ab6000-42ab9000 ---p 42ab6000 00:00 0 42ab9000-42bb7000 rwxp 42ab9000 00:00 0 7f561400-7f5614da rwxp 7f561400 00:00 0 7f5614da-7f561800 ---p 7f5614da 00:00 0 7f561918a000-7f56191a r-xp 09:01 77300 /lib/libgcc_s.so.1 7f56191a-7f56193a ---p 00016000 09:01 77300 /lib/libgcc_s.so.1 7f56193a-7f56193a1000 rwxp 00016000 09:01 77300 /lib/libgcc_s.so.1 7f56193a1000-7f56193a6000 r-xp 09:05 12594380 /usr/lib/libXdmcp.so.6.0.0 7f56193a6000-7f56195a5000 ---p 5000 09:05 12594380 /usr/lib/libXdmcp.so.6.0.0 7f56195a5000-7f56195a6000 rwxp 4000 09:05 12594380 /usr/lib/libXdmcp.so.6.0.0 7f56195a6000-7f56195a8000 r-xp
Re: JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mohamedin, On 10/7/2009 10:40 AM, Mohamedin wrote: Dear all, I am trying to use a JNI library written by me that uses GraphicsMagick wand. It is working fine as a stand alone java application but when I tried to use it in tomcat it give me this error and tomcat crashed. Technically speaking, the JVM has crashed, not Tomcat. I am running on: AMD64 Tomcat 6.0.20 CATALINA_OPTS = -server -Xms512m -Xmx2048m -Djava.library.path=/usr/lib/apache-tomcat-6.0.20/shared/lib/:/usr/local/lib/ Please help *** glibc detected *** /usr/bin/java: malloc(): memory corruption: 0x7f5614455720 *** === Backtrace: = /lib/libc.so.6[0x7f56b0cc7948] /lib/libc.so.6[0x7f56b0cca17c] /lib/libc.so.6(__libc_malloc+0x98)[0x7f56b0ccba78] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(NewMagickWand+0x13)[0x7f561b7068de] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality_to+0x26)[0x7f561b6f71f6] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(reduce_quality+0x88)[0x7f561b6f74e8] /usr/lib/apache-tomcat-6.0.20/shared/lib/libPhotoOperations.so(Java_com_vehicle_netapp_backend_objects_photo_PhotoOperations_reduceQuality+0x68)[0x7f561b6f7688] [0x7f56a95ca542] Since your code is definitely involved, here (the stack trace above shows 4 layers of your code before glibc is involved), I suspect your code is to blame for this problem. Tomcat does not use any native code directly (except for tcnative if you are using that). Are you using tcnative? If so, disable it and re-try to convince yourself that this is not a Tomcat problem. I'm not saying it is definitely /not/ a Tomcat problem, but chances are that it's your code at fault. My experience with native code from Java is that when memory corruption is found in one instance but not another and the code is the same, then there is probably some bug in your code that is sensitive to re-location of your code within memory. That is, you are making assumptions about your environment that are not valid when running from within a JVM (or they work sometimes, but not other times because more code gets loaded when running under an app server). How much of your JNI code are you willing to post? Typically, one develops a native library that has nothing to do with Java, and then writes a Java wrapper around that code which is little more than the plumbing necessary to convert data between Java-style objects, arrays, etc. and C-style data structures. Have you done that? If so, go ahead and post the JNI-specific layer. If not, I think you're playing with fire by writing a native library that does a great deal of Java interaction. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrM4EcACgkQ9CaO5/Lv0PBregCgumcWoLGOm+fOjvV4S79ZHt1P y10AoKqWpMNgMMYKKubd9H+jQPKjIHS2 =rfQZ -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: JNI problem
Christopher Schultz wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mohamedin, On 10/7/2009 10:40 AM, Mohamedin wrote: Dear all, I am trying to use a JNI library written by me that uses GraphicsMagick wand. It is working fine as a stand alone java application but when I tried to use it in tomcat it give me this error and tomcat crashed. Considering the above, might it simply be not thread-safe ? - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org
Re: JNI problem
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 André, On 10/7/2009 8:18 PM, Warnier wrote: Christopher Schultz wrote: -BEGIN PGP SIGNED MESSAGE- Hash: SHA1 Mohamedin, On 10/7/2009 10:40 AM, Mohamedin wrote: Dear all, I am trying to use a JNI library written by me that uses GraphicsMagick wand. It is working fine as a stand alone java application but when I tried to use it in tomcat it give me this error and tomcat crashed. Considering the above, might it simply be not thread-safe ? It's definitely possible, and likely probably. I'm guessing that GraphicsMagick itself /is/ threadsafe, so I wonder if the OP wrote a broken JNI bridge... which is why I was asking for the code. - -chris -BEGIN PGP SIGNATURE- Version: GnuPG v1.4.9 (MingW32) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/ iEYEARECAAYFAkrNPRoACgkQ9CaO5/Lv0PA4lQCeNG2A5pjt1ktj1O1FCM/Vs3+m cw0AoKXFVJdUcBdy5+cwm2tn6glV6hR5 =o8js -END PGP SIGNATURE- - To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org For additional commands, e-mail: users-h...@tomcat.apache.org