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