Main Page   Modules   Compound List   File List   Compound Members   File Members  

gc.c File Reference

Jaune - Ahead of time Java compiler for small systems. More...

#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)


Detailed Description

Jaune - Ahead of time Java compiler for small systems.

Author:
Copyright Michael Hope 2002 <michaelh@juju.net.nz> This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public License as published by the Free Software Foundation; either version 2.1 of the License, or (at your option) any later version.
Id:
gc.c,v 1.1.1.1 2002/04/23 03:42:57 michaelh Exp


Enumeration Type Documentation

anonymous enum
 

Enumeration values:
HEAPMAGIC  Magic number used in HeapEntry.uMagic.
USEDFLAG  Flag used to mark an entry as used.
TRACEINITIALSIZE  Initial size of the alloc trace.
TRACEGROWTHSTEP  Increment used in growing the alloc trace.

anonymous enum
 

Flags for the garbage collector.

Enumeration values:
FLAGMARKED  Marks a heap entry as marked as in it can be reached from the root set.
FLAGSCANNED  Marks a heap entry as scanned as in it has been searched by the GC system for references to other objects.


Function Documentation

void* __Alloc UINT    uSize
 

Attempt to allocate a block of memory out of the heap, returning NULL if there is insufficent space.

Does not zero the memory.

STATIC void _checkIntegrity void   
 

Scans the heap and verifies that it is consistent.

Checks:

  • The next and prev pointers are consistent.
  • If the block is free, the next ptr and size match up.
  • The number of allocated blocks matches the recorded number.

void Free void *    p
 

Frees a previousally allocated block.

Will fail if the passed in pointer is invalid.

UINT GetAvailableHeap void   
 

Returns a rough estimate of the available heap space.

Returns the sum of all free space, which may not be contigious and allocatable.

void* GrowAlloc void *    p,
UINT    uNewSize
 

Grows the previousally allocated buffer, copying if the block can't be grown in place.

Zeros the new area.

Parameters:
p  Base of the current block. If null, equvalient to Alloc()

void InitHeap void *    pBase,
UINT    uSize
 

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.

UINT RunGarbageCollectorInt void **    pRoot,
UINT    nInRoot,
void **    pStatic,
UINT    nInStatic
 

Runs the garbage collector using the given data as the root set.

Returns the number of blocks that were returned to the free pool.


Variable Documentation

UINT16 uAlloced
 

Total number of allocated blocks.

Used by the GC to save computing the size of the GC state block.


Generated on Sat May 11 15:15:41 2002 for JauneRuntimeclib by doxygen1.2.14 written by Dimitri van Heesch, © 1997-2002