In perl.git, the branch smoke-me/destruct has been updated

<http://perl5.git.perl.org/perl.git/commitdiff/127859483e0b957b2909f98d9e3e5f0d6f7a19b3?hp=5637ef5b34a3e8caf72080387a15ea8d81b61baf>

- Log -----------------------------------------------------------------
commit 127859483e0b957b2909f98d9e3e5f0d6f7a19b3
Author: Nicholas Clark <[email protected]>
Date:   Fri Jan 13 13:16:11 2012 +0100

    Don't set PL_perl_destruct_level = 2 as a side effect of use threads;
    
    There's no reason to enable full global destruction in the *top most 
thread*,
    which is what the code used to do by setting PL_perl_destruct_level in a
    BOOT block. The top most thread of an interpreter that has created threads
    is no different to the only thread of an interpreter that has never created
    threads, and we don't force full destruction there.
    
    Instead, it only needs to be enabled in child threads, to ensure that they
    are properly cleaned up.
    
    I'm not confident that there are zero users out there on existing perls,
    possibly in embedding scenarios, who are relying on some side effect of
    setting destruction globally, so for now only enable this change on newer
    perls. (As we expect people to have tested things more carefully before
    upgrading their entire perl installation, and can't legislate against all
    foolishness if they don't.)

M       dist/threads/lib/threads.pm
M       dist/threads/threads.xs

commit 92a6767337d69ae0c987ad08cd82aeca6e97bc25
Author: Nicholas Clark <[email protected]>
Date:   Fri Jan 13 12:51:49 2012 +0100

    Skip updating per-class method caches during global destruction.
    
    If we're sufficiently far into global destruction that all objects are gone,
    then it's much faster to invalidate all method caches globally and
    return. It's unlikely that they will be needed again, but it's not
    inconceivable (eg XS code attached to free magic creating more objects).

M       mro.c
-----------------------------------------------------------------------

Summary of changes:
 dist/threads/lib/threads.pm |    2 +-
 dist/threads/threads.xs     |   15 +++++++++++++++
 mro.c                       |   10 ++++++++++
 3 files changed, 26 insertions(+), 1 deletions(-)

diff --git a/dist/threads/lib/threads.pm b/dist/threads/lib/threads.pm
index 3c55886..b03aa94 100644
--- a/dist/threads/lib/threads.pm
+++ b/dist/threads/lib/threads.pm
@@ -5,7 +5,7 @@ use 5.008;
 use strict;
 use warnings;
 
-our $VERSION = '1.86';
+our $VERSION = '1.87';
 my $XS_VERSION = $VERSION;
 $VERSION = eval $VERSION;
 
diff --git a/dist/threads/threads.xs b/dist/threads/threads.xs
index f6fe7dc..40e1e03 100644
--- a/dist/threads/threads.xs
+++ b/dist/threads/threads.xs
@@ -779,6 +779,17 @@ S_ithread_create(
     thread->interp = perl_clone(aTHX, CLONEf_KEEP_PTR_TABLE);
 #endif
 
+#if PERL_VERSION >= 15
+    /* We only need total destruction on child threads. The parent thread
+       (the main interpreter) is no different from the "never created a
+       thread" case, and the destruct level is not forced to 2 there.
+
+       This may be a not-entirely-compatible change, so for now, only enable
+       it for the next version of Perl 5. The old code remains in the BOOT
+       section. */
+    thread->interp->Iperl_destruct_level = 2;
+#endif
+
     /* perl_clone() leaves us in new interpreter's context.  As it is tricky
      * to spot an implicit aTHX, create a new scope with aTHX matching the
      * context for the duration of our work for new interpreter.
@@ -1758,7 +1769,11 @@ BOOT:
     Zero(my_poolp, 1, my_pool_t);
     sv_setuv(my_pool_sv, PTR2UV(my_poolp));
 
+    /* See the comment in S_ithread_create as to why this is conditionally
+       compiled in (for now), rather than simply removed.  */
+#  if PERL_VERSION < 15
     PL_perl_destruct_level = 2;
+#  endif
     MUTEX_INIT(&MY_POOL.create_destruct_mutex);
     MUTEX_LOCK(&MY_POOL.create_destruct_mutex);
 
diff --git a/mro.c b/mro.c
index 94be41c..5cbb212 100644
--- a/mro.c
+++ b/mro.c
@@ -1321,6 +1321,16 @@ Perl_mro_method_changed_in(pTHX_ HV *stash)
     /* Inc the package generation, since a local method changed */
     HvMROMETA(stash)->pkg_gen++;
 
+    if (PL_phase == PERL_PHASE_DESTRUCT && PL_sv_objcount == 0) {
+       /* If we're sufficiently far into global destruction that all objects
+          are gone, then it's much faster to invalidate all method caches
+          globally and return. It's unlikely that they will be needed again,
+          but it's not inconceivable (eg XS code attached to free magic
+          creating more objects).  */
+        ++PL_sub_generation;
+        return;
+    }
+
     /* If stash is UNIVERSAL, or one of UNIVERSAL's parents,
        invalidate all method caches globally */
     if((stashname_len == 9 && strEQ(stashname, "UNIVERSAL"))

--
Perl5 Master Repository

Reply via email to