author | Claus Gittinger <cg@exept.de> |
Tue, 31 Oct 1995 15:36:06 +0100 | |
changeset 463 | 447ead9f870c |
parent 458 | ef1a25054341 |
child 464 | 83af924c8cff |
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 |
|
178 | 23 |
AllocationFailureSignal 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 |
|
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
37 |
$Header: /cvs/stx/stx/libbasic/Attic/ObjMem.st,v 1.59 1995-10-30 14:46:17 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 |
" |
|
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
58 |
$Header: /cvs/stx/stx/libbasic/Attic/ObjMem.st,v 1.59 1995-10-30 14:46:17 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 |
|
580 |
LowSpaceSemaphore := Semaphore new. |
|
2 | 581 |
]. |
290 | 582 |
DisposeInterruptHandler := self. |
2 | 583 |
IncrementalGCLimit := 500000. |
310 | 584 |
FreeSpaceGCLimit := FreeSpaceGCAmount := nil. |
13 | 585 |
MemoryInterruptHandler := self |
2 | 586 |
! ! |
587 |
||
345 | 588 |
!ObjectMemory class methodsFor:'Signal constants'! |
2 | 589 |
|
590 |
allocationFailureSignal |
|
13 | 591 |
"return the signal raised when an object allocation failed" |
592 |
||
2 | 593 |
^ AllocationFailureSignal |
594 |
! ! |
|
1 | 595 |
|
178 | 596 |
!ObjectMemory class methodsFor:'semaphore access'! |
597 |
||
598 |
lowSpaceSemaphore |
|
599 |
"return the semaphore that is signalled when the system detects a |
|
600 |
low space condition. Usually, some time after this, an allocationFailure |
|
601 |
will happen. You can have a cleanup process sitting in that semaphore and |
|
602 |
start to release object." |
|
603 |
||
604 |
^ LowSpaceSemaphore |
|
605 |
! ! |
|
606 |
||
375 | 607 |
!ObjectMemory class methodsFor:'VM messages'! |
608 |
||
609 |
infoPrinting:aBoolean |
|
610 |
"turn on/off various informational printouts in the VM. |
|
611 |
For example, the GC activity messages are controlled by |
|
612 |
this flags setting. |
|
613 |
The default is true, since (currently) those messages |
|
614 |
are useful for ST/X developers." |
|
615 |
||
616 |
%{ /* NOCONTEXT */ |
|
617 |
extern int __infoPrinting; |
|
618 |
||
619 |
__infoPrinting = (aBoolean == true); |
|
620 |
%} |
|
621 |
! |
|
622 |
||
623 |
infoPrinting |
|
624 |
"return true, if various informational printouts in the VM |
|
625 |
are turned on, false of off." |
|
626 |
||
627 |
%{ /* NOCONTEXT */ |
|
628 |
extern int __infoPrinting; |
|
629 |
||
630 |
RETURN (__infoPrinting ? true : false); |
|
631 |
%} |
|
632 |
! |
|
633 |
||
634 |
debugPrinting:aBoolean |
|
635 |
"turn on/off various debug printouts in the VM |
|
636 |
in case of an error. For example, a double-notUnderstood |
|
637 |
leads to a VM context dump if debugPrinting is on. |
|
638 |
If off, those messages are suppressed. |
|
639 |
The default is on, since these messages are only printed for |
|
640 |
severe errors." |
|
641 |
||
642 |
%{ /* NOCONTEXT */ |
|
643 |
extern int __debugPrinting; |
|
644 |
||
645 |
__debugPrinting = (aBoolean == true); |
|
646 |
%} |
|
647 |
! |
|
648 |
||
649 |
debugPrinting |
|
650 |
"return true, if various debug printouts in the VM |
|
651 |
are turned on, false of off." |
|
652 |
||
653 |
%{ /* NOCONTEXT */ |
|
654 |
extern int __debugPrinting; |
|
655 |
||
656 |
RETURN (__debugPrinting ? true : false); |
|
657 |
%} |
|
658 |
! ! |
|
659 |
||
10 | 660 |
!ObjectMemory class methodsFor:'dependents access'! |
661 |
||
662 |
dependents |
|
663 |
"return the colleciton of my dependents" |
|
664 |
||
665 |
^ Dependents |
|
666 |
! |
|
667 |
||
668 |
dependents:aCollection |
|
669 |
"set the dependents collection" |
|
670 |
||
671 |
Dependents := aCollection |
|
282 | 672 |
! |
673 |
||
674 |
dependentsDo:aBlock |
|
675 |
"evaluate aBlock for all of my dependents. |
|
676 |
Since this is performed at startup time (under the scheduler), |
|
677 |
this is redefined here to catch abort signals. |
|
678 |
Thus, if any error occurs in a #returnFromSnapshot, |
|
679 |
the user can press abort to continue." |
|
680 |
||
681 |
|deps| |
|
682 |
||
683 |
deps := Dependents. |
|
684 |
deps notNil ifTrue:[ |
|
685 |
deps do:[:each | |
|
686 |
AbortSignal handle:[:ex | |
|
687 |
ex return |
|
688 |
] do:[ |
|
689 |
aBlock value:each |
|
690 |
] |
|
691 |
] |
|
692 |
] |
|
10 | 693 |
! ! |
694 |
||
1 | 695 |
!ObjectMemory class methodsFor:'cache management'! |
696 |
||
697 |
flushInlineCachesForClass:aClass |
|
93 | 698 |
"flush inlinecaches for calls to aClass." |
1 | 699 |
|
700 |
%{ /* NOCONTEXT */ |
|
701 |
__flushInlineCachesFor(aClass); |
|
702 |
%} |
|
703 |
! |
|
704 |
||
705 |
flushInlineCachesWithArgs:nargs |
|
706 |
"flush inlinecaches for calls with nargs arguments" |
|
707 |
||
708 |
%{ /* NOCONTEXT */ |
|
709 |
__flushInlineCaches(_intVal(nargs)); |
|
710 |
%} |
|
711 |
! |
|
712 |
||
713 |
flushInlineCachesFor:aClass withArgs:nargs |
|
714 |
"flush inlinecaches for calls to aClass with nargs arguments" |
|
715 |
||
716 |
%{ /* NOCONTEXT */ |
|
717 |
__flushInlineCachesForAndNargs(aClass, _intVal(nargs)); |
|
718 |
%} |
|
719 |
! |
|
720 |
||
332 | 721 |
flushInlineCachesForSelector:aSelector |
722 |
"flush inlinecaches for sends of aSelector" |
|
723 |
||
724 |
%{ /* NOCONTEXT */ |
|
725 |
__flushInlineCachesForSelector(aSelector); |
|
726 |
%} |
|
727 |
! |
|
728 |
||
1 | 729 |
flushInlineCaches |
730 |
"flush all inlinecaches" |
|
731 |
||
732 |
%{ /* NOCONTEXT */ |
|
733 |
__flushAllInlineCaches(); |
|
734 |
%} |
|
735 |
! |
|
736 |
||
737 |
flushMethodCacheFor:aClass |
|
738 |
"flush the method cache for sends to aClass" |
|
739 |
||
740 |
%{ /* NOCONTEXT */ |
|
741 |
__flushMethodCacheFor(aClass); |
|
742 |
%} |
|
743 |
! |
|
744 |
||
332 | 745 |
flushMethodCacheForSelector:aSelector |
746 |
"flush the method cache for sends of aSelector" |
|
747 |
||
748 |
%{ /* NOCONTEXT */ |
|
749 |
__flushMethodCacheForSelector(aSelector); |
|
750 |
%} |
|
751 |
! |
|
752 |
||
1 | 753 |
flushMethodCache |
754 |
"flush the method cache" |
|
755 |
||
756 |
%{ /* NOCONTEXT */ |
|
757 |
__flushMethodCache(); |
|
758 |
%} |
|
759 |
! |
|
760 |
||
2 | 761 |
flushCachesFor:aClass |
762 |
"flush method and inline caches for aClass" |
|
763 |
||
764 |
%{ /* NOCONTEXT */ |
|
765 |
__flushMethodCacheFor(aClass); |
|
766 |
__flushInlineCachesFor(aClass); |
|
767 |
%} |
|
768 |
! |
|
769 |
||
332 | 770 |
flushCachesForSelector:aSelector |
440 | 771 |
"flush method and inline caches for aSelector" |
332 | 772 |
|
773 |
%{ /* NOCONTEXT */ |
|
774 |
__flushMethodCacheForSelector(aSelector); |
|
775 |
__flushInlineCachesForSelector(aSelector); |
|
776 |
%} |
|
777 |
! |
|
778 |
||
1 | 779 |
flushCaches |
2 | 780 |
"flush method and inline caches for all classes" |
1 | 781 |
|
782 |
%{ /* NOCONTEXT */ |
|
783 |
__flushMethodCache(); |
|
784 |
__flushAllInlineCaches(); |
|
785 |
%} |
|
786 |
! ! |
|
787 |
||
216 | 788 |
!ObjectMemory class methodsFor:'enumerating'! |
1 | 789 |
|
790 |
allObjectsDo:aBlock |
|
85 | 791 |
"evaluate the argument, aBlock for all objects in the system. |
792 |
There is one caveat: if a compressing oldSpace collect |
|
793 |
occurs while looping over the objects, the loop cannot be |
|
794 |
continued (for some internal reasons). In this case, false |
|
795 |
is returned." |
|
2 | 796 |
|
797 |
|work| |
|
22 | 798 |
|
799 |
%{ /* NOREGISTER - work may not be placed into a register here */ |
|
326 | 800 |
__nonTenuringScavenge(__context); |
2 | 801 |
/* |
802 |
* allObjectsDo needs a temporary to hold newSpace objects |
|
803 |
*/ |
|
369 | 804 |
if (__allInstancesOfDo((OBJ *)0, &aBlock, &work COMMA_CON) < 0) { |
805 |
RETURN (false); |
|
806 |
} |
|
807 |
%}. |
|
808 |
^ true |
|
809 |
! |
|
810 |
||
811 |
allInstancesOf:aClass do:aBlock |
|
812 |
"evaluate the argument, aBlock for all instances of aClass in the system. |
|
813 |
There is one caveat: if a compressing oldSpace collect |
|
814 |
occurs while looping over the objects, the loop cannot be |
|
815 |
continued (for some internal reasons). In this case, false |
|
816 |
is returned." |
|
817 |
||
818 |
|work| |
|
819 |
||
820 |
%{ /* NOREGISTER - work may not be placed into a register here */ |
|
821 |
__nonTenuringScavenge(__context); |
|
822 |
/* |
|
823 |
* allInstancesDo needs a temporary to hold newSpace objects |
|
824 |
*/ |
|
825 |
if (__allInstancesOfDo(&aClass, &aBlock, &work COMMA_CON) < 0) { |
|
159 | 826 |
RETURN (false); |
85 | 827 |
} |
828 |
%}. |
|
829 |
^ true |
|
2 | 830 |
! |
831 |
||
832 |
allOldObjectsDo:aBlock |
|
833 |
"evaluate the argument, aBlock for all old objects in the system. |
|
834 |
For debugging and tests only - do not use" |
|
835 |
%{ |
|
369 | 836 |
if (__allInstancesOfDo((OBJ *)0, &aBlock, (OBJ *)0 COMMA_CON) < 0) { |
159 | 837 |
RETURN (false); |
85 | 838 |
} |
839 |
%}. |
|
840 |
^ true |
|
1 | 841 |
! ! |
842 |
||
229 | 843 |
!ObjectMemory class methodsFor:'interrupt handler access'! |
2 | 844 |
|
845 |
internalErrorHandler |
|
13 | 846 |
"return the handler for ST/X internal errors. |
847 |
An internal error is reported for example when a methods |
|
848 |
bytecode is not a ByteArray, the selector table is not an Array |
|
93 | 849 |
etc. |
850 |
Those should not occur in normal circumstances." |
|
13 | 851 |
|
2 | 852 |
^ InternalErrorHandler |
853 |
! |
|
854 |
||
855 |
userInterruptHandler |
|
13 | 856 |
"return the handler for CNTL-C interrupt handling" |
857 |
||
2 | 858 |
^ UserInterruptHandler |
859 |
! |
|
860 |
||
861 |
userInterruptHandler:aHandler |
|
13 | 862 |
"set the handler for CNTL-C interrupt handling" |
863 |
||
2 | 864 |
UserInterruptHandler := aHandler |
865 |
! |
|
866 |
||
867 |
timerInterruptHandler |
|
13 | 868 |
"return the handler for timer interrupts" |
869 |
||
2 | 870 |
^ TimerInterruptHandler |
871 |
! |
|
872 |
||
10 | 873 |
timerInterruptHandler:aHandler |
13 | 874 |
"set the handler for timer interrupts" |
875 |
||
10 | 876 |
TimerInterruptHandler := aHandler |
877 |
! |
|
878 |
||
2 | 879 |
spyInterruptHandler |
13 | 880 |
"return the handler for spy-timer interrupts" |
881 |
||
2 | 882 |
^ SpyInterruptHandler |
883 |
! |
|
884 |
||
885 |
spyInterruptHandler:aHandler |
|
13 | 886 |
"set the handler for spy-timer interrupts" |
887 |
||
2 | 888 |
SpyInterruptHandler := aHandler |
889 |
! |
|
890 |
||
891 |
stepInterruptHandler |
|
13 | 892 |
"return the handler for single step interrupts" |
893 |
||
2 | 894 |
^ StepInterruptHandler |
895 |
! |
|
896 |
||
897 |
stepInterruptHandler:aHandler |
|
13 | 898 |
"set the handler for single step interrupts" |
899 |
||
2 | 900 |
StepInterruptHandler := aHandler |
901 |
! |
|
902 |
||
903 |
exceptionInterruptHandler |
|
13 | 904 |
"return the handler for floating point exception interrupts" |
905 |
||
2 | 906 |
^ ExceptionInterruptHandler |
907 |
! |
|
908 |
||
909 |
errorInterruptHandler |
|
13 | 910 |
"return the handler for display error interrupts" |
911 |
||
2 | 912 |
^ ErrorInterruptHandler |
913 |
! |
|
914 |
||
915 |
errorInterruptHandler:aHandler |
|
13 | 916 |
"set the handler for display error interrupts" |
917 |
||
2 | 918 |
ErrorInterruptHandler := aHandler |
919 |
! |
|
920 |
||
345 | 921 |
registeredErrorInterruptHandlers |
922 |
"return registered handlers" |
|
923 |
||
924 |
^ RegisteredErrorInterruptHandlers |
|
925 |
! |
|
926 |
||
927 |
registerErrorInterruptHandler:aHandler forID:errorIDSymbol |
|
928 |
"register a handler" |
|
929 |
||
930 |
RegisteredErrorInterruptHandlers isNil ifTrue:[ |
|
931 |
RegisteredErrorInterruptHandlers := IdentityDictionary new |
|
932 |
]. |
|
933 |
RegisteredErrorInterruptHandlers at:errorIDSymbol put:aHandler |
|
934 |
! |
|
935 |
||
13 | 936 |
signalInterruptHandler |
937 |
"return the handler for UNIX-signal interrupts" |
|
2 | 938 |
|
939 |
^ SignalInterruptHandler |
|
940 |
! |
|
941 |
||
13 | 942 |
signalInterruptHandler:aHandler |
943 |
"set the handler for UNIX-signal interrupts" |
|
944 |
||
945 |
SignalInterruptHandler := aHandler |
|
946 |
! |
|
947 |
||
2 | 948 |
childSignalInterruptHandler |
13 | 949 |
"return the handler for UNIX-death-of-a-childprocess-signal interrupts" |
950 |
||
2 | 951 |
^ ChildSignalInterruptHandler |
952 |
! |
|
953 |
||
954 |
disposeInterruptHandler |
|
13 | 955 |
"return the handler for object disposal interrupts" |
956 |
||
2 | 957 |
^ DisposeInterruptHandler |
958 |
! |
|
959 |
||
960 |
disposeInterruptHandler:aHandler |
|
13 | 961 |
"set the handler for object disposal interrupts" |
962 |
||
2 | 963 |
DisposeInterruptHandler := aHandler |
964 |
! |
|
965 |
||
966 |
recursionInterruptHandler |
|
13 | 967 |
"return the handler for recursion/stack overflow interrupts" |
968 |
||
2 | 969 |
^ RecursionInterruptHandler |
970 |
! |
|
971 |
||
13 | 972 |
recursionInterruptHandler:aHandler |
973 |
"set the handler for recursion/stack overflow interrupts" |
|
974 |
||
975 |
RecursionInterruptHandler := aHandler |
|
976 |
! |
|
977 |
||
2 | 978 |
ioInterruptHandler |
13 | 979 |
"return the handler for I/O available signal interrupts (SIGIO/SIGPOLL)" |
980 |
||
2 | 981 |
^ IOInterruptHandler |
982 |
! |
|
983 |
||
984 |
ioInterruptHandler:aHandler |
|
13 | 985 |
"set the handler for I/O available signal interrupts (SIGIO/SIGPOLL)" |
986 |
||
2 | 987 |
IOInterruptHandler := aHandler |
85 | 988 |
! |
989 |
||
990 |
customInterruptHandler |
|
991 |
"return the handler for custom interrupts" |
|
992 |
||
993 |
^ CustomInterruptHandler |
|
994 |
! |
|
995 |
||
996 |
customInterruptHandler:aHandler |
|
997 |
"set the handler for custom interrupts" |
|
998 |
||
999 |
CustomInterruptHandler := aHandler |
|
2 | 1000 |
! ! |
1001 |
||
1 | 1002 |
!ObjectMemory class methodsFor:'queries'! |
1003 |
||
13 | 1004 |
newSpaceSize |
1005 |
"return the total size of the new space - this is usually fix" |
|
1006 |
||
1007 |
%{ /* NOCONTEXT */ |
|
133 | 1008 |
extern unsigned __newSpaceSize(); |
1009 |
||
13 | 1010 |
RETURN ( _MKSMALLINT(__newSpaceSize()) ); |
1011 |
%} |
|
93 | 1012 |
" |
1013 |
ObjectMemory newSpaceSize |
|
1014 |
" |
|
13 | 1015 |
! |
1016 |
||
1017 |
oldSpaceSize |
|
1018 |
"return the total size of the old space. - may grow slowly" |
|
1019 |
||
1020 |
%{ /* NOCONTEXT */ |
|
133 | 1021 |
extern unsigned __oldSpaceSize(); |
1022 |
||
13 | 1023 |
RETURN ( _MKSMALLINT(__oldSpaceSize()) ); |
1024 |
%} |
|
93 | 1025 |
" |
1026 |
ObjectMemory oldSpaceSize |
|
1027 |
" |
|
13 | 1028 |
! |
1029 |
||
325 | 1030 |
symSpaceSize |
1031 |
"return the total size of the sym space." |
|
1032 |
||
1033 |
%{ /* NOCONTEXT */ |
|
1034 |
extern unsigned __symSpaceSize(); |
|
1035 |
||
1036 |
RETURN ( _MKSMALLINT(__symSpaceSize()) ); |
|
1037 |
%} |
|
1038 |
" |
|
1039 |
ObjectMemory symSpaceSize |
|
1040 |
" |
|
1041 |
! |
|
1042 |
||
216 | 1043 |
fixSpaceSize |
1044 |
"return the total size of the fix space." |
|
1045 |
||
1046 |
%{ /* NOCONTEXT */ |
|
1047 |
extern unsigned __fixSpaceSize(); |
|
1048 |
||
1049 |
RETURN ( _MKSMALLINT(__fixSpaceSize()) ); |
|
1050 |
%} |
|
1051 |
" |
|
1052 |
ObjectMemory fixSpaceSize |
|
1053 |
" |
|
1054 |
! |
|
1055 |
||
1 | 1056 |
newSpaceUsed |
10 | 1057 |
"return the number of bytes allocated for new objects. |
1058 |
The returned value is usually obsolete as soon as you do |
|
13 | 1059 |
something with it ..." |
1 | 1060 |
|
1061 |
%{ /* NOCONTEXT */ |
|
133 | 1062 |
extern unsigned __newSpaceUsed(); |
1063 |
||
1 | 1064 |
RETURN ( _MKSMALLINT(__newSpaceUsed()) ); |
1065 |
%} |
|
93 | 1066 |
" |
202 | 1067 |
ObjectMemory newSpaceUsed |
93 | 1068 |
" |
1 | 1069 |
! |
1070 |
||
1071 |
oldSpaceUsed |
|
10 | 1072 |
"return the number of bytes allocated for old objects. |
1073 |
(This includes the free lists)" |
|
1 | 1074 |
|
1075 |
%{ /* NOCONTEXT */ |
|
133 | 1076 |
extern unsigned __oldSpaceUsed(); |
1077 |
||
1 | 1078 |
RETURN ( _MKSMALLINT(__oldSpaceUsed()) ); |
1079 |
%} |
|
93 | 1080 |
" |
202 | 1081 |
ObjectMemory oldSpaceUsed |
93 | 1082 |
" |
1 | 1083 |
! |
1084 |
||
325 | 1085 |
symSpaceUsed |
1086 |
"return the number of bytes allocated for old objects in sym space." |
|
1087 |
||
1088 |
%{ /* NOCONTEXT */ |
|
1089 |
extern unsigned __symSpaceUsed(); |
|
1090 |
||
1091 |
RETURN ( _MKSMALLINT(__symSpaceUsed()) ); |
|
1092 |
%} |
|
1093 |
" |
|
1094 |
ObjectMemory symSpaceUsed |
|
1095 |
" |
|
1096 |
! |
|
1097 |
||
216 | 1098 |
fixSpaceUsed |
1099 |
"return the number of bytes allocated for old objects in fix space." |
|
1100 |
||
1101 |
%{ /* NOCONTEXT */ |
|
1102 |
extern unsigned __fixSpaceUsed(); |
|
1103 |
||
1104 |
RETURN ( _MKSMALLINT(__fixSpaceUsed()) ); |
|
1105 |
%} |
|
1106 |
" |
|
1107 |
ObjectMemory fixSpaceUsed |
|
1108 |
" |
|
1109 |
! |
|
1110 |
||
270 | 1111 |
freeSpace |
1112 |
"return the number of bytes in the compact free area. |
|
1113 |
(oldSpaceUsed + freeSpaceSize = oldSpaceSize)" |
|
1114 |
||
1115 |
%{ /* NOCONTEXT */ |
|
1116 |
extern unsigned __oldSpaceSize(), __oldSpaceUsed(); |
|
1117 |
||
1118 |
RETURN ( _MKSMALLINT(__oldSpaceSize() - __oldSpaceUsed()) ); |
|
1119 |
%} |
|
1120 |
" |
|
1121 |
ObjectMemory freeSpace |
|
1122 |
" |
|
1123 |
! |
|
1124 |
||
133 | 1125 |
freeListSpace |
10 | 1126 |
"return the number of bytes in the free lists. |
1127 |
(which is included in oldSpaceUsed)" |
|
1128 |
||
1129 |
%{ /* NOCONTEXT */ |
|
133 | 1130 |
extern unsigned __freeListSpace(); |
1131 |
||
1132 |
RETURN ( _MKSMALLINT(__freeListSpace()) ); |
|
10 | 1133 |
%} |
93 | 1134 |
" |
133 | 1135 |
ObjectMemory freeListSpace |
93 | 1136 |
" |
10 | 1137 |
! |
1138 |
||
1 | 1139 |
bytesUsed |
1140 |
"return the number of bytes allocated for objects - |
|
178 | 1141 |
this number is not exact, since some objects may already be dead |
1142 |
(i.e. not yet reclaimed by the garbage collector). |
|
1143 |
If you need the exact number, you have to loop over all |
|
1144 |
objects and ask for the bytesize using ObjectMemory>>sizeOf:." |
|
1 | 1145 |
|
1146 |
%{ /* NOCONTEXT */ |
|
133 | 1147 |
extern unsigned __oldSpaceUsed(), __newSpaceUsed(), __freeListSpace(); |
1148 |
||
1149 |
RETURN ( _MKSMALLINT(__oldSpaceUsed() + __newSpaceUsed() - __freeListSpace()) ); |
|
1 | 1150 |
%} |
93 | 1151 |
" |
202 | 1152 |
ObjectMemory bytesUsed |
93 | 1153 |
" |
1 | 1154 |
! |
1155 |
||
2 | 1156 |
oldSpaceAllocatedSinceLastGC |
1157 |
"return the number of bytes allocated for old objects since the |
|
178 | 1158 |
last oldspace garbage collect occured. This information is used |
1159 |
by ProcessorScheduler to decide when to start the incremental |
|
1160 |
background GC." |
|
2 | 1161 |
|
1162 |
%{ /* NOCONTEXT */ |
|
133 | 1163 |
extern unsigned __oldSpaceAllocatedSinceLastGC(); |
1164 |
||
2 | 1165 |
RETURN ( _MKSMALLINT(__oldSpaceAllocatedSinceLastGC()) ); |
1166 |
%} |
|
93 | 1167 |
" |
202 | 1168 |
ObjectMemory oldSpaceAllocatedSinceLastGC |
93 | 1169 |
" |
2 | 1170 |
! |
1171 |
||
178 | 1172 |
tenureAge |
1173 |
"return the current tenure age - thats the number of times |
|
1174 |
an object has to survive scavenges to be moved into oldSpace. |
|
202 | 1175 |
For statistic/debugging only - this method may vanish" |
178 | 1176 |
|
1177 |
%{ /* NOCONTEXT */ |
|
1178 |
extern unsigned __tenureAge(); |
|
1179 |
||
1180 |
RETURN ( _MKSMALLINT(__tenureAge()) ); |
|
1181 |
%} |
|
1182 |
! |
|
1183 |
||
362 | 1184 |
lastScavengeReclamation |
194 | 1185 |
"returns the number of bytes replacimed by the last scavenge. |
1186 |
For statistic only - this may vanish." |
|
1187 |
||
1188 |
%{ /* NOCONTEXT */ |
|
1189 |
extern int __newSpaceReclaimed(); |
|
1190 |
||
1191 |
RETURN ( _MKSMALLINT(__newSpaceReclaimed()) ); |
|
1192 |
%} |
|
202 | 1193 |
"percentage of reclaimed objects is returned by: |
1194 |
||
362 | 1195 |
((ObjectMemory lastScavengeReclamation) |
202 | 1196 |
/ (ObjectMemory newSpaceSize)) * 100.0 |
194 | 1197 |
" |
1198 |
! |
|
1199 |
||
362 | 1200 |
resetMinScavengeReclamation |
1201 |
"resets the number of bytes replacimed by the least effective scavenge. |
|
1202 |
For statistic only - this may vanish." |
|
1203 |
||
1204 |
%{ /* NOCONTEXT */ |
|
1205 |
extern int __resetNewSpaceReclaimedMin(); |
|
1206 |
||
1207 |
__resetNewSpaceReclaimedMin(); |
|
1208 |
%}. |
|
1209 |
^ self |
|
1210 |
" |
|
1211 |
ObjectMemory resetMinScavengeReclamation. |
|
1212 |
ObjectMemory minScavengeReclamation |
|
1213 |
" |
|
1214 |
! |
|
1215 |
||
1216 |
minScavengeReclamation |
|
1217 |
"returns the number of bytes replacimed by the least effective scavenge. |
|
1218 |
For statistic only - this may vanish." |
|
1219 |
||
1220 |
%{ /* NOCONTEXT */ |
|
1221 |
extern int __newSpaceReclaimedMin(); |
|
1222 |
||
1223 |
RETURN ( _MKSMALLINT(__newSpaceReclaimedMin()) ); |
|
1224 |
%} |
|
1225 |
" |
|
1226 |
ObjectMemory minScavengeReclamation |
|
1227 |
" |
|
1228 |
! |
|
1229 |
||
178 | 1230 |
runsSingleOldSpace |
1231 |
"return true, if the system runs in a single oldSpace or |
|
326 | 1232 |
false if not. |
1233 |
The memory system will always drop the second semispace when |
|
1234 |
running out of virtual memory, or the baker-limit is reached. |
|
202 | 1235 |
OBSOLETE: |
1236 |
the system may now decide at any time to switch between |
|
1237 |
single and double-space algorithms, depending on the overall memory |
|
1238 |
size. You will now almost always get false as result, since the |
|
326 | 1239 |
second semispace is only allocated when needed, and released |
1240 |
immediately afterwards. |
|
202 | 1241 |
" |
178 | 1242 |
|
1243 |
%{ /* NOCONTEXT */ |
|
357 | 1244 |
extern int __runsSingleOldSpace(); |
1245 |
||
1246 |
RETURN ( (__runsSingleOldSpace() ? true : false) ); |
|
178 | 1247 |
%} |
202 | 1248 |
" |
1249 |
ObjectMemory runsSingleOldSpace |
|
1250 |
" |
|
178 | 1251 |
! |
1252 |
||
1253 |
incrementalGCPhase |
|
1254 |
"returns the internal state of the incremental GC. |
|
1255 |
The meaning of those numbers is a secret :-). |
|
326 | 1256 |
(for the curious: (currently) |
1257 |
2 is idle, 3..11 are various mark phases, |
|
1258 |
12 is the sweep phase. 0 and 1 are cleanup phases when the |
|
1259 |
incr. GC gets interrupted by a full GC). |
|
356 | 1260 |
Do not depend on the values - there may be additional phases in |
1261 |
future versions (incremental compact ;-). |
|
326 | 1262 |
This is for debugging and monitoring only - and may change or vanish" |
178 | 1263 |
|
1264 |
%{ /* NOCONTEXT */ |
|
1265 |
extern int __incrGCphase(); |
|
1266 |
||
1267 |
RETURN (_MKSMALLINT(__incrGCphase())); |
|
1268 |
%} |
|
1269 |
! |
|
1270 |
||
270 | 1271 |
scavengeCount |
1272 |
"return the number of scavenges that occurred since startup" |
|
1273 |
||
1274 |
%{ /* NOCONTEXT */ |
|
1275 |
extern int __scavengeCount(); |
|
1276 |
||
1277 |
RETURN (_MKSMALLINT(__scavengeCount())); |
|
1278 |
%} |
|
1279 |
" |
|
1280 |
ObjectMemory scavengeCount |
|
1281 |
" |
|
1282 |
! |
|
1283 |
||
1284 |
markAndSweepCount |
|
1285 |
"return the number of mark&sweep collects that occurred since startup" |
|
1286 |
||
1287 |
%{ /* NOCONTEXT */ |
|
1288 |
extern int __markAndSweepCount(); |
|
1289 |
||
1290 |
RETURN (_MKSMALLINT(__markAndSweepCount())); |
|
1291 |
%} |
|
1292 |
" |
|
1293 |
ObjectMemory markAndSweepCount |
|
1294 |
" |
|
1295 |
! |
|
1296 |
||
1297 |
garbageCollectCount |
|
1298 |
"return the number of compressing collects that occurred since startup" |
|
1299 |
||
1300 |
%{ /* NOCONTEXT */ |
|
1301 |
extern int __garbageCollectCount(); |
|
1302 |
||
1303 |
RETURN (_MKSMALLINT(__garbageCollectCount())); |
|
1304 |
%} |
|
1305 |
" |
|
1306 |
ObjectMemory garbageCollectCount |
|
1307 |
" |
|
1308 |
! |
|
1309 |
||
443 | 1310 |
incrementalGCCount |
1311 |
"return the number of incremental collects that occurred since startup" |
|
1312 |
||
1313 |
%{ /* NOCONTEXT */ |
|
1314 |
extern int __incrementalGCCount(); |
|
1315 |
||
1316 |
RETURN (_MKSMALLINT(__incrementalGCCount())); |
|
1317 |
%} |
|
1318 |
" |
|
1319 |
ObjectMemory incrementalGCCount |
|
1320 |
" |
|
1321 |
! |
|
1322 |
||
362 | 1323 |
rememberedSetSize |
369 | 1324 |
"return the number of old objects referencing new ones. |
1325 |
This is a VM debugging interface and may vanish without notice." |
|
362 | 1326 |
|
1327 |
%{ /* NOCONTEXT */ |
|
1328 |
extern int __rememberedSetSize(); |
|
1329 |
||
1330 |
RETURN (_MKSMALLINT(__rememberedSetSize())); |
|
1331 |
%} |
|
1332 |
" |
|
1333 |
ObjectMemory rememberedSetSize |
|
1334 |
" |
|
1335 |
! |
|
1336 |
||
369 | 1337 |
lifoRememberedSetSize |
1338 |
"return the size of the lifoRemSet. |
|
1339 |
This is a VM debugging interface and may vanish without notice." |
|
1340 |
||
1341 |
%{ /* NOCONTEXT */ |
|
1342 |
extern int __lifoRememberedSetSize(); |
|
1343 |
||
1344 |
RETURN (_MKSMALLINT(__lifoRememberedSetSize())); |
|
1345 |
%} |
|
1346 |
" |
|
1347 |
ObjectMemory lifoRememberedSetSize |
|
1348 |
" |
|
1349 |
! |
|
1350 |
||
1351 |
lifoRememberedSet |
|
1352 |
"return the lifoRemSet. |
|
1353 |
This is pure VM debugging and will vanish without notice." |
|
1354 |
||
1355 |
%{ /* NOCONTEXT */ |
|
1356 |
extern OBJ __lifoRememberedSet(); |
|
1357 |
||
1358 |
RETURN ( __lifoRememberedSet() ); |
|
1359 |
%} |
|
1360 |
" |
|
1361 |
ObjectMemory lifoRememberedSet |
|
1362 |
" |
|
1363 |
! |
|
1364 |
||
1365 |
numberOfWeakObjects |
|
1366 |
"return the number of weak objects in the system" |
|
1367 |
||
1368 |
%{ /* NOCONTEXT */ |
|
1369 |
extern int __weakListSize(); |
|
1370 |
||
1371 |
RETURN ( __MKSMALLINT(__weakListSize()) ); |
|
1372 |
%} |
|
1373 |
" |
|
1374 |
ObjectMemory numberOfWeakObjects |
|
1375 |
" |
|
1376 |
! |
|
1377 |
||
1 | 1378 |
numberOfObjects |
13 | 1379 |
"return the number of objects in the system." |
1 | 1380 |
|
326 | 1381 |
|tally "{ Class: SmallInteger }"| |
1 | 1382 |
|
1383 |
tally := 0. |
|
1384 |
self allObjectsDo:[:obj | tally := tally + 1]. |
|
1385 |
^ tally |
|
1386 |
||
93 | 1387 |
" |
202 | 1388 |
ObjectMemory numberOfObjects |
93 | 1389 |
" |
1 | 1390 |
! |
1391 |
||
202 | 1392 |
collectObjectsWhich:aBlock |
1393 |
"helper for the whoReferences queries. Returns a collection |
|
1394 |
of objects for which aBlock returns true." |
|
1 | 1395 |
|
1396 |
|aCollection| |
|
1397 |
||
1398 |
aCollection := IdentitySet new. |
|
1399 |
self allObjectsDo:[:o | |
|
202 | 1400 |
(aBlock value:o) ifTrue:[ |
159 | 1401 |
aCollection add:o |
1402 |
] |
|
1 | 1403 |
]. |
1404 |
(aCollection size == 0) ifTrue:[ |
|
159 | 1405 |
"actually this cannot happen - there is always one" |
1406 |
^ nil |
|
1 | 1407 |
]. |
1408 |
^ aCollection |
|
13 | 1409 |
! |
1410 |
||
202 | 1411 |
whoReferences:anObject |
1412 |
"return a collection of objects referencing the argument, anObject" |
|
1413 |
||
1414 |
^ self collectObjectsWhich:[:o | o references:anObject] |
|
1415 |
||
1416 |
" |
|
1417 |
(ObjectMemory whoReferences:Transcript) printNL |
|
1418 |
" |
|
1419 |
! |
|
1420 |
||
1421 |
whoReferencesInstancesOf:aClass |
|
1422 |
"return a collection of objects refering to instances |
|
1423 |
of the argument, aClass" |
|
1424 |
||
1425 |
^ self collectObjectsWhich:[:o | o referencesInstanceOf:aClass] |
|
1426 |
||
1427 |
" |
|
1428 |
(ObjectMemory whoReferencesInstancesOf:SystemBrowser) printNL |
|
1429 |
" |
|
1430 |
! |
|
1431 |
||
1432 |
whoReferencesDerivedInstancesOf:aClass |
|
1433 |
"return a collection of objects refering to instances |
|
1434 |
of the argument, aClass or a subclass of it." |
|
1435 |
||
1436 |
^ self collectObjectsWhich:[:o | o referencesDerivedInstanceOf:aClass] |
|
1437 |
||
1438 |
" |
|
1439 |
(ObjectMemory whoReferencesDerivedInstancesOf:View) printNL |
|
1440 |
" |
|
1441 |
! |
|
1442 |
||
435 | 1443 |
maximumIdentityHashValue |
1444 |
"for ST-80 compatibility: return the maximum value |
|
1445 |
a hashKey as returned by identityHash can get. |
|
1446 |
Since ST/X uses direct pointers, a field in the objectHeader |
|
1447 |
is used, which is currently 11 bits in size." |
|
1448 |
||
1449 |
%{ /* NOCONTEXT */ |
|
1450 |
RETURN ( __MKSMALLINT( __MAX_HASH__ << __HASH_SHIFT__) ); |
|
1451 |
%} |
|
1452 |
" |
|
1453 |
ObjectMemory maximumIdentityHashValue |
|
1454 |
" |
|
1455 |
! ! |
|
1456 |
||
1457 |
!ObjectMemory class methodsFor:'debug queries'! |
|
1458 |
||
1459 |
printReferences:anObject |
|
1460 |
"for debugging: print referents to anObject. |
|
1461 |
WARNING: this method is for ST/X debugging only |
|
1462 |
it will be removed without notice |
|
1463 |
use ObjectMemory>>whoReferences: or anObject>>allOwners." |
|
1464 |
||
1465 |
%{ |
|
1466 |
__printRefChain(__context, anObject); |
|
1467 |
%} |
|
1468 |
! |
|
1469 |
||
1470 |
dumpObject:someObject |
|
1471 |
"low level dump an object. |
|
1472 |
WARNING: this method is for ST/X debugging only |
|
1473 |
it will be removed without notice" |
|
1474 |
||
1475 |
%{ |
|
1476 |
dumpObject(someObject); |
|
1477 |
%} |
|
1478 |
" |
|
1479 |
ObjectMemory dumpObject:true |
|
1480 |
ObjectMemory dumpObject:(Array new:10) |
|
1481 |
ObjectMemory dumpObject:(10@20 corner:30@40) |
|
1482 |
" |
|
1483 |
! |
|
1484 |
||
13 | 1485 |
addressOf:anObject |
1486 |
"return the core address of anObject as an integer |
|
1487 |
- since objects may move around, the returned value is invalid after the |
|
1488 |
next scavenge/collect. |
|
435 | 1489 |
WARNING: this method is for ST/X debugging only |
1490 |
it will be removed without notice" |
|
13 | 1491 |
|
1492 |
%{ /* NOCONTEXT */ |
|
1493 |
||
329 | 1494 |
if (! __isNonNilObject(anObject)) { |
159 | 1495 |
RETURN ( nil ); |
13 | 1496 |
} |
326 | 1497 |
if (((int)anObject >= _MIN_INT) && ((int)anObject <= _MAX_INT)) { |
1498 |
RETURN ( _MKSMALLINT((int)anObject) ); |
|
1499 |
} |
|
1500 |
RETURN ( _MKLARGEINT((int)anObject) ); |
|
13 | 1501 |
%} |
1502 |
" |
|
1503 |
|p| |
|
1504 |
p := Point new. |
|
370 | 1505 |
((ObjectMemory addressOf:p) printStringRadix:16) printNL. |
13 | 1506 |
ObjectMemory scavenge. |
370 | 1507 |
((ObjectMemory addressOf:p) printStringRadix:16) printNL. |
13 | 1508 |
" |
1509 |
! |
|
1510 |
||
159 | 1511 |
objectAt:anAddress |
1512 |
"return whatever anAddress points to as object. |
|
202 | 1513 |
BIG BIG DANGER ALERT: |
326 | 1514 |
this method is only to be used for debugging ST/X itself |
1515 |
- you can easily (and badly) crash the system. |
|
435 | 1516 |
WARNING: this method is for ST/X debugging only |
1517 |
it will be removed without notice" |
|
159 | 1518 |
|
1519 |
|low high| |
|
1520 |
||
1521 |
low := anAddress bitAnd:16rFFFF. |
|
1522 |
high := (anAddress bitShift:16) bitAnd:16rFFFF. |
|
1523 |
%{ |
|
253 | 1524 |
if (__bothSmallInteger(low, high)) { |
159 | 1525 |
RETURN ((OBJ)((_intVal(high) << 16) | _intVal(low))); |
1526 |
} |
|
1527 |
%} |
|
1528 |
! |
|
1529 |
||
13 | 1530 |
sizeOf:anObject |
1531 |
"return the size of anObject in bytes. |
|
326 | 1532 |
(this is not the same as 'anObject size'). |
435 | 1533 |
WARNING: this method is for ST/X debugging only |
1534 |
it will be removed without notice" |
|
13 | 1535 |
|
1536 |
%{ /* NOCONTEXT */ |
|
1537 |
||
329 | 1538 |
RETURN ( __isNonNilObject(anObject) ? _MKSMALLINT(__qSize(anObject)) : _MKSMALLINT(0) ) |
13 | 1539 |
%} |
1540 |
" |
|
1541 |
|hist big nw| |
|
1542 |
||
1543 |
hist := Array new:100 withAll:0. |
|
1544 |
big := 0. |
|
1545 |
ObjectMemory allObjectsDo:[:o | |
|
159 | 1546 |
nw := (ObjectMemory sizeOf:o) // 4 + 1. |
1547 |
nw > 100 ifTrue:[ |
|
1548 |
big := big + 1 |
|
1549 |
] ifFalse:[ |
|
1550 |
hist at:nw put:(hist at:nw) + 1 |
|
1551 |
]. |
|
13 | 1552 |
]. |
77 | 1553 |
hist printNL. |
1554 |
big printNL |
|
13 | 1555 |
" |
1556 |
! |
|
1557 |
||
435 | 1558 |
ageOf:anObject |
1559 |
"return the number of scavenges, an object has survived |
|
1560 |
in new space. |
|
1561 |
For old objects and living contexts, the returned number is invalid. |
|
1562 |
WARNING: this method is for ST/X debugging only |
|
1563 |
it will be removed without notice" |
|
13 | 1564 |
|
1565 |
%{ /* NOCONTEXT */ |
|
1566 |
||
329 | 1567 |
if (! __isNonNilObject(anObject)) { |
435 | 1568 |
RETURN ( 0 ); |
13 | 1569 |
} |
435 | 1570 |
RETURN ( _MKSMALLINT( _GET_AGE(anObject) ) ); |
13 | 1571 |
%} |
435 | 1572 |
" |
1573 |
|p| |
|
1574 |
p := Point new. |
|
1575 |
(ObjectMemory ageOf:p) printNL. |
|
1576 |
ObjectMemory tenuringScavenge. |
|
1577 |
(ObjectMemory spaceOf:p) printNL. |
|
1578 |
ObjectMemory tenuringScavenge. |
|
1579 |
(ObjectMemory spaceOf:p) printNL. |
|
1580 |
ObjectMemory tenuringScavenge. |
|
1581 |
(ObjectMemory spaceOf:p) printNL. |
|
1582 |
ObjectMemory tenuringScavenge. |
|
1583 |
(ObjectMemory spaceOf:p) printNL. |
|
1584 |
" |
|
159 | 1585 |
! |
1586 |
||
1587 |
flagsOf:anObject |
|
435 | 1588 |
"For debugging only. |
1589 |
WARNING: this method is for ST/X debugging only |
|
1590 |
it will be removed without notice" |
|
202 | 1591 |
|
159 | 1592 |
%{ /* NOCONTEXT */ |
1593 |
||
329 | 1594 |
if (! __isNonNilObject(anObject)) { |
159 | 1595 |
RETURN ( nil ); |
1596 |
} |
|
1597 |
RETURN ( _MKSMALLINT( anObject->o_flags ) ); |
|
1598 |
%} |
|
13 | 1599 |
" |
202 | 1600 |
F_ISREMEMBERED 1 /* a new-space thing being refd by some oldSpace thing */ |
1601 |
F_ISFORWARDED 2 /* a forwarded object (you will never see this here) */ |
|
159 | 1602 |
F_DEREFERENCED 4 /* a collection after grow (not currently used) */ |
1603 |
F_ISONLIFOLIST 8 /* a non-lifo-context-referencing-obj already on list */ |
|
1604 |
F_MARK 16 /* mark bit for background collector */ |
|
77 | 1605 |
" |
326 | 1606 |
|
1607 |
" |
|
1608 |
|arr| |
|
1609 |
||
1610 |
arr := Array new. |
|
1611 |
arr at:1 put:([thisContext] value). |
|
1612 |
(ObjectMemory flagsOf:anObject) printNL |
|
1613 |
" |
|
77 | 1614 |
! |
1615 |
||
435 | 1616 |
spaceOf:anObject |
1617 |
"return the memory space, in which anObject is. |
|
1618 |
- since objects may move between spaces, |
|
1619 |
the returned value may be invalid after the next scavenge/collect. |
|
1620 |
WARNING: this method is for ST/X debugging only |
|
1621 |
it will be removed without notice" |
|
77 | 1622 |
|
1623 |
%{ /* NOCONTEXT */ |
|
1624 |
||
329 | 1625 |
if (! __isNonNilObject(anObject)) { |
435 | 1626 |
RETURN ( nil ); |
77 | 1627 |
} |
435 | 1628 |
RETURN ( _MKSMALLINT( __qSpace(anObject) ) ); |
77 | 1629 |
%} |
1 | 1630 |
! ! |
1631 |
||
178 | 1632 |
!ObjectMemory class methodsFor:'garbage collection'! |
1 | 1633 |
|
133 | 1634 |
scavenge |
1635 |
"collect young objects, without aging (i.e. no tenure). |
|
1636 |
Can be used to quickly get rid of shortly before allocated |
|
1637 |
stuff. This is relatively fast (compared to oldspace collect). |
|
1638 |
||
1639 |
An example where a non-tenuring scavenge makes sense is when |
|
1640 |
allocating some OperatingSystem resource (a Color, File or View) |
|
1641 |
and the OS runs out of resources. In this case, the scavenge may |
|
1642 |
free some ST-objects and therefore (by signalling the WeakArrays |
|
1643 |
or Registries) free the OS resources too. |
|
1644 |
Of course, only recently allocated resources will be freed this |
|
1645 |
way. If none was freed, a full collect will be needed." |
|
1646 |
%{ |
|
326 | 1647 |
__nonTenuringScavenge(__context); |
133 | 1648 |
%} |
1649 |
||
1650 |
" |
|
1651 |
ObjectMemory scavenge |
|
1652 |
" |
|
1653 |
! |
|
1654 |
||
1655 |
tenuringScavenge |
|
1656 |
"collect newspace stuff, with aging (i.e. objects old enough |
|
1657 |
will be moved into the oldSpace). |
|
1658 |
Use this for debugging and testing only - the system performs |
|
1659 |
this automatically when the newspace fills up. |
|
1660 |
This is relatively fast (compared to oldspace collect)" |
|
1661 |
%{ |
|
326 | 1662 |
__scavenge(__context); |
133 | 1663 |
%} |
1664 |
||
1665 |
" |
|
1666 |
ObjectMemory tenuringScavenge |
|
1667 |
" |
|
1668 |
! |
|
1669 |
||
1670 |
tenure |
|
1671 |
"force all living new stuff into old-space - effectively making |
|
312 | 1672 |
all living young objects become old objects immediately. |
133 | 1673 |
This is relatively fast (compared to oldspace collect). |
1674 |
||
1675 |
This method should only be used in very special situations: |
|
1676 |
for example, when building up some long-living data structure |
|
1677 |
in a time critical application. |
|
194 | 1678 |
To do so, you have to do a scavenge followed by a tenure after the |
133 | 1679 |
objects are created. Be careful, to not reference any other chunk- |
1680 |
data when calling for a tenure (this will lead to lots of garbage in |
|
1681 |
the oldspace). |
|
1682 |
In normal situations, explicit tenures are not needed." |
|
1683 |
%{ |
|
326 | 1684 |
__tenure(__context); |
133 | 1685 |
%} |
1686 |
||
1687 |
" |
|
1688 |
ObjectMemory tenure |
|
1689 |
" |
|
194 | 1690 |
" |
1691 |
... build up long living objects ... |
|
1692 |
ObjectMemory scavenge. |
|
1693 |
ObjectMemory tenure |
|
1694 |
... continue - objects created above are now in oldSpace ... |
|
1695 |
" |
|
133 | 1696 |
! |
1697 |
||
1 | 1698 |
garbageCollect |
375 | 1699 |
"search for and free garbage in the oldSpace. |
1700 |
This can take a long time - especially, if paging is involved." |
|
1701 |
||
1702 |
"/ used to be |
|
1703 |
"/ self compressingGarbageCollect |
|
1704 |
"/ here; changed to default to markAndSweep |
|
1705 |
||
1706 |
self markAndSweep |
|
1707 |
||
1708 |
" |
|
1709 |
ObjectMemory garbageCollect |
|
1710 |
" |
|
1711 |
! |
|
1712 |
||
1713 |
compressingGarbageCollect |
|
178 | 1714 |
"search for and free garbage in the oldSpace (newSpace is cleaned automatically) |
1715 |
performing a COMPRESSING garbage collect. |
|
133 | 1716 |
This can take a long time - especially, if paging is involved |
178 | 1717 |
(when no paging is involved, its faster than I thought :-). |
202 | 1718 |
If no memory is available for the compress, or the system has been started with |
1719 |
the -Msingle option, this does a non-COMPRESSING collect." |
|
1 | 1720 |
%{ |
178 | 1721 |
if (! __garbageCollect(__context)) { |
326 | 1722 |
__markAndSweep(__context); |
178 | 1723 |
} |
1 | 1724 |
%} |
1725 |
||
93 | 1726 |
" |
375 | 1727 |
ObjectMemory compressingGarbageCollect |
93 | 1728 |
" |
1729 |
! |
|
1730 |
||
1 | 1731 |
markAndSweep |
133 | 1732 |
"mark/sweep garbage collector. |
1733 |
perform a full mark&sweep collect. |
|
369 | 1734 |
Warning: this may take some time and it is NOT interruptable. |
1735 |
If you want to do a collect from a background process, or have |
|
1736 |
other things to do, better use #incrementalGC which is interruptable." |
|
1 | 1737 |
%{ |
326 | 1738 |
__markAndSweep(__context); |
1 | 1739 |
%} |
1740 |
||
93 | 1741 |
" |
133 | 1742 |
ObjectMemory markAndSweep |
1743 |
" |
|
1 | 1744 |
! |
1745 |
||
375 | 1746 |
reclaimSymbols |
1747 |
"reclaim unused symbols; |
|
1748 |
Unused symbols are (currently) not reclaimed automatically, |
|
1749 |
but only upon request with this method. |
|
1750 |
It takes some time to do this ... and it is NOT interruptable. |
|
1751 |
Future versions may do this automatically, while garbage collecting." |
|
1752 |
%{ |
|
1753 |
__reclaimSymbols(__context); |
|
1754 |
%} |
|
1755 |
" |
|
1756 |
ObjectMemory reclaimSymbols |
|
1757 |
" |
|
1758 |
! |
|
1759 |
||
1 | 1760 |
gcStep |
77 | 1761 |
"one incremental garbage collect step. |
1762 |
Mark or sweep some small number of objects. This |
|
85 | 1763 |
method will return after a reasonable (short) time. |
133 | 1764 |
This is used by the ProcessorScheduler at idle times. |
1765 |
Returns true, if an incremental GC cycle has finished." |
|
1 | 1766 |
%{ |
133 | 1767 |
extern int __incrGCstep(); |
1768 |
||
1769 |
RETURN (__incrGCstep(__context) ? true : false); |
|
1 | 1770 |
%} |
1771 |
! |
|
1772 |
||
133 | 1773 |
incrementalGC |
1774 |
"perform one round of incremental GC steps. |
|
403 | 1775 |
The overall effect of this method is (almost) the same as calling |
1776 |
markAndSweep. However, #incrementalGC is interruptable while #markAndSweep |
|
1777 |
is atomic and blocks for a while. The code here performs incremental |
|
1778 |
GC steps, until one complete gc-cycle is completed. If running at a higher |
|
1779 |
than userBackground priority, it will give up the CPU after every such |
|
1780 |
step for a while. |
|
1781 |
Thus this method can be called either from a low prio (background) process |
|
1782 |
or from a high prio process. |
|
369 | 1783 |
(however, if you have nothing else to do, its better to call for markAndSweep, |
1784 |
since it is faster) |
|
159 | 1785 |
For example, someone allocating huge amounts of memory could |
1786 |
ask for the possibility of a quick allocation using |
|
1787 |
#checkForFastNew: and try a #incrementalGC if not. In many |
|
270 | 1788 |
cases, this can avoid a pause (in the higher prio processes) due to |
1789 |
a blocking GC." |
|
133 | 1790 |
|
403 | 1791 |
|p delay| |
1792 |
||
1793 |
Processor activeProcess priority > Processor userBackgroundPriority ifTrue:[ |
|
1794 |
delay := Delay forMilliseconds:1 |
|
1795 |
]. |
|
1796 |
||
1797 |
[self gcStep] whileFalse:[ |
|
1798 |
delay notNil ifTrue:[delay wait] |
|
1799 |
]. |
|
369 | 1800 |
self moreOldSpaceIfUseful |
133 | 1801 |
|
1802 |
" |
|
1803 |
ObjectMemory incrementalGC |
|
356 | 1804 |
[ObjectMemory incrementalGC] forkAt:3 |
403 | 1805 |
[ObjectMemory incrementalGC] forkAt:9 |
133 | 1806 |
" |
194 | 1807 |
! |
1808 |
||
270 | 1809 |
gcStepIfUseful |
1810 |
"If either the IncrementalGCLimit or the FreeSpaceGCLimits have been |
|
290 | 1811 |
reached, perform one incremental garbage collect step. |
1812 |
Return true, if more gcSteps are required to finish the cycle, |
|
1813 |
false if done with a gc round. |
|
1814 |
If no limit has been reached yet, do nothing and return false. |
|
312 | 1815 |
This is called by the ProcessorScheduler at idle times or by the |
1816 |
backgroundCollector." |
|
270 | 1817 |
|
379 | 1818 |
|done limit| |
270 | 1819 |
|
290 | 1820 |
limit := IncrementalGCLimit. |
1821 |
(limit notNil and:[self oldSpaceAllocatedSinceLastGC > limit]) ifTrue:[ |
|
369 | 1822 |
done := ObjectMemory gcStep |
1823 |
] ifFalse:[ |
|
1824 |
limit := FreeSpaceGCLimit. |
|
1825 |
(limit notNil and:[(self freeSpace + self freeListSpace) < limit]) ifTrue:[ |
|
1826 |
done := ObjectMemory gcStep. |
|
1827 |
done ifTrue:[ |
|
1828 |
self moreOldSpaceIfUseful |
|
1829 |
]. |
|
1830 |
] ifFalse:[ |
|
1831 |
done := true |
|
1832 |
] |
|
290 | 1833 |
]. |
369 | 1834 |
^ done not |
270 | 1835 |
! |
1836 |
||
194 | 1837 |
verboseGarbageCollect |
375 | 1838 |
"perform a compressing garbage collect and show some informational |
194 | 1839 |
output on the Transcript" |
1840 |
||
370 | 1841 |
|nBytesBefore nReclaimed value unit| |
194 | 1842 |
|
1843 |
nBytesBefore := self oldSpaceUsed. |
|
375 | 1844 |
self compressingGarbageCollect. |
194 | 1845 |
nReclaimed := nBytesBefore - self oldSpaceUsed. |
1846 |
nReclaimed > 0 ifTrue:[ |
|
1847 |
nReclaimed > 1024 ifTrue:[ |
|
1848 |
nReclaimed > (1024 * 1024) ifTrue:[ |
|
370 | 1849 |
value := nReclaimed // (1024 * 1024). |
1850 |
unit := ' Mb.' |
|
194 | 1851 |
] ifFalse:[ |
370 | 1852 |
value := nReclaimed // 1024. |
1853 |
unit := ' Kb.' |
|
194 | 1854 |
] |
1855 |
] ifFalse:[ |
|
370 | 1856 |
value := nReclaimed. |
1857 |
unit := ' bytes.' |
|
1858 |
]. |
|
1859 |
Transcript show:'reclaimed '; show:value printString. |
|
1860 |
Transcript showCr:unit |
|
194 | 1861 |
] |
1862 |
||
1863 |
" |
|
1864 |
ObjectMemory verboseGarbageCollect |
|
1865 |
" |
|
207 | 1866 |
! |
1867 |
||
1868 |
startBackgroundCollectorAt:aPriority |
|
1869 |
"start a process doing incremental GC in the background. |
|
1870 |
Use this, if you have suspendable background processes which |
|
1871 |
run all the time, and therefore would prevent the idle-collector |
|
1872 |
from running. See documentation in this class for more details." |
|
1873 |
||
290 | 1874 |
|p| |
1875 |
||
270 | 1876 |
"/ |
1877 |
"/ its not useful, to run it more than once |
|
1878 |
"/ |
|
207 | 1879 |
BackgroundCollectProcess notNil ifTrue:[ |
1880 |
BackgroundCollectProcess priority:aPriority. |
|
1881 |
^ self |
|
1882 |
]. |
|
270 | 1883 |
|
290 | 1884 |
p := |
207 | 1885 |
[ |
290 | 1886 |
[ |
1887 |
[true] whileTrue:[ |
|
1888 |
self gcStepIfUseful ifTrue:[ |
|
1889 |
" |
|
1890 |
perform a full cycle |
|
1891 |
" |
|
1892 |
self incrementalGC |
|
1893 |
]. |
|
270 | 1894 |
" |
290 | 1895 |
wait a bit |
1896 |
" |
|
1897 |
(Delay forSeconds:5) wait |
|
1898 |
] |
|
1899 |
] valueOnUnwindDo:[ |
|
1900 |
BackgroundCollectProcess := nil |
|
211 | 1901 |
] |
207 | 1902 |
] newProcess. |
290 | 1903 |
p name:'background collector'. |
1904 |
p priority:aPriority. |
|
339 | 1905 |
p restartable:true. |
290 | 1906 |
p resume. |
1907 |
BackgroundCollectProcess := p |
|
211 | 1908 |
|
1909 |
" |
|
293 | 1910 |
the following lets the backgroundCollector run at prio 5 |
1911 |
whenever 100000 bytes have been allocated, OR freeSpace drops |
|
1912 |
below 1meg. Having the system keep 1meg as reserve for peak allocation. |
|
1913 |
||
1914 |
Doing this may reduce pauses due to inevitable collects when running |
|
1915 |
out of freeSpace, if the collector can keep up with allocation rate. |
|
1916 |
" |
|
1917 |
||
1918 |
" |
|
1919 |
ObjectMemory incrementalGCLimit:100000. |
|
1920 |
ObjectMemory freeSpaceGCLimit:1000000. |
|
211 | 1921 |
ObjectMemory startBackgroundCollectorAt:5 |
1922 |
" |
|
207 | 1923 |
! |
1924 |
||
1925 |
stopBackgroundCollector |
|
1926 |
"stop the background collector" |
|
1927 |
||
1928 |
BackgroundCollectProcess notNil ifTrue:[ |
|
1929 |
BackgroundCollectProcess terminate. |
|
1930 |
BackgroundCollectProcess := nil |
|
1931 |
] |
|
293 | 1932 |
|
211 | 1933 |
" |
1934 |
ObjectMemory stopBackgroundCollector |
|
1935 |
" |
|
362 | 1936 |
! |
1937 |
||
1938 |
backgroundCollectorRunning |
|
1939 |
"return true, if a backgroundCollector is running" |
|
1940 |
||
1941 |
^ BackgroundCollectProcess notNil |
|
1942 |
||
1943 |
" |
|
1944 |
ObjectMemory backgroundCollectorRunning |
|
1945 |
" |
|
178 | 1946 |
! ! |
1947 |
||
1948 |
!ObjectMemory class methodsFor:'garbage collector control'! |
|
133 | 1949 |
|
270 | 1950 |
freeSpaceGCLimit:aNumber |
1951 |
"set the freeSpace limit for incremental GC activation. |
|
1952 |
The system will start doing incremental background GC, once less than this number |
|
310 | 1953 |
of bytes are available for allocation. |
1954 |
The default is nil; setting it to nil will turn this trigger off." |
|
270 | 1955 |
|
1956 |
FreeSpaceGCLimit := aNumber |
|
1957 |
||
1958 |
" |
|
310 | 1959 |
the following will start the incrementalGC (in the background) |
1960 |
whenever the freeSpace drops below 1meg of free space |
|
290 | 1961 |
" |
1962 |
" |
|
1963 |
ObjectMemory freeSpaceGCLimit:1000000. |
|
1964 |
" |
|
1965 |
||
1966 |
" |
|
293 | 1967 |
turn it off (i.e. let the system hit the wall ...) |
290 | 1968 |
" |
1969 |
" |
|
270 | 1970 |
ObjectMemory freeSpaceGCLimit:nil. |
1971 |
" |
|
1972 |
! |
|
1973 |
||
310 | 1974 |
freeSpaceGCAmount:aNumber |
1975 |
"set the amount to be allocated if, after an incrementalGC, |
|
1976 |
not at least FreeSpaceGCLimit bytes are available for allocation. |
|
1977 |
The amount should be greater than the limit, otherwise the incremental |
|
1978 |
GC may try over and over to get the memory (actually waisting time)." |
|
1979 |
||
1980 |
FreeSpaceGCAmount := aNumber |
|
1981 |
||
1982 |
" |
|
1983 |
the following will try to always keep at least 1meg of free space |
|
1984 |
(in the background) and start to do so, whenever the freeSpace drops |
|
1985 |
below 250k. |
|
1986 |
" |
|
1987 |
" |
|
1988 |
ObjectMemory freeSpaceGCLimit:250000. |
|
1989 |
ObjectMemory freeSpaceGCAmount:1000000. |
|
1990 |
" |
|
1991 |
||
1992 |
" |
|
1993 |
turn it off (i.e. let the system compute an appropriate amount ...) |
|
1994 |
" |
|
1995 |
" |
|
1996 |
ObjectMemory freeSpaceGCAmount:nil. |
|
1997 |
" |
|
1998 |
! |
|
1999 |
||
270 | 2000 |
freeSpaceGCLimit |
2001 |
"return the freeSpace limit for incremental GC activation. |
|
2002 |
The system will start doing incremental background GC, once less than this number |
|
2003 |
of bytes are available in the compact free space. |
|
2004 |
The default is 100000; setting it to nil will turn this trigger off." |
|
2005 |
||
2006 |
^ FreeSpaceGCLimit |
|
2007 |
||
2008 |
" |
|
2009 |
ObjectMemory freeSpaceGCLimit |
|
2010 |
" |
|
2011 |
! |
|
2012 |
||
310 | 2013 |
freeSpaceGCAmount |
2014 |
"return the amount to be allocated if, after an incrementalGC, |
|
2015 |
not at least FreeSpaceGCLimit bytes are available for allocation. |
|
2016 |
The default is nil, which lets the system compute an abbpropriate value" |
|
2017 |
||
2018 |
^ FreeSpaceGCAmount |
|
2019 |
||
2020 |
" |
|
2021 |
ObjectMemory freeSpaceGCAmount |
|
2022 |
" |
|
2023 |
! |
|
2024 |
||
2 | 2025 |
incrementalGCLimit:aNumber |
270 | 2026 |
"set the allocatedSinceLastGC limit for incremental GC activation. |
2027 |
The system will start doing incremental background GC, once more than this number |
|
2028 |
of bytes have been allocated since the last GC. |
|
2029 |
The default is 500000; setting it to nil will turn this trigger off." |
|
2 | 2030 |
|
2031 |
IncrementalGCLimit := aNumber |
|
2032 |
||
85 | 2033 |
" |
213 | 2034 |
ObjectMemory incrementalGCLimit:500000. 'do incr. GC very seldom' |
2035 |
ObjectMemory incrementalGCLimit:100000. 'medium' |
|
2036 |
ObjectMemory incrementalGCLimit:10000. 'do incr. GC very often' |
|
2037 |
ObjectMemory incrementalGCLimit:nil. 'never' |
|
85 | 2038 |
" |
2 | 2039 |
! |
2040 |
||
13 | 2041 |
incrementalGCLimit |
270 | 2042 |
"return the allocatedSinceLastGC limit for incremental GC activation. |
2043 |
The system will start doing incremental background GC, once more than this number |
|
2044 |
of bytes have been allocated since the last GC. |
|
2045 |
The default is 500000; setting it to nil will turn this trigger off." |
|
13 | 2046 |
|
2047 |
^ IncrementalGCLimit |
|
2048 |
||
85 | 2049 |
" |
2050 |
ObjectMemory incrementalGCLimit |
|
2051 |
" |
|
13 | 2052 |
! |
2053 |
||
369 | 2054 |
moreOldSpaceIfUseful |
2055 |
"to be called after an incremental GC cycle; |
|
2056 |
if freeSpace is still below limit, allocate more oldSpace" |
|
2057 |
||
2058 |
|limit free amount| |
|
2059 |
||
2060 |
limit := FreeSpaceGCLimit. |
|
2061 |
limit notNil ifTrue:[ |
|
2062 |
"/ if reclaimed space is below limit, we have to allocate more |
|
2063 |
"/ oldSpace, to avoid excessive gcSteps (due to freeSpaceLimit |
|
2064 |
"/ still not reached) |
|
2065 |
"/ |
|
2066 |
free := self freeSpace + self freeListSpace. |
|
2067 |
free < (limit * 3 // 2) ifTrue:[ |
|
2068 |
amount := FreeSpaceGCAmount. |
|
2069 |
amount isNil ifTrue:[ |
|
2070 |
amount := limit * 3 // 2. |
|
2071 |
]. |
|
2072 |
'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
|
2073 |
(self moreOldSpace:(amount - free + (64*1024))) ifFalse:[ |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2074 |
"/ |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2075 |
"/ 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
|
2076 |
"/ useless retries |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2077 |
'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
|
2078 |
FreeSpaceGCLimit := nil |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2079 |
] |
369 | 2080 |
]. |
2081 |
]. |
|
2082 |
! |
|
2083 |
||
133 | 2084 |
moreOldSpace:howMuch |
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2085 |
"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
|
2086 |
false if that failed. |
133 | 2087 |
This is done automatically, when running out of space, but makes |
2088 |
sense, if its known in advance that a lot of memory is needed to |
|
2089 |
avoid multiple reallocations and compresses. |
|
310 | 2090 |
On systems which do not support the mmap (or equivalent) system call, |
2091 |
this (currently) implies a compressing garbage collect - so its slow. |
|
133 | 2092 |
Notice: this is a nonstandard interface - use only in special situations." |
2093 |
||
2094 |
%{ |
|
458
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2095 |
if (__isSmallInteger(howMuch)) { |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2096 |
RETURN( __moreOldSpace(__context, _intVal(howMuch)) ? true : false ); |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2097 |
} |
ef1a25054341
avoid looping in IGC if moreOldSpace fails
Claus Gittinger <cg@exept.de>
parents:
443
diff
changeset
|
2098 |
RETURN (false); |
133 | 2099 |
%} |
2100 |
" |
|
2101 |
ObjectMemory moreOldSpace:1000000 |
|
2102 |
" |
|
2103 |
! |
|
2104 |
||
202 | 2105 |
announceSpaceNeed:howMuch |
2106 |
"announce to the memory system, that howMuch bytes of memory will be needed |
|
2107 |
soon. The VM tries to prepare itself for this allocation to be performed |
|
2108 |
with less overhead. For example, it could preallocate some memory in one |
|
2109 |
big chunk (instead of doing many smaller reallocations later). |
|
2110 |
Notice: this is a nonstandard interface - use only in special situations. |
|
2111 |
Also, this does a background collect before the big chunk of memory is |
|
2112 |
allocated, not locking other processes while doing so." |
|
2113 |
||
2114 |
(howMuch < (self newSpaceSize // 2)) ifTrue:[ |
|
2115 |
self scavenge. |
|
2116 |
]. |
|
2117 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2118 |
(howMuch > (self newSpaceSize // 2)) ifFalse:[ |
|
2119 |
self scavenge. |
|
2120 |
]. |
|
2121 |
self incrementalGC. |
|
2122 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2123 |
self moreOldSpace:howMuch |
|
2124 |
] |
|
2125 |
] |
|
2126 |
||
2127 |
" |
|
2128 |
ObjectMemory announceSpaceNeed:100000 |
|
2129 |
" |
|
2130 |
! |
|
2131 |
||
133 | 2132 |
announceOldSpaceNeed:howMuch |
202 | 2133 |
"announce to the memory system, that howMuch bytes of memory will be needed |
2134 |
soon, which is going to live longer (whatever that means). |
|
2135 |
It first checks if the memory can be allocated without forcing a compressing |
|
2136 |
GC. If not, the oldSpace is increased. This may also lead to a slow compressing |
|
133 | 2137 |
collect. However, many smaller increases are avoided afterwards. Calling this |
2138 |
method before allocating huge chunks of data may provide better overall performance. |
|
2139 |
Notice: this is a nonstandard interface - use only in special situations." |
|
2140 |
||
2141 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
159 | 2142 |
self incrementalGC. |
2143 |
(self checkForFastNew:howMuch) ifFalse:[ |
|
2144 |
self moreOldSpace:howMuch |
|
2145 |
] |
|
133 | 2146 |
] |
2147 |
||
2148 |
" |
|
2149 |
ObjectMemory announceOldSpaceNeed:1000000 |
|
2150 |
" |
|
2151 |
! |
|
2152 |
||
2153 |
oldSpaceIncrement |
|
2154 |
"return the oldSpaceIncrement value. Thats the amount by which |
|
2155 |
more memory is allocated in case the oldSpace gets filled up. |
|
2156 |
In normal situations, the default value used in the VM is fine |
|
2157 |
and there is no need to change it." |
|
178 | 2158 |
|
2159 |
%{ /* NOCONTEXT */ |
|
133 | 2160 |
extern unsigned __oldSpaceIncrement(); |
2161 |
||
2162 |
RETURN (_MKSMALLINT( __oldSpaceIncrement(-1) )); |
|
2163 |
%} |
|
178 | 2164 |
" |
2165 |
ObjectMemory oldSpaceIncrement |
|
2166 |
" |
|
133 | 2167 |
! |
2168 |
||
2169 |
oldSpaceIncrement:amount |
|
2170 |
"set the oldSpaceIncrement value. Thats the amount by which |
|
2171 |
more memory is allocated in case the oldSpace gets filled up. |
|
2172 |
In normal situations, the default value used in the VM is fine |
|
2173 |
and there is no need to change it. This method returns the |
|
2174 |
previous increment value." |
|
178 | 2175 |
|
2176 |
%{ /* NOCONTEXT */ |
|
133 | 2177 |
extern unsigned __oldSpaceIncrement(); |
2178 |
||
253 | 2179 |
if (__isSmallInteger(amount)) { |
159 | 2180 |
RETURN (_MKSMALLINT( __oldSpaceIncrement(_intVal(amount)) )); |
133 | 2181 |
} |
2182 |
%} |
|
178 | 2183 |
"to change increment to 1Meg:" |
2184 |
" |
|
2185 |
ObjectMemory oldSpaceIncrement:1024*1024 |
|
2186 |
" |
|
2187 |
! |
|
2188 |
||
329 | 2189 |
oldSpaceCompressLimit:amount |
2190 |
"set the limit for oldSpace compression. If more memory than this |
|
2191 |
limit is in use, the system will not perform compresses on the oldspace, |
|
2192 |
but instead do a mark&sweep GC followed by an oldSpace increase if not enough |
|
2193 |
could be reclaimed. The default is currently some 8Mb, which is ok for workstations |
|
2194 |
with 16..32Mb of physical memory. If your system has much more physical RAM, |
|
2195 |
you may want to increase this limit. |
|
2196 |
This method returns the previous increment value." |
|
2197 |
||
2198 |
%{ /* NOCONTEXT */ |
|
2199 |
extern unsigned __compressingGCLimit(); |
|
2200 |
||
2201 |
if (__isSmallInteger(amount)) { |
|
2202 |
RETURN (_MKSMALLINT( __compressingGCLimit(_intVal(amount)) )); |
|
2203 |
} |
|
2204 |
%} |
|
2205 |
"to change the limit to 12Mb:" |
|
2206 |
" |
|
2207 |
ObjectMemory oldSpaceCompressLimit:12*1024*1024 |
|
2208 |
" |
|
2209 |
! |
|
2210 |
||
178 | 2211 |
fastMoreOldSpaceAllocation:aBoolean |
2212 |
"this method turns on/off fastMoreOldSpace allocation. |
|
2213 |
By default, this is turned off (false), which means that in case of |
|
202 | 2214 |
a filled-up oldSpace, a GC is tried first before more oldSpace is allocated. |
178 | 2215 |
This strategy is ok for the normal operation of the system, |
2216 |
but behaves badly, if the program allocates huge data structures (say a |
|
202 | 2217 |
game tree of 30Mb in size) which survives and therefore will not be reclaimed |
178 | 2218 |
by a GC. |
202 | 2219 |
Of course while building this tree, and the memory becomes full, the system |
2220 |
would not know in advance, that the GC will not reclaim anything. |
|
2221 |
||
178 | 2222 |
Setting fastOldSpaceIncrement to true will avoid this, by forcing the |
2223 |
memory system to allocate more memory right away, without doing a GC first. |
|
2224 |
||
2225 |
WARNING: make certain that this flag is turned off, after your huge data |
|
2226 |
is allocated, since otherwise the system may continue to increase its |
|
202 | 2227 |
virtual memory without ever checking for garbage. |
310 | 2228 |
This method returns the previous value of the flag; typically this return |
2229 |
value should be used to switch back." |
|
178 | 2230 |
|
2231 |
%{ /* NOCONTEXT */ |
|
370 | 2232 |
extern int __fastMoreOldSpaceAllocation(); |
2233 |
||
178 | 2234 |
RETURN (__fastMoreOldSpaceAllocation(aBoolean == true ? 1 : 0) ? true : false); |
2235 |
%} |
|
310 | 2236 |
" |
2237 |
|previousSetting| |
|
2238 |
||
2239 |
previousSetting := ObjectMemory fastMoreOldSpaceAllocation:true. |
|
2240 |
[ |
|
2241 |
... |
|
2242 |
allocate your huge data |
|
2243 |
... |
|
2244 |
] valueNoOrOnUnwindDo:[ |
|
2245 |
ObjectMemory fastMoreOldSpaceAllocation:previousSetting |
|
2246 |
] |
|
2247 |
" |
|
370 | 2248 |
|
2249 |
" |
|
2250 |
|prev this| |
|
2251 |
||
2252 |
prev := ObjectMemory fastMoreOldSpaceAllocation:true. |
|
2253 |
ObjectMemory fastMoreOldSpaceAllocation:prev. |
|
2254 |
^ prev |
|
2255 |
" |
|
2256 |
! |
|
2257 |
||
2258 |
fastMoreOldSpaceLimit:aNumber |
|
2259 |
"this method sets and returns the fastMoreOldSpace limit. |
|
2260 |
If fastMoreOldSpaceAllocation is true, and the current oldSpace size is |
|
2261 |
below this limit, the memory manager will NOT do a GC when running out of |
|
2262 |
oldSpace, but instead quickly go ahead increasing the size of the oldSpace. |
|
2263 |
Setting the limit to 0 turns off any limit (i.e. it will continue to |
|
2264 |
increase the oldSpace forwever - actually, until the OS refuses to give us |
|
2265 |
more memory). The returned value is the previous setting of the limit." |
|
2266 |
||
2267 |
%{ /* NOCONTEXT */ |
|
2268 |
extern int __fastMoreOldSpaceLimit(); |
|
2269 |
||
2270 |
if (__isSmallInteger(aNumber)) { |
|
2271 |
RETURN ( __MKSMALLINT( __fastMoreOldSpaceLimit(__intVal(aNumber)))); |
|
2272 |
} |
|
2273 |
%}. |
|
2274 |
self primitiveFailed |
|
2275 |
||
2276 |
" |
|
2277 |
|prev this| |
|
2278 |
||
2279 |
prev := ObjectMemory fastMoreOldSpaceLimit:10*1024*1024. |
|
2280 |
ObjectMemory fastMoreOldSpaceLimit:prev. |
|
2281 |
^ prev |
|
2282 |
" |
|
133 | 2283 |
! |
2284 |
||
2285 |
checkForFastNew:amount |
|
2286 |
"this method returns true, if amount bytes could be allocated |
|
2287 |
quickly (i.e. without forcing a full GC or compress). |
|
2288 |
This can be used for smart background processes, which want to |
|
2289 |
allocate big chunks of data without disturbing foreground processes |
|
2290 |
too much. Such a process would check for fast-allocation, and perform |
|
202 | 2291 |
incremental GC-steps if required. Thus, avoiding the long blocking pause |
310 | 2292 |
due to a forced (non-incremental) GC. |
2293 |
Especially: doing so will not block higher priority foreground processes. |
|
2294 |
See an example use in Behavior>>niceBasicNew:. |
|
133 | 2295 |
This is experimental and not guaranteed to be in future versions." |
2296 |
||
178 | 2297 |
%{ /* NOCONTEXT */ |
370 | 2298 |
extern int __checkForFastNew(); |
133 | 2299 |
|
253 | 2300 |
if (__isSmallInteger(amount)) { |
159 | 2301 |
if (! __checkForFastNew(_intVal(amount))) { |
2302 |
RETURN (false); |
|
2303 |
} |
|
133 | 2304 |
} |
2305 |
||
2306 |
%}. |
|
2307 |
^ true |
|
2308 |
! |
|
2309 |
||
2 | 2310 |
turnGarbageCollectorOff |
310 | 2311 |
"turn off the generational garbage collector by forcing new objects to be |
2312 |
allocated directly in oldSpace (instead of newSpace) |
|
178 | 2313 |
WARNING: |
93 | 2314 |
This is somewhat dangerous: if collector is turned off, |
77 | 2315 |
and too many objects are created, the system may run into trouble |
2316 |
(i.e. oldSpace becomes full) and be forced to perform a full mark&sweep |
|
202 | 2317 |
or even a compressing collect - making the overall realtime behavior worse. |
93 | 2318 |
Use this only for special purposes or when realtime behavior |
403 | 2319 |
is required for a limited time period. |
2320 |
||
2321 |
OBSOLETE: this is no longer supported |
|
2322 |
- it may be a no-operation by the time you read this." |
|
178 | 2323 |
|
2324 |
%{ /* NOCONTEXT */ |
|
133 | 2325 |
__allocForceSpace(OLDSPACE); |
1 | 2326 |
%} |
2327 |
! |
|
2328 |
||
2 | 2329 |
turnGarbageCollectorOn |
202 | 2330 |
"turn garbage collector on again (see ObjectMemory>>turnGarbageCollectorOff)" |
1 | 2331 |
|
178 | 2332 |
%{ /* NOCONTEXT */ |
133 | 2333 |
__allocForceSpace(9999); |
1 | 2334 |
%} |
178 | 2335 |
! |
85 | 2336 |
|
2337 |
makeOld:anObject |
|
93 | 2338 |
"move anObject into oldSpace. |
133 | 2339 |
This method is for internal & debugging purposes only - |
2340 |
it may vanish. Dont use it." |
|
85 | 2341 |
%{ |
2342 |
if (__moveToOldSpace(anObject, __context) < 0) { |
|
159 | 2343 |
RETURN (false); |
93 | 2344 |
} |
2345 |
%}. |
|
2346 |
^ true |
|
194 | 2347 |
! |
2348 |
||
2349 |
tenureParameters:magic |
|
2350 |
"this is pure magic and not for public eyes ... |
|
202 | 2351 |
This method allows fine tuning the scavenger internals, |
194 | 2352 |
in cooperation to some statistic & test programs. |
202 | 2353 |
It is undocumented, secret and may vanish. |
2354 |
If you play around here, the system may behave very strange." |
|
194 | 2355 |
|
2356 |
%{ /* NOCONTEXT */ |
|
2357 |
__tenureParams(magic); |
|
2358 |
%}. |
|
370 | 2359 |
! |
2360 |
||
379 | 2361 |
lockTenure:flag |
370 | 2362 |
"set/clear the tenureLock. If the lock is set, the system |
2363 |
completely turns off tenuring, and objects remain in newSpace (forever). |
|
379 | 2364 |
Once this lock is set, the system operates only in the newSpace and no memory |
2365 |
allocations from oldSpace are allowed (except for explicit tenure calls). |
|
370 | 2366 |
If any allocation request cannot be resoved, the VM raises a memory interrupt, |
379 | 2367 |
clears the lockTenure-flag and returns nil. Thus, it automatically falls back into |
2368 |
the normal mode of operation, to avoid big trouble |
|
2369 |
(fail to allocate memory when handling the exception). |
|
370 | 2370 |
|
2371 |
This interface can be used in applications, which are guaranteed to have their |
|
2372 |
working set completely in the newSpace AND want to limit the worst case |
|
379 | 2373 |
pause times to the worst case scavenge time |
2374 |
(which itself is limitd by the size of the newSpace). |
|
370 | 2375 |
I.e. systems which go into some event loop after initial startup, |
2376 |
may turn on the tenureLock to make certain that no oldSpace memory is |
|
379 | 2377 |
allocated in the future; thereby limiting any GC activity to newSpace scavenges only. |
2378 |
||
2379 |
This is an EXPERIMENTAL interface. |
|
2380 |
" |
|
370 | 2381 |
|
2382 |
%{ |
|
379 | 2383 |
if (flag == true) { |
370 | 2384 |
__tenure(__context); |
2385 |
} |
|
379 | 2386 |
__lockTenure(flag == true ? 1 : 0); |
2387 |
%} |
|
2388 |
! |
|
2389 |
||
2390 |
avoidTenure:flag |
|
2391 |
"set/clear the avoidTenure flag. If set, aging of newSpace is turned off |
|
2392 |
as long as the newSpace fill-grade stays below some magic high-water mark. |
|
2393 |
If off (the default), aging is done as usual. |
|
2394 |
If the flag is turned on, scavenge may be a bit slower, due to more |
|
2395 |
objects being copied around. However, chances are high that in an idle |
|
2396 |
or (almost idle) system, less objects are moved into oldSpace. |
|
2397 |
Therefore, this helps to avoid oldSpace colelcts, in systems which go into |
|
2398 |
some standby mode and are reactivated by some external event. |
|
2399 |
(the avoid-flag should be turned off there, and set again once the idle loop |
|
2400 |
is reentered). |
|
2401 |
||
2402 |
This is an EXPERIMENTAL interface." |
|
2403 |
||
2404 |
%{ /* NOCONTEXT */ |
|
2405 |
__avoidTenure(flag == true ? 1 : 0); |
|
2406 |
%} |
|
2407 |
! |
|
2408 |
||
2409 |
watchTenure:flag |
|
2410 |
"set/clear the tenureWatch. If set, an internalError exception will be raised, |
|
2411 |
whenever objects are tenured from newSpace into oldSpace |
|
2412 |
(except for an explicit tenure request). |
|
2413 |
This can be used to validate that no oldSpace objects are created |
|
2414 |
(i.e. the system operates fully in newSpace). |
|
2415 |
Be careful, if the avoidTenure flag is not set, |
|
2416 |
there will almost always be a tenure sooner or later. |
|
2417 |
||
2418 |
EXPERIMENTAL - no warranty" |
|
2419 |
||
2420 |
%{ /* NOCONTEXT */ |
|
2421 |
__watchTenure(flag == true ? 1 : 0); |
|
370 | 2422 |
%} |
2423 |
! |
|
2424 |
||
2425 |
newSpaceSize:newSize |
|
2426 |
"change the size of the newSpace. To do this, the current contents |
|
2427 |
of the newSpace may have to be tenured (if size is smaller). |
|
2428 |
Returns false, if it failed for any reason. |
|
2429 |
Experimental: this interface may valish without notice. |
|
2430 |
||
2431 |
DANGER ALERT: |
|
2432 |
be careful too big of a size may lead to longer scavenge pauses. |
|
2433 |
Too small of a newSpace may lead to more CPU overhead, due to |
|
2434 |
excessive scavenges. You have been warned." |
|
2435 |
||
2436 |
%{ |
|
2437 |
extern int __setNewSpaceSize(); |
|
2438 |
||
2439 |
if (__isSmallInteger(newSize)) { |
|
2440 |
RETURN (__setNewSpaceSize(__intVal(newSize)) ? true : false); |
|
2441 |
} |
|
2442 |
%}. |
|
2443 |
self primitiveFailed |
|
2444 |
||
2445 |
" less absolute CPU overhead (but longer pauses): |
|
2446 |
||
2447 |
ObjectMemory newSpaceSize:800*1024 |
|
2448 |
" |
|
2449 |
||
2450 |
" smaller pauses, but more overall CPU overhead: |
|
2451 |
||
2452 |
ObjectMemory newSpaceSize:200*1024 |
|
2453 |
" |
|
2454 |
||
2455 |
" the default: |
|
2456 |
||
2457 |
ObjectMemory newSpaceSize:400*1024 |
|
2458 |
" |
|
178 | 2459 |
! ! |
2460 |
||
362 | 2461 |
!ObjectMemory class ignoredMethodsFor:'object finalization'! |
290 | 2462 |
|
2463 |
allShadowObjectsDo:aBlock |
|
2464 |
"evaluate the argument, aBlock for all known shadow objects" |
|
2465 |
%{ |
|
326 | 2466 |
__allShadowObjectsDo(&aBlock COMMA_CON); |
290 | 2467 |
%} |
362 | 2468 |
! ! |
2469 |
||
2470 |
!ObjectMemory class methodsFor:'object finalization'! |
|
290 | 2471 |
|
2472 |
allChangedShadowObjectsDo:aBlock |
|
2473 |
"evaluate the argument, aBlock for all known shadow objects which have |
|
2474 |
lost a pointer recently." |
|
2475 |
%{ |
|
326 | 2476 |
__allChangedShadowObjectsDo(&aBlock COMMA_CON); |
290 | 2477 |
%} |
2478 |
! |
|
2479 |
||
291 | 2480 |
finalize |
2481 |
"tell all weak objects that something happened." |
|
2482 |
||
2483 |
self allChangedShadowObjectsDo:[:aShadowArray | |
|
2484 |
aShadowArray lostPointer. |
|
2485 |
] |
|
2486 |
! |
|
2487 |
||
290 | 2488 |
disposeInterrupt |
2489 |
"this is triggered by the garbage collector, |
|
2490 |
whenever any shadowArray looses a pointer." |
|
2491 |
||
2492 |
FinalizationSemaphore notNil ifTrue:[ |
|
2493 |
"/ |
|
2494 |
"/ background finalizer is waiting ... |
|
2495 |
"/ |
|
2496 |
FinalizationSemaphore signal |
|
2497 |
] ifFalse:[ |
|
2498 |
"/ |
|
2499 |
"/ do it right here |
|
2500 |
"/ |
|
291 | 2501 |
self finalize |
290 | 2502 |
] |
2503 |
! |
|
2504 |
||
2505 |
startBackgroundFinalizationAt:aPriority |
|
2506 |
"start a process doing finalization work in the background. |
|
2507 |
Can be used to reduce the pauses created by finalization. |
|
2508 |
Normally, these pauses are not noticed; however if you have (say) |
|
2509 |
ten thousands of weak objects, these could become long enough to |
|
2510 |
make background finalization usefull. |
|
2511 |
WARNING: background finalization may lead to much delayed freeing of |
|
2512 |
system resources. Especially, you may temporarily run out of free |
|
2513 |
color table entries or fileDescriptors etc. Use at your own risk (if at all)" |
|
2514 |
||
2515 |
|p| |
|
2516 |
||
2517 |
"/ |
|
2518 |
"/ its not useful, to run it more than once |
|
2519 |
"/ |
|
2520 |
BackgroundFinalizationProcess notNil ifTrue:[ |
|
2521 |
BackgroundFinalizationProcess priority:aPriority. |
|
2522 |
^ self |
|
2523 |
]. |
|
2524 |
||
2525 |
FinalizationSemaphore := Semaphore new. |
|
2526 |
||
2527 |
p := |
|
2528 |
[ |
|
2529 |
[ |
|
2530 |
[true] whileTrue:[ |
|
2531 |
" |
|
2532 |
wait till something to do ... |
|
2533 |
" |
|
2534 |
FinalizationSemaphore wait. |
|
2535 |
" |
|
2536 |
... and do it |
|
2537 |
" |
|
291 | 2538 |
self finalize |
290 | 2539 |
] |
2540 |
] valueOnUnwindDo:[ |
|
2541 |
BackgroundFinalizationProcess := nil. |
|
2542 |
FinalizationSemaphore := nil |
|
2543 |
] |
|
2544 |
] newProcess. |
|
2545 |
p name:'background finalizer'. |
|
2546 |
p priority:aPriority. |
|
339 | 2547 |
p restartable:true. |
290 | 2548 |
p resume. |
2549 |
BackgroundFinalizationProcess := p |
|
2550 |
||
2551 |
" |
|
2552 |
ObjectMemory startBackgroundFinalizationAt:5 |
|
2553 |
" |
|
2554 |
! |
|
2555 |
||
2556 |
stopBackgroundFinalization |
|
2557 |
"stop the background finalizer" |
|
2558 |
||
2559 |
BackgroundFinalizationProcess notNil ifTrue:[ |
|
2560 |
BackgroundFinalizationProcess terminate. |
|
2561 |
BackgroundFinalizationProcess := nil |
|
2562 |
]. |
|
2563 |
||
2564 |
" |
|
2565 |
ObjectMemory stopBackgroundFinalization |
|
2566 |
" |
|
2567 |
! ! |
|
2568 |
||
178 | 2569 |
!ObjectMemory class methodsFor:'physical memory access'! |
93 | 2570 |
|
2571 |
newSpacePagesDo:aBlock |
|
2572 |
"evaluates aBlock for all pages in the newSpace, passing |
|
2573 |
the pages address as argument. |
|
2574 |
For internal & debugging use only." |
|
2575 |
%{ |
|
2576 |
if (__newSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2577 |
RETURN (false); |
85 | 2578 |
} |
2579 |
%}. |
|
2580 |
^ true |
|
2581 |
! |
|
2582 |
||
2583 |
oldSpacePagesDo:aBlock |
|
2584 |
"evaluates aBlock for all pages in the oldSpace, passing |
|
2585 |
the pages address as argument. |
|
93 | 2586 |
For internal & debugging use only." |
85 | 2587 |
%{ |
2588 |
if (__oldSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2589 |
RETURN (false); |
85 | 2590 |
} |
2591 |
%}. |
|
2592 |
^ true |
|
2593 |
! |
|
2594 |
||
93 | 2595 |
collectedOldSpacePagesDo:aBlock |
2596 |
"evaluates aBlock for all pages in the prev. oldSpace, passing |
|
2597 |
the pages address as argument. |
|
2598 |
For internal & debugging use only." |
|
2599 |
%{ |
|
2600 |
if (__collectedOldSpacePagesDo(&aBlock COMMA_CON) < 0) { |
|
159 | 2601 |
RETURN (false); |
93 | 2602 |
} |
2603 |
%}. |
|
2604 |
^ true |
|
2605 |
! |
|
2606 |
||
85 | 2607 |
pageIsInCore:aPageNumber |
2608 |
"return true, if the page (as enumerated via oldSpacePagesDo:) |
|
2609 |
is in memory; false, if currently paged out. For internal |
|
93 | 2610 |
use / monitors only; may vanish. |
2611 |
NOTICE: not all systems provide this information; on those that |
|
2612 |
do not, true is returned for all pages." |
|
85 | 2613 |
%{ |
2614 |
#ifdef HAS_MINCORE |
|
2615 |
int pageSize = getpagesize(); |
|
2616 |
char result[10]; |
|
2617 |
INT addr; |
|
2618 |
||
253 | 2619 |
if (__isSmallInteger(aPageNumber)) { |
159 | 2620 |
addr = _intVal(aPageNumber) & ~(pageSize - 1); |
85 | 2621 |
} else { |
159 | 2622 |
addr = ((INT)aPageNumber) & ~(pageSize - 1); |
85 | 2623 |
} |
2624 |
if (mincore(addr, pageSize-1, result) < 0) { |
|
159 | 2625 |
RETURN (true); |
85 | 2626 |
} |
2627 |
RETURN ((result[0] & 1) ? true : false); |
|
2628 |
#endif |
|
2629 |
%}. |
|
2630 |
"OS does not supply this info - assume yes" |
|
2631 |
^ true |
|
2632 |
! ! |
|
2633 |
||
379 | 2634 |
!ObjectMemory class methodsFor:'statistics'! |
2635 |
||
2636 |
ageStatistic |
|
2637 |
%{ /* NOCONTEXT */ |
|
2638 |
||
2639 |
__ageStatistics(); |
|
2640 |
%} |
|
2641 |
! ! |
|
2642 |
||
13 | 2643 |
!ObjectMemory class methodsFor:'low memory handling'! |
2644 |
||
2645 |
memoryInterrupt |
|
2646 |
"when a low-memory condition arises, ask all classes to |
|
290 | 2647 |
remove possibly cached data. You may help the system a bit, |
2648 |
in providing a lowSpaceCleanup method in your classes which have |
|
2649 |
lots of data kept somewhere (usually, cached data). |
|
2650 |
- this may or may not help." |
|
13 | 2651 |
|
308 | 2652 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 2653 |
aClass lowSpaceCleanup |
13 | 2654 |
]. |
2655 |
||
178 | 2656 |
"/ self error:'almost out of memory' |
2657 |
'almost out of memory' errorPrintNL. |
|
2658 |
||
2659 |
LowSpaceSemaphore signalIf. |
|
13 | 2660 |
! ! |
2661 |
||
1 | 2662 |
!ObjectMemory class methodsFor:'system management'! |
2663 |
||
2664 |
loadClassBinary:aClassName |
|
2665 |
"find the object file for aClassName and -if found - load it; |
|
2666 |
this one loads precompiled object files" |
|
2667 |
||
357 | 2668 |
|fName newClass| |
1 | 2669 |
|
2670 |
fName := self fileNameForClass:aClassName. |
|
2671 |
fName notNil ifTrue:[ |
|
202 | 2672 |
Class withoutUpdatingChangesDo: |
159 | 2673 |
[ |
2674 |
self loadBinary:(fName , '.o') |
|
2675 |
]. |
|
2676 |
newClass := self at:(aClassName asSymbol). |
|
2677 |
(newClass notNil and:[newClass implements:#initialize]) ifTrue:[ |
|
2678 |
newClass initialize |
|
2679 |
] |
|
1 | 2680 |
] |
2681 |
! |
|
2682 |
||
77 | 2683 |
imageName |
2684 |
"return the filename of the current image, or nil |
|
2685 |
if not running from an image." |
|
2686 |
||
2687 |
^ ImageName |
|
159 | 2688 |
|
2689 |
" |
|
202 | 2690 |
ObjectMemory imageName |
2691 |
" |
|
2692 |
! |
|
2693 |
||
2694 |
imageBaseName |
|
2695 |
"return a reasonable filename to use as baseName (i.e. without extension). |
|
2696 |
This is the filename of the current image (without '.img') or, |
|
2697 |
if not running from an image, the default name 'st'" |
|
2698 |
||
2699 |
|nm| |
|
2700 |
||
2701 |
nm := ImageName. |
|
2702 |
(nm isNil or:[nm isBlank]) ifTrue:[ |
|
2703 |
^ 'st' |
|
2704 |
]. |
|
2705 |
(nm endsWith:'.sav') ifTrue:[ |
|
359 | 2706 |
nm := nm copyWithoutLast:4 |
202 | 2707 |
]. |
2708 |
(nm endsWith:'.img') ifTrue:[ |
|
359 | 2709 |
^ nm copyWithoutLast:4 |
202 | 2710 |
]. |
2711 |
^ nm |
|
2712 |
||
2713 |
" |
|
2714 |
ObjectMemory imageBaseName |
|
159 | 2715 |
" |
77 | 2716 |
! |
2717 |
||
22 | 2718 |
nameForSnapshot |
159 | 2719 |
"return a reasonable filename to store the snapshot image into. |
2720 |
This is the filename of the current image or, |
|
22 | 2721 |
if not running from an image, the default name 'st.img'" |
2722 |
||
202 | 2723 |
^ self imageBaseName , '.img' |
2724 |
||
2725 |
" |
|
2726 |
ObjectMemory nameForSnapshot |
|
2727 |
" |
|
2728 |
! |
|
2729 |
||
2730 |
nameForSources |
|
2731 |
"return a reasonable filename to store the sources into. |
|
2732 |
This is the basename of the current image with '.img' replaced |
|
2733 |
by '.src', or, if not running from an image, the default name 'st.src'" |
|
2734 |
||
2735 |
^ self imageBaseName , '.src' |
|
159 | 2736 |
|
2737 |
" |
|
202 | 2738 |
ObjectMemory nameForSources |
2739 |
" |
|
2740 |
! |
|
2741 |
||
2742 |
nameForChanges |
|
2743 |
"return a reasonable filename to store the changes into. |
|
2744 |
This is the basename of the current image with '.img' replaced |
|
2745 |
by '.chg', or, if not running from an image, the default name 'st.chg'" |
|
2746 |
||
2747 |
^ 'changes'. |
|
360 | 2748 |
|
2749 |
"/ future versions will have: |
|
2750 |
"/ (requires some additionas at other places) |
|
2751 |
"/ |
|
2752 |
"/ ^ self imageBaseName , '.chg' |
|
202 | 2753 |
|
2754 |
" |
|
2755 |
ObjectMemory nameForChanges |
|
159 | 2756 |
" |
22 | 2757 |
! |
2758 |
||
1 | 2759 |
snapShot |
159 | 2760 |
"create a snapshot file containing all of the current state." |
1 | 2761 |
|
22 | 2762 |
self snapShotOn:(self nameForSnapshot) |
1 | 2763 |
|
159 | 2764 |
" |
2765 |
ObjectMemory snapShot |
|
2766 |
" |
|
1 | 2767 |
! |
2768 |
||
2769 |
snapShotOn:aFileName |
|
329 | 2770 |
"create a snapshot in the given file. |
2771 |
If the file exists, save it for backup. |
|
2772 |
Return true if the snapshot worked, false if it failed for some reason. |
|
2773 |
Notify dependents before and after the snapshot operation." |
|
1 | 2774 |
|
159 | 2775 |
|ok oldImageName| |
2776 |
||
2777 |
" |
|
2778 |
keep a save version - just in case something |
|
2779 |
bad happens while writing the image. |
|
2780 |
(could be st/x internal error or file-system errors etc) |
|
2781 |
" |
|
2782 |
(OperatingSystem isValidPath:aFileName) ifTrue:[ |
|
2783 |
OperatingSystem renameFile:aFileName to:(aFileName , '.sav'). |
|
2784 |
]. |
|
22 | 2785 |
|
93 | 2786 |
" |
2787 |
give others a chance to fix things |
|
2788 |
" |
|
329 | 2789 |
self changed:#save. "/ will vanish ... |
2790 |
self changed:#aboutToSnapshot. "/ ... for ST-80 compatibility |
|
13 | 2791 |
|
93 | 2792 |
" |
2793 |
ST-80 compatibility; send #preSnapshot to all classes |
|
2794 |
" |
|
202 | 2795 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 2796 |
aClass preSnapshot |
93 | 2797 |
]. |
2798 |
||
159 | 2799 |
" |
2800 |
save the name with it ... |
|
2801 |
" |
|
2802 |
oldImageName := ImageName. |
|
2803 |
ImageName := aFileName. |
|
2804 |
ok := self primSnapShotOn:aFileName. |
|
2805 |
ImageName := oldImageName. |
|
2806 |
||
2807 |
ok ifTrue:[ |
|
2808 |
Class addChangeRecordForSnapshot:aFileName. |
|
329 | 2809 |
]. |
159 | 2810 |
|
2811 |
||
329 | 2812 |
" |
2813 |
ST-80 compatibility; send #postSnapshot to all classes |
|
2814 |
" |
|
2815 |
Smalltalk allBehaviorsDo:[:aClass | |
|
2816 |
aClass postSnapshot |
|
159 | 2817 |
]. |
329 | 2818 |
self changed:#finishedSnapshot. "/ ST-80 compatibility |
159 | 2819 |
^ ok |
2820 |
||
2821 |
" |
|
2822 |
ObjectMemory snapShotOn:'myimage.img' |
|
2823 |
" |
|
2824 |
! |
|
2825 |
||
2826 |
primSnapShotOn:aFileName |
|
2827 |
"create a snapshot in the given file. |
|
2828 |
Low level entry. Does not notify classes or write an entry to |
|
2829 |
the changes file. Also, no image backup is created. Returns true if |
|
2830 |
the snapshot worked, false if it failed for some reason. |
|
2831 |
This method should not be used in normal cases." |
|
2832 |
||
2833 |
|ok| |
|
2834 |
||
13 | 2835 |
%{ /* STACK:32000 */ |
2836 |
||
1 | 2837 |
OBJ __snapShotOn(); |
159 | 2838 |
OBJ funny = @symbol(funnySnapshotSymbol); |
1 | 2839 |
|
56 | 2840 |
if (__isString(aFileName)) { |
356 | 2841 |
__BLOCKINTERRUPTS(); |
159 | 2842 |
ok = __snapShotOn(__context, _stringVal(aFileName), funny); |
356 | 2843 |
__UNBLOCKINTERRUPTS(); |
1 | 2844 |
} |
159 | 2845 |
%}. |
22 | 2846 |
^ ok |
418 | 2847 |
! |
2848 |
||
2849 |
allBinaryModulesDo:aBlock |
|
2850 |
"internal private method - walk over all known binary |
|
2851 |
modules and evaluate aBlock for each entry. |
|
2852 |
Do not depend on the information returned for each - this may |
|
2853 |
change without notice." |
|
2854 |
||
2855 |
%{ |
|
2856 |
__REGISTRATION_DO_BLOCK(&aBlock COMMA_SND); |
|
2857 |
%} |
|
2858 |
! |
|
2859 |
||
2860 |
binaryModuleInfo |
|
2861 |
"return a collection of moduleInfo entries. |
|
2862 |
This returns a dictionary (keys are internal moduleIDs) |
|
2863 |
with one entry for each binary package." |
|
2864 |
||
2865 |
|modules| |
|
2866 |
||
2867 |
modules := IdentityDictionary new. |
|
2868 |
self allBinaryModulesDo:[:entry | |
|
438 | 2869 |
|id name type libName subModuleName module dynamic infoRec pathName |
2870 |
typeName nameString| |
|
418 | 2871 |
|
2872 |
id := entry at:1. |
|
2873 |
subModuleName := (entry at:2) asSymbol. |
|
2874 |
libName := (entry at:4). |
|
2875 |
||
2876 |
id > 0 ifTrue:[ |
|
2877 |
pathName := ObjectFileLoader pathNameFromID:id. |
|
2878 |
dynamic := true. |
|
438 | 2879 |
typeName := 'dynamic '. |
2880 |
name := pathName asFilename baseName |
|
418 | 2881 |
] ifFalse:[ |
2882 |
dynamic := false. |
|
443 | 2883 |
typeName := 'builtIn '. |
418 | 2884 |
pathName := nil. |
2885 |
libName isNil ifTrue:[ |
|
438 | 2886 |
name := subModuleName |
418 | 2887 |
] ifFalse:[ |
438 | 2888 |
name := libName |
418 | 2889 |
]. |
2890 |
]. |
|
438 | 2891 |
nameString := typeName. |
2892 |
libName isNil ifTrue:[ |
|
2893 |
nameString := nameString, 'module ' |
|
2894 |
] ifFalse:[ |
|
2895 |
nameString := nameString, 'classLib ' |
|
2896 |
]. |
|
2897 |
nameString := nameString , name. |
|
2898 |
||
418 | 2899 |
libName isNil ifTrue:[ |
2900 |
type := #classObject |
|
2901 |
] ifFalse:[ |
|
2902 |
type := #classLibrary |
|
2903 |
]. |
|
2904 |
infoRec := modules at:id ifAbsent:nil. |
|
2905 |
infoRec notNil ifTrue:[ |
|
2906 |
(infoRec at:#classNames) add:subModuleName |
|
2907 |
] ifFalse:[ |
|
2908 |
infoRec := IdentityDictionary new. |
|
2909 |
infoRec at:#id put:id. |
|
2910 |
infoRec at:#classNames put:(Set with:subModuleName). |
|
2911 |
infoRec at:#pathName put:pathName. |
|
438 | 2912 |
infoRec at:#name put:nameString. |
418 | 2913 |
infoRec at:#libraryName put:libName. |
2914 |
infoRec at:#dynamic put:dynamic. |
|
2915 |
infoRec at:#type put:type. |
|
2916 |
modules at:id put:infoRec. |
|
2917 |
]. |
|
2918 |
]. |
|
2919 |
^ modules |
|
2920 |
||
2921 |
" |
|
2922 |
ObjectMemory binaryModuleInfo |
|
2923 |
" |
|
2924 |
||
438 | 2925 |
"Modified: 17.9.1995 / 16:33:02 / claus" |
418 | 2926 |
! |
2927 |
||
2928 |
fullBinaryModuleInfo |
|
2929 |
"return a full collection of moduleInfo entries. |
|
2930 |
This returns a dictionary (keys are component names) |
|
2931 |
with one entry for each component in all binary packages." |
|
2932 |
||
2933 |
|modules| |
|
2934 |
||
2935 |
modules := IdentityDictionary new. |
|
2936 |
self allBinaryModulesDo:[:entry | |
|
2937 |
|id name type libName subModuleName module dynamic infoRec pathName |
|
2938 |
t| |
|
2939 |
||
2940 |
id := entry at:1. |
|
2941 |
subModuleName := (entry at:2) asSymbol. |
|
2942 |
libName := (entry at:4). |
|
2943 |
t := AbsoluteTime fromOSTime:(entry at:5). |
|
2944 |
||
2945 |
id > 0 ifTrue:[ |
|
2946 |
dynamic := true. |
|
2947 |
] ifFalse:[ |
|
2948 |
dynamic := false. |
|
2949 |
]. |
|
2950 |
libName isNil ifTrue:[ |
|
2951 |
type := #classObject |
|
2952 |
] ifFalse:[ |
|
2953 |
type := #classLibrary |
|
2954 |
]. |
|
2955 |
infoRec := IdentityDictionary new. |
|
2956 |
infoRec at:#id put:id. |
|
2957 |
infoRec at:#className put:subModuleName. |
|
2958 |
infoRec at:#libraryName put:libName. |
|
2959 |
infoRec at:#dynamic put:dynamic. |
|
2960 |
infoRec at:#type put:type. |
|
2961 |
infoRec at:#timeStamp put:t. |
|
2962 |
modules at:subModuleName put:infoRec. |
|
2963 |
]. |
|
2964 |
^ modules |
|
2965 |
||
2966 |
" |
|
2967 |
ObjectMemory fullBinaryModuleInfo |
|
2968 |
" |
|
2969 |
||
2970 |
"Modified: 30.8.1995 / 17:29:30 / claus" |
|
379 | 2971 |
! ! |
2972 |
||
2973 |
!ObjectMemory class ignoredMethodsFor:'system management'! |
|
1 | 2974 |
|
2975 |
applicationImageOn:aFileName for:startupClass selector:startupSelector |
|
2976 |
"create a snapshot which will come up without any views |
|
93 | 2977 |
but starts up an application by sending startupClass the startupSelector. |
312 | 2978 |
This exists to nail down an idea I tried once. |
2979 |
It is absolutely EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 2980 |
|
2 | 2981 |
|viewsKnown savedIdleBlocks savedTimeoutBlocks savedTranscript |
2982 |
savedRoot| |
|
1 | 2983 |
|
2984 |
viewsKnown := Display knownViews. |
|
2985 |
savedTranscript := Transcript. |
|
2 | 2986 |
savedRoot := RootView. |
1 | 2987 |
|
335 | 2988 |
"a kludge: save image with modified knownViews, |
10 | 2989 |
and also Transcript set to StdErr ..." |
1 | 2990 |
|
2991 |
Display knownViews:nil. |
|
2 | 2992 |
RootView := nil. |
2993 |
||
1 | 2994 |
Transcript := Stderr. |
10 | 2995 |
Smalltalk startupClass:startupClass selector:startupSelector arguments:nil. |
1 | 2996 |
self snapShotOn:aFileName. |
10 | 2997 |
Smalltalk startupClass:nil selector:nil arguments:nil. |
1 | 2998 |
|
2 | 2999 |
RootView := savedRoot. |
1 | 3000 |
Transcript := savedTranscript. |
3001 |
Display knownViews:viewsKnown. |
|
335 | 3002 |
|
3003 |
" |
|
3004 |
ObjectMemory applicationImageOn:'draw.img' for:DrawTool selector:#start |
|
3005 |
" |
|
1 | 3006 |
! |
3007 |
||
3008 |
minimumApplicationImageOn:aFileName for:startupClass selector:startupSelector |
|
3009 |
"create a snapshot which will come up without any views |
|
3010 |
but starts up an application by sending startupClass the startupSelector. |
|
93 | 3011 |
All unneeded info is stripped from the saved image. |
312 | 3012 |
This exists to nail down an idea I tried once. |
3013 |
It is absolutely EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 3014 |
|
3015 |
"create a temporary image, for continuation" |
|
3016 |
self snapShotOn:'temp.img'. |
|
3017 |
||
3018 |
Display knownViews do:[:aView | |
|
159 | 3019 |
aView notNil ifTrue:[ |
3020 |
aView superView isNil ifTrue:[ |
|
3021 |
aView destroy |
|
3022 |
] |
|
3023 |
] |
|
1 | 3024 |
]. |
3025 |
||
3026 |
self stripImage. |
|
3027 |
||
3028 |
self applicationImageOn:aFileName for:startupClass selector:startupSelector. |
|
3029 |
||
3030 |
"continue in old image" |
|
3031 |
||
3032 |
OperatingSystem exec:(Arguments at:1) |
|
159 | 3033 |
withArguments:#('smalltalk' '-i' 'temp.img') , (Arguments copyFrom:2) |
1 | 3034 |
|
335 | 3035 |
" |
3036 |
ObjectMemory minimumApplicationImageOn:'draw1.img' for:DrawTool selector:#start |
|
3037 |
ObjectMemory applicationImageOn:'draw2.img' for:DrawTool selector:#start |
|
3038 |
" |
|
1 | 3039 |
! |
3040 |
||
3041 |
stripImage |
|
93 | 3042 |
"remove all unneeded stuff from the image - much more is possible here. |
3043 |
EXPERIMENTAL and unfinished. Dont use this method." |
|
1 | 3044 |
|
2 | 3045 |
"remove all class comments & source" |
1 | 3046 |
|
2 | 3047 |
Smalltalk allBehaviorsDo:[:aClass | |
159 | 3048 |
aClass setComment:nil. |
3049 |
aClass methodArray do:[:aMethod | |
|
3050 |
aMethod source:''. |
|
3051 |
aMethod category:#none |
|
3052 |
] |
|
1 | 3053 |
]. |
335 | 3054 |
|
3055 |
"remove some developpers classes" |
|
3056 |
||
3057 |
Smalltalk at:#Compiler put:Parser. |
|
3058 |
Smalltalk at:#Debugger put:MiniDebugger. |
|
3059 |
Smalltalk at:#Inspector put:MiniInspector. |
|
3060 |
Smalltalk at:#FileBrowser put:nil. |
|
3061 |
Smalltalk at:#SystemBrowser put:nil. |
|
3062 |
Debugger newDebugger. |
|
3063 |
||
1 | 3064 |
self garbageCollect |
3065 |
! ! |
|
362 | 3066 |
|
3067 |
!ObjectMemory class methodsFor:'ST-80 compatibility'! |
|
3068 |
||
3069 |
availableFreeBytes |
|
3070 |
^ self freeSpace + self freeListSpace |
|
3071 |
||
3072 |
" |
|
3073 |
ObjectMemory availableFreeBytes |
|
3074 |
" |
|
3075 |
! |
|
3076 |
||
3077 |
current |
|
3078 |
^ self |
|
3079 |
! |
|
3080 |
||
3081 |
growMemoryBy:numberOfBytes |
|
3082 |
^ self moreOldSpace:numberOfBytes |
|
3083 |
! |
|
3084 |
||
3085 |
numOopsNumBytes |
|
3086 |
^ Array with:(self numberOfObjects) |
|
3087 |
with:(self bytesUsed) |
|
3088 |
||
3089 |
" |
|
3090 |
ObjectMemory numOopsNumBytes |
|
3091 |
" |
|
3092 |
! |
|
3093 |
||
426 | 3094 |
bytesPerOOP |
3095 |
"return the number of bytes an object reference (for example: an instvar) |
|
3096 |
takes" |
|
3097 |
||
3098 |
%{ /* NOCONTEXT */ |
|
3099 |
RETURN(__MKSMALLINT(sizeof(OBJ))); |
|
3100 |
%} |
|
3101 |
||
3102 |
" |
|
3103 |
ObjectMemory bytesPerOOP |
|
3104 |
" |
|
3105 |
! |
|
3106 |
||
3107 |
bytesPerOTE |
|
3108 |
"return the number of overhead bytes of an object. |
|
3109 |
i.e. the number of bytes in every objects header." |
|
3110 |
||
3111 |
%{ /* NOCONTEXT */ |
|
3112 |
RETURN(__MKSMALLINT(OHDR_SIZE)); |
|
3113 |
%} |
|
3114 |
||
3115 |
" |
|
3116 |
ObjectMemory bytesPerOTE |
|
3117 |
" |
|
3118 |
! |
|
3119 |
||
362 | 3120 |
globalCompactingGC |
3121 |
self garbageCollect |
|
3122 |
! |
|
3123 |
||
3124 |
compactingGC |
|
3125 |
self garbageCollect |
|
3126 |
! ! |