#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gc.h"
Compounds | |
struct | _HeapEntry |
Header that appears at the start of each alloced or unallocated block in the heap. More... | |
struct | _HeapEntryState |
Entry used during garbage collection that tracks the state of a heap entry and is used for searching when finding if a number is a heap pointer. More... | |
Defines | |
#define | DEBUGMODE 1 |
If set will enable many internal consistency checks. | |
#define | PROFILEMODE 0 |
If set will enable the profiling code and alternative heap reverse lookup algorithims. | |
#define | INLINE |
#define | STATIC |
#define | TRACE(_a) |
#define | TRACE1(_a) |
#define | CHECKINTEGRITY() _checkIntegrity() |
#define | CHECKSORTED(_a, _b) |
#define | HEAPASSERT(_a, _msg) if (!(_a)) { DumpHeapState(); _cassert(_msg " at " __FILE__ ":", __LINE__); } |
#define | SETMAGIC(_a) (_a)->uMagic = HEAPMAGIC |
#define | VERIFYMAGIC(_a) HEAPASSERT((_a)->uMagic == HEAPMAGIC, "Invalid heap object") |
#define | IFPROFILE(_a) |
#define | ISUSED(pEnt) (pEnt->uSize & USEDFLAG) |
Returns TRUE if this block is used. | |
Typedefs | |
typedef _HeapEntry | HeapEntry |
typedef _HeapEntryState | HeapEntryState |
Entry used during garbage collection that tracks the state of a heap entry and is used for searching when finding if a number is a heap pointer. | |
Enumerations | |
enum | { HEAPMAGIC = 0xBEEF, USEDFLAG = 1, TRACEINITIALSIZE = 40, TRACEGROWTHSTEP = 20 } |
enum | { FLAGMARKED = 1, FLAGSCANNED = 2 } |
Flags for the garbage collector. More... | |
Functions | |
STATIC INLINE UINT16 | _getSize (HeapEntry *pEnt) |
Returns the size in bytes of this block. | |
void | SetupGarbageCollector (UINT16 *pTopOfStack, void **pStatics, UINT nInStatics) |
STATIC void | _checkIntegrity (void) |
Scans the heap and verifies that it is consistent. More... | |
void | InitHeap (void *pBase, UINT uSize) |
Initialise the heap to use the given memory block. More... | |
void * | __Alloc (UINT uSize) |
Attempt to allocate a block of memory out of the heap, returning NULL if there is insufficent space. More... | |
void | Free (void *p) |
Frees a previousally allocated block. More... | |
UINT | GetAvailableHeap (void) |
Returns a rough estimate of the available heap space. More... | |
void * | GrowAlloc (void *p, UINT uSize) |
Grows the previousally allocated buffer, copying if the block can't be grown in place. More... | |
void | DumpHeapState (void) |
Dumps the heap state to stdout. | |
void | DumpHeapStats (void) |
Dumps the heap statistics to stdout. | |
STATIC void | _checkSorted (HeapEntryState *pEntries, UINT nEntries) |
STATIC void * | _getBase (HeapEntryState *pStates, int iOff) |
STATIC HeapEntryState * | _getHeapEntryState (void *p, HeapEntryState *pStates, UINT nStateEntries) |
void | _mark (void *p, HeapEntryState *pStates, UINT nStateEntries) |
STATIC void | _scanArea (void **pScan, UINT nToScan, HeapEntryState *pStates, UINT nStateEntries) |
void | _scanReferenceArray (Array *pArray, HeapEntryState *pStates, UINT nStateEntries) |
void | _scanInstance (Instance *pIns, HeapEntryState *pStates, UINT nStateEntries) |
void | _scanStringBuffer (StringBuffer *pSB, HeapEntryState *pStates, UINT nStateEntries) |
void | _scanHeap (HeapEntryState *pStates, UINT nStateEntries) |
UINT | RunGarbageCollector (void) |
UINT | RunGarbageCollectorInt (void **pRoot, UINT nInRoot, void **pStatic, UINT nInStatic) |
Runs the garbage collector using the given data as the root set. More... | |
void | HeapSetSearchMode (UINT u) |
|
|
|
Flags for the garbage collector.
|
|
Attempt to allocate a block of memory out of the heap, returning NULL if there is insufficent space. Does not zero the memory. |
|
Scans the heap and verifies that it is consistent. Checks:
|
|
Frees a previousally allocated block. Will fail if the passed in pointer is invalid. |
|
Returns a rough estimate of the available heap space. Returns the sum of all free space, which may not be contigious and allocatable. |
|
Grows the previousally allocated buffer, copying if the block can't be grown in place. Zeros the new area.
|
|
Initialise the heap to use the given memory block. Completely resets the heap. Note that the total free space will be less than that fed in due to the headers. |
|
Runs the garbage collector using the given data as the root set. Returns the number of blocks that were returned to the free pool. |
|
Total number of allocated blocks. Used by the GC to save computing the size of the GC state block. |