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