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 DEBUG_ONLY(bool is_valid() const); // Tasks to be pushed/popped must be valid. 59 60 private: 61 oop _obj; 62 }; 63 64 typedef FormatBuffer<8192> ShenandoahMessageBuffer; 65 typedef Stack<ShenandoahVerifierTask, mtGC> ShenandoahVerifierStack; 66 typedef volatile juint ShenandoahLivenessData; 67 68 class ShenandoahVerifier : public CHeapObj<mtGC> { 69 private: 70 ShenandoahHeap* _heap; 71 MarkBitMap* _verification_bit_map; 72 public: 73 typedef enum { 74 // Disable matrix verification completely 75 _verify_matrix_disable, 76 77 // Conservative matrix verification: all connected objects should have matrix 78 // connections. The verification is conservative, because it allows matrix 79 // connection that do not have actual heap connections. 80 _verify_matrix_conservative, 81 82 // Precise matrix verification: all connected objects should have matrix connections, 83 // *and* every matrix connection should have at least a pair a connected objects. 84 // TODO: implement this, if needed 85 _verify_matrix_precise, 86 } VerifyMatrix; 87 88 typedef enum { 89 // Disable marked objects verification. 90 _verify_marked_disable, 91 92 // Objects should be marked in "next" bitmap. 93 _verify_marked_next, 94 95 // Objects should be marked in "complete" bitmap. 96 _verify_marked_complete, 97 } VerifyMarked; 98 99 typedef enum { 100 // Disable forwarded objects verification. 101 _verify_forwarded_disable, 102 103 // Objects should not have forwardees. 104 _verify_forwarded_none, 105 106 // Objects may have forwardees. 107 _verify_forwarded_allow, 108 } VerifyForwarded; 109 110 typedef enum { 111 // Disable collection set verification. 112 _verify_cset_disable, 113 114 // Should have no references to cset. 115 _verify_cset_none, 116 117 // May have references to cset, all should be forwarded. 118 // Note: Allowing non-forwarded references to cset is equivalent 119 // to _verify_cset_disable. 120 _verify_cset_forwarded, 121 } VerifyCollectionSet; 122 123 typedef enum { 124 // Disable liveness verification 125 _verify_liveness_disable, 126 127 // All objects should belong to live regions 128 _verify_liveness_conservative, 129 130 // All objects should belong to live regions, 131 // and liveness data should be accurate 132 _verify_liveness_complete, 133 } VerifyLiveness; 134 135 typedef enum { 136 // Disable region verification 137 _verify_regions_disable, 138 139 // No trash regions allowed 140 _verify_regions_notrash, 141 142 // No collection set regions allowed 143 _verify_regions_nocset, 144 145 // No trash and no cset regions allowed 146 _verify_regions_notrash_nocset, 147 } VerifyRegions; 148 149 struct VerifyOptions { 150 VerifyForwarded _verify_forwarded; 151 VerifyMarked _verify_marked; 152 VerifyMatrix _verify_matrix; 153 VerifyCollectionSet _verify_cset; 154 VerifyLiveness _verify_liveness; 155 VerifyRegions _verify_regions; 156 157 VerifyOptions(VerifyForwarded verify_forwarded, 158 VerifyMarked verify_marked, 159 VerifyMatrix verify_matrix, 160 VerifyCollectionSet verify_collection_set, 161 VerifyLiveness verify_liveness, 162 VerifyRegions verify_regions) : 163 _verify_forwarded(verify_forwarded), _verify_marked(verify_marked), 164 _verify_matrix(verify_matrix), _verify_cset(verify_collection_set), 165 _verify_liveness(verify_liveness), _verify_regions(verify_regions) {} 166 }; 167 168 private: 169 void verify_at_safepoint(const char *label, 170 VerifyForwarded forwarded, 171 VerifyMarked marked, 172 VerifyMatrix matrix, 173 VerifyCollectionSet cset, 174 VerifyLiveness liveness, 175 VerifyRegions regions); 176 177 public: 178 ShenandoahVerifier(ShenandoahHeap* heap, MarkBitMap* verification_bitmap) : 179 _heap(heap), _verification_bit_map(verification_bitmap) {}; 180 181 void verify_before_concmark(); 182 void verify_after_concmark(); 183 void verify_before_evacuation(); 184 void verify_after_evacuation(); 185 void verify_before_updaterefs(); 186 void verify_after_updaterefs(); 187 void verify_before_fullgc(); 188 void verify_after_fullgc(); 189 void verify_before_partial(); 190 void verify_after_partial(); 191 void verify_generic(VerifyOption option); 192 193 static void verify_oop(oop obj); 194 static void verify_oop_fwdptr(oop obj, oop new_fwd); 195 }; 196 197 #endif // SHARE_VM_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP