[kaffe] Some optimization patches

Jukka Santala jsantala at morphine.tml.hut.fi
Thu Sep 12 04:06:25 PDT 2002


Don't recall if I posted any fo these patches before summer vacation, but
I'm posting them now anyway as a part of the "autumn cleanup" ;)

kaffe-donwulff-sanitychk.patch

	Turns off the so-called "Sanity check" code from the VM core by
default. These checks are no doubt useful, if something goes drastically
wrong, but considering things don't usually go wrong (that way), they
instead drastically slow down the VM core. Most users want to run with
these disabled; the only reason to have them turned on is if you're
porting or doing other critical VM rework, and want to catch problems as
soon as they occur. If you want, you could replace SCHK(s) macro with one
to check a debug-flag and execute the check dependent on that, but it
would still add some non-trivial work to the core, so I propose using this
patch as is.

kaffe-donwulff-hashmap.patch

	It was previously agreed that we do not want to go the way of
invidual optimization-touches like this. However due to the whole point of
hash-tables being that they're expected to be fast, and because our
application (XML/XSL processing) uses them so heavily this change alone
makes arguable difference, I'm posting this patch here to at least make it
available to people with similiar interests. As the comment says, it folds
in two very small convenience methods into the HashMap.find(Object) call,
which is crucial method for most hashtable operations.

kaffe-donwulff-vertypo.patch

	No doubt a very important patch with far-ranging consequences ;)

 -Jukka Santala
-------------- next part --------------
Index: kaffe/kaffe/version.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffe/version.c,v
retrieving revision 1.4
diff -u -r1.4 version.c
--- kaffe/kaffe/version.c	29 Jun 2002 01:14:19 -0000	1.4
+++ kaffe/kaffe/version.c	12 Sep 2002 10:50:18 -0000
@@ -30,7 +30,7 @@
 		versionfd = stderr;
 	fprintf(versionfd, "Kaffe Virtual Machine\n\n");
 	fprintf(versionfd, "Copyright (c) 1996-2002 Kaffe.org project contributors (please see\n");
-	fprintf(versionfd, "  the source code for a full list of contributors).  All rights reservced.\n");
+	fprintf(versionfd, "  the source code for a full list of contributors).  All rights reserved.\n");
 	fprintf(versionfd, "Portions Copyright (c) 1996-2002 Transvirtual Technologies, Inc.\n\n");
 
 	fprintf(versionfd, "The Kaffe virtual machine is free software, licensed under the terms of\n");
-------------- next part --------------
Index: kaffe/kaffevm/jit3/machine.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jit3/machine.c,v
retrieving revision 1.28
diff -u -r1.28 machine.c
--- kaffe/kaffevm/jit3/machine.c	20 Jun 2001 22:50:01 -0000	1.28
+++ kaffe/kaffevm/jit3/machine.c	12 Sep 2002 10:50:18 -0000
@@ -12,7 +12,7 @@
  * of this file.
  */
 
-#define SCHK(s) s
+#define SCHK(s)
 #define	SUSE(s)
 
 #include "config.h"
Index: kaffe/kaffevm/jit3/registers.c
===================================================================
RCS file: /cvs/kaffe/kaffe/kaffe/kaffevm/jit3/registers.c,v
retrieving revision 1.9
diff -u -r1.9 registers.c
--- kaffe/kaffevm/jit3/registers.c	20 Jun 2001 22:50:01 -0000	1.9
+++ kaffe/kaffevm/jit3/registers.c	12 Sep 2002 10:50:18 -0000
@@ -8,6 +8,8 @@
  * of this file.
  */
 
+#define SCHK(s)
+
 #include "config.h"
 #include "config-std.h"
 #include "config-mem.h"
@@ -264,7 +266,7 @@
 	int needreload;
 	int oldmod;
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	reg = slot->regno;
 	regi = &reginfo[reg];
@@ -319,7 +321,7 @@
 		reg = allocRegister(idealreg, type);
 		clobberRegister(reg);
 
-		sanityCheck();
+SCHK(		sanityCheck();					)
 
 		/* If we're modifying this slot, clear the modified bits
 		 * so when we clobber it, it won't get written back.
@@ -373,7 +375,7 @@
 			}
 		}
 
-		sanityCheck();
+SCHK(		sanityCheck();					)
 
 		/* Setup the new slot/register mapping and delete old one */
 		regi = &reginfo[reg];
@@ -401,7 +403,7 @@
 		slot_invalidate(slot);
 	}
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	/* Return register */
 	return (regi->regno);
@@ -419,7 +421,7 @@
 	SlotData* nslot;
 	kregs* regi;
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	if (reg != NOREG) {
 		regi = &reginfo[reg];
@@ -441,7 +443,7 @@
 		regi->used = ++usecnt;
 	}
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 }
 
 /*
@@ -453,7 +455,7 @@
 {
 	kregs* regi;
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	if (slot->regno != reg) {
 		assert(!isGlobal(slot));
@@ -487,7 +489,7 @@
 
 	/* Finally, we assume the copy is done elsewhere */
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 }
 
 /*
@@ -497,7 +499,7 @@
 int
 slotOffset(SlotData* slot, int type, int use)
 {
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	/* If slot is in a register, clobber the register to force it back
 	 * into memory.
@@ -507,7 +509,7 @@
 		clobberRegister(slot[1].regno);
 	}
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	return (slotOffsetNoSpill(slot, type));
 }
@@ -544,7 +546,7 @@
 	SlotData** ptr;
 	int reg;
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 
 	reg = sdata->regno;
 
@@ -571,7 +573,7 @@
 	}
 	sdata->modified = 0;
 
-	sanityCheck();
+SCHK(	sanityCheck();						)
 }
 
 /*
-------------- next part --------------
Index: libraries/javalib/java/util/HashMap.java
===================================================================
RCS file: /cvs/kaffe/kaffe/libraries/javalib/java/util/HashMap.java,v
retrieving revision 1.16
diff -u -r1.16 HashMap.java
--- libraries/javalib/java/util/HashMap.java	24 May 2002 14:46:43 -0000	1.16
+++ libraries/javalib/java/util/HashMap.java	12 Sep 2002 10:50:18 -0000
@@ -232,8 +232,17 @@
 		table = newtab;
 	}
 
+	// Folded find(Object, int) and bucket(Object, int) in,
+	// because this should be _fast_ call...
 	private Entry find(Object key) {
-		return find(key, bucket(key, table.length));
+		int hash = (key == null) ? 0 : key.hashCode();
+		hash &= 0x7fffffff;
+		for (Entry e = table[hash % table.length]; e != null; e = e.next) {
+			if (key == null ? e.key == null : key.equals(e.key)) {
+				return e;
+			}
+		}
+		return null;
 	}
 
 	private Entry find(Object key, int bucket) {


More information about the kaffe mailing list