mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-09 23:40:29 +02:00
API-ify gc_print_stats; add semi-inline.h
This commit is contained in:
parent
a00c83878e
commit
8f2f4f7c69
7 changed files with 71 additions and 66 deletions
4
bdw.h
4
bdw.h
|
@ -278,9 +278,7 @@ static void* gc_call_without_gc(struct mutator *mut,
|
|||
return GC_do_blocking(f, data);
|
||||
}
|
||||
|
||||
static inline void print_start_gc_stats(struct heap *heap) {
|
||||
}
|
||||
static inline void print_end_gc_stats(struct heap *heap) {
|
||||
static void gc_print_stats(struct heap *heap) {
|
||||
printf("Completed %ld collections\n", (long)GC_get_gc_no());
|
||||
printf("Heap size is %ld\n", (long)GC_get_heap_size());
|
||||
}
|
||||
|
|
1
gc-api.h
1
gc-api.h
|
@ -43,6 +43,7 @@ GC_API_ struct mutator* gc_init_for_thread(uintptr_t *stack_base,
|
|||
GC_API_ void gc_finish_for_thread(struct mutator *mut);
|
||||
GC_API_ void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
|
||||
void *data) GC_NEVER_INLINE;
|
||||
GC_API_ void gc_print_stats(struct heap *heap);
|
||||
|
||||
enum gc_allocator_kind {
|
||||
GC_ALLOCATOR_INLINE_BUMP_POINTER,
|
||||
|
|
|
@ -430,7 +430,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
printf("Garbage Collector Test\n");
|
||||
printf(" Live storage will peak at %zd bytes.\n\n", heap_max_live);
|
||||
print_start_gc_stats(heap);
|
||||
|
||||
unsigned long start = current_time();
|
||||
|
||||
|
@ -456,5 +455,5 @@ int main(int argc, char *argv[]) {
|
|||
}
|
||||
|
||||
printf("Completed in %.3f msec\n", elapsed_millis(start));
|
||||
print_end_gc_stats(heap);
|
||||
gc_print_stats(heap);
|
||||
}
|
||||
|
|
4
quads.c
4
quads.c
|
@ -149,8 +149,6 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
PUSH_HANDLE(mut, quad);
|
||||
|
||||
print_start_gc_stats(heap);
|
||||
|
||||
printf("Making quad tree of depth %zu (%zu nodes). Total size %.3fGB.\n",
|
||||
depth, nquads, (nquads * sizeof(Quad)) / 1e9);
|
||||
unsigned long start = current_time();
|
||||
|
@ -176,7 +174,7 @@ int main(int argc, char *argv[]) {
|
|||
print_elapsed("allocation loop", garbage_start);
|
||||
print_elapsed("quads test", gc_start);
|
||||
|
||||
print_end_gc_stats(heap);
|
||||
gc_print_stats(heap);
|
||||
|
||||
POP_HANDLE(mut);
|
||||
return 0;
|
||||
|
|
54
semi-inline.h
Normal file
54
semi-inline.h
Normal file
|
@ -0,0 +1,54 @@
|
|||
#ifndef SEMI_INLINE_H
|
||||
#define SEMI_INLINE_H
|
||||
|
||||
#include "gc-api.h"
|
||||
|
||||
static const uintptr_t GC_ALIGNMENT = 8;
|
||||
static const size_t GC_LARGE_OBJECT_THRESHOLD = 8192;
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return GC_ALIGNMENT;
|
||||
}
|
||||
static inline size_t gc_allocator_large_threshold(void) {
|
||||
return GC_LARGE_OBJECT_THRESHOLD;
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_allocation_pointer_offset(void) {
|
||||
return sizeof(uintptr_t) * 0;
|
||||
}
|
||||
static inline size_t gc_allocator_allocation_limit_offset(void) {
|
||||
return sizeof(uintptr_t) * 1;
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_freelist_offset(size_t size) {
|
||||
abort();
|
||||
}
|
||||
|
||||
static inline int gc_allocator_needs_clear(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_alloc_table_alignment(void) {
|
||||
return 0;
|
||||
}
|
||||
static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) {
|
||||
abort();
|
||||
}
|
||||
static inline uint8_t gc_allocator_alloc_table_end_pattern(void) {
|
||||
abort();
|
||||
}
|
||||
|
||||
static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) {
|
||||
return GC_WRITE_BARRIER_NONE;
|
||||
}
|
||||
static inline size_t gc_small_write_barrier_card_table_alignment(void) {
|
||||
abort();
|
||||
}
|
||||
static inline size_t gc_small_write_barrier_card_size(void) {
|
||||
abort();
|
||||
}
|
||||
|
||||
#endif // SEMI_INLINE_H
|
66
semi.h
66
semi.h
|
@ -5,6 +5,7 @@
|
|||
#include <sys/mman.h>
|
||||
#include <unistd.h>
|
||||
|
||||
#include "semi-inline.h"
|
||||
#include "large-object-space.h"
|
||||
#include "precise-roots.h"
|
||||
|
||||
|
@ -29,48 +30,11 @@ struct mutator {
|
|||
struct handle *roots;
|
||||
};
|
||||
|
||||
static const uintptr_t ALIGNMENT = 8;
|
||||
static const size_t LARGE_OBJECT_THRESHOLD = 8192;
|
||||
|
||||
static inline void clear_memory(uintptr_t addr, size_t size) {
|
||||
memset((char*)addr, 0, size);
|
||||
}
|
||||
|
||||
static inline enum gc_allocator_kind gc_allocator_kind(void) {
|
||||
return GC_ALLOCATOR_INLINE_BUMP_POINTER;
|
||||
}
|
||||
static inline size_t gc_allocator_small_granule_size(void) {
|
||||
return ALIGNMENT;
|
||||
}
|
||||
static inline size_t gc_allocator_large_threshold(void) {
|
||||
return LARGE_OBJECT_THRESHOLD;
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_allocation_pointer_offset(void) {
|
||||
return offsetof(struct semi_space, hp);
|
||||
}
|
||||
static inline size_t gc_allocator_allocation_limit_offset(void) {
|
||||
return offsetof(struct semi_space, limit);
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_freelist_offset(size_t size) {
|
||||
abort();
|
||||
}
|
||||
|
||||
static inline int gc_allocator_needs_clear(void) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
static inline size_t gc_allocator_alloc_table_alignment(void) {
|
||||
return 0;
|
||||
}
|
||||
static inline uint8_t gc_allocator_alloc_table_begin_pattern(void) {
|
||||
abort();
|
||||
}
|
||||
static inline uint8_t gc_allocator_alloc_table_end_pattern(void) {
|
||||
abort();
|
||||
}
|
||||
|
||||
static inline struct heap* mutator_heap(struct mutator *mut) {
|
||||
return &mut->heap;
|
||||
}
|
||||
|
@ -135,14 +99,14 @@ static void* copy(struct semi_space *space, void *obj) {
|
|||
void *new_obj = (void*)space->hp;
|
||||
memcpy(new_obj, obj, size);
|
||||
*(uintptr_t*) obj = space->hp;
|
||||
space->hp += align_up (size, ALIGNMENT);
|
||||
space->hp += align_up (size, GC_ALIGNMENT);
|
||||
return new_obj;
|
||||
}
|
||||
|
||||
static uintptr_t scan(struct heap *heap, uintptr_t grey) {
|
||||
size_t size;
|
||||
gc_trace_object((void*)grey, visit, heap, &size);
|
||||
return grey + align_up(size, ALIGNMENT);
|
||||
return grey + align_up(size, GC_ALIGNMENT);
|
||||
}
|
||||
|
||||
static void* forward(struct semi_space *space, void *obj) {
|
||||
|
@ -237,7 +201,7 @@ static void* gc_allocate_small(struct mutator *mut, size_t size) {
|
|||
struct semi_space *space = mutator_semi_space(mut);
|
||||
while (1) {
|
||||
uintptr_t addr = space->hp;
|
||||
uintptr_t new_hp = align_up (addr + size, ALIGNMENT);
|
||||
uintptr_t new_hp = align_up (addr + size, GC_ALIGNMENT);
|
||||
if (space->limit < new_hp) {
|
||||
collect_for_alloc(mut, size);
|
||||
continue;
|
||||
|
@ -252,16 +216,6 @@ static inline void* gc_allocate_pointerless(struct mutator *mut, size_t size) {
|
|||
return gc_allocate(mut, size);
|
||||
}
|
||||
|
||||
static inline enum gc_write_barrier_kind gc_small_write_barrier_kind(void) {
|
||||
return GC_WRITE_BARRIER_NONE;
|
||||
}
|
||||
static inline size_t gc_small_write_barrier_card_table_alignment(void) {
|
||||
abort();
|
||||
}
|
||||
static inline size_t gc_small_write_barrier_card_size(void) {
|
||||
abort();
|
||||
}
|
||||
|
||||
static int initialize_semi_space(struct semi_space *space, size_t size) {
|
||||
// Allocate even numbers of pages.
|
||||
size_t page_size = getpagesize();
|
||||
|
@ -348,8 +302,15 @@ static int parse_options(int argc, struct gc_option argv[],
|
|||
return 1;
|
||||
}
|
||||
|
||||
#define GC_ASSERT_EQ(a, b) GC_ASSERT((a) == (b))
|
||||
|
||||
static int gc_init(int argc, struct gc_option argv[],
|
||||
struct heap **heap, struct mutator **mut) {
|
||||
GC_ASSERT_EQ(gc_allocator_allocation_pointer_offset(),
|
||||
offsetof(struct semi_space, hp));
|
||||
GC_ASSERT_EQ(gc_allocator_allocation_limit_offset(),
|
||||
offsetof(struct semi_space, limit));
|
||||
|
||||
struct options options = { 0, };
|
||||
if (!parse_options(argc, argv, &options))
|
||||
return 0;
|
||||
|
@ -384,10 +345,7 @@ static void* gc_call_without_gc(struct mutator *mut, void* (*f)(void*),
|
|||
return f(data);
|
||||
}
|
||||
|
||||
static inline void print_start_gc_stats(struct heap *heap) {
|
||||
}
|
||||
|
||||
static inline void print_end_gc_stats(struct heap *heap) {
|
||||
static void gc_print_stats(struct heap *heap) {
|
||||
struct semi_space *space = heap_semi_space(heap);
|
||||
printf("Completed %ld collections\n", space->count);
|
||||
printf("Heap size is %zd\n", space->size);
|
||||
|
|
|
@ -2097,10 +2097,7 @@ static void* gc_call_without_gc(struct mutator *mut,
|
|||
return ret;
|
||||
}
|
||||
|
||||
static inline void print_start_gc_stats(struct heap *heap) {
|
||||
}
|
||||
|
||||
static inline void print_end_gc_stats(struct heap *heap) {
|
||||
static void gc_print_stats(struct heap *heap) {
|
||||
printf("Completed %ld collections (%ld major)\n",
|
||||
heap->count, heap->count - heap->minor_count);
|
||||
printf("Heap size with overhead is %zd (%zu slabs)\n",
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue