-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement optimized ephemeron support
- Loading branch information
Showing
18 changed files
with
198 additions
and
11 deletions.
There are no files selected for viewing
Empty file.
24 changes: 24 additions & 0 deletions
24
...kage/FLEphemeronTest.class/instance/testWeakKeyAssociationMourningAfterMaterialization.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
tests | ||
testWeakKeyAssociationMourningAfterMaterialization | ||
"This tests serialization / materialization of WeakKeyAssociation, which is an ephemeron class. | ||
When the key is not strongly referenced, which is the case here, the garbage collector | ||
will send #mourn to the object to finalize it. This will cause the ephemeron to remove itself | ||
from its container." | ||
|
||
| dictionary ephemeron materializedDictionary materializedAssociation | | ||
dictionary := Dictionary new. | ||
ephemeron := WeakKeyAssociation new | ||
key: Object new; | ||
value: 'value'; | ||
container: dictionary. | ||
dictionary add: ephemeron. | ||
|
||
materializedDictionary := self resultOfSerializeAndMaterialize: dictionary. | ||
self deny: materializedDictionary isEmpty. | ||
self assert: materializedDictionary size equals: 1. | ||
materializedAssociation := materializedDictionary associations first. | ||
self assert: materializedAssociation key isNil. | ||
self assert: materializedAssociation value equals: 'value'. | ||
|
||
Smalltalk garbageCollect. | ||
self deny: materializedDictionary isEmpty |
29 changes: 29 additions & 0 deletions
29
...age/FLEphemeronTest.class/instance/testWeakKeyAssociationMourningBeforeMaterialization.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
tests | ||
testWeakKeyAssociationMourningBeforeMaterialization | ||
"This tests serialization / materialization of WeakKeyAssociation, which is an ephemeron class. | ||
When the key is not strongly referenced, which is the case here, the garbage collector | ||
will send #mourn to the object to finalize it. This will cause the ephemeron to remove itself | ||
from its container." | ||
|
||
| dictionary ephemeron materializedDictionary | | ||
dictionary := Dictionary new. | ||
ephemeron := WeakKeyAssociation new | ||
key: Object new; | ||
value: 'value'; | ||
container: dictionary. | ||
dictionary add: ephemeron. | ||
|
||
self deny: dictionary isEmpty. | ||
|
||
self serialize: dictionary. | ||
Smalltalk garbageCollect. | ||
self assert: dictionary isEmpty. | ||
|
||
materializedDictionary := self materialized. | ||
self deny: materializedDictionary isEmpty. | ||
self assert: materializedDictionary size equals: 1. | ||
self assert: materializedDictionary associations first key isNil. | ||
self assert: materializedDictionary associations first value equals: 'value'. | ||
|
||
Smalltalk garbageCollect. | ||
self deny: materializedDictionary isEmpty |
17 changes: 17 additions & 0 deletions
17
...ckage/FLEphemeronTest.class/instance/testWeakKeyAssociationMourningBeforeSerialization.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
tests | ||
testWeakKeyAssociationMourningBeforeSerialization | ||
"This tests serialization / materialization of WeakKeyAssociation, which is an ephemeron class. | ||
When the key is not strongly referenced, which is the case here, the garbage collector | ||
will send #mourn to the object to finalize it. This will cause the ephemeron to remove itself | ||
from its container." | ||
|
||
| dictionary ephemeron | | ||
dictionary := Dictionary new. | ||
ephemeron := WeakKeyAssociation new | ||
key: Object new; | ||
value: 'value'; | ||
container: dictionary. | ||
dictionary add: ephemeron. | ||
|
||
Smalltalk garbageCollect. | ||
self assert: dictionary isEmpty |
29 changes: 29 additions & 0 deletions
29
...Tests.package/FLEphemeronTest.class/instance/testWeakKeyAssociationWithStrongReference.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
tests | ||
testWeakKeyAssociationWithStrongReference | ||
"This tests serialization / materialization of WeakKeyAssociation, which is an ephemeron class. | ||
When the key is strongly referenced, which is the case here, the garbage collector will | ||
not finalize the ephemeron." | ||
|
||
| dictionary key ephemeron materializedDictionary | | ||
dictionary := Dictionary new. | ||
key := Object new. | ||
ephemeron := WeakKeyAssociation new | ||
key: key; | ||
value: 'value'; | ||
container: dictionary. | ||
dictionary add: ephemeron. | ||
|
||
self deny: dictionary isEmpty. | ||
|
||
self serialize: dictionary. | ||
Smalltalk garbageCollect. | ||
self deny: dictionary isEmpty. | ||
|
||
materializedDictionary := self materialized. | ||
self deny: materializedDictionary isEmpty. | ||
self assert: materializedDictionary size equals: 1. | ||
self assert: materializedDictionary associations first key isNil. | ||
self assert: materializedDictionary associations first value equals: 'value'. | ||
|
||
Smalltalk garbageCollect. | ||
self deny: materializedDictionary isEmpty |
32 changes: 32 additions & 0 deletions
32
...ackage/FLEphemeronTest.class/instance/testWeakKeyAssociationWithStrongReferenceInGraph.st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
tests | ||
testWeakKeyAssociationWithStrongReferenceInGraph | ||
"This tests serialization / materialization of WeakKeyAssociation, which is an ephemeron class. | ||
When the key is strongly referenced, which is the case here, the garbage collector will | ||
not finalize the ephemeron. | ||
If the ephemeron's key is strongly referenced from inside the graph the key should also | ||
be serialized." | ||
|
||
| dictionary ephemeron materializedDictionary | | ||
dictionary := Dictionary new. | ||
ephemeron := WeakKeyAssociation new | ||
key: Object new; | ||
value: 'value'; | ||
container: dictionary. | ||
dictionary add: ephemeron. | ||
|
||
self deny: dictionary isEmpty. | ||
|
||
self serialize: {dictionary. ephemeron key}. | ||
Smalltalk garbageCollect. | ||
self deny: dictionary isEmpty. | ||
|
||
materializedDictionary := self materialized first. | ||
self deny: materializedDictionary isEmpty. | ||
self assert: materializedDictionary size equals: 1. | ||
self assert: materializedDictionary associations first key class identicalTo: Object. | ||
self assert: materializedDictionary associations first value equals: 'value'. | ||
|
||
Smalltalk garbageCollect. | ||
"As there's no strong reference to the materialized key, the ephemeron should | ||
be finalized by the garbage collector and remove itself from its container." | ||
self assert: materializedDictionary isEmpty |
11 changes: 11 additions & 0 deletions
11
repository/Fuel-Core-Tests.package/FLEphemeronTest.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "", | ||
"super" : "FLSerializationTest", | ||
"category" : "Fuel-Core-Tests-Base", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "FLEphemeronTest", | ||
"type" : "normal" | ||
} |
11 changes: 5 additions & 6 deletions
11
...ry/Fuel-Core.package/FLDictionaryCollectionCluster.class/instance/hasRealAssociations..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,11 @@ | ||
testing | ||
hasRealAssociations: aDictionary | ||
"Only check the first association, assume that all other entries | ||
"Weak assocations and ephemerons should not be serialized as simple key / value tuples | ||
but with their actual class. | ||
Only check the first association, assume that all other entries | ||
are of the same type" | ||
aDictionary associationsDo: [ :assoc | | ||
^ #( | ||
Association | ||
WeakKeyAssociation | ||
WeakValueAssociation | ||
) includes: assoc className ]. | ||
^ assoc class == Association ]. | ||
|
||
^ true |
2 changes: 0 additions & 2 deletions
2
...sitory/Fuel-Core.package/FLDictionaryCollectionCluster.class/instance/referencesOf.do..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
repository/Fuel-Core.package/FLDictionaryCollectionCluster.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 5 additions & 0 deletions
5
repository/Fuel-Core.package/FLEphemeronCluster.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
I am responsible for serializing and materializing ephemerons. Ephemerons are subclasses of Association with the EphemeronLayout class layout. The garbage collector finalizes ephemerons (called "mourning") when no strong references to the key of the association remain. | ||
|
||
See the class comment of FinalizationRegistryEntry for additional information. | ||
|
||
I only serialize the ephemeron's key if there's also a strong reference to it from within the graph, as otherwise the garbage collector would finalize and collect the ephemeron immediately during materialization. |
6 changes: 6 additions & 0 deletions
6
repository/Fuel-Core.package/FLEphemeronCluster.class/instance/clusterReferencesDo..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
analyzing | ||
clusterReferencesDo: aBlock | ||
"Ensures that nil could be encoded, later in references step." | ||
|
||
super clusterReferencesDo: aBlock. | ||
aBlock value: nil |
12 changes: 12 additions & 0 deletions
12
repository/Fuel-Core.package/FLEphemeronCluster.class/instance/referencesOf.do..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
analyzing | ||
referencesOf: anObject do: aBlock | ||
"Do not store strong reference to the key, which is essentially a weak reference. | ||
Do not trace the key either. We only want to serialize the key if there's an | ||
explicit reference to it in the graph." | ||
| key | | ||
key := anObject key. | ||
variablesMapping | ||
referencesOf: anObject | ||
do: [ :object | | ||
object == key ifFalse: [ | ||
aBlock value: object ] ] |
10 changes: 10 additions & 0 deletions
10
...sitory/Fuel-Core.package/FLEphemeronCluster.class/instance/serializeReferencesOf.with..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
serialize/materialize | ||
serializeReferencesOf: anObject with: anEncoder | ||
"As we did not trace the key we can simply encode it here, | ||
provided it was strongly referenced from within the graph." | ||
anEncoder encodeWeakReferenceTo: anObject key. | ||
|
||
"The references do not contain the key" | ||
super | ||
serializeReferencesOf: anObject | ||
with: anEncoder |
11 changes: 11 additions & 0 deletions
11
repository/Fuel-Core.package/FLEphemeronCluster.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
{ | ||
"commentStamp" : "MaxLeske 11/26/2023 09:58", | ||
"super" : "FLFixedObjectCluster", | ||
"category" : "Fuel-Core-Clusters", | ||
"classinstvars" : [ ], | ||
"pools" : [ ], | ||
"classvars" : [ ], | ||
"instvars" : [ ], | ||
"name" : "FLEphemeronCluster", | ||
"type" : "normal" | ||
} |
4 changes: 4 additions & 0 deletions
4
repository/Fuel-Core.package/FLLightGeneralMapper.class/instance/visitEphemeron..st
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
visiting | ||
visitEphemeron: anObject | ||
|
||
self mapAndTraceByObjectClass: anObject to: FLEphemeronCluster |
2 changes: 1 addition & 1 deletion
2
repository/Fuel-Core.package/FLWeakVariableObjectCluster.class/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
I am a cluster for objects with weak indexable variables. | ||
I am a cluster for objects with weak indexable variables. I only serialize a weak reference if there is also a strong reference from within the graph, as otherwise the garbage collector would immediately collect the object during materialization. |
2 changes: 1 addition & 1 deletion
2
repository/Fuel-Core.package/FLWeakVariableObjectCluster.class/properties.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters