diff options
| author | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2017-03-10 17:29:21 +0100 |
|---|---|---|
| committer | Sébastien Hinderer <Sebastien.Hinderer@inria.fr> | 2017-03-13 13:55:08 +0100 |
| commit | adcb4497968dbdc1b0db97998488ad20c02fe225 (patch) | |
| tree | a808375cb22f26cd7b65baefd1cd79b4426b94c7 /byterun/gc_ctrl.c | |
| parent | ad72a6749c2e61cf30eb4e55a8787d45a5d5f10b (diff) | |
| download | ocaml-adcb4497968dbdc1b0db97998488ad20c02fe225.tar.gz | |
Assertions cleanup
Replace a few occurrences of assert and many occurrences of Assert
by CAMLassert.
In asmrun/spacetime_snapshot.c, the line
Assert(0); /* unreachable */
in the function caml_spacetime_shape_table has been removed
rather than replaced because the caml_failwith function called
just above has the noreturn attribute which should be enough to
keep compilers happy.
The same holds in the function caml_spacetime_only_works_for_native_code
defined in byterun/spacetime.c
Diffstat (limited to 'byterun/gc_ctrl.c')
| -rw-r--r-- | byterun/gc_ctrl.c | 82 |
1 files changed, 42 insertions, 40 deletions
diff --git a/byterun/gc_ctrl.c b/byterun/gc_ctrl.c index bfc170a3b1..c3fedd076a 100644 --- a/byterun/gc_ctrl.c +++ b/byterun/gc_ctrl.c @@ -64,25 +64,25 @@ extern uintnat caml_allocation_policy; /* see freelist.c */ /* Check that [v]'s header looks good. [v] must be a block in the heap. */ static void check_head (value v) { - Assert (Is_block (v)); - Assert (Is_in_heap (v)); + CAMLassert (Is_block (v)); + CAMLassert (Is_in_heap (v)); - Assert (Wosize_val (v) != 0); - Assert (Color_hd (Hd_val (v)) != Caml_blue); - Assert (Is_in_heap (v)); + CAMLassert (Wosize_val (v) != 0); + CAMLassert (Color_hd (Hd_val (v)) != Caml_blue); + CAMLassert (Is_in_heap (v)); if (Tag_val (v) == Infix_tag){ int offset = Wsize_bsize (Infix_offset_val (v)); value trueval = Val_op (&Field (v, -offset)); - Assert (Tag_val (trueval) == Closure_tag); - Assert (Wosize_val (trueval) > offset); - Assert (Is_in_heap (&Field (trueval, Wosize_val (trueval) - 1))); + CAMLassert (Tag_val (trueval) == Closure_tag); + CAMLassert (Wosize_val (trueval) > offset); + CAMLassert (Is_in_heap (&Field (trueval, Wosize_val (trueval) - 1))); }else{ - Assert (Is_in_heap (&Field (v, Wosize_val (v) - 1))); + CAMLassert (Is_in_heap (&Field (v, Wosize_val (v) - 1))); } if (Tag_val (v) == Double_tag){ - Assert (Wosize_val (v) == Double_wosize); + CAMLassert (Wosize_val (v) == Double_wosize); }else if (Tag_val (v) == Double_array_tag){ - Assert (Wosize_val (v) % Double_wosize == 0); + CAMLassert (Wosize_val (v) % Double_wosize == 0); } } @@ -98,26 +98,26 @@ static void check_block (header_t *hp) case String_tag: break; case Double_tag: - Assert (Wosize_val (v) == Double_wosize); + CAMLassert (Wosize_val (v) == Double_wosize); break; case Double_array_tag: - Assert (Wosize_val (v) % Double_wosize == 0); + CAMLassert (Wosize_val (v) % Double_wosize == 0); break; case Custom_tag: - Assert (!Is_in_heap (Custom_ops_val (v))); + CAMLassert (!Is_in_heap (Custom_ops_val (v))); break; case Infix_tag: - Assert (0); + CAMLassert (0); break; default: - Assert (Tag_hp (hp) < No_scan_tag); + CAMLassert (Tag_hp (hp) < No_scan_tag); for (i = 0; i < Wosize_hp (hp); i++){ f = Field (v, i); if (Is_block (f) && Is_in_heap (f)){ check_head (f); - Assert (Color_val (f) != Caml_blue); + CAMLassert (Color_val (f) != Caml_blue); } } } @@ -155,14 +155,14 @@ static value heap_stats (int returnstats) cur_hp = (header_t *) chunk; while (cur_hp < (header_t *) chunk_end){ cur_hd = Hd_hp (cur_hp); - Assert (Next (cur_hp) <= (header_t *) chunk_end); + CAMLassert (Next (cur_hp) <= (header_t *) chunk_end); switch (Color_hd (cur_hd)){ case Caml_white: if (Wosize_hd (cur_hd) == 0){ ++ fragments; - Assert (prev_hp == NULL - || Color_hp (prev_hp) != Caml_blue - || cur_hp == (header_t *) caml_gc_sweep_hp); + CAMLassert (prev_hp == NULL + || Color_hp (prev_hp) != Caml_blue + || cur_hp == (header_t *) caml_gc_sweep_hp); }else{ if (caml_gc_phase == Phase_sweep && cur_hp >= (header_t *) caml_gc_sweep_hp){ @@ -181,7 +181,7 @@ static value heap_stats (int returnstats) } break; case Caml_gray: case Caml_black: - Assert (Wosize_hd (cur_hd) > 0); + CAMLassert (Wosize_hd (cur_hd) > 0); ++ live_blocks; live_words += Whsize_hd (cur_hd); #ifdef DEBUG @@ -189,21 +189,23 @@ static value heap_stats (int returnstats) #endif break; case Caml_blue: - Assert (Wosize_hd (cur_hd) > 0); + CAMLassert (Wosize_hd (cur_hd) > 0); ++ free_blocks; free_words += Whsize_hd (cur_hd); if (Whsize_hd (cur_hd) > largest_free){ largest_free = Whsize_hd (cur_hd); } /* not true any more with big heap chunks - Assert (prev_hp == NULL - || (Color_hp (prev_hp) != Caml_blue && Wosize_hp (prev_hp) > 0) - || cur_hp == caml_gc_sweep_hp); - Assert (Next (cur_hp) == chunk_end - || (Color_hp (Next (cur_hp)) != Caml_blue - && Wosize_hp (Next (cur_hp)) > 0) - || (Whsize_hd (cur_hd) + Wosize_hp (Next (cur_hp)) > Max_wosize) - || Next (cur_hp) == caml_gc_sweep_hp); + CAMLassert (prev_hp == NULL + || (Color_hp (prev_hp) != Caml_blue + && Wosize_hp (prev_hp) > 0) + || cur_hp == caml_gc_sweep_hp); + CAMLassert (Next (cur_hp) == chunk_end + || (Color_hp (Next (cur_hp)) != Caml_blue + && Wosize_hp (Next (cur_hp)) > 0) + || (Whsize_hd (cur_hd) + Wosize_hp (Next (cur_hp)) + > Max_wosize) + || Next (cur_hp) == caml_gc_sweep_hp); */ break; } @@ -211,7 +213,7 @@ static value heap_stats (int returnstats) prev_hp = cur_hp; #endif cur_hp = Next (cur_hp); - } Assert (cur_hp == (header_t *) chunk_end); + } CAMLassert (cur_hp == (header_t *) chunk_end); chunk = Chunk_next (chunk); } @@ -219,8 +221,8 @@ static value heap_stats (int returnstats) caml_final_invariant_check(); #endif - Assert (heap_chunks == caml_stat_heap_chunks); - Assert (live_words + free_words + fragments == caml_stat_heap_wsz); + CAMLassert (heap_chunks == caml_stat_heap_chunks); + CAMLassert (live_words + free_words + fragments == caml_stat_heap_wsz); if (returnstats){ CAMLlocal1 (res); @@ -270,7 +272,7 @@ CAMLprim value caml_gc_stat(value v) { value result; CAML_INSTR_SETUP (tmr, ""); - Assert (v == Val_unit); + CAMLassert (v == Val_unit); result = heap_stats (1); CAML_INSTR_TIME (tmr, "explicit/gc_stat"); return result; @@ -464,7 +466,7 @@ CAMLprim value caml_gc_set(value v) CAMLprim value caml_gc_minor(value v) { CAML_INSTR_SETUP (tmr, ""); - Assert (v == Val_unit); + CAMLassert (v == Val_unit); caml_request_minor_gc (); caml_gc_dispatch (); CAML_INSTR_TIME (tmr, "explicit/gc_minor"); @@ -489,7 +491,7 @@ static void test_and_compact (void) CAMLprim value caml_gc_major(value v) { CAML_INSTR_SETUP (tmr, ""); - Assert (v == Val_unit); + CAMLassert (v == Val_unit); caml_gc_message (0x1, "Major GC cycle requested\n", 0); caml_empty_minor_heap (); caml_finish_major_cycle (); @@ -502,7 +504,7 @@ CAMLprim value caml_gc_major(value v) CAMLprim value caml_gc_full_major(value v) { CAML_INSTR_SETUP (tmr, ""); - Assert (v == Val_unit); + CAMLassert (v == Val_unit); caml_gc_message (0x1, "Full major GC cycle requested\n", 0); caml_empty_minor_heap (); caml_finish_major_cycle (); @@ -518,7 +520,7 @@ CAMLprim value caml_gc_full_major(value v) CAMLprim value caml_gc_major_slice (value v) { CAML_INSTR_SETUP (tmr, ""); - Assert (Is_long (v)); + CAMLassert (Is_long (v)); caml_major_collection_slice (Long_val (v)); CAML_INSTR_TIME (tmr, "explicit/gc_major_slice"); return Val_long (0); @@ -527,7 +529,7 @@ CAMLprim value caml_gc_major_slice (value v) CAMLprim value caml_gc_compaction(value v) { CAML_INSTR_SETUP (tmr, ""); - Assert (v == Val_unit); + CAMLassert (v == Val_unit); caml_gc_message (0x10, "Heap compaction requested\n", 0); caml_empty_minor_heap (); caml_finish_major_cycle (); |
