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