author | Claus Gittinger <cg@exept.de> |
Sat, 22 Mar 1997 16:19:44 +0100 | |
changeset 2484 | 05bd2cc43192 |
parent 2318 | 880ab58b4ef9 |
child 2644 | b6e66194e355 |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 3 |
All Rights Reserved |
6 | 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 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
13 |
ArrayedCollection variableSubclass:#WeakArray |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
14 |
instanceVariableNames:'dependents' |
1263 | 15 |
classVariableNames:'RegistrationFailedSignal AlreadyInitialized' |
16 |
poolDictionaries:'' |
|
17 |
category:'Collections-Arrayed' |
|
6 | 18 |
! |
19 |
||
20 |
!WeakArray class methodsFor:'documentation'! |
|
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
6 | 36 |
documentation |
37 |
" |
|
88 | 38 |
WeakArrays can be used to trace disposal of objects; in contrast to other |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
39 |
objects, references by WeakArrays will NOT keep an object from being |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
40 |
garbage collected. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
41 |
Instead, whenever an object kept in a WeakArray dies, its entry is zeroed, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
42 |
and the WeakArray is informed by the storage manager. The WeakArray itself |
2271 | 43 |
then informs possible dependents via the dependency mechanism. |
290 | 44 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
45 |
WeakArrays are used to track disposal of objects which keep external |
95 | 46 |
world resources. For example, FileStreams must close their underlying |
290 | 47 |
file when disposed (otherwise you could run out of OS filedescriptors). |
95 | 48 |
This can be done by keeping the FileStream objects in a weakArray, and |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
49 |
keep a parallel array of filedescriptors. Whenever a fileStream is |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
50 |
freed, search both arrays for an index where the stream is zero, but the |
95 | 51 |
filedescriptor is non-nil. Then close that file, and nil the filedescriptor |
290 | 52 |
entry. Notice, that there is a class (Registry) which does exactly this in |
53 |
a more programmer friendly way. |
|
95 | 54 |
|
290 | 55 |
Another application is caching of data: keep it in a weakArray, so the |
95 | 56 |
data in that cache will not be unreclaimable due to being cached. |
57 |
(for example, the ResourcePack class uses a WeakArray to cache recently |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
58 |
used resource data for a while). |
88 | 59 |
|
186 | 60 |
The way in which weakArrays get informed by the runtime system is via |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
61 |
an interrupt (DisposeInterrupt) which is first sent to the disposeHandler |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
62 |
(typically ObjectMemory). ObjectMemory then takes the required steps to |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
63 |
notify all weakArrays via the #lostPointer message. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
64 |
The reason for not sending messages directly from the VM is to make it |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
65 |
possible to run the finalization code at lower priority or from another class. |
186 | 66 |
Also, as a side effect, it is possible to delay finalization by blocking |
2271 | 67 |
interrupts. (thus, the actual sending of the #lostPointer message is under |
68 |
control of Smalltalk code, which is modifyable). |
|
69 |
||
186 | 70 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
71 |
A weakArray notifies its dependents via normal dependency notfications. |
186 | 72 |
|
2145 | 73 |
[hint:] |
2271 | 74 |
WeakArray handling adds small some overhead to the VM |
75 |
(each weakarray is scanned after each GC). |
|
76 |
It is uncertain, if the current mechanism works well |
|
77 |
with (say) ten-thousands of weakArrays. |
|
78 |
We had the system running with >2000 weakArrays, some being quite |
|
79 |
big for a while and had a few percent of added gc time. |
|
80 |
The system as delivered creates between 50 and 100 weakArrays, |
|
81 |
but with many dependents, this number may grow. |
|
82 |
If you need the dependency mechanism on a huge number of objects, |
|
83 |
consider adding a (non-weak) dependents field to your class |
|
84 |
- take the implementation of Model as a guide (or subclass them |
|
85 |
from Model). |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
86 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
87 |
As a possible option, we could perform the weakArray scanning only in |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
88 |
the oldSpace reclamation code - this would remove most of the overhead, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
89 |
but will lead to much longer delayed finalization .... we will see. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
90 |
|
290 | 91 |
|
1290 | 92 |
[instance variables:] |
290 | 93 |
|
2271 | 94 |
dependents get informed via #change notifiction |
95 |
that the weakArray has lost pointers. |
|
96 |
Having the dependents here is an optimization. |
|
290 | 97 |
|
1290 | 98 |
[class variables:] |
290 | 99 |
|
2271 | 100 |
RegistrationFailedSignal raised if a weakArray cannot be |
101 |
registered by the VM. This only happens, |
|
102 |
if the VM has to resize its internal tables |
|
103 |
and is running out of malloc-memory. |
|
1263 | 104 |
|
1290 | 105 |
[author:] |
2271 | 106 |
Claus Gittinger |
1290 | 107 |
|
1263 | 108 |
[See also:] |
2271 | 109 |
Array WeakIdentitySet WeakIdentityDictionary Registry |
110 |
Model |
|
6 | 111 |
" |
112 |
! ! |
|
113 |
||
159 | 114 |
!WeakArray class methodsFor:'initialization'! |
115 |
||
116 |
initialize |
|
117 |
"setup the private signal" |
|
118 |
||
119 |
RegistrationFailedSignal isNil ifTrue:[ |
|
302 | 120 |
RegistrationFailedSignal := ErrorSignal newSignalMayProceed:true. |
186 | 121 |
RegistrationFailedSignal nameClass:self message:#registrationFailedSignal. |
122 |
RegistrationFailedSignal notifierString:'weakArray registration failed'. |
|
159 | 123 |
] |
124 |
! ! |
|
125 |
||
6 | 126 |
!WeakArray class methodsFor:'instance creation'! |
127 |
||
128 |
new:size |
|
95 | 129 |
"return a new weakArray with size slots" |
6 | 130 |
|
2271 | 131 |
"This is a kludge: I would like to set the WEAK-flag in the classes |
216 | 132 |
initialize method, but (currently) the order in which the class-initialize |
290 | 133 |
methods are called is not defined ... |
216 | 134 |
... therefore it could happen, that a WeakArray is used by other |
135 |
classes initialize method BEFORE this method is evaluated. |
|
136 |
To avoid this, the WEAK bit in the class is set here, when the very first |
|
2271 | 137 |
WeakArray is created. |
138 |
[Actually, the cleanest solution was to add another class definition |
|
139 |
keyword (such as #variableWeakSubclass:) which sets the weak flag right |
|
140 |
from the start.]" |
|
95 | 141 |
|
216 | 142 |
AlreadyInitialized isNil ifTrue:[ |
2271 | 143 |
self flags:(Behavior flagWeakPointers). |
144 |
AlreadyInitialized := true |
|
216 | 145 |
]. |
95 | 146 |
|
159 | 147 |
^ (self basicNew:size) registerAsWeakArray |
2271 | 148 |
|
149 |
"Modified: 25.1.1997 / 13:17:22 / cg" |
|
159 | 150 |
! ! |
151 |
||
2318 | 152 |
!WeakArray class methodsFor:'queries'! |
153 |
||
154 |
isBuiltInClass |
|
155 |
"return true if this class is known by the run-time-system. |
|
156 |
Here, true is returned for myself, false for subclasses." |
|
157 |
||
158 |
^ self == WeakArray |
|
159 |
! ! |
|
160 |
||
159 | 161 |
!WeakArray methodsFor:'GC registration'! |
162 |
||
163 |
registerAsWeakArray |
|
164 |
"register the receiver in the VM - |
|
165 |
i.e. tell the VM to nil disposed entries in the receiver |
|
166 |
and notify the disposeInterruptHandler whenever that happened." |
|
167 |
||
168 |
|ok| |
|
2318 | 169 |
|
6 | 170 |
%{ |
171 |
OBJ __addShadowObject(); |
|
172 |
||
159 | 173 |
ok = __addShadowObject(self, 0); |
6 | 174 |
if (ok == false) { |
2271 | 175 |
/* |
176 |
* the behavior of __addShadowObject() in case of overflowing |
|
177 |
* VM-table space can be controlled by the second argument: |
|
178 |
* if its 0, the weakObject is not registered, and false |
|
179 |
* is returned. |
|
180 |
* if its 1, the tables are reallocated, registration proceeds, |
|
181 |
* and true is returned. |
|
182 |
* This allows for the caller to have an influence on the VM's |
|
183 |
* shadow table allocation. |
|
184 |
* |
|
185 |
* If addShadowObject() returned false, too many shadow objects are |
|
186 |
* already there. Then collect garbage to get rid of |
|
187 |
* obsolete ones, and try again. |
|
188 |
* Since a full collect is expensive, we try |
|
189 |
* a scavenge first, doing a full collect only if |
|
190 |
* that does not help. |
|
191 |
* |
|
192 |
* THIS MAY OR MAY NOT BE A GOOD IDEA: although it reduces |
|
193 |
* the number of shadow objects that have to be |
|
194 |
* processed at GC time, it may create a long delay here, |
|
195 |
* at shadow object creation time. |
|
196 |
* Dont know which is better ... |
|
197 |
*/ |
|
198 |
__nonTenuringScavenge(__context); |
|
199 |
ok = __addShadowObject(self, 0); |
|
200 |
||
201 |
if (ok == false) { |
|
202 |
/* |
|
203 |
* hard stuff - need full collect |
|
204 |
* if this is the very first GC, assume that we are in |
|
205 |
* the startup phase (where all weak stuff is allocated). |
|
206 |
* Then do no GC. |
|
207 |
* Heuristics showed, that this GC does not find much ... |
|
208 |
*/ |
|
209 |
if ((__garbageCollectCount() != 0) |
|
210 |
|| (__incrementalGCCount() != 0)) { |
|
211 |
__markAndSweepIfUseful(__context); |
|
212 |
ok = __addShadowObject(self, 0); |
|
213 |
} |
|
214 |
if (ok == false) { |
|
215 |
/* |
|
216 |
* mhmh - it seems that there are really many shadow |
|
217 |
* objects around - force creation |
|
218 |
*/ |
|
219 |
ok = __addShadowObject(self, 1); |
|
220 |
if (ok == false) { |
|
221 |
/* |
|
222 |
* no chance - something must be wrong |
|
223 |
* lets fall into the exception and see. |
|
224 |
*/ |
|
225 |
} |
|
226 |
} |
|
227 |
} |
|
6 | 228 |
} |
159 | 229 |
%}. |
230 |
ok ifFalse:[ |
|
2271 | 231 |
" |
232 |
the VM was not able to register the new weakArray |
|
233 |
This can only happen, if the VM has to resize its tables, |
|
234 |
and a malloc request failed. Usually, this smells like big |
|
235 |
trouble being on the way (soon running out of memory in |
|
236 |
other places as well). |
|
237 |
Configure your OS for more swap space. |
|
238 |
" |
|
239 |
^ RegistrationFailedSignal raiseRequestWith:self |
|
159 | 240 |
] |
6 | 241 |
! ! |
242 |
||
603 | 243 |
!WeakArray methodsFor:'accessing'! |
244 |
||
245 |
at:index |
|
246 |
"return the indexed instance variable with index, anInteger. |
|
2271 | 247 |
Reimplemented here for IGC readBarrier. |
248 |
(You dont have to understand this.)" |
|
603 | 249 |
|
250 |
^ self basicAt:index |
|
2271 | 251 |
|
252 |
"Modified: 25.1.1997 / 13:41:25 / cg" |
|
603 | 253 |
! |
6 | 254 |
|
603 | 255 |
basicAt:index |
256 |
"return the indexed instance variable with index, anInteger. |
|
2271 | 257 |
Reimplemented here for IGC readBarrier. |
258 |
(You dont have to understand this.)" |
|
603 | 259 |
|
260 |
%{ /* NOCONTEXT */ |
|
261 |
||
262 |
REGISTER int indx; |
|
263 |
REGISTER unsigned int nIndex; |
|
264 |
OBJ el; |
|
6 | 265 |
|
603 | 266 |
if (__isSmallInteger(index)) { |
2271 | 267 |
indx = __intVal(index) - 1; |
268 |
if (indx >= 0) { |
|
269 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
270 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
271 |
if (indx < nIndex) { |
|
272 |
el = __InstPtr(self)->i_instvars[indx]; |
|
273 |
if (__isNonNilObject(el)) el = __WEAK_READ__(self, el); |
|
274 |
RETURN (el); |
|
275 |
} |
|
276 |
} |
|
603 | 277 |
} |
278 |
%}. |
|
279 |
^ super basicAt:index |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
280 |
! ! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
281 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
282 |
!WeakArray methodsFor:'dependents access'! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
283 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
284 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
285 |
"make the argument, anObject be a dependent of the receiver" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
286 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
287 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
288 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
289 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
290 |
[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
291 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
292 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
293 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
294 |
"/ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
295 |
"/ store the very first dependent directly in |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
296 |
"/ the dependents instVar |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
297 |
"/ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
298 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
299 |
dependents := anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
300 |
] ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
301 |
"/ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
302 |
"/ store more dependents in the dependents collection |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
303 |
"/ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
304 |
deps isCollection ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
305 |
deps add:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
306 |
] ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
307 |
deps == anObject ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
308 |
dependents := (IdentitySet with:dependents with:anObject) |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
309 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
310 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
311 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
312 |
] valueNowOrOnUnwindDo:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
313 |
wasBlocked ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
314 |
OperatingSystem unblockInterrupts |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
315 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
316 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
317 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
318 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
603 | 319 |
! |
320 |
||
321 |
dependents |
|
322 |
"return the dependents of the receiver" |
|
323 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
324 |
dependents isNil ifTrue:[^ nil]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
325 |
dependents isCollection ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
326 |
^ dependents |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
327 |
]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
328 |
^ IdentitySet with:dependents |
603 | 329 |
! |
330 |
||
331 |
dependents:aCollection |
|
332 |
"set the dependents of the receiver" |
|
333 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
334 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
335 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
336 |
aCollection size == 1 ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
337 |
dep := aCollection first. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
338 |
dep isCollection ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
339 |
dependents := aCollection first. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
340 |
^ self |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
341 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
342 |
]. |
603 | 343 |
dependents := aCollection |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
344 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
345 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
346 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
347 |
"evaluate aBlock for all of my dependents" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
348 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
349 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
350 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
351 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
352 |
deps notNil ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
353 |
deps isCollection ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
354 |
deps do:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
355 |
] ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
356 |
aBlock value:deps |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
357 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
358 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
359 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
360 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
361 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
362 |
"make the argument, anObject be independent of the receiver" |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
363 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
364 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
365 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
366 |
"/ must do this save from interrupts, since the dependents collection |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
367 |
"/ is possibly accessed from multiple threads. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
368 |
"/ Used to use #valueUninterruptably here; inlined that code for slightly |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
369 |
"/ faster execution. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
370 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
371 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
372 |
[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
373 |
|deps sz dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
374 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
375 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
376 |
deps notNil ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
377 |
deps isCollection ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
378 |
deps remove:anObject ifAbsent:[]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
379 |
(sz := deps size) == 0 ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
380 |
dependents := nil |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
381 |
] ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
382 |
sz == 1 ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
383 |
(dep := deps first) isCollection ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
384 |
dependents := dep |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
385 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
386 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
387 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
388 |
] ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
389 |
deps == anObject ifTrue:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
390 |
dependents := nil |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
391 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
392 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
393 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
394 |
] valueNowOrOnUnwindDo:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
395 |
wasBlocked ifFalse:[ |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
396 |
OperatingSystem unblockInterrupts |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
397 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
398 |
] |
6 | 399 |
! ! |
400 |
||
159 | 401 |
!WeakArray methodsFor:'copying'! |
402 |
||
403 |
postCopy |
|
404 |
"copying alone does not really help - we have to tell |
|
405 |
the VM, that there is a new WeakArray around ... |
|
406 |
Q: who copies weakArrays ?" |
|
407 |
||
290 | 408 |
dependents := nil. |
159 | 409 |
self registerAsWeakArray. |
410 |
! ! |
|
411 |
||
1825 | 412 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
413 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
414 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
415 |
"evaluate the argument, aBlock for each element in the collection. |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
416 |
- reimplemented for IGC readBarrier. |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
417 |
You dont have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
418 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
419 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
420 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
421 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
422 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
423 |
|
1136 | 424 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
425 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
426 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
427 |
if (__isBlockLike(aBlock) |
1136 | 428 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
429 |
{ |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
430 |
/* |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
431 |
* the most common case: a static compiled block, with home on the stack ... |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
432 |
*/ |
2189 | 433 |
REGISTER OBJFUNC codeVal; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
434 |
|
2254 | 435 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
436 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
437 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
438 |
#ifdef NEW_BLOCK_CALL |
2189 | 439 |
# define BLOCK_ARG aBlock |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
440 |
#else |
2189 | 441 |
# define BLOCK_ARG rHome |
442 |
REGISTER OBJ rHome; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
443 |
|
2189 | 444 |
rHome = __BlockInstPtr(aBlock)->b_home; |
445 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
446 |
#endif |
2189 | 447 |
{ |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
448 |
for (; index < nIndex; index++) { |
2216 | 449 |
OBJ element; |
450 |
||
2189 | 451 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
452 |
|
2189 | 453 |
element = __InstPtr(self)->i_instvars[index]; |
454 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
455 |
(*codeVal)(BLOCK_ARG, element); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
456 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
457 |
RETURN (self); |
2189 | 458 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
459 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
460 |
} |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
461 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
462 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
463 |
* sorry, must check code-pointer in the loop |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
464 |
* it could be recompiled or flushed |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
465 |
*/ |
2189 | 466 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
467 |
#ifdef NEW_BLOCK_CALL |
2189 | 468 |
# define BLOCK_ARG aBlock |
469 |
# define IBLOCK_ARG nil |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
470 |
#else |
2189 | 471 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
472 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
473 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
474 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
475 |
for (; index < nIndex; index++) { |
2189 | 476 |
REGISTER OBJFUNC codeVal; |
2220 | 477 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
478 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
479 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
480 |
|
1136 | 481 |
element = __InstPtr(self)->i_instvars[index]; |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
482 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
483 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
484 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2189 | 485 |
(*codeVal)(BLOCK_ARG, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
486 |
} else { |
2189 | 487 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
488 |
/* |
|
489 |
* arg is a compiled block with bytecode - |
|
490 |
* directly call interpreter without going through Block>>value |
|
491 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
492 |
#ifdef PASS_ARG_POINTER |
2189 | 493 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
494 |
#else |
2189 | 495 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
496 |
#endif |
2189 | 497 |
} else { |
498 |
/* |
|
499 |
* arg is something else - call it with #value |
|
500 |
*/ |
|
501 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
502 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
503 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
504 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
505 |
RETURN (self); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
506 |
|
2189 | 507 |
# undef BLOCK_ARG |
508 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
509 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
510 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
511 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
512 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
513 |
* not a block - send it #value: |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
514 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
515 |
for (; index < nIndex; index++) { |
2216 | 516 |
OBJ element; |
517 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
518 |
if (InterruptPending != nil) __interruptL(@line); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
519 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
520 |
element = __InstPtr(self)->i_instvars[index]; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
521 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
522 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
523 |
(*val.ilc_func)(aBlock, |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
524 |
@symbol(value:), |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
525 |
nil, &val, |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
526 |
element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
527 |
} |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
528 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
529 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
530 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
531 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
532 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
533 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 534 |
replaced by zero (due to a collected object). |
535 |
Be aware, that while indices are being enumerated, other |
|
536 |
slots may change iff the garbage collector finds new garbage." |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
537 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
538 |
self keysAndValuesDo:[:index :element | |
2271 | 539 |
element == 0 ifTrue:[ |
540 |
aBlock value:index |
|
541 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
542 |
] |
2271 | 543 |
|
544 |
"Modified: 25.1.1997 / 14:50:59 / cg" |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
545 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
546 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
547 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
548 |
"evaluate the argument, aBlock for all indices where elements have been |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
549 |
replaced by zero (due to a collected object), and replace the element |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
550 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
551 |
In the current implementation, the block sees the newValue (i.e. it is |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
552 |
changed before the block is called); this behavior is not guaranteed |
2271 | 553 |
with future versions. |
554 |
Be aware, that while indices are being enumerated, other |
|
555 |
slots may change iff the garbage collector finds new garbage." |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
556 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
557 |
self keysAndValuesDo:[:index :element | |
2271 | 558 |
element == 0 ifTrue:[ |
559 |
self at:index put:newValue. |
|
560 |
aBlock value:index. |
|
561 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
562 |
] |
2271 | 563 |
|
564 |
"Modified: 25.1.1997 / 14:51:28 / cg" |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
565 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
566 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
567 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
568 |
"evaluate the argument, aBlock for all indices where elements have been |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
569 |
cleared (due to a collected object), nil the entry." |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
570 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
571 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
572 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
573 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
574 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
575 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
576 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
577 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
578 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
579 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
580 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
581 |
|
1136 | 582 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
583 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
584 |
if (__isBlockLike(aBlock) |
1136 | 585 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2189 | 586 |
{ |
587 |
/* |
|
588 |
* the most common case: a static compiled block, with home on the stack ... |
|
589 |
*/ |
|
590 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
591 |
|
2254 | 592 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
593 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
594 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
595 |
#ifdef NEW_BLOCK_CALL |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
596 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
597 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
598 |
# define BLOCK_ARG rHome |
2189 | 599 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
600 |
|
2189 | 601 |
rHome = __BlockInstPtr(aBlock)->b_home; |
602 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
603 |
#endif |
2189 | 604 |
{ |
605 |
for (; index < nIndex; index++) { |
|
2216 | 606 |
REGISTER OBJ element; |
607 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
608 |
element = __InstPtr(self)->i_instvars[index]; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
609 |
if (element) { |
2189 | 610 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
611 |
__interruptL(@line); |
2189 | 612 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
613 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
614 |
|
2189 | 615 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
616 |
if (element) { |
2189 | 617 |
(*codeVal)(BLOCK_ARG, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
618 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
619 |
} |
2189 | 620 |
} |
621 |
RETURN (self); |
|
622 |
} |
|
623 |
} |
|
624 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
625 |
|
2189 | 626 |
/* |
627 |
* sorry, must check code-pointer in the loop |
|
628 |
* it could be recompiled or flushed |
|
629 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
630 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
631 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
632 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
633 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
634 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
635 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
636 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
637 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
638 |
|
2189 | 639 |
for (; index < nIndex; index++) { |
640 |
REGISTER OBJFUNC codeVal; |
|
2220 | 641 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
642 |
|
2189 | 643 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
644 |
if (element) { |
2189 | 645 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
646 |
__interruptL(@line); |
1903 | 647 |
element = __InstPtr(self)->i_instvars[index]; |
648 |
} |
|
2189 | 649 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
650 |
if (element) { |
2189 | 651 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
652 |
(*codeVal)(BLOCK_ARG, element); |
|
653 |
} else { |
|
654 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
655 |
/* |
|
656 |
* arg is a compiled block with bytecode - |
|
657 |
* directly call interpreter without going through Block>>value |
|
658 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
659 |
#ifdef PASS_ARG_POINTER |
2189 | 660 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
661 |
#else |
2189 | 662 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
663 |
#endif |
2189 | 664 |
} else { |
665 |
/* |
|
666 |
* arg is something else - call it with #value |
|
667 |
*/ |
|
668 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
669 |
} |
|
670 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
671 |
} |
2189 | 672 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
673 |
} |
2189 | 674 |
RETURN (self); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
675 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
676 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
677 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
678 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
679 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
680 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
681 |
* not a block - send it #value: |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
682 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
683 |
for (; index < nIndex; index++) { |
2216 | 684 |
REGISTER OBJ element; |
685 |
||
2189 | 686 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
687 |
if (element) { |
2189 | 688 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
689 |
__interruptL(@line); |
1136 | 690 |
element = __InstPtr(self)->i_instvars[index]; |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
691 |
} |
2189 | 692 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
693 |
if (element) { |
2189 | 694 |
(*val.ilc_func)(aBlock, |
695 |
@symbol(value:), |
|
696 |
nil, &val, |
|
697 |
element); |
|
698 |
} |
|
699 |
} |
|
700 |
} |
|
701 |
%}. |
|
702 |
^ self |
|
703 |
! |
|
704 |
||
705 |
validElementsDo:aBlock |
|
706 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
707 |
||
708 |
%{ |
|
709 |
REGISTER int index; |
|
710 |
int nIndex; |
|
711 |
static struct inlineCache val = _ILC1; |
|
712 |
||
713 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
714 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
715 |
if (__isBlockLike(aBlock) |
|
716 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
717 |
{ |
|
718 |
/* |
|
719 |
* the most common case: a static compiled block, with home on the stack ... |
|
720 |
*/ |
|
721 |
REGISTER OBJFUNC codeVal; |
|
722 |
||
2254 | 723 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
724 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
725 |
||
2189 | 726 |
#ifdef NEW_BLOCK_CALL |
727 |
# define BLOCK_ARG aBlock |
|
728 |
#else |
|
729 |
# define BLOCK_ARG rHome |
|
730 |
REGISTER OBJ rHome; |
|
731 |
||
732 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
733 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
734 |
#endif |
|
735 |
{ |
|
736 |
for (; index < nIndex; index++) { |
|
2216 | 737 |
REGISTER OBJ element; |
738 |
||
2189 | 739 |
element = __InstPtr(self)->i_instvars[index]; |
740 |
if (element && (element != __MKSMALLINT(0))) { |
|
741 |
if (InterruptPending != nil) { |
|
742 |
__interruptL(@line); |
|
743 |
element = __InstPtr(self)->i_instvars[index]; |
|
744 |
} |
|
745 |
||
746 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
747 |
if (element && (element != __MKSMALLINT(0))) { |
|
748 |
(*codeVal)(BLOCK_ARG, element); |
|
749 |
} |
|
750 |
} |
|
751 |
} |
|
752 |
RETURN (self); |
|
753 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
754 |
} |
2189 | 755 |
} |
756 |
||
757 |
/* |
|
758 |
* sorry, must check code-pointer in the loop |
|
759 |
* it could be recompiled or flushed |
|
760 |
*/ |
|
761 |
# undef BLOCK_ARG |
|
762 |
#ifdef NEW_BLOCK_CALL |
|
763 |
# define BLOCK_ARG aBlock |
|
764 |
# define IBLOCK_ARG nil |
|
765 |
#else |
|
766 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
767 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
768 |
#endif |
|
769 |
||
770 |
for (; index < nIndex; index++) { |
|
771 |
REGISTER OBJFUNC codeVal; |
|
2220 | 772 |
OBJ element; |
2189 | 773 |
|
774 |
element = __InstPtr(self)->i_instvars[index]; |
|
775 |
if (element && (element != __MKSMALLINT(0))) { |
|
776 |
if (InterruptPending != nil) { |
|
777 |
__interruptL(@line); |
|
778 |
element = __InstPtr(self)->i_instvars[index]; |
|
779 |
} |
|
780 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
781 |
if (element && (element != __MKSMALLINT(0))) { |
|
782 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
783 |
(*codeVal)(BLOCK_ARG, element); |
|
784 |
} else { |
|
785 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
786 |
/* |
|
787 |
* arg is a compiled block with bytecode - |
|
788 |
* directly call interpreter without going through Block>>value |
|
789 |
*/ |
|
790 |
#ifdef PASS_ARG_POINTER |
|
791 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
|
792 |
#else |
|
793 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
|
794 |
#endif |
|
795 |
} else { |
|
796 |
/* |
|
797 |
* arg is something else - call it with #value |
|
798 |
*/ |
|
799 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
800 |
} |
|
801 |
} |
|
802 |
} |
|
803 |
} |
|
804 |
} |
|
805 |
RETURN (self); |
|
806 |
||
807 |
# undef BLOCK_ARG |
|
808 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
809 |
} |
2189 | 810 |
|
811 |
/* |
|
812 |
* not a block - send it #value: |
|
813 |
*/ |
|
814 |
for (; index < nIndex; index++) { |
|
2216 | 815 |
REGISTER OBJ element; |
816 |
||
2189 | 817 |
element = __InstPtr(self)->i_instvars[index]; |
818 |
if (element && (element != __MKSMALLINT(0))) { |
|
819 |
if (InterruptPending != nil) { |
|
820 |
__interruptL(@line); |
|
821 |
element = __InstPtr(self)->i_instvars[index]; |
|
822 |
} |
|
823 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
824 |
if (element && (element != __MKSMALLINT(0))) { |
|
825 |
(*val.ilc_func)(aBlock, |
|
826 |
@symbol(value:), |
|
827 |
nil, &val, |
|
828 |
element); |
|
829 |
} |
|
830 |
} |
|
831 |
} |
|
604 | 832 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
833 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
834 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
835 |
|
603 | 836 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
837 |
|
603 | 838 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
839 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
840 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
841 |
|
603 | 842 |
dependents notNil ifTrue:[ |
2189 | 843 |
self changed:#ElementExpired with:nil. |
603 | 844 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
845 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
846 |
"Modified: 18.10.1996 / 21:28:10 / cg" |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
847 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 848 |
! ! |
6 | 849 |
|
628 | 850 |
!WeakArray class methodsFor:'documentation'! |
851 |
||
852 |
version |
|
2318 | 853 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.48 1997-01-29 21:16:41 cg Exp $' |
628 | 854 |
! ! |
603 | 855 |
WeakArray initialize! |