Skip to content

Commit

Permalink
More factoring and simplifications
Browse files Browse the repository at this point in the history
  • Loading branch information
gadmm committed Mar 25, 2021
1 parent fdcf77e commit c0db4e1
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 51 deletions.
16 changes: 1 addition & 15 deletions runtime/caml/startup_aux.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,27 +23,13 @@
extern void caml_init_locale(void);
extern void caml_free_locale(void);

extern void caml_init_atom_table (void);

extern uintnat caml_init_percent_free;
extern uintnat caml_init_max_percent_free;
extern uintnat caml_init_minor_heap_wsz;
extern uintnat caml_init_heap_chunk_sz;
extern uintnat caml_init_heap_wsz;
extern uintnat caml_init_max_stack_wsz;
extern uintnat caml_init_major_window;
extern uintnat caml_init_custom_major_ratio;
extern uintnat caml_init_custom_minor_ratio;
extern uintnat caml_init_custom_minor_max_bsz;
extern uintnat caml_init_policy;
extern uintnat caml_trace_level;
extern int caml_cleanup_on_exit;

extern void caml_parse_ocamlrunparam (void);

/* Common entry point to caml_startup.
Returns 0 if the runtime is already initialized.
If [pooling] is 0, [caml_stat_*] functions will not be backed by a pool. */
If [pooling] is 1, [caml_stat_*] functions will be backed by a pool. */
extern int caml_startup_aux (int pooling);

#endif /* CAML_INTERNALS */
Expand Down
62 changes: 31 additions & 31 deletions runtime/startup_aux.c
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ extern void caml_win32_unregister_overflow_detection (void);
CAMLexport header_t *caml_atom_table = NULL;

/* Initialize the atom table */
void caml_init_atom_table(void)
static void init_atom_table(void)
{
caml_stat_block b;
int i;
Expand Down Expand Up @@ -73,17 +73,19 @@ void caml_init_atom_table(void)

/* Parse the OCAMLRUNPARAM environment variable. */

uintnat caml_init_percent_free = Percent_free_def;
uintnat caml_init_max_percent_free = Max_percent_free_def;
uintnat caml_init_minor_heap_wsz = Minor_heap_def;
uintnat caml_init_heap_chunk_sz = Heap_chunk_def;
uintnat caml_init_heap_wsz = Init_heap_def;
static uintnat init_percent_free = Percent_free_def;
static uintnat init_max_percent_free = Max_percent_free_def;
static uintnat init_minor_heap_wsz = Minor_heap_def;
static uintnat init_heap_chunk_sz = Heap_chunk_def;
static uintnat init_heap_wsz = Init_heap_def;
static uintnat init_major_window = Major_window_def;
static uintnat init_custom_major_ratio = Custom_major_ratio_def;
static uintnat init_custom_minor_ratio = Custom_minor_ratio_def;
static uintnat init_custom_minor_max_bsz = Custom_minor_max_bsz_def;
static uintnat init_policy = Allocation_policy_def;
static uintnat record_backtrace = 0;

uintnat caml_init_max_stack_wsz = Max_stack_def;
uintnat caml_init_major_window = Major_window_def;
uintnat caml_init_custom_major_ratio = Custom_major_ratio_def;
uintnat caml_init_custom_minor_ratio = Custom_minor_ratio_def;
uintnat caml_init_custom_minor_max_bsz = Custom_minor_max_bsz_def;
uintnat caml_init_policy = Allocation_policy_def;
extern int caml_parser_trace;
uintnat caml_trace_level = 0;
int caml_cleanup_on_exit = 0;
Expand All @@ -103,9 +105,7 @@ static void scanmult (char_os *opt, uintnat *var)
}
}

static uintnat record_backtrace = 0;

void caml_parse_ocamlrunparam(void)
static void parse_ocamlrunparam(void)
{
char_os *opt = caml_secure_getenv (T("OCAMLRUNPARAM"));
uintnat p;
Expand All @@ -115,24 +115,24 @@ void caml_parse_ocamlrunparam(void)
if (opt != NULL){
while (*opt != '\0'){
switch (*opt++){
case 'a': scanmult (opt, &caml_init_policy); break;
case 'a': scanmult (opt, &init_policy); break;
case 'b': scanmult (opt, &record_backtrace); break;
case 'c': scanmult (opt, &p); caml_cleanup_on_exit = (p != 0); break;
case 'h': scanmult (opt, &caml_init_heap_wsz); break;
case 'h': scanmult (opt, &init_heap_wsz); break;
case 'H': scanmult (opt, &caml_use_huge_pages); break;
case 'i': scanmult (opt, &caml_init_heap_chunk_sz); break;
case 'i': scanmult (opt, &init_heap_chunk_sz); break;
case 'l': scanmult (opt, &caml_init_max_stack_wsz); break;
case 'M': scanmult (opt, &caml_init_custom_major_ratio); break;
case 'm': scanmult (opt, &caml_init_custom_minor_ratio); break;
case 'n': scanmult (opt, &caml_init_custom_minor_max_bsz); break;
case 'o': scanmult (opt, &caml_init_percent_free); break;
case 'O': scanmult (opt, &caml_init_max_percent_free); break;
case 'M': scanmult (opt, &init_custom_major_ratio); break;
case 'm': scanmult (opt, &init_custom_minor_ratio); break;
case 'n': scanmult (opt, &init_custom_minor_max_bsz); break;
case 'o': scanmult (opt, &init_percent_free); break;
case 'O': scanmult (opt, &init_max_percent_free); break;
case 'p': scanmult (opt, &p); caml_parser_trace = (p != 0); break;
case 'R': break; /* see stdlib/hashtbl.mli */
case 's': scanmult (opt, &caml_init_minor_heap_wsz); break;
case 's': scanmult (opt, &init_minor_heap_wsz); break;
case 't': scanmult (opt, &caml_trace_level); break;
case 'v': scanmult (opt, &caml_verb_gc); break;
case 'w': scanmult (opt, &caml_init_major_window); break;
case 'w': scanmult (opt, &init_major_window); break;
case 'W': scanmult (opt, &caml_runtime_warnings); break;
case ',': continue;
}
Expand All @@ -150,7 +150,6 @@ static int startup_count = 0;
/* Has the runtime been shut down already? */
static int shutdown_happened = 0;


int caml_startup_aux(int pooling)
{
if (shutdown_happened == 1)
Expand All @@ -167,7 +166,7 @@ int caml_startup_aux(int pooling)
#ifdef DEBUG
caml_verb_gc = 0x3F;
#endif
caml_parse_ocamlrunparam();
parse_ocamlrunparam();
if (pooling)
caml_cleanup_on_exit = 1;

Expand All @@ -189,13 +188,14 @@ int caml_startup_aux(int pooling)
caml_install_invalid_parameter_handler();
#endif
caml_init_custom_operations();
caml_init_gc(caml_init_minor_heap_wsz, caml_init_heap_wsz,
caml_init_heap_chunk_sz, caml_init_percent_free,
caml_init_max_percent_free, caml_init_major_window,
caml_init_custom_major_ratio, caml_init_custom_minor_ratio,
caml_init_custom_minor_max_bsz, caml_init_policy);
caml_init_gc(init_minor_heap_wsz, init_heap_wsz,
init_heap_chunk_sz, init_percent_free,
init_max_percent_free, init_major_window,
init_custom_major_ratio, init_custom_minor_ratio,
init_custom_minor_max_bsz, init_policy);
caml_init_backtrace();
caml_record_backtrace(Val_int(record_backtrace));
init_atom_table();

return 1;
}
Expand Down
2 changes: 0 additions & 2 deletions runtime/startup_byt.c
Original file line number Diff line number Diff line change
Expand Up @@ -519,7 +519,6 @@ CAMLexport void caml_main(char_os **argv)
caml_read_section_descriptors(fd, &trail);
/* Initialize the abstract machine */
caml_init_stack (caml_init_max_stack_wsz);
caml_init_atom_table();
/* Initialize the interpreter */
caml_interprete(NULL, 0);
/* Initialize the debugger, if needed */
Expand Down Expand Up @@ -596,7 +595,6 @@ CAMLexport value caml_startup_code_exn(
if (exe_name == NULL) exe_name = caml_search_exe_in_path(argv[0]);
/* Initialize the abstract machine */
caml_init_stack (caml_init_max_stack_wsz);
caml_init_atom_table();
/* Initialize the interpreter */
caml_interprete(NULL, 0);
/* Initialize the debugger, if needed */
Expand Down
4 changes: 1 addition & 3 deletions runtime/startup_nat.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@
extern int caml_parser_trace;
extern char caml_system__code_begin, caml_system__code_end;

/* Initialize the atom table and the static data and code area limits. */
/* Initialize the static data and code area limits. */

struct segment { char * begin; char * end; };

Expand All @@ -54,8 +54,6 @@ static void init_static(void)
char * caml_code_area_start, * caml_code_area_end;
int i;

caml_init_atom_table ();

for (i = 0; caml_data_segments[i].begin != 0; i++) {
/* PR#5509: we must include the zero word at end of data segment,
because pointers equal to caml_data_segments[i].end are static data. */
Expand Down

0 comments on commit c0db4e1

Please sign in to comment.