@@ -622,7 +622,7 @@ static const char *absformat(const char *in)
622
622
return out ;
623
623
}
624
624
625
- static void jl_resolve_sysimg_location (JL_IMAGE_SEARCH rel )
625
+ static void jl_resolve_sysimg_location (JL_IMAGE_SEARCH rel , const char * julia_bindir )
626
626
{
627
627
// this function resolves the paths in jl_options to absolute file locations as needed
628
628
// and it replaces the pointers to `julia_bindir`, `julia_bin`, `image_file`, and output file paths
@@ -642,11 +642,13 @@ static void jl_resolve_sysimg_location(JL_IMAGE_SEARCH rel)
642
642
jl_options .julia_bin = (char * )malloc_s (path_size + 1 );
643
643
memcpy ((char * )jl_options .julia_bin , free_path , path_size );
644
644
((char * )jl_options .julia_bin )[path_size ] = '\0' ;
645
- if (!jl_options . julia_bindir ) {
645
+ if (!julia_bindir ) {
646
646
jl_options .julia_bindir = getenv ("JULIA_BINDIR" );
647
647
if (!jl_options .julia_bindir ) {
648
648
jl_options .julia_bindir = dirname (free_path );
649
649
}
650
+ } else {
651
+ jl_options .julia_bindir = julia_bindir ;
650
652
}
651
653
if (jl_options .julia_bindir )
652
654
jl_options .julia_bindir = absrealpath (jl_options .julia_bindir , 0 );
@@ -721,8 +723,85 @@ static void restore_fp_env(void)
721
723
jl_error ("Failed to configure floating point environment" );
722
724
}
723
725
}
726
+ static NOINLINE void _finish_julia_init (jl_image_buf_t sysimage , jl_ptls_t ptls , jl_task_t * ct )
727
+ {
728
+ JL_TIMING (JULIA_INIT , JULIA_INIT );
729
+
730
+ if (sysimage .kind == JL_IMAGE_KIND_SO )
731
+ jl_gc_notify_image_load (sysimage .data , sysimage .size );
732
+
733
+ if (jl_options .cpu_target == NULL )
734
+ jl_options .cpu_target = "native" ;
735
+
736
+ // Parse image, perform relocations, and init JIT targets, etc.
737
+ jl_image_t parsed_image = jl_init_processor_sysimg (sysimage , jl_options .cpu_target );
738
+
739
+ jl_init_codegen ();
740
+ jl_init_common_symbols ();
741
+
742
+ if (sysimage .kind != JL_IMAGE_KIND_NONE ) {
743
+ // Load the .ji or .so sysimage
744
+ jl_restore_system_image (& parsed_image , sysimage );
745
+ } else {
746
+ // No sysimage provided, init a minimal environment
747
+ jl_init_types ();
748
+ jl_global_roots_list = (jl_genericmemory_t * )jl_an_empty_memory_any ;
749
+ jl_global_roots_keyset = (jl_genericmemory_t * )jl_an_empty_memory_any ;
750
+ }
751
+
752
+ jl_init_flisp ();
753
+ jl_init_serializer ();
754
+
755
+ if (sysimage .kind == JL_IMAGE_KIND_NONE ) {
756
+ jl_top_module = jl_core_module ;
757
+ jl_init_intrinsic_functions ();
758
+ jl_init_primitives ();
759
+ jl_init_main_module ();
760
+ jl_load (jl_core_module , "boot.jl" );
761
+ jl_current_task -> world_age = jl_atomic_load_acquire (& jl_world_counter );
762
+ post_boot_hooks ();
763
+ }
764
+
765
+ if (jl_base_module == NULL ) {
766
+ // nthreads > 1 requires code in Base
767
+ jl_atomic_store_relaxed (& jl_n_threads , 1 );
768
+ jl_n_markthreads = 0 ;
769
+ jl_n_sweepthreads = 0 ;
770
+ jl_n_gcthreads = 0 ;
771
+ jl_n_threads_per_pool [JL_THREADPOOL_ID_INTERACTIVE ] = 0 ;
772
+ jl_n_threads_per_pool [JL_THREADPOOL_ID_DEFAULT ] = 1 ;
773
+ } else {
774
+ jl_current_task -> world_age = jl_atomic_load_acquire (& jl_world_counter );
775
+ post_image_load_hooks ();
776
+ }
777
+ jl_start_threads ();
778
+ jl_start_gc_threads ();
779
+ uv_barrier_wait (& thread_init_done );
780
+
781
+ jl_gc_enable (1 );
782
+
783
+ if ((sysimage .kind != JL_IMAGE_KIND_NONE ) &&
784
+ (!jl_generating_output () || jl_options .incremental ) && jl_module_init_order ) {
785
+ jl_array_t * init_order = jl_module_init_order ;
786
+ JL_GC_PUSH1 (& init_order );
787
+ jl_module_init_order = NULL ;
788
+ int i , l = jl_array_nrows (init_order );
789
+ for (i = 0 ; i < l ; i ++ ) {
790
+ jl_value_t * mod = jl_array_ptr_ref (init_order , i );
791
+ jl_module_run_initializer ((jl_module_t * )mod );
792
+ }
793
+ JL_GC_POP ();
794
+ }
795
+
796
+ if (jl_options .trim ) {
797
+ jl_entrypoint_mis = (arraylist_t * )malloc_s (sizeof (arraylist_t ));
798
+ arraylist_new (jl_entrypoint_mis , 0 );
799
+ }
800
+
801
+ if (jl_options .handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON )
802
+ jl_install_sigint_handler ();
803
+ }
724
804
725
- static NOINLINE void _finish_julia_init (JL_IMAGE_SEARCH rel , jl_ptls_t ptls , jl_task_t * ct );
726
805
727
806
JL_DLLEXPORT int jl_default_debug_info_kind ;
728
807
JL_DLLEXPORT jl_cgparams_t jl_default_cgparams = {
@@ -750,7 +829,7 @@ static void init_global_mutexes(void) {
750
829
JL_MUTEX_INIT (& profile_show_peek_cond_lock , "profile_show_peek_cond_lock" );
751
830
}
752
831
753
- JL_DLLEXPORT void julia_init (JL_IMAGE_SEARCH rel )
832
+ static void julia_init (jl_image_buf_t sysimage )
754
833
{
755
834
// initialize many things, in no particular order
756
835
// but generally running from simple platform things to optional
@@ -860,96 +939,27 @@ JL_DLLEXPORT void julia_init(JL_IMAGE_SEARCH rel)
860
939
jl_task_t * ct = jl_init_root_task (ptls , stack_lo , stack_hi );
861
940
#pragma GCC diagnostic pop
862
941
JL_GC_PROMISE_ROOTED (ct );
863
- _finish_julia_init (rel , ptls , ct );
942
+ _finish_julia_init (sysimage , ptls , ct );
864
943
}
865
944
866
- static NOINLINE void _finish_julia_init (JL_IMAGE_SEARCH rel , jl_ptls_t ptls , jl_task_t * ct )
867
- {
868
- JL_TIMING (JULIA_INIT , JULIA_INIT );
869
- jl_resolve_sysimg_location (rel );
945
+
946
+ // This function is responsible for loading the image and initializing paths in jl_options
947
+ JL_DLLEXPORT void jl_load_image_and_init (JL_IMAGE_SEARCH rel , const char * julia_bindir , void * handle ) {
948
+ libsupport_init ();
949
+
950
+ jl_resolve_sysimg_location (rel , julia_bindir );
870
951
871
952
// loads sysimg if available, and conditionally sets jl_options.cpu_target
872
953
jl_image_buf_t sysimage = { JL_IMAGE_KIND_NONE };
873
- if (rel == JL_IMAGE_IN_MEMORY ) {
954
+ if (handle != NULL ) {
955
+ sysimage = jl_set_sysimg_so (handle );
956
+ } else if (rel == JL_IMAGE_IN_MEMORY ) {
874
957
sysimage = jl_set_sysimg_so (jl_exe_handle );
875
958
jl_options .image_file = jl_options .julia_bin ;
876
- }
877
- else if (jl_options .image_file )
959
+ } else if (jl_options .image_file )
878
960
sysimage = jl_preload_sysimg (jl_options .image_file );
879
961
880
- if (sysimage .kind == JL_IMAGE_KIND_SO )
881
- jl_gc_notify_image_load (sysimage .data , sysimage .size );
882
-
883
- if (jl_options .cpu_target == NULL )
884
- jl_options .cpu_target = "native" ;
885
-
886
- // Parse image, perform relocations, and init JIT targets, etc.
887
- jl_image_t parsed_image = jl_init_processor_sysimg (sysimage , jl_options .cpu_target );
888
-
889
- jl_init_codegen ();
890
- jl_init_common_symbols ();
891
-
892
- if (sysimage .kind != JL_IMAGE_KIND_NONE ) {
893
- // Load the .ji or .so sysimage
894
- jl_restore_system_image (& parsed_image , sysimage );
895
- } else {
896
- // No sysimage provided, init a minimal environment
897
- jl_init_types ();
898
- jl_global_roots_list = (jl_genericmemory_t * )jl_an_empty_memory_any ;
899
- jl_global_roots_keyset = (jl_genericmemory_t * )jl_an_empty_memory_any ;
900
- }
901
-
902
- jl_init_flisp ();
903
- jl_init_serializer ();
904
-
905
- if (sysimage .kind == JL_IMAGE_KIND_NONE ) {
906
- jl_top_module = jl_core_module ;
907
- jl_init_intrinsic_functions ();
908
- jl_init_primitives ();
909
- jl_init_main_module ();
910
- jl_load (jl_core_module , "boot.jl" );
911
- jl_current_task -> world_age = jl_atomic_load_acquire (& jl_world_counter );
912
- post_boot_hooks ();
913
- }
914
-
915
- if (jl_base_module == NULL ) {
916
- // nthreads > 1 requires code in Base
917
- jl_atomic_store_relaxed (& jl_n_threads , 1 );
918
- jl_n_markthreads = 0 ;
919
- jl_n_sweepthreads = 0 ;
920
- jl_n_gcthreads = 0 ;
921
- jl_n_threads_per_pool [JL_THREADPOOL_ID_INTERACTIVE ] = 0 ;
922
- jl_n_threads_per_pool [JL_THREADPOOL_ID_DEFAULT ] = 1 ;
923
- } else {
924
- jl_current_task -> world_age = jl_atomic_load_acquire (& jl_world_counter );
925
- post_image_load_hooks ();
926
- }
927
- jl_start_threads ();
928
- jl_start_gc_threads ();
929
- uv_barrier_wait (& thread_init_done );
930
-
931
- jl_gc_enable (1 );
932
-
933
- if ((sysimage .kind != JL_IMAGE_KIND_NONE ) &&
934
- (!jl_generating_output () || jl_options .incremental ) && jl_module_init_order ) {
935
- jl_array_t * init_order = jl_module_init_order ;
936
- JL_GC_PUSH1 (& init_order );
937
- jl_module_init_order = NULL ;
938
- int i , l = jl_array_nrows (init_order );
939
- for (i = 0 ; i < l ; i ++ ) {
940
- jl_value_t * mod = jl_array_ptr_ref (init_order , i );
941
- jl_module_run_initializer ((jl_module_t * )mod );
942
- }
943
- JL_GC_POP ();
944
- }
945
-
946
- if (jl_options .trim ) {
947
- jl_entrypoint_mis = (arraylist_t * )malloc_s (sizeof (arraylist_t ));
948
- arraylist_new (jl_entrypoint_mis , 0 );
949
- }
950
-
951
- if (jl_options .handle_signals == JL_OPTIONS_HANDLE_SIGNALS_ON )
952
- jl_install_sigint_handler ();
962
+ julia_init (sysimage );
953
963
}
954
964
955
965
#ifdef __cplusplus
0 commit comments