[svn:parrot] r49043 - branches/string_gc_split/src/gc
bacek at svn.parrot.org
bacek at svn.parrot.org
Thu Sep 16 08:36:42 UTC 2010
Author: bacek
Date: Thu Sep 16 08:36:42 2010
New Revision: 49043
URL: https://trac.parrot.org/parrot/changeset/49043
Log:
Switch compact_pool to use GC_Sys iterator over strings instead of direct poking into header pools
Modified:
branches/string_gc_split/src/gc/alloc_resources.c
branches/string_gc_split/src/gc/gc_private.h
Modified: branches/string_gc_split/src/gc/alloc_resources.c
==============================================================================
--- branches/string_gc_split/src/gc/alloc_resources.c Thu Sep 16 08:36:17 2010 (r49042)
+++ branches/string_gc_split/src/gc/alloc_resources.c Thu Sep 16 08:36:42 2010 (r49043)
@@ -34,6 +34,11 @@
typedef void (*compact_f) (Interp *, Memory_Pools * const, Variable_Size_Pool *);
+typedef struct string_callback_data {
+ Memory_Block *new_block; /* A pointer to our working block */
+ char *cur_spot; /* Where we're currently copying to */
+} string_callback_data;
+
/* HEADERIZER HFILE: src/gc/gc_private.h */
/* HEADERIZER BEGIN: static */
@@ -439,11 +444,12 @@
INTVAL j;
UINTVAL total_size;
- Memory_Block *new_block; /* A pointer to our working block */
- char *cur_spot; /* Where we're currently copying to */
-
Fixed_Size_Arena *cur_buffer_arena;
+ /* Contains new_block and cur_spot */
+ string_callback_data cb_data;
+
+
/* Bail if we're blocked */
if (mem_pools->gc_sweep_block_level)
return;
@@ -466,57 +472,53 @@
alloc_new_block(mem_pools, total_size, pool, "inside compact");
- new_block = pool->top_block;
+ cb_data.new_block = pool->top_block;
/* Start at the beginning */
- cur_spot = new_block->start;
+ cb_data.cur_spot = cb_data.new_block->start;
/* Run through all the Buffer header pools and copy */
- for (j = (INTVAL)mem_pools->num_sized - 1; j >= 0; --j) {
- Fixed_Size_Pool * const header_pool = mem_pools->sized_header_pools[j];
- UINTVAL object_size;
+ interp->gc_sys->iterate_live_strings(interp, move_buffer_callback, &cb_data);
- if (!header_pool)
- continue;
-
- object_size = header_pool->object_size;
+ /* Okay, we're done with the copy. Set the bits in the pool struct */
+ /* First, where we allocate next */
+ cb_data.new_block->top = cb_data.cur_spot;
- for (cur_buffer_arena = header_pool->last_Arena;
- cur_buffer_arena;
- cur_buffer_arena = cur_buffer_arena->prev) {
- Buffer *b = (Buffer *) cur_buffer_arena->start_objects;
- UINTVAL i;
- const size_t objects_end = cur_buffer_arena->used;
+ PARROT_ASSERT(cb_data.new_block->size
+ >=
+ (size_t)cb_data.new_block->top - (size_t)cb_data.new_block->start);
- for (i = objects_end; i; --i) {
+ /* How much is free. That's the total size minus the amount we used */
+ cb_data.new_block->free = cb_data.new_block->size
+ - (cb_data.cur_spot - cb_data.new_block->start);
+ mem_pools->memory_collected += (cb_data.cur_spot - cb_data.new_block->start);
+ mem_pools->memory_used += (cb_data.cur_spot - cb_data.new_block->start);
- if (Buffer_buflen(b) && PObj_is_movable_TESTALL(b)) {
- Memory_Block *old_block = Buffer_pool(b);
+ free_old_mem_blocks(mem_pools, pool, cb_data.new_block, total_size);
- if (!is_block_almost_full(old_block))
- cur_spot = move_one_buffer(interp, new_block, b, cur_spot);
- }
+ --mem_pools->gc_sweep_block_level;
+}
- b = (Buffer *)((char *)b + object_size);
- }
- }
- }
+/*
+=item C<void move_buffer_callback(PARROT_INTERP, Buffer *b, void *data)>
- /* Okay, we're done with the copy. Set the bits in the pool struct */
- /* First, where we allocate next */
- new_block->top = cur_spot;
+Callback for live STRING/Buffer for compating.
- PARROT_ASSERT(new_block->size >= (size_t)new_block->top -
- (size_t)new_block->start);
+=cut
+*/
+void
+move_buffer_callback(PARROT_INTERP, ARGIN(Buffer *b), ARGIN(void *data))
+{
+ ASSERT_ARGS(move_buffer_callback)
+ string_callback_data *cb = (string_callback_data*)data;
- /* How much is free. That's the total size minus the amount we used */
- new_block->free = new_block->size - (cur_spot - new_block->start);
- mem_pools->memory_collected += (cur_spot - new_block->start);
- mem_pools->memory_used += (cur_spot - new_block->start);
+ if (Buffer_buflen(b) && PObj_is_movable_TESTALL(b)) {
+ Memory_Block *old_block = Buffer_pool(b);
- free_old_mem_blocks(mem_pools, pool, new_block, total_size);
+ if (!is_block_almost_full(old_block))
+ cb->cur_spot = move_one_buffer(interp, cb->new_block, b, cb->cur_spot);
+ }
- --mem_pools->gc_sweep_block_level;
}
/*
Modified: branches/string_gc_split/src/gc/gc_private.h
==============================================================================
--- branches/string_gc_split/src/gc/gc_private.h Thu Sep 16 08:36:17 2010 (r49042)
+++ branches/string_gc_split/src/gc/gc_private.h Thu Sep 16 08:36:42 2010 (r49043)
@@ -549,6 +549,13 @@
FUNC_MODIFIES(*dest)
FUNC_MODIFIES(*source);
+void move_buffer_callback(PARROT_INTERP,
+ ARGIN(Buffer *b),
+ ARGIN(void *data))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(3);
+
void Parrot_gc_destroy_header_pools(PARROT_INTERP,
ARGMOD(Memory_Pools *mem_pools))
__attribute__nonnull__(1)
@@ -588,6 +595,10 @@
#define ASSERT_ARGS_merge_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(source))
+#define ASSERT_ARGS_move_buffer_callback __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(b) \
+ , PARROT_ASSERT_ARG(data))
#define ASSERT_ARGS_Parrot_gc_destroy_header_pools \
__attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(interp) \
More information about the parrot-commits
mailing list