[kaffe] CVS kaffe (stack): Fix jit bug reported by Jim
Kaffe CVS
Kaffe Mailing List <kaffe@kaffe.org>
Sun Nov 2 09:54:02 2003
PatchSet 4150
Date: 2003/11/02 17:51:58
Author: stack
Branch: HEAD
Tag: (none)
Log:
Fix jit bug reported by Jim
Members:
ChangeLog:1.1742->1.1743
kaffe/kaffevm/jit3/machine.c:1.43->1.44
kaffe/kaffevm/jit3/seq.c:1.7->1.8
kaffe/kaffevm/jit3/seq.h:1.8->1.9
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.1742 kaffe/ChangeLog:1.1743
--- kaffe/ChangeLog:1.1742 Sun Nov 2 16:01:55 2003
+++ kaffe/ChangeLog Sun Nov 2 17:51:58 2003
@@ -1,3 +1,17 @@
+2003-11-02 Timothy S. Stack <stack@cs.utah.edu>
+
+ * kaffe/kaffevm/jit3/machine.c:
+ Merge checkCaughtException stuff from jit1, so that we only
+ generate extra spill code if an instruction is actually in an
+ exception handler. Also, be sure to spill dead slots within an
+ exception handler, otherwise subsequent basic blocks might read a
+ bogus value.
+
+ * kaffe/kaffevm/jit3/seq.h,
+ kaffe/kaffevm/jit3/seq.c:
+ Store the current willcatch flags in the sequence structure so
+ they can be referenced later.
+
2003-11-02 Guilhem Lavaux <guilhem@kaffe.org>
* librairies/clib/zip/Deflater.c: Readded DBG macro.
Index: kaffe/kaffe/kaffevm/jit3/machine.c
diff -u kaffe/kaffe/kaffevm/jit3/machine.c:1.43 kaffe/kaffe/kaffevm/jit3/machine.c:1.44
--- kaffe/kaffe/kaffevm/jit3/machine.c:1.43 Sat Oct 11 20:45:50 2003
+++ kaffe/kaffe/kaffevm/jit3/machine.c Sun Nov 2 17:51:59 2003
@@ -1,7 +1,7 @@
/* machine.c
* Translate the Kaffe instruction set to the native one.
*
- * Copyright (c) 1996-1999
+ * Copyright (c) 1996-1999, 2003
* Transvirtual Technologies, Inc. All rights reserved.
*
* Cross-language profiling changes contributed by
@@ -106,6 +106,16 @@
} jitStats;
static jboolean generateInsnSequence(errorInfo*);
+
+/**
+ * Look for exception handlers that enclose the given PC in the given method.
+ * If a match is found, it will set the appropriate willcatch flags.
+ *
+ * @param meth The method that may contain an exception handler.
+ * @param pc The location within the method to look for a handler.
+ */
+static void checkCaughtExceptions(Method* meth, int pc);
+
static void initFakeCalls(void);
static void makeFakeCalls(void);
static void relinkFakeCalls(void);
@@ -245,26 +255,6 @@
base = (bytecode*)METHOD_BYTECODE_CODE(xmeth);
len = METHOD_BYTECODE_LEN(xmeth);
- willcatch.ANY = false;
- willcatch.BADARRAYINDEX = false;
-
- /* Deterimine various exception conditions */
- if (xmeth->exception_table != 0) {
- willCatch(ANY);
- for (i = 0; i < (int)xmeth->exception_table->length; i++) {
- Hjava_lang_Class* etype;
- etype = xmeth->exception_table->entry[i].catch_type;
- if (etype == 0) {
- willCatch(BADARRAYINDEX);
- }
- else {
- if (instanceof(javaLangArrayIndexOutOfBoundsException, etype)) {
- willCatch(BADARRAYINDEX);
- }
- }
- }
- }
-
/*
* Initialise the translator.
*/
@@ -315,6 +305,9 @@
continue;
}
+ /* Determine various exception conditions */
+ checkCaughtExceptions(xmeth, pc);
+
start_instruction();
/* Note start of exception handling blocks */
@@ -790,6 +783,17 @@
if ((m & 1) != 0) {
assert(!isGlobal(t->u[i].slot));
slot_kill_readonce(t->u[i].slot);
+ /*
+ * If this sequence is in an exception
+ * handler we need to spill the slot
+ * in case its used in a subsequent
+ * basic block.
+ */
+ if( t->jflags.ANY )
+ {
+ spillAndUpdate(t->u[i].slot,
+ true);
+ }
slot_invalidate(t->u[i].slot);
}
}
@@ -803,6 +807,48 @@
}
/*
+ * check what synchronous exceptions are caught for a given instruction
+ */
+static
+void
+checkCaughtExceptions(Method* meth, int pc)
+{
+ int i;
+
+ willcatch.ANY = false;
+ willcatch.BADARRAYINDEX = false;
+ willcatch.NULLPOINTER = false;
+
+ if (meth->exception_table == 0)
+ return;
+
+ /* Determine various exception conditions */
+ for (i = 0; i < meth->exception_table->length; i++) {
+ Hjava_lang_Class* etype;
+
+ /* include only if exception handler range matches pc */
+ if (meth->exception_table->entry[i].start_pc > pc ||
+ meth->exception_table->entry[i].end_pc <= pc)
+ continue;
+
+ willCatch(ANY);
+ etype = meth->exception_table->entry[i].catch_type;
+ if (etype == 0) {
+ willCatch(BADARRAYINDEX);
+ willCatch(NULLPOINTER);
+ }
+ else {
+ if (instanceof(javaLangArrayIndexOutOfBoundsException, etype)) {
+ willCatch(BADARRAYINDEX);
+ }
+ if (instanceof(javaLangNullPointerException, etype)) {
+ willCatch(NULLPOINTER);
+ }
+ }
+ }
+}
+
+/*
* Start a new instruction.
*/
void
@@ -848,7 +894,7 @@
break;
case SR_FUNCTION:
- if (calleeSave(sd->regno) == 0 || canCatch(ANY) != 0) {
+ if (calleeSave(sd->regno) == 0 || s->jflags.ANY != 0) {
spillAndUpdate(sd, true);
}
break;
Index: kaffe/kaffe/kaffevm/jit3/seq.c
diff -u kaffe/kaffe/kaffevm/jit3/seq.c:1.7 kaffe/kaffe/kaffevm/jit3/seq.c:1.8
--- kaffe/kaffe/kaffevm/jit3/seq.c:1.7 Sun Sep 21 18:18:19 2003
+++ kaffe/kaffe/kaffevm/jit3/seq.c Sun Nov 2 17:51:59 2003
@@ -1,7 +1,7 @@
/* seq.c
* Pseudo instruction sequences.
*
- * Copyright (c) 1996, 1997
+ * Copyright (c) 1996, 1997, 2003
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
@@ -81,6 +81,7 @@
currSeq = ret->next;
ret->lastuse = 0;
ret->refed = 1;
+ ret->jflags = willcatch;
activeSeq = ret;
return (ret);
}
Index: kaffe/kaffe/kaffevm/jit3/seq.h
diff -u kaffe/kaffe/kaffevm/jit3/seq.h:1.8 kaffe/kaffe/kaffevm/jit3/seq.h:1.9
--- kaffe/kaffe/kaffevm/jit3/seq.h:1.8 Sun Sep 21 18:18:19 2003
+++ kaffe/kaffe/kaffevm/jit3/seq.h Sun Nov 2 17:51:59 2003
@@ -1,7 +1,7 @@
/* seq.h
* Pseudo instruction sequences.
*
- * Copyright (c) 1996, 1997
+ * Copyright (c) 1996, 1997, 2003
* Transvirtual Technologies, Inc. All rights reserved.
*
* See the file "license.terms" for information on usage and redistribution
@@ -11,6 +11,8 @@
#ifndef __seq_hh
#define __seq_hh
+#include "machine.h"
+
struct _sequence;
struct _label_;
@@ -46,6 +48,7 @@
uint8 type;
uint8 refed;
uint32 lastuse;
+ jitflags jflags;
struct _sequence* next;
} sequence;