Re: [PATCH] force finalizers only if finalizers exist

2020-05-07 Thread felix . winkelmann
> The Right Thing is probably to eventually run the GC on a private thread,
> at least when multiple threads are running at all.  That way the finalizers
> run on the same thread that doesn't hold any locks or otherwise risk
> trouble.  That's what the JVM and the CLR do.
>

Yes, this was already the consensus, but thready/interrupts/IO/finalizers
and all the interactions between them need an overhaul anyway.


felix





Re: [PATCH] force finalizers only if finalizers exist

2020-05-06 Thread Jörg F. Wittenberger
On Wed, 6 May 2020 13:13:24 -0400
John Cowan  wrote:

> The Right Thing is probably to eventually run the GC on a private
> thread, at least when multiple threads are running at all.  That way
> the finalizers run on the same thread that doesn't hold any locks or
> otherwise risk trouble.  That's what the JVM and the CLR do.

+1!

Safe for interrupts.  Better we send them to a dedicated thread (may,
or may not be the same as the finilizer thread; my bet: the same).

> 
> On Wed, May 6, 2020 at 5:42 AM  wrote:
> 
> > > There might be a situation where a thread is already executing
> > > ##sys#run-pending-finalizers, but has run out of its time slice,
> > > or gc interrupted or something. In this situation running
> > > ##sys#run-pending-finalizers only once might not be enough.  
> >
> > This is basically true, but with threads we make no effort to
> > terminate them properly once the main thread exists - all unjoined
> > threads will die anyway,
> > regardless of what they are currently doing.
> >
> > Also, the interplay between threads and finalizers is more or less
> > undefined - interrupts are executed in whatever thread happens to be
> > active and manually forcing finalizers in a different thread than
> > the main thread is already asking for trouble. This is a known
> > problem of the threading/interrupt system and needs to be solved
> > differently.
> >
> >
> > felix
> >
> >
> >
> >  




Re: [PATCH] force finalizers only if finalizers exist

2020-05-06 Thread John Cowan
The Right Thing is probably to eventually run the GC on a private thread,
at least when multiple threads are running at all.  That way the finalizers
run on the same thread that doesn't hold any locks or otherwise risk
trouble.  That's what the JVM and the CLR do.

On Wed, May 6, 2020 at 5:42 AM  wrote:

> > There might be a situation where a thread is already executing
> > ##sys#run-pending-finalizers, but has run out of its time slice, or gc
> > interrupted or something. In this situation running
> > ##sys#run-pending-finalizers only once might not be enough.
>
> This is basically true, but with threads we make no effort to terminate
> them properly once the main thread exists - all unjoined threads will die
> anyway,
> regardless of what they are currently doing.
>
> Also, the interplay between threads and finalizers is more or less
> undefined - interrupts are executed in whatever thread happens to be
> active and manually forcing finalizers in a different thread than the
> main thread is already asking for trouble. This is a known problem of
> the threading/interrupt system and needs to be solved differently.
>
>
> felix
>
>
>
>


Re: [PATCH] force finalizers only if finalizers exist

2020-05-06 Thread felix . winkelmann
> There might be a situation where a thread is already executing
> ##sys#run-pending-finalizers, but has run out of its time slice, or gc
> interrupted or something. In this situation running
> ##sys#run-pending-finalizers only once might not be enough.

This is basically true, but with threads we make no effort to terminate
them properly once the main thread exists - all unjoined threads will die 
anyway,
regardless of what they are currently doing.

Also, the interplay between threads and finalizers is more or less
undefined - interrupts are executed in whatever thread happens to be
active and manually forcing finalizers in a different thread than the
main thread is already asking for trouble. This is a known problem of
the threading/interrupt system and needs to be solved differently.


felix





Re: [PATCH] force finalizers only if finalizers exist

2020-05-03 Thread megane


felix.winkelm...@bevuta.com writes:

>> On 2020-04-07 14:51, felix.winkelm...@bevuta.com wrote:
>> > > > This patch disables the final GC for finalizer forcing at normal 
>> > > > program termination
>> > > > if no finalizers are live as the GC is unnecessary in such cases.
>> > >
>> > > How about possible pending finalizers?
>> >
>> > You mean pending from a previous GC? I'm not sure - shouldn't they already
>> > be executed at this stage?
>>
>> Hey megane, could you go into a bit more detail about this?
>>
>> If I understand correctly, you mean that some finalizers that have been
>> moved onto the pending_finalizers_symbol may not have been invoked by
>> this point, but will also not included in the C_i_live_finalizers_count,
>> is that right? That seems right to me, but it's not clear to me what the
>> check should rather be.
>>
>
> live_finalizer_count gets decreased when a pending finalizer is inserted
> into the pending finalizers lists, so I understand that the live count does 
> not
> include the pending ones. But the ones pending are not automatically run,
> so it may be that before exiting we may have to do a final 
> ##sys#run-pending-finalizers.
> I will submit a modified patch.

Yeah that sounds about right.

There might be a situation where a thread is already executing
##sys#run-pending-finalizers, but has run out of its time slice, or gc
interrupted or something. In this situation running
##sys#run-pending-finalizers only once might not be enough.


>
>
> felix



Re: [PATCH] force finalizers only if finalizers exist

2020-04-29 Thread felix . winkelmann
> On 2020-04-07 14:51, felix.winkelm...@bevuta.com wrote:
> > > > This patch disables the final GC for finalizer forcing at normal 
> > > > program termination
> > > > if no finalizers are live as the GC is unnecessary in such cases.
> > >
> > > How about possible pending finalizers?
> >
> > You mean pending from a previous GC? I'm not sure - shouldn't they already
> > be executed at this stage?
>
> Hey megane, could you go into a bit more detail about this?
>
> If I understand correctly, you mean that some finalizers that have been
> moved onto the pending_finalizers_symbol may not have been invoked by
> this point, but will also not included in the C_i_live_finalizers_count,
> is that right? That seems right to me, but it's not clear to me what the
> check should rather be.
>

live_finalizer_count gets decreased when a pending finalizer is inserted
into the pending finalizers lists, so I understand that the live count does not
include the pending ones. But the ones pending are not automatically run,
so it may be that before exiting we may have to do a final 
##sys#run-pending-finalizers.
I will submit a modified patch.


felix





Re: [PATCH] force finalizers only if finalizers exist

2020-04-29 Thread Evan Hanson
On 2020-04-07 14:51, felix.winkelm...@bevuta.com wrote:
> > > This patch disables the final GC for finalizer forcing at normal program 
> > > termination
> > > if no finalizers are live as the GC is unnecessary in such cases.
> >
> > How about possible pending finalizers?
> 
> You mean pending from a previous GC? I'm not sure - shouldn't they already
> be executed at this stage?

Hey megane, could you go into a bit more detail about this?

If I understand correctly, you mean that some finalizers that have been
moved onto the pending_finalizers_symbol may not have been invoked by
this point, but will also not included in the C_i_live_finalizers_count,
is that right? That seems right to me, but it's not clear to me what the
check should rather be.

Evan



Re: [PATCH] force finalizers only if finalizers exist

2020-04-07 Thread felix . winkelmann
>
> felix.winkelm...@bevuta.com writes:
>
> > This patch disables the final GC for finalizer forcing at normal program 
> > termination
> > if no finalizers are live as the GC is unnecessary in such cases.
>
> How about possible pending finalizers?

You mean pending from a previous GC? I'm not sure - shouldn't they already
be executed at this stage?


felix





Re: [PATCH] force finalizers only if finalizers exist

2020-04-07 Thread megane


felix.winkelm...@bevuta.com writes:

> This patch disables the final GC for finalizer forcing at normal program 
> termination
> if no finalizers are live as the GC is unnecessary in such cases.

How about possible pending finalizers?

>
> felix




[PATCH] force finalizers only if finalizers exist

2020-04-07 Thread felix . winkelmann
This patch disables the final GC for finalizer forcing at normal program 
termination
if no finalizers are live as the GC is unnecessary in such cases.

felix

From fe21a1e2d61196d07f766fac87d8bf54dcc95336 Mon Sep 17 00:00:00 2001
From: felix 
Date: Tue, 7 Apr 2020 12:40:22 +0200
Subject: [PATCH] Only force finalizers at program cleanup when live finalizer
 count is non-zero

---
 library.scm | 9 +
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/library.scm b/library.scm
index 199057f7..edee62aa 100644
--- a/library.scm
+++ b/library.scm
@@ -5002,10 +5002,11 @@ EOF
   (unless (null? tasks)
 	(for-each (lambda (t) (t)) tasks)
 	(loop
-  (when (##sys#debug-mode?)
-(##sys#print "[debug] forcing finalizers...\n" #f ##sys#standard-error))
-  (when (chicken.gc#force-finalizers)
-(##sys#force-finalizers)))
+  (when (fx> (##core#inline "C_i_live_finalizer_count") 0)
+(when (##sys#debug-mode?)
+  (##sys#print "[debug] forcing finalizers...\n" #f ##sys#standard-error))
+(when (chicken.gc#force-finalizers)
+  (##sys#force-finalizers
 
 (set! chicken.base#exit-handler
   (make-parameter
-- 
2.21.0