X-Git-Url: http://git.megacz.com/?a=blobdiff_plain;f=ghc%2Finterpreter%2Fstorage.c;h=637c15bc6ca4b9f06eed3f66f2fa55c83a73a17b;hb=9ff75d089614cce1cfa8c88344ace47698258bfa;hp=ee0363bf2e8e7c74c00ec740e4b94665df1fb0ef;hpb=5ae62a561d08c762a84e6c0afd2e0520f772426a;p=ghc-hetmet.git diff --git a/ghc/interpreter/storage.c b/ghc/interpreter/storage.c index ee0363b..637c15b 100644 --- a/ghc/interpreter/storage.c +++ b/ghc/interpreter/storage.c @@ -9,8 +9,8 @@ * included in the distribution. * * $RCSfile: storage.c,v $ - * $Revision: 1.57 $ - * $Date: 2000/03/31 04:13:27 $ + * $Revision: 1.71 $ + * $Date: 2000/04/14 15:18:06 $ * ------------------------------------------------------------------------*/ #include "hugsbasictypes.h" @@ -19,6 +19,7 @@ #include "errors.h" #include "object.h" #include +#include "Stg.h" /*#define DEBUG_SHOWUSE*/ @@ -101,11 +102,11 @@ Cell v; { if (!isPair(v)) { internal("identToStr"); } - switch (fst(v)) { + switch (whatIs(v)) { case VARIDCELL : case VAROPCELL : case CONIDCELL : - case CONOPCELL : return text+textOf(v); + case CONOPCELL : return textToStr(textOf(v)); case QUALIDENT : { String qmod = textToStr(qmodOf(v)); String qtext = textToStr(qtextOf(v)); @@ -469,6 +470,13 @@ Text t; { * tycon, class, instance and module tables. Also, potentially, TREX Exts. * ------------------------------------------------------------------------*/ +#ifdef DEBUG_STORAGE_EXTRA +static Bool debugStorageExtra = TRUE; +#else +static Bool debugStorageExtra = FALSE; +#endif + + #define EXPANDABLE_SYMBOL_TABLE(type_name,struct_name, \ proc_name,free_proc_name, \ free_list,tab_name,tab_size,err_msg, \ @@ -484,9 +492,11 @@ Text t; { assert(TAB_BASE_ADDR <= n); \ assert(n < TAB_BASE_ADDR+tab_size); \ assert(tab_name[n-TAB_BASE_ADDR].inUse); \ - tab_name[n-TAB_BASE_ADDR].inUse = FALSE; \ - /*tab_name[n-TAB_BASE_ADDR].nextFree = free_list; */ \ - /*free_list = n;*/ \ + tab_name[n-TAB_BASE_ADDR].inUse = FALSE; \ + if (!debugStorageExtra) { \ + tab_name[n-TAB_BASE_ADDR].nextFree = free_list; \ + free_list = n; \ + } \ } \ \ type_name proc_name ( void ) \ @@ -514,8 +524,9 @@ Text t; { newTab[i].inUse = FALSE; \ newTab[i].nextFree = i-1+TAB_BASE_ADDR; \ } \ - /* fprintf(stderr, "Expanding " #type_name \ - "table to size %d\n", newSz );*/ \ + if (0 && debugStorageExtra) \ + fprintf(stderr, "Expanding " #type_name \ + "table to size %d\n", newSz ); \ newTab[tab_size].nextFree = TAB_BASE_ADDR-1; \ free_list = newSz-1+TAB_BASE_ADDR; \ tab_size = newSz; \ @@ -613,7 +624,8 @@ struct strModule* generate_module_ref ( Cell mo ) * ------------------------------------------------------------------------*/ #define TYCONHSZ 256 /* Size of Tycon hash table*/ - //#define tHash(x) (((x)-TEXT_BASE_ADDR)%TYCONHSZ)/* Tycon hash function */ +static Tycon tyconHash[TYCONHSZ]; /* Hash table storage */ + static int tHash(Text x) { int r; @@ -625,12 +637,13 @@ static int tHash(Text x) assert(r= 0 && x < TYCONHSZ); return x; } + Tycon newTycon ( Text t ) /* add new tycon to tycon table */ { Int h = tHash(t); @@ -656,7 +669,7 @@ Tycon newTycon ( Text t ) /* add new tycon to tycon table */ Tycon findTycon(t) /* locate Tycon in tycon table */ Text t; { Tycon tc = tyconHash[RC_T(tHash(t))]; -assert(isTycon(tc) || isTuple(tc) || isNull(tc)); + assert(isTycon(tc) || isTuple(tc) || isNull(tc)); while (nonNull(tc) && tycon(tc).text!=t) tc = tycon(tc).nextTyconHash; return tc; @@ -814,7 +827,8 @@ Tycon mkTuple ( Int n ) * ------------------------------------------------------------------------*/ #define NAMEHSZ 256 /* Size of Name hash table */ -//#define nHash(x) (((x)-TEXT_BASE_ADDR)%NAMEHSZ) /* hash fn :: Text->Int */ +static Name nameHash[NAMEHSZ]; /* Hash table storage */ + static int nHash(Text x) { assert(isText(x) || inventedText(x)); @@ -822,12 +836,13 @@ static int nHash(Text x) if (x < 0) x = -x; return x%NAMEHSZ; } -static Name nameHash[NAMEHSZ]; /* Hash table storage */ + int RC_N ( int x ) { assert (x >= 0 && x < NAMEHSZ); return x; } + void hashSanity ( void ) { Int i, j; @@ -860,6 +875,7 @@ Name newName ( Text t, Cell parent ) /* Add new name to name table */ name(nm).arity = 0; name(nm).number = EXECNAME; name(nm).defn = NIL; + name(nm).hasStrict = FALSE; name(nm).stgVar = NIL; name(nm).callconv = NIL; name(nm).type = NIL; @@ -874,8 +890,8 @@ Name newName ( Text t, Cell parent ) /* Add new name to name table */ Name findName(t) /* Locate name in name table */ Text t; { Name n = nameHash[RC_N(nHash(t))]; -assert(isText(t)); -assert(isName(n) || isNull(n)); + assert(isText(t) || isInventedVar(t) || isInventedDictVar(t)); + assert(isName(n) || isNull(n)); while (nonNull(n) && name(n).text!=t) n = name(n).nextNameHash; return n; @@ -1034,7 +1050,7 @@ Tycon addTupleTycon ( Int n ) if (combined) m = findFakeModule(findText(n==0 ? "PrelBase" : "PrelTup")); else - m = findModule(findText("Prelude")); + m = findModule(findText("PrelPrim")); setCurrModule(m); k = STAR; @@ -1517,6 +1533,15 @@ List getAllKnownTyconsAndClasses ( void ) return xs; } +Int numQualifiers ( Type t ) +{ + if (isPolyType(t)) t = monotypeOf(t); + if (isQualType(t)) + return length ( fst(snd(t)) ); else + return 0; +} + + /* Purely for debugging. */ void locateSymbolByName ( Text t ) { @@ -1591,7 +1616,7 @@ Module newModule ( Text t ) /* add new module to module table */ module(mod).completed = FALSE; module(mod).lastStamp = 0; /* ???? */ - module(mod).fromSrc = TRUE; + module(mod).mode = NIL; module(mod).srcExt = findText(""); module(mod).uses = NIL; @@ -1604,13 +1629,27 @@ Module newModule ( Text t ) /* add new module to module table */ return mod; } + +Bool nukeModule_needs_major_gc = TRUE; + void nukeModule ( Module m ) { ObjectCode* oc; ObjectCode* oc2; Int i; -assert(isModule(m)); -/*fprintf(stderr, "NUKEMODULE `%s'\n", textToStr(module(m).text)); */ + + if (!isModule(m)) internal("nukeModule"); + + /* fprintf ( stderr, "NUKE MODULE %s\n", textToStr(module(m).text) ); */ + + /* see comment in compiler.c about this, + and interaction with info tables */ + if (nukeModule_needs_major_gc) { + /* fprintf ( stderr, "doing major GC in nukeModule\n"); */ + /* performMajorGC(); */ + nukeModule_needs_major_gc = FALSE; + } + oc = module(m).object; while (oc) { oc2 = oc->next; @@ -1626,14 +1665,20 @@ assert(isModule(m)); for (i = NAME_BASE_ADDR; i < NAME_BASE_ADDR+tabNameSz; i++) if (tabName[i-NAME_BASE_ADDR].inUse && name(i).mod == m) { - if (name(i).itbl) free(name(i).itbl); + if (name(i).itbl && + module(name(i).mod).mode == FM_SOURCE) { + free(name(i).itbl); + } name(i).itbl = NULL; freeName(i); } for (i = TYCON_BASE_ADDR; i < TYCON_BASE_ADDR+tabTyconSz; i++) if (tabTycon[i-TYCON_BASE_ADDR].inUse && tycon(i).mod == m) { - if (tycon(i).itbl) free(tycon(i).itbl); + if (tycon(i).itbl && + module(tycon(i).mod).mode == FM_SOURCE) { + free(tycon(i).itbl); + } tycon(i).itbl = NULL; freeTycon(i); } @@ -1718,7 +1763,7 @@ Void setCurrModule(m) /* set lookup tables for current module */ Module m; { Int i; assert(isModule(m)); - /* fprintf(stderr, "SET CURR MODULE %s %d\n", textToStr(module(m).text),m);*/ + /* fprintf(stderr, "SET CURR MODULE %s %d\n", textToStr(module(m).text),m); */ {List t; for (t = module(m).names; nonNull(t); t=tl(t)) assert(isName(hd(t))); @@ -1804,6 +1849,31 @@ void* lookupOExtraTabName ( char* sym ) } +/* Only call this if in dire straits; searches every object symtab + in the system -- so is therefore slow. +*/ +void* lookupOTabNameAbsolutelyEverywhere ( char* sym ) +{ + ObjectCode* oc; + Module m; + void* ad; + for (m = MODULE_BASE_ADDR; + m < MODULE_BASE_ADDR+tabModuleSz; m++) { + if (tabModule[m-MODULE_BASE_ADDR].inUse) { + if (module(m).object) { + ad = ocLookupSym ( module(m).object, sym ); + if (ad) return ad; + } + for (oc = module(m).objectExtras; oc; oc=oc->next) { + ad = ocLookupSym ( oc, sym ); + if (ad) return ad; + } + } + } + return NULL; +} + + OSectionKind lookupSection ( void* ad ) { int i; @@ -1843,12 +1913,8 @@ OSectionKind lookupSection ( void* ad ) Int heapSize = DEFAULTHEAP; /* number of cells in heap */ Heap heapFst; /* array of fst component of pairs */ Heap heapSnd; /* array of snd component of pairs */ -#ifndef GLOBALfst Heap heapTopFst; -#endif -#ifndef GLOBALsnd Heap heapTopSnd; -#endif Bool consGC = TRUE; /* Set to FALSE to turn off gc from*/ /* C stack; use with extreme care! */ Long numCells; @@ -1901,7 +1967,6 @@ static Int markCount, stackRoots; Cell pair(l,r) /* Allocate pair (l, r) from */ Cell l, r; { /* heap, garbage collecting first */ Cell c = freeList; /* if necessary ... */ - if (isNull(c)) { lsave = l; rsave = r; @@ -1922,77 +1987,40 @@ Cell l, r; { /* heap, garbage collecting first */ static Int *marks; static Int marksSize; -Cell markExpr(c) /* External interface to markCell */ -Cell c; { - return isGenPair(c) ? markCell(c) : c; -} - -static Cell local markCell(c) /* Traverse part of graph marking */ -Cell c; { /* cells reachable from given root */ - /* markCell(c) is only called if c */ - /* is a pair */ - { register int place = placeInSet(c); - register int mask = maskInSet(c); - if (marks[place]&mask) - return c; - else { - marks[place] |= mask; - recordMark(); - } - } - - /* STACK_CHECK: Avoid stack overflows during recursive marking. */ - if (isGenPair(fst(c))) { - STACK_CHECK - fst(c) = markCell(fst(c)); - markSnd(c); - } - else if (isNull(fst(c)) || isTagPtr(fst(c))) { - STACK_CHECK - markSnd(c); - } - - return c; -} - -static Void local markSnd(c) /* Variant of markCell used to */ -Cell c; { /* update snd component of cell */ - Cell t; /* using tail recursion */ +void mark ( Cell root ) +{ + Cell c; + Cell mstack[NUM_MSTACK]; + Int msp = -1; + Int msp_max = -1; -ma: t = c; /* Keep pointer to original pair */ - c = snd(c); - if (!isPair(c)) - return; + mstack[++msp] = root; - { register int place = placeInSet(c); - register int mask = maskInSet(c); - if (marks[place]&mask) - return; - else { + while (msp >= 0) { + if (msp > msp_max) msp_max = msp; + c = mstack[msp--]; + if (!isGenPair(c)) continue; + if (fst(c)==FREECELL) continue; + { + register int place = placeInSet(c); + register int mask = maskInSet(c); + if (!(marks[place]&mask)) { marks[place] |= mask; - recordMark(); - } - } - - if (isGenPair(fst(c))) { - fst(c) = markCell(fst(c)); - goto ma; - } - else if (isNull(fst(c)) || isTagPtr(fst(c))) - goto ma; - return; -} - -Void markWithoutMove(n) /* Garbage collect cell at n, as if*/ -Cell n; { /* it was a cell ref, but don't */ - /* move cell so we don't have */ - /* to modify the stored value of n */ - if (isGenPair(n)) { - recordStackRoot(); - markCell(n); - } + if (msp >= NUM_MSTACK-5) { + fprintf ( stderr, + "hugs: fatal stack overflow during GC. " + "Increase NUM_MSTACK.\n" ); + exit(9); + } + mstack[++msp] = fst(c); + mstack[++msp] = snd(c); + } + } + } + // fprintf(stderr, "%d ",msp_max); } + Void garbageCollect() { /* Run garbage collector ... */ /* disable break checking */ Int i,j; @@ -2002,11 +2030,11 @@ Void garbageCollect() { /* Run garbage collector ... */ jmp_buf regs; /* save registers on stack */ HugsBreakAction oldBrk = setBreakAction ( HugsIgnoreBreak ); -fprintf ( stderr, "wa-hey! garbage collection! too difficult! bye!\n" ); -exit(0); + setjmp(regs); gcStarted(); + for (i=0; i