[kaffe] CVS kaffe (robilad): Fixed synchronization problems when opening ZipFiles
Kaffe CVS
cvs-commits at kaffe.org
Wed Jan 5 14:49:14 PST 2005
PatchSet 5773
Date: 2005/01/05 22:40:55
Author: robilad
Branch: HEAD
Tag: (none)
Log:
Fixed synchronization problems when opening ZipFiles
2005-01-05 Dalibor Topic <robilad at kaffe.org>
* libraries/javalib/java/util/zip/ZipFile.java (ZipFile):
Synchronize on file name before calling native method, in order to
avoid races between threads trying to load the same file and
getting confused in the jar file cache.
Reported by: Davanum Srinivas <davanum at gmail.com>
* kaffe/kaffevm/jar.c (findCachedJarFile): Renamed from findJarFile.
(openJarFile): Use findCachedJarFile.
(closeJarFile, findCachedJarFile, cacheJarFile): Added debug output.
Members:
ChangeLog:1.3317->1.3318
kaffe/kaffevm/jar.c:1.34->1.35
libraries/javalib/java/util/zip/ZipFile.java:1.15->1.16
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.3317 kaffe/ChangeLog:1.3318
--- kaffe/ChangeLog:1.3317 Wed Jan 5 20:16:24 2005
+++ kaffe/ChangeLog Wed Jan 5 22:40:55 2005
@@ -1,5 +1,18 @@
2005-01-05 Dalibor Topic <robilad at kaffe.org>
+ * libraries/javalib/java/util/zip/ZipFile.java (ZipFile):
+ Synchronize on file name before calling native method, in order to
+ avoid races between threads trying to load the same file and
+ getting confused in the jar file cache.
+
+ Reported by: Davanum Srinivas <davanum at gmail.com>
+
+ * kaffe/kaffevm/jar.c (findCachedJarFile): Renamed from findJarFile.
+ (openJarFile): Use findCachedJarFile.
+ (closeJarFile, findCachedJarFile, cacheJarFile): Added debug output.
+
+2005-01-05 Dalibor Topic <robilad at kaffe.org>
+
Resynced with GNU Classpath.
2004-12-29 Jerry Quinn <jlquinn at optonline.net>
Index: kaffe/kaffe/kaffevm/jar.c
diff -u kaffe/kaffe/kaffevm/jar.c:1.34 kaffe/kaffe/kaffevm/jar.c:1.35
--- kaffe/kaffe/kaffevm/jar.c:1.34 Tue Dec 21 08:06:37 2004
+++ kaffe/kaffe/kaffevm/jar.c Wed Jan 5 22:40:58 2005
@@ -101,9 +101,8 @@
* Find a cached jarFile object. If the file is found, it is returned and its
* user count is incremented.
*
- * XXX rename findCachedJarFile()
*/
-static jarFile *findJarFile(char *name)
+static jarFile *findCachedJarFile(char *name)
{
jarFile *curr, **prev, *retval = NULL;
#if !defined(KAFFEH)
@@ -131,6 +130,8 @@
retval = curr;
retval->users++;
+DBG(JARFILES, dprintf("Found cached jar file %s, %d users\n", retval->fileName, retval->users); );
+
assert(retval->users >= 1);
}
prev = &curr->next;
@@ -232,6 +233,9 @@
*prev = curr->next;
retval = curr;
retval->users++;
+
+DBG(JARFILES, dprintf("Found cached jar file %s, %d users\n", retval->fileName, retval->users); );
+
}
else
{
@@ -249,6 +253,9 @@
*prev = curr->next;
curr->flags &= ~JFF_CACHED;
dead_jar = curr;
+
+DBG(JARFILES, dprintf("Cached jar file %s purged\n", curr->fileName); );
+
}
/*
* `jf' is redundant so the number of cached files
@@ -1054,7 +1061,7 @@
assert(name != NULL);
/* Look for it in the cache first */
- if( (retval = findJarFile(name)) )
+ if( (retval = findCachedJarFile(name)) )
{
/* Check if we need to reopen the file */
if( (retval->fd == -1)
@@ -1191,6 +1198,8 @@
lockStaticMutex(&jarCache.lock);
jf->users--;
+DBG(JARFILES, dprintf("Closing jar file %s, users %d\n", jf->fileName, jf->users); );
+
if( jf->users == 0 )
{
if( jarCache.count <= JAR_FILE_CACHE_MAX )
Index: kaffe/libraries/javalib/java/util/zip/ZipFile.java
diff -u kaffe/libraries/javalib/java/util/zip/ZipFile.java:1.15 kaffe/libraries/javalib/java/util/zip/ZipFile.java:1.16
--- kaffe/libraries/javalib/java/util/zip/ZipFile.java:1.15 Fri Dec 24 21:04:27 2004
+++ kaffe/libraries/javalib/java/util/zip/ZipFile.java Wed Jan 5 22:40:58 2005
@@ -44,7 +44,10 @@
public ZipFile(String fname) throws IOException
{
name = fname;
- zip = openZipFile0(fname);
+ /* only have one thread at a time attempt to open the zip file */
+ synchronized(fname) {
+ zip = openZipFile0(fname);
+ }
if (zip == null) {
throw new IOException("No such zip file " + fname);
}
More information about the kaffe
mailing list