author | Claus Gittinger <cg@exept.de> |
Tue, 05 Jun 2012 23:53:04 +0200 | |
changeset 2875 | f7f46f53bc84 |
parent 2715 | 10a744f8ce68 |
child 2944 | b0a2b03382fa |
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 |
||
2634 | 10 |
InstrumentationInfo subclass:#StatementExecutionInfo |
2390 | 11 |
instanceVariableNames:'startPosition count' |
2359 | 12 |
classVariableNames:'' |
13 |
poolDictionaries:'' |
|
14 |
privateIn:InstrumentingCompiler |
|
15 |
! |
|
16 |
||
2635 | 17 |
InstrumentationInfo subclass:#MethodInvocationInfo |
2357 | 18 |
instanceVariableNames:'infoPerReceiverClass' |
19 |
classVariableNames:'' |
|
20 |
poolDictionaries:'' |
|
21 |
privateIn:InstrumentingCompiler |
|
22 |
! |
|
23 |
||
24 |
Object subclass:#MethodInvocationInfoPerReceiverClass |
|
25 |
instanceVariableNames:'infoPerSendingMethod' |
|
26 |
classVariableNames:'' |
|
27 |
poolDictionaries:'' |
|
28 |
privateIn:InstrumentingCompiler::MethodInvocationInfo |
|
29 |
! |
|
30 |
||
31 |
Object subclass:#MethodInvocationInfoPerSendingMethod |
|
2368 | 32 |
instanceVariableNames:'countPerSendersClass invokedViaPerform' |
2357 | 33 |
classVariableNames:'' |
34 |
poolDictionaries:'' |
|
35 |
privateIn:InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass |
|
36 |
! |
|
37 |
||
2711 | 38 |
InstrumentingCompiler::MethodInvocationInfo subclass:#MethodInvocationInfoInAlreadyEnteredState |
39 |
instanceVariableNames:'' |
|
40 |
classVariableNames:'' |
|
41 |
poolDictionaries:'' |
|
42 |
privateIn:InstrumentingCompiler |
|
43 |
! |
|
44 |
||
2715 | 45 |
InstrumentingCompiler::StatementExecutionInfo subclass:#VariableAccessExecutionInfo |
46 |
instanceVariableNames:'' |
|
47 |
classVariableNames:'' |
|
48 |
poolDictionaries:'' |
|
49 |
privateIn:InstrumentingCompiler |
|
50 |
! |
|
51 |
||
2390 | 52 |
InstrumentingCompiler::StatementExecutionInfo subclass:#BlockExecutionInfo |
53 |
instanceVariableNames:'endPosition' |
|
54 |
classVariableNames:'' |
|
55 |
poolDictionaries:'' |
|
56 |
privateIn:InstrumentingCompiler |
|
57 |
! |
|
58 |
||
2715 | 59 |
InstrumentingCompiler::VariableAccessExecutionInfo subclass:#ReadAccessExecutionInfo |
60 |
instanceVariableNames:'' |
|
61 |
classVariableNames:'' |
|
62 |
poolDictionaries:'' |
|
63 |
privateIn:InstrumentingCompiler |
|
64 |
! |
|
65 |
||
66 |
InstrumentingCompiler::VariableAccessExecutionInfo subclass:#WriteAccessExecutionInfo |
|
67 |
instanceVariableNames:'' |
|
68 |
classVariableNames:'' |
|
69 |
poolDictionaries:'' |
|
70 |
privateIn:InstrumentingCompiler |
|
71 |
! |
|
72 |
||
2357 | 73 |
!InstrumentingCompiler class methodsFor:'documentation'! |
74 |
||
75 |
documentation |
|
76 |
" |
|
2632 | 77 |
an experiment - recompile classes using this compiler adds instrumentation code. |
78 |
This remembers who calls a method from where (methodInvocationInfo) what the receiver's types are |
|
79 |
(inherited classes) and how often basic blocks (blockExecutionInfo) and statements |
|
80 |
(statementExecutionInfo) are invoked . |
|
81 |
||
82 |
The who-calls and receiver type info may produce some overhead, which can be avoided by |
|
83 |
using the somewhat more naive InstrumentingForSimpleCoverageCompiler (that is what people are |
|
84 |
used to from the C/Java world, anyway). |
|
85 |
||
86 |
From the first bulk, we can compute the inheritanceCoverage info (which methods have been called for which |
|
87 |
subclass) in addition to the known line and block coverages. |
|
2357 | 88 |
" |
89 |
! ! |
|
90 |
||
91 |
!InstrumentingCompiler class methodsFor:'compilation-public'! |
|
92 |
||
93 |
compileClass:aClass |
|
94 |
"compile all methods of aClass with instrumentation" |
|
95 |
||
96 |
aClass methodsDo:[:eachMethod | |
|
97 |
self compileMethod:eachMethod |
|
98 |
]. |
|
99 |
! |
|
100 |
||
101 |
compileMethod:aMethod |
|
102 |
"compile a single method with instrumentation" |
|
103 |
||
104 |
self |
|
105 |
compile:(aMethod source) |
|
106 |
forClass:(aMethod mclass) |
|
107 |
inCategory:(aMethod category) |
|
108 |
! ! |
|
109 |
||
110 |
!InstrumentingCompiler class methodsFor:'special'! |
|
111 |
||
112 |
allInstrumentedMethods |
|
113 |
^ InstrumentedMethod allInstances |
|
114 |
||
115 |
" |
|
116 |
self allInstrumentedMethods |
|
117 |
" |
|
118 |
||
119 |
"Modified: / 27-04-2010 / 13:37:51 / cg" |
|
120 |
! |
|
121 |
||
122 |
callersOf:aMethod do:aBlock |
|
2632 | 123 |
"enumerate all callers of aMethod into a block" |
124 |
||
2357 | 125 |
|info| |
126 |
||
127 |
info := aMethod methodInvocationInfo. |
|
128 |
info notNil ifTrue:[ |
|
129 |
info callingMethodsDo:[:callingMethod | |
|
130 |
aBlock value:callingMethod |
|
131 |
] |
|
132 |
] |
|
133 |
||
134 |
"Modified: / 27-04-2010 / 13:35:00 / cg" |
|
2632 | 135 |
"Modified (comment): / 07-08-2011 / 15:08:33 / cg" |
2357 | 136 |
! |
137 |
||
138 |
isInstrumented:aMethod |
|
139 |
^ aMethod isInstrumented |
|
140 |
||
141 |
" |
|
142 |
self methodInfoOf:aMethod |
|
143 |
" |
|
144 |
||
145 |
"Modified: / 27-04-2010 / 13:35:21 / cg" |
|
146 |
! |
|
147 |
||
148 |
methodInfoOf:aMethod |
|
149 |
<resource: #obsolete> |
|
150 |
||
151 |
self obsoleteMethodWarning:'please use Method >> methodInvocationInfo'. |
|
152 |
^ aMethod methodInvocationInfo |
|
153 |
||
154 |
" |
|
155 |
self methodInfoOf:aMethod |
|
156 |
" |
|
157 |
||
158 |
"Modified: / 27-04-2010 / 13:37:31 / cg" |
|
159 |
! |
|
160 |
||
161 |
methodInvocationInfoOf:aMethod |
|
162 |
self obsoleteMethodWarning:'please use method>>methodInvocationInfo'. |
|
163 |
^ aMethod methodInvocationInfo |
|
164 |
||
165 |
" |
|
166 |
self methodInfoOf:aMethod |
|
167 |
" |
|
168 |
||
169 |
"Created: / 27-04-2010 / 12:28:56 / cg" |
|
170 |
"Modified: / 27-04-2010 / 13:34:36 / cg" |
|
171 |
! ! |
|
172 |
||
173 |
!InstrumentingCompiler methodsFor:'code generation helpers'! |
|
174 |
||
175 |
addBlockCounterTo:aBlockNode |
|
176 |
|countCode blockEntryInfo| |
|
177 |
||
178 |
blockInvocationInfo isNil ifTrue:[ |
|
179 |
blockInvocationInfo := OrderedCollection new. |
|
180 |
]. |
|
2632 | 181 |
blockEntryInfo := self blockExecutionInfoInstance. |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
182 |
blockEntryInfo startPosition:aBlockNode startPosition endPosition:aBlockNode endPosition. |
2675
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
183 |
"/ Transcript show:aBlockNode startPosition; |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
184 |
"/ show:' -> '; |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
185 |
"/ showCR: aBlockNode endPosition. |
2357 | 186 |
blockInvocationInfo add:blockEntryInfo. |
187 |
||
188 |
countCode := |
|
189 |
StatementNode |
|
190 |
expression:(MessageNode |
|
191 |
receiver:(ConstantNode value:blockEntryInfo) |
|
192 |
selector:#entry: |
|
193 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn)). |
|
194 |
||
195 |
aBlockNode isEmptyBlock ifTrue:[ |
|
196 |
"/ q: are we interested in empty blocks ? |
|
2665
2071b01a050f
changed: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2635
diff
changeset
|
197 |
countCode nextStatement:(StatementNode expression:(ConstantNode value:nil)). |
2357 | 198 |
aBlockNode statements:countCode. |
199 |
] ifFalse:[ |
|
200 |
countCode nextStatement:aBlockNode statements. |
|
201 |
aBlockNode statements:countCode. |
|
202 |
]. |
|
203 |
||
2675
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
204 |
"Modified: / 21-08-2011 / 16:02:52 / cg" |
2357 | 205 |
! |
206 |
||
207 |
addBlockCountersToEachBlockIn:aCollection |
|
208 |
aCollection do:[:eachNode | |
|
209 |
eachNode isBlockNode ifTrue:[ |
|
210 |
self addBlockCounterTo:eachNode |
|
211 |
] |
|
212 |
]. |
|
213 |
||
214 |
"Created: / 27-04-2010 / 11:47:56 / cg" |
|
215 |
! |
|
216 |
||
217 |
createMethod |
|
218 |
method := super createMethod. |
|
219 |
||
220 |
methodEntryInfo notNil ifTrue:[ |
|
221 |
methodEntryInfo owningMethod:method |
|
222 |
]. |
|
223 |
blockInvocationInfo notNil ifTrue:[ |
|
224 |
blockInvocationInfo do:[:eachInfo | eachInfo owningMethod:method] |
|
225 |
]. |
|
226 |
||
227 |
^ method |
|
228 |
||
229 |
"Modified: / 27-04-2010 / 14:04:50 / cg" |
|
230 |
! |
|
231 |
||
232 |
methodClass |
|
233 |
^ InstrumentedMethod |
|
234 |
||
235 |
"Created: / 27-04-2010 / 12:17:22 / cg" |
|
2390 | 236 |
! |
237 |
||
238 |
statementCounterBefore:aStatementNode |
|
239 |
|countCode statementEntryInfo| |
|
240 |
||
241 |
blockInvocationInfo isNil ifTrue:[ |
|
242 |
blockInvocationInfo := OrderedCollection new. |
|
243 |
]. |
|
2632 | 244 |
statementEntryInfo := self statementExecutionInfoInstance. |
2390 | 245 |
statementEntryInfo startPosition:aStatementNode startPosition. |
246 |
blockInvocationInfo add:statementEntryInfo. |
|
247 |
||
248 |
countCode := |
|
249 |
StatementNode |
|
250 |
expression:(MessageNode |
|
251 |
receiver:(ConstantNode value:statementEntryInfo) |
|
252 |
selector:#entry: |
|
253 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn)). |
|
254 |
||
255 |
countCode nextStatement:aStatementNode. |
|
256 |
^ countCode |
|
2571 | 257 |
|
2632 | 258 |
"Modified: / 07-08-2011 / 15:32:45 / cg" |
2357 | 259 |
! ! |
260 |
||
2715 | 261 |
!InstrumentingCompiler methodsFor:'code generation hooks'! |
262 |
||
263 |
assignmentRewriteHookFor:anAssignmentNode |
|
264 |
"invoked whenever an assignment node has been generated" |
|
265 |
||
266 |
^ anAssignmentNode |
|
267 |
||
268 |
"Created: / 30-09-2011 / 12:28:09 / cg" |
|
269 |
! |
|
2357 | 270 |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
271 |
blockNodeRewriteHookFor:aBlockNode |
2715 | 272 |
"invoked whenever a block node has been generated" |
273 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
274 |
"/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
275 |
self addBlockCounterTo:aBlockNode. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
276 |
^ aBlockNode |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
277 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
278 |
"Created: / 28-04-2010 / 14:21:27 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
279 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
280 |
|
2357 | 281 |
messageNodeRewriteHookFor:aMessageNode |
2715 | 282 |
"invoked whenever a message send node has been generated" |
283 |
||
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
284 |
"/ see blockNodeRewriter... |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
285 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
286 |
"/ "/ argument could be a constantNode (due to contant-folding optimization) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
287 |
"/ aMessageNode isConstant ifTrue:[^ aMessageNode]. |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
288 |
"/ ( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
289 |
"/ #( |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
290 |
"/ ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
291 |
"/ ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
292 |
"/ ifTrue:ifFalse: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
293 |
"/ ifFalse:ifTrue: |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
294 |
"/ ) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
295 |
"/ includes:aMessageNode selector |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
296 |
"/ ) ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
297 |
"/ "/ add a counter for the block |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
298 |
"/ self addBlockCountersToEachBlockIn:(aMessageNode arguments) |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
299 |
"/ ]. |
2357 | 300 |
^ aMessageNode |
301 |
||
302 |
"Created: / 27-04-2010 / 11:43:22 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
303 |
"Modified: / 28-04-2010 / 14:22:05 / cg" |
2715 | 304 |
"Modified (comment): / 30-09-2011 / 12:16:56 / cg" |
2357 | 305 |
! |
306 |
||
307 |
startCodeGenerationHookOn:codeStream |
|
2715 | 308 |
"invoked before code is generated" |
309 |
||
2632 | 310 |
methodEntryInfo := self methodInvocationInfoInstance. |
2357 | 311 |
|
312 |
(StatementNode |
|
313 |
expression:(MessageNode |
|
314 |
receiver:(ConstantNode value:methodEntryInfo) |
|
315 |
selector:#entry: |
|
316 |
arg:(VariableNode type:#ThisContext context:contextToEvaluateIn))) |
|
317 |
codeForSideEffectOn:codeStream inBlock:nil for:self. |
|
318 |
||
2632 | 319 |
"Modified: / 07-08-2011 / 15:34:09 / cg" |
2715 | 320 |
"Modified (comment): / 30-09-2011 / 12:16:05 / cg" |
2390 | 321 |
! |
322 |
||
323 |
statementListRewriteHookFor:firstStatement |
|
2715 | 324 |
"invoked whenever a statement list node has been generated" |
325 |
||
2390 | 326 |
"/ care for blocks which return... |
327 |
|thisStatement prevStatement countStatement mustInsertExecutionInfo| |
|
328 |
||
329 |
mustInsertExecutionInfo := false. |
|
330 |
prevStatement := nil. |
|
331 |
||
332 |
thisStatement := firstStatement. |
|
333 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
334 |
||
335 |
[true] whileTrue:[ |
|
336 |
mustInsertExecutionInfo ifTrue:[ |
|
337 |
"/ prev-stat had a return in it (a block with a return); |
|
338 |
"/ insert a statement-entry here. |
|
339 |
thisStatement notNil ifTrue:[ |
|
340 |
countStatement := self statementCounterBefore:thisStatement. |
|
341 |
prevStatement nextStatement:countStatement. |
|
342 |
mustInsertExecutionInfo := false. |
|
343 |
prevStatement := countStatement. |
|
344 |
] |
|
345 |
]. |
|
346 |
thisStatement isNil ifTrue:[^ firstStatement]. |
|
347 |
||
348 |
thisStatement isReturnNode ifFalse:[ |
|
349 |
thisStatement containsReturn ifTrue:[ |
|
350 |
mustInsertExecutionInfo := true |
|
351 |
] |
|
352 |
]. |
|
353 |
prevStatement := thisStatement. |
|
354 |
thisStatement := thisStatement nextStatement. |
|
355 |
]. |
|
2715 | 356 |
|
357 |
"Modified (comment): / 30-09-2011 / 12:15:52 / cg" |
|
358 |
! |
|
359 |
||
360 |
variableReadRewriteHookFor:aVariableNode |
|
361 |
"invoked whenever a variable access node has been generated" |
|
362 |
||
363 |
^ aVariableNode |
|
364 |
||
365 |
"Created: / 30-09-2011 / 12:27:47 / cg" |
|
2357 | 366 |
! ! |
367 |
||
2632 | 368 |
!InstrumentingCompiler methodsFor:'redefinable'! |
2357 | 369 |
|
2632 | 370 |
blockExecutionInfoInstance |
371 |
"one instance is generated for every block, |
|
372 |
and called at execution time with entry:" |
|
2357 | 373 |
|
2632 | 374 |
^ BlockExecutionInfo new cleanInfoWithChange:false. |
375 |
||
376 |
"Created: / 07-08-2011 / 15:13:42 / cg" |
|
2357 | 377 |
! |
378 |
||
2632 | 379 |
methodInvocationInfoInstance |
380 |
"one instance is generated for every method, |
|
381 |
and called at execution time with entry:" |
|
2357 | 382 |
|
2632 | 383 |
^ MethodInvocationInfo new. |
2357 | 384 |
|
2632 | 385 |
"Created: / 07-08-2011 / 15:33:57 / cg" |
386 |
! |
|
2357 | 387 |
|
2632 | 388 |
statementExecutionInfoInstance |
389 |
"one instance is generated for every statement, |
|
390 |
and called at execution time with entry:" |
|
2357 | 391 |
|
2632 | 392 |
^ StatementExecutionInfo new cleanInfoWithChange:false. |
2357 | 393 |
|
2632 | 394 |
"Created: / 07-08-2011 / 15:32:36 / cg" |
2357 | 395 |
! ! |
396 |
||
2715 | 397 |
!InstrumentingCompiler::StatementExecutionInfo class methodsFor:'documentation'! |
398 |
||
399 |
documentation |
|
400 |
" |
|
401 |
(sub)instances of me are updated by instrumented code when statements are executed. |
|
402 |
" |
|
403 |
! ! |
|
404 |
||
2390 | 405 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'accessing'! |
2359 | 406 |
|
407 |
callCount |
|
408 |
^ count |
|
409 |
||
410 |
"Created: / 27-04-2010 / 13:45:15 / cg" |
|
411 |
! |
|
412 |
||
413 |
characterPosition |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
414 |
^ startPosition |
2359 | 415 |
|
416 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
417 |
"Modified: / 28-04-2010 / 15:54:24 / cg" |
2359 | 418 |
! |
419 |
||
420 |
characterPosition:something |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
421 |
startPosition := something. |
2359 | 422 |
|
423 |
"Created: / 23-06-2006 / 13:31:19 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
424 |
"Modified: / 28-04-2010 / 15:54:30 / cg" |
2359 | 425 |
! |
426 |
||
427 |
count |
|
428 |
^ count |
|
429 |
||
430 |
"Created: / 23-06-2006 / 13:31:28 / cg" |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
431 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
432 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
433 |
startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
434 |
^ startPosition |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
435 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
436 |
"Created: / 28-04-2010 / 15:54:26 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
437 |
! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
438 |
|
2390 | 439 |
startPosition:something |
440 |
startPosition := something. |
|
2359 | 441 |
! ! |
442 |
||
2390 | 443 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'cleanup'! |
2359 | 444 |
|
2571 | 445 |
cleanInfoWithChange:withChange |
2569 | 446 |
count := 0. |
2571 | 447 |
withChange ifTrue:[ |
448 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
449 |
]. |
|
2569 | 450 |
|
2570 | 451 |
"Modified: / 20-07-2011 / 17:55:49 / cg" |
2571 | 452 |
"Created: / 20-07-2011 / 18:59:01 / cg" |
2359 | 453 |
! ! |
454 |
||
2390 | 455 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'instrumentation calls'! |
2359 | 456 |
|
457 |
entry:callingContext |
|
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
458 |
"invoked by instrumented code; |
2632 | 459 |
called whenever the block/statment is entered" |
460 |
||
461 |
|context| |
|
2359 | 462 |
|
2632 | 463 |
context := InstrumentationContext current. |
464 |
context isNil ifTrue:[^ self]. |
|
2711 | 465 |
context coverageOnly ifTrue:[ |
466 |
self hasBeenExecuted ifTrue:[^ self]. |
|
467 |
]. |
|
2632 | 468 |
context enabledAndNotInInstrumentedCode ifFalse:[^ self]. |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
469 |
|
2359 | 470 |
count := count + 1. |
471 |
count == 1 ifTrue:[ |
|
2632 | 472 |
"/ the very first time, send a change notification, so the browsers update |
473 |
||
474 |
context inInstrumentedCode:true. |
|
475 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
476 |
context inInstrumentedCode:false. |
|
2359 | 477 |
]. |
478 |
||
479 |
"Created: / 23-06-2006 / 13:31:16 / cg" |
|
2711 | 480 |
"Modified: / 23-08-2011 / 21:29:39 / cg" |
2359 | 481 |
! ! |
482 |
||
2390 | 483 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'queries'! |
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
484 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
485 |
hasBeenExecuted |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
486 |
^ count > 0 |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
487 |
|
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
488 |
"Created: / 28-04-2010 / 14:39:46 / cg" |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
489 |
! ! |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
490 |
|
2632 | 491 |
!InstrumentingCompiler::StatementExecutionInfo methodsFor:'testing'! |
492 |
||
493 |
isStatementExecutionInfo |
|
494 |
^ true |
|
495 |
||
496 |
"Created: / 08-08-2011 / 14:40:51 / cg" |
|
497 |
! ! |
|
498 |
||
2357 | 499 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'accessing'! |
500 |
||
501 |
callingMethodsDo:aBlock |
|
502 |
infoPerReceiverClass notNil ifTrue:[ |
|
503 |
infoPerReceiverClass do:[:each | |
|
504 |
each callingMethodsDo:aBlock |
|
505 |
] |
|
506 |
] |
|
507 |
! |
|
508 |
||
509 |
hasBeenCalled |
|
510 |
^ infoPerReceiverClass notEmptyOrNil |
|
511 |
||
512 |
"Created: / 27-04-2010 / 13:43:15 / cg" |
|
513 |
! |
|
514 |
||
2368 | 515 |
invokedViaPerform |
516 |
^ infoPerReceiverClass contains:[:someInfo | someInfo invokedViaPerform]. |
|
517 |
||
518 |
"Created: / 27-04-2010 / 18:21:56 / cg" |
|
519 |
! |
|
520 |
||
2357 | 521 |
invokingMethods |
522 |
|setOfMethods| |
|
523 |
||
524 |
setOfMethods := IdentitySet new. |
|
525 |
self invokingMethodsDo:[:m | setOfMethods add:m]. |
|
526 |
^ setOfMethods. |
|
527 |
! |
|
528 |
||
529 |
invokingMethodsDo:aBlock |
|
530 |
infoPerReceiverClass isNil ifTrue:[ ^ self]. |
|
531 |
^ infoPerReceiverClass do:[:eachInfo | eachInfo invokingMethodsDo:aBlock]. |
|
532 |
! |
|
533 |
||
534 |
numberOfInvocations |
|
535 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
536 |
^ infoPerReceiverClass inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
537 |
! |
|
538 |
||
539 |
numberOfInvocationsFromExternalOf:aClass |
|
540 |
|sum| |
|
541 |
||
542 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
543 |
||
544 |
sum := 0. |
|
545 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
546 |
sum := sum + (info numberOfInvocationsFromExternalOf:aClass) |
|
547 |
]. |
|
548 |
^ sum |
|
549 |
! |
|
550 |
||
551 |
numberOfInvocationsFromInternalOf:aClass |
|
552 |
|sum| |
|
553 |
||
554 |
infoPerReceiverClass isNil ifTrue:[ ^ 0]. |
|
555 |
||
556 |
sum := 0. |
|
557 |
infoPerReceiverClass keysAndValuesDo:[:recClass :info | |
|
558 |
sum := sum + (info numberOfInvocationsFromInternalOf:aClass) |
|
559 |
]. |
|
560 |
^ sum |
|
561 |
! ! |
|
562 |
||
563 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'cleanup'! |
|
564 |
||
2571 | 565 |
cleanInfoWithChange:withChange |
2357 | 566 |
infoPerReceiverClass := nil. |
2571 | 567 |
withChange ifTrue:[ |
568 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
569 |
] |
|
2569 | 570 |
|
2570 | 571 |
"Modified: / 20-07-2011 / 17:55:35 / cg" |
2571 | 572 |
"Created: / 20-07-2011 / 18:59:22 / cg" |
2357 | 573 |
! ! |
574 |
||
575 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'instrumentation probe calls'! |
|
576 |
||
577 |
entry:aContext |
|
578 |
"invoked by instrumented compiled code, upon method entry" |
|
579 |
||
2632 | 580 |
|context receiversClass infoPerReceiver firstEntry| |
2357 | 581 |
|
2632 | 582 |
context := InstrumentationContext current. |
583 |
context isNil ifTrue:[^ self]. |
|
584 |
context enabledAndNotInInstrumentedCode ifFalse:[^ self]. |
|
585 |
context inInstrumentedCode:true. |
|
586 |
||
2875 | 587 |
context coverageOnly ifTrue:[ |
588 |
self hasBeenCalled ifTrue:[^ self]. |
|
589 |
infoPerReceiverClass := #(). |
|
2632 | 590 |
firstEntry := true. |
2875 | 591 |
] ifFalse:[ |
592 |
receiversClass := aContext receiver class. |
|
593 |
firstEntry := false. |
|
594 |
||
595 |
infoPerReceiverClass isNil ifTrue:[ |
|
596 |
infoPerReceiverClass := IdentityDictionary new. |
|
597 |
firstEntry := true. |
|
598 |
]. |
|
599 |
infoPerReceiver := infoPerReceiverClass |
|
600 |
at:receiversClass |
|
601 |
ifAbsentPut:[MethodInvocationInfoPerReceiverClass new]. |
|
602 |
infoPerReceiver entry:aContext. |
|
2632 | 603 |
]. |
2569 | 604 |
|
2632 | 605 |
"/ the very first time, send a change notification, so the browsers update |
606 |
firstEntry ifTrue:[ |
|
607 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
608 |
]. |
|
2711 | 609 |
self changeClassTo:(InstrumentingCompiler::MethodInvocationInfoInAlreadyEnteredState). |
2632 | 610 |
context inInstrumentedCode:false. |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
611 |
|
2875 | 612 |
"Modified: / 05-06-2012 / 23:51:53 / cg" |
2632 | 613 |
! ! |
614 |
||
615 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'testing'! |
|
616 |
||
617 |
isMethodInvocationInfo |
|
618 |
^ true |
|
619 |
||
620 |
"Created: / 08-08-2011 / 14:37:58 / cg" |
|
2357 | 621 |
! ! |
622 |
||
623 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'accessing'! |
|
624 |
||
625 |
callingMethodsDo:aBlock |
|
626 |
infoPerSendingMethod keysAndValuesDo:[:m :eachInfo | |
|
627 |
aBlock value:m |
|
628 |
] |
|
629 |
! |
|
630 |
||
2368 | 631 |
invokedViaPerform |
632 |
^ infoPerSendingMethod contains:[:someInfo | someInfo invokedViaPerform]. |
|
633 |
||
634 |
"Created: / 27-04-2010 / 18:21:36 / cg" |
|
635 |
! |
|
636 |
||
2357 | 637 |
invokingMethodsDo:aBlock |
638 |
infoPerSendingMethod isNil ifTrue:[ ^ self]. |
|
639 |
^ infoPerSendingMethod keysDo:aBlock. |
|
640 |
! |
|
641 |
||
642 |
numberOfInvocations |
|
643 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
644 |
^ infoPerSendingMethod inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
645 |
! |
|
646 |
||
647 |
numberOfInvocationsFromExternalOf:aClass |
|
648 |
|sum| |
|
649 |
||
650 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
651 |
||
652 |
sum := 0. |
|
653 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
654 |
|sendingMethodsClass| |
|
655 |
||
656 |
sendingMethodsClass := sendingMethod mclass. |
|
657 |
sendingMethodsClass notNil ifTrue:[ |
|
658 |
((sendingMethodsClass isSubclassOf:aClass) |
|
659 |
or:[(aClass isSubclassOf:sendingMethodsClass )]) ifFalse:[ |
|
660 |
sum := sum + (info numberOfInvocations) |
|
661 |
] |
|
662 |
] |
|
663 |
]. |
|
664 |
^ sum |
|
665 |
! |
|
666 |
||
667 |
numberOfInvocationsFromInternalOf:aClass |
|
668 |
|sum| |
|
669 |
||
670 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
671 |
||
672 |
sum := 0. |
|
673 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
674 |
|sendingMethodsClass| |
|
675 |
||
676 |
sendingMethodsClass := sendingMethod mclass. |
|
677 |
sendingMethodsClass notNil ifTrue:[ |
|
678 |
((sendingMethodsClass isSubclassOf:aClass) |
|
679 |
or:[(aClass isSubclassOf:sendingMethodsClass)]) ifTrue:[ |
|
680 |
sum := sum + (info numberOfInvocations) |
|
681 |
] |
|
682 |
] |
|
683 |
]. |
|
684 |
^ sum |
|
685 |
! ! |
|
686 |
||
687 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'! |
|
688 |
||
689 |
entry:aContext |
|
690 |
"invoked by instrumented compiled code, upon method entry" |
|
691 |
||
2368 | 692 |
|sender sendingMethod infoPerMethod viaPerform| |
2357 | 693 |
|
2391 | 694 |
aContext selector == #doesNotUnderstand: ifTrue:[ |
695 |
sender := aContext sender sender methodHome. |
|
696 |
] ifFalse:[ |
|
697 |
sender := aContext sender methodHome. |
|
698 |
]. |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
699 |
sender isNil ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
700 |
^ self. |
2569 | 701 |
]. |
702 |
sendingMethod := sender method. |
|
703 |
sendingMethod isNil ifTrue:[^ self]. |
|
2391 | 704 |
|
2569 | 705 |
viaPerform := false. |
706 |
(sendingMethod mclass == Object |
|
707 |
and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[ |
|
708 |
"/ Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix). |
|
709 |
sender := sender sender methodHome. |
|
710 |
sendingMethod := sender method. |
|
711 |
viaPerform := true. |
|
2357 | 712 |
]. |
713 |
||
714 |
infoPerSendingMethod isNil ifTrue:[ |
|
715 |
infoPerSendingMethod := IdentityDictionary new. |
|
716 |
]. |
|
717 |
infoPerMethod := infoPerSendingMethod |
|
718 |
at:sendingMethod |
|
719 |
ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ]. |
|
720 |
||
2368 | 721 |
infoPerMethod entry:aContext viaPerform:viaPerform |
722 |
||
2569 | 723 |
"Modified: / 20-07-2011 / 17:26:31 / cg" |
2357 | 724 |
! ! |
725 |
||
726 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'! |
|
727 |
||
2368 | 728 |
invokedViaPerform |
729 |
^ invokedViaPerform ? false |
|
730 |
||
731 |
"Created: / 27-04-2010 / 18:20:05 / cg" |
|
732 |
! |
|
733 |
||
2357 | 734 |
numberOfInvocations |
735 |
countPerSendersClass isNil ifTrue:[ ^ 0]. |
|
736 |
^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] |
|
737 |
! ! |
|
738 |
||
739 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'! |
|
740 |
||
2368 | 741 |
entry:aContext viaPerform:viaPerformBoolean |
2357 | 742 |
"invoked by instrumented compiled code, upon method entry" |
743 |
||
744 |
|sendersClass count| |
|
745 |
||
746 |
sendersClass := aContext sender receiver class. |
|
747 |
||
748 |
countPerSendersClass isNil ifTrue:[ |
|
749 |
countPerSendersClass := IdentityDictionary new. |
|
750 |
]. |
|
751 |
count := countPerSendersClass at:sendersClass ifAbsentPut:0. |
|
2368 | 752 |
countPerSendersClass at:sendersClass put:(count + 1). |
753 |
viaPerformBoolean ifTrue:[ invokedViaPerform := true ]. |
|
754 |
||
755 |
"Created: / 27-04-2010 / 18:17:27 / cg" |
|
2357 | 756 |
! ! |
757 |
||
2711 | 758 |
!InstrumentingCompiler::MethodInvocationInfoInAlreadyEnteredState methodsFor:'cleanup'! |
759 |
||
760 |
cleanInfoWithChange:withChange |
|
761 |
self changeClassTo:InstrumentingCompiler::MethodInvocationInfo. |
|
762 |
infoPerReceiverClass := nil. |
|
763 |
withChange ifTrue:[ |
|
764 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
765 |
] |
|
766 |
||
767 |
"Modified: / 20-07-2011 / 17:55:35 / cg" |
|
768 |
"Created: / 24-08-2011 / 11:10:29 / cg" |
|
769 |
! ! |
|
770 |
||
2715 | 771 |
!InstrumentingCompiler::VariableAccessExecutionInfo class methodsFor:'documentation'! |
772 |
||
773 |
documentation |
|
774 |
" |
|
775 |
(sub)instances of me are updated by instrumented code when a variable is accessed |
|
776 |
" |
|
777 |
! ! |
|
778 |
||
779 |
!InstrumentingCompiler::BlockExecutionInfo class methodsFor:'documentation'! |
|
780 |
||
781 |
documentation |
|
782 |
" |
|
783 |
(sub)instances of me are updated by instrumented code when a block is executed. |
|
784 |
" |
|
785 |
! ! |
|
786 |
||
2390 | 787 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'accessing'! |
788 |
||
789 |
endPosition |
|
790 |
^ endPosition |
|
791 |
||
792 |
"Created: / 28-04-2010 / 15:57:14 / cg" |
|
793 |
! |
|
794 |
||
795 |
startPosition:startArg endPosition:endArg |
|
796 |
startPosition := startArg. |
|
797 |
endPosition := endArg. |
|
798 |
||
799 |
"Created: / 28-04-2010 / 15:54:47 / cg" |
|
800 |
! ! |
|
801 |
||
2675
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
802 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'printing'! |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
803 |
|
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
804 |
printOn:aStream |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
805 |
aStream nextPutAll:'['. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
806 |
startPosition printOn:aStream. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
807 |
aStream nextPutAll:'...'. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
808 |
endPosition printOn:aStream. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
809 |
aStream nextPutAll:']'. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
810 |
|
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
811 |
"Created: / 21-08-2011 / 14:02:01 / cg" |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
812 |
! ! |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
813 |
|
2632 | 814 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'testing'! |
815 |
||
816 |
isBlockExecutionInfo |
|
817 |
^ true |
|
818 |
||
819 |
"Created: / 07-08-2011 / 17:06:39 / cg" |
|
820 |
! ! |
|
821 |
||
2715 | 822 |
!InstrumentingCompiler::ReadAccessExecutionInfo class methodsFor:'documentation'! |
823 |
||
824 |
documentation |
|
825 |
" |
|
826 |
(sub)instances of me are updated by instrumented code when a variable is read |
|
827 |
" |
|
828 |
! ! |
|
829 |
||
830 |
!InstrumentingCompiler::WriteAccessExecutionInfo class methodsFor:'documentation'! |
|
831 |
||
832 |
documentation |
|
833 |
" |
|
834 |
(sub)instances of me are updated by instrumented code when a variable is written |
|
835 |
" |
|
836 |
! ! |
|
837 |
||
2357 | 838 |
!InstrumentingCompiler class methodsFor:'documentation'! |
839 |
||
2570 | 840 |
version |
2875 | 841 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.18 2012-06-05 21:53:04 cg Exp $' |
2570 | 842 |
! |
843 |
||
2357 | 844 |
version_CVS |
2875 | 845 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.18 2012-06-05 21:53:04 cg Exp $' |
2357 | 846 |
! ! |