Author: chromatic
Date: Tue Jun 12 01:15:50 2007
New Revision: 18944
Modified:
trunk/src/gc/smallobject.c
trunk/src/hash.c
Log:
[PDD 07] Minor coding standards cleanup. This is so much prettier!
Modified: trunk/src/gc/smallobject.c
==============================================================================
--- trunk/src/gc/smallobject.c (original)
+++ trunk/src/gc/smallobject.c Tue Jun 12 01:15:50 2007
@@ -20,13 +20,14 @@
/* HEADER: include/parrot/smallobject.h */
-#define GC_DEBUG_REPLENISH_LEVEL_FACTOR 0.0
+#define GC_DEBUG_REPLENISH_LEVEL_FACTOR 0.0
#define GC_DEBUG_UNITS_PER_ALLOC_GROWTH_FACTOR 1
-#define REPLENISH_LEVEL_FACTOR 0.3
+#define REPLENISH_LEVEL_FACTOR 0.3
+
/* this factor is totally arbitrary, but gives good timings for stress.pasm */
-#define UNITS_PER_ALLOC_GROWTH_FACTOR 1.75
+#define UNITS_PER_ALLOC_GROWTH_FACTOR 1.75
-#define POOL_MAX_BYTES 65536*128
+#define POOL_MAX_BYTES 65536 * 128
/*
@@ -51,11 +52,11 @@
(ptrdiff_t)ptr - (ptrdiff_t)arena->start_objects;
if (0 <= ptr_diff
- && ptr_diff <
- (ptrdiff_t)(arena->used * pool->object_size)
+ && ptr_diff < (ptrdiff_t)(arena->used * pool->object_size)
&& ptr_diff % pool->object_size == 0)
return 1;
}
+
return 0;
}
@@ -71,10 +72,11 @@
Parrot_is_const_pmc(Parrot_Interp interp /*NN*/, PMC *pmc)
{
Small_Object_Pool * const pool = interp->arena_base->constant_pmc_pool;
- const int c = contained_in_pool(interp, pool, pmc);
+ const int c = contained_in_pool(interp, pool, pmc);
/* some paranoia first */
assert(!!PObj_constant_TEST(pmc) == !!c);
+
return c;
}
@@ -97,6 +99,7 @@
if (arena) {
if (arena->used == arena->total_objects)
Parrot_do_dod_run(interp, DOD_trace_stack_FLAG);
+
if (pool->num_free_objects <= pool->replenish_level)
pool->skip = 1;
}
@@ -104,12 +107,10 @@
/* requires that num_free_objects be updated in Parrot_do_dod_run. If dod
* is disabled, then we must check the free list directly. */
- if (!pool->free_list) {
+ if (!pool->free_list)
(*pool->alloc_objects) (interp, pool);
- }
}
-
/*
FUNCDOC: gc_ms_add_free_object
@@ -119,10 +120,11 @@
*/
static void
-gc_ms_add_free_object(Interp *interp, Small_Object_Pool *pool /*NN*/, void
*to_add)
+gc_ms_add_free_object(Interp *interp, Small_Object_Pool *pool /*NN*/,
+ void *to_add)
{
*(void **)to_add = pool->free_list;
- pool->free_list = to_add;
+ pool->free_list = to_add;
}
/*
@@ -141,10 +143,14 @@
/* if we don't have any objects */
if (!pool->free_list)
(*pool->more_objects)(interp, pool);
- ptr = pool->free_list;
+
+ ptr = pool->free_list;
pool->free_list = *(void **)ptr;
+
PObj_flags_SETTO((PObj*) ptr, 0);
+
--pool->num_free_objects;
+
return ptr;
}
@@ -158,20 +164,20 @@
void
Parrot_add_to_free_list(Interp *interp,
- Small_Object_Pool *pool /*NN*/,
+ Small_Object_Pool *pool /*NN*/,
Small_Object_Arena *arena /*NN*/,
- UINTVAL start,
- UINTVAL end)
+ UINTVAL start,
+ UINTVAL end)
{
- UINTVAL i;
- void *object;
+ UINTVAL i;
+ void *object;
pool->total_objects += end - start;
- arena->used = end;
+ arena->used = end;
/* Move all the new objects into the free list */
- object = (void *)((char *)arena->start_objects +
- start * pool->object_size);
+ object = (void *)((char *)arena->start_objects + start *
pool->object_size);
+
for (i = start; i < end; i++) {
PObj_flags_SETTO((PObj *)object, PObj_on_free_list_FLAG);
/*
@@ -182,6 +188,7 @@
pool->add_free_object(interp, pool, object);
object = (void *)((char *)object + pool->object_size);
}
+
pool->num_free_objects += end - start;
}
@@ -193,7 +200,8 @@
*/
void
-Parrot_append_arena_in_pool(Interp *interp /*NN*/, Small_Object_Pool *pool
/*NN*/,
+Parrot_append_arena_in_pool(Interp *interp /*NN*/,
+ Small_Object_Pool *pool /*NN*/,
Small_Object_Arena *new_arena /*NN*/, size_t size)
{
@@ -206,12 +214,14 @@
if (!pool->last_Arena || (pool->end_arena_memory <
(size_t)new_arena->start_objects + size))
pool->end_arena_memory = (size_t)new_arena->start_objects + size;
+
new_arena->total_objects = pool->objects_per_alloc;
- new_arena->next = NULL;
- new_arena->prev = pool->last_Arena;
- if (new_arena->prev) {
+ new_arena->next = NULL;
+ new_arena->prev = pool->last_Arena;
+
+ if (new_arena->prev)
new_arena->prev->next = new_arena;
- }
+
pool->last_Arena = new_arena;
interp->arena_base->header_allocs_since_last_collect++;
}
@@ -228,22 +238,25 @@
static void
gc_ms_alloc_objects(Interp *interp /*NN*/, Small_Object_Pool *pool /*NN*/)
{
- size_t size;
+ size_t size;
UINTVAL start, end;
/* Setup memory for the new objects */
- Small_Object_Arena * const new_arena = (Small_Object_Arena
*)mem_internal_allocate(
- sizeof (Small_Object_Arena));
+ Small_Object_Arena * const new_arena =
+ mem_internal_allocate_typed(Small_Object_Arena);
+
if (!new_arena)
PANIC("Out of arena memory");
- size = pool->object_size * pool->objects_per_alloc;
+
+ size = pool->object_size * pool->objects_per_alloc;
+
/* could be mem_internal_allocate too, but calloc is fast */
new_arena->start_objects = mem_internal_allocate_zeroed(size);
Parrot_append_arena_in_pool(interp, pool, new_arena, size);
start = 0;
- end = pool->objects_per_alloc;
+ end = pool->objects_per_alloc;
Parrot_add_to_free_list(interp, pool, new_arena, start, end);
/* Allocate more next time */
@@ -256,15 +269,15 @@
else {
pool->objects_per_alloc = (size_t)(pool->objects_per_alloc *
UNITS_PER_ALLOC_GROWTH_FACTOR);
- pool->replenish_level =
+ pool->replenish_level =
(size_t)(pool->total_objects * REPLENISH_LEVEL_FACTOR);
}
+
/* check alloc size against maximum */
size = pool->object_size * pool->objects_per_alloc;
- if (size > POOL_MAX_BYTES) {
+ if (size > POOL_MAX_BYTES)
pool->objects_per_alloc = POOL_MAX_BYTES / pool->object_size;
- }
}
/*
@@ -275,20 +288,17 @@
*/
-
Small_Object_Pool *
new_small_object_pool(Interp *interp,
size_t object_size, size_t objects_per_alloc)
/* WARN_UNUSED */
{
Small_Object_Pool * const pool =
- (Small_Object_Pool *)mem_internal_allocate_zeroed(
- sizeof (Small_Object_Pool));
-
- pool->last_Arena = NULL;
- pool->free_list = NULL;
- pool->mem_pool = NULL;
+ mem_internal_allocate_zeroed_typed(Small_Object_Pool);
+ pool->last_Arena = NULL;
+ pool->free_list = NULL;
+ pool->mem_pool = NULL;
pool->object_size = object_size;
pool->objects_per_alloc = objects_per_alloc;
@@ -310,7 +320,7 @@
pool->add_free_object = gc_ms_add_free_object;
pool->get_free_object = gc_ms_get_free_object;
pool->alloc_objects = gc_ms_alloc_objects;
- pool->more_objects = more_traceable_objects;
+ pool->more_objects = more_traceable_objects;
}
/*
@@ -327,11 +337,11 @@
void
Parrot_gc_ms_init(Interp *interp /*NN*/)
{
- Arenas * const arena_base = interp->arena_base;
+ Arenas * const arena_base = interp->arena_base;
- arena_base->do_dod_run = Parrot_dod_ms_run;
+ arena_base->do_dod_run = Parrot_dod_ms_run;
arena_base->de_init_gc_system = (void (*)(Interp*)) NULLfunc;
- arena_base->init_pool = gc_ms_pool_init;
+ arena_base->init_pool = gc_ms_pool_init;
}
/*
@@ -346,8 +356,8 @@
Parrot_small_object_pool_merge(Interp *interp,
Small_Object_Pool *dest /*NN*/, Small_Object_Pool *source /*NN*/)
{
- Small_Object_Arena *cur_arena;
- void **free_list_end;
+ Small_Object_Arena *cur_arena;
+ void **free_list_end;
/* XXX num_free_objects doesn't seem to be accounted correctly in, e.g.,
* the PMC_EXT pool.
@@ -367,38 +377,41 @@
/* append new free_list to old */
/* XXX this won't work with, e.g., gc_gms */
- free_list_end = &dest->free_list;
- while (*free_list_end) {
+ free_list_end = &dest->free_list;
+
+ while (*free_list_end)
free_list_end = (void **)*free_list_end;
- }
+
*free_list_end = source->free_list;
/* now append source arenas */
cur_arena = source->last_Arena;
+
while (cur_arena) {
- size_t total_objects;
+ size_t total_objects;
Small_Object_Arena * const next_arena = cur_arena->prev;
cur_arena->next = cur_arena->prev = NULL;
- total_objects = cur_arena->total_objects;
+ total_objects = cur_arena->total_objects;
Parrot_append_arena_in_pool(interp, dest, cur_arena,
cur_arena->total_objects);
- cur_arena->total_objects = total_objects; /* XXX needed? */
+ /* XXX needed? */
+ cur_arena->total_objects = total_objects;
cur_arena = next_arena;
}
/* remove things from source */
/* XXX is this enough? */
- source->last_Arena = NULL;
- source->free_list = NULL;
- source->total_objects = 0;
+ source->last_Arena = NULL;
+ source->free_list = NULL;
+ source->total_objects = 0;
source->num_free_objects = 0;
-
}
+
/*
=head1 SEE ALSO
@@ -409,7 +422,6 @@
*/
-
/*
* Local variables:
* c-file-style: "parrot"
Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c (original)
+++ trunk/src/hash.c Tue Jun 12 01:15:50 2007
@@ -726,8 +726,8 @@
parrot_hash_get_bucket(Interp *interp, const Hash *hash, void *key)
/* PURE, WARN_UNUSED */
{
- const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
- HashBucket *bucket = hash->bi[hashval & hash->mask];
+ const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
+ HashBucket *bucket = hash->bi[hashval & hash->mask];
while (bucket) {
/* store hash_val or not */
if ((hash->compare)(interp, key, bucket->key) == 0)
@@ -782,7 +782,8 @@
parrot_hash_put(Interp *interp, Hash *hash, void *key, void *value)
{
const UINTVAL hashval = (hash->hash_val)(interp, key, hash->seed);
- HashBucket *bucket = hash->bi[hashval & hash->mask];
+ HashBucket *bucket = hash->bi[hashval & hash->mask];
+
while (bucket) {
/* store hash_val or not */
if ((hash->compare)(interp, key, bucket->key) == 0)
@@ -802,18 +803,22 @@
DOD_WRITE_BARRIER_KEY(interp, hash->container,
NULL, NULL, (PMC*)value, key);
}
+
bucket = hash->free_list;
+
if (!bucket) {
expand_hash(interp, hash);
bucket = hash->free_list;
}
+
hash->entries++;
- hash->free_list = bucket->next;
- bucket->key = key;
- bucket->value = value;
- bucket->next = hash->bi[hashval & hash->mask];
+ hash->free_list = bucket->next;
+ bucket->key = key;
+ bucket->value = value;
+ bucket->next = hash->bi[hashval & hash->mask];
hash->bi[hashval & hash->mask] = bucket;
}
+
return bucket;
}
@@ -865,24 +870,26 @@
parrot_new_hash_x(interp, dest, hash->entry_type,
hash->key_type, hash->compare, hash->hash_val);
+
for (i = 0; i <= hash->mask; i++) {
HashBucket *b = hash->bi[i];
while (b) {
- void * const key = b->key;
- void *valtmp;
+ void * const key = b->key;
+ void *valtmp;
+
switch (hash->entry_type) {
case enum_type_undef:
case enum_type_ptr:
case enum_type_INTVAL:
- valtmp = b->value;
+ valtmp = (void *)b->value;
break;
case enum_type_STRING:
- valtmp = string_copy(interp, (STRING *)b->value);
+ valtmp = (void *)string_copy(interp, (STRING *)b->value);
break;
case enum_type_PMC:
- valtmp = VTABLE_clone(interp, (PMC*)b->value);
+ valtmp = (void *)VTABLE_clone(interp, (PMC*)b->value);
break;
default: