This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
[BC] Patch: Cached class map
- From: Andrew Haley <aph at redhat dot com>
- To: java-patches at gcc dot gnu dot org, Tom Tromey <tromey at redhat dot com>
- Date: Thu, 28 Oct 2004 18:51:04 +0100
- Subject: [BC] Patch: Cached class map
- References: <m3oeioduic.fsf@localhost.localdomain><16767.62665.881475.791718@cuddles.cambridge.redhat.com><16767.63050.12354.298557@cuddles.cambridge.redhat.com><m3fz3zddat.fsf@localhost.localdomain>
This is one of the final planks of our binary compatibility work.
Many Java apps have their own class loaders, and they feed bytes to
myOwnClassLoader.defineClass(). Hitherto we've interpreted these,
but we really want to precompile them.
This patch creates a database of mappings from
digest(byte[] classfile) -> DSO
and at runtime, compileClass() first looks aside to the database to
see if we have a precompiled copy of a class. If we do, can load that
instead.
In practice, what this means is that you simply install your
application, precompile all the .jars into DSOs, and generate the map
database.
Like this:
gcj -shared -fPIC foo.jar -o foo.so -findirect-dispatch
jv-dbtool -n foo.gcjdb # create the database
jv-dbtool -a foo.gcjdb foo.jar foo.so # add foo.jar to the database
gij --cp foo.jar -Djava.precompiled.db=foo.db <whatever>
... and gij will use the precompiled versions of all the .class files.
The most important effect of all this is that we no longer need to
have special rhug versions of java libraries: we simply install the
standard jarfiles, create corresponding DSOs, and add them to the map.
There's an extra optimization possible here: if we know for certain
the jarfile from which the bytes came, we don't even need to do the
digest: was can create a direct mapping from .jar straight to the
precompiled file. But I haven't written that bit yet.
We need more docs for this, I know. I'm on it.
Andrew.
2004-10-28 Andrew Haley <aph@redhat.com>
* gnu/gcj/runtime/PersistentByteMap.java: New file.
* jv_dbtool.java: New file.
* Makefile.am (bin_PROGRAMS): Add jv-dbtool
(jv_dbtool_SOURCES, jv_dbtool_LDFLAGS, jv_dbtool_LINK)
(jv_dbtool_LDADD, jv_dbtool_DEPENDENCIES): New.
* Makefile.in: Regenerate,
* java/lang/VMCompiler.java: Import NoSuchAlgorithmException,
Enumeration, StringTokenizer, Vector, PersistentByteMap.
(precompiledMapFiles): New variable.
(VMCompiler static intializer): Read "gnu.gcj.precompiled.db" to
initialize precompiledMapFiles.
(compileClass): Look at the database of precompiled class files
before firing up gcj.
* gnu/gcj/runtime/VMClassLoader.java (findClass): Fix comment.
Index: Makefile.am
===================================================================
RCS file: /cvs/gcc/gcc/libjava/Makefile.am,v
retrieving revision 1.368.2.6
diff -c -2 -p -r1.368.2.6 Makefile.am
*** Makefile.am 12 Oct 2004 12:32:12 -0000 1.368.2.6
--- Makefile.am 28 Oct 2004 17:36:13 -0000
*************** propdir = $(libdir)
*** 118,122 ****
## For now, only on native systems. FIXME.
if NATIVE
! bin_PROGRAMS = jv-convert gij grmic grmiregistry
endif
--- 118,122 ----
## For now, only on native systems. FIXME.
if NATIVE
! bin_PROGRAMS = jv-convert gij grmic grmiregistry jv-dbtool
endif
*************** jv_convert_LDADD = -L$(here)/.libs libgc
*** 906,909 ****
--- 906,928 ----
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
+ ## with `-lgcj', but it must come first, otherwise the -L flags
+ ## brought in from libgcj.la would cause the install directories to be
+ ## searched before the build-tree ones, and we'd get errors because of
+ ## 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 =
## We need -nodefaultlibs because we want to avoid gcj's `-lgcj'. We
*************** gnu/gcj/runtime/JNIWeakRef.java \
*** 2473,2476 ****
--- 2492,2496 ----
gnu/gcj/runtime/MethodRef.java \
gnu/gcj/runtime/NameFinder.java \
+ gnu/gcj/runtime/PersistentByteMap.java \
gnu/gcj/runtime/SharedLibHelper.java \
gnu/gcj/runtime/SharedLibLoader.java \
Index: jv_dbtool.java
===================================================================
RCS file: jv_dbtool.java
diff -N jv_dbtool.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- jv_dbtool.java 28 Oct 2004 17:36:20 -0000
***************
*** 0 ****
--- 1,236 ----
+ /* 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;
+
+ 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);
+ try
+ {
+ PersistentByteMap b
+ = PersistentByteMap.emptyPersistentByteMap (s[1], 32749, 2000000);
+ }
+ 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);
+ 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 - 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();
+ }
+ }
+
\ No newline at end of file
Index: gnu/gcj/runtime/PersistentByteMap.java
===================================================================
RCS file: gnu/gcj/runtime/PersistentByteMap.java
diff -N gnu/gcj/runtime/PersistentByteMap.java
*** /dev/null 1 Jan 1970 00:00:00 -0000
--- gnu/gcj/runtime/PersistentByteMap.java 28 Oct 2004 17:36:21 -0000
***************
*** 0 ****
--- 1,484 ----
+ /* 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. */
+
+
+
+ /* A PersistentByteMap maps a byte array to another byte array. It
+ uses a file that does not need to be serialized but may be
+ memory-mapped and read in-place. So, even if there are many instances
+ of gcj applications running, the can share PersistentByteMaps.
+
+ The idea is to make searches as fast as possible: opening a
+ PersistentByteMap is cheap and search time doesn't grow with the
+ number of entries in the table. On the other hand, enumerating the
+ map is slow, but that is a relatively uncommon operation.
+
+ The main use of this class is to provide a way to map the
+ MessageDigest of a class file to the location of a DSO that contains
+ the compiled version of that class. It is up the the installer of an
+ application to keep the DSO up to date with the jar.
+
+ USAGE:
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ digest = md.digest(bytes);
+
+ PersistentByteMap map
+ = new PersistentByteMap
+ (fileName, PersistentByteMap.AccessMode.READ_ONLY);
+
+ byte[] soName = map.get(digest);
+ if (soName)
+ {
+ String SharedLibraryName = new String(soName);
+
+ BUGS/FEATURES:
+ remove() isn't written yet.
+
+ we can't change the capacity of a PersistentByteMap.
+
+ 0x12345678 is a bad choice for the magic number.
+
+ capacity is fixed once the map has been created.
+
+ We use linear probing to resolve collisions. It might be
+ better to use a scheme that results in fewer probes to
+ determine that an item isn't found. However, even when the
+ table is half full there are only on average 1.5 probes for a
+ successful search and 2.5 probes for an unsuccessful one.
+
+ We don't use unique strings. This wastes space.
+
+ capacity should probably be prime, but we don't check that.
+
+ we don't do any locking at all: adding to a PersistentByteMap
+ at runtime is possible, but it requires filesystem locks
+ around get(), put(), and remove().
+ */
+
+ package gnu.gcj.runtime;
+
+ import java.io.*;
+ import java.nio.*;
+ import java.nio.channels.*;
+ import java.util.*;
+ import java.security.MessageDigest;
+
+ public class PersistentByteMap
+ {
+ private MappedByteBuffer buf;
+
+ static private final int MAGIC = 0;
+ static private final int VERSION = 4;
+ static private final int CAPACITY = 8;
+ static private final int TABLE_BASE = 12;
+ static private final int STRING_BASE = 16;
+ static private final int STRING_SIZE = 20;
+ static private final int FILE_SIZE = 24;
+ static private final int ELEMENTS = 28;
+
+ static private final int INT_SIZE = 4;
+
+ static private final int TABLE_ENTRY_SIZE = 2 * INT_SIZE;
+
+ private int capacity; // number of entries
+ private int table_base; // offset from start of file, in bytes
+ private int string_base; // offset from start of file, in bytes
+ private int string_size; // size of string table, in bytes
+ private int file_size; // size of file, in bytes;
+ private int elements; // number of elements in table
+
+ private long length; // the length of the underlying file
+
+ static private final int UNUSED_ENTRY = -1;
+
+ static public final int KEYS = 0;
+ static public final int VALUES = 1;
+ static public final int ENTRIES = 2;
+
+ static final public class AccessMode
+ {
+ private final FileChannel.MapMode mapMode;
+
+ static
+ {
+ READ_ONLY = new AccessMode(FileChannel.MapMode.READ_ONLY);
+ READ_WRITE = new AccessMode(FileChannel.MapMode.READ_WRITE);
+ }
+
+ public static final AccessMode READ_ONLY;
+ public static final AccessMode READ_WRITE;
+
+ private AccessMode(FileChannel.MapMode mode)
+ {
+ this.mapMode = mode;
+ }
+ }
+
+ private PersistentByteMap()
+ {
+ }
+
+ public PersistentByteMap(String filename, AccessMode mode)
+ throws IOException
+ {
+ this(new File(filename), mode);
+ }
+
+ public PersistentByteMap(File f, AccessMode mode)
+ throws IOException
+ {
+ FileChannel fc;
+
+ if (mode == AccessMode.READ_ONLY)
+ {
+ FileInputStream fis = new FileInputStream(f);
+ fc = fis.getChannel();
+ }
+ else
+ {
+ RandomAccessFile fos = new RandomAccessFile(f, "rw");
+ fc = fos.getChannel();
+ }
+
+ length = fc.size();
+ buf = fc.map(mode.mapMode, 0, length);
+
+ int magic = getWord (MAGIC);
+ if (magic != 0x12345678)
+ throw new IllegalArgumentException(f.getName());
+
+ table_base = getWord (TABLE_BASE);
+ capacity = getWord (CAPACITY);
+ string_base = getWord (STRING_BASE);
+ string_size = getWord (STRING_SIZE);
+ file_size = getWord (FILE_SIZE);
+ elements = getWord (ELEMENTS);
+
+ // FIXME: Insert a bunch of sanity checks here
+ }
+
+ private void init (PersistentByteMap m, File f, int capacity, int strtabSize)
+ throws IOException
+ {
+ f.createNewFile();
+ RandomAccessFile raf = new RandomAccessFile(f, "rw");
+
+ this.capacity = capacity;
+ table_base = 64;
+ string_base = table_base + capacity * TABLE_ENTRY_SIZE;
+ string_size = 0;
+ file_size = string_base;
+ elements = 0;
+
+ int totalFileSize = string_base + strtabSize;
+
+ // Create the file; this rounds up the size of the file to a fixed
+ // number of 4k pages.
+ byte[] _4k = new byte[4096];
+ for (long i = 0; i < totalFileSize; i+= 4096)
+ raf.write(_4k);
+
+ FileChannel fc = raf.getChannel();
+ buf = fc.map(FileChannel.MapMode.READ_WRITE, 0, raf.length());
+
+ for (int i = 0; i < capacity; i++)
+ putKeyPos(UNUSED_ENTRY, i);
+
+ putWord(0x12345678, MAGIC);
+ putWord(0x01, VERSION);
+ putWord(capacity, CAPACITY);
+ putWord(table_base, TABLE_BASE);
+ putWord(string_base, STRING_BASE);
+ putWord(file_size, FILE_SIZE);
+ putWord(elements, ELEMENTS);
+ buf.force();
+ }
+
+ static public PersistentByteMap emptyPersistentByteMap(String filename,
+ int capacity, int strtabSize)
+ throws IOException
+ {
+ File f = new File(filename);
+ PersistentByteMap m = new PersistentByteMap();
+ m.init(m, f, capacity, strtabSize);
+ return m;
+ }
+
+ private int getWord (int index)
+ {
+ buf.position(index);
+ byte[] wordBuf = new byte[4];
+ buf.get(wordBuf);
+
+ int result = (int)wordBuf[0]&0xff;
+ result += ((int)wordBuf[1]&0xff) << 8;
+ result += ((int)wordBuf[2]&0xff) << 16;
+ result += ((int)wordBuf[3]&0xff) << 24;
+ return result;
+ }
+
+ private void putWord (int word, int index)
+ {
+ buf.position(index);
+ byte[] wordBuf = new byte[4];
+ wordBuf[0] = (byte)(word);
+ wordBuf[1] = (byte)(word >>> 8);
+ wordBuf[2] = (byte)(word >>> 16);
+ wordBuf[3] = (byte)(word >>> 24);
+ buf.put(wordBuf);
+ }
+
+ public Set entrySet()
+ {
+ return null;
+ }
+
+ private int getBucket(int n)
+ {
+ return table_base + (2*n * INT_SIZE);
+ }
+
+ private int getKeyPos(int n)
+ {
+ return getWord(getBucket(n));
+ }
+
+ private int getValuePos(int n)
+ {
+ return getWord(getBucket(n) + INT_SIZE);
+ }
+
+ private void putKeyPos(int index, int n)
+ {
+ putWord(index, getBucket(n));
+ }
+
+ private void putValuePos(int index, int n)
+ {
+ putWord(index, getBucket(n) + INT_SIZE);
+ }
+
+ private byte[] getBytes(int n)
+ {
+ int len = getWord (string_base + n);
+ int base = string_base + n + INT_SIZE;
+ byte[] key = new byte[len];
+ buf.position(base);
+ buf.get(key, 0, len);
+ return key;
+ }
+
+ private int hash (byte[] b)
+ {
+ // We assume that the message digest is evenly distributed, so we
+ // only need to use a few bytes of it as the hash function.
+ long hashIndex
+ = ((b[0]&0xffL)
+ + ((b[1]&0xffL)<<8)
+ + ((b[2]&0xffL)<<16)
+ + ((b[3]&0xffL)<<24));
+ long result = hashIndex % (long)capacity;
+ return (int)result;
+ }
+
+ public byte[] get(byte[] digest)
+ {
+ int hashIndex = hash(digest);
+
+ do
+ {
+ int k = getKeyPos(hashIndex);
+ if (k == UNUSED_ENTRY)
+ return null;
+
+ if (Arrays.equals ((byte[])digest, getBytes(k)))
+ return getBytes(getValuePos(hashIndex));
+
+ // Use linear probing to resolve hash collisions. This may
+ // not be theoretically as good as open addressing, but it has
+ // good cache behviour.
+ hashIndex++;
+ hashIndex %= capacity;
+ }
+ while (true);
+ }
+
+ public void put(byte[] digest, byte[] value)
+ throws IllegalAccessException
+ {
+ int hashIndex = hash(digest);
+
+ // With the the table 2/3 full there will be on average 2 probes
+ // for a successful search and 5 probes for an unsuccessful one.
+ if (elements >= capacity * 2/3)
+ throw new IllegalAccessException("Table Full: " + elements);
+
+ do
+ {
+ int k = getKeyPos(hashIndex);
+ if (k == UNUSED_ENTRY)
+ {
+ int newKey = addBytes(digest);
+ putKeyPos(newKey, hashIndex);
+ int newValue = addBytes(value);
+ putValuePos(newValue, hashIndex);
+ elements++;
+ putWord(elements, ELEMENTS);
+ return;
+ }
+ else if (Arrays.equals (digest, getBytes(k)))
+ {
+ int newValue = addBytes((byte[])value);
+ putValuePos(newValue, hashIndex);
+ return;
+ }
+
+ hashIndex++;
+ hashIndex %= capacity;
+ }
+ while (true);
+ }
+
+ private int addBytes (byte[] data)
+ throws IllegalAccessException
+ {
+ if (data.length + INT_SIZE >= this.length)
+ throw new IllegalAccessException("String table Full");
+
+ int extent = string_base+string_size;
+ int top = extent;
+ putWord(data.length, extent);
+ extent += INT_SIZE;
+ buf.position(extent);
+ buf.put(data, 0, data.length);
+ extent += data.length;
+ extent += INT_SIZE-1;
+ extent &= ~(INT_SIZE-1); // align
+ string_size = extent - string_base;
+ file_size = extent;
+ putWord (string_size, STRING_SIZE);
+ putWord (file_size, FILE_SIZE);
+
+ return top - string_base;
+ }
+
+ public Iterator iterator(int type)
+ {
+ return new HashIterator(type);
+ }
+
+ public int size()
+ {
+ return elements;
+ }
+
+ public int capacity()
+ {
+ return capacity;
+ }
+
+ private final class HashIterator implements Iterator
+ {
+ /** Current index in the physical hash table. */
+
+ private int idx;
+ private int count;
+ private final int type;
+
+ /**
+ * Construct a new HashIterator with the supplied type.
+ * @param type {@link #KEYS}, {@link #VALUES}, or {@link #ENTRIES}
+ */
+ HashIterator(int type)
+ {
+ this.type = type;
+ count = elements;
+ idx = 0;
+ }
+
+ /**
+ * Returns true if the Iterator has more elements.
+ * @return true if there are more elements
+ * @throws ConcurrentModificationException if the HashMap was modified
+ */
+ public boolean hasNext()
+ {
+ return count > 0;
+ }
+
+ /**
+ * Returns the next element in the Iterator's sequential view.
+ * @return the next element
+ * @throws ConcurrentModificationException if the HashMap was modified
+ * @throws NoSuchElementException if there is none
+ */
+ public Object next()
+ {
+ count--;
+ for (int i = idx; i < capacity; i++)
+ if (getKeyPos(i) != UNUSED_ENTRY)
+ {
+ idx = i+1;
+ if (type == VALUES)
+ return getBytes(getValuePos(i));
+ if (type == KEYS)
+ return getBytes(getKeyPos(i));
+ return new MapEntry(i,
+ getBytes(getKeyPos(i)),
+ getBytes(getValuePos(i)));
+ }
+ return null;
+ }
+
+ /**
+ * Remove from the underlying collection the last element returned
+ * by next (optional operation). This method can be called only
+ * once after each call to <code>next()</code>. It does not affect
+ * what will be returned by subsequent calls to next.
+ *
+ * @throws IllegalStateException if next has not yet been called
+ * or remove has already been called since the last call
+ * to next.
+ * @throws UnsupportedOperationException if this Iterator does not
+ * support the remove operation.
+ */
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+ }
+
+ static public final class MapEntry
+ {
+ private final Object key;
+ private final Object value;
+ private final int bucket;
+
+ public MapEntry(int bucket, Object newKey, Object newValue)
+ {
+ this.key = newKey;
+ this.value = newValue;
+ this.bucket = bucket;
+ }
+
+ public final Object getKey()
+ {
+ return key;
+ }
+
+ public final Object getValue()
+ {
+ return value;
+ }
+
+ public final int getBucket()
+ {
+ return bucket;
+ }
+ }
+ }
Index: gnu/gcj/runtime/VMClassLoader.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/gnu/gcj/runtime/VMClassLoader.java,v
retrieving revision 1.12.10.1
diff -c -2 -p -r1.12.10.1 VMClassLoader.java
*** gnu/gcj/runtime/VMClassLoader.java 12 Oct 2004 14:52:19 -0000 1.12.10.1
--- gnu/gcj/runtime/VMClassLoader.java 28 Oct 2004 17:36:21 -0000
*************** public final class VMClassLoader extends
*** 106,110 ****
* will only search existing linked-in classes. This will make
* the default implementation of loadClass (in ClassLoader) work right.
! * The implementation of this method is in java/lang/natClassLoader.cc.
*/
protected native Class findClass(String name)
--- 106,111 ----
* will only search existing linked-in classes. This will make
* the default implementation of loadClass (in ClassLoader) work right.
! * The implementation of this method is in
! * gnu/gcj/runtime/natVMClassLoader.cc.
*/
protected native Class findClass(String name)
Index: java/lang/VMCompiler.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/Attic/VMCompiler.java,v
retrieving revision 1.1.2.2
diff -c -2 -p -r1.1.2.2 VMCompiler.java
*** java/lang/VMCompiler.java 18 Aug 2004 16:18:42 -0000 1.1.2.2
--- java/lang/VMCompiler.java 28 Oct 2004 17:36:22 -0000
*************** import java.io.InputStreamReader;
*** 43,49 ****
--- 43,54 ----
import java.security.MessageDigest;
import java.security.ProtectionDomain;
+ import java.security.NoSuchAlgorithmException;
import java.util.WeakHashMap;
import java.util.HashSet;
+ import java.util.Enumeration;
+ import java.util.StringTokenizer;
+ import java.util.Vector;
import gnu.gcj.runtime.SharedLibHelper;
+ import gnu.gcj.runtime.PersistentByteMap;
/**
*************** final class VMCompiler
*** 73,76 ****
--- 78,83 ----
private static WeakHashMap sharedHelperMap = new WeakHashMap();
+ private static Vector precompiledMapFiles;
+
static
{
*************** final class VMCompiler
*** 90,93 ****
--- 97,130 ----
canUseCompiler = true;
}
+
+ String prop = System.getProperty ("gnu.gcj.precompiled.db");
+ if (prop != null)
+ {
+ precompiledMapFiles = new Vector();
+ // Add the
+ StringTokenizer st
+ = new StringTokenizer (prop,
+ System.getProperty ("path.separator", ":"));
+ {
+ while (st.hasMoreElements ())
+ {
+ String e = st.nextToken ();
+ try
+ {
+ PersistentByteMap map
+ = new PersistentByteMap
+ (e, PersistentByteMap.AccessMode.READ_ONLY);
+ precompiledMapFiles.add(map);
+ }
+ catch (IllegalArgumentException _)
+ {
+ // Not a map file
+ }
+ catch (java.io.IOException _)
+ {
+ }
+ }
+ }
+ }
}
*************** final class VMCompiler
*** 130,133 ****
--- 167,208 ----
ProtectionDomain domain)
{
+ if (precompiledMapFiles == null
+ && (! useCompiler || ! canUseCompiler))
+ return null;
+
+ byte digest[];
+
+ try
+ {
+ MessageDigest md = MessageDigest.getInstance("MD5");
+ digest = md.digest(data);
+ }
+ catch (NoSuchAlgorithmException _)
+ {
+ return null;
+ }
+
+ // We use lookaside cache files to determine whether these bytes
+ // correspond to a class file that is part of a precompiled DSO.
+ if (precompiledMapFiles != null)
+ {
+ try
+ {
+ Enumeration elements = precompiledMapFiles.elements();
+ while (elements.hasMoreElements())
+ {
+ PersistentByteMap map = (PersistentByteMap)elements.nextElement();
+ byte[] soName = map.get(digest);
+ if (soName != null)
+ return loadSharedLibrary(loader,
+ new String(soName),
+ domain, name);
+ }
+ }
+ catch (Exception _)
+ {
+ }
+ }
+
if (! useCompiler || ! canUseCompiler)
return null;
*************** final class VMCompiler
*** 138,143 ****
// bytes in DATA really is the class named in NAME. Make
// sure it's not "java.*".
- MessageDigest md = MessageDigest.getInstance("MD5");
- byte digest[] = md.digest(data);
StringBuffer hexBytes = new StringBuffer(gcjJitTmpdir);
hexBytes.append(File.separatorChar);
--- 213,216 ----