< prev index next >

src/share/vm/jfr/leakprofiler/chains/bfsClosure.cpp

Print this page
rev 9055 : 8214542: JFR: Old Object Sample event slow on a deep heap in debug builds
Reviewed-by: egahlin, rwestberg
rev 9057 : 8229437: assert(is_aligned(ref, HeapWordSize)) failed: invariant
Reviewed-by: egahlin
   1 /*
   2  * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved.
   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  *


  80                              _edge_queue->bottom(),
  81                              _next_frontier_idx,
  82                              edge_size);
  83 
  84   // additional information about DFS fallover
  85   if (LogJFR && Verbose) tty->print_cr(
  86       "BFS front: " SIZE_FORMAT " filled edge queue at edge: " SIZE_FORMAT,
  87       _current_frontier_level,
  88       _dfs_fallback_idx
  89                         );
  90 
  91   const size_t nof_dfs_completed_edges = _edge_queue->bottom() - _dfs_fallback_idx;
  92   if (LogJFR && Verbose) tty->print_cr(
  93       "DFS to complete " SIZE_FORMAT " edges size: " SIZE_FORMAT " [KB]",
  94       nof_dfs_completed_edges,
  95       (nof_dfs_completed_edges * edge_size) / K
  96                         );
  97 }
  98 
  99 void BFSClosure::process() {
 100 
 101   process_root_set();
 102   process_queue();
 103 }
 104 
 105 void BFSClosure::process_root_set() {
 106   for (size_t idx = _edge_queue->bottom(); idx < _edge_queue->top(); ++idx) {
 107     const Edge* edge = _edge_queue->element_at(idx);
 108     assert(edge->parent() == NULL, "invariant");
 109     process(edge->reference(), edge->pointee());
 110   }
 111 }
 112 
 113 void BFSClosure::process(const oop* reference, const oop pointee) {
 114   closure_impl(reference, pointee);
 115 }
 116 void BFSClosure::closure_impl(const oop* reference, const oop pointee) {
 117   assert(reference != NULL, "invariant");
 118   assert(UnifiedOop::dereference(reference) == pointee, "invariant");
 119 
 120   if (GranularTimer::is_finished()) {
 121      return;
 122   }
 123 
 124   if (_use_dfs) {
 125     assert(_current_parent != NULL, "invariant");
 126     DFSClosure::find_leaks_from_edge(_edge_store, _mark_bits, _current_parent);
 127     return;
 128   }
 129 
 130   if (!_mark_bits->is_marked(pointee)) {
 131     _mark_bits->mark_obj(pointee);
 132     // is the pointee a sample object?
 133     if (NULL == pointee->mark()) {
 134       add_chain(reference, pointee);
 135     }
 136 
 137     // if we are processinig initial root set, don't add to queue
 138     if (_current_parent != NULL) {
 139       assert(_current_parent->distance_to_root() == _current_frontier_level, "invariant");
 140       _edge_queue->add(_current_parent, reference);
 141     }
 142 
 143     if (_edge_queue->is_full()) {
 144       dfs_fallback();
 145     }
 146   }
 147 }
 148 
 149 void BFSClosure::add_chain(const oop* reference, const oop pointee) {
 150   assert(pointee != NULL, "invariant");
 151   assert(NULL == pointee->mark(), "invariant");
 152 
 153   const size_t length = _current_parent == NULL ? 1 : _current_parent->distance_to_root() + 2;
 154   ResourceMark rm;
 155   Edge* const chain = NEW_RESOURCE_ARRAY(Edge, length);
 156   size_t idx = 0;
 157   chain[idx++] = Edge(NULL, reference);
 158   // aggregate from breadth-first search
 159   const Edge* current = _current_parent;
 160   while (current != NULL) {
 161     chain[idx++] = Edge(NULL, current->reference());
 162     current = current->parent();
 163   }
 164   assert(length == idx, "invariant");
 165   _edge_store->add_chain(chain, length);
 166 }
 167 
 168 void BFSClosure::dfs_fallback() {
 169   assert(_edge_queue->is_full(), "invariant");
 170   _use_dfs = true;
 171   _dfs_fallback_idx = _edge_queue->bottom();
 172   while (!_edge_queue->is_empty()) {
 173     const Edge* edge = _edge_queue->remove();
 174     if (edge->pointee() != NULL) {
 175       DFSClosure::find_leaks_from_edge(_edge_store, _mark_bits, edge);
 176     }
 177   }
 178 }
 179 
 180 void BFSClosure::process_queue() {
 181   assert(_current_frontier_level == 0, "invariant");
 182   assert(_next_frontier_idx == 0, "invariant");
 183   assert(_prev_frontier_idx == 0, "invariant");
 184 
 185   _next_frontier_idx = _edge_queue->top();


 220   assert(pointee != NULL, "invariant");
 221   _current_parent = parent;
 222   pointee->oop_iterate(this);
 223 }
 224 
 225 void BFSClosure::do_oop(oop* ref) {
 226   assert(ref != NULL, "invariant");
 227   assert(is_aligned(ref, HeapWordSize), "invariant");
 228   const oop pointee = *ref;
 229   if (pointee != NULL) {
 230     closure_impl(ref, pointee);
 231   }
 232 }
 233 
 234 void BFSClosure::do_oop(narrowOop* ref) {
 235   assert(ref != NULL, "invariant");
 236   assert(is_aligned(ref, sizeof(narrowOop)), "invariant");
 237   const oop pointee = oopDesc::load_decode_heap_oop(ref);
 238   if (pointee != NULL) {
 239     closure_impl(UnifiedOop::encode(ref), pointee);







 240   }
 241 }
   1 /*
   2  * Copyright (c) 2014, 2019, Oracle and/or its affiliates. All rights reserved.
   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  *


  80                              _edge_queue->bottom(),
  81                              _next_frontier_idx,
  82                              edge_size);
  83 
  84   // additional information about DFS fallover
  85   if (LogJFR && Verbose) tty->print_cr(
  86       "BFS front: " SIZE_FORMAT " filled edge queue at edge: " SIZE_FORMAT,
  87       _current_frontier_level,
  88       _dfs_fallback_idx
  89                         );
  90 
  91   const size_t nof_dfs_completed_edges = _edge_queue->bottom() - _dfs_fallback_idx;
  92   if (LogJFR && Verbose) tty->print_cr(
  93       "DFS to complete " SIZE_FORMAT " edges size: " SIZE_FORMAT " [KB]",
  94       nof_dfs_completed_edges,
  95       (nof_dfs_completed_edges * edge_size) / K
  96                         );
  97 }
  98 
  99 void BFSClosure::process() {

 100   process_root_set();
 101   process_queue();
 102 }
 103 
 104 void BFSClosure::process_root_set() {
 105   for (size_t idx = _edge_queue->bottom(); idx < _edge_queue->top(); ++idx) {
 106     const Edge* edge = _edge_queue->element_at(idx);
 107     assert(edge->parent() == NULL, "invariant");
 108     process(edge->reference(), edge->pointee());
 109   }
 110 }
 111 
 112 void BFSClosure::process(const oop* reference, const oop pointee) {
 113   closure_impl(reference, pointee);
 114 }
 115 void BFSClosure::closure_impl(const oop* reference, const oop pointee) {
 116   assert(reference != NULL, "invariant");
 117   assert(UnifiedOop::dereference(reference) == pointee, "invariant");
 118 
 119   if (GranularTimer::is_finished()) {
 120      return;
 121   }
 122 
 123   if (_use_dfs) {
 124     assert(_current_parent != NULL, "invariant");
 125     DFSClosure::find_leaks_from_edge(_edge_store, _mark_bits, _current_parent);
 126     return;
 127   }
 128 
 129   if (!_mark_bits->is_marked(pointee)) {
 130     _mark_bits->mark_obj(pointee);
 131     // is the pointee a sample object?
 132     if (NULL == pointee->mark()) {
 133       add_chain(reference, pointee);
 134     }
 135 
 136     // if we are processinig initial root set, don't add to queue
 137     if (_current_parent != NULL) {

 138       _edge_queue->add(_current_parent, reference);
 139     }
 140 
 141     if (_edge_queue->is_full()) {
 142       dfs_fallback();
 143     }
 144   }
 145 }
 146 
 147 void BFSClosure::add_chain(const oop* reference, const oop pointee) {
 148   assert(pointee != NULL, "invariant");
 149   assert(NULL == pointee->mark(), "invariant");
 150   Edge leak_edge(_current_parent, reference);
 151   _edge_store->put_chain(&leak_edge, _current_parent == NULL ? 1 : _current_frontier_level + 2);












 152 }
 153 
 154 void BFSClosure::dfs_fallback() {
 155   assert(_edge_queue->is_full(), "invariant");
 156   _use_dfs = true;
 157   _dfs_fallback_idx = _edge_queue->bottom();
 158   while (!_edge_queue->is_empty()) {
 159     const Edge* edge = _edge_queue->remove();
 160     if (edge->pointee() != NULL) {
 161       DFSClosure::find_leaks_from_edge(_edge_store, _mark_bits, edge);
 162     }
 163   }
 164 }
 165 
 166 void BFSClosure::process_queue() {
 167   assert(_current_frontier_level == 0, "invariant");
 168   assert(_next_frontier_idx == 0, "invariant");
 169   assert(_prev_frontier_idx == 0, "invariant");
 170 
 171   _next_frontier_idx = _edge_queue->top();


 206   assert(pointee != NULL, "invariant");
 207   _current_parent = parent;
 208   pointee->oop_iterate(this);
 209 }
 210 
 211 void BFSClosure::do_oop(oop* ref) {
 212   assert(ref != NULL, "invariant");
 213   assert(is_aligned(ref, HeapWordSize), "invariant");
 214   const oop pointee = *ref;
 215   if (pointee != NULL) {
 216     closure_impl(ref, pointee);
 217   }
 218 }
 219 
 220 void BFSClosure::do_oop(narrowOop* ref) {
 221   assert(ref != NULL, "invariant");
 222   assert(is_aligned(ref, sizeof(narrowOop)), "invariant");
 223   const oop pointee = oopDesc::load_decode_heap_oop(ref);
 224   if (pointee != NULL) {
 225     closure_impl(UnifiedOop::encode(ref), pointee);
 226   }
 227 }
 228 
 229 void BFSClosure::do_root(const oop* ref) {
 230   assert(ref != NULL, "invariant");
 231   if (!_edge_queue->is_full()) {
 232     _edge_queue->add(NULL, ref);
 233   }
 234 }
< prev index next >