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 24 #ifndef SHARE_VM_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP 25 #define SHARE_VM_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP 26 27 #include "memory/allocation.hpp" 28 #include "utilities/stack.hpp" 29 #include "gc/shared/markBitMap.hpp" 30 31 class Thread; 32 class ShenandoahHeapRegionSet; 33 class ShenandoahHeap; 34 class ShenandoahVerifyOopClosure; 35 36 #ifdef _WINDOWS 37 #pragma warning( disable : 4522 ) 38 #endif 39 40 class ShenandoahVerifierTask { 41 public: 42 ShenandoahVerifierTask(oop o = NULL, int idx = 0): _obj(o) { } 43 ShenandoahVerifierTask(oop o, size_t idx): _obj(o) { } 44 ShenandoahVerifierTask(const ShenandoahVerifierTask& t): _obj(t._obj) { } 45 46 ShenandoahVerifierTask& operator =(const ShenandoahVerifierTask& t) { 47 _obj = t._obj; 48 return *this; 49 } 50 volatile ShenandoahVerifierTask& 51 operator =(const volatile ShenandoahVerifierTask& t) volatile { 52 (void)const_cast<oop&>(_obj = t._obj); 53 return *this; 54 } 55 56 inline oop obj() const { return _obj; } 57 58 private: 59 oop _obj; 60 }; 61 62 typedef Stack<ShenandoahVerifierTask, mtGC> ShenandoahVerifierStack; 63 typedef volatile juint ShenandoahLivenessData; 64 65 class ShenandoahVerifier : public CHeapObj<mtGC> { 66 private: 67 ShenandoahHeap* _heap; 68 MarkBitMap* _verification_bit_map; 69 public: 70 typedef enum { 71 // Disable matrix verification completely 72 _verify_matrix_disable, 73 74 // Conservative matrix verification: all connected objects should have matrix 75 // connections. The verification is conservative, because it allows matrix 76 // connection that do not have actual heap connections. 77 _verify_matrix_conservative, 78 79 // Precise matrix verification: all connected objects should have matrix connections, 80 // *and* every matrix connection should have at least a pair a connected objects. 81 // TODO: implement this, if needed 82 _verify_matrix_precise, 83 } VerifyMatrix; 84 85 typedef enum { 86 // Disable marked objects verification. 87 _verify_marked_disable, 88 89 // Objects should be marked in "next" bitmap. 90 _verify_marked_next, 91 92 // Objects should be marked in "complete" bitmap. 93 _verify_marked_complete, 94 } VerifyMarked; 95 96 typedef enum { 97 // Disable forwarded objects verification. 98 _verify_forwarded_disable, 99 100 // Objects should not have forwardees. 101 _verify_forwarded_none, 102 103 // Objects may have forwardees. 104 _verify_forwarded_allow, 105 } VerifyForwarded; 106 107 typedef enum { 108 // Disable collection set verification. 109 _verify_cset_disable, 110 111 // Should have no references to cset. 112 _verify_cset_none, 113 114 // May have references to cset, all should be forwarded. 115 // Note: Allowing non-forwarded references to cset is equivalent 116 // to _verify_cset_disable. 117 _verify_cset_forwarded, 118 } VerifyCollectionSet; 119 120 typedef enum { 121 // Disable liveness verification 122 _verify_liveness_disable, 123 124 // All objects should belong to live regions 125 _verify_liveness_conservative, 126 127 // All objects should belong to live regions, 128 // and liveness data should be accurate 129 _verify_liveness_complete, 130 } VerifyLiveness; 131 132 typedef enum { 133 // Disable region verification 134 _verify_regions_disable, 135 136 // No trash regions allowed 137 _verify_regions_notrash, 138 139 // No collection set regions allowed 140 _verify_regions_nocset, 141 142 // No trash and no cset regions allowed 143 _verify_regions_notrash_nocset, 144 } VerifyRegions; 145 146 struct VerifyOptions { 147 VerifyForwarded _verify_forwarded; 148 VerifyMarked _verify_marked; 149 VerifyMatrix _verify_matrix; 150 VerifyCollectionSet _verify_cset; 151 VerifyLiveness _verify_liveness; 152 VerifyRegions _verify_regions; 153 154 VerifyOptions(VerifyForwarded verify_forwarded, 155 VerifyMarked verify_marked, 156 VerifyMatrix verify_matrix, 157 VerifyCollectionSet verify_collection_set, 158 VerifyLiveness verify_liveness, 159 VerifyRegions verify_regions) : 160 _verify_forwarded(verify_forwarded), _verify_marked(verify_marked), 161 _verify_matrix(verify_matrix), _verify_cset(verify_collection_set), 162 _verify_liveness(verify_liveness), _verify_regions(verify_regions) {} 163 }; 164 165 private: 166 void verify_at_safepoint(const char *label, 167 VerifyForwarded forwarded, 168 VerifyMarked marked, 169 VerifyMatrix matrix, 170 VerifyCollectionSet cset, 171 VerifyLiveness liveness, 172 VerifyRegions regions); 173 174 public: 175 ShenandoahVerifier(ShenandoahHeap* heap, MarkBitMap* verification_bitmap) : 176 _heap(heap), _verification_bit_map(verification_bitmap) {}; 177 178 void verify_before_concmark(); 179 void verify_after_concmark(); 180 void verify_before_evacuation(); 181 void verify_after_evacuation(); 182 void verify_before_updaterefs(); 183 void verify_after_updaterefs(); 184 void verify_before_fullgc(); 185 void verify_after_fullgc(); 186 void verify_before_partial(); 187 void verify_after_partial(); 188 void verify_before_traversal(); 189 void verify_after_traversal(); 190 void verify_after_degenerated(); 191 void verify_generic(VerifyOption option); 192 }; 193 194 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP