Skip to content

Commit

Permalink
fix ptrhash_remove (JuliaLang#42009)
Browse files Browse the repository at this point in the history
Same bug as 5e57c21 (JuliaLang#26833), same fix.
  • Loading branch information
vtjnash authored and LilithHafner committed Mar 8, 2022
1 parent 57b25d8 commit 5ccf6e6
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 56 deletions.
4 changes: 2 additions & 2 deletions src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -278,10 +278,10 @@ $(addprefix $(BUILDDIR)/,threading.o threading.dbg.obj gc.o gc.dbg.obj init.c in
$(addprefix $(BUILDDIR)/,APInt-C.o APInt-C.dbg.obj runtime_intrinsics.o runtime_intrinsics.dbg.obj): $(SRCDIR)/APInt-C.h

# archive library file rules
$(BUILDDIR)/support/libsupport.a: $(addprefix $(SRCDIR)/support/,*.h *.c *.S) $(SRCDIR)/support/*.c
$(BUILDDIR)/support/libsupport.a: $(addprefix $(SRCDIR)/support/,*.h *.c *.S *.inc) $(SRCDIR)/support/*.c
$(MAKE) -C $(SRCDIR)/support BUILDDIR='$(abspath $(BUILDDIR)/support)'

$(BUILDDIR)/support/libsupport-debug.a: $(addprefix $(SRCDIR)/support/,*.h *.c *.S) $(SRCDIR)/support/*.c
$(BUILDDIR)/support/libsupport-debug.a: $(addprefix $(SRCDIR)/support/,*.h *.c *.S *.inc) $(SRCDIR)/support/*.c
$(MAKE) -C $(SRCDIR)/support debug BUILDDIR='$(abspath $(BUILDDIR)/support)'

$(FLISP_EXECUTABLE_release): $(BUILDDIR)/flisp/libflisp.a
Expand Down
5 changes: 2 additions & 3 deletions src/dump.c
Original file line number Diff line number Diff line change
Expand Up @@ -2058,14 +2058,14 @@ static void jl_insert_backedges(jl_array_t *list, jl_array_t *targets)
while (codeinst) {
if (codeinst->min_world > 0)
codeinst->max_world = ~(size_t)0;
ptrhash_put(&new_code_instance_validate, codeinst, HT_NOTFOUND); // mark it as handled
ptrhash_remove(&new_code_instance_validate, codeinst); // mark it as handled
codeinst = jl_atomic_load_relaxed(&codeinst->next);
}
}
else {
jl_code_instance_t *codeinst = caller->cache;
while (codeinst) {
ptrhash_put(&new_code_instance_validate, codeinst, HT_NOTFOUND); // should be left invalid
ptrhash_remove(&new_code_instance_validate, codeinst); // should be left invalid
codeinst = jl_atomic_load_relaxed(&codeinst->next);
}
if (_jl_debug_method_invalidation) {
Expand All @@ -2084,7 +2084,6 @@ static void validate_new_code_instances(void)
for (i = 0; i < new_code_instance_validate.size; i += 2) {
if (new_code_instance_validate.table[i+1] != HT_NOTFOUND) {
((jl_code_instance_t*)new_code_instance_validate.table[i])->max_world = ~(size_t)0;
new_code_instance_validate.table[i+1] = HT_NOTFOUND;
}
}
}
Expand Down
112 changes: 61 additions & 51 deletions src/support/htable.inc
Original file line number Diff line number Diff line change
Expand Up @@ -13,67 +13,77 @@
static void **HTNAME##_lookup_bp_r(htable_t *h, void *key, void *ctx) \
{ \
uint_t hv; \
size_t i, orig, index, iter; \
size_t i, orig, index, iter, empty_slot; \
size_t newsz, sz = hash_size(h); \
size_t maxprobe = max_probe(sz); \
void **tab = h->table; \
void **ol; \
\
hv = HFUNC((uintptr_t)key, ctx); \
retry_bp: \
iter = 0; \
index = (size_t)(hv & (sz-1)) * 2; \
sz *= 2; \
orig = index; \
\
do { \
if (tab[index+1] == HT_NOTFOUND) { \
tab[index] = key; \
return &tab[index+1]; \
while (1) { \
iter = 0; \
index = (size_t)(hv & (sz-1)) * 2; \
sz *= 2; \
orig = index; \
empty_slot = -1; \
\
do { \
if (tab[index] == HT_NOTFOUND) { \
if (empty_slot == -1) \
empty_slot = index; \
break; \
} \
if (tab[index+1] == HT_NOTFOUND) { \
if (empty_slot == -1) \
empty_slot = index; \
} \
\
if (EQFUNC(key, tab[index], ctx)) \
return &tab[index+1]; \
\
index = (index+2) & (sz-1); \
iter++; \
if (iter > maxprobe) \
break; \
} while (index != orig); \
\
if (empty_slot != -1) { \
tab[empty_slot] = key; \
return &tab[empty_slot+1]; \
} \
\
if (EQFUNC(key, tab[index], ctx)) \
return &tab[index+1]; \
\
index = (index+2) & (sz-1); \
iter++; \
if (iter > maxprobe) \
break; \
} while (index != orig); \
\
/* table full */ \
/* quadruple size, rehash, retry the insert */ \
/* it's important to grow the table really fast; otherwise we waste */ \
/* lots of time rehashing all the keys over and over. */ \
sz = h->size; \
ol = h->table; \
if (sz < HT_N_INLINE) \
newsz = HT_N_INLINE; \
else if (sz >= (1<<19) || (sz <= (1<<8))) \
newsz = sz<<1; \
else \
newsz = sz<<2; \
/*printf("trying to allocate %d words.\n", newsz); fflush(stdout);*/ \
tab = (void**)LLT_ALLOC(newsz*sizeof(void*)); \
if (tab == NULL) \
return NULL; \
for(i=0; i < newsz; i++) \
tab[i] = HT_NOTFOUND; \
h->table = tab; \
h->size = newsz; \
for(i=0; i < sz; i+=2) { \
if (ol[i+1] != HT_NOTFOUND) { \
(*HTNAME##_lookup_bp_r(h, ol[i], ctx)) = ol[i+1]; \
/* table full */ \
/* quadruple size, rehash, retry the insert */ \
/* it's important to grow the table really fast; otherwise we waste */ \
/* lots of time rehashing all the keys over and over. */ \
sz = h->size; \
ol = h->table; \
if (sz < HT_N_INLINE) \
newsz = HT_N_INLINE; \
else if (sz >= (1<<19) || (sz <= (1<<8))) \
newsz = sz<<1; \
else \
newsz = sz<<2; \
/*printf("trying to allocate %d words.\n", newsz); fflush(stdout);*/ \
tab = (void**)LLT_ALLOC(newsz*sizeof(void*)); \
if (tab == NULL) \
return NULL; \
for (i = 0; i < newsz; i++) \
tab[i] = HT_NOTFOUND; \
h->table = tab; \
h->size = newsz; \
for (i = 0; i < sz; i += 2) { \
if (ol[i+1] != HT_NOTFOUND) { \
(*HTNAME##_lookup_bp_r(h, ol[i], ctx)) = ol[i+1]; \
} \
} \
} \
if (ol != &h->_space[0]) \
LLT_FREE(ol); \
if (ol != &h->_space[0]) \
LLT_FREE(ol); \
\
sz = hash_size(h); \
maxprobe = max_probe(sz); \
tab = h->table; \
\
goto retry_bp; \
sz = hash_size(h); \
maxprobe = max_probe(sz); \
tab = h->table; \
} \
\
return NULL; \
} \
Expand Down

0 comments on commit 5ccf6e6

Please sign in to comment.