author | Claus Gittinger <cg@exept.de> |
Tue, 05 Jul 2011 13:36:04 +0200 | |
changeset 2528 | e57cc8caf6f9 |
parent 2391 | 2bd90c14cd75 |
child 2569 | e9fcb54ac3d4 |
permissions | -rw-r--r-- |
2357 | 1 |
"{ Package: 'stx:libcomp' }" |
2 |
||
3 |
ByteCodeCompiler subclass:#InstrumentingCompiler |
|
4 |
instanceVariableNames:'method methodEntryInfo blockInvocationInfo' |
|
5 |
classVariableNames:'' |
|
6 |
poolDictionaries:'' |
|
7 |
category:'System-Compiler-Instrumentation' |
|
8 |
! |
|
9 |
||
10 |
Object subclass:#InstrumentationInfo |
|
11 |
instanceVariableNames:'owningMethod' |
|
12 |
classVariableNames:'' |
|
13 |
poolDictionaries:'' |
|
14 |
privateIn:InstrumentingCompiler |
|
15 |
! |
|
16 |
||
2390 | 17 |
InstrumentingCompiler::InstrumentationInfo subclass:#StatementExecutionInfo |
18 |
instanceVariableNames:'startPosition count' |
|
2359 | 19 |
classVariableNames:'' |
20 |
poolDictionaries:'' |
|
21 |
privateIn:InstrumentingCompiler |
|
22 |
! |
|
23 |
||
2357 | 24 |
InstrumentingCompiler::InstrumentationInfo subclass:#MethodInvocationInfo |
25 |
instanceVariableNames:'infoPerReceiverClass' |
|
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:InstrumentingCompiler |
|
29 |
! |
|
30 |
||
31 |
Object subclass:#MethodInvocationInfoPerReceiverClass |
|
32 |
instanceVariableNames:'infoPerSendingMethod' |
|
33 |
classVariableNames:'' |
|
34 |
poolDictionaries:'' |
|
35 |
privateIn:InstrumentingCompiler::MethodInvocationInfo |
|
36 |
! |
|
37 |
||
38 |
Object subclass:#MethodInvocationInfoPerSendingMethod |
|
2368 | 39 |
instanceVariableNames:'countPerSendersClass invokedViaPerform' |
2357 | 40 |
classVariableNames:'' |
41 |
poolDictionaries:'' |
|
42 |
privateIn:InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass |
|
43 |
! |
|
44 |
||
2390 | 45 |
InstrumentingCompiler::StatementExecutionInfo subclass:#BlockExecutionInfo |
46 |
instanceVariableNames:'endPosition' |
|
47 |
classVariableNames:'' |
|
48 |
poolDictionaries:'' |
|
49 |
privateIn:InstrumentingCompiler |
|
50 |
! |
|
51 |
||
2357 | 52 |
!InstrumentingCompiler class methodsFor:'documentation'! |
53 |
||
54 |
documentation |
|
55 |
" |
|
56 |
an experiment - recompile classes using this compiler adds instrumentation |
|
57 |
code. This remembers who calls a method (methodInvocationInfo) and how often |
|
58 |
basic blocks are invoked (blockExecutionInfo). |
|
59 |
" |
|
60 |
! ! |
|
61 |
||
62 |
!InstrumentingCompiler class methodsFor:'compilation-public'! |
|
63 |
||
64 |
compileClass:aClass |
|
65 |
"compile all methods of aClass with instrumentation" |
|
66 |
||
67 |
aClass methodsDo:[:eachMethod | |
|
68 |
self compileMethod:eachMethod |
|
69 |
]. |
|
70 |
! |
|
71 |
||
72 |
compileMethod:aMethod |
|
73 |
"compile a single method with instrumentation" |
|
74 |
||
75 |
self |
|
76 |
compile:(aMethod source) |
|
77 |
forClass:(aMethod mclass) |
|
78 |
inCategory:(aMethod category) |
|
79 |
! ! |
|
80 |
||
81 |
!InstrumentingCompiler class methodsFor:'special'! |
|
82 |
||
83 |
allInstrumentedMethods |
|
84 |
^ InstrumentedMethod allInstances |
|
85 |
||
86 |
" |
|
87 |
self allInstrumentedMethods |
|
88 |
" |
|
89 |
||
90 |
"Modified: / 27-04-2010 / 13:37:51 / cg" |
|
91 |
! |
|
92 |
||
93 |
callersOf:aMethod do:aBlock |
|
94 |
|info| |
|
95 |
||
96 |
info := aMethod methodInvocationInfo. |
|
97 |
info notNil ifTrue:[ |
|
98 |
info callingMethodsDo:[:callingMethod | |
|
99 |
aBlock value:callingMethod |
|
100 |
] |
|
101 |
] |
|
102 |
||
103 |
"Modified: / 27-04-2010 / 13:35:00 / cg" |
|
104 |
! |
|
105 |
||
106 |
isInstrumented:aMethod |
|
107 |
^ aMethod isInstrumented |
|
108 |
||
109 |
" |
|
110 |
self methodInfoOf:aMethod |
|
111 |
" |
|
112 |
||
113 |
"Modified: / 27-04-2010 / 13:35:21 / cg" |
|
114 |
! |
|
115 |
||
116 |
methodInfoOf:aMethod |
|
117 |
<resource: #obsolete> |
|
118 |
||
119 |
self obsoleteMethodWarning:'please use Method >> methodInvocationInfo'. |
|
120 |
^ aMethod methodInvocationInfo |
|
121 |
||
122 |
" |
|
123 |
self methodInfoOf:aMethod |
|
124 |
" |
|
125 |
||
126 |
"Modified: / 27-04-2010 / 13:37:31 / cg" |
|
127 |
! |
|
128 |
||
129 |
methodInvocationInfoOf:aMethod |
|
130 |
self obsoleteMethodWarning:'please use method>>methodInvocationInfo'. |
|
131 |
^ aMethod methodInvocationInfo |
|
132 |
||
133 |
" |
|
134 |
self methodInfoOf:aMethod |
|
135 |
" |
|
136 |
||
137 |
"Created: / 27-04-2010 / 12:28:56 / cg" |
|
138 |
"Modified: / 27-04-2010 / 13:34:36 / cg" |
|
139 |
! ! |
|
140 |
||
141 |
!InstrumentingCompiler methodsFor:'code generation helpers'! |
|
142 |
||
143 |
addBlockCounterTo:aBlockNode |
|
144 |
|countCode blockEntryInfo| |
|
145 |
||
146 |
blockInvocationInfo isNil ifTrue:[ |
|
147 |
blockInvocationInfo := OrderedCollection new. |
|
148 |
]. |
|
149 |
blockEntryInfo := BlockExecutionInfo new cleanInfo. |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
150 |
blockEntryInfo startPosition:aBlockNode startPosition endPosition:aBlockNode endPosition. |
2357 | 151 |
blockInvocationInfo add:blockEntryInfo. |
152 |
||
153 |
countCode := |
|
154 |
StatementNode |
|
155 |
expression:(MessageNode |
|
156 |
receiver:(ConstantNode value:blockEntryInfo) |
|
157 |
selector:#entry: |
|
158 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn)). |
|
159 |
||
160 |
aBlockNode isEmptyBlock ifTrue:[ |
|
161 |
"/ q: are we interested in empty blocks ? |
|
162 |
aBlockNode statements:countCode. |
|
163 |
] ifFalse:[ |
|
164 |
countCode nextStatement:aBlockNode statements. |
|
165 |
aBlockNode statements:countCode. |
|
166 |
]. |
|
167 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
168 |
"Modified: / 28-04-2010 / 15:55:30 / cg" |
2357 | 169 |
! |
170 |
||
171 |
addBlockCountersToEachBlockIn:aCollection |
|
172 |
aCollection do:[:eachNode | |
|
173 |
eachNode isBlockNode ifTrue:[ |
|
174 |
self addBlockCounterTo:eachNode |
|
175 |
] |
|
176 |
]. |
|
177 |
||
178 |
"Created: / 27-04-2010 / 11:47:56 / cg" |
|
179 |
! |
|
180 |
||
181 |
createMethod |
|
182 |
method := super createMethod. |
|
183 |
||
184 |
methodEntryInfo notNil ifTrue:[ |
|
185 |
methodEntryInfo owningMethod:method |
|
186 |
]. |
|
187 |
blockInvocationInfo notNil ifTrue:[ |
|
188 |
blockInvocationInfo do:[:eachInfo | eachInfo owningMethod:method] |
|
189 |
]. |
|
190 |
||
191 |
^ method |
|
192 |
||
193 |
"Modified: / 27-04-2010 / 14:04:50 / cg" |
|
194 |
! |
|
195 |
||
196 |
methodClass |
|
197 |
^ InstrumentedMethod |
|
198 |
||
199 |
"Created: / 27-04-2010 / 12:17:22 / cg" |
|
2390 | 200 |
! |
201 |
||
202 |
statementCounterBefore:aStatementNode |
|
203 |
|countCode statementEntryInfo| |
|
204 |
||
205 |
blockInvocationInfo isNil ifTrue:[ |
|
206 |
blockInvocationInfo := OrderedCollection new. |
|
207 |
]. |
|
208 |
statementEntryInfo := StatementExecutionInfo new cleanInfo. |
|
209 |
statementEntryInfo startPosition:aStatementNode startPosition. |
|
210 |
blockInvocationInfo add:statementEntryInfo. |
|
211 |
||
212 |
countCode := |
|
213 |
StatementNode |
|
214 |
expression:(MessageNode |
|
215 |
receiver:(ConstantNode value:statementEntryInfo) |
|
216 |
selector:#entry: |
|
217 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn)). |
|
218 |
||
219 |
countCode nextStatement:aStatementNode. |
|
220 |
^ countCode |
|
2357 | 221 |
! ! |
222 |
||
223 |
!InstrumentingCompiler methodsFor:'code generation-hooks'! |
|
224 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
225 |
blockNodeRewriteHookFor:aBlockNode |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
226 |
"/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
227 |
self addBlockCounterTo:aBlockNode. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
228 |
^ aBlockNode |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
229 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
230 |
"Created: / 28-04-2010 / 14:21:27 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
231 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
232 |
|
2357 | 233 |
messageNodeRewriteHookFor:aMessageNode |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
234 |
"/ see blockNodeRewriter... |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
235 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
236 |
"/ "/ argument could be a constantNode (due to contant-folding optimization) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
237 |
"/ aMessageNode isConstant ifTrue:[^ aMessageNode]. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
238 |
"/ ( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
239 |
"/ #( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
240 |
"/ ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
241 |
"/ ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
242 |
"/ ifTrue:ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
243 |
"/ ifFalse:ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
244 |
"/ ) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
245 |
"/ includes:aMessageNode selector |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
246 |
"/ ) ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
247 |
"/ "/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
248 |
"/ self addBlockCountersToEachBlockIn:(aMessageNode arguments) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
249 |
"/ ]. |
2357 | 250 |
^ aMessageNode |
251 |
||
252 |
"Created: / 27-04-2010 / 11:43:22 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
253 |
"Modified: / 28-04-2010 / 14:22:05 / cg" |
2357 | 254 |
! |
255 |
||
256 |
startCodeGenerationHookOn:codeStream |
|
257 |
methodEntryInfo := MethodInvocationInfo new. |
|
258 |
||
259 |
(StatementNode |
|
260 |
expression:(MessageNode |
|
261 |
receiver:(ConstantNode value:methodEntryInfo) |
|
262 |
selector:#entry: |
|
263 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn))) |
|
264 |
codeForSideEffectOn:codeStream inBlock:nil for:self. |
|
265 |
||
266 |
"Modified: / 27-04-2010 / 11:50:48 / cg" |
|
2390 | 267 |
! |
268 |
||
269 |
statementListRewriteHookFor:firstStatement |
|
270 |
"/ care for blocks which return... |
|
271 |
|thisStatement prevStatement countStatement mustInsertExecutionInfo| |
|
272 |
||
273 |
mustInsertExecutionInfo := false. |
|
274 |
prevStatement := nil. |
|
275 |
||
276 |
thisStatement := firstStatement. |
|
277 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
278 |
||
279 |
[true] whileTrue:[ |
|
280 |
mustInsertExecutionInfo ifTrue:[ |
|
281 |
"/ prev-stat had a return in it (a block with a return); |
|
282 |
"/ insert a statement-entry here. |
|
283 |
thisStatement notNil ifTrue:[ |
|
284 |
countStatement := self statementCounterBefore:thisStatement. |
|
285 |
prevStatement nextStatement:countStatement. |
|
286 |
mustInsertExecutionInfo := false. |
|
287 |
prevStatement := countStatement. |
|
288 |
] |
|
289 |
]. |
|
290 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
291 |
||
292 |
thisStatement isReturnNode ifFalse:[ |
|
293 |
thisStatement containsReturn ifTrue:[ |
|
294 |
mustInsertExecutionInfo := true |
|
295 |
] |
|
296 |
]. |
|
297 |
prevStatement := thisStatement. |
|
298 |
thisStatement := thisStatement nextStatement. |
|
299 |
]. |
|
2357 | 300 |
! ! |
301 |
||
302 |
!InstrumentingCompiler::InstrumentationInfo class methodsFor:'cleanup'! |
|
303 |
||
304 |
allInfosDo:aBlock |
|
305 |
InstrumentedMethod allInstancesDo:[:m | |
|
306 |
m literalsDo:[:l | |
|
307 |
(l isKindOf:self) ifTrue:[ |
|
308 |
aBlock value:l. |
|
309 |
]. |
|
310 |
] |
|
311 |
]. |
|
312 |
||
313 |
"Created: / 27-04-2010 / 12:09:03 / cg" |
|
314 |
! |
|
315 |
||
316 |
cleanAllInfo |
|
317 |
self allInfosDo:[:l | |
|
318 |
l cleanInfo. |
|
319 |
]. |
|
320 |
||
321 |
" |
|
322 |
InstrumentingCompiler::InstrumentationInfo cleanAllInfo |
|
323 |
InstrumentingCompiler::MethodInvocationInfo cleanAllInfo |
|
324 |
" |
|
325 |
||
326 |
"Modified: / 27-04-2010 / 12:10:07 / cg" |
|
327 |
! ! |
|
328 |
||
329 |
!InstrumentingCompiler::InstrumentationInfo methodsFor:'accessing'! |
|
330 |
||
331 |
owningMethod:something |
|
332 |
owningMethod := something. |
|
333 |
! ! |
|
334 |
||
335 |
!InstrumentingCompiler::InstrumentationInfo methodsFor:'instrumentation probe calls'! |
|
336 |
||
337 |
entry:callingContext |
|
338 |
"probe entry from instrumented code" |
|
339 |
||
340 |
"Created: / 27-04-2010 / 12:06:48 / cg" |
|
341 |
! ! |
|
342 |
||
2390 | 343 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'accessing'! |
2359 | 344 |
|
345 |
callCount |
|
346 |
^ count |
|
347 |
||
348 |
"Created: / 27-04-2010 / 13:45:15 / cg" |
|
349 |
! |
|
350 |
||
351 |
characterPosition |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
352 |
^ startPosition |
2359 | 353 |
|
354 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
355 |
"Modified: / 28-04-2010 / 15:54:24 / cg" |
2359 | 356 |
! |
357 |
||
358 |
characterPosition:something |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
359 |
startPosition := something. |
2359 | 360 |
|
361 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
362 |
"Modified: / 28-04-2010 / 15:54:30 / cg" |
2359 | 363 |
! |
364 |
||
365 |
count |
|
366 |
^ count |
|
367 |
||
368 |
"Created: / 23-06-2006 / 13:31:28 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
369 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
370 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
371 |
startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
372 |
^ startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
373 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
374 |
"Created: / 28-04-2010 / 15:54:26 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
375 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
376 |
|
2390 | 377 |
startPosition:something |
378 |
startPosition := something. |
|
2359 | 379 |
! ! |
380 |
||
2390 | 381 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'cleanup'! |
2359 | 382 |
|
383 |
cleanInfo |
|
384 |
count := 0 |
|
385 |
! ! |
|
386 |
||
2390 | 387 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'instrumentation calls'! |
2359 | 388 |
|
389 |
entry:callingContext |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
390 |
"invoked by instrumented code; |
2359 | 391 |
called whenever the block is entered" |
392 |
||
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
393 |
|p| |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
394 |
|
2359 | 395 |
count := count + 1. |
396 |
count == 1 ifTrue:[ |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
397 |
"/ the very first time, send a change notification |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
398 |
p := Processor activeProcess. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
399 |
(p environmentAt:#inInstrument ifAbsent:false) ifFalse:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
400 |
p withThreadVariable:#inInstrument boundTo:true do:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
401 |
owningMethod changed:#methodInfo |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
402 |
]. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
403 |
] |
2359 | 404 |
]. |
405 |
||
406 |
"Created: / 23-06-2006 / 13:31:16 / cg" |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
407 |
"Modified: / 05-07-2011 / 13:35:25 / cg" |
2359 | 408 |
! ! |
409 |
||
2390 | 410 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'queries'! |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
411 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
412 |
hasBeenExecuted |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
413 |
^ count > 0 |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
414 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
415 |
"Created: / 28-04-2010 / 14:39:46 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
416 |
! ! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
417 |
|
2357 | 418 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'accessing'! |
419 |
||
420 |
callingMethodsDo:aBlock |
|
421 |
infoPerReceiverClass notNil ifTrue:[ |
|
422 |
infoPerReceiverClass do:[:each | |
|
423 |
each callingMethodsDo:aBlock |
|
424 |
] |
|
425 |
] |
|
426 |
! |
|
427 |
||
428 |
hasBeenCalled |
|
429 |
^ infoPerReceiverClass notEmptyOrNil |
|
430 |
||
431 |
"Created: / 27-04-2010 / 13:43:15 / cg" |
|
432 |
! |
|
433 |
||
2368 | 434 |
invokedViaPerform |
435 |
^ infoPerReceiverClass contains:[:someInfo | someInfo invokedViaPerform]. |
|
436 |
||
437 |
"Created: / 27-04-2010 / 18:21:56 / cg" |
|
438 |
! |
|
439 |
||
2357 | 440 |
invokingMethods |
441 |
|setOfMethods| |
|
442 |
||
443 |
setOfMethods := IdentitySet new. |
|
444 |
self invokingMethodsDo:[:m | setOfMethods add:m]. |
|
445 |
^ setOfMethods. |
|
446 |
! |
|
447 |
||
448 |
invokingMethodsDo:aBlock |
|
449 |
infoPerReceiverClass isNil ifTrue:[ ^ self]. |
|
450 |
^ infoPerReceiverClass do:[:eachInfo | eachInfo invokingMethodsDo:aBlock]. |
|
451 |
! |
|
452 |
||
453 |
numberOfInvocations |
|
454 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
455 |
^ infoPerReceiverClass inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
456 |
! |
|
457 |
||
458 |
numberOfInvocationsFromExternalOf:aClass |
|
459 |
|sum| |
|
460 |
||
461 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
462 |
||
463 |
sum := 0. |
|
464 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
465 |
sum := sum + (info numberOfInvocationsFromExternalOf:aClass) |
|
466 |
]. |
|
467 |
^ sum |
|
468 |
! |
|
469 |
||
470 |
numberOfInvocationsFromInternalOf:aClass |
|
471 |
|sum| |
|
472 |
||
473 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
474 |
||
475 |
sum := 0. |
|
476 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
477 |
sum := sum + (info numberOfInvocationsFromInternalOf:aClass) |
|
478 |
]. |
|
479 |
^ sum |
|
480 |
! ! |
|
481 |
||
482 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'cleanup'! |
|
483 |
||
484 |
cleanInfo |
|
485 |
infoPerReceiverClass := nil. |
|
486 |
! ! |
|
487 |
||
488 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'instrumentation probe calls'! |
|
489 |
||
490 |
entry:aContext |
|
491 |
"invoked by instrumented compiled code, upon method entry" |
|
492 |
||
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
493 |
|p receiversClass infoPerReceiver| |
2357 | 494 |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
495 |
p := Processor activeProcess. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
496 |
(p environmentAt:#inInstrument ifAbsent:false) ifTrue:[^ self]. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
497 |
p withThreadVariable:#inInstrument boundTo:true do:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
498 |
receiversClass := aContext receiver class. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
499 |
infoPerReceiverClass isNil ifTrue:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
500 |
infoPerReceiverClass := IdentityDictionary new. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
501 |
]. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
502 |
infoPerReceiver := infoPerReceiverClass |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
503 |
at:receiversClass |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
504 |
ifAbsentPut:[ MethodInvocationInfoPerReceiverClass new ]. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
505 |
infoPerReceiver entry:aContext |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
506 |
] |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
507 |
|
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
508 |
"Modified: / 05-07-2011 / 13:35:42 / cg" |
2357 | 509 |
! ! |
510 |
||
511 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'accessing'! |
|
512 |
||
513 |
callingMethodsDo:aBlock |
|
514 |
infoPerSendingMethod keysAndValuesDo:[:m :eachInfo | |
|
515 |
aBlock value:m |
|
516 |
] |
|
517 |
! |
|
518 |
||
2368 | 519 |
invokedViaPerform |
520 |
^ infoPerSendingMethod contains:[:someInfo | someInfo invokedViaPerform]. |
|
521 |
||
522 |
"Created: / 27-04-2010 / 18:21:36 / cg" |
|
523 |
! |
|
524 |
||
2357 | 525 |
invokingMethodsDo:aBlock |
526 |
infoPerSendingMethod isNil ifTrue:[ ^ self]. |
|
527 |
^ infoPerSendingMethod keysDo:aBlock. |
|
528 |
! |
|
529 |
||
530 |
numberOfInvocations |
|
531 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
532 |
^ infoPerSendingMethod inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
533 |
! |
|
534 |
||
535 |
numberOfInvocationsFromExternalOf:aClass |
|
536 |
|sum| |
|
537 |
||
538 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
539 |
||
540 |
sum := 0. |
|
541 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
542 |
|sendingMethodsClass| |
|
543 |
||
544 |
sendingMethodsClass := sendingMethod mclass. |
|
545 |
sendingMethodsClass notNil ifTrue:[ |
|
546 |
((sendingMethodsClass isSubclassOf:aClass) |
|
547 |
or:[(aClass isSubclassOf:sendingMethodsClass )]) ifFalse:[ |
|
548 |
sum := sum + (info numberOfInvocations) |
|
549 |
] |
|
550 |
] |
|
551 |
]. |
|
552 |
^ sum |
|
553 |
! |
|
554 |
||
555 |
numberOfInvocationsFromInternalOf:aClass |
|
556 |
|sum| |
|
557 |
||
558 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
559 |
||
560 |
sum := 0. |
|
561 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
562 |
|sendingMethodsClass| |
|
563 |
||
564 |
sendingMethodsClass := sendingMethod mclass. |
|
565 |
sendingMethodsClass notNil ifTrue:[ |
|
566 |
((sendingMethodsClass isSubclassOf:aClass) |
|
567 |
or:[(aClass isSubclassOf:sendingMethodsClass)]) ifTrue:[ |
|
568 |
sum := sum + (info numberOfInvocations) |
|
569 |
] |
|
570 |
] |
|
571 |
]. |
|
572 |
^ sum |
|
573 |
! ! |
|
574 |
||
575 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'! |
|
576 |
||
577 |
entry:aContext |
|
578 |
"invoked by instrumented compiled code, upon method entry" |
|
579 |
||
2368 | 580 |
|sender sendingMethod infoPerMethod viaPerform| |
2357 | 581 |
|
2391 | 582 |
aContext selector == #doesNotUnderstand: ifTrue:[ |
583 |
sender := aContext sender sender methodHome. |
|
584 |
] ifFalse:[ |
|
585 |
sender := aContext sender methodHome. |
|
586 |
]. |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
587 |
sender isNil ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
588 |
^ self. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
589 |
] ifFalse:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
590 |
sendingMethod := sender method. |
2391 | 591 |
sendingMethod isNil ifTrue:[^ self]. |
592 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
593 |
viaPerform := false. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
594 |
(sendingMethod mclass == Object |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
595 |
and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
596 |
"/ Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix). |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
597 |
sender := sender sender methodHome. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
598 |
sendingMethod := sender method. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
599 |
viaPerform := true. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
600 |
]. |
2357 | 601 |
]. |
602 |
||
603 |
infoPerSendingMethod isNil ifTrue:[ |
|
604 |
infoPerSendingMethod := IdentityDictionary new. |
|
605 |
]. |
|
606 |
infoPerMethod := infoPerSendingMethod |
|
607 |
at:sendingMethod |
|
608 |
ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ]. |
|
609 |
||
2368 | 610 |
infoPerMethod entry:aContext viaPerform:viaPerform |
611 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
612 |
"Modified: / 28-04-2010 / 16:09:04 / cg" |
2357 | 613 |
! ! |
614 |
||
615 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'! |
|
616 |
||
2368 | 617 |
invokedViaPerform |
618 |
^ invokedViaPerform ? false |
|
619 |
||
620 |
"Created: / 27-04-2010 / 18:20:05 / cg" |
|
621 |
! |
|
622 |
||
2357 | 623 |
numberOfInvocations |
624 |
countPerSendersClass isNil ifTrue:[ ^ 0]. |
|
625 |
^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] |
|
626 |
! ! |
|
627 |
||
628 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'! |
|
629 |
||
2368 | 630 |
entry:aContext viaPerform:viaPerformBoolean |
2357 | 631 |
"invoked by instrumented compiled code, upon method entry" |
632 |
||
633 |
|sendersClass count| |
|
634 |
||
635 |
sendersClass := aContext sender receiver class. |
|
636 |
||
637 |
countPerSendersClass isNil ifTrue:[ |
|
638 |
countPerSendersClass := IdentityDictionary new. |
|
639 |
]. |
|
640 |
count := countPerSendersClass at:sendersClass ifAbsentPut:0. |
|
2368 | 641 |
countPerSendersClass at:sendersClass put:(count + 1). |
642 |
viaPerformBoolean ifTrue:[ invokedViaPerform := true ]. |
|
643 |
||
644 |
"Created: / 27-04-2010 / 18:17:27 / cg" |
|
2357 | 645 |
! ! |
646 |
||
2390 | 647 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'accessing'! |
648 |
||
649 |
endPosition |
|
650 |
^ endPosition |
|
651 |
||
652 |
"Created: / 28-04-2010 / 15:57:14 / cg" |
|
653 |
! |
|
654 |
||
655 |
startPosition:startArg endPosition:endArg |
|
656 |
startPosition := startArg. |
|
657 |
endPosition := endArg. |
|
658 |
||
659 |
"Created: / 28-04-2010 / 15:54:47 / cg" |
|
660 |
! ! |
|
661 |
||
2357 | 662 |
!InstrumentingCompiler class methodsFor:'documentation'! |
663 |
||
664 |
version_CVS |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
665 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.7 2011-07-05 11:36:04 cg Exp $' |
2357 | 666 |
! ! |