This is the mail archive of the java-patches@gcc.gnu.org mailing list for the Java project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[BC] Patch: FYI: GC fixlets


I'm checking this in on the BC branch.

This fixes the GC for a subtle issue involving Miranda methods and the
interpreted_methods array.  See the new comment for a full
explanation.

This also eliminates a memory leak by allocating the JNI argument type
array via the GC.

With today's two patches, plus the version of java.net.URL from the
trunk, plus javax.xml from xalan (I used rhug), I am able to run
Eclipse 3 using the BC gij.

I don't plan to merge java.net.URL myself as I expect that will be
done by Andrew's merge.

Tom

Index: ChangeLog
from  Tom Tromey  <tromey@redhat.com>
	* include/java-interp.h (class _Jv_JNIMethod): Added
	JV_MARKOBJ_DECL as a friend.
	* interpret.cc (ncode): Allocate jni_arg_types field with GC.
	* boehm.cc (_Jv_MarkObj): Skip abstract methods when marking
	interpreter method structures.  Mark jni_arg_types of JNI
	methods.

Index: boehm.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/boehm.cc,v
retrieving revision 1.42.12.5
diff -u -r1.42.12.5 boehm.cc
--- boehm.cc 4 Oct 2004 18:58:36 -0000 1.42.12.5
+++ boehm.cc 6 Oct 2004 18:45:22 -0000
@@ -244,12 +244,40 @@
 
 	  for (int i = 0; i < c->method_count; i++)
 	    {
+	      // 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);
+
+	      using namespace java::lang::reflect;
+
+	      // Mark the direct-threaded code.  Note a subtlety here:
+	      // when we add Miranda methods to a class, we don't
+	      // resize its interpreted_methods array.  If we try to
+	      // reference one of these methods, we may crash.
+	      // However, we know these are all abstract, and we know
+	      // that abstract methods have nothing useful in this
+	      // array.  So, we skip all abstract methods to avoid the
+	      // problem.  FIXME: this is pretty obscure, it may be
+	      // better to add a methods to the execution engine and
+	      // resize the array.
+	      if ((c->methods[i].accflags & Modifier::ABSTRACT) != 0)
+		continue;
+
 	      p = (ptr_t) ic->interpreted_methods[i];
 	      MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
 
-	      // Mark the direct-threaded code.
-	      if ((c->methods[i].accflags
-		   & java::lang::reflect::Modifier::NATIVE) == 0)
+	      if ((c->methods[i].accflags & Modifier::NATIVE) != 0)
+		{
+		  _Jv_JNIMethod *jm
+		    = (_Jv_JNIMethod *) ic->interpreted_methods[i];
+		  if (jm)
+		    {
+		      p = (ptr_t) jm->jni_arg_types;
+		      MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, p);
+		    }
+		}
+	      else
 		{
 		  _Jv_InterpMethod *im
 		    = (_Jv_InterpMethod *) ic->interpreted_methods[i];
@@ -259,11 +287,6 @@
 		      MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, ic);
 		    }
 		}
-
-	      // 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);
 	    }
 
 	  p = (ptr_t) ic->field_initializers;
Index: interpret.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/interpret.cc,v
retrieving revision 1.40.18.5
diff -u -r1.40.18.5 interpret.cc
--- interpret.cc 29 Sep 2004 21:13:22 -0000 1.40.18.5
+++ interpret.cc 6 Oct 2004 18:45:23 -0000
@@ -3629,8 +3629,8 @@
   int extra_args = 1;
   if ((self->accflags & Modifier::STATIC))
     ++extra_args;
-  jni_arg_types = (ffi_type **) _Jv_Malloc ((extra_args + arg_count)
-					    * sizeof (ffi_type *));
+  jni_arg_types = (ffi_type **) _Jv_AllocBytes ((extra_args + arg_count)
+						* sizeof (ffi_type *));
   int offset = 0;
   jni_arg_types[offset++] = &ffi_type_pointer;
   if ((self->accflags & Modifier::STATIC))
Index: include/java-interp.h
===================================================================
RCS file: /cvs/gcc/gcc/libjava/include/java-interp.h,v
retrieving revision 1.23.16.3
diff -u -r1.23.16.3 java-interp.h
--- include/java-interp.h 17 Sep 2004 19:36:09 -0000 1.23.16.3
+++ include/java-interp.h 6 Oct 2004 18:45:24 -0000
@@ -209,6 +209,10 @@
   friend class _Jv_ClassReader;
   friend class _Jv_InterpreterEngine;
 
+#ifdef JV_MARKOBJ_DECL
+  friend JV_MARKOBJ_DECL;
+#endif
+
 public:
   // FIXME: this is ugly.
   void set_function (void *f)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]