1
|
1 |
"
|
5
|
2 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
3 |
All Rights Reserved
|
|
4 |
|
|
5 |
This software is furnished under a license and may be used
|
|
6 |
only in accordance with the terms of that license and with the
|
|
7 |
inclusion of the above copyright notice. This software may not
|
|
8 |
be provided or otherwise made available to, or used by, any
|
|
9 |
other person. No title to or ownership of the software is
|
|
10 |
hereby transferred.
|
|
11 |
"
|
|
12 |
|
|
13 |
Object subclass:#ObjectMemory
|
|
14 |
instanceVariableNames:''
|
2
|
15 |
classVariableNames:'InternalErrorHandler UserInterruptHandler TimerInterruptHandler
|
|
16 |
SpyInterruptHandler StepInterruptHandler ExceptionInterruptHandler
|
|
17 |
ErrorInterruptHandler MemoryInterruptHandler SignalInterruptHandler
|
|
18 |
ChildSignalInterruptHandler DisposeInterruptHandler
|
|
19 |
RecursionInterruptHandler IOInterruptHandler
|
85
|
20 |
CustomInterruptHandler
|
2
|
21 |
|
|
22 |
AllocationFailureSignal
|
10
|
23 |
IncrementalGCLimit
|
77
|
24 |
Dependents
|
|
25 |
ImageName'
|
1
|
26 |
poolDictionaries:''
|
|
27 |
category:'System-Support'
|
|
28 |
!
|
|
29 |
|
|
30 |
ObjectMemory comment:'
|
5
|
31 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
1
|
32 |
All Rights Reserved
|
2
|
33 |
'!
|
|
34 |
|
|
35 |
!ObjectMemory class methodsFor:'documentation'!
|
|
36 |
|
88
|
37 |
copyright
|
|
38 |
"
|
|
39 |
COPYRIGHT (c) 1992 by Claus Gittinger
|
|
40 |
All Rights Reserved
|
|
41 |
|
|
42 |
This software is furnished under a license and may be used
|
|
43 |
only in accordance with the terms of that license and with the
|
|
44 |
inclusion of the above copyright notice. This software may not
|
|
45 |
be provided or otherwise made available to, or used by, any
|
|
46 |
other person. No title to or ownership of the software is
|
|
47 |
hereby transferred.
|
|
48 |
"
|
|
49 |
!
|
|
50 |
|
|
51 |
version
|
|
52 |
"
|
|
53 |
$Header: /cvs/stx/stx/libbasic/Attic/ObjMem.st,v 1.12 1994-06-02 16:21:03 claus Exp $
|
|
54 |
"
|
|
55 |
!
|
|
56 |
|
2
|
57 |
documentation
|
|
58 |
"
|
68
|
59 |
This class contains access methods to the system memory -
|
|
60 |
in previous versions this stuff used to be in the Smalltalk class.
|
|
61 |
It has been separated for better overall structure.
|
1
|
62 |
|
68
|
63 |
Many methods here are for debuging purposes only, and not standard.
|
|
64 |
Do not depend on them being there - some may vanish ...
|
|
65 |
(especially those, that depend on a specific GC implementation)
|
13
|
66 |
|
68
|
67 |
kludge:
|
|
68 |
The InterruptHandler variables are known by the runtime system -
|
|
69 |
they are the objects that get an interrupt message when the event
|
|
70 |
occurs.
|
2
|
71 |
|
68
|
72 |
ClassVariables:
|
2
|
73 |
|
68
|
74 |
InternalErrorHandler gets informed, when some runtime error occurs
|
|
75 |
(usually fatal)
|
2
|
76 |
|
68
|
77 |
UserInterruptHandler gets informed when CNTL-C is pressed
|
|
78 |
TimerInterruptHandler gets alarm timer interrupts
|
|
79 |
SpyInterruptHandler another alarm timer
|
|
80 |
StepInterruptHandler gets single step interrupts
|
|
81 |
ExceptionInterruptHandler gets floating point exceptions
|
|
82 |
ErrorInterruptHandler gets graphic device errors
|
|
83 |
MemoryInterruptHandler gets soon-out-of-memory conditions
|
|
84 |
SignalInterruptHandler gets unix signals
|
|
85 |
ChildSignalInterruptHandler gets child death signals
|
|
86 |
DisposeInterruptHandler gets informed, when an object is disposed from
|
|
87 |
a shadowArray
|
|
88 |
RecursionInterruptHandler gets recursion limit violations
|
85
|
89 |
IOInterruptHandler gets SIGIO unix signals
|
|
90 |
CustomInterruptHandler gets custom interrupts
|
2
|
91 |
|
68
|
92 |
AllocationFailureSignal signal raised when a new fails (see Behavior)
|
|
93 |
IngrementalGCLimit number of bytes, that must be allocated since
|
|
94 |
last full garbage collect to turn on incremental
|
|
95 |
collector.
|
|
96 |
Dependents keep my dependents locally (its faster) for
|
|
97 |
all those registries
|
2
|
98 |
"
|
|
99 |
! !
|
|
100 |
|
|
101 |
!ObjectMemory class methodsFor:'initialization'!
|
|
102 |
|
|
103 |
initialize
|
|
104 |
AllocationFailureSignal isNil ifTrue:[
|
|
105 |
AllocationFailureSignal := (Signal new) mayProceed:true.
|
|
106 |
AllocationFailureSignal notifierString:'allocation failure'.
|
|
107 |
].
|
|
108 |
IncrementalGCLimit := 500000.
|
13
|
109 |
MemoryInterruptHandler := self
|
2
|
110 |
! !
|
|
111 |
|
|
112 |
!ObjectMemory class methodsFor:'signal access'!
|
|
113 |
|
|
114 |
allocationFailureSignal
|
13
|
115 |
"return the signal raised when an object allocation failed"
|
|
116 |
|
2
|
117 |
^ AllocationFailureSignal
|
|
118 |
! !
|
1
|
119 |
|
10
|
120 |
!ObjectMemory class methodsFor:'dependents access'!
|
|
121 |
|
|
122 |
dependents
|
|
123 |
"return the colleciton of my dependents"
|
|
124 |
|
|
125 |
^ Dependents
|
|
126 |
!
|
|
127 |
|
|
128 |
dependents:aCollection
|
|
129 |
"set the dependents collection"
|
|
130 |
|
|
131 |
Dependents := aCollection
|
|
132 |
! !
|
|
133 |
|
1
|
134 |
!ObjectMemory class methodsFor:'cache management'!
|
|
135 |
|
|
136 |
flushInlineCachesForClass:aClass
|
|
137 |
"flush inlinecaches for calls to aClass"
|
|
138 |
|
|
139 |
%{ /* NOCONTEXT */
|
|
140 |
__flushInlineCachesFor(aClass);
|
|
141 |
%}
|
|
142 |
!
|
|
143 |
|
|
144 |
flushInlineCachesWithArgs:nargs
|
|
145 |
"flush inlinecaches for calls with nargs arguments"
|
|
146 |
|
|
147 |
%{ /* NOCONTEXT */
|
|
148 |
__flushInlineCaches(_intVal(nargs));
|
|
149 |
%}
|
|
150 |
!
|
|
151 |
|
|
152 |
flushInlineCachesFor:aClass withArgs:nargs
|
|
153 |
"flush inlinecaches for calls to aClass with nargs arguments"
|
|
154 |
|
|
155 |
%{ /* NOCONTEXT */
|
|
156 |
__flushInlineCachesForAndNargs(aClass, _intVal(nargs));
|
|
157 |
%}
|
|
158 |
!
|
|
159 |
|
|
160 |
flushInlineCaches
|
|
161 |
"flush all inlinecaches"
|
|
162 |
|
|
163 |
%{ /* NOCONTEXT */
|
|
164 |
__flushAllInlineCaches();
|
|
165 |
%}
|
|
166 |
!
|
|
167 |
|
|
168 |
flushMethodCacheFor:aClass
|
|
169 |
"flush the method cache for sends to aClass"
|
|
170 |
|
|
171 |
%{ /* NOCONTEXT */
|
|
172 |
__flushMethodCacheFor(aClass);
|
|
173 |
%}
|
|
174 |
!
|
|
175 |
|
|
176 |
flushMethodCache
|
|
177 |
"flush the method cache"
|
|
178 |
|
|
179 |
%{ /* NOCONTEXT */
|
|
180 |
__flushMethodCache();
|
|
181 |
%}
|
|
182 |
!
|
|
183 |
|
2
|
184 |
flushCachesFor:aClass
|
|
185 |
"flush method and inline caches for aClass"
|
|
186 |
|
|
187 |
%{ /* NOCONTEXT */
|
|
188 |
__flushMethodCacheFor(aClass);
|
|
189 |
__flushInlineCachesFor(aClass);
|
|
190 |
%}
|
|
191 |
!
|
|
192 |
|
1
|
193 |
flushCaches
|
2
|
194 |
"flush method and inline caches for all classes"
|
1
|
195 |
|
|
196 |
%{ /* NOCONTEXT */
|
|
197 |
__flushMethodCache();
|
|
198 |
__flushAllInlineCaches();
|
|
199 |
%}
|
|
200 |
! !
|
|
201 |
|
|
202 |
!ObjectMemory class methodsFor:'enumeration'!
|
|
203 |
|
|
204 |
allObjectsDo:aBlock
|
85
|
205 |
"evaluate the argument, aBlock for all objects in the system.
|
|
206 |
There is one caveat: if a compressing oldSpace collect
|
|
207 |
occurs while looping over the objects, the loop cannot be
|
|
208 |
continued (for some internal reasons). In this case, false
|
|
209 |
is returned."
|
2
|
210 |
|
|
211 |
|work|
|
22
|
212 |
|
|
213 |
%{ /* NOREGISTER - work may not be placed into a register here */
|
2
|
214 |
nonTenuringScavenge(__context);
|
|
215 |
/*
|
|
216 |
* allObjectsDo needs a temporary to hold newSpace objects
|
|
217 |
*/
|
85
|
218 |
if (__allObjectsDo(&aBlock, &work COMMA_CON) < 0) {
|
|
219 |
RETURN (false);
|
|
220 |
}
|
|
221 |
%}.
|
|
222 |
^ true
|
2
|
223 |
!
|
|
224 |
|
|
225 |
allOldObjectsDo:aBlock
|
|
226 |
"evaluate the argument, aBlock for all old objects in the system.
|
|
227 |
For debugging and tests only - do not use"
|
|
228 |
%{
|
85
|
229 |
if (__allObjectsDo(&aBlock, (OBJ *)0 COMMA_CON) < 0) {
|
|
230 |
RETURN (false);
|
|
231 |
}
|
|
232 |
%}.
|
|
233 |
^ true
|
1
|
234 |
! !
|
|
235 |
|
2
|
236 |
!ObjectMemory class methodsFor:'handler access'!
|
|
237 |
|
|
238 |
internalErrorHandler
|
13
|
239 |
"return the handler for ST/X internal errors.
|
|
240 |
An internal error is reported for example when a methods
|
|
241 |
bytecode is not a ByteArray, the selector table is not an Array
|
|
242 |
etc. Those should not occur in normal circumstances."
|
|
243 |
|
2
|
244 |
^ InternalErrorHandler
|
|
245 |
!
|
|
246 |
|
|
247 |
userInterruptHandler
|
13
|
248 |
"return the handler for CNTL-C interrupt handling"
|
|
249 |
|
2
|
250 |
^ UserInterruptHandler
|
|
251 |
!
|
|
252 |
|
|
253 |
userInterruptHandler:aHandler
|
13
|
254 |
"set the handler for CNTL-C interrupt handling"
|
|
255 |
|
2
|
256 |
UserInterruptHandler := aHandler
|
|
257 |
!
|
|
258 |
|
|
259 |
timerInterruptHandler
|
13
|
260 |
"return the handler for timer interrupts"
|
|
261 |
|
2
|
262 |
^ TimerInterruptHandler
|
|
263 |
!
|
|
264 |
|
10
|
265 |
timerInterruptHandler:aHandler
|
13
|
266 |
"set the handler for timer interrupts"
|
|
267 |
|
10
|
268 |
TimerInterruptHandler := aHandler
|
|
269 |
!
|
|
270 |
|
2
|
271 |
spyInterruptHandler
|
13
|
272 |
"return the handler for spy-timer interrupts"
|
|
273 |
|
2
|
274 |
^ SpyInterruptHandler
|
|
275 |
!
|
|
276 |
|
|
277 |
spyInterruptHandler:aHandler
|
13
|
278 |
"set the handler for spy-timer interrupts"
|
|
279 |
|
2
|
280 |
SpyInterruptHandler := aHandler
|
|
281 |
!
|
|
282 |
|
|
283 |
stepInterruptHandler
|
13
|
284 |
"return the handler for single step interrupts"
|
|
285 |
|
2
|
286 |
^ StepInterruptHandler
|
|
287 |
!
|
|
288 |
|
|
289 |
stepInterruptHandler:aHandler
|
13
|
290 |
"set the handler for single step interrupts"
|
|
291 |
|
2
|
292 |
StepInterruptHandler := aHandler
|
|
293 |
!
|
|
294 |
|
|
295 |
exceptionInterruptHandler
|
13
|
296 |
"return the handler for floating point exception interrupts"
|
|
297 |
|
2
|
298 |
^ ExceptionInterruptHandler
|
|
299 |
!
|
|
300 |
|
|
301 |
errorInterruptHandler
|
13
|
302 |
"return the handler for display error interrupts"
|
|
303 |
|
2
|
304 |
^ ErrorInterruptHandler
|
|
305 |
!
|
|
306 |
|
|
307 |
errorInterruptHandler:aHandler
|
13
|
308 |
"set the handler for display error interrupts"
|
|
309 |
|
2
|
310 |
ErrorInterruptHandler := aHandler
|
|
311 |
!
|
|
312 |
|
13
|
313 |
signalInterruptHandler
|
|
314 |
"return the handler for UNIX-signal interrupts"
|
2
|
315 |
|
|
316 |
^ SignalInterruptHandler
|
|
317 |
!
|
|
318 |
|
13
|
319 |
signalInterruptHandler:aHandler
|
|
320 |
"set the handler for UNIX-signal interrupts"
|
|
321 |
|
|
322 |
SignalInterruptHandler := aHandler
|
|
323 |
!
|
|
324 |
|
2
|
325 |
childSignalInterruptHandler
|
13
|
326 |
"return the handler for UNIX-death-of-a-childprocess-signal interrupts"
|
|
327 |
|
2
|
328 |
^ ChildSignalInterruptHandler
|
|
329 |
!
|
|
330 |
|
|
331 |
disposeInterruptHandler
|
13
|
332 |
"return the handler for object disposal interrupts"
|
|
333 |
|
2
|
334 |
^ DisposeInterruptHandler
|
|
335 |
!
|
|
336 |
|
|
337 |
disposeInterruptHandler:aHandler
|
13
|
338 |
"set the handler for object disposal interrupts"
|
|
339 |
|
2
|
340 |
DisposeInterruptHandler := aHandler
|
|
341 |
!
|
|
342 |
|
|
343 |
recursionInterruptHandler
|
13
|
344 |
"return the handler for recursion/stack overflow interrupts"
|
|
345 |
|
2
|
346 |
^ RecursionInterruptHandler
|
|
347 |
!
|
|
348 |
|
13
|
349 |
recursionInterruptHandler:aHandler
|
|
350 |
"set the handler for recursion/stack overflow interrupts"
|
|
351 |
|
|
352 |
RecursionInterruptHandler := aHandler
|
|
353 |
!
|
|
354 |
|
2
|
355 |
ioInterruptHandler
|
13
|
356 |
"return the handler for I/O available signal interrupts (SIGIO/SIGPOLL)"
|
|
357 |
|
2
|
358 |
^ IOInterruptHandler
|
|
359 |
!
|
|
360 |
|
|
361 |
ioInterruptHandler:aHandler
|
13
|
362 |
"set the handler for I/O available signal interrupts (SIGIO/SIGPOLL)"
|
|
363 |
|
2
|
364 |
IOInterruptHandler := aHandler
|
85
|
365 |
!
|
|
366 |
|
|
367 |
customInterruptHandler
|
|
368 |
"return the handler for custom interrupts"
|
|
369 |
|
|
370 |
^ CustomInterruptHandler
|
|
371 |
!
|
|
372 |
|
|
373 |
customInterruptHandler:aHandler
|
|
374 |
"set the handler for custom interrupts"
|
|
375 |
|
|
376 |
CustomInterruptHandler := aHandler
|
2
|
377 |
! !
|
|
378 |
|
1
|
379 |
!ObjectMemory class methodsFor:'queries'!
|
|
380 |
|
13
|
381 |
newSpaceSize
|
|
382 |
"return the total size of the new space - this is usually fix"
|
|
383 |
|
|
384 |
%{ /* NOCONTEXT */
|
|
385 |
RETURN ( _MKSMALLINT(__newSpaceSize()) );
|
|
386 |
%}
|
|
387 |
"ObjectMemory newSpaceSize"
|
|
388 |
!
|
|
389 |
|
|
390 |
oldSpaceSize
|
|
391 |
"return the total size of the old space. - may grow slowly"
|
|
392 |
|
|
393 |
%{ /* NOCONTEXT */
|
|
394 |
RETURN ( _MKSMALLINT(__oldSpaceSize()) );
|
|
395 |
%}
|
|
396 |
"ObjectMemory oldSpaceSize"
|
|
397 |
!
|
|
398 |
|
1
|
399 |
newSpaceUsed
|
10
|
400 |
"return the number of bytes allocated for new objects.
|
|
401 |
The returned value is usually obsolete as soon as you do
|
13
|
402 |
something with it ..."
|
1
|
403 |
|
|
404 |
%{ /* NOCONTEXT */
|
|
405 |
RETURN ( _MKSMALLINT(__newSpaceUsed()) );
|
|
406 |
%}
|
|
407 |
"ObjectMemory newSpaceUsed"
|
|
408 |
!
|
|
409 |
|
|
410 |
oldSpaceUsed
|
10
|
411 |
"return the number of bytes allocated for old objects.
|
|
412 |
(This includes the free lists)"
|
1
|
413 |
|
|
414 |
%{ /* NOCONTEXT */
|
|
415 |
RETURN ( _MKSMALLINT(__oldSpaceUsed()) );
|
|
416 |
%}
|
|
417 |
"ObjectMemory oldSpaceUsed"
|
|
418 |
!
|
|
419 |
|
10
|
420 |
freeSpace
|
|
421 |
"return the number of bytes in the free lists.
|
|
422 |
(which is included in oldSpaceUsed)"
|
|
423 |
|
|
424 |
%{ /* NOCONTEXT */
|
|
425 |
RETURN ( _MKSMALLINT(__freeSpace()) );
|
|
426 |
%}
|
|
427 |
"ObjectMemory freeSpace"
|
|
428 |
!
|
|
429 |
|
1
|
430 |
bytesUsed
|
|
431 |
"return the number of bytes allocated for objects -
|
|
432 |
this number is not exact, since some objects may be dead"
|
|
433 |
|
|
434 |
%{ /* NOCONTEXT */
|
10
|
435 |
RETURN ( _MKSMALLINT(__oldSpaceUsed() + __newSpaceUsed() - __freeSpace()) );
|
1
|
436 |
%}
|
|
437 |
"ObjectMemory bytesUsed"
|
|
438 |
!
|
|
439 |
|
2
|
440 |
oldSpaceAllocatedSinceLastGC
|
|
441 |
"return the number of bytes allocated for old objects since the
|
|
442 |
last garbage collect occured"
|
|
443 |
|
|
444 |
%{ /* NOCONTEXT */
|
|
445 |
RETURN ( _MKSMALLINT(__oldSpaceAllocatedSinceLastGC()) );
|
|
446 |
%}
|
|
447 |
"ObjectMemory oldSpaceAllocatedSinceLastGC"
|
|
448 |
!
|
|
449 |
|
1
|
450 |
numberOfObjects
|
13
|
451 |
"return the number of objects in the system."
|
1
|
452 |
|
|
453 |
|tally|
|
|
454 |
|
|
455 |
tally := 0.
|
|
456 |
self allObjectsDo:[:obj | tally := tally + 1].
|
|
457 |
^ tally
|
|
458 |
|
|
459 |
"ObjectMemory numberOfObjects"
|
|
460 |
!
|
|
461 |
|
|
462 |
printReferences:anObject
|
13
|
463 |
"for debugging: print referents to anObject - will vanish.
|
|
464 |
use 'whoReferences:anObject' below (or 'anObject allOwners')"
|
1
|
465 |
|
|
466 |
%{
|
|
467 |
_printRefChain(__context, anObject);
|
|
468 |
%}
|
|
469 |
!
|
|
470 |
|
|
471 |
whoReferences:anObject
|
|
472 |
"return a collection of objects referencing the argument, anObject"
|
|
473 |
|
|
474 |
|aCollection|
|
|
475 |
|
|
476 |
aCollection := IdentitySet new.
|
|
477 |
self allObjectsDo:[:o |
|
|
478 |
(o references:anObject) ifTrue:[
|
|
479 |
aCollection add:o
|
|
480 |
]
|
|
481 |
].
|
|
482 |
(aCollection size == 0) ifTrue:[
|
|
483 |
"actually this cannot happen - there is always one"
|
|
484 |
^ nil
|
|
485 |
].
|
|
486 |
^ aCollection
|
13
|
487 |
!
|
|
488 |
|
|
489 |
addressOf:anObject
|
|
490 |
"return the core address of anObject as an integer
|
|
491 |
- since objects may move around, the returned value is invalid after the
|
|
492 |
next scavenge/collect.
|
|
493 |
Use only for debugging."
|
|
494 |
|
|
495 |
%{ /* NOCONTEXT */
|
|
496 |
|
|
497 |
if (! _isNonNilObject(anObject)) {
|
|
498 |
RETURN ( nil );
|
|
499 |
}
|
|
500 |
RETURN ( _MKSMALLINT( (int)anObject ) );
|
|
501 |
%}
|
|
502 |
"
|
|
503 |
|p|
|
|
504 |
p := Point new.
|
77
|
505 |
(ObjectMemory addressOf:p) printNL.
|
13
|
506 |
ObjectMemory scavenge.
|
77
|
507 |
(ObjectMemory addressOf:p) printNL.
|
13
|
508 |
"
|
|
509 |
!
|
|
510 |
|
|
511 |
sizeOf:anObject
|
|
512 |
"return the size of anObject in bytes.
|
|
513 |
Use only for debugging/memory monitoring."
|
|
514 |
|
|
515 |
%{ /* NOCONTEXT */
|
|
516 |
|
|
517 |
RETURN ( _isNonNilObject(anObject) ? _MKSMALLINT(_qSize(anObject)) : _MKSMALLINT(0) )
|
|
518 |
%}
|
|
519 |
"
|
|
520 |
|hist big nw|
|
|
521 |
|
|
522 |
hist := Array new:100 withAll:0.
|
|
523 |
big := 0.
|
|
524 |
ObjectMemory allObjectsDo:[:o |
|
|
525 |
nw := (ObjectMemory sizeOf:o) // 4 + 1.
|
|
526 |
nw > 100 ifTrue:[
|
|
527 |
big := big + 1
|
|
528 |
] ifFalse:[
|
|
529 |
hist at:nw put:(hist at:nw) + 1
|
|
530 |
].
|
|
531 |
].
|
77
|
532 |
hist printNL.
|
|
533 |
big printNL
|
13
|
534 |
"
|
|
535 |
!
|
|
536 |
|
|
537 |
spaceOf:anObject
|
|
538 |
"return the memory space, in which anObject is.
|
|
539 |
- since objects may move between spaces, returned value is invalid after the
|
|
540 |
next scavenge/collect.
|
|
541 |
Use only for debugging."
|
|
542 |
|
|
543 |
%{ /* NOCONTEXT */
|
|
544 |
|
|
545 |
if (! _isNonNilObject(anObject)) {
|
|
546 |
RETURN ( nil );
|
|
547 |
}
|
|
548 |
RETURN ( _MKSMALLINT( _qSpace(anObject) ) );
|
|
549 |
%}
|
|
550 |
"
|
|
551 |
|p|
|
|
552 |
p := Point new.
|
77
|
553 |
(ObjectMemory spaceOf:p) printNL.
|
13
|
554 |
1 to:100 do:[:i |
|
|
555 |
ObjectMemory scavenge.
|
|
556 |
].
|
77
|
557 |
(ObjectMemory spaceOf:p) printNL.
|
|
558 |
1 to:100 do:[:i |
|
|
559 |
ObjectMemory tenuringScavenge.
|
|
560 |
].
|
|
561 |
(ObjectMemory spaceOf:p) printNL.
|
|
562 |
"
|
|
563 |
!
|
|
564 |
|
|
565 |
ageOf:anObject
|
|
566 |
"return the number of scavenges, an object has survived
|
|
567 |
in new space. For old objects, the returned number is invalid.
|
|
568 |
Use only for debugging."
|
|
569 |
|
|
570 |
%{ /* NOCONTEXT */
|
|
571 |
|
|
572 |
if (! _isNonNilObject(anObject)) {
|
|
573 |
RETURN ( 0 );
|
|
574 |
}
|
|
575 |
RETURN ( _MKSMALLINT( _GET_AGE(anObject) ) );
|
|
576 |
%}
|
|
577 |
"
|
|
578 |
|p|
|
|
579 |
p := Point new.
|
|
580 |
(ObjectMemory ageOf:p) printNL.
|
|
581 |
ObjectMemory tenuringScavenge.
|
|
582 |
(ObjectMemory spaceOf:p) printNL.
|
|
583 |
ObjectMemory tenuringScavenge.
|
|
584 |
(ObjectMemory spaceOf:p) printNL.
|
|
585 |
ObjectMemory tenuringScavenge.
|
|
586 |
(ObjectMemory spaceOf:p) printNL.
|
|
587 |
ObjectMemory tenuringScavenge.
|
|
588 |
(ObjectMemory spaceOf:p) printNL.
|
13
|
589 |
"
|
1
|
590 |
! !
|
|
591 |
|
|
592 |
!ObjectMemory class methodsFor:'garbage collector control'!
|
|
593 |
|
|
594 |
garbageCollect
|
|
595 |
"search for and free garbage in the oldSpace
|
|
596 |
(newSpace is cleaned automatically)
|
|
597 |
- can take a long time if paging is involved
|
|
598 |
- when no paging is involved, its faster than I thought :-)"
|
|
599 |
%{
|
|
600 |
__garbageCollect(__context);
|
|
601 |
%}
|
|
602 |
|
|
603 |
"ObjectMemory garbageCollect"
|
|
604 |
!
|
|
605 |
|
13
|
606 |
moreOldSpace:howMuch
|
|
607 |
"allocate howMuch bytes more for old objects.
|
|
608 |
This is done automatically, when running out of space.
|
|
609 |
This (currently) implies a compressing garbage collect - so its slow.
|
|
610 |
May vanish."
|
|
611 |
|
|
612 |
%{
|
|
613 |
if (_isSmallInteger(howMuch))
|
|
614 |
_moreOldSpace(__context, _intVal(howMuch));
|
|
615 |
%}
|
|
616 |
"ObjectMemory moreOldSpace:1000000"
|
|
617 |
!
|
|
618 |
|
1
|
619 |
scavenge
|
77
|
620 |
"collect young objects, without aging.
|
|
621 |
Can be used to quickly get rid of shortly before allocated
|
85
|
622 |
stuff. Is relatively fast (compared to oldspace collect)"
|
1
|
623 |
%{
|
|
624 |
nonTenuringScavenge(__context);
|
|
625 |
%}
|
|
626 |
|
|
627 |
"ObjectMemory scavenge"
|
|
628 |
!
|
|
629 |
|
77
|
630 |
tenuringScavenge
|
|
631 |
"collect newspace stuff, with aging.
|
85
|
632 |
For debugging only. This method may vanish.
|
|
633 |
Is relatively fast (compared to oldspace collect)"
|
77
|
634 |
%{
|
|
635 |
scavenge(__context);
|
|
636 |
%}
|
|
637 |
|
|
638 |
"ObjectMemory tenuringScavenge"
|
|
639 |
!
|
|
640 |
|
1
|
641 |
tenure
|
77
|
642 |
"force all new stuff into old-space - effectively making
|
|
643 |
all living young objects become old objects.
|
85
|
644 |
Is relatively fast (compared to oldspace collect).
|
77
|
645 |
For debugging only. This method may vanish."
|
1
|
646 |
%{
|
|
647 |
tenure(__context);
|
|
648 |
%}
|
|
649 |
|
|
650 |
"ObjectMemory tenure"
|
|
651 |
!
|
|
652 |
|
|
653 |
markAndSweep
|
77
|
654 |
"mark/sweep garbage collector; perform a
|
|
655 |
full mark&sweep collect.
|
|
656 |
Warning: this may take some time."
|
1
|
657 |
%{
|
|
658 |
markAndSweep(__context);
|
|
659 |
%}
|
|
660 |
|
|
661 |
"ObjectMemory markAndSweep"
|
|
662 |
!
|
|
663 |
|
|
664 |
gcStep
|
77
|
665 |
"one incremental garbage collect step.
|
|
666 |
Mark or sweep some small number of objects. This
|
85
|
667 |
method will return after a reasonable (short) time.
|
|
668 |
This is used by the ProcessorScheduler at idle times."
|
1
|
669 |
%{
|
|
670 |
incrGCstep(__context);
|
|
671 |
%}
|
|
672 |
!
|
|
673 |
|
2
|
674 |
incrementalGCLimit:aNumber
|
85
|
675 |
"set the limit for incremental GC activation.
|
|
676 |
This is used by the ProcessorScheduler."
|
2
|
677 |
|
|
678 |
IncrementalGCLimit := aNumber
|
|
679 |
|
85
|
680 |
"
|
|
681 |
ObjectMemory incrementalGCLimit:100000
|
|
682 |
"
|
2
|
683 |
!
|
|
684 |
|
13
|
685 |
incrementalGCLimit
|
85
|
686 |
"return the limit for incremental GC activation.
|
|
687 |
This is used by the ProcessorScheduler."
|
13
|
688 |
|
|
689 |
^ IncrementalGCLimit
|
|
690 |
|
85
|
691 |
"
|
|
692 |
ObjectMemory incrementalGCLimit
|
|
693 |
"
|
13
|
694 |
!
|
|
695 |
|
2
|
696 |
turnGarbageCollectorOff
|
|
697 |
"turn off garbage collector by forcing new objects to be
|
|
698 |
allocated in oldSpace (instead of newSpace)
|
1
|
699 |
this method is somewhat dangerous: if collector is turned off,
|
77
|
700 |
and too many objects are created, the system may run into trouble
|
|
701 |
(i.e. oldSpace becomes full) and be forced to perform a full mark&sweep
|
|
702 |
or even a compressing collect.
|
1
|
703 |
Use this only for measurement purposes or when realtime behavior
|
77
|
704 |
is required for a limited time period. No warranty."
|
1
|
705 |
%{
|
77
|
706 |
allocForceSpace(OLDSPACE);
|
1
|
707 |
%}
|
|
708 |
!
|
|
709 |
|
2
|
710 |
turnGarbageCollectorOn
|
|
711 |
"turn garbage collector on again"
|
1
|
712 |
|
|
713 |
%{
|
77
|
714 |
allocForceSpace(9999);
|
1
|
715 |
%}
|
|
716 |
! !
|
|
717 |
|
85
|
718 |
!ObjectMemory class methodsFor:'physical memory access'!
|
|
719 |
|
|
720 |
makeOld:anObject
|
|
721 |
"move anObject into oldSpace - for debugging only;
|
|
722 |
may vanish. Dont use it."
|
|
723 |
%{
|
|
724 |
if (__moveToOldSpace(anObject, __context) < 0) {
|
|
725 |
RETURN (false);
|
|
726 |
}
|
|
727 |
%}.
|
|
728 |
^ true
|
|
729 |
!
|
|
730 |
|
|
731 |
oldSpacePagesDo:aBlock
|
|
732 |
"evaluates aBlock for all pages in the oldSpace, passing
|
|
733 |
the pages address as argument.
|
|
734 |
For internal use only."
|
|
735 |
%{
|
|
736 |
if (__oldSpacePagesDo(&aBlock COMMA_CON) < 0) {
|
|
737 |
RETURN (false);
|
|
738 |
}
|
|
739 |
%}.
|
|
740 |
^ true
|
|
741 |
!
|
|
742 |
|
|
743 |
pageIsInCore:aPageNumber
|
|
744 |
"return true, if the page (as enumerated via oldSpacePagesDo:)
|
|
745 |
is in memory; false, if currently paged out. For internal
|
|
746 |
use / monitors only; may vanish."
|
|
747 |
|
|
748 |
%{
|
|
749 |
#ifdef HAS_MINCORE
|
|
750 |
int pageSize = getpagesize();
|
|
751 |
char result[10];
|
|
752 |
INT addr;
|
|
753 |
|
|
754 |
if (_isSmallInteger(aPageNumber)) {
|
|
755 |
addr = _intVal(aPageNumber) & ~(pageSize - 1);
|
|
756 |
} else {
|
|
757 |
addr = ((INT)aPageNumber) & ~(pageSize - 1);
|
|
758 |
}
|
|
759 |
if (mincore(addr, pageSize-1, result) < 0) {
|
|
760 |
RETURN (true);
|
|
761 |
}
|
|
762 |
RETURN ((result[0] & 1) ? true : false);
|
|
763 |
#endif
|
|
764 |
%}.
|
|
765 |
"OS does not supply this info - assume yes"
|
|
766 |
^ true
|
|
767 |
! !
|
|
768 |
|
13
|
769 |
!ObjectMemory class methodsFor:'low memory handling'!
|
|
770 |
|
|
771 |
memoryInterrupt
|
|
772 |
"when a low-memory condition arises, ask all classes to
|
|
773 |
remove possibly cached data - this may help a bit"
|
|
774 |
|
|
775 |
Smalltalk allClasses do:[:aClass |
|
|
776 |
aClass lowSpaceCleanup
|
|
777 |
].
|
|
778 |
|
|
779 |
self error:'almost out of memory'
|
|
780 |
! !
|
|
781 |
|
1
|
782 |
!ObjectMemory class methodsFor:'system management'!
|
|
783 |
|
|
784 |
loadClassBinary:aClassName
|
|
785 |
"find the object file for aClassName and -if found - load it;
|
|
786 |
this one loads precompiled object files"
|
|
787 |
|
|
788 |
|fName newClass upd|
|
|
789 |
|
|
790 |
fName := self fileNameForClass:aClassName.
|
|
791 |
fName notNil ifTrue:[
|
|
792 |
upd := Class updateChanges:false.
|
|
793 |
[
|
|
794 |
self loadBinary:(fName , '.o')
|
|
795 |
] valueNowOrOnUnwindDo:[
|
|
796 |
Class updateChanges:upd
|
|
797 |
].
|
|
798 |
newClass := self at:(aClassName asSymbol).
|
|
799 |
(newClass notNil and:[newClass implements:#initialize]) ifTrue:[
|
|
800 |
newClass initialize
|
|
801 |
]
|
|
802 |
]
|
|
803 |
!
|
|
804 |
|
77
|
805 |
imageName
|
|
806 |
"return the filename of the current image, or nil
|
|
807 |
if not running from an image."
|
|
808 |
|
|
809 |
^ ImageName
|
|
810 |
!
|
|
811 |
|
22
|
812 |
nameForSnapshot
|
|
813 |
"return the filename of the current image or,
|
|
814 |
if not running from an image, the default name 'st.img'"
|
|
815 |
|
|
816 |
(ImageName isNil or:[ImageName isBlank]) ifTrue:[
|
|
817 |
^ 'st.img'
|
|
818 |
].
|
|
819 |
^ ImageName
|
|
820 |
!
|
|
821 |
|
1
|
822 |
snapShot
|
|
823 |
"create a snapshot"
|
|
824 |
|
|
825 |
ImageName isNil ifTrue:[
|
|
826 |
ImageName := 'st.img'
|
|
827 |
].
|
22
|
828 |
self snapShotOn:(self nameForSnapshot)
|
1
|
829 |
|
|
830 |
"ObjectMemory snapShot"
|
|
831 |
!
|
|
832 |
|
|
833 |
snapShotOn:aFileName
|
|
834 |
"create a snapshot in the given file"
|
|
835 |
|
22
|
836 |
|ok|
|
|
837 |
|
1
|
838 |
"give others a chance to fix things"
|
|
839 |
self changed:#save.
|
13
|
840 |
|
|
841 |
%{ /* STACK:32000 */
|
|
842 |
|
1
|
843 |
OBJ __snapShotOn();
|
13
|
844 |
OBJ retVal;
|
1
|
845 |
|
56
|
846 |
if (__isString(aFileName)) {
|
22
|
847 |
BLOCKINTERRUPTS();
|
|
848 |
ok = __snapShotOn(__context, _stringVal(aFileName));
|
|
849 |
UNBLOCKINTERRUPTS();
|
1
|
850 |
}
|
|
851 |
%}
|
|
852 |
.
|
22
|
853 |
ok ifTrue:[
|
|
854 |
Class addChangeRecordForSnapshot:aFileName
|
|
855 |
].
|
|
856 |
^ ok
|
1
|
857 |
|
|
858 |
"ObjectMemory snapShotOn:'myimage.img'"
|
|
859 |
!
|
|
860 |
|
|
861 |
applicationImageOn:aFileName for:startupClass selector:startupSelector
|
|
862 |
"create a snapshot which will come up without any views
|
|
863 |
but starts up an application by sending startupClass the startupSelector"
|
|
864 |
|
2
|
865 |
|viewsKnown savedIdleBlocks savedTimeoutBlocks savedTranscript
|
|
866 |
savedRoot|
|
1
|
867 |
|
|
868 |
viewsKnown := Display knownViews.
|
|
869 |
savedIdleBlocks := Display idleBlocks.
|
|
870 |
savedTimeoutBlocks := Display timeOutBlocks.
|
|
871 |
savedTranscript := Transcript.
|
2
|
872 |
savedRoot := RootView.
|
1
|
873 |
|
10
|
874 |
"a kludge: save image with modified knownViews, no idle- and timeoutblocks
|
|
875 |
and also Transcript set to StdErr ..."
|
1
|
876 |
|
|
877 |
Display knownViews:nil.
|
|
878 |
Display idleBlocks:nil.
|
|
879 |
Display timeOutBlocks:nil.
|
2
|
880 |
RootView := nil.
|
|
881 |
|
1
|
882 |
Transcript := Stderr.
|
10
|
883 |
Smalltalk startupClass:startupClass selector:startupSelector arguments:nil.
|
1
|
884 |
self snapShotOn:aFileName.
|
10
|
885 |
Smalltalk startupClass:nil selector:nil arguments:nil.
|
1
|
886 |
|
2
|
887 |
RootView := savedRoot.
|
1
|
888 |
Transcript := savedTranscript.
|
|
889 |
Display knownViews:viewsKnown.
|
|
890 |
Display idleBlocks:savedIdleBlocks.
|
|
891 |
Display timeOutBlocks:savedTimeoutBlocks
|
|
892 |
|
|
893 |
"ObjectMemory applicationImageOn:'draw.img' for:DrawTool selector:#start"
|
|
894 |
"ObjectMemory applicationImageOn:'pm.img' for:PMSimulator selector:#start"
|
|
895 |
!
|
|
896 |
|
|
897 |
minimumApplicationImageOn:aFileName for:startupClass selector:startupSelector
|
|
898 |
"create a snapshot which will come up without any views
|
|
899 |
but starts up an application by sending startupClass the startupSelector.
|
|
900 |
All unneeded info is stripped from the saved image."
|
|
901 |
|
|
902 |
"create a temporary image, for continuation"
|
|
903 |
self snapShotOn:'temp.img'.
|
|
904 |
|
|
905 |
Display knownViews do:[:aView |
|
|
906 |
aView notNil ifTrue:[
|
|
907 |
aView superView isNil ifTrue:[
|
|
908 |
aView destroy
|
|
909 |
]
|
|
910 |
]
|
|
911 |
].
|
|
912 |
|
|
913 |
self stripImage.
|
|
914 |
|
|
915 |
self applicationImageOn:aFileName for:startupClass selector:startupSelector.
|
|
916 |
|
|
917 |
"continue in old image"
|
|
918 |
|
|
919 |
OperatingSystem exec:(Arguments at:1)
|
|
920 |
withArguments:#('smalltalk' '-i' 'temp.img') , (Arguments copyFrom:2)
|
|
921 |
|
|
922 |
"ObjectMemory minimumApplicationImageOn:'clock1.img' for:Clock selector:#start"
|
|
923 |
"ObjectMemory applicationImageOn:'clock2.img' for:Clock selector:#start"
|
|
924 |
!
|
|
925 |
|
|
926 |
stripImage
|
|
927 |
"remove all unneeded stuff from the image - much more is possible here"
|
|
928 |
|
2
|
929 |
"remove all class comments & source"
|
1
|
930 |
|
2
|
931 |
Smalltalk allBehaviorsDo:[:aClass |
|
1
|
932 |
aClass setComment:nil.
|
68
|
933 |
aClass methodArray do:[:aMethod |
|
1
|
934 |
aMethod source:''.
|
|
935 |
aMethod category:#none
|
|
936 |
]
|
|
937 |
].
|
|
938 |
self garbageCollect
|
|
939 |
! !
|