Skip to content

Commit da2f13c

Browse files
committed
add programatic interface to caching modules. renames sys.ji to Base.ji for consistency
1 parent f9bfc9e commit da2f13c

File tree

8 files changed

+84
-67
lines changed

8 files changed

+84
-67
lines changed

Make.inc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ RANLIB := $(CROSS_COMPILE)ranlib
368368

369369

370370
# if not absolute, then relative to the directory of the julia executable
371-
JCPPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/sys.ji\""
371+
JCPPFLAGS += "-DJL_SYSTEM_IMAGE_PATH=\"$(build_private_libdir_rel)/Base.ji\""
372372

373373
# On Windows, we want shared library files to end up in $(build_bindir), instead of $(build_libdir)
374374
ifeq ($(OS),WINNT)

Makefile

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ endif
4848
debug release: | $(DIRS) $(build_datarootdir)/julia/base $(build_datarootdir)/julia/test $(build_docdir) $(build_sysconfdir)/julia/juliarc.jl $(build_man1dir)/julia.1
4949
@$(MAKE) $(QUIET_MAKE) julia-$@
5050
@export private_libdir=$(private_libdir) && \
51-
$(MAKE) $(QUIET_MAKE) LD_LIBRARY_PATH=$(build_libdir):$(LD_LIBRARY_PATH) JULIA_EXECUTABLE="$(JULIA_EXECUTABLE_$@)" $(build_private_libdir)/sys.$(SHLIB_EXT)
51+
$(MAKE) $(QUIET_MAKE) LD_LIBRARY_PATH=$(build_libdir):$(LD_LIBRARY_PATH) JULIA_EXECUTABLE="$(JULIA_EXECUTABLE_$@)" $(build_private_libdir)/Base.$(SHLIB_EXT)
5252

5353
release-candidate: release test
5454
@#Check documentation
@@ -123,12 +123,12 @@ $(build_sysconfdir)/julia/juliarc.jl: contrib/windows/juliarc.jl
123123
endif
124124

125125
# use sys.ji if it exists, otherwise run two stages
126-
$(build_private_libdir)/sys%ji: $(build_private_libdir)/sys%o
126+
$(build_private_libdir)/%.ji: $(build_private_libdir)/%.o
127127

128-
.SECONDARY: $(build_private_libdir)/sys.o
129-
.SECONDARY: $(build_private_libdir)/sys0.o
128+
.SECONDARY: $(build_private_libdir)/Base.o
129+
.SECONDARY: $(build_private_libdir)/Base0.o
130130

131-
$(build_private_libdir)/sys%$(SHLIB_EXT): $(build_private_libdir)/sys%o
131+
$(build_private_libdir)/%.$(SHLIB_EXT): $(build_private_libdir)/%.o
132132
ifneq ($(USEMSVC), 1)
133133
@$(call PRINT_LINK, $(CXX) -shared -fPIC -L$(build_private_libdir) -L$(build_libdir) -L$(build_shlibdir) -o $@ $< \
134134
$$([ $(OS) = Darwin ] && echo '' -Wl,-undefined,dynamic_lookup || echo '' -Wl,--unresolved-symbols,ignore-all ) \
@@ -138,17 +138,21 @@ else
138138
@true
139139
endif
140140

141-
$(build_private_libdir)/sys0.o:
141+
$(build_private_libdir)/Base0.o:
142142
@$(call PRINT_JULIA, cd base && \
143-
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)/sys0) sysimg.jl)
143+
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)) sysimg.jl)
144+
mv $(build_private_libdir)/Base.ji $(build_private_libdir)/Base0.ji
145+
mv $(build_private_libdir)/Base.o $(build_private_libdir)/Base0.o
144146

145147
BASE_SRCS := $(wildcard base/*.jl base/*/*.jl base/*/*/*.jl)
146148

149+
# This rule defines $(,) to be an escaped ',' character
147150
,:=,
148-
$(build_private_libdir)/sys.o: VERSION $(BASE_SRCS) $(build_docdir)/helpdb.jl $(build_private_libdir)/sys0.$(SHLIB_EXT)
151+
152+
$(build_private_libdir)/Base.o: VERSION $(BASE_SRCS) $(build_docdir)/helpdb.jl $(build_private_libdir)/Base0.$(SHLIB_EXT)
149153
@$(call PRINT_JULIA, cd base && \
150-
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)/sys) \
151-
-J$(call cygpath_w,$(build_private_libdir))/$$([ -e $(build_private_libdir)/sys.ji ] && echo sys.ji || echo sys0.ji) -f sysimg.jl \
154+
$(call spawn,$(JULIA_EXECUTABLE)) --build $(call cygpath_w,$(build_private_libdir)) \
155+
-J$(call cygpath_w,$(build_private_libdir))/$$([ -e $(build_private_libdir)/Base.ji ] && echo Base.ji || echo Base0.ji) -f sysimg.jl \
152156
|| { echo '*** This error is usually fixed by running `make clean`. If the error persists$(,) try `make cleanall`. ***' && false; } )
153157

154158
$(build_bindir)/stringreplace: contrib/stringreplace.c | $(build_bindir)
@@ -263,8 +267,8 @@ endif
263267

264268
$(INSTALL_F) src/julia.h src/options.h src/support/*.h $(DESTDIR)$(includedir)/julia
265269
# Copy system image
266-
$(INSTALL_F) $(build_private_libdir)/sys.ji $(DESTDIR)$(private_libdir)
267-
$(INSTALL_M) $(build_private_libdir)/sys.$(SHLIB_EXT) $(DESTDIR)$(private_libdir)
270+
$(INSTALL_F) $(build_private_libdir)/Base.ji $(DESTDIR)$(private_libdir)
271+
$(INSTALL_M) $(build_private_libdir)/Base.$(SHLIB_EXT) $(DESTDIR)$(private_libdir)
268272
# Copy in all .jl sources as well
269273
cp -R -L $(build_datarootdir)/julia $(DESTDIR)$(datarootdir)/
270274
# Copy documentation
@@ -302,7 +306,7 @@ endif
302306

303307
# Overwrite JL_SYSTEM_IMAGE_PATH in julia binaries
304308
for julia in $(DESTDIR)$(bindir)/julia* ; do \
305-
$(call spawn,$(build_bindir)/stringreplace $$(strings -t x - $$julia | grep "sys.ji$$" | awk '{print $$1;}' ) "$(private_libdir_rel)/sys.ji" 256 $(call cygpath_w,$$julia)); \
309+
$(call spawn,$(build_bindir)/stringreplace $$(strings -t x - $$julia | grep "Base.ji$$" | awk '{print $$1;}' ) "$(private_libdir_rel)/Base.ji" 256 $(call cygpath_w,$$julia)); \
306310
done
307311
endif
308312

@@ -337,15 +341,15 @@ ifeq ($(OS), Darwin)
337341
-cat ./contrib/mac/juliarc.jl >> $(DESTDIR)$(prefix)/etc/julia/juliarc.jl
338342
endif
339343

340-
# purge sys.{dll,so,dylib} as that file is not relocatable across processor architectures
344+
# purge Base.{dll,so,dylib} as that file is not relocatable across processor architectures
341345
ifeq ($(JULIA_CPU_TARGET), native)
342-
-rm -f $(DESTDIR)$(private_libdir)/sys.$(SHLIB_EXT)
346+
-rm -f $(DESTDIR)$(private_libdir)/Base.$(SHLIB_EXT)
343347
endif
344348

345349
ifeq ($(OS), WINNT)
346350
ifeq ($(ARCH),x86_64)
347351
# If we are running on WIN64, also delete sys.dll until we switch to llvm3.5+
348-
-rm -f $(DESTDIR)$(private_libdir)/sys.$(SHLIB_EXT)
352+
-rm -f $(DESTDIR)$(private_libdir)/Base.$(SHLIB_EXT)
349353
endif
350354

351355
[ ! -d dist-extras ] || ( cd dist-extras && \

src/Windows.mk

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ LIB = $(LIB);C:\Program Files\llvm\lib\Release
4747
!endif
4848

4949
CFLAGS = $(CFLAGS) -DCOPY_STACKS -D_CRT_SECURE_NO_WARNINGS
50-
CFLAGS = $(CFLAGS) -DJL_SYSTEM_IMAGE_PATH=\"../lib/julia/sys.ji\" -DLIBRARY_EXPORTS
50+
CFLAGS = $(CFLAGS) -DJL_SYSTEM_IMAGE_PATH=\"../lib/julia/Base.ji\" -DLIBRARY_EXPORTS
5151

5252
LIBWINDOWS = \
5353
kernel32.lib \

src/dump.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -884,8 +884,8 @@ static jl_value_t *jl_deserialize_datatype(ios_t *s, int pos, jl_value_t **loc)
884884
if (tag == 7) {
885885
jl_tuple_t *parameters = (jl_tuple_t*)jl_deserialize_value(s, NULL);
886886
dtv = jl_apply_type(dtv, parameters);
887-
backref_list.items[pos] = dtv;
888887
}
888+
backref_list.items[pos] = dtv;
889889
return dtv;
890890
}
891891
uint16_t nf = read_uint16(s);
@@ -1345,6 +1345,10 @@ void jl_deserialize_lambdas_from_mod(ios_t *s)
13451345

13461346
int jl_deserialize_verify_mod_list(ios_t *s)
13471347
{
1348+
if (!jl_main_module->uuid) {
1349+
JL_PRINTF(JL_STDERR, "error: Main module uuid state is invalid for module deserialization.\n");
1350+
return 0;
1351+
}
13481352
while (1) {
13491353
size_t len = read_int32(s);
13501354
if (len == 0)
@@ -1355,15 +1359,15 @@ int jl_deserialize_verify_mod_list(ios_t *s)
13551359
uint64_t uuid = read_uint64(s);
13561360
jl_module_t *m = (jl_module_t*)jl_get_global(jl_main_module, jl_symbol(name));
13571361
if (!m) {
1358-
JL_PRINTF(JL_STDERR, "Module %s must be loaded first\n", name);
1362+
JL_PRINTF(JL_STDERR, "error: Module %s must be loaded first\n", name);
13591363
return 0;
13601364
}
13611365
if (!jl_is_module(m)) {
13621366
ios_close(s);
13631367
jl_errorf("typeassert: expected %s::Module", name);
13641368
}
13651369
if (m->uuid != uuid) {
1366-
JL_PRINTF(JL_STDERR, "Module %s uuid did not match cache file\n", name);
1370+
JL_PRINTF(JL_STDERR, "error: Module %s uuid did not match cache file\n", name);
13671371
return 0;
13681372
}
13691373
}
@@ -1380,6 +1384,7 @@ DLLEXPORT void jl_save_system_image(char *fname)
13801384
int en = jl_gc_is_enabled();
13811385
jl_gc_disable();
13821386
htable_reset(&backref_table, 250000);
1387+
backref_table_numel = 0;
13831388
ios_t f;
13841389
if (ios_file(&f, fname, 1, 1, 1, 1) == NULL) {
13851390
JL_PRINTF(JL_STDERR, "Cannot open system image file \"%s\" for writing.\n", fname);
@@ -1623,6 +1628,7 @@ int jl_save_new_module(char *fname, jl_module_t *mod)
16231628
jl_serialize_mod_list(&f);
16241629
htable_new(&backref_table, 5000);
16251630
ptrhash_put(&backref_table, jl_main_module, (void*)(uintptr_t)0);
1631+
backref_table_numel = 1;
16261632

16271633
int en = jl_gc_is_enabled();
16281634
jl_gc_disable();

src/init.c

Lines changed: 1 addition & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,6 @@
3636

3737
#include "julia.h"
3838
#include "julia_internal.h"
39-
#include <stdio.h>
4039

4140
#ifdef __cplusplus
4241
extern "C" {
@@ -628,7 +627,7 @@ void *mach_segv_listener(void *arg)
628627
(void)arg;
629628
while (1) {
630629
int ret = mach_msg_server(exc_server,2048,segv_port,MACH_MSG_TIMEOUT_NONE);
631-
printf("mach_msg_server: %s\n", mach_error_string(ret));
630+
ios_printf(ios_stderr, "mach_msg_server: %s\n", mach_error_string(ret));
632631
jl_exit(1);
633632
}
634633
}
@@ -998,8 +997,6 @@ DLLEXPORT void jl_install_sigint_handler()
998997
extern int asprintf(char **str, const char *fmt, ...);
999998
extern void *__stack_chk_guard;
1000999

1001-
void jl_compile_all(void);
1002-
10031000
DLLEXPORT int julia_trampoline(int argc, char **argv, int (*pmain)(int ac,char *av[]))
10041001
{
10051002
#if defined(_OS_WINDOWS_)
@@ -1015,37 +1012,6 @@ DLLEXPORT int julia_trampoline(int argc, char **argv, int (*pmain)(int ac,char *
10151012
p[0] = 0;
10161013
JL_SET_STACK_BASE;
10171014
int ret = pmain(argc, argv);
1018-
char *build_path = jl_compileropts.build_path;
1019-
if (build_path) {
1020-
if (jl_compileropts.compile_enabled == JL_COMPILEROPT_COMPILE_ALL)
1021-
jl_compile_all();
1022-
char *build_ji;
1023-
if (asprintf(&build_ji, "%s.ji",build_path) > 0) {
1024-
jl_save_system_image(build_ji);
1025-
free(build_ji);
1026-
if (jl_compileropts.dumpbitcode == JL_COMPILEROPT_DUMPBITCODE_ON) {
1027-
char *build_bc;
1028-
if (asprintf(&build_bc, "%s.bc",build_path) > 0) {
1029-
jl_dump_bitcode(build_bc);
1030-
free(build_bc);
1031-
}
1032-
else {
1033-
ios_printf(ios_stderr,"\nWARNING: failed to create string for .bc build path\n");
1034-
}
1035-
}
1036-
char *build_o;
1037-
if (asprintf(&build_o, "%s.o",build_path) > 0) {
1038-
jl_dump_objfile(build_o,0);
1039-
free(build_o);
1040-
}
1041-
else {
1042-
ios_printf(ios_stderr,"\nFATAL: failed to create string for .o build path\n");
1043-
}
1044-
}
1045-
else {
1046-
ios_printf(ios_stderr,"\nFATAL: failed to create string for .ji build path\n");
1047-
}
1048-
}
10491015
p[sizeof(__stack_chk_guard)-1] = a;
10501016
p[sizeof(__stack_chk_guard)-2] = b;
10511017
p[0] = c;

src/jlapi.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,10 @@ int jl_is_initialized(void) { return jl_main_module!=NULL; }
4646

4747
// First argument is the usr/lib directory where libjulia is, or NULL to guess.
4848
// if that doesn't work, try the full path to the "lib" directory that
49-
// contains lib/julia/sys.ji
49+
// contains lib/julia/Base.ji
5050
// Second argument is the path of a system image file (*.ji) relative to the
5151
// first argument path, or relative to the default julia home dir. The default
52-
// is something like ../lib/julia/sys.ji
52+
// is something like ../lib/julia/Base.ji
5353
DLLEXPORT void jl_init_with_image(char *julia_home_dir, char *image_relative_path)
5454
{
5555
if (jl_is_initialized()) return;

src/toplevel.c

Lines changed: 49 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
#include <stdlib.h>
77
#include <string.h>
8+
#include <stdio.h>
89
#include <setjmp.h>
910
#include <assert.h>
1011
#include <sys/types.h>
@@ -83,11 +84,14 @@ void jl_module_load_time_initialize(jl_module_t *m)
8384
}
8485
}
8586

87+
void jl_compile_all(void);
88+
8689
extern void jl_get_system_hooks(void);
8790
jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
8891
{
8992
static arraylist_t module_stack;
9093
static int initialized=0;
94+
int isbase = 0;
9195
if (!initialized) {
9296
arraylist_new(&module_stack, 0);
9397
initialized = 1;
@@ -106,12 +110,14 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
106110
jl_binding_t *b = jl_get_binding_wr(parent_module, name);
107111
jl_declare_constant(b);
108112
if (b->value != NULL) {
113+
jl_main_module->uuid = 0;
109114
JL_PRINTF(JL_STDERR, "Warning: replacing module %s\n", name->name);
110115
}
111116
jl_module_t *newm = jl_new_module(name);
112117
newm->parent = parent_module;
113118
b->value = (jl_value_t*)newm;
114119
if (parent_module == jl_main_module && name == jl_symbol("Base")) {
120+
isbase = 1;
115121
// pick up Base module during bootstrap
116122
jl_old_base_module = jl_base_module;
117123
jl_base_module = newm;
@@ -156,6 +162,49 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
156162
jl_current_module = last_module;
157163
jl_current_task->current_module = task_last_m;
158164

165+
arraylist_push(&module_stack, newm);
166+
167+
if (jl_current_module == jl_main_module) {
168+
while (module_stack.len > 0) {
169+
jl_module_load_time_initialize((jl_module_t *) arraylist_pop(&module_stack));
170+
}
171+
172+
char *build_path = jl_compileropts.build_path;
173+
if (build_path) {
174+
if (jl_compileropts.compile_enabled == JL_COMPILEROPT_COMPILE_ALL)
175+
jl_compile_all();
176+
char *build_ji;
177+
if (asprintf(&build_ji, "%s" PATHSEPSTRING "%s.ji",build_path,newm->name->name) > 0) {
178+
if (isbase)
179+
jl_save_system_image(build_ji);
180+
else
181+
jl_save_new_module(build_ji, newm);
182+
free(build_ji);
183+
if (jl_compileropts.dumpbitcode == JL_COMPILEROPT_DUMPBITCODE_ON) {
184+
char *build_bc;
185+
if (asprintf(&build_bc, "%s" PATHSEPSTRING "%s.bc",build_path,newm->name->name) > 0) {
186+
jl_dump_bitcode(build_bc);
187+
free(build_bc);
188+
}
189+
else {
190+
ios_printf(ios_stderr,"\nWARNING: failed to create string for .bc build path\n");
191+
}
192+
}
193+
char *build_o;
194+
if (asprintf(&build_o, "%s" PATHSEPSTRING "%s.o",build_path,newm->name->name) > 0) {
195+
jl_dump_objfile(build_o,0);
196+
free(build_o);
197+
}
198+
else {
199+
ios_printf(ios_stderr,"\nFATAL: failed to create string for .o build path\n");
200+
}
201+
}
202+
else {
203+
ios_printf(ios_stderr,"\nFATAL: failed to create string for .ji build path\n");
204+
}
205+
}
206+
}
207+
159208
#if 0
160209
// some optional post-processing steps
161210
size_t i;
@@ -176,14 +225,6 @@ jl_value_t *jl_eval_module_expr(jl_expr_t *ex)
176225
}
177226
#endif
178227

179-
arraylist_push(&module_stack, newm);
180-
181-
if (jl_current_module == jl_main_module) {
182-
while (module_stack.len > 0) {
183-
jl_module_load_time_initialize((jl_module_t *) arraylist_pop(&module_stack));
184-
}
185-
}
186-
187228
return jl_nothing;
188229
}
189230

ui/repl.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ static const char *opts =
8787
" --check-bounds={yes|no} Emit bounds checks always or never (ignoring declarations)\n"
8888
" -O, --optimize Run time-intensive code optimizations\n"
8989
" --int-literals={32|64} Select integer literal size independent of platform\n"
90-
" --dump-bitcode={yes|no} Dump bitcode for the system image (used with --build)\n";
90+
" --dump-bitcode={yes|no} Dump bitcode for the cache image (used with --build)\n";
9191

9292
void parse_opts(int *argcp, char ***argvp)
9393
{

0 commit comments

Comments
 (0)