39
39
40
40
`uniquing_list` also holds the serialized location of external DataTypes, MethodInstances, and singletons
41
41
in the serialized blob (i.e., new-at-the-time-of-serialization specializations).
42
+ `uniquing_target` is a hash table for which `uniquing_target[obj] -> chosen_target`.
42
43
43
44
Most of step 2 is handled by `jl_write_values`, followed by special handling of the dedicated parallel streams.
44
45
@@ -1837,7 +1838,7 @@ static void write_gvars(jl_serializer_state *s, arraylist_t *globals) JL_NOTSAFE
1837
1838
}
1838
1839
1839
1840
// Pointer relocation for native-code referenced global variables
1840
- static void jl_update_all_gvars (jl_serializer_state * s )
1841
+ static void jl_update_all_gvars (jl_serializer_state * s , htable_t * uniquing_target )
1841
1842
{
1842
1843
if (sysimg_gvars_base == NULL )
1843
1844
return ;
@@ -1851,7 +1852,11 @@ static void jl_update_all_gvars(jl_serializer_state *s)
1851
1852
uintptr_t offset = * gvars ;
1852
1853
if (offset ) {
1853
1854
uintptr_t v = get_item_for_reloc (s , base , size , offset , s -> link_ids_gvars , & link_index );
1854
- // TODO(required): if (incremental) v = jl_as_global_root((jl_value_t*)v);
1855
+ uintptr_t unique_value = (uintptr_t )ptrhash_get (uniquing_target , (void * )v );
1856
+ if ((void * )unique_value != HT_NOTFOUND )
1857
+ v = unique_value ;
1858
+ // if (s->incremental)
1859
+ // v = (uintptr_t) jl_as_global_root((jl_value_t*)v);
1855
1860
* sysimg_gvars (sysimg_gvars_base , gvname_index ) = (uintptr_t )v ;
1856
1861
}
1857
1862
gvname_index += 1 ;
@@ -2779,21 +2784,10 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_array_t *depmods,
2779
2784
* pfld = (uintptr_t )newobj | GC_OLD ;
2780
2785
else
2781
2786
* pfld = (uintptr_t )newobj ;
2787
+ ptrhash_put (& uniquing_target , (void * )obj , (void * )newobj );
2782
2788
assert (!(image_base < (char * )newobj && (char * )newobj <= image_base + sizeof_sysimg + sizeof (uintptr_t )));
2783
2789
assert (jl_typeis (obj , otyp ));
2784
2790
}
2785
- // Write junk in place of the source data we used during uniquing, to catch inadvertent references to
2786
- // it from elsewhere.
2787
- for (size_t i = 0 ; i < s .uniquing_list .len ; i ++ ) {
2788
- void * item = s .uniquing_list .items [i ];
2789
- jl_taggedvalue_t * o = jl_astaggedvalue (item );
2790
- if (o -> type == (jl_value_t * )jl_method_instance_type )
2791
- memset (o , 0xba , sizeof (jl_value_t * ) + sizeof (jl_method_instance_t ));
2792
- else if (o -> type == (jl_value_t * )jl_datatype_type )
2793
- memset (o , 0xba , sizeof (jl_value_t * ) + sizeof (jl_datatype_t ));
2794
- else
2795
- memset (o , 0xba , sizeof (jl_value_t * ));
2796
- }
2797
2791
// Perform fixups: things like updating world ages, inserting methods & specializations, etc.
2798
2792
size_t world = jl_atomic_load_acquire (& jl_world_counter );
2799
2793
for (size_t i = 0 ; i < s .fixup_list .len ; i ++ ) {
@@ -2872,14 +2866,29 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_array_t *depmods,
2872
2866
r -> bnd_cache = b && b -> value ? b : NULL ;
2873
2867
}
2874
2868
}
2875
- arraylist_free (& s .uniquing_list );
2876
2869
arraylist_free (& s .fixup_list );
2877
2870
2878
2871
// s.link_ids_gvars will be processed in `jl_update_all_gvars`
2879
2872
ios_close (& relocs );
2880
2873
ios_close (& const_data );
2881
- jl_update_all_gvars (& s ); // gvars relocs
2874
+ jl_update_all_gvars (& s , & uniquing_target ); // gvars relocs
2882
2875
ios_close (& gvar_record );
2876
+
2877
+ // Write junk in place of the source data we used during uniquing, to catch inadvertent references to
2878
+ // it from elsewhere. This needs to be delayed after update_all_gvars so that we can rewire gvars as well.
2879
+ for (size_t i = 0 ; i < s .uniquing_list .len ; i ++ ) {
2880
+ void * item = s .uniquing_list .items [i ];
2881
+ jl_taggedvalue_t * o = jl_astaggedvalue (item );
2882
+ if (o -> type == (jl_value_t * )jl_method_instance_type )
2883
+ memset (o , 0xba , sizeof (jl_value_t * ) + sizeof (jl_method_instance_t ));
2884
+ else if (o -> type == (jl_value_t * )jl_datatype_type )
2885
+ memset (o , 0xba , sizeof (jl_value_t * ) + sizeof (jl_datatype_t ));
2886
+ else
2887
+ memset (o , 0xba , sizeof (jl_value_t * ));
2888
+ }
2889
+ arraylist_free (& s .uniquing_list );
2890
+ htable_free (& uniquing_target );
2891
+
2883
2892
s .s = NULL ;
2884
2893
2885
2894
if (0 ) {
0 commit comments