This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: fix memory leak
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 06 Dec 2002 16:39:19 -0700
- Subject: Patch: FYI: fix memory leak
- Reply-to: tromey at redhat dot com
I'm checking this in.
This fixes a memory leak I noticed (by accident, not at runtime). We
allocate the direct-threaded structure using malloc, but never free
it. This patch changes it to be GCd.
This ran the test suite with no regressions. For good measure, I
rebuilt kawa using this patch.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
* include/java-interp.h (class _Jv_InterpMethod): Added
JV_MARKOBJ_DECL.
* boehm.cc (_Jv_MarkObj): Consolidated interpreter code. Also
mark `prepared' field of interpreted method.
* interpret.cc (compile): Use _Jv_AllocBytes.
Index: boehm.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/boehm.cc,v
retrieving revision 1.34
diff -u -r1.34 boehm.cc
--- boehm.cc 25 Sep 2002 20:14:37 -0000 1.34
+++ boehm.cc 6 Dec 2002 23:40:10 -0000
@@ -39,7 +39,6 @@
ptr_t GC_debug_generic_malloc (size_t size, int k, GC_EXTRA_PARAMS);
};
-// We must check for plausibility ourselves.
#define MAYBE_MARK(Obj, Top, Limit, Source, Exit) \
Top=GC_MARK_AND_PUSH((GC_PTR)Obj, Top, Limit, (GC_PTR *)Source)
@@ -153,19 +152,6 @@
p = (ptr_t) c->methods[i].signature;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c,
cm2label);
-
- // FIXME: `ncode' entry?
-
-#ifdef INTERPRETER
- // The interpreter installs a heap-allocated
- // trampoline here, so we'll mark it.
- if (_Jv_IsInterpretedClass (c))
- {
- p = (ptr_t) c->methods[i].ncode;
- MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c,
- cm3label);
- }
-#endif
}
}
@@ -221,7 +207,7 @@
#ifdef INTERPRETER
if (_Jv_IsInterpretedClass (c))
{
- _Jv_InterpClass* ic = (_Jv_InterpClass*)c;
+ _Jv_InterpClass* ic = (_Jv_InterpClass*) c;
p = (ptr_t) ic->interpreted_methods;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic, cElabel);
@@ -231,6 +217,26 @@
p = (ptr_t) ic->interpreted_methods[i];
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic, \
cFlabel);
+
+ // Mark the direct-threaded code.
+ if ((c->methods[i].accflags
+ & java::lang::reflect::Modifier::NATIVE) == 0)
+ {
+ _Jv_InterpMethod *im
+ = (_Jv_InterpMethod *) ic->interpreted_methods[i];
+ if (im)
+ {
+ p = (ptr_t) im->prepared;
+ MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic, \
+ cFlabel);
+ }
+ }
+
+ // The interpreter installs a heap-allocated trampoline
+ // here, so we'll mark it.
+ p = (ptr_t) c->methods[i].ncode;
+ MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c,
+ cm3label);
}
p = (ptr_t) ic->field_initializers;
Index: interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.36
diff -u -r1.36 interpret.cc
--- interpret.cc 26 Nov 2002 06:51:14 -0000 1.36
+++ interpret.cc 6 Dec 2002 23:40:11 -0000
@@ -312,7 +312,7 @@
if (! first_pass)
{
- insns = (insn_slot *) _Jv_Malloc (sizeof (insn_slot) * next);
+ insns = (insn_slot *) _Jv_AllocBytes (sizeof (insn_slot) * next);
next = 0;
}
Index: include/java-interp.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/java-interp.h,v
retrieving revision 1.19
diff -u -r1.19 java-interp.h
--- include/java-interp.h 3 Dec 2002 13:50:05 -0000 1.19
+++ include/java-interp.h 6 Dec 2002 23:40:12 -0000
@@ -144,6 +144,10 @@
friend class gnu::gcj::runtime::StackTrace;
friend void _Jv_PrepareClass(jclass);
+
+#ifdef JV_MARKOBJ_DECL
+ friend JV_MARKOBJ_DECL;
+#endif
};
class _Jv_InterpClass : public java::lang::Class