How to force finalization?

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

How to force finalization?

Martin McClure
To unit test some of our weak collections, we need to force the system
to garbage collect and finalize all objects that are eligible. By doing
things like "ObjectMemory globalGarbageCollect" and waiting a bit, and
repeating a few times, we can get it to collect most of the objects most
of the time.

However, we haven't yet found a way to get it to collect all of the
objects all of the time.

I don't know enough about how the VM collects weak references to know
what else to try. Before I run off and spend a lot of time reading docs
and VM sources, does anyone know offhand how this works? These are
WeakArray references, not ephemerons.

Thanks,

-Martin

Reply | Threaded
Open this post in threaded view
|

RE: How to force finalization?

Boris Popov, DeepCove Labs (SNN)
If you find a way to do it, please share. I have a few tests to ensure
that our image processing routines don't leak memory, but have yet to
find a reliable way of collecting all the garbage to make them pass all
the time. They pass most of the time when I do #globalGarbageCollect and
#yield a few times, but its still nowhere near 100%.

Cheers,

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Martin McClure [mailto:[hidden email]]
Sent: Friday, January 19, 2007 3:07 PM
To: VWNC
Subject: How to force finalization?

To unit test some of our weak collections, we need to force the system
to garbage collect and finalize all objects that are eligible. By doing
things like "ObjectMemory globalGarbageCollect" and waiting a bit, and
repeating a few times, we can get it to collect most of the objects most

of the time.

However, we haven't yet found a way to get it to collect all of the
objects all of the time.

I don't know enough about how the VM collects weak references to know
what else to try. Before I run off and spend a lot of time reading docs
and VM sources, does anyone know offhand how this works? These are
WeakArray references, not ephemerons.

Thanks,

-Martin

Reply | Threaded
Open this post in threaded view
|

RE: How to force finalization?

Alan Knight-2
I've had pretty good luck in the Glorp tests just repeating a few times if necessary, i.e.

doesCacheSatisfy: aBlock

10 timesRepeat: [
   Dialect garbageCollect.
   (Delay forMilliseconds: 100) wait.
   aBlock value ifTrue: [^true]].
  ^false

At 06:10 PM 1/19/2007, Boris Popov wrote:
If you find a way to do it, please share. I have a few tests to ensure
that our image processing routines don't leak memory, but have yet to
find a reliable way of collecting all the garbage to make them pass all
the time. They pass most of the time when I do #globalGarbageCollect and
#yield a few times, but its still nowhere near 100%.

Cheers,

-Boris

--
+1.604.689.0322
DeepCove Labs Ltd.
4th floor 595 Howe Street
Vancouver, Canada V6C 2T5
http://tinyurl.com/r7uw4

[hidden email]

CONFIDENTIALITY NOTICE

This email is intended only for the persons named in the message
header. Unless otherwise indicated, it contains information that is
private and confidential. If you have received it in error, please
notify the sender and delete the entire message including any
attachments.

Thank you.

-----Original Message-----
From: Martin McClure [[hidden email]]
Sent: Friday, January 19, 2007 3:07 PM
To: VWNC
Subject: How to force finalization?

To unit test some of our weak collections, we need to force the system
to garbage collect and finalize all objects that are eligible. By doing
things like "ObjectMemory globalGarbageCollect" and waiting a bit, and
repeating a few times, we can get it to collect most of the objects most

of the time.

However, we haven't yet found a way to get it to collect all of the
objects all of the time.

I don't know enough about how the VM collects weak references to know
what else to try. Before I run off and spend a lot of time reading docs
and VM sources, does anyone know offhand how this works? These are
WeakArray references, not ephemerons.

Thanks,

-Martin

--
Alan Knight [|], Cincom Smalltalk Development

"The Static Typing Philosophy: Make it fast. Make it right. Make it run." - Niall Ross
Reply | Threaded
Open this post in threaded view
|

Re: How to force finalization?

Reinout Heeck
In reply to this post by Martin McClure

Since finalizing objects may free up other objects to be finalized  
this is a problem of reaching a fixedpoint.

Essentially you want to repeat GCs as long as the previous GC has  
placed objects into the finalization queue.

Whenever something is placed on the finalization queue WeakArray  
class>>innerFinalizationLoopWith: is called. So you can try to  
instrument this method (MethodWrapper/DebugProbe/your own  
override/...) to detect finalization 'events'.

Now simply keep GC-ing until no more finilization events are detected.


Finalizers runs at priority 90 so you should not need delays to allow  
for them to run.



(I haven't tried this ;-)


R
-

Reply | Threaded
Open this post in threaded view
|

Re: How to force finalization?

Reinout Heeck
I couldn't resist...

I hacked a way to detect finalization without instrumenting methods,
the comment illustrates how to use it to force deep finalization:




WeakArray class>>
finalizesWhile: aBlock
        "Return whether objects are finalized during excution of aBlock.
        Must run at priority < #lowIOPriority"

        "[WeakArray finalizesWhile: [ ObjectMemory verboseGlobalCompactingGC]]
                whileTrue:[Transcript tab; show: 'need more:']"

        | sem continue finalized |
        sem := Semaphore new.
        continue := true.
        finalized := false.
       
        [
        [sem wait.
        continue] whileTrue:
                                [finalized := true.
                                FinalizationSemaphore signal]]
                        forkAt: Processor highIOPriority.
       
        [self installFinalizationSemaphore: sem.
        aBlock value] ensure:
                                [self installFinalizationSemaphore: FinalizationSemaphore.
                                continue := false.
                                sem signal].
        ^finalized





Anybody care to test this in anger?


R
-






On Jan 20, 2007, at 12:18 PM, Reinout Heeck wrote:

>
> Since finalizing objects may free up other objects to be finalized  
> this is a problem of reaching a fixedpoint.
>
> Essentially you want to repeat GCs as long as the previous GC has  
> placed objects into the finalization queue.
>
> Whenever something is placed on the finalization queue WeakArray  
> class>>innerFinalizationLoopWith: is called. So you can try to  
> instrument this method (MethodWrapper/DebugProbe/your own  
> override/...) to detect finalization 'events'.
>
> Now simply keep GC-ing until no more finilization events are detected.
>
>
> Finalizers runs at priority 90 so you should not need delays to  
> allow for them to run.
>
>
>
> (I haven't tried this ;-)
>
>
> R
> -
>
>

Reply | Threaded
Open this post in threaded view
|

[ann] ForceFinalization

Reinout Heeck

I published into the open repository as package ForceFinalization.

after loading you can

ObjectMemory finalizeDeeply.
ObjectMemory globalFinalizeDeeply.
ObjectMemory verboseFinalizeDeeply.
ObjectMemory verboseGlobalFinalizeDeeply.


Please let me know if this works,

R
-




On Jan 20, 2007, at 2:23 PM, Reinout Heeck wrote:

> I couldn't resist...
>
> I hacked a way to detect finalization without instrumenting methods,
> the comment illustrates how to use it to force deep finalization:
>
>
>
>
> WeakArray class>>
> finalizesWhile: aBlock
> "Return whether objects are finalized during excution of aBlock.
> Must run at priority < #lowIOPriority"
>
> "[WeakArray finalizesWhile: [ ObjectMemory  
> verboseGlobalCompactingGC]]
> whileTrue:[Transcript tab; show: 'need more:']"
>
> | sem continue finalized |
> sem := Semaphore new.
> continue := true.
> finalized := false.
>
> [
> [sem wait.
> continue] whileTrue:
> [finalized := true.
> FinalizationSemaphore signal]]
> forkAt: Processor highIOPriority.
>
> [self installFinalizationSemaphore: sem.
> aBlock value] ensure:
> [self installFinalizationSemaphore: FinalizationSemaphore.
> continue := false.
> sem signal].
> ^finalized
>
>
>
>
>
> Anybody care to test this in anger?
>
>
> R
> -
>
>
>
>
>
>
> On Jan 20, 2007, at 12:18 PM, Reinout Heeck wrote:
>
>>
>> Since finalizing objects may free up other objects to be finalized  
>> this is a problem of reaching a fixedpoint.
>>
>> Essentially you want to repeat GCs as long as the previous GC has  
>> placed objects into the finalization queue.
>>
>> Whenever something is placed on the finalization queue WeakArray  
>> class>>innerFinalizationLoopWith: is called. So you can try to  
>> instrument this method (MethodWrapper/DebugProbe/your own  
>> override/...) to detect finalization 'events'.
>>
>> Now simply keep GC-ing until no more finilization events are  
>> detected.
>>
>>
>> Finalizers runs at priority 90 so you should not need delays to  
>> allow for them to run.
>>
>>
>>
>> (I haven't tried this ;-)
>>
>>
>> R
>> -
>>
>>
>
>