Skip to content

Commit 82c4a27

Browse files
authored
fix ptrhash_remove (#42009)
Same bug as 5e57c21 (#26833), same fix.
1 parent 24876b7 commit 82c4a27

File tree

3 files changed

+65
-56
lines changed

3 files changed

+65
-56
lines changed

src/Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -278,10 +278,10 @@ $(addprefix $(BUILDDIR)/,threading.o threading.dbg.obj gc.o gc.dbg.obj init.c in
278278
$(addprefix $(BUILDDIR)/,APInt-C.o APInt-C.dbg.obj runtime_intrinsics.o runtime_intrinsics.dbg.obj): $(SRCDIR)/APInt-C.h
279279

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

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

287287
$(FLISP_EXECUTABLE_release): $(BUILDDIR)/flisp/libflisp.a

src/dump.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2058,14 +2058,14 @@ static void jl_insert_backedges(jl_array_t *list, jl_array_t *targets)
20582058
while (codeinst) {
20592059
if (codeinst->min_world > 0)
20602060
codeinst->max_world = ~(size_t)0;
2061-
ptrhash_put(&new_code_instance_validate, codeinst, HT_NOTFOUND); // mark it as handled
2061+
ptrhash_remove(&new_code_instance_validate, codeinst); // mark it as handled
20622062
codeinst = jl_atomic_load_relaxed(&codeinst->next);
20632063
}
20642064
}
20652065
else {
20662066
jl_code_instance_t *codeinst = caller->cache;
20672067
while (codeinst) {
2068-
ptrhash_put(&new_code_instance_validate, codeinst, HT_NOTFOUND); // should be left invalid
2068+
ptrhash_remove(&new_code_instance_validate, codeinst); // should be left invalid
20692069
codeinst = jl_atomic_load_relaxed(&codeinst->next);
20702070
}
20712071
if (_jl_debug_method_invalidation) {
@@ -2084,7 +2084,6 @@ static void validate_new_code_instances(void)
20842084
for (i = 0; i < new_code_instance_validate.size; i += 2) {
20852085
if (new_code_instance_validate.table[i+1] != HT_NOTFOUND) {
20862086
((jl_code_instance_t*)new_code_instance_validate.table[i])->max_world = ~(size_t)0;
2087-
new_code_instance_validate.table[i+1] = HT_NOTFOUND;
20882087
}
20892088
}
20902089
}

src/support/htable.inc

Lines changed: 61 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -13,67 +13,77 @@
1313
static void **HTNAME##_lookup_bp_r(htable_t *h, void *key, void *ctx) \
1414
{ \
1515
uint_t hv; \
16-
size_t i, orig, index, iter; \
16+
size_t i, orig, index, iter, empty_slot; \
1717
size_t newsz, sz = hash_size(h); \
1818
size_t maxprobe = max_probe(sz); \
1919
void **tab = h->table; \
2020
void **ol; \
2121
\
2222
hv = HFUNC((uintptr_t)key, ctx); \
23-
retry_bp: \
24-
iter = 0; \
25-
index = (size_t)(hv & (sz-1)) * 2; \
26-
sz *= 2; \
27-
orig = index; \
28-
\
29-
do { \
30-
if (tab[index+1] == HT_NOTFOUND) { \
31-
tab[index] = key; \
32-
return &tab[index+1]; \
23+
while (1) { \
24+
iter = 0; \
25+
index = (size_t)(hv & (sz-1)) * 2; \
26+
sz *= 2; \
27+
orig = index; \
28+
empty_slot = -1; \
29+
\
30+
do { \
31+
if (tab[index] == HT_NOTFOUND) { \
32+
if (empty_slot == -1) \
33+
empty_slot = index; \
34+
break; \
35+
} \
36+
if (tab[index+1] == HT_NOTFOUND) { \
37+
if (empty_slot == -1) \
38+
empty_slot = index; \
39+
} \
40+
\
41+
if (EQFUNC(key, tab[index], ctx)) \
42+
return &tab[index+1]; \
43+
\
44+
index = (index+2) & (sz-1); \
45+
iter++; \
46+
if (iter > maxprobe) \
47+
break; \
48+
} while (index != orig); \
49+
\
50+
if (empty_slot != -1) { \
51+
tab[empty_slot] = key; \
52+
return &tab[empty_slot+1]; \
3353
} \
3454
\
35-
if (EQFUNC(key, tab[index], ctx)) \
36-
return &tab[index+1]; \
37-
\
38-
index = (index+2) & (sz-1); \
39-
iter++; \
40-
if (iter > maxprobe) \
41-
break; \
42-
} while (index != orig); \
43-
\
44-
/* table full */ \
45-
/* quadruple size, rehash, retry the insert */ \
46-
/* it's important to grow the table really fast; otherwise we waste */ \
47-
/* lots of time rehashing all the keys over and over. */ \
48-
sz = h->size; \
49-
ol = h->table; \
50-
if (sz < HT_N_INLINE) \
51-
newsz = HT_N_INLINE; \
52-
else if (sz >= (1<<19) || (sz <= (1<<8))) \
53-
newsz = sz<<1; \
54-
else \
55-
newsz = sz<<2; \
56-
/*printf("trying to allocate %d words.\n", newsz); fflush(stdout);*/ \
57-
tab = (void**)LLT_ALLOC(newsz*sizeof(void*)); \
58-
if (tab == NULL) \
59-
return NULL; \
60-
for(i=0; i < newsz; i++) \
61-
tab[i] = HT_NOTFOUND; \
62-
h->table = tab; \
63-
h->size = newsz; \
64-
for(i=0; i < sz; i+=2) { \
65-
if (ol[i+1] != HT_NOTFOUND) { \
66-
(*HTNAME##_lookup_bp_r(h, ol[i], ctx)) = ol[i+1]; \
55+
/* table full */ \
56+
/* quadruple size, rehash, retry the insert */ \
57+
/* it's important to grow the table really fast; otherwise we waste */ \
58+
/* lots of time rehashing all the keys over and over. */ \
59+
sz = h->size; \
60+
ol = h->table; \
61+
if (sz < HT_N_INLINE) \
62+
newsz = HT_N_INLINE; \
63+
else if (sz >= (1<<19) || (sz <= (1<<8))) \
64+
newsz = sz<<1; \
65+
else \
66+
newsz = sz<<2; \
67+
/*printf("trying to allocate %d words.\n", newsz); fflush(stdout);*/ \
68+
tab = (void**)LLT_ALLOC(newsz*sizeof(void*)); \
69+
if (tab == NULL) \
70+
return NULL; \
71+
for (i = 0; i < newsz; i++) \
72+
tab[i] = HT_NOTFOUND; \
73+
h->table = tab; \
74+
h->size = newsz; \
75+
for (i = 0; i < sz; i += 2) { \
76+
if (ol[i+1] != HT_NOTFOUND) { \
77+
(*HTNAME##_lookup_bp_r(h, ol[i], ctx)) = ol[i+1]; \
78+
} \
6779
} \
68-
} \
69-
if (ol != &h->_space[0]) \
70-
LLT_FREE(ol); \
80+
if (ol != &h->_space[0]) \
81+
LLT_FREE(ol); \
7182
\
72-
sz = hash_size(h); \
73-
maxprobe = max_probe(sz); \
74-
tab = h->table; \
75-
\
76-
goto retry_bp; \
83+
sz = hash_size(h); \
84+
maxprobe = max_probe(sz); \
85+
tab = h->table; \
86+
} \
7787
\
7888
return NULL; \
7989
} \

0 commit comments

Comments
 (0)