This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[BC] Patch: Cached class map
In response to justfied criticism (cf. Cultural Revolution passim) I
have made a few changes.
Andrew.
2004-11-05 Andrew Haley <aph@redhat.com>
* Makefile.am: Move jv_dbtool.java to
gnu/gcj/tools/gcj_dbtool/Main.java.
(bin_PROGRAMS): Rename jv-dbtool to gcj-dbtool.
* Makefile.in: Rebuild.
* java/lang/VMCompiler.java: Rename property
"gnu.gcj.precompiled.db" to "gnu.gcj.precompiled.db.path".
* gnu/gcj/tools/gcj_dbtool/Main.java: moved here from
jv_dbtool.java.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.368.2.7
diff -c -2 -p -r1.368.2.7 Makefile.am
*** Makefile.am 28 Oct 2004 18:08:24 -0000 1.368.2.7
--- Makefile.am 5 Nov 2004 13:50:26 -0000
*************** propdir = $(libdir)
*** 118,122 ****
## For now, only on native systems. FIXME.
if NATIVE
! bin_PROGRAMS = jv-convert gij grmic grmiregistry jv-dbtool
endif
--- 118,122 ----
## For now, only on native systems. FIXME.
if NATIVE
! bin_PROGRAMS = jv-convert gij grmic grmiregistry gcj-dbtool
endif
*************** jv_convert_LDADD = -L$(here)/.libs libgc
*** 906,916 ****
jv_convert_DEPENDENCIES = libgcj.la libgcj.spec
! jv_dbtool_SOURCES = jv_dbtool.java
## We need -nodefaultlibs because we want to avoid gcj's `-lgcj'. We
## need this because we are explicitly using libtool to link using the
## `.la' file.
! jv_dbtool_LDFLAGS = --main=jv_dbtool \
-rpath $(toolexeclibdir) -shared-libgcc $(THREADLDFLAGS)
! jv_dbtool_LINK = $(GCJLINK)
## We don't explicitly link in the libraries we need; libgcj.la brings
## in all dependencies. We need the -L so that gcj can find libgcj
--- 906,916 ----
jv_convert_DEPENDENCIES = libgcj.la libgcj.spec
! gcj_dbtool_SOURCES = gnu/gcj/tools/gcj_dbtool/Main.java
## We need -nodefaultlibs because we want to avoid gcj's `-lgcj'. We
## need this because we are explicitly using libtool to link using the
## `.la' file.
! gcj_dbtool_LDFLAGS = --main=gnu.gcj.tools.gcj_dbtool.Main \
-rpath $(toolexeclibdir) -shared-libgcc $(THREADLDFLAGS)
! gcj_dbtool_LINK = $(GCJLINK)
## We don't explicitly link in the libraries we need; libgcj.la brings
## in all dependencies. We need the -L so that gcj can find libgcj
*************** jv_dbtool_LINK = $(GCJLINK)
*** 920,927 ****
## different libraries with the same SONAME from picky linkers such as
## Solaris'. FIXME: should be _libs on some systems.
! jv_dbtool_LDADD = -L$(here)/.libs libgcj.la
## Depend on the spec file to make sure it is up to date before
## linking this program.
! jv_dbtool_DEPENDENCIES = libgcj.la libgcj.spec
gij_SOURCES =
--- 920,927 ----
## different libraries with the same SONAME from picky linkers such as
## Solaris'. FIXME: should be _libs on some systems.
! gcj_dbtool_LDADD = -L$(here)/.libs libgcj.la
## Depend on the spec file to make sure it is up to date before
## linking this program.
! gcj_dbtool_DEPENDENCIES = libgcj.la libgcj.spec
gij_SOURCES =
Index: jv_dbtool.java
===================================================================
RCS file: jv_dbtool.java
diff -N jv_dbtool.java
*** jv_dbtool.java 5 Nov 2004 13:19:17 -0000 1.1.2.4
--- /dev/null 1 Jan 1970 00:00:00 -0000
***************
*** 1,270 ****
- /* Copyright (C) 2004 Free Software Foundation
-
- This file is part of libgcj.
-
- This software is copyrighted work licensed under the terms of the
- Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
- details. */
-
-
- import gnu.gcj.runtime.PersistentByteMap;
- import java.io.*;
- import java.util.*;
- import java.util.jar.*;
- import java.security.MessageDigest;
- import java.math.BigInteger;
-
- public class jv_dbtool
- {
- public static void main (String[] s)
- {
- insist (s.length >= 1);
- if (s[0].equals("-v"))
- {
- insist (s.length == 1);
- System.out.println("jv-dbtool ("
- + System.getProperty("java.vm.name")
- + ") "
- + System.getProperty("java.vm.version"));
- System.out.println();
- System.out.println("Copyright 2004 Free Software Foundation, Inc.");
- System.out.println("This is free software; see the source for copying conditions. There is NO");
- System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
- return;
- }
-
- if (s[0].equals("-n"))
- {
- insist (s.length >= 2 && s.length <= 3);
-
- int capacity = 32749;
-
- if (s.length == 3)
- {
- // The user has explicitly provided a size for the table.
- // We're going to make that size prime. This isn't
- // strictly necessary but it can't hurt.
-
- BigInteger size = new BigInteger(s[2], 10);
- BigInteger two = BigInteger.ONE.add(BigInteger.ONE);
-
- if (size.getLowestSetBit() != 0) // A hard way to say isEven()
- size = size.add(BigInteger.ONE);
-
- while (! size.isProbablePrime(10))
- size = size.add(two);
-
- capacity = size.intValue();
-
- if (capacity <= 2)
- {
- usage();
- System.exit(1);
- }
- }
-
- try
- {
- PersistentByteMap b
- = PersistentByteMap.emptyPersistentByteMap (s[1], capacity, capacity*64);
- }
- catch (Exception e)
- {
- System.err.println ("error: could not create "
- + s[1] + ": " + e.toString());
- System.exit(2);
- }
- return;
- }
-
- if (s[0].equals("-a"))
- {
- try
- {
- insist (s.length == 4);
- File jar = new File(s[2]);
- PersistentByteMap b
- = new PersistentByteMap(new File(s[1]),
- PersistentByteMap.AccessMode.READ_WRITE);
- File soFile = new File(s[3]);
- if (! soFile.isFile())
- throw new IllegalArgumentException(s[3] + " is not a file");
-
- addJar(jar, b, soFile);
- }
- catch (Exception e)
- {
- System.err.println ("error: could not update " + s[1]
- + ": " + e.toString());
- System.exit(2);
- }
- return;
- }
-
- if (s[0].equals("-t"))
- {
- try
- {
- insist (s.length == 2);
- PersistentByteMap b
- = new PersistentByteMap(new File(s[1]),
- PersistentByteMap.AccessMode.READ_ONLY);
- Iterator iterator = b.iterator(PersistentByteMap.ENTRIES);
-
- while (iterator.hasNext())
- {
- PersistentByteMap.MapEntry entry
- = (PersistentByteMap.MapEntry)iterator.next();
- byte[] key = (byte[])entry.getKey();
- byte[] value = (byte[])b.get(key);
- if (! Arrays.equals (value, (byte[])entry.getValue()))
- {
- String err
- = ("Key " + bytesToString(key) + " at bucket "
- + entry.getBucket());
-
- throw new RuntimeException(err);
- }
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.exit(3);
- }
- return;
- }
-
- if (s[0].equals("-l"))
- {
- insist (s.length == 2);
- try
- {
- PersistentByteMap b
- = new PersistentByteMap(new File(s[1]),
- PersistentByteMap.AccessMode.READ_ONLY);
-
- System.out.println ("Capacity: " + b.capacity());
- System.out.println ("Size: " + b.size());
- System.out.println ();
-
- System.out.println ("Elements: ");
- Iterator iterator = b.iterator(PersistentByteMap.ENTRIES);
-
- while (iterator.hasNext())
- {
- PersistentByteMap.MapEntry entry
- = (PersistentByteMap.MapEntry)iterator.next();
- byte[] digest = (byte[])entry.getKey();
- System.out.print ("[" + entry.getBucket() + "] "
- + bytesToString(digest)
- + " -> ");
- System.out.println (new String((byte[])entry.getValue()));
- }
- }
- catch (Exception e)
- {
- System.err.println ("error: could not list "
- + s[1] + ": " + e.toString());
- System.exit(2);
- }
- return;
- }
-
- if (s[0].equals("-d"))
- {
- insist (s.length == 2);
- try
- {
- MessageDigest md = MessageDigest.getInstance("MD5");
- PersistentByteMap b
- = new PersistentByteMap(new File(s[1]),
- PersistentByteMap.AccessMode.READ_WRITE);
- int N = b.capacity();
- byte[] bytes = new byte[1];
- byte digest[] = md.digest(bytes);
- for (int i = 0; i < N; i++)
- {
- digest = md.digest(digest);
- b.put(digest, digest);
- }
- }
- catch (Exception e)
- {
- e.printStackTrace();
- System.exit(3);
- }
- return;
- }
-
- usage();
- System.exit(1);
- }
-
- private static void insist(boolean ok)
- {
- if (! ok)
- {
- usage();
- System.exit(1);
- }
- }
-
- private static void usage()
- {
- System.err.println
- ("jv-dbtool: Manipulate gcj map database files\n"
- + "\n"
- + " Usage: \n"
- + " jv-dbtool -n file.gcjdb [size] - Create a new gcj map database\n"
- + " jv-dbtool -a file.gcjdb file.jar file.so\n"
- + " - Add the contents of file.jar to the database\n"
- + " jv-dbtool -t file.gcjdb - Test a gcj map database\n"
- + " jv-dbtool -l file.gcjdb - List a gcj map database\n");
- }
-
-
- private static void addJar(File f, PersistentByteMap b, File soFile)
- throws Exception
- {
- MessageDigest md = MessageDigest.getInstance("MD5");
-
- JarFile jar = new JarFile (f);
- Enumeration entries = jar.entries();
-
- while (entries.hasMoreElements())
- {
- JarEntry classfile = (JarEntry)entries.nextElement();
- if (classfile.getName().endsWith(".class"))
- {
- InputStream str = jar.getInputStream(classfile);
- long length = classfile.getSize();
- if (length == -1)
- throw new EOFException();
-
- byte[] data = new byte[length];
- int pos = 0;
- while (length - pos > 0)
- {
- int len = str.read(data, pos, (int)(length - pos));
- if (len == -1)
- throw new EOFException("Not enough data reading from: "
- + classfile.getName());
- pos += len;
- }
- b.put(md.digest(data),
- soFile.getCanonicalPath().getBytes());
- }
- }
- }
-
- static String bytesToString(byte[] b)
- {
- StringBuffer hexBytes = new StringBuffer();
- int length = b.length;
- for (int i = 0; i < length; ++i)
- hexBytes.append(Integer.toHexString(b[i] & 0xff));
- return hexBytes.toString();
- }
- }
-
--- 0 ----
Index: java/lang/VMCompiler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Attic/VMCompiler.java,v
retrieving revision 1.1.2.3
diff -c -2 -p -r1.1.2.3 VMCompiler.java
*** java/lang/VMCompiler.java 28 Oct 2004 18:08:40 -0000 1.1.2.3
--- java/lang/VMCompiler.java 5 Nov 2004 13:50:26 -0000
*************** final class VMCompiler
*** 98,102 ****
}
! String prop = System.getProperty ("gnu.gcj.precompiled.db");
if (prop != null)
{
--- 98,102 ----
}
! String prop = System.getProperty ("gnu.gcj.precompiled.db.path");
if (prop != null)
{
Index: gnu/gcj/tools/gcj_dbtool/Main.java
===================================================================
RCS file: gnu/gcj/tools/gcj_dbtool/Main.java
diff -N gnu/gcj/tools/gcj_dbtool/Main.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gnu/gcj/tools/gcj_dbtool/Main.java 5 Nov 2004 13:50:26 -0000
***************
*** 0 ****
--- 1,272 ----
+ /* Copyright (C) 2004 Free Software Foundation
+
+ This file is part of libgcj.
+
+ This software is copyrighted work licensed under the terms of the
+ Libgcj License. Please consult the file "LIBGCJ_LICENSE" for
+ details. */
+
+ package gnu.gcj.tools.gcj_dbtool;
+
+
+ import gnu.gcj.runtime.PersistentByteMap;
+ import java.io.*;
+ import java.util.*;
+ import java.util.jar.*;
+ import java.security.MessageDigest;
+ import java.math.BigInteger;
+
+ public class Main
+ {
+ public static void main (String[] s)
+ {
+ insist (s.length >= 1);
+ if (s[0].equals("-v"))
+ {
+ insist (s.length == 1);
+ System.out.println("jv-dbtool ("
+ + System.getProperty("java.vm.name")
+ + ") "
+ + System.getProperty("java.vm.version"));
+ System.out.println();
+ System.out.println("Copyright 2004 Free Software Foundation, Inc.");
+ System.out.println("This is free software; see the source for copying conditions. There is NO");
+ System.out.println("warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.");
+ return;
+ }
+
+ if (s[0].equals("-n"))
+ {
+ insist (s.length >= 2 && s.length <= 3);
+
+ int capacity = 32749;
+
+ if (s.length == 3)
+ {
+ // The user has explicitly provided a size for the table.
+ // We're going to make that size prime. This isn't
+ // strictly necessary but it can't hurt.
+
+ BigInteger size = new BigInteger(s[2], 10);
+ BigInteger two = BigInteger.ONE.add(BigInteger.ONE);
+
+ if (size.getLowestSetBit() != 0) // A hard way to say isEven()
+ size = size.add(BigInteger.ONE);
+
+ while (! size.isProbablePrime(10))
+ size = size.add(two);
+
+ capacity = size.intValue();
+
+ if (capacity <= 2)
+ {
+ usage();
+ System.exit(1);
+ }
+ }
+
+ try
+ {
+ PersistentByteMap b
+ = PersistentByteMap.emptyPersistentByteMap (s[1], capacity, capacity*64);
+ }
+ catch (Exception e)
+ {
+ System.err.println ("error: could not create "
+ + s[1] + ": " + e.toString());
+ System.exit(2);
+ }
+ return;
+ }
+
+ if (s[0].equals("-a"))
+ {
+ try
+ {
+ insist (s.length == 4);
+ File jar = new File(s[2]);
+ PersistentByteMap b
+ = new PersistentByteMap(new File(s[1]),
+ PersistentByteMap.AccessMode.READ_WRITE);
+ File soFile = new File(s[3]);
+ if (! soFile.isFile())
+ throw new IllegalArgumentException(s[3] + " is not a file");
+
+ addJar(jar, b, soFile);
+ }
+ catch (Exception e)
+ {
+ System.err.println ("error: could not update " + s[1]
+ + ": " + e.toString());
+ System.exit(2);
+ }
+ return;
+ }
+
+ if (s[0].equals("-t"))
+ {
+ try
+ {
+ insist (s.length == 2);
+ PersistentByteMap b
+ = new PersistentByteMap(new File(s[1]),
+ PersistentByteMap.AccessMode.READ_ONLY);
+ Iterator iterator = b.iterator(PersistentByteMap.ENTRIES);
+
+ while (iterator.hasNext())
+ {
+ PersistentByteMap.MapEntry entry
+ = (PersistentByteMap.MapEntry)iterator.next();
+ byte[] key = (byte[])entry.getKey();
+ byte[] value = (byte[])b.get(key);
+ if (! Arrays.equals (value, (byte[])entry.getValue()))
+ {
+ String err
+ = ("Key " + bytesToString(key) + " at bucket "
+ + entry.getBucket());
+
+ throw new RuntimeException(err);
+ }
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.exit(3);
+ }
+ return;
+ }
+
+ if (s[0].equals("-l"))
+ {
+ insist (s.length == 2);
+ try
+ {
+ PersistentByteMap b
+ = new PersistentByteMap(new File(s[1]),
+ PersistentByteMap.AccessMode.READ_ONLY);
+
+ System.out.println ("Capacity: " + b.capacity());
+ System.out.println ("Size: " + b.size());
+ System.out.println ();
+
+ System.out.println ("Elements: ");
+ Iterator iterator = b.iterator(PersistentByteMap.ENTRIES);
+
+ while (iterator.hasNext())
+ {
+ PersistentByteMap.MapEntry entry
+ = (PersistentByteMap.MapEntry)iterator.next();
+ byte[] digest = (byte[])entry.getKey();
+ System.out.print ("[" + entry.getBucket() + "] "
+ + bytesToString(digest)
+ + " -> ");
+ System.out.println (new String((byte[])entry.getValue()));
+ }
+ }
+ catch (Exception e)
+ {
+ System.err.println ("error: could not list "
+ + s[1] + ": " + e.toString());
+ System.exit(2);
+ }
+ return;
+ }
+
+ if (s[0].equals("-d"))
+ {
+ insist (s.length == 2);
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ PersistentByteMap b
+ = new PersistentByteMap(new File(s[1]),
+ PersistentByteMap.AccessMode.READ_WRITE);
+ int N = b.capacity();
+ byte[] bytes = new byte[1];
+ byte digest[] = md.digest(bytes);
+ for (int i = 0; i < N; i++)
+ {
+ digest = md.digest(digest);
+ b.put(digest, digest);
+ }
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace();
+ System.exit(3);
+ }
+ return;
+ }
+
+ usage();
+ System.exit(1);
+ }
+
+ private static void insist(boolean ok)
+ {
+ if (! ok)
+ {
+ usage();
+ System.exit(1);
+ }
+ }
+
+ private static void usage()
+ {
+ System.err.println
+ ("jv-dbtool: Manipulate gcj map database files\n"
+ + "\n"
+ + " Usage: \n"
+ + " jv-dbtool -n file.gcjdb [size] - Create a new gcj map database\n"
+ + " jv-dbtool -a file.gcjdb file.jar file.so\n"
+ + " - Add the contents of file.jar to the database\n"
+ + " jv-dbtool -t file.gcjdb - Test a gcj map database\n"
+ + " jv-dbtool -l file.gcjdb - List a gcj map database\n");
+ }
+
+
+ private static void addJar(File f, PersistentByteMap b, File soFile)
+ throws Exception
+ {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+
+ JarFile jar = new JarFile (f);
+ Enumeration entries = jar.entries();
+
+ while (entries.hasMoreElements())
+ {
+ JarEntry classfile = (JarEntry)entries.nextElement();
+ if (classfile.getName().endsWith(".class"))
+ {
+ InputStream str = jar.getInputStream(classfile);
+ long length = classfile.getSize();
+ if (length == -1)
+ throw new EOFException();
+
+ byte[] data = new byte[length];
+ int pos = 0;
+ while (length - pos > 0)
+ {
+ int len = str.read(data, pos, (int)(length - pos));
+ if (len == -1)
+ throw new EOFException("Not enough data reading from: "
+ + classfile.getName());
+ pos += len;
+ }
+ b.put(md.digest(data),
+ soFile.getCanonicalPath().getBytes());
+ }
+ }
+ }
+
+ static String bytesToString(byte[] b)
+ {
+ StringBuffer hexBytes = new StringBuffer();
+ int length = b.length;
+ for (int i = 0; i < length; ++i)
+ hexBytes.append(Integer.toHexString(b[i] & 0xff));
+ return hexBytes.toString();
+ }
+ }
+