author | Claus Gittinger <cg@exept.de> |
Fri, 17 Jan 1997 16:45:41 +0100 | |
changeset 2189 | 618dcdc1cee9 |
parent 2186 | a82449c022fc |
child 2199 | 40b621897c59 |
permissions | -rw-r--r-- |
6 | 1 |
" |
2 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 3 |
All Rights Reserved |
6 | 4 |
|
5 |
This software is furnished under a license and may be used |
|
6 |
only in accordance with the terms of that license and with the |
|
7 |
inclusion of the above copyright notice. This software may not |
|
8 |
be provided or otherwise made available to, or used by, any |
|
9 |
other person. No title to or ownership of the software is |
|
10 |
hereby transferred. |
|
11 |
" |
|
12 |
||
603 | 13 |
Array subclass:#WeakArray |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
14 |
instanceVariableNames:'dependents' |
1263 | 15 |
classVariableNames:'RegistrationFailedSignal AlreadyInitialized' |
16 |
poolDictionaries:'' |
|
17 |
category:'Collections-Arrayed' |
|
6 | 18 |
! |
19 |
||
20 |
!WeakArray class methodsFor:'documentation'! |
|
21 |
||
88 | 22 |
copyright |
23 |
" |
|
24 |
COPYRIGHT (c) 1991 by Claus Gittinger |
|
186 | 25 |
All Rights Reserved |
88 | 26 |
|
27 |
This software is furnished under a license and may be used |
|
28 |
only in accordance with the terms of that license and with the |
|
29 |
inclusion of the above copyright notice. This software may not |
|
30 |
be provided or otherwise made available to, or used by, any |
|
31 |
other person. No title to or ownership of the software is |
|
32 |
hereby transferred. |
|
33 |
" |
|
34 |
! |
|
35 |
||
6 | 36 |
documentation |
37 |
" |
|
88 | 38 |
WeakArrays can be used to trace disposal of objects; in contrast to other |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
39 |
objects, references by WeakArrays will NOT keep an object from being |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
40 |
garbage collected. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
41 |
Instead, whenever an object kept in a WeakArray dies, its entry is zeroed, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
42 |
and the WeakArray is informed by the storage manager. The WeakArray itself |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
43 |
then informs possible dependents via te dependency mechanism. |
290 | 44 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
45 |
WeakArrays are used to track disposal of objects which keep external |
95 | 46 |
world resources. For example, FileStreams must close their underlying |
290 | 47 |
file when disposed (otherwise you could run out of OS filedescriptors). |
95 | 48 |
This can be done by keeping the FileStream objects in a weakArray, and |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
49 |
keep a parallel array of filedescriptors. Whenever a fileStream is |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
50 |
freed, search both arrays for an index where the stream is zero, but the |
95 | 51 |
filedescriptor is non-nil. Then close that file, and nil the filedescriptor |
290 | 52 |
entry. Notice, that there is a class (Registry) which does exactly this in |
53 |
a more programmer friendly way. |
|
95 | 54 |
|
290 | 55 |
Another application is caching of data: keep it in a weakArray, so the |
95 | 56 |
data in that cache will not be unreclaimable due to being cached. |
57 |
(for example, the ResourcePack class uses a WeakArray to cache recently |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
58 |
used resource data for a while). |
88 | 59 |
|
186 | 60 |
The way in which weakArrays get informed by the runtime system is via |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
61 |
an interrupt (DisposeInterrupt) which is first sent to the disposeHandler |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
62 |
(typically ObjectMemory). ObjectMemory then takes the required steps to |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
63 |
notify all weakArrays via the #lostPointer message. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
64 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
65 |
The reason for not sending messages directly from the VM is to make it |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
66 |
possible to run the finalization code at lower priority or from another class. |
186 | 67 |
Also, as a side effect, it is possible to delay finalization by blocking |
216 | 68 |
interrupts. |
186 | 69 |
|
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
70 |
A weakArray notifies its dependents via normal dependency notfications. |
186 | 71 |
|
2145 | 72 |
[hint:] |
2189 | 73 |
WeakArray handling adds small some overhead to the VM |
74 |
(each weakarray is scanned after each GC). |
|
75 |
It is uncertain, if the current mechanism works well |
|
76 |
with (say) ten-thousands of weakArrays. |
|
77 |
We had the system running with >2000 weakArrays, some being quite |
|
78 |
big for a while and had a few percent of added gc time. |
|
79 |
The system as delivered creates between 50 and 100 weakArrays, |
|
80 |
but with many dependents, this number may grow. |
|
81 |
If you need the dependency mechanism on a huge number of objects, |
|
82 |
consider adding a (non-weak) dependents field to your class |
|
83 |
- take the implementation of Model as a guide (or subclass them |
|
84 |
from Model). |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
85 |
|
2189 | 86 |
\ |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
87 |
As a possible option, we could perform the weakArray scanning only in |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
88 |
the oldSpace reclamation code - this would remove most of the overhead, |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
89 |
but will lead to much longer delayed finalization .... we will see. |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
90 |
|
290 | 91 |
|
1290 | 92 |
[instance variables:] |
290 | 93 |
|
2189 | 94 |
dependents get informed via #change notifiction |
95 |
that the weakArray has lost pointers. |
|
96 |
Having the dependents here is an optimization. |
|
290 | 97 |
|
98 |
||
1290 | 99 |
[class variables:] |
290 | 100 |
|
2189 | 101 |
RegistrationFailedSignal raised if a weakArray cannot be |
102 |
registered by the VM. This only happens, |
|
103 |
if the VM has to resize its shadow tables |
|
104 |
and is running out of malloc-memory. |
|
1263 | 105 |
|
1290 | 106 |
[author:] |
2189 | 107 |
Claus Gittinger |
1290 | 108 |
|
1263 | 109 |
[See also:] |
2189 | 110 |
Array WeakIdentitySet WeakIdentityDictionary Registry |
111 |
Model |
|
6 | 112 |
" |
113 |
! ! |
|
114 |
||
159 | 115 |
!WeakArray class methodsFor:'initialization'! |
116 |
||
117 |
initialize |
|
118 |
"setup the private signal" |
|
119 |
||
120 |
RegistrationFailedSignal isNil ifTrue:[ |
|
302 | 121 |
RegistrationFailedSignal := ErrorSignal newSignalMayProceed:true. |
186 | 122 |
RegistrationFailedSignal nameClass:self message:#registrationFailedSignal. |
123 |
RegistrationFailedSignal notifierString:'weakArray registration failed'. |
|
159 | 124 |
] |
125 |
! ! |
|
126 |
||
6 | 127 |
!WeakArray class methodsFor:'instance creation'! |
128 |
||
129 |
new:size |
|
95 | 130 |
"return a new weakArray with size slots" |
6 | 131 |
|
95 | 132 |
"This is a kludge: I would like to set WEAK-flag in the classes |
216 | 133 |
initialize method, but (currently) the order in which the class-initialize |
290 | 134 |
methods are called is not defined ... |
216 | 135 |
... therefore it could happen, that a WeakArray is used by other |
136 |
classes initialize method BEFORE this method is evaluated. |
|
137 |
To avoid this, the WEAK bit in the class is set here, when the very first |
|
138 |
WeakArray is created." |
|
95 | 139 |
|
216 | 140 |
AlreadyInitialized isNil ifTrue:[ |
141 |
self flags:(Behavior flagWeakPointers). |
|
142 |
AlreadyInitialized := true |
|
143 |
]. |
|
95 | 144 |
|
159 | 145 |
^ (self basicNew:size) registerAsWeakArray |
146 |
! ! |
|
147 |
||
148 |
!WeakArray methodsFor:'GC registration'! |
|
149 |
||
150 |
registerAsWeakArray |
|
151 |
"register the receiver in the VM - |
|
152 |
i.e. tell the VM to nil disposed entries in the receiver |
|
153 |
and notify the disposeInterruptHandler whenever that happened." |
|
154 |
||
155 |
|ok| |
|
6 | 156 |
%{ |
157 |
OBJ __addShadowObject(); |
|
158 |
||
159 | 159 |
ok = __addShadowObject(self, 0); |
6 | 160 |
if (ok == false) { |
186 | 161 |
/* |
162 |
* this happens when too many shadow objects are |
|
163 |
* already there, collect garbage to get rid of |
|
164 |
* obsolete ones, and try again. |
|
165 |
* since a full collect is expensive, we try |
|
166 |
* a scavenge first, doing a full collect only if |
|
167 |
* that does not help. |
|
290 | 168 |
* |
169 |
* THIS MAY OR MAY NOT BE A GOOD IDEA: although it reduces |
|
170 |
* the number of shadow objects that have to be |
|
171 |
* processed at GC time, it may create a long delay here, |
|
172 |
* at shadow object creation time. |
|
173 |
* Dont know which is better ... |
|
186 | 174 |
*/ |
326 | 175 |
__nonTenuringScavenge(__context); |
186 | 176 |
ok = __addShadowObject(self, 0); |
308 | 177 |
#ifdef OLD |
186 | 178 |
if (ok == false) { |
290 | 179 |
/* |
180 |
* try more ... |
|
181 |
*/ |
|
326 | 182 |
__scavenge(__context); |
186 | 183 |
ok = __addShadowObject(self, 0); |
308 | 184 |
#endif |
186 | 185 |
if (ok == false) { |
290 | 186 |
/* |
187 |
* hard stuff - need full collect |
|
462 | 188 |
* if this is the very first GC, assume that we are in |
189 |
* the startup phase. Then do no GC. |
|
190 |
* Heuristics showed, that this GC does not find much ... |
|
290 | 191 |
*/ |
1127 | 192 |
if ((__garbageCollectCount() != 0) |
193 |
|| (__incrementalGCCount() != 0)) { |
|
462 | 194 |
__markAndSweepIfUseful(__context); |
195 |
ok = __addShadowObject(self, 0); |
|
196 |
} |
|
186 | 197 |
if (ok == false) { |
290 | 198 |
/* |
199 |
* mhmh - it seems that there are really many shadow |
|
200 |
* objects around - force creation |
|
201 |
*/ |
|
186 | 202 |
ok = __addShadowObject(self, 1); |
203 |
if (ok == false) { |
|
204 |
/* no chance - something must be wrong */ |
|
205 |
} |
|
206 |
} |
|
207 |
} |
|
308 | 208 |
#ifdef OLD |
186 | 209 |
} |
308 | 210 |
#endif |
6 | 211 |
} |
159 | 212 |
%}. |
213 |
ok ifFalse:[ |
|
290 | 214 |
" |
215 |
the VM was not able to register the new weakArray |
|
216 |
This can only happen, if the VM has to resize its tables, |
|
217 |
and a malloc request failed. Usually, this smells like big |
|
218 |
trouble being on the way (soon running out of memory in |
|
219 |
other places as well). |
|
220 |
Configure your OS for more swap space. |
|
221 |
" |
|
186 | 222 |
^ RegistrationFailedSignal raiseRequestWith:self |
159 | 223 |
] |
6 | 224 |
! ! |
225 |
||
603 | 226 |
!WeakArray methodsFor:'accessing'! |
227 |
||
228 |
at:index |
|
229 |
"return the indexed instance variable with index, anInteger. |
|
230 |
Reimplemented here for IGC readBarrier. You dont have to understand this." |
|
231 |
||
232 |
^ self basicAt:index |
|
233 |
! |
|
6 | 234 |
|
603 | 235 |
basicAt:index |
236 |
"return the indexed instance variable with index, anInteger. |
|
237 |
Reimplemented here for IGC readBarrier. You dont have to understand this." |
|
238 |
||
239 |
%{ /* NOCONTEXT */ |
|
240 |
||
241 |
REGISTER int indx; |
|
242 |
REGISTER unsigned int nIndex; |
|
243 |
OBJ el; |
|
6 | 244 |
|
603 | 245 |
if (__isSmallInteger(index)) { |
1136 | 246 |
indx = __intVal(index) - 1; |
603 | 247 |
if (indx >= 0) { |
248 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
1136 | 249 |
indx += __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
603 | 250 |
if (indx < nIndex) { |
1136 | 251 |
el = __InstPtr(self)->i_instvars[indx]; |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
252 |
if (__isNonNilObject(el)) el = __WEAK_READ__(self, el); |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
253 |
RETURN (el); |
603 | 254 |
} |
255 |
} |
|
256 |
} |
|
257 |
%}. |
|
258 |
^ super basicAt:index |
|
259 |
! |
|
260 |
||
261 |
dependents |
|
262 |
"return the dependents of the receiver" |
|
263 |
||
264 |
^ dependents |
|
265 |
! |
|
266 |
||
267 |
dependents:aCollection |
|
268 |
"set the dependents of the receiver" |
|
269 |
||
270 |
dependents := aCollection |
|
6 | 271 |
! ! |
272 |
||
159 | 273 |
!WeakArray methodsFor:'copying'! |
274 |
||
275 |
postCopy |
|
276 |
"copying alone does not really help - we have to tell |
|
277 |
the VM, that there is a new WeakArray around ... |
|
278 |
Q: who copies weakArrays ?" |
|
279 |
||
290 | 280 |
dependents := nil. |
159 | 281 |
self registerAsWeakArray. |
282 |
! ! |
|
283 |
||
1825 | 284 |
!WeakArray methodsFor:'enumerating'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
285 |
|
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
286 |
do:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
287 |
"evaluate the argument, aBlock for each element in the collection. |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
288 |
- reimplemented for IGC readBarrier. |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
289 |
You dont have to understand this." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
290 |
|
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
291 |
|home element| |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
292 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
293 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
294 |
unsigned int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
295 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
296 |
|
1136 | 297 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
298 |
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
|
299 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
300 |
if (__isBlockLike(aBlock) |
1136 | 301 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
302 |
{ |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
303 |
/* |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
304 |
* the most common case: a static compiled block, with home on the stack ... |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
305 |
*/ |
2189 | 306 |
REGISTER OBJFUNC codeVal; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
307 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
308 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
309 |
#ifdef NEW_BLOCK_CALL |
2189 | 310 |
# 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
|
311 |
#else |
2189 | 312 |
# define BLOCK_ARG rHome |
313 |
REGISTER OBJ rHome; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
314 |
|
2189 | 315 |
rHome = __BlockInstPtr(aBlock)->b_home; |
316 |
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
|
317 |
#endif |
2189 | 318 |
{ |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
319 |
for (; index < nIndex; index++) { |
2189 | 320 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
321 |
|
2189 | 322 |
element = __InstPtr(self)->i_instvars[index]; |
323 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
324 |
(*codeVal)(BLOCK_ARG, element); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
325 |
} |
2189 | 326 |
element = home = nil; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
327 |
RETURN (self); |
2189 | 328 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
329 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
330 |
} |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
331 |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
332 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
333 |
* sorry, must check code-pointer in the loop |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
334 |
* it could be recompiled or flushed |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
335 |
*/ |
2189 | 336 |
# undef BLOCK_ARG |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
337 |
#ifdef NEW_BLOCK_CALL |
2189 | 338 |
# define BLOCK_ARG aBlock |
339 |
# 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
|
340 |
#else |
2189 | 341 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
342 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
343 |
#endif |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
344 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
345 |
for (; index < nIndex; index++) { |
2189 | 346 |
REGISTER OBJFUNC codeVal; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
347 |
|
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
348 |
if (InterruptPending != nil) __interruptL(@line); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
349 |
|
1136 | 350 |
element = __InstPtr(self)->i_instvars[index]; |
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
351 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
352 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
353 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
2189 | 354 |
(*codeVal)(BLOCK_ARG, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
355 |
} else { |
2189 | 356 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
357 |
/* |
|
358 |
* arg is a compiled block with bytecode - |
|
359 |
* directly call interpreter without going through Block>>value |
|
360 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
361 |
#ifdef PASS_ARG_POINTER |
2189 | 362 |
__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
|
363 |
#else |
2189 | 364 |
__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
|
365 |
#endif |
2189 | 366 |
} else { |
367 |
/* |
|
368 |
* arg is something else - call it with #value |
|
369 |
*/ |
|
370 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
371 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
372 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
373 |
} |
2189 | 374 |
element = home = nil; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
375 |
RETURN (self); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
376 |
|
2189 | 377 |
# undef BLOCK_ARG |
378 |
# undef IBLOCK_ARG |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
379 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
380 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
381 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
382 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
383 |
* 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
|
384 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
385 |
for (; index < nIndex; index++) { |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
386 |
if (InterruptPending != nil) __interruptL(@line); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
387 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
388 |
element = __InstPtr(self)->i_instvars[index]; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
389 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
390 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
391 |
(*val.ilc_func)(aBlock, |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
392 |
@symbol(value:), |
1688
8a42db1eea60
removed all COMMA_CON / CON_COMMA uses
Claus Gittinger <cg@exept.de>
parents:
1290
diff
changeset
|
393 |
nil, &val, |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
394 |
element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
395 |
} |
2189 | 396 |
element = home = nil; |
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
397 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
398 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
399 |
! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
400 |
|
1780
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
401 |
forAllDeadIndicesDo:aBlock |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
402 |
"evaluate the argument, aBlock for all indices where elements have been |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
403 |
replaced by zero (due to a collected object)." |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
404 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
405 |
self keysAndValuesDo:[:index :element | |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
406 |
element == 0 ifTrue:[ |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
407 |
aBlock value:index |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
408 |
] |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
409 |
] |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
410 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
411 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
412 |
forAllDeadIndicesDo:aBlock replacingCorpsesWith:newValue |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
413 |
"evaluate the argument, aBlock for all indices where elements have been |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
414 |
replaced by zero (due to a collected object), and replace the element |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
415 |
with newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
416 |
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
|
417 |
changed before the block is called); this behavior is not guaranteed |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
418 |
with future versions." |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
419 |
|
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
420 |
self keysAndValuesDo:[:index :element | |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
421 |
element == 0 ifTrue:[ |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
422 |
self at:index put:newValue. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
423 |
aBlock value:index. |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
424 |
] |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
425 |
] |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
426 |
! |
1b3a4ddc5b94
changed WeakArray to set emptied slots to zero
Claus Gittinger <cg@exept.de>
parents:
1688
diff
changeset
|
427 |
|
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
428 |
nilAllCorpsesAndDo:aBlock |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
429 |
"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
|
430 |
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
|
431 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
432 |
self forAllDeadIndicesDo:aBlock replacingCorpsesWith:nil |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
433 |
! |
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
434 |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
435 |
nonNilElementsDo:aBlock |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
436 |
"evaluate the argument, aBlock for each non-nil element" |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
437 |
|
981
6da206fcc1c4
keep ref to weak-element somewhere (this is a try)
Claus Gittinger <cg@exept.de>
parents:
829
diff
changeset
|
438 |
|home element| |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
439 |
%{ |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
440 |
REGISTER int index; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
441 |
int nIndex; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
442 |
static struct inlineCache val = _ILC1; |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
443 |
|
1136 | 444 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
445 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
446 |
if (__isBlockLike(aBlock) |
1136 | 447 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
2189 | 448 |
{ |
449 |
/* |
|
450 |
* the most common case: a static compiled block, with home on the stack ... |
|
451 |
*/ |
|
452 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
453 |
|
2189 | 454 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
455 |
#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
|
456 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
457 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
458 |
# define BLOCK_ARG rHome |
2189 | 459 |
REGISTER OBJ rHome; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
460 |
|
2189 | 461 |
rHome = __BlockInstPtr(aBlock)->b_home; |
462 |
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
|
463 |
#endif |
2189 | 464 |
{ |
465 |
for (; index < nIndex; index++) { |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
466 |
element = __InstPtr(self)->i_instvars[index]; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
467 |
if (element) { |
2189 | 468 |
if (InterruptPending != nil) { |
469 |
/* |
|
470 |
* must clear local ref, otherwise, a bad ref might |
|
471 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd |
|
472 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
473 |
element = nil; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
474 |
__interruptL(@line); |
2189 | 475 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
476 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
477 |
|
2189 | 478 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
479 |
if (element) { |
2189 | 480 |
(*codeVal)(BLOCK_ARG, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
481 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
482 |
} |
2189 | 483 |
} |
484 |
element = home = nil; |
|
485 |
RETURN (self); |
|
486 |
} |
|
487 |
} |
|
488 |
} |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
489 |
|
2189 | 490 |
/* |
491 |
* sorry, must check code-pointer in the loop |
|
492 |
* it could be recompiled or flushed |
|
493 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
494 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
495 |
#ifdef NEW_BLOCK_CALL |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
496 |
# define BLOCK_ARG aBlock |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
497 |
# define IBLOCK_ARG nil |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
498 |
#else |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
499 |
# 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
|
500 |
# 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
|
501 |
#endif |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
502 |
|
2189 | 503 |
for (; index < nIndex; index++) { |
504 |
REGISTER OBJFUNC codeVal; |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
505 |
|
2189 | 506 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
507 |
if (element) { |
2189 | 508 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
509 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
510 |
* must clear local ref, otherwise, a bad ref might |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
511 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
512 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
513 |
element = nil; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
514 |
__interruptL(@line); |
1903 | 515 |
element = __InstPtr(self)->i_instvars[index]; |
516 |
} |
|
2189 | 517 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
518 |
if (element) { |
2189 | 519 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
520 |
(*codeVal)(BLOCK_ARG, element); |
|
521 |
} else { |
|
522 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
523 |
/* |
|
524 |
* arg is a compiled block with bytecode - |
|
525 |
* directly call interpreter without going through Block>>value |
|
526 |
*/ |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
527 |
#ifdef PASS_ARG_POINTER |
2189 | 528 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
529 |
#else |
2189 | 530 |
__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
|
531 |
#endif |
2189 | 532 |
} else { |
533 |
/* |
|
534 |
* arg is something else - call it with #value |
|
535 |
*/ |
|
536 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
537 |
} |
|
538 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
539 |
} |
2189 | 540 |
} |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
541 |
} |
2189 | 542 |
element = home = nil; |
543 |
RETURN (self); |
|
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
544 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
545 |
# undef BLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
546 |
# undef IBLOCK_ARG |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
547 |
} |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
548 |
|
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
549 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
550 |
* 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
|
551 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
552 |
for (; index < nIndex; index++) { |
2189 | 553 |
element = __InstPtr(self)->i_instvars[index]; |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
554 |
if (element) { |
2189 | 555 |
if (InterruptPending != nil) { |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
556 |
/* |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
557 |
* must clear local ref, otherwise, a bad ref might |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
558 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd) |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
559 |
*/ |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
560 |
element = nil; |
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
561 |
__interruptL(@line); |
1136 | 562 |
element = __InstPtr(self)->i_instvars[index]; |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
563 |
} |
2189 | 564 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
2186
a82449c022fc
care for blocks being recompiled, or code being flushed while
Claus Gittinger <cg@exept.de>
parents:
2145
diff
changeset
|
565 |
if (element) { |
2189 | 566 |
(*val.ilc_func)(aBlock, |
567 |
@symbol(value:), |
|
568 |
nil, &val, |
|
569 |
element); |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
element = home = nil; |
|
574 |
%}. |
|
575 |
^ self |
|
576 |
! |
|
577 |
||
578 |
validElementsDo:aBlock |
|
579 |
"evaluate the argument, aBlock for each non-nil/non-zero element" |
|
580 |
||
581 |
|home element| |
|
582 |
%{ |
|
583 |
REGISTER int index; |
|
584 |
int nIndex; |
|
585 |
static struct inlineCache val = _ILC1; |
|
586 |
||
587 |
index = __intVal(__ClassInstPtr(__qClass(self))->c_ninstvars); |
|
588 |
nIndex = __BYTES2OBJS__(__qSize(self) - OHDR_SIZE); |
|
589 |
if (__isBlockLike(aBlock) |
|
590 |
&& (__BlockInstPtr(aBlock)->b_nargs == __MKSMALLINT(1))) { |
|
591 |
{ |
|
592 |
/* |
|
593 |
* the most common case: a static compiled block, with home on the stack ... |
|
594 |
*/ |
|
595 |
REGISTER OBJFUNC codeVal; |
|
596 |
||
597 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
598 |
#ifdef NEW_BLOCK_CALL |
|
599 |
# define BLOCK_ARG aBlock |
|
600 |
#else |
|
601 |
# define BLOCK_ARG rHome |
|
602 |
REGISTER OBJ rHome; |
|
603 |
||
604 |
rHome = __BlockInstPtr(aBlock)->b_home; |
|
605 |
if ((rHome == nil) || (__qSpace(rHome) >= STACKSPACE)) |
|
606 |
#endif |
|
607 |
{ |
|
608 |
for (; index < nIndex; index++) { |
|
609 |
element = __InstPtr(self)->i_instvars[index]; |
|
610 |
if (element && (element != __MKSMALLINT(0))) { |
|
611 |
if (InterruptPending != nil) { |
|
612 |
/* |
|
613 |
* must clear local ref, otherwise, a bad ref might |
|
614 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd |
|
615 |
*/ |
|
616 |
element = nil; |
|
617 |
__interruptL(@line); |
|
618 |
element = __InstPtr(self)->i_instvars[index]; |
|
619 |
} |
|
620 |
||
621 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
622 |
if (element && (element != __MKSMALLINT(0))) { |
|
623 |
(*codeVal)(BLOCK_ARG, element); |
|
624 |
} |
|
625 |
} |
|
626 |
} |
|
627 |
element = home = nil; |
|
628 |
RETURN (self); |
|
629 |
} |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
630 |
} |
2189 | 631 |
} |
632 |
||
633 |
/* |
|
634 |
* sorry, must check code-pointer in the loop |
|
635 |
* it could be recompiled or flushed |
|
636 |
*/ |
|
637 |
# undef BLOCK_ARG |
|
638 |
#ifdef NEW_BLOCK_CALL |
|
639 |
# define BLOCK_ARG aBlock |
|
640 |
# define IBLOCK_ARG nil |
|
641 |
#else |
|
642 |
# define BLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
643 |
# define IBLOCK_ARG (__BlockInstPtr(aBlock)->b_home) |
|
644 |
#endif |
|
645 |
||
646 |
for (; index < nIndex; index++) { |
|
647 |
REGISTER OBJFUNC codeVal; |
|
648 |
||
649 |
element = __InstPtr(self)->i_instvars[index]; |
|
650 |
if (element && (element != __MKSMALLINT(0))) { |
|
651 |
if (InterruptPending != nil) { |
|
652 |
/* |
|
653 |
* must clear local ref, otherwise, a bad ref might |
|
654 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd) |
|
655 |
*/ |
|
656 |
element = nil; |
|
657 |
__interruptL(@line); |
|
658 |
element = __InstPtr(self)->i_instvars[index]; |
|
659 |
} |
|
660 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
661 |
if (element && (element != __MKSMALLINT(0))) { |
|
662 |
if ((codeVal = __BlockInstPtr(aBlock)->b_code) != (OBJFUNC)nil) { |
|
663 |
(*codeVal)(BLOCK_ARG, element); |
|
664 |
} else { |
|
665 |
if (__BlockInstPtr(aBlock)->b_bytecodes != nil) { |
|
666 |
/* |
|
667 |
* arg is a compiled block with bytecode - |
|
668 |
* directly call interpreter without going through Block>>value |
|
669 |
*/ |
|
670 |
#ifdef PASS_ARG_POINTER |
|
671 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, &element); |
|
672 |
#else |
|
673 |
__interpret(aBlock, 1, nil, IBLOCK_ARG, nil, nil, element); |
|
674 |
#endif |
|
675 |
} else { |
|
676 |
/* |
|
677 |
* arg is something else - call it with #value |
|
678 |
*/ |
|
679 |
(*val.ilc_func)(aBlock, @symbol(value:), nil, &val, element); |
|
680 |
} |
|
681 |
} |
|
682 |
} |
|
683 |
} |
|
684 |
} |
|
685 |
element = home = nil; |
|
686 |
RETURN (self); |
|
687 |
||
688 |
# undef BLOCK_ARG |
|
689 |
# undef IBLOCK_ARG |
|
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
690 |
} |
2189 | 691 |
|
692 |
/* |
|
693 |
* not a block - send it #value: |
|
694 |
*/ |
|
695 |
for (; index < nIndex; index++) { |
|
696 |
element = __InstPtr(self)->i_instvars[index]; |
|
697 |
if (element && (element != __MKSMALLINT(0))) { |
|
698 |
if (InterruptPending != nil) { |
|
699 |
/* |
|
700 |
* must clear local ref, otherwise, a bad ref might |
|
701 |
* be int the context chain ... (otherwise, a __WEAK_READ__ was req'd) |
|
702 |
*/ |
|
703 |
element = nil; |
|
704 |
__interruptL(@line); |
|
705 |
element = __InstPtr(self)->i_instvars[index]; |
|
706 |
} |
|
707 |
if (__isNonNilObject(element)) element = __WEAK_READ__(self, element); |
|
708 |
if (element && (element != __MKSMALLINT(0))) { |
|
709 |
(*val.ilc_func)(aBlock, |
|
710 |
@symbol(value:), |
|
711 |
nil, &val, |
|
712 |
element); |
|
713 |
} |
|
714 |
} |
|
715 |
} |
|
716 |
element = home = nil; |
|
604 | 717 |
%}. |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
718 |
^ self |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
719 |
! ! |
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
720 |
|
603 | 721 |
!WeakArray methodsFor:'notification'! |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
722 |
|
603 | 723 |
lostPointer |
2091
c11bb3e29a1b
Use dependent mechamism of WeakArray instead of #watcher.
Stefan Vogel <sv@exept.de>
parents:
1903
diff
changeset
|
724 |
"I lost a pointer; tell dependents. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
725 |
This is sent from the finalization code in ObjectMemory." |
586
cab695f942a6
weakArray readBarrier for IGC
Claus Gittinger <cg@exept.de>
parents:
530
diff
changeset
|
726 |
|
603 | 727 |
dependents notNil ifTrue:[ |
2189 | 728 |
self changed:#ElementExpired with:nil. |
603 | 729 |
]. |
1785
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
730 |
|
4b18823528b8
commentary & change-aspect made ST-80 compatible
Claus Gittinger <cg@exept.de>
parents:
1782
diff
changeset
|
731 |
"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
|
732 |
"Modified: 7.1.1997 / 17:22:52 / stefan" |
603 | 733 |
! ! |
6 | 734 |
|
628 | 735 |
!WeakArray class methodsFor:'documentation'! |
736 |
||
737 |
version |
|
2189 | 738 |
^ '$Header: /cvs/stx/stx/libbasic/WeakArray.st,v 1.40 1997-01-17 15:45:36 cg Exp $' |
628 | 739 |
! ! |
603 | 740 |
WeakArray initialize! |