@@ -2960,7 +2960,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
29602960 jl_set_gs_ctr (gs_ctr );
29612961 }
29622962 else {
2963- jl_atomic_fetch_add (& jl_world_counter , 1 );
29642963 offset_restored = jl_read_offset (& s );
29652964 offset_init_order = jl_read_offset (& s );
29662965 offset_extext_methods = jl_read_offset (& s );
@@ -3190,7 +3189,6 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
31903189 jl_cache_type_ ((jl_datatype_t * )obj );
31913190 }
31923191 // Perform fixups: things like updating world ages, inserting methods & specializations, etc.
3193- size_t world = jl_atomic_load_acquire (& jl_world_counter );
31943192 for (size_t i = 0 ; i < s .uniquing_objs .len ; i ++ ) {
31953193 uintptr_t item = (uintptr_t )s .uniquing_objs .items [i ];
31963194 // check whether this is a gvar index
@@ -3244,6 +3242,16 @@ static void jl_restore_system_image_from_stream_(ios_t *f, jl_image_t *image, jl
32443242 o -> bits .in_image = 1 ;
32453243 }
32463244 arraylist_free (& cleanup_list );
3245+ size_t world = jl_atomic_load_relaxed (& jl_world_counter );
3246+ for (size_t i = 0 ; i < s .fixup_objs .len ; i ++ ) {
3247+ // decide if we need to allocate a world
3248+ uintptr_t item = (uintptr_t )s .fixup_objs .items [i ];
3249+ jl_value_t * obj = (jl_value_t * )(image_base + item );
3250+ if (jl_is_method (obj )) {
3251+ world = jl_atomic_fetch_add (& jl_world_counter , 1 ) + 1 ;
3252+ break ;
3253+ }
3254+ }
32473255 for (size_t i = 0 ; i < s .fixup_objs .len ; i ++ ) {
32483256 uintptr_t item = (uintptr_t )s .fixup_objs .items [i ];
32493257 jl_value_t * obj = (jl_value_t * )(image_base + item );
0 commit comments