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"
26 #include "jfr/leakprofiler/chains/bitset.inline.hpp"
27 #include "jfr/leakprofiler/chains/dfsClosure.hpp"
28 #include "jfr/leakprofiler/chains/edge.hpp"
29 #include "jfr/leakprofiler/chains/edgeStore.hpp"
30 #include "jfr/leakprofiler/chains/rootSetClosure.hpp"
31 #include "jfr/leakprofiler/utilities/granularTimer.hpp"
32 #include "jfr/leakprofiler/utilities/rootType.hpp"
33 #include "jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp"
34 #include "memory/iterator.inline.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/access.inline.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "utilities/align.hpp"
39
40 UnifiedOopRef DFSClosure::_reference_stack[max_dfs_depth];
41
42 void DFSClosure::find_leaks_from_edge(EdgeStore* edge_store,
43 BitSet* mark_bits,
44 const Edge* start_edge) {
45 assert(edge_store != NULL, "invariant");
46 assert(mark_bits != NULL," invariant");
47 assert(start_edge != NULL, "invariant");
48
49 // Depth-first search, starting from a BFS egde
50 DFSClosure dfs(edge_store, mark_bits, start_edge);
51 start_edge->pointee()->oop_iterate(&dfs);
52 }
53
54 void DFSClosure::find_leaks_from_root_set(EdgeStore* edge_store,
55 BitSet* mark_bits) {
56 assert(edge_store != NULL, "invariant");
57 assert(mark_bits != NULL, "invariant");
58
59 // Mark root set, to avoid going sideways
60 DFSClosure dfs(edge_store, mark_bits, NULL);
61 dfs._max_depth = 1;
62 RootSetClosure<DFSClosure> rs(&dfs);
63 rs.process();
64
65 // Depth-first search
66 dfs._max_depth = max_dfs_depth;
67 dfs._ignore_root_set = true;
68 rs.process();
69 }
70
71 DFSClosure::DFSClosure(EdgeStore* edge_store, BitSet* mark_bits, const Edge* start_edge)
72 :_edge_store(edge_store), _mark_bits(mark_bits), _start_edge(start_edge),
73 _max_depth(max_dfs_depth), _depth(0), _ignore_root_set(false) {
74 }
75
76 void DFSClosure::closure_impl(UnifiedOopRef reference, const oop pointee) {
77 assert(pointee != NULL, "invariant");
78 assert(!reference.is_null(), "invariant");
79
80 if (GranularTimer::is_finished()) {
81 return;
82 }
83
84 if (_depth == 0 && _ignore_root_set) {
85 // Root set is already marked, but we want
86 // to continue, so skip is_marked check.
87 assert(_mark_bits->is_marked(pointee), "invariant");
88 _reference_stack[_depth] = reference;
89 } else {
90 if (_mark_bits->is_marked(pointee)) {
91 return;
|
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"
26 #include "jfr/leakprofiler/chains/dfsClosure.hpp"
27 #include "jfr/leakprofiler/chains/edge.hpp"
28 #include "jfr/leakprofiler/chains/edgeStore.hpp"
29 #include "jfr/leakprofiler/chains/jfrbitset.hpp"
30 #include "jfr/leakprofiler/chains/rootSetClosure.hpp"
31 #include "jfr/leakprofiler/utilities/granularTimer.hpp"
32 #include "jfr/leakprofiler/utilities/rootType.hpp"
33 #include "jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp"
34 #include "memory/iterator.inline.hpp"
35 #include "memory/resourceArea.hpp"
36 #include "oops/access.inline.hpp"
37 #include "oops/oop.inline.hpp"
38 #include "utilities/align.hpp"
39
40 UnifiedOopRef DFSClosure::_reference_stack[max_dfs_depth];
41
42 void DFSClosure::find_leaks_from_edge(EdgeStore* edge_store,
43 JFRBitSet* mark_bits,
44 const Edge* start_edge) {
45 assert(edge_store != NULL, "invariant");
46 assert(mark_bits != NULL," invariant");
47 assert(start_edge != NULL, "invariant");
48
49 // Depth-first search, starting from a BFS egde
50 DFSClosure dfs(edge_store, mark_bits, start_edge);
51 start_edge->pointee()->oop_iterate(&dfs);
52 }
53
54 void DFSClosure::find_leaks_from_root_set(EdgeStore* edge_store,
55 JFRBitSet* mark_bits) {
56 assert(edge_store != NULL, "invariant");
57 assert(mark_bits != NULL, "invariant");
58
59 // Mark root set, to avoid going sideways
60 DFSClosure dfs(edge_store, mark_bits, NULL);
61 dfs._max_depth = 1;
62 RootSetClosure<DFSClosure> rs(&dfs);
63 rs.process();
64
65 // Depth-first search
66 dfs._max_depth = max_dfs_depth;
67 dfs._ignore_root_set = true;
68 rs.process();
69 }
70
71 DFSClosure::DFSClosure(EdgeStore* edge_store, JFRBitSet* mark_bits, const Edge* start_edge)
72 :_edge_store(edge_store), _mark_bits(mark_bits), _start_edge(start_edge),
73 _max_depth(max_dfs_depth), _depth(0), _ignore_root_set(false) {
74 }
75
76 void DFSClosure::closure_impl(UnifiedOopRef reference, const oop pointee) {
77 assert(pointee != NULL, "invariant");
78 assert(!reference.is_null(), "invariant");
79
80 if (GranularTimer::is_finished()) {
81 return;
82 }
83
84 if (_depth == 0 && _ignore_root_set) {
85 // Root set is already marked, but we want
86 // to continue, so skip is_marked check.
87 assert(_mark_bits->is_marked(pointee), "invariant");
88 _reference_stack[_depth] = reference;
89 } else {
90 if (_mark_bits->is_marked(pointee)) {
91 return;
|