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