[Mono-bugs] [Bug 31333][Nor] New - GC problem with Console.WriteLine in the finalization code.
bugzilla-daemon@rocky.ximian.com
bugzilla-daemon@rocky.ximian.com
27 Sep 2002 03:57:22 -0000
Please do not reply to this email- if you want to comment on the bug, go to the
URL shown below and enter your comments there.
Changed by manyoso@yahoo.com.
http://bugzilla.ximian.com/show_bug.cgi?id=31333
--- shadow/31333 Thu Sep 26 23:57:22 2002
+++ shadow/31333.tmp.23266 Thu Sep 26 23:57:22 2002
@@ -0,0 +1,101 @@
+Bug#: 31333
+Product: Mono/Runtime
+Version: unspecified
+OS:
+OS Details:
+Status: NEW
+Resolution:
+Severity:
+Priority: Normal
+Component: misc
+AssignedTo: mono-bugs@ximian.com
+ReportedBy: manyoso@yahoo.com
+QAContact: mono-bugs@ximian.com
+TargetMilestone: ---
+URL:
+Cc:
+Summary: GC problem with Console.WriteLine in the finalization code.
+
+The following code is a test case for something that's been haunting us for quite awhile.
+For some reason the inclusion of the call to Console.WriteLine is producing hard segv's
+with curious backtraces in gdb... The stack frame is _huge_ and it always ends with
+some finalizer and then some type of threading code. This also seems dependant upon
+which version of boehm we use, but the results are always similar. Here is the code:
+
+using System;
+using System.Collections;
+
+public class MyClass
+{
+ public int instanceNumber;
+ private static int classCounter = 0;
+
+ public MyClass()
+ {
+ instanceNumber = classCounter++;
+ }
+
+ ~MyClass()
+ {
+ Console.WriteLine("MyClass instance {0} destroyed", instanceNumber);
+ }
+}
+
+public class Testing
+{
+ static void Main()
+ {
+ ArrayList list = new ArrayList ();
+ while(true)
+ {
+ MyClass instance = new MyClass();
+ list.Add (new WeakReference(instance));
+ }
+ }
+}
+
+This produces this kind of output followed by a segv:
+...
+MyClass instance 6494 destroyed
+MyClass instance 6495 destroyed
+MyClass instance 6496 destroyed
+MyClass instance 6497 destroyed
+MyClass instance 6498 destroyed
+Segmentation fault
+
+The backtrace looks something like this:
+
+Program received signal SIGSEGV, Segmentation fault.
+[Switching to Thread 1024 (LWP 28859)]
+0x400f3f68 in __pthread_lock () from /lib/libpthread.so.0
+(gdb) bt
+#0 0x400f3f68 in __pthread_lock () from /lib/libpthread.so.0
+#1 0x400f0e1a in pthread_mutex_lock () from /lib/libpthread.so.0
+#2 0x0814a63e in EnterCriticalSection (section=0x817d6fc) at critical-sections.c:138
+#3 0x080d6158 in mono_ldftn (method=0x8242160) at codegen-x86.c:10677
+#4 0x08246f3d in ?? ()
+#5 0x080e6b6d in mono_jit_runtime_invoke (method=0x8242160, obj=0x8826910,
+params=0x0, exc=0xbfe011a8) at jit.c:307
+#6 0x08108e08 in mono_runtime_invoke (method=0x8242160, obj=0x8826910,
+params=0x0, exc=0xbfe011a8) at object.c:365
+#7 0x081177a2 in run_finalize (obj=0x8826910, data=0x0) at gc.c:50
+#8 0x400b5f7c in GC_invoke_finalizers () at finalize.c:789
+#9 0x400b5fde in GC_notify_or_invoke_finalizers () at finalize.c:816
+#10 0x400b7031 in GC_generic_malloc (lb=12, k=1) at malloc.c:186
+#11 0x400b7218 in GC_malloc (lb=12) at malloc.c:309
+#12 0x08109b8b in mono_object_allocate (size=12) at object.c:732
+#13 0x08109c3c in mono_object_new_specific (vtable=<incomplete type>) at
+object.c:786
+#14 0x08109c09 in mono_object_new (domain=0x81aff60, klass=0x81d45f0) at
+object.c:771
+#15 0x080d2ff8 in mono_object_new_wrapper (klass=0x81d45f0) at
+codegen-x86.c:10420
+#16 0x0875e227 in ?? ()
+#17 0x08246f4b in ?? ()
+#18 0x080e6b6d in mono_jit_runtime_invoke (method=0x8242160, obj=0x8826930,
+params=0x0, exc=0xbfe0146c) at jit.c:307
+#19 0x08108e08 in mono_runtime_invoke (method=0x8242160, obj=0x8826930,
+params=0x0, exc=0xbfe0146c) at object.c:365
+---Type <return> to continue, or q <return> to quit---
+
+The mono_jit_runtime_invoke method is Finalize and the obj is a MyClass...