author | Claus Gittinger <cg@exept.de> |
Thu, 12 Aug 1999 10:59:29 +0200 | |
changeset 4595 | 24446fd5d3e1 |
parent 4351 | 27cb4edec0e2 |
child 4730 | 278b9e735be7 |
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. |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
332 |
! ! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
333 |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
334 |
!WeakArray methodsFor:'dependents access'! |
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 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
337 |
"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
|
338 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
339 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
340 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
341 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
342 |
[ |
4310 | 343 |
|deps| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
344 |
|
4310 | 345 |
deps := dependents. |
346 |
"/ |
|
347 |
"/ store the very first dependent directly in |
|
348 |
"/ the dependents instVar |
|
349 |
"/ |
|
350 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
351 |
dependents := anObject |
|
352 |
] ifFalse:[ |
|
353 |
"/ |
|
354 |
"/ store more dependents in the dependents collection |
|
355 |
"/ |
|
356 |
deps isCollection ifTrue:[ |
|
357 |
deps add:anObject |
|
358 |
] ifFalse:[ |
|
359 |
deps == anObject ifFalse:[ |
|
360 |
dependents := (IdentitySet with:dependents with:anObject) |
|
361 |
] |
|
362 |
] |
|
363 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
364 |
] valueNowOrOnUnwindDo:[ |
4310 | 365 |
wasBlocked ifFalse:[ |
366 |
OperatingSystem unblockInterrupts |
|
367 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
368 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
369 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
370 |
"Modified: 8.1.1997 / 23:40:30 / cg" |
603 | 371 |
! |
372 |
||
373 |
dependents |
|
374 |
"return the dependents of the receiver" |
|
375 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
376 |
dependents isNil ifTrue:[^ #()]. |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
377 |
dependents isCollection ifTrue:[ |
4310 | 378 |
^ dependents |
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 |
^ IdentitySet with:dependents |
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
381 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
382 |
"Modified: / 27.10.1997 / 19:37:16 / cg" |
603 | 383 |
! |
384 |
||
385 |
dependents:aCollection |
|
386 |
"set the dependents of the receiver" |
|
387 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
388 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
389 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
390 |
aCollection size == 1 ifTrue:[ |
4310 | 391 |
dep := aCollection first. |
392 |
dep isCollection ifFalse:[ |
|
393 |
dependents := aCollection first. |
|
394 |
^ self |
|
395 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
396 |
]. |
603 | 397 |
dependents := aCollection |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
398 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
399 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
400 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
401 |
"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
|
402 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
403 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
404 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
405 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
406 |
deps notNil ifTrue:[ |
4310 | 407 |
deps isCollection ifTrue:[ |
408 |
deps do:aBlock |
|
409 |
] ifFalse:[ |
|
410 |
aBlock value:deps |
|
411 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
412 |
] |
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 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
415 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
416 |
"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
|
417 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
418 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
419 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
420 |
"/ 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
|
421 |
"/ 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
|
422 |
"/ 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
|
423 |
"/ faster execution. |
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 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
426 |
[ |
4310 | 427 |
|deps sz dep| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
428 |
|
4310 | 429 |
deps := dependents. |
430 |
deps notNil ifTrue:[ |
|
431 |
deps isCollection ifTrue:[ |
|
432 |
deps remove:anObject ifAbsent:[]. |
|
433 |
(sz := deps size) == 0 ifTrue:[ |
|
434 |
dependents := nil |
|
435 |
] ifFalse:[ |
|
436 |
sz == 1 ifTrue:[ |
|
437 |
(dep := deps first) isCollection ifFalse:[ |
|
438 |
dependents := dep |
|
439 |
] |
|
440 |
] |
|
441 |
] |
|
442 |
] ifFalse:[ |
|
443 |
deps == anObject ifTrue:[ |
|
444 |
dependents := nil |
|
445 |
] |
|
446 |
] |
|
447 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
448 |
] valueNowOrOnUnwindDo:[ |
4310 | 449 |
wasBlocked ifFalse:[ |
450 |
OperatingSystem unblockInterrupts |
|
451 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
452 |
] |
6 | 453 |
! ! |
454 |
||
1825 | 455 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
456 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
457 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
458 |
"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
|
459 |
- reimplemented for IGC readBarrier. |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
460 |
You dont have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
461 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
462 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
463 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
464 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
465 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
466 |
|
1136 | 467 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
468 |
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
|
469 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
470 |
if (__isBlockLike(aBlock) |
1136 | 471 |
&& (__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
|
472 |
{ |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
473 |
/* |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
474 |
* 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
|
475 |
*/ |
2189 | 476 |
REGISTER OBJFUNC codeVal; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
477 |
|
2254 | 478 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
479 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
480 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
481 |
#ifdef NEW_BLOCK_CALL |
2189 | 482 |
# 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
|
483 |
#else |
2189 | 484 |
# define BLOCK_ARG rHome |
485 |
REGISTER OBJ rHome; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
486 |
|
2189 | 487 |
rHome = __BlockInstPtr(aBlock)->b_home; |
488 |
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
|
489 |
#endif |
2189 | 490 |
{ |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
491 |
for (; index < nIndex; index++) { |
2216 | 492 |
OBJ element; |
493 |
||
2189 | 494 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
495 |
|
2189 | 496 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 497 |
if (__isNonNilObject(element)) { |
498 |
element = __WEAK_READ__(self, element); |
|
499 |
} |
|
2189 | 500 |
(*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
|
501 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
502 |
RETURN (self); |
2189 | 503 |
} |
2186
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 |
} |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
506 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
507 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
508 |
* 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
|
509 |
* 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
|
510 |
*/ |
2189 | 511 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
512 |
#ifdef NEW_BLOCK_CALL |
2189 | 513 |
# define BLOCK_ARG aBlock |
514 |
# 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
|
515 |
#else |
2189 | 516 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
517 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
518 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
519 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
520 |
for (; index < nIndex; index++) { |
2189 | 521 |
REGISTER OBJFUNC codeVal; |
2220 | 522 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
523 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
524 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
525 |
|
1136 | 526 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 527 |
if (__isNonNilObject(element)) { |
528 |
element = __WEAK_READ__(self, element); |
|
529 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
530 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2189 | 531 |
(*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
|
532 |
} else { |
2189 | 533 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
534 |
/* |
|
535 |
* arg is a compiled block with bytecode - |
|
536 |
* directly call interpreter without going through Block>>value |
|
537 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
538 |
#ifdef PASS_ARG_POINTER |
2189 | 539 |
__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
|
540 |
#else |
2189 | 541 |
__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
|
542 |
#endif |
2189 | 543 |
} else { |
544 |
/* |
|
545 |
* arg is something else - call it with #value |
|
546 |
*/ |
|
547 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
548 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
549 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
550 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
551 |
RETURN (self); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
552 |
|
2189 | 553 |
# undef BLOCK_ARG |
554 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
555 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
556 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
557 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
558 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
559 |
* 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
|
560 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
561 |
for (; index < nIndex; index++) { |
2216 | 562 |
OBJ element; |
563 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
564 |
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
|
565 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
566 |
element = __InstPtr(self)->i_instvars[index]; |
4311 | 567 |
if (__isNonNilObject(element)) { |
568 |
element = __WEAK_READ__(self, element); |
|
569 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
570 |
(*val.ilc_func)(aBlock, |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
571 |
@symbol(value:), |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
572 |
nil, &val, |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
573 |
element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
574 |
} |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
575 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
576 |
^ self |
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 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
579 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
580 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 581 |
replaced by zero (due to a collected object). |
582 |
Be aware, that while indices are being enumerated, other |
|
583 |
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
|
584 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
585 |
self keysAndValuesDo:[:index :element | |
4310 | 586 |
element == 0 ifTrue:[ |
587 |
aBlock value:index |
|
588 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
589 |
] |
2271 | 590 |
|
591 |
"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
|
592 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
593 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
594 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
595 |
"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
|
596 |
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
|
597 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
598 |
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
|
599 |
changed before the block is called); this behavior is not guaranteed |
2271 | 600 |
with future versions. |
601 |
Be aware, that while indices are being enumerated, other |
|
602 |
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
|
603 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
604 |
self keysAndValuesDo:[:index :element | |
4310 | 605 |
element == 0 ifTrue:[ |
606 |
self at:index put:newValue. |
|
607 |
aBlock value:index. |
|
608 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
609 |
] |
2271 | 610 |
|
611 |
"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
|
612 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
613 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
614 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
615 |
"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
|
616 |
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
|
617 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
618 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
619 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
620 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
621 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
622 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
623 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
624 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
625 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
626 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
627 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
628 |
|
1136 | 629 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
630 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
631 |
if (__isBlockLike(aBlock) |
1136 | 632 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2189 | 633 |
{ |
634 |
/* |
|
635 |
* the most common case: a static compiled block, with home on the stack ... |
|
636 |
*/ |
|
637 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
638 |
|
2254 | 639 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
640 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
641 |
||
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
642 |
#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
|
643 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
644 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
645 |
# define BLOCK_ARG rHome |
2189 | 646 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
647 |
|
2189 | 648 |
rHome = __BlockInstPtr(aBlock)->b_home; |
649 |
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
|
650 |
#endif |
2189 | 651 |
{ |
652 |
for (; index < nIndex; index++) { |
|
2216 | 653 |
REGISTER OBJ element; |
654 |
||
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
655 |
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
|
656 |
if (element) { |
2189 | 657 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
658 |
__interruptL(@line); |
2189 | 659 |
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
|
660 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
661 |
|
4311 | 662 |
if (__isNonNilObject(element)) { |
663 |
element = __WEAK_READ__(self, element); |
|
664 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
665 |
if (element) { |
2189 | 666 |
(*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
|
667 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
668 |
} |
2189 | 669 |
} |
670 |
RETURN (self); |
|
671 |
} |
|
672 |
} |
|
673 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
674 |
|
2189 | 675 |
/* |
676 |
* sorry, must check code-pointer in the loop |
|
677 |
* it could be recompiled or flushed |
|
678 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
679 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
680 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
681 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
682 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
683 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
684 |
# 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
|
685 |
# 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
|
686 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
687 |
|
2189 | 688 |
for (; index < nIndex; index++) { |
689 |
REGISTER OBJFUNC codeVal; |
|
2220 | 690 |
OBJ element; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
691 |
|
2189 | 692 |
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
|
693 |
if (element) { |
2189 | 694 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
695 |
__interruptL(@line); |
1903 | 696 |
element = __InstPtr(self)->i_instvars[index]; |
697 |
} |
|
4311 | 698 |
if (__isNonNilObject(element)) { |
699 |
element = __WEAK_READ__(self, element); |
|
700 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
701 |
if (element) { |
2189 | 702 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
703 |
(*codeVal)(BLOCK_ARG, element); |
|
704 |
} else { |
|
705 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
706 |
/* |
|
707 |
* arg is a compiled block with bytecode - |
|
708 |
* directly call interpreter without going through Block>>value |
|
709 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
710 |
#ifdef PASS_ARG_POINTER |
2189 | 711 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
712 |
#else |
2189 | 713 |
__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
|
714 |
#endif |
2189 | 715 |
} else { |
716 |
/* |
|
717 |
* arg is something else - call it with #value |
|
718 |
*/ |
|
719 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
720 |
} |
|
721 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
722 |
} |
2189 | 723 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
724 |
} |
2189 | 725 |
RETURN (self); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
726 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
727 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
728 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
729 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
730 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
731 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
732 |
* 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
|
733 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
734 |
for (; index < nIndex; index++) { |
2216 | 735 |
REGISTER OBJ element; |
736 |
||
2189 | 737 |
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
|
738 |
if (element) { |
2189 | 739 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
740 |
__interruptL(@line); |
1136 | 741 |
element = __InstPtr(self)->i_instvars[index]; |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
742 |
} |
4311 | 743 |
if (__isNonNilObject(element)) { |
744 |
element = __WEAK_READ__(self, element); |
|
745 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
746 |
if (element) { |
2189 | 747 |
(*val.ilc_func)(aBlock, |
748 |
@symbol(value:), |
|
749 |
nil, &val, |
|
750 |
element); |
|
751 |
} |
|
752 |
} |
|
753 |
} |
|
754 |
%}. |
|
755 |
^ self |
|
756 |
! |
|
757 |
||
758 |
validElementsDo:aBlock |
|
759 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
760 |
||
761 |
%{ |
|
762 |
REGISTER int index; |
|
763 |
int nIndex; |
|
764 |
static struct inlineCache val = _ILC1; |
|
765 |
||
766 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
767 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
768 |
if (__isBlockLike(aBlock) |
|
769 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
770 |
{ |
|
771 |
/* |
|
772 |
* the most common case: a static compiled block, with home on the stack ... |
|
773 |
*/ |
|
774 |
REGISTER OBJFUNC codeVal; |
|
775 |
||
2254 | 776 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
777 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
778 |
||
2189 | 779 |
#ifdef NEW_BLOCK_CALL |
780 |
# define BLOCK_ARG aBlock |
|
781 |
#else |
|
782 |
# define BLOCK_ARG rHome |
|
783 |
REGISTER OBJ rHome; |
|
784 |
||
785 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
786 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
787 |
#endif |
|
788 |
{ |
|
789 |
for (; index < nIndex; index++) { |
|
2216 | 790 |
REGISTER OBJ element; |
791 |
||
2189 | 792 |
element = __InstPtr(self)->i_instvars[index]; |
793 |
if (element && (element != __MKSMALLINT(0))) { |
|
794 |
if (InterruptPending != nil) { |
|
795 |
__interruptL(@line); |
|
796 |
element = __InstPtr(self)->i_instvars[index]; |
|
797 |
} |
|
798 |
||
4311 | 799 |
if (__isNonNilObject(element)) { |
800 |
element = __WEAK_READ__(self, element); |
|
801 |
} |
|
2189 | 802 |
if (element && (element != __MKSMALLINT(0))) { |
803 |
(*codeVal)(BLOCK_ARG, element); |
|
804 |
} |
|
805 |
} |
|
806 |
} |
|
807 |
RETURN (self); |
|
808 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
809 |
} |
2189 | 810 |
} |
811 |
||
812 |
/* |
|
813 |
* sorry, must check code-pointer in the loop |
|
814 |
* it could be recompiled or flushed |
|
815 |
*/ |
|
816 |
# undef BLOCK_ARG |
|
817 |
#ifdef NEW_BLOCK_CALL |
|
818 |
# define BLOCK_ARG aBlock |
|
819 |
# define IBLOCK_ARG nil |
|
820 |
#else |
|
821 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
822 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
823 |
#endif |
|
824 |
||
825 |
for (; index < nIndex; index++) { |
|
826 |
REGISTER OBJFUNC codeVal; |
|
2220 | 827 |
OBJ element; |
2189 | 828 |
|
829 |
element = __InstPtr(self)->i_instvars[index]; |
|
830 |
if (element && (element != __MKSMALLINT(0))) { |
|
831 |
if (InterruptPending != nil) { |
|
832 |
__interruptL(@line); |
|
833 |
element = __InstPtr(self)->i_instvars[index]; |
|
834 |
} |
|
4311 | 835 |
if (__isNonNilObject(element)) { |
836 |
element = __WEAK_READ__(self, element); |
|
837 |
} |
|
2189 | 838 |
if (element && (element != __MKSMALLINT(0))) { |
839 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
840 |
(*codeVal)(BLOCK_ARG, element); |
|
841 |
} else { |
|
842 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
843 |
/* |
|
844 |
* arg is a compiled block with bytecode - |
|
845 |
* directly call interpreter without going through Block>>value |
|
846 |
*/ |
|
847 |
#ifdef PASS_ARG_POINTER |
|
848 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
|
849 |
#else |
|
850 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
|
851 |
#endif |
|
852 |
} else { |
|
853 |
/* |
|
854 |
* arg is something else - call it with #value |
|
855 |
*/ |
|
856 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
857 |
} |
|
858 |
} |
|
859 |
} |
|
860 |
} |
|
861 |
} |
|
862 |
RETURN (self); |
|
863 |
||
864 |
# undef BLOCK_ARG |
|
865 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
866 |
} |
2189 | 867 |
|
868 |
/* |
|
869 |
* not a block - send it #value: |
|
870 |
*/ |
|
871 |
for (; index < nIndex; index++) { |
|
2216 | 872 |
REGISTER OBJ element; |
873 |
||
2189 | 874 |
element = __InstPtr(self)->i_instvars[index]; |
875 |
if (element && (element != __MKSMALLINT(0))) { |
|
876 |
if (InterruptPending != nil) { |
|
877 |
__interruptL(@line); |
|
878 |
element = __InstPtr(self)->i_instvars[index]; |
|
879 |
} |
|
4311 | 880 |
if (__isNonNilObject(element)) { |
881 |
element = __WEAK_READ__(self, element); |
|
882 |
} |
|
2189 | 883 |
if (element && (element != __MKSMALLINT(0))) { |
884 |
(*val.ilc_func)(aBlock, |
|
885 |
@symbol(value:), |
|
886 |
nil, &val, |
|
887 |
element); |
|
888 |
} |
|
889 |
} |
|
890 |
} |
|
604 | 891 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
892 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
893 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
894 |
|
603 | 895 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
896 |
|
603 | 897 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
898 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
899 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
900 |
|
603 | 901 |
dependents notNil ifTrue:[ |
2189 | 902 |
self changed:#ElementExpired with:nil. |
603 | 903 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
904 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
905 |
"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
|
906 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 907 |
! ! |
6 | 908 |
|
628 | 909 |
!WeakArray class methodsFor:'documentation'! |
910 |
||
911 |
version |
|
4351 | 912 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.55 1999-07-07 18:43:36 cg Exp $' |
628 | 913 |
! ! |
603 | 914 |
WeakArray initialize! |