Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

Whiteknight/pmc is ptr #160

Closed
wants to merge 8 commits into from

4 participants

@gerdr

changes to more accurately track arena sizes
fixes bugs in whiteknight's original pull request

@leto
Owner

Did you mean to submit this pull request into master or whiteknight/pmc_is_ptr ?

@gerdr

should have gone to whiteknight/pmc_is_ptr, but my github-fu is weak - I'll close and re-open a request with the correct target branch...

@leto
Owner

No worries. Just use the "switch branches" toggle on the upper left to switch to the branch you want a pull request for, then hit the pull request button.

@gerdr

sent pull request with correct target branch; sorry for the noise...

@gerdr gerdr closed this
@rurban rurban referenced this pull request from a commit
@rurban rurban [imcc] fix GH #1061, nqp -O2: set_addr label marks a basic_block
set_addr label does mark a basic_block, dead_code_remove() needs the
label. disable old premature optimization

Fixes nqp/#160
All nqp tests pass now with parrot -O2.
dfe541d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Sep 4, 2011
  1. @Whiteknight

    first stab at a gc is_pmc_ptr optimization from jnthn__++. Parrot mos…

    Whiteknight authored
    …tly builds and is only a little segfaulty. I need to double-check some logic
  2. @Whiteknight
  3. @Whiteknight

    misc cleanups

    Whiteknight authored
  4. @Whiteknight

    Allocate the array_bounds array in chunks of 128, so we aren't doing …

    Whiteknight authored
    …a realloc on every arena allocation
  5. @Whiteknight

    Allocate the arena_bounds array when the pool is allocated. Don't che…

    Whiteknight authored
    …ck for NULL every time we get a new arena
  6. @Benabik

    Fix g++ build errors

    Benabik authored
    g++ is far pickier about casts, and it's good to make these things
    explicit.
Commits on Sep 5, 2011
  1. @gerdr
  2. @gerdr

    remove unnecessary casts

    gerdr authored
This page is out of date. Refresh to see the latest.
Showing with 38 additions and 22 deletions.
  1. +31 −22 src/gc/fixed_allocator.c
  2. +7 −0 src/gc/fixed_allocator.h
View
53 src/gc/fixed_allocator.c
@@ -313,6 +313,8 @@ Parrot_gc_pool_new(SHIM_INTERP, size_t object_size)
newpool->hi_arena_ptr = NULL;
newpool->newfree = NULL;
newpool->newlast = NULL;
+ newpool->num_arenas = 0;
+ newpool->arena_bounds = (void **)mem_sys_allocate(NEXT_ARENA_BOUNDS_SIZE(0));
return newpool;
}
@@ -330,6 +332,7 @@ Parrot_gc_pool_destroy(SHIM_INTERP, ARGMOD(Pool_Allocator *pool))
mem_internal_free(arena);
arena = next;
}
+ mem_sys_free(pool->arena_bounds);
mem_internal_free(pool);
}
@@ -506,25 +509,20 @@ static int
pool_is_owned(ARGMOD(Pool_Allocator *pool), ARGIN(const void *ptr))
{
ASSERT_ARGS(pool_is_owned)
-
- if (ptr >= pool->lo_arena_ptr && ptr <= pool->hi_arena_ptr) {
- const Pool_Allocator_Arena *arena = pool->top_arena;
-
- /* We can cache these values. All arenas are same size */
- const ptrdiff_t a_size = arena_size(pool);
-
- while (arena) {
- const Pool_Allocator_Arena * const arena_item = arena + 1;
- const ptrdiff_t ptr_diff = (const char *) ptr - (const char *) arena_item;
-
- if (ptr_diff >= 0 && ptr_diff < a_size
- && ptr_diff % pool->object_size == 0)
+ int p;
+
+ if (ptr >= pool->lo_arena_ptr && ptr < pool->hi_arena_ptr) {
+ for (p = 0; p < pool->num_arenas; p++) {
+ 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;
+ if (ptrdiff % pool->object_size == 0)
return 1;
-
- arena = arena->next;
+ }
}
}
-
return 0;
}
@@ -543,7 +541,7 @@ static void
allocate_new_pool_arena(PARROT_INTERP, ARGMOD(Pool_Allocator *pool))
{
ASSERT_ARGS(allocate_new_pool_arena)
- Pool_Allocator_Free_List *next;
+ Pool_Allocator_Free_List *next, *last;
Pool_Allocator_Arena *new_arena;
const size_t num_items = pool->objects_per_alloc;
@@ -563,18 +561,28 @@ allocate_new_pool_arena(PARROT_INTERP, ARGMOD(Pool_Allocator *pool))
new_arena->next = pool->top_arena;
pool->top_arena = new_arena;
next = (Pool_Allocator_Free_List *)(new_arena + 1);
+ last = (Pool_Allocator_Free_List *)((char *)next + item_space);
pool->newfree = next;
- pool->newlast = (Pool_Allocator_Free_List *)((char *)next + item_space);
+ pool->newlast = last;
pool->num_free_objects += num_items;
pool->total_objects += num_items;
- if (pool->lo_arena_ptr > (void *)new_arena)
- pool->lo_arena_ptr = new_arena;
+ if (pool->lo_arena_ptr > (void *)next)
+ pool->lo_arena_ptr = next;
+
+ if (pool->hi_arena_ptr < (void *)last)
+ pool->hi_arena_ptr = last;
- if ((char *)pool->hi_arena_ptr < (char *)new_arena + total_size)
- pool->hi_arena_ptr = (char *)new_arena + total_size;
+ if (pool->num_arenas % ARENA_BOUNDS_PADDING == 0)
+ pool->arena_bounds = (void **)mem_sys_realloc(pool->arena_bounds, NEXT_ARENA_BOUNDS_SIZE(pool->num_arenas));
+ pool->num_arenas++;
+ {
+ size_t ptr_idx = (pool->num_arenas - 1) * 2;
+ pool->arena_bounds[ptr_idx] = next;
+ pool->arena_bounds[ptr_idx + 1] = last;
+ }
}
/*
@@ -612,6 +620,7 @@ arena_size(ARGIN(const Pool_Allocator *self))
=cut
+
*/
/*
View
7 src/gc/fixed_allocator.h
@@ -23,6 +23,9 @@ src/gc/fixed_allocator.h - implementation of allocator for small-size objects.
increase *_HEADERS_PER_ALLOC and GC_FIXED_SIZE_POOL_SIZE to be large
enough to satisfy most startup costs. */
+#define ARENA_BOUNDS_PADDING 128
+#define NEXT_ARENA_BOUNDS_SIZE(n) (2 * ((n) + ARENA_BOUNDS_PADDING) * sizeof (void*))
+
typedef struct Pool_Allocator_Free_List {
struct Pool_Allocator_Free_List * next;
} Pool_Allocator_Free_List;
@@ -45,6 +48,10 @@ typedef struct Pool_Allocator {
/* Pointers of arena bounds. Used in .is_owned check */
void *lo_arena_ptr;
void *hi_arena_ptr;
+
+ int num_arenas; /* number of arenas, for keeping track of the
+ size of arena_bounds */
+ void **arena_bounds; /* Array of low/high pairs for each arena. */
} Pool_Allocator;
typedef struct Fixed_Allocator
Something went wrong with that request. Please try again.