[project @ 1996-07-25 20:43:49 by partain]
[ghc-hetmet.git] / ghc / runtime / main / StgUpdate.lhc
index 904f637..04d2a5c 100644 (file)
@@ -7,10 +7,6 @@
 This code is required by the update interface which sits on top of the
 storage manager interface (See \tr{SMupdate.lh}).
 
-Some of this stuff has been separated (correctly!) into StgThreads.lhc
-for version 0.23.  Could someone (Hans?) bring us up to date, please!
-KH.
-
 \begin{itemize}
 \item Indirection entry code and info table.
 \item Black Hole entry code and info table.
@@ -31,11 +27,10 @@ System-wide constants need to be included:
 #endif
 #endif
 
-EXTDATA(Nil_closure);
+EXTDATA(Prelude_Z91Z93_closure);
 
-#if defined(DO_REDN_COUNTING)
-extern void PrintRednCountInfo(STG_NO_ARGS);
-extern I_   showRednCountStats;
+#if defined(TICKY_TICKY)
+void PrintTickyInfo(STG_NO_ARGS);
 #endif
 \end{code}
 
@@ -51,7 +46,6 @@ STGFUN(Ind_entry)
 {
     FB_
     ENT_IND(Node);     /* Ticky-ticky profiling info */
-    SET_ACTIVITY(ACT_INDIRECT); /* SPAT profiling */
 
     Node = (P_) IND_CLOSURE_PTR((P_) Node);
     ENT_VIA_NODE();
@@ -61,7 +55,6 @@ STGFUN(Ind_entry)
 }
 
 IND_ITBL(Ind_info,Ind_entry,const,EF_);
-
 \end{code}
 
 We also need a special @CAF@ indirection info table which is used to
@@ -71,7 +64,6 @@ STGFUN(Caf_entry)     /* same as Ind_entry */
 {
     FB_
     ENT_IND(Node);
-    SET_ACTIVITY(ACT_INDIRECT); /* SPAT profiling */
 
     Node = (P_) IND_CLOSURE_PTR((P_) Node);
     ENT_VIA_NODE();
@@ -102,8 +94,8 @@ EXTFUN(EnterNodeCode);
 EXTFUN(StackUnderflowEnterNode);
 EXTDATA_RO(BQ_info);
 #else
-extern StgStablePtr errorHandler;
-extern void raiseError PROTO((StgStablePtr));
+void raiseError PROTO((StgStablePtr));
+extern StgStablePtr errorHandler; /* NB: prone to magic-value-ery (WDP 95/12) */
 #endif
 
 STGFUN(BH_UPD_entry)
@@ -113,16 +105,16 @@ STGFUN(BH_UPD_entry)
     (void) STGCALL1(int,(void *, FILE *),fflush,stdout);
     (void) STGCALL2(int,(),fprintf,stderr,"Entered a `black hole': the program has a cyclic data dependency.\n");
 
-# if defined(USE_COST_CENTRES)
+# if defined(PROFILING)
     {
        CostCentre cc = (CostCentre) CC_HDR(Node);
        (void) STGCALL5(int,(),fprintf,stderr,"Cost Centre: %s  Module: %s  Group %s\n",cc->label, cc->module, cc->group);
     }
 # endif    
 
-# if defined(DO_REDN_COUNTING)
-    if (showRednCountStats) {
-       (void) STGCALL0(void,(),PrintRednCountInfo);
+# if defined(TICKY_TICKY)
+    if (RTSflags.TickyFlags.showTickyStats) {
+       (void) STGCALL0(void,(),PrintTickyInfo);
     }
 # endif
 
@@ -134,15 +126,16 @@ STGFUN(BH_UPD_entry)
     FB_
 
 # if 0
-    if ( debug & 0x80 ) 
+    if ( RTSflags.GranFlags.debug & 0x80 ) 
       (void) STGCALL4(int,(),fprintf,stderr,"GRAN_CHECK in BH_UPD_entry: Entered a `black hole' @ 0x%x (CurrentTSO @ 0x%x\n ",Node,CurrentTSO);
-#endif
+# endif
 
 # if defined(GRAN)
-    STGCALL0(void,(),GranSimBlock);    /* Do this before losing its TSO_LINK */
+    /* Do this before losing its TSO_LINK */
+    STGCALL3(void,(),GranSimBlock,CurrentTSO,CurrentProc,Node);        
 # endif
 
-    TSO_LINK(CurrentTSO) = Nil_closure;
+    TSO_LINK(CurrentTSO) = Prelude_Z91Z93_closure;
     SET_INFO_PTR(Node, BQ_info);
     BQ_ENTRIES(Node) = (W_) CurrentTSO;
 
@@ -166,7 +159,7 @@ STGFUN(BH_UPD_entry)
     }
 
 # ifdef PAR
-    if(do_gr_profile) {
+    if(RTSflags.ParFlags.granSimStats) {
        TIME now = CURRENT_TIME;
         TSO_EXECTIME(CurrentTSO) += now - TSO_BLOCKEDAT(CurrentTSO);
         TSO_BLOCKCOUNT(CurrentTSO)++;
@@ -177,13 +170,14 @@ STGFUN(BH_UPD_entry)
 # endif
 
 # if defined(GRAN)
-    /* CurrentTSO = Nil_closure; */
-    ReSchedule(NEW_THREAD);
+    /* CurrentTSO = Prelude_Z91Z93_closure; */
+    ReSchedule(SAME_THREAD);
 # else
     ReSchedule(0);
 # endif
 
     FE_
+
 #endif /* threads */
 }
 
@@ -197,16 +191,16 @@ STGFUN(BH_SINGLE_entry)
     (void) STGCALL2(int,(),fprintf,stderr,"either the compiler made a mistake on single-entryness,\n");
     (void) STGCALL2(int,(),fprintf,stderr,"or the program has a cyclic data dependency.\n");
 
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
     {
        CostCentre cc = (CostCentre) CC_HDR(Node);
        (void) STGCALL5(int,(),fprintf,stderr, "Cost Centre: %s  Module: %s  Group %s\n",cc->label, cc->module, cc->group);
     }
 #endif    
 
-# if defined(DO_REDN_COUNTING)
-    if (showRednCountStats) {
-       (void) STGCALL0(void,(),PrintRednCountInfo);
+# if defined(TICKY_TICKY)
+    if (RTSflags.TickyFlags.showTickyStats) {
+       (void) STGCALL0(void,(),PrintTickyInfo);
     }
 # endif
 
@@ -303,27 +297,27 @@ vtbl_StdUpdFrame[] = {
 %*                                                                     *
 %************************************************************************
 
-Here is the standard update code for objects that are returned in the heap
-(or those which are initially returned in registers, but have already been
-allocated in the heap earlier in the update chain.)  In either case, Node
-points to the heap object.  The update code grabs the address of the updatee
-out of the partial update frame (the return address has already been popped),
-makes the updatee an indirection to Node, and returns according to the convention
-for the constructor.
+Here is the standard update code for objects that are returned in the
+heap (or those which are initially returned in registers, but have
+already been allocated in the heap earlier in the update chain).  In
+either case, @Node@ points to the heap object.  The update code grabs
+the address of the updatee out of the partial update frame (the return
+address has already been popped), makes the updatee an indirection to
+@Node@, and returns according to the convention for the constructor.
 
 \begin{code}
-#define IND_UPD_TEMPLATE(label, retvector)                                     \
-  STGFUN(label)                                                                \
-  {                                                                            \
-    FB_                                                                                \
-    UPD_EXISTING();                    /* Ticky-ticky profiling info */        \
-    /* Update thing off stk with an indirection to Node */                     \
-    UPD_IND(GRAB_UPDATEE(SpB), Node);                                          \
-    /* Pop the standard update frame */                                         \
-    POP_STD_UPD_FRAME()                                                                \
-                                                                               \
-    JMP_(retvector);                                                           \
-    FE_                                                                        \
+#define IND_UPD_TEMPLATE(label, retvector)                     \
+  STGFUN(label)                                                \
+  {                                                            \
+    FB_                                                                \
+    UPD_EXISTING();    /* Ticky-ticky profiling info */        \
+    /* Update thing off stk with an indirection to Node */     \
+    UPD_IND(GRAB_UPDATEE(SpB), Node);                           \
+    /* Pop the standard update frame */                         \
+    POP_STD_UPD_FRAME()                                                \
+                                                               \
+    JMP_(retvector);                                           \
+    FE_                                                        \
   }
 
 IND_UPD_TEMPLATE(IndUpdRetDir, DIRECT(((P_)RetReg)))
@@ -335,7 +329,6 @@ IND_UPD_TEMPLATE(IndUpdRetV4, ((P_)RetReg)[RVREL(4)])
 IND_UPD_TEMPLATE(IndUpdRetV5, ((P_)RetReg)[RVREL(5)])
 IND_UPD_TEMPLATE(IndUpdRetV6, ((P_)RetReg)[RVREL(6)])
 IND_UPD_TEMPLATE(IndUpdRetV7, ((P_)RetReg)[RVREL(7)])
-
 \end{code}
 
 %************************************************************************
@@ -385,8 +378,12 @@ the cost centre when entered. The heap profiler ignores the space
 occupied by it as it would not reside in the heap during normal
 execution.
 
+In ticky-land: If we are trying to collect update-entry counts
+(controlled by an RTS flag), then we must use permanent indirections
+(the shorting-out of regular indirections loses the counts).
+
 \begin{code}
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING) || defined(TICKY_TICKY)
 
 STGFUN(Perm_Ind_entry)
 {
@@ -394,25 +391,24 @@ STGFUN(Perm_Ind_entry)
 
     /* Don't add INDs to granularity cost */
 
-    ENT_IND(Node);     /* Ticky-ticky profiling info */
+    /* Dont: ENT_IND(Node); for ticky-ticky; this ind is here only to help profiling */
 
     /* Enter PAP cost centre -- lexical scoping only */
     ENTER_CC_PAP_CL(Node);
 
     Node = (P_) IND_CLOSURE_PTR((P_) Node);
-    ENT_VIA_NODE();    /* Ticky-ticky profiling info */
+
+    /* Dont: ENT_VIA_NODE(); for ticky-ticky; as above */
 
     InfoPtr=(D_)(INFO_PTR(Node));
-# if defined(GRAN)
-    GRAN_EXEC(1,1,2,0,0);
-# endif
+
     JMP_(ENTRY_CODE(InfoPtr));
     FE_
 }
 
 PERM_IND_ITBL(Perm_Ind_info,Perm_Ind_entry,const,EF_);
 
-#endif /* USE_COST_CENTRES */
+#endif /* PROFILING or TICKY */
 \end{code}
 
 %************************************************************************
@@ -443,7 +439,6 @@ stack chunk.
 \end{itemize}
 
 \begin{code}
-
 STGFUN(UpdatePAP)
 {
     /* 
@@ -455,7 +450,7 @@ STGFUN(UpdatePAP)
 #define NPtrWords      (R3.i)
 #define NArgWords      (R4.i)
 #define PapSize                (R5.i)
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
 # define CC_pap        ((CostCentre)(R7.p))
 #endif
 
@@ -468,12 +463,10 @@ STGFUN(UpdatePAP)
 
     FB_
 
-#if defined(COUNT)
+#if defined(GRAN_COUNT)
       ++nPAPs;
 #endif
 
-    SET_ACTIVITY(ACT_UPDATE_PAP);   /* SPAT profiling */
-
     NPtrWords    = AREL(SuA - SpA);
     NNonPtrWords = BREL(SuB - SpB);
 
@@ -482,11 +475,11 @@ STGFUN(UpdatePAP)
 
     NArgWords = NPtrWords + NNonPtrWords + 1;  /* +1 for Node */
 
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
       /* set "CC_pap" to go in the updatee (see Sansom thesis, p 183) */
 
     CC_pap /*really cc_enter*/ = (CostCentre) CC_HDR(Node);
-    if (IS_SUBSUMED_CC(CC_pap) /*really cc_enter*/)
+    if (IS_CAF_OR_DICT_OR_SUB_CC(CC_pap) /*really cc_enter*/)
        CC_pap = CCC;
 #endif
 
@@ -516,8 +509,6 @@ STGFUN(UpdatePAP)
        /* Allocate PapClosure -- Only Node (R1) is live */
        HEAP_CHK(LIVENESS_R1, PapSize, 0);
 
-       SET_ACTIVITY(ACT_UPDATE_PAP);   /* back to it (for SPAT profiling) */
-    
        PapClosure = Hp + 1 - PapSize;  /* The new PapClosure */
 
        SET_DYN_HDR(PapClosure, PAP_info, CC_pap, NArgWords + DYN_VHS, NPtrWords + 1);
@@ -526,13 +517,14 @@ STGFUN(UpdatePAP)
 
        p = Hp;
         for (i = NNonPtrWords - 1; i >= 0; i--) *p-- = (W_) SpB[BREL(i)];
-        for (i = NPtrWords - 1; i >= 0; i--)    *p-- = (W_) SpA[AREL(i)];
+        for (i = NPtrWords    - 1; i >= 0; i--) *p-- = (W_) SpA[AREL(i)];
        *p = (W_) Node;
        }
 
     /* 
-     * Finished constructing PAP closure; now update the updatee. 
-     * But wait!  What if there is no updatee?  Then we fall off the stack.
+     * Finished constructing PAP closure; now update the updatee.  But
+     * wait!  What if there is no updatee?  Then we fall off the
+     * stack.
      */
 
 #ifdef CONCURRENT
@@ -558,12 +550,12 @@ STGFUN(UpdatePAP)
     UPD_IND(Updatee, PapClosure);   /* Indirect Updatee to PapClosure */
 
     if (NArgWords != 1) {
-       UPD_PAP_IN_NEW();
+       UPD_PAP_IN_NEW(NArgWords);
 
     } else {
        UPD_PAP_IN_PLACE();     
 
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
        /* 
          * Lexical scoping requires a *permanent* indirection, and we
          * also have to set the cost centre for the indirection.
@@ -571,18 +563,18 @@ STGFUN(UpdatePAP)
        INFO_PTR(Updatee) = (W_) Perm_Ind_info;
        SET_CC_HDR(Updatee, CC_pap);
 
-#endif /* USE_COST_CENTRES */
+#endif /* PROFILING */
     }
 
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
     /* 
      * Restore the Cost Centre too (if required); again see Sansom thesis p 183.
      * Take the CC out of the update frame if a CAF/DICT.
      */
 
-    CCC = (IS_CAF_OR_DICT_CC(CC_pap)) ? GRAB_COST_CENTRE(SuB) : CC_pap;
+    CCC = (IS_CAF_OR_DICT_OR_SUB_CC(CC_pap)) ? GRAB_COST_CENTRE(SuB) : CC_pap;
 
-#endif /* USE_COST_CENTRES */
+#endif /* PROFILING */
 
     /* Restore SuA, SuB, RetReg */
     RetReg = GRAB_RET(SuB);
@@ -604,7 +596,7 @@ STGFUN(UpdatePAP)
      * Don't count this entry for ticky-ticky profiling. 
     */
 
-#if defined(GRAN)
+#if 0 /* defined(GRAN) */
     GRAN_EXEC(16,4,7,4,0);
 #endif
     InfoPtr=(D_)(INFO_PTR(Node));
@@ -615,7 +607,7 @@ STGFUN(UpdatePAP)
 #undef NPtrWords
 #undef NArgWords
 #undef PapSize
-#ifdef USE_COST_CENTRES
+#ifdef PROFILING
 # undef CC_pap
 #endif
 }
@@ -631,11 +623,11 @@ STGFUN(PAP_entry)
     /* Use STG registers for these locals which must survive the STK_CHK */
 #define NPtrWords      (R2.i)
 #define NNonPtrWords   (R3.i)
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
 # define CC_pap        ((CostCentre)(R7.p))
 #endif
 
-    /* These locals don't have to survive a HEAP_CHK */
+    /* These locals don't have to survive the STK_CHK */
     P_ Updatee;
     P_ p;
     I_ i;
@@ -643,8 +635,6 @@ STGFUN(PAP_entry)
 
     FB_
 
-    SET_ACTIVITY(ACT_UPDATE_PAP);   /* SPAT profiling */
-
     while (AREL(SuA - SpA) == 0 && BREL(SuB - SpB) == 0) {
 #ifdef CONCURRENT
         if (SuB < STKO_BSTK_BOT(StkOReg)) {
@@ -660,16 +650,17 @@ STGFUN(PAP_entry)
         Updatee = GRAB_UPDATEE(SuB);
        UPD_IND(Updatee, Node);
 
-#if defined(USE_COST_CENTRES)
+#if defined(PROFILING)
         /* 
-         * Restore the Cost Centre too (if required); again see Sansom thesis p 183.
-         * Take the CC out of the update frame if a CAF/DICT.
-     */
+         * Restore the Cost Centre too (if required); again see Sansom
+         * thesis p 183.  Take the CC out of the update frame if a
+         * CAF/DICT.
+         */
 
         CC_pap = (CostCentre) CC_HDR(Node);
-        CCC = (IS_CAF_OR_DICT_CC(CC_pap)) ? GRAB_COST_CENTRE(SuB) : CC_pap;
+        CCC = (IS_CAF_OR_DICT_OR_SUB_CC(CC_pap)) ? GRAB_COST_CENTRE(SuB) : CC_pap;
 
-#endif /* USE_COST_CENTRES */
+#endif /* PROFILING */
 
         RetReg = GRAB_RET(SuB);
         SuA = GRAB_SuA(SuB);
@@ -718,7 +709,7 @@ STGFUN(PAP_entry)
 
 #undef NPtrWords
 #undef NNonPtrWords
-#ifdef USE_COST_CENTRES
+#ifdef PROFILING
 # undef CC_pap
 #endif
 }