[MLton-commit] r4617

Matthew Fluet MLton@mlton.org
Sat, 27 May 2006 16:33:14 -0700


Profiling functions are called from the mutator without calling
enter/leave, so must compute the frameIndex and sourceSeqIndex of the
top frame via the cached gcState.stackTop, not through
gcState.currentThread.


----------------------------------------------------------------------

U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.h
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c
U   mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h

----------------------------------------------------------------------

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c	2006-05-27 16:48:09 UTC (rev 4616)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/profiling.c	2006-05-27 23:33:13 UTC (rev 4617)
@@ -92,7 +92,7 @@
 }
 
 void GC_profileEnter (GC_state s) {
-  enterForProfiling (s, getStackTopFrameSourceSeqIndex (s, getStackCurrent (s)));
+  enterForProfiling (s, getCachedStackTopFrameSourceSeqIndex (s));
 }
 
 void removeFromStackForProfiling (GC_state s, GC_profileMasterIndex i) {
@@ -152,7 +152,7 @@
 }
 
 void GC_profileLeave (GC_state s) {
-  leaveForProfiling (s, getStackTopFrameSourceSeqIndex (s, getStackCurrent (s)));
+  leaveForProfiling (s, getCachedStackTopFrameSourceSeqIndex (s));
 }
 
 
@@ -192,7 +192,7 @@
   incForProfiling (s, amount,
                    s->amInGC
                    ? SOURCE_SEQ_GC
-                   : getStackTopFrameSourceSeqIndex (s, getStackCurrent (s)));
+                   : getCachedStackTopFrameSourceSeqIndex (s));
 }
 
 void GC_profileAllocInc (GC_state s, size_t amount) {
@@ -326,7 +326,7 @@
   if (s->amInGC)
     sourceSeqsIndex = SOURCE_SEQ_GC;
   else {
-    frameIndex = getStackTopFrameIndex (s, getStackCurrent (s));
+    frameIndex = getCachedStackTopFrameIndex (s);
     if (C_FRAME == s->frameLayouts[frameIndex].kind)
       sourceSeqsIndex = s->sourceMaps.frameSources[frameIndex];
     else {

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.c	2006-05-27 16:48:09 UTC (rev 4616)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.c	2006-05-27 23:33:13 UTC (rev 4617)
@@ -6,8 +6,12 @@
  * See the file MLton-LICENSE for details.
  */
 
-GC_sourceSeqIndex getStackTopFrameSourceSeqIndex (GC_state s, GC_stack stack) {
-  return s->sourceMaps.frameSources[getStackTopFrameIndex (s, stack)];
+GC_sourceSeqIndex getCachedStackTopFrameSourceSeqIndex (GC_state s) {
+  GC_frameIndex i;
+
+  i = getCachedStackTopFrameIndex (s);
+  assert(i < s->sourceMaps.frameSourcesLength);
+  return s->sourceMaps.frameSources[i];
 }
 
 char* getSourceName (GC_state s, GC_sourceIndex i) {

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.h	2006-05-27 16:48:09 UTC (rev 4616)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/sources.h	2006-05-27 23:33:13 UTC (rev 4617)
@@ -75,7 +75,7 @@
 
 #if (defined (MLTON_GC_INTERNAL_FUNCS))
 
-static inline GC_sourceSeqIndex getStackTopFrameSourceSeqIndex (GC_state s, GC_stack stack);
+static inline GC_sourceSeqIndex getCachedStackTopFrameSourceSeqIndex (GC_state s);
 
 static inline char* getSourceName (GC_state s, GC_sourceIndex i);
 

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c	2006-05-27 16:48:09 UTC (rev 4616)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.c	2006-05-27 23:33:13 UTC (rev 4617)
@@ -64,6 +64,22 @@
 }
 
 
+GC_frameIndex getCachedStackTopFrameIndex (GC_state s) {
+  GC_frameIndex res;
+  
+  res = 
+    getFrameIndexFromReturnAddress 
+    (s, *((GC_returnAddress*)(s->stackTop - GC_RETURNADDRESS_SIZE)));
+  return res;
+}
+
+GC_frameLayout getCachedStackTopFrameLayout (GC_state s) {
+  GC_frameLayout layout;
+
+  layout = getFrameLayoutFromFrameIndex (s, getCachedStackTopFrameIndex (s));
+  return layout;
+}
+
 GC_frameIndex getStackTopFrameIndex (GC_state s, GC_stack stack) {
   GC_frameIndex res;
   

Modified: mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h
===================================================================
--- mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2006-05-27 16:48:09 UTC (rev 4616)
+++ mlton/branches/on-20050822-x86_64-branch/runtime/gc/stack.h	2006-05-27 23:33:13 UTC (rev 4617)
@@ -69,6 +69,8 @@
 static inline pointer getStackTop (GC_state s, GC_stack stack);
 static inline pointer getStackLimitPlusSlop (GC_state s, GC_stack stack);
 static inline pointer getStackLimit (GC_state s, GC_stack stack);
+static inline GC_frameIndex getCachedStackTopFrameIndex (GC_state s);
+static inline GC_frameLayout getCachedStackTopFrameLayout (GC_state s);
 static inline GC_frameIndex getStackTopFrameIndex (GC_state s, GC_stack stack);
 static inline GC_frameLayout getStackTopFrameLayout (GC_state s, GC_stack stack);
 static inline uint16_t getStackTopFrameSize (GC_state s, GC_stack stack);