[MLton] More on Parallel Runtime

schatzp at purdue.edu schatzp at purdue.edu
Mon Oct 29 02:53:22 PST 2007


Quoting Daniel Spoonhower <spoons+ at cs.cmu.edu>:

> I've also been working on a "multi-core" MLton, though I have a somewhat
> different (and maybe simpler) purpose in mind, so some of the design
> decisions
> I've made are different.  I'm interested in a data-parallel language (as
> opposed to a CML-like language), so the semantics is still sequential and
> scheduling is cooperative (even at the user level).
> 
> I've also been working with pthreads and the C codegen, but I'm still using
> a
> shared heap.  I have a big lock too, but I've been whittling away at it and
> using lighter weight synchronization in some places (e.g. allocation).  I'm

My solution to locking during allocation was to use separate heaps.
So far, the big lock is only used in GC_collect (eventually only if a 
collect needs to be run) and in Thread_atomicBegin/End.

> also happy to share what I have so far, and I would be interested to compare
> our changes to GC_state.
> 
> 
> --djs
>
> > (removed for brevity)

Below are my GC_state (which is per-pthread) and GC_sharedState (which 
is a global var) structs. To note, I added nextFunc and returnToC into 
GC_state.

struct GC_state {
  /* These fields are at the front because they are the most commonly
   * referenced, and having them at smaller offsets may decrease code
   * size and improve cache performance.
   */
  pointer frontier; /* heap.start <= frontier < limit */
  pointer limit; /* limit = heap.start + heap.size */
  pointer stackTop; /* Top of stack in current thread. */
  pointer stackLimit; /* stackBottom + stackSize - maxFrameSize */
  size_t exnStack;
  uintptr_t nextFunc; //Now per-pthread.
  //  Also, include/c-common.h needs to find nextFunc by offset
  int returnToC; //Now per-pthread

  /* Alphabetized fields follow. */
  uint32_t atomicState;
  objptr callFromCHandlerThread; /* Handler for exported C calls (in 
heap). */
  struct GC_callStackState callStackState;
  bool canMinor; /* TRUE iff there is space for a minor gc. */
  objptr currentThread; /* Currently executing thread (in heap). */
  struct GC_generationalMaps generationalMaps;
  bool hashConsDuringGC;
  struct GC_heap heap;
  struct GC_lastMajorStatistics lastMajorStatistics;
  pointer limitPlusSlop; /* limit + GC_HEAP_LIMIT_SLOP */
  GC_objectHashTable objectHashTable;
  objptr savedThread; /* Result of GC_copyCurrentThread.
                       * Thread interrupted by arrival of signal.
                       */
  struct GC_heap secondaryHeap; /* Used for major copying collection. */
  objptr signalHandlerThread; /* Handler for signals (in heap). */
  struct GC_signalsInfo signalsInfo;
  pointer stackBottom; /* Bottom of stack in current thread. */
  GC_weak weaks; /* Linked list of (live) weak pointers */
};

struct GC_sharedState {
  /* Global info shared by all GC_state's.
   */
  bool amInGC;
  bool amOriginal;
  char **atMLtons; /* Initial @MLton args, processed before command 
line. */
  uint32_t atMLtonsLength;
  size_t alignment; /* */
  struct GC_controls controls;
  struct GC_cumulativeStatistics cumulativeStatistics;
  struct GC_forwardState forwardState;
  GC_frameLayout frameLayouts; /* Array of frame layouts. */
  uint32_t frameLayoutsLength; /* Cardinality of frameLayouts array. */
  objptr *globals;
  uint32_t globalsLength;
  struct GC_intInfInit *intInfInits;
  uint32_t intInfInitsLength;
  int (*loadGlobals)(FILE *f); /* loads the globals from the file. */
  uint32_t magic; /* The magic number for this executable. */
  uint32_t maxFrameSize;
  bool mutatorMarksCards;
  GC_objectType objectTypes; /* Array of object types. */
  uint32_t objectTypesLength; /* Cardinality of objectTypes array. */
  struct GC_profiling profiling;
  GC_frameIndex (*returnAddressToFrameIndex) (GC_returnAddress ra);
  int (*saveGlobals)(FILE *f); /* saves the globals to the file. */
  bool saveWorldStatus; /* */
  struct GC_sourceMaps sourceMaps;
  uintmax_t startTime; /* The time when GC_init or GC_loadWorld was 
called. */
  struct GC_sysvals sysvals;
  struct GC_translateState translateState;
  struct GC_vectorInit *vectorInits;
  uint32_t vectorInitsLength;
};


-- 
Philip Schatz
CS Graduate Student
Purdue University




More information about the MLton mailing list