author | Jan Vrany <jan.vrany@fit.cvut.cz> |
Fri, 04 May 2012 15:07:47 +0200 | |
changeset 2866 | 21be09ac87b1 |
parent 2715 | 10a744f8ce68 |
child 2875 | f7f46f53bc84 |
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]. |
|
2711 | 584 |
context coverageOnly ifTrue:[ |
585 |
self hasBeenCalled ifTrue:[^ self]. |
|
586 |
]. |
|
2632 | 587 |
context enabledAndNotInInstrumentedCode ifFalse:[^ self]. |
588 |
context inInstrumentedCode:true. |
|
589 |
||
590 |
receiversClass := aContext receiver class. |
|
591 |
firstEntry := false. |
|
2569 | 592 |
|
2632 | 593 |
infoPerReceiverClass isNil ifTrue:[ |
594 |
infoPerReceiverClass := IdentityDictionary new. |
|
595 |
firstEntry := true. |
|
596 |
]. |
|
597 |
infoPerReceiver := infoPerReceiverClass |
|
598 |
at:receiversClass |
|
599 |
ifAbsentPut:[MethodInvocationInfoPerReceiverClass new]. |
|
600 |
infoPerReceiver entry:aContext. |
|
2569 | 601 |
|
2632 | 602 |
"/ the very first time, send a change notification, so the browsers update |
603 |
firstEntry ifTrue:[ |
|
604 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
605 |
]. |
|
2711 | 606 |
self changeClassTo:(InstrumentingCompiler::MethodInvocationInfoInAlreadyEnteredState). |
2632 | 607 |
context inInstrumentedCode:false. |
2528
e57cc8caf6f9
dont instrument the instrumentation code
Claus Gittinger <cg@exept.de>
parents:
2391
diff
changeset
|
608 |
|
2711 | 609 |
"Modified: / 24-08-2011 / 11:12:06 / cg" |
2632 | 610 |
! ! |
611 |
||
612 |
!InstrumentingCompiler::MethodInvocationInfo methodsFor:'testing'! |
|
613 |
||
614 |
isMethodInvocationInfo |
|
615 |
^ true |
|
616 |
||
617 |
"Created: / 08-08-2011 / 14:37:58 / cg" |
|
2357 | 618 |
! ! |
619 |
||
620 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'accessing'! |
|
621 |
||
622 |
callingMethodsDo:aBlock |
|
623 |
infoPerSendingMethod keysAndValuesDo:[:m :eachInfo | |
|
624 |
aBlock value:m |
|
625 |
] |
|
626 |
! |
|
627 |
||
2368 | 628 |
invokedViaPerform |
629 |
^ infoPerSendingMethod contains:[:someInfo | someInfo invokedViaPerform]. |
|
630 |
||
631 |
"Created: / 27-04-2010 / 18:21:36 / cg" |
|
632 |
! |
|
633 |
||
2357 | 634 |
invokingMethodsDo:aBlock |
635 |
infoPerSendingMethod isNil ifTrue:[ ^ self]. |
|
636 |
^ infoPerSendingMethod keysDo:aBlock. |
|
637 |
! |
|
638 |
||
639 |
numberOfInvocations |
|
640 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
641 |
^ infoPerSendingMethod inject:0 into:[:sumSoFar :info | sumSoFar + info numberOfInvocations] |
|
642 |
! |
|
643 |
||
644 |
numberOfInvocationsFromExternalOf:aClass |
|
645 |
|sum| |
|
646 |
||
647 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
648 |
||
649 |
sum := 0. |
|
650 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
651 |
|sendingMethodsClass| |
|
652 |
||
653 |
sendingMethodsClass := sendingMethod mclass. |
|
654 |
sendingMethodsClass notNil ifTrue:[ |
|
655 |
((sendingMethodsClass isSubclassOf:aClass) |
|
656 |
or:[(aClass isSubclassOf:sendingMethodsClass )]) ifFalse:[ |
|
657 |
sum := sum + (info numberOfInvocations) |
|
658 |
] |
|
659 |
] |
|
660 |
]. |
|
661 |
^ sum |
|
662 |
! |
|
663 |
||
664 |
numberOfInvocationsFromInternalOf:aClass |
|
665 |
|sum| |
|
666 |
||
667 |
infoPerSendingMethod isNil ifTrue:[ ^ 0]. |
|
668 |
||
669 |
sum := 0. |
|
670 |
infoPerSendingMethod keysAndValuesDo:[:sendingMethod :info | |
|
671 |
|sendingMethodsClass| |
|
672 |
||
673 |
sendingMethodsClass := sendingMethod mclass. |
|
674 |
sendingMethodsClass notNil ifTrue:[ |
|
675 |
((sendingMethodsClass isSubclassOf:aClass) |
|
676 |
or:[(aClass isSubclassOf:sendingMethodsClass)]) ifTrue:[ |
|
677 |
sum := sum + (info numberOfInvocations) |
|
678 |
] |
|
679 |
] |
|
680 |
]. |
|
681 |
^ sum |
|
682 |
! ! |
|
683 |
||
684 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass methodsFor:'instrumentation calls'! |
|
685 |
||
686 |
entry:aContext |
|
687 |
"invoked by instrumented compiled code, upon method entry" |
|
688 |
||
2368 | 689 |
|sender sendingMethod infoPerMethod viaPerform| |
2357 | 690 |
|
2391 | 691 |
aContext selector == #doesNotUnderstand: ifTrue:[ |
692 |
sender := aContext sender sender methodHome. |
|
693 |
] ifFalse:[ |
|
694 |
sender := aContext sender methodHome. |
|
695 |
]. |
|
2370
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
696 |
sender isNil ifTrue:[ |
a801cc4df234
added: #blockNodeRewriteHookFor:
Claus Gittinger <cg@exept.de>
parents:
2368
diff
changeset
|
697 |
^ self. |
2569 | 698 |
]. |
699 |
sendingMethod := sender method. |
|
700 |
sendingMethod isNil ifTrue:[^ self]. |
|
2391 | 701 |
|
2569 | 702 |
viaPerform := false. |
703 |
(sendingMethod mclass == Object |
|
704 |
and:[ sendingMethod selector startsWith:'perform:'] ) ifTrue:[ |
|
705 |
"/ Transcript showCR:('%1 [info]: skipping #perform' bindWith:self class nameWithoutPrefix). |
|
706 |
sender := sender sender methodHome. |
|
707 |
sendingMethod := sender method. |
|
708 |
viaPerform := true. |
|
2357 | 709 |
]. |
710 |
||
711 |
infoPerSendingMethod isNil ifTrue:[ |
|
712 |
infoPerSendingMethod := IdentityDictionary new. |
|
713 |
]. |
|
714 |
infoPerMethod := infoPerSendingMethod |
|
715 |
at:sendingMethod |
|
716 |
ifAbsentPut:[ MethodInvocationInfoPerSendingMethod new ]. |
|
717 |
||
2368 | 718 |
infoPerMethod entry:aContext viaPerform:viaPerform |
719 |
||
2569 | 720 |
"Modified: / 20-07-2011 / 17:26:31 / cg" |
2357 | 721 |
! ! |
722 |
||
723 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'accessing'! |
|
724 |
||
2368 | 725 |
invokedViaPerform |
726 |
^ invokedViaPerform ? false |
|
727 |
||
728 |
"Created: / 27-04-2010 / 18:20:05 / cg" |
|
729 |
! |
|
730 |
||
2357 | 731 |
numberOfInvocations |
732 |
countPerSendersClass isNil ifTrue:[ ^ 0]. |
|
733 |
^ countPerSendersClass inject:0 into:[:sumSoFar :count | sumSoFar + count] |
|
734 |
! ! |
|
735 |
||
736 |
!InstrumentingCompiler::MethodInvocationInfo::MethodInvocationInfoPerReceiverClass::MethodInvocationInfoPerSendingMethod methodsFor:'instrumentation calls'! |
|
737 |
||
2368 | 738 |
entry:aContext viaPerform:viaPerformBoolean |
2357 | 739 |
"invoked by instrumented compiled code, upon method entry" |
740 |
||
741 |
|sendersClass count| |
|
742 |
||
743 |
sendersClass := aContext sender receiver class. |
|
744 |
||
745 |
countPerSendersClass isNil ifTrue:[ |
|
746 |
countPerSendersClass := IdentityDictionary new. |
|
747 |
]. |
|
748 |
count := countPerSendersClass at:sendersClass ifAbsentPut:0. |
|
2368 | 749 |
countPerSendersClass at:sendersClass put:(count + 1). |
750 |
viaPerformBoolean ifTrue:[ invokedViaPerform := true ]. |
|
751 |
||
752 |
"Created: / 27-04-2010 / 18:17:27 / cg" |
|
2357 | 753 |
! ! |
754 |
||
2711 | 755 |
!InstrumentingCompiler::MethodInvocationInfoInAlreadyEnteredState methodsFor:'cleanup'! |
756 |
||
757 |
cleanInfoWithChange:withChange |
|
758 |
self changeClassTo:InstrumentingCompiler::MethodInvocationInfo. |
|
759 |
infoPerReceiverClass := nil. |
|
760 |
withChange ifTrue:[ |
|
761 |
Smalltalk changed:#methodCoverageInfo with:owningMethod. |
|
762 |
] |
|
763 |
||
764 |
"Modified: / 20-07-2011 / 17:55:35 / cg" |
|
765 |
"Created: / 24-08-2011 / 11:10:29 / cg" |
|
766 |
! ! |
|
767 |
||
2715 | 768 |
!InstrumentingCompiler::VariableAccessExecutionInfo class methodsFor:'documentation'! |
769 |
||
770 |
documentation |
|
771 |
" |
|
772 |
(sub)instances of me are updated by instrumented code when a variable is accessed |
|
773 |
" |
|
774 |
! ! |
|
775 |
||
776 |
!InstrumentingCompiler::BlockExecutionInfo class methodsFor:'documentation'! |
|
777 |
||
778 |
documentation |
|
779 |
" |
|
780 |
(sub)instances of me are updated by instrumented code when a block is executed. |
|
781 |
" |
|
782 |
! ! |
|
783 |
||
2390 | 784 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'accessing'! |
785 |
||
786 |
endPosition |
|
787 |
^ endPosition |
|
788 |
||
789 |
"Created: / 28-04-2010 / 15:57:14 / cg" |
|
790 |
! |
|
791 |
||
792 |
startPosition:startArg endPosition:endArg |
|
793 |
startPosition := startArg. |
|
794 |
endPosition := endArg. |
|
795 |
||
796 |
"Created: / 28-04-2010 / 15:54:47 / cg" |
|
797 |
! ! |
|
798 |
||
2675
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
799 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'printing'! |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
800 |
|
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
801 |
printOn:aStream |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
802 |
aStream nextPutAll:'['. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
803 |
startPosition printOn:aStream. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
804 |
aStream nextPutAll:'...'. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
805 |
endPosition printOn:aStream. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
806 |
aStream nextPutAll:']'. |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
807 |
|
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
808 |
"Created: / 21-08-2011 / 14:02:01 / cg" |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
809 |
! ! |
3e8368ea406e
comment/format in: #addBlockCounterTo:
Claus Gittinger <cg@exept.de>
parents:
2665
diff
changeset
|
810 |
|
2632 | 811 |
!InstrumentingCompiler::BlockExecutionInfo methodsFor:'testing'! |
812 |
||
813 |
isBlockExecutionInfo |
|
814 |
^ true |
|
815 |
||
816 |
"Created: / 07-08-2011 / 17:06:39 / cg" |
|
817 |
! ! |
|
818 |
||
2715 | 819 |
!InstrumentingCompiler::ReadAccessExecutionInfo class methodsFor:'documentation'! |
820 |
||
821 |
documentation |
|
822 |
" |
|
823 |
(sub)instances of me are updated by instrumented code when a variable is read |
|
824 |
" |
|
825 |
! ! |
|
826 |
||
827 |
!InstrumentingCompiler::WriteAccessExecutionInfo class methodsFor:'documentation'! |
|
828 |
||
829 |
documentation |
|
830 |
" |
|
831 |
(sub)instances of me are updated by instrumented code when a variable is written |
|
832 |
" |
|
833 |
! ! |
|
834 |
||
2357 | 835 |
!InstrumentingCompiler class methodsFor:'documentation'! |
836 |
||
2570 | 837 |
version |
2715 | 838 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.17 2011-09-30 10:29:09 cg Exp $' |
2570 | 839 |
! |
840 |
||
2357 | 841 |
version_CVS |
2715 | 842 |
^ '$Header: /cvs/stx/stx/libcomp/InstrumentingCompiler.st,v 1.17 2011-09-30 10:29:09 cg Exp $' |
2357 | 843 |
! ! |