Commit fd6a6309 by Tom Tromey

Initial revision

From-SVN: r30324
parent d9bba9c3
/*
* This is a simple API to implement pointer back tracing, i.e.
* to answer questions such as "who is pointing to this" or
* "why is this object being retained by the collector"
*
* This API assumes that we have an ANSI C compiler.
*
* Most of these calls yield useful information on only after
* a garbage collection. Usually the client will first force
* a full collection and then gather information, preferably
* before much intervening allocation.
*
* The implementation of the interface is only about 99.9999%
* correct. It is intended to be good enough for profiling,
* but is not intended to be used with production code.
*
* Results are likely to be much more useful if all allocation is
* accomplished through the debugging allocators.
*
* The implementation idea is due to A. Demers.
*/
/* Store information about the object referencing dest in *base_p */
/* and *offset_p. */
/* If multiple objects or roots point to dest, the one reported */
/* will be the last on used by the garbage collector to trace the */
/* object. */
/* source is root ==> *base_p = address, *offset_p = 0 */
/* source is heap object ==> *base_p != 0, *offset_p = offset */
/* Returns 1 on success, 0 if source couldn't be determined. */
/* Dest can be any address within a heap object. */
typedef enum { GC_UNREFERENCED, /* No refence info available. */
GC_NO_SPACE, /* Dest not allocated with debug alloc */
GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */
GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
GC_FINALIZER_REFD /* Finalizable and hence accessible. */
} GC_ref_kind;
GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p);
/* Generate a random heap address. */
/* The resulting address is in the heap, but */
/* not necessarily inside a valid object. */
void * GC_generate_random_heap_address(void);
/* Generate a random address inside a valid marked heap object. */
void * GC_generate_random_valid_address(void);
/* Force a garbage collection and generate a backtrace from a */
/* random heap address. */
/* This uses the GC logging mechanism (GC_printf) to produce */
/* output. It can often be called from a debugger. The */
/* source in dbg_mlc.c also serves as a sample client. */
void GC_generate_random_backtrace(void);
.SPACE $PRIVATE$
.SUBSPA $DATA$,QUAD=1,ALIGN=8,ACCESS=31
.SUBSPA $BSS$,QUAD=1,ALIGN=8,ACCESS=31,ZERO,SORT=82
.SPACE $TEXT$
.SUBSPA $LIT$,QUAD=0,ALIGN=8,ACCESS=44
.SUBSPA $CODE$,QUAD=0,ALIGN=8,ACCESS=44,CODE_ONLY
.IMPORT $global$,DATA
.IMPORT $$dyncall,MILLICODE
.SPACE $TEXT$
.SUBSPA $CODE$
.align 4
.EXPORT GC_test_and_clear,ENTRY,PRIV_LEV=3,ARGW0=GR,RTNVAL=GR
GC_test_and_clear
.PROC
.CALLINFO FRAME=0,NO_CALLS
.ENTRY
ldcw,co (%r26),%r28
bv,n 0(%r2)
.EXIT
.PROCEND
/*
* This is a simple API to implement pointer back tracing, i.e.
* to answer questions such as "who is pointing to this" or
* "why is this object being retained by the collector"
*
* This API assumes that we have an ANSI C compiler.
*
* Most of these calls yield useful information on only after
* a garbage collection. Usually the client will first force
* a full collection and then gather information, preferably
* before much intervening allocation.
*
* The implementation of the interface is only about 99.9999%
* correct. It is intended to be good enough for profiling,
* but is not intended to be used with production code.
*
* Results are likely to be much more useful if all allocation is
* accomplished through the debugging allocators.
*
* The implementation idea is due to A. Demers.
*/
/* Store information about the object referencing dest in *base_p */
/* and *offset_p. */
/* If multiple objects or roots point to dest, the one reported */
/* will be the last on used by the garbage collector to trace the */
/* object. */
/* source is root ==> *base_p = address, *offset_p = 0 */
/* source is heap object ==> *base_p != 0, *offset_p = offset */
/* Returns 1 on success, 0 if source couldn't be determined. */
/* Dest can be any address within a heap object. */
typedef enum { GC_UNREFERENCED, /* No refence info available. */
GC_NO_SPACE, /* Dest not allocated with debug alloc */
GC_REFD_FROM_ROOT, /* Referenced directly by root *base_p */
GC_REFD_FROM_HEAP, /* Referenced from another heap obj. */
GC_FINALIZER_REFD /* Finalizable and hence accessible. */
} GC_ref_kind;
GC_ref_kind GC_get_back_ptr_info(void *dest, void **base_p, size_t *offset_p);
/* Generate a random heap address. */
/* The resulting address is in the heap, but */
/* not necessarily inside a valid object. */
void * GC_generate_random_heap_address(void);
/* Generate a random address inside a valid marked heap object. */
void * GC_generate_random_valid_address(void);
/* Force a garbage collection and generate a backtrace from a */
/* random heap address. */
/* This uses the GC logging mechanism (GC_printf) to produce */
/* output. It can often be called from a debugger. The */
/* source in dbg_mlc.c also serves as a sample client. */
void GC_generate_random_backtrace(void);
/*
* Copyright (c) 1999 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/* Descriptor for allocation request. May be redefined by client. */
typedef struct {
GC_word bitmap; /* Bitmap describing pointer locations. */
/* High order bit correspond to 0th */
/* word. 2 lsbs must be 0. */
size_t length; /* In bytes, must be multiple of word */
/* size. Must be >0, <= 512 */
} * GC_copy_descriptor;
/* The collector accesses descriptors only through these two macros. */
#define GC_SIZE_FROM_DESCRIPTOR(d) ((d) -> length)
#define GC_BIT_MAP_FROM_DESCRIPTOR(d) ((d) -> bitmap)
/*
* Copyright (c) 1999 by Silicon Graphics. All rights reserved.
*
* THIS MATERIAL IS PROVIDED AS IS, WITH ABSOLUTELY NO WARRANTY EXPRESSED
* OR IMPLIED. ANY USE IS AT YOUR OWN RISK.
*
* Permission is hereby granted to use or copy this program
* for any purpose, provided the above notices are retained on all copies.
* Permission to modify the code and to distribute modified code is granted,
* provided the above notices are retained, and a notice that the code was
* modified is included with the above copyright notice.
*/
/*
* THIS IMPLEMENTATION FOR THIS INTERFACE IS INCOMPLETE.
* NONE OF THIS HAS BEEN TESTED. DO NOT USE.
*
* Comments on the interface are appreciated, especially from
* potential users of the interface.
*
* This is a Bartlett style copying collector for young objects.
* We assume for now that all objects allocated through this
* mechanism have pointers only in the first BITMAP_BITS words.
* (On a 32-bit machine, BITMAP_BITS is 30.)
* Objects allocated in this manner should be rarely referenced
* by objects not allocated either through this interface, or through
* the typed allocation interface.
* If this interface is used, we assume that type information provided
* through either this or the typed allocation interface is valid
* in a stronger sense:
*
* 1) No pointers are stored in fields not marked as such.
* (Otherwise it is only necessary that objects referenced by
* fields marked as nonpointers are also reachable via another
* path.)
* 2) Values stored in pointer fields are either not addresses in
* the heap, or they really are pointers. In the latter case, it
* is acceptable to move the object they refer to, and to update
* the pointer.
*
* GC_free may not be invoked on objects allocated with GC_copying_malloc.
*
* No extra space is added to the end of objects allocated through this
* interface. If the client needs to maintain pointers past the
* end, the size should be explicitly padded.
*
* We assume that calls to this will usually be compiler generated.
* Hence the interface is allowed to be a bit ugly in return for speed.
*/
#include "gc_copy_descr.h"
/* GC_copy_descr.h must define */
/* GC_SIZE_FROM_DESCRIPTOR(descr) and */
/* GC_BIT_MAP_FROM_DESCRIPTOR(descr). */
/* It may either be the GC supplied version of the header file, or a */
/* client specific one that derives the information from a client- */
/* specific type descriptor. */
typedef GC_PTR GC_copy_alloc_state;
/* Current allocator state. */
/* Multiple allocation states */
/* may be used for concurrent */
/* allocation, or to enhance */
/* locality. */
/* Should be treated as opaque. */
/* Allocate a memory block of size given in the descriptor, and with */
/* pointer layout given by the descriptor. The resulting block may not */
/* be cleared, and should immediately be initialized by the client. */
/* (A concurrent GC may see an uninitialized pointer field. If it */
/* points outside the nursery, that's fine. If it points inside, it */
/* may retain an object, and be relocated. But that's also fine, since */
/* the new value will be immediately overwritten. */
/* This variant acquires the allocation lock, and uses a default */
/* global allocation state. */
GC_PTR GC_copying_malloc(GC_copy_descriptor);
/* A variant of the above that does no locking on the fast path, */
/* and passes an explicit pointer to an allocation state. */
/* The allocation state is updated. */
/* There will eventually need to be a macro or inline function version */
/* of this. */
GC_PTR GC_copying_malloc2(GC_copy_descriptor, GC_copy_alloc_state *);
/* Initialize an allocation state so that it can be used for */
/* allocation. This implicitly reserves a small section of the */
/* nursery for use with this allocator. */
void GC_init_copy_alloc_state(GC_copy_alloc_state *);
#define GC_DEBUG
#include "gc.h"
#define malloc(n) GC_MALLOC(n)
#define calloc(m,n) GC_MALLOC(m*n)
#define free(p) GC_FREE(p)
#define realloc(p,n) GC_REALLOC(n)
#define CHECK_LEAKS() GC_gcollect()
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment