[svn:parrot] r49060 - branches/string_gc_encapsulate/src/gc
bacek at svn.parrot.org
bacek at svn.parrot.org
Thu Sep 16 13:53:33 UTC 2010
Author: bacek
Date: Thu Sep 16 13:53:33 2010
New Revision: 49060
URL: https://trac.parrot.org/parrot/changeset/49060
Log:
Move mem_allocate function into string_gc.c and made static. It's not used anywhere else
Modified:
branches/string_gc_encapsulate/src/gc/alloc_resources.c
branches/string_gc_encapsulate/src/gc/gc_private.h
branches/string_gc_encapsulate/src/gc/string_gc.c
Modified: branches/string_gc_encapsulate/src/gc/alloc_resources.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/alloc_resources.c Thu Sep 16 13:34:42 2010 (r49059)
+++ branches/string_gc_encapsulate/src/gc/alloc_resources.c Thu Sep 16 13:53:33 2010 (r49060)
@@ -190,102 +190,6 @@
/*
-=item C<void * mem_allocate(PARROT_INTERP, Memory_Pools *mem_pools, size_t size,
-Variable_Size_Pool *pool)>
-
-Allocates memory for headers.
-
-Alignment problems history:
-
-See L<http://archive.develooper.com/perl6-internals%40perl.org/msg12310.html>
-for details.
-
-- return aligned pointer *if needed*
-- return strings et al at unaligned i.e. void* boundaries
-- remember alignment in a buffer header bit
- use this in compaction code
-- reduce alignment to a reasonable value i.e. MALLOC_ALIGNMENT
- aka 2*sizeof (size_t) or just 8 (TODO make a config hint)
-
-See pobj.h for a discussion of the Buffer descriptor and the buffer itself,
-including its header.
-
-=cut
-
-*/
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void *
-mem_allocate(PARROT_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t size,
- ARGMOD(Variable_Size_Pool *pool))
-{
- ASSERT_ARGS(mem_allocate)
- void *return_val;
-
- /* we always should have one block at least */
- PARROT_ASSERT(pool->top_block);
-
- /* If not enough room, try to find some */
- if (pool->top_block->free < size) {
- /*
- * force a GC mark run to get live flags set
- * for incremental M&S collection is run from there
- * but only if there may be something worth collecting!
- * TODO pass required allocation size to the GC system,
- * so that collection can be skipped if needed
- */
- size_t new_mem = mem_pools->memory_used -
- mem_pools->mem_used_last_collect;
- if (!mem_pools->gc_mark_block_level
- && new_mem > (mem_pools->mem_used_last_collect >> 2)
- && new_mem > GC_SIZE_THRESHOLD) {
- Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG);
-
- if (interp->gc_sys->sys_type != INF) {
- /* Compact the pool if allowed and worthwhile */
- if (pool->compact) {
- /* don't bother reclaiming if it's only a small amount */
- if ((pool->possibly_reclaimable * pool->reclaim_factor +
- pool->guaranteed_reclaimable) > size) {
- (*pool->compact) (interp, mem_pools, pool);
- }
- }
- }
- }
- if (pool->top_block->free < size) {
- if (pool->minimum_block_size < 65536 * 16)
- pool->minimum_block_size *= 2;
- /*
- * TODO - Big blocks
- *
- * Mark the block as big block (it has just one item)
- * And don't set big blocks as the top_block.
- */
- Parrot_gc_str_alloc_new_block(mem_pools, size, pool, "compact failed");
-
- ++mem_pools->mem_allocs_since_last_collect;
-
- if (pool->top_block->free < size) {
- fprintf(stderr, "out of mem\n");
- exit(EXIT_FAILURE);
- }
- }
- }
-
- /* TODO inline the fast path */
- return_val = pool->top_block->top;
- pool->top_block->top += size;
- pool->top_block->free -= size;
- mem_pools->memory_used += size;
-
- return return_val;
-}
-
-/*
-
=item C<static const char * buffer_location(PARROT_INTERP, const Buffer *b)>
Recturns a constant string representing the location of the given
Modified: branches/string_gc_encapsulate/src/gc/gc_private.h
==============================================================================
--- branches/string_gc_encapsulate/src/gc/gc_private.h Thu Sep 16 13:34:42 2010 (r49059)
+++ branches/string_gc_encapsulate/src/gc/gc_private.h Thu Sep 16 13:53:33 2010 (r49060)
@@ -530,18 +530,6 @@
FUNC_MODIFIES(*mem_pools)
FUNC_MODIFIES(*pool);
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
-void * mem_allocate(PARROT_INTERP,
- ARGMOD(Memory_Pools *mem_pools),
- size_t size,
- ARGMOD(Variable_Size_Pool *pool))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- __attribute__nonnull__(4)
- FUNC_MODIFIES(*mem_pools)
- FUNC_MODIFIES(*pool);
-
void merge_pools(
ARGMOD(Variable_Size_Pool *dest),
ARGMOD(Variable_Size_Pool *source))
@@ -580,10 +568,6 @@
PARROT_ASSERT_ARG(interp) \
, PARROT_ASSERT_ARG(mem_pools) \
, PARROT_ASSERT_ARG(pool))
-#define ASSERT_ARGS_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
- PARROT_ASSERT_ARG(interp) \
- , PARROT_ASSERT_ARG(mem_pools) \
- , PARROT_ASSERT_ARG(pool))
#define ASSERT_ARGS_merge_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
PARROT_ASSERT_ARG(dest) \
, PARROT_ASSERT_ARG(source))
Modified: branches/string_gc_encapsulate/src/gc/string_gc.c
==============================================================================
--- branches/string_gc_encapsulate/src/gc/string_gc.c Thu Sep 16 13:34:42 2010 (r49059)
+++ branches/string_gc_encapsulate/src/gc/string_gc.c Thu Sep 16 13:53:33 2010 (r49060)
@@ -47,6 +47,18 @@
FUNC_MODIFIES(*mem_pools)
FUNC_MODIFIES(*pool);
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+static void * mem_allocate(PARROT_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t size,
+ ARGMOD(Variable_Size_Pool *pool))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ __attribute__nonnull__(4)
+ FUNC_MODIFIES(*mem_pools)
+ FUNC_MODIFIES(*pool);
+
PARROT_WARN_UNUSED_RESULT
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
@@ -58,6 +70,10 @@
PARROT_ASSERT_ARG(mem_pools) \
, PARROT_ASSERT_ARG(pool) \
, PARROT_ASSERT_ARG(why))
+#define ASSERT_ARGS_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
+ PARROT_ASSERT_ARG(interp) \
+ , PARROT_ASSERT_ARG(mem_pools) \
+ , PARROT_ASSERT_ARG(pool))
#define ASSERT_ARGS_new_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: static */
@@ -489,6 +505,102 @@
/*
+=item C<static void * mem_allocate(PARROT_INTERP, Memory_Pools *mem_pools,
+size_t size, Variable_Size_Pool *pool)>
+
+Allocates memory for headers.
+
+Alignment problems history:
+
+See L<http://archive.develooper.com/perl6-internals%40perl.org/msg12310.html>
+for details.
+
+- return aligned pointer *if needed*
+- return strings et al at unaligned i.e. void* boundaries
+- remember alignment in a buffer header bit
+ use this in compaction code
+- reduce alignment to a reasonable value i.e. MALLOC_ALIGNMENT
+ aka 2*sizeof (size_t) or just 8 (TODO make a config hint)
+
+See pobj.h for a discussion of the Buffer descriptor and the buffer itself,
+including its header.
+
+=cut
+
+*/
+
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+static void *
+mem_allocate(PARROT_INTERP,
+ ARGMOD(Memory_Pools *mem_pools),
+ size_t size,
+ ARGMOD(Variable_Size_Pool *pool))
+{
+ ASSERT_ARGS(mem_allocate)
+ void *return_val;
+
+ /* we always should have one block at least */
+ PARROT_ASSERT(pool->top_block);
+
+ /* If not enough room, try to find some */
+ if (pool->top_block->free < size) {
+ /*
+ * force a GC mark run to get live flags set
+ * for incremental M&S collection is run from there
+ * but only if there may be something worth collecting!
+ * TODO pass required allocation size to the GC system,
+ * so that collection can be skipped if needed
+ */
+ size_t new_mem = mem_pools->memory_used -
+ mem_pools->mem_used_last_collect;
+ if (!mem_pools->gc_mark_block_level
+ && new_mem > (mem_pools->mem_used_last_collect >> 2)
+ && new_mem > GC_SIZE_THRESHOLD) {
+ Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG);
+
+ if (interp->gc_sys->sys_type != INF) {
+ /* Compact the pool if allowed and worthwhile */
+ if (pool->compact) {
+ /* don't bother reclaiming if it's only a small amount */
+ if ((pool->possibly_reclaimable * pool->reclaim_factor +
+ pool->guaranteed_reclaimable) > size) {
+ (*pool->compact) (interp, mem_pools, pool);
+ }
+ }
+ }
+ }
+ if (pool->top_block->free < size) {
+ if (pool->minimum_block_size < 65536 * 16)
+ pool->minimum_block_size *= 2;
+ /*
+ * TODO - Big blocks
+ *
+ * Mark the block as big block (it has just one item)
+ * And don't set big blocks as the top_block.
+ */
+ Parrot_gc_str_alloc_new_block(mem_pools, size, pool, "compact failed");
+
+ ++mem_pools->mem_allocs_since_last_collect;
+
+ if (pool->top_block->free < size) {
+ fprintf(stderr, "out of mem\n");
+ exit(EXIT_FAILURE);
+ }
+ }
+ }
+
+ /* TODO inline the fast path */
+ return_val = pool->top_block->top;
+ pool->top_block->top += size;
+ pool->top_block->free -= size;
+ mem_pools->memory_used += size;
+
+ return return_val;
+}
+
+/*
+
=back
=head1 SEE ALSO
More information about the parrot-commits
mailing list