1 /* 2 * Copyright (c) 2017, Red Hat, Inc. and/or its affiliates. 3 * 4 * This code is free software; you can redistribute it and/or modify it 5 * under the terms of the GNU General Public License version 2 only, as 6 * published by the Free Software Foundation. 7 * 8 * This code is distributed in the hope that it will be useful, but WITHOUT 9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 11 * version 2 for more details (a copy is included in the LICENSE file that 12 * accompanied this code). 13 * 14 * You should have received a copy of the GNU General Public License version 15 * 2 along with this work; if not, write to the Free Software Foundation, 16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 17 * 18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 19 * or visit www.oracle.com if you need additional information or have any 20 * questions. 21 * 22 */ 23 #include "precompiled.hpp" 24 25 #ifdef ASSERT 26 27 #include "memory/allocation.hpp" 28 #include "gc/shenandoah/shenandoahHeap.hpp" 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp" 30 #include "gc/shenandoah/shenandoahPrinter.hpp" 31 32 class ShenandoahPrintAllRefsOopClosure: public ExtendedOopClosure { 33 private: 34 int _index; 35 const char* _prefix; 36 37 public: 38 ShenandoahPrintAllRefsOopClosure(const char* prefix) : _index(0), _prefix(prefix) {} 39 40 private: 41 template <class T> 42 inline void do_oop_work(T* p) { 43 oop o = oopDesc::load_decode_heap_oop(p); 44 if (o != NULL) { 45 if (ShenandoahHeap::heap()->is_in(o) && oopDesc::is_oop(o)) { 46 tty->print_cr("%s "INT32_FORMAT" ("PTR_FORMAT")-> "PTR_FORMAT" (marked: %s) (%s "PTR_FORMAT")", 47 _prefix, _index, 48 p2i(p), p2i(o), 49 BOOL_TO_STR(ShenandoahHeap::heap()->is_marked(o)), 50 o->klass()->internal_name(), p2i(o->klass())); 51 } else { 52 tty->print_cr("%s "INT32_FORMAT" ("PTR_FORMAT" dirty -> "PTR_FORMAT" (not in heap, possibly corrupted or dirty)", 53 _prefix, _index, 54 p2i(p), p2i(o)); 55 } 56 } else { 57 tty->print_cr("%s "INT32_FORMAT" ("PTR_FORMAT") -> "PTR_FORMAT, _prefix, _index, p2i(p), p2i((HeapWord*) o)); 58 } 59 _index++; 60 } 61 62 public: 63 void do_oop(oop* p) { 64 do_oop_work(p); 65 } 66 67 void do_oop(narrowOop* p) { 68 do_oop_work(p); 69 } 70 }; 71 72 class ShenandoahPrintAllRefsObjectClosure : public ObjectClosure { 73 const char* _prefix; 74 75 public: 76 ShenandoahPrintAllRefsObjectClosure(const char* prefix) : _prefix(prefix) {} 77 78 void do_object(oop p) { 79 if (ShenandoahHeap::heap()->is_in(p)) { 80 tty->print_cr("%s object "PTR_FORMAT" (marked: %s) (%s "PTR_FORMAT") refers to:", 81 _prefix, p2i(p), 82 BOOL_TO_STR(ShenandoahHeap::heap()->is_marked(p)), 83 p->klass()->internal_name(), p2i(p->klass())); 84 ShenandoahPrintAllRefsOopClosure cl(_prefix); 85 p->oop_iterate(&cl); 86 } 87 } 88 }; 89 90 void ShenandoahPrinter::print_all_refs(const char* prefix) { 91 tty->print_cr("printing all references in the heap"); 92 tty->print_cr("root references:"); 93 94 _heap->make_tlabs_parsable(false); 95 96 ShenandoahPrintAllRefsOopClosure cl(prefix); 97 _heap->roots_iterate(&cl); 98 99 tty->print_cr("heap references:"); 100 ShenandoahPrintAllRefsObjectClosure cl2(prefix); 101 _heap->object_iterate(&cl2); 102 } 103 104 #endif