37
37
#include " oops/oop.inline.hpp"
38
38
#include " utilities/align.hpp"
39
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(UnifiedOopRef::encode_null()),
52
- _depth(0 ) {
53
- }
54
-
55
- DFSClosure::DFSClosure (DFSClosure* parent, size_t depth) :
56
- _parent(parent),
57
- _reference(UnifiedOopRef::encode_null()),
58
- _depth(depth) {
59
- }
40
+ // max dfs depth should not exceed size of stack
41
+ static const size_t max_dfs_depth = 4000 ;
60
42
61
43
void DFSClosure::find_leaks_from_edge (EdgeStore* edge_store,
62
44
BitSet* mark_bits,
@@ -65,14 +47,8 @@ void DFSClosure::find_leaks_from_edge(EdgeStore* edge_store,
65
47
assert (mark_bits != NULL ," invariant" );
66
48
assert (start_edge != NULL , " invariant" );
67
49
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
50
// Depth-first search, starting from a BFS egde
75
- DFSClosure dfs;
51
+ DFSClosure dfs (edge_store, mark_bits, start_edge) ;
76
52
start_edge->pointee ()->oop_iterate (&dfs);
77
53
}
78
54
@@ -81,42 +57,45 @@ void DFSClosure::find_leaks_from_root_set(EdgeStore* edge_store,
81
57
assert (edge_store != NULL , " invariant" );
82
58
assert (mark_bits != NULL , " invariant" );
83
59
84
- _edge_store = edge_store;
85
- _mark_bits = mark_bits;
86
- _start_edge = NULL ;
87
-
88
60
// Mark root set, to avoid going sideways
89
- _max_depth = 1 ;
90
- _ignore_root_set = false ;
91
- DFSClosure dfs;
61
+ DFSClosure dfs (edge_store, mark_bits, NULL );
62
+ dfs._max_depth = 1 ;
92
63
RootSetClosure<DFSClosure> rs (&dfs);
93
64
rs.process ();
94
65
95
66
// Depth-first search
96
- _max_depth = max_dfs_depth;
97
- _ignore_root_set = true ;
98
- assert (_start_edge == NULL , " invariant" );
67
+ dfs._max_depth = max_dfs_depth;
68
+ dfs._ignore_root_set = true ;
99
69
rs.process ();
100
70
}
101
71
72
+ DFSClosure::DFSClosure (EdgeStore* edge_store, BitSet* mark_bits, const Edge* start_edge)
73
+ :_edge_store(edge_store), _mark_bits(mark_bits), _start_edge(start_edge),
74
+ _max_depth(max_dfs_depth), _depth(0 ), _ignore_root_set(false ) {
75
+ _reference_stack = NEW_C_HEAP_ARRAY (UnifiedOopRef, max_dfs_depth, mtTracing);
76
+ }
77
+
78
+ DFSClosure::~DFSClosure () {
79
+ FREE_C_HEAP_ARRAY (UnifiedOopRef, _reference_stack);
80
+ }
81
+
102
82
void DFSClosure::closure_impl (UnifiedOopRef reference, const oop pointee) {
103
83
assert (pointee != NULL , " invariant" );
104
84
assert (!reference.is_null (), " invariant" );
105
85
106
86
if (GranularTimer::is_finished ()) {
107
- return ;
87
+ return ;
108
88
}
109
89
if (_depth == 0 && _ignore_root_set) {
110
90
// Root set is already marked, but we want
111
91
// to continue, so skip is_marked check.
112
92
assert (_mark_bits->is_marked (pointee), " invariant" );
113
- } else {
93
+ } else {
114
94
if (_mark_bits->is_marked (pointee)) {
115
95
return ;
116
96
}
117
97
}
118
-
119
- _reference = reference;
98
+ _reference_stack[_depth] = reference;
120
99
_mark_bits->mark_obj (pointee);
121
100
assert (_mark_bits->is_marked (pointee), " invariant" );
122
101
@@ -127,8 +106,10 @@ void DFSClosure::closure_impl(UnifiedOopRef reference, const oop pointee) {
127
106
128
107
assert (_max_depth >= 1 , " invariant" );
129
108
if (_depth < _max_depth - 1 ) {
130
- DFSClosure next_level (this , _depth + 1 );
131
- pointee->oop_iterate (&next_level);
109
+ _depth++;
110
+ pointee->oop_iterate (this );
111
+ assert (_depth > 0 , " invariant" );
112
+ _depth--;
132
113
}
133
114
}
134
115
@@ -140,11 +121,10 @@ void DFSClosure::add_chain() {
140
121
size_t idx = 0 ;
141
122
142
123
// aggregate from depth-first search
143
- const DFSClosure* c = this ;
144
- while (c != NULL ) {
124
+ for (size_t i = 0 ; i <= _depth; i++) {
145
125
const size_t next = idx + 1 ;
146
- chain[idx++] = Edge (&chain[next], c-> reference ()) ;
147
- c = c-> parent ( );
126
+ const size_t depth = _depth - i ;
127
+ chain[idx++] = Edge (&chain[next], _reference_stack[depth] );
148
128
}
149
129
assert (_depth + 1 == idx, " invariant" );
150
130
assert (array_length == idx + 1 , " invariant" );
0 commit comments