@@ -12,26 +12,34 @@ static void **jl_table_lookup_bp(jl_array_t **pa, void *key);
12
12
13
13
void jl_idtable_rehash (jl_array_t * * pa , size_t newsz )
14
14
{
15
+ // Assume *pa don't need a write barrier
16
+ // pa doesn't have to be a GC slot but *pa needs to be rooted
15
17
size_t sz = jl_array_len (* pa );
16
18
size_t i ;
17
19
void * * ol = (void * * )(* pa )-> data ;
18
- * pa = jl_alloc_cell_1d (newsz );
19
- // we do not check the write barrier here
20
- // because pa always points to a C stack location
21
- // (see eqtable_put)
22
- // it should be changed if this assumption no longer holds
20
+ jl_array_t * newa = jl_alloc_cell_1d (newsz );
21
+ // keep the original array in the original slot since we need `ol`
22
+ // to be valid in the loop below.
23
+ JL_GC_PUSH1 (& newa );
23
24
for (i = 0 ; i < sz ; i += 2 ) {
24
25
if (ol [i + 1 ] != NULL ) {
25
- (* jl_table_lookup_bp (pa , ol [i ])) = ol [i + 1 ];
26
- jl_gc_wb (* pa , ol [i + 1 ]);
26
+ (* jl_table_lookup_bp (& newa , ol [i ])) = ol [i + 1 ];
27
+ jl_gc_wb (newa , ol [i + 1 ]);
27
28
// it is however necessary here because allocation
28
29
// can (and will) occur in a recursive call inside table_lookup_bp
29
30
}
30
31
}
32
+ * pa = newa ;
33
+ // we do not check the write barrier here
34
+ // because pa always points to a C stack location
35
+ // (see jl_eqtable_put and jl_finalize_deserializer)
36
+ // it should be changed if this assumption no longer holds
37
+ JL_GC_POP ();
31
38
}
32
39
33
40
static void * * jl_table_lookup_bp (jl_array_t * * pa , void * key )
34
41
{
42
+ // pa points to a **rooted** gc frame slot
35
43
uint_t hv ;
36
44
jl_array_t * a = * pa ;
37
45
size_t orig , index , iter ;
@@ -116,9 +124,12 @@ static void **jl_table_peek_bp(jl_array_t *a, void *key)
116
124
JL_DLLEXPORT
117
125
jl_array_t * jl_eqtable_put (jl_array_t * h , void * key , void * val )
118
126
{
127
+ JL_GC_PUSH1 (& h );
128
+ // &h may be assigned to in jl_idtable_rehash so it need to be rooted
119
129
void * * bp = jl_table_lookup_bp (& h , key );
120
130
* bp = val ;
121
131
jl_gc_wb (h , val );
132
+ JL_GC_POP ();
122
133
return h ;
123
134
}
124
135
0 commit comments