1 /*
  2  * Copyright (c) 2018, 2019, 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_SHENANDOAHASSERTS_HPP
 27 #define SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
 28 
 29 #include "memory/iterator.hpp"
 30 #include "runtime/mutex.hpp"
 31 #include "utilities/formatBuffer.hpp"
 32 
 33 typedef FormatBuffer<8192> ShenandoahMessageBuffer;
 34 
 35 class ShenandoahAsserts {
 36 public:
 37   enum SafeLevel {
 38     _safe_unknown,
 39     _safe_oop,
 40     _safe_oop_fwd,
 41     _safe_all
 42   };
 43 
 44   static void print_obj(ShenandoahMessageBuffer &msg, oop obj);
 45 
 46   static void print_non_obj(ShenandoahMessageBuffer &msg, void *loc);
 47 
 48   static void print_obj_safe(ShenandoahMessageBuffer &msg, void *loc);
 49 
 50   static void print_failure(SafeLevel level, oop obj, void *interior_loc, oop loc,
 51                             const char *phase, const char *label,
 52                             const char *file, int line);
 53 
 54   static void print_rp_failure(const char *label, BoolObjectClosure* actual,
 55                                const char *file, int line);
 56 
 57   static void assert_in_heap(void* interior_loc, oop obj, const char* file, int line);
 58   static void assert_in_heap_or_null(void* interior_loc, oop obj, const char* file, int line);
 59   static void assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line);
 60 
 61   static void assert_correct(void* interior_loc, oop obj, const char* file, int line);
 62   static void assert_forwarded(void* interior_loc, oop obj, const char* file, int line);
 63   static void assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line);
 64   static void assert_marked(void* interior_loc, oop obj, const char* file, int line);
 65   static void assert_marked_weak(void* interior_loc, oop obj, const char* file, int line);
 66   static void assert_marked_strong(void* interior_loc, oop obj, const char* file, int line);
 67   static void assert_in_cset(void* interior_loc, oop obj, const char* file, int line);
 68   static void assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line);
 69   static void assert_not_in_cset_loc(void* interior_loc, const char* file, int line);
 70 
 71   static void assert_locked_or_shenandoah_safepoint(Mutex* lock, const char* file, int line);
 72 
 73   static void assert_heaplocked(const char* file, int line);
 74   static void assert_not_heaplocked(const char* file, int line);
 75   static void assert_heaplocked_or_safepoint(const char* file, int line);
 76   static void assert_heaplocked_or_fullgc_safepoint(const char* file, int line);
 77 
 78 #ifdef ASSERT
 79 #define shenandoah_assert_in_heap(interior_loc, obj) \
 80                     ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__)
 81 #define shenandoah_assert_in_heap_or_null(interior_loc, obj) \
 82                     ShenandoahAsserts::assert_in_heap_or_null(interior_loc, obj, __FILE__, __LINE__)
 83 #define shenandoah_assert_in_correct_region(interior_loc, obj) \
 84                     ShenandoahAsserts::assert_in_correct_region(interior_loc, obj, __FILE__, __LINE__)
 85 
 86 #define shenandoah_assert_correct_if(interior_loc, obj, condition) \
 87   if (condition)    ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
 88 #define shenandoah_assert_correct_except(interior_loc, obj, exception) \
 89   if (!(exception)) ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
 90 #define shenandoah_assert_correct(interior_loc, obj) \
 91                     ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__)
 92 
 93 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition) \
 94   if (condition)    ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
 95 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception) \
 96   if (!(exception)) ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
 97 #define shenandoah_assert_forwarded(interior_loc, obj) \
 98                     ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__)
 99 
100 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition) \
101   if (condition)    ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
102 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception) \
103   if (!(exception)) ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
104 #define shenandoah_assert_not_forwarded(interior_loc, obj) \
105                     ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__)
106 
107 #define shenandoah_assert_marked_if(interior_loc, obj, condition) \
108   if (condition)    ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
109 #define shenandoah_assert_marked_except(interior_loc, obj, exception) \
110   if (!(exception)) ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
111 #define shenandoah_assert_marked(interior_loc, obj) \
112                     ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__)
113 
114 #define shenandoah_assert_marked_weak_if(interior_loc, obj, condition) \
115   if (condition)    ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__)
116 #define shenandoah_assert_marked_weak_except(interior_loc, obj, exception) \
117   if (!(exception)) ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__)
118 #define shenandoah_assert_marked_weak(interior_loc, obj) \
119                     ShenandoahAsserts::assert_marked_weak(interior_loc, obj, __FILE__, __LINE__)
120 
121 #define shenandoah_assert_marked_strong_if(interior_loc, obj, condition) \
122   if (condition)    ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__)
123 #define shenandoah_assert_marked_strong_except(interior_loc, obj, exception) \
124   if (!(exception)) ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__)
125 #define shenandoah_assert_marked_strong(interior_loc, obj) \
126                     ShenandoahAsserts::assert_marked_strong(interior_loc, obj, __FILE__, __LINE__)
127 
128 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) \
129   if (condition)    ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
130 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) \
131   if (!(exception)) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
132 #define shenandoah_assert_in_cset(interior_loc, obj) \
133                     ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__)
134 
135 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition) \
136   if (condition)    ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
137 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception) \
138   if (!(exception)) ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
139 #define shenandoah_assert_not_in_cset(interior_loc, obj) \
140                     ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__)
141 
142 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition) \
143   if (condition)    ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
144 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception) \
145   if (!(exception)) ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
146 #define shenandoah_assert_not_in_cset_loc(interior_loc) \
147                     ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__)
148 
149 #define shenandoah_assert_rp_isalive_installed() \
150                     ShenandoahAsserts::assert_rp_isalive_installed(__FILE__, __LINE__)
151 #define shenandoah_assert_rp_isalive_not_installed() \
152                     ShenandoahAsserts::assert_rp_isalive_not_installed(__FILE__, __LINE__)
153 
154 #define shenandoah_assert_safepoint() \
155                     assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at Shenandoah Safepoints")
156 
157 #define shenandoah_assert_locked_or_safepoint(lock) \
158                     ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(lock, __FILE__, __LINE__)
159 
160 #define shenandoah_assert_heaplocked() \
161                     ShenandoahAsserts::assert_heaplocked(__FILE__, __LINE__)
162 
163 #define shenandoah_assert_not_heaplocked() \
164                     ShenandoahAsserts::assert_not_heaplocked(__FILE__, __LINE__)
165 
166 #define shenandoah_assert_heaplocked_or_safepoint() \
167                     ShenandoahAsserts::assert_heaplocked_or_safepoint(__FILE__, __LINE__)
168 
169 #define shenandoah_assert_heaplocked_or_fullgc_safepoint() \
170                     ShenandoahAsserts::assert_heaplocked_or_fullgc_safepoint(__FILE__, __LINE__)
171 #define shenandoah_assert_control_or_vm_thread() \
172                     assert(Thread::current()->is_VM_thread() || Thread::current() == ShenandoahHeap::heap()->control_thread(), "Expected control thread or vm thread")
173 
174 #define shenandoah_assert_generational() \
175                     assert(ShenandoahHeap::heap()->mode()->is_generational(), "Must be in generational mode here.")
176 #else
177 #define shenandoah_assert_in_heap(interior_loc, obj)
178 #define shenandoah_assert_in_heap_or_null(interior_loc, obj)
179 #define shenandoah_assert_in_correct_region(interior_loc, obj)
180 
181 #define shenandoah_assert_correct_if(interior_loc, obj, condition)
182 #define shenandoah_assert_correct_except(interior_loc, obj, exception)
183 #define shenandoah_assert_correct(interior_loc, obj)
184 
185 #define shenandoah_assert_forwarded_if(interior_loc, obj, condition)
186 #define shenandoah_assert_forwarded_except(interior_loc, obj, exception)
187 #define shenandoah_assert_forwarded(interior_loc, obj)
188 
189 #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition)
190 #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception)
191 #define shenandoah_assert_not_forwarded(interior_loc, obj)
192 
193 #define shenandoah_assert_marked_if(interior_loc, obj, condition)
194 #define shenandoah_assert_marked_except(interior_loc, obj, exception)
195 #define shenandoah_assert_marked(interior_loc, obj)
196 
197 #define shenandoah_assert_marked_weak_if(interior_loc, obj, condition)
198 #define shenandoah_assert_marked_weak_except(interior_loc, obj, exception)
199 #define shenandoah_assert_marked_weak(interior_loc, obj)
200 
201 #define shenandoah_assert_marked_strong_if(interior_loc, obj, condition)
202 #define shenandoah_assert_marked_strong_except(interior_loc, obj, exception)
203 #define shenandoah_assert_marked_strong(interior_loc, obj)
204 
205 #define shenandoah_assert_in_cset_if(interior_loc, obj, condition)
206 #define shenandoah_assert_in_cset_except(interior_loc, obj, exception)
207 #define shenandoah_assert_in_cset(interior_loc, obj)
208 
209 #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition)
210 #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception)
211 #define shenandoah_assert_not_in_cset(interior_loc, obj)
212 
213 #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition)
214 #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception)
215 #define shenandoah_assert_not_in_cset_loc(interior_loc)
216 
217 #define shenandoah_assert_rp_isalive_installed()
218 #define shenandoah_assert_rp_isalive_not_installed()
219 
220 #define shenandoah_assert_safepoint()
221 #define shenandoah_assert_locked_or_safepoint(lock)
222 
223 #define shenandoah_assert_heaplocked()
224 #define shenandoah_assert_not_heaplocked()
225 #define shenandoah_assert_heaplocked_or_safepoint()
226 #define shenandoah_assert_heaplocked_or_fullgc_safepoint()
227 #define shenandoah_assert_control_or_vm_thread()
228 #define shenandoah_assert_generational()
229 
230 #endif
231 
232 #define shenandoah_not_implemented \
233                     { fatal("Deliberately not implemented."); }
234 #define shenandoah_not_implemented_return(v) \
235                     { fatal("Deliberately not implemented."); return v; }
236 
237 };
238 
239 #endif // SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP
--- EOF ---