[Gc] interior pointers to large allocations
Benjamin Smedberg
benjamin at smedbergs.us
Thu Sep 18 10:06:09 PDT 2008
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
Benjamin Smedberg wrote:
> Dear GC list:
>
> I have a problem with interior pointers that doesn't seem to be covered by
> the docs.
>
> I found that if the allocated size is larger than a hblk,
> GC_is_valid_displacement rejects all interior pointers, due to this line:
> https://hg.mozilla.org/users/bsmedberg_mozilla.com/gcmonkey/file/96af1e84dbaa/memory/boehmgc/ptr_chck.c#l143
>
> * Am I misusing GC_is_valid_displacement?
> * Is this a bug in GC_is_valid_displacement
> * or are interior pointers to large allocations actually not recognized?
I wrote a testcase which shows that interior pointers to large objects are
in fact not recognized... the finalizer runs before the loop finishes, and
there is a crash with the following stack:
#0 GC_is_marked
#1 GC_finalize
#2 GC_finish_collection
#3 GC_try_to_collect_inner
#4 GC_try_to_collect
#5 GC_gcollect
#6 RunTest
#7 main
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.5 (Darwin)
Comment: Using GnuPG with Mozilla - https://enigmail.mozdev.org
iD8DBQFI0oqBSSwGp5sTYNkRAt6RAKDYACQik13dod77P4MhUyD++AqtmgCcCjKj
yWiOzUwV+Z3Uma4Rw0v+Vlg=
=sHyS
-----END PGP SIGNATURE-----
-------------- next part --------------
#include <gc/gc.h>
#include <stdio.h>
struct OffsetBuffer
{
int shared;
size_t size;
char buffer[12000];
};
static void OffsetBufferFinalizer(void *obj, void *client_data)
{
printf("Finalizing OffsetBuffer at %p, index %i\n", obj, (long long int) client_data);
}
static char* CreateOffsetBuffer(long long int i)
{
struct OffsetBuffer *ob = GC_malloc_atomic(sizeof(struct OffsetBuffer));
GC_register_finalizer(ob, OffsetBufferFinalizer, (void*) i, 0, 0);
return ob->buffer;
}
static void RunTest()
{
char **carray = GC_malloc(sizeof(char*) * 100);
for (int i = 0; i < 10000; ++i) {
carray[i] = CreateOffsetBuffer(i);
GC_gcollect();
}
}
int main()
{
GC_INIT();
printf("Starting the test\n");
RunTest();
printf("Ended the test\n");
GC_gcollect();
return 0;
}
-------------- next part --------------
A non-text attachment was scrubbed...
Name: large-interior.c.sig
Type: application/octet-stream
Size: 65 bytes
Desc: not available
Url : https://napali.hpl.hp.com/pipermail/gc/attachments/20080918/157bf5ed/large-interior.c.obj
More information about the Gc
mailing list