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