[Vm-dev] [ENH] A better finalization support (VM & language side)

Igor Stasenko siguctua at gmail.com
Mon Mar 8 22:49:56 UTC 2010


On 9 March 2010 00:32, Andreas Raab <andreas.raab at gmx.de> wrote:
>
> Hi Igor -
>
> Could you give us a brief explanation about what you did? The bug report
> doesn't say much and the benchmark below says even less :-)
>

Oh.. sorry for being brief :)

There is a little change, introduced in ObjectMemory>>finalizeReference: oop
method , which:

a) once it detects an oop who having a weak references which just
died, and replaced by nil
b) given oop having at least 2 instance variables (non-weak pointers)
c) a first instance variable points to an object which is an instance
of class , registered as a special object (WeakFinalizer)

if all of these conditions met, then it simply does following:

	list := oop instVarAt: 1.
	list class == WeakFinalizer ifTrue: [
		first := list instVarAt: 1.
		oop instVarAt: 2 put: first.
		list instVarAt: 1 put: oop ]	

so, in case if you have a multiple such objects, which holding a weak
refs, and using the same object in 'list',
and then if some (or all of them will have their weak refs gone), then
these objects will be linked to that list:

head := list head.
list head: object.
object next: head.

This means, that list will contain only those objects, which losed a
weak refs during last GC, and so, you don't have to scan all items in
weak container to determine which ones if gone due to GC (like
currently WeakRegistry doing).


> Cheers,
>  - Andreas
>
> On 3/8/2010 1:31 PM, Igor Stasenko wrote:
>>
>> Please, review the
>> http://bugs.squeak.org/view.php?id=7473
>>
>> There are two sets of changesets - one for vmmaker and other is for
>> language-side.
>>
>> A VMMaker changeset is based on VMMaker-dtl.159.
>>
>> Here the little benchmark, between old and new weak registries:
>>
>> { WeakRegistry. WeakFinalizationRegistry } collect: [:class |
>>    | registry weaklings time1 time2 |
>>    registry := class new.
>>    WeakArray removeWeakDependent: registry.
>>
>>    weaklings := (1 to: 100000) collect: [:i | Object new ].
>>    time1 := [ weaklings do: [:each | registry add: each ] ] timeToRun.
>>    weaklings at: 100 put: nil.
>>    Smalltalk garbageCollect; garbageCollect.
>>    time2 := [ registry finalizeValues ] timeToRun.
>>    time1 @ time2
>> ]
>>  {7816 at 41 . 4114 at 0}
>>
>> While its not much better at first benchmark (since using the same
>> approach to store objects in one dictionary),
>> while other is significant, since there is no longer need to scan a
>> whole collection to detect an items which become a garbage.
>>
>> Btw, i wonder, why current WeakRegistry using a WeakKeyDictionary
>> instead of WeakIdentityKeyDictionary?
>> Isn't a weak refs is identity-based?
>>
>> I am also a bit wonder, why WeakRegistry has to support a copy protocol?
>> It may lead to unpredictable behavior once you try to copy such kind
>> of container, no matter how well you protect it.
>>
>



-- 
Best regards,
Igor Stasenko AKA sig.


More information about the Vm-dev mailing list