< prev index next >

src/hotspot/share/gc/shenandoah/shenandoahAsserts.cpp

Print this page

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahAsserts.hpp"
 28 #include "gc/shenandoah/shenandoahForwarding.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 30 #include "gc/shenandoah/shenandoahHeapRegionSet.inline.hpp"
 31 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"

 32 #include "gc/shenandoah/shenandoahUtils.hpp"
 33 #include "memory/resourceArea.hpp"
 34 
 35 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
 36   // Be extra safe. Only access data that is guaranteed to be safe:
 37   // should be in heap, in known committed region, within that region.
 38 
 39   ShenandoahHeap* heap = ShenandoahHeap::heap();
 40   if (!heap->is_in(loc)) return;
 41 
 42   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
 43   if (r != NULL && r->is_committed()) {
 44     address start = MAX2((address) r->bottom(), (address) loc - 32);
 45     address end   = MIN2((address) r->end(),    (address) loc + 128);
 46     if (start >= end) return;
 47 
 48     stringStream ss;
 49     os::print_hex_dump(&ss, start, end, 4);
 50     msg.append("\n");
 51     msg.append("Raw heap memory:\n%s", ss.freeze());

180   ShenandoahHeap* heap = ShenandoahHeap::heap();
181 
182   if (obj != NULL && !heap->is_in(obj)) {
183     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap_or_null failed",
184                   "oop must point to a heap address",
185                   file, line);
186   }
187 }
188 
189 void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
190   ShenandoahHeap* heap = ShenandoahHeap::heap();
191 
192   // Step 1. Check that obj is correct.
193   // After this step, it is safe to call heap_region_containing().
194   if (!heap->is_in(obj)) {
195     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
196                   "oop must point to a heap address",
197                   file, line);
198   }
199 
200   Klass* obj_klass = obj->klass_or_null();
201   if (obj_klass == NULL) {
202     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
203                   "Object klass pointer should not be NULL",
204                   file,line);
205   }
206 
207   if (!Metaspace::contains(obj_klass)) {
208     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
209                   "Object klass pointer must go to metaspace",
210                   file,line);
211   }
212 
213   oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
214 
215   if (obj != fwd) {
216     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
217     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
218     // that still points to the object itself.
219     if (heap->is_full_gc_move_in_progress()) {
220       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
221                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
222                     file, line);
223     }
224 
225     // Step 2. Check that forwardee is correct
226     if (!heap->is_in(fwd)) {
227       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
228                     "Forwardee must point to a heap address",
229                     file, line);
230     }
231 
232     if (obj_klass != fwd->klass()) {
233       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
234                     "Forwardee klass disagrees with object class",
235                     file, line);
236     }
237 
238     // Step 3. Check that forwardee points to correct region
239     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
240       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
241                     "Non-trivial forwardee should in another region",
242                     file, line);
243     }
244 
245     // Step 4. Check for multiple forwardings
246     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
247     if (fwd != fwd2) {
248       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
249                     "Multiple forwardings",
250                     file, line);
251     }
252   }

 12  * version 2 for more details (a copy is included in the LICENSE file that
 13  * accompanied this code).
 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 
 27 #include "gc/shenandoah/shenandoahAsserts.hpp"
 28 #include "gc/shenandoah/shenandoahForwarding.hpp"
 29 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
 30 #include "gc/shenandoah/shenandoahHeapRegionSet.inline.hpp"
 31 #include "gc/shenandoah/shenandoahMarkingContext.inline.hpp"
 32 #include "gc/shenandoah/shenandoahObjectUtils.inline.hpp"
 33 #include "gc/shenandoah/shenandoahUtils.hpp"
 34 #include "memory/resourceArea.hpp"
 35 
 36 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
 37   // Be extra safe. Only access data that is guaranteed to be safe:
 38   // should be in heap, in known committed region, within that region.
 39 
 40   ShenandoahHeap* heap = ShenandoahHeap::heap();
 41   if (!heap->is_in(loc)) return;
 42 
 43   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
 44   if (r != NULL && r->is_committed()) {
 45     address start = MAX2((address) r->bottom(), (address) loc - 32);
 46     address end   = MIN2((address) r->end(),    (address) loc + 128);
 47     if (start >= end) return;
 48 
 49     stringStream ss;
 50     os::print_hex_dump(&ss, start, end, 4);
 51     msg.append("\n");
 52     msg.append("Raw heap memory:\n%s", ss.freeze());

181   ShenandoahHeap* heap = ShenandoahHeap::heap();
182 
183   if (obj != NULL && !heap->is_in(obj)) {
184     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap_or_null failed",
185                   "oop must point to a heap address",
186                   file, line);
187   }
188 }
189 
190 void ShenandoahAsserts::assert_correct(void* interior_loc, oop obj, const char* file, int line) {
191   ShenandoahHeap* heap = ShenandoahHeap::heap();
192 
193   // Step 1. Check that obj is correct.
194   // After this step, it is safe to call heap_region_containing().
195   if (!heap->is_in(obj)) {
196     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
197                   "oop must point to a heap address",
198                   file, line);
199   }
200 
201   Klass* obj_klass = ShenandoahObjectUtils::klass(obj);
202   if (obj_klass == NULL) {
203     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
204                   "Object klass pointer should not be NULL",
205                   file,line);
206   }
207 
208   if (!Metaspace::contains(obj_klass)) {
209     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
210                   "Object klass pointer must go to metaspace",
211                   file,line);
212   }
213 
214   oop fwd = ShenandoahForwarding::get_forwardee_raw_unchecked(obj);
215 
216   if (obj != fwd) {
217     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
218     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
219     // that still points to the object itself.
220     if (heap->is_full_gc_move_in_progress()) {
221       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
222                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
223                     file, line);
224     }
225 
226     // Step 2. Check that forwardee is correct
227     if (!heap->is_in(fwd)) {
228       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
229                     "Forwardee must point to a heap address",
230                     file, line);
231     }
232 
233     if (obj_klass != ShenandoahObjectUtils::klass(fwd)) {
234       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
235                     "Forwardee klass disagrees with object class",
236                     file, line);
237     }
238 
239     // Step 3. Check that forwardee points to correct region
240     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
241       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
242                     "Non-trivial forwardee should in another region",
243                     file, line);
244     }
245 
246     // Step 4. Check for multiple forwardings
247     oop fwd2 = ShenandoahForwarding::get_forwardee_raw_unchecked(fwd);
248     if (fwd != fwd2) {
249       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
250                     "Multiple forwardings",
251                     file, line);
252     }
253   }
< prev index next >