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

Igor Stasenko siguctua at gmail.com
Wed Mar 10 04:24:17 UTC 2010

On 10 March 2010 06:03, Igor Stasenko <siguctua at gmail.com> wrote:
> 2010/3/10 Levente Uzonyi <leves at elte.hu>:
>>> The main role of weak registry is to receive a notification, when
>>> particular object become garbage.
>>> Obviously, for this, we need to store a reference to notification
>>> handler (also known as executor) somewhere to
>>> be able to handle it. That's why current implementation using WeakKeyDictionary.
>>> Once such notification is handled, we usually no longer need to keep
>>> this object as well (thus we have to remove/unlink it from registry).
>> I didn't see any code in your changesets that changed the way how weak registries are notified when their objects are gone. Did I miss something?
>> If not, then #finalizeValues is still sent by the finalization process of WeakArray when it's semaphore is signaled, so one just has to register it's registry there.
> Well, looks like you paying too much attention to implementation
> details and don't see the whole idea behind this.
> Its not really matter in what way you receiving such notification ,
> what matters is that sometimes you need to be able to receive
> a notification when some object become garbage. This is the reason why
> we having a WeakRegistry.

Think of following potential implementation:

SocketHandle>>initialize: ...
	socketHandle :=
		self primSocketCreateNetwork: 0
			type: socketType
			receiveBufferSize: 8000
			sendBufSize: 8000
			semaIndex: semaIndex
			readSemaIndex: readSemaIndex
			writeSemaIndex: writeSemaIndex.

   socketHandle ifNotNil: [
       self onDeathDo: [
                Socket primSocketDestroyGently: socketHandle.
                Smalltalk unregisterExternalObject: semaphore.
		Smalltalk unregisterExternalObject: readSemaphore.
		Smalltalk unregisterExternalObject: writeSemaphore.

as simple as that.
You just telling the system, that once socket object become garbage,
evaluate the block - an argument of #onDeathDo: message.

Do such pattern convincing you that what we talking here is about
notification when particular object dies?
Also, you may notice that given approach is much simpler and
straightforward comparing to existing one, where you have to implement
own #register:, #unregister: and #finalize?
We could have such protocol (#myWill: , #cancelBurialCeremony ;) ) for
all Objects in system, and don't pay attention anymore to speak
directly to WeakRegistry.

Best regards,
Igor Stasenko AKA sig.

More information about the Vm-dev mailing list