author | Claus Gittinger <cg@exept.de> |
Tue, 31 Oct 1995 18:17:57 +0100 | |
changeset 464 | 83af924c8cff |
parent 458 | ef1a25054341 |
child 465 | fdc81f5887a1 |
permissions | -rw-r--r-- |
1 | 1 |
" |
5 | 2 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 3 |
All Rights Reserved |
1 | 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 |
159 | 16 |
SpyInterruptHandler StepInterruptHandler ExceptionInterruptHandler |
17 |
ErrorInterruptHandler MemoryInterruptHandler SignalInterruptHandler |
|
18 |
ChildSignalInterruptHandler DisposeInterruptHandler |
|
19 |
RecursionInterruptHandler IOInterruptHandler |
|
20 |
CustomInterruptHandler |
|
345 | 21 |
RegisteredErrorInterruptHandlers |
2 | 22 |
|
464
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
23 |
AllocationFailureSignal MallocFailureSignal LowSpaceSemaphore |
310 | 24 |
IncrementalGCLimit FreeSpaceGCLimit FreeSpaceGCAmount |
290 | 25 |
BackgroundCollectProcess BackgroundFinalizationProcess |
26 |
FinalizationSemaphore |
|
159 | 27 |
Dependents |
28 |
ImageName' |
|
1 | 29 |
poolDictionaries:'' |
30 |
category:'System-Support' |
|
31 |
! |
|
32 |
||
33 |
ObjectMemory comment:' |
|
5 | 34 |
COPYRIGHT (c) 1992 by Claus Gittinger |
159 | 35 |
All Rights Reserved |
93 | 36 |
|
464
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
37 |
$Header: /cvs/stx/stx/libbasic/ObjectMemory.st,v 1.60 1995-10-31 17:17:57 cg Exp $ |
2 | 38 |
'! |
39 |
||
40 |
!ObjectMemory class methodsFor:'documentation'! |
|
41 |
||
88 | 42 |
copyright |
43 |
" |
|
44 |
COPYRIGHT (c) 1992 by Claus Gittinger |
|
159 | 45 |
All Rights Reserved |
88 | 46 |
|
47 |
This software is furnished under a license and may be used |
|
48 |
only in accordance with the terms of that license and with the |
|
49 |
inclusion of the above copyright notice. This software may not |
|
50 |
be provided or otherwise made available to, or used by, any |
|
51 |
other person. No title to or ownership of the software is |
|
52 |
hereby transferred. |
|
53 |
" |
|
54 |
! |
|
55 |
||
56 |
version |
|
57 |
" |
|
464
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
58 |
$Header: /cvs/stx/stx/libbasic/ObjectMemory.st,v 1.60 1995-10-31 17:17:57 cg Exp $ |
88 | 59 |
" |
60 |
! |
|
61 |
||
2 | 62 |
documentation |
63 |
" |
|
403 | 64 |
This class contains access methods to the system memory and the VM. |
65 |
||
66 |
In previous ST/X versions, this stuff used to be in the Smalltalk class. |
|
67 |
It has been separated for better overall class structure and modularisation. |
|
229 | 68 |
There are no instances of ObjectMemory - all is done in class methods. |
403 | 69 |
(this is a functional interface). |
70 |
||
71 |
Many methods here are for debuging purposes, for developers |
|
72 |
or experimental, and therefore not standard. |
|
68 | 73 |
Do not depend on them being there - some may vanish ... |
74 |
(especially those, that depend on a specific GC implementation) |
|
403 | 75 |
Most of the stuff found here is not available, or different or called |
76 |
different in other smalltalk implementations. Be aware, that using these |
|
77 |
interfaces (especially: depending on them) may make your application |
|
78 |
non portable. |
|
79 |
||
80 |
See more documentation in -> caching |
|
81 |
-> interrupts |
|
82 |
-> garbageCollection |
|
2 | 83 |
|
229 | 84 |
Class variables: |
2 | 85 |
|
159 | 86 |
InternalErrorHandler gets informed (by VM), when some runtime |
87 |
error occurs (usually fatal) |
|
2 | 88 |
|
159 | 89 |
UserInterruptHandler gets informed (by VM) when CNTL-C is pressed |
90 |
TimerInterruptHandler gets alarm timer interrupts (from VM) |
|
91 |
SpyInterruptHandler another alarm timer (from VM) |
|
92 |
StepInterruptHandler gets single step interrupts (from VM) |
|
93 |
ExceptionInterruptHandler gets floating point exceptions (from VM) |
|
345 | 94 |
ErrorInterruptHandler gets primitive errors (from VM) |
159 | 95 |
MemoryInterruptHandler gets soon-out-of-memory conditions (from VM) |
96 |
SignalInterruptHandler gets unix signals (from VM) |
|
97 |
ChildSignalInterruptHandler gets child death signals (from VM) |
|
98 |
DisposeInterruptHandler gets informed, when an object is disposed from |
|
99 |
a shadowArray (from VM) |
|
100 |
RecursionInterruptHandler gets recursion limit violations (from VM) |
|
101 |
IOInterruptHandler gets SIGIO unix signals (from VM) |
|
102 |
CustomInterruptHandler gets custom interrupts (from VM) |
|
2 | 103 |
|
345 | 104 |
RegisteredErrorInterruptHandlers |
105 |
associates errorID (as passed from primitive |
|
106 |
to the __errorInterruptWithID() function) |
|
107 |
with handlers. |
|
108 |
||
270 | 109 |
IncrementalGCLimit number of bytes, that must be allocated since |
290 | 110 |
last full garbage collect to turn the incremental |
111 |
collector on (at idle time). |
|
112 |
||
113 |
FreeSpaceGCLimit low limit on freeSpace at which incremental |
|
114 |
gc starts to run at idle time. |
|
270 | 115 |
|
310 | 116 |
FreeSpaceGCAmount amount to allocate once freeSpace drops |
117 |
below FreeSpaceGCLimit |
|
118 |
||
159 | 119 |
Dependents keep my dependents locally (its faster) for |
120 |
all those registries |
|
270 | 121 |
|
213 | 122 |
LowSpaceSemaphore a semaphore signalled whenever the system is |
123 |
running in low memory (i.e. the memory manager |
|
124 |
ran into memory shortage and feels that it |
|
125 |
may soon be no longer grant allocation requests). |
|
126 |
You can have a process waiting on this semaphore |
|
127 |
which starts to remove (i.e. nil-out) objects |
|
128 |
or preform other cleanup actions. |
|
129 |
||
130 |
AllocationFailureSignal signal raised when a new fails (see Behavior) |
|
131 |
When this signal is raised, the meomory manager |
|
132 |
is really in trouble (i.e. above feelings where |
|
133 |
correct) |
|
290 | 134 |
|
135 |
BackgroundCollectProcess created by startBackgroundCollectorAt: |
|
136 |
||
137 |
BackgroundFinalizationProcess created by startBackgroundFinalizationAt: |
|
403 | 138 |
|
139 |
Warning: |
|
140 |
The InterruptHandler variables are known by the runtime system - |
|
141 |
they are the objects that get an interrupt message when the event |
|
142 |
occurs. You may not remove any of them. |
|
2 | 143 |
" |
93 | 144 |
! |
145 |
||
146 |
caching |
|
147 |
" |
|
148 |
The system uses various caches to speed up method-lookup. |
|
149 |
Currently, there is a three-level cache hierarchy: |
|
150 |
||
159 | 151 |
inline-cache keeps the target of the last send at the caller- |
152 |
side (i.e. every send goes through its private |
|
153 |
1-slot inline-cache, where the address of the last |
|
154 |
called function at this call location is kept.) |
|
93 | 155 |
|
229 | 156 |
polymorph-inline-cache keeps a limited list of all targets ever reached |
157 |
at this call location. The list is automatically |
|
158 |
flushed if it grows too large, or the overall number |
|
159 |
of poly-chache entries exceeds a limit. |
|
93 | 160 |
|
159 | 161 |
method-lookup-cache a global cache. Hashes on class-selector pairs, |
162 |
returning the target method. |
|
93 | 163 |
|
164 |
Whenever methods are added or removed from the system, or the inheritance |
|
165 |
hierarchy changes, some or all caches have to be flushed. |
|
202 | 166 |
The flushXXX methods perform the task of flushing various caches. |
207 | 167 |
All standard methods in Behavior call for cache flushing, when things change; |
229 | 168 |
however, if you use the low level access methods in Behavior |
169 |
(for example: #setSuperclass:) special care has to be taken. |
|
170 |
||
171 |
In some situations, not all caches need flushing, for example a change |
|
172 |
in an interpreted method (currently) needs no flushing of the inline caches. |
|
173 |
Also, flushing can be limited to entries for a specific class for most changes. |
|
174 |
||
202 | 175 |
To be 'on the brigth side of live', use ObjectMemory>>flushCaches (which |
176 |
flushes all of them), when in doubt of which caches should be flushed. |
|
177 |
It is better flush too much - otherwise you may end up in a wrong method after |
|
178 |
a send. |
|
93 | 179 |
" |
180 |
! |
|
181 |
||
182 |
interrupts |
|
183 |
" |
|
184 |
Handling of interrupts (i.e. unix-signals) is done via handler objects, which |
|
185 |
get a #XXXInterrupt-message sent. This is more flexible than (say) signalling |
|
186 |
a semaphore, since the handler-object may do anything to react on the signal |
|
187 |
(of course, it can also signal a semaphore to emulate the above behavior). |
|
188 |
||
229 | 189 |
Another reason for having handler objects is that they allow interrupt handling |
207 | 190 |
without any context switch, for high speed interrupt response. |
403 | 191 |
However, if you do this, special care is needed, since it is not defined, |
192 |
which process gets the interrupt and will do the processing (therefore, |
|
193 |
the default setup installs handlers which simply signal a semaphore and |
|
194 |
continue the running process). |
|
195 |
||
93 | 196 |
Typically, the handlers are set during early initialization of the system |
202 | 197 |
by sending 'ObjectMemory XXXInterruptHandler:aHandler' and not changed later. |
198 |
(see Smalltalk>>initialize or ProcessorScheduler>>initialize). |
|
207 | 199 |
To setup your own handler, create some object which responds to #xxxInterrupt, |
200 |
and make it the handler using the above method. |
|
201 |
||
202 |
Interrupt messages sent to handlers are: |
|
203 |
internalError:<someString> - internal interpreter/GC errors |
|
204 |
userInterrupt - ^C interrupt |
|
205 |
customInterrupt - custom interrupt |
|
206 |
ioInterrupt - SIGIO interrupt |
|
229 | 207 |
timerInterrupt - alarm timer (SIGALRM) |
345 | 208 |
errorInterrupt:<id> - errors from other primitives/subsystems |
209 |
(DisplayError) |
|
229 | 210 |
spyInterrupt - spy timer interrupt (SIGVTALARM) |
207 | 211 |
stepInterrupt - single step interrupt |
212 |
disposeInterrupt - finalization required |
|
213 |
recursionInterrupt - recursion (stack) overflow |
|
214 |
memoryInterrupt - soon running out of memory |
|
229 | 215 |
fpExceptionInterrupt - floating point exception (SIGFPE) |
207 | 216 |
childSignalInterrupt - death of a child process (SIGCHILD) |
217 |
signalInterrupt:<number> - unix signal (if other than above signals) |
|
403 | 218 |
|
219 |
To avoid frustration in case of badly set handlers, these messages |
|
220 |
are also implemented in the Object class - thus anything can be defined |
|
221 |
as interrupt handler. However, the VM will not send any |
|
222 |
interrupt message, if the corresonding handler object is nil |
|
223 |
(which means that nil is a bad choice, if you are interrested in the event). |
|
224 |
||
225 |
Interrupt processing is not immediately after the event arrives: there |
|
226 |
are certain ``save-places'' at which this handling is performed |
|
227 |
(message send, method return and loop-heads). |
|
228 |
If not explicitely enabled, primitive code is never interrupted. |
|
229 |
||
230 |
Interrupts may be disabled (OperatingSystem blockInterrupts) and reenabled |
|
231 |
(unblockInterrupts) to allow for critical data to be manipulated. |
|
232 |
Every process has its own interrupt-enable state which is switched |
|
233 |
when processes switch control (i.e. you cannot block interrupts across |
|
234 |
a suspend, delay etc.). However, the state will be restored after a resume. |
|
93 | 235 |
" |
236 |
! |
|
237 |
||
238 |
garbageCollection |
|
239 |
" |
|
403 | 240 |
Currently, Smalltalk/X uses a two-level memory hierachy (actually, there |
241 |
are more memory regions used for stack, permanent objects, symbols etc. |
|
242 |
but for the following discussion, these are not of interrest). |
|
243 |
||
244 |
newSpace: |
|
245 |
||
93 | 246 |
Objects are created in a so-called newSpace, which is relatively small. |
403 | 247 |
This newSpace is cleaned by a so called ``scavenge''-operation, whenever |
248 |
becoming full. Scavenging means, that all still-live objects (i.e. referenced |
|
249 |
by some other) are copied over to another memory area, leaving all unreachable |
|
250 |
objects as garbage behind. Thus, the newSpace actually consists of two semispaces, |
|
251 |
of whih only one is active - the other being used only while objects are |
|
252 |
copied. |
|
253 |
After this copying, these two semispaces exchange their roles - i.e. reachable |
|
254 |
objects are copied ping-pong like between these semispaces. |
|
202 | 255 |
Once an object survives enough of these copying operations, the next scavenge |
216 | 256 |
will move it into the so called oldSpace, which is much larger, and not |
202 | 257 |
processed by the scavenger. |
403 | 258 |
This movement of an object from newSpace to oldSpace is called ``tenure''. |
259 |
(this avoids objects being copied around forever). |
|
260 |
Once tenured, an object is no longer contained in the newSpace, and |
|
261 |
thus ceases to create any scavenging overhead after that. |
|
133 | 262 |
|
93 | 263 |
Scavenging occurs automatically, and is usually done fast enough to go |
264 |
unnoticed (typically, it takes some 5 to 50ms to perform a scavenge, |
|
265 |
depending on how many live objects are in the newspace). |
|
403 | 266 |
|
93 | 267 |
Interrestingly, the scavenger performs better, if many garbage objects |
268 |
are to be reclaimed, since less object-copying has to be done. Therefore, |
|
216 | 269 |
the best-case scavenge time is almost zero, if there is only garbage in |
270 |
the newSpace. In contrast, the worst-case is when all newSpace objects are still |
|
403 | 271 |
living. Thus, from a newSpace collectors viewPoint, it makes sense to get |
272 |
objects out of the way as fast as possible. However the oldSpace is |
|
273 |
collected much less frequently and the cost to reclaim an oldspace object |
|
274 |
is much higher (actually, the cost to reclaim a newspace object is zero - |
|
275 |
its the survival of objects which we have to pay for). |
|
276 |
Therefore, from an oldSpace collectors point of view, its preferable to |
|
277 |
keep objects in the newSpace as long as possible. |
|
278 |
||
279 |
To honor this conflicting situation, the system uses an adaptive tenure-count, |
|
207 | 280 |
which adjusts the number of scavenges required for tenure (the so called |
281 |
'tenureAge') according to the fill-grade of the newSpace. |
|
403 | 282 |
If the newSpace is relatively empty, it tries to keep objects longer there. |
283 |
The controlling parameters of the tenure age can be changed dynamically, |
|
284 |
detailed information is available upon request. |
|
285 |
||
286 |
The exact speed of the scavenger depends mostly on the speed of your memory |
|
287 |
interface (and, since most of todays memories have access times in the order |
|
288 |
of 50-100ns, the raw CPU speed does not correlate linear with the GC speed). |
|
289 |
Measurements give roughly 40-70ms for a full 400k newSpace |
|
290 |
(i.e. all objects survive). |
|
291 |
The upper bounds of the scavenge blocking time can be controlled by changing |
|
292 |
the size of the newSpace - ether via acommand line argument, or even dynamically |
|
293 |
by Objectmemory>>newSpaceSize:. Smaller sizes lead to shorter blocking periods, |
|
294 |
but greater absolute GC overhead. The default (400k) seems to be a good compromise. |
|
295 |
(if you are not happy with it, try playing around with the settings) |
|
296 |
||
297 |
oldSpace: |
|
93 | 298 |
|
299 |
To reclaim oldspace, the system uses three algorithms: mark&sweep, a copying |
|
300 |
(and compressing) baker-type collector and an incremental mark&sweep. |
|
301 |
||
302 |
The mark&sweep runs whenever the oldspace becomes full, putting dead objects |
|
303 |
onto a free list. If a memory request cannot be served from this freelist, |
|
304 |
and the total size of objects on the freelist exceeds a threshold, the system |
|
305 |
will compress the oldspace to make the free-space into one big area. |
|
207 | 306 |
This compress is done by copying all live objects into a newly allocated |
307 |
area, and freeing the previous memory afterwards (baker collector). |
|
93 | 308 |
Since a compressing oldspace collect leads to a noticable pause of the system, |
309 |
the memory manager tries hard to avoid oldspace compression. |
|
207 | 310 |
(actually, if enough real memory is available to hold both spaces in physical |
311 |
memory, the compress is pretty fast). |
|
202 | 312 |
|
93 | 313 |
The incremental mark&sweep runs in the background, whenever the system is idle |
403 | 314 |
(see ProcessorSceduler>>waitForEventOrTimeout), or alternatively as a low or high |
315 |
priority background process (see ObjectMemory>>startBackgroundCollector). |
|
362 | 316 |
Like the normal mark&sweep, this incremental collector follows object references |
317 |
and marks reachable objects on its way. However, this is done 'a few objects-at-a-time', |
|
318 |
to not disrupt the system noticably. Currently, there are some (theoretical) and in |
|
403 | 319 |
practice never occurring situations, in which the incremental GC still creates noticable |
320 |
delays. A current project is involved with this and a future versions of ST/X (ST/X-RT) |
|
321 |
will be available which shows deterministic worst case behavior in its GC pauses |
|
322 |
(this will be provided as an additional add-on option - certainly not for free ;-). |
|
323 |
Currently, incremental GC blockings are in the order of 10-70ms. |
|
324 |
There is one catch with low priority background IGC: if there is never any idle |
|
325 |
time available (i.e. all processes run all the time), it would never get a chance |
|
326 |
to do any collection work. To handle this case, a background IGC can also be started |
|
327 |
as a high priority process, which gives up the cpu (by delaying on the time) after |
|
328 |
every IGC step. A high priority background collector will always make progress |
|
329 |
and eventually finish a GC cycle. However, it may have more of an influence on |
|
330 |
the other processes. So, its up to you, to decide ... |
|
362 | 331 |
|
332 |
Incremental garbage collection is controlled by the variables |
|
333 |
'IncrementalGCLimit', 'FreeSpaceGCLimit' and 'FreeSpaceGCAmount': |
|
310 | 334 |
|
290 | 335 |
the ProcessorScheduler will perform incremental GC steps at idle time, |
336 |
if the total space allocated since the last full collect exceeds |
|
362 | 337 |
'IncrementalGCLimit', |
290 | 338 |
or if there are less than 'FreeSpaceGCLimit' bytes available in free store. |
362 | 339 |
If after the incrementalGC, less than 'FreeSpaceGCLimi't bytes are available, |
310 | 340 |
'FreeSpaceGCAmount' more bytes are requested from the memory manager. |
290 | 341 |
|
342 |
The defaults are set in ObjectMemory>>initialize and can be changed in your |
|
403 | 343 |
startup 'smalltalk.rc'-file. Setting them to nil turns incremental GC off. |
270 | 344 |
|
362 | 345 |
For example, setting 'IncrementalGCLimit' to 500000 will start the background collector |
207 | 346 |
whenever 500k bytes have been allocated - usually very seldom. Setting it to some |
347 |
small number (say 10000) will have it run very often. |
|
290 | 348 |
|
362 | 349 |
Setting 'FreeSpaceGCAmount' to (say) 1meg lets the system try to always keep |
403 | 350 |
1meg of freeSpace. If less memory is available, more oldSpace will be allocated. |
351 |
Keeping some memory in the pocket may prevent the system from running into a blocking |
|
352 |
GC if memory is allocated in peaks (but only, if the incremental GC can keep up with |
|
353 |
allocation rate). The trigger level 'FreeSpaceGCLimit' should be below that amount; |
|
310 | 354 |
to avoid excessive incremental GC activity (say 1/4 if the amount). |
290 | 355 |
|
356 |
Having the background GC running often should not hurt the performance of your |
|
362 | 357 |
smalltalk processes, since the IGC only runs at times when no ST processes are runnable. |
290 | 358 |
(there are some short delays in event processing, since the IGC's steps may take |
359 |
some XX ms.) |
|
270 | 360 |
However, if you are not alone on your machine (i.e. a timesharing system) or |
361 |
you have other Unix processes to run, you should not run the IGC too often, |
|
362 | 362 |
since it may hurt OTHER users/unix processes. |
93 | 363 |
|
216 | 364 |
Since this collector only runs at idle times, even a low priority background |
365 |
process will prevent it from doing its work. You may want to start a somewhat |
|
207 | 366 |
higher priority background collect (say at prio 4), which also preempts these |
367 |
background processes. (see ObjectMemory>>startBackgroundCollectorAt:). |
|
202 | 368 |
|
325 | 369 |
Beginning with 2.10.4, a third space, called symSpace has been added. |
216 | 370 |
Objects in this space are never moved or garbage collected. |
325 | 371 |
This space is used for (some) symbols only. |
372 |
||
373 |
Beginning with 2.10.5, a fourth space, called fixSpace has been added. |
|
374 |
Objects in this space are never moved or garbage collected. |
|
375 |
This space is used for constant objects (true, false, some basic classes etc.). |
|
229 | 376 |
|
377 |
A plan for 2.11 is to offer an arbitrary number of spaces, which can be |
|
378 |
attached and detached at runtime. This will allow easy share of object |
|
379 |
with remote systems and separating objects into a per application/package |
|
380 |
space. (be prepared for changes in the future and make your application |
|
381 |
independ of the VM internals) |
|
216 | 382 |
|
403 | 383 |
default setup: |
384 |
||
385 |
The following table lists some default settings and means for changing them: |
|
386 |
||
387 |
what default change by |
|
388 |
command line arg dynamically |
|
389 |
----------------------------------------------------------------------- |
|
390 |
newSpace size 400k -Mnew nnn newSpaceSize:nnn |
|
391 |
||
392 |
oldSpace size 3000k -Mold nnn moreOldSpace: |
|
393 |
announceSpaceNeed: |
|
394 |
collectGarbage |
|
395 |
||
396 |
max tenure age 29 lockTenure: |
|
397 |
avoidTenure: |
|
398 |
(sets it to infinity) |
|
399 |
||
400 |
adaptive tenure tenureParameters |
|
401 |
||
402 |
oldSpace |
|
403 |
compressor enabled -Msingle - |
|
404 |
||
405 |
limit for |
|
406 |
old-compress 8000k - oldSpaceCompressLimit: |
|
407 |
||
408 |
chunk size |
|
409 |
to increase |
|
410 |
oldpPace 256k - oldSpaceIncrement: |
|
411 |
||
412 |
prefer moreOld |
|
413 |
to doing GC false - fastMoreOldSpaceAllocation: |
|
414 |
||
415 |
limit for |
|
416 |
above - - fastMoreOldSpaceLimit: |
|
417 |
||
418 |
keep size for - - freeSpaceGCAmount: |
|
419 |
IGC |
|
420 |
||
421 |
low water |
|
422 |
trigger for IGC - - freeSpaceGCLimit: |
|
423 |
||
424 |
allocated |
|
425 |
trigger for IGC 500k - incrementalGCLimit |
|
426 |
||
427 |
||
428 |
By default, no incremental GC activity is started. |
|
429 |
You have to change your startup files to do this. A suggested configuration |
|
430 |
(used by the author) is: |
|
431 |
||
432 |
' keep 1meg in the pocket ' |
|
433 |
||
434 |
ObjectMemory freeSpaceGCAmount:1000000. |
|
435 |
||
436 |
' start incrementalGC when freespace drops below 250k ' |
|
437 |
' or 500k of oldSpace has been allocated ' |
|
438 |
||
439 |
ObjectMemory freeSpaceGCLimit:250000. ' |
|
440 |
ObjectMemory incrementalGCLimit:500000. ' |
|
441 |
||
442 |
' collect as a background process (the default is: at idle times) |
|
443 |
' this means that running cubes or other demo processes are suspended |
|
444 |
' for the collect; change the prio to below 4 if you want them to continue |
|
445 |
||
446 |
ObjectMemory startBackgroundCollectorAt:5. ' |
|
447 |
ObjectMemory startBackgroundFinalizationAt:5. ' |
|
448 |
||
449 |
' quickly allocate more space (i.e. avoid blocking collects) |
|
450 |
' up to 8meg - then start to collect if more memory is needed. |
|
451 |
||
452 |
ObjectMemory fastMoreOldSpaceLimit:8*1024*1024. ' |
|
453 |
ObjectMemory fastMoreOldSpaceAllocation:true. ' |
|
454 |
||
202 | 455 |
hints & tricks: |
456 |
||
213 | 457 |
normally, there is no need to call for an explicit garbage collection, or |
216 | 458 |
modify the default parameters. |
213 | 459 |
The memory system should adapt reasonable and provide good performance |
202 | 460 |
for a wide range of allocation patterns (see Example3 below for an exception). |
461 |
||
207 | 462 |
However, there may be situations, in which hints and/or explicit |
202 | 463 |
control over allocation can speedup your programs; but please: |
93 | 464 |
|
207 | 465 |
- if you think you have to play around with the memory policies, |
202 | 466 |
first check your program - you may find useless allocations |
467 |
or bad uses of collections. A typical error that is made is to |
|
468 |
create large collections using the #, (comma) concatenation method, |
|
469 |
which shows square behavior, since it allocates many, many temporary |
|
213 | 470 |
collections. Also, watch out for #copyWith:, #add: etc. |
202 | 471 |
All of these create a new collection. Remember, that most collections |
472 |
offer methods to preallocate some space; for example, 'Set new:' creates |
|
229 | 473 |
an empty set, but preallocates space to avoid resizing over and over. |
474 |
||
216 | 475 |
An especially bad performace dog is to use #add: on fix-size collection |
476 |
objects (such as Strings or Arrays), since in addition to allocating |
|
229 | 477 |
lots of garbage, a #become: operation is required for EACH element |
216 | 478 |
added. NEVER use Arrays for growing/shrinking data - use OrderedCollection |
229 | 479 |
instead. (if you really need an array, use asArray afterwards) |
202 | 480 |
|
207 | 481 |
- if you are going to allocate huge data structures, think about |
482 |
optimizing space. For example, if you allocate a million instances of |
|
213 | 483 |
some object, each added instance variable makes up 4Mb of additional |
484 |
memory need. |
|
207 | 485 |
Also, for Byte-valued, Integer-valued and Float like objects, special |
486 |
collections are provided, which store their values directly inside (instead |
|
487 |
of a reference to the object). A FloatArray consisting of 1 million floats |
|
213 | 488 |
requires about 4mb of memory, while an Array of Floats requires 4mb for the |
489 |
references to the floats, PLUS 20Mb for the floats themself. |
|
93 | 490 |
|
207 | 491 |
- check if you really need fast access to all of these objects; you may |
492 |
try to only keep some subset in memory, and use binary storage or |
|
493 |
(if this is too slow) optimized store/retrieve methods and keep the bigger |
|
229 | 494 |
part in a file. |
362 | 495 |
(How about a DiskArray class, which does this transparently ? |
229 | 496 |
See the FileText class for some ideas and something to start with ...) |
207 | 497 |
|
498 |
||
499 |
Hint / Example 1: |
|
93 | 500 |
you are about to allocate a huge data structure, which is known to |
501 |
survive long. In this case, it is better to have these objects move into the |
|
502 |
oldspace sooner, to avoid the copying overhead during scavenges. |
|
503 |
||
504 |
To do this, you can call ObjectMemory>>tenure after allocation, which |
|
505 |
forces all new-objects immediately into the oldspace. |
|
506 |
Make certain, that not to many (ideally no) short-living objects are in the |
|
507 |
newspace when doing this. |
|
508 |
||
509 |
Another alternative is to tell the system that all allocation should be |
|
510 |
done directly in the oldspace. This completely avoids the scavenging overhead |
|
511 |
for these objects. To do so, use ObjectMemory>>turnGarbageCollectorOff |
|
512 |
before the allocation, and ObjectMemory>>turnGarbageCollectorOn afterwards. |
|
202 | 513 |
Keep in mind, that do-loops may allocate block-objects and other temporaries, |
178 | 514 |
so there is a danger of making things worse due to having all those temporaries |
93 | 515 |
in the oldspace afterwards. (which is not a fatal situation, but will |
178 | 516 |
force the system to do an oldspace collect earlier, which may not be your |
517 |
intention). |
|
93 | 518 |
|
202 | 519 |
|
207 | 520 |
Hint / Example 2: |
93 | 521 |
you know in advance, that a certain (big) amount of memory will be needed. |
522 |
For example, the fileBrowser wants to show a huge file in its text-view. |
|
133 | 523 |
In this case, it is better to tell the memory system in advance, how much |
93 | 524 |
memory will be needed, since otherwise many compresses and reallocations will |
133 | 525 |
occur (the memory system will allocate additional memory in chunks of smaller |
526 |
256k pieces, if a compress failes. Thus, if you are going to allocate (say) 1Mb of |
|
527 |
strings, it will perform 5 compressing GC's). |
|
528 |
||
202 | 529 |
This is done using ObjectMemory>>moreOldSpace: or ObjectMemory announceSpaceNeed:. |
530 |
In the above example, you would do 'ObjectMemory announceSpaceNeed:500000', which |
|
133 | 531 |
avoids those annoying 5 compressing GC's. |
207 | 532 |
BTW: if you have other smalltalk processes (threads) running which should not be |
533 |
paused if possible, it is better to use #announceSpaceNeed. This tries to avoid |
|
534 |
pausing in other processes and sometimes succeeds, while moreOldSpace will always |
|
535 |
block the whole system for a while. However, there is no 'no-pause' guarantee. |
|
133 | 536 |
|
537 |
The amount of automatic increase (in case the oldSpace becomes full) is 256k by |
|
538 |
default. This number can be changed with ObjectMemory>>oldSpaceIncrement:. |
|
539 |
||
207 | 540 |
|
541 |
Hint / Example3: |
|
178 | 542 |
There are rare cases, when an explicit GC makes a difference: since |
543 |
object finalization is done at GC time, objects which keep operatingSystem |
|
544 |
resources may be finalized late. This is normally no problem, except if |
|
545 |
the system is running out of resources. For example, allocating new colors |
|
546 |
may fail if many colors have already been allocated in the past - even |
|
547 |
though these colors are actually free. The Depth8Image calls for an |
|
548 |
explicit GC, whenever it fails to allocate a color for a bitmap, to force |
|
549 |
finalization of free, but not yet finalized colors. |
|
550 |
||
207 | 551 |
|
552 |
Hint 4: |
|
553 |
If you run in too small of physical memory, the incremental GC may have a |
|
554 |
bad effect on your working set: since it touches pages (which may otherwise |
|
555 |
not be needed at the moment, the operating system is forced to steal other |
|
556 |
(possibly more useful) pages from your set of incore pages. |
|
557 |
You may get better performance, if you turn off the incremental GC while |
|
558 |
processing a big data structure. |
|
559 |
||
560 |
||
229 | 561 |
Warning: many of the methods found here are not standard and may not even be available in |
133 | 562 |
future versions of ST/X. Use them only in very special situations or experiments. |
229 | 563 |
|
207 | 564 |
Let me know about additional special features you think are useful, and about |
565 |
special features you are using - this provides the feedback required to decide |
|
403 | 566 |
which methods are to be removed, kept or enhanced in future versions. |
93 | 567 |
" |
2 | 568 |
! ! |
569 |
||
570 |
!ObjectMemory class methodsFor:'initialization'! |
|
571 |
||
572 |
initialize |
|
178 | 573 |
"initialize the class" |
574 |
||
2 | 575 |
AllocationFailureSignal isNil ifTrue:[ |
302 | 576 |
AllocationFailureSignal := ErrorSignal newSignalMayProceed:true. |
159 | 577 |
AllocationFailureSignal nameClass:self message:#allocationFailureSignal. |
578 |
AllocationFailureSignal notifierString:'allocation failure'. |
|
178 | 579 |
|
464
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
580 |
MallocFailureSignal := ErrorSignal newSignalMayProceed:true. |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
581 |
MallocFailureSignal nameClass:self message:#mallocFailureSignal. |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
582 |
MallocFailureSignal notifierString:'(malloc) allocation failure'. |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
583 |
|
178 | 584 |
LowSpaceSemaphore := Semaphore new. |
2 | 585 |
]. |
290 | 586 |
DisposeInterruptHandler := self. |
2 | 587 |
IncrementalGCLimit := 500000. |
310 | 588 |
FreeSpaceGCLimit := FreeSpaceGCAmount := nil. |
13 | 589 |
MemoryInterruptHandler := self |
2 | 590 |
! ! |
591 |
||
345 | 592 |
!ObjectMemory class methodsFor:'Signal constants'! |
2 | 593 |
|
594 |
allocationFailureSignal |
|
13 | 595 |
"return the signal raised when an object allocation failed" |
596 |
||
2 | 597 |
^ AllocationFailureSignal |
464
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
598 |
! |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
599 |
|
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
600 |
mallocFailureSignal |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
601 |
"return the signal raised when malloc memory allocation failed. |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
602 |
(usually, this kind of memory is used with I/O buffers or other temporary |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
603 |
non-Object storage)" |
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
604 |
|
83af924c8cff
differenciate between object-allocation-failure and malloc-allocation-failure
Claus Gittinger <cg@exept.de>
parents:
458
diff
changeset
|
605 |
^ MallocFailureSignal |
2 | 606 |
! ! |
1 | 607 |
|
178 | 608 |
!ObjectMemory class methodsFor:'semaphore access'! |
609 |
||
610 |
lowSpaceSemaphore |
|
611 |
"return the semaphore that is signalled when the system detects a |
|
612 |
low space condition. Usually, some time after this, an allocationFailure |
|
613 |
will happen. You can have a cleanup process sitting in that semaphore and |
|
614 |
start to release object." |
|
615 |
||
616 |
^ LowSpaceSemaphore |
|
617 |
! ! |
|
618 |
||
375 | 619 |
!ObjectMemory class methodsFor:'VM messages'! |
620 |
||
621 |
infoPrinting:aBoolean |
|
622 |
"turn on/off various informational printouts in the VM. |
|
623 |
For example, the GC activity messages are controlled by |
|
624 |
this flags setting. |
|
625 |
The default is true, since (currently) those messages |
|
626 |
are useful for ST/X developers." |
|
627 |
||
628 |
%{ /* NOCONTEXT */ |
|
629 |
extern int __infoPrinting; |
|
630 |
||
631 |
__infoPrinting = (aBoolean == true); |
|
632 |
%} |
|
633 |
! |
|
634 |
||
635 |
infoPrinting |
|
636 |
"return true, if various informational printouts in the VM |
|
637 |
are turned on, false of off." |
|
638 |
||
639 |
%{ /* NOCONTEXT */ |
|
640 |
extern int __infoPrinting; |
|
641 |
||
642 |
RETURN (__infoPrinting ? true : false); |
|
643 |
%} |
|
644 |
! |
|
645 |
||
646 |
debugPrinting:aBoolean |
|
647 |
"turn on/off various debug printouts in the VM |
|
648 |
in case of an error. For example, a double-notUnderstood |
|
649 |
leads to a VM context dump if debugPrinting is on. |
|
650 |
If off, those messages are suppressed. |
|
651 |
The default is on, since these messages are only printed for |
|
652 |
severe errors." |
|
653 |
||
654 |
%{ /* NOCONTEXT */ |
|
655 |
extern int __debugPrinting; |
|
656 |
||
657 |
__debugPrinting = (aBoolean == true); |
|
658 |
%} |
|
659 |
! |
|
660 |
||
661 |
debugPrinting |
|
662 |
"return true, if various debug printouts in the VM |
|
663 |
are turned on, false of off." |
|
664 |
||
665 |
%{ /* NOCONTEXT */ |
|
666 |
extern int __debugPrinting; |
|
667 |
||
668 |
RETURN (__debugPrinting ? true : false); |
|
669 |
%} |
|
670 |
! ! |
|
671 |
||
10 | 672 |
!ObjectMemory class methodsFor:'dependents access'! |
673 |
||
674 |
dependents |
|
675 |
"return the colleciton of my dependents" |
|
676 |
||
677 |
^ Dependents |
|
678 |
! |
|
679 |
||
680 |
dependents:aCollection |
|
681 |
"set the dependents collection" |
|
682 |
||
683 |
Dependents := aCollection |
|
282 | 684 |
! |
685 |
||
686 |
dependentsDo:aBlock |
|
687 |
"evaluate aBlock for all of my dependents. |
|
688 |
Since this is performed at startup time (under the scheduler), |
|
689 |
this is redefined here to catch abort signals. |
|
690 |
Thus, if any error occurs in a #returnFromSnapshot, |
|
691 |
the user can press abort to continue." |
|
692 |
||
693 |
|deps| |
|
694 |
||
695 |
deps := Dependents. |
|
696 |
deps notNil ifTrue:[ |
|
697 |
deps do:[:each | |
|
698 |
AbortSignal handle:[:ex | |
|
699 |
ex return |
|
700 |
] do:[ |
|
701 |
aBlock value:each |
|
702 |
] |
|
703 |
] |
|
704 |
] |
|
10 | 705 |
! ! |
706 |
||
1 | 707 |
!ObjectMemory class methodsFor:'cache management'! |
708 |
||
709 |
flushInlineCachesForClass:aClass |
|
93 | 710 |
"flush inlinecaches for calls to aClass." |
1 | 711 |
|
712 |
%{ /* NOCONTEXT */ |
|
713 |
__flushInlineCachesFor(aClass); |
|
714 |
%} |
|
715 |
! |
|
716 |
||
717 |
flushInlineCachesWithArgs:nargs |
|
718 |
"flush inlinecaches for calls with nargs arguments" |
|
719 |
||
720 |
%{ /* NOCONTEXT */ |
|
721 |
__flushInlineCaches(_intVal(nargs)); |
|
722 |
%} |
|
723 |
! |
|
724 |
||
725 |
flushInlineCachesFor:aClass withArgs:nargs |
|
726 |
"flush inlinecaches for calls to aClass with nargs arguments" |
|
727 |
||
728 |
%{ /* NOCONTEXT */ |
|
729 |
__flushInlineCachesForAndNargs(aClass, _intVal(nargs)); |
|
730 |
%} |
|
731 |
! |
|
732 |
||
332 | 733 |
flushInlineCachesForSelector:aSelector |
734 |
"flush inlinecaches for sends of aSelector" |
|
735 |
||
736 |
%{ /* NOCONTEXT */ |
|
737 |
__flushInlineCachesForSelector(aSelector); |
|
738 |
%} |
|
739 |
! |
|
740 |
||
1 | 741 |
flushInlineCaches |
742 |
"flush all inlinecaches" |
|
743 |
||
744 |
%{ /* NOCONTEXT */ |
|
745 |
__flushAllInlineCaches(); |
|
746 |
%} |
|
747 |
! |
|
748 |
||
749 |
flushMethodCacheFor:aClass |
|
750 |
"flush the method cache for sends to aClass" |
|
751 |
||
752 |
%{ /* NOCONTEXT */ |
|
753 |
__flushMethodCacheFor(aClass); |
|
754 |
%} |
|
755 |
! |
|
756 |
||
332 | 757 |
flushMethodCacheForSelector:aSelector |
758 |
"flush the method cache for sends of aSelector" |
|
759 |
||
760 |
%{ /* NOCONTEXT */ |
|
761 |
__flushMethodCacheForSelector(aSelector); |
|
762 |
%} |
|
763 |
! |
|
764 |
||
1 | 765 |
flushMethodCache |
766 |
"flush the method cache" |
|
767 |
||
768 |
%{ /* NOCONTEXT */ |
|
769 |
__flushMethodCache(); |
|
770 |
%} |
|
771 |
! |
|
772 |
||
2 | 773 |
flushCachesFor:aClass |
774 |
"flush method and inline caches for aClass" |
|
775 |
||
776 |
%{ /* NOCONTEXT */ |
|
777 |
__flushMethodCacheFor(aClass); |
|
778 |
__flushInlineCachesFor(aClass); |
|
779 |
%} |
|
780 |
! |
|
781 |
||
332 | 782 |
flushCachesForSelector:aSelector |
440 | 783 |
"flush method and inline caches for aSelector" |
332 | 784 |
|
785 |
%{ /* NOCONTEXT */ |
|
786 |
__flushMethodCacheForSelector(aSelector); |
|
787 |
__flushInlineCachesForSelector(aSelector); |
|
788 |
%} |
|
789 |
! |
|
790 |
||
1 | 791 |
flushCaches |
2 | 792 |
"flush method and inline caches for all classes" |
1 | 793 |
|
794 |
%{ /* NOCONTEXT */ |
|
795 |
__flushMethodCache(); |
|
796 |
__flushAllInlineCaches(); |
|
797 |
%} |
|
798 |
! ! |
|
799 |
||
216 | 800 |
!ObjectMemory class methodsFor:'enumerating'! |
1 | 801 |
|
802 |
allObjectsDo:aBlock |
|
85 | 803 |
"evaluate the argument, aBlock for all objects in the system. |
804 |
There is one caveat: if a compressing oldSpace collect |
|
805 |
occurs while looping over the objects, the loop cannot be |
|
806 |
continued (for some internal reasons). In this case, false |
|
807 |
is returned." |
|
2 | 808 |
|
809 |
|work| |
|
22 | 810 |
|
811 |
%{ /* NOREGISTER - work may not be placed into a register here */ |
|
326 | 812 |
__nonTenuringScavenge(__context); |
2 | 813 |
/* |
814 |
* allObjectsDo needs a temporary to hold newSpace objects |
|
815 |
*/ |
|
369 | 816 |
if (__allInstancesOfDo((OBJ *)0, &aBlock, &work COMMA_CON) < 0) { |
817 |
RETURN (false); |
|
818 |
} |
|
819 |
%}. |
|
820 |
^ true |
|
821 |
! |
|
822 |
||
823 |
allInstancesOf:aClass do:aBlock |
|
824 |
"evaluate the argument, aBlock for all instances of aClass in the system. |
|
825 |
There is one caveat: if a compressing oldSpace collect |
|
826 |
occurs while looping over the objects, the loop cannot be |
|
827 |
continued (for some internal reasons). In this case, false |
|
828 |
is returned." |
|
829 |
||
830 |
|work| |
|
831 |
||
832 |
%{ /* NOREGISTER - work may not be placed into a register here */ |
|
833 |
__nonTenuringScavenge(__context); |
|
834 |
/* |
|
835 |
* allInstancesDo needs a temporary to hold newSpace objects |
|
836 |
*/ |
|
837 |
if (__allInstancesOfDo(&aClass, &aBlock, &work COMMA_CON) < 0) { |
|
159 | 838 |
RETURN (false); |
85 | 839 |
} |
840 |
%}. |
|
841 |
^ true |
|
2 | 842 |
! |
843 |
||
844 |
allOldObjectsDo:aBlock |
|
845 |
"evaluate the argument, aBlock for all old objects in the system. |
|
846 |
For debugging and tests only - do not use" |
|
847 |
%{ |
|
369 | 848 |
if (__allInstancesOfDo((OBJ *)0, &aBlock, (OBJ *)0 COMMA_CON) < 0) { |
159 | 849 |
RETURN (false); |
85 | 850 |
} |
851 |
%}. |
|
852 |
^ true |
|
1 | 853 |
! ! |
854 |
||
229 | 855 |
!ObjectMemory class methodsFor:'interrupt handler access'! |
2 | 856 |
|
857 |
internalErrorHandler |
|
13 | 858 |
"return the handler for ST/X internal errors. |
859 |
An internal error is reported for example when a methods |
|
860 |
bytecode is not a ByteArray, the selector table is not an Array |
|
93 | 861 |
etc. |
862 |
Those should not occur in normal circumstances." |
|
13 | 863 |
|
2 | 864 |
^ InternalErrorHandler |
865 |
! |
|
866 |
||
867 |
userInterruptHandler |
|
13 | 868 |
"return the handler for CNTL-C interrupt handling" |
869 |
||
2 | 870 |
^ UserInterruptHandler |
871 |
! |
|
872 |
||
873 |
userInterruptHandler:aHandler |
|
13 | 874 |
"set the handler for CNTL-C interrupt handling" |
875 |
||
2 | 876 |
UserInterruptHandler := aHandler |
877 |
! |
|
878 |
||
879 |
timerInterruptHandler |
|
13 | 880 |
"return the handler for timer interrupts" |
881 |
||
2 | 882 |
^ TimerInterruptHandler |
883 |
! |
|
884 |
||
10 | 885 |
timerInterruptHandler:aHandler |
13 | 886 |
"set the handler for timer interrupts" |
887 |
||
10 | 888 |
TimerInterruptHandler := aHandler |
889 |
! |
|
890 |
||
2 | 891 |
spyInterruptHandler |
13 | 892 |
"return the handler for spy-timer interrupts" |
893 |
||
2 | 894 |
^ SpyInterruptHandler |
895 |
! |
|
896 |
||
897 |
spyInterruptHandler:aHandler |
|
13 | 898 |
"set the handler for spy-timer interrupts" |
899 |
||
2 | 900 |
SpyInterruptHandler := aHandler |
901 |
! |
|
902 |
||
903 |
stepInterruptHandler |
|
13 | 904 |
"return the handler for single step interrupts" |
905 |
||
2 | 906 |
^ StepInterruptHandler |
907 |
! |
|
908 |
||
909 |
stepInterruptHandler:aHandler |
|
13 | 910 |
"set the handler for single step interrupts" |
911 |
||
2 | 912 |
StepInterruptHandler := aHandler |
913 |
! |
|
914 |
||
915 |
exceptionInterruptHandler |
|
13 | 916 |
"return the handler for floating point exception interrupts" |
917 |
||
2 | 918 |
^ ExceptionInterruptHandler |
919 |
! |
|
920 |
||
921 |
errorInterruptHandler |
|
13 | 922 |
"return the handler for display error interrupts" |
923 |
||
2 | 924 |
^ ErrorInterruptHandler |
925 |
! |
|
926 |
||
927 |
errorInterruptHandler:aHandler |
|
13 | 928 |
"set the handler for display error interrupts" |
929 |
||
2 | 930 |
ErrorInterruptHandler := aHandler |
931 |
! |
|
932 |
||
345 | 933 |
registeredErrorInterruptHandlers |
934 |
"return registered handlers" |
|
935 |
||
936 |
^ RegisteredErrorInterruptHandlers |
|
937 |
! |
|
938 |
||
939 |
registerErrorInterruptHandler:aHandler forID:errorIDSymbol |
|
940 |
"register a handler" |
|
941 |
||
942 |
RegisteredErrorInterruptHandlers isNil ifTrue:[ |
|
943 |
RegisteredErrorInterruptHandlers := IdentityDictionary new |
|
944 |
]. |
|
945 |
RegisteredErrorInterruptHandlers at:errorIDSymbol put:aHandler |
|
946 |
! |
|
947 |
||
13 | 948 |
signalInterruptHandler |
949 |
"return the handler for UNIX-signal interrupts" |
|
2 | 950 |
|
951 |
^ SignalInterruptHandler |
|
952 |
! |
|
953 |
||
13 | 954 |
signalInterruptHandler:aHandler |
955 |
"set the handler for UNIX-signal interrupts" |
|
956 |
||
957 |
SignalInterruptHandler := aHandler |
|
958 |
! |
|
959 |
||
2 | 960 |
childSignalInterruptHandler |
13 | 961 |
"return the handler for UNIX-death-of-a-childprocess-signal interrupts" |
962 |
||
2 | 963 |
^ ChildSignalInterruptHandler |
964 |
! |
|
965 |
||
966 |
disposeInterruptHandler |
|
13 | 967 |
"return the handler for object disposal interrupts" |
968 |
||
2 | 969 |
^ DisposeInterruptHandler |
970 |
! |
|
971 |
||
972 |
disposeInterruptHandler:aHandler |
|
13 | 973 |
"set the handler for object disposal interrupts" |
974 |
||
2 | 975 |
DisposeInterruptHandler := aHandler |
976 |
! |
|
977 |
||
978 |
recursionInterruptHandler |
|
13 | 979 |
"return the handler for recursion/stack overflow interrupts" |
980 |
||
2 | 981 |
^ RecursionInterruptHandler |
982 |
! |
|
983 |
||
13 | 984 |
recursionInterruptHandler:aHandler |
985 |
"set the handler for recursion/stack overflow interrupts" |
|
986 |
||
987 |
RecursionInterruptHandler := aHandler |
|
988 |
! |
|
989 |
||
2 | 990 |
ioInterruptHandler |
13 | 991 |
"return the handler for I/O available signal interrupts (SIGIO/SIGPOLL)" |
992 |
||
2 | 993 |
^ IOInterruptHandler |
994 |
! |
|
995 |
||
996 |
ioInterruptHandler:aHandler |
|
13 | 997 |
"set the handler for I/O available signal interrupts (SIGIO/SIGPOLL)" |
998 |
||
2 | 999 |
IOInterruptHandler := aHandler |
85 | 1000 |
! |
1001 |
||
1002 |
customInterruptHandler |
|
1003 |
"return the handler for custom interrupts" |
|
1004 |
||
1005 |
^ CustomInterruptHandler |
|
1006 |
! |
|
1007 |
||
1008 |
customInterruptHandler:aHandler |
|
1009 |
"set the handler for custom interrupts" |
|
1010 |
||
1011 |
CustomInterruptHandler := aHandler |
|
2 | 1012 |
! ! |
1013 |
||
1 | 1014 |
!ObjectMemory class methodsFor:'queries'! |
1015 |
||
13 | 1016 |
newSpaceSize |
1017 |
"return the total size of the new space - this is usually fix" |
|
1018 |
||
1019 |
%{ /* NOCONTEXT */ |
|
133 | 1020 |
extern unsigned __newSpaceSize(); |
1021 |
||
13 | 1022 |
RETURN ( _MKSMALLINT(__newSpaceSize()) ); |
1023 |
%} |
|
93 | 1024 |
" |
1025 |
ObjectMemory newSpaceSize |
|
1026 |
" |
|
13 | 1027 |
! |
1028 |
||
1029 |
oldSpaceSize |
|
1030 |
"return the total size of the old space. - may grow slowly" |
|
1031 |
||
1032 |
%{ /* NOCONTEXT */ |
|
133 | 1033 |
extern unsigned __oldSpaceSize(); |
1034 |
||
13 | 1035 |
RETURN ( _MKSMALLINT(__oldSpaceSize()) ); |
1036 |
%} |
|
93 | 1037 |
" |
1038 |
ObjectMemory oldSpaceSize |
|
1039 |
" |
|
13 | 1040 |
! |
1041 |
||
325 | 1042 |
symSpaceSize |
1043 |
"return the total size of the sym space." |
|
1044 |
||
1045 |
%{ /* NOCONTEXT */ |
|
1046 |
extern unsigned __symSpaceSize(); |
|
1047 |
||
1048 |
RETURN ( _MKSMALLINT(__symSpaceSize()) ); |
|
1049 |
%} |
|
1050 |
" |
|
1051 |
ObjectMemory symSpaceSize |
|
1052 |
" |
|
1053 |
! |
|
1054 |
||
216 | 1055 |
fixSpaceSize |
1056 |
"return the total size of the fix space." |
|
1057 |
||
1058 |
%{ /* NOCONTEXT */ |
|
1059 |
extern unsigned __fixSpaceSize(); |
|
1060 |
||
1061 |
RETURN ( _MKSMALLINT(__fixSpaceSize()) ); |
|
1062 |
%} |
|
1063 |
" |
|
1064 |
ObjectMemory fixSpaceSize |
|
1065 |
" |
|
1066 |
! |
|
1067 |
||
1 | 1068 |
newSpaceUsed |
10 | 1069 |
"return the number of bytes allocated for new objects. |
1070 |
The returned value is usually obsolete as soon as you do |
|
13 | 1071 |
something with it ..." |
1 | 1072 |
|
1073 |
%{ /* NOCONTEXT */ |
|
133 | 1074 |
extern unsigned __newSpaceUsed(); |
1075 |
||
1 | 1076 |
RETURN ( _MKSMALLINT(__newSpaceUsed()) ); |
1077 |
%} |
|
93 | 1078 |
" |
202 | 1079 |
ObjectMemory newSpaceUsed |
93 | 1080 |
" |
1 | 1081 |
! |
1082 |
||
1083 |
oldSpaceUsed |
|
10 | 1084 |
"return the number of bytes allocated for old objects. |
1085 |
(This includes the free lists)" |
|
1 | 1086 |
|
1087 |
%{ /* NOCONTEXT */ |
|
133 | 1088 |
extern unsigned __oldSpaceUsed(); |
1089 |
||
1 | 1090 |
RETURN ( _MKSMALLINT(__oldSpaceUsed()) ); |
1091 |
%} |
|
93 | 1092 |
" |
202 | 1093 |
ObjectMemory oldSpaceUsed |
93 | 1094 |
" |
1 | 1095 |
! |
1096 |
||
325 | 1097 |
symSpaceUsed |
1098 |
"return the number of bytes allocated for old objects in sym space." |
|
1099 |
||
1100 |
%{ /* NOCONTEXT */ |
|
1101 |
extern unsigned __symSpaceUsed(); |
|
1102 |
||
1103 |
RETURN ( _MKSMALLINT(__symSpaceUsed()) ); |
|
1104 |
%} |
|
1105 |
" |
|
1106 |
ObjectMemory symSpaceUsed |
|
1107 |
" |
|
1108 |
! |
|
1109 |
||
216 | 1110 |
fixSpaceUsed |
1111 |
"return the number of bytes allocated for old objects in fix space." |
|
1112 |
||
1113 |
%{ /* NOCONTEXT */ |
|
1114 |
extern unsigned __fixSpaceUsed(); |
|
1115 |
||
1116 |
RETURN ( _MKSMALLINT(__fixSpaceUsed()) ); |
|
1117 |
%} |
|
1118 |
" |
|
1119 |
ObjectMemory fixSpaceUsed |
|
1120 |
" |
|
1121 |
! |
|
1122 |
||
270 | 1123 |
freeSpace |
1124 |
"return the number of bytes in the compact free area. |
|
1125 |
(oldSpaceUsed + freeSpaceSize = oldSpaceSize)" |
|
1126 |
||
1127 |
%{ /* NOCONTEXT */ |
|
1128 |
extern unsigned __oldSpaceSize(), __oldSpaceUsed(); |
|
1129 |
||
1130 |
RETURN ( _MKSMALLINT(__oldSpaceSize() - __oldSpaceUsed()) ); |
|
1131 |
%} |
|
1132 |
" |
|
1133 |
ObjectMemory freeSpace |
|
1134 |
" |
|
1135 |
! |
|
1136 |
||
133 | 1137 |
freeListSpace |
10 | 1138 |
"return the number of bytes in the free lists. |
1139 |
(which is included in oldSpaceUsed)" |
|
1140 |
||
1141 |
%{ /* NOCONTEXT */ |
|
133 | 1142 |
extern unsigned __freeListSpace(); |
1143 |
||
1144 |
RETURN ( _MKSMALLINT(__freeListSpace()) ); |
|
10 | 1145 |
%} |
93 | 1146 |
" |
133 | 1147 |
ObjectMemory freeListSpace |
93 | 1148 |
" |
10 | 1149 |
! |
1150 |
||
1 | 1151 |
bytesUsed |
1152 |
"return the number of bytes allocated for objects - |
|
178 | 1153 |
this number is not exact, since some objects may already be dead |
1154 |
(i.e. not yet reclaimed by the garbage collector). |
|
1155 |
If you need the exact number, you have to loop over all |
|
1156 |
objects and ask for the bytesize using ObjectMemory>>sizeOf:." |
|
1 | 1157 |
|
1158 |
%{ /* NOCONTEXT */ |
|
133 | 1159 |
extern unsigned __oldSpaceUsed(), __newSpaceUsed(), __freeListSpace(); |
1160 |
||
1161 |
RETURN ( _MKSMALLINT(__oldSpaceUsed() + __newSpaceUsed() - __freeListSpace()) ); |
|
1 | 1162 |
%} |
93 | 1163 |
" |
202 | 1164 |
ObjectMemory bytesUsed |
93 | 1165 |
" |
1 | 1166 |
! |
1167 |
||
2 | 1168 |
oldSpaceAllocatedSinceLastGC |
1169 |
"return the number of bytes allocated for old objects since the |
|
178 | 1170 |
last oldspace garbage collect occured. This information is used |
1171 |
by ProcessorScheduler to decide when to start the incremental |
|
1172 |
background GC." |
|
2 | 1173 |
|
1174 |
%{ /* NOCONTEXT */ |
|
133 | 1175 |
extern unsigned __oldSpaceAllocatedSinceLastGC(); |
1176 |
||
2 | 1177 |
RETURN ( _MKSMALLINT(__oldSpaceAllocatedSinceLastGC()) ); |
1178 |
%} |
|
93 | 1179 |
" |
202 | 1180 |
ObjectMemory oldSpaceAllocatedSinceLastGC |
93 | 1181 |
" |
2 | 1182 |
! |
1183 |
||
178 | 1184 |
tenureAge |
1185 |
"return the current tenure age - thats the number of times |
|
1186 |
an object has to survive scavenges to be moved into oldSpace. |
|
202 | 1187 |
For statistic/debugging only - this method may vanish" |
178 | 1188 |
|
1189 |
%{ /* NOCONTEXT */ |
|
1190 |
extern unsigned __tenureAge(); |
|
1191 |
||
1192 |
RETURN ( _MKSMALLINT(__tenureAge()) ); |
|
1193 |
%} |
|
1194 |
! |
|
1195 |
||
362 | 1196 |
lastScavengeReclamation |
194 | 1197 |
"returns the number of bytes replacimed by the last scavenge. |
1198 |
For statistic only - this may vanish." |
|
1199 |
||
1200 |
%{ /* NOCONTEXT */ |
|
1201 |
extern int __newSpaceReclaimed(); |
|
1202 |
||
1203 |
RETURN ( _MKSMALLINT(__newSpaceReclaimed()) ); |
|
1204 |
%} |
|
202 | 1205 |
"percentage of reclaimed objects is returned by: |
1206 |
||
362 | 1207 |
((ObjectMemory lastScavengeReclamation) |
202 | 1208 |
/ (ObjectMemory newSpaceSize)) * 100.0 |
194 | 1209 |
" |
1210 |
! |
|
1211 |
||
362 | 1212 |
resetMinScavengeReclamation |
1213 |
"resets the number of bytes replacimed by the least effective scavenge. |
|
1214 |
For statistic only - this may vanish." |
|
1215 |
||
1216 |
%{ /* NOCONTEXT */ |
|
1217 |
extern int __resetNewSpaceReclaimedMin(); |
|
1218 |
||
1219 |
__resetNewSpaceReclaimedMin(); |
|
1220 |
%}. |
|
1221 |
^ self |
|
1222 |
" |
|
1223 |
ObjectMemory resetMinScavengeReclamation. |
|
1224 |
ObjectMemory minScavengeReclamation |
|
1225 |
" |
|
1226 |
! |
|
1227 |
||
1228 |
minScavengeReclamation |
|
1229 |
"returns the number of bytes replacimed by the least effective scavenge. |
|
1230 |
For statistic only - this may vanish." |
|
1231 |
||
1232 |
%{ /* NOCONTEXT */ |
|
1233 |
extern int __newSpaceReclaimedMin(); |
|
1234 |
||
1235 |
RETURN ( _MKSMALLINT(__newSpaceReclaimedMin()) ); |
|
1236 |
%} |
|
1237 |
" |
|
1238 |
ObjectMemory minScavengeReclamation |
|
1239 |
" |
|
1240 |
! |
|
1241 |
||
178 | 1242 |
runsSingleOldSpace |
1243 |
"return true, if the system runs in a single oldSpace or |
|
326 | 1244 |
false if not. |
1245 |
The memory system will always drop the second semispace when |
|
1246 |
running out of virtual memory, or the baker-limit is reached. |
|
202 | 1247 |
OBSOLETE: |
1248 |
the system may now decide at any time to switch between |
|
1249 |
single and double-space algorithms, depending on the overall memory |
|
1250 |
size. You will now almost always get false as result, since the |
|
326 | 1251 |
second semispace is only allocated when needed, and released |
1252 |
immediately afterwards. |
|
202 | 1253 |
" |
178 | 1254 |
|
1255 |
%{ /* NOCONTEXT */ |
|
357 | 1256 |
extern int __runsSingleOldSpace(); |
1257 |
||
1258 |
RETURN ( (__runsSingleOldSpace() ? true : false) ); |
|
178 | 1259 |
%} |
202 | 1260 |
" |
1261 |
ObjectMemory runsSingleOldSpace |
|
1262 |
" |
|
178 | 1263 |
! |
1264 |
||
1265 |
incrementalGCPhase |
|
1266 |
"returns the internal state of the incremental GC. |
|
1267 |
The meaning of those numbers is a secret :-). |
|
326 | 1268 |
(for the curious: (currently) |
1269 |
2 is idle, 3..11 are various mark phases, |
|
1270 |
12 is the sweep phase. 0 and 1 are cleanup phases when the |
|
1271 |
incr. GC gets interrupted by a full GC). |
|
356 | 1272 |
Do not depend on the values - there may be additional phases in |
1273 |
future versions (incremental compact ;-). |
|
326 | 1274 |
This is for debugging and monitoring only - and may change or vanish" |
178 | 1275 |
|
1276 |
%{ /* NOCONTEXT */ |
|
1277 |
extern int __incrGCphase(); |
|
1278 |
||
1279 |
RETURN (_MKSMALLINT(__incrGCphase())); |
|
1280 |
%} |
|
1281 |
! |
|
1282 |
||
270 | 1283 |
scavengeCount |
1284 |
"return the number of scavenges that occurred since startup" |
|
1285 |
||
1286 |
%{ /* NOCONTEXT */ |
|
1287 |
extern int __scavengeCount(); |
|
1288 |
||
1289 |
RETURN (_MKSMALLINT(__scavengeCount())); |
|
1290 |
%} |
|
1291 |
" |
|
1292 |
ObjectMemory scavengeCount |
|
1293 |
" |
|
1294 |
! |
|
1295 |
||
1296 |
markAndSweepCount |
|
1297 |
"return the number of mark&sweep collects that occurred since startup" |
|
1298 |
||
1299 |
%{ /* NOCONTEXT */ |
|
1300 |
extern int __markAndSweepCount(); |
|
1301 |
||
1302 |
RETURN (_MKSMALLINT(__markAndSweepCount())); |
|
1303 |
%} |
|
1304 |
" |
|
1305 |
ObjectMemory markAndSweepCount |
|
1306 |
" |
|
1307 |
! |
|
1308 |
||
1309 |
garbageCollectCount |
|
1310 |
"return the number of compressing collects that occurred since startup" |
|
1311 |
||
1312 |
%{ /* NOCONTEXT */ |
|
1313 |
extern int __garbageCollectCount(); |
|
1314 |
||
1315 |
RETURN (_MKSMALLINT(__garbageCollectCount())); |
|
1316 |
%} |
|
1317 |
" |
|
1318 |
ObjectMemory garbageCollectCount |
|
1319 |
" |
|
1320 |
! |
|
1321 |
||
443 | 1322 |
incrementalGCCount |
1323 |
"return the number of incremental collects that occurred since startup" |
|
1324 |
||
1325 |
%{ /* NOCONTEXT */ |
|
1326 |
extern int __incrementalGCCount(); |
|
1327 |
||
1328 |
RETURN (_MKSMALLINT(__incrementalGCCount())); |
|
1329 |
%} |
|
1330 |
" |
|
1331 |
ObjectMemory incrementalGCCount |
|
1332 |
" |
|
1333 |
! |
|
1334 |
||
362 | 1335 |
rememberedSetSize |
369 | 1336 |
"return the number of old objects referencing new ones. |
1337 |
This is a VM debugging interface and may vanish without notice." |
|
362 | 1338 |
|
1339 |
%{ /* NOCONTEXT */ |
|
1340 |
extern int __rememberedSetSize(); |
|
1341 |
||
1342 |
RETURN (_MKSMALLINT(__rememberedSetSize())); |
|
1343 |
%} |
|
1344 |
" |
|
1345 |
ObjectMemory rememberedSetSize |
|
1346 |
" |
|
1347 |
! |
|
1348 |
||
369 | 1349 |
lifoRememberedSetSize |
1350 |
"return the size of the lifoRemSet. |
|
1351 |
This is a VM debugging interface and may vanish without notice." |
|
1352 |
||
1353 |
%{ /* NOCONTEXT */ |
|
1354 |
extern int __lifoRememberedSetSize(); |
|
1355 |
||
1356 |
RETURN (_MKSMALLINT(__lifoRememberedSetSize())); |
|
1357 |
%} |
|
1358 |
" |
|
1359 |
ObjectMemory lifoRememberedSetSize |
|
1360 |
" |
|
1361 |
! |
|
1362 |
||
1363 |
lifoRememberedSet |
|
1364 |
"return the lifoRemSet. |
|
1365 |
This is pure VM debugging and will vanish without notice." |
|
1366 |
||
1367 |
%{ /* NOCONTEXT */ |
|
1368 |
extern OBJ __lifoRememberedSet(); |
|
1369 |
||
1370 |
RETURN ( __lifoRememberedSet() ); |
|
1371 |
%} |
|
1372 |
" |
|
1373 |
ObjectMemory lifoRememberedSet |
|
1374 |
" |
|
1375 |
! |
|
1376 |
||
1377 |
numberOfWeakObjects |
|
1378 |
"return the number of weak objects in the system" |
|
1379 |
||
1380 |
%{ /* NOCONTEXT */ |
|
1381 |
extern int __weakListSize(); |
|
1382 |
||
1383 |
RETURN ( __MKSMALLINT(__weakListSize()) ); |
|
1384 |
%} |
|
1385 |
" |
|
1386 |
ObjectMemory numberOfWeakObjects |
|
1387 |
" |
|
1388 |
! |
|
1389 |
||
1 | 1390 |
numberOfObjects |
13 | 1391 |
"return the number of objects in the system." |
1 | 1392 |
|
326 | 1393 |
|tally "{ Class: SmallInteger }"| |
1 | 1394 |
|
1395 |
tally := 0. |
|
1396 |
self allObjectsDo:[:obj | tally := tally + 1]. |
|
1397 |
^ tally |
|
1398 |
||
93 | 1399 |
" |
202 | 1400 |
ObjectMemory numberOfObjects |
93 | 1401 |
" |
1 | 1402 |
! |
1403 |
||
202 | 1404 |
collectObjectsWhich:aBlock |
1405 |
"helper for the whoReferences queries. Returns a collection |
|
1406 |
of objects for which aBlock returns true." |
|
1 | 1407 |
|
1408 |
|aCollection| |
|
1409 |
||
1410 |
aCollection := IdentitySet new. |
|
1411 |
self allObjectsDo:[:o | |
|
202 | 1412 |
(aBlock value:o) ifTrue:[ |
159 | 1413 |
aCollection add:o |
1414 |
] |
|
1 | 1415 |
]. |
1416 |
(aCollection size == 0) ifTrue:[ |
|
159 | 1417 |
"actually this cannot happen - there is always one" |
1418 |
^ nil |
|
1 | 1419 |
]. |
1420 |
^ aCollection |
|
13 | 1421 |
! |
1422 |
||
202 | 1423 |
whoReferences:anObject |
1424 |
"return a collection of objects referencing the argument, anObject" |
|
1425 |
||
1426 |
^ self collectObjectsWhich:[:o | o references:anObject] |
|
1427 |
||
1428 |
" |
|
1429 |
(ObjectMemory whoReferences:Transcript) printNL |
|
1430 |
" |
|
1431 |
! |
|
1432 |
||
1433 |
whoReferencesInstancesOf:aClass |
|
1434 |
"return a collection of objects refering to instances |
|
1435 |
of the argument, aClass" |
|
1436 |
||
1437 |
^ self collectObjectsWhich:[:o | o referencesInstanceOf:aClass] |
|
1438 |
||
1439 |
" |
|
1440 |
(ObjectMemory whoReferencesInstancesOf:SystemBrowser) printNL |
|
1441 |
" |
|
1442 |
! |
|
1443 |
||
1444 |
whoReferencesDerivedInstancesOf:aClass |
|
1445 |
"return a collection of objects refering to instances |
|
1446 |
of the argument, aClass or a subclass of it." |
|
1447 |
||
1448 |
^ self collectObjectsWhich:[:o | o referencesDerivedInstanceOf:aClass] |
|
1449 |
||
1450 |
" |
|
1451 |
(ObjectMemory whoReferencesDerivedInstancesOf:View) printNL |
|
1452 |
" |
|
1453 |
! |
|
1454 |
||
435 | 1455 |
maximumIdentityHashValue |
1456 |
"for ST-80 compatibility: return the maximum value |
|
1457 |
a hashKey as returned by identityHash can get. |
|
1458 |
Since ST/X uses direct pointers, a field in the objectHeader |
|
1459 |
is used, which is currently 11 bits in size." |
|
1460 |
||
1461 |
%{ /* NOCONTEXT */ |
|
1462 |
RETURN ( __MKSMALLINT( __MAX_HASH__ << __HASH_SHIFT__) ); |
|
1463 |
%} |
|
1464 |
" |
|
1465 |
ObjectMemory maximumIdentityHashValue |
|
1466 |
" |
|
1467 |
! ! |
|
1468 |
||
1469 |
!ObjectMemory class methodsFor:'debug queries'! |
|
1470 |
||
1471 |
printReferences:anObject |
|
1472 |
"for debugging: print referents to anObject. |
|
1473 |
WARNING: this method is for ST/X debugging only |
|
1474 |
it will be removed without notice |
|
1475 |
use ObjectMemory>>whoReferences: or anObject>>allOwners." |
|
1476 |
||
1477 |
%{ |
|
1478 |
__printRefChain(__context, anObject); |
|
1479 |
%} |
|
1480 |
! |
|
1481 |
||
1482 |
dumpObject:someObject |
|
1483 |
"low level dump an object. |
|
1484 |
WARNING: this method is for ST/X debugging only |
|
1485 |
it will be removed without notice" |
|
1486 |
||
1487 |
%{ |
|
1488 |
dumpObject(someObject); |
|
1489 |
%} |
|
1490 |
" |
|
1491 |
ObjectMemory dumpObject:true |
|
1492 |
ObjectMemory dumpObject:(Array new:10) |
|
1493 |
ObjectMemory dumpObject:(10@20 corner:30@40) |
|
1494 |
" |
|
1495 |
! |
|
1496 |
||
13 | 1497 |
addressOf:anObject |
1498 |
"return the core address of anObject as an integer |
|
1499 |
- since objects may move around, the returned value is invalid after the |
|
1500 |
next scavenge/collect. |
|
435 | 1501 |
WARNING: this method is for ST/X debugging only |
1502 |
it will be removed without notice" |
|
13 | 1503 |
|
1504 |
%{ /* NOCONTEXT */ |
|
1505 |
||
329 | 1506 |
if (! __isNonNilObject(anObject)) { |
159 | 1507 |
RETURN ( nil ); |
13 | 1508 |
} |
326 | 1509 |
if (((int)anObject >= _MIN_INT) && ((int)anObject <= _MAX_INT)) { |
1510 |
RETURN ( _MKSMALLINT((int)anObject) ); |
|
1511 |
} |
|
1512 |
RETURN ( _MKLARGEINT((int)anObject) ); |
|
13 | 1513 |
%} |
1514 |
" |
|
1515 |
|p| |
|
1516 |
p := Point new. |
|
370 | 1517 |
((ObjectMemory addressOf:p) printStringRadix:16) printNL. |
13 | 1518 |
ObjectMemory scavenge. |
370 | 1519 |
((ObjectMemory addressOf:p) printStringRadix:16) printNL. |
13 | 1520 |
" |
1521 |
! |
|
1522 |
||
159 | 1523 |
objectAt:anAddress |
1524 |
"return whatever anAddress points to as object. |
|
202 | 1525 |
BIG BIG DANGER ALERT: |
326 | 1526 |
this method is only to be used for debugging ST/X itself |
1527 |
- you can easily (and badly) crash the system. |
|
435 | 1528 |
WARNING: this method is for ST/X debugging only |
1529 |
it will be removed without notice" |
|
159 | 1530 |
|
1531 |
|low high| |
|
1532 |
||
1533 |
low := anAddress bitAnd:16rFFFF. |
|
1534 |
high := (anAddress bitShift:16) bitAnd:16rFFFF. |
|
1535 |
%{ |
|
253 | 1536 |
if (__bothSmallInteger(low, high)) { |
159 | 1537 |
RETURN ((OBJ)((_intVal(high) << 16) | _intVal(low))); |
1538 |
} |
|
1539 |
%} |
|
1540 |
! |
|
1541 |
||
13 | 1542 |
sizeOf:anObject |
1543 |
"return the size of anObject in bytes. |
|
326 | 1544 |
(this is not the same as 'anObject size'). |
435 | 1545 |
WARNING: this method is for ST/X debugging only |
1546 |
it will be removed without notice" |
|
13 | 1547 |
|
1548 |
%{ /* NOCONTEXT */ |
|
1549 |
||
329 | 1550 |
RETURN ( __isNonNilObject(anObject) ? _MKSMALLINT(__qSize(anObject)) : _MKSMALLINT(0) ) |
13 | 1551 |
%} |
1552 |
" |
|
1553 |
|hist big nw| |
|
1554 |
||
1555 |
hist := Array new:100 withAll:0. |
|
1556 |
big := 0. |
|
1557 |
ObjectMemory allObjectsDo:[:o | |
|
159 | 1558 |
nw := (ObjectMemory sizeOf:o) // 4 + 1. |
1559 |
nw > 100 ifTrue:[ |
|
1560 |
big := big + 1 |
|
1561 |
] ifFalse:[ |
|
1562 |
hist at:nw put:(hist at:nw) + 1 |
|
1563 |
]. |
|
13 | 1564 |
]. |
77 | 1565 |
hist printNL. |
1566 |
big printNL |
|
13 | 1567 |
" |
1568 |
! |
|
1569 |
||
435 | 1570 |
ageOf:anObject |
1571 |
"return the number of scavenges, an object has survived |
|
1572 |
in new space. |
|
1573 |
For old objects and living contexts, the returned number is invalid. |
|
1574 |
WARNING: this method is for ST/X debugging only |
|
1575 |
it will be removed without notice" |
|
13 | 1576 |
|
1577 |
%{ /* NOCONTEXT */ |
|
1578 |
||
329 | 1579 |
if (! __isNonNilObject(anObject)) { |
435 | 1580 |
RETURN ( 0 ); |
13 | 1581 |
} |
435 | 1582 |
RETURN ( _MKSMALLINT( _GET_AGE(anObject) ) ); |
13 | 1583 |
%} |
435 | 1584 |
" |
1585 |
|p| |
|
1586 |
p := Point new. |
|
1587 |
(ObjectMemory ageOf:p) printNL. |
|
1588 |
ObjectMemory tenuringScavenge. |
|
1589 |
(ObjectMemory spaceOf:p) printNL. |
|
1590 |
ObjectMemory tenuringScavenge. |
|
1591 |
(ObjectMemory spaceOf:p) printNL. |
|
1592 |
ObjectMemory tenuringScavenge. |
|
1593 |
(ObjectMemory spaceOf:p) printNL. |
|
1594 |
ObjectMemory tenuringScavenge. |
|
1595 |
(ObjectMemory spaceOf:p) printNL. |
|
1596 |
" |
|
159 | 1597 |
! |
1598 |
||
1599 |
flagsOf:anObject |
|
435 | 1600 |
"For debugging only. |
1601 |
WARNING: this method is for ST/X debugging only |
|
1602 |
it will be removed without notice" |
|
202 | 1603 |
|
159 | 1604 |
%{ /* NOCONTEXT */ |
1605 |
||
329 | 1606 |
if (! __isNonNilObject(anObject)) { |
159 | 1607 |
RETURN ( nil ); |
1608 |
} |
|
1609 |
RETURN ( _MKSMALLINT( anObject->o_flags ) ); |
|
1610 |
%} |
|
13 | 1611 |
" |
202 | 1612 |
F_ISREMEMBERED 1 /* a new-space thing being refd by some oldSpace thing */ |
1613 |
F_ISFORWARDED 2 /* a forwarded object (you will never see this here) */ |
|
159 | 1614 |
F_DEREFERENCED 4 /* a collection after grow (not currently used) */ |
1615 |
F_ISONLIFOLIST 8 /* a non-lifo-context-referencing-obj already on list */ |
|
1616 |
F_MARK 16 /* mark bit for background collector */ |
|
77 | 1617 |
" |
326 | 1618 |
|
1619 |
" |
|
1620 |
|arr| |
|
1621 |
||
1622 |
arr := Array new. |
|
1623 |
arr at:1 put:([thisContext] value). |
|
1624 |
(ObjectMemory flagsOf:anObject) printNL |
|
1625 |
" |
|
77 | 1626 |
! |
1627 |
||
435 | 1628 |
spaceOf:anObject |
1629 |
"return the memory space, in which anObject is. |
|
1630 |
- since objects may move between spaces, |
|
1631 |
the returned value may be invalid after the next scavenge/collect. |
|
1632 |
WARNING: this method is for ST/X debugging only |
|
1633 |
it will be removed without notice" |
|
77 | 1634 |
|
1635 |
%{ /* NOCONTEXT */ |
|
1636 |
||
329 | 1637 |
if (! __isNonNilObject(anObject)) { |
435 | 1638 |
RETURN ( nil ); |
77 | 1639 |
} |
435 | 1640 |
RETURN ( _MKSMALLINT( __qSpace(anObject) ) ); |
77 | 1641 |
%} |
1 | 1642 |
! ! |
1643 |
||
178 | 1644 |
!ObjectMemory class methodsFor:'garbage collection'! |
1 | 1645 |
|
133 | 1646 |
scavenge |
1647 |
"collect young objects, without aging (i.e. no tenure). |
|
1648 |
Can be used to quickly get rid of shortly before allocated |
|
1649 |
stuff. This is relatively fast (compared to oldspace collect). |
|
1650 |
||
1651 |
An example where a non-tenuring scavenge makes sense is when |
|
1652 |
allocating some OperatingSystem resource (a Color, File or View) |
|
1653 |
and the OS runs out of resources. In this case, the scavenge may |
|
1654 |
free some ST-objects and therefore (by signalling the WeakArrays |
|
1655 |
or Registries) free the OS resources too. |
|
1656 |
Of course, only recently allocated resources will be freed this |
|
1657 |
way. If none was freed, a full collect will be needed." |
|
1658 |
%{ |
|
326 | 1659 |
__nonTenuringScavenge(__context); |
133 | 1660 |
%} |
1661 |
||
1662 |
" |
|
1663 |
ObjectMemory scavenge |
|
1664 |
" |
|
1665 |
! |
|
1666 |
||
1667 |
tenuringScavenge |
|
1668 |
"collect newspace stuff, with aging (i.e. objects old enough |
|
1669 |
will be moved into the oldSpace). |
|
1670 |
Use this for debugging and testing only - the system performs |
|
1671 |
this automatically when the newspace fills up. |
|
1672 |
This is relatively fast (compared to oldspace collect)" |
|
1673 |
%{ |
|
326 | 1674 |
__scavenge(__context); |
133 | 1675 |
%} |
1676 |
||
1677 |
" |
|
1678 |
ObjectMemory tenuringScavenge |
|
1679 |
" |
|
1680 |
! |
|
1681 |
||
1682 |
tenure |
|
1683 |
"force all living new stuff into old-space - effectively making |
|
312 | 1684 |
all living young objects become old objects immediately. |
133 | 1685 |
This is relatively fast (compared to oldspace collect). |
1686 |
||
1687 |
This method should only be used in very special situations: |
|
1688 |
for example, when building up some long-living data structure |
|
1689 |
in a time critical application. |
|
194 | 1690 |
To do so, you have to do a scavenge followed by a tenure after the |
133 | 1691 |
objects are created. Be careful, to not reference any other chunk- |
1692 |
data when calling for a tenure (this will lead to lots of garbage in |
|
1693 |
the oldspace). |
|
1694 |
In normal situations, explicit tenures are not needed." |
|
1695 |
%{ |
|
326 | 1696 |
__tenure(__context); |
133 | 1697 |
%} |
1698 |
||
1699 |
" |
|
1700 |
ObjectMemory tenure |
|
1701 |
" |
|
194 | 1702 |
" |
1703 |
... build up long living objects ... |
|
1704 |
ObjectMemory scavenge. |
|
1705 |
ObjectMemory tenure |
|
1706 |
... continue - objects created above are now in oldSpace ... |
|
1707 |
" |
|
133 | 1708 |
! |
1709 |
||
1 | 1710 |
garbageCollect |
375 | 1711 |
"search for and free garbage in the oldSpace. |
1712 |
This can take a long time - especially, if paging is involved." |
|
1713 |
||
1714 |
"/ used to be |
|
1715 |
"/ self compressingGarbageCollect |
|
1716 |
"/ here; changed to default to markAndSweep |
|
1717 |
||
1718 |
self markAndSweep |
|
1719 |
||
1720 |
" |
|
1721 |
ObjectMemory garbageCollect |
|
1722 |
" |
|
1723 |
! |
|
1724 |
||
1725 |
compressingGarbageCollect |
|
178 | 1726 |
"search for and free garbage in the oldSpace (newSpace is cleaned automatically) |
1727 |
performing a COMPRESSING garbage collect. |
|
133 | 1728 |
This can take a long time - especially, if paging is involved |
178 | 1729 |
(when no paging is involved, its faster than I thought :-). |
202 | 1730 |
If no memory is available for the compress, or the system has been started with |
1731 |
the -Msingle option, this does a non-COMPRESSING collect." |
|
1 | 1732 |
%{ |
178 | 1733 |
if (! __garbageCollect(__context)) { |
326 | 1734 |
__markAndSweep(__context); |
178 | 1735 |
} |
1 | 1736 |
%} |
1737 |
||
93 | 1738 |
" |
375 | 1739 |
ObjectMemory compressingGarbageCollect |
93 | 1740 |
" |
1741 |
! |
|
1742 |
||
1 | 1743 |
markAndSweep |
133 | 1744 |
"mark/sweep garbage collector. |
1745 |
perform a full mark&sweep collect. |
|
369 | 1746 |
Warning: this may take some time and it is NOT interruptable. |
1747 |
If you want to do a collect from a background process, or have |
|
1748 |
other things to do, better use #incrementalGC which is interruptable." |
|
1 | 1749 |
%{ |
326 | 1750 |
__markAndSweep(__context); |
1 | 1751 |
%} |
1752 |
||
93 | 1753 |
" |
133 | 1754 |
ObjectMemory markAndSweep |
1755 |
" |
|
1 | 1756 |
! |
1757 |
||
375 | 1758 |
reclaimSymbols |
1759 |
"reclaim unused symbols; |
|
1760 |
Unused symbols are (currently) not reclaimed automatically, |
|
1761 |
but only upon request with this method. |
|
1762 |
It takes some time to do this ... and it is NOT interruptable. |
|
1763 |
Future versions may do this automatically, while garbage collecting." |
|
1764 |
%{ |
|
1765 |
__reclaimSymbols(__context); |
|
1766 |
%} |
|
1767 |
" |
|
1768 |
ObjectMemory reclaimSymbols |
|
1769 |
" |
|
1770 |
! |
|
1771 |
||
1 | 1772 |
gcStep |
77 | 1773 |
"one incremental garbage collect step. |
1774 |
Mark or sweep some small number of objects. This |
|
85 | 1775 |
method will return after a reasonable (short) time. |
133 | 1776 |
This is used by the ProcessorScheduler at idle times. |
1777 |
Returns true, if an incremental GC cycle has finished." |
|
1 | 1778 |
%{ |
133 | 1779 |
extern int __incrGCstep(); |
1780 |
||
1781 |
RETURN (__incrGCstep(__context) ? true : false); |
|
1 | 1782 |
%} |
1783 |
! |
|
1784 |
||
133 | 1785 |
incrementalGC |
1786 |
"perform one round of incremental GC steps. |
|
403 | 1787 |
The overall effect of this method is (almost) the same as calling |
1788 |
markAndSweep. However, #incrementalGC is interruptable while #markAndSweep |
|
1789 |
is atomic and blocks for a while. The code here performs incremental |
|
1790 |
GC steps, until one complete gc-cycle is completed. If running at a higher |
|
1791 |
than userBackground priority, it will give up the CPU after every such |
|
1792 |
step for a while. |
|
1793 |
Thus this method can be called either from a low prio (background) process |
|
1794 |
or from a high prio process. |
|
369 | 1795 |
(however, if you have nothing else to do, its better to call for markAndSweep, |
1796 |
since it is faster) |
|
159 | 1797 |
For example, someone allocating huge amounts of memory could |
1798 |
ask for the possibility of a quick allocation using |
|
1799 |
#checkForFastNew: and try a #incrementalGC if not. In many |
|
270 | 1800 |
cases, this can avoid a pause (in the higher prio processes) due to |
1801 |
a blocking GC." |
|
133 | 1802 |
|
403 | 1803 |
|p delay| |
1804 |
||
1805 |
Processor activeProcess priority > Processor userBackgroundPriority ifTrue:[ |
|
1806 |
delay := Delay forMilliseconds:1 |
|
1807 |
]. |
|
1808 |
||
1809 |
[self gcStep] whileFalse:[ |
|
1810 |
delay notNil ifTrue:[delay wait] |
|
1811 |
]. |
|
369 | 1812 |
self moreOldSpaceIfUseful |
133 | 1813 |
|
1814 |
" |
|
1815 |
ObjectMemory incrementalGC |
|
356 | 1816 |
[ObjectMemory incrementalGC] forkAt:3 |
403 | 1817 |
[ObjectMemory incrementalGC] forkAt:9 |
133 | 1818 |
" |
194 | 1819 |
! |
1820 |
||
270 | 1821 |
gcStepIfUseful |
1822 |
"If either the IncrementalGCLimit or the FreeSpaceGCLimits have been |
|
290 | 1823 |
reached, perform one incremental garbage collect step. |
1824 |
Return true, if more gcSteps are required to finish the cycle, |
|
1825 |
false if done with a gc round. |
|
1826 |
If no limit has been reached yet, do nothing and return false. |
|
312 | 1827 |
This is called by the ProcessorScheduler at idle times or by the |
1828 |
backgroundCollector." |
|
270 | 1829 |
|
379 | 1830 |
|done limit| |
270 | 1831 |
|
290 | 1832 |
limit := IncrementalGCLimit. |
1833 |
(limit notNil and:[self oldSpaceAllocatedSinceLastGC > limit]) ifTrue:[ |
|
369 | 1834 |
done := ObjectMemory gcStep |
1835 |
] ifFalse:[ |
|
1836 |
limit := FreeSpaceGCLimit. |
|
1837 |
(limit notNil and:[(self freeSpace + self freeListSpace) < limit]) ifTrue:[ |
|
1838 |
done := ObjectMemory gcStep. |
|
1839 |
done ifTrue:[ |
|
1840 |
self moreOldSpaceIfUseful |
|
1841 |
]. |
|
1842 |
] ifFalse:[ |
|
1843 |
done := true |
|
1844 |
] |
|
290 | 1845 |
]. |
369 | 1846 |
^ done not |
270 | 1847 |
! |
1848 |
||
194 | 1849 |
verboseGarbageCollect |
375 | 1850 |
"perform a compressing garbage collect and show some informational |
194 | 1851 |
output on the Transcript" |
1852 |
||
370 | 1853 |
|nBytesBefore nReclaimed value unit| |
194 | 1854 |
|
1855 |
nBytesBefore := self oldSpaceUsed. |
|
375 | 1856 |
self compressingGarbageCollect. |
194 | 1857 |
nReclaimed := nBytesBefore - self oldSpaceUsed. |
1858 |
nReclaimed > 0 ifTrue:[ |
|
1859 |
nReclaimed > 1024 ifTrue:[ |
|
1860 |
nReclaimed > (1024 * 1024) ifTrue:[ |
|
370 | 1861 |
value := nReclaimed // (1024 * 1024). |
1862 |
unit := ' Mb.' |
|
194 | 1863 |
] ifFalse:[ |
370 | 1864 |
value := nReclaimed // 1024. |
1865 |
unit := ' Kb.' |
|
194 | 1866 |
] |
1867 |
] ifFalse:[ |
|
370 | 1868 |
value := nReclaimed. |
1869 |
unit := ' bytes.' |
|
1870 |
]. |
|
1871 |
Transcript show:'reclaimed '; show:value printString. |
|
1872 |
Transcript showCr:unit |
|
194 | 1873 |
] |
1874 |
||
1875 |
" |
|
1876 |
ObjectMemory verboseGarbageCollect |
|
1877 |
" |
|
207 | 1878 |
! |
1879 |
||
1880 |
startBackgroundCollectorAt:aPriority |
|
1881 |
"start a process doing incremental GC in the background. |
|
1882 |
Use this, if you have suspendable background processes which |
|
1883 |
run all the time, and therefore would prevent the idle-collector |
|
1884 |
from running. See documentation in this class for more details." |
|
1885 |
||
290 | 1886 |
|p| |
1887 |
||
270 | 1888 |
"/ |
1889 |
"/ its not useful, to run it more than once |
|
1890 |
"/ |
|
207 | 1891 |
BackgroundCollectProcess notNil ifTrue:[ |
1892 |
BackgroundCollectProcess priority:aPriority. |
|
1893 |
^ self |
|
1894 |
]. |
|
270 | 1895 |
|
290 | 1896 |
p := |
207 | 1897 |
[ |
290 | 1898 |
[ |
1899 |
[true] whileTrue:[ |
|
1900 |
self gcStepIfUseful ifTrue:[ |
|
1901 |
" |
|
1902 |
perform a full cycle |
|
1903 |
" |
|
1904 |
self incrementalGC |
|
1905 |
]. |
|
270 | 1906 |
" |
290 | 1907 |
wait a bit |
1908 |
" |
|
1909 |
(Delay forSeconds:5) wait |
|
1910 |
] |
|
1911 |
] valueOnUnwindDo:[ |
|
1912 |
BackgroundCollectProcess := nil |
|
211 | 1913 |
] |
207 | 1914 |
] newProcess. |
290 | 1915 |
p name:'background collector'. |
1916 |
p priority:aPriority. |
|
339 | 1917 |
p restartable:true. |
290 | 1918 |
p resume. |
1919 |
BackgroundCollectProcess := p |
|
211 | 1920 |
|
1921 |
" |
|
293 | 1922 |
the following lets the backgroundCollector run at prio 5 |
1923 |
whenever 100000 bytes have been allocated, OR freeSpace drops |
|
1924 |
below 1meg. Having the system keep 1meg as reserve for peak allocation. |
|
1925 |
||
1926 |
Doing this may reduce pauses due to inevitable collects when running |
|
1927 |
out of freeSpace, if the collector can keep up with allocation rate. |
|
1928 |
" |
|
1929 |
||
1930 |
" |
|
1931 |
ObjectMemory incrementalGCLimit:100000. |
|
1932 |
ObjectMemory freeSpaceGCLimit:1000000. |
|
211 | 1933 |
ObjectMemory startBackgroundCollectorAt:5 |
1934 |
" |
|
207 | 1935 |
! |
1936 |
||
1937 |
stopBackgroundCollector |
|
1938 |
"stop the background collector" |
|
1939 |
||
1940 |
BackgroundCollectProcess notNil ifTrue:[ |
|
1941 |
BackgroundCollectProcess terminate. |
|
1942 |
BackgroundCollectProcess := nil |
|
1943 |
] |
|
293 | 1944 |
|
211 | 1945 |
" |
1946 |
ObjectMemory stopBackgroundCollector |
|
1947 |
" |
|
362 | 1948 |
! |
1949 |
||
1950 |
backgroundCollectorRunning |
|
1951 |
"return true, if a backgroundCollector is running" |
|
1952 |
||
1953 |
^ BackgroundCollectProcess notNil |
|
1954 |
||
1955 |
" |
|
1956 |
ObjectMemory backgroundCollectorRunning |
|
1957 |
" |
|
178 | 1958 |
! ! |
1959 |
||
1960 |
!ObjectMemory class methodsFor:'garbage collector control'! |
|
133 | 1961 |
|
270 | 1962 |
freeSpaceGCLimit:aNumber |
1963 |
"set the freeSpace limit for incremental GC activation. |
|
1964 |
The system will start doing incremental background GC, once less than this number |
|
310 | 1965 |
of bytes are available for allocation. |
1966 |
The default is nil; setting it to nil will turn this trigger off." |
|
270 | 1967 |
|
1968 |
FreeSpaceGCLimit := aNumber |
|
1969 |
||
1970 |
" |
|
310 | 1971 |
the following will start the incrementalGC (in the background) |
1972 |
whenever the freeSpace drops below 1meg of free space |
|
290 | 1973 |
" |
1974 |
" |
|
1975 |
ObjectMemory freeSpaceGCLimit:1000000. |
|
1976 |
" |
|
1977 |
||
1978 |
" |
|
293 | 1979 |
turn it off (i.e. let the system hit the wall ...) |
290 | 1980 |
" |
1981 |
" |
|
270 | 1982 |
ObjectMemory freeSpaceGCLimit:nil. |
1983 |
" |
|
1984 |
! |
|
1985 |
||
310 | 1986 |
freeSpaceGCAmount:aNumber |
1987 |
"set the amount to be allocated if, after an incrementalGC, |
|
1988 |
not at least FreeSpaceGCLimit bytes are available for allocation. |
|
1989 |
The amount should be greater than the limit, otherwise the incremental |
|
1990 |
GC may try over and over to get the memory (actually waisting time)." |
|
1991 |
||
1992 |
FreeSpaceGCAmount := aNumber |
|
1993 |
||
1994 |
" |
|
1995 |
the following will try to always keep at least 1meg of free space |
|
1996 |
(in the background) and start to do so, whenever the freeSpace drops |
|
1997 |
below 250k. |
|
1998 |
" |
|
1999 |
" |
|
2000 |
ObjectMemory freeSpaceGCLimit:250000. |
|
2001 |
ObjectMemory freeSpaceGCAmount:1000000. |
|
2002 |
" |
|
2003 |
||
2004 |
" |
|
2005 |
turn it off (i.e. let the system compute an appropriate amount ...) |
|
2006 |
" |
|
2007 |
" |
|
2008 |
ObjectMemory freeSpaceGCAmount:nil. |
|
2009 |
" |
|
2010 |
! |
|
2011 |
||
270 | 2012 |
freeSpaceGCLimit |
2013 |
"return the freeSpace limit for incremental GC activation. |
|
2014 |
The system will start doing incremental background GC, once less than this number |
|
2015 |
of bytes are available in the compact free space. |
|
2016 |
The default is 100000; setting it to nil will turn this trigger off." |
|
2017 |
||
2018 |
^ FreeSpaceGCLimit |
|
2019 |
||
2020 |
" |
|
2021 |
ObjectMemory freeSpaceGCLimit |
|
2022 |
" |
|
2023 |
! |
|
2024 |
||
310 | 2025 |
freeSpaceGCAmount |
2026 |
"return the amount to be allocated if, after an incrementalGC, |
|
2027 |
not at least FreeSpaceGCLimit bytes are available for allocation. |
|
2028 |
The default is nil, which lets the system compute an abbpropriate value" |
|
2029 |
||
2030 |
^ FreeSpaceGCAmount |
|
2031 |
||
2032 |
" |
|
2033 |
ObjectMemory freeSpaceGCAmount |
|
2034 |
" |
|
2035 |
! |
|
2036 |
||
2 | 2037 |
incrementalGCLimit:aNumber |
270 | 2038 |
"set the allocatedSinceLastGC limit for incremental GC activation. |
2039 |
The system will start doing incremental background GC, once more than this number |
|
2040 |
of bytes have been allocated since the last GC. |
|
2041 |
The default is 500000; setting it to nil will turn this trigger off." |
|
2 | 2042 |
|
2043 |
IncrementalGCLimit := aNumber |
|
2044 |
||
85 | 2045 |
" |
213 | 2046 |
ObjectMemory incrementalGCLimit:500000. 'do incr. GC very seldom' |
2047 |
ObjectMemory incrementalGCLimit:100000. 'medium' |
|
2048 |
ObjectMemory incrementalGCLimit:10000. 'do incr. GC very often' |
|
2049 |
ObjectMemory incrementalGCLimit:nil. 'never' |
|
85 | 2050 |
" |
2 | 2051 |
! |
2052 |
||
13 | 2053 |
incrementalGCLimit |
270 | 2054 |
"return the allocatedSinceLastGC limit for incremental GC activation. |
2055 |
The system will start doing incremental background GC, once more than this number |
|
2056 |
of bytes have been allocated since the last GC. |
|
2057 |
The default is 500000; setting it to nil will turn this trigger off." |
|
13 | 2058 |
|
2059 |
^ IncrementalGCLimit |
|
2060 |
||
85 | 2061 |
" |
2062 |
ObjectMemory incrementalGCLimit |
|
2063 |
" |
|
13 | 2064 |
! |
2065 |
||
369 | 2066 |
moreOldSpaceIfUseful |
2067 |
"to be called after an incremental GC cycle; |
|
2068 |
if freeSpace is still below limit, allocate more oldSpace" |
|
2069 |
||
2070 |
|limit free amount| |
|
2071 |
||
2072 |
limit := FreeSpaceGCLimit. |
|
2073 |
limit notNil ifTrue:[ |
|
2074 |
"/ if reclaimed space is below limit, we have to allocate more |
|
2075 |
"/ oldSpace, to avoid excessive gcSteps (due to freeSpaceLimit |
|
2076 |
"/ still not reached) |
|
2077 |
"/ |
|
2078 |
free := self freeSpace + self freeListSpace. |
|
2079 |
free < (limit * 3 // 2) ifTrue:[ |
|
2080 |
amount := FreeSpaceGCAmount. |
|
2081 |
amount isNil ifTrue:[ |
|
2082 |
amount := limit * 3 // 2. |
|
2083 |
]. |
|
2084 |
'OBJECTMEMORY: moreOldSpace to satisfy free-limit' infoPrintNL. |
|
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2085 |
(self moreOldSpace:(amount - free + (64*1024))) ifFalse:[ |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2086 |
"/ |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2087 |
"/ could not increase oldspace; reset FreeSpaceGCLimit to avoid |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2088 |
"/ useless retries |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2089 |
'OBJECTMEMORY: could not increase oldSpace - reset limit' errorPrintNL. |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2090 |
FreeSpaceGCLimit := nil |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2091 |
] |
369 | 2092 |
]. |
2093 |
]. |
|
2094 |
! |
|
2095 |
||
133 | 2096 |
moreOldSpace:howMuch |
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2097 |
"allocate howMuch bytes more for old objects; return true if this worked, |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2098 |
false if that failed. |
133 | 2099 |
This is done automatically, when running out of space, but makes |
2100 |
sense, if its known in advance that a lot of memory is needed to |
|
2101 |
avoid multiple reallocations and compresses. |
|
310 | 2102 |
On systems which do not support the mmap (or equivalent) system call, |
2103 |
this (currently) implies a compressing garbage collect - so its slow. |
|
133 | 2104 |
Notice: this is a nonstandard interface - use only in special situations." |
2105 |
||
2106 |
%{ |
|
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2107 |
if (__isSmallInteger(howMuch)) { |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2108 |
RETURN( __moreOldSpace(__context, _intVal(howMuch)) ? true : false ); |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2109 |
} |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2110 |
RETURN (false); |
133 | 2111 |
%} |
2112 |
" |
|
2113 |
ObjectMemory moreOldSpace:1000000 |
|
2114 |
" |
|
2115 |
! |
|
2116 |
||
202 | 2117 |
announceSpaceNeed:howMuch |
2118 |
"announce to the memory system, that howMuch bytes of memory will be needed |
|
2119 |
soon. The VM tries to prepare itself for this allocation to be performed |
|
2120 |
with less overhead. For example, it could preallocate some memory in one |
|
2121 |
big chunk (instead of doing many smaller reallocations later). |
|
2122 |
Notice: this is a nonstandard interface - use only in special situations. |
|
2123 |
Also, this does a background collect before the big chunk of memory is |
|
2124 |
allocated, not locking other processes while doing so." |
|
2125 |
||
2126 |
(howMuch < (self newSpaceSize // 2)) ifTrue:[ |
|
2127 |
self scavenge. |
|
2128 |
]. |
|
2129 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2130 |
(howMuch > (self newSpaceSize // 2)) ifFalse:[ |
|
2131 |
self scavenge. |
|
2132 |
]. |
|
2133 |
self incrementalGC. |
|
2134 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2135 |
self moreOldSpace:howMuch |
|
2136 |
] |
|
2137 |
] |
|
2138 |
||
2139 |
" |
|
2140 |
ObjectMemory announceSpaceNeed:100000 |
|
2141 |
" |
|
2142 |
! |
|
2143 |
||
133 | 2144 |
announceOldSpaceNeed:howMuch |
202 | 2145 |
"announce to the memory system, that howMuch bytes of memory will be needed |
2146 |
soon, which is going to live longer (whatever that means). |
|
2147 |
It first checks if the memory can be allocated without forcing a compressing |
|
2148 |
GC. If not, the oldSpace is increased. This may also lead to a slow compressing |
|
133 | 2149 |
collect. However, many smaller increases are avoided afterwards. Calling this |
2150 |
method before allocating huge chunks of data may provide better overall performance. |
|
2151 |
Notice: this is a nonstandard interface - use only in special situations." |
|
2152 |
||
2153 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
159 | 2154 |
self incrementalGC. |
2155 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2156 |
self moreOldSpace:howMuch |
|
2157 |
] |
|
133 | 2158 |
] |
2159 |
||
2160 |
" |
|
2161 |
ObjectMemory announceOldSpaceNeed:1000000 |
|
2162 |
" |
|
2163 |
! |
|
2164 |
||
2165 |
oldSpaceIncrement |
|
2166 |
"return the oldSpaceIncrement value. Thats the amount by which |
|
2167 |
more memory is allocated in case the oldSpace gets filled up. |
|
2168 |
In normal situations, the default value used in the VM is fine |
|
2169 |
and there is no need to change it." |
|
178 | 2170 |
|
2171 |
%{ /* NOCONTEXT */ |
|
133 | 2172 |
extern unsigned __oldSpaceIncrement(); |
2173 |
||
2174 |
RETURN (_MKSMALLINT( __oldSpaceIncrement(-1) )); |
|
2175 |
%} |
|
178 | 2176 |
" |
2177 |
ObjectMemory oldSpaceIncrement |
|
2178 |
" |
|
133 | 2179 |
! |
2180 |
||
2181 |
oldSpaceIncrement:amount |
|
2182 |
"set the oldSpaceIncrement value. Thats the amount by which |
|
2183 |
more memory is allocated in case the oldSpace gets filled up. |
|
2184 |
In normal situations, the default value used in the VM is fine |
|
2185 |
and there is no need to change it. This method returns the |
|
2186 |
previous increment value." |
|
178 | 2187 |
|
2188 |
%{ /* NOCONTEXT */ |
|
133 | 2189 |
extern unsigned __oldSpaceIncrement(); |
2190 |
||
253 | 2191 |
if (__isSmallInteger(amount)) { |
159 | 2192 |
RETURN (_MKSMALLINT( __oldSpaceIncrement(_intVal(amount)) )); |
133 | 2193 |
} |
2194 |
%} |
|
178 | 2195 |
"to change increment to 1Meg:" |
2196 |
" |
|
2197 |
ObjectMemory oldSpaceIncrement:1024*1024 |
|
2198 |
" |
|
2199 |
! |
|
2200 |
||
329 | 2201 |
oldSpaceCompressLimit:amount |
2202 |
"set the limit for oldSpace compression. If more memory than this |
|
2203 |
limit is in use, the system will not perform compresses on the oldspace, |
|
2204 |
but instead do a mark&sweep GC followed by an oldSpace increase if not enough |
|
2205 |
could be reclaimed. The default is currently some 8Mb, which is ok for workstations |
|
2206 |
with 16..32Mb of physical memory. If your system has much more physical RAM, |
|
2207 |
you may want to increase this limit. |
|
2208 |
This method returns the previous increment value." |
|
2209 |
||
2210 |
%{ /* NOCONTEXT */ |
|
2211 |
extern unsigned __compressingGCLimit(); |
|
2212 |
||
2213 |
if (__isSmallInteger(amount)) { |
|
2214 |
RETURN (_MKSMALLINT( __compressingGCLimit(_intVal(amount)) )); |
|
2215 |
} |
|
2216 |
%} |
|
2217 |
"to change the limit to 12Mb:" |
|
2218 |
" |
|
2219 |
ObjectMemory oldSpaceCompressLimit:12*1024*1024 |
|
2220 |
" |
|
2221 |
! |
|
2222 |
||
178 | 2223 |
fastMoreOldSpaceAllocation:aBoolean |
2224 |
"this method turns on/off fastMoreOldSpace allocation. |
|
2225 |
By default, this is turned off (false), which means that in case of |
|
202 | 2226 |
a filled-up oldSpace, a GC is tried first before more oldSpace is allocated. |
178 | 2227 |
This strategy is ok for the normal operation of the system, |
2228 |
but behaves badly, if the program allocates huge data structures (say a |
|
202 | 2229 |
game tree of 30Mb in size) which survives and therefore will not be reclaimed |
178 | 2230 |
by a GC. |
202 | 2231 |
Of course while building this tree, and the memory becomes full, the system |
2232 |
would not know in advance, that the GC will not reclaim anything. |
|
2233 |
||
178 | 2234 |
Setting fastOldSpaceIncrement to true will avoid this, by forcing the |
2235 |
memory system to allocate more memory right away, without doing a GC first. |
|
2236 |
||
2237 |
WARNING: make certain that this flag is turned off, after your huge data |
|
2238 |
is allocated, since otherwise the system may continue to increase its |
|
202 | 2239 |
virtual memory without ever checking for garbage. |
310 | 2240 |
This method returns the previous value of the flag; typically this return |
2241 |
value should be used to switch back." |
|
178 | 2242 |
|
2243 |
%{ /* NOCONTEXT */ |
|
370 | 2244 |
extern int __fastMoreOldSpaceAllocation(); |
2245 |
||
178 | 2246 |
RETURN (__fastMoreOldSpaceAllocation(aBoolean == true ? 1 : 0) ? true : false); |
2247 |
%} |
|
310 | 2248 |
" |
2249 |
|previousSetting| |
|
2250 |
||
2251 |
previousSetting := ObjectMemory fastMoreOldSpaceAllocation:true. |
|
2252 |
[ |
|
2253 |
... |
|
2254 |
allocate your huge data |
|
2255 |
... |
|
2256 |
] valueNoOrOnUnwindDo:[ |
|
2257 |
ObjectMemory fastMoreOldSpaceAllocation:previousSetting |
|
2258 |
] |
|
2259 |
" |
|
370 | 2260 |
|
2261 |
" |
|
2262 |
|prev this| |
|
2263 |
||
2264 |
prev := ObjectMemory fastMoreOldSpaceAllocation:true. |
|
2265 |
ObjectMemory fastMoreOldSpaceAllocation:prev. |
|
2266 |
^ prev |
|
2267 |
" |
|
2268 |
! |
|
2269 |
||
2270 |
fastMoreOldSpaceLimit:aNumber |
|
2271 |
"this method sets and returns the fastMoreOldSpace limit. |
|
2272 |
If fastMoreOldSpaceAllocation is true, and the current oldSpace size is |
|
2273 |
below this limit, the memory manager will NOT do a GC when running out of |
|
2274 |
oldSpace, but instead quickly go ahead increasing the size of the oldSpace. |
|
2275 |
Setting the limit to 0 turns off any limit (i.e. it will continue to |
|
2276 |
increase the oldSpace forwever - actually, until the OS refuses to give us |
|
2277 |
more memory). The returned value is the previous setting of the limit." |
|
2278 |
||
2279 |
%{ /* NOCONTEXT */ |
|
2280 |
extern int __fastMoreOldSpaceLimit(); |
|
2281 |
||
2282 |
if (__isSmallInteger(aNumber)) { |
|
2283 |
RETURN ( __MKSMALLINT( __fastMoreOldSpaceLimit(__intVal(aNumber)))); |
|
2284 |
} |
|
2285 |
%}. |
|
2286 |
self primitiveFailed |
|
2287 |
||
2288 |
" |
|
2289 |
|prev this| |
|
2290 |
||
2291 |
prev := ObjectMemory fastMoreOldSpaceLimit:10*1024*1024. |
|
2292 |
ObjectMemory fastMoreOldSpaceLimit:prev. |
|
2293 |
^ prev |
|
2294 |
" |
|
133 | 2295 |
! |
2296 |
||
2297 |
checkForFastNew:amount |
|
2298 |
"this method returns true, if amount bytes could be allocated |
|
2299 |
quickly (i.e. without forcing a full GC or compress). |
|
2300 |
This can be used for smart background processes, which want to |
|
2301 |
allocate big chunks of data without disturbing foreground processes |
|
2302 |
too much. Such a process would check for fast-allocation, and perform |
|
202 | 2303 |
incremental GC-steps if required. Thus, avoiding the long blocking pause |
310 | 2304 |
due to a forced (non-incremental) GC. |
2305 |
Especially: doing so will not block higher priority foreground processes. |
|
2306 |
See an example use in Behavior>>niceBasicNew:. |
|
133 | 2307 |
This is experimental and not guaranteed to be in future versions." |
2308 |
||
178 | 2309 |
%{ /* NOCONTEXT */ |
370 | 2310 |
extern int __checkForFastNew(); |
133 | 2311 |
|
253 | 2312 |
if (__isSmallInteger(amount)) { |
159 | 2313 |
if (! __checkForFastNew(_intVal(amount))) { |
2314 |
RETURN (false); |
|
2315 |
} |
|
133 | 2316 |
} |
2317 |
||
2318 |
%}. |
|
2319 |
^ true |
|
2320 |
! |
|
2321 |
||
2 | 2322 |
turnGarbageCollectorOff |
310 | 2323 |
"turn off the generational garbage collector by forcing new objects to be |
2324 |
allocated directly in oldSpace (instead of newSpace) |
|
178 | 2325 |
WARNING: |
93 | 2326 |
This is somewhat dangerous: if collector is turned off, |
77 | 2327 |
and too many objects are created, the system may run into trouble |
2328 |
(i.e. oldSpace becomes full) and be forced to perform a full mark&sweep |
|
202 | 2329 |
or even a compressing collect - making the overall realtime behavior worse. |
93 | 2330 |
Use this only for special purposes or when realtime behavior |
403 | 2331 |
is required for a limited time period. |
2332 |
||
2333 |
OBSOLETE: this is no longer supported |
|
2334 |
- it may be a no-operation by the time you read this." |
|
178 | 2335 |
|
2336 |
%{ /* NOCONTEXT */ |
|
133 | 2337 |
__allocForceSpace(OLDSPACE); |
1 | 2338 |
%} |
2339 |
! |
|
2340 |
||
2 | 2341 |
turnGarbageCollectorOn |
202 | 2342 |
"turn garbage collector on again (see ObjectMemory>>turnGarbageCollectorOff)" |
1 | 2343 |
|
178 | 2344 |
%{ /* NOCONTEXT */ |
133 | 2345 |
__allocForceSpace(9999); |
1 | 2346 |
%} |
178 | 2347 |
! |
85 | 2348 |
|
2349 |
makeOld:anObject |
|
93 | 2350 |
"move anObject into oldSpace. |
133 | 2351 |
This method is for internal & debugging purposes only - |
2352 |
it may vanish. Dont use it." |
|
85 | 2353 |
%{ |
2354 |
if (__moveToOldSpace(anObject, __context) < 0) { |
|
159 | 2355 |
RETURN (false); |
93 | 2356 |
} |
2357 |
%}. |
|
2358 |
^ true |
|
194 | 2359 |
! |
2360 |
||
2361 |
tenureParameters:magic |
|
2362 |
"this is pure magic and not for public eyes ... |
|
202 | 2363 |
This method allows fine tuning the scavenger internals, |
194 | 2364 |
in cooperation to some statistic & test programs. |
202 | 2365 |
It is undocumented, secret and may vanish. |
2366 |
If you play around here, the system may behave very strange." |
|
194 | 2367 |
|
2368 |
%{ /* NOCONTEXT */ |
|
2369 |
__tenureParams(magic); |
|
2370 |
%}. |
|
370 | 2371 |
! |
2372 |
||
379 | 2373 |
lockTenure:flag |
370 | 2374 |
"set/clear the tenureLock. If the lock is set, the system |
2375 |
completely turns off tenuring, and objects remain in newSpace (forever). |
|
379 | 2376 |
Once this lock is set, the system operates only in the newSpace and no memory |
2377 |
allocations from oldSpace are allowed (except for explicit tenure calls). |
|
370 | 2378 |
If any allocation request cannot be resoved, the VM raises a memory interrupt, |
379 | 2379 |
clears the lockTenure-flag and returns nil. Thus, it automatically falls back into |
2380 |
the normal mode of operation, to avoid big trouble |
|
2381 |
(fail to allocate memory when handling the exception). |
|
370 | 2382 |
|
2383 |
This interface can be used in applications, which are guaranteed to have their |
|
2384 |
working set completely in the newSpace AND want to limit the worst case |
|
379 | 2385 |
pause times to the worst case scavenge time |
2386 |
(which itself is limitd by the size of the newSpace). |
|
370 | 2387 |
I.e. systems which go into some event loop after initial startup, |
2388 |
may turn on the tenureLock to make certain that no oldSpace memory is |
|
379 | 2389 |
allocated in the future; thereby limiting any GC activity to newSpace scavenges only. |
2390 |
||
2391 |
This is an EXPERIMENTAL interface. |
|
2392 |
" |
|
370 | 2393 |
|
2394 |
%{ |
|
379 | 2395 |
if (flag == true) { |
370 | 2396 |
__tenure(__context); |
2397 |
} |
|
379 | 2398 |
__lockTenure(flag == true ? 1 : 0); |
2399 |
%} |
|
2400 |
! |
|
2401 |
||
2402 |
avoidTenure:flag |
|
2403 |
"set/clear the avoidTenure flag. If set, aging of newSpace is turned off |
|
2404 |
as long as the newSpace fill-grade stays below some magic high-water mark. |
|
2405 |
If off (the default), aging is done as usual. |
|
2406 |
If the flag is turned on, scavenge may be a bit slower, due to more |
|
2407 |
objects being copied around. However, chances are high that in an idle |
|
2408 |
or (almost idle) system, less objects are moved into oldSpace. |
|
2409 |
Therefore, this helps to avoid oldSpace colelcts, in systems which go into |
|
2410 |
some standby mode and are reactivated by some external event. |
|
2411 |
(the avoid-flag should be turned off there, and set again once the idle loop |
|
2412 |
is reentered). |
|
2413 |
||
2414 |
This is an EXPERIMENTAL interface." |
|
2415 |
||
2416 |
%{ /* NOCONTEXT */ |
|
2417 |
__avoidTenure(flag == true ? 1 : 0); |
|
2418 |
%} |
|
2419 |
! |
|
2420 |
||
2421 |
watchTenure:flag |
|
2422 |
"set/clear the tenureWatch. If set, an internalError exception will be raised, |
|
2423 |
whenever objects are tenured from newSpace into oldSpace |
|
2424 |
(except for an explicit tenure request). |
|
2425 |
This can be used to validate that no oldSpace objects are created |
|
2426 |
(i.e. the system operates fully in newSpace). |
|
2427 |
Be careful, if the avoidTenure flag is not set, |
|
2428 |
there will almost always be a tenure sooner or later. |
|
2429 |
||
2430 |
EXPERIMENTAL - no warranty" |
|
2431 |
||
2432 |
%{ /* NOCONTEXT */ |
|
2433 |
__watchTenure(flag == true ? 1 : 0); |
|
370 | 2434 |
%} |
2435 |
! |
|
2436 |
||
2437 |
newSpaceSize:newSize |
|
2438 |
"change the size of the newSpace. To do this, the current contents |
|
2439 |
of the newSpace may have to be tenured (if size is smaller). |
|
2440 |
Returns false, if it failed for any reason. |
|
2441 |
Experimental: this interface may valish without notice. |
|
2442 |
||
2443 |
DANGER ALERT: |
|
2444 |
be careful too big of a size may lead to longer scavenge pauses. |
|
2445 |
Too small of a newSpace may lead to more CPU overhead, due to |
|
2446 |
excessive scavenges. You have been warned." |
|
2447 |
||
2448 |
%{ |
|
2449 |
extern int __setNewSpaceSize(); |
|
2450 |
||
2451 |
if (__isSmallInteger(newSize)) { |
|
2452 |
RETURN (__setNewSpaceSize(__intVal(newSize)) ? true : false); |
|
2453 |
} |
|
2454 |
%}. |
|
2455 |
self primitiveFailed |
|
2456 |
||
2457 |
" less absolute CPU overhead (but longer pauses): |
|
2458 |
||
2459 |
ObjectMemory newSpaceSize:800*1024 |
|
2460 |
" |
|
2461 |
||
2462 |
" smaller pauses, but more overall CPU overhead: |
|
2463 |
||
2464 |
ObjectMemory newSpaceSize:200*1024 |
|
2465 |
" |
|
2466 |
||
2467 |
" the default: |
|
2468 |
||
2469 |
ObjectMemory newSpaceSize:400*1024 |
|
2470 |
" |
|
178 | 2471 |
! ! |
2472 |
||
362 | 2473 |
!ObjectMemory class ignoredMethodsFor:'object finalization'! |
290 | 2474 |
|
2475 |
allShadowObjectsDo:aBlock |
|
2476 |
"evaluate the argument, aBlock for all known shadow objects" |
|
2477 |
%{ |
|
326 | 2478 |
__allShadowObjectsDo(&aBlock COMMA_CON); |
290 | 2479 |
%} |
362 | 2480 |
! ! |
2481 |
||
2482 |
!ObjectMemory class methodsFor:'object finalization'! |
|
290 | 2483 |
|
2484 |
allChangedShadowObjectsDo:aBlock |
|
2485 |
"evaluate the argument, aBlock for all known shadow objects which have |
|
2486 |
lost a pointer recently." |
|
2487 |
%{ |
|
326 | 2488 |
__allChangedShadowObjectsDo(&aBlock COMMA_CON); |
290 | 2489 |
%} |
2490 |
! |
|
2491 |
||
291 | 2492 |
finalize |
2493 |
"tell all weak objects that something happened." |
|
2494 |
||
2495 |
self allChangedShadowObjectsDo:[:aShadowArray | |
|
2496 |
aShadowArray lostPointer. |
|
2497 |
] |
|
2498 |
! |
|
2499 |
||
290 | 2500 |
disposeInterrupt |
2501 |
"this is triggered by the garbage collector, |
|
2502 |
whenever any shadowArray looses a pointer." |
|
2503 |
||
2504 |
FinalizationSemaphore notNil ifTrue:[ |
|
2505 |
"/ |
|
2506 |
"/ background finalizer is waiting ... |
|
2507 |
"/ |
|
2508 |
FinalizationSemaphore signal |
|
2509 |
] ifFalse:[ |
|
2510 |
"/ |
|
2511 |
"/ do it right here |
|
2512 |
"/ |
|
291 | 2513 |
self finalize |
290 | 2514 |
] |
2515 |
! |
|
2516 |
||
2517 |
startBackgroundFinalizationAt:aPriority |
|
2518 |
"start a process doing finalization work in the background. |
|
2519 |
Can be used to reduce the pauses created by finalization. |
|
2520 |
Normally, these pauses are not noticed; however if you have (say) |
|
2521 |
ten thousands of weak objects, these could become long enough to |
|
2522 |
make background finalization usefull. |
|
2523 |
WARNING: background finalization may lead to much delayed freeing of |
|
2524 |
system resources. Especially, you may temporarily run out of free |
|
2525 |
color table entries or fileDescriptors etc. Use at your own risk (if at all)" |
|
2526 |
||
2527 |
|p| |
|
2528 |
||
2529 |
"/ |
|
2530 |
"/ its not useful, to run it more than once |
|
2531 |
"/ |
|
2532 |
BackgroundFinalizationProcess notNil ifTrue:[ |
|
2533 |
BackgroundFinalizationProcess priority:aPriority. |
|
2534 |
^ self |
|
2535 |
]. |
|
2536 |
||
2537 |
FinalizationSemaphore := Semaphore new. |
|
2538 |
||
2539 |
p := |
|
2540 |
[ |
|
2541 |
[ |
|
2542 |
[true] whileTrue:[ |
|
2543 |
" |
|
2544 |
wait till something to do ... |
|
2545 |
" |
|
2546 |
FinalizationSemaphore wait. |
|
2547 |
" |
|
2548 |
... and do it |
|
2549 |
" |
|
291 | 2550 |
self finalize |
290 | 2551 |
] |
2552 |
] valueOnUnwindDo:[ |
|
2553 |
BackgroundFinalizationProcess := nil. |
|
2554 |
FinalizationSemaphore := nil |
|
2555 |
] |
|
2556 |
] newProcess. |
|
2557 |
p name:'background finalizer'. |
|
2558 |
p priority:aPriority. |
|
339 | 2559 |
p restartable:true. |
290 | 2560 |
p resume. |
2561 |
BackgroundFinalizationProcess := p |
|
2562 |
||
2563 |
" |
|
2564 |
ObjectMemory startBackgroundFinalizationAt:5 |
|
2565 |
" |
|
2566 |
! |
|
2567 |
||
2568 |
stopBackgroundFinalization |
|
2569 |
"stop the background finalizer" |
|
2570 |
||
2571 |
BackgroundFinalizationProcess notNil ifTrue:[ |
|
2572 |
BackgroundFinalizationProcess terminate. |
|
2573 |
BackgroundFinalizationProcess := nil |
|
2574 |
]. |
|
2575 |
||
2576 |
" |
|
2577 |
ObjectMemory stopBackgroundFinalization |
|
2578 |
" |
|
2579 |
! ! |
|
2580 |
||
178 | 2581 |
!ObjectMemory class methodsFor:'physical memory access'! |
93 | 2582 |
|
2583 |
newSpacePagesDo:aBlock |
|
2584 |
"evaluates aBlock for all pages in the newSpace, passing |
|
2585 |
the pages address as argument. |
|
2586 |
For internal & debugging use only." |
|
2587 |
%{ |
|
2588 |
if (__newSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2589 |
RETURN (false); |
85 | 2590 |
} |
2591 |
%}. |
|
2592 |
^ true |
|
2593 |
! |
|
2594 |
||
2595 |
oldSpacePagesDo:aBlock |
|
2596 |
"evaluates aBlock for all pages in the oldSpace, passing |
|
2597 |
the pages address as argument. |
|
93 | 2598 |
For internal & debugging use only." |
85 | 2599 |
%{ |
2600 |
if (__oldSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2601 |
RETURN (false); |
85 | 2602 |
} |
2603 |
%}. |
|
2604 |
^ true |
|
2605 |
! |
|
2606 |
||
93 | 2607 |
collectedOldSpacePagesDo:aBlock |
2608 |
"evaluates aBlock for all pages in the prev. oldSpace, passing |
|
2609 |
the pages address as argument. |
|
2610 |
For internal & debugging use only." |
|
2611 |
%{ |
|
2612 |
if (__collectedOldSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2613 |
RETURN (false); |
93 | 2614 |
} |
2615 |
%}. |
|
2616 |
^ true |
|
2617 |
! |
|
2618 |
||
85 | 2619 |
pageIsInCore:aPageNumber |
2620 |
"return true, if the page (as enumerated via oldSpacePagesDo:) |
|
2621 |
is in memory; false, if currently paged out. For internal |
|
93 | 2622 |
use / monitors only; may vanish. |
2623 |
NOTICE: not all systems provide this information; on those that |
|
2624 |
do not, true is returned for all pages." |
|
85 | 2625 |
%{ |
2626 |
#ifdef HAS_MINCORE |
|
2627 |
int pageSize = getpagesize(); |
|
2628 |
char result[10]; |
|
2629 |
INT addr; |
|
2630 |
||
253 | 2631 |
if (__isSmallInteger(aPageNumber)) { |
159 | 2632 |
addr = _intVal(aPageNumber) & ~(pageSize - 1); |
85 | 2633 |
} else { |
159 | 2634 |
addr = ((INT)aPageNumber) & ~(pageSize - 1); |
85 | 2635 |
} |
2636 |
if (mincore(addr, pageSize-1, result) < 0) { |
|
159 | 2637 |
RETURN (true); |
85 | 2638 |
} |
2639 |
RETURN ((result[0] & 1) ? true : false); |
|
2640 |
#endif |
|
2641 |
%}. |
|
2642 |
"OS does not supply this info - assume yes" |
|
2643 |
^ true |
|
2644 |
! ! |
|
2645 |
||
379 | 2646 |
!ObjectMemory class methodsFor:'statistics'! |
2647 |
||
2648 |
ageStatistic |
|
2649 |
%{ /* NOCONTEXT */ |
|
2650 |
||
2651 |
__ageStatistics(); |
|
2652 |
%} |
|
2653 |
! ! |
|
2654 |
||
13 | 2655 |
!ObjectMemory class methodsFor:'low memory handling'! |
2656 |
||
2657 |
memoryInterrupt |
|
2658 |
"when a low-memory condition arises, ask all classes to |
|
290 | 2659 |
remove possibly cached data. You may help the system a bit, |
2660 |
in providing a lowSpaceCleanup method in your classes which have |
|
2661 |
lots of data kept somewhere (usually, cached data). |
|
2662 |
- this may or may not help." |
|
13 | 2663 |
|
308 | 2664 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 2665 |
aClass lowSpaceCleanup |
13 | 2666 |
]. |
2667 |
||
178 | 2668 |
"/ self error:'almost out of memory' |
2669 |
'almost out of memory' errorPrintNL. |
|
2670 |
||
2671 |
LowSpaceSemaphore signalIf. |
|
13 | 2672 |
! ! |
2673 |
||
1 | 2674 |
!ObjectMemory class methodsFor:'system management'! |
2675 |
||
2676 |
loadClassBinary:aClassName |
|
2677 |
"find the object file for aClassName and -if found - load it; |
|
2678 |
this one loads precompiled object files" |
|
2679 |
||
357 | 2680 |
|fName newClass| |
1 | 2681 |
|
2682 |
fName := self fileNameForClass:aClassName. |
|
2683 |
fName notNil ifTrue:[ |
|
202 | 2684 |
Class withoutUpdatingChangesDo: |
159 | 2685 |
[ |
2686 |
self loadBinary:(fName , '.o') |
|
2687 |
]. |
|
2688 |
newClass := self at:(aClassName asSymbol). |
|
2689 |
(newClass notNil and:[newClass implements:#initialize]) ifTrue:[ |
|
2690 |
newClass initialize |
|
2691 |
] |
|
1 | 2692 |
] |
2693 |
! |
|
2694 |
||
77 | 2695 |
imageName |
2696 |
"return the filename of the current image, or nil |
|
2697 |
if not running from an image." |
|
2698 |
||
2699 |
^ ImageName |
|
159 | 2700 |
|
2701 |
" |
|
202 | 2702 |
ObjectMemory imageName |
2703 |
" |
|
2704 |
! |
|
2705 |
||
2706 |
imageBaseName |
|
2707 |
"return a reasonable filename to use as baseName (i.e. without extension). |
|
2708 |
This is the filename of the current image (without '.img') or, |
|
2709 |
if not running from an image, the default name 'st'" |
|
2710 |
||
2711 |
|nm| |
|
2712 |
||
2713 |
nm := ImageName. |
|
2714 |
(nm isNil or:[nm isBlank]) ifTrue:[ |
|
2715 |
^ 'st' |
|
2716 |
]. |
|
2717 |
(nm endsWith:'.sav') ifTrue:[ |
|
359 | 2718 |
nm := nm copyWithoutLast:4 |
202 | 2719 |
]. |
2720 |
(nm endsWith:'.img') ifTrue:[ |
|
359 | 2721 |
^ nm copyWithoutLast:4 |
202 | 2722 |
]. |
2723 |
^ nm |
|
2724 |
||
2725 |
" |
|
2726 |
ObjectMemory imageBaseName |
|
159 | 2727 |
" |
77 | 2728 |
! |
2729 |
||
22 | 2730 |
nameForSnapshot |
159 | 2731 |
"return a reasonable filename to store the snapshot image into. |
2732 |
This is the filename of the current image or, |
|
22 | 2733 |
if not running from an image, the default name 'st.img'" |
2734 |
||
202 | 2735 |
^ self imageBaseName , '.img' |
2736 |
||
2737 |
" |
|
2738 |
ObjectMemory nameForSnapshot |
|
2739 |
" |
|
2740 |
! |
|
2741 |
||
2742 |
nameForSources |
|
2743 |
"return a reasonable filename to store the sources into. |
|
2744 |
This is the basename of the current image with '.img' replaced |
|
2745 |
by '.src', or, if not running from an image, the default name 'st.src'" |
|
2746 |
||
2747 |
^ self imageBaseName , '.src' |
|
159 | 2748 |
|
2749 |
" |
|
202 | 2750 |
ObjectMemory nameForSources |
2751 |
" |
|
2752 |
! |
|
2753 |
||
2754 |
nameForChanges |
|
2755 |
"return a reasonable filename to store the changes into. |
|
2756 |
This is the basename of the current image with '.img' replaced |
|
2757 |
by '.chg', or, if not running from an image, the default name 'st.chg'" |
|
2758 |
||
2759 |
^ 'changes'. |
|
360 | 2760 |
|
2761 |
"/ future versions will have: |
|
2762 |
"/ (requires some additionas at other places) |
|
2763 |
"/ |
|
2764 |
"/ ^ self imageBaseName , '.chg' |
|
202 | 2765 |
|
2766 |
" |
|
2767 |
ObjectMemory nameForChanges |
|
159 | 2768 |
" |
22 | 2769 |
! |
2770 |
||
1 | 2771 |
snapShot |
159 | 2772 |
"create a snapshot file containing all of the current state." |
1 | 2773 |
|
22 | 2774 |
self snapShotOn:(self nameForSnapshot) |
1 | 2775 |
|
159 | 2776 |
" |
2777 |
ObjectMemory snapShot |
|
2778 |
" |
|
1 | 2779 |
! |
2780 |
||
2781 |
snapShotOn:aFileName |
|
329 | 2782 |
"create a snapshot in the given file. |
2783 |
If the file exists, save it for backup. |
|
2784 |
Return true if the snapshot worked, false if it failed for some reason. |
|
2785 |
Notify dependents before and after the snapshot operation." |
|
1 | 2786 |
|
159 | 2787 |
|ok oldImageName| |
2788 |
||
2789 |
" |
|
2790 |
keep a save version - just in case something |
|
2791 |
bad happens while writing the image. |
|
2792 |
(could be st/x internal error or file-system errors etc) |
|
2793 |
" |
|
2794 |
(OperatingSystem isValidPath:aFileName) ifTrue:[ |
|
2795 |
OperatingSystem renameFile:aFileName to:(aFileName , '.sav'). |
|
2796 |
]. |
|
22 | 2797 |
|
93 | 2798 |
" |
2799 |
give others a chance to fix things |
|
2800 |
" |
|
329 | 2801 |
self changed:#save. "/ will vanish ... |
2802 |
self changed:#aboutToSnapshot. "/ ... for ST-80 compatibility |
|
13 | 2803 |
|
93 | 2804 |
" |
2805 |
ST-80 compatibility; send #preSnapshot to all classes |
|
2806 |
" |
|
202 | 2807 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 2808 |
aClass preSnapshot |
93 | 2809 |
]. |
2810 |
||
159 | 2811 |
" |
2812 |
save the name with it ... |
|
2813 |
" |
|
2814 |
oldImageName := ImageName. |
|
2815 |
ImageName := aFileName. |
|
2816 |
ok := self primSnapShotOn:aFileName. |
|
2817 |
ImageName := oldImageName. |
|
2818 |
||
2819 |
ok ifTrue:[ |
|
2820 |
Class addChangeRecordForSnapshot:aFileName. |
|
329 | 2821 |
]. |
159 | 2822 |
|
2823 |
||
329 | 2824 |
" |
2825 |
ST-80 compatibility; send #postSnapshot to all classes |
|
2826 |
" |
|
2827 |
Smalltalk allBehaviorsDo:[:aClass | |
|
2828 |
aClass postSnapshot |
|
159 | 2829 |
]. |
329 | 2830 |
self changed:#finishedSnapshot. "/ ST-80 compatibility |
159 | 2831 |
^ ok |
2832 |
||
2833 |
" |
|
2834 |
ObjectMemory snapShotOn:'myimage.img' |
|
2835 |
" |
|
2836 |
! |
|
2837 |
||
2838 |
primSnapShotOn:aFileName |
|
2839 |
"create a snapshot in the given file. |
|
2840 |
Low level entry. Does not notify classes or write an entry to |
|
2841 |
the changes file. Also, no image backup is created. Returns true if |
|
2842 |
the snapshot worked, false if it failed for some reason. |
|
2843 |
This method should not be used in normal cases." |
|
2844 |
||
2845 |
|ok| |
|
2846 |
||
13 | 2847 |
%{ /* STACK:32000 */ |
2848 |
||
1 | 2849 |
OBJ __snapShotOn(); |
159 | 2850 |
OBJ funny = @symbol(funnySnapshotSymbol); |
1 | 2851 |
|
56 | 2852 |
if (__isString(aFileName)) { |
356 | 2853 |
__BLOCKINTERRUPTS(); |
159 | 2854 |
ok = __snapShotOn(__context, _stringVal(aFileName), funny); |
356 | 2855 |
__UNBLOCKINTERRUPTS(); |
1 | 2856 |
} |
159 | 2857 |
%}. |
22 | 2858 |
^ ok |
418 | 2859 |
! |
2860 |
||
2861 |
allBinaryModulesDo:aBlock |
|
2862 |
"internal private method - walk over all known binary |
|
2863 |
modules and evaluate aBlock for each entry. |
|
2864 |
Do not depend on the information returned for each - this may |
|
2865 |
change without notice." |
|
2866 |
||
2867 |
%{ |
|
2868 |
__REGISTRATION_DO_BLOCK(&aBlock COMMA_SND); |
|
2869 |
%} |
|
2870 |
! |
|
2871 |
||
2872 |
binaryModuleInfo |
|
2873 |
"return a collection of moduleInfo entries. |
|
2874 |
This returns a dictionary (keys are internal moduleIDs) |
|
2875 |
with one entry for each binary package." |
|
2876 |
||
2877 |
|modules| |
|
2878 |
||
2879 |
modules := IdentityDictionary new. |
|
2880 |
self allBinaryModulesDo:[:entry | |
|
438 | 2881 |
|id name type libName subModuleName module dynamic infoRec pathName |
2882 |
typeName nameString| |
|
418 | 2883 |
|
2884 |
id := entry at:1. |
|
2885 |
subModuleName := (entry at:2) asSymbol. |
|
2886 |
libName := (entry at:4). |
|
2887 |
||
2888 |
id > 0 ifTrue:[ |
|
2889 |
pathName := ObjectFileLoader pathNameFromID:id. |
|
2890 |
dynamic := true. |
|
438 | 2891 |
typeName := 'dynamic '. |
2892 |
name := pathName asFilename baseName |
|
418 | 2893 |
] ifFalse:[ |
2894 |
dynamic := false. |
|
443 | 2895 |
typeName := 'builtIn '. |
418 | 2896 |
pathName := nil. |
2897 |
libName isNil ifTrue:[ |
|
438 | 2898 |
name := subModuleName |
418 | 2899 |
] ifFalse:[ |
438 | 2900 |
name := libName |
418 | 2901 |
]. |
2902 |
]. |
|
438 | 2903 |
nameString := typeName. |
2904 |
libName isNil ifTrue:[ |
|
2905 |
nameString := nameString, 'module ' |
|
2906 |
] ifFalse:[ |
|
2907 |
nameString := nameString, 'classLib ' |
|
2908 |
]. |
|
2909 |
nameString := nameString , name. |
|
2910 |
||
418 | 2911 |
libName isNil ifTrue:[ |
2912 |
type := #classObject |
|
2913 |
] ifFalse:[ |
|
2914 |
type := #classLibrary |
|
2915 |
]. |
|
2916 |
infoRec := modules at:id ifAbsent:nil. |
|
2917 |
infoRec notNil ifTrue:[ |
|
2918 |
(infoRec at:#classNames) add:subModuleName |
|
2919 |
] ifFalse:[ |
|
2920 |
infoRec := IdentityDictionary new. |
|
2921 |
infoRec at:#id put:id. |
|
2922 |
infoRec at:#classNames put:(Set with:subModuleName). |
|
2923 |
infoRec at:#pathName put:pathName. |
|
438 | 2924 |
infoRec at:#name put:nameString. |
418 | 2925 |
infoRec at:#libraryName put:libName. |
2926 |
infoRec at:#dynamic put:dynamic. |
|
2927 |
infoRec at:#type put:type. |
|
2928 |
modules at:id put:infoRec. |
|
2929 |
]. |
|
2930 |
]. |
|
2931 |
^ modules |
|
2932 |
||
2933 |
" |
|
2934 |
ObjectMemory binaryModuleInfo |
|
2935 |
" |
|
2936 |
||
438 | 2937 |
"Modified: 17.9.1995 / 16:33:02 / claus" |
418 | 2938 |
! |
2939 |
||
2940 |
fullBinaryModuleInfo |
|
2941 |
"return a full collection of moduleInfo entries. |
|
2942 |
This returns a dictionary (keys are component names) |
|
2943 |
with one entry for each component in all binary packages." |
|
2944 |
||
2945 |
|modules| |
|
2946 |
||
2947 |
modules := IdentityDictionary new. |
|
2948 |
self allBinaryModulesDo:[:entry | |
|
2949 |
|id name type libName subModuleName module dynamic infoRec pathName |
|
2950 |
t| |
|
2951 |
||
2952 |
id := entry at:1. |
|
2953 |
subModuleName := (entry at:2) asSymbol. |
|
2954 |
libName := (entry at:4). |
|
2955 |
t := AbsoluteTime fromOSTime:(entry at:5). |
|
2956 |
||
2957 |
id > 0 ifTrue:[ |
|
2958 |
dynamic := true. |
|
2959 |
] ifFalse:[ |
|
2960 |
dynamic := false. |
|
2961 |
]. |
|
2962 |
libName isNil ifTrue:[ |
|
2963 |
type := #classObject |
|
2964 |
] ifFalse:[ |
|
2965 |
type := #classLibrary |
|
2966 |
]. |
|
2967 |
infoRec := IdentityDictionary new. |
|
2968 |
infoRec at:#id put:id. |
|
2969 |
infoRec at:#className put:subModuleName. |
|
2970 |
infoRec at:#libraryName put:libName. |
|
2971 |
infoRec at:#dynamic put:dynamic. |
|
2972 |
infoRec at:#type put:type. |
|
2973 |
infoRec at:#timeStamp put:t. |
|
2974 |
modules at:subModuleName put:infoRec. |
|
2975 |
]. |
|
2976 |
^ modules |
|
2977 |
||
2978 |
" |
|
2979 |
ObjectMemory fullBinaryModuleInfo |
|
2980 |
" |
|
2981 |
||
2982 |
"Modified: 30.8.1995 / 17:29:30 / claus" |
|
379 | 2983 |
! ! |
2984 |
||
2985 |
!ObjectMemory class ignoredMethodsFor:'system management'! |
|
1 | 2986 |
|
2987 |
applicationImageOn:aFileName for:startupClass selector:startupSelector |
|
2988 |
"create a snapshot which will come up without any views |
|
93 | 2989 |
but starts up an application by sending startupClass the startupSelector. |
312 | 2990 |
This exists to nail down an idea I tried once. |
2991 |
It is absolutely EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 2992 |
|
2 | 2993 |
|viewsKnown savedIdleBlocks savedTimeoutBlocks savedTranscript |
2994 |
savedRoot| |
|
1 | 2995 |
|
2996 |
viewsKnown := Display knownViews. |
|
2997 |
savedTranscript := Transcript. |
|
2 | 2998 |
savedRoot := RootView. |
1 | 2999 |
|
335 | 3000 |
"a kludge: save image with modified knownViews, |
10 | 3001 |
and also Transcript set to StdErr ..." |
1 | 3002 |
|
3003 |
Display knownViews:nil. |
|
2 | 3004 |
RootView := nil. |
3005 |
||
1 | 3006 |
Transcript := Stderr. |
10 | 3007 |
Smalltalk startupClass:startupClass selector:startupSelector arguments:nil. |
1 | 3008 |
self snapShotOn:aFileName. |
10 | 3009 |
Smalltalk startupClass:nil selector:nil arguments:nil. |
1 | 3010 |
|
2 | 3011 |
RootView := savedRoot. |
1 | 3012 |
Transcript := savedTranscript. |
3013 |
Display knownViews:viewsKnown. |
|
335 | 3014 |
|
3015 |
" |
|
3016 |
ObjectMemory applicationImageOn:'draw.img' for:DrawTool selector:#start |
|
3017 |
" |
|
1 | 3018 |
! |
3019 |
||
3020 |
minimumApplicationImageOn:aFileName for:startupClass selector:startupSelector |
|
3021 |
"create a snapshot which will come up without any views |
|
3022 |
but starts up an application by sending startupClass the startupSelector. |
|
93 | 3023 |
All unneeded info is stripped from the saved image. |
312 | 3024 |
This exists to nail down an idea I tried once. |
3025 |
It is absolutely EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 3026 |
|
3027 |
"create a temporary image, for continuation" |
|
3028 |
self snapShotOn:'temp.img'. |
|
3029 |
||
3030 |
Display knownViews do:[:aView | |
|
159 | 3031 |
aView notNil ifTrue:[ |
3032 |
aView superView isNil ifTrue:[ |
|
3033 |
aView destroy |
|
3034 |
] |
|
3035 |
] |
|
1 | 3036 |
]. |
3037 |
||
3038 |
self stripImage. |
|
3039 |
||
3040 |
self applicationImageOn:aFileName for:startupClass selector:startupSelector. |
|
3041 |
||
3042 |
"continue in old image" |
|
3043 |
||
3044 |
OperatingSystem exec:(Arguments at:1) |
|
159 | 3045 |
withArguments:#('smalltalk' '-i' 'temp.img') , (Arguments copyFrom:2) |
1 | 3046 |
|
335 | 3047 |
" |
3048 |
ObjectMemory minimumApplicationImageOn:'draw1.img' for:DrawTool selector:#start |
|
3049 |
ObjectMemory applicationImageOn:'draw2.img' for:DrawTool selector:#start |
|
3050 |
" |
|
1 | 3051 |
! |
3052 |
||
3053 |
stripImage |
|
93 | 3054 |
"remove all unneeded stuff from the image - much more is possible here. |
3055 |
EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 3056 |
|
2 | 3057 |
"remove all class comments & source" |
1 | 3058 |
|
2 | 3059 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 3060 |
aClass setComment:nil. |
3061 |
aClass methodArray do:[:aMethod | |
|
3062 |
aMethod source:''. |
|
3063 |
aMethod category:#none |
|
3064 |
] |
|
1 | 3065 |
]. |
335 | 3066 |
|
3067 |
"remove some developpers classes" |
|
3068 |
||
3069 |
Smalltalk at:#Compiler put:Parser. |
|
3070 |
Smalltalk at:#Debugger put:MiniDebugger. |
|
3071 |
Smalltalk at:#Inspector put:MiniInspector. |
|
3072 |
Smalltalk at:#FileBrowser put:nil. |
|
3073 |
Smalltalk at:#SystemBrowser put:nil. |
|
3074 |
Debugger newDebugger. |
|
3075 |
||
1 | 3076 |
self garbageCollect |
3077 |
! ! |
|
362 | 3078 |
|
3079 |
!ObjectMemory class methodsFor:'ST-80 compatibility'! |
|
3080 |
||
3081 |
availableFreeBytes |
|
3082 |
^ self freeSpace + self freeListSpace |
|
3083 |
||
3084 |
" |
|
3085 |
ObjectMemory availableFreeBytes |
|
3086 |
" |
|
3087 |
! |
|
3088 |
||
3089 |
current |
|
3090 |
^ self |
|
3091 |
! |
|
3092 |
||
3093 |
growMemoryBy:numberOfBytes |
|
3094 |
^ self moreOldSpace:numberOfBytes |
|
3095 |
! |
|
3096 |
||
3097 |
numOopsNumBytes |
|
3098 |
^ Array with:(self numberOfObjects) |
|
3099 |
with:(self bytesUsed) |
|
3100 |
||
3101 |
" |
|
3102 |
ObjectMemory numOopsNumBytes |
|
3103 |
" |
|
3104 |
! |
|
3105 |
||
426 | 3106 |
bytesPerOOP |
3107 |
"return the number of bytes an object reference (for example: an instvar) |
|
3108 |
takes" |
|
3109 |
||
3110 |
%{ /* NOCONTEXT */ |
|
3111 |
RETURN(__MKSMALLINT(sizeof(OBJ))); |
|
3112 |
%} |
|
3113 |
||
3114 |
" |
|
3115 |
ObjectMemory bytesPerOOP |
|
3116 |
" |
|
3117 |
! |
|
3118 |
||
3119 |
bytesPerOTE |
|
3120 |
"return the number of overhead bytes of an object. |
|
3121 |
i.e. the number of bytes in every objects header." |
|
3122 |
||
3123 |
%{ /* NOCONTEXT */ |
|
3124 |
RETURN(__MKSMALLINT(OHDR_SIZE)); |
|
3125 |
%} |
|
3126 |
||
3127 |
" |
|
3128 |
ObjectMemory bytesPerOTE |
|
3129 |
" |
|
3130 |
! |
|
3131 |
||
362 | 3132 |
globalCompactingGC |
3133 |
self garbageCollect |
|
3134 |
! |
|
3135 |
||
3136 |
compactingGC |
|
3137 |
self garbageCollect |
|
3138 |
! ! |