void S_set_maxgen(IGEN g) { if (g < 0 || g >= static_generation) { fprintf(stderr, "invalid maxgen %d\n", g); S_abnormal_exit(); } if (S_G.new_min_free_gen == S_G.new_max_nonstatic_generation || S_G.new_min_free_gen > g) { S_G.new_min_free_gen = g; } S_G.new_max_nonstatic_generation = g; }
void *S_getmem(iptr bytes, IBOOL zerofill) { void *addr; if ((uptr)bytes < S_pagesize) { if ((addr = malloc(bytes)) == (void *)0) { (void) fprintf(stderr,"out of memory\n"); S_abnormal_exit(); } debug(printf("getmem malloc(%p) -> %p\n", bytes, addr)) if ((membytes += bytes) > maxmembytes) maxmembytes = membytes; if (zerofill) memset(addr, 0, bytes); } else {
static void idiot_checks() { IBOOL oops = 0; if (bytes_per_segment < S_pagesize) { fprintf(stderr, "bytes_per_segment (%x) < S_pagesize (%lx)\n", bytes_per_segment, (long)S_pagesize); oops = 1; } if (sizeof(iptr) != sizeof(ptr)) { fprintf(stderr, "sizeof(iptr) [%ld] != sizeof(ptr) [%ld]\n", (long)sizeof(iptr), (long)sizeof(ptr)); oops = 1; } if (sizeof(uptr) != sizeof(ptr)) { fprintf(stderr, "sizeof(uptr) [%ld] != sizeof(ptr) [%ld]\n", (long)sizeof(uptr), (long)sizeof(ptr)); oops = 1; } if (sizeof(ptr) * 8 != ptr_bits) { fprintf(stderr, "sizeof(ptr) * 8 [%ld] != ptr_bits [%d]\n", (long)sizeof(ptr), ptr_bits); oops = 1; } if (sizeof(int) * 8 != int_bits) { fprintf(stderr, "sizeof(int) * 8 [%ld] != int_bits [%d]\n", (long)sizeof(int), int_bits); oops = 1; } if (sizeof(short) * 8 != short_bits) { fprintf(stderr, "sizeof(short) * 8 [%ld] != short_bits [%d]\n", (long)sizeof(short), short_bits); oops = 1; } if (sizeof(long) * 8 != long_bits) { fprintf(stderr, "sizeof(long) * 8 [%ld] != long_bits [%d]\n", (long)sizeof(long), long_bits); oops = 1; } #ifndef WIN32 if (sizeof(long long) * 8 != long_long_bits) { fprintf(stderr, "sizeof(long long) * 8 [%ld] != long_long_bits [%d]\n", (long)sizeof(long long), long_long_bits); oops = 1; } #endif if (sizeof(wchar_t) * 8 != wchar_bits) { fprintf(stderr, "sizeof(wchar_t) * 8 [%ld] != wchar_bits [%d]\n", (long)sizeof(wchar_t), wchar_bits); oops = 1; } if (sizeof(size_t) * 8 != size_t_bits) { fprintf(stderr, "sizeof(size_t) * 8 [%ld] != size_t_bits [%d]\n", (long)sizeof(size_t), size_t_bits); oops = 1; } #ifndef WIN32 if (sizeof(ssize_t) * 8 != size_t_bits) { fprintf(stderr, "sizeof(ssize_t) * 8 [%ld] != size_t_bits [%d]\n", (long)sizeof(ssize_t), size_t_bits); oops = 1; } #endif if (sizeof(ptrdiff_t) * 8 != ptrdiff_t_bits) { fprintf(stderr, "sizeof(ptrdiff_t) * 8 [%ld] != ptrdiff_t_bits [%d]\n", (long)sizeof(ptrdiff_t), ptrdiff_t_bits); oops = 1; } if (sizeof(time_t) * 8 != time_t_bits) { fprintf(stderr, "sizeof(time_t) * 8 [%ld] != time_t_bits [%d]\n", (long)sizeof(time_t), time_t_bits); oops = 1; } if (sizeof(bigit) * 8 != bigit_bits) { fprintf(stderr, "sizeof(bigit) * 8 [%ld] != bigit_bits [%d]\n", (long)sizeof(bigit), bigit_bits); oops = 1; } if (sizeof(bigitbigit) != 2 * sizeof(bigit)) { fprintf(stderr, "sizeof(bigitbigit) [%ld] != sizeof(bigit) [%ld] * 2\n", (long)sizeof(bigitbigit), (long)sizeof(bigit)); oops = 1; } if (sizeof(char) != 1) { fprintf(stderr, "sizeof(char) [%ld] != 1\n", (long)sizeof(char)); oops = 1; } if (sizeof(I8) != 1) { fprintf(stderr, "sizeof(I8) [%ld] != 1\n", (long)sizeof(I8)); oops = 1; } if (sizeof(U8) != 1) { fprintf(stderr, "sizeof(U8) [%ld] != 1\n", (long)sizeof(U8)); oops = 1; } if (sizeof(I16) != 2) { fprintf(stderr, "sizeof(I16) [%ld] != 2\n", (long)sizeof(I16)); oops = 1; } if (sizeof(U16) != 2) { fprintf(stderr, "sizeof(U16) [%ld] != 2\n", (long)sizeof(U16)); oops = 1; } if (sizeof(I32) != 4) { fprintf(stderr, "sizeof(I32) [%ld] != 4\n", (long)sizeof(I32)); oops = 1; } if (sizeof(U32) != 4) { fprintf(stderr, "sizeof(U32) [%ld] != 4\n", (long)sizeof(U32)); oops = 1; } if (sizeof(I64) != 8) { fprintf(stderr, "sizeof(I64) [%ld] != 8\n", (long)sizeof(I64)); oops = 1; } if (sizeof(U64) != 8) { fprintf(stderr, "sizeof(U64) [%ld] != 8\n", (long)sizeof(U64)); oops = 1; } if (sizeof(string_char) != string_char_bytes) { fprintf(stderr, "sizeof(string_char) [%ld] != string_char_bytes [%d]\n", (long)sizeof(string_char), string_char_bytes); oops = 1; } if (UNFIX(fixtest) != -1) { fprintf(stderr, "UNFIX operation failed\n"); oops = 1; } if (strlen(VERSION)+1 > HEAP_VERSION_LENGTH) { fprintf(stderr, "insufficient space for version in heap header\n"); oops = 1; } if (strlen(MACHINE_TYPE)+1 > HEAP_MACHID_LENGTH) { fprintf(stderr, "insufficient space for machine id in heap header\n"); oops = 1; } #define big 0 #define little 1 if (native_endianness == big) { uptr x[1]; *x = 1; if (*(char *)x != 0) { fprintf(stderr, "endianness claimed to be big, appears to be little\n"); oops = 1; } } else { uptr x[1]; *x = 1; if (*(char *)x == 0) { fprintf(stderr, "endianness claimed to be little, appears to be big\n"); oops = 1; } } if (sizeof(bucket_pointer_list) != sizeof(bucket_list)) { /* gc repurposes bucket_lists for bucket_pointer lists, so they'd better have the same size */ fprintf(stderr, "bucket_pointer_list and bucket_list have different sizes\n"); oops = 1; } if ((cards_per_segment & (sizeof(iptr) - 1)) != 0) { /* gc sometimes processes dirty bytes sizeof(iptr) bytes at a time */ fprintf(stderr, "cards_per_segment is not a multiple of sizeof(iptr)\n"); oops = 1; } if (((uptr)(&((seginfo *)0)->dirty_bytes[0]) & (sizeof(iptr) - 1)) != 0) { /* gc sometimes processes dirty bytes sizeof(iptr) bytes at a time */ fprintf(stderr, "dirty_bytes[0] is not iptr-aligned wrt to seginfo struct\n"); oops = 1; } if (!Sfixnump(type_vector | ~mask_vector)) { /* gc counts on vector type/length looking like a fixnum, so it can put vectors in space_impure */ fprintf(stderr, "vector type/length field does not look like a fixnum\n"); oops = 1; } if (oops) S_abnormal_exit(); }
void S_gc_init() { IGEN g; INT i; S_checkheap = 0; /* 0 for disabled, 1 for enabled */ S_checkheap_errors = 0; /* count of errors detected by checkheap */ checkheap_noisy = 0; /* 0 for error output only; 1 for more noisy output */ if (S_checkheap) { printf(checkheap_noisy ? "NB: check_heap is enabled and noisy\n" : "NB: check_heap_is_enabled\n"); fflush(stdout); } #ifndef WIN32 for (g = 0; g <= static_generation; g++) { S_child_processes[g] = Snil; } #endif /* WIN32 */ if (!S_boot_time) return; for (g = 0; g <= static_generation; g++) { S_G.guardians[g] = Snil; S_G.locked_objects[g] = Snil; S_G.unlocked_objects[g] = Snil; } S_G.max_nonstatic_generation = S_G.new_max_nonstatic_generation = S_G.min_free_gen = S_G.new_min_free_gen = default_max_nonstatic_generation; for (g = 0; g <= static_generation; g += 1) { for (i = 0; i < countof_types; i += 1) { S_G.countof[g][i] = 0; S_G.bytesof[g][i] = 0; } S_G.gctimestamp[g] = 0; S_G.rtds_with_counts[g] = Snil; } S_G.countof[static_generation][countof_oblist] += 1; S_G.bytesof[static_generation][countof_oblist] += S_G.oblist_length * sizeof(bucket *); S_protect(&S_G.static_id); S_G.static_id = S_intern((const unsigned char *)"static"); S_protect(&S_G.countof_names); S_G.countof_names = S_vector(countof_types); for (i = 0; i < countof_types; i += 1) { INITVECTIT(S_G.countof_names, i) = FIX(0); S_G.countof_size[i] = 0; } INITVECTIT(S_G.countof_names, countof_pair) = S_intern((const unsigned char *)"pair"); S_G.countof_size[countof_pair] = size_pair; INITVECTIT(S_G.countof_names, countof_symbol) = S_intern((const unsigned char *)"symbol"); S_G.countof_size[countof_symbol] = size_symbol; INITVECTIT(S_G.countof_names, countof_flonum) = S_intern((const unsigned char *)"flonum"); S_G.countof_size[countof_flonum] = size_flonum; INITVECTIT(S_G.countof_names, countof_closure) = S_intern((const unsigned char *)"procedure"); S_G.countof_size[countof_closure] = 0; INITVECTIT(S_G.countof_names, countof_continuation) = S_intern((const unsigned char *)"continuation"); S_G.countof_size[countof_continuation] = size_continuation; INITVECTIT(S_G.countof_names, countof_bignum) = S_intern((const unsigned char *)"bignum"); S_G.countof_size[countof_bignum] = 0; INITVECTIT(S_G.countof_names, countof_ratnum) = S_intern((const unsigned char *)"ratnum"); S_G.countof_size[countof_ratnum] = size_ratnum; INITVECTIT(S_G.countof_names, countof_inexactnum) = S_intern((const unsigned char *)"inexactnum"); S_G.countof_size[countof_inexactnum] = size_inexactnum; INITVECTIT(S_G.countof_names, countof_exactnum) = S_intern((const unsigned char *)"exactnum"); S_G.countof_size[countof_exactnum] = size_exactnum; INITVECTIT(S_G.countof_names, countof_box) = S_intern((const unsigned char *)"box"); S_G.countof_size[countof_box] = size_box; INITVECTIT(S_G.countof_names, countof_port) = S_intern((const unsigned char *)"port"); S_G.countof_size[countof_port] = size_port; INITVECTIT(S_G.countof_names, countof_code) = S_intern((const unsigned char *)"code"); S_G.countof_size[countof_code] = 0; INITVECTIT(S_G.countof_names, countof_thread) = S_intern((const unsigned char *)"thread"); S_G.countof_size[countof_thread] = size_thread; INITVECTIT(S_G.countof_names, countof_tlc) = S_intern((const unsigned char *)"tlc"); S_G.countof_size[countof_tlc] = size_tlc; INITVECTIT(S_G.countof_names, countof_rtd_counts) = S_intern((const unsigned char *)"rtd-counts"); S_G.countof_size[countof_rtd_counts] = size_rtd_counts; INITVECTIT(S_G.countof_names, countof_stack) = S_intern((const unsigned char *)"stack"); S_G.countof_size[countof_stack] = 0; INITVECTIT(S_G.countof_names, countof_relocation_table) = S_intern((const unsigned char *)"reloc-table"); S_G.countof_size[countof_relocation_table] = 0; INITVECTIT(S_G.countof_names, countof_weakpair) = S_intern((const unsigned char *)"weakpair"); S_G.countof_size[countof_weakpair] = size_pair; INITVECTIT(S_G.countof_names, countof_vector) = S_intern((const unsigned char *)"vector"); S_G.countof_size[countof_vector] = 0; INITVECTIT(S_G.countof_names, countof_string) = S_intern((const unsigned char *)"string"); S_G.countof_size[countof_string] = 0; INITVECTIT(S_G.countof_names, countof_fxvector) = S_intern((const unsigned char *)"fxvector"); S_G.countof_size[countof_fxvector] = 0; INITVECTIT(S_G.countof_names, countof_bytevector) = S_intern((const unsigned char *)"bytevector"); S_G.countof_size[countof_bytevector] = 0; INITVECTIT(S_G.countof_names, countof_locked) = S_intern((const unsigned char *)"locked"); S_G.countof_size[countof_locked] = 0; INITVECTIT(S_G.countof_names, countof_guardian) = S_intern((const unsigned char *)"guardian"); S_G.countof_size[countof_guardian] = size_guardian_entry; INITVECTIT(S_G.countof_names, countof_oblist) = S_intern((const unsigned char *)"oblist"); S_G.countof_size[countof_guardian] = 0; INITVECTIT(S_G.countof_names, countof_ephemeron) = S_intern((const unsigned char *)"ephemron"); S_G.countof_size[countof_ephemeron] = 0; for (i = 0; i < countof_types; i += 1) { if (Svector_ref(S_G.countof_names, i) == FIX(0)) { fprintf(stderr, "uninitialized countof_name at index %d\n", i); S_abnormal_exit(); } } }