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