Skip to content

Commit

Permalink
gc_ms: skip counting num_free_objects unless GC_STATS (debugging only)
Browse files Browse the repository at this point in the history
  • Loading branch information
Reini Urban committed Jan 23, 2015
1 parent 68c7dac commit 53139d9
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 10 deletions.
20 changes: 16 additions & 4 deletions src/gc/fixed_allocator.c
Expand Up @@ -419,6 +419,7 @@ Static implementation of public methods.
*/

PARROT_INLINE
PARROT_CANNOT_RETURN_NULL
static void *
get_free_list_item(ARGMOD(Pool_Allocator *pool))
Expand All @@ -427,7 +428,9 @@ get_free_list_item(ARGMOD(Pool_Allocator *pool))

Pool_Allocator_Free_List * const item = pool->free_list;
pool->free_list = item->next;
#ifdef GC_STATS
--pool->num_free_objects;
#endif
return item;
}

Expand All @@ -446,20 +449,24 @@ pool_allocate(PARROT_INTERP, ARGMOD(Pool_Allocator *pool))
return get_newfree_list_item(pool);
}

PARROT_INLINE
PARROT_CANNOT_RETURN_NULL
static void *
get_newfree_list_item(ARGMOD(Pool_Allocator *pool))
{
ASSERT_ARGS(get_newfree_list_item)

Pool_Allocator_Free_List * const item = pool->newfree;
#ifdef GC_STATS
--pool->num_free_objects;
#endif
pool->newfree = (Pool_Allocator_Free_List *)
((char *)(pool->newfree) + pool->object_size);

--pool->num_free_objects;
return item;
}

PARROT_INLINE
static void
pool_free(SHIM_INTERP, ARGMOD(Pool_Allocator *pool), ARGMOD(void *data))
{
Expand All @@ -473,9 +480,12 @@ pool_free(SHIM_INTERP, ARGMOD(Pool_Allocator *pool), ARGMOD(void *data))
item->next = pool->free_list;
pool->free_list = item;

#ifdef GC_STATS
++pool->num_free_objects;
#endif
}

PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
PARROT_PURE_FUNCTION
static int
Expand All @@ -490,6 +500,7 @@ pool_is_maybe_owned(ARGIN(const Pool_Allocator *pool), ARGIN(const void *ptr))
return (ptr >= pool->lo_arena_ptr && ptr < pool->hi_arena_ptr);
}

PARROT_INLINE
PARROT_WARN_UNUSED_RESULT
static int
pool_is_owned(ARGIN(const Pool_Allocator *pool), ARGIN(const void *ptr))
Expand All @@ -500,8 +511,8 @@ pool_is_owned(ARGIN(const Pool_Allocator *pool), ARGIN(const void *ptr))
int p;

for (p = 0; p < pool->num_arenas; p++) {
const size_t idx = 2 * p;
void * const low = pool->arena_bounds[idx];
const size_t idx = 2 * p;
void * const low = pool->arena_bounds[idx];
void * const high = pool->arena_bounds[idx + 1];
if (ptr >= low && ptr < high) {
const ptrdiff_t ptrdiff = (const char *)ptr - (const char *)low;
Expand Down Expand Up @@ -551,8 +562,9 @@ allocate_new_pool_arena(PARROT_INTERP, ARGMOD(Pool_Allocator *pool))
pool->newfree = next;
pool->newlast = last;

#ifdef GC_STATS
pool->num_free_objects += num_items;

#endif
if (pool->lo_arena_ptr > (void *)next)
pool->lo_arena_ptr = next;

Expand Down
24 changes: 18 additions & 6 deletions src/gc/gc_ms.c
@@ -1,5 +1,5 @@
/*
Copyright (C) 2001-2014, Parrot Foundation.
Copyright (C) 2001-2015, Parrot Foundation.
=head1 NAME
Expand Down Expand Up @@ -633,11 +633,9 @@ gc_ms_mark_and_sweep(PARROT_INTERP, UINTVAL flags)
function to the PMC pool and all the sized pools. */
header_pools_iterate_callback(interp, mem_pools,
POOL_BUFFER | POOL_PMC, (void *)&total_free, gc_ms_sweep_cb);

}
else {
++interp->gc_sys->stats.gc_lazy_mark_runs;

Parrot_gc_clear_live_bits(interp, mem_pools->pmc_pool);
}

Expand Down Expand Up @@ -838,7 +836,9 @@ gc_ms_free_pmc_header(PARROT_INTERP, ARGMOD(PMC *pmc))

PObj_flags_SETTO((PObj *)pmc, PObj_on_free_list_FLAG);
pool->add_free_object(interp, mem_pools, pool, (PObj *)pmc);
#ifdef GC_STATS
++pool->num_free_objects;
#endif
}

/*
Expand Down Expand Up @@ -967,7 +967,9 @@ gc_ms_free_string_header(PARROT_INTERP, ARGMOD(STRING *s))
Fixed_Size_Pool * const pool = mem_pools->string_header_pool;
PObj_flags_SETTO((PObj *)s, PObj_on_free_list_FLAG);
pool->add_free_object(interp, mem_pools, pool, s);
#ifdef GC_STATS
++pool->num_free_objects;
#endif
}
}

Expand Down Expand Up @@ -1100,7 +1102,9 @@ Parrot_gc_get_attributes_from_pool(PARROT_INTERP, ARGMOD(PMC_Attribute_Pool * po
return Parrot_gc_get_attributes_from_pool(interp, pool);
}

#ifdef GC_STATS
--pool->num_free_objects; /* the hottest op in --gc ms: 11.64% */
#endif
return (void *)item;
}

Expand All @@ -1127,7 +1131,9 @@ Parrot_gc_allocate_new_attributes_arena(ARGMOD(PMC_Attribute_Pool *pool))
pool->newfree = next;
pool->newlast = (PMC_Attribute_Free_List *)((char *)next + item_space);

#ifdef GC_STATS
pool->num_free_objects += num_items;
#endif
pool->total_objects += num_items;
}

Expand Down Expand Up @@ -1198,7 +1204,9 @@ Parrot_gc_create_attrib_pool(size_t attrib_idx)
newpool->attr_size = attrib_size;
newpool->total_objects = 0;
newpool->objects_per_alloc = num_objs;
#ifdef GC_STATS
newpool->num_free_objects = 0;
#endif
newpool->free_list = NULL;
newpool->top_arena = NULL;

Expand Down Expand Up @@ -1313,7 +1321,9 @@ gc_ms_free_attributes_from_pool(ARGMOD(PMC_Attribute_Pool *pool), ARGMOD(void *d
item->next = pool->free_list;
pool->free_list = item;

#ifdef GC_STATS
++pool->num_free_objects;
#endif
}

/*
Expand Down Expand Up @@ -1507,8 +1517,9 @@ gc_ms_sweep_cb(PARROT_INTERP,

Parrot_gc_sweep_pool(interp, mem_pools, pool);

#ifdef GC_STATS
*total_free += pool->num_free_objects;

#endif
return 0;
}

Expand Down Expand Up @@ -1567,8 +1578,9 @@ gc_ms_more_traceable_objects(PARROT_INTERP,
&& Parrot_gc_ms_needed(interp)))
Parrot_gc_mark_and_sweep(interp, GC_trace_stack_FLAG);

/* requires that num_free_objects be updated in Parrot_gc_mark_and_sweep.
If gc is disabled, then we must check the free list directly. */
/* Requires that num_free_objects be updated in Parrot_gc_mark_and_sweep.
Keeping num_free_objects is expensive, so we disable it with --optimize.
Also if gc is disabled, then we must check the free list directly. */
if ((!pool->free_list || pool->num_free_objects < pool->replenish_level)
&& !pool->newfree)
(*pool->alloc_objects) (interp, mem_pools, pool);
Expand Down
13 changes: 13 additions & 0 deletions src/gc/gc_private.h
Expand Up @@ -25,6 +25,17 @@ Parrot.
#include "parrot/settings.h"
#include "variable_size_pool.h"

/* Do not calculate private gc statistics, only used in gc_ms.
Currently skipped: num_free_objects.
*/
#ifndef GC_STATS
# ifdef NDEBUG
# undef GC_STATS
# else
# define GC_STATS
# endif
#endif

#if ! DISABLE_GC_DEBUG
/* Set when walking the system stack. Defined in src/gc/system.c */
extern int CONSERVATIVE_POINTER_CHASING;
Expand Down Expand Up @@ -316,7 +327,9 @@ typedef struct PMC_Attribute_Pool {
size_t attr_size; /* Size of attribute object. */
size_t total_objects; /* Total objects in the pool. */
size_t objects_per_alloc; /* Number of object slots to allocate. */
#ifdef GC_STATS
size_t num_free_objects; /* Number of objects on the free list. */
#endif
PMC_Attribute_Free_List * free_list; /* List of free object slots, or NULL. */
PMC_Attribute_Arena * top_arena; /* Pointer to most recent arena. */
PMC_Attribute_Free_List * newfree; /* Pointer to next object slot in
Expand Down

0 comments on commit 53139d9

Please sign in to comment.