[Gc] DONT_ADD_BYTE_AT_END and GC_malloc(0) (gc-7.1)

Boehm, Hans hans.boehm at hp.com
Mon May 12 17:17:37 PDT 2008


Sorry about posting too quickly.  I now have the following patch relative to gc7.1:

Index: thread_local_alloc.c
===================================================================
RCS file: /cvsroot/bdwgc/bdwgc/thread_local_alloc.c,v
retrieving revision 1.13
diff -u -r1.13 thread_local_alloc.c
--- thread_local_alloc.c        25 Oct 2007 00:41:06 -0000      1.13
+++ thread_local_alloc.c        13 May 2008 00:03:36 -0000
@@ -291,14 +291,16 @@
     ptr_t q;
     int j;

-    for (j = 1; j < TINY_FREELISTS; ++j) {
+    for (j = 0; j < TINY_FREELISTS; ++j) {
       q = p -> ptrfree_freelists[j];
       if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
       q = p -> normal_freelists[j];
       if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
 #     ifdef GC_GCJ_SUPPORT
-        q = p -> gcj_freelists[j];
-        if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
+       if (j > 0) {
+          q = p -> gcj_freelists[j];
+          if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
+       }
 #     endif /* GC_GCJ_SUPPORT */
     }
 }

I've been testing with gctest and (variants of) the attached smaller test case.  I'm no longer seeing failures.  If you're still seeing failures, could you send a stack trace?

I think that to see the original failure in 7.1, you need:

1) Threads and thread local allocation enabled (default)

2) Either a build with -DDONT_ADD_BYTE_AT_END, or a client that resets GC_all_interior_pointers.

3) A client that allocates size 0 pointer-free or gcj objects.

Thanks.

Hans

> -----Original Message-----
> From: Shiro Kawai [mailto:shiro at lava.net]
> Sent: Monday, May 12, 2008 7:12 AM
> To: Boehm, Hans
> Cc: gc at napali.hpl.hp.com; shiro at acm.org
> Subject: Re: [Gc] DONT_ADD_BYTE_AT_END and GC_malloc(0) (gc-7.1)
>
> Oops, sorry, with these patches (including GC_GCJ_SUPPORT
> case), I'm still getting SEGV in gctest occasionally, on
> Ubuntu 8.04/AMD64x2, although it is less likely than before.
>
> --shiro
>
>
> From: Shiro Kawai <shiro at lava.net>
> Subject: Re: [Gc] DONT_ADD_BYTE_AT_END and GC_malloc(0) (gc-7.1)
> Date: Mon, 12 May 2008 03:58:20 -1000 (HST)
>
> > Thanks Hans, but I had a problem with the patch against gc-7.1 tree.
> >
> > From: Hans Boehm <Hans.Boehm at hp.com>
> > Subject: Re: [Gc] DONT_ADD_BYTE_AT_END and GC_malloc(0) (gc-7.1)
> > Date: Sun, 11 May 2008 22:13:53 -0700 (PDT)
> >
> > > @@ -291,7 +291,7 @@
> > >       ptr_t q;
> > >       int j;
> > >
> > > -    for (j = 1; j < TINY_FREELISTS; ++j) {
> > > +    for (j = 0; j < TINY_FREELISTS; ++j) {
> > >         q = p -> ptrfree_freelists[j];
> > >         if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
> > >         q = p -> normal_freelists[j];
> >
> > This caused SEGV for all gc tests.  It seems that gcj_freelists[0]
> > shouldn't be marked.  The following, as well as the above
> patch, seems
> > to fix the problem.
> >
> > @@ -297,8 +297,10 @@
> >        q = p -> normal_freelists[j];
> >        if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
> >  #     ifdef GC_GCJ_SUPPORT
> > +      if (j > 0) {
> >          q = p -> gcj_freelists[j];
> >          if ((word)q > HBLKSIZE) GC_set_fl_marks(q);
> > +      }
> >  #     endif /* GC_GCJ_SUPPORT */
> >      }
> >  }
> >
> > > @@ -87,7 +87,7 @@
> > >       if (0 != GC_setspecific(GC_thread_key, p)) {
> > >     ABORT("Failed to set thread specific allocation pointers");
> > >       }
> > > -    for (i = 1; i < TINY_FREELISTS; ++i) {
> > > +    for (i = 0; i < TINY_FREELISTS; ++i) {
> > >     p -> ptrfree_freelists[i] = (void *)1;
> > >     p -> normal_freelists[i] = (void *)1;
> > >   # ifdef GC_GCJ_SUPPORT
> >
> > OTOH, this doesn't seem necessary, for the size 0 freelists are
> > handled just below this for-loop.
> > _______________________________________________
> > Gc mailing list
> > Gc at linux.hpl.hp.com
> > http://www.hpl.hp.com/hosted/linux/mail-archives/gc/
> >
>
-------------- next part --------------
#include <pthread.h>
#include <stdio.h>
#define GC_THREADS
#include "gc.h"

void *run_one_test(void * dummy)
{
        size_t i;

 	GC_INIT();
	for (i = 0; i < 10000; ++i) {
	     /* GC_MALLOC(0);
	     GC_FREE(GC_MALLOC(0)); */
	     GC_MALLOC_ATOMIC(0);
	     GC_FREE(GC_MALLOC_ATOMIC(0));
	}
}

#define NTHREADS 100

int main()
{
    pthread_t th[NTHREADS];
    pthread_attr_t attr;
    int code;
    int j;

    GC_INIT();
    pthread_attr_init(&attr);
    for (j = 0; j < NTHREADS; ++j) {
      if ((code = pthread_create(&th[j], &attr, run_one_test, 0)) != 0) {
    	printf("Thread %d creation failed %d\n", j, code);
      }
    }
    for (j = 0; j < NTHREADS; ++j) {
      if ((code = pthread_join(th[j], 0)) != 0) {
        printf("Thread %d failed %d\n", j, code);
      }
    }
    return 0;
}


More information about the Gc mailing list