1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204
|
/* ml-state.c
*
* COPYRIGHT (c) 1993 by AT&T Bell Laboratories.
*
*/
#include <stdarg.h>
#include "ml-base.h"
#include "vproc-state.h"
#include "ml-state.h"
#include "system-signals.h"
#include "tags.h"
#include "ml-values.h"
#include "ml-objects.h"
#include "ml-globals.h"
#include "gc.h"
#include "ml-timer.h"
#include "ml-limits.h"
vproc_state_t *VProc[MAX_NUM_PROCS];
int NumVProcs;
/* local routines */
PVT void InitVProcState (vproc_state_t *vsp);
/* AllocMLState:
*/
ml_state_t *AllocMLState (bool_t isBoot, heap_params_t *heapParams)
{
ml_state_t *msp = NIL(ml_state_t *);
#ifdef MP_SUPPORT
int i;
#endif
#ifdef MP_SUPPORT
for (i = 0; i < MAX_NUM_PROCS; i++) {
if (((VProc[i] = NEW_OBJ(vproc_state_t)) == NIL(vproc_state_t *))
|| ((msp = NEW_OBJ(ml_state_t)) == NIL(ml_state_t *))) {
Die ("unable to allocate ML state vectors");
}
VProc[i]->vp_state = msp;
}
msp = VProc[0]->vp_state;
#else
if (((VProc[0] = NEW_OBJ(vproc_state_t)) == NIL (vproc_state_t *))
|| ((msp = NEW_OBJ(ml_state_t)) == NIL(ml_state_t *))) {
Die ("unable to allocate ML state vector");
}
VProc[0]->vp_state = msp;
#endif /* MP_SUPPORT */
/* allocate and initialize the heap data structures */
InitHeap (msp, isBoot, heapParams);
#ifdef MP_SUPPORT
/* partition the allocation arena given by InitHeap among the
* MAX_NUM_PROCS processors.
*/
NumVProcs = MAX_NUM_PROCS;
PartitionAllocArena(VProc);
/* initialize the per-processor ML state */
for (i = 0; i < MAX_NUM_PROCS; i++) {
int j;
InitVProcState (VProc[i]);
/* single timers are currently shared among multiple processors */
if (i != 0) {
VProc[i]->vp_gcTime0 = VProc[0]->vp_gcTime0;
VProc[i]->vp_gcTime = VProc[0]->vp_gcTime;
}
}
/* initialize the first processor here */
VProc[0]->vp_mpSelf = MP_ProcId ();
VProc[0]->vp_mpState = MP_PROC_RUNNING;
#else
InitVProcState (VProc[0]);
NumVProcs = 1;
#endif /* MP_SUPPORT */
/* initialize the timers */
/** MP_SUPPORT note: for now, only proc 0 has timers **/
ResetTimers (VProc[0]);
return msp;
} /* end of AllocMLState */
/* InitVProcState:
*/
PVT void InitVProcState (vproc_state_t *vsp)
{
int i;
vsp->vp_heap = vsp->vp_state->ml_heap;
vsp->vp_state->ml_vproc = vsp;
vsp->vp_inMLFlag = FALSE;
vsp->vp_handlerPending = FALSE;
vsp->vp_inSigHandler = FALSE;
vsp->vp_numPendingSysSigs = 0;
vsp->vp_numPendingSigs = 0;
vsp->vp_sigCode = 0;
vsp->vp_sigCount = 0;
vsp->vp_nextPendingSig = 0;
vsp->vp_numInQ = 0;
vsp->vp_gcSigState = ML_SIG_IGNORE;
vsp->vp_gcTime0 = NEW_OBJ(Time_t);
vsp->vp_gcTime = NEW_OBJ(Time_t);
for (i = 0; i < NUM_SIGS; i++) {
vsp->vp_pendingSigQ[i].sigNum = 0;
vsp->vp_pendingSigQ[i].count = 0;
}
/* initialize the ML state, including the roots */
InitMLState (vsp->vp_state);
vsp->vp_state->ml_arg = ML_unit;
vsp->vp_state->ml_cont = ML_unit;
vsp->vp_state->ml_closure = ML_unit;
vsp->vp_state->ml_linkReg = ML_unit;
vsp->vp_state->ml_pc = ML_unit;
vsp->vp_state->ml_exnCont = ML_unit;
vsp->vp_state->ml_varReg = ML_unit;
vsp->vp_state->ml_calleeSave[0] = ML_unit;
vsp->vp_state->ml_calleeSave[1] = ML_unit;
vsp->vp_state->ml_calleeSave[2] = ML_unit;
#ifdef MP_SUPPORT
vsp->vp_mpSelf = 0;
vsp->vp_mpState = MP_PROC_NO_PROC;
#endif
} /* end of InitVProcState */
/* InitMLState:
*
* Initialize the ML State vector. Note that we do not initialize the root
* registers here, since this is sometimes called when the roots are live (from
* ML_ApplyFn).
*/
void InitMLState (ml_state_t *msp)
{
msp->ml_storePtr = ML_unit;
#ifdef SOFT_POLL
msp->ml_pollPending = FALSE;
msp->ml_inPollHandler = FALSE;
#endif
} /* end of InitMLState. */
/* SaveCState:
*
* Build a return closure that will save a collection of ML values
* being used by C. The ML values are passed by reference, with NIL
* as termination.
*/
void SaveCState (ml_state_t *msp, ...)
{
va_list ap;
int n, i;
ml_val_t *vp;
va_start (ap, msp);
for (n = 0; (vp = va_arg(ap, ml_val_t *)) != NIL(ml_val_t *); n++)
continue;
va_end (ap);
va_start (ap, msp);
ML_AllocWrite (msp, 0, MAKE_DESC(n, DTAG_record));
for (i = 1; i <= n; i++) {
vp = va_arg (ap, ml_val_t *);
ML_AllocWrite (msp, i, *vp);
}
msp->ml_calleeSave[0] = ML_Alloc(msp, n);
msp->ml_cont = PTR_CtoML(return_c);
va_end (ap);
} /* end of SaveCState */
/* RestoreCState:
*
* Restore a collection of ML values from the return closure.
*/
void RestoreCState (ml_state_t *msp, ...)
{
va_list ap;
int n, i;
ml_val_t *vp;
ml_val_t savedState;
va_start (ap, msp);
savedState = msp->ml_calleeSave[0];
n = OBJ_LEN(savedState);
for (i = 0; i < n; i++) {
vp = va_arg (ap, ml_val_t *);
*vp = REC_SEL(savedState, i);
}
va_end (ap);
} /* end of RestoreCState */
|