author | Claus Gittinger <cg@exept.de> |
Thu, 02 Dec 1999 12:22:55 +0100 | |
changeset 5049 | d8279f59df21 |
parent 4730 | 278b9e735be7 |
child 5334 | f8837914d424 |
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:'' |
|
4351 | 17 |
category:'Collections-Weak' |
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:] |
4310 | 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 |
|
4310 | 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 |
|
4310 | 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 |
|
4062 | 105 |
[memory requirements:] |
4310 | 106 |
OBJ-HEADER + (size * ptr-size) + ptr-size |
107 |
+ sizeof(dependents-collection) |
|
4062 | 108 |
|
1290 | 109 |
[author:] |
4310 | 110 |
Claus Gittinger |
1290 | 111 |
|
1263 | 112 |
[See also:] |
4310 | 113 |
Array WeakIdentitySet WeakIdentityDictionary Registry |
114 |
Model |
|
6 | 115 |
" |
116 |
! ! |
|
117 |
||
159 | 118 |
!WeakArray class methodsFor:'initialization'! |
119 |
||
120 |
initialize |
|
121 |
"setup the private signal" |
|
122 |
||
123 |
RegistrationFailedSignal isNil ifTrue:[ |
|
302 | 124 |
RegistrationFailedSignal := ErrorSignal newSignalMayProceed:true. |
186 | 125 |
RegistrationFailedSignal nameClass:self message:#registrationFailedSignal. |
126 |
RegistrationFailedSignal notifierString:'weakArray registration failed'. |
|
159 | 127 |
] |
128 |
! ! |
|
129 |
||
6 | 130 |
!WeakArray class methodsFor:'instance creation'! |
131 |
||
3090 | 132 |
basicNew:size |
95 | 133 |
"return a new weakArray with size slots" |
6 | 134 |
|
2271 | 135 |
"This is a kludge: I would like to set the WEAK-flag in the classes |
216 | 136 |
initialize method, but (currently) the order in which the class-initialize |
290 | 137 |
methods are called is not defined ... |
216 | 138 |
... therefore it could happen, that a WeakArray is used by other |
139 |
classes initialize method BEFORE this method is evaluated. |
|
140 |
To avoid this, the WEAK bit in the class is set here, when the very first |
|
2271 | 141 |
WeakArray is created. |
142 |
[Actually, the cleanest solution was to add another class definition |
|
143 |
keyword (such as #variableWeakSubclass:) which sets the weak flag right |
|
144 |
from the start.]" |
|
95 | 145 |
|
216 | 146 |
AlreadyInitialized isNil ifTrue:[ |
4310 | 147 |
self flags:(Behavior flagWeakPointers). |
148 |
AlreadyInitialized := true |
|
216 | 149 |
]. |
95 | 150 |
|
3090 | 151 |
^ (super basicNew:size) registerAsWeakArray |
2271 | 152 |
|
153 |
"Modified: 25.1.1997 / 13:17:22 / cg" |
|
159 | 154 |
! ! |
155 |
||
2318 | 156 |
!WeakArray class methodsFor:'queries'! |
157 |
||
158 |
isBuiltInClass |
|
159 |
"return true if this class is known by the run-time-system. |
|
160 |
Here, true is returned for myself, false for subclasses." |
|
161 |
||
162 |
^ self == WeakArray |
|
163 |
! ! |
|
164 |
||
159 | 165 |
!WeakArray methodsFor:'GC registration'! |
166 |
||
167 |
registerAsWeakArray |
|
168 |
"register the receiver in the VM - |
|
169 |
i.e. tell the VM to nil disposed entries in the receiver |
|
170 |
and notify the disposeInterruptHandler whenever that happened." |
|
171 |
||
172 |
|ok| |
|
2318 | 173 |
|
6 | 174 |
%{ |
175 |
OBJ __addShadowObject(); |
|
176 |
||
159 | 177 |
ok = __addShadowObject(self, 0); |
6 | 178 |
if (ok == false) { |
4310 | 179 |
/* |
180 |
* the behavior of __addShadowObject() in case of overflowing |
|
181 |
* VM-table space can be controlled by the second argument: |
|
182 |
* if its 0, the weakObject is not registered, and false |
|
183 |
* is returned. |
|
184 |
* if its 1, the tables are reallocated, registration proceeds, |
|
185 |
* and true is returned. |
|
186 |
* This allows for the caller to have an influence on the VM's |
|
187 |
* shadow table allocation. |
|
188 |
* |
|
189 |
* If addShadowObject() returned false, too many shadow objects are |
|
190 |
* already there. Then collect garbage to get rid of |
|
191 |
* obsolete ones, and try again. |
|
192 |
* Since a full collect is expensive, we try |
|
193 |
* a scavenge first, doing a full collect only if |
|
194 |
* that does not help. |
|
195 |
* |
|
196 |
* THIS MAY OR MAY NOT BE A GOOD IDEA: although it reduces |
|
197 |
* the number of shadow objects that have to be |
|
198 |
* processed at GC time, it may create a long delay here, |
|
199 |
* at shadow object creation time. |
|
200 |
* Dont know which is better ... |
|
201 |
*/ |
|
202 |
__nonTenuringScavenge(__context); |
|
203 |
ok = __addShadowObject(self, 0); |
|
2271 | 204 |
|
4310 | 205 |
if (ok == false) { |
206 |
/* |
|
207 |
* hard stuff - need full collect |
|
208 |
* if this is the very first GC, assume that we are in |
|
209 |
* the startup phase (where all weak stuff is allocated). |
|
210 |
* Then do no GC. |
|
211 |
* Heuristics showed, that this GC does not find much ... |
|
212 |
*/ |
|
213 |
if ((__garbageCollectCount() != 0) |
|
214 |
|| (__incrementalGCCount() != 0)) { |
|
215 |
__markAndSweepIfUseful(__context); |
|
216 |
ok = __addShadowObject(self, 0); |
|
217 |
} |
|
218 |
if (ok == false) { |
|
219 |
/* |
|
220 |
* mhmh - it seems that there are really many shadow |
|
221 |
* objects around - force creation |
|
222 |
*/ |
|
223 |
ok = __addShadowObject(self, 1); |
|
224 |
if (ok == false) { |
|
225 |
/* |
|
226 |
* no chance - something must be wrong |
|
227 |
* lets fall into the exception and see. |
|
228 |
*/ |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
6 | 232 |
} |
159 | 233 |
%}. |
234 |
ok ifFalse:[ |
|
4310 | 235 |
" |
236 |
the VM was not able to register the new weakArray |
|
237 |
This can only happen, if the VM has to resize its tables, |
|
238 |
and a malloc request failed. Usually, this smells like big |
|
239 |
trouble being on the way (soon running out of memory in |
|
240 |
other places as well). |
|
241 |
Configure your OS for more swap space. |
|
242 |
" |
|
243 |
^ RegistrationFailedSignal raiseRequestWith:self |
|
159 | 244 |
] |
6 | 245 |
! ! |
246 |
||
603 | 247 |
!WeakArray methodsFor:'accessing'! |
248 |
||
249 |
at:index |
|
250 |
"return the indexed instance variable with index, anInteger. |
|
2271 | 251 |
Reimplemented here for IGC readBarrier. |
252 |
(You dont have to understand this.)" |
|
603 | 253 |
|
254 |
^ self basicAt:index |
|
2271 | 255 |
|
256 |
"Modified: 25.1.1997 / 13:41:25 / cg" |
|
603 | 257 |
! |
6 | 258 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
259 |
at:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
260 |
"store someObject in the weakArray at some index." |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
261 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
262 |
^ self basicAt:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
263 |
! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
264 |
|
603 | 265 |
basicAt:index |
266 |
"return the indexed instance variable with index, anInteger. |
|
2271 | 267 |
Reimplemented here for IGC readBarrier. |
268 |
(You dont have to understand this.)" |
|
603 | 269 |
|
270 |
%{ /* NOCONTEXT */ |
|
271 |
||
272 |
REGISTER int indx; |
|
273 |
REGISTER unsigned int nIndex; |
|
274 |
OBJ el; |
|
6 | 275 |
|
603 | 276 |
if (__isSmallInteger(index)) { |
4310 | 277 |
indx = __intVal(index) - 1; |
278 |
if (indx >= 0) { |
|
279 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
280 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
281 |
if (indx < nIndex) { |
|
282 |
el = __InstPtr(self)->i_instvars[indx]; |
|
4311 | 283 |
if (__isNonNilObject(el)) { |
284 |
el = __WEAK_READ__(self, el); |
|
285 |
} |
|
4310 | 286 |
RETURN (el); |
287 |
} |
|
288 |
} |
|
603 | 289 |
} |
290 |
%}. |
|
291 |
^ super basicAt:index |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
292 |
! |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
293 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
294 |
basicAt:index put:someObject |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
295 |
"store someObject in the weakArray at some index." |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
296 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
297 |
%{ /* NOCONTEXT */ |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
298 |
REGISTER int indx; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
299 |
REGISTER unsigned int nIndex; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
300 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
301 |
if (__isSmallInteger(index)) { |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
302 |
indx = __intVal(index) - 1; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
303 |
if (indx >= 0) { |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
304 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
305 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
306 |
if (indx < nIndex) { |
4310 | 307 |
REGISTER OBJ el = someObject; |
308 |
||
309 |
__InstPtr(self)->i_instvars[indx] = el; |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
310 |
if (__isNonNilObject(el)) { |
4310 | 311 |
__STORE(self, el); |
312 |
__WEAK_WRITE__(self, el); |
|
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
313 |
} |
4310 | 314 |
RETURN (el); |
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
315 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
316 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
317 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
318 |
%}. |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
319 |
"/ for the error-message ... |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
320 |
^ super basicAt:index put:someObject |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
321 |
! ! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
322 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
323 |
!WeakArray methodsFor:'copying'! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
324 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
325 |
postCopy |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
326 |
"copying alone does not really help - we have to tell |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
327 |
the VM, that there is a new WeakArray around ... |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
328 |
Q: who copies weakArrays ?" |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
329 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
330 |
dependents := nil. |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
331 |
self registerAsWeakArray. |
4730
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
332 |
! |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
333 |
|
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
334 |
skipInstvarIndexInDeepCopy:index |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
335 |
"a helper for deepCopy; only indices for which this method returns |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
336 |
false are copied in a deep copy." |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
337 |
|
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
338 |
index == 1 ifTrue:[ |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
339 |
^ true "/ skip dependents |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
340 |
]. |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
341 |
^ false |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
342 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
343 |
! ! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
344 |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
345 |
!WeakArray methodsFor:'dependents access'! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
346 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
347 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
348 |
"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
|
349 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
350 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
351 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
352 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
353 |
[ |
4310 | 354 |
|deps| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
355 |
|
4310 | 356 |
deps := dependents. |
357 |
"/ |
|
358 |
"/ store the very first dependent directly in |
|
359 |
"/ the dependents instVar |
|
360 |
"/ |
|
361 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
362 |
dependents := anObject |
|
363 |
] ifFalse:[ |
|
364 |
"/ |
|
365 |
"/ store more dependents in the dependents collection |
|
366 |
"/ |
|
367 |
deps isCollection ifTrue:[ |
|
368 |
deps add:anObject |
|
369 |
] ifFalse:[ |
|
370 |
deps == anObject ifFalse:[ |
|
371 |
dependents := (IdentitySet with:dependents with:anObject) |
|
372 |
] |
|
373 |
] |
|
374 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
375 |
] valueNowOrOnUnwindDo:[ |
4310 | 376 |
wasBlocked ifFalse:[ |
377 |
OperatingSystem unblockInterrupts |
|
378 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
379 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
380 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
381 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
603 | 382 |
! |
383 |
||
384 |
dependents |
|
385 |
"return the dependents of the receiver" |
|
386 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
387 |
dependents isNil ifTrue:[^ #()]. |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
388 |
dependents isCollection ifTrue:[ |
4310 | 389 |
^ dependents |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
390 |
]. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
391 |
^ IdentitySet with:dependents |
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
392 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
393 |
"Modified: / 27.10.1997 / 19:37:16 / cg" |
603 | 394 |
! |
395 |
||
396 |
dependents:aCollection |
|
397 |
"set the dependents of the receiver" |
|
398 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
399 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
400 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
401 |
aCollection size == 1 ifTrue:[ |
4310 | 402 |
dep := aCollection first. |
403 |
dep isCollection ifFalse:[ |
|
404 |
dependents := aCollection first. |
|
405 |
^ self |
|
406 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
407 |
]. |
603 | 408 |
dependents := aCollection |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
409 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
410 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
411 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
412 |
"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
|
413 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
414 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
415 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
416 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
417 |
deps notNil ifTrue:[ |
4310 | 418 |
deps isCollection ifTrue:[ |
419 |
deps do:aBlock |
|
420 |
] ifFalse:[ |
|
421 |
aBlock value:deps |
|
422 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
423 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
424 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
425 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
426 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
427 |
"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
|
428 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
429 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
430 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
431 |
"/ 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
|
432 |
"/ 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
|
433 |
"/ 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
|
434 |
"/ faster execution. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
435 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
436 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
437 |
[ |
4310 | 438 |
|deps sz dep| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
439 |
|
4310 | 440 |
deps := dependents. |
441 |
deps notNil ifTrue:[ |
|
442 |
deps isCollection ifTrue:[ |
|
443 |
deps remove:anObject ifAbsent:[]. |
|
444 |
(sz := deps size) == 0 ifTrue:[ |
|
445 |
dependents := nil |
|
446 |
] ifFalse:[ |
|
447 |
sz == 1 ifTrue:[ |
|
448 |
(dep := deps first) isCollection ifFalse:[ |
|
449 |
dependents := dep |
|
450 |
] |
|
451 |
] |
|
452 |
] |
|
453 |
] ifFalse:[ |
|
454 |
deps == anObject ifTrue:[ |
|
455 |
dependents := nil |
|
456 |
] |
|
457 |
] |
|
458 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
459 |
] valueNowOrOnUnwindDo:[ |
4310 | 460 |
wasBlocked ifFalse:[ |
461 |
OperatingSystem unblockInterrupts |
|
462 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
463 |
] |
6 | 464 |
! ! |
465 |
||
1825 | 466 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
467 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
468 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
469 |
"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
|
470 |
- reimplemented for IGC readBarrier. |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
471 |
You dont have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
472 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
473 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
474 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
475 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
476 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
477 |
|
1136 | 478 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
479 |
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
|
480 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
481 |
if (__isBlockLike(aBlock) |
1136 | 482 |
&& (__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
|
483 |
{ |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
484 |
/* |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
485 |
* 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
|
486 |
*/ |
2189 | 487 |
REGISTER OBJFUNC codeVal; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
488 |
|
2254 | 489 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
490 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
491 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
492 |
#ifdef NEW_BLOCK_CALL |
2189 | 493 |
# 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
|
494 |
#else |
2189 | 495 |
# define BLOCK_ARG rHome |
496 |
REGISTER OBJ rHome; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
497 |
|
2189 | 498 |
rHome = __BlockInstPtr(aBlock)->b_home; |
499 |
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
|
500 |
#endif |
2189 | 501 |
{ |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
502 |
for (; index < nIndex; index++) { |
2216 | 503 |
OBJ element; |
504 |
||
2189 | 505 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
506 |
|
2189 | 507 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 508 |
if (__isNonNilObject(element)) { |
509 |
element = __WEAK_READ__(self, element); |
|
510 |
} |
|
2189 | 511 |
(*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
|
512 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
513 |
RETURN (self); |
2189 | 514 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
515 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
516 |
} |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
517 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
518 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
519 |
* 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
|
520 |
* 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
|
521 |
*/ |
2189 | 522 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
523 |
#ifdef NEW_BLOCK_CALL |
2189 | 524 |
# define BLOCK_ARG aBlock |
525 |
# 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
|
526 |
#else |
2189 | 527 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
528 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
529 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
530 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
531 |
for (; index < nIndex; index++) { |
2189 | 532 |
REGISTER OBJFUNC codeVal; |
2220 | 533 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
534 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
535 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
536 |
|
1136 | 537 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 538 |
if (__isNonNilObject(element)) { |
539 |
element = __WEAK_READ__(self, element); |
|
540 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
541 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2189 | 542 |
(*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
|
543 |
} else { |
2189 | 544 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
545 |
/* |
|
546 |
* arg is a compiled block with bytecode - |
|
547 |
* directly call interpreter without going through Block>>value |
|
548 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
549 |
#ifdef PASS_ARG_POINTER |
2189 | 550 |
__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
|
551 |
#else |
2189 | 552 |
__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
|
553 |
#endif |
2189 | 554 |
} else { |
555 |
/* |
|
556 |
* arg is something else - call it with #value |
|
557 |
*/ |
|
558 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
559 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
560 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
561 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
562 |
RETURN (self); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
563 |
|
2189 | 564 |
# undef BLOCK_ARG |
565 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
566 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
567 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
568 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
569 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
570 |
* 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
|
571 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
572 |
for (; index < nIndex; index++) { |
2216 | 573 |
OBJ element; |
574 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
575 |
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
|
576 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
577 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 578 |
if (__isNonNilObject(element)) { |
579 |
element = __WEAK_READ__(self, element); |
|
580 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
581 |
(*val.ilc_func)(aBlock, |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
582 |
@symbol(value:), |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
583 |
nil, &val, |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
584 |
element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
585 |
} |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
586 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
587 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
588 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
589 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
590 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
591 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 592 |
replaced by zero (due to a collected object). |
593 |
Be aware, that while indices are being enumerated, other |
|
594 |
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
|
595 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
596 |
self keysAndValuesDo:[:index :element | |
4310 | 597 |
element == 0 ifTrue:[ |
598 |
aBlock value:index |
|
599 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
600 |
] |
2271 | 601 |
|
602 |
"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
|
603 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
604 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
605 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
606 |
"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
|
607 |
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
|
608 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
609 |
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
|
610 |
changed before the block is called); this behavior is not guaranteed |
2271 | 611 |
with future versions. |
612 |
Be aware, that while indices are being enumerated, other |
|
613 |
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
|
614 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
615 |
self keysAndValuesDo:[:index :element | |
4310 | 616 |
element == 0 ifTrue:[ |
617 |
self at:index put:newValue. |
|
618 |
aBlock value:index. |
|
619 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
620 |
] |
2271 | 621 |
|
622 |
"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
|
623 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
624 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
625 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
626 |
"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
|
627 |
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
|
628 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
629 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
630 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
631 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
632 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
633 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
634 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
635 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
636 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
637 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
638 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
639 |
|
1136 | 640 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
641 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
642 |
if (__isBlockLike(aBlock) |
1136 | 643 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2189 | 644 |
{ |
645 |
/* |
|
646 |
* the most common case: a static compiled block, with home on the stack ... |
|
647 |
*/ |
|
648 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
649 |
|
2254 | 650 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
651 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
652 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
653 |
#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
|
654 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
655 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
656 |
# define BLOCK_ARG rHome |
2189 | 657 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
658 |
|
2189 | 659 |
rHome = __BlockInstPtr(aBlock)->b_home; |
660 |
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
|
661 |
#endif |
2189 | 662 |
{ |
663 |
for (; index < nIndex; index++) { |
|
2216 | 664 |
REGISTER OBJ element; |
665 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
666 |
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
|
667 |
if (element) { |
2189 | 668 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
669 |
__interruptL(@line); |
2189 | 670 |
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
|
671 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
672 |
|
4311 | 673 |
if (__isNonNilObject(element)) { |
674 |
element = __WEAK_READ__(self, element); |
|
675 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
676 |
if (element) { |
2189 | 677 |
(*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
|
678 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
679 |
} |
2189 | 680 |
} |
681 |
RETURN (self); |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
685 |
|
2189 | 686 |
/* |
687 |
* sorry, must check code-pointer in the loop |
|
688 |
* it could be recompiled or flushed |
|
689 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
690 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
691 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
692 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
693 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
694 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
695 |
# 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
|
696 |
# 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
|
697 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
698 |
|
2189 | 699 |
for (; index < nIndex; index++) { |
700 |
REGISTER OBJFUNC codeVal; |
|
2220 | 701 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
702 |
|
2189 | 703 |
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
|
704 |
if (element) { |
2189 | 705 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
706 |
__interruptL(@line); |
1903 | 707 |
element = __InstPtr(self)->i_instvars[index]; |
708 |
} |
|
4311 | 709 |
if (__isNonNilObject(element)) { |
710 |
element = __WEAK_READ__(self, element); |
|
711 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
712 |
if (element) { |
2189 | 713 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
714 |
(*codeVal)(BLOCK_ARG, element); |
|
715 |
} else { |
|
716 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
717 |
/* |
|
718 |
* arg is a compiled block with bytecode - |
|
719 |
* directly call interpreter without going through Block>>value |
|
720 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
721 |
#ifdef PASS_ARG_POINTER |
2189 | 722 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
723 |
#else |
2189 | 724 |
__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
|
725 |
#endif |
2189 | 726 |
} else { |
727 |
/* |
|
728 |
* arg is something else - call it with #value |
|
729 |
*/ |
|
730 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
731 |
} |
|
732 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
733 |
} |
2189 | 734 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
735 |
} |
2189 | 736 |
RETURN (self); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
737 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
738 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
739 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
740 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
741 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
742 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
743 |
* 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
|
744 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
745 |
for (; index < nIndex; index++) { |
2216 | 746 |
REGISTER OBJ element; |
747 |
||
2189 | 748 |
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
|
749 |
if (element) { |
2189 | 750 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
751 |
__interruptL(@line); |
1136 | 752 |
element = __InstPtr(self)->i_instvars[index]; |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
753 |
} |
4311 | 754 |
if (__isNonNilObject(element)) { |
755 |
element = __WEAK_READ__(self, element); |
|
756 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
757 |
if (element) { |
2189 | 758 |
(*val.ilc_func)(aBlock, |
759 |
@symbol(value:), |
|
760 |
nil, &val, |
|
761 |
element); |
|
762 |
} |
|
763 |
} |
|
764 |
} |
|
765 |
%}. |
|
766 |
^ self |
|
767 |
! |
|
768 |
||
769 |
validElementsDo:aBlock |
|
770 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
771 |
||
772 |
%{ |
|
773 |
REGISTER int index; |
|
774 |
int nIndex; |
|
775 |
static struct inlineCache val = _ILC1; |
|
776 |
||
777 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
778 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
779 |
if (__isBlockLike(aBlock) |
|
780 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
781 |
{ |
|
782 |
/* |
|
783 |
* the most common case: a static compiled block, with home on the stack ... |
|
784 |
*/ |
|
785 |
REGISTER OBJFUNC codeVal; |
|
786 |
||
2254 | 787 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
788 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
789 |
||
2189 | 790 |
#ifdef NEW_BLOCK_CALL |
791 |
# define BLOCK_ARG aBlock |
|
792 |
#else |
|
793 |
# define BLOCK_ARG rHome |
|
794 |
REGISTER OBJ rHome; |
|
795 |
||
796 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
797 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
798 |
#endif |
|
799 |
{ |
|
800 |
for (; index < nIndex; index++) { |
|
2216 | 801 |
REGISTER OBJ element; |
802 |
||
2189 | 803 |
element = __InstPtr(self)->i_instvars[index]; |
804 |
if (element && (element != __MKSMALLINT(0))) { |
|
805 |
if (InterruptPending != nil) { |
|
806 |
__interruptL(@line); |
|
807 |
element = __InstPtr(self)->i_instvars[index]; |
|
808 |
} |
|
809 |
||
4311 | 810 |
if (__isNonNilObject(element)) { |
811 |
element = __WEAK_READ__(self, element); |
|
812 |
} |
|
2189 | 813 |
if (element && (element != __MKSMALLINT(0))) { |
814 |
(*codeVal)(BLOCK_ARG, element); |
|
815 |
} |
|
816 |
} |
|
817 |
} |
|
818 |
RETURN (self); |
|
819 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
820 |
} |
2189 | 821 |
} |
822 |
||
823 |
/* |
|
824 |
* sorry, must check code-pointer in the loop |
|
825 |
* it could be recompiled or flushed |
|
826 |
*/ |
|
827 |
# undef BLOCK_ARG |
|
828 |
#ifdef NEW_BLOCK_CALL |
|
829 |
# define BLOCK_ARG aBlock |
|
830 |
# define IBLOCK_ARG nil |
|
831 |
#else |
|
832 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
833 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
834 |
#endif |
|
835 |
||
836 |
for (; index < nIndex; index++) { |
|
837 |
REGISTER OBJFUNC codeVal; |
|
2220 | 838 |
OBJ element; |
2189 | 839 |
|
840 |
element = __InstPtr(self)->i_instvars[index]; |
|
841 |
if (element && (element != __MKSMALLINT(0))) { |
|
842 |
if (InterruptPending != nil) { |
|
843 |
__interruptL(@line); |
|
844 |
element = __InstPtr(self)->i_instvars[index]; |
|
845 |
} |
|
4311 | 846 |
if (__isNonNilObject(element)) { |
847 |
element = __WEAK_READ__(self, element); |
|
848 |
} |
|
2189 | 849 |
if (element && (element != __MKSMALLINT(0))) { |
850 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
851 |
(*codeVal)(BLOCK_ARG, element); |
|
852 |
} else { |
|
853 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
854 |
/* |
|
855 |
* arg is a compiled block with bytecode - |
|
856 |
* directly call interpreter without going through Block>>value |
|
857 |
*/ |
|
858 |
#ifdef PASS_ARG_POINTER |
|
859 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
|
860 |
#else |
|
861 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
|
862 |
#endif |
|
863 |
} else { |
|
864 |
/* |
|
865 |
* arg is something else - call it with #value |
|
866 |
*/ |
|
867 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
868 |
} |
|
869 |
} |
|
870 |
} |
|
871 |
} |
|
872 |
} |
|
873 |
RETURN (self); |
|
874 |
||
875 |
# undef BLOCK_ARG |
|
876 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
877 |
} |
2189 | 878 |
|
879 |
/* |
|
880 |
* not a block - send it #value: |
|
881 |
*/ |
|
882 |
for (; index < nIndex; index++) { |
|
2216 | 883 |
REGISTER OBJ element; |
884 |
||
2189 | 885 |
element = __InstPtr(self)->i_instvars[index]; |
886 |
if (element && (element != __MKSMALLINT(0))) { |
|
887 |
if (InterruptPending != nil) { |
|
888 |
__interruptL(@line); |
|
889 |
element = __InstPtr(self)->i_instvars[index]; |
|
890 |
} |
|
4311 | 891 |
if (__isNonNilObject(element)) { |
892 |
element = __WEAK_READ__(self, element); |
|
893 |
} |
|
2189 | 894 |
if (element && (element != __MKSMALLINT(0))) { |
895 |
(*val.ilc_func)(aBlock, |
|
896 |
@symbol(value:), |
|
897 |
nil, &val, |
|
898 |
element); |
|
899 |
} |
|
900 |
} |
|
901 |
} |
|
604 | 902 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
903 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
904 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
905 |
|
603 | 906 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
907 |
|
603 | 908 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
909 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
910 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
911 |
|
603 | 912 |
dependents notNil ifTrue:[ |
2189 | 913 |
self changed:#ElementExpired with:nil. |
603 | 914 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
915 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
916 |
"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
|
917 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 918 |
! ! |
6 | 919 |
|
628 | 920 |
!WeakArray class methodsFor:'documentation'! |
921 |
||
922 |
version |
|
4730
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
923 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.56 1999-09-15 12:57:11 cg Exp $' |
628 | 924 |
! ! |
603 | 925 |
WeakArray initialize! |