home *** CD-ROM | disk | FTP | other *** search
- /*
- * @(#)gc.c 1.7 4/5/89
- */
-
- /* Copyright 1986 Eric Jul. May not be used for any purpose without */
- /* written permission from the author. */
- /* The Emerald kernel for the Emerald programming language. */
-
- /* Version 1.0 started 1986-12-06, eric */
-
- /* This file contains the implementation of the Emerald kernel garbage */
- /* collector */
-
- #include <stdio.h>
-
- #include "Kernel/h/system.h"
- #include "Kernel/h/assert.h"
- #include "Kernel/h/macros.h"
- #include "Kernel/h/errMsgs.h"
- #include "Kernel/h/emTypes.h"
- #include "Kernel/h/kmdTypes.h"
- #include "Kernel/h/kEvents.h"
- #include "Kernel/h/emkDefs.h"
- #include "Kernel/h/hotsTypes.h"
- #include "Kernel/h/map.h"
- #include "Kernel/h/set.h"
- #include "Kernel/h/utils.h"
- #include "Kernel/h/builtins.h"
-
- extern EmLocation thisNodeLocation;
-
- /**********************************************************************/
- /* GC */
- /**********************************************************************/
-
- #ifdef RICEGC
- /* Snapshot */
- void GC()
- {
- extern int ok_to_expand;
- KMDPrint("Garbage Collection, starting\n");
- ok_to_expand = 0;
- gcollect();
- ok_to_expand = 1;
- KMDPrint("Garbage Collection, done\n");
- }
- #else RICEGC
- /* Snapshot */
- void GC()
- {
- KMDPrint("Garbage Collection not implemented\n");
- }
-
- #endif RICEGC
- extern int OTSize;
-
- #ifdef RICEGC
-
- /*
- * Go through the object table, Xoring all references with -1.
- */
- gc_before()
- {
- register ODP *p, *limit;
- register OID id;
- ODTag tag;
- KMDTrace("GC", 1, "GC starting\n");
- for (p = &OT[0], limit = &OT[OTSize]; p < limit; p++) {
- if (!*p) continue;
- tag = (*p)->G.tag;
- id = (*p)->G.ownOID;
- if (tag.tag == CodeODTag) {
- KMDTrace("GC", 5, "Not Xoring Code ODP 0x%X OID 0x%X\n", *p, id);
- continue;
- }
- if (tag.xref) {
- KMDTrace("GC", 5, "Not Xoring externally referenced ODP 0x%X OID 0x%X\n", *p, id);
- continue;
- }
- if (id >= (unsigned)BUILTINOBJECTBASE &&
- id <= (unsigned)(INSTCTOFBUILTINOBJECTBASE+0x20)) {
- KMDTrace("GC", 5, "Not Xoring 0x%X OID 0x%X\n", *p, id);
- continue;
- }
- KMDTrace("GC", 3, "Xoring 0x%X OID 0x%X\n", *p, id);
- *(int *)p ^= (-1);
- }
- }
-
- extern int nOT;
- #define OTDelete(P) { (*(P)) = (ODP) -1; nOT--; }
-
- /*
- * Go through the object table, and for each non referencable object,
- * delete it from the OT.
- */
- gc_during()
- {
- register ODP *p, *limit;
- register int isreachable;
- extern void OTFinishDelete();
- for (p = &OT[0], limit = &OT[OTSize]; p < limit; p++) {
- if (!((int)*p & 0x80000000)) continue;
- *(int *)p ^= (-1);
- KMDTrace("GC", 5, "Checking 0x%X OID 0x%X\n", *p, (*p)->G.ownOID);
- isreachable = gc_ismarked(*p);
- KMDTrace("GC", 3, "0x%X OID 0x%X is %sreachable\n", *p, (*p)->G.ownOID,
- isreachable?"":"not ");
- if (!isreachable) OTDelete(p);
- }
- OTFinishDelete();
- }
-
- gc_after()
- {
- KMDTrace("GC", 1, "GC Done\n");
- }
-
- struct pcs {
- int (*pc[5])();
- };
-
- #ifdef DEBUGGC
- gc_each(b, p)
- ODP b;
- struct pcs p;
- {
- char *PPCodePtr(), *PPODTag();
- if (!ok_to_expand) {
- /* during a snapshot */
- if (b->G.tag.otherstuff == OBSCUREVALUE) {
- if (b->G.tag.tag == GODataTag || b->G.tag.tag == LOTag) {
- KMDPrint("freed %x tag %s %s\n",
- b,
- PPODTag(b->G.tag),
- PPCodePtr(((LODataPtr)b)->myCodePtr));
- } else if(b->G.tag.tag == GODTag) {
- KMDPrint("freed %x tag %s id %x dataPtr %x %s\n",
- b,
- PPODTag(b->G.tag),
- b->G.ownOID,
- b->G.dataPtr,
- b->G.dataPtr == 0 || b->G.dataPtr == EMNIL ? "" : PPCodePtr(b->G.dataPtr->myCodePtr));
- }
-
- }
- }
- }
- #endif DEBUGGC
-
- #endif RICEGC
-
- /**********************************************************************/
- /* GCInit */
- /**********************************************************************/
- void GCInit()
- {
- #ifdef RICEGC
- #ifdef DEBUGGC
- gc_init(gc_before, gc_during, gc_after, gc_each);
- #else
- gc_init(gc_before, gc_during, gc_after, 0);
- #endif DEBUGGC
- expand_hp((1024 - 64) / 4);
- #endif RICEGC
- KMDSetSnap(GC);
- KMDSetTrace(GC);
- }
-
- /* Copyright 1986 Eric Jul */
-