Front page | perl.cvs.parrot |
Postings from July 2008
[svn:parrot] r29014 - in branches/gsoc_pdd09: include/parrot src src/gc
From:
Whiteknight
Date:
July 3, 2008 11:04
Subject:
[svn:parrot] r29014 - in branches/gsoc_pdd09: include/parrot src src/gc
Author: Whiteknight
Date: Thu Jul 3 07:52:32 2008
New Revision: 29014
Modified:
branches/gsoc_pdd09/include/parrot/smallobject.h
branches/gsoc_pdd09/src/gc/dod.c
branches/gsoc_pdd09/src/gc/gc_it.c
branches/gsoc_pdd09/src/gc/smallobject.c
branches/gsoc_pdd09/src/headers.c
branches/gsoc_pdd09/src/stacks.c
branches/gsoc_pdd09/src/string.c
Log:
[gsoc_pdd09] changes to header allocators. Better separation between aggregate and non-aggregate types
Modified: branches/gsoc_pdd09/include/parrot/smallobject.h
==============================================================================
--- branches/gsoc_pdd09/include/parrot/smallobject.h (original)
+++ branches/gsoc_pdd09/include/parrot/smallobject.h Thu Jul 3 07:52:32 2008
@@ -156,13 +156,11 @@
typedef struct Gc_it_hdr {
struct Gc_it_hdr *next;
struct Small_Object_Arena *parent_arena;
- union {
- UINTVAL _x_align; /* force UINTVAL alignment and sizing */
- struct {
- unsigned short card;
- unsigned char flag;
- } num;
- } index;
+ struct {
+ unsigned short card; /* The number of the card that contains the flag */
+ unsigned char flag; /* The index of the flag on the card (1-4) */
+ unsigned char agg; /* 1 if the item is a PObj, 0 otherwise */
+ } data;
} Gc_it_hdr;
/*
Modified: branches/gsoc_pdd09/src/gc/dod.c
==============================================================================
--- branches/gsoc_pdd09/src/gc/dod.c (original)
+++ branches/gsoc_pdd09/src/gc/dod.c Thu Jul 3 07:52:32 2008
@@ -194,10 +194,12 @@
the object's header to the queue. We add it to the beginning of the
queue so we can exploit the cache locality benefits of marking a
node and it's children together. We make a few basic tests here to
- avoid adding objects to the queue unnecessarily. */
+ avoid adding objects to the queue unnecessarily.
- /* If gc_priv_data->state == GC_IT_MARK_ROOTS, we need to add all found
- objects to gc_priv_data->root_queue instead of gc_priv_data->queue. */
+ Only aggregate (PObj) items end up on the queue. Items which are not
+ PObjs are marked as black immediately, but are not put on the queue.
+ C<object_lives> handles the marking of these simple, non-aggregate
+ objects. */
Gc_it_hdr * hdr;
Gc_it_data * gc_priv_data;
@@ -206,10 +208,19 @@
fprintf(stderr, "PObj lives: null pointer received, ignoring.\n");
return;
}
+ /* Eventually this will all be more clean. For now, it's spread-out for
+ debugging. */
+ PARROT_ASSERT(obj);
hdr = PObj_to_IT_HDR(obj);
+ PARROT_ASSERT(hdr);
+ if(!hdr->data.agg) {
+ /* If the data is not an aggregate, mark it as being a simple buffer
+ and do not treat it like a PObj. */
+ object_lives(interp, obj);
+ return;
+ }
gc_priv_data =(Gc_it_data *)interp->arena_base->gc_private;
card_mark = gc_it_get_card_mark(hdr);
- PARROT_ASSERT(hdr);
/*
# ifdef GC_IT_DEBUG
fprintf(stderr, "PObj lives: Object (%p), pool (%p), cardmark %d\n",
@@ -228,12 +239,16 @@
if(card_mark == GC_IT_CARD_BLACK || hdr->next != NULL)
return;
+
/* black items should have been caught. Nothing should ever be "UNUSED"
- at the moment. "FREE" items should not be here either, but if an item
- is marked free at this point, we can mark it as being unfree like
- normal. */
+ at the moment. "FREE" items should not be here either. */
+
PARROT_ASSERT(card_mark != GC_IT_CARD_UNUSED);
PARROT_ASSERT(card_mark != GC_IT_CARD_FREE);
+
+ /* If gc_priv_data->state == GC_IT_MARK_ROOTS, we need to add all found
+ objects to gc_priv_data->root_queue instead of gc_priv_data->queue. */
+
if(gc_priv_data->state == GC_IT_MARK_ROOTS)
GC_IT_ADD_TO_ROOT_QUEUE(gc_priv_data, hdr);
else
@@ -317,6 +332,24 @@
/*
+=item C<void is_PObj>
+
+Specify whether the given allocated item is a PObj or not
+
+=cut
+
+*/
+
+void
+is_PObj(ARGMOD(void * ptr))
+{
+#if PARROT_GC_IT
+ gc_it_ptr_set_aggregate(ptr, 1);
+#endif
+}
+
+/*
+
=item C<int Parrot_dod_trace_root>
Traces the root set. Returns 0 if it's a lazy DOD run and all objects
Modified: branches/gsoc_pdd09/src/gc/gc_it.c
==============================================================================
--- branches/gsoc_pdd09/src/gc/gc_it.c (original)
+++ branches/gsoc_pdd09/src/gc/gc_it.c Thu Jul 3 07:52:32 2008
@@ -308,12 +308,12 @@
GC_IT_BREAK_AFTER_5;
case GC_IT_SWEEP_HEADERS:
- gc_it_sweep_header_pools(interp);
+ /*gc_it_sweep_header_pools(interp);*/
gc_priv_data->state = GC_IT_SWEEP_BUFFERS;
GC_IT_BREAK_AFTER_6;
case GC_IT_SWEEP_BUFFERS:
- gc_it_sweep_sized_pools(interp);
+ /*gc_it_sweep_sized_pools(interp);*/
gc_priv_data->state = GC_IT_FINAL_CLEANUP;
GC_IT_BREAK_AFTER_7;
@@ -1125,6 +1125,10 @@
/* mark the item as black, so it doesn't get collected prematurely. */
gc_it_set_card_mark(hdr, GC_IT_CARD_BLACK);
+
+ /* clear the aggregate flag, in case it hasn't been done yet */
+ hdr->data.agg = 0;
+
/*
#ifdef GC_IT_DEBUG
fprintf(stderr, "Get free object from pool %s (%p): %p (%d left) \n",
@@ -1258,15 +1262,16 @@
/* Cache the object's parent pool and card addresses */
p->parent_arena = new_arena;
- p->index.num.card = i / 4;
- p->index.num.flag = i % 4;
+ p->data.card = i / 4;
+ p->data.flag = i % 4;
+ p->data.agg = 0;
PARROT_ASSERT(p->parent_arena == new_arena);
PARROT_ASSERT(p->parent_arena->parent_pool == pool);
/*
#ifdef GC_IT_DEBUG
fprintf(stderr, "new item: (%p), arena: (%p), pool: (%p) card: %d[%d]\n",
p, p->parent_arena, p->parent_arena->parent_pool,
- p->index.num.card, p->index.num.flag);
+ p->data.card, p->data.flag);
#endif
*/
/* Find the next item in the arena with voodoo pointer magic */
@@ -1293,17 +1298,17 @@
gc_it_set_card_mark(ARGMOD(Gc_it_hdr *hdr), UINTVAL flag)
{
Gc_it_card * const card_start = hdr->parent_arena->cards;
- Gc_it_card * const card = (card_start + hdr->index.num.card);
+ Gc_it_card * const card = (card_start + hdr->data.card);
/*
#ifdef GC_IT_DEBUG
fprintf(stderr, "Card Set. Pool|hdr|card: (%p, %p, %p). card %d[%d]\n",
hdr->parent_arena->parent_pool, hdr, card,
- hdr->index.num.card, hdr->index.num.flag);
+ hdr->data.card, hdr->data.flag);
#endif
*/
PARROT_ASSERT(flag < 4);
- switch (hdr->index.num.flag) {
+ switch (hdr->data.flag) {
case 0:
card->_f.flag1 = flag;
break;
@@ -1338,8 +1343,8 @@
gc_it_get_card_mark(ARGMOD(Gc_it_hdr *hdr))
{
Gc_it_card * const card_start = hdr->parent_arena->cards;
- Gc_it_card * const card = (card_start + hdr->index.num.card);
- switch (hdr->index.num.flag) {
+ Gc_it_card * const card = (card_start + hdr->data.card);
+ switch (hdr->data.flag) {
case 0:
return card->_f.flag1;
case 1:
@@ -1561,6 +1566,23 @@
return NULL;
}
+/*
+
+=item C<void gc_it_ptr_set_PObj>
+
+Sets whether the given object is a PObj or not
+
+=cut
+
+*/
+
+void
+gc_it_ptr_set_aggregate(ARGMOD(void *ptr), unsigned char flag)
+{
+ Gc_it_hdr * const hdr = PObj_to_IT_HDR(ptr);
+ hdr->data.agg = flag;
+}
+
#endif /* PARROT_GC_IT */
Modified: branches/gsoc_pdd09/src/gc/smallobject.c
==============================================================================
--- branches/gsoc_pdd09/src/gc/smallobject.c (original)
+++ branches/gsoc_pdd09/src/gc/smallobject.c Thu Jul 3 07:52:32 2008
@@ -107,7 +107,7 @@
#endif
const Small_Object_Arena *arena;
- ptr = PObj_to_ARENA(ptr);
+ ptr = (void*)PObj_to_ARENA(ptr);
for (arena = pool->last_Arena; arena; arena = arena->prev) {
const ptrdiff_t ptr_diff =
Modified: branches/gsoc_pdd09/src/headers.c
==============================================================================
--- branches/gsoc_pdd09/src/headers.c (original)
+++ branches/gsoc_pdd09/src/headers.c Thu Jul 3 07:52:32 2008
@@ -87,7 +87,8 @@
Gets a free object or buffer from the given C<pool> and returns it.
If the object is larger then a starndard C<PObj> structure, all
-additional memory is cleared.
+additional memory is cleared. Buffer is assumed to be a PObj or an
+object which is isomorphic with a PObj.
=cut
@@ -103,6 +104,7 @@
/* don't mess around with flags */
PObj_bufstart(buffer) = NULL;
PObj_buflen(buffer) = 0;
+ is_PObj(buffer);
if (pool->object_size - GC_HEADER_SIZE > sizeof (PObj))
memset(buffer + 1, 0,
@@ -321,6 +323,7 @@
: interp->arena_base->pmc_pool;
PMC * const pmc = (PMC *)pool->get_free_object(interp, pool);
+ is_PObj(pmc);
if (!pmc)
real_exception(interp, NULL, ALLOCATION_ERROR,
"Parrot VM: PMC allocation failed!\n");
@@ -369,6 +372,26 @@
/*
+=item C<Stack_Chunk_t * new_stack_chunk>
+
+Allocates a new stack chunk
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+PARROT_CANNOT_RETURN_NULL
+Stack_Chunk_t*
+new_stack_chunk(PARROT_INTERP, ARGMOD(Small_Object_Pool *pool))
+{
+ Stack_Chunk_t * const chunk = get_free_buffer(interp, pool);
+ chunk->pool = pool;
+ return chunk;
+}
+
+/*
+
=item C<void add_pmc_ext>
Obtains a new C<PMC_EXT> structure, and attaches it to the given C<PMC>.
@@ -481,7 +504,10 @@
=item C<void * new_bufferlike_header>
Returns a new buffer-like header from the appropriate sized pool. Does
-not check to ensure the header is non-null.
+not check to ensure the header is non-null. The buffer is not treated
+as if it is PObj isomorphic. This is best used for non-aggregate object
+allocations. Use C<new_pmc_header>, C<new_string_header>,
+C<new_buffer_header> and C<new_stack_chunk> to allocate PObjs.
=cut
@@ -493,8 +519,7 @@
new_bufferlike_header(PARROT_INTERP, size_t size)
{
Small_Object_Pool * const pool = get_bufferlike_pool(interp, size);
-
- return get_free_buffer(interp, pool);
+ return pool->get_free_object(interp, pool);
}
/*
Modified: branches/gsoc_pdd09/src/stacks.c
==============================================================================
--- branches/gsoc_pdd09/src/stacks.c (original)
+++ branches/gsoc_pdd09/src/stacks.c Thu Jul 3 07:52:32 2008
@@ -57,15 +57,9 @@
Stack_Chunk_t *
cst_new_stack_chunk(PARROT_INTERP, ARGIN(const Stack_Chunk_t *chunk))
{
- Small_Object_Pool * const pool = chunk->pool;
- Stack_Chunk_t * const new_chunk = (Stack_Chunk_t *)pool->get_free_object(interp, pool);
-
- PObj_bufstart(new_chunk) = NULL;
- PObj_buflen(new_chunk) = 0;
-
- new_chunk->pool = chunk->pool;
- new_chunk->name = chunk->name;
-
+ Small_Object_Pool * const pool = chunk->pool;
+ Stack_Chunk_t * const new_chunk = new_stack_chunk(interp, pool);
+ new_chunk->name = chunk->name;
return new_chunk;
}
@@ -86,12 +80,11 @@
Stack_Chunk_t *
new_stack(PARROT_INTERP, ARGIN(const char *name))
{
- Small_Object_Pool * const pool = make_bufferlike_pool(interp, sizeof (Stack_Chunk_t));
- Stack_Chunk_t * const chunk = (Stack_Chunk_t *)(pool->get_free_object)(interp, pool);
+ Small_Object_Pool * const pool = make_bufferlike_pool(interp, sizeof (Stack_Chunk_t));
+ Stack_Chunk_t * const chunk = new_stack_chunk(interp, pool);
chunk->prev = chunk; /* mark the top of the stack */
chunk->name = name;
- chunk->pool = pool; /* cache the pool pointer, for ease */
return chunk;
}
Modified: branches/gsoc_pdd09/src/string.c
==============================================================================
--- branches/gsoc_pdd09/src/string.c (original)
+++ branches/gsoc_pdd09/src/string.c Thu Jul 3 07:52:32 2008
@@ -80,6 +80,9 @@
Parrot_unmake_COW(PARROT_INTERP, ARGMOD(STRING *s))
{
PARROT_ASSERT(s);
+ /* Quick hack to try to isolate a problem. --AW */
+ if(!s->strstart)
+ return;
/* COW_FLAG | constant_FLAG | external_FLAG) */
if (PObj_is_cowed_TESTALL(s)) {
-
[svn:parrot] r29014 - in branches/gsoc_pdd09: include/parrot src src/gc
by Whiteknight