From 85bacafcd045e0b12857e61bbc9313ac6231943e Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Tue, 7 Nov 2023 18:10:07 -0500 Subject: [PATCH 01/26] First attempt at hash table (local) --- src/egalhash.c | 30 ++++++++++++++++++++++++ src/egalhash.h | 18 +++++++++++++++ src/ircode.c | 55 ++++++++++++++++++++++++++++++++++++++------ src/julia_internal.h | 1 + src/support/Makefile | 2 +- 5 files changed, 98 insertions(+), 8 deletions(-) create mode 100644 src/egalhash.c create mode 100644 src/egalhash.h diff --git a/src/egalhash.c b/src/egalhash.c new file mode 100644 index 0000000000000..5c49b1413854c --- /dev/null +++ b/src/egalhash.c @@ -0,0 +1,30 @@ +// This file is a part of Julia. License is MIT: https://julialang.org/license + +/* + pointer hash table + optimized for storing info about particular values +*/ + +#include +#include +#include +#include +#include + +#include "dtypes.h" +#include "hashing.h" +#include "egalhash.h" +#include "julia.h" + + +#include "htable.inc" + +#ifdef __cplusplus +extern "C" { +#endif + +HTIMPL(egalhash, jl_object_id, jl_egal) + +#ifdef __cplusplus +} +#endif diff --git a/src/egalhash.h b/src/egalhash.h new file mode 100644 index 0000000000000..a8a397823ceee --- /dev/null +++ b/src/egalhash.h @@ -0,0 +1,18 @@ +// This file is a part of Julia. License is MIT: https://julialang.org/license + +#ifndef JL_EGALHASH_H +#define JL_EGALHASH_H + +#include "htable.h" + +#ifdef __cplusplus +extern "C" { +#endif + +HTPROT(egalhash) + +#ifdef __cplusplus +} +#endif + +#endif diff --git a/src/ircode.c b/src/ircode.c index 6ed1740b3667a..a8f497a62a867 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -71,19 +71,60 @@ static void tagged_root(rle_reference *rr, jl_ircode_state *s, int i) static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) JL_GC_DISABLED { jl_array_t *rs = s->method->roots; + int i, l = jl_array_nrows(rs); + + // assemble a hash table of the roots + htable_t *h = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); + for (i = 0; i < l; i++) { + ptrhash_put(h, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + } + + htable_t *h2 = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); + for (i = 0; i < l; i++) { + egalhash_put(h2, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + } + if (jl_is_symbol(v) || jl_is_concrete_type(v)) { - for (i = 0; i < l; i++) { - if (jl_array_ptr_ref(rs, i) == v) - return tagged_root(rr, s, i); - } + if (ptrhash_has(h, v) != egalhash_has(h2, v)) + jl_safe_printf("%s: ptrhash_has and egalhash_has disagree for symbols/concrete\n", jl_symbol_name(s->method->name)); + if (ptrhash_has(h, v)) + return tagged_root(rr, s, (uintptr_t)ptrhash_get(h, v) - (uintptr_t)HT_NOTFOUND - 1); } else { - for (i = 0; i < l; i++) { - if (jl_egal(jl_array_ptr_ref(rs, i), v)) - return tagged_root(rr, s, i); + int has_match = 0; + i = -1; + for (int ii = 0; ii < l; ii++) { + if(jl_egal(jl_array_ptr_ref(rs, ii), v)) + { + has_match = 1; + i = ii; + } + } + if (has_match != egalhash_has(h2, v)) { + jl_safe_printf("\n"); + jl_safe_printf("found match at %d\n", i); + jl_safe_printf("%s: jl_egal and egalhash_has h2 disagree; %d vs. %d\n", jl_symbol_name(s->method->name), has_match, egalhash_has(h2, v)); + jl_value_t *a = jl_array_ptr_ref(rs, i); + jl_value_t *b = v; + jl_safe_printf("%d\n", jl_egal(a, b)); + jl_safe_printf("==: %d, has a: %d, has b: %d\n", a == b, egalhash_has(h2, a), egalhash_has(h2, b)); + jl_safe_printf("%ld vs. %ld\n", (uintptr_t)a, (uintptr_t)b); + uintptr_t dtag = jl_typetagof(a); + jl_safe_printf("type tags: %lu vs. %lu\n", dtag, jl_typetagof(b)); + if (dtag < jl_max_tags << 4) + if (dtag == jl_symbol_tag << 4 || dtag == jl_bool_tag << 4) { + jl_safe_printf("type tag check: %d vs. %d\n", dtag == jl_symbol_tag << 4, dtag == jl_bool_tag << 4); + } + //if (((jl_datatype_t*)dtag)->name->mutabl) + // jl_safe_printf("is mutable\n"); + jl_safe_printf("object_ids: %ld vs. %ld\n", jl_object_id(a), jl_object_id(b)); } + if (egalhash_has(h2, v)) + return tagged_root(rr, s, (uintptr_t)egalhash_get(h2, v) - (uintptr_t)HT_NOTFOUND - 1); } + htable_free(h2); + htable_free(h); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); return tagged_root(rr, s, jl_array_nrows(rs) - 1); } diff --git a/src/julia_internal.h b/src/julia_internal.h index da025a900400e..1e6f6aa85946b 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -10,6 +10,7 @@ #include "support/utils.h" #include "support/hashing.h" #include "support/ptrhash.h" +#include "egalhash.h" #include "support/strtod.h" #include "gc-alloc-profiler.h" #include "support/rle.h" diff --git a/src/support/Makefile b/src/support/Makefile index 1ee98a4eabdee..1b0dd04a4d6a8 100644 --- a/src/support/Makefile +++ b/src/support/Makefile @@ -8,7 +8,7 @@ JCXXFLAGS += $(CXXFLAGS) JCPPFLAGS += $(CPPFLAGS) JLDFLAGS += $(LDFLAGS) -SRCS := hashing timefuncs ptrhash operators utf8 ios htable bitvector \ +SRCS := hashing timefuncs ptrhash egalhash operators utf8 ios htable bitvector \ int2str libsupportinit arraylist strtod rle ifeq ($(OS),WINNT) SRCS += asprintf strptime From 039ed859271a7493af0b255faa45c6cab351dcee Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Tue, 7 Nov 2023 21:05:09 -0500 Subject: [PATCH 02/26] egalhash seems to work --- src/Makefile | 2 +- src/egalhash.c | 13 +++++++----- src/ircode.c | 47 +++----------------------------------------- src/support/Makefile | 2 +- 4 files changed, 13 insertions(+), 51 deletions(-) diff --git a/src/Makefile b/src/Makefile index 5fc2bc2eaaa41..591559fb2a3f8 100644 --- a/src/Makefile +++ b/src/Makefile @@ -46,7 +46,7 @@ SRCS := \ simplevector runtime_intrinsics precompile jloptions mtarraylist \ threading partr stackwalk gc gc-debug gc-pages gc-stacks gc-alloc-profiler method \ jlapi signal-handling safepoint timing subtype rtutils gc-heap-snapshot \ - crc32c APInt-C processor ircode opaque_closure codegen-stubs coverage runtime_ccall + crc32c APInt-C processor ircode opaque_closure codegen-stubs coverage runtime_ccall egalhash RT_LLVMLINK := CG_LLVMLINK := diff --git a/src/egalhash.c b/src/egalhash.c index 5c49b1413854c..9d68fb45eba14 100644 --- a/src/egalhash.c +++ b/src/egalhash.c @@ -11,19 +11,22 @@ #include #include -#include "dtypes.h" -#include "hashing.h" +#include "support/dtypes.h" +#include "support/hashing.h" #include "egalhash.h" #include "julia.h" - -#include "htable.inc" +#include "support/htable.inc" #ifdef __cplusplus extern "C" { #endif -HTIMPL(egalhash, jl_object_id, jl_egal) +#define OP_EQ(x, y) jl_egal((jl_value_t*)(x), (jl_value_t*)(y)) + +#define OP_HASH(x) jl_object_id((jl_value_t*)(x)) + +HTIMPL(egalhash, OP_HASH, OP_EQ) #ifdef __cplusplus } diff --git a/src/ircode.c b/src/ircode.c index a8f497a62a867..9d706d28b3ab6 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -77,53 +77,12 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) // assemble a hash table of the roots htable_t *h = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); for (i = 0; i < l; i++) { - ptrhash_put(h, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + egalhash_put(h, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); } - htable_t *h2 = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); - for (i = 0; i < l; i++) { - egalhash_put(h2, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); - } + if (egalhash_has(h, v)) + return tagged_root(rr, s, (uintptr_t)egalhash_get(h, v) - (uintptr_t)HT_NOTFOUND - 1); - if (jl_is_symbol(v) || jl_is_concrete_type(v)) { - if (ptrhash_has(h, v) != egalhash_has(h2, v)) - jl_safe_printf("%s: ptrhash_has and egalhash_has disagree for symbols/concrete\n", jl_symbol_name(s->method->name)); - if (ptrhash_has(h, v)) - return tagged_root(rr, s, (uintptr_t)ptrhash_get(h, v) - (uintptr_t)HT_NOTFOUND - 1); - } - else { - int has_match = 0; - i = -1; - for (int ii = 0; ii < l; ii++) { - if(jl_egal(jl_array_ptr_ref(rs, ii), v)) - { - has_match = 1; - i = ii; - } - } - if (has_match != egalhash_has(h2, v)) { - jl_safe_printf("\n"); - jl_safe_printf("found match at %d\n", i); - jl_safe_printf("%s: jl_egal and egalhash_has h2 disagree; %d vs. %d\n", jl_symbol_name(s->method->name), has_match, egalhash_has(h2, v)); - jl_value_t *a = jl_array_ptr_ref(rs, i); - jl_value_t *b = v; - jl_safe_printf("%d\n", jl_egal(a, b)); - jl_safe_printf("==: %d, has a: %d, has b: %d\n", a == b, egalhash_has(h2, a), egalhash_has(h2, b)); - jl_safe_printf("%ld vs. %ld\n", (uintptr_t)a, (uintptr_t)b); - uintptr_t dtag = jl_typetagof(a); - jl_safe_printf("type tags: %lu vs. %lu\n", dtag, jl_typetagof(b)); - if (dtag < jl_max_tags << 4) - if (dtag == jl_symbol_tag << 4 || dtag == jl_bool_tag << 4) { - jl_safe_printf("type tag check: %d vs. %d\n", dtag == jl_symbol_tag << 4, dtag == jl_bool_tag << 4); - } - //if (((jl_datatype_t*)dtag)->name->mutabl) - // jl_safe_printf("is mutable\n"); - jl_safe_printf("object_ids: %ld vs. %ld\n", jl_object_id(a), jl_object_id(b)); - } - if (egalhash_has(h2, v)) - return tagged_root(rr, s, (uintptr_t)egalhash_get(h2, v) - (uintptr_t)HT_NOTFOUND - 1); - } - htable_free(h2); htable_free(h); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); return tagged_root(rr, s, jl_array_nrows(rs) - 1); diff --git a/src/support/Makefile b/src/support/Makefile index 1b0dd04a4d6a8..1ee98a4eabdee 100644 --- a/src/support/Makefile +++ b/src/support/Makefile @@ -8,7 +8,7 @@ JCXXFLAGS += $(CXXFLAGS) JCPPFLAGS += $(CPPFLAGS) JLDFLAGS += $(LDFLAGS) -SRCS := hashing timefuncs ptrhash egalhash operators utf8 ios htable bitvector \ +SRCS := hashing timefuncs ptrhash operators utf8 ios htable bitvector \ int2str libsupportinit arraylist strtod rle ifeq ($(OS),WINNT) SRCS += asprintf strptime From 491f6d1abcd7502c5be10d6796c82efe4a142ceb Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Tue, 7 Nov 2023 21:47:22 -0500 Subject: [PATCH 03/26] Move the table into jl_method_t --- src/ircode.c | 36 ++++++++++++++++++++++++------------ src/julia.h | 3 +++ src/method.c | 19 +++++++++++++++++-- 3 files changed, 44 insertions(+), 14 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 9d706d28b3ab6..cb2f1e8af72b0 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -71,21 +71,28 @@ static void tagged_root(rle_reference *rr, jl_ircode_state *s, int i) static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) JL_GC_DISABLED { jl_array_t *rs = s->method->roots; - - int i, l = jl_array_nrows(rs); - - // assemble a hash table of the roots - htable_t *h = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); - for (i = 0; i < l; i++) { - egalhash_put(h, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + htable_t *rt = s->method->roots_table; + int i; + + // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. + // But should really find the source of the issue. + if (rs != NULL && !rt) { + int l = jl_array_nrows(rs); + s->method->roots_table = rt = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); // does this need freeing? + for (i = 0; i < l; i++) { + egalhash_put(rt, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + } } - if (egalhash_has(h, v)) - return tagged_root(rr, s, (uintptr_t)egalhash_get(h, v) - (uintptr_t)HT_NOTFOUND - 1); + if (rt != NULL && egalhash_has(rt, v)) { + i = (uintptr_t)egalhash_get(rt, v) - (uintptr_t)HT_NOTFOUND - 1; + } + else { + i = jl_array_nrows(rs); + jl_add_method_root(s->method, jl_precompile_toplevel_module, v); + } - htable_free(h); - jl_add_method_root(s->method, jl_precompile_toplevel_module, v); - return tagged_root(rr, s, jl_array_nrows(rs) - 1); + return tagged_root(rr, s, i); } static void jl_encode_int32(jl_ircode_state *s, int32_t x) @@ -813,6 +820,7 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) if (m->roots == NULL) { m->roots = jl_alloc_vec_any(0); + m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? jl_gc_wb(m, m->roots); } jl_ircode_state s = { @@ -888,6 +896,10 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) ios_close(s.s); if (jl_array_nrows(m->roots) == 0) { m->roots = NULL; + if (m->roots_table != NULL) { + htable_free(m->roots_table); + m->roots_table = NULL; + } } JL_GC_PUSH1(&v); jl_gc_enable(en); diff --git a/src/julia.h b/src/julia.h index 9b69dd54dabc8..d7c49addfdf0c 100644 --- a/src/julia.h +++ b/src/julia.h @@ -366,6 +366,9 @@ typedef struct _jl_method_t { // hidden fields: // lock for modifications to the method jl_mutex_t writelock; + + // root -> index into `roots` (offset by HT_NOTFOUND) + htable_t *roots_table; } jl_method_t; // This type is a placeholder to cache data for a specType signature specialization of a Method diff --git a/src/method.c b/src/method.c index 9cb7e83d57c1c..ed1bf6185adb3 100644 --- a/src/method.c +++ b/src/method.c @@ -825,6 +825,7 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module) m->purity.bits = 0; m->max_varargs = UINT8_MAX; JL_MUTEX_INIT(&m->writelock, "method->writelock"); + m->roots_table = NULL; return m; } @@ -1193,8 +1194,17 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) { if (!m->roots) { m->roots = jl_alloc_vec_any(0); + m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? jl_gc_wb(m, m->roots); } + else { + // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. + // But should really find the source of the issue. + m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), i); // does this need freeing? + for (int j = 0; j < i; j++) { + egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(m->roots, i), (void*)(j + (uintptr_t)HT_NOTFOUND + 1)); + } + } if (!m->root_blocks && modid != 0) { m->root_blocks = jl_alloc_array_1d(jl_array_uint64_type, 0); jl_gc_wb(m, m->root_blocks); @@ -1212,9 +1222,11 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ } assert(jl_is_method(m)); prepare_method_for_roots(m, modid); + int i = jl_array_nrows(m->roots); if (current_root_id(m->root_blocks) != modid) - add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots)); + add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); + egalhash_put(m->roots_table, (void*)root, (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); JL_GC_POP(); } @@ -1225,8 +1237,11 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) assert(jl_is_method(m)); assert(jl_is_array(roots)); prepare_method_for_roots(m, modid); - add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots)); + int i = jl_array_nrows(m->roots); + add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); + for(int j = 0; j < jl_array_nrows(roots); j++) + egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(roots, j), (void*)(i + j + (uintptr_t)HT_NOTFOUND + 1)); JL_GC_POP(); } From e94da03555eee049c7c2967b8fe31a3d8067111b Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Wed, 8 Nov 2023 00:03:50 -0500 Subject: [PATCH 04/26] fix --- src/method.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/method.c b/src/method.c index ed1bf6185adb3..abe5d1eff1f0f 100644 --- a/src/method.c +++ b/src/method.c @@ -1197,12 +1197,13 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? jl_gc_wb(m, m->roots); } - else { + else if (!m->roots_table) { // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. // But should really find the source of the issue. - m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), i); // does this need freeing? - for (int j = 0; j < i; j++) { - egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(m->roots, i), (void*)(j + (uintptr_t)HT_NOTFOUND + 1)); + int l = jl_array_nrows(m->roots); + m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); // does this need freeing? + for (int i = 0; i < l; i++) { + egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(m->roots, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); } } if (!m->root_blocks && modid != 0) { From a769017031151d5bc59830fdc47a2fef8732b069 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Wed, 8 Nov 2023 08:48:22 -0500 Subject: [PATCH 05/26] Fix? null logic --- src/ircode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index cb2f1e8af72b0..d6d5fa087add9 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -76,7 +76,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. // But should really find the source of the issue. - if (rs != NULL && !rt) { + if (!rt) { int l = jl_array_nrows(rs); s->method->roots_table = rt = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); // does this need freeing? for (i = 0; i < l; i++) { @@ -84,7 +84,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) } } - if (rt != NULL && egalhash_has(rt, v)) { + if (egalhash_has(rt, v)) { i = (uintptr_t)egalhash_get(rt, v) - (uintptr_t)HT_NOTFOUND - 1; } else { From 65db925ceb232ad2161af0a72eb36c1af3930374 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 00:13:22 -0500 Subject: [PATCH 06/26] Switch to iddict --- src/Makefile | 2 +- src/egalhash.c | 33 --------------------------------- src/egalhash.h | 18 ------------------ src/ircode.c | 30 +++++++++++++----------------- src/julia.h | 4 ++-- src/julia_internal.h | 1 - src/method.c | 15 ++++++--------- 7 files changed, 22 insertions(+), 81 deletions(-) delete mode 100644 src/egalhash.c delete mode 100644 src/egalhash.h diff --git a/src/Makefile b/src/Makefile index 591559fb2a3f8..5fc2bc2eaaa41 100644 --- a/src/Makefile +++ b/src/Makefile @@ -46,7 +46,7 @@ SRCS := \ simplevector runtime_intrinsics precompile jloptions mtarraylist \ threading partr stackwalk gc gc-debug gc-pages gc-stacks gc-alloc-profiler method \ jlapi signal-handling safepoint timing subtype rtutils gc-heap-snapshot \ - crc32c APInt-C processor ircode opaque_closure codegen-stubs coverage runtime_ccall egalhash + crc32c APInt-C processor ircode opaque_closure codegen-stubs coverage runtime_ccall RT_LLVMLINK := CG_LLVMLINK := diff --git a/src/egalhash.c b/src/egalhash.c deleted file mode 100644 index 9d68fb45eba14..0000000000000 --- a/src/egalhash.c +++ /dev/null @@ -1,33 +0,0 @@ -// This file is a part of Julia. License is MIT: https://julialang.org/license - -/* - pointer hash table - optimized for storing info about particular values -*/ - -#include -#include -#include -#include -#include - -#include "support/dtypes.h" -#include "support/hashing.h" -#include "egalhash.h" -#include "julia.h" - -#include "support/htable.inc" - -#ifdef __cplusplus -extern "C" { -#endif - -#define OP_EQ(x, y) jl_egal((jl_value_t*)(x), (jl_value_t*)(y)) - -#define OP_HASH(x) jl_object_id((jl_value_t*)(x)) - -HTIMPL(egalhash, OP_HASH, OP_EQ) - -#ifdef __cplusplus -} -#endif diff --git a/src/egalhash.h b/src/egalhash.h deleted file mode 100644 index a8a397823ceee..0000000000000 --- a/src/egalhash.h +++ /dev/null @@ -1,18 +0,0 @@ -// This file is a part of Julia. License is MIT: https://julialang.org/license - -#ifndef JL_EGALHASH_H -#define JL_EGALHASH_H - -#include "htable.h" - -#ifdef __cplusplus -extern "C" { -#endif - -HTPROT(egalhash) - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/src/ircode.c b/src/ircode.c index d6d5fa087add9..4fc08513b9483 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -71,26 +71,20 @@ static void tagged_root(rle_reference *rr, jl_ircode_state *s, int i) static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) JL_GC_DISABLED { jl_array_t *rs = s->method->roots; - htable_t *rt = s->method->roots_table; + jl_genericmemory_t *rt = s->method->roots_table; int i; + int l = jl_array_nrows(rs); - // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. - // But should really find the source of the issue. if (!rt) { - int l = jl_array_nrows(rs); - s->method->roots_table = rt = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); // does this need freeing? + h = jl_alloc_memory_any(0); for (i = 0; i < l; i++) { - egalhash_put(rt, (void*)jl_array_ptr_ref(rs, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), jl_box_long(i), NULL); } } - if (egalhash_has(rt, v)) { - i = (uintptr_t)egalhash_get(rt, v) - (uintptr_t)HT_NOTFOUND - 1; - } - else { - i = jl_array_nrows(rs); + i = jl_unbox_long(jl_eqtable_get(rt, v, jl_box_long(l))); + if (i == l) jl_add_method_root(s->method, jl_precompile_toplevel_module, v); - } return tagged_root(rr, s, i); } @@ -820,7 +814,8 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) if (m->roots == NULL) { m->roots = jl_alloc_vec_any(0); - m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? + //m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? + m->h = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots); } jl_ircode_state s = { @@ -896,10 +891,11 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) ios_close(s.s); if (jl_array_nrows(m->roots) == 0) { m->roots = NULL; - if (m->roots_table != NULL) { - htable_free(m->roots_table); - m->roots_table = NULL; - } + m->h = NULL; + // if (m->roots_table != NULL) { + // htable_free(m->roots_table); + // m->roots_table = NULL; + // } } JL_GC_PUSH1(&v); jl_gc_enable(en); diff --git a/src/julia.h b/src/julia.h index d7c49addfdf0c..7c226091fbcb8 100644 --- a/src/julia.h +++ b/src/julia.h @@ -367,8 +367,8 @@ typedef struct _jl_method_t { // lock for modifications to the method jl_mutex_t writelock; - // root -> index into `roots` (offset by HT_NOTFOUND) - htable_t *roots_table; + // iddict: root -> index into `roots` + jl_genericmemory_t *roots_table; } jl_method_t; // This type is a placeholder to cache data for a specType signature specialization of a Method diff --git a/src/julia_internal.h b/src/julia_internal.h index 1e6f6aa85946b..da025a900400e 100644 --- a/src/julia_internal.h +++ b/src/julia_internal.h @@ -10,7 +10,6 @@ #include "support/utils.h" #include "support/hashing.h" #include "support/ptrhash.h" -#include "egalhash.h" #include "support/strtod.h" #include "gc-alloc-profiler.h" #include "support/rle.h" diff --git a/src/method.c b/src/method.c index abe5d1eff1f0f..7cce43bab82c8 100644 --- a/src/method.c +++ b/src/method.c @@ -1194,16 +1194,13 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) { if (!m->roots) { m->roots = jl_alloc_vec_any(0); - m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? jl_gc_wb(m, m->roots); } - else if (!m->roots_table) { - // Not sure why, but sometimes roots is not null but roots_table is. If so, regenerate. - // But should really find the source of the issue. + if (!m->roots_table) { int l = jl_array_nrows(m->roots); - m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), l); // does this need freeing? + m->roots_table = jl_alloc_memory_any(0); for (int i = 0; i < l; i++) { - egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(m->roots, i), (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), jl_box_long(i), NULL); } } if (!m->root_blocks && modid != 0) { @@ -1227,7 +1224,7 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ if (current_root_id(m->root_blocks) != modid) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); - egalhash_put(m->roots_table, (void*)root, (void*)(i + (uintptr_t)HT_NOTFOUND + 1)); + m->roots_table = jl_eqtable_put(m->roots_table, root, jl_box_long(i), NULL); JL_GC_POP(); } @@ -1241,8 +1238,8 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) int i = jl_array_nrows(m->roots); add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); - for(int j = 0; j < jl_array_nrows(roots); j++) - egalhash_put(m->roots_table, (void*)jl_array_ptr_ref(roots, j), (void*)(i + j + (uintptr_t)HT_NOTFOUND + 1)); + for (int j = 0; j < jl_array_nrows(roots); j++) + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(roots, j), jl_box_long(i + j), NULL); JL_GC_POP(); } From c94120a0ba2458995f39b68d18271e4f9ac39689 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 00:13:22 -0500 Subject: [PATCH 07/26] Switch to iddict --- src/ircode.c | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 4fc08513b9483..fd9650f9a5485 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -76,7 +76,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) int l = jl_array_nrows(rs); if (!rt) { - h = jl_alloc_memory_any(0); + s->method->roots_table = rt = jl_alloc_memory_any(0); for (i = 0; i < l; i++) { s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), jl_box_long(i), NULL); } @@ -814,8 +814,7 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) if (m->roots == NULL) { m->roots = jl_alloc_vec_any(0); - //m->roots_table = htable_new((htable_t*)malloc_s(sizeof(htable_t)), 1); // does this need freeing? - m->h = jl_alloc_memory_any(0); + m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots); } jl_ircode_state s = { @@ -891,11 +890,7 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) ios_close(s.s); if (jl_array_nrows(m->roots) == 0) { m->roots = NULL; - m->h = NULL; - // if (m->roots_table != NULL) { - // htable_free(m->roots_table); - // m->roots_table = NULL; - // } + m->roots_table = NULL; } JL_GC_PUSH1(&v); jl_gc_enable(en); From ad870f2f99d30baa3ef831c6c05efe160e6e13e4 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 09:20:01 -0500 Subject: [PATCH 08/26] Try adding jl_gc_wb --- src/method.c | 1 + 1 file changed, 1 insertion(+) diff --git a/src/method.c b/src/method.c index 7cce43bab82c8..00b1c15a43dea 100644 --- a/src/method.c +++ b/src/method.c @@ -1199,6 +1199,7 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) if (!m->roots_table) { int l = jl_array_nrows(m->roots); m->roots_table = jl_alloc_memory_any(0); + jl_gc_wb(m, m->roots_table); for (int i = 0; i < l; i++) { m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), jl_box_long(i), NULL); } From 3cac75984520e2fe842cad3e93840ccb6cc99e51 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 09:21:23 -0500 Subject: [PATCH 09/26] Try adding jl_gc_wb --- src/ircode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ircode.c b/src/ircode.c index fd9650f9a5485..ac09d8950de22 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -77,6 +77,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) if (!rt) { s->method->roots_table = rt = jl_alloc_memory_any(0); + jl_gc_wb(m, s->method->roots_table); for (i = 0; i < l; i++) { s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), jl_box_long(i), NULL); } @@ -816,6 +817,7 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) m->roots = jl_alloc_vec_any(0); m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots); + jl_gc_wb(m, m->roots_table); } jl_ircode_state s = { &dest, From 7db6f68fa3e7899664d95e0220ffbedec1388bc2 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 09:31:37 -0500 Subject: [PATCH 10/26] fix --- src/ircode.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ircode.c b/src/ircode.c index ac09d8950de22..c2772b83de457 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -77,7 +77,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) if (!rt) { s->method->roots_table = rt = jl_alloc_memory_any(0); - jl_gc_wb(m, s->method->roots_table); + jl_gc_wb(s->method, s->method->roots_table); for (i = 0; i < l; i++) { s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), jl_box_long(i), NULL); } From 5d86edef8f712a616d45ce3f09bb84a6114292b8 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 10:47:40 -0500 Subject: [PATCH 11/26] attempt to be defensive with GC? --- src/ircode.c | 5 ++++- src/method.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 5 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index c2772b83de457..392464760e78d 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -79,7 +79,10 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) s->method->roots_table = rt = jl_alloc_memory_any(0); jl_gc_wb(s->method, s->method->roots_table); for (i = 0; i < l; i++) { - s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), jl_box_long(i), NULL); + jl_value_t *ibox = jl_box_long(i); + jl_gc_wb(s->method->roots_table, ibox); + s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), ibox, NULL); + jl_gc_wb(s->method, s->method->roots_table); } } diff --git a/src/method.c b/src/method.c index 00b1c15a43dea..a2467d1aa3f7b 100644 --- a/src/method.c +++ b/src/method.c @@ -1201,7 +1201,10 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots_table); for (int i = 0; i < l; i++) { - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), jl_box_long(i), NULL); + jl_value_t *ibox = jl_box_long(i); + jl_gc_wb(m->roots_table, ibox); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), ibox, NULL); + jl_gc_wb(m, m->roots_table); } } if (!m->root_blocks && modid != 0) { @@ -1225,7 +1228,10 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ if (current_root_id(m->root_blocks) != modid) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); - m->roots_table = jl_eqtable_put(m->roots_table, root, jl_box_long(i), NULL); + jl_value_t *ibox = jl_box_long(i); + jl_gc_wb(m->roots_table, ibox); + m->roots_table = jl_eqtable_put(m->roots_table, root, ibox, NULL); + jl_gc_wb(m, m->roots_table); JL_GC_POP(); } @@ -1239,8 +1245,12 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) int i = jl_array_nrows(m->roots); add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); - for (int j = 0; j < jl_array_nrows(roots); j++) - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(roots, j), jl_box_long(i + j), NULL); + for (int j = 0; j < jl_array_nrows(roots); j++) { + jl_value_t *ijbox = jl_box_long(i + j); + jl_gc_wb(m->roots_table, ijbox); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(roots, j), ijbox, NULL); + jl_gc_wb(m, m->roots_table); + } JL_GC_POP(); } From cd0b9b3dad58657ee4e6f67796b8293212415b04 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 12:19:51 -0500 Subject: [PATCH 12/26] Add back todo --- src/ircode.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ircode.c b/src/ircode.c index 392464760e78d..de0b950cd4976 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -75,6 +75,8 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) int i; int l = jl_array_nrows(rs); + // In theory roots_table is initialized wherever roots is, but there seems to be a case + // where it is not; should really find that location, but for now we'll just initialize here. if (!rt) { s->method->roots_table = rt = jl_alloc_memory_any(0); jl_gc_wb(s->method, s->method->roots_table); From b3c0855c90e34a511cc800299de7cab829ecf012 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 14:46:21 -0500 Subject: [PATCH 13/26] roots_table needs to be visible as part of Julia type for GC --- src/jltypes.c | 7 ++++--- src/julia.h | 6 +++--- src/method.c | 2 +- 3 files changed, 8 insertions(+), 7 deletions(-) diff --git a/src/jltypes.c b/src/jltypes.c index dddf88aececac..734babc3bd34a 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -3149,7 +3149,7 @@ void jl_init_types(void) JL_GC_DISABLED jl_method_type = jl_new_datatype(jl_symbol("Method"), core, jl_any_type, jl_emptysvec, - jl_perm_symsvec(30, + jl_perm_symsvec(31, "name", "module", "file", @@ -3179,8 +3179,9 @@ void jl_init_types(void) JL_GC_DISABLED "nospecializeinfer", "constprop", "max_varargs", - "purity"), - jl_svec(30, + "purity", + "roots_table"), + jl_svec(31, jl_symbol_type, jl_module_type, jl_symbol_type, diff --git a/src/julia.h b/src/julia.h index 7c226091fbcb8..c241f09758e8e 100644 --- a/src/julia.h +++ b/src/julia.h @@ -362,13 +362,13 @@ typedef struct _jl_method_t { // Override the conclusions of inter-procedural effect analysis, // forcing the conclusion to always true. _jl_purity_overrides_t purity; + + // iddict: root -> index into `roots` + jl_genericmemory_t *roots_table; // hidden fields: // lock for modifications to the method jl_mutex_t writelock; - - // iddict: root -> index into `roots` - jl_genericmemory_t *roots_table; } jl_method_t; // This type is a placeholder to cache data for a specType signature specialization of a Method diff --git a/src/method.c b/src/method.c index a2467d1aa3f7b..8b7678919b633 100644 --- a/src/method.c +++ b/src/method.c @@ -824,8 +824,8 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module) m->constprop = 0; m->purity.bits = 0; m->max_varargs = UINT8_MAX; - JL_MUTEX_INIT(&m->writelock, "method->writelock"); m->roots_table = NULL; + JL_MUTEX_INIT(&m->writelock, "method->writelock"); return m; } From 66ba7d69c9d5d36458b89f9bf7be9736506cb281 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 16:19:52 -0500 Subject: [PATCH 14/26] Remove the tentative jl_gc_wb calls --- src/ircode.c | 5 ++--- src/method.c | 9 +++------ 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index de0b950cd4976..b0ae9db88f491 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -79,12 +79,11 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) // where it is not; should really find that location, but for now we'll just initialize here. if (!rt) { s->method->roots_table = rt = jl_alloc_memory_any(0); - jl_gc_wb(s->method, s->method->roots_table); + jl_gc_wb(s->method, rt); for (i = 0; i < l; i++) { jl_value_t *ibox = jl_box_long(i); - jl_gc_wb(s->method->roots_table, ibox); s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), ibox, NULL); - jl_gc_wb(s->method, s->method->roots_table); + jl_gc_wb(s->method, rt); } } diff --git a/src/method.c b/src/method.c index 8b7678919b633..e33f6229edf8a 100644 --- a/src/method.c +++ b/src/method.c @@ -1202,7 +1202,6 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) jl_gc_wb(m, m->roots_table); for (int i = 0; i < l; i++) { jl_value_t *ibox = jl_box_long(i); - jl_gc_wb(m->roots_table, ibox); m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), ibox, NULL); jl_gc_wb(m, m->roots_table); } @@ -1229,7 +1228,6 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); jl_value_t *ibox = jl_box_long(i); - jl_gc_wb(m->roots_table, ibox); m->roots_table = jl_eqtable_put(m->roots_table, root, ibox, NULL); jl_gc_wb(m, m->roots_table); JL_GC_POP(); @@ -1245,10 +1243,9 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) int i = jl_array_nrows(m->roots); add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); - for (int j = 0; j < jl_array_nrows(roots); j++) { - jl_value_t *ijbox = jl_box_long(i + j); - jl_gc_wb(m->roots_table, ijbox); - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(roots, j), ijbox, NULL); + for (int j = i; j < jl_array_nrows(m->roots); j++) { + jl_value_t *jbox = jl_box_long(j); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jbox, NULL); jl_gc_wb(m, m->roots_table); } JL_GC_POP(); From df28a1767d252ed00b346830b5b7ac40f7cd4fb6 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 17:25:24 -0500 Subject: [PATCH 15/26] Remove unneeded regeneration loops, simplify --- src/ircode.c | 12 ------------ src/method.c | 13 ++----------- 2 files changed, 2 insertions(+), 23 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index b0ae9db88f491..6871f2b532827 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -75,18 +75,6 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) int i; int l = jl_array_nrows(rs); - // In theory roots_table is initialized wherever roots is, but there seems to be a case - // where it is not; should really find that location, but for now we'll just initialize here. - if (!rt) { - s->method->roots_table = rt = jl_alloc_memory_any(0); - jl_gc_wb(s->method, rt); - for (i = 0; i < l; i++) { - jl_value_t *ibox = jl_box_long(i); - s->method->roots_table = rt = jl_eqtable_put(rt, jl_array_ptr_ref(rs, i), ibox, NULL); - jl_gc_wb(s->method, rt); - } - } - i = jl_unbox_long(jl_eqtable_get(rt, v, jl_box_long(l))); if (i == l) jl_add_method_root(s->method, jl_precompile_toplevel_module, v); diff --git a/src/method.c b/src/method.c index e33f6229edf8a..1950692c60344 100644 --- a/src/method.c +++ b/src/method.c @@ -1194,17 +1194,9 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) { if (!m->roots) { m->roots = jl_alloc_vec_any(0); - jl_gc_wb(m, m->roots); - } - if (!m->roots_table) { - int l = jl_array_nrows(m->roots); m->roots_table = jl_alloc_memory_any(0); + jl_gc_wb(m, m->roots); jl_gc_wb(m, m->roots_table); - for (int i = 0; i < l; i++) { - jl_value_t *ibox = jl_box_long(i); - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, i), ibox, NULL); - jl_gc_wb(m, m->roots_table); - } } if (!m->root_blocks && modid != 0) { m->root_blocks = jl_alloc_array_1d(jl_array_uint64_type, 0); @@ -1227,8 +1219,7 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ if (current_root_id(m->root_blocks) != modid) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); - jl_value_t *ibox = jl_box_long(i); - m->roots_table = jl_eqtable_put(m->roots_table, root, ibox, NULL); + m->roots_table = jl_eqtable_put(m->roots_table, root, jl_box_long(i), NULL); jl_gc_wb(m, m->roots_table); JL_GC_POP(); } From e272a80ce34dfad393a93f5d076d3c2630abb58a Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 17:32:39 -0500 Subject: [PATCH 16/26] whitespace, simplify --- src/julia.h | 2 +- src/method.c | 3 +-- 2 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/julia.h b/src/julia.h index c241f09758e8e..895eb9d68cdf9 100644 --- a/src/julia.h +++ b/src/julia.h @@ -362,7 +362,7 @@ typedef struct _jl_method_t { // Override the conclusions of inter-procedural effect analysis, // forcing the conclusion to always true. _jl_purity_overrides_t purity; - + // iddict: root -> index into `roots` jl_genericmemory_t *roots_table; diff --git a/src/method.c b/src/method.c index 1950692c60344..2d312b02d4445 100644 --- a/src/method.c +++ b/src/method.c @@ -1235,8 +1235,7 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); for (int j = i; j < jl_array_nrows(m->roots); j++) { - jl_value_t *jbox = jl_box_long(j); - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jbox, NULL); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jl_box_long(j), NULL); jl_gc_wb(m, m->roots_table); } JL_GC_POP(); From 97e10da0446ac8f4d749ef92bf335634866c9531 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 19:35:37 -0500 Subject: [PATCH 17/26] Reorder jl_gc_wb --- src/ircode.c | 2 +- src/method.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 6871f2b532827..c9957984d4f91 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -807,8 +807,8 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) if (m->roots == NULL) { m->roots = jl_alloc_vec_any(0); - m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots); + m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots_table); } jl_ircode_state s = { diff --git a/src/method.c b/src/method.c index 2d312b02d4445..17ee483ef8cef 100644 --- a/src/method.c +++ b/src/method.c @@ -1194,8 +1194,8 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) { if (!m->roots) { m->roots = jl_alloc_vec_any(0); - m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots); + m->roots_table = jl_alloc_memory_any(0); jl_gc_wb(m, m->roots_table); } if (!m->root_blocks && modid != 0) { From a452ca61f0357c619d28d81ccfd0f94935c87a45 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 19:44:40 -0500 Subject: [PATCH 18/26] Change another loop to a hash lookup --- src/codegen.cpp | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index bc7f30f49626d..c8427c4419c9b 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3053,13 +3053,11 @@ static jl_value_t *jl_ensure_rooted(jl_codectx_t &ctx, jl_value_t *val) // the method might have a root for this already; use it if so JL_LOCK(&m->writelock); if (m->roots) { - size_t i, len = jl_array_dim0(m->roots); - for (i = 0; i < len; i++) { - jl_value_t *mval = jl_array_ptr_ref(m->roots, i); - if (mval == val || jl_egal(mval, val)) { - JL_UNLOCK(&m->writelock); - return mval; - } + size_t len = jl_array_dim0(m->roots); + size_t i = jl_unbox_long(jl_eqtable_get(m->roots_table, val, jl_box_long(-1))); + if (i > -1) { + JL_UNLOCK(&m->writelock); + return jl_array_ptr_ref(m->roots, i); } } JL_UNLOCK(&m->writelock); From b1f7da11f25471906d44c01ebf8dd1523c260445 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 21:07:47 -0500 Subject: [PATCH 19/26] Avoid boxing an int just to provide a default --- src/codegen.cpp | 7 +++---- src/ircode.c | 10 +++++++--- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index c8427c4419c9b..88779968c36b2 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3053,11 +3053,10 @@ static jl_value_t *jl_ensure_rooted(jl_codectx_t &ctx, jl_value_t *val) // the method might have a root for this already; use it if so JL_LOCK(&m->writelock); if (m->roots) { - size_t len = jl_array_dim0(m->roots); - size_t i = jl_unbox_long(jl_eqtable_get(m->roots_table, val, jl_box_long(-1))); - if (i > -1) { + jl_value_t *ival = jl_eqtable_get(m->roots_table, val, NULL); + if (ival) { JL_UNLOCK(&m->writelock); - return jl_array_ptr_ref(m->roots, i); + return jl_array_ptr_ref(m->roots, jl_unbox_long(ival)); } } JL_UNLOCK(&m->writelock); diff --git a/src/ircode.c b/src/ircode.c index c9957984d4f91..1482410e2a716 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -73,11 +73,15 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) jl_array_t *rs = s->method->roots; jl_genericmemory_t *rt = s->method->roots_table; int i; - int l = jl_array_nrows(rs); - i = jl_unbox_long(jl_eqtable_get(rt, v, jl_box_long(l))); - if (i == l) + jl_value_t *ival = jl_eqtable_get(rt, v, NULL); + if (!ival) { + i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); + } + else { + i = jl_unbox_long(ival); + } return tagged_root(rr, s, i); } From f9769208d29ac66b270d45e47fa7a0b7bdc76144 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Thu, 9 Nov 2023 21:28:00 -0500 Subject: [PATCH 20/26] Try rooting the boxed entries --- src/method.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/method.c b/src/method.c index 17ee483ef8cef..3b3c278554518 100644 --- a/src/method.c +++ b/src/method.c @@ -1219,7 +1219,9 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ if (current_root_id(m->root_blocks) != modid) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); - m->roots_table = jl_eqtable_put(m->roots_table, root, jl_box_long(i), NULL); + jl_value_t *ibox = jl_box_long(i); + jl_gc_wb(m->roots_table, ibox); + m->roots_table = jl_eqtable_put(m->roots_table, root, ibox, NULL); jl_gc_wb(m, m->roots_table); JL_GC_POP(); } @@ -1235,7 +1237,9 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); for (int j = i; j < jl_array_nrows(m->roots); j++) { - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jl_box_long(j), NULL); + jl_value_t *jbox = jl_box_long(j); + jl_gc_wb(m->roots_table, jbox); + m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jbox, NULL); jl_gc_wb(m, m->roots_table); } JL_GC_POP(); From 7861156523c30c52880503b429c4400c76cd1951 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sat, 11 Nov 2023 00:06:52 -0500 Subject: [PATCH 21/26] Move hashtable from jl_method_t and into jl_ircode_state --- src/codegen.cpp | 11 +++++++---- src/ircode.c | 19 +++++++++++++------ src/jltypes.c | 7 +++---- src/julia.h | 3 --- src/method.c | 13 ------------- 5 files changed, 23 insertions(+), 30 deletions(-) diff --git a/src/codegen.cpp b/src/codegen.cpp index 88779968c36b2..bc7f30f49626d 100644 --- a/src/codegen.cpp +++ b/src/codegen.cpp @@ -3053,10 +3053,13 @@ static jl_value_t *jl_ensure_rooted(jl_codectx_t &ctx, jl_value_t *val) // the method might have a root for this already; use it if so JL_LOCK(&m->writelock); if (m->roots) { - jl_value_t *ival = jl_eqtable_get(m->roots_table, val, NULL); - if (ival) { - JL_UNLOCK(&m->writelock); - return jl_array_ptr_ref(m->roots, jl_unbox_long(ival)); + size_t i, len = jl_array_dim0(m->roots); + for (i = 0; i < len; i++) { + jl_value_t *mval = jl_array_ptr_ref(m->roots, i); + if (mval == val || jl_egal(mval, val)) { + JL_UNLOCK(&m->writelock); + return mval; + } } } JL_UNLOCK(&m->writelock); diff --git a/src/ircode.c b/src/ircode.c index 1482410e2a716..1e4b69421486e 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -27,6 +27,7 @@ typedef struct { jl_method_t *method; jl_ptls_t ptls; uint8_t relocatability; + jl_genericmemory_t *roots_ids; } jl_ircode_state; // type => tag hash for a few core types (e.g., Expr, PhiNode, etc) @@ -71,13 +72,15 @@ static void tagged_root(rle_reference *rr, jl_ircode_state *s, int i) static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) JL_GC_DISABLED { jl_array_t *rs = s->method->roots; - jl_genericmemory_t *rt = s->method->roots_table; + jl_genericmemory_t *rt = s->roots_ids; int i; jl_value_t *ival = jl_eqtable_get(rt, v, NULL); if (!ival) { i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); + jl_value_t *ibox = jl_box_long(i); + s->roots_ids = jl_eqtable_put(s->roots_ids, v, ibox, NULL); } else { i = jl_unbox_long(ival); @@ -812,15 +815,19 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) if (m->roots == NULL) { m->roots = jl_alloc_vec_any(0); jl_gc_wb(m, m->roots); - m->roots_table = jl_alloc_memory_any(0); - jl_gc_wb(m, m->roots_table); } jl_ircode_state s = { &dest, m, jl_current_task->ptls, - 1 + 1, + jl_alloc_memory_any(0) }; + // generate hash table to lookup root indexes + for (int i = 0; i < jl_array_nrows(m->roots); i++) { + jl_value_t *ibox = jl_box_long(i); + s.roots_ids = jl_eqtable_put(s.roots_ids, jl_array_ptr_ref(m->roots, i), ibox, NULL); + } jl_code_info_flags_t flags = code_info_flags(code->inferred, code->propagate_inbounds, code->has_fcall, code->nospecializeinfer, code->inlining, code->constprop); @@ -888,7 +895,6 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) ios_close(s.s); if (jl_array_nrows(m->roots) == 0) { m->roots = NULL; - m->roots_table = NULL; } JL_GC_PUSH1(&v); jl_gc_enable(en); @@ -916,7 +922,8 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t &src, m, jl_current_task->ptls, - 1 + 1, + NULL }; jl_code_info_t *code = jl_new_code_info_uninit(); diff --git a/src/jltypes.c b/src/jltypes.c index 734babc3bd34a..dddf88aececac 100644 --- a/src/jltypes.c +++ b/src/jltypes.c @@ -3149,7 +3149,7 @@ void jl_init_types(void) JL_GC_DISABLED jl_method_type = jl_new_datatype(jl_symbol("Method"), core, jl_any_type, jl_emptysvec, - jl_perm_symsvec(31, + jl_perm_symsvec(30, "name", "module", "file", @@ -3179,9 +3179,8 @@ void jl_init_types(void) JL_GC_DISABLED "nospecializeinfer", "constprop", "max_varargs", - "purity", - "roots_table"), - jl_svec(31, + "purity"), + jl_svec(30, jl_symbol_type, jl_module_type, jl_symbol_type, diff --git a/src/julia.h b/src/julia.h index 895eb9d68cdf9..9b69dd54dabc8 100644 --- a/src/julia.h +++ b/src/julia.h @@ -363,9 +363,6 @@ typedef struct _jl_method_t { // forcing the conclusion to always true. _jl_purity_overrides_t purity; - // iddict: root -> index into `roots` - jl_genericmemory_t *roots_table; - // hidden fields: // lock for modifications to the method jl_mutex_t writelock; diff --git a/src/method.c b/src/method.c index 3b3c278554518..4b00fe80f47a6 100644 --- a/src/method.c +++ b/src/method.c @@ -824,7 +824,6 @@ JL_DLLEXPORT jl_method_t *jl_new_method_uninit(jl_module_t *module) m->constprop = 0; m->purity.bits = 0; m->max_varargs = UINT8_MAX; - m->roots_table = NULL; JL_MUTEX_INIT(&m->writelock, "method->writelock"); return m; } @@ -1195,8 +1194,6 @@ static void prepare_method_for_roots(jl_method_t *m, uint64_t modid) if (!m->roots) { m->roots = jl_alloc_vec_any(0); jl_gc_wb(m, m->roots); - m->roots_table = jl_alloc_memory_any(0); - jl_gc_wb(m, m->roots_table); } if (!m->root_blocks && modid != 0) { m->root_blocks = jl_alloc_array_1d(jl_array_uint64_type, 0); @@ -1219,10 +1216,6 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ if (current_root_id(m->root_blocks) != modid) add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_push(m->roots, root); - jl_value_t *ibox = jl_box_long(i); - jl_gc_wb(m->roots_table, ibox); - m->roots_table = jl_eqtable_put(m->roots_table, root, ibox, NULL); - jl_gc_wb(m, m->roots_table); JL_GC_POP(); } @@ -1236,12 +1229,6 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) int i = jl_array_nrows(m->roots); add_root_block(m->root_blocks, modid, i); jl_array_ptr_1d_append(m->roots, roots); - for (int j = i; j < jl_array_nrows(m->roots); j++) { - jl_value_t *jbox = jl_box_long(j); - jl_gc_wb(m->roots_table, jbox); - m->roots_table = jl_eqtable_put(m->roots_table, jl_array_ptr_ref(m->roots, j), jbox, NULL); - jl_gc_wb(m, m->roots_table); - } JL_GC_POP(); } From d59678db4078326e37958a99a9d00880d277850d Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sat, 11 Nov 2023 02:01:04 -0500 Subject: [PATCH 22/26] Refinement and comment --- src/ircode.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 1e4b69421486e..52ede5978cf67 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -27,7 +27,7 @@ typedef struct { jl_method_t *method; jl_ptls_t ptls; uint8_t relocatability; - jl_genericmemory_t *roots_ids; + jl_genericmemory_t *roots_ids; // iddict for method root ids; only needed during compression } jl_ircode_state; // type => tag hash for a few core types (e.g., Expr, PhiNode, etc) @@ -80,7 +80,7 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); jl_value_t *ibox = jl_box_long(i); - s->roots_ids = jl_eqtable_put(s->roots_ids, v, ibox, NULL); + s->roots_ids = rt = jl_eqtable_put(rt, v, ibox, NULL); } else { i = jl_unbox_long(ival); From 6dba6ac6c53c2023100e6270dc80801278d47eb3 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sat, 11 Nov 2023 02:14:50 -0500 Subject: [PATCH 23/26] Revert unneeded changes --- src/method.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/method.c b/src/method.c index 4b00fe80f47a6..9cb7e83d57c1c 100644 --- a/src/method.c +++ b/src/method.c @@ -1212,9 +1212,8 @@ JL_DLLEXPORT void jl_add_method_root(jl_method_t *m, jl_module_t *mod, jl_value_ } assert(jl_is_method(m)); prepare_method_for_roots(m, modid); - int i = jl_array_nrows(m->roots); if (current_root_id(m->root_blocks) != modid) - add_root_block(m->root_blocks, modid, i); + add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots)); jl_array_ptr_1d_push(m->roots, root); JL_GC_POP(); } @@ -1226,8 +1225,7 @@ void jl_append_method_roots(jl_method_t *m, uint64_t modid, jl_array_t* roots) assert(jl_is_method(m)); assert(jl_is_array(roots)); prepare_method_for_roots(m, modid); - int i = jl_array_nrows(m->roots); - add_root_block(m->root_blocks, modid, i); + add_root_block(m->root_blocks, modid, jl_array_nrows(m->roots)); jl_array_ptr_1d_append(m->roots, roots); JL_GC_POP(); } From 5acd6dccd1a77e25a410ebfe9f00e809946f31df Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Sat, 11 Nov 2023 09:00:29 -0500 Subject: [PATCH 24/26] Simplify --- src/ircode.c | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 52ede5978cf67..0c630cf737003 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -79,12 +79,10 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) if (!ival) { i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); - jl_value_t *ibox = jl_box_long(i); - s->roots_ids = rt = jl_eqtable_put(rt, v, ibox, NULL); + s->roots_ids = rt = jl_eqtable_put(rt, v, jl_box_long(i), NULL); } - else { + else i = jl_unbox_long(ival); - } return tagged_root(rr, s, i); } @@ -824,10 +822,8 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) jl_alloc_memory_any(0) }; // generate hash table to lookup root indexes - for (int i = 0; i < jl_array_nrows(m->roots); i++) { - jl_value_t *ibox = jl_box_long(i); - s.roots_ids = jl_eqtable_put(s.roots_ids, jl_array_ptr_ref(m->roots, i), ibox, NULL); - } + for (int i = 0; i < jl_array_nrows(m->roots); i++) + s.roots_ids = jl_eqtable_put(s.roots_ids, jl_array_ptr_ref(m->roots, i), jl_box_long(i), NULL); jl_code_info_flags_t flags = code_info_flags(code->inferred, code->propagate_inbounds, code->has_fcall, code->nospecializeinfer, code->inlining, code->constprop); From 18c0888fb9af8f0b781109338e1ae5345e68b41f Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Mon, 27 Nov 2023 12:45:35 -0500 Subject: [PATCH 25/26] Switch to idset implementation --- src/ircode.c | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 0c630cf737003..1458f3c99df79 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -28,6 +28,7 @@ typedef struct { jl_ptls_t ptls; uint8_t relocatability; jl_genericmemory_t *roots_ids; // iddict for method root ids; only needed during compression + jl_genericmemory_t *roots_keys; // idset for method root ids; only needed during compression } jl_ircode_state; // type => tag hash for a few core types (e.g., Expr, PhiNode, etc) @@ -73,16 +74,18 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) { jl_array_t *rs = s->method->roots; jl_genericmemory_t *rt = s->roots_ids; - int i; + jl_genericmemory_t *rs1 = s->roots_keys; - jl_value_t *ival = jl_eqtable_get(rt, v, NULL); - if (!ival) { + ssize_t i = jl_idset_peek_bp(rs1, rt, v); + + if (i == -1) { i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); - s->roots_ids = rt = jl_eqtable_put(rt, v, jl_box_long(i), NULL); + + ssize_t k = i; + s->roots_keys = rs1 = jl_idset_put_key(rs1, v, &k); + s->roots_ids = rt = jl_idset_put_idx(rs1, rt, k); } - else - i = jl_unbox_long(ival); return tagged_root(rr, s, i); } @@ -819,11 +822,15 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) m, jl_current_task->ptls, 1, + jl_alloc_memory_any(0), jl_alloc_memory_any(0) }; // generate hash table to lookup root indexes - for (int i = 0; i < jl_array_nrows(m->roots); i++) - s.roots_ids = jl_eqtable_put(s.roots_ids, jl_array_ptr_ref(m->roots, i), jl_box_long(i), NULL); + for (int i = 0; i < jl_array_nrows(m->roots); i++) { + ssize_t k; + s.roots_keys = jl_idset_put_key(s.roots_keys, jl_array_ptr_ref(m->roots, i), &k); + s.roots_ids = jl_idset_put_idx(s.roots_keys, s.roots_ids, k); + } jl_code_info_flags_t flags = code_info_flags(code->inferred, code->propagate_inbounds, code->has_fcall, code->nospecializeinfer, code->inlining, code->constprop); @@ -919,6 +926,7 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t m, jl_current_task->ptls, 1, + NULL, NULL }; From 2134d46ee0f09956bf5e47a3dbe4b8fd2d44c681 Mon Sep 17 00:00:00 2001 From: Nicholas Bauer Date: Mon, 27 Nov 2023 13:14:21 -0500 Subject: [PATCH 26/26] Simplify --- src/ircode.c | 17 ++++------------- 1 file changed, 4 insertions(+), 13 deletions(-) diff --git a/src/ircode.c b/src/ircode.c index 1458f3c99df79..cabb587a50f22 100644 --- a/src/ircode.c +++ b/src/ircode.c @@ -27,8 +27,7 @@ typedef struct { jl_method_t *method; jl_ptls_t ptls; uint8_t relocatability; - jl_genericmemory_t *roots_ids; // iddict for method root ids; only needed during compression - jl_genericmemory_t *roots_keys; // idset for method root ids; only needed during compression + jl_genericmemory_t *roots_ids; // idset for method root ids; only needed during compression } jl_ircode_state; // type => tag hash for a few core types (e.g., Expr, PhiNode, etc) @@ -74,17 +73,13 @@ static void literal_val_id(rle_reference *rr, jl_ircode_state *s, jl_value_t *v) { jl_array_t *rs = s->method->roots; jl_genericmemory_t *rt = s->roots_ids; - jl_genericmemory_t *rs1 = s->roots_keys; - ssize_t i = jl_idset_peek_bp(rs1, rt, v); + ssize_t i = jl_idset_peek_bp(rs->ref.mem, rt, v); if (i == -1) { i = jl_array_nrows(rs); jl_add_method_root(s->method, jl_precompile_toplevel_module, v); - - ssize_t k = i; - s->roots_keys = rs1 = jl_idset_put_key(rs1, v, &k); - s->roots_ids = rt = jl_idset_put_idx(rs1, rt, k); + s->roots_ids = rt = jl_idset_put_idx(rs->ref.mem, rt, i); } return tagged_root(rr, s, i); @@ -822,14 +817,11 @@ JL_DLLEXPORT jl_string_t *jl_compress_ir(jl_method_t *m, jl_code_info_t *code) m, jl_current_task->ptls, 1, - jl_alloc_memory_any(0), jl_alloc_memory_any(0) }; // generate hash table to lookup root indexes for (int i = 0; i < jl_array_nrows(m->roots); i++) { - ssize_t k; - s.roots_keys = jl_idset_put_key(s.roots_keys, jl_array_ptr_ref(m->roots, i), &k); - s.roots_ids = jl_idset_put_idx(s.roots_keys, s.roots_ids, k); + s.roots_ids = jl_idset_put_idx(m->roots->ref.mem, s.roots_ids, i); } jl_code_info_flags_t flags = code_info_flags(code->inferred, code->propagate_inbounds, code->has_fcall, @@ -926,7 +918,6 @@ JL_DLLEXPORT jl_code_info_t *jl_uncompress_ir(jl_method_t *m, jl_code_instance_t m, jl_current_task->ptls, 1, - NULL, NULL };