author | Claus Gittinger <cg@exept.de> |
Wed, 20 Jul 2011 20:16:33 +0200 | |
changeset 2571 | b441a3fc0ce6 |
parent 2570 | f0b8fc6cdabb |
child 2632 | 734313b470d3 |
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 |
]. |
|
2571 | 149 |
blockEntryInfo := BlockExecutionInfo new cleanInfoWithChange:false. |
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 |
||
2571 | 168 |
"Modified: / 20-07-2011 / 19:00:05 / 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 |
]. |
|
2571 | 208 |
statementEntryInfo := StatementExecutionInfo new cleanInfoWithChange:false. |
2390 | 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 |
|
2571 | 221 |
|
222 |
"Modified: / 20-07-2011 / 19:00:13 / cg" |
|
2357 | 223 |
! ! |
224 |
||
225 |
!InstrumentingCompiler methodsFor:'code generation-hooks'! |
|
226 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
227 |
blockNodeRewriteHookFor:aBlockNode |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
228 |
"/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
229 |
self addBlockCounterTo:aBlockNode. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
230 |
^ aBlockNode |
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 |
"Created: / 28-04-2010 / 14:21:27 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
233 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
234 |
|
2357 | 235 |
messageNodeRewriteHookFor:aMessageNode |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
236 |
"/ see blockNodeRewriter... |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
237 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
238 |
"/ "/ argument could be a constantNode (due to contant-folding optimization) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
239 |
"/ aMessageNode isConstant ifTrue:[^ aMessageNode]. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
240 |
"/ ( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
241 |
"/ #( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
242 |
"/ ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
243 |
"/ ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
244 |
"/ ifTrue:ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
245 |
"/ ifFalse:ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
246 |
"/ ) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
247 |
"/ includes:aMessageNode selector |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
248 |
"/ ) ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
249 |
"/ "/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
250 |
"/ self addBlockCountersToEachBlockIn:(aMessageNode arguments) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
251 |
"/ ]. |
2357 | 252 |
^ aMessageNode |
253 |
||
254 |
"Created: / 27-04-2010 / 11:43:22 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
255 |
"Modified: / 28-04-2010 / 14:22:05 / cg" |
2357 | 256 |
! |
257 |
||
258 |
startCodeGenerationHookOn:codeStream |
|
259 |
methodEntryInfo := MethodInvocationInfo new. |
|
260 |
||
261 |
(StatementNode |
|
262 |
expression:(MessageNode |
|
263 |
receiver:(ConstantNode value:methodEntryInfo) |
|
264 |
selector:#entry: |
|
265 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn))) |
|
266 |
codeForSideEffectOn:codeStream inBlock:nil for:self. |
|
267 |
||
268 |
"Modified: / 27-04-2010 / 11:50:48 / cg" |
|
2390 | 269 |
! |
270 |
||
271 |
statementListRewriteHookFor:firstStatement |
|
272 |
"/ care for blocks which return... |
|
273 |
|thisStatement prevStatement countStatement mustInsertExecutionInfo| |
|
274 |
||
275 |
mustInsertExecutionInfo := false. |
|
276 |
prevStatement := nil. |
|
277 |
||
278 |
thisStatement := firstStatement. |
|
279 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
280 |
||
281 |
[true] whileTrue:[ |
|
282 |
mustInsertExecutionInfo ifTrue:[ |
|
283 |
"/ prev-stat had a return in it (a block with a return); |
|
284 |
"/ insert a statement-entry here. |
|
285 |
thisStatement notNil ifTrue:[ |
|
286 |
countStatement := self statementCounterBefore:thisStatement. |
|
287 |
prevStatement nextStatement:countStatement. |
|
288 |
mustInsertExecutionInfo := false. |
|
289 |
prevStatement := countStatement. |
|
290 |
] |
|
291 |
]. |
|
292 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
293 |
||
294 |
thisStatement isReturnNode ifFalse:[ |
|
295 |
thisStatement containsReturn ifTrue:[ |
|
296 |
mustInsertExecutionInfo := true |
|
297 |
] |
|
298 |
]. |
|
299 |
prevStatement := thisStatement. |
|
300 |
thisStatement := thisStatement nextStatement. |
|
301 |
]. |
|
2357 | 302 |
! ! |
303 |
||
304 |
!InstrumentingCompiler::InstrumentationInfo class methodsFor:'cleanup'! |
|
305 |
||
306 |
allInfosDo:aBlock |
|
307 |
InstrumentedMethod allInstancesDo:[:m | |
|
308 |
m literalsDo:[:l | |
|
309 |
(l isKindOf:self) ifTrue:[ |
|
310 |
aBlock value:l. |
|
311 |
]. |
|
312 |
] |
|
313 |
]. |
|
314 |
||
315 |
"Created: / 27-04-2010 / 12:09:03 / cg" |
|
316 |
! |
|
317 |
||
2571 | 318 |
cleanAllInfoWithChange:withChange |
2357 | 319 |
self allInfosDo:[:l | |
2571 | 320 |
l cleanInfoWithChange:withChange. |
2357 | 321 |
]. |
322 |
||
323 |
" |
|
324 |
InstrumentingCompiler::InstrumentationInfo cleanAllInfo |
|
325 |
InstrumentingCompiler::MethodInvocationInfo cleanAllInfo |
|
326 |
" |
|
327 |
||
328 |
"Modified: / 27-04-2010 / 12:10:07 / cg" |
|
2571 | 329 |
"Created: / 20-07-2011 / 19:00:37 / cg" |
2357 | 330 |
! ! |
331 |
||
332 |
!InstrumentingCompiler::InstrumentationInfo methodsFor:'accessing'! |
|
333 |
||
334 |
owningMethod:something |
|
335 |
owningMethod := something. |
|
336 |
! ! |
|
337 |
||
338 |
!InstrumentingCompiler::InstrumentationInfo methodsFor:'instrumentation probe calls'! |
|
339 |
||
340 |
entry:callingContext |
|
341 |
"probe entry from instrumented code" |
|
342 |
||
343 |
"Created: / 27-04-2010 / 12:06:48 / cg" |
|
344 |
! ! |
|
345 |
||
2390 | 346 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'accessing'! |
2359 | 347 |
|
348 |
callCount |
|
349 |
^ count |
|
350 |
||
351 |
"Created: / 27-04-2010 / 13:45:15 / cg" |
|
352 |
! |
|
353 |
||
354 |
characterPosition |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
355 |
^ startPosition |
2359 | 356 |
|
357 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
358 |
"Modified: / 28-04-2010 / 15:54:24 / cg" |
2359 | 359 |
! |
360 |
||
361 |
characterPosition:something |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
362 |
startPosition := something. |
2359 | 363 |
|
364 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
365 |
"Modified: / 28-04-2010 / 15:54:30 / cg" |
2359 | 366 |
! |
367 |
||
368 |
count |
|
369 |
^ count |
|
370 |
||
371 |
"Created: / 23-06-2006 / 13:31:28 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
372 |
! |
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 |
startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
375 |
^ startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
376 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
377 |
"Created: / 28-04-2010 / 15:54:26 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
378 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
379 |
|
2390 | 380 |
startPosition:something |
381 |
startPosition := something. |
|
2359 | 382 |
! ! |
383 |
||
2390 | 384 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'cleanup'! |
2359 | 385 |
|
2571 | 386 |
cleanInfoWithChange:withChange |
2569 | 387 |
count := 0. |
2571 | 388 |
withChange ifTrue:[ |
389 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
390 |
]. |
|
2569 | 391 |
|
2570 | 392 |
"Modified: / 20-07-2011 / 17:55:49 / cg" |
2571 | 393 |
"Created: / 20-07-2011 / 18:59:01 / cg" |
2359 | 394 |
! ! |
395 |
||
2390 | 396 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'instrumentation calls'! |
2359 | 397 |
|
398 |
entry:callingContext |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
399 |
"invoked by instrumented code; |
2359 | 400 |
called whenever the block is entered" |
401 |
||
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
402 |
|p| |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
403 |
|
2359 | 404 |
count := count + 1. |
405 |
count == 1 ifTrue:[ |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
406 |
"/ the very first time, send a change notification |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
407 |
p := Processor activeProcess. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
408 |
(p environmentAt:#inInstrument ifAbsent:false) ifFalse:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
409 |
p withThreadVariable:#inInstrument boundTo:true do:[ |
2570 | 410 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
411 |
]. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
412 |
] |
2359 | 413 |
]. |
414 |
||
415 |
"Created: / 23-06-2006 / 13:31:16 / cg" |
|
2570 | 416 |
"Modified: / 20-07-2011 / 17:56:06 / cg" |
2359 | 417 |
! ! |
418 |
||
2390 | 419 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'queries'! |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
420 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
421 |
hasBeenExecuted |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
422 |
^ count > 0 |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
423 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
424 |
"Created: / 28-04-2010 / 14:39:46 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
425 |
! ! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
426 |
|
2357 | 427 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'accessing'! |
428 |
||
429 |
callingMethodsDo:aBlock |
|
430 |
infoPerReceiverClass notNil ifTrue:[ |
|
431 |
infoPerReceiverClass do:[:each | |
|
432 |
each callingMethodsDo:aBlock |
|
433 |
] |
|
434 |
] |
|
435 |
! |
|
436 |
||
437 |
hasBeenCalled |
|
438 |
^ infoPerReceiverClass notEmptyOrNil |
|
439 |
||
440 |
"Created: / 27-04-2010 / 13:43:15 / cg" |
|
441 |
! |
|
442 |
||
2368 | 443 |
invokedViaPerform |
444 |
^ infoPerReceiverClass contains:[:someInfo | someInfo invokedViaPerform]. |
|
445 |
||
446 |
"Created: / 27-04-2010 / 18:21:56 / cg" |
|
447 |
! |
|
448 |
||
2357 | 449 |
invokingMethods |
450 |
|setOfMethods| |
|
451 |
||
452 |
setOfMethods := IdentitySet new. |
|
453 |
self invokingMethodsDo:[:m | setOfMethods add:m]. |
|
454 |
^ setOfMethods. |
|
455 |
! |
|
456 |
||
457 |
invokingMethodsDo:aBlock |
|
458 |
infoPerReceiverClass isNil ifTrue:[ ^ self]. |
|
459 |
^ infoPerReceiverClass do:[:eachInfo | eachInfo invokingMethodsDo:aBlock]. |
|
460 |
! |
|
461 |
||
462 |
numberOfInvocations |
|
463 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
464 |
^ infoPerReceiverClass inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
465 |
! |
|
466 |
||
467 |
numberOfInvocationsFromExternalOf:aClass |
|
468 |
|sum| |
|
469 |
||
470 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
471 |
||
472 |
sum := 0. |
|
473 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
474 |
sum := sum + (info numberOfInvocationsFromExternalOf:aClass) |
|
475 |
]. |
|
476 |
^ sum |
|
477 |
! |
|
478 |
||
479 |
numberOfInvocationsFromInternalOf:aClass |
|
480 |
|sum| |
|
481 |
||
482 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
483 |
||
484 |
sum := 0. |
|
485 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
486 |
sum := sum + (info numberOfInvocationsFromInternalOf:aClass) |
|
487 |
]. |
|
488 |
^ sum |
|
489 |
! ! |
|
490 |
||
491 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'cleanup'! |
|
492 |
||
2571 | 493 |
cleanInfoWithChange:withChange |
2357 | 494 |
infoPerReceiverClass := nil. |
2571 | 495 |
withChange ifTrue:[ |
496 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
497 |
] |
|
2569 | 498 |
|
2570 | 499 |
"Modified: / 20-07-2011 / 17:55:35 / cg" |
2571 | 500 |
"Created: / 20-07-2011 / 18:59:22 / cg" |
2357 | 501 |
! ! |
502 |
||
503 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'instrumentation probe calls'! |
|
504 |
||
505 |
entry:aContext |
|
506 |
"invoked by instrumented compiled code, upon method entry" |
|
507 |
||
2569 | 508 |
|p receiversClass infoPerReceiver firstEntry| |
2357 | 509 |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
510 |
p := Processor activeProcess. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
511 |
(p environmentAt:#inInstrument ifAbsent:false) ifTrue:[^ self]. |
2569 | 512 |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
513 |
p withThreadVariable:#inInstrument boundTo:true do:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
514 |
receiversClass := aContext receiver class. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
515 |
infoPerReceiverClass isNil ifTrue:[ |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
516 |
infoPerReceiverClass := IdentityDictionary new. |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
517 |
]. |
2569 | 518 |
firstEntry := false. |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
519 |
infoPerReceiver := infoPerReceiverClass |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
520 |
at:receiversClass |
2569 | 521 |
ifAbsentPut:[ firstEntry := true. |
522 |
MethodInvocationInfoPerReceiverClass new ]. |
|
523 |
infoPerReceiver entry:aContext. |
|
524 |
||
525 |
"/ the very first time, send a change notification |
|
526 |
firstEntry ifTrue:[ |
|
2570 | 527 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
2569 | 528 |
] |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
529 |
] |
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
530 |
|
2570 | 531 |
"Modified: / 20-07-2011 / 17:55:56 / cg" |
2357 | 532 |
! ! |
533 |
||
534 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'accessing'! |
|
535 |
||
536 |
callingMethodsDo:aBlock |
|
537 |
infoPerSendingMethod keysAndValuesDo:[:m :eachInfo | |
|
538 |
aBlock value:m |
|
539 |
] |
|
540 |
! |
|
541 |
||
2368 | 542 |
invokedViaPerform |
543 |
^ infoPerSendingMethod contains:[:someInfo | someInfo invokedViaPerform]. |
|
544 |
||
545 |
"Created: / 27-04-2010 / 18:21:36 / cg" |
|
546 |
! |
|
547 |
||
2357 | 548 |
invokingMethodsDo:aBlock |
549 |
infoPerSendingMethod isNil ifTrue:[ ^ self]. |
|
550 |
^ infoPerSendingMethod keysDo:aBlock. |
|
551 |
! |
|
552 |
||
553 |
numberOfInvocations |
|
554 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
555 |
^ infoPerSendingMethod inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
556 |
! |
|
557 |
||
558 |
numberOfInvocationsFromExternalOf:aClass |
|
559 |
|sum| |
|
560 |
||
561 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
562 |
||
563 |
sum := 0. |
|
564 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
565 |
|sendingMethodsClass| |
|
566 |
||
567 |
sendingMethodsClass := sendingMethod mclass. |
|
568 |
sendingMethodsClass notNil ifTrue:[ |
|
569 |
((sendingMethodsClass isSubclassOf:aClass) |
|
570 |
or:[(aClass isSubclassOf:sendingMethodsClass )]) ifFalse:[ |
|
571 |
sum := sum + (info numberOfInvocations) |
|
572 |
] |
|
573 |
] |
|
574 |
]. |
|
575 |
^ sum |
|
576 |
! |
|
577 |
||
578 |
numberOfInvocationsFromInternalOf:aClass |
|
579 |
|sum| |
|
580 |
||
581 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
582 |
||
583 |
sum := 0. |
|
584 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
585 |
|sendingMethodsClass| |
|
586 |
||
587 |
sendingMethodsClass := sendingMethod mclass. |
|
588 |
sendingMethodsClass notNil ifTrue:[ |
|
589 |
((sendingMethodsClass isSubclassOf:aClass) |
|
590 |
or:[(aClass isSubclassOf:sendingMethodsClass)]) ifTrue:[ |
|
591 |
sum := sum + (info numberOfInvocations) |
|
592 |
] |
|
593 |
] |
|
594 |
]. |
|
595 |
^ sum |
|
596 |
! ! |
|
597 |
||
598 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'! |
|
599 |
||
600 |
entry:aContext |
|
601 |
"invoked by instrumented compiled code, upon method entry" |
|
602 |
||
2368 | 603 |
|sender sendingMethod infoPerMethod viaPerform| |
2357 | 604 |
|
2391 | 605 |
aContext selector == #doesNotUnderstand: ifTrue:[ |
606 |
sender := aContext sender sender methodHome. |
|
607 |
] ifFalse:[ |
|
608 |
sender := aContext sender methodHome. |
|
609 |
]. |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
610 |
sender isNil ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
611 |
^ self. |
2569 | 612 |
]. |
613 |
sendingMethod := sender method. |
|
614 |
sendingMethod isNil ifTrue:[^ self]. |
|
2391 | 615 |
|
2569 | 616 |
viaPerform := false. |
617 |
(sendingMethod mclass == Object |
|
618 |
and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[ |
|
619 |
"/ Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix). |
|
620 |
sender := sender sender methodHome. |
|
621 |
sendingMethod := sender method. |
|
622 |
viaPerform := true. |
|
2357 | 623 |
]. |
624 |
||
625 |
infoPerSendingMethod isNil ifTrue:[ |
|
626 |
infoPerSendingMethod := IdentityDictionary new. |
|
627 |
]. |
|
628 |
infoPerMethod := infoPerSendingMethod |
|
629 |
at:sendingMethod |
|
630 |
ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ]. |
|
631 |
||
2368 | 632 |
infoPerMethod entry:aContext viaPerform:viaPerform |
633 |
||
2569 | 634 |
"Modified: / 20-07-2011 / 17:26:31 / cg" |
2357 | 635 |
! ! |
636 |
||
637 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'! |
|
638 |
||
2368 | 639 |
invokedViaPerform |
640 |
^ invokedViaPerform ? false |
|
641 |
||
642 |
"Created: / 27-04-2010 / 18:20:05 / cg" |
|
643 |
! |
|
644 |
||
2357 | 645 |
numberOfInvocations |
646 |
countPerSendersClass isNil ifTrue:[ ^ 0]. |
|
647 |
^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] |
|
648 |
! ! |
|
649 |
||
650 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'! |
|
651 |
||
2368 | 652 |
entry:aContext viaPerform:viaPerformBoolean |
2357 | 653 |
"invoked by instrumented compiled code, upon method entry" |
654 |
||
655 |
|sendersClass count| |
|
656 |
||
657 |
sendersClass := aContext sender receiver class. |
|
658 |
||
659 |
countPerSendersClass isNil ifTrue:[ |
|
660 |
countPerSendersClass := IdentityDictionary new. |
|
661 |
]. |
|
662 |
count := countPerSendersClass at:sendersClass ifAbsentPut:0. |
|
2368 | 663 |
countPerSendersClass at:sendersClass put:(count + 1). |
664 |
viaPerformBoolean ifTrue:[ invokedViaPerform := true ]. |
|
665 |
||
666 |
"Created: / 27-04-2010 / 18:17:27 / cg" |
|
2357 | 667 |
! ! |
668 |
||
2390 | 669 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'accessing'! |
670 |
||
671 |
endPosition |
|
672 |
^ endPosition |
|
673 |
||
674 |
"Created: / 28-04-2010 / 15:57:14 / cg" |
|
675 |
! |
|
676 |
||
677 |
startPosition:startArg endPosition:endArg |
|
678 |
startPosition := startArg. |
|
679 |
endPosition := endArg. |
|
680 |
||
681 |
"Created: / 28-04-2010 / 15:54:47 / cg" |
|
682 |
! ! |
|
683 |
||
2357 | 684 |
!InstrumentingCompiler class methodsFor:'documentation'! |
685 |
||
2570 | 686 |
version |
2571 | 687 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.10 2011-07-20 18:16:33 cg Exp $' |
2570 | 688 |
! |
689 |
||
2357 | 690 |
version_CVS |
2571 | 691 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.10 2011-07-20 18:16:33 cg Exp $' |
2357 | 692 |
! ! |