[svn:parrot] r38617 - in branches/gc_api: include/parrot src/gc
whiteknight at svn.parrot.org
whiteknight at svn.parrot.org
Fri May 8 22:53:44 UTC 2009
Author: whiteknight
Date: Fri May 8 22:53:43 2009
New Revision: 38617
URL: https://trac.parrot.org/parrot/changeset/38617
Log:
[gc_api] move a few more functions around, making sure that they are visible where they need to be and no further
Modified:
branches/gc_api/include/parrot/gc_api.h
branches/gc_api/include/parrot/parrot.h
branches/gc_api/include/parrot/resources.h
branches/gc_api/src/gc/api.c
branches/gc_api/src/gc/pools.c
branches/gc_api/src/gc/resources.c
Modified: branches/gc_api/include/parrot/gc_api.h
==============================================================================
--- branches/gc_api/include/parrot/gc_api.h Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/include/parrot/gc_api.h Fri May 8 22:53:43 2009 (r38617)
@@ -84,6 +84,18 @@
/* HEADERIZER BEGIN: src/gc/api.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
+void Parrot_allocate_aligned(PARROT_INTERP,
+ ARGOUT(Buffer *buffer),
+ size_t size)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*buffer);
+
+void Parrot_allocate_string(PARROT_INTERP, ARGOUT(STRING *str), size_t size)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*str);
+
void Parrot_destroy_header_pools(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -131,6 +143,14 @@
STRING * Parrot_gc_new_string_header(PARROT_INTERP, UINTVAL flags)
__attribute__nonnull__(1);
+void Parrot_go_collect(PARROT_INTERP)
+ __attribute__nonnull__(1);
+
+PARROT_WARN_UNUSED_RESULT
+int Parrot_in_memory_pool(PARROT_INTERP, ARGIN(void *bufstart))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
void Parrot_merge_header_pools(
ARGMOD(Interp *dest_interp),
ARGIN(Interp *source_interp))
@@ -138,6 +158,32 @@
__attribute__nonnull__(2)
FUNC_MODIFIES(*dest_interp);
+void Parrot_merge_memory_pools(
+ ARGIN(Interp *dest_interp),
+ ARGIN(Interp *source_interp))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+void Parrot_reallocate(PARROT_INTERP,
+ ARGMOD(Buffer *buffer),
+ size_t newsize)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*buffer);
+
+void Parrot_reallocate_string(PARROT_INTERP,
+ ARGMOD(STRING *str),
+ size_t newsize)
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2)
+ FUNC_MODIFIES(*str);
+
+#define ASSERT_ARGS_Parrot_allocate_aligned __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(buffer)
+#define ASSERT_ARGS_Parrot_allocate_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(str)
#define ASSERT_ARGS_Parrot_destroy_header_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_add_pmc_ext __attribute__unused__ int _ASSERT_ARGS_CHECK = \
@@ -165,9 +211,23 @@
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_new_string_header __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_go_collect __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp)
+#define ASSERT_ARGS_Parrot_in_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(bufstart)
#define ASSERT_ARGS_Parrot_merge_header_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(dest_interp) \
|| PARROT_ASSERT_ARG(source_interp)
+#define ASSERT_ARGS_Parrot_merge_memory_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(dest_interp) \
+ || PARROT_ASSERT_ARG(source_interp)
+#define ASSERT_ARGS_Parrot_reallocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(buffer)
+#define ASSERT_ARGS_Parrot_reallocate_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(str)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/gc/api.c */
Modified: branches/gc_api/include/parrot/parrot.h
==============================================================================
--- branches/gc_api/include/parrot/parrot.h Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/include/parrot/parrot.h Fri May 8 22:53:43 2009 (r38617)
@@ -284,7 +284,6 @@
#include "parrot/events.h"
#include "parrot/gc_api.h"
#include "parrot/gc_mark_sweep.h"
-#include "parrot/gc_pools.h"
#include "parrot/resources.h"
#include "parrot/string_funcs.h"
#include "parrot/misc.h"
Modified: branches/gc_api/include/parrot/resources.h
==============================================================================
--- branches/gc_api/include/parrot/resources.h Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/include/parrot/resources.h Fri May 8 22:53:43 2009 (r38617)
@@ -39,22 +39,43 @@
/* HEADERIZER BEGIN: src/gc/resources.c */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-void Parrot_allocate(PARROT_INTERP, ARGOUT(Buffer *buffer), size_t size)
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+char * aligned_mem(ARGIN(const Buffer *buffer), ARGIN(char *mem))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(2);
+
+PARROT_PURE_FUNCTION
+PARROT_WARN_UNUSED_RESULT
+size_t aligned_size(ARGIN(const Buffer *buffer), size_t len)
+ __attribute__nonnull__(1);
+
+PARROT_CONST_FUNCTION
+PARROT_WARN_UNUSED_RESULT
+size_t aligned_string_size(size_t len);
+
+void compact_pool(PARROT_INTERP, ARGMOD(Memory_Pool *pool))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- FUNC_MODIFIES(*buffer);
+ FUNC_MODIFIES(*pool);
+
+PARROT_MALLOC
+PARROT_CANNOT_RETURN_NULL
+void * mem_allocate(PARROT_INTERP, size_t size, ARGMOD(Memory_Pool *pool))
+ __attribute__nonnull__(1)
+ __attribute__nonnull__(3)
+ FUNC_MODIFIES(*pool);
-void Parrot_allocate_aligned(PARROT_INTERP,
- ARGOUT(Buffer *buffer),
- size_t size)
+void merge_pools(ARGMOD(Memory_Pool *dest), ARGMOD(Memory_Pool *source))
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- FUNC_MODIFIES(*buffer);
+ FUNC_MODIFIES(*dest)
+ FUNC_MODIFIES(*source);
-void Parrot_allocate_string(PARROT_INTERP, ARGOUT(STRING *str), size_t size)
+void Parrot_allocate(PARROT_INTERP, ARGOUT(Buffer *buffer), size_t size)
__attribute__nonnull__(1)
__attribute__nonnull__(2)
- FUNC_MODIFIES(*str);
+ FUNC_MODIFIES(*buffer);
void Parrot_destroy_memory_pools(PARROT_INTERP)
__attribute__nonnull__(1);
@@ -65,69 +86,36 @@
void Parrot_gc_profile_start(PARROT_INTERP)
__attribute__nonnull__(1);
-void Parrot_go_collect(PARROT_INTERP)
- __attribute__nonnull__(1);
-
-PARROT_WARN_UNUSED_RESULT
-int Parrot_in_memory_pool(PARROT_INTERP, ARGIN(void *bufstart))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
void Parrot_initialize_memory_pools(PARROT_INTERP)
__attribute__nonnull__(1);
-void Parrot_merge_memory_pools(
- ARGIN(Interp *dest_interp),
- ARGIN(Interp *source_interp))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-void Parrot_reallocate(PARROT_INTERP,
- ARGMOD(Buffer *buffer),
- size_t newsize)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*buffer);
-
-void Parrot_reallocate_string(PARROT_INTERP,
- ARGMOD(STRING *str),
- size_t newsize)
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*str);
-
+#define ASSERT_ARGS_aligned_mem __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(buffer) \
+ || PARROT_ASSERT_ARG(mem)
+#define ASSERT_ARGS_aligned_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(buffer)
+#define ASSERT_ARGS_aligned_string_size __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
+#define ASSERT_ARGS_compact_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(pool)
+#define ASSERT_ARGS_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(interp) \
+ || PARROT_ASSERT_ARG(pool)
+#define ASSERT_ARGS_merge_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+ PARROT_ASSERT_ARG(dest) \
+ || PARROT_ASSERT_ARG(source)
#define ASSERT_ARGS_Parrot_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(buffer)
-#define ASSERT_ARGS_Parrot_allocate_aligned __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(buffer)
-#define ASSERT_ARGS_Parrot_allocate_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(str)
#define ASSERT_ARGS_Parrot_destroy_memory_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_profile_end __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
#define ASSERT_ARGS_Parrot_gc_profile_start __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_go_collect __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_in_memory_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(bufstart)
#define ASSERT_ARGS_Parrot_initialize_memory_pools \
__attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp)
-#define ASSERT_ARGS_Parrot_merge_memory_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(dest_interp) \
- || PARROT_ASSERT_ARG(source_interp)
-#define ASSERT_ARGS_Parrot_reallocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(buffer)
-#define ASSERT_ARGS_Parrot_reallocate_string __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(str)
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
/* HEADERIZER END: src/gc/resources.c */
Modified: branches/gc_api/src/gc/api.c
==============================================================================
--- branches/gc_api/src/gc/api.c Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/src/gc/api.c Fri May 8 22:53:43 2009 (r38617)
@@ -586,6 +586,297 @@
return 0;
}
+/*
+
+=item C<void Parrot_allocate_aligned(PARROT_INTERP, Buffer *buffer, size_t
+size)>
+
+Like above, except the C<size> will be rounded up and the address of
+the buffer will have the same alignment as a pointer returned by
+malloc(3) suitable to hold e.g. a C<FLOATVAL> array.
+
+=cut
+
+*/
+
+void
+Parrot_allocate_aligned(PARROT_INTERP, ARGOUT(Buffer *buffer), size_t size)
+{
+ ASSERT_ARGS(Parrot_allocate_aligned)
+ size_t new_size;
+ char *mem;
+
+ PObj_buflen(buffer) = 0;
+ PObj_bufstart(buffer) = NULL;
+ new_size = aligned_size(buffer, size);
+ mem = (char *)mem_allocate(interp, new_size,
+ interp->arena_base->memory_pool);
+ mem = aligned_mem(buffer, mem);
+ PObj_bufstart(buffer) = mem;
+ if (PObj_is_COWable_TEST(buffer))
+ new_size -= sizeof (void*);
+ PObj_buflen(buffer) = new_size;
+}
+
+/*
+
+=item C<void Parrot_allocate_string(PARROT_INTERP, STRING *str, size_t size)>
+
+Allocate the STRING's buffer memory to the given size. The allocated
+buffer maybe slightly bigger than the given C<size>. This function
+sets also C<< str->strstart >> to the new buffer location, C<< str->bufused >>
+is B<not> changed.
+
+=cut
+
+*/
+
+void
+Parrot_allocate_string(PARROT_INTERP, ARGOUT(STRING *str), size_t size)
+{
+ ASSERT_ARGS(Parrot_allocate_string)
+ size_t new_size;
+ Memory_Pool *pool;
+ char *mem;
+
+ PObj_buflen(str) = 0;
+ PObj_bufstart(str) = NULL;
+
+ /* there's no sense in allocating zero memory, when the overhead of
+ * allocating a string is one pointer; this can fill the pools in an
+ * uncompactable way. See RT #42320.
+ */
+ if (size == 0)
+ return;
+
+ pool = PObj_constant_TEST(str)
+ ? interp->arena_base->constant_string_pool
+ : interp->arena_base->memory_pool;
+
+ new_size = aligned_string_size(size);
+ mem = (char *)mem_allocate(interp, new_size, pool);
+ mem += sizeof (void*);
+
+ PObj_bufstart(str) = str->strstart = mem;
+ PObj_buflen(str) = new_size - sizeof (void*);
+}
+
+/*
+
+=item C<void Parrot_go_collect(PARROT_INTERP)>
+
+Scan the string pools and compact them. This does not perform a GC mark or
+sweep run, and does not check whether string buffers are still alive.
+Redirects to C<compact_pool>.
+
+=cut
+
+*/
+
+void
+Parrot_go_collect(PARROT_INTERP)
+{
+ ASSERT_ARGS(Parrot_go_collect)
+ compact_pool(interp, interp->arena_base->memory_pool);
+}
+
+/*
+
+=item C<int Parrot_in_memory_pool(PARROT_INTERP, void *bufstart)>
+
+Determines if the given C<bufstart> pointer points to a location inside the
+memory pool. Returns 1 if the pointer is in the memory pool, 0 otherwise.
+
+=cut
+
+*/
+
+PARROT_WARN_UNUSED_RESULT
+int
+Parrot_in_memory_pool(PARROT_INTERP, ARGIN(void *bufstart))
+{
+ ASSERT_ARGS(Parrot_in_memory_pool)
+ Memory_Pool * const pool = interp->arena_base->memory_pool;
+ Memory_Block * cur_block = pool->top_block;
+
+ while (cur_block) {
+ if ((char *)bufstart >= cur_block->start &&
+ (char *) bufstart < cur_block->start + cur_block->size) {
+ return 1;
+ }
+ cur_block = cur_block->prev;
+ }
+ return 0;
+}
+
+/*
+
+=item C<void Parrot_merge_memory_pools(Interp *dest_interp, Interp
+*source_interp)>
+
+Merge the memory pools of two interpreter structures. Merge the general
+memory pool and the constant string pools from C<source_interp> into
+C<dest_interp>.
+
+=cut
+
+*/
+
+void
+Parrot_merge_memory_pools(ARGIN(Interp *dest_interp), ARGIN(Interp *source_interp))
+{
+ ASSERT_ARGS(Parrot_merge_memory_pools)
+ merge_pools(dest_interp->arena_base->constant_string_pool,
+ source_interp->arena_base->constant_string_pool);
+
+ merge_pools(dest_interp->arena_base->memory_pool,
+ source_interp->arena_base->memory_pool);
+}
+
+/*
+
+=item C<void Parrot_reallocate(PARROT_INTERP, Buffer *buffer, size_t newsize)>
+
+Reallocate the Buffer's buffer memory to the given size. The
+allocated buffer will not shrink. If the buffer was allocated with
+L<Parrot_allocate_aligned> the new buffer will also be aligned. As with
+all reallocation, the new buffer might have moved and the additional
+memory is not cleared.
+
+=cut
+
+*/
+
+void
+Parrot_reallocate(PARROT_INTERP, ARGMOD(Buffer *buffer), size_t newsize)
+{
+ ASSERT_ARGS(Parrot_reallocate)
+ size_t copysize;
+ char *mem;
+ Memory_Pool * const pool = interp->arena_base->memory_pool;
+ size_t new_size, needed, old_size;
+
+ /*
+ * we don't shrink buffers
+ */
+ if (newsize <= PObj_buflen(buffer))
+ return;
+
+ /*
+ * same as below but barely used and tested - only 3 list related
+ * tests do use true reallocation
+ *
+ * list.c, which does _reallocate, has 2 reallocations
+ * normally, which play ping pong with buffers.
+ * The normal case is therefore always to allocate a new block
+ */
+ new_size = aligned_size(buffer, newsize);
+ old_size = aligned_size(buffer, PObj_buflen(buffer));
+ needed = new_size - old_size;
+
+ if ((pool->top_block->free >= needed)
+ && (pool->top_block->top == (char *)PObj_bufstart(buffer) + old_size)) {
+ pool->top_block->free -= needed;
+ pool->top_block->top += needed;
+ PObj_buflen(buffer) = newsize;
+ return;
+ }
+
+ copysize = PObj_buflen(buffer);
+
+ if (!PObj_COW_TEST(buffer))
+ pool->guaranteed_reclaimable += copysize;
+
+ pool->possibly_reclaimable += copysize;
+ mem = (char *)mem_allocate(interp, new_size, pool);
+ mem = aligned_mem(buffer, mem);
+
+ /* We shouldn't ever have a 0 from size, but we do. If we can track down
+ * those bugs, this can be removed which would make things cheaper */
+ if (copysize)
+ memcpy(mem, PObj_bufstart(buffer), copysize);
+
+ PObj_bufstart(buffer) = mem;
+
+ if (PObj_is_COWable_TEST(buffer))
+ new_size -= sizeof (void *);
+
+ PObj_buflen(buffer) = new_size;
+}
+
+
+/*
+
+=item C<void Parrot_reallocate_string(PARROT_INTERP, STRING *str, size_t
+newsize)>
+
+Reallocate the STRING's buffer memory to the given size. The allocated
+buffer will not shrink. This function sets also C<str-E<gt>strstart> to the
+new buffer location, C<str-E<gt>bufused> is B<not> changed.
+
+=cut
+
+*/
+
+void
+Parrot_reallocate_string(PARROT_INTERP, ARGMOD(STRING *str), size_t newsize)
+{
+ ASSERT_ARGS(Parrot_reallocate_string)
+ size_t copysize;
+ char *mem, *oldmem;
+ size_t new_size, needed, old_size;
+
+ Memory_Pool * const pool =
+ PObj_constant_TEST(str)
+ ? interp->arena_base->constant_string_pool
+ : interp->arena_base->memory_pool;
+
+ /* if the requested size is smaller then buflen, we are done */
+ if (newsize <= PObj_buflen(str))
+ return;
+
+ /*
+ * first check, if we can reallocate:
+ * - if the passed strings buffer is the last string in the pool and
+ * - if there is enough size, we can just move the pool's top pointer
+ */
+ new_size = aligned_string_size(newsize);
+ old_size = aligned_string_size(PObj_buflen(str));
+ needed = new_size - old_size;
+
+ if (pool->top_block->free >= needed
+ && pool->top_block->top == (char *)PObj_bufstart(str) + old_size) {
+ pool->top_block->free -= needed;
+ pool->top_block->top += needed;
+ PObj_buflen(str) = new_size - sizeof (void*);
+ return;
+ }
+
+ PARROT_ASSERT(str->bufused <= newsize);
+
+ /* only copy used memory, not total string buffer */
+ copysize = str->bufused;
+
+ if (!PObj_COW_TEST(str))
+ pool->guaranteed_reclaimable += PObj_buflen(str);
+
+ pool->possibly_reclaimable += PObj_buflen(str);
+
+ mem = (char *)mem_allocate(interp, new_size, pool);
+ mem += sizeof (void *);
+
+ /* copy mem from strstart, *not* bufstart */
+ oldmem = str->strstart;
+ PObj_bufstart(str) = (void *)mem;
+ str->strstart = mem;
+ PObj_buflen(str) = new_size - sizeof (void*);
+
+ /* We shouldn't ever have a 0 from size, but we do. If we can track down
+ * those bugs, this can be removed which would make things cheaper */
+ if (copysize)
+ memcpy(mem, oldmem, copysize);
+}
+
/*
Modified: branches/gc_api/src/gc/pools.c
==============================================================================
--- branches/gc_api/src/gc/pools.c Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/src/gc/pools.c Fri May 8 22:53:43 2009 (r38617)
@@ -15,7 +15,6 @@
*/
#include "parrot/parrot.h"
-#include "parrot/gc_pools.h"
#include "gc_private.h"
/* HEADERIZER HFILE: src/gc/gc_private.h */
Modified: branches/gc_api/src/gc/resources.c
==============================================================================
--- branches/gc_api/src/gc/resources.c Fri May 8 22:32:32 2009 (r38616)
+++ branches/gc_api/src/gc/resources.c Fri May 8 22:53:43 2009 (r38617)
@@ -37,21 +37,6 @@
/* HEADERIZER BEGIN: static */
/* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-static char * aligned_mem(ARGIN(const Buffer *buffer), ARGIN(char *mem))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2);
-
-PARROT_PURE_FUNCTION
-PARROT_WARN_UNUSED_RESULT
-static size_t aligned_size(ARGIN(const Buffer *buffer), size_t len)
- __attribute__nonnull__(1);
-
-PARROT_CONST_FUNCTION
-PARROT_WARN_UNUSED_RESULT
-static size_t aligned_string_size(size_t len);
-
static void alloc_new_block(PARROT_INTERP,
size_t size,
ARGMOD(Memory_Pool *pool),
@@ -67,44 +52,16 @@
__attribute__nonnull__(1)
__attribute__nonnull__(2);
-static void compact_pool(PARROT_INTERP, ARGMOD(Memory_Pool *pool))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*pool);
-
static void debug_print_buf(PARROT_INTERP, ARGIN(const PObj *b))
__attribute__nonnull__(1)
__attribute__nonnull__(2);
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
-static void * mem_allocate(PARROT_INTERP,
- size_t size,
- ARGMOD(Memory_Pool *pool))
- __attribute__nonnull__(1)
- __attribute__nonnull__(3)
- FUNC_MODIFIES(*pool);
-
-static void merge_pools(
- ARGMOD(Memory_Pool *dest),
- ARGMOD(Memory_Pool *source))
- __attribute__nonnull__(1)
- __attribute__nonnull__(2)
- FUNC_MODIFIES(*dest)
- FUNC_MODIFIES(*source);
-
-PARROT_MALLOC
-PARROT_CANNOT_RETURN_NULL
static Memory_Pool * new_memory_pool(
size_t min_block,
NULLOK(compact_f compact));
-#define ASSERT_ARGS_aligned_mem __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(buffer) \
- || PARROT_ASSERT_ARG(mem)
-#define ASSERT_ARGS_aligned_size __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(buffer)
-#define ASSERT_ARGS_aligned_string_size __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
#define ASSERT_ARGS_alloc_new_block __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(pool) \
@@ -112,18 +69,9 @@
#define ASSERT_ARGS_buffer_location __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(b)
-#define ASSERT_ARGS_compact_pool __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pool)
#define ASSERT_ARGS_debug_print_buf __attribute__unused__ int _ASSERT_ARGS_CHECK = \
PARROT_ASSERT_ARG(interp) \
|| PARROT_ASSERT_ARG(b)
-#define ASSERT_ARGS_mem_allocate __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(interp) \
- || PARROT_ASSERT_ARG(pool)
-#define ASSERT_ARGS_merge_pools __attribute__unused__ int _ASSERT_ARGS_CHECK = \
- PARROT_ASSERT_ARG(dest) \
- || PARROT_ASSERT_ARG(source)
#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 */
@@ -191,8 +139,7 @@
/*
-=item C<static void * mem_allocate(PARROT_INTERP, size_t size, Memory_Pool
-*pool)>
+=item C<void * mem_allocate(PARROT_INTERP, size_t size, Memory_Pool *pool)>
Allocates memory for headers.
@@ -229,7 +176,7 @@
PARROT_MALLOC
PARROT_CANNOT_RETURN_NULL
-static void *
+void *
mem_allocate(PARROT_INTERP, size_t size, ARGMOD(Memory_Pool *pool))
{
ASSERT_ARGS(mem_allocate)
@@ -353,7 +300,7 @@
=over 4
-=item C<static void compact_pool(PARROT_INTERP, Memory_Pool *pool)>
+=item C<void compact_pool(PARROT_INTERP, Memory_Pool *pool)>
Compact the string buffer pool. Does not perform a GC scan, or mark items
as being alive in any way.
@@ -362,7 +309,7 @@
*/
-static void
+void
compact_pool(PARROT_INTERP, ARGMOD(Memory_Pool *pool))
{
ASSERT_ARGS(compact_pool)
@@ -590,26 +537,7 @@
/*
-=item C<void Parrot_go_collect(PARROT_INTERP)>
-
-Scan the string pools and compact them. This does not perform a GC mark or
-sweep run, and does not check whether string buffers are still alive.
-Redirects to C<compact_pool>.
-
-=cut
-
-*/
-
-void
-Parrot_go_collect(PARROT_INTERP)
-{
- ASSERT_ARGS(Parrot_go_collect)
- compact_pool(interp, interp->arena_base->memory_pool);
-}
-
-/*
-
-=item C<static size_t aligned_size(const Buffer *buffer, size_t len)>
+=item C<size_t aligned_size(const Buffer *buffer, size_t len)>
Determines the size of Buffer C<buffer> which has nominal length C<len>.
The actual size in RAM of the Buffer might be different because of
@@ -621,7 +549,7 @@
PARROT_PURE_FUNCTION
PARROT_WARN_UNUSED_RESULT
-static size_t
+size_t
aligned_size(ARGIN(const Buffer *buffer), size_t len)
{
ASSERT_ARGS(aligned_size)
@@ -636,7 +564,7 @@
/*
-=item C<static char * aligned_mem(const Buffer *buffer, char *mem)>
+=item C<char * aligned_mem(const Buffer *buffer, char *mem)>
Returns a pointer to the aligned allocated storage for Buffer C<buffer>,
which might not be the same as the pointer to C<buffeR> because of
@@ -648,7 +576,7 @@
PARROT_CANNOT_RETURN_NULL
PARROT_WARN_UNUSED_RESULT
-static char *
+char *
aligned_mem(ARGIN(const Buffer *buffer), ARGIN(char *mem))
{
ASSERT_ARGS(aligned_mem)
@@ -665,7 +593,7 @@
/*
-=item C<static size_t aligned_string_size(size_t len)>
+=item C<size_t aligned_string_size(size_t len)>
Determines the size of a string of length C<len> in RAM, accounting for
alignment.
@@ -677,7 +605,7 @@
/* XXX Looks like we can lose buffer here */
PARROT_CONST_FUNCTION
PARROT_WARN_UNUSED_RESULT
-static size_t
+size_t
aligned_string_size(size_t len)
{
ASSERT_ARGS(aligned_string_size)
@@ -688,185 +616,12 @@
/*
-=item C<int Parrot_in_memory_pool(PARROT_INTERP, void *bufstart)>
-
-Determines if the given C<bufstart> pointer points to a location inside the
-memory pool. Returns 1 if the pointer is in the memory pool, 0 otherwise.
-
-=cut
-
-*/
-
-PARROT_WARN_UNUSED_RESULT
-int
-Parrot_in_memory_pool(PARROT_INTERP, ARGIN(void *bufstart))
-{
- ASSERT_ARGS(Parrot_in_memory_pool)
- Memory_Pool * const pool = interp->arena_base->memory_pool;
- Memory_Block * cur_block = pool->top_block;
-
- while (cur_block) {
- if ((char *)bufstart >= cur_block->start &&
- (char *) bufstart < cur_block->start + cur_block->size) {
- return 1;
- }
- cur_block = cur_block->prev;
- }
- return 0;
-}
-
-
-/*
-
=back
=head2 Parrot Re/Allocate Code
=over 4
-=item C<void Parrot_reallocate(PARROT_INTERP, Buffer *buffer, size_t newsize)>
-
-Reallocate the Buffer's buffer memory to the given size. The
-allocated buffer will not shrink. If the buffer was allocated with
-L<Parrot_allocate_aligned> the new buffer will also be aligned. As with
-all reallocation, the new buffer might have moved and the additional
-memory is not cleared.
-
-=cut
-
-*/
-
-void
-Parrot_reallocate(PARROT_INTERP, ARGMOD(Buffer *buffer), size_t newsize)
-{
- ASSERT_ARGS(Parrot_reallocate)
- size_t copysize;
- char *mem;
- Memory_Pool * const pool = interp->arena_base->memory_pool;
- size_t new_size, needed, old_size;
-
- /*
- * we don't shrink buffers
- */
- if (newsize <= PObj_buflen(buffer))
- return;
-
- /*
- * same as below but barely used and tested - only 3 list related
- * tests do use true reallocation
- *
- * list.c, which does _reallocate, has 2 reallocations
- * normally, which play ping pong with buffers.
- * The normal case is therefore always to allocate a new block
- */
- new_size = aligned_size(buffer, newsize);
- old_size = aligned_size(buffer, PObj_buflen(buffer));
- needed = new_size - old_size;
-
- if ((pool->top_block->free >= needed)
- && (pool->top_block->top == (char *)PObj_bufstart(buffer) + old_size)) {
- pool->top_block->free -= needed;
- pool->top_block->top += needed;
- PObj_buflen(buffer) = newsize;
- return;
- }
-
- copysize = PObj_buflen(buffer);
-
- if (!PObj_COW_TEST(buffer))
- pool->guaranteed_reclaimable += copysize;
-
- pool->possibly_reclaimable += copysize;
- mem = (char *)mem_allocate(interp, new_size, pool);
- mem = aligned_mem(buffer, mem);
-
- /* We shouldn't ever have a 0 from size, but we do. If we can track down
- * those bugs, this can be removed which would make things cheaper */
- if (copysize)
- memcpy(mem, PObj_bufstart(buffer), copysize);
-
- PObj_bufstart(buffer) = mem;
-
- if (PObj_is_COWable_TEST(buffer))
- new_size -= sizeof (void *);
-
- PObj_buflen(buffer) = new_size;
-}
-
-
-/*
-
-=item C<void Parrot_reallocate_string(PARROT_INTERP, STRING *str, size_t
-newsize)>
-
-Reallocate the STRING's buffer memory to the given size. The allocated
-buffer will not shrink. This function sets also C<str-E<gt>strstart> to the
-new buffer location, C<str-E<gt>bufused> is B<not> changed.
-
-=cut
-
-*/
-
-void
-Parrot_reallocate_string(PARROT_INTERP, ARGMOD(STRING *str), size_t newsize)
-{
- ASSERT_ARGS(Parrot_reallocate_string)
- size_t copysize;
- char *mem, *oldmem;
- size_t new_size, needed, old_size;
-
- Memory_Pool * const pool =
- PObj_constant_TEST(str)
- ? interp->arena_base->constant_string_pool
- : interp->arena_base->memory_pool;
-
- /* if the requested size is smaller then buflen, we are done */
- if (newsize <= PObj_buflen(str))
- return;
-
- /*
- * first check, if we can reallocate:
- * - if the passed strings buffer is the last string in the pool and
- * - if there is enough size, we can just move the pool's top pointer
- */
- new_size = aligned_string_size(newsize);
- old_size = aligned_string_size(PObj_buflen(str));
- needed = new_size - old_size;
-
- if (pool->top_block->free >= needed
- && pool->top_block->top == (char *)PObj_bufstart(str) + old_size) {
- pool->top_block->free -= needed;
- pool->top_block->top += needed;
- PObj_buflen(str) = new_size - sizeof (void*);
- return;
- }
-
- PARROT_ASSERT(str->bufused <= newsize);
-
- /* only copy used memory, not total string buffer */
- copysize = str->bufused;
-
- if (!PObj_COW_TEST(str))
- pool->guaranteed_reclaimable += PObj_buflen(str);
-
- pool->possibly_reclaimable += PObj_buflen(str);
-
- mem = (char *)mem_allocate(interp, new_size, pool);
- mem += sizeof (void *);
-
- /* copy mem from strstart, *not* bufstart */
- oldmem = str->strstart;
- PObj_bufstart(str) = (void *)mem;
- str->strstart = mem;
- PObj_buflen(str) = new_size - sizeof (void*);
-
- /* We shouldn't ever have a 0 from size, but we do. If we can track down
- * those bugs, this can be removed which would make things cheaper */
- if (copysize)
- memcpy(mem, oldmem, copysize);
-}
-
-/*
=item C<void Parrot_allocate(PARROT_INTERP, Buffer *buffer, size_t size)>
@@ -890,82 +645,6 @@
PObj_buflen(buffer) = size;
}
-
-/*
-
-=item C<void Parrot_allocate_aligned(PARROT_INTERP, Buffer *buffer, size_t
-size)>
-
-Like above, except the C<size> will be rounded up and the address of
-the buffer will have the same alignment as a pointer returned by
-malloc(3) suitable to hold e.g. a C<FLOATVAL> array.
-
-=cut
-
-*/
-
-void
-Parrot_allocate_aligned(PARROT_INTERP, ARGOUT(Buffer *buffer), size_t size)
-{
- ASSERT_ARGS(Parrot_allocate_aligned)
- size_t new_size;
- char *mem;
-
- PObj_buflen(buffer) = 0;
- PObj_bufstart(buffer) = NULL;
- new_size = aligned_size(buffer, size);
- mem = (char *)mem_allocate(interp, new_size,
- interp->arena_base->memory_pool);
- mem = aligned_mem(buffer, mem);
- PObj_bufstart(buffer) = mem;
- if (PObj_is_COWable_TEST(buffer))
- new_size -= sizeof (void*);
- PObj_buflen(buffer) = new_size;
-}
-
-/*
-
-=item C<void Parrot_allocate_string(PARROT_INTERP, STRING *str, size_t size)>
-
-Allocate the STRING's buffer memory to the given size. The allocated
-buffer maybe slightly bigger than the given C<size>. This function
-sets also C<< str->strstart >> to the new buffer location, C<< str->bufused >>
-is B<not> changed.
-
-=cut
-
-*/
-
-void
-Parrot_allocate_string(PARROT_INTERP, ARGOUT(STRING *str), size_t size)
-{
- ASSERT_ARGS(Parrot_allocate_string)
- size_t new_size;
- Memory_Pool *pool;
- char *mem;
-
- PObj_buflen(str) = 0;
- PObj_bufstart(str) = NULL;
-
- /* there's no sense in allocating zero memory, when the overhead of
- * allocating a string is one pointer; this can fill the pools in an
- * uncompactable way. See RT #42320.
- */
- if (size == 0)
- return;
-
- pool = PObj_constant_TEST(str)
- ? interp->arena_base->constant_string_pool
- : interp->arena_base->memory_pool;
-
- new_size = aligned_string_size(size);
- mem = (char *)mem_allocate(interp, new_size, pool);
- mem += sizeof (void*);
-
- PObj_bufstart(str) = str->strstart = mem;
- PObj_buflen(str) = new_size - sizeof (void*);
-}
-
/*
=item C<static Memory_Pool * new_memory_pool(size_t min_block, compact_f
@@ -1063,7 +742,7 @@
/*
-=item C<static void merge_pools(Memory_Pool *dest, Memory_Pool *source)>
+=item C<void merge_pools(Memory_Pool *dest, Memory_Pool *source)>
Merge two memory pools together. Do this by moving all memory blocks
from the C<*source> pool into the C<*dest> pool. The C<source> pool
@@ -1073,7 +752,7 @@
*/
-static void
+void
merge_pools(ARGMOD(Memory_Pool *dest), ARGMOD(Memory_Pool *source))
{
ASSERT_ARGS(merge_pools)
@@ -1108,30 +787,6 @@
/*
-=item C<void Parrot_merge_memory_pools(Interp *dest_interp, Interp
-*source_interp)>
-
-Merge the memory pools of two interpreter structures. Merge the general
-memory pool and the constant string pools from C<source_interp> into
-C<dest_interp>.
-
-=cut
-
-*/
-
-void
-Parrot_merge_memory_pools(ARGIN(Interp *dest_interp), ARGIN(Interp *source_interp))
-{
- ASSERT_ARGS(Parrot_merge_memory_pools)
- merge_pools(dest_interp->arena_base->constant_string_pool,
- source_interp->arena_base->constant_string_pool);
-
- merge_pools(dest_interp->arena_base->memory_pool,
- source_interp->arena_base->memory_pool);
-}
-
-/*
-
=item C<void Parrot_gc_profile_start(PARROT_INTERP)>
Records the start time of a GC mark run when profiling is enabled.
More information about the parrot-commits
mailing list