[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Garbage Collector
I've attached the first cut at the interface for the proposed OOC
garbage
collector and some changes to the existing Kernel.Mod module to support
the garbage collector.
In a multi-threaded environment I don't think it makes sense to have the
memory allocator work in a single address space. For that reason the
current interface may have to change in order to support multiple
address
spaces (as long as we use the primitive malloc as our foundation). Any
thoughts on this. The main change would be to define an AddressSpace
object which would reside in the runtime's address space. This object
would essentially provide all the memory allocation and garbage
collection
services.
Michael Griebling
MODULE GC;
CONST
MarkBit = 31;
TYPE
Block = POINTER TO BlockDesc;
[BlockDesc] = RECORD
END;
[FinObj] = POINTER TO FinObjNode;
[FinObjNode] = RECORD
END;
Finalizer = PROCEDURE (obj: PTR);
Notifier = PROCEDURE;
Queue = RECORD
PROCEDURE (VAR q: Queue) Init;
PROCEDURE (VAR q: Queue) Add (notify: Notifier);
PROCEDURE (VAR q: Queue) Remove (notify: Notifier);
PROCEDURE (VAR q: Queue) Handle;
END;
VAR
GCenabled: BOOLEAN;
afterQ: Queue;
finObjs: FinObj;
gcQ: Queue;
heapBeg: LONGINT;
heapEnd: LONGINT;
prepQ: Queue;
quitQ: Queue;
resumeSP: LONGINT;
PROCEDURE AddStack (beg: LONGINT; end: LONGINT);
PROCEDURE Available (): LONGINT;
PROCEDURE FinalizeAll;
PROCEDURE GC;
PROCEDURE LargestAvailable (): LONGINT;
PROCEDURE Mark (block: Block);
PROCEDURE MarkStack;
PROCEDURE NewArr (eltg: LONGINT; nofelem: LONGINT; nofdim: LONGINT): LONGINT;
PROCEDURE NewRec (tg: LONGINT): LONGINT;
PROCEDURE NewSys (size: LONGINT): LONGINT;
PROCEDURE RegisterObject (obj: PTR; fin: Finalizer);
PROCEDURE RemoveStack (pos: LONGINT);
END GC.
MODULE Kernel [FOREIGN "C";
LINK FILE "Kernel.c" END];
IMPORT
SYSTEM;
TYPE
Name* = POINTER TO ARRAY OF CHAR;
Module* = POINTER TO ModuleDesc;
ModuleDesc* = RECORD
next-: Module;
name-: Name;
key: LONGINT;
tdescs-: LONGINT;
(* additions for GC *)
noftds-: LONGINT; (* number of type descriptors *)
block-: LONGINT; (* ??? *)
SB-: LONGINT; (* module static base address *)
nofptrs-: LONGINT; (* number of pointers in module *)
pointers-: LONGINT; (* pointer list *)
END;
VAR
modules-["_program_modules"]: Module;
END Kernel.