author | chegar |
Thu, 17 Oct 2019 20:54:25 +0100 | |
branch | datagramsocketimpl-branch |
changeset 58679 | 9c3209ff7550 |
parent 58678 | 9cf78a70fa4f |
parent 58014 | aba258cd7df8 |
permissions | -rw-r--r-- |
50113 | 1 |
/* |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
2 |
* Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved. |
50113 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. |
|
8 |
* |
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
13 |
* accompanied this code). |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License version |
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
18 |
* |
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
22 |
* |
|
23 |
*/ |
|
24 |
||
25 |
#include "precompiled.hpp" |
|
58014
aba258cd7df8
8229189: Improve JFR leak profiler tracing to deal with discontiguous heaps
eosterlund
parents:
57979
diff
changeset
|
26 |
#include "jfr/leakprofiler/chains/bitset.inline.hpp" |
50113 | 27 |
#include "jfr/leakprofiler/chains/dfsClosure.hpp" |
28 |
#include "jfr/leakprofiler/chains/edge.hpp" |
|
29 |
#include "jfr/leakprofiler/chains/edgeStore.hpp" |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
30 |
#include "jfr/leakprofiler/chains/rootSetClosure.hpp" |
50113 | 31 |
#include "jfr/leakprofiler/utilities/granularTimer.hpp" |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
32 |
#include "jfr/leakprofiler/utilities/rootType.hpp" |
50113 | 33 |
#include "jfr/leakprofiler/utilities/unifiedOop.hpp" |
50752 | 34 |
#include "memory/iterator.inline.hpp" |
50113 | 35 |
#include "memory/resourceArea.hpp" |
36 |
#include "oops/access.inline.hpp" |
|
37 |
#include "oops/oop.inline.hpp" |
|
38 |
#include "utilities/align.hpp" |
|
39 |
||
40 |
// max dfs depth should not exceed size of stack |
|
41 |
static const size_t max_dfs_depth = 5000; |
|
42 |
||
43 |
EdgeStore* DFSClosure::_edge_store = NULL; |
|
44 |
BitSet* DFSClosure::_mark_bits = NULL; |
|
45 |
const Edge* DFSClosure::_start_edge = NULL; |
|
46 |
size_t DFSClosure::_max_depth = max_dfs_depth; |
|
47 |
bool DFSClosure::_ignore_root_set = false; |
|
48 |
||
49 |
DFSClosure::DFSClosure() : |
|
50 |
_parent(NULL), |
|
51 |
_reference(NULL), |
|
52 |
_depth(0) { |
|
53 |
} |
|
54 |
||
55 |
DFSClosure::DFSClosure(DFSClosure* parent, size_t depth) : |
|
56 |
_parent(parent), |
|
57 |
_reference(NULL), |
|
58 |
_depth(depth) { |
|
59 |
} |
|
60 |
||
61 |
void DFSClosure::find_leaks_from_edge(EdgeStore* edge_store, |
|
62 |
BitSet* mark_bits, |
|
63 |
const Edge* start_edge) { |
|
64 |
assert(edge_store != NULL, "invariant"); |
|
65 |
assert(mark_bits != NULL," invariant"); |
|
66 |
assert(start_edge != NULL, "invariant"); |
|
67 |
||
68 |
_edge_store = edge_store; |
|
69 |
_mark_bits = mark_bits; |
|
70 |
_start_edge = start_edge; |
|
71 |
_ignore_root_set = false; |
|
72 |
assert(_max_depth == max_dfs_depth, "invariant"); |
|
73 |
||
74 |
// Depth-first search, starting from a BFS egde |
|
75 |
DFSClosure dfs; |
|
76 |
start_edge->pointee()->oop_iterate(&dfs); |
|
77 |
} |
|
78 |
||
79 |
void DFSClosure::find_leaks_from_root_set(EdgeStore* edge_store, |
|
80 |
BitSet* mark_bits) { |
|
81 |
assert(edge_store != NULL, "invariant"); |
|
82 |
assert(mark_bits != NULL, "invariant"); |
|
83 |
||
84 |
_edge_store = edge_store; |
|
85 |
_mark_bits = mark_bits; |
|
86 |
_start_edge = NULL; |
|
87 |
||
88 |
// Mark root set, to avoid going sideways |
|
89 |
_max_depth = 1; |
|
90 |
_ignore_root_set = false; |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
91 |
DFSClosure dfs; |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
92 |
RootSetClosure<DFSClosure> rs(&dfs); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
93 |
rs.process(); |
50113 | 94 |
|
95 |
// Depth-first search |
|
96 |
_max_depth = max_dfs_depth; |
|
97 |
_ignore_root_set = true; |
|
98 |
assert(_start_edge == NULL, "invariant"); |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
99 |
rs.process(); |
50113 | 100 |
} |
101 |
||
102 |
void DFSClosure::closure_impl(const oop* reference, const oop pointee) { |
|
103 |
assert(pointee != NULL, "invariant"); |
|
104 |
assert(reference != NULL, "invariant"); |
|
105 |
||
106 |
if (GranularTimer::is_finished()) { |
|
107 |
return; |
|
108 |
} |
|
109 |
if (_depth == 0 && _ignore_root_set) { |
|
110 |
// Root set is already marked, but we want |
|
111 |
// to continue, so skip is_marked check. |
|
112 |
assert(_mark_bits->is_marked(pointee), "invariant"); |
|
113 |
} else { |
|
114 |
if (_mark_bits->is_marked(pointee)) { |
|
115 |
return; |
|
116 |
} |
|
117 |
} |
|
118 |
||
119 |
_reference = reference; |
|
120 |
_mark_bits->mark_obj(pointee); |
|
121 |
assert(_mark_bits->is_marked(pointee), "invariant"); |
|
122 |
||
123 |
// is the pointee a sample object? |
|
57777
90ead0febf56
8229258: Rework markOop and markOopDesc into a simpler mark word value carrier
stefank
parents:
55571
diff
changeset
|
124 |
if (NULL == pointee->mark().to_pointer()) { |
50113 | 125 |
add_chain(); |
126 |
} |
|
127 |
||
128 |
assert(_max_depth >= 1, "invariant"); |
|
129 |
if (_depth < _max_depth - 1) { |
|
130 |
DFSClosure next_level(this, _depth + 1); |
|
131 |
pointee->oop_iterate(&next_level); |
|
132 |
} |
|
133 |
} |
|
134 |
||
135 |
void DFSClosure::add_chain() { |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
136 |
const size_t array_length = _depth + 2; |
50113 | 137 |
|
138 |
ResourceMark rm; |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
139 |
Edge* const chain = NEW_RESOURCE_ARRAY(Edge, array_length); |
50113 | 140 |
size_t idx = 0; |
141 |
||
142 |
// aggregate from depth-first search |
|
143 |
const DFSClosure* c = this; |
|
144 |
while (c != NULL) { |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
145 |
const size_t next = idx + 1; |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
146 |
chain[idx++] = Edge(&chain[next], c->reference()); |
50113 | 147 |
c = c->parent(); |
148 |
} |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
149 |
assert(_depth + 1 == idx, "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
150 |
assert(array_length == idx + 1, "invariant"); |
50113 | 151 |
|
152 |
// aggregate from breadth-first search |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
153 |
if (_start_edge != NULL) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
154 |
chain[idx++] = *_start_edge; |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
155 |
} else { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
156 |
chain[idx - 1] = Edge(NULL, chain[idx - 1].reference()); |
50113 | 157 |
} |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
158 |
_edge_store->put_chain(chain, idx + (_start_edge != NULL ? _start_edge->distance_to_root() : 0)); |
50113 | 159 |
} |
160 |
||
161 |
void DFSClosure::do_oop(oop* ref) { |
|
162 |
assert(ref != NULL, "invariant"); |
|
163 |
assert(is_aligned(ref, HeapWordSize), "invariant"); |
|
164 |
const oop pointee = *ref; |
|
165 |
if (pointee != NULL) { |
|
166 |
closure_impl(ref, pointee); |
|
167 |
} |
|
168 |
} |
|
169 |
||
170 |
void DFSClosure::do_oop(narrowOop* ref) { |
|
171 |
assert(ref != NULL, "invariant"); |
|
172 |
assert(is_aligned(ref, sizeof(narrowOop)), "invariant"); |
|
173 |
const oop pointee = RawAccess<>::oop_load(ref); |
|
174 |
if (pointee != NULL) { |
|
175 |
closure_impl(UnifiedOop::encode(ref), pointee); |
|
176 |
} |
|
177 |
} |
|
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
178 |
|
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
179 |
void DFSClosure::do_root(const oop* ref) { |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
180 |
assert(ref != NULL, "invariant"); |
57979
94481c2b9388
8229437: assert(is_aligned(ref, HeapWordSize)) failed: invariant
mgronlun
parents:
57777
diff
changeset
|
181 |
const oop pointee = UnifiedOop::dereference(ref); |
55571
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
182 |
assert(pointee != NULL, "invariant"); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
183 |
closure_impl(ref, pointee); |
49102ba8cf14
8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
mgronlun
parents:
50752
diff
changeset
|
184 |
} |