1 /* 2 * Copyright (c) 2017, 2020, Red Hat, Inc. All rights reserved. 3 * Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 5 * 6 * This code is free software; you can redistribute it and/or modify it 7 * under the terms of the GNU General Public License version 2 only, as 8 * published by the Free Software Foundation. 9 * 10 * This code is distributed in the hope that it will be useful, but WITHOUT 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 13 * version 2 for more details (a copy is included in the LICENSE file that 14 * accompanied this code). 15 * 16 * You should have received a copy of the GNU General Public License version 17 * 2 along with this work; if not, write to the Free Software Foundation, 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 19 * 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 21 * or visit www.oracle.com if you need additional information or have any 22 * questions. 23 * 24 */ 25 26 #ifndef SHARE_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP 28 29 #include "gc/shared/markBitMap.hpp" 30 #include "gc/shenandoah/shenandoahRootVerifier.hpp" 31 #include "memory/allocation.hpp" 32 #include "oops/oopsHierarchy.hpp" 33 #include "utilities/stack.hpp" 34 35 class ShenandoahHeap; 36 37 #ifdef _WINDOWS 38 #pragma warning( disable : 4522 ) 39 #endif 40 41 class ShenandoahVerifierTask { 42 public: 43 ShenandoahVerifierTask(oop o = nullptr, int idx = 0): _obj(o) { } 44 ShenandoahVerifierTask(oop o, size_t idx): _obj(o) { } 45 // Trivially copyable. 46 47 inline oop obj() const { return _obj; } 48 49 private: 50 oop _obj; 51 }; 52 53 typedef Stack<ShenandoahVerifierTask, mtGC> ShenandoahVerifierStack; 54 typedef volatile juint ShenandoahLivenessData; 55 56 class ShenandoahVerifier : public CHeapObj<mtGC> { 57 private: 58 ShenandoahHeap* _heap; 59 MarkBitMap* _verification_bit_map; 60 public: 61 typedef enum { 62 // Disable remembered set verification. 63 _verify_remembered_disable, 64 65 // Old objects should be registered and RS cards within *read-only* RS are dirty for all 66 // inter-generational pointers. 67 _verify_remembered_before_marking, 68 69 // Old objects should be registered and RS cards within *read-write* RS are dirty for all 70 // inter-generational pointers. 71 _verify_remembered_before_updating_references, 72 73 // Old objects should be registered and RS cards within *read-write* RS are dirty for all 74 // inter-generational pointers. 75 // TODO: This differs from the previous mode by update-watermark() vs top() end range? 76 _verify_remembered_after_full_gc 77 } VerifyRememberedSet; 78 79 typedef enum { 80 // Disable marked objects verification. 81 _verify_marked_disable, 82 83 // Objects should be marked in "next" bitmap. 84 _verify_marked_incomplete, 85 86 // Objects should be marked in "complete" bitmap. 87 _verify_marked_complete, 88 89 // Objects should be marked in "complete" bitmap, except j.l.r.Reference referents, which 90 // may be dangling after marking but before conc-weakrefs-processing. 91 _verify_marked_complete_except_references, 92 93 // Objects should be marked in "complete" bitmap, except j.l.r.Reference referents, which 94 // may be dangling after marking but before conc-weakrefs-processing. All SATB buffers must 95 // be empty. 96 _verify_marked_complete_satb_empty, 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 typedef enum { 150 // Disable size verification 151 _verify_size_disable, 152 153 // Enforce exact consistency 154 _verify_size_exact, 155 156 // Expect promote-in-place adjustments: padding inserted to temporarily prevent further allocation in regular regions 157 _verify_size_adjusted_for_padding 158 } VerifySize; 159 160 typedef enum { 161 // Disable gc-state verification 162 _verify_gcstate_disable, 163 164 // Nothing is in progress, no forwarded objects 165 _verify_gcstate_stable, 166 167 // Nothing is in progress, no forwarded objects, weak roots handling 168 _verify_gcstate_stable_weakroots, 169 170 // Nothing is in progress, some objects are forwarded 171 _verify_gcstate_forwarded, 172 173 // Evacuation is in progress, some objects are forwarded 174 _verify_gcstate_evacuation, 175 176 // Evacuation is done, some objects are forwarded, updating is in progress 177 _verify_gcstate_updating 178 } VerifyGCState; 179 180 struct VerifyOptions { 181 VerifyForwarded _verify_forwarded; 182 VerifyMarked _verify_marked; 183 VerifyCollectionSet _verify_cset; 184 VerifyLiveness _verify_liveness; 185 VerifyRegions _verify_regions; 186 VerifyGCState _verify_gcstate; 187 188 VerifyOptions(VerifyForwarded verify_forwarded, 189 VerifyMarked verify_marked, 190 VerifyCollectionSet verify_collection_set, 191 VerifyLiveness verify_liveness, 192 VerifyRegions verify_regions, 193 VerifyGCState verify_gcstate) : 194 _verify_forwarded(verify_forwarded), _verify_marked(verify_marked), 195 _verify_cset(verify_collection_set), 196 _verify_liveness(verify_liveness), _verify_regions(verify_regions), 197 _verify_gcstate(verify_gcstate) {} 198 }; 199 200 private: 201 void verify_at_safepoint(const char* label, 202 VerifyRememberedSet remembered, 203 VerifyForwarded forwarded, 204 VerifyMarked marked, 205 VerifyCollectionSet cset, 206 VerifyLiveness liveness, 207 VerifyRegions regions, 208 VerifySize sizeness, 209 VerifyGCState gcstate); 210 211 public: 212 ShenandoahVerifier(ShenandoahHeap* heap, MarkBitMap* verification_bitmap) : 213 _heap(heap), _verification_bit_map(verification_bitmap) {}; 214 215 void verify_before_concmark(); 216 void verify_after_concmark(); 217 void verify_before_evacuation(); 218 void verify_during_evacuation(); 219 void verify_after_evacuation(); 220 void verify_before_updaterefs(); 221 void verify_after_updaterefs(); 222 void verify_before_fullgc(); 223 void verify_after_fullgc(); 224 void verify_after_degenerated(); 225 void verify_generic(VerifyOption option); 226 227 // Roots should only contain to-space oops 228 void verify_roots_in_to_space(); 229 230 void verify_roots_no_forwarded(); 231 232 private: 233 void help_verify_region_rem_set(ShenandoahHeapRegion* r, ShenandoahMarkingContext* ctx, 234 HeapWord* from, HeapWord* top, HeapWord* update_watermark, const char* message); 235 236 void verify_rem_set_before_mark(); 237 void verify_rem_set_before_update_ref(); 238 void verify_rem_set_after_full_gc(); 239 }; 240 241 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHVERIFIER_HPP