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