Replace the static error string in ZIP_Put_In_Cache0 with on stack memory
Sean Chou
zhouyx at linux.vnet.ibm.com
Mon Apr 9 07:53:43 UTC 2012
Hi all,
I would like to suggest to replace the static error string in
ZIP_Put_In_Cache0 with on stack memory. Because it takes more time to
modify a string than an int typed error number, it opens a window larger
than int typed error number and might bring in race in multi-thread user
cases.
I wrote a simple c testcase for JNI call "ZIP_Open", which shows that
it is easy to cause a race. In my machine, the testcase fails several time
with only 2 threads.
The testcase is attached, it needs jdk shared libs to compile and run.
compile: gcc test_zip_open.c -I j2sdk-image/include/ -I
j2sdk-image/include/linux/ j2sdk-image/jre/lib/i386/lib*.so
j2sdk-image/jre/lib/i386/client/libjvm.so -pthread
run: please include the libs in LD_LIBRARY_PATH , it is easy to catch the
error case with grep ////
Following is a simple output from my tests:
zhouyx at zhouyx-workstation:/media/data/GiveBack/OJDK-482/i386$ ./a.out 1 |
grep ////
////////////////////////// method1 pmsg :Permission denied
zhouyx at zhouyx-workstation:/media/data/GiveBack/OJDK-482/i386$ ./a.out 10 |
grep ////
//////////////////////// method2 pmsg :No such file or directory
//////////////////////// method2 pmsg :No such file or directory
//////////////////////// method2 pmsg :No such file or directory
zhouyx at zhouyx-workstation:/media/data/GiveBack/OJDK-482/i386$ ./a.out 100 |
grep ////
////////////////////////// method1 pmsg :Permission denied
////////////////////////// method1 pmsg :Permission denied
//////////////////////// method2 pmsg :No such file or directory
//////////////////////// method2 pmsg :No such file or directory
////////////////////////// method1 pmsg :Permission denied
The modification is here:
http://cr.openjdk.java.net/~zhouyx/OJDK-482/webrev.00/ .
It puts the error string on stack and return a dup one.
Please take a look and give some comments, thanks.
--
Best Regards,
Sean Chou
More information about the core-libs-dev
mailing list