[kaffe] CVS kaffe (guilhem): Handle OOM in jitter.
Kaffe CVS
cvs-commits at kaffe.org
Mon Dec 26 10:10:52 PST 2005
PatchSet 7056
Date: 2005/12/26 18:01:44
Author: guilhem
Branch: HEAD
Tag: (none)
Log:
Handle OOM in jitter.
* kaffe/kaffevm/jit3/machine.h,
kaffe/kaffevm/jit3/machine.c
(KaffeJIT3_exitWithOOM,
KaffeJIT3_setupExitWithOOM): New functions.
(KaffeJIT3_cleanupInsnSequence): New function.
(translate): Handle OOM cleanly.
* kaffe/kaffevm/jit3/seq.c,
kaffe/kaffevm/jit3/labels.c,
kaffe/kaffevm/jit3/constpool.c,
kaffe/kaffevm/jit3/global-regs.c:
Throw an OOM if there is no memory anymore (instead
of crashing the VM with an assert).
* kaffe/kaffevm/jit/native-wrapper.c
(startJNI): Throw an OOM if it is not possible to allocate
a new local ref table.
(Kaffe_wrapper): Handle OOM cleanly.
* kaffe/kaffevm/jit/machine.c
(KaffeJIT_exitWithOOM, KaffeJIT_setupExitWithOOM,
KaffeJIT_cleanupInsnSequence): New functions.
Members:
ChangeLog:1.4574->1.4575
kaffe/kaffevm/jit/machine.c:1.83->1.84
kaffe/kaffevm/jit/machine.h:1.24->1.25
kaffe/kaffevm/jit/native-wrapper.c:1.12->1.13
kaffe/kaffevm/jit3/constpool.c:1.16->1.17
kaffe/kaffevm/jit3/global-regs.c:1.1->1.2
kaffe/kaffevm/jit3/labels.c:1.19->1.20
kaffe/kaffevm/jit3/machine.c:1.78->1.79
kaffe/kaffevm/jit3/machine.h:1.27->1.28
kaffe/kaffevm/jit3/seq.c:INITIAL->1.10
Index: kaffe/ChangeLog
diff -u kaffe/ChangeLog:1.4574 kaffe/ChangeLog:1.4575
--- kaffe/ChangeLog:1.4574 Mon Dec 26 02:00:14 2005
+++ kaffe/ChangeLog Mon Dec 26 18:01:44 2005
@@ -1,4 +1,30 @@
+2005-12-26 Guilhem Lavaux <guilhem at kaffe.org>
+
+ * kaffe/kaffevm/jit3/machine.h,
+ kaffe/kaffevm/jit3/machine.c
+ (KaffeJIT3_exitWithOOM,
+ KaffeJIT3_setupExitWithOOM): New functions.
+ (KaffeJIT3_cleanupInsnSequence): New function.
+ (translate): Handle OOM cleanly.
+
+ * kaffe/kaffevm/jit3/seq.c,
+ kaffe/kaffevm/jit3/labels.c,
+ kaffe/kaffevm/jit3/constpool.c,
+ kaffe/kaffevm/jit3/global-regs.c:
+ Throw an OOM if there is no memory anymore (instead
+ of crashing the VM with an assert).
+
+ * kaffe/kaffevm/jit/native-wrapper.c
+ (startJNI): Throw an OOM if it is not possible to allocate
+ a new local ref table.
+ (Kaffe_wrapper): Handle OOM cleanly.
+
+ * kaffe/kaffevm/jit/machine.c
+ (KaffeJIT_exitWithOOM, KaffeJIT_setupExitWithOOM,
+ KaffeJIT_cleanupInsnSequence): New functions.
+
2005-12-26 Riccardo Mottola <riccardo at kaffe.org>
+
* config/config-io.h,
config/config-math.h,
config/config-mem.h,
Index: kaffe/kaffe/kaffevm/jit/machine.c
diff -u kaffe/kaffe/kaffevm/jit/machine.c:1.83 kaffe/kaffe/kaffevm/jit/machine.c:1.84
--- kaffe/kaffe/kaffevm/jit/machine.c:1.83 Sat Aug 20 19:20:33 2005
+++ kaffe/kaffe/kaffevm/jit/machine.c Mon Dec 26 18:01:47 2005
@@ -134,6 +134,22 @@
void cancelNoWriteback(void);
jlong currentTime(void);
+static JTHREAD_JMPBUF JIT_jumpExitWithOOM;
+
+void KaffeJIT_exitWithOOM()
+{
+ JTHREAD_LONGJMP(JIT_jumpExitWithOOM, 1);
+}
+
+bool KaffeJIT_setupExitWithOOM(struct _errorInfo* einfo)
+{
+ if (!JTHREAD_SETJMP(JIT_jumpExitWithOOM))
+ return false;
+
+ postOutOfMemory(einfo);
+ return true;
+}
+
/*
* By default, we comply with the Java spec and turn stack overflow checks
* on. Note that this involves a noticeable performance penalty. If you
@@ -255,6 +271,12 @@
enterTranslator();
startTiming(&jit_time, "jittime");
+ if (KaffeJIT_setupExitWithOOM(einfo))
+ {
+ success = false;
+ goto done2;
+ }
+
#if defined(KAFFE_PROFILER)
if (profFlag) {
static int init = 0;
@@ -640,6 +662,13 @@
*/
KaffeJIT_newConstant(CPref, meth);
return true;
+}
+
+/*
+ */
+void KaffeJIT_cleanupInsnSequence()
+{
+ initSeq();
}
/*
Index: kaffe/kaffe/kaffevm/jit/machine.h
diff -u kaffe/kaffe/kaffevm/jit/machine.h:1.24 kaffe/kaffe/kaffevm/jit/machine.h:1.25
--- kaffe/kaffe/kaffevm/jit/machine.h:1.24 Wed Sep 28 02:02:16 2005
+++ kaffe/kaffe/kaffevm/jit/machine.h Mon Dec 26 18:01:47 2005
@@ -167,6 +167,10 @@
bool finishInsnSequence(struct codeinfo*, nativeCodeInfo*, errorInfo*);
void installMethodCode(struct codeinfo*, Method*, nativeCodeInfo*);
+extern void KaffeJIT_cleanupInsnSequence();
+extern void KaffeJIT_exitWithOOM();
+extern bool KaffeJIT_setupExitWithOOM(errorInfo *einfo);
+
typedef struct {
bool BADARRAYINDEX;
bool NULLPOINTER;
Index: kaffe/kaffe/kaffevm/jit/native-wrapper.c
diff -u kaffe/kaffe/kaffevm/jit/native-wrapper.c:1.12 kaffe/kaffe/kaffevm/jit/native-wrapper.c:1.13
--- kaffe/kaffe/kaffevm/jit/native-wrapper.c:1.12 Tue Jul 19 16:27:36 2005
+++ kaffe/kaffe/kaffevm/jit/native-wrapper.c Mon Dec 26 18:01:47 2005
@@ -36,9 +36,9 @@
threadData *thread_data = THREAD_DATA();
jnirefs* table;
- table = gc_malloc
- (sizeof(jnirefs) + sizeof(jref)*DEFAULT_JNIREFS_NUMBER,
- KGC_ALLOC_STATIC_THREADDATA);
+ table = checkPtr(gc_malloc
+ (sizeof(jnirefs) + sizeof(jref)*DEFAULT_JNIREFS_NUMBER,
+ KGC_ALLOC_STATIC_THREADDATA));
table->prev = thread_data->jnireferences;
thread_data->jnireferences = table;
@@ -104,6 +104,12 @@
*/
enterTranslator();
+ if (KJIT(setupExitWithOOM)(&info))
+ {
+ success = false;
+ goto exitOOM;
+ }
+
#if defined(KAFFE_PROFILER)
if (profFlag) {
profiler_get_clicks(xmeth->jitClicks);
@@ -452,6 +458,9 @@
if (use_JNI)
xmeth->accflags |= ACC_JNI;
+ goto done;
+exitOOM:
+ KJIT(cleanupInsnSequence)();
done:
KJIT(resetConstants)();
KJIT(resetLabels)();
Index: kaffe/kaffe/kaffevm/jit3/constpool.c
diff -u kaffe/kaffe/kaffevm/jit3/constpool.c:1.16 kaffe/kaffe/kaffevm/jit3/constpool.c:1.17
--- kaffe/kaffe/kaffevm/jit3/constpool.c:1.16 Fri Oct 28 15:26:20 2005
+++ kaffe/kaffe/kaffevm/jit3/constpool.c Mon Dec 26 18:01:47 2005
@@ -92,7 +92,8 @@
/* Allocate chunk of constpool elements */
cpc = gc_malloc(sizeof(constpoolchunk), KGC_ALLOC_JIT_CONST);
/* XXX Ack! */
- assert(cpc != 0);
+ if (cpc == NULL)
+ KaffeJIT3_exitWithOOM();
cpc->next = poolchunks;
poolchunks = cpc;
Index: kaffe/kaffe/kaffevm/jit3/global-regs.c
diff -u kaffe/kaffe/kaffevm/jit3/global-regs.c:1.1 kaffe/kaffe/kaffevm/jit3/global-regs.c:1.2
--- kaffe/kaffe/kaffevm/jit3/global-regs.c:1.1 Wed Aug 10 11:03:18 2005
+++ kaffe/kaffe/kaffevm/jit3/global-regs.c Mon Dec 26 18:01:47 2005
@@ -99,6 +99,9 @@
/* Allocate an array for the slot pointers and copy them in */
slots = gc_malloc((1+maxLocal) * sizeof(SlotInfo*), KGC_ALLOC_JIT_SLOTS);
+ if (slots == NULL)
+ KaffeJIT3_exitWithOOM();
+
for (j = 0; j < maxLocal; j++) {
slots[j] = &localinfo[j];
}
Index: kaffe/kaffe/kaffevm/jit3/labels.c
diff -u kaffe/kaffe/kaffevm/jit3/labels.c:1.19 kaffe/kaffe/kaffevm/jit3/labels.c:1.20
--- kaffe/kaffe/kaffevm/jit3/labels.c:1.19 Mon May 30 09:24:01 2005
+++ kaffe/kaffe/kaffevm/jit3/labels.c Mon Dec 26 18:01:47 2005
@@ -230,7 +230,8 @@
/* Allocate chunk of label elements */
lc = gc_malloc(sizeof(labelchunk), KGC_ALLOC_JIT_LABELS);
- assert(lc != NULL);
+ if (lc == NULL)
+ KaffeJIT3_exitWithOOM();
lc->next = labelchunks;
labelchunks = lc;
Index: kaffe/kaffe/kaffevm/jit3/machine.c
diff -u kaffe/kaffe/kaffevm/jit3/machine.c:1.78 kaffe/kaffe/kaffevm/jit3/machine.c:1.79
--- kaffe/kaffe/kaffevm/jit3/machine.c:1.78 Wed Aug 10 11:03:20 2005
+++ kaffe/kaffe/kaffevm/jit3/machine.c Mon Dec 26 18:01:47 2005
@@ -138,6 +138,22 @@
static void printProfilerStats(void);
#endif
+JTHREAD_JMPBUF JIT3_jumpExitWithOOM;
+
+void KaffeJIT3_exitWithOOM()
+{
+ JTHREAD_LONGJMP(JIT3_jumpExitWithOOM, 1);
+}
+
+jboolean KaffeJIT3_setupExitWithOOM(struct _errorInfo* einfo)
+{
+ if (!JTHREAD_SETJMP(JIT3_jumpExitWithOOM))
+ return false;
+
+ postOutOfMemory(einfo);
+ return true;
+}
+
/*
* Translate a method into native code.
*
@@ -270,6 +286,13 @@
maxArgs += 1;
}
+
+ if (KaffeJIT3_setupExitWithOOM(einfo))
+ {
+ success = false;
+ goto oom_error;
+ }
+
DBG(MOREJIT,
dprintf("Method: %s.%s%s\n", CLASS_CNAME(xmeth->class), xmeth->name->data, METHOD_SIGD(xmeth));
for (i = 0; i < maxLocal; i++) {
@@ -390,7 +413,11 @@
{
success = false;
}
+ goto done;
+oom_error:;
+ KaffeJIT3_cleanupInsnSequence();
+
done:;
KaffeJIT3_resetLabels();
KaffeJIT3_resetConstants();
@@ -449,6 +476,22 @@
return (success);
}
+void
+KaffeJIT3_cleanupInsnSequence()
+{
+ sequence *s;
+
+ for (s = firstSeq; s != currSeq; s = s->next)
+ {
+ if (s->func != doSpill)
+ continue;
+
+ /* According to doSpill */
+ gc_free(s->u[1].smask);
+ }
+ initSeq();
+}
+
/*
* Generate the code.
*/
@@ -578,6 +621,7 @@
strlen(METHOD_SIGD(meth)) +
1,
KGC_ALLOC_JITTEMP);
+ assert(sym != NULL);
sprintf(sym,
"%s/%s%s",
CLASS_CNAME(meth->class),
@@ -1069,7 +1113,9 @@
c++; /* Add null slot on the end */
mem = gc_malloc(c * sizeof(SlotData*), KGC_ALLOC_JIT_SLOTS);
-
+ if (mem == NULL)
+ KaffeJIT3_exitWithOOM();
+
i = maxLocal + maxStack + tmpslot;
c = 0;
for (i--; i >= 0; i--) {
@@ -1295,6 +1341,8 @@
fc = KGC_malloc(main_collector,
sizeof(fakeCall),
KGC_ALLOC_JIT_FAKE_CALL);
+ if (fc == NULL)
+ KaffeJIT3_exitWithOOM();
}
#if defined(HAVE_branch_and_link)
fc->parent = findFakeCall(func);
Index: kaffe/kaffe/kaffevm/jit3/machine.h
diff -u kaffe/kaffe/kaffevm/jit3/machine.h:1.27 kaffe/kaffe/kaffevm/jit3/machine.h:1.28
--- kaffe/kaffe/kaffevm/jit3/machine.h:1.27 Wed Sep 28 02:02:16 2005
+++ kaffe/kaffe/kaffevm/jit3/machine.h Mon Dec 26 18:01:47 2005
@@ -206,6 +206,9 @@
extern void slotAlias(struct _sequence*);
extern void startInsn(struct _sequence*);
extern jboolean translate(Method* xmeth, struct _errorInfo* einfo);
+extern void KaffeJIT3_exitWithOOM();
+extern jboolean KaffeJIT3_setupExitWithOOM(struct _errorInfo* einfo);
+extern void KaffeJIT3_cleanupInsnSequence();
/*
* Some global variables used by the translater which we must export.
===================================================================
Checking out kaffe/kaffe/kaffevm/jit3/seq.c
RCS: /home/cvs/kaffe/kaffe/kaffe/kaffevm/jit3/seq.c,v
VERS: 1.10
***************
--- /dev/null Sun Aug 4 19:57:58 2002
+++ kaffe/kaffe/kaffevm/jit3/seq.c Mon Dec 26 18:10:52 2005
@@ -0,0 +1,88 @@
+/* seq.c
+ * Pseudo instruction sequences.
+ *
+ * Copyright (c) 1996, 1997, 2003
+ * Transvirtual Technologies, Inc. All rights reserved.
+ *
+ * See the file "license.terms" for information on usage and redistribution
+ * of this file.
+ */
+
+#include "config.h"
+#include "config-std.h"
+#include "config-mem.h"
+#include "gtypes.h"
+#include "seq.h"
+#include "gc.h"
+
+static sequencechunk* sequencechunks;
+sequence* firstSeq;
+sequence* lastSeq;
+sequence* currSeq;
+sequence* activeSeq;
+
+/**
+ * Reset the sequence list.
+ */
+void
+initSeq(void)
+{
+ currSeq = firstSeq;
+ while( (sequencechunks != NULL) && (sequencechunks->next != NULL) )
+ {
+ sequencechunk *sc = sequencechunks;
+
+ sequencechunks = sc->next;
+ gc_free(sc);
+ }
+ if( sequencechunks != NULL )
+ {
+ lastSeq = &sequencechunks->data[ALLOCSEQNR - 1];
+ lastSeq->next = NULL;
+ }
+}
+
+/**
+ * Allocate a new sequence element.
+ */
+sequence*
+nextSeq(void)
+{
+ sequence* ret;
+
+ ret = currSeq;
+ if (ret == 0) {
+ sequencechunk *sc;
+
+ int i;
+ /* Allocate chunk of sequence elements */
+ sc = gc_malloc(sizeof(sequencechunk), KGC_ALLOC_JIT_SEQ);
+ if (sc == NULL)
+ KaffeJIT3_exitWithOOM();
+
+ sc->next = sequencechunks;
+ sequencechunks = sc;
+
+ ret = &sc->data[0];
+
+ /* Attach to current chain */
+ if (lastSeq == 0) {
+ firstSeq = ret;
+ }
+ else {
+ lastSeq->next = ret;
+ }
+ lastSeq = &sc->data[ALLOCSEQNR-1];
+
+ /* Link elements into list */
+ for (i = 0; i < ALLOCSEQNR-1; i++) {
+ sc->data[i].next = &sc->data[i+1];
+ }
+ }
+ currSeq = ret->next;
+ ret->lastuse = 0;
+ ret->refed = 1;
+ ret->jflags = willcatch;
+ activeSeq = ret;
+ return (ret);
+}
More information about the kaffe
mailing list