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