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