From ab75598043519b10963b8be04de8aeefd44a3f44 Mon Sep 17 00:00:00 2001 From: Zack Buhman Date: Mon, 6 Jan 2025 22:29:32 -0600 Subject: [PATCH] remove class_resolver_memoize_string_type This was a decent idea, but it is not flexible enough to allow for correct superclass type comparisons. --- c/class_resolver.c | 34 ---------------------------------- c/class_resolver.h | 7 ------- c/execute.c | 16 +--------------- c/frame.c | 3 --- c/frame.h | 4 ---- test/TestMultiArray.java | 2 +- 6 files changed, 2 insertions(+), 64 deletions(-) diff --git a/c/class_resolver.c b/c/class_resolver.c index 844873d..dea31a5 100644 --- a/c/class_resolver.c +++ b/c/class_resolver.c @@ -665,37 +665,3 @@ bool class_resolver_instanceof(int class_hash_table_length, class_entry->class_file->super_class); } } - -struct hash_table_entry * class_resolver_init_string_hash_table(int length) -{ - assert((length & (length - 1)) == 0); // length must be a power of two - int hash_table_length = length; - uint32_t hash_table_size = (sizeof (struct hash_table_entry)) * hash_table_length; - struct hash_table_entry * hash_table = malloc_class_arena(hash_table_size); - hash_table_init(hash_table_length, hash_table); - - return hash_table; -} - -void * class_resolver_memoize_string_type(int string_hash_table_length, - struct hash_table_entry * string_hash_table, - const uint8_t * type, - int length) -{ - struct hash_table_entry * e = hash_table_find(string_hash_table_length, - string_hash_table, - type, - length); - if (e != nullptr) { - assert(e->value == (void *)0x12345678); - return e; - } else { - struct hash_table_entry * e = hash_table_add(string_hash_table_length, - string_hash_table, - type, - length, - (void *)0x12345678); - assert(e != nullptr); - return e; - } -} diff --git a/c/class_resolver.h b/c/class_resolver.h index 33413eb..48c8e36 100644 --- a/c/class_resolver.h +++ b/c/class_resolver.h @@ -95,10 +95,3 @@ bool class_resolver_instanceof(int class_hash_table_length, struct class_entry * origin_class_entry, const int class_index, struct objectref * objectref); - -struct hash_table_entry * class_resolver_init_string_hash_table(int length); - -void * class_resolver_memoize_string_type(int string_hash_table_length, - struct hash_table_entry * string_hash_table, - const uint8_t * type, - int length); diff --git a/c/execute.c b/c/execute.c index 3e33461..1317c8c 100644 --- a/c/execute.c +++ b/c/execute.c @@ -1663,21 +1663,7 @@ static struct arrayref * _multiarray(struct vm * vm, int32_t * dims, int num_dim struct arrayref * arrayref = memory_allocate(size); assert(arrayref != nullptr); arrayref->length = count; - { // generate/recall unique pointer for type string - uint8_t * array_type = type - 1; - assert(*array_type == '['); - int type_length = type_end - array_type; - assert(type_length > 0); - void * type = class_resolver_memoize_string_type(vm->string_hash_table.length, - vm->string_hash_table.entry, - array_type, - type_length); - debugf("memoized string type: %d %p: ", count, type); - print_string((const char *)array_type, type_length); - debugc('\n'); - assert(type != nullptr); - arrayref->class_entry = type; - } + arrayref->class_entry = nullptr; int32_t array_element_size = count * element_size; // bytes int32_t u32_count = (array_element_size + 3) / 4; // u32 units diff --git a/c/frame.c b/c/frame.c index 3910035..9d99e9e 100644 --- a/c/frame.c +++ b/c/frame.c @@ -612,9 +612,6 @@ struct vm * vm_start(int class_hash_table_length, vm.class_hash_table.length = class_hash_table_length; vm.class_hash_table.entry = class_hash_table; - vm.string_hash_table.length = 128; - vm.string_hash_table.entry = class_resolver_init_string_hash_table(vm.string_hash_table.length); - vm.frame_stack.ix = 0; vm.frame_stack.capacity = 1024; struct frame frames[vm.frame_stack.capacity]; diff --git a/c/frame.h b/c/frame.h index f633357..4795baf 100644 --- a/c/frame.h +++ b/c/frame.h @@ -35,10 +35,6 @@ struct vm { int length; struct hash_table_entry * entry; } class_hash_table; - struct { - int length; - struct hash_table_entry * entry; - } string_hash_table; }; static inline struct frame * stack_push_frame(struct stack * stack, int num_frames) { diff --git a/test/TestMultiArray.java b/test/TestMultiArray.java index 11f6949..efaaef8 100644 --- a/test/TestMultiArray.java +++ b/test/TestMultiArray.java @@ -11,7 +11,7 @@ class TestMultiArray { return a instanceof Object[][]; } - public static void main(String[] args) { + public static void main() { System.out.print("testInstanceof: "); System.out.println(testInstanceof()); System.out.print("testInstanceof2: ");