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