From 4ffb19230ffb29cada63b557dbe3d7f2ae0ec92b Mon Sep 17 00:00:00 2001 From: theraven Date: Sun, 29 May 2011 14:27:41 +0000 Subject: [PATCH] Make sure that the statics used to store internal tables are marked as roots. --- alias_table.c | 2 +- class_table.c | 4 ++-- gc_boehm.c | 18 +++++++----------- hash_table.h | 17 +++++++++++++++++ loader.c | 5 ++++- protocol.c | 2 +- selector_table.c | 2 +- 7 files changed, 33 insertions(+), 17 deletions(-) diff --git a/alias_table.c b/alias_table.c index ed39040..8555038 100644 --- a/alias_table.c +++ b/alias_table.c @@ -64,7 +64,7 @@ static alias_table_internal_table *alias_table; PRIVATE void init_alias_table(void) { - alias_table = alias_table_internal_create(128); + alias_table_internal_initialize(&alias_table, 128); } diff --git a/class_table.c b/class_table.c index 4d1823f..34750b0 100644 --- a/class_table.c +++ b/class_table.c @@ -39,7 +39,7 @@ SEL loadSel; PRIVATE void objc_init_load_messages_table(void) { - load_table = load_messages_create(4096); + load_messages_initialize(&load_table, 4096); loadSel = sel_registerName("load"); } @@ -140,7 +140,7 @@ PRIVATE Class class_table_next(void **e) PRIVATE void init_class_tables(void) { - class_table = class_table_internal_create(4096); + class_table_internal_initialize(&class_table, 4096); objc_init_load_messages_table(); } diff --git a/gc_boehm.c b/gc_boehm.c index 392e662..59f1eec 100644 --- a/gc_boehm.c +++ b/gc_boehm.c @@ -540,8 +540,9 @@ static void runFinalizers(void) } } -static void init(void) +PRIVATE void init_gc(void) { + GC_INIT(); char *sigNumber; // Dump GC stats on exit - uncomment when debugging. if (getenv("LIBOBJC_DUMP_GC_STATUS_ON_EXIT")) @@ -553,12 +554,7 @@ static void init(void) int s = sigNumber[0] ? (int)strtol(sigNumber, NULL, 10) : SIGUSR2; signal(s, collectAndDumpStats); } - refcounts = refcount_create(4096); GC_clear_roots(); - finalize = sel_registerName("finalize"); - cxx_destruct = sel_registerName(".cxx_destruct"); - copy = sel_registerName("copy"); - GC_finalizer_notifier = runFinalizers; } BOOL objc_collecting_enabled(void) @@ -609,14 +605,14 @@ PRIVATE struct gc_ops gc_ops_boehm = .allocate_class = allocate_class, .malloc = debug_malloc, .free = debug_free, - .init = init }; PRIVATE void enableGC(BOOL exclude) { isGCEnabled = YES; - if (__sync_bool_compare_and_swap(&gc, &gc_ops_none, &gc_ops_boehm)) - { - gc->init(); - } + refcounts = refcount_create(4096); + finalize = sel_registerName("finalize"); + cxx_destruct = sel_registerName(".cxx_destruct"); + copy = sel_registerName("copy"); + GC_finalizer_notifier = runFinalizers; } diff --git a/hash_table.h b/hash_table.h index 3d21635..676b8d5 100644 --- a/hash_table.h +++ b/hash_table.h @@ -126,10 +126,18 @@ struct PREFIX(_table_cell_struct) *PREFIX(alloc_cells)(PREFIX(_table) *table, in # endif } +static void PREFIX(delete_table)(void *table, void *unused) +{ + fprintf(stderr, "finalizing table %p\n", table); +} PREFIX(_table) *PREFIX(_create)(uint32_t capacity) { PREFIX(_table) *table = CALLOC(1, sizeof(PREFIX(_table))); + fprintf(stderr, "Allocated hash table %p \n", table); +#ifdef ENABLE_GC + GC_REGISTER_FINALIZER_NO_ORDER(table, PREFIX(delete_table), 0, 0, 0); +#endif # ifndef MAP_TABLE_NO_LOCK INIT_LOCK(table->lock); # endif @@ -143,6 +151,15 @@ PREFIX(_table) *PREFIX(_create)(uint32_t capacity) table->table_size = capacity; return table; } + +void PREFIX(_initialize)(PREFIX(_table) **table, uint32_t capacity) +{ +#ifdef ENABLE_GC + GC_add_roots(table, table+1); +#endif + *table = PREFIX(_create)(capacity); +} + # define TABLE_SIZE(x) (x->table_size) #endif diff --git a/loader.c b/loader.c index d4c1552..c7226d1 100644 --- a/loader.c +++ b/loader.c @@ -7,6 +7,7 @@ #ifdef ENABLE_GC #include #endif +#include /** * Runtime lock. This is exposed in @@ -19,6 +20,7 @@ void init_protocol_table(void); void init_class_tables(void); void init_dispatch_tables(void); void init_alias_table(void); +void init_gc(void); void objc_send_load_message(Class class); /* Number of threads that are alive. */ @@ -28,6 +30,7 @@ void __objc_exec_class(struct objc_module_abi_8 *module) { static BOOL first_run = YES; + fprintf(stderr, "Loading %s\n", module->name); // Check that this module uses an ABI version that we recognise. // In future, we should pass the ABI version to the class / category load // functions so that we can change various structures more easily. @@ -36,7 +39,7 @@ void __objc_exec_class(struct objc_module_abi_8 *module) if (first_run) { #if ENABLE_GC - GC_INIT(); + init_gc(); #endif // Create the main runtime lock. This is not safe in theory, but in // practice the first time that this function is called will be in the diff --git a/protocol.c b/protocol.c index c889e02..66f43d1 100644 --- a/protocol.c +++ b/protocol.c @@ -31,7 +31,7 @@ static protocol_table *known_protocol_table; void init_protocol_table(void) { - known_protocol_table = protocol_create(128); + protocol_initialize(&known_protocol_table, 128); } static void protocol_table_insert(const struct objc_protocol2 *protocol) diff --git a/selector_table.c b/selector_table.c index 1c03a72..4f9ecbf 100644 --- a/selector_table.c +++ b/selector_table.c @@ -239,7 +239,7 @@ PRIVATE void init_selector_tables() { selector_list = SparseArrayNew(); INIT_LOCK(selector_table_lock); - sel_table = selector_create(4096); + selector_initialize(&sel_table, 4096); } static SEL selector_lookup(const char *name, const char *types)