InstrumentationContext.st
changeset 2874 68b98f42a54f
parent 2710 f2e7d18ca6c8
child 2942 2f6d164949bf
--- a/InstrumentationContext.st	Fri Jun 01 22:38:51 2012 +0200
+++ b/InstrumentationContext.st	Tue Jun 05 23:31:07 2012 +0200
@@ -13,7 +13,7 @@
 
 Object variableSubclass:#InstrumentationContext
 	instanceVariableNames:'inInstrumentedCode enabled coverageOnly'
-	classVariableNames:'CachedProcessToInstrumentationContextMapping
+	classVariableNames:'LastProcess LastInstrumentationContext
 		GlobalInstrumentationContext'
 	poolDictionaries:''
 	category:'System-Compiler-Instrumentation'
@@ -76,27 +76,29 @@
 
     |p context|
 
-    CachedProcessToInstrumentationContextMapping isNil ifTrue:[
-        CachedProcessToInstrumentationContextMapping := WeakIdentityDictionary new.
+    aProcess == LastProcess ifTrue:[
+        ^ LastInstrumentationContext
     ].
 
-    context := CachedProcessToInstrumentationContextMapping at:aProcess ifAbsent:nil.
-    context == 0 ifTrue:[ ^ nil].   "/ special entry for a known nil value
-    context isNil ifTrue:[
-        "/ future (need a faster parentProcess query)
-        p := aProcess.
-        [p notNil] whileTrue:[
-            context := p environmentAt:#instrumentationContext ifAbsent:nil.
-            context notNil ifTrue:[
-                CachedProcessToInstrumentationContextMapping at:aProcess put:context.
-                ^ context
+    "/ future (need a faster parentProcess query)
+    p := aProcess.
+    [p notNil] whileTrue:[
+        context := p environmentAt:#instrumentationContext ifAbsent:nil.
+        context notNil ifTrue:[
+            aProcess environmentAt:#instrumentationContext put:context.
+            context == 0 ifTrue:[
+                context := nil.
             ].
-            p := p parentProcess
+            LastProcess := aProcess.
+            LastInstrumentationContext := context.
+            ^ context
         ].
-        CachedProcessToInstrumentationContextMapping at:aProcess put:(GlobalInstrumentationContext ? 0). "/ known to be nil
-        context := GlobalInstrumentationContext.
+        p := p parentProcess
     ].
-    ^ context
+    aProcess environmentAt:#instrumentationContext put:(GlobalInstrumentationContext ? 0).      "/ could be nil
+    LastProcess := aProcess.
+    LastInstrumentationContext := GlobalInstrumentationContext.
+    ^ GlobalInstrumentationContext.
 
     "
      InstrumentationContext current
@@ -144,9 +146,7 @@
     "setup for global instrumentation: instrumentation is performed for all processes"
 
     GlobalInstrumentationContext := aContextOrNil.
-    CachedProcessToInstrumentationContextMapping notNil ifTrue:[
-        CachedProcessToInstrumentationContextMapping removeAll
-    ].
+    LastInstrumentationContext := LastProcess := nil.
 
     "Created: / 21-09-2011 / 19:07:00 / cg"
 !
@@ -159,9 +159,7 @@
      at least local..."
 
     aProcess environmentAt:#instrumentationContext put:aContextOrNil.
-    CachedProcessToInstrumentationContextMapping notNil ifTrue:[
-        CachedProcessToInstrumentationContextMapping removeAll
-    ].
+    LastInstrumentationContext := LastProcess := nil.
 
     "Created: / 17-08-2011 / 11:53:19 / cg"
 ! !
@@ -170,7 +168,8 @@
 
 coverageOnly
     "if on, only keep track of coverage (not counting);
-     if off, we also count how often the code has been entered"
+     if off, we also count how often the code has been entered,
+     and by which sender"
 
     ^ coverageOnly
 
@@ -227,9 +226,7 @@
     "become the current instrumentaion context for all processes."
 
     self class setGlobalInstrumentationContext:self. 
-    CachedProcessToInstrumentationContextMapping notNil ifTrue:[
-        CachedProcessToInstrumentationContextMapping removeAll.
-    ].
+    LastInstrumentationContext := LastProcess := nil.
 
     "
      InstrumentationContext new beActiveEverywhere
@@ -242,9 +239,7 @@
     "become the current instrumentaion context for a process."
 
     self class setInstrumentationContext:self in:aProcess.
-    CachedProcessToInstrumentationContextMapping notNil ifTrue:[
-        CachedProcessToInstrumentationContextMapping removeKey:aProcess ifAbsent:[].
-    ].
+    LastInstrumentationContext := LastProcess := nil.
 
     "
      InstrumentationContext new beActiveIn:(Processor activeProcess)
@@ -283,9 +278,9 @@
 !InstrumentationContext class methodsFor:'documentation'!
 
 version
-    ^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.7 2011-09-30 09:09:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.8 2012-06-05 21:31:07 cg Exp $'
 !
 
 version_CVS
-    ^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.7 2011-09-30 09:09:10 cg Exp $'
+    ^ '$Header: /cvs/stx/stx/libcomp/InstrumentationContext.st,v 1.8 2012-06-05 21:31:07 cg Exp $'
 ! !