author | Claus Gittinger <cg@exept.de> |
Fri, 13 Dec 2019 15:12:31 +0100 | |
changeset 25111 | 457334bdb9eb |
parent 24622 | 031078d2cdba |
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:] |
22312 | 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 |
|
22312 | 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 |
|
22312 | 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:] |
22312 | 109 |
OBJ-HEADER + (size * ptr-size) + ptr-size |
110 |
+ sizeof(dependents-collection) |
|
4062 | 111 |
|
1290 | 112 |
[author:] |
22312 | 113 |
Claus Gittinger |
1290 | 114 |
|
1263 | 115 |
[See also:] |
22312 | 116 |
Array WeakIdentitySet WeakIdentityDictionary Registry |
117 |
Model |
|
6 | 118 |
" |
119 |
! ! |
|
120 |
||
159 | 121 |
!WeakArray class methodsFor:'initialization'! |
122 |
||
123 |
initialize |
|
22312 | 124 |
"adjust my class flags and setup the private signal" |
159 | 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) { |
22312 | 183 |
/* |
184 |
* the behavior of __addShadowObject() in case of overflowing |
|
185 |
* VM-table space can be controlled by the second argument: |
|
186 |
* if it's 0, the weakObject is not registered, and false |
|
187 |
* is returned. |
|
188 |
* if it's 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 |
|
22312 | 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:[ |
|
22312 | 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 |
] |
21440 | 249 |
|
250 |
"Modified: / 13-02-2017 / 20:34:24 / cg" |
|
6 | 251 |
! ! |
252 |
||
603 | 253 |
!WeakArray methodsFor:'accessing'! |
254 |
||
255 |
at:index |
|
256 |
"return the indexed instance variable with index, anInteger. |
|
12841 | 257 |
Reimplemented here for IGC readBarrier. |
20813 | 258 |
(You don't have to understand this.)" |
603 | 259 |
|
260 |
^ self basicAt:index |
|
2271 | 261 |
|
262 |
"Modified: 25.1.1997 / 13:41:25 / cg" |
|
603 | 263 |
! |
6 | 264 |
|
16397 | 265 |
at:index ifAbsent:exceptionValue |
266 |
"return the indexed instance variable with index, anInteger, |
|
267 |
or exceptionValue if the index is invalid. |
|
268 |
Reimplemented here for IGC readBarrier. |
|
20813 | 269 |
(You don't have to understand this.)" |
16397 | 270 |
|
271 |
(index < 0 or:[index > self size]) ifTrue:[^ exceptionValue]. |
|
272 |
^ self at:index |
|
273 |
! |
|
274 |
||
19625 | 275 |
at:index ifInvalid:exceptionalValue |
13013 | 276 |
"return the indexed instance variable with index, anInteger, |
277 |
but only if still valid; otherwise return the value from exceptionalValue" |
|
278 |
||
279 |
|el| |
|
280 |
||
281 |
el := self basicAt:index. |
|
18603 | 282 |
el class == SmallInteger ifTrue:[ |
22312 | 283 |
^ exceptionalValue value |
13013 | 284 |
]. |
285 |
^ el |
|
286 |
! |
|
287 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
288 |
at:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
289 |
"store someObject in the weakArray at some index." |
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 |
^ self basicAt:index put:someObject |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
292 |
! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
293 |
|
603 | 294 |
basicAt:index |
295 |
"return the indexed instance variable with index, anInteger. |
|
12841 | 296 |
Reimplemented here for IGC readBarrier. |
297 |
(You don't have to understand this.)" |
|
603 | 298 |
|
299 |
%{ /* NOCONTEXT */ |
|
300 |
||
301 |
REGISTER int indx; |
|
302 |
REGISTER unsigned int nIndex; |
|
303 |
OBJ el; |
|
6 | 304 |
|
603 | 305 |
if (__isSmallInteger(index)) { |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
306 |
indx = __intVal(index) - 1; |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
307 |
if (indx >= 0) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
308 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
309 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
310 |
if (indx < nIndex) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
311 |
el = __InstPtr(self)->i_instvars[indx]; |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
312 |
if (__isNonNilObject(el)) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
313 |
el = __WEAK_READ__(self, el); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
314 |
#ifdef WEAK_DEBUG |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
315 |
if (! __ISVALIDOBJECT(el)) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
316 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
23571
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
317 |
__dumpObject__(el, __LINE__,__FILE__); |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
318 |
el = nil; |
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 |
#endif |
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 |
RETURN (el); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
323 |
} |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
324 |
} |
603 | 325 |
} |
326 |
%}. |
|
327 |
^ 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
|
328 |
! |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
329 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
330 |
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
|
331 |
"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
|
332 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
333 |
%{ /* NOCONTEXT */ |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
334 |
REGISTER int indx; |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
335 |
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
|
336 |
|
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
337 |
if (__isSmallInteger(index)) { |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
338 |
indx = __intVal(index) - 1; |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
339 |
if (indx >= 0) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
340 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
341 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
342 |
if (indx < nIndex) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
343 |
REGISTER OBJ el = someObject; |
4310 | 344 |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
345 |
__InstPtr(self)->i_instvars[indx] = el; |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
346 |
if (__isNonNilObject(el)) { |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
347 |
__STORE(self, el); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
348 |
__WEAK_WRITE__(self, 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 |
RETURN (el); |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
351 |
} |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
352 |
} |
2644
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
353 |
} |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
354 |
%}. |
b6e66194e355
need write barrier to keep track of newSpace refs in weakArrays
Claus Gittinger <cg@exept.de>
parents:
2318
diff
changeset
|
355 |
"/ 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
|
356 |
^ 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
|
357 |
! ! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
358 |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
359 |
!WeakArray methodsFor:'copying'! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
360 |
|
24184 | 361 |
skipInstvarIndexInDeepCopy:index |
362 |
"a helper for deepCopy; only indices for which this method returns |
|
363 |
false are copied in a deep copy." |
|
364 |
||
365 |
^ index == 1 "/ skip dependents |
|
366 |
! ! |
|
367 |
||
368 |
!WeakArray methodsFor:'copying-private'! |
|
369 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
370 |
postCopy |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
371 |
"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
|
372 |
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
|
373 |
Q: who copies weakArrays ?" |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
374 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
375 |
dependents := nil. |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
376 |
self registerAsWeakArray. |
4730
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
377 |
! |
278b9e735be7
deepCopy fix (do not copy dependents)
Claus Gittinger <cg@exept.de>
parents:
4351
diff
changeset
|
378 |
|
8931 | 379 |
postDeepCopy |
380 |
dependents := nil. |
|
381 |
self registerAsWeakArray. |
|
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
382 |
! ! |
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
383 |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
384 |
!WeakArray methodsFor:'dependents access'! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
385 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
386 |
addDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
387 |
"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
|
388 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
389 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
390 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
391 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
392 |
[ |
22312 | 393 |
|deps| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
394 |
|
22312 | 395 |
deps := dependents. |
396 |
"/ |
|
397 |
"/ store the very first dependent directly in |
|
398 |
"/ the dependents instVar |
|
399 |
"/ |
|
400 |
(deps isNil and:[anObject isCollection not]) ifTrue:[ |
|
401 |
dependents := anObject |
|
402 |
] ifFalse:[ |
|
403 |
"/ |
|
404 |
"/ store more dependents in the dependents collection |
|
405 |
"/ |
|
406 |
deps isCollection ifTrue:[ |
|
407 |
deps add:anObject |
|
408 |
] ifFalse:[ |
|
409 |
deps ~~ anObject ifTrue:[ |
|
410 |
deps isNil ifTrue:[ |
|
411 |
dependents := IdentitySet with:anObject. |
|
412 |
] ifFalse:[ |
|
413 |
dependents := IdentitySet with:deps with:anObject. |
|
414 |
] |
|
415 |
] |
|
416 |
] |
|
417 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
418 |
] ensure:[ |
22312 | 419 |
wasBlocked ifFalse:[ |
420 |
OperatingSystem unblockInterrupts |
|
421 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
422 |
] |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
423 |
|
21924 | 424 |
"Modified: / 08-01-1997 / 23:40:30 / cg" |
425 |
"Modified: / 23-06-2017 / 10:43:20 / stefan" |
|
603 | 426 |
! |
427 |
||
12841 | 428 |
dependents |
603 | 429 |
"return the dependents of the receiver" |
430 |
||
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
431 |
dependents isNil ifTrue:[^ #()]. |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
432 |
dependents isCollection ifTrue:[ |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
433 |
^ dependents |
2305
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 |
^ IdentitySet with:dependents |
3056
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
436 |
|
e1eae509aadb
dependents now always returns a collection
Claus Gittinger <cg@exept.de>
parents:
2644
diff
changeset
|
437 |
"Modified: / 27.10.1997 / 19:37:16 / cg" |
603 | 438 |
! |
439 |
||
22536 | 440 |
dependents:aCollectionOrNil |
603 | 441 |
"set the dependents of the receiver" |
442 |
||
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
443 |
|dep| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
444 |
|
22536 | 445 |
aCollectionOrNil size == 1 ifTrue:[ |
23571
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
446 |
dep := aCollectionOrNil first. |
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
447 |
dep isCollection ifFalse:[ |
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
448 |
dependents := dep. |
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
449 |
^ self |
4aa9bc1a2076
extra filename arg to __dumpObject__
Claus Gittinger <cg@exept.de>
parents:
22536
diff
changeset
|
450 |
] |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
451 |
]. |
22536 | 452 |
dependents := aCollectionOrNil |
453 |
||
454 |
"Modified: / 07-02-2018 / 12:01:41 / stefan" |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
455 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
456 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
457 |
dependentsDo:aBlock |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
458 |
"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
|
459 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
460 |
|deps| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
461 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
462 |
deps := dependents. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
463 |
deps notNil ifTrue:[ |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
464 |
deps isCollection ifTrue:[ |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
465 |
deps do:aBlock |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
466 |
] ifFalse:[ |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
467 |
aBlock value:deps |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
468 |
] |
2305
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 |
! |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
471 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
472 |
removeDependent:anObject |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
473 |
"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
|
474 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
475 |
|wasBlocked| |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
476 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
477 |
"/ 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
|
478 |
"/ 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
|
479 |
"/ 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
|
480 |
"/ faster execution. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
481 |
|
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
482 |
wasBlocked := OperatingSystem blockInterrupts. |
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
483 |
[ |
22312 | 484 |
|deps sz dep| |
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
485 |
|
22312 | 486 |
deps := dependents. |
487 |
deps notNil ifTrue:[ |
|
488 |
deps isCollection ifTrue:[ |
|
489 |
dep := deps remove:anObject ifAbsent:[]. |
|
490 |
"if dep is nil, nothing has changed" |
|
491 |
dep notNil ifTrue:[ |
|
492 |
(sz := deps size) == 0 ifTrue:[ |
|
493 |
dependents := nil |
|
494 |
] ifFalse:[ |
|
495 |
sz == 1 ifTrue:[ |
|
496 |
(dep := deps first) isCollection ifFalse:[ |
|
497 |
dependents := dep |
|
498 |
] |
|
499 |
] |
|
500 |
]. |
|
501 |
]. |
|
502 |
] ifFalse:[ |
|
503 |
deps == anObject ifTrue:[ |
|
504 |
dependents := nil |
|
505 |
] |
|
506 |
] |
|
507 |
] |
|
6421
58dca33cf0fc
#valueNowOrOnUnwindDo: -> #ensure:
Claus Gittinger <cg@exept.de>
parents:
5454
diff
changeset
|
508 |
] ensure:[ |
22312 | 509 |
wasBlocked ifFalse:[ |
510 |
OperatingSystem unblockInterrupts |
|
511 |
] |
|
2305
1413b683d299
made it a subclass of ArrayedCollection - avoid inheriting inprotected
Claus Gittinger <cg@exept.de>
parents:
2271
diff
changeset
|
512 |
] |
6 | 513 |
! ! |
514 |
||
1825 | 515 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
516 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
517 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
518 |
"evaluate the argument, aBlock for each element in the collection. |
12841 | 519 |
- reimplemented for IGC readBarrier. |
18627 | 520 |
You don't have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
521 |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
522 |
|element| |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
523 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
524 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
525 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
526 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
527 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
528 |
|
1136 | 529 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
530 |
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
|
531 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
532 |
if (__isBlockLike(aBlock) |
8913 | 533 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
24622 | 534 |
{ |
535 |
/* |
|
536 |
* the most common case: a static compiled block, with home on the stack ... |
|
537 |
*/ |
|
538 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
539 |
|
24622 | 540 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
541 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 542 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
543 |
#ifdef NEW_BLOCK_CALL |
2189 | 544 |
# 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
|
545 |
#else |
2189 | 546 |
# define BLOCK_ARG rHome |
24622 | 547 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
548 |
|
24622 | 549 |
rHome = __BlockInstPtr(aBlock)->b_home; |
550 |
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
|
551 |
#endif |
24622 | 552 |
{ |
553 |
for (; index < nIndex; index++) { |
|
554 |
if (InterruptPending != nil) __interruptL(@line); |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
555 |
|
24622 | 556 |
element = __InstPtr(self)->i_instvars[index]; |
557 |
if (__isNonNilObject(element)) { |
|
558 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
559 |
#ifdef WEAK_DEBUG |
24622 | 560 |
if (! __ISVALIDOBJECT(element)) { |
561 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
562 |
__dumpObject__(element, __LINE__,__FILE__); |
|
563 |
element = nil; |
|
564 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
565 |
#endif |
24622 | 566 |
} |
567 |
(*codeVal)(BLOCK_ARG, element); |
|
568 |
} |
|
569 |
RETURN (self); |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
573 |
|
24622 | 574 |
/* |
575 |
* sorry, must check code-pointer in the loop |
|
576 |
* it could be recompiled or flushed |
|
577 |
*/ |
|
2189 | 578 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
579 |
#ifdef NEW_BLOCK_CALL |
2189 | 580 |
# define BLOCK_ARG aBlock |
581 |
# 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
|
582 |
#else |
2189 | 583 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
584 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
585 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
586 |
|
24622 | 587 |
for (; index < nIndex; index++) { |
588 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
589 |
|
24622 | 590 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
591 |
|
24622 | 592 |
element = __InstPtr(self)->i_instvars[index]; |
593 |
if (__isNonNilObject(element)) { |
|
594 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
595 |
#ifdef WEAK_DEBUG |
24622 | 596 |
if (! __ISVALIDOBJECT(element)) { |
597 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
598 |
__dumpObject__(element, __LINE__,__FILE__); |
|
599 |
element = nil; |
|
600 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
601 |
#endif |
24622 | 602 |
} |
603 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
604 |
(*codeVal)(BLOCK_ARG, element); |
|
605 |
} else { |
|
606 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
607 |
/* |
|
608 |
* arg is a compiled block with bytecode - |
|
609 |
* directly call interpreter without going through Block>>value |
|
610 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
611 |
#ifdef PASS_ARG_POINTER |
24622 | 612 |
__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
|
613 |
#else |
24622 | 614 |
__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
|
615 |
#endif |
24622 | 616 |
} else { |
617 |
/* |
|
618 |
* arg is something else - call it with #value |
|
619 |
*/ |
|
620 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
621 |
} |
|
622 |
} |
|
623 |
} |
|
624 |
RETURN (self); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
625 |
|
2189 | 626 |
# undef BLOCK_ARG |
627 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
628 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
629 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
630 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
631 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
632 |
* 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
|
633 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
634 |
for (; index < nIndex; index++) { |
24622 | 635 |
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
|
636 |
|
24622 | 637 |
element = __InstPtr(self)->i_instvars[index]; |
638 |
if (__isNonNilObject(element)) { |
|
639 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
640 |
#ifdef WEAK_DEBUG |
24622 | 641 |
if (! __ISVALIDOBJECT(element)) { |
642 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
643 |
__dumpObject__(element, __LINE__,__FILE__); |
|
644 |
element = nil; |
|
645 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
646 |
#endif |
24622 | 647 |
} |
648 |
(*val.ilc_func)(aBlock, |
|
649 |
@symbol(value:), |
|
650 |
nil, &val, |
|
651 |
element); |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
652 |
} |
5454 | 653 |
RETURN (self); |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
654 |
%}. |
24622 | 655 |
super do:[:each | |
656 |
each notNil ifTrue:[aBlock value:each] |
|
657 |
] |
|
18627 | 658 |
|
659 |
"Modified: / 23-07-2015 / 15:35:24 / cg" |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
660 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
661 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
662 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
663 |
"evaluate the argument, aBlock for all indices where elements have been |
2271 | 664 |
replaced by zero (due to a collected object). |
665 |
Be aware, that while indices are being enumerated, other |
|
666 |
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
|
667 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
668 |
self keysAndValuesDo:[:index :element | |
18603 | 669 |
element class == SmallInteger ifTrue:[ |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
670 |
aBlock value:index |
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
671 |
] |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
672 |
] |
2271 | 673 |
|
674 |
"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
|
675 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
676 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
677 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
678 |
"evaluate the argument, aBlock for all indices where elements have been |
20040 | 679 |
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
|
680 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
681 |
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
|
682 |
changed before the block is called); this behavior is not guaranteed |
2271 | 683 |
with future versions. |
684 |
Be aware, that while indices are being enumerated, other |
|
685 |
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
|
686 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
687 |
self keysAndValuesDo:[:index :element | |
22312 | 688 |
element class == SmallInteger ifTrue:[ |
689 |
self at:index put:newValue. |
|
690 |
aBlock value:index. |
|
691 |
] |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
692 |
] |
2271 | 693 |
|
694 |
"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
|
695 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
696 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
697 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
698 |
"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
|
699 |
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
|
700 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
701 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
702 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
703 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
704 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
705 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
706 |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
707 |
|element| |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
708 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
709 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
710 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
711 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
712 |
|
1136 | 713 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
714 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
715 |
if (__isBlockLike(aBlock) |
8913 | 716 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
24622 | 717 |
{ |
718 |
/* |
|
719 |
* the most common case: a static compiled block, with home on the stack ... |
|
720 |
*/ |
|
721 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
722 |
|
24622 | 723 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
724 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 725 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
726 |
#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
|
727 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
728 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
729 |
# define BLOCK_ARG rHome |
24622 | 730 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
731 |
|
24622 | 732 |
rHome = __BlockInstPtr(aBlock)->b_home; |
733 |
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
|
734 |
#endif |
24622 | 735 |
{ |
736 |
for (; index < nIndex; index++) { |
|
737 |
element = __InstPtr(self)->i_instvars[index]; |
|
738 |
if (element) { |
|
739 |
if (InterruptPending != nil) { |
|
740 |
__interruptL(@line); |
|
741 |
element = __InstPtr(self)->i_instvars[index]; |
|
742 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
743 |
|
24622 | 744 |
if (__isNonNilObject(element)) { |
745 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
746 |
#ifdef WEAK_DEBUG |
24622 | 747 |
if (! __ISVALIDOBJECT(element)) { |
748 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
749 |
__dumpObject__(element, __LINE__,__FILE__); |
|
750 |
element = nil; |
|
751 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
752 |
#endif |
24622 | 753 |
} |
754 |
if (element) { |
|
755 |
(*codeVal)(BLOCK_ARG, element); |
|
756 |
} |
|
757 |
} |
|
758 |
} |
|
759 |
RETURN (self); |
|
760 |
} |
|
761 |
} |
|
762 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
763 |
|
24622 | 764 |
/* |
765 |
* sorry, must check code-pointer in the loop |
|
766 |
* it could be recompiled or flushed |
|
767 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
768 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
769 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
770 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
771 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
772 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
773 |
# 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
|
774 |
# 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
|
775 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
776 |
|
24622 | 777 |
for (; index < nIndex; index++) { |
778 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
779 |
|
24622 | 780 |
element = __InstPtr(self)->i_instvars[index]; |
781 |
if (element) { |
|
782 |
if (InterruptPending != nil) { |
|
783 |
__interruptL(@line); |
|
784 |
element = __InstPtr(self)->i_instvars[index]; |
|
785 |
} |
|
786 |
if (__isNonNilObject(element)) { |
|
787 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
788 |
#ifdef WEAK_DEBUG |
24622 | 789 |
if (! __ISVALIDOBJECT(element)) { |
790 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
791 |
__dumpObject__(element, __LINE__,__FILE__); |
|
792 |
element = nil; |
|
793 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
794 |
#endif |
24622 | 795 |
} |
796 |
if (element) { |
|
797 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
798 |
(*codeVal)(BLOCK_ARG, element); |
|
799 |
} else { |
|
800 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
801 |
/* |
|
802 |
* arg is a compiled block with bytecode - |
|
803 |
* directly call interpreter without going through Block>>value |
|
804 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
805 |
#ifdef PASS_ARG_POINTER |
24622 | 806 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
807 |
#else |
24622 | 808 |
__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
|
809 |
#endif |
24622 | 810 |
} else { |
811 |
/* |
|
812 |
* arg is something else - call it with #value |
|
813 |
*/ |
|
814 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
815 |
} |
|
816 |
} |
|
817 |
} |
|
818 |
} |
|
819 |
} |
|
820 |
RETURN (self); |
|
2186
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 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
823 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
824 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
825 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
826 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
827 |
* 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
|
828 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
829 |
for (; index < nIndex; index++) { |
24622 | 830 |
element = __InstPtr(self)->i_instvars[index]; |
831 |
if (element) { |
|
832 |
if (InterruptPending != nil) { |
|
833 |
__interruptL(@line); |
|
834 |
element = __InstPtr(self)->i_instvars[index]; |
|
835 |
} |
|
836 |
if (__isNonNilObject(element)) { |
|
837 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
838 |
#ifdef WEAK_DEBUG |
24622 | 839 |
if (! __ISVALIDOBJECT(element)) { |
840 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
841 |
__dumpObject__(element, __LINE__,__FILE__); |
|
842 |
element = nil; |
|
843 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
844 |
#endif |
24622 | 845 |
} |
846 |
if (element) { |
|
847 |
(*val.ilc_func)(aBlock, |
|
848 |
@symbol(value:), |
|
849 |
nil, &val, |
|
850 |
element); |
|
851 |
} |
|
852 |
} |
|
2189 | 853 |
} |
5454 | 854 |
RETURN (self); |
2189 | 855 |
%}. |
24622 | 856 |
super do:[:each | |
857 |
each notNil ifTrue:[aBlock value:each] |
|
858 |
] |
|
2189 | 859 |
! |
860 |
||
861 |
validElementsDo:aBlock |
|
18627 | 862 |
"evaluate the argument, aBlock for each non-nil/non-evacuated element" |
2189 | 863 |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
864 |
|element| |
2189 | 865 |
%{ |
866 |
REGISTER int index; |
|
867 |
int nIndex; |
|
868 |
static struct inlineCache val = _ILC1; |
|
869 |
||
870 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
871 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
872 |
if (__isBlockLike(aBlock) |
|
8913 | 873 |
&& (__BlockInstPtr(aBlock)->b_nargs == __mkSmallInteger(1))) { |
24622 | 874 |
{ |
875 |
/* |
|
876 |
* the most common case: a static compiled block, with home on the stack ... |
|
877 |
*/ |
|
878 |
REGISTER OBJFUNC codeVal; |
|
2189 | 879 |
|
24622 | 880 |
if (((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) |
881 |
&& (! ((INT)(__BlockInstPtr(aBlock)->b_flags) & __MASKSMALLINT(F_DYNAMIC)))) { |
|
2254 | 882 |
|
2189 | 883 |
#ifdef NEW_BLOCK_CALL |
884 |
# define BLOCK_ARG aBlock |
|
885 |
#else |
|
886 |
# define BLOCK_ARG rHome |
|
24622 | 887 |
REGISTER OBJ rHome; |
2189 | 888 |
|
24622 | 889 |
rHome = __BlockInstPtr(aBlock)->b_home; |
890 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
2189 | 891 |
#endif |
24622 | 892 |
{ |
893 |
for (; index < nIndex; index++) { |
|
894 |
element = __InstPtr(self)->i_instvars[index]; |
|
895 |
if (__isNonNilObject(element)) { |
|
896 |
if (InterruptPending != nil) { |
|
897 |
__interruptL(@line); |
|
898 |
element = __InstPtr(self)->i_instvars[index]; |
|
899 |
} |
|
2189 | 900 |
|
24622 | 901 |
if (__isNonNilObject(element)) { |
902 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
903 |
#ifdef WEAK_DEBUG |
24622 | 904 |
if (! __ISVALIDOBJECT(element)) { |
905 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
906 |
__dumpObject__(element, __LINE__,__FILE__); |
|
907 |
element = nil; |
|
908 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
909 |
#endif |
24622 | 910 |
if (__isNonNilObject(element)) { |
911 |
(*codeVal)(BLOCK_ARG, element); |
|
912 |
} |
|
913 |
} |
|
914 |
} |
|
915 |
} |
|
916 |
RETURN (self); |
|
917 |
} |
|
918 |
} |
|
919 |
} |
|
2189 | 920 |
|
24622 | 921 |
/* |
922 |
* sorry, must check code-pointer in the loop |
|
923 |
* it could be recompiled or flushed |
|
924 |
*/ |
|
2189 | 925 |
# undef BLOCK_ARG |
926 |
#ifdef NEW_BLOCK_CALL |
|
927 |
# define BLOCK_ARG aBlock |
|
928 |
# define IBLOCK_ARG nil |
|
929 |
#else |
|
930 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
931 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
932 |
#endif |
|
933 |
||
24622 | 934 |
for (; index < nIndex; index++) { |
935 |
REGISTER OBJFUNC codeVal; |
|
2189 | 936 |
|
24622 | 937 |
element = __InstPtr(self)->i_instvars[index]; |
938 |
if (__isNonNilObject(element)) { |
|
939 |
if (InterruptPending != nil) { |
|
940 |
__interruptL(@line); |
|
941 |
element = __InstPtr(self)->i_instvars[index]; |
|
942 |
} |
|
943 |
if (__isNonNilObject(element)) { |
|
944 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
945 |
#ifdef WEAK_DEBUG |
24622 | 946 |
if (! __ISVALIDOBJECT(element)) { |
947 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
948 |
__dumpObject__(element, __LINE__,__FILE__); |
|
949 |
element = nil; |
|
950 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
951 |
#endif |
24622 | 952 |
if (__isNonNilObject(element)) { |
953 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
954 |
(*codeVal)(BLOCK_ARG, element); |
|
955 |
} else { |
|
956 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
957 |
/* |
|
958 |
* arg is a compiled block with bytecode - |
|
959 |
* directly call interpreter without going through Block>>value |
|
960 |
*/ |
|
2189 | 961 |
#ifdef PASS_ARG_POINTER |
24622 | 962 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
2189 | 963 |
#else |
24622 | 964 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
2189 | 965 |
#endif |
24622 | 966 |
} else { |
967 |
/* |
|
968 |
* arg is something else - call it with #value |
|
969 |
*/ |
|
970 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
971 |
} |
|
972 |
} |
|
973 |
} |
|
974 |
} |
|
975 |
} |
|
976 |
} |
|
977 |
RETURN (self); |
|
2189 | 978 |
|
979 |
# undef BLOCK_ARG |
|
980 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
981 |
} |
2189 | 982 |
|
983 |
/* |
|
984 |
* not a block - send it #value: |
|
985 |
*/ |
|
986 |
for (; index < nIndex; index++) { |
|
24622 | 987 |
element = __InstPtr(self)->i_instvars[index]; |
988 |
if (__isNonNilObject(element)) { |
|
989 |
if (InterruptPending != nil) { |
|
990 |
__interruptL(@line); |
|
991 |
element = __InstPtr(self)->i_instvars[index]; |
|
992 |
} |
|
993 |
if (__isNonNilObject(element)) { |
|
994 |
element = __WEAK_READ__(self, element); |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
995 |
#ifdef WEAK_DEBUG |
24622 | 996 |
if (! __ISVALIDOBJECT(element)) { |
997 |
fprintf(stderr, "****** OOPS - invalid Weak-Read\n"); |
|
998 |
__dumpObject__(element, __LINE__,__FILE__); |
|
999 |
element = nil; |
|
1000 |
} |
|
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
1001 |
#endif |
24622 | 1002 |
if (__isNonNilObject(element)) { |
1003 |
(*val.ilc_func)(aBlock, |
|
1004 |
@symbol(value:), |
|
1005 |
nil, &val, |
|
1006 |
element); |
|
1007 |
} |
|
1008 |
} |
|
1009 |
} |
|
2189 | 1010 |
} |
5454 | 1011 |
RETURN (self); |
604 | 1012 |
%}. |
24622 | 1013 |
super do:[:each | |
1014 |
(each notNil and:[each class ~~ SmallInteger]) ifTrue:[aBlock value:each] |
|
1015 |
] |
|
5454 | 1016 |
|
18627 | 1017 |
"Modified: / 23-07-2015 / 15:32:44 / cg" |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1018 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1019 |
|
603 | 1020 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1021 |
|
603 | 1022 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
1023 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1024 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
1025 |
|
603 | 1026 |
dependents notNil ifTrue:[ |
12952
82385a928dac
keep element in a context slot
Claus Gittinger <cg@exept.de>
parents:
12841
diff
changeset
|
1027 |
self changed:#ElementExpired with:nil. |
603 | 1028 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1029 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
1030 |
"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
|
1031 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 1032 |
! ! |
6 | 1033 |
|
9244 | 1034 |
!WeakArray methodsFor:'testing'! |
1035 |
||
1036 |
isWeakCollection |
|
1037 |
"return true, if the receiver has weak references to its elements." |
|
1038 |
||
1039 |
^ true |
|
1040 |
! ! |
|
1041 |
||
628 | 1042 |
!WeakArray class methodsFor:'documentation'! |
1043 |
||
1044 |
version |
|
18603 | 1045 |
^ '$Header$' |
13013 | 1046 |
! |
1047 |
||
1048 |
version_CVS |
|
18603 | 1049 |
^ '$Header$' |
628 | 1050 |
! ! |
7097
23529d6e866e
Convert Object>>errorSignal -> Error
Stefan Vogel <sv@exept.de>
parents:
6421
diff
changeset
|
1051 |
|
15094 | 1052 |
|
603 | 1053 |
WeakArray initialize! |