This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: fix for obscure SEGV in boehm.cc
- From: Tom Tromey <tromey at redhat dot com>
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Date: 25 Sep 2002 14:11:01 -0600
- Subject: Patch: FYI: fix for obscure SEGV in boehm.cc
- Reply-to: tromey at redhat dot com
I'm checking this in.
It turns out that _Jv_MarkObj can crash in an obscure situation. If
the GC decides to collect during a call to JvAllocObject(Class,...),
we can run into a class object which has been allocated but not filled
in. In particular Class.name is NULL, meaning that Class.isArray()
will SEGV.
Tom
2002-09-25 Tom Tromey <tromey@redhat.com>
* boehm.cc (_Jv_MarkObj): Don't fail if class object has been
allocated but not initialized.
Index: boehm.cc
===================================================================
RCS file: /cvs/gcc/gcc/libjava/boehm.cc,v
retrieving revision 1.33
diff -u -r1.33 boehm.cc
--- boehm.cc 12 Feb 2002 04:14:52 -0000 1.33
+++ boehm.cc 25 Sep 2002 20:10:57 -0000
@@ -1,6 +1,6 @@
// boehm.cc - interface between libjava and Boehm GC.
-/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001, 2002 Free Software Foundation
This file is part of libgcj.
@@ -134,6 +134,12 @@
p = (ptr_t) c->methods;
MAYBE_MARK (p, mark_stack_ptr, mark_stack_limit, c, c6label);
+ // The vtable might have been set, but the rest of the class
+ // could still be uninitialized. If this is the case, then
+ // c.isArray will SEGV. We check for this, and if it is the
+ // case we just return.
+ if (__builtin_expect (c->name == NULL, false))
+ return mark_stack_ptr;
if (! c->isArray() && ! c->isPrimitive())
{