< prev index next >

src/share/vm/gc_implementation/shenandoah/shenandoahAsserts.cpp

Print this page
rev 10658 : [backport] Single marking bitmap
rev 10669 : [backport] Clean up dead code
rev 10715 : [backport] Cleanup up superfluous newlines
rev 10724 : [backport] Add JFR parallel and concurrent events (infrastructure)
rev 10764 : [backport] Rename BrooksPointer to ShenandoahBrooksPointer
rev 10772 : [backport] Update copyrights
   1 /*
   2  * Copyright (c) 2018, Red Hat, Inc. and/or its affiliates.
   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 #include "precompiled.hpp"
  25 
  26 #include "gc_implementation/shenandoah/brooksPointer.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahAsserts.hpp"

  28 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahMarkingContext.inline.hpp"

  31 #include "memory/resourceArea.hpp"
  32 
  33 
  34 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
  35   // Be extra safe. Only access data that is guaranteed to be safe:
  36   // should be in heap, in known committed region, within that region.
  37 
  38   ShenandoahHeap* heap = ShenandoahHeap::heap();
  39   if (!heap->is_in(loc)) return;
  40 
  41   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
  42   if (r != NULL && r->is_committed()) {
  43 
  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.as_string());
  52   }
  53 }
  54 
  55 void ShenandoahAsserts::print_obj(ShenandoahMessageBuffer& msg, oop obj) {
  56   ShenandoahHeap* heap = ShenandoahHeap::heap();
  57   ShenandoahHeapRegion *r = heap->heap_region_containing(obj);
  58 
  59   ResourceMark rm;
  60   stringStream ss;
  61   r->print_on(&ss);
  62 
  63   ShenandoahMarkingContext* const next_ctx = heap->next_marking_context();
  64   ShenandoahMarkingContext* const compl_ctx = heap->complete_marking_context();
  65 
  66   msg.append("  " PTR_FORMAT " - klass " PTR_FORMAT " %s\n", p2i(obj), p2i(obj->klass()), obj->klass()->external_name());
  67   msg.append("    %3s allocated after complete mark start\n", compl_ctx->allocated_after_mark_start((HeapWord *) obj) ? "" : "not");
  68   msg.append("    %3s allocated after next mark start\n",     next_ctx->allocated_after_mark_start((HeapWord *) obj)     ? "" : "not");
  69   msg.append("    %3s marked complete\n",      compl_ctx->is_marked(obj) ? "" : "not");
  70   msg.append("    %3s marked next\n",          next_ctx->is_marked(obj) ? "" : "not");
  71   msg.append("    %3s in collection set\n",    heap->in_collection_set(obj) ? "" : "not");
  72   msg.append("  region: %s", ss.as_string());
  73 }
  74 
  75 void ShenandoahAsserts::print_non_obj(ShenandoahMessageBuffer& msg, void* loc) {
  76   ShenandoahHeap* heap = ShenandoahHeap::heap();
  77   if (heap->is_in(loc)) {
  78     msg.append("  inside Java heap\n");
  79     ShenandoahHeapRegion *r = heap->heap_region_containing(loc);
  80     stringStream ss;
  81     r->print_on(&ss);
  82 
  83     msg.append("    %3s in collection set\n",    heap->in_collection_set(loc) ? "" : "not");
  84     msg.append("  region: %s", ss.as_string());
  85   } else {
  86     msg.append("  outside of Java heap\n");
  87     stringStream ss;
  88     os::print_location(&ss, (intptr_t) loc, false);
  89     msg.append("  %s", ss.as_string());
  90   }


 119     msg.append("  interior location: " PTR_FORMAT "\n", p2i(interior_loc));
 120     if (loc_in_heap) {
 121       print_obj(msg, loc);
 122     } else {
 123       print_non_obj(msg, interior_loc);
 124     }
 125   } else {
 126     msg.append("  no interior location recorded (probably a plain heap scan, or detached oop)\n");
 127   }
 128   msg.append("\n");
 129 
 130   msg.append("Object:\n");
 131   if (level >= _safe_oop) {
 132     print_obj(msg, obj);
 133   } else {
 134     print_obj_safe(msg, obj);
 135   }
 136   msg.append("\n");
 137 
 138   if (level >= _safe_oop) {
 139     oop fwd = (oop) BrooksPointer::get_raw_unchecked(obj);
 140     msg.append("Forwardee:\n");
 141     if (!oopDesc::unsafe_equals(obj, fwd)) {
 142       if (level >= _safe_oop_fwd) {
 143         print_obj(msg, fwd);
 144       } else {
 145         print_obj_safe(msg, fwd);
 146       }
 147     } else {
 148       msg.append("  (the object itself)");
 149     }
 150     msg.append("\n");
 151   }
 152 
 153   if (level >= _safe_oop_fwd) {
 154     oop fwd = (oop) BrooksPointer::get_raw_unchecked(obj);
 155     oop fwd2 = (oop) BrooksPointer::get_raw_unchecked(fwd);
 156     if (!oopDesc::unsafe_equals(fwd, fwd2)) {
 157       msg.append("Second forwardee:\n");
 158       print_obj_safe(msg, fwd2);
 159       msg.append("\n");
 160     }
 161   }
 162 
 163   report_vm_error(file, line, msg.buffer());
 164 }
 165 
 166 void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) {
 167   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 168 
 169   if (!heap->is_in(obj)) {
 170     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap failed",
 171                   "oop must point to a heap address",
 172                   file, line);
 173   }
 174 }
 175 


 180   // After this step, it is safe to call heap_region_containing().
 181   if (!heap->is_in(obj)) {
 182     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 183                   "oop must point to a heap address",
 184                   file, line);
 185   }
 186 
 187   Klass* obj_klass = obj->klass_or_null();
 188   if (obj_klass == NULL) {
 189     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 190                   "Object klass pointer should not be NULL",
 191                   file,line);
 192   }
 193 
 194   if (!Metaspace::contains(obj_klass)) {
 195     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 196                   "Object klass pointer must go to metaspace",
 197                   file,line);
 198   }
 199 
 200   oop fwd = oop(BrooksPointer::get_raw_unchecked(obj));
 201 
 202   if (!oopDesc::unsafe_equals(obj, fwd)) {
 203 
 204     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
 205     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
 206     // that still points to the object itself.
 207     if (heap->is_full_gc_move_in_progress()) {
 208       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 209                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
 210                     file, line);
 211     }
 212 
 213     // Step 2. Check that forwardee is correct
 214     if (!heap->is_in(fwd)) {
 215       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 216                     "Forwardee must point to a heap address",
 217                     file, line);
 218     }
 219 
 220     if (obj_klass != fwd->klass()) {
 221       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 222                     "Forwardee klass disagrees with object class",
 223                     file, line);
 224     }
 225 
 226     // Step 3. Check that forwardee points to correct region
 227     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
 228       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 229                     "Non-trivial forwardee should in another region",
 230                     file, line);
 231     }
 232 
 233     // Step 4. Check for multiple forwardings
 234     oop fwd2 = oop(BrooksPointer::get_raw_unchecked(fwd));
 235     if (!oopDesc::unsafe_equals(fwd, fwd2)) {
 236       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 237                     "Multiple forwardings",
 238                     file, line);
 239     }
 240   }
 241 }
 242 
 243 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
 244   assert_correct(interior_loc, obj, file, line);
 245 
 246   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 247   ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
 248   if (!r->is_active()) {
 249     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 250                   "Object must reside in active region",
 251                   file, line);
 252   }
 253 
 254   size_t alloc_size = obj->size() + BrooksPointer::word_size();
 255   if (alloc_size > ShenandoahHeapRegion::humongous_threshold_words()) {
 256     size_t idx = r->region_number();
 257     size_t num_regions = ShenandoahHeapRegion::required_regions(alloc_size * HeapWordSize);
 258     for (size_t i = idx; i < idx + num_regions; i++) {
 259       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
 260       if (i == idx && !chain_reg->is_humongous_start()) {
 261         print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 262                       "Object must reside in humongous start",
 263                       file, line);
 264       }
 265       if (i != idx && !chain_reg->is_humongous_continuation()) {
 266         print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 267                       "Humongous continuation should be of proper size",
 268                       file, line);
 269       }
 270     }
 271   }
 272 }
 273 
 274 void ShenandoahAsserts::assert_forwarded(void* interior_loc, oop obj, const char* file, int line) {
 275   assert_correct(interior_loc, obj, file, line);
 276   oop fwd = oop(BrooksPointer::get_raw_unchecked(obj));
 277 
 278   if (oopDesc::unsafe_equals(obj, fwd)) {
 279     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_forwarded failed",
 280                   "Object should be forwarded",
 281                   file, line);
 282   }
 283 }
 284 
 285 void ShenandoahAsserts::assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line) {
 286   assert_correct(interior_loc, obj, file, line);
 287   oop fwd = oop(BrooksPointer::get_raw_unchecked(obj));
 288 
 289   if (!oopDesc::unsafe_equals(obj, fwd)) {
 290     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_forwarded failed",
 291                   "Object should not be forwarded",
 292                   file, line);
 293   }
 294 }
 295 
 296 void ShenandoahAsserts::assert_marked_complete(void* interior_loc, oop obj, const char* file, int line) {
 297   assert_correct(interior_loc, obj, file, line);
 298 
 299   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 300   if (!heap->complete_marking_context()->is_marked(obj)) {
 301     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked_complete failed",
 302                   "Object should be marked (complete)",
 303                   file, line);
 304   }
 305 }
 306 
 307 void ShenandoahAsserts::assert_marked_next(void* interior_loc, oop obj, const char* file, int line) {
 308   assert_correct(interior_loc, obj, file, line);
 309 
 310   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 311   if (!heap->next_marking_context()->is_marked(obj)) {
 312     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked_next failed",
 313                   "Object should be marked (next)",
 314                   file, line);
 315   }
 316 }
 317 
 318 void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) {
 319   assert_correct(interior_loc, obj, file, line);
 320 
 321   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 322   if (!heap->in_collection_set(obj)) {
 323     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_in_cset failed",
 324                   "Object should be in collection set",
 325                   file, line);
 326   }
 327 }
 328 
 329 void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line) {
 330   assert_correct(interior_loc, obj, file, line);
 331 
 332   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 333   if (heap->in_collection_set(obj)) {
 334     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_in_cset failed",
 335                   "Object should not be in collection set",
 336                   file, line);
 337   }
 338 }
 339 
 340 void ShenandoahAsserts::assert_not_in_cset_loc(void* interior_loc, const char* file, int line) {
 341   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 342   if (heap->in_collection_set(interior_loc)) {
 343     print_failure(_safe_unknown, NULL, interior_loc, NULL, "Shenandoah assert_not_in_cset_loc failed",
 344                   "Interior location should not be in collection set",
 345                   file, line);
 346   }
 347 }
 348 
 349 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
 350                                          const char *file, int line) {
 351   ShenandoahHeap* heap = ShenandoahHeap::heap();
 352   ShenandoahMessageBuffer msg("%s\n", label);
 353   msg.append(" Actual:                  " PTR_FORMAT "\n", p2i(actual));
 354   report_vm_error(file, line, msg.buffer());
 355 }
 356 
 357 void ShenandoahAsserts::assert_rp_isalive_not_installed(const char *file, int line) {
 358   ShenandoahHeap* heap = ShenandoahHeap::heap();
 359   ReferenceProcessor* rp = heap->ref_processor();
 360   if (rp->is_alive_non_header() != NULL) {
 361     print_rp_failure("Shenandoah assert_rp_isalive_not_installed failed", rp->is_alive_non_header(),
 362                      file, line);
 363   }
 364 }
 365 
 366 void ShenandoahAsserts::assert_rp_isalive_installed(const char *file, int line) {
 367   ShenandoahHeap* heap = ShenandoahHeap::heap();
 368   ReferenceProcessor* rp = heap->ref_processor();
 369   if (rp->is_alive_non_header() == NULL) {
 370     print_rp_failure("Shenandoah assert_rp_isalive_installed failed", rp->is_alive_non_header(),
 371                      file, line);
   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 #include "precompiled.hpp"
  25 

  26 #include "gc_implementation/shenandoah/shenandoahAsserts.hpp"
  27 #include "gc_implementation/shenandoah/shenandoahBrooksPointer.hpp"
  28 #include "gc_implementation/shenandoah/shenandoahHeap.hpp"
  29 #include "gc_implementation/shenandoah/shenandoahHeap.inline.hpp"
  30 #include "gc_implementation/shenandoah/shenandoahMarkingContext.inline.hpp"
  31 #include "gc_implementation/shenandoah/shenandoahUtils.hpp"
  32 #include "memory/resourceArea.hpp"
  33 

  34 void print_raw_memory(ShenandoahMessageBuffer &msg, void* loc) {
  35   // Be extra safe. Only access data that is guaranteed to be safe:
  36   // should be in heap, in known committed region, within that region.
  37 
  38   ShenandoahHeap* heap = ShenandoahHeap::heap();
  39   if (!heap->is_in(loc)) return;
  40 
  41   ShenandoahHeapRegion* r = heap->heap_region_containing(loc);
  42   if (r != NULL && r->is_committed()) {

  43     address start = MAX2((address) r->bottom(), (address) loc - 32);
  44     address end   = MIN2((address) r->end(),    (address) loc + 128);
  45     if (start >= end) return;
  46 
  47     stringStream ss;
  48     os::print_hex_dump(&ss, start, end, 4);
  49     msg.append("\n");
  50     msg.append("Raw heap memory:\n%s", ss.as_string());
  51   }
  52 }
  53 
  54 void ShenandoahAsserts::print_obj(ShenandoahMessageBuffer& msg, oop obj) {
  55   ShenandoahHeap* heap = ShenandoahHeap::heap();
  56   ShenandoahHeapRegion *r = heap->heap_region_containing(obj);
  57 
  58   ResourceMark rm;
  59   stringStream ss;
  60   r->print_on(&ss);
  61 
  62   ShenandoahMarkingContext* const ctx = heap->marking_context();

  63 
  64   msg.append("  " PTR_FORMAT " - klass " PTR_FORMAT " %s\n", p2i(obj), p2i(obj->klass()), obj->klass()->external_name());
  65   msg.append("    %3s allocated after mark start\n", ctx->allocated_after_mark_start((HeapWord *) obj)     ? "" : "not");
  66   msg.append("    %3s marked \n",                    ctx->is_marked(obj) ? "" : "not");


  67   msg.append("    %3s in collection set\n",          heap->in_collection_set(obj) ? "" : "not");
  68   msg.append("  region: %s", ss.as_string());
  69 }
  70 
  71 void ShenandoahAsserts::print_non_obj(ShenandoahMessageBuffer& msg, void* loc) {
  72   ShenandoahHeap* heap = ShenandoahHeap::heap();
  73   if (heap->is_in(loc)) {
  74     msg.append("  inside Java heap\n");
  75     ShenandoahHeapRegion *r = heap->heap_region_containing(loc);
  76     stringStream ss;
  77     r->print_on(&ss);
  78 
  79     msg.append("    %3s in collection set\n",    heap->in_collection_set(loc) ? "" : "not");
  80     msg.append("  region: %s", ss.as_string());
  81   } else {
  82     msg.append("  outside of Java heap\n");
  83     stringStream ss;
  84     os::print_location(&ss, (intptr_t) loc, false);
  85     msg.append("  %s", ss.as_string());
  86   }


 115     msg.append("  interior location: " PTR_FORMAT "\n", p2i(interior_loc));
 116     if (loc_in_heap) {
 117       print_obj(msg, loc);
 118     } else {
 119       print_non_obj(msg, interior_loc);
 120     }
 121   } else {
 122     msg.append("  no interior location recorded (probably a plain heap scan, or detached oop)\n");
 123   }
 124   msg.append("\n");
 125 
 126   msg.append("Object:\n");
 127   if (level >= _safe_oop) {
 128     print_obj(msg, obj);
 129   } else {
 130     print_obj_safe(msg, obj);
 131   }
 132   msg.append("\n");
 133 
 134   if (level >= _safe_oop) {
 135     oop fwd = (oop) ShenandoahBrooksPointer::get_raw_unchecked(obj);
 136     msg.append("Forwardee:\n");
 137     if (!oopDesc::unsafe_equals(obj, fwd)) {
 138       if (level >= _safe_oop_fwd) {
 139         print_obj(msg, fwd);
 140       } else {
 141         print_obj_safe(msg, fwd);
 142       }
 143     } else {
 144       msg.append("  (the object itself)");
 145     }
 146     msg.append("\n");
 147   }
 148 
 149   if (level >= _safe_oop_fwd) {
 150     oop fwd = (oop) ShenandoahBrooksPointer::get_raw_unchecked(obj);
 151     oop fwd2 = (oop) ShenandoahBrooksPointer::get_raw_unchecked(fwd);
 152     if (!oopDesc::unsafe_equals(fwd, fwd2)) {
 153       msg.append("Second forwardee:\n");
 154       print_obj_safe(msg, fwd2);
 155       msg.append("\n");
 156     }
 157   }
 158 
 159   report_vm_error(file, line, msg.buffer());
 160 }
 161 
 162 void ShenandoahAsserts::assert_in_heap(void* interior_loc, oop obj, const char *file, int line) {
 163   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 164 
 165   if (!heap->is_in(obj)) {
 166     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_heap failed",
 167                   "oop must point to a heap address",
 168                   file, line);
 169   }
 170 }
 171 


 176   // After this step, it is safe to call heap_region_containing().
 177   if (!heap->is_in(obj)) {
 178     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 179                   "oop must point to a heap address",
 180                   file, line);
 181   }
 182 
 183   Klass* obj_klass = obj->klass_or_null();
 184   if (obj_klass == NULL) {
 185     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 186                   "Object klass pointer should not be NULL",
 187                   file,line);
 188   }
 189 
 190   if (!Metaspace::contains(obj_klass)) {
 191     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 192                   "Object klass pointer must go to metaspace",
 193                   file,line);
 194   }
 195 
 196   oop fwd = oop(ShenandoahBrooksPointer::get_raw_unchecked(obj));
 197 
 198   if (!oopDesc::unsafe_equals(obj, fwd)) {

 199     // When Full GC moves the objects, we cannot trust fwdptrs. If we got here, it means something
 200     // tries fwdptr manipulation when Full GC is running. The only exception is using the fwdptr
 201     // that still points to the object itself.
 202     if (heap->is_full_gc_move_in_progress()) {
 203       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 204                     "Non-trivial forwarding pointer during Full GC moves, probable bug.",
 205                     file, line);
 206     }
 207 
 208     // Step 2. Check that forwardee is correct
 209     if (!heap->is_in(fwd)) {
 210       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 211                     "Forwardee must point to a heap address",
 212                     file, line);
 213     }
 214 
 215     if (obj_klass != fwd->klass()) {
 216       print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 217                     "Forwardee klass disagrees with object class",
 218                     file, line);
 219     }
 220 
 221     // Step 3. Check that forwardee points to correct region
 222     if (heap->heap_region_index_containing(fwd) == heap->heap_region_index_containing(obj)) {
 223       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 224                     "Non-trivial forwardee should in another region",
 225                     file, line);
 226     }
 227 
 228     // Step 4. Check for multiple forwardings
 229     oop fwd2 = oop(ShenandoahBrooksPointer::get_raw_unchecked(fwd));
 230     if (!oopDesc::unsafe_equals(fwd, fwd2)) {
 231       print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_correct failed",
 232                     "Multiple forwardings",
 233                     file, line);
 234     }
 235   }
 236 }
 237 
 238 void ShenandoahAsserts::assert_in_correct_region(void* interior_loc, oop obj, const char* file, int line) {
 239   assert_correct(interior_loc, obj, file, line);
 240 
 241   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 242   ShenandoahHeapRegion* r = heap->heap_region_containing(obj);
 243   if (!r->is_active()) {
 244     print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 245                   "Object must reside in active region",
 246                   file, line);
 247   }
 248 
 249   size_t alloc_size = obj->size() + ShenandoahBrooksPointer::word_size();
 250   if (alloc_size > ShenandoahHeapRegion::humongous_threshold_words()) {
 251     size_t idx = r->region_number();
 252     size_t num_regions = ShenandoahHeapRegion::required_regions(alloc_size * HeapWordSize);
 253     for (size_t i = idx; i < idx + num_regions; i++) {
 254       ShenandoahHeapRegion* chain_reg = heap->get_region(i);
 255       if (i == idx && !chain_reg->is_humongous_start()) {
 256         print_failure(_safe_unknown, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 257                       "Object must reside in humongous start",
 258                       file, line);
 259       }
 260       if (i != idx && !chain_reg->is_humongous_continuation()) {
 261         print_failure(_safe_oop, obj, interior_loc, NULL, "Shenandoah assert_in_correct_region failed",
 262                       "Humongous continuation should be of proper size",
 263                       file, line);
 264       }
 265     }
 266   }
 267 }
 268 
 269 void ShenandoahAsserts::assert_forwarded(void* interior_loc, oop obj, const char* file, int line) {
 270   assert_correct(interior_loc, obj, file, line);
 271   oop fwd = oop(ShenandoahBrooksPointer::get_raw_unchecked(obj));
 272 
 273   if (oopDesc::unsafe_equals(obj, fwd)) {
 274     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_forwarded failed",
 275                   "Object should be forwarded",
 276                   file, line);
 277   }
 278 }
 279 
 280 void ShenandoahAsserts::assert_not_forwarded(void* interior_loc, oop obj, const char* file, int line) {
 281   assert_correct(interior_loc, obj, file, line);
 282   oop fwd = oop(ShenandoahBrooksPointer::get_raw_unchecked(obj));
 283 
 284   if (!oopDesc::unsafe_equals(obj, fwd)) {
 285     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_forwarded failed",
 286                   "Object should not be forwarded",
 287                   file, line);
 288   }
 289 }
 290 
 291 void ShenandoahAsserts::assert_marked(void *interior_loc, oop obj, const char *file, int line) {
 292   assert_correct(interior_loc, obj, file, line);
 293 
 294   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 295   if (!heap->marking_context()->is_marked(obj)) {
 296     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_marked failed",
 297                   "Object should be marked",











 298                   file, line);
 299   }
 300 }
 301 
 302 void ShenandoahAsserts::assert_in_cset(void* interior_loc, oop obj, const char* file, int line) {
 303   assert_correct(interior_loc, obj, file, line);
 304 
 305   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 306   if (!heap->in_collection_set(obj)) {
 307     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_in_cset failed",
 308                   "Object should be in collection set",
 309                   file, line);
 310   }
 311 }
 312 
 313 void ShenandoahAsserts::assert_not_in_cset(void* interior_loc, oop obj, const char* file, int line) {
 314   assert_correct(interior_loc, obj, file, line);
 315 
 316   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 317   if (heap->in_collection_set(obj)) {
 318     print_failure(_safe_all, obj, interior_loc, NULL, "Shenandoah assert_not_in_cset failed",
 319                   "Object should not be in collection set",
 320                   file, line);
 321   }
 322 }
 323 
 324 void ShenandoahAsserts::assert_not_in_cset_loc(void* interior_loc, const char* file, int line) {
 325   ShenandoahHeap* heap = ShenandoahHeap::heap_no_check();
 326   if (heap->in_collection_set(interior_loc)) {
 327     print_failure(_safe_unknown, NULL, interior_loc, NULL, "Shenandoah assert_not_in_cset_loc failed",
 328                   "Interior location should not be in collection set",
 329                   file, line);
 330   }
 331 }
 332 
 333 void ShenandoahAsserts::print_rp_failure(const char *label, BoolObjectClosure* actual,
 334                                          const char *file, int line) {

 335   ShenandoahMessageBuffer msg("%s\n", label);
 336   msg.append(" Actual:                  " PTR_FORMAT "\n", p2i(actual));
 337   report_vm_error(file, line, msg.buffer());
 338 }
 339 
 340 void ShenandoahAsserts::assert_rp_isalive_not_installed(const char *file, int line) {
 341   ShenandoahHeap* heap = ShenandoahHeap::heap();
 342   ReferenceProcessor* rp = heap->ref_processor();
 343   if (rp->is_alive_non_header() != NULL) {
 344     print_rp_failure("Shenandoah assert_rp_isalive_not_installed failed", rp->is_alive_non_header(),
 345                      file, line);
 346   }
 347 }
 348 
 349 void ShenandoahAsserts::assert_rp_isalive_installed(const char *file, int line) {
 350   ShenandoahHeap* heap = ShenandoahHeap::heap();
 351   ReferenceProcessor* rp = heap->ref_processor();
 352   if (rp->is_alive_non_header() == NULL) {
 353     print_rp_failure("Shenandoah assert_rp_isalive_installed failed", rp->is_alive_non_header(),
 354                      file, line);
< prev index next >