CAMLprim value caml_array_get_float(value array, value index) { intnat idx = Long_val(index); double d; value res; if (idx < 0 || idx >= Wosize_val(array) / Double_wosize) caml_array_bound_error(); d = Double_field(array, idx); Alloc_small(res, Double_wosize, Double_tag, { caml_handle_gc_interrupt(); });
CAMLprim value caml_gc_major_slice (value v) { intnat res; CAMLassert (Is_long (v)); caml_ev_pause(EV_PAUSE_GC); caml_empty_minor_heap (); res = caml_major_collection_slice(Long_val(v), 0); caml_ev_resume(); caml_handle_gc_interrupt(); return Val_long (res); }
CAMLexport value caml_alloc (mlsize_t wosize, tag_t tag) { value result; mlsize_t i; Assert (tag < 256); Assert (tag != Infix_tag); if (wosize == 0){ result = Atom (tag); }else if (wosize <= Max_young_wosize){ Alloc_small (result, wosize, tag, { caml_handle_gc_interrupt(); });
/* Do a minor collection and a slice of major collection, call finalisation functions, etc. Leave the minor heap empty. */ CAMLexport void caml_minor_collection (void) { caml_ev_pause(EV_PAUSE_GC); caml_handle_incoming_interrupts (); caml_empty_minor_heap (); caml_handle_incoming_interrupts (); caml_major_collection_slice (0, 0); caml_final_do_calls(); caml_ev_resume(); /* If the major slice triggered a STW, do that now */ caml_handle_gc_interrupt(); }
intnat caml_major_collection_slice(intnat howmuch) { intnat computed_work = howmuch ? howmuch : default_slice_budget(); intnat budget = computed_work; intnat sweep_work, mark_work; uintnat blocks_marked_before = stat_blocks_marked; value v; caml_save_stack_gc(); sweep_work = budget; budget = caml_sweep(caml_domain_self()->shared_heap, budget); sweep_work -= budget; if (gc_phase == Phase_idle) { caml_do_local_roots(&caml_darken, caml_domain_self()); caml_scan_global_roots(&caml_darken); gc_phase = Phase_marking; } mark_work = budget; if (mark_stack_pop(&v)) budget = mark(v, budget); mark_work -= budget; caml_gc_log("Major slice: %lu alloc, %ld work, %ld sweep, %ld mark (%lu blocks)", (unsigned long)caml_domain_state->allocated_words, (long)computed_work, (long)sweep_work, (long)mark_work, (unsigned long)(stat_blocks_marked - blocks_marked_before)); caml_domain_state->allocated_words = 0; caml_restore_stack_gc(); if (budget > 0) { caml_trigger_stw_gc(); caml_handle_gc_interrupt(); } return computed_work; }
CAMLexport value caml_check_urgent_gc (value extra_root) { CAMLparam1 (extra_root); caml_handle_gc_interrupt(); CAMLreturn (extra_root); }
CAMLexport value caml_copy_double(double d) { value res; Alloc_small(res, Double_wosize, Double_tag, { caml_handle_gc_interrupt(); });