/* * GC.h -- stubbed PCR; based on Mike Agostino's pseudo-PCR */ #ifndef _P_GC_H #define _P_GC_H #include "BasicTypes.h" #include "Threads.h" #include "../gc/gc.h" /* * Finalizable Object structures and Finalization Queues: */ typedef struct XR_FinalizationQueueStructure { struct XR_FinalizableObjectStructure * head; struct XR_FinalizableObjectStructure * tail; struct XR_CVRep fqNonempty; } * XR_FinalizationQueue; typedef struct XR_FinalizableObjectStructure { unsigned long firstword; unsigned long secondword; XR_FinalizationQueue associatedFQ; struct XR_FinalizableObjectStructure *next; } * XR_FinalizationHandle; extern XR_FinalizationHandle GC_finalizeListHead; #define XR_IsDisguised(h) ((h)->secondword != 0) #define XR_FetchFromDisguised(h) ( ((h)->firstword) | ((h)->secondword << 16) ) #define XR_FetchFromUndisguised(h) ( (h)->firstword ) #define XR_StoreDisguised(w,h) { \ (h)->firstword = ((unsigned long)(w)) & 0xffff; \ (h)->secondword = (((unsigned long)(w)) >> 16) & 0xffff; \ } #define XR_StoreUndisguised(w,h) { \ (h)->firstword = ((unsigned long)(w)); \ (h)->secondword = 0; \ } typedef enum { fzsEnabled = 0, fzsOnFQ = 1, fzsDisabled = 2, fzsError = 0x7fffffff /* force to 32 bits */ } XR_FinalizationState; /* extern XR_Pointer GC_malloc(unsigned ObjectSizeInBytes); */ /* Allocates a new object of at least the specified length. The object is cleared. It will be aligned on at least a 4 byte boundary. If the architecture requires n byte alignment for certain objects, then it will be n byte aligned unless the requested size is less than n. If the requested size is a multiple of n, where n is a power of 2 no larger than 16, then the object will also be n byte aligned. No space is implicitly reserved for type tags or the like. Returns (XR_Pointer)0 if no memory is available. */ /* extern XR_Pointer GC_malloc_atomic(unsigned ObjectSizeInBytes); */ /* Identical to GC_malloc, except that the object is assumed to contain no pointers, amd the object is not cleared. Is faster than, and results in faster collections than GC_malloc. */ extern unsigned XR_GCHeapSize(); /* Size in bytes of garbage collected heap. */ extern unsigned XR_GCTotalByteCount(); /* Number of bytes allocated since the beginning of the world. */ /* This style of finalization cannot really be supported here. * The implementations look real, except that nothing ever gets finalized. */ extern XR_FinalizationState XR_DisableFinalization(/* XR_FinalizationHandle h */); /* Disable the object described by 'h' for finalization. Return its prior XR_FinalizationState. If it is already on a finalize q, remote it. */ extern XR_FinalizationState XR_ReenableFinalization(/* XR_FinalizationHandle h;XR_FinalizationQueue fq */); /* Causes an object which was once finalizable to be so again, now on queue 'fq'. If it is on some other queue, it is removed first. Prior state is returned. */ extern void XR_EnableFinalization(/* XR_Pointer object; XR_FinalizationQueue fq; XR_FinalizationHandle h */); /* Cause the object to be enabled for finalization. 'h' is updated to describe the object. When the time comes, fq will be the finalization queue on which the object is placed. */ extern bool XR_FQEmpty(/* XR_FinalizationQueue fq */); extern XR_FinalizationHandle XR_NewFinalizationHandle(); /* return a new, empty, initialized handle for an object to be finalized. */ extern XR_FinalizationHandle XR_FQNextNoAbort(/* XR_FinalizationQueue fq */); /* return the next handle on queue 'fq', waiting on a condition variable until there is an item if necessary. If there is no item, or the wait is interrupted, return NIL */ extern XR_FinalizationState XR_GetFinalizationState(/* XR_FinalizationHandle h */); /* get the finalization state of the object */ extern XR_Pointer XR_HandleToObject(/* XR_FinalizationHandle h */); /* Get the pointer to the real object, given its handle */ extern XR_FinalizationQueue XR_NewFQ(); /* return a new, empty, initialized finalization queue. */ extern void XR_GCollect(); /* initiate a garbage collection. */ #endif _P_GC_H