summaryrefslogtreecommitdiff
path: root/headers.c
diff options
context:
space:
mode:
authorivmai <ivmai>2009-09-16 14:43:37 +0000
committerIvan Maidanski <ivmai@mail.ru>2011-07-26 21:06:46 +0400
commitdb2565100a193fa71336be2951b342ef7596f828 (patch)
tree4214eb726e4912fa34628655dc41ae247213caf8 /headers.c
parentd70b0280af3c3d53e2a794b26aa7a3127943b8c3 (diff)
downloadbdwgc-db2565100a193fa71336be2951b342ef7596f828.tar.gz
2009-09-16 Ivan Maidanski <ivmai@mail.ru>
* ChangeLog: Remove trailing spaces at EOLn; insert blank lines where missed. * doc/README: Expand all tabs to spaces; remove trailing spaces at EOLn; remove multiple trailing blank lines. * doc/README.autoconf: Ditto. * doc/README.DGUX386: Ditto. * doc/README.environment: Ditto. * doc/README.macros: Ditto. * doc/README.win32: Ditto. * tests/test.c: Ditto. * tests/test_cpp.cc: Ditto. * backgraph.c: Ditto. * blacklst.c: Ditto. * checksums.c: Ditto. * darwin_stop_world.c: Ditto. * dbg_mlc.c: Ditto. * dyn_load.c: Ditto. * finalize.c: Ditto. * gc_dlopen.c: Ditto. * gcj_mlc.c: Ditto. * headers.c: Ditto. * mach_dep.c: Ditto. * malloc.c: Ditto. * mallocx.c: Ditto. * new_hblk.c: Ditto. * obj_map.c: Ditto. * ptr_chck.c: Ditto. * real_malloc.c: Ditto. * reclaim.c: Ditto. * stubborn.c: Ditto. * thread_local_alloc.c: Ditto. * typd_mlc.c: Ditto. * gc_cpp.cc: Ditto. * include/gc_allocator.h: Ditto. * include/gc_backptr.h: Ditto. * include/gc_config_macros.h: Ditto. * include/gc_cpp.h: Ditto. * include/gc_gcj.h: Ditto. * include/gc_inline.h: Ditto. * include/gc_mark.h: Ditto. * include/gc_pthread_redirects.h: Ditto. * include/gc_typed.h: Ditto. * include/gc_version.h: Ditto. * include/javaxfc.h: Ditto. * include/new_gc_alloc.h: Ditto. * include/private/darwin_semaphore.h: Ditto. * include/private/dbg_mlc.h: Ditto. * include/private/gc_hdrs.h: Ditto. * include/private/gc_locks.h: Ditto. * include/private/gc_pmark.h: Ditto. * include/private/gcconfig.h: Ditto. * include/private/pthread_support.h: Ditto. * include/private/thread_local_alloc.h: Ditto. * darwin_stop_world.c: Add copyright header. * include/gc_backptr.h: Ditto. * include/gc_config_macros.h: Ditto. * include/gc_pthread_redirects.h: Ditto. * include/gc_version.h: Ditto. * include/javaxfc.h: Ditto. * include/private/darwin_semaphore.h: Ditto. * include/private/pthread_support.h: Ditto. * gc_cpp.cc: Make copyright header uniform across the package. * include/gc_cpp.h: Ditto.
Diffstat (limited to 'headers.c')
-rw-r--r--headers.c206
1 files changed, 103 insertions, 103 deletions
diff --git a/headers.c b/headers.c
index 774cf8d4..3cf8ad4b 100644
--- a/headers.c
+++ b/headers.c
@@ -1,4 +1,4 @@
-/*
+/*
* Copyright 1988, 1989 Hans-J. Boehm, Alan J. Demers
* Copyright (c) 1991-1994 by Xerox Corporation. All rights reserved.
* Copyright (c) 1996 by Silicon Graphics. All rights reserved.
@@ -12,7 +12,7 @@
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
-
+
/*
* This implements:
* 1. allocation of heap block headers
@@ -21,36 +21,36 @@
* Access speed is crucial. We implement an index structure based on a 2
* level tree.
*/
-
+
# include "private/gc_priv.h"
STATIC bottom_index * GC_all_bottom_indices = 0;
- /* Pointer to first (lowest addr) */
- /* bottom_index. */
+ /* Pointer to first (lowest addr) */
+ /* bottom_index. */
STATIC bottom_index * GC_all_bottom_indices_end = 0;
- /* Pointer to last (highest addr) */
- /* bottom_index. */
-
+ /* Pointer to last (highest addr) */
+ /* bottom_index. */
+
/* Non-macro version of header location routine */
hdr * GC_find_header(ptr_t h)
{
# ifdef HASH_TL
- hdr * result;
- GET_HDR(h, result);
- return(result);
+ hdr * result;
+ GET_HDR(h, result);
+ return(result);
# else
- return(HDR_INNER(h));
+ return(HDR_INNER(h));
# endif
}
-/* Handle a header cache miss. Returns a pointer to the */
-/* header corresponding to p, if p can possibly be a valid */
-/* object pointer, and 0 otherwise. */
-/* GUARANTEED to return 0 for a pointer past the first page */
-/* of an object unless both GC_all_interior_pointers is set */
-/* and p is in fact a valid object pointer. */
-/* Never returns a pointer to a free hblk. */
+/* Handle a header cache miss. Returns a pointer to the */
+/* header corresponding to p, if p can possibly be a valid */
+/* object pointer, and 0 otherwise. */
+/* GUARANTEED to return 0 for a pointer past the first page */
+/* of an object unless both GC_all_interior_pointers is set */
+/* and p is in fact a valid object pointer. */
+/* Never returns a pointer to a free hblk. */
#ifdef PRINT_BLACK_LIST
hdr * GC_header_cache_miss(ptr_t p, hdr_cache_entry *hce, ptr_t source)
#else
@@ -63,34 +63,34 @@ hdr * GC_find_header(ptr_t h)
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
if (GC_all_interior_pointers) {
if (hhdr != 0) {
- ptr_t current = p;
-
- current = (ptr_t)HBLKPTR(current);
- do {
- current = current - HBLKSIZE*(word)hhdr;
- hhdr = HDR(current);
- } while(IS_FORWARDING_ADDR_OR_NIL(hhdr));
- /* current points to near the start of the large object */
- if (hhdr -> hb_flags & IGNORE_OFF_PAGE)
- return 0;
- if (HBLK_IS_FREE(hhdr)
- || p - current >= (ptrdiff_t)(hhdr->hb_sz)) {
- GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
- /* Pointer past the end of the block */
- return 0;
- }
+ ptr_t current = p;
+
+ current = (ptr_t)HBLKPTR(current);
+ do {
+ current = current - HBLKSIZE*(word)hhdr;
+ hhdr = HDR(current);
+ } while(IS_FORWARDING_ADDR_OR_NIL(hhdr));
+ /* current points to near the start of the large object */
+ if (hhdr -> hb_flags & IGNORE_OFF_PAGE)
+ return 0;
+ if (HBLK_IS_FREE(hhdr)
+ || p - current >= (ptrdiff_t)(hhdr->hb_sz)) {
+ GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
+ /* Pointer past the end of the block */
+ return 0;
+ }
} else {
- GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
- /* And return zero: */
+ GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
+ /* And return zero: */
}
GC_ASSERT(hhdr == 0 || !HBLK_IS_FREE(hhdr));
return hhdr;
- /* Pointers past the first page are probably too rare */
- /* to add them to the cache. We don't. */
- /* And correctness relies on the fact that we don't. */
+ /* Pointers past the first page are probably too rare */
+ /* to add them to the cache. We don't. */
+ /* And correctness relies on the fact that we don't. */
} else {
if (hhdr == 0) {
- GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
+ GC_ADD_TO_BLACK_LIST_NORMAL(p, source);
}
return 0;
}
@@ -100,20 +100,20 @@ hdr * GC_find_header(ptr_t h)
return 0;
} else {
hce -> block_addr = (word)(p) >> LOG_HBLKSIZE;
- hce -> hce_hdr = hhdr;
+ hce -> hce_hdr = hhdr;
return hhdr;
}
- }
+ }
}
-
+
/* Routines to dynamically allocate collector data structures that will */
-/* never be freed. */
-
+/* never be freed. */
+
static ptr_t scratch_free_ptr = 0;
-
+
/* GC_scratch_last_end_ptr is end point of last obtained scratch area. */
-/* GC_scratch_end_ptr is end point of current scratch area. */
-
+/* GC_scratch_end_ptr is end point of current scratch area. */
+
ptr_t GC_scratch_alloc(size_t bytes)
{
register ptr_t result = scratch_free_ptr;
@@ -126,34 +126,34 @@ ptr_t GC_scratch_alloc(size_t bytes)
}
{
word bytes_to_get = MINHINCR * HBLKSIZE;
-
+
if (bytes_to_get <= bytes) {
/* Undo the damage, and get memory directly */
- bytes_to_get = bytes;
-# ifdef USE_MMAP
- bytes_to_get += GC_page_size - 1;
- bytes_to_get &= ~(GC_page_size - 1);
-# endif
- result = (ptr_t)GET_MEM(bytes_to_get);
- GC_add_to_our_memory(result, bytes_to_get);
+ bytes_to_get = bytes;
+# ifdef USE_MMAP
+ bytes_to_get += GC_page_size - 1;
+ bytes_to_get &= ~(GC_page_size - 1);
+# endif
+ result = (ptr_t)GET_MEM(bytes_to_get);
+ GC_add_to_our_memory(result, bytes_to_get);
scratch_free_ptr -= bytes;
- GC_scratch_last_end_ptr = result + bytes;
+ GC_scratch_last_end_ptr = result + bytes;
return(result);
}
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
if (result == 0) {
- if (GC_print_stats)
+ if (GC_print_stats)
GC_printf("Out of memory - trying to allocate less\n");
scratch_free_ptr -= bytes;
- bytes_to_get = bytes;
-# ifdef USE_MMAP
- bytes_to_get += GC_page_size - 1;
- bytes_to_get &= ~(GC_page_size - 1);
-# endif
+ bytes_to_get = bytes;
+# ifdef USE_MMAP
+ bytes_to_get += GC_page_size - 1;
+ bytes_to_get &= ~(GC_page_size - 1);
+# endif
result = (ptr_t)GET_MEM(bytes_to_get);
GC_add_to_our_memory(result, bytes_to_get);
- return result;
+ return result;
}
scratch_free_ptr = result;
GC_scratch_end_ptr = scratch_free_ptr + bytes_to_get;
@@ -168,7 +168,7 @@ static hdr * hdr_free_list = 0;
static hdr * alloc_hdr(void)
{
register hdr * result;
-
+
if (hdr_free_list == 0) {
result = (hdr *) GC_scratch_alloc((word)(sizeof(hdr)));
} else {
@@ -188,11 +188,11 @@ static void free_hdr(hdr * hhdr)
word GC_hdr_cache_hits = 0;
word GC_hdr_cache_misses = 0;
#endif
-
+
void GC_init_headers(void)
{
register unsigned i;
-
+
GC_all_nils = (bottom_index *)GC_scratch_alloc((word)sizeof(bottom_index));
BZERO(GC_all_nils, sizeof(bottom_index));
for (i = 0; i < TOP_SZ; i++) {
@@ -201,7 +201,7 @@ void GC_init_headers(void)
}
/* Make sure that there is a bottom level index block for address addr */
-/* Return FALSE on failure. */
+/* Return FALSE on failure. */
static GC_bool get_index(word addr)
{
word hi = (word)(addr) >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE);
@@ -209,11 +209,11 @@ static GC_bool get_index(word addr)
bottom_index * p;
bottom_index ** prev;
bottom_index *pi;
-
+
# ifdef HASH_TL
word i = TL_HASH(hi);
bottom_index * old;
-
+
old = p = GC_top_index[i];
while(p != GC_all_nils) {
if (p -> key == hi) return(TRUE);
@@ -233,35 +233,35 @@ static GC_bool get_index(word addr)
# endif
r -> key = hi;
/* Add it to the list of bottom indices */
- prev = &GC_all_bottom_indices; /* pointer to p */
- pi = 0; /* bottom_index preceding p */
+ prev = &GC_all_bottom_indices; /* pointer to p */
+ pi = 0; /* bottom_index preceding p */
while ((p = *prev) != 0 && p -> key < hi) {
- pi = p;
- prev = &(p -> asc_link);
+ pi = p;
+ prev = &(p -> asc_link);
}
r -> desc_link = pi;
if (0 == p) {
- GC_all_bottom_indices_end = r;
+ GC_all_bottom_indices_end = r;
} else {
- p -> desc_link = r;
+ p -> desc_link = r;
}
r -> asc_link = p;
*prev = r;
return(TRUE);
}
-/* Install a header for block h. */
-/* The header is uninitialized. */
-/* Returns the header or 0 on failure. */
+/* Install a header for block h. */
+/* The header is uninitialized. */
+/* Returns the header or 0 on failure. */
struct hblkhdr * GC_install_header(struct hblk *h)
{
hdr * result;
-
+
if (!get_index((word) h)) return(0);
result = alloc_hdr();
SET_HDR(h, result);
# ifdef USE_MUNMAP
- result -> hb_last_reclaimed = (unsigned short)GC_gc_no;
+ result -> hb_last_reclaimed = (unsigned short)GC_gc_no;
# endif
return(result);
}
@@ -271,7 +271,7 @@ GC_bool GC_install_counts(struct hblk *h, size_t sz/* bytes */)
{
struct hblk * hbp;
word i;
-
+
for (hbp = h; (char *)hbp < (char *)h + sz; hbp += BOTTOM_SZ) {
if (!get_index((word) hbp)) return(FALSE);
}
@@ -287,7 +287,7 @@ GC_bool GC_install_counts(struct hblk *h, size_t sz/* bytes */)
void GC_remove_header(struct hblk *h)
{
hdr ** ha;
-
+
GET_HDR_ADDR(h, ha);
free_hdr(*ha);
*ha = 0;
@@ -297,7 +297,7 @@ void GC_remove_header(struct hblk *h)
void GC_remove_counts(struct hblk *h, size_t sz/* bytes */)
{
register struct hblk * hbp;
-
+
for (hbp = h+1; (char *)hbp < (char *)h + sz; hbp += 1) {
SET_HDR(hbp, 0);
}
@@ -306,19 +306,19 @@ void GC_remove_counts(struct hblk *h, size_t sz/* bytes */)
/* Apply fn to all allocated blocks */
/*VARARGS1*/
void GC_apply_to_all_blocks(void (*fn)(struct hblk *h, word client_data),
- word client_data)
+ word client_data)
{
signed_word j;
bottom_index * index_p;
-
+
for (index_p = GC_all_bottom_indices; index_p != 0;
index_p = index_p -> asc_link) {
for (j = BOTTOM_SZ-1; j >= 0;) {
if (!IS_FORWARDING_ADDR_OR_NIL(index_p->index[j])) {
if (!HBLK_IS_FREE(index_p->index[j])) {
(*fn)(((struct hblk *)
- (((index_p->key << LOG_BOTTOM_SZ) + (word)j)
- << LOG_HBLKSIZE)),
+ (((index_p->key << LOG_BOTTOM_SZ) + (word)j)
+ << LOG_HBLKSIZE)),
client_data);
}
j--;
@@ -331,13 +331,13 @@ void GC_apply_to_all_blocks(void (*fn)(struct hblk *h, word client_data),
}
}
-/* Get the next valid block whose address is at least h */
-/* Return 0 if there is none. */
+/* Get the next valid block whose address is at least h */
+/* Return 0 if there is none. */
struct hblk * GC_next_used_block(struct hblk *h)
{
register bottom_index * bi;
register word j = ((word)h >> LOG_HBLKSIZE) & (BOTTOM_SZ-1);
-
+
GET_BI(h, bi);
if (bi == GC_all_nils) {
register word hi = (word)h >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE);
@@ -347,14 +347,14 @@ struct hblk * GC_next_used_block(struct hblk *h)
}
while(bi != 0) {
while (j < BOTTOM_SZ) {
- hdr * hhdr = bi -> index[j];
+ hdr * hhdr = bi -> index[j];
if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
j++;
} else {
if (!HBLK_IS_FREE(hhdr)) {
return((struct hblk *)
- (((bi -> key << LOG_BOTTOM_SZ) + j)
- << LOG_HBLKSIZE));
+ (((bi -> key << LOG_BOTTOM_SZ) + j)
+ << LOG_HBLKSIZE));
} else {
j += divHBLKSZ(hhdr -> hb_sz);
}
@@ -366,14 +366,14 @@ struct hblk * GC_next_used_block(struct hblk *h)
return(0);
}
-/* Get the last (highest address) block whose address is */
-/* at most h. Return 0 if there is none. */
-/* Unlike the above, this may return a free block. */
+/* Get the last (highest address) block whose address is */
+/* at most h. Return 0 if there is none. */
+/* Unlike the above, this may return a free block. */
struct hblk * GC_prev_block(struct hblk *h)
{
register bottom_index * bi;
register signed_word j = ((word)h >> LOG_HBLKSIZE) & (BOTTOM_SZ-1);
-
+
GET_BI(h, bi);
if (bi == GC_all_nils) {
register word hi = (word)h >> (LOG_BOTTOM_SZ + LOG_HBLKSIZE);
@@ -383,15 +383,15 @@ struct hblk * GC_prev_block(struct hblk *h)
}
while(bi != 0) {
while (j >= 0) {
- hdr * hhdr = bi -> index[j];
- if (0 == hhdr) {
- --j;
+ hdr * hhdr = bi -> index[j];
+ if (0 == hhdr) {
+ --j;
} else if (IS_FORWARDING_ADDR_OR_NIL(hhdr)) {
j -= (signed_word)hhdr;
} else {
return((struct hblk *)
(((bi -> key << LOG_BOTTOM_SZ) + j)
- << LOG_HBLKSIZE));
+ << LOG_HBLKSIZE));
}
}
j = BOTTOM_SZ - 1;