garbage collecting interfaces
Timothy Stack
stack at cs.utah.edu
Mon May 22 14:11:56 PDT 2000
hi,
There seems to be a bug in the destroyClass function when trying to
garbage collect an interface. It attempts to get the native code for
a method, but ends up just dereferencing a null pointer. The
following code extends the ClassGC test to include a class that
implements a dummy interface and a simple fix for destroyClass.
Unfortunately, I don't know how to verify that the interface was
actually collected, but atleast it doesn't crash anymore.
tim stack
Index: kaffe/kaffe/kaffevm/gcFuncs.c
diff -u kaffe/kaffe/kaffevm/gcFuncs.c:1.1 kaffe/kaffe/kaffevm/gcFuncs.c:1.2
--- kaffe/kaffe/kaffevm/gcFuncs.c:1.1 Thu May 4 16:13:06 2000
+++ kaffe/kaffe/kaffevm/gcFuncs.c Mon May 22 14:54:58 2000
@@ -108,19 +108,24 @@
if (!CLASS_IS_ARRAY(clazz) && CLASS_METHODS(clazz) != 0) {
Method *m = CLASS_METHODS(clazz);
for (i = 0; i < CLASS_NMETHODS(clazz); i++) {
- void *ncode = METHOD_NATIVECODE(m);
+ void *ncode = 0;
+
+ if (!CLASS_IS_INTERFACE(clazz))
+ {
+ ncode = METHOD_NATIVECODE(m);
#if defined(TRANSLATOR) && (defined (MD_UNREGISTER_JIT_EXCEPTION_INFO) || defined (JIT3))
- if (METHOD_JITTED(m)) {
+ if (METHOD_JITTED(m)) {
#if defined(MD_UNREGISTER_JIT_EXCEPTION_INFO)
- MD_UNREGISTER_JIT_EXCEPTION_INFO (m->c.ncode.ncode_start,
- ncode,
- m->c.ncode.ncode_end - ncode);
+ MD_UNREGISTER_JIT_EXCEPTION_INFO (m->c.ncode.ncode_start,
+ ncode,
+ m->c.ncode.ncode_end - ncode);
#endif
#if defined(JIT3)
- makeMethodInactive(m);
+ makeMethodInactive(m);
#endif
- }
+ }
#endif
+ }
utf8ConstRelease(m->name);
utf8ConstRelease(METHOD_SIG(m));
KFREE(METHOD_PSIG(m));
Index: kaffe/test/regression/ClassGC.java
diff -u kaffe/test/regression/ClassGC.java:1.1 kaffe/test/regression/ClassGC.java:1.2
--- kaffe/test/regression/ClassGC.java:1.1 Thu May 4 16:13:48 2000
+++ kaffe/test/regression/ClassGC.java Mon May 22 14:53:26 2000
@@ -75,21 +75,42 @@
c.newInstance();
}
}
- public static boolean gotOne;
+ public static boolean gotOneForF;
+ public static boolean gotOneForG;
}
class ClassGCTest
{
public static class HObject {
protected void finalize() throws Throwable {
- if (!ClassGC.gotOne) {
- ClassGC.gotOne = true;
+ if (!ClassGC.gotOneForF) {
+ ClassGC.gotOneForF = true;
System.out.println("Success.");
}
}
}
public static Object f = new HObject();
+
+ /* Make sure interfaces are GC'd also */
+ public interface HInterface {
+ void func();
+ }
+
+ public static class HImplementor implements HInterface {
+ public void func()
+ {
+ }
+
+ protected void finalize() throws Throwable {
+ if (!ClassGC.gotOneForG) {
+ ClassGC.gotOneForG = true;
+ System.out.println("Success.");
+ }
+ }
+ }
+
+ public static Object g = new HImplementor();
}
class ClassGCTestLater
@@ -114,5 +135,6 @@
/* Expected Output:
+Success.
Success.
*/
More information about the kaffe
mailing list