New weak finalization support. Implementation

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
5 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.



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

Re: New weak finalization support. Implementation

Eliot Miranda-2


On Mon, May 24, 2010 at 9:35 PM, Igor Stasenko <[hidden email]> wrote:
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?

Or store it in a flag in the image header flags word, accessed through vmParameterAt:put:. I would argue strongly that the VM should be backwards-compatible and the new mechanism is enabled by an image and that the enablement persists with the image rather than having to be reestablished on every startup.

I can supply code examples which will make this trivial.

best
Eliot

I need your advice.


--
Best regards,
Igor Stasenko AKA sig.






Reply | Threaded
Open this post in threaded view
|

Re: New weak finalization support. Implementation

Igor Stasenko
On 25 May 2010 07:47, Eliot Miranda <[hidden email]> wrote:

>
>
> On Mon, May 24, 2010 at 9:35 PM, Igor Stasenko <[hidden email]> wrote:
>>
>> 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?
>
> Or store it in a flag in the image header flags word, accessed through
> vmParameterAt:put:. I would argue strongly that the VM should be
> backwards-compatible and the new mechanism is enabled by an image and that
> the enablement persists with the image rather than having to be
> reestablished on every startup.
> I can supply code examples which will make this trivial.

Please, do. I never dealt with #vmParameterAt:put: before.

> best
> Eliot
>>
>> I need your advice.
>>
>>
>> --
>> Best regards,
>> Igor Stasenko AKA sig.
>>
>>
>>
>
>
>
>
>



--
Best regards,
Igor Stasenko AKA sig.

Reply | Threaded
Open this post in threaded view
|

Re: New weak finalization support. Implementation

Andreas.Raab
In reply to this post by Eliot Miranda-2
On 5/24/2010 9:47 PM, Eliot Miranda wrote:
> Or store it in a flag in the image header flags word, accessed through
> vmParameterAt:put:. I would argue strongly that the VM should be
> backwards-compatible and the new mechanism is enabled by an image and
> that the enablement persists with the image rather than having to be
> reestablished on every startup.

I really don't like using header bits like that. Header bits are an
*extremely* scarce resource since every new bit effectively cuts the
image format version space in half. Once we have 32 header bits we can't
use an image format identifier any longer because every possible
combination of bits will be spoken for by some obscure combination of
features.

Really, if you want to use header bits more regularly, then we should
add a new image format that has room for header bits depending on image
format version. That way you can add header bits and their meaning
incrementally and when you've run out of space you're forced to update
the image format version (which resets and accumulates previously
optional features).

For the case at hand, what's wrong with simply requiring that the
sizeof(splObjs) must be larger than 55 to enable the finalization
scheme? That is backwards compatible and doesn't require fuzzing with
header bits.

Cheers,
   - Andreas

Reply | Threaded
Open this post in threaded view
|

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.