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