[squeak-dev] The Trunk: System-eem.1395.mcz

commits at source.squeak.org commits at source.squeak.org
Thu Mar 23 22:35:01 UTC 2023


Eliot Miranda uploaded a new version of System to project The Trunk:
http://source.squeak.org/trunk/System-eem.1395.mcz

==================== Summary ====================

Name: System-eem.1395
Author: eem
Time: 23 March 2023, 3:34:56.554408 pm
UUID: d923e690-07b0-43ae-bc0d-0102525ac783
Ancestors: System-eem.1394

Humble mumble.  Undo inadvertent commits in the previous commit. I forgot to use ignore in the cmmit dialogue.

=============== Diff against System-eem.1394 ===============

Item was removed:
- ----- Method: Array>>objectsAccessibleFromRoots (in category '*System-Object Storage-file in/out') -----
- objectsAccessibleFromRoots
- 	"This primitive will answer an array of the receiver and every object in its proper tree of subParts
- 	 (ie, that is not refered to from anywhere else outside the tree).  Note: all elements of the reciever
- 	 are treated as roots in determining the extent of the tree."
- 
- 	<primitive: 96 error: ec>
- 	self primitiveFailed
- 
- 	"{ Object } objectsAccessibleFromRoots"!

Item was removed:
- Association ephemeronSubclass: #Ephemeron
- 	instanceVariableNames: 'container'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'System-Finalization'!
- 
- !Ephemeron commentStamp: 'eem 6/7/2022 15:45' prior: 0!
- An Ephemeron is an association known to the garbage collection system, allowing it to function as a pre-mortem finalizer.
- 
- An Ephemeron is intended for uses such as associating an object's dependents with an object without preventing garbage collection.
- 
- Consider a traditional implementation of dependents in non-Model classes.  There is a Dictionary in Object, DependentsFields, into which objects wishing to have dependents are entered as keys, with the value being the sequence of their dependents.  Since a key's dependents (if they are like views/morphs, etc in MVC) will refer directly back to the key (e.g. in their model inst var etc), the key remains srongly referenced; there is no way to use weak collections in DependentsFields to allow the cycle of an object and its dependents to be collected.  If DependentsFields were to use a WeakArray to hold the associations from objects to their dependents then those associations, and the dependencies they record, would simply be lost since the only reference to the associations is from DependentsFields.
- 
- Ephemeron differs from a normal association in that it is known to the garbage collector and it is involved in tracing.  First, note that an Ephemeron is a *strong* referrer.  The objects it refers to cannot be garbage collected.  It is not weak.  But it is able to discover when it is the *only* reference to an object.  To be accurate, an Ephemeron is notified by the collector when its key is only referenced from the transitive closure of references from ephemerons.  i.e. when an ephemeron is notified we know that there are no reference paths to the ephemeron's key other than through ephemerons; the ephemeron's key is not otherwise reachable from the roots.
- 
- Ephemerons are notified by the garage collector placing them in a queue and signalling a semaphore for each element in the queue.  An image level process (the extended finalization process) extracts them from the queue and sends mourn to each ephemeron (since their keys are effectively dead).  What an Ephemeron does in response to the notification is programmable (one can add subclasses of Ephemeron).  But the default behaviour is to send finalize to the key, and then to remove itself from the dictionary it is in, allowing it and the transitive closure of objects reachable from it, to be collected in a subsequent garbage collection.
- 
- Implementation: both in scavenging, and in scan-mark, if an ephemeron is encountered its key is examined.  If the key is reachable from the roots (has already been scavenged, or is already marked), then the ephemeron marked and treated as an ordinary object. If the key is not yet known to be reachable the ephemeron is held in an internal queue of maybe triggerable ephemerons, and its objects are not traced.
- 
- At the end of the initial scavenge or scan-mark phase, this queue of triggerable ephemerons is examined.  All ephemerons in the list whose key is reachable are traced, and removed from the list.  i.e. what has happened was that their key was found reachable form the roots after they were added in the list (the garbage collector traces the object graph in an arbitrary order, typically breadth first in the scavenger, depth-dirst in teh scan-mark).  This then leaves the list populated only with ephemerons whose keys are as yet untraced, and hence only referenced from the ephemerons in the triggerable ephemeron queue, which now becomes the triggered ephemeron queue.  All these ephemerons are placed in the finalization queue for processing in the image above, and all objects reachable from these ephemerons are traced (scavenged, marked).  This tracing phase may encounter new potentially triggerable ephemerons which will be added to the triggerable ephemeron queue (not likely in practice
 , but essential for sound semantics).  So the triggering phase continues until the system reaches a fixed point with an empty triggerable ephemeron queue.
- 
- Implications and advantages:
- Because ephemerons do not allow their object to be collected, they can be, and are, used to implement pre-mortem finalization.  So e.g. a file can flush its buffers and then close its file descriptor before being collected (which may also imply that the system runs the garbage collector *before* snapshotting, not as part of the snapshot primitive).  Ephemerons are conceptually more simple than WeakKeyDictionary et al, since they are about reference paths, not merely the existence of strong references.  They accurately identify when an object is no longer reachable from the roots, no matter how many ephemerons are attached to a specific object for whatever purpose.  Note that the back reference from a dependent to an object renders a weak key dictionary useless in enabling an isolated cycle to be collected since the back reference is string, and keeps the reference from the weak key alive.
- 
- History: Ephemerons are like guardians.  They were invented by George Bosworth in the early '90's, to provide pre-mortem finalization and to solve the problem of DependentsFields retaining garbage.
- 
- Instance Variables (inherited)
- 	container 	<Dictionary|Set> - the container in which the Ephemeron resides.
- !

Item was removed:
- ----- Method: Ephemeron>>container (in category 'accessing') -----
- container
- 	"Answer the Dictionary containing the receiver, if any."
- 	^container!

Item was removed:
- ----- Method: Ephemeron>>container: (in category 'accessing') -----
- container: aDictionarySetOrNil
- 	"Set the Dictionary containing the receiver, or nil it."
- 	container := aDictionarySetOrNil!

Item was removed:
- ----- Method: Ephemeron>>isEphemeron (in category 'testing') -----
- isEphemeron
- 	^true!

Item was removed:
- ----- Method: Ephemeron>>mourn (in category 'mourning') -----
- mourn
- 	"Triggered ephemerons get sent mourn by WeakArray class's finalizationProcess
- 	 (via mournLoopWith:) when the only reference(s) to an ephemeron's key is through
- 	 one or more ephemerons. i.e. the key is not reachable from the roots of the system,
- 	 only through ephemerons.  So ephemerons get sent mourn when their key would
- 	 otherwise have been garbage collected.  Respond to the information that the key
- 	 would have been garbage collected other than through ephemeron references by
- 	 sending finalize to the key."
- 	container ifNotNil: [container removeKey: key ifAbsent: nil].
- 	key finalize!

Item was removed:
- Dictionary subclass: #EphemeronDictionary
- 	instanceVariableNames: 'mutex'
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'System-Finalization'!
- 
- !EphemeronDictionary commentStamp: 'eem 10/1/2020 16:31' prior: 0!
- An EphemeronDictionary is a dictionary that uses ephemerons for its associations, and hence is able to arrange that its keys are finalizable.  See Phemeron's class comment.
- 
- Instance Variables
- 	mutex:		<Mutex>
- 
- mutex
- 	- an access protect that prevents the receiver getting corrupted as finalization occurs while lower priority processes are adding and/or rremoving ephemerons.
- !

Item was removed:
- ----- Method: EphemeronDictionary>>add: (in category 'adding') -----
- add: anAssociation
- 	anAssociation class ~~ self associationClass ifTrue:
- 		[self error: self class name, 's hold only ', self associationClass name, ' instances'].
- 	^super add: anAssociation!

Item was removed:
- ----- Method: EphemeronDictionary>>associationClass (in category 'accessing') -----
- associationClass
- 	^Ephemeron!

Item was removed:
- ----- Method: EphemeronDictionary>>atNewIndex:put: (in category 'private') -----
- atNewIndex: index put: anEphemeron
- 
- 	anEphemeron container: self.
- 	^super atNewIndex: index put: anEphemeron!

Item was removed:
- ----- Method: EphemeronDictionary>>initialize: (in category 'initialize-release') -----
- initialize: n
- 	mutex := Mutex new.
- 	super initialize: n!

Item was removed:
- IdentitySet subclass: #EphemeronRegistry
- 	instanceVariableNames: ''
- 	classVariableNames: ''
- 	poolDictionaries: ''
- 	category: 'System-Finalization'!

Item was removed:
- ----- Method: Object>>isEphemeron (in category '*System-Finalization-testing') -----
- isEphemeron
- 	^false!

Item was removed:
- ----- Method: Preferences class>>vmProfilerFillInIntegral (in category 'standard queries') -----
- vmProfilerFillInIntegral
- 	^ self
- 		valueOfFlag: #vmProfilerFillInIntegral
- 		ifAbsent: [false]!

Item was removed:
- ----- Method: WeakArray class>>doOldFinalization (in category '*System-Finalization') -----
- doOldFinalization
- 	"Process the weak registries, in the old finalization style.  Hopefully this will
- 	 eventually go away when all clients have adopted the new finalization scheme."
- 	FinalizationLock
- 		critical:
- 			[FinalizationDependents do:
- 				[ :weakDependent |
- 				weakDependent ifNotNil:
- 					[weakDependent finalizeValues]]]
- 		ifError:
- 			[:msg :rcvr | rcvr error: msg]!

Item was changed:
  ----- Method: WeakArray class>>finalizationProcess (in category '*System-Finalization') -----
  finalizationProcess
- 	"The finalization process arranges to send mourn to each element of the VM's finalization queue,
- 	 which is accessed via primitiveFetchMourner.  The VM signals FinalizationSemaphore whenever
- 	 the queue is non-empty.  This process loops, waiting on the semaphore, fetches the first element
- 	 of the queue and then spawns a process at a higher priority to actually send the mourn messages.
- 	 If an error occurs in the higher priority mourn loop process then this process will simply spawn
- 	 another process, hence ensuring that errors in finalization methods don't break finalization.
  
+ 	[FinalizationSemaphore wait.
+ 	 FinalizationLock
+ 		critical:
+ 			[FinalizationDependents do:
+ 				[ :weakDependent |
+ 				weakDependent ifNotNil:
+ 					[weakDependent finalizeValues]]]
+ 		ifError:
+ 			[:msg :rcvr | rcvr error: msg]] repeat!
- 	 In addition this process also runs the old finalization scheme, supporting clients of the older,
- 	 WeakRegistry based scheme.  Hopefully this will go away when all cleints have moved over."
- 	| throttle firstMourner |
- 	throttle := Semaphore new.
- 	[FinalizationSemaphore wait; initSignals.
- 	 "Support the old scheme until things have changed over..."
- 	 self doOldFinalization.
- 	 [firstMourner := self primitiveFetchMourner.
- 	  firstMourner notNil] whileTrue:
- 		[[throttle signal.
- 		  self mournLoopWith: firstMourner] forkAt: Processor activePriority + 1.
- 		 throttle wait]] repeat!

Item was removed:
- ----- Method: WeakArray class>>mournLoopWith: (in category '*System-Finalization') -----
- mournLoopWith: firstMourner
- 	"Send mourn to all the objects available in the mourn queue, starting
- 	 with firstMourner which the sender has already extraced for us.  If
- 	 an error occurs here, it will break this loop but the sender will spawn
- 	 another mournLoopWith: so that finalization is not broken by errors in
- 	 individual cases."
- 	| mourner |
- 	mourner := firstMourner.
- 	[mourner isEphemeron ifTrue:
- 		[mourner mourn].
- 	 (mourner := self primitiveFetchMourner) notNil] whileTrue!



More information about the Squeak-dev mailing list