miscellaneous kaffe fixes
Timothy Stack
stack at cs.utah.edu
Tue Jun 6 14:04:39 PDT 2000
hi,
Here are some fixes for the following bugs:
- removeClassEntries in classPool.c could skip over an entry
whenever one was removed.
- readConstantPool in constants.c wouldn't handle a bad UTF string
correctly. Now it just sets the size of the constant pool to zero so
that destroyClass doesn't try to free strings that were never
allocated in the first place.
- Trampolines weren't being freed by the jitter/jni/dynamic library
code.
- Jit3 wasn't freeing the byte code it just translated. And it
wasn't freeing the structure allocated by verifyMethod when a
method was empty.
- The ksem in a thread wasn't being freed after the thread died
- getZipData0 in ZipFile.c wasn't freeing the memory it got from
getDataJarFile.
- And a couple of minor tweaks to get rid of compiler warnings
tim stack
Index: kaffe/kaffe/kaffevm/classPool.c
diff -u kaffe/kaffe/kaffevm/classPool.c:1.1 kaffe/kaffe/kaffevm/classPool.c:1.3
--- kaffe/kaffe/kaffevm/classPool.c:1.1 Thu May 4 16:13:06 2000
+++ kaffe/kaffe/kaffevm/classPool.c Tue Jun 6 14:50:04 2000
@@ -179,7 +179,10 @@
lockStaticMutex(&classHashLock);
for (ipool = CLASSHASHSZ; --ipool >= 0; ) {
entryp = &classEntryPool[ipool];
- for (; *entryp != NULL; entryp = &(*entryp)->next) {
+ while (*entryp != NULL) {
+ /* loop invariant: entryp points at the next non-null
+ * entry that must be examined.
+ */
entry = *entryp;
if (entry->loader == loader) {
/*
@@ -198,12 +201,11 @@
(*entryp) = entry->next;
addToCounter(&cpemem, "vmmem-class entry pool",
1, -(jlong)GCSIZEOF(entry));
- KFREE(entry);
+ gc_free(entry);
totalent++;
+ } else {
+ entryp = &(*entryp)->next;
}
- /* if this was the last item, break */
- if (*entryp == 0)
- break;
}
}
unlockStaticMutex(&classHashLock);
Index: kaffe/kaffe/kaffevm/constants.c
diff -u kaffe/kaffe/kaffevm/constants.c:1.1 kaffe/kaffe/kaffevm/constants.c:1.2
--- kaffe/kaffe/kaffevm/constants.c:1.1 Thu May 4 16:13:06 2000
+++ kaffe/kaffe/kaffevm/constants.c Mon Jun 5 16:02:37 2000
@@ -80,7 +80,7 @@
pool[i] = (ConstSlot) utf8ConstNew(fp->buf, len);
if (!pool[i]) {
postOutOfMemory(einfo);
- return 0;
+ goto fail;
}
fp->buf += len;
break;
@@ -151,6 +151,7 @@
JAVA_LANG(ClassFormatError),
"Invalid constant type %d", type);
fail:
+ info->size = 0;
while (--i >= 0) {
if (tags[i] == CONSTANT_Utf8) {
utf8ConstRelease((Utf8Const*)pool[i]);
Index: kaffe/kaffe/kaffevm/external.c
diff -u kaffe/kaffe/kaffevm/external.c:1.3 kaffe/kaffe/kaffevm/external.c:1.4
--- kaffe/kaffe/kaffevm/external.c:1.3 Tue May 16 17:12:33 2000
+++ kaffe/kaffe/kaffevm/external.c Mon Jun 5 16:02:47 2000
@@ -362,6 +362,9 @@
dprintf("Failed to locate native function:\n\t%s.%s%s\n",
m->class->name->data, m->name->data, METHOD_SIGD(m));
)
+#if defined(TRANSLATOR)
+ KFREE(METHOD_NATIVECODE(m));
+#endif
SET_METHOD_NATIVECODE(m, (void*)error_stub);
postExceptionMessage(einfo, JAVA_LANG(UnsatisfiedLinkError),
Index: kaffe/kaffe/kaffevm/findInJar.c
diff -u kaffe/kaffe/kaffevm/findInJar.c:1.3 kaffe/kaffe/kaffevm/findInJar.c:1.5
--- kaffe/kaffe/kaffevm/findInJar.c:1.3 Tue May 16 17:12:37 2000
+++ kaffe/kaffe/kaffevm/findInJar.c Mon Jun 5 16:03:27 2000
@@ -122,6 +122,7 @@
class = newClass();
if (class == 0) {
postOutOfMemory(einfo);
+ KFREE(hand.base);
return (0);
}
@@ -450,7 +451,7 @@
dprintf("insertClasspath(): '%s' %spend\n", cp, prepend ? "pre" : "ap"); )
if (*cp == '\0')
- return;
+ return (0);
lptr = 0;
lockStaticMutex(&classpathLock);
Index: kaffe/kaffe/kaffevm/gcFuncs.c
diff -u kaffe/kaffe/kaffevm/gcFuncs.c:1.3 kaffe/kaffe/kaffevm/gcFuncs.c:1.4
--- kaffe/kaffe/kaffevm/gcFuncs.c:1.3 Thu Jun 1 09:20:55 2000
+++ kaffe/kaffe/kaffevm/gcFuncs.c Mon Jun 5 16:03:40 2000
@@ -56,7 +56,7 @@
/* ARGSUSED */
destroyClass(Collector *collector, void* c)
{
- int i;
+ int i, j;
int idx;
Hjava_lang_Class* clazz = c;
constants* pool;
@@ -162,9 +162,41 @@
/* free various other fixed things */
KFREE(CLASS_STATICDATA(clazz));
- KFREE(clazz->dtable);
+ if( clazz->dtable )
+ {
+ for( i = 0; i < clazz->msize; i++ )
+ {
+ if( clazz->dtable->method[i] == 0 )
+ continue;
+ /* Free ncode if necessary: this concerns
+ * any uninvoked trampolines
+ */
+ if (GC_getObjectIndex(collector,
+ clazz->dtable->method[i])
+ == GC_ALLOC_DISPATCHTABLE) {
+ KFREE(clazz->dtable->method[i]);
+ }
+ }
+ KFREE(clazz->dtable);
+ }
KFREE(clazz->if2itable);
- KFREE(clazz->itable2dtable);
+ if( clazz->itable2dtable )
+ {
+ j = 0;
+ for( i = 0; i < clazz->total_interface_len; i++ )
+ {
+ j += clazz->interfaces[i]->msize + 1;
+ }
+ for( i = 0; i < j; i++ )
+ {
+ if (GC_getObjectIndex(collector,
+ clazz->itable2dtable[i])
+ == GC_ALLOC_DISPATCHTABLE) {
+ GC_free(collector, clazz->itable2dtable[i]);
+ }
+ }
+ GC_free(collector, clazz->itable2dtable);
+ }
KFREE(clazz->gc_layout);
KFREE(clazz->sourcefile);
KFREE(clazz->implementors);
Index: kaffe/kaffe/kaffevm/jni.c
diff -u kaffe/kaffe/kaffevm/jni.c:1.3 kaffe/kaffe/kaffevm/jni.c:1.4
--- kaffe/kaffe/kaffevm/jni.c:1.3 Tue May 16 17:12:42 2000
+++ kaffe/kaffe/kaffevm/jni.c Mon Jun 5 16:03:43 2000
@@ -3982,6 +3982,9 @@
Kaffe_wrapper(xmeth, func, false);
}
else {
+#if defined(TRANSLATOR)
+ KFREE(METHOD_NATIVECODE(xmeth));
+#endif
SET_METHOD_NATIVECODE(xmeth, func);
}
}
Index: kaffe/kaffe/kaffevm/lookup.c
diff -u kaffe/kaffe/kaffevm/lookup.c:1.1 kaffe/kaffe/kaffevm/lookup.c:1.2
--- kaffe/kaffe/kaffevm/lookup.c:1.1 Thu May 4 16:13:07 2000
+++ kaffe/kaffe/kaffevm/lookup.c Mon Jun 5 16:03:48 2000
@@ -261,6 +261,13 @@
for (mptr = CLASS_METHODS(class); --n >= 0; ++mptr) {
if (utf8ConstEqual (name, mptr->name) && utf8ConstEqual (signature, METHOD_SIG(mptr))) {
if ((mptr->accflags & ACC_ABSTRACT) != 0 && !CLASS_IS_INTERFACE(mptr->class)) {
+#if defined(TRANSLATOR)
+ if(GC_getObjectIndex(main_collector,
+ METHOD_NATIVECODE(mptr))
+ == GC_ALLOC_DISPATCHTABLE) {
+ KFREE(METHOD_NATIVECODE(mptr));
+ }
+#endif
SET_METHOD_NATIVECODE(mptr, (void*)throwAbstractMethodError);
mptr->accflags |= ACC_NATIVE;
}
Index: kaffe/kaffe/kaffevm/thread.c
diff -u kaffe/kaffe/kaffevm/thread.c:1.1 kaffe/kaffe/kaffevm/thread.c:1.2
--- kaffe/kaffe/kaffevm/thread.c:1.1 Thu May 4 16:13:08 2000
+++ kaffe/kaffe/kaffevm/thread.c Thu Jun 1 11:51:08 2000
@@ -526,6 +526,7 @@
if (unhand(tid)->PrivateInfo != 0) {
jthread_t jtid = (jthread_t)unhand(tid)->PrivateInfo;
unhand(tid)->PrivateInfo = 0;
+ thread_free(unhand(tid)->sem);
jthread_destroy(jtid);
}
}
Index: kaffe/kaffe/kaffevm/utf8const.c
diff -u kaffe/kaffe/kaffevm/utf8const.c:1.3 kaffe/kaffe/kaffevm/utf8const.c:1.4
--- kaffe/kaffe/kaffevm/utf8const.c:1.3 Thu Jun 1 09:21:00 2000
+++ kaffe/kaffe/kaffevm/utf8const.c Mon Jun 5 16:04:05 2000
@@ -74,7 +74,7 @@
int *myRoot = utfLockRoot;
_unlockMutex(&utf8Lock, myRoot);
- jfree(mem);
+ jfree((void *)mem);
_lockMutex(&utf8Lock, myRoot);
utfLockRoot = myRoot;
}
Index: kaffe/kaffe/kaffevm/jit3/machine.c
diff -u kaffe/kaffe/kaffevm/jit3/machine.c:1.3 kaffe/kaffe/kaffevm/jit3/machine.c:1.5
--- kaffe/kaffe/kaffevm/jit3/machine.c:1.3 Fri May 5 09:30:53 2000
+++ kaffe/kaffe/kaffevm/jit3/machine.c Mon Jun 5 16:04:24 2000
@@ -199,15 +199,17 @@
}
#endif
+ codeInfo = mycodeInfo;
+
/* Handle null calls specially */
if (METHOD_BYTECODE_LEN(xmeth) == 1 && METHOD_BYTECODE_CODE(xmeth)[0] == RETURN) {
+ KFREE(METHOD_NATIVECODE(xmeth));
SET_METHOD_NATIVECODE(xmeth, (nativecode*)nullCall);
goto done;
}
assert(reinvoke == false);
reinvoke = true;
- codeInfo = mycodeInfo;
maxLocal = xmeth->localsz;
maxStack = xmeth->stacksz;
@@ -489,7 +491,10 @@
}
GC_WRITE(meth, code->mem);
+ KFREE(METHOD_NATIVECODE(meth));
SET_METHOD_JITCODE(meth, code->code);
+ if( meth->c.bcode.code )
+ gc_free(meth->c.bcode.code);
meth->c.ncode.ncode_start = code->mem;
meth->c.ncode.ncode_end = (void*)((uintp)code->code + code->codelen);
Index: kaffe/libraries/clib/native/ZipFile.c
diff -u kaffe/libraries/clib/native/ZipFile.c:1.1 kaffe/libraries/clib/native/ZipFile.c:1.2
--- kaffe/libraries/clib/native/ZipFile.c:1.1 Thu May 4 16:13:16 2000
+++ kaffe/libraries/clib/native/ZipFile.c Mon Jun 5 16:04:41 2000
@@ -75,6 +75,7 @@
}
array = (HArrayOfByte*)AllocArray(unhand(zentry)->size, TYPE_Byte);
memcpy(unhand_array(array)->body, buf, unhand(zentry)->size);
+ KFREE(buf);
return (array);
}
More information about the kaffe
mailing list