< prev index next >

src/share/vm/gc_implementation/g1/heapRegion.cpp

Print this page
rev 7698 : [mq]: fix-iterate-oop-kim
   1 /*
   2  * Copyright (c) 2001, 2014, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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  *


 417   HeapWord* cur = block_start(start);
 418   assert(cur <= start, "Postcondition");
 419 
 420   oop obj;
 421 
 422   HeapWord* next = cur;
 423   while (next <= start) {
 424     cur = next;
 425     obj = oop(cur);
 426     if (obj->klass_or_null() == NULL) {
 427       // Ran into an unparseable point.
 428       return cur;
 429     }
 430     // Otherwise...
 431     next = cur + block_size(cur);
 432   }
 433 
 434   // If we finish the above loop...We have a parseable object that
 435   // begins on or before the start of the memory region, and ends
 436   // inside or spans the entire region.
 437 
 438   assert(cur <= start, "Loop postcondition");

 439 
 440   do {
 441     assert(obj->klass_or_null() != NULL, "Loop invariant");
 442     assert((cur + block_size(cur)) > (HeapWord*)obj, "Loop invariant");
 443     assert(obj == oop(cur), "Loop invariant");
 444     if (obj->klass_or_null() == NULL) {
 445       // Ran into an unparseable point.
 446       return cur;
 447     }
 448 
 449     // Advance the current pointer. "obj" still points to the object to iterate.
 450     cur = cur + block_size(cur);
 451 
 452     if (!g1h->is_obj_dead(obj)) {
 453       // Non-object arrays are sometimes marked imprecise at the object start. We
 454       // always need to iterate over them in full.
 455       // We only iterate over object arrays in full if they are completely contained
 456       // in the memory region.
 457       if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur < end)) {
 458         obj->oop_iterate(cl);
 459       } else {
 460         obj->oop_iterate(cl, mr);
 461       }
 462     }
 463     obj = oop(cur);
 464   } while (cur < end);
 465 
 466   return NULL;
 467 }
 468 
 469 // Code roots support
 470 
 471 void HeapRegion::add_strong_code_root(nmethod* nm) {
 472   HeapRegionRemSet* hrrs = rem_set();
 473   hrrs->add_strong_code_root(nm);
 474 }
 475 
 476 void HeapRegion::add_strong_code_root_locked(nmethod* nm) {
 477   assert_locked_or_safepoint(CodeCache_lock);
 478   HeapRegionRemSet* hrrs = rem_set();
 479   hrrs->add_strong_code_root_locked(nm);
 480 }
 481 
 482 void HeapRegion::remove_strong_code_root(nmethod* nm) {
 483   HeapRegionRemSet* hrrs = rem_set();


 658   }
 659 
 660   bool failures() { return _failures; }
 661   int n_failures() { return _n_failures; }
 662 
 663   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 664   virtual void do_oop(      oop* p) { do_oop_work(p); }
 665 
 666   void print_object(outputStream* out, oop obj) {
 667 #ifdef PRODUCT
 668     Klass* k = obj->klass();
 669     const char* class_name = InstanceKlass::cast(k)->external_name();
 670     out->print_cr("class name %s", class_name);
 671 #else // PRODUCT
 672     obj->print_on(out);
 673 #endif // PRODUCT
 674   }
 675 
 676   template <class T>
 677   void do_oop_work(T* p) {
 678 //      gclog_or_tty->print_cr("Verifying address " PTR_FORMAT, p2i(p));
 679     assert(_containing_obj != NULL, "Precondition");
 680     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 681            "Precondition");
 682     T heap_oop = oopDesc::load_heap_oop(p);
 683     if (!oopDesc::is_null(heap_oop)) {
 684       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 685       bool failed = false;
 686       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 687         MutexLockerEx x(ParGCRareEvent_lock,
 688                         Mutex::_no_safepoint_check_flag);
 689 
 690         if (!_failures) {
 691           gclog_or_tty->cr();
 692           gclog_or_tty->print_cr("----------");
 693         }
 694         if (!_g1h->is_in_closed_subset(obj)) {
 695           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 696           gclog_or_tty->print_cr("Field "PTR_FORMAT
 697                                  " of live obj "PTR_FORMAT" in region "
 698                                  "["PTR_FORMAT", "PTR_FORMAT")",


   1 /*
   2  * Copyright (c) 2001, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  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  *


 417   HeapWord* cur = block_start(start);
 418   assert(cur <= start, "Postcondition");
 419 
 420   oop obj;
 421 
 422   HeapWord* next = cur;
 423   while (next <= start) {
 424     cur = next;
 425     obj = oop(cur);
 426     if (obj->klass_or_null() == NULL) {
 427       // Ran into an unparseable point.
 428       return cur;
 429     }
 430     // Otherwise...
 431     next = cur + block_size(cur);
 432   }
 433 
 434   // If we finish the above loop...We have a parseable object that
 435   // begins on or before the start of the memory region, and ends
 436   // inside or spans the entire region.

 437   assert(cur <= start, "Loop postcondition");
 438   assert(obj->klass_or_null() != NULL, "Loop invariant");
 439 
 440   do {
 441     obj = oop(cur);
 442     assert((cur + block_size(cur)) > (HeapWord*)obj, "Loop invariant");

 443     if (obj->klass_or_null() == NULL) {
 444       // Ran into an unparseable point.
 445       return cur;
 446     }
 447 
 448     // Advance the current pointer. "obj" still points to the object to iterate.
 449     cur = cur + block_size(cur);
 450 
 451     if (!g1h->is_obj_dead(obj)) {
 452       // Non-objArrays are sometimes marked imprecise at the object start. We
 453       // always need to iterate over them in full.
 454       // We only iterate over object arrays in full if they are completely contained
 455       // in the memory region.
 456       if (!obj->is_objArray() || (((HeapWord*)obj) >= start && cur < end)) {
 457         obj->oop_iterate(cl);
 458       } else {
 459         obj->oop_iterate(cl, mr);
 460       }
 461     }

 462   } while (cur < end);
 463 
 464   return NULL;
 465 }
 466 
 467 // Code roots support
 468 
 469 void HeapRegion::add_strong_code_root(nmethod* nm) {
 470   HeapRegionRemSet* hrrs = rem_set();
 471   hrrs->add_strong_code_root(nm);
 472 }
 473 
 474 void HeapRegion::add_strong_code_root_locked(nmethod* nm) {
 475   assert_locked_or_safepoint(CodeCache_lock);
 476   HeapRegionRemSet* hrrs = rem_set();
 477   hrrs->add_strong_code_root_locked(nm);
 478 }
 479 
 480 void HeapRegion::remove_strong_code_root(nmethod* nm) {
 481   HeapRegionRemSet* hrrs = rem_set();


 656   }
 657 
 658   bool failures() { return _failures; }
 659   int n_failures() { return _n_failures; }
 660 
 661   virtual void do_oop(narrowOop* p) { do_oop_work(p); }
 662   virtual void do_oop(      oop* p) { do_oop_work(p); }
 663 
 664   void print_object(outputStream* out, oop obj) {
 665 #ifdef PRODUCT
 666     Klass* k = obj->klass();
 667     const char* class_name = InstanceKlass::cast(k)->external_name();
 668     out->print_cr("class name %s", class_name);
 669 #else // PRODUCT
 670     obj->print_on(out);
 671 #endif // PRODUCT
 672   }
 673 
 674   template <class T>
 675   void do_oop_work(T* p) {

 676     assert(_containing_obj != NULL, "Precondition");
 677     assert(!_g1h->is_obj_dead_cond(_containing_obj, _vo),
 678            "Precondition");
 679     T heap_oop = oopDesc::load_heap_oop(p);
 680     if (!oopDesc::is_null(heap_oop)) {
 681       oop obj = oopDesc::decode_heap_oop_not_null(heap_oop);
 682       bool failed = false;
 683       if (!_g1h->is_in_closed_subset(obj) || _g1h->is_obj_dead_cond(obj, _vo)) {
 684         MutexLockerEx x(ParGCRareEvent_lock,
 685                         Mutex::_no_safepoint_check_flag);
 686 
 687         if (!_failures) {
 688           gclog_or_tty->cr();
 689           gclog_or_tty->print_cr("----------");
 690         }
 691         if (!_g1h->is_in_closed_subset(obj)) {
 692           HeapRegion* from = _g1h->heap_region_containing((HeapWord*)p);
 693           gclog_or_tty->print_cr("Field "PTR_FORMAT
 694                                  " of live obj "PTR_FORMAT" in region "
 695                                  "["PTR_FORMAT", "PTR_FORMAT")",


< prev index next >