[kaffe] CVS kaffe (robilad): reimplemented jar reading

Kaffe CVS cvs-commits at kaffe.org
Sun Jan 20 17:05:46 PST 2008


PatchSet 7712 
Date: 2008/01/21 01:04:28
Author: robilad
Branch: HEAD
Tag: (none) 
Log:
reimplemented jar reading

2008-01-21  Dalibor Topic  <robilad at kaffe.org>

* kaffe/kaffevm/baseClasses.c (initialiseKaffe): Don't initialize
JAR file cache, it's gone.

* kaffe/kaffevm/jar.h, kaffe/kaffevm/jar.c:
Rewriten from scratch to use zzip library. Since zzlib
allows transprent access to files and directories as well
as zip files, it could be possible to rewrite findInJar.c
to use jar.c now, regardless of the entry type.

* configure.ac: Check for zzip library and header.

* kaffe/kaffeh/support.c (kaffeh_findClass),
kaffe/kaffevm/findInJar.c (getManifestMainAttribute)
(findClassInJar): Use zziplib types and updated jar interfaces.

* kaffe/kaffevm/classpath.h (_classpathEntry): Use ZZIP_DIR
for a jar entry.

Members: 
	ChangeLog:1.5213->1.5214 
	configure:1.635->1.636 
	configure.ac:1.305->1.306 
	config/config.h.in:1.179->1.180 
	kaffe/kaffeh/support.c:1.56->1.57 
	kaffe/kaffevm/baseClasses.c:1.79->1.80 
	kaffe/kaffevm/classpath.h:1.3->1.4 
	kaffe/kaffevm/findInJar.c:1.76->1.77 
	kaffe/kaffevm/jar.c:1.44->1.45 
	kaffe/kaffevm/jar.h:INITIAL->1.11 

Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.5213 kaffe/ChangeLog:1.5214
--- kaffe/ChangeLog:1.5213	Sun Jan 20 20:03:35 2008
+++ kaffe/ChangeLog	Mon Jan 21 01:04:28 2008
@@ -1,3 +1,23 @@
+2008-01-21  Dalibor Topic  <robilad at kaffe.org>
+
+	* kaffe/kaffevm/baseClasses.c (initialiseKaffe): Don't initialize
+	JAR file cache, it's gone.
+
+	* kaffe/kaffevm/jar.h, kaffe/kaffevm/jar.c: 
+	Rewriten from scratch to use zzip library. Since zzlib
+	allows transprent access to files and directories as well
+	as zip files, it could be possible to rewrite findInJar.c
+	to use jar.c now, regardless of the entry type.
+
+	* configure.ac: Check for zzip library and header.
+
+	* kaffe/kaffeh/support.c (kaffeh_findClass),
+	kaffe/kaffevm/findInJar.c (getManifestMainAttribute)
+	(findClassInJar): Use zziplib types and updated jar interfaces.
+
+	* kaffe/kaffevm/classpath.h (_classpathEntry): Use ZZIP_DIR
+	for a jar entry.
+
 2008-01-20  Dalibor Topic  <robilad at kaffe.org>
 
 	TODO: Updated.
Index: kaffe/configure
diff -u kaffe/configure:1.635 kaffe/configure:1.636
--- kaffe/configure:1.635	Sun Jan 20 19:55:36 2008
+++ kaffe/configure	Mon Jan 21 01:04:29 2008
@@ -2176,6 +2176,7 @@
 ac_header_list="$ac_header_list sys/ucontext.h"
 ac_header_list="$ac_header_list unistd.h"
 ac_header_list="$ac_header_list wintypes.h"
+ac_header_list="$ac_header_list zzip/zzip.h"
 ac_header_list="$ac_header_list zlib.h"
 ac_header_list="$ac_header_list asm/sigcontext.h"
 ac_header_list="$ac_header_list asm/ppc_asm.h"
@@ -7032,7 +7033,7 @@
   ;;
 *-*-irix6*)
   # Find out which ABI we are using.
-  echo '#line 7035 "configure"' > conftest.$ac_ext
+  echo '#line 7036 "configure"' > conftest.$ac_ext
   if { (eval echo "$as_me:$LINENO: \"$ac_compile\"") >&5
   (eval $ac_compile) 2>&5
   ac_status=$?
@@ -9592,11 +9593,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:9595: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:9596: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:9599: \$? = $ac_status" >&5
+   echo "$as_me:9600: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -9882,11 +9883,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:9885: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:9886: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:9889: \$? = $ac_status" >&5
+   echo "$as_me:9890: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -9986,11 +9987,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:9989: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:9990: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:9993: \$? = $ac_status" >&5
+   echo "$as_me:9994: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -12335,7 +12336,7 @@
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 12338 "configure"
+#line 12339 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -12435,7 +12436,7 @@
   lt_dlunknown=0; lt_dlno_uscore=1; lt_dlneed_uscore=2
   lt_status=$lt_dlunknown
   cat > conftest.$ac_ext <<EOF
-#line 12438 "configure"
+#line 12439 "configure"
 #include "confdefs.h"
 
 #if HAVE_DLFCN_H
@@ -14855,11 +14856,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14858: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14859: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:14862: \$? = $ac_status" >&5
+   echo "$as_me:14863: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -14959,11 +14960,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:14962: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:14963: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:14966: \$? = $ac_status" >&5
+   echo "$as_me:14967: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -16521,11 +16522,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16524: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16525: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:16528: \$? = $ac_status" >&5
+   echo "$as_me:16529: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -16625,11 +16626,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:16628: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:16629: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:16632: \$? = $ac_status" >&5
+   echo "$as_me:16633: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -18812,11 +18813,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:18815: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:18816: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:18819: \$? = $ac_status" >&5
+   echo "$as_me:18820: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -19102,11 +19103,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:19105: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:19106: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>conftest.err)
    ac_status=$?
    cat conftest.err >&5
-   echo "$as_me:19109: \$? = $ac_status" >&5
+   echo "$as_me:19110: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s "$ac_outfile"; then
      # The compiler can only warn and ignore the option if not recognized
      # So say no if there are warnings other than the usual output.
@@ -19206,11 +19207,11 @@
    -e 's:.*FLAGS}\{0,1\} :&$lt_compiler_flag :; t' \
    -e 's: [^ ]*conftest\.: $lt_compiler_flag&:; t' \
    -e 's:$: $lt_compiler_flag:'`
-   (eval echo "\"\$as_me:19209: $lt_compile\"" >&5)
+   (eval echo "\"\$as_me:19210: $lt_compile\"" >&5)
    (eval "$lt_compile" 2>out/conftest.err)
    ac_status=$?
    cat out/conftest.err >&5
-   echo "$as_me:19213: \$? = $ac_status" >&5
+   echo "$as_me:19214: \$? = $ac_status" >&5
    if (exit $ac_status) && test -s out/conftest2.$ac_objext
    then
      # The compiler can only warn and ignore the option if not recognized
@@ -25748,7 +25749,7 @@
 JAVA_TEST=Test.java
 CLASS_TEST=Test.class
 cat << \EOF > $JAVA_TEST
-/* #line 25751 "configure" */
+/* #line 25752 "configure" */
 public class Test {
 }
 EOF
@@ -30276,6 +30277,10 @@
 
 
 
+
+
+
+
 # check sys/sysctl.h seperately, as it requires other headers on at least OpenBSD
 
 for ac_header in sys/sysctl.h
@@ -41696,6 +41701,100 @@
 	AWT_LIB="$AWT_LIB \$(top_builddir)/libraries/clib/awt/xynth/libxynthawt.la"
    fi
 fi
+
+if test x"$ac_cv_header_zzip_zzip_h" != x"yes" ; then
+  { { echo "$as_me:$LINENO: error: Can't find or can't use system zzip/zzip.h from zzip library" >&5
+echo "$as_me: error: Can't find or can't use system zzip/zzip.h from zzip library" >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
+{ echo "$as_me:$LINENO: checking for library containing zzip_read" >&5
+echo $ECHO_N "checking for library containing zzip_read... $ECHO_C" >&6; }
+if test "${ac_cv_search_zzip_read+set}" = set; then
+  echo $ECHO_N "(cached) $ECHO_C" >&6
+else
+  ac_func_search_save_LIBS=$LIBS
+cat >conftest.$ac_ext <<_ACEOF
+/* confdefs.h.  */
+_ACEOF
+cat confdefs.h >>conftest.$ac_ext
+cat >>conftest.$ac_ext <<_ACEOF
+/* end confdefs.h.  */
+
+/* Override any GCC internal prototype to avoid an error.
+   Use char because int might match the return type of a GCC
+   builtin and then its argument prototype would still apply.  */
+#ifdef __cplusplus
+extern "C"
+#endif
+char zzip_read ();
+int
+main ()
+{
+return zzip_read ();
+  ;
+  return 0;
+}
+_ACEOF
+for ac_lib in '' zzip; do
+  if test -z "$ac_lib"; then
+    ac_res="none required"
+  else
+    ac_res=-l$ac_lib
+    LIBS="-l$ac_lib  $ac_func_search_save_LIBS"
+  fi
+  rm -f conftest.$ac_objext conftest$ac_exeext
+if { (ac_try="$ac_link"
+case "(($ac_try" in
+  *\"* | *\`* | *\\*) ac_try_echo=\$ac_try;;
+  *) ac_try_echo=$ac_try;;
+esac
+eval "echo \"\$as_me:$LINENO: $ac_try_echo\"") >&5
+  (eval "$ac_link") 2>conftest.er1
+  ac_status=$?
+  grep -v '^ *+' conftest.er1 >conftest.err
+  rm -f conftest.er1
+  cat conftest.err >&5
+  echo "$as_me:$LINENO: \$? = $ac_status" >&5
+  (exit $ac_status); } && {
+	 test -z "$ac_c_werror_flag" ||
+	 test ! -s conftest.err
+       } && test -s conftest$ac_exeext &&
+       $as_test_x conftest$ac_exeext; then
+  ac_cv_search_zzip_read=$ac_res
+else
+  echo "$as_me: failed program was:" >&5
+sed 's/^/| /' conftest.$ac_ext >&5
+
+
+fi
+
+rm -f core conftest.err conftest.$ac_objext conftest_ipa8_conftest.oo \
+      conftest$ac_exeext
+  if test "${ac_cv_search_zzip_read+set}" = set; then
+  break
+fi
+done
+if test "${ac_cv_search_zzip_read+set}" = set; then
+  :
+else
+  ac_cv_search_zzip_read=no
+fi
+rm conftest.$ac_ext
+LIBS=$ac_func_search_save_LIBS
+fi
+{ echo "$as_me:$LINENO: result: $ac_cv_search_zzip_read" >&5
+echo "${ECHO_T}$ac_cv_search_zzip_read" >&6; }
+ac_res=$ac_cv_search_zzip_read
+if test "$ac_res" != no; then
+  test "$ac_res" = "none required" || LIBS="$ac_res $LIBS"
+
+else
+  { { echo "$as_me:$LINENO: error: Can't find the zzip library." >&5
+echo "$as_me: error: Can't find the zzip library." >&2;}
+   { (exit 1); exit 1; }; }
+fi
+
 
 # Check whether --enable-zlib_zip was given.
 if test "${enable_zlib_zip+set}" = set; then
Index: kaffe/configure.ac
diff -u kaffe/configure.ac:1.305 kaffe/configure.ac:1.306
--- kaffe/configure.ac:1.305	Sun Jan 20 19:55:38 2008
+++ kaffe/configure.ac	Mon Jan 21 01:04:35 2008
@@ -953,6 +953,7 @@
 sys/ucontext.h \
 unistd.h \
 wintypes.h \
+zzip/zzip.h \
 zlib.h])
 
 # check sys/sysctl.h seperately, as it requires other headers on at least OpenBSD
@@ -1575,6 +1576,12 @@
 	AWT_LIB="$AWT_LIB \$(top_builddir)/libraries/clib/awt/xynth/libxynthawt.la"
    fi
 fi
+
+if test x"$ac_cv_header_zzip_zzip_h" != x"yes" ; then
+  AC_MSG_ERROR([Can't find or can't use system zzip/zzip.h from zzip library])
+fi
+
+AC_SEARCH_LIBS([zzip_read], [zzip], [], [AC_MSG_ERROR([Can't find the zzip library.])])
 
 AC_ARG_ENABLE([zlib_zip],
               AS_HELP_STRING([--enable-zlib-zip],
Index: kaffe/config/config.h.in
diff -u kaffe/config/config.h.in:1.179 kaffe/config/config.h.in:1.180
--- kaffe/config/config.h.in:1.179	Sun Jan  6 19:05:16 2008
+++ kaffe/config/config.h.in	Mon Jan 21 01:04:36 2008
@@ -469,6 +469,9 @@
 /* Define to 1 if you have the <zlib.h> header file. */
 #undef HAVE_ZLIB_H
 
+/* Define to 1 if you have the <zzip/zzip.h> header file. */
+#undef HAVE_ZZIP_ZZIP_H
+
 /* Define if __va_copy is available */
 #undef HAVE__VA_COPY
 
Index: kaffe/kaffe/kaffeh/support.c
diff -u kaffe/kaffe/kaffeh/support.c:1.56 kaffe/kaffe/kaffeh/support.c:1.57
--- kaffe/kaffe/kaffeh/support.c:1.56	Wed Jan  2 20:34:01 2008
+++ kaffe/kaffe/kaffeh/support.c	Mon Jan 21 01:04:36 2008
@@ -782,8 +782,8 @@
 kaffeh_findClass(const char* nm)
 {
 	int fd;
-	jarFile* jfile;
-	jarEntry* jentry;
+	ZZIP_DIR* jfile;
+	ZZIP_FILE* jentry;
 	char superName[512];
 	struct stat sbuf;
 	char* start;
@@ -890,7 +890,7 @@
 				continue;
 			}
 
-			buf = getDataJarFile(jfile, jentry);
+			buf = getDataJarFile(jentry);
                         if (buf == NULL) {
 				closeJarFile(jfile);
 				continue;
@@ -899,7 +899,7 @@
 			classFileInit(&hand,
 				      buf,
 				      buf,
-				      jentry->uncompressedSize,
+				      getUncompressedSize(jentry),
 				      CP_ZIPFILE);
 
 			objectDepth++;
Index: kaffe/kaffe/kaffevm/baseClasses.c
diff -u kaffe/kaffe/kaffevm/baseClasses.c:1.79 kaffe/kaffe/kaffevm/baseClasses.c:1.80
--- kaffe/kaffe/kaffevm/baseClasses.c:1.79	Sun Jan  6 19:05:22 2008
+++ kaffe/kaffe/kaffevm/baseClasses.c	Mon Jan 21 01:04:36 2008
@@ -216,7 +216,6 @@
 	initLocking();
 	initEngine();
 	KaffeVM_initClassPool();
-	KaffeVM_initJarCache();
 
 	/* Initialise the string and utf8 systems */
 	stringInit();
Index: kaffe/kaffe/kaffevm/classpath.h
diff -u kaffe/kaffe/kaffevm/classpath.h:1.3 kaffe/kaffe/kaffevm/classpath.h:1.4
--- kaffe/kaffe/kaffevm/classpath.h:1.3	Wed May 29 22:58:44 2002
+++ kaffe/kaffe/kaffevm/classpath.h	Mon Jan 21 01:04:37 2008
@@ -11,6 +11,8 @@
 #ifndef __classpath_h
 #define __classpath_h
 
+#include <zzip/zzip.h>
+
 #define IS_ZIP(B) \
 	((B)[0] == 'P' && (B)[1] == 'K')
 #define	IS_SOFILE(B) \
@@ -20,7 +22,7 @@
         int     type;
         char*   path;
         union {
-                jarFile*        jar;
+                ZZIP_DIR*        jar;
                 struct {
                         int     loaded;
                 } sof;
Index: kaffe/kaffe/kaffevm/findInJar.c
diff -u kaffe/kaffe/kaffevm/findInJar.c:1.76 kaffe/kaffe/kaffevm/findInJar.c:1.77
--- kaffe/kaffe/kaffevm/findInJar.c:1.76	Sat Jan 19 15:13:39 2008
+++ kaffe/kaffe/kaffevm/findInJar.c	Mon Jan 21 01:04:37 2008
@@ -66,7 +66,7 @@
 
 #if defined(HANDLE_MANIFEST_CLASSPATH)
 static int isEntryInClasspath(const char*);
-static char* getManifestMainAttribute(jarFile*, const char*);
+static char* getManifestMainAttribute(ZZIP_DIR*, const char*);
 static void handleManifestClassPath (classpathEntry *);
 #endif
 
@@ -211,7 +211,7 @@
 		switch (ptr->type) {
 		case CP_ZIPFILE:
 		{
-			jarEntry* entry;
+		        ZZIP_FILE * entry;
 			unsigned char* data;
 
 DBG(CLASSLOOKUP,	dprintf("Opening JAR file %s for %s\n", ptr->path, cname); );
@@ -230,31 +230,27 @@
 			if (entry == 0) {
 				break;
 			}
-			if (entry->compressedSize == 0) {
+			if (getUncompressedSize(entry) == 0) {
 				hand->type = CP_NULLCLASS;
 				goto done;
 			}
-			data = getDataJarFile(ptr->u.jar, entry);
+			data = getDataJarFile(entry);
 			if (data == 0) {
 				postExceptionMessage(einfo,
 					JAVA_IO(IOException),
-					"Couldn't extract data from jar: %s",
-					ptr->u.jar->error);
+					"Couldn't extract data from jar %s",
+					ptr->path);
 				goto done;
 			}
 
 			classFileInit(hand,
 				      data,
 				      data,
-				      entry->uncompressedSize,
+				      getUncompressedSize(entry),
 				      CP_ZIPFILE);
 
 			if (Kaffe_JavaVMArgs.enableVerboseClassloading) {
-				dprintf("Loading %s(%s)", cname, ptr->path);
-				if (entry->compressionMethod != COMPRESSION_STORED) {
-					dprintf(" [compressed]");
-				}
-				dprintf("\n");
+				dprintf("Loading %s(%s)\n", cname, ptr->path);
 			}
 			goto done;
 		}
@@ -629,9 +625,9 @@
 
 
 static char*
-getManifestMainAttribute(jarFile* file, const char* attrName)
+getManifestMainAttribute(ZZIP_DIR* file, const char* attrName)
 {
-	jarEntry* mf;
+	ZZIP_FILE* mf;
 	char* mfdata;
 	char* attrEntry;
 	char* ret;
@@ -644,13 +640,13 @@
 		return (NULL);
 
 	/* Read it */
-	mfdata = (char*)getDataJarFile(file, mf);
+	mfdata = (char*)getDataJarFile(mf);
 	if (mfdata == 0)
 		return (NULL);
 
 	/* Look for the desired entry */
 	attrEntry = mfdata;
-	for (i = 0; i < mf->uncompressedSize; ++i) {
+	for (i = 0; i < getUncompressedSize(mf); ++i) {
 		/* Sun's jar, even under Linux, insists on terminating
 		   newlines with newline *and* carriage return */
 		if (mfdata[i] == '\n' || mfdata[i] == '\r') {
@@ -666,7 +662,7 @@
 					++attrEntry;
 
 				/* Now look for end of string. */
-				while (i < mf->uncompressedSize && attrEntry[i] != 0xd)
+				while (i < getUncompressedSize(mf) && attrEntry[i] != 0xd)
 					++i;
 
 				attrEntry[i] = '\0';
Index: kaffe/kaffe/kaffevm/jar.c
diff -u kaffe/kaffe/kaffevm/jar.c:1.44 kaffe/kaffe/kaffevm/jar.c:1.45
--- kaffe/kaffe/kaffevm/jar.c:1.44	Sat Jan 19 15:13:39 2008
+++ kaffe/kaffe/kaffevm/jar.c	Mon Jan 21 01:04:37 2008
@@ -2,1343 +2,56 @@
  * jar.c
  * Handle JAR input files.
  *
- * Copyright (c) 2000, 2001, 2002 The University of Utah and the Flux Group.
- * All rights reserved.
+ * Copyright (c) 2008
+ *   Dalibor Topic  <robilad at kaffe.org>
  *
- * This file is licensed under the terms of the GNU Public License.  
+ * This file is licensed under the terms of the GNU Public License.
+ * (v2 or any later version)
  * See the file "license.terms" for restrictions on redistribution 
  * of this file, and for a DISCLAIMER OF ALL WARRANTIES.
  */
 
-#include "config.h"
-#include "debug.h"
-#include "config-std.h"
-#include "config-io.h"
-#include "config-mem.h"
-#include "gtypes.h"
-#include "jsyscall.h"
+#include "kaffe/jmalloc.h"
 #include "jar.h"
-#include "gc.h"
-#include "stats.h"
-#include "files.h"
 
-#include <zlib.h>
-
-#if defined(HAVE_SYS_TYPES_H)
-#include <sys/types.h>
-#endif /* defined(HAVE_SYS_TYPES_H) */
-
-/* Undefine this to make jar files mutable during the vm lifetime */
-/* #define STATIC_JAR_FILES */
-
-#if defined(KAFFEH)
-#undef KAFFEVM_ABORT
-#define KAFFEVM_ABORT() abort()
-#undef  initStaticLock
-#define initStaticLock(x)
-#undef  staticLockIsInitialized
-#define staticLockIsInitialized(x)	1
-#undef  lockStaticMutex
-#undef  unlockStaticMutex
-#define unlockStaticMutex(x)
-#define lockStaticMutex(x)
-#undef  lockMutex
-#undef  unlockMutex
-#define lockMutex(x)
-#define unlockMutex(x)
-#undef destroyStaticLock
-#define destroyStaticLock(x)
-#endif
-
-/*
- * Error messages.
- */
-
-static const char * JAR_ERROR_BAD_CENTRAL_RECORD_SIGNATURE = "Bad central record signature";
-static const char * JAR_ERROR_BAD_SIGNATURE                = "Bad signature";
-static const char * JAR_ERROR_DECOMPRESSION_FAILED         = "Decompression failed";
-static const char * JAR_ERROR_ENTRY_COUNT_MISMATCH         = "Entry count doesn't match directory size";
-static const char * JAR_ERROR_IMPOSSIBLY_LARGE_DIRECTORY   = "Impossibly large directory size";
-static const char * JAR_ERROR_IO                           = "I/O error";
-static const char * JAR_ERROR_NO_END                       = "Failed to find end of JAR record";
-static const char * JAR_ERROR_OUT_OF_MEMORY                = "Out of memory";
-static const char * JAR_ERROR_TRUNCATED_FILE               = "Truncated file";
-static const char * JAR_ERROR_UNSUPPORTED_COMPRESSION      = "Unsupported compression in JAR file";
-
-/*
- * This constant determines how large is the block in which we must
- * look for the central directory end.
- */
-#define MAX_CENTRAL_END_DISPLACEMENT 65536
-
-/*
- * The jarCache keeps a list of all the jarFiles cached in the system.
- * However, since some JAR files are opened and closed frequently we don't
- * actively flush unused files from the system unless there are more than
- * JAR_FILE_CACHE_MAX jarFiles in the system.  This means we'll keep some
- * jarFiles in memory longer than we should but it helps to avoid the
- * constant opening/closing some java code does.
- */
-struct _jarCache {
-#if !defined(KAFFEH)
-	iStaticLock	lock;
-#endif
-	jarFile *files;
-#define JAR_FILE_CACHE_MAX 12
-	unsigned int count;
-};
-
-static struct _jarCache jarCache;
-
-/*
- * Hash a file name, the hash value is stored in what `hash' points to.
- */
-static unsigned int hashName(const char *name)
-{
-	unsigned int hash = 0;
-
-	assert(name != 0);
-	
-	for( hash = 0; *name; name++ )
-		hash = (31 * hash) + (*name);
-
-	return hash;
-}
-
-/*
- * Find a cached jarFile object.  If the file is found, it is returned and its
- * user count is incremented.
- *
- */
-static jarFile *findCachedJarFile(char *name)
+void *getDataJarFile(ZZIP_FILE *je)
 {
-	jarFile *curr, **prev, *retval = NULL;
+  zzip_ssize_t size = getUncompressedSize(je);
 
-	assert(name != NULL);
-	
-	lockStaticMutex(&jarCache.lock);
-	curr = jarCache.files;
-	prev = &jarCache.files;
-	while( curr && !retval )
-	{
-		assert(curr != NULL);
-		assert(curr->fileName != NULL);
-		
-		if( !strcmp(curr->fileName, name) )
-		{
-			/* unlink it... */
-			*prev = curr->next;
-			/* and move it to the front */
-			curr->next = jarCache.files;
-			jarCache.files = curr;
-			/* Return this node and increment the user count */
-			retval = curr;
-			retval->users++;
+  if (-1 != size) {
+    void * buf = KMALLOC(size);
+    if (NULL != buf)
+      if (-1 != zzip_read(je, buf, size))
+	return buf;
+  }
 
-DBG(JARFILES,  dprintf("Found cached jar file %s, %d users\n", retval->fileName, retval->users); );
-
-			assert(retval->users >= 1);
-		}
-		prev = &curr->next;
-		curr = curr->next;
-	}
-	unlockStaticMutex(&jarCache.lock);
-	return( retval );
+  return NULL;
 }
 
-/*
- * Free the contents of the entry table.
- */
-static void collectEntryTable(jarFile *jf)
+zzip_ssize_t getUncompressedSize(ZZIP_FILE * je) 
 {
-	assert(jf != 0);
-	assert(jf->users == 0);
-	
-	if( jf->table )
-	{
-		addToCounter(&jarmem, "vmmem-jar files",
-			     1, -(jlong)GCSIZEOF(jf->table));
-		gc_free(jf->table);
-		jf->table = NULL;
-	}
-}
+  /* Stores information about the file. */
+  ZZIP_STAT stat;
 
-/*
- * Free a jarFile structure and its child objects.
- */
-static void collectJarFile(jarFile *jf)
-{
-	assert(jf != NULL);
-	assert(jf->users == 0);
-	assert(!(jf->flags & JFF_CACHED));
-	
-	collectEntryTable(jf);
-	/* Make sure we free everything */
-	if( jf->fd != -1 )
-	{
-		/* Close the file */
-		KCLOSE(jf->fd);
-		jf->fd = -1;
-	}
-#ifdef HAVE_MMAP
-	if( jf->data != MAP_FAILED )
-	{
-#if !defined(NDEBUG)
-		/* Only define rc for use in assert */
-		int rc = 
-#endif /* defined(NDEBUG)  */
-		munmap(jf->data, jf->size);
+  if (-1 != zzip_fstat(je, &stat))
+    return stat.st_size;
 
-		assert(rc == 0);
-	}
-#endif
-	addToCounter(&jarmem, "vmmem-jar files", 1, -(jlong)GCSIZEOF(jf));
-	destroyStaticLock(&jf->lock);
-	gc_free(jf);
+  /* If entry can't be found, return -1. */
+  return -1;
 }
 
-/*
- * Cache a jarFile object, if the passed in object matches one in the cache
- * it will be thrown away, and the cached one is returned, with its user
- * count incremented.
- */
-static jarFile *cacheJarFile(jarFile *jf)
+ZZIP_DIR *openJarFile(zzip_char_t *name)
 {
-	jarFile *curr, **prev, **lru = NULL, *dead_jar = NULL, *retval = jf;
-	int already_cached = 0;
-
-	assert(jf != 0);
-	assert(!(jf->flags & JFF_CACHED));
-	
-	lockStaticMutex(&jarCache.lock);
-	/*
-	 * Walk the cache, if the file we're trying to cache already matches
-	 * one in the cache then we can just use it.  Otherwise, we need to
-	 * make room in the cache and continue.
-	 */
-	curr = jarCache.files;
-	prev = &jarCache.files;
-	while( curr && !already_cached )
-	{
-		assert(curr != NULL);
-		assert(curr->fileName != 0);
-		
-		/* Look for a matching JAR file */
-		if( !strcmp(curr->fileName, jf->fileName) )
-		{
-			/* Names match, check the dates */
-			if( curr->lastModified == jf->lastModified )
-			{
-				/*
-				 * They're the same, unlink it from the cache
-				 * so we can put it at the front later on.
-				 */
-				*prev = curr->next;
-				retval = curr;
-				retval->users++;
-
-DBG(JARFILES,  dprintf("Found cached jar file %s, %d users\n", retval->fileName, retval->users); );
-
-			}
-			else
-			{
-				/*
-				 * The modified time is different, purge our
-				 * cached version and proclaim this one the
-				 * canonical version.
-				 *
-				 * XXX Hmm...  Do we care how the two dates
-				 * relate?  Since this is the one now being
-				 * loaded from disk it "must" be the one
-				 * the user wants.  Bleh, too bad the
-				 * semantics don't seem to have been defined.
-				 */
-				*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
-			 * isn't going to change.
-			 */
-			already_cached = 1;
-
-			assert(retval->users >= 1);
-		}
-		else if( curr->users == 0 )
-		{
-			/*
-			 * Record the least recently used file in case we need
-			 * to eject someone.
-			 */
-			lru = prev;
-		}
-		prev = &curr->next;
-		curr = curr->next;
-	}
-	if( !already_cached )
-	{
-		/*
-		 * Cache the file if theres still room rather than ejecting
-		 * the lru or if theres no room and no lru.
-		 */
-		if( (jarCache.count < JAR_FILE_CACHE_MAX) || !lru )
-		{
-			/* Adding a new cache node */
-			jarCache.count++;
-		}
-		else
-		{
-			/*
-			 * Theres an unused jarFile, unlink the least
-			 * recently used one.
-			 */
-			dead_jar = *lru;
-			*lru = dead_jar->next;
-			dead_jar->flags &= ~JFF_CACHED;
-		}
-	}
-	/* Put the file at the start of the cache */
-	retval->next = jarCache.files;
-	jarCache.files = retval;
-	retval->flags |= JFF_CACHED;
-	unlockStaticMutex(&jarCache.lock);
-	/*
-	 * Free the redundant/excess files outside of the lock.
-	 *
-	 * NOTE: The dead_jar test must come first since the file could
-	 * already be cached and get superceded by a newer version of the
-	 * file.
-	 */
-	if( dead_jar )
-		collectJarFile(dead_jar);
-	else if( already_cached )
-	{
-		assert(jf->users == 1);
-		jf->users = 0;
-		collectJarFile(jf);
-	}
-
-	assert(retval != 0);
-	
-	return( retval );
+  return zzip_opendir(name);
 }
 
-/*
- * Remove a JAR file from the cache.
- */
-static void removeJarFile(jarFile *jf)
+void closeJarFile(ZZIP_DIR *jf)
 {
-	jarFile *curr, **prev;
-
-	assert(jf != NULL);
-
-	/* Make sure its actually in the cache. */
-	if( jf->flags & JFF_CACHED )
-	{
-		lockStaticMutex(&jarCache.lock);
-		{
-			curr = jarCache.files;
-			prev = &jarCache.files;
-			/* Find `jf' on the list and... */
-			while( curr != jf )
-			{
-				assert(curr != NULL);
-				
-				prev = &curr->next;
-				curr = curr->next;
-			}
-			/* unlink it */
-			*prev = curr->next;
-			jf->next = NULL;
-			jf->flags &= ~JFF_CACHED;
-			jarCache.count--;
-		}
-		unlockStaticMutex(&jarCache.lock);
-	}
+  zzip_closedir(jf);
 }
 
-void flushJarCache(void)
+ZZIP_FILE *lookupJarFile(ZZIP_DIR *jf, zzip_char_t *entry_name)
 {
-	jarFile **prev, *curr, *next;
-
-	lockStaticMutex(&jarCache.lock);
-	curr = jarCache.files;
-	prev = &jarCache.files;
-	while( curr )
-	{
-		next = curr->next;
-		if( curr->users == 0 )
-		{
-			*prev = next;
-			curr->flags &= ~JFF_CACHED;
-			collectJarFile(curr);
-		}
-		else
-		{
-			prev = &curr->next;
-		}
-		curr = next;
-	}
-	unlockStaticMutex(&jarCache.lock);
+  return zzip_file_open(jf, entry_name, 0);
 }
 
-/*
- * Convenient read function that operates on regular or mmap'ed files.
- * This also takes an `instantiation' function which is used to convert
- * any data into the proper byte order and alignment.
- */
-static int jarRead(jarFile *jf, uint8 *buf, size_t len,
-		   int (*ins_func)(uint8 *dest, uint8 *src))
-{
-	int retval = -1;
-

*** Patch too long, truncated ***




More information about the kaffe mailing list