| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
# You may distribute under the terms of either the GNU General Public License |
|
2
|
|
|
|
|
|
|
# or the Artistic License (the same terms as Perl itself) |
|
3
|
|
|
|
|
|
|
# |
|
4
|
|
|
|
|
|
|
# (C) Paul Evans, 2013-2017 -- leonerd@leonerd.org.uk |
|
5
|
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
package Devel::MAT::Tool::Inrefs 0.51; |
|
7
|
|
|
|
|
|
|
|
|
8
|
5
|
|
|
5
|
|
3523
|
use v5.14; |
|
|
5
|
|
|
|
|
30
|
|
|
9
|
5
|
|
|
5
|
|
27
|
use warnings; |
|
|
5
|
|
|
|
|
15
|
|
|
|
5
|
|
|
|
|
135
|
|
|
10
|
5
|
|
|
5
|
|
28
|
use base qw( Devel::MAT::Tool ); |
|
|
5
|
|
|
|
|
16
|
|
|
|
5
|
|
|
|
|
490
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
33
|
use List::Util qw( any pairs ); |
|
|
5
|
|
|
|
|
12
|
|
|
|
5
|
|
|
|
|
441
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
my %STRENGTH_TO_IDX = ( |
|
15
|
|
|
|
|
|
|
strong => 0, |
|
16
|
|
|
|
|
|
|
weak => 1, |
|
17
|
|
|
|
|
|
|
indirect => 2, |
|
18
|
|
|
|
|
|
|
inferred => 3, |
|
19
|
|
|
|
|
|
|
); |
|
20
|
|
|
|
|
|
|
use constant { |
|
21
|
5
|
|
|
|
|
5750
|
IDX_ROOTS_STRONG => 4, |
|
22
|
|
|
|
|
|
|
IDX_ROOTS_WEAK => 5, |
|
23
|
|
|
|
|
|
|
IDX_STACK => 6, |
|
24
|
5
|
|
|
5
|
|
34
|
}; |
|
|
5
|
|
|
|
|
16
|
|
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 NAME |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
C - annotate which SVs are referred to by others |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
This C tool annotates each SV with back-references from other SVs |
|
33
|
|
|
|
|
|
|
that refer to it. It follows the C method of every heap SV and |
|
34
|
|
|
|
|
|
|
annotates the referred SVs with back-references pointing back to the SVs that |
|
35
|
|
|
|
|
|
|
refer to them. |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=cut |
|
38
|
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub init_tool |
|
40
|
|
|
|
|
|
|
{ |
|
41
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
|
42
|
|
|
|
|
|
|
|
|
43
|
2
|
|
|
|
|
17
|
my $df = $self->df; |
|
44
|
|
|
|
|
|
|
|
|
45
|
2
|
|
|
|
|
11
|
my $heap_total = scalar $df->heap; |
|
46
|
2
|
|
|
|
|
5
|
my $count = 0; |
|
47
|
2
|
|
|
|
|
6
|
foreach my $sv ( $df->heap ) { |
|
48
|
163796
|
|
|
|
|
553671
|
foreach ( pairs $sv->outrefs( "NO_DESC" ) ) { |
|
49
|
295691
|
|
|
|
|
531446
|
my ( $strength, $refsv ) = @$_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
295691
|
100
|
|
|
|
602876
|
push @{ $refsv->{tool_inrefs}[ $STRENGTH_TO_IDX{ $strength } ] }, $sv->addr if !$refsv->immortal; |
|
|
293293
|
|
|
|
|
1249802
|
|
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
163796
|
|
|
|
|
301996
|
$count++; |
|
55
|
163796
|
100
|
|
|
|
354158
|
$self->report_progress( sprintf "Patching refs in %d of %d (%.2f%%)", |
|
56
|
|
|
|
|
|
|
$count, $heap_total, 100*$count / $heap_total ) if ($count % 10000) == 0 |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Most SVs are not roots or on the stack. To save time later on we'll make |
|
60
|
|
|
|
|
|
|
# a note of those rare ones that are |
|
61
|
|
|
|
|
|
|
|
|
62
|
2
|
|
|
|
|
20108
|
foreach ( pairs $df->roots_strong ) { |
|
63
|
118
|
|
|
|
|
169
|
my ( undef, $sv ) = @$_; |
|
64
|
118
|
100
|
|
|
|
198
|
next unless $sv; |
|
65
|
60
|
|
|
|
|
176
|
$sv->{tool_inrefs}[IDX_ROOTS_STRONG]++; |
|
66
|
|
|
|
|
|
|
} |
|
67
|
|
|
|
|
|
|
|
|
68
|
2
|
|
|
|
|
49
|
foreach ( pairs $df->roots_weak ) { |
|
69
|
14
|
|
|
|
|
26
|
my ( undef, $sv ) = @$_; |
|
70
|
14
|
100
|
|
|
|
32
|
next unless $sv; |
|
71
|
8
|
|
|
|
|
33
|
$sv->{tool_inrefs}[IDX_ROOTS_WEAK]++; |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
2
|
|
|
|
|
22
|
foreach my $sv ( $df->stack ) { |
|
75
|
4
|
|
|
|
|
16
|
$sv->{tool_inrefs}[IDX_STACK]++; |
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
2
|
|
|
|
|
17
|
$self->report_progress(); |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=head1 SV METHODS |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
This tool adds the following SV methods. |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head2 inrefs |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
@refs = $sv->inrefs |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns a list of Reference objects for each of the SVs that refer to this |
|
90
|
|
|
|
|
|
|
one. This is formed by the inverse mapping along the SV graph from C. |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 inrefs_strong |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 inrefs_weak |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 inrefs_direct |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 inrefs_indirect |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 inrefs_inferred |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
@refs = $sv->inrefs_strong |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
@refs = $sv->inrefs_weak |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
@refs = $sv->inrefs_direct |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
@refs = $sv->inrefs_indirect |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
@refs = $sv->inrefs_inferred |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Returns lists of Reference objects filtered by type, analogous to the various |
|
113
|
|
|
|
|
|
|
C methods. |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub Devel::MAT::SV::_inrefs |
|
118
|
|
|
|
|
|
|
{ |
|
119
|
3394
|
|
|
3394
|
|
8000
|
my $self = shift; |
|
120
|
3394
|
|
|
|
|
10999
|
my ( @strengths ) = @_; |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
# In scalar context we don't need to return SVs or Reference instances, |
|
123
|
|
|
|
|
|
|
# just count them. This allows a lot of optimisations. |
|
124
|
3394
|
|
|
|
|
7218
|
my $just_count = !wantarray; |
|
125
|
|
|
|
|
|
|
|
|
126
|
3394
|
|
100
|
|
|
13880
|
$self->{tool_inrefs} ||= []; |
|
127
|
|
|
|
|
|
|
|
|
128
|
3394
|
|
|
|
|
12586
|
my $df = $self->df; |
|
129
|
3394
|
|
|
|
|
6172
|
my @inrefs; |
|
130
|
3394
|
|
|
|
|
8206
|
foreach my $strength ( @strengths ) { |
|
131
|
13515
|
|
|
|
|
3500864
|
my %seen; |
|
132
|
13515
|
|
100
|
|
|
24285
|
foreach my $addr ( @{ $self->{tool_inrefs}[ $STRENGTH_TO_IDX{$strength} ] // [] } ) { |
|
|
13515
|
|
|
|
|
95041
|
|
|
133
|
16851
|
50
|
|
|
|
504886
|
if( $just_count ) { |
|
134
|
0
|
|
|
|
|
0
|
push @inrefs, 1; |
|
135
|
|
|
|
|
|
|
} |
|
136
|
|
|
|
|
|
|
else { |
|
137
|
16851
|
100
|
|
|
|
93347
|
$seen{$addr}++ and next; |
|
138
|
|
|
|
|
|
|
|
|
139
|
16850
|
|
|
|
|
53094
|
my $sv = $df->sv_at( $addr ); |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
push @inrefs, Devel::MAT::SV::Reference( $_->name, $_->strength, $sv ) |
|
142
|
16850
|
100
|
|
|
|
76777
|
for grep { $_->strength eq $strength and $_->sv == $self } $sv->outrefs; |
|
|
11950316
|
|
|
|
|
101645514
|
|
|
143
|
|
|
|
|
|
|
} |
|
144
|
|
|
|
|
|
|
} |
|
145
|
|
|
|
|
|
|
} |
|
146
|
|
|
|
|
|
|
|
|
147
|
3394
|
100
|
66
|
|
|
20000
|
if( $self->{tool_inrefs}[IDX_ROOTS_STRONG] and $strengths[0] eq "strong" ) { |
|
148
|
4
|
50
|
|
|
|
16
|
if( $just_count ) { |
|
149
|
0
|
|
|
|
|
0
|
push @inrefs, ( 1 ) x $self->{tool_inrefs}[IDX_ROOTS_STRONG]; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
|
|
|
|
|
|
else { |
|
152
|
4
|
|
|
|
|
25
|
foreach ( pairs $df->roots_strong ) { |
|
153
|
236
|
|
|
|
|
381
|
my ( $name, $sv ) = @$_; |
|
154
|
236
|
100
|
100
|
|
|
642
|
push @inrefs, Devel::MAT::SV::Reference( $name, strong => undef ) |
|
155
|
|
|
|
|
|
|
if defined $sv and $sv == $self; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
} |
|
159
|
|
|
|
|
|
|
|
|
160
|
3394
|
50
|
33
|
0
|
|
12196
|
if( $self->{tool_inrefs}[IDX_ROOTS_WEAK] and any { $_ eq "weak" } @strengths ) { |
|
|
0
|
|
|
|
|
0
|
|
|
161
|
0
|
0
|
|
|
|
0
|
if( $just_count ) { |
|
162
|
0
|
|
|
|
|
0
|
push @inrefs, ( 1 ) x $self->{tool_inrefs}[IDX_ROOTS_WEAK]; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
else { |
|
165
|
0
|
|
|
|
|
0
|
foreach ( pairs $df->roots_weak ) { |
|
166
|
0
|
|
|
|
|
0
|
my ( $name, $sv ) = @$_; |
|
167
|
0
|
0
|
0
|
|
|
0
|
push @inrefs, Devel::MAT::SV::Reference( $name, weak => undef ) |
|
168
|
|
|
|
|
|
|
if defined $sv and $sv == $self; |
|
169
|
|
|
|
|
|
|
} |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
} |
|
172
|
|
|
|
|
|
|
|
|
173
|
3394
|
100
|
66
|
2
|
|
14001
|
if( $self->{tool_inrefs}[IDX_STACK] and any { $_ eq "weak" } @strengths ) { |
|
|
2
|
|
|
|
|
8
|
|
|
174
|
1
|
50
|
|
|
|
4
|
if( $just_count ) { |
|
175
|
0
|
|
|
|
|
0
|
push @inrefs, ( 1 ) x $self->{tool_inrefs}[IDX_STACK]; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
else { |
|
178
|
1
|
|
|
|
|
7
|
foreach my $stacksv ( $df->stack ) { |
|
179
|
2
|
100
|
|
|
|
29
|
next unless $stacksv->addr == $self->addr; |
|
180
|
|
|
|
|
|
|
|
|
181
|
1
|
|
|
|
|
5
|
push @inrefs, Devel::MAT::SV::Reference( "a value on the stack", strong => undef ); |
|
182
|
|
|
|
|
|
|
} |
|
183
|
|
|
|
|
|
|
} |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
3394
|
|
|
|
|
24356
|
return @inrefs; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
# If 'strong' is included in these lists it must be first |
|
190
|
3373
|
|
|
3373
|
0
|
30516
|
sub Devel::MAT::SV::inrefs { shift->_inrefs( qw( strong weak indirect inferred )) } |
|
191
|
18
|
|
|
18
|
0
|
59
|
sub Devel::MAT::SV::inrefs_strong { shift->_inrefs( qw( strong )) } |
|
192
|
0
|
|
|
0
|
0
|
0
|
sub Devel::MAT::SV::inrefs_weak { shift->_inrefs( qw( weak )) } |
|
193
|
2
|
|
|
2
|
0
|
21
|
sub Devel::MAT::SV::inrefs_direct { shift->_inrefs( qw( strong weak )) } |
|
194
|
1
|
|
|
1
|
0
|
712
|
sub Devel::MAT::SV::inrefs_indirect { shift->_inrefs( qw( indirect )) } |
|
195
|
0
|
|
|
0
|
0
|
|
sub Devel::MAT::SV::inrefs_inferred { shift->_inrefs( qw( inferred )) } |
|
196
|
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=head1 COMANDS |
|
198
|
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=cut |
|
200
|
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
=head2 inrefs |
|
202
|
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
pmat> inrefs defstash |
|
204
|
|
|
|
|
|
|
s the hash GLOB(%*) at 0x556e47243e40 |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
Shows the incoming references that refer to a given SV. |
|
207
|
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
Takes the following named options: |
|
209
|
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
=over 4 |
|
211
|
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
=item --weak |
|
213
|
|
|
|
|
|
|
|
|
214
|
|
|
|
|
|
|
Include weak direct references in the output (by default only strong direct |
|
215
|
|
|
|
|
|
|
ones will be included). |
|
216
|
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item --all |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
Include both weak and indirect references in the output. |
|
220
|
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=back |
|
222
|
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
|
224
|
|
|
|
|
|
|
|
|
225
|
5
|
|
|
5
|
|
38
|
use constant CMD => "inrefs"; |
|
|
5
|
|
|
|
|
42
|
|
|
|
5
|
|
|
|
|
341
|
|
|
226
|
5
|
|
|
5
|
|
40
|
use constant CMD_DESC => "Show incoming references to a given SV"; |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
387
|
|
|
227
|
|
|
|
|
|
|
|
|
228
|
5
|
|
|
|
|
327
|
use constant CMD_OPTS => ( |
|
229
|
|
|
|
|
|
|
weak => { help => "include weak references" }, |
|
230
|
|
|
|
|
|
|
all => { help => "include weak and indirect references", |
|
231
|
|
|
|
|
|
|
alias => "a" }, |
|
232
|
5
|
|
|
5
|
|
35
|
); |
|
|
5
|
|
|
|
|
10
|
|
|
233
|
|
|
|
|
|
|
|
|
234
|
5
|
|
|
5
|
|
34
|
use constant CMD_ARGS_SV => 1; |
|
|
5
|
|
|
|
|
13
|
|
|
|
5
|
|
|
|
|
766
|
|
|
235
|
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
sub run |
|
237
|
|
|
|
|
|
|
{ |
|
238
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
239
|
0
|
|
|
|
|
|
my %opts = %{ +shift }; |
|
|
0
|
|
|
|
|
|
|
|
240
|
0
|
|
|
|
|
|
my ( $sv ) = @_; |
|
241
|
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
my $method = $opts{all} ? "inrefs" : |
|
243
|
0
|
0
|
|
|
|
|
$opts{weak} ? "inrefs_direct" : |
|
|
|
0
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
"inrefs_strong"; |
|
245
|
|
|
|
|
|
|
|
|
246
|
0
|
|
|
|
|
|
require Devel::MAT::Tool::Outrefs; |
|
247
|
0
|
|
|
|
|
|
Devel::MAT::Tool::Outrefs->show_refs_by_method( $method, $sv ); |
|
248
|
|
|
|
|
|
|
} |
|
249
|
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
=head1 AUTHOR |
|
251
|
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
Paul Evans |
|
253
|
|
|
|
|
|
|
|
|
254
|
|
|
|
|
|
|
=cut |
|
255
|
|
|
|
|
|
|
|
|
256
|
|
|
|
|
|
|
0x55AA; |