| 1 | /*
|
|---|
| 2 | * Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
|
|---|
| 3 | * Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
|
|---|
| 4 | * Copyright (c) 2000 by Hewlett-Packard Company. All rights reserved.
|
|---|
| 5 | *
|
|---|
| 6 | * THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
|
|---|
| 7 | * OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
|
|---|
| 8 | *
|
|---|
| 9 | * Permission is hereby granted to use or copy this program
|
|---|
| 10 | * for any purpose, provided the above notices are retained on all copies.
|
|---|
| 11 | * Permission to modify the code and to distribute modified code is granted,
|
|---|
| 12 | * provided the above notices are retained, and a notice that the code was
|
|---|
| 13 | * modified is included with the above copyright notice.
|
|---|
| 14 | */
|
|---|
| 15 | /* Boehm, February 7, 1996 4:32 pm PST */
|
|---|
| 16 |
|
|---|
| 17 | #include <stdio.h>
|
|---|
| 18 | #include "private/gc_priv.h"
|
|---|
| 19 |
|
|---|
| 20 | extern ptr_t GC_clear_stack(); /* in misc.c, behaves like identity */
|
|---|
| 21 | void GC_extend_size_map(); /* in misc.c. */
|
|---|
| 22 |
|
|---|
| 23 | /* Allocate reclaim list for kind: */
|
|---|
| 24 | /* Return TRUE on success */
|
|---|
| 25 | GC_bool GC_alloc_reclaim_list(kind)
|
|---|
| 26 | register struct obj_kind * kind;
|
|---|
| 27 | {
|
|---|
| 28 | struct hblk ** result = (struct hblk **)
|
|---|
| 29 | GC_scratch_alloc((MAXOBJSZ+1) * sizeof(struct hblk *));
|
|---|
| 30 | if (result == 0) return(FALSE);
|
|---|
| 31 | BZERO(result, (MAXOBJSZ+1)*sizeof(struct hblk *));
|
|---|
| 32 | kind -> ok_reclaim_list = result;
|
|---|
| 33 | return(TRUE);
|
|---|
| 34 | }
|
|---|
| 35 |
|
|---|
| 36 | /* Allocate a large block of size lw words. */
|
|---|
| 37 | /* The block is not cleared. */
|
|---|
| 38 | /* Flags is 0 or IGNORE_OFF_PAGE. */
|
|---|
| 39 | ptr_t GC_alloc_large(lw, k, flags)
|
|---|
| 40 | word lw;
|
|---|
| 41 | int k;
|
|---|
| 42 | unsigned flags;
|
|---|
| 43 | {
|
|---|
| 44 | struct hblk * h;
|
|---|
| 45 | word n_blocks = OBJ_SZ_TO_BLOCKS(lw);
|
|---|
| 46 | ptr_t result;
|
|---|
| 47 |
|
|---|
| 48 | if (!GC_is_initialized) GC_init_inner();
|
|---|
| 49 | /* Do our share of marking work */
|
|---|
| 50 | if(GC_incremental && !GC_dont_gc)
|
|---|
| 51 | GC_collect_a_little_inner((int)n_blocks);
|
|---|
| 52 | h = GC_allochblk(lw, k, flags);
|
|---|
| 53 | # ifdef USE_MUNMAP
|
|---|
| 54 | if (0 == h) {
|
|---|
| 55 | GC_merge_unmapped();
|
|---|
| 56 | h = GC_allochblk(lw, k, flags);
|
|---|
| 57 | }
|
|---|
| 58 | # endif
|
|---|
| 59 | while (0 == h && GC_collect_or_expand(n_blocks, (flags != 0))) {
|
|---|
| 60 | h = GC_allochblk(lw, k, flags);
|
|---|
| 61 | }
|
|---|
| 62 | if (h == 0) {
|
|---|
| 63 | result = 0;
|
|---|
| 64 | } else {
|
|---|
| 65 | int total_bytes = BYTES_TO_WORDS(n_blocks * HBLKSIZE);
|
|---|
| 66 | if (n_blocks > 1) {
|
|---|
| 67 | GC_large_allocd_bytes += n_blocks * HBLKSIZE;
|
|---|
| 68 | if (GC_large_allocd_bytes > GC_max_large_allocd_bytes)
|
|---|
| 69 | GC_max_large_allocd_bytes = GC_large_allocd_bytes;
|
|---|
| 70 | }
|
|---|
| 71 | result = (ptr_t) (h -> hb_body);
|
|---|
| 72 | GC_words_wasted += total_bytes - lw;
|
|---|
| 73 | }
|
|---|
| 74 | return result;
|
|---|
| 75 | }
|
|---|
| 76 |
|
|---|
| 77 |
|
|---|
| 78 | /* Allocate a large block of size lb bytes. Clear if appropriate. */
|
|---|
| 79 | ptr_t GC_alloc_large_and_clear(lw, k, flags)
|
|---|
| 80 | word lw;
|
|---|
| 81 | int k;
|
|---|
| 82 | unsigned flags;
|
|---|
| 83 | {
|
|---|
| 84 | ptr_t result = GC_alloc_large(lw, k, flags);
|
|---|
| 85 | word n_blocks = OBJ_SZ_TO_BLOCKS(lw);
|
|---|
| 86 |
|
|---|
| 87 | if (0 == result) return 0;
|
|---|
| 88 | if (GC_debugging_started || GC_obj_kinds[k].ok_init) {
|
|---|
| 89 | /* Clear the whole block, in case of GC_realloc call. */
|
|---|
| 90 | BZERO(result, n_blocks * HBLKSIZE);
|
|---|
| 91 | }
|
|---|
| 92 | return result;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | /* allocate lb bytes for an object of kind k. */
|
|---|
|
|---|