r74608 - in /trunk/libdevel-size-perl: CHANGES META.yml Size.xs debian/changelog lib/Devel/Size.pm t/basic.t t/globs.t
periapt-guest at users.alioth.debian.org
periapt-guest at users.alioth.debian.org
Tue May 17 00:36:24 UTC 2011
Author: periapt-guest
Date: Tue May 17 00:36:13 2011
New Revision: 74608
URL: http://svn.debian.org/wsvn/pkg-perl/?sc=1&rev=74608
Log:
New upstream release
Modified:
trunk/libdevel-size-perl/CHANGES
trunk/libdevel-size-perl/META.yml
trunk/libdevel-size-perl/Size.xs
trunk/libdevel-size-perl/debian/changelog
trunk/libdevel-size-perl/lib/Devel/Size.pm
trunk/libdevel-size-perl/t/basic.t
trunk/libdevel-size-perl/t/globs.t
Modified: trunk/libdevel-size-perl/CHANGES
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/CHANGES?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/CHANGES (original)
+++ trunk/libdevel-size-perl/CHANGES Tue May 17 00:36:13 2011
@@ -1,4 +1,13 @@
Revision history for Perl extension Devel::Size.
+
+0.77 2011-05-16 nicholas
+ [no changes]
+
+0.76_50 2011-05-12 nicholas
+ * Split out HEK size calculation into hek_size(). Add the shared HE overhead.
+ * Handle shared hash key scalars correctly.
+ * GvNAME() is shared from 5.10 onwards.
+ * Count HvNAME(), the HV "aux" struct, the mro_meta struct, and ENAMEs.
0.76 2011-05-11 nicholas
* Just fix the version number in the line below.
Modified: trunk/libdevel-size-perl/META.yml
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/META.yml?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/META.yml (original)
+++ trunk/libdevel-size-perl/META.yml Tue May 17 00:36:13 2011
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: Devel-Size
-version: 0.76
+version: 0.77
abstract: ~
author: []
license: perl
Modified: trunk/libdevel-size-perl/Size.xs
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/Size.xs?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/Size.xs (original)
+++ trunk/libdevel-size-perl/Size.xs Tue May 17 00:36:13 2011
@@ -1,3 +1,5 @@
+/* -*- mode: C -*- */
+
#define PERL_NO_GET_CONTEXT
#include "EXTERN.h"
@@ -14,6 +16,17 @@
#endif
#ifndef SvOOK_offset
# define SvOOK_offset(sv, len) STMT_START { len = SvIVX(sv); } STMT_END
+#endif
+#ifndef SvIsCOW
+# define SvIsCOW(sv) ((SvFLAGS(sv) & (SVf_FAKE | SVf_READONLY)) == \
+ (SVf_FAKE | SVf_READONLY))
+#endif
+#ifndef SvIsCOW_shared_hash
+# define SvIsCOW_shared_hash(sv) (SvIsCOW(sv) && SvLEN(sv) == 0)
+#endif
+#ifndef SvSHARED_HEK_FROM_PV
+# define SvSHARED_HEK_FROM_PV(pvx) \
+ ((struct hek*)(pvx - STRUCT_OFFSET(struct hek, hek_key)))
#endif
#if PERL_VERSION < 6
@@ -146,7 +159,7 @@
/* Nodes */
do {
if (tv[i]) {
- free_tracking_at(tv[i], level);
+ free_tracking_at((void **) tv[i], level);
Safefree(tv[i]);
}
} while (i--);
@@ -522,6 +535,29 @@
warn( "Devel::Size: Encountered dangling pointer in opcode at: %p\n", baseop );
}
}
+
+static void
+hek_size(pTHX_ struct state *st, HEK *hek, U32 shared)
+{
+ /* Hash keys can be shared. Have we seen this before? */
+ if (!check_new(st, hek))
+ return;
+ st->total_size += HEK_BASESIZE + hek->hek_len
+#if PERL_VERSION < 8
+ + 1 /* No hash key flags prior to 5.8.0 */
+#else
+ + 2
+#endif
+ ;
+ if (shared) {
+#if PERL_VERSION < 10
+ st->total_size += sizeof(struct he);
+#else
+ st->total_size += STRUCT_OFFSET(struct shared_he, shared_he_hek);
+#endif
+ }
+}
+
#if PERL_VERSION < 8 || PERL_SUBVERSION < 9
# define SVt_LAST 16
@@ -698,18 +734,53 @@
cur_entry = *(HvARRAY(thing) + cur_bucket);
while (cur_entry) {
st->total_size += sizeof(HE);
- if (cur_entry->hent_hek) {
- /* Hash keys can be shared. Have we seen this before? */
- if (check_new(st, cur_entry->hent_hek)) {
- st->total_size += HEK_BASESIZE + cur_entry->hent_hek->hek_len + 2;
- }
- }
+ hek_size(aTHX_ st, cur_entry->hent_hek, HvSHAREKEYS(thing));
if (recurse >= TOTAL_SIZE_RECURSION)
sv_size(aTHX_ st, HeVAL(cur_entry), recurse);
cur_entry = cur_entry->hent_next;
}
}
}
+#ifdef HvAUX
+ if (SvOOK(thing)) {
+ /* This direct access is arguably "naughty": */
+ struct mro_meta *meta = HvAUX(thing)->xhv_mro_meta;
+#if PERL_VERSION > 13 || PERL_SUBVERSION > 8
+ /* As is this: */
+ I32 count = HvAUX(thing)->xhv_name_count;
+
+ if (count) {
+ HEK **names = HvAUX(thing)->xhv_name_u.xhvnameu_names;
+ if (count < 0)
+ count = -count;
+ while (--count)
+ hek_size(aTHX_ st, names[count], 1);
+ }
+ else
+#endif
+ {
+ hek_size(aTHX_ st, HvNAME_HEK(thing), 1);
+ }
+
+ st->total_size += sizeof(struct xpvhv_aux);
+ if (meta) {
+ st->total_size += sizeof(struct mro_meta);
+ sv_size(aTHX_ st, (SV *)meta->mro_nextmethod, TOTAL_SIZE_RECURSION);
+#if PERL_VERSION > 10 || (PERL_VERSION == 10 && PERL_SUBVERSION > 0)
+ sv_size(aTHX_ st, (SV *)meta->isa, TOTAL_SIZE_RECURSION);
+#endif
+#if PERL_VERSION > 10
+ sv_size(aTHX_ st, (SV *)meta->mro_linear_all, TOTAL_SIZE_RECURSION);
+ sv_size(aTHX_ st, meta->mro_linear_current, TOTAL_SIZE_RECURSION);
+#else
+ sv_size(aTHX_ st, (SV *)meta->mro_linear_dfs, TOTAL_SIZE_RECURSION);
+ sv_size(aTHX_ st, (SV *)meta->mro_linear_c3, TOTAL_SIZE_RECURSION);
+#endif
+ }
+ }
+#else
+ check_new_and_strlen(st, HvNAME_get(thing));
+#endif
TAG;break;
@@ -763,8 +834,14 @@
case SVt_PVGV: TAG;
if(isGV_with_GP(thing)) {
+#ifdef GvNAME_HEK
+ hek_size(aTHX_ st, GvNAME_HEK(thing), 1);
+#else
st->total_size += GvNAMELEN(thing);
-#ifdef GvFILE
+#endif
+#ifdef GvFILE_HEK
+ hek_size(aTHX_ st, GvFILE_HEK(thing), 1);
+#elif defined(GvFILE)
# if !defined(USE_ITHREADS) || (PERL_VERSION > 8 || (PERL_VERSION == 8 && PERL_SUBVERSION > 8))
/* With itreads, before 5.8.9, this can end up pointing to freed memory
if the GV was created in an eval, as GvFILE() points to CopFILE(),
@@ -800,6 +877,8 @@
freescalar:
if(recurse && SvROK(thing))
sv_size(aTHX_ st, SvRV_const(thing), recurse);
+ else if (SvIsCOW_shared_hash(thing))
+ hek_size(aTHX_ st, SvSHARED_HEK_FROM_PV(SvPVX(thing)), 1);
else
st->total_size += SvLEN(thing);
Modified: trunk/libdevel-size-perl/debian/changelog
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/debian/changelog?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/debian/changelog (original)
+++ trunk/libdevel-size-perl/debian/changelog Tue May 17 00:36:13 2011
@@ -1,3 +1,9 @@
+libdevel-size-perl (0.77-1) UNRELEASED; urgency=low
+
+ * New upstream release
+
+ -- Nicholas Bamber <nicholas at periapt.co.uk> Tue, 17 May 2011 01:38:29 +0100
+
libdevel-size-perl (0.76-1) unstable; urgency=low
* New upstream release.
Modified: trunk/libdevel-size-perl/lib/Devel/Size.pm
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/lib/Devel/Size.pm?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/lib/Devel/Size.pm (original)
+++ trunk/libdevel-size-perl/lib/Devel/Size.pm Tue May 17 00:36:13 2011
@@ -14,7 +14,7 @@
# This allows declaration use Devel::Size ':all';
%EXPORT_TAGS = ( 'all' => \@EXPORT_OK );
-$VERSION = '0.76';
+$VERSION = '0.77';
XSLoader::load( __PACKAGE__);
Modified: trunk/libdevel-size-perl/t/basic.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/t/basic.t?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/t/basic.t (original)
+++ trunk/libdevel-size-perl/t/basic.t Tue May 17 00:36:13 2011
@@ -1,6 +1,6 @@
#!/usr/bin/perl -w
-use Test::More tests => 19;
+use Test::More tests => 30;
use strict;
use Devel::Size qw(size total_size);
@@ -10,7 +10,7 @@
/);
die ("Uhoh, test uses an outdated version of Devel::Size")
- unless is ($Devel::Size::VERSION, '0.76', 'VERSION MATCHES');
+ unless is ($Devel::Size::VERSION, '0.77', 'VERSION MATCHES');
#############################################################################
# some basic checks:
@@ -123,3 +123,51 @@
"Size doesn't change because OOK is used");
cmp_ok(length $uurk, '<', $before_size, 'but string is shorter');
}
+
+sub shared_hash_keys {
+ my %h = @_;
+ my $one = total_size([keys %h]);
+ cmp_ok($one, '>', 0, 'Size of one entry is sane');
+ my $two = total_size([keys %h, keys %h]);
+ cmp_ok($two, '>', $one, 'Two take more space than one');
+ my $increment = $two - $one;
+ is(total_size([keys %h, keys %h, keys %h]), $one + 2 * $increment,
+ 'Linear size increase for three');
+ return $increment;
+}
+
+{
+ my $small = shared_hash_keys(Perl => 'Rules');
+ my $big = shared_hash_keys('x' x 1024, '');
+ SKIP: {
+ skip("[keys %h] doesn't copy as shared hash key scalars prior to 5.10.0",
+ 1) if $] < 5.010;
+ is ($small, $big, 'The "shared" part of shared hash keys is spotted');
+ }
+}
+
+{
+ use vars '%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG';
+ my $hash_size = total_size(\%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG);
+ cmp_ok($hash_size, '>', 0, 'Hash size is sane');
+ my $stash_size
+ = total_size(\%DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG::);
+ cmp_ok($stash_size, '>',
+ $hash_size + length 'DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG_DANG',
+ 'Stash size is larger than hash size plus length of the name');
+}
+
+{
+ my %h = (Perl => 'Rules');
+ my $hash_size = total_size(\%h);
+ cmp_ok($hash_size, '>', 0, 'Hash size is sane');
+ my $a = keys %h;
+ if ($] < 5.010) {
+ is(total_size(\%h), $hash_size,
+ "Creating iteration state doesn't need to allocate storage");
+ # because all hashes carry the overhead of this storage from creation
+ } else {
+ cmp_ok(total_size(\%h), '>', $hash_size,
+ 'Creating iteration state allocates storage');
+ }
+}
Modified: trunk/libdevel-size-perl/t/globs.t
URL: http://svn.debian.org/wsvn/pkg-perl/trunk/libdevel-size-perl/t/globs.t?rev=74608&op=diff
==============================================================================
--- trunk/libdevel-size-perl/t/globs.t (original)
+++ trunk/libdevel-size-perl/t/globs.t Tue May 17 00:36:13 2011
@@ -60,9 +60,18 @@
my $copy = *PFLAP;
my $copy_gv_size = total_size($copy);
# GV copies point back to the real GV through GvEGV. They share the same GP
- # and GvFILE
- is($copy_gv_size, $real_gv_size + $incremental_gv_size - $gp_size,
- 'GV copies point back to the real GV');
+ # and GvFILE. In 5.10 and later GvNAME is also shared.
+ my $shared_gvname = 0;
+ if ($] >= 5.010) {
+ # Calculate the size of the shared HEK:
+ my %h = (PFLAP => 0);
+ my $shared = (keys %h)[0];
+ $shared_gvname = total_size($shared);
+ undef $shared;
+ $shared_gvname-= total_size($shared);
+ }
+ is($copy_gv_size, $real_gv_size + $incremental_gv_size - $gp_size
+ - $shared_gvname, 'GV copies point back to the real GV');
}
sub gv_grew {
More information about the Pkg-perl-cvs-commits
mailing list