1 | /* |
2 | * Copyright (c) 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_SHENANDOAHASSERTS_HPP |
25 | #define SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP |
26 | |
27 | #include "memory/iterator.hpp" |
28 | #include "runtime/mutex.hpp" |
29 | #include "utilities/formatBuffer.hpp" |
30 | |
31 | typedef FormatBuffer<8192> ShenandoahMessageBuffer; |
32 | |
33 | class ShenandoahAsserts { |
34 | public: |
35 | enum SafeLevel { |
36 | _safe_unknown, |
37 | _safe_oop, |
38 | _safe_oop_fwd, |
39 | _safe_all |
40 | }; |
41 | |
42 | static void print_obj(ShenandoahMessageBuffer &msg, oop obj); |
43 | |
44 | static void print_non_obj(ShenandoahMessageBuffer &msg, void *loc); |
45 | |
46 | static void print_obj_safe(ShenandoahMessageBuffer &msg, void *loc); |
47 | |
48 | static void print_failure(SafeLevel level, oop obj, void *interior_loc, oop loc, |
49 | const char *phase, const char *label, |
50 | const char *file, int line); |
51 | |
52 | static void print_rp_failure(const char *label, BoolObjectClosure* actual, |
53 | const char *file, int line); |
54 | |
55 | static void assert_in_heap(void* interior_loc, oop obj, const char* file, int line); |
56 | static void assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line); |
57 | |
58 | static void assert_correct(void* interior_loc, oop obj, const char* file, int line); |
59 | static void assert_forwarded(void* interior_loc, oop obj, const char* file, int line); |
60 | static void assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line); |
61 | static void assert_marked(void* interior_loc, oop obj, const char* file, int line); |
62 | static void assert_in_cset(void* interior_loc, oop obj, const char* file, int line); |
63 | static void assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line); |
64 | static void assert_not_in_cset_loc(void* interior_loc, const char* file, int line); |
65 | |
66 | static void assert_rp_isalive_not_installed(const char *file, int line); |
67 | static void assert_rp_isalive_installed(const char *file, int line); |
68 | |
69 | static void assert_locked_or_shenandoah_safepoint(const Monitor* lock, const char*file, int line); |
70 | |
71 | #ifdef ASSERT |
72 | #define shenandoah_assert_in_heap(interior_loc, obj) \ |
73 | ShenandoahAsserts::assert_in_heap(interior_loc, obj, __FILE__, __LINE__); |
74 | #define shenandoah_assert_in_correct_region(interior_loc, obj) \ |
75 | ShenandoahAsserts::assert_in_correct_region(interior_loc, obj, __FILE__, __LINE__); |
76 | |
77 | #define shenandoah_assert_correct_if(interior_loc, obj, condition) \ |
78 | if (condition) ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__); |
79 | #define shenandoah_assert_correct_except(interior_loc, obj, exception) \ |
80 | if (!(exception)) ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__); |
81 | #define shenandoah_assert_correct(interior_loc, obj) \ |
82 | ShenandoahAsserts::assert_correct(interior_loc, obj, __FILE__, __LINE__); |
83 | |
84 | #define shenandoah_assert_forwarded_if(interior_loc, obj, condition) \ |
85 | if (condition) ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__); |
86 | #define shenandoah_assert_forwarded_except(interior_loc, obj, exception) \ |
87 | if (!(exception)) ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__); |
88 | #define shenandoah_assert_forwarded(interior_loc, obj) \ |
89 | ShenandoahAsserts::assert_forwarded(interior_loc, obj, __FILE__, __LINE__); |
90 | |
91 | #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition) \ |
92 | if (condition) ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__); |
93 | #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception) \ |
94 | if (!(exception)) ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__); |
95 | #define shenandoah_assert_not_forwarded(interior_loc, obj) \ |
96 | ShenandoahAsserts::assert_not_forwarded(interior_loc, obj, __FILE__, __LINE__); |
97 | |
98 | #define shenandoah_assert_marked_if(interior_loc, obj, condition) \ |
99 | if (condition) ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__); |
100 | #define shenandoah_assert_marked_except(interior_loc, obj, exception) \ |
101 | if (!(exception)) ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__); |
102 | #define shenandoah_assert_marked(interior_loc, obj) \ |
103 | ShenandoahAsserts::assert_marked(interior_loc, obj, __FILE__, __LINE__); |
104 | |
105 | #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) \ |
106 | if (condition) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__); |
107 | #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) \ |
108 | if (!(exception)) ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__); |
109 | #define shenandoah_assert_in_cset(interior_loc, obj) \ |
110 | ShenandoahAsserts::assert_in_cset(interior_loc, obj, __FILE__, __LINE__); |
111 | |
112 | #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition) \ |
113 | if (condition) ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__); |
114 | #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception) \ |
115 | if (!(exception)) ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__); |
116 | #define shenandoah_assert_not_in_cset(interior_loc, obj) \ |
117 | ShenandoahAsserts::assert_not_in_cset(interior_loc, obj, __FILE__, __LINE__); |
118 | |
119 | #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition) \ |
120 | if (condition) ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__); |
121 | #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception) \ |
122 | if (!(exception)) ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__); |
123 | #define shenandoah_assert_not_in_cset_loc(interior_loc) \ |
124 | ShenandoahAsserts::assert_not_in_cset_loc(interior_loc, __FILE__, __LINE__); |
125 | |
126 | #define shenandoah_assert_rp_isalive_installed() \ |
127 | ShenandoahAsserts::assert_rp_isalive_installed(__FILE__, __LINE__); |
128 | #define shenandoah_assert_rp_isalive_not_installed() \ |
129 | ShenandoahAsserts::assert_rp_isalive_not_installed(__FILE__, __LINE__); |
130 | |
131 | #define shenandoah_assert_safepoint() \ |
132 | assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at Shenandoah Safepoints"); |
133 | |
134 | #define shenandoah_assert_locked_or_safepoint(lock) \ |
135 | ShenandoahAsserts::assert_locked_or_shenandoah_safepoint(lock, __FILE__, __LINE__); |
136 | #else |
137 | #define shenandoah_assert_in_heap(interior_loc, obj) |
138 | #define shenandoah_assert_in_correct_region(interior_loc, obj) |
139 | |
140 | #define shenandoah_assert_correct_if(interior_loc, obj, condition) |
141 | #define shenandoah_assert_correct_except(interior_loc, obj, exception) |
142 | #define shenandoah_assert_correct(interior_loc, obj) |
143 | |
144 | #define shenandoah_assert_forwarded_if(interior_loc, obj, condition) |
145 | #define shenandoah_assert_forwarded_except(interior_loc, obj, exception) |
146 | #define shenandoah_assert_forwarded(interior_loc, obj) |
147 | |
148 | #define shenandoah_assert_not_forwarded_if(interior_loc, obj, condition) |
149 | #define shenandoah_assert_not_forwarded_except(interior_loc, obj, exception) |
150 | #define shenandoah_assert_not_forwarded(interior_loc, obj) |
151 | |
152 | #define shenandoah_assert_marked_if(interior_loc, obj, condition) |
153 | #define shenandoah_assert_marked_except(interior_loc, obj, exception) |
154 | #define shenandoah_assert_marked(interior_loc, obj) |
155 | |
156 | #define shenandoah_assert_in_cset_if(interior_loc, obj, condition) |
157 | #define shenandoah_assert_in_cset_except(interior_loc, obj, exception) |
158 | #define shenandoah_assert_in_cset(interior_loc, obj) |
159 | |
160 | #define shenandoah_assert_not_in_cset_if(interior_loc, obj, condition) |
161 | #define shenandoah_assert_not_in_cset_except(interior_loc, obj, exception) |
162 | #define shenandoah_assert_not_in_cset(interior_loc, obj) |
163 | |
164 | #define shenandoah_assert_not_in_cset_loc_if(interior_loc, condition) |
165 | #define shenandoah_assert_not_in_cset_loc_except(interior_loc, exception) |
166 | #define shenandoah_assert_not_in_cset_loc(interior_loc) |
167 | |
168 | #define shenandoah_assert_rp_isalive_installed() |
169 | #define shenandoah_assert_rp_isalive_not_installed() |
170 | |
171 | #define shenandoah_assert_safepoint() |
172 | #define shenandoah_assert_locked_or_safepoint(lock) |
173 | |
174 | #endif |
175 | |
176 | #define shenandoah_not_implemented \ |
177 | { fatal("Deliberately not implemented."); } |
178 | #define shenandoah_not_implemented_return(v) \ |
179 | { fatal("Deliberately not implemented."); return v; } |
180 | |
181 | }; |
182 | |
183 | #endif // SHARE_GC_SHENANDOAH_SHENANDOAHASSERTS_HPP |
184 | |