[svn:parrot] r46026 - in branches/compact_pool_revamp: include/parrot src/gc

bacek at svn.parrot.org bacek at svn.parrot.org
Mon Apr 26 10:22:55 UTC 2010


Author: bacek
Date: Mon Apr 26 10:22:55 2010
New Revision: 46026
URL: https://trac.parrot.org/parrot/changeset/46026

Log:
'Upgrade' aligned_string_size function to ALIGNED_STRING_SIZE macro. It
give us easy win of almost 2% of performance.

Also remove couple of redundant "if"s and other small fixes.

Modified:
   branches/compact_pool_revamp/include/parrot/gc_api.h
   branches/compact_pool_revamp/src/gc/alloc_resources.c
   branches/compact_pool_revamp/src/gc/gc_ms.c
   branches/compact_pool_revamp/src/gc/gc_private.h
   branches/compact_pool_revamp/src/gc/mark_sweep.c

Modified: branches/compact_pool_revamp/include/parrot/gc_api.h
==============================================================================
--- branches/compact_pool_revamp/include/parrot/gc_api.h	Mon Apr 26 09:29:04 2010	(r46025)
+++ branches/compact_pool_revamp/include/parrot/gc_api.h	Mon Apr 26 10:22:55 2010	(r46026)
@@ -31,6 +31,8 @@
 #define WORD_ALIGN_1 (sizeof (void *) - 1)
 #define WORD_ALIGN_MASK ~WORD_ALIGN_1
 
+#define ALIGNED_STRING_SIZE(len) (((len) + sizeof (void*) + WORD_ALIGN_1) & WORD_ALIGN_MASK)
+
 /* pool iteration */
 typedef enum {
     POOL_PMC    = 0x01,

Modified: branches/compact_pool_revamp/src/gc/alloc_resources.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/alloc_resources.c	Mon Apr 26 09:29:04 2010	(r46025)
+++ branches/compact_pool_revamp/src/gc/alloc_resources.c	Mon Apr 26 10:22:55 2010	(r46026)
@@ -554,7 +554,7 @@
     Memory_Block *cur_block = pool->top_block;
 
     UINTVAL total_size   = 0;
-#ifdef RESOURCE_DEBUG
+#if RESOURCE_DEBUG
     size_t  total_blocks = 0;
 #endif
 
@@ -562,7 +562,7 @@
         //total_size += cur_block->size - cur_block->free;
         total_size += cur_block->size - cur_block->freed - cur_block->free;
         cur_block   = cur_block->prev;
-#ifdef RESOURCE_DEBUG
+#if RESOURCE_DEBUG
         ++total_blocks;
 #endif
     }
@@ -572,7 +572,7 @@
     total_size += pool->minimum_block_size;
 #endif
 
-#ifdef RESOURCE_DEBUG
+#if RESOURCE_DEBUG
     fprintf(stderr, "Total blocks: %d\n", total_blocks);
 #endif
 
@@ -779,29 +779,6 @@
 
 /*
 
-=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.
-
-=cut
-
-*/
-
-PARROT_CONST_FUNCTION
-PARROT_WARN_UNUSED_RESULT
-size_t
-aligned_string_size(size_t len)
-{
-    ASSERT_ARGS(aligned_string_size)
-
-    len += sizeof (void *);
-    len  = (len + WORD_ALIGN_1) & WORD_ALIGN_MASK;
-    return len;
-}
-
-/*
-
 =back
 
 =head2 Parrot Re/Allocate Code

Modified: branches/compact_pool_revamp/src/gc/gc_ms.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/gc_ms.c	Mon Apr 26 09:29:04 2010	(r46025)
+++ branches/compact_pool_revamp/src/gc/gc_ms.c	Mon Apr 26 10:22:55 2010	(r46026)
@@ -834,7 +834,7 @@
     ARGOUT(Buffer *buffer), size_t size)
 {
     ASSERT_ARGS(gc_ms_allocate_buffer_storage)
-    const size_t new_size   = aligned_string_size(size);
+    const size_t new_size   = ALIGNED_STRING_SIZE(size);
 
     Buffer_bufstart(buffer) = (void *)aligned_mem(buffer,
         (char *)mem_allocate(interp,
@@ -883,8 +883,8 @@
      * normally, which play ping pong with buffers.
      * The normal case is therefore always to allocate a new block
      */
-    new_size = aligned_string_size(newsize);
-    old_size = aligned_string_size(Buffer_buflen(buffer));
+    new_size = ALIGNED_STRING_SIZE(newsize);
+    old_size = ALIGNED_STRING_SIZE(Buffer_buflen(buffer));
     needed   = new_size - old_size;
 
     if ((pool->top_block->free >= needed)
@@ -948,7 +948,7 @@
                 ? interp->mem_pools->constant_string_pool
                 : interp->mem_pools->memory_pool;
 
-    new_size = aligned_string_size(size);
+    new_size = ALIGNED_STRING_SIZE(size);
     mem      = (char *)mem_allocate(interp, interp->mem_pools, new_size, pool);
     mem     += sizeof (void *);
 
@@ -995,8 +995,8 @@
      * - 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(Buffer_buflen(str));
+    new_size = ALIGNED_STRING_SIZE(newsize);
+    old_size = ALIGNED_STRING_SIZE(Buffer_buflen(str));
     needed   = new_size - old_size;
 
     if (pool->top_block->free >= needed

Modified: branches/compact_pool_revamp/src/gc/gc_private.h
==============================================================================
--- branches/compact_pool_revamp/src/gc/gc_private.h	Mon Apr 26 09:29:04 2010	(r46025)
+++ branches/compact_pool_revamp/src/gc/gc_private.h	Mon Apr 26 10:22:55 2010	(r46026)
@@ -492,10 +492,6 @@
 char * aligned_mem(SHIM(const Buffer *buffer), ARGIN(char *mem))
         __attribute__nonnull__(2);
 
-PARROT_CONST_FUNCTION
-PARROT_WARN_UNUSED_RESULT
-size_t aligned_string_size(size_t len);
-
 void check_buffer_ptr(
     ARGMOD(Buffer * pobj),
     ARGMOD(Variable_Size_Pool * pool))
@@ -560,7 +556,6 @@
 
 #define ASSERT_ARGS_aligned_mem __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(mem))
-#define ASSERT_ARGS_aligned_string_size __attribute__unused__ int _ASSERT_ARGS_CHECK = (0)
 #define ASSERT_ARGS_check_buffer_ptr __attribute__unused__ int _ASSERT_ARGS_CHECK = (\
        PARROT_ASSERT_ARG(pobj) \
     , PARROT_ASSERT_ARG(pool))

Modified: branches/compact_pool_revamp/src/gc/mark_sweep.c
==============================================================================
--- branches/compact_pool_revamp/src/gc/mark_sweep.c	Mon Apr 26 09:29:04 2010	(r46025)
+++ branches/compact_pool_revamp/src/gc/mark_sweep.c	Mon Apr 26 10:22:55 2010	(r46026)
@@ -704,10 +704,6 @@
     ASSERT_ARGS(free_buffer)
     Variable_Size_Pool * const mem_pool = (Variable_Size_Pool *)pool->mem_pool;
 
-    /* If this is header for external buffer - bail out */
-    if (PObj_external_TEST(b))
-        return;
-
     /* If there is no allocated buffer - bail out */
     if (!Buffer_buflen(b))
         return;
@@ -716,7 +712,7 @@
      * shouldn't happen */
     if (mem_pool) {
         /* Update Memory_Block usage */
-        if (PObj_is_movable_TESTALL(b)) {
+        if (Buffer_buflen(b) && PObj_is_movable_TESTALL(b)) {
             INTVAL *buffer_flags = buffer_flags = Buffer_bufrefcountptr(b);
 
             /* Mask low 2 bits used for flags */
@@ -726,7 +722,7 @@
 
             /* We can have shared buffers. Don't count them (yet) */
             if (!(*buffer_flags & Buffer_shared_FLAG)) {
-                block->freed  += aligned_string_size(Buffer_buflen(b));
+                block->freed  += ALIGNED_STRING_SIZE(Buffer_buflen(b));
             }
 
         }


More information about the parrot-commits mailing list