@@ -2952,7 +2952,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29522952 jl_set_gs_ctr (gs_ctr );
29532953 }
29542954 else {
2955- jl_atomic_fetch_add (& jl_world_counter , 1 );
29562955 offset_restored = jl_read_offset (& s );
29572956 offset_init_order = jl_read_offset (& s );
29582957 offset_extext_methods = jl_read_offset (& s );
@@ -3182,7 +3181,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
31823181 jl_cache_type_ ((jl_datatype_t * )obj );
31833182 }
31843183 // Perform fixups: things like updating world ages, inserting methods & specializations, etc.
3185- size_t world = jl_atomic_load_acquire (& jl_world_counter );
31863184 for (size_t i = 0 ; i < s .uniquing_objs .len ; i ++ ) {
31873185 uintptr_t item = (uintptr_t )s .uniquing_objs .items [i ];
31883186 // check whether this is a gvar index
@@ -3236,6 +3234,16 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
32363234 o -> bits .in_image = 1 ;
32373235 }
32383236 arraylist_free (& cleanup_list );
3237+ size_t world = jl_atomic_load_relaxed (& jl_world_counter );
3238+ for (size_t i = 0 ; i < s .fixup_objs .len ; i ++ ) {
3239+ // decide if we need to allocate a world
3240+ uintptr_t item = (uintptr_t )s .fixup_objs .items [i ];
3241+ jl_value_t * obj = (jl_value_t * )(image_base + item );
3242+ if (jl_is_method (obj )) {
3243+ world = jl_atomic_fetch_add (& jl_world_counter , 1 ) + 1 ;
3244+ break ;
3245+ }
3246+ }
32393247 for (size_t i = 0 ; i < s .fixup_objs .len ; i ++ ) {
32403248 uintptr_t item = (uintptr_t )s .fixup_objs .items [i ];
32413249 jl_value_t * obj = (jl_value_t * )(image_base + item );
0 commit comments