Make sure that the statics used to store internal tables are marked as roots.

main
theraven 15 years ago
parent 8f530849fd
commit 4ffb19230f

@ -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);
}

@ -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();
}

@ -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;
}

@ -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

@ -7,6 +7,7 @@
#ifdef ENABLE_GC
#include <gc/gc.h>
#endif
#include <stdio.h>
/**
* 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

@ -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)

@ -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)

Loading…
Cancel
Save