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