New weak finalization support. Implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

New weak finalization support. Implementation

Igor Stasenko
Hello,
i updated the weak finalization classes.

I made its behavior/protocol similar to old WeakRegistry,
also all weak registry tests on new class is green.

First, file in .st
then .cs

Also, don't forget about special objects array:
http://bugs.squeak.org/view.php?id=7525

And sure thing, you will need a VM support for it.

But I am unsure, how to introduce a fallback code (and do we really need it)?
I thought, that i could just add a simple startUp routine which does
GC to see if new finalization supported by VM.
Then it could pick either WeakFinalizationRegistry or old WeakRegistry.
But then, it will slow down the image startup significantly,
not saying that John fought hard to avoid full memory/heap walk during
image startup on iPhone.
So, maybe introduce an additional prim into VM, which will tell us if
it supports new finalization?
Or query the VM version?
I need your advice.


--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project

new finalization.zip (7K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: [squeak-dev] Re: New weak finalization support. Implementation

Igor Stasenko
Guys, it looks like i found an elegant solution.

Please check the new-finalization-auto.2.cs, which i uploaded to
http://bugs.squeak.org/view.php?id=7473.

It adds just a few things:

initTestPair
        TestItem := WeakFinalizerItem new list: TestList object: Object new.

checkTestPair
        HasNewFinalization := TestList swapWithNil notNil.

These two method is then sent from within WeakArray's finalization process:

finalizationProcess
        [true] whileTrue:
                [ WeakFinalizationRegistry initTestPair.
                FinalizationSemaphore wait.
                FinalizationLock critical:
                        [
                        WeakFinalizationRegistry checkTestPair.
                        FinalizationDependents do:
                                [:weakDependent |
                                weakDependent ifNotNil:
                                        [weakDependent finalizeValues]]]
                        ifError:
                        [:msg :rcvr | rcvr error: msg].
                ].

And so, at each GC cycle, a new registry it knows exactly if it
allowed to do a shortcut, or not.

And if not, then it behaves in same way as old registry - it starts
scanning the whole dictionary to
clean graveyard.

So, in summary: running on older VMs , a WeakFinalizationRegistry will
behave exactly as old WeakRegistry.
While on VMs, which supporting new finalization, it will do a shortcut.

This is at cost of extra 2 objects, allocated per GC cycle, to detect
if new finalization is supported.

P.S. oops, actually it could be just one object.. just need to change
two methods at WeakFinalizationRegistry class side:

initialize
   TestList := WeakFinalizationList new.
   TestItem := WeakFinalizerItem new.

initTestPair
   TestList swapWithNil. "make sure list is empty"
   TestItem list: TestList object: Object new.

--
Best regards,
Igor Stasenko AKA sig.

_______________________________________________
Pharo-project mailing list
[hidden email]
http://lists.gforge.inria.fr/cgi-bin/mailman/listinfo/pharo-project