< prev index next >

src/hotspot/share/gc/shared/space.cpp

Print this page




   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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"
  28 #include "gc/serial/defNewGeneration.hpp"
  29 #include "gc/shared/blockOffsetTable.inline.hpp"
  30 #include "gc/shared/collectedHeap.inline.hpp"
  31 #include "gc/shared/genCollectedHeap.hpp"
  32 #include "gc/shared/genOopClosures.inline.hpp"
  33 #include "gc/shared/space.hpp"
  34 #include "gc/shared/space.inline.hpp"
  35 #include "gc/shared/spaceDecorator.hpp"
  36 #include "memory/universe.hpp"
  37 #include "oops/oop.inline.hpp"
  38 #include "runtime/atomic.hpp"
  39 #include "runtime/java.hpp"
  40 #include "runtime/orderAccess.inline.hpp"
  41 #include "runtime/prefetch.inline.hpp"
  42 #include "runtime/safepoint.hpp"
  43 #include "utilities/align.hpp"
  44 #include "utilities/copy.hpp"
  45 #include "utilities/globalDefinitions.hpp"
  46 #include "utilities/macros.hpp"



  47 
  48 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
  49                                                 HeapWord* top_obj) {
  50   if (top_obj != NULL) {
  51     if (_sp->block_is_obj(top_obj)) {
  52       if (_precision == CardTable::ObjHeadPreciseArray) {
  53         if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
  54           // An arrayOop is starting on the dirty card - since we do exact
  55           // store checks for objArrays we are done.
  56         } else {
  57           // Otherwise, it is possible that the object starting on the dirty
  58           // card spans the entire card, and that the store happened on a
  59           // later card.  Figure out where the object ends.
  60           // Use the block_size() method of the space over which
  61           // the iteration is being done.  That space (e.g. CMS) may have
  62           // specific requirements on object sizes which will
  63           // be reflected in the block_size() method.
  64           top = top_obj + oop(top_obj)->size();
  65         }
  66       }


 395     q->forward_to(oop(compact_top));
 396     assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
 397   } else {
 398     // if the object isn't moving we can just set the mark to the default
 399     // mark and handle it specially later on.
 400     q->init_mark_raw();
 401     assert(q->forwardee() == NULL, "should be forwarded to NULL");
 402   }
 403 
 404   compact_top += size;
 405 
 406   // we need to update the offset table so that the beginnings of objects can be
 407   // found during scavenge.  Note that we are updating the offset table based on
 408   // where the object will be once the compaction phase finishes.
 409   if (compact_top > cp->threshold)
 410     cp->threshold =
 411       cp->space->cross_threshold(compact_top - size, compact_top);
 412   return compact_top;
 413 }
 414 


 415 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
 416   scan_and_forward(this, cp);
 417 }
 418 
 419 void CompactibleSpace::adjust_pointers() {
 420   // Check first is there is any work to do.
 421   if (used() == 0) {
 422     return;   // Nothing to do.
 423   }
 424 
 425   scan_and_adjust_pointers(this);
 426 }
 427 
 428 void CompactibleSpace::compact() {
 429   scan_and_compact(this);
 430 }
 431 


 432 void Space::print_short() const { print_short_on(tty); }
 433 
 434 void Space::print_short_on(outputStream* st) const {
 435   st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
 436               (int) ((double) used() * 100 / capacity()));
 437 }
 438 
 439 void Space::print() const { print_on(tty); }
 440 
 441 void Space::print_on(outputStream* st) const {
 442   print_short_on(st);
 443   st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 444                 p2i(bottom()), p2i(end()));
 445 }
 446 
 447 void ContiguousSpace::print_on(outputStream* st) const {
 448   print_short_on(st);
 449   st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 450                 p2i(bottom()), p2i(top()), p2i(end()));
 451 }


 467     p += oop(p)->size();
 468   }
 469   guarantee(p == top(), "end of last object must match end of space");
 470   if (top() != end()) {
 471     guarantee(top() == block_start_const(end()-1) &&
 472               top() == block_start_const(top()),
 473               "top should be start of unallocated block, if it exists");
 474   }
 475 }
 476 
 477 void Space::oop_iterate(ExtendedOopClosure* blk) {
 478   ObjectToOopClosure blk2(blk);
 479   object_iterate(&blk2);
 480 }
 481 
 482 bool Space::obj_is_alive(const HeapWord* p) const {
 483   assert (block_is_obj(p), "The address should point to an object");
 484   return true;
 485 }
 486 
 487 #if INCLUDE_ALL_GCS
 488 #define ContigSpace_PAR_OOP_ITERATE_DEFN(OopClosureType, nv_suffix)         \
 489                                                                             \
 490   void ContiguousSpace::par_oop_iterate(MemRegion mr, OopClosureType* blk) {\
 491     HeapWord* obj_addr = mr.start();                                        \
 492     HeapWord* t = mr.end();                                                 \
 493     while (obj_addr < t) {                                                  \
 494       assert(oopDesc::is_oop(oop(obj_addr)), "Should be an oop");           \
 495       obj_addr += oop(obj_addr)->oop_iterate_size(blk);                     \
 496     }                                                                       \
 497   }
 498 
 499   ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DEFN)
 500 
 501 #undef ContigSpace_PAR_OOP_ITERATE_DEFN
 502 #endif // INCLUDE_ALL_GCS
 503 
 504 void ContiguousSpace::oop_iterate(ExtendedOopClosure* blk) {
 505   if (is_empty()) return;
 506   HeapWord* obj_addr = bottom();
 507   HeapWord* t = top();
 508   // Could call objects iterate, but this is easier.
 509   while (obj_addr < t) {
 510     obj_addr += oop(obj_addr)->oop_iterate_size(blk);
 511   }
 512 }
 513 
 514 void ContiguousSpace::object_iterate(ObjectClosure* blk) {
 515   if (is_empty()) return;
 516   object_iterate_from(bottom(), blk);
 517 }
 518 
 519 // For a ContiguousSpace object_iterate() and safe_object_iterate()
 520 // are the same.
 521 void ContiguousSpace::safe_object_iterate(ObjectClosure* blk) {
 522   object_iterate(blk);




   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  *
  23  */
  24 
  25 #include "precompiled.hpp"
  26 #include "classfile/systemDictionary.hpp"
  27 #include "classfile/vmSymbols.hpp"

  28 #include "gc/shared/blockOffsetTable.inline.hpp"
  29 #include "gc/shared/collectedHeap.inline.hpp"
  30 #include "gc/shared/genCollectedHeap.hpp"
  31 #include "gc/shared/genOopClosures.inline.hpp"
  32 #include "gc/shared/space.hpp"
  33 #include "gc/shared/space.inline.hpp"
  34 #include "gc/shared/spaceDecorator.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/oop.inline.hpp"
  37 #include "runtime/atomic.hpp"
  38 #include "runtime/java.hpp"
  39 #include "runtime/orderAccess.inline.hpp"
  40 #include "runtime/prefetch.inline.hpp"
  41 #include "runtime/safepoint.hpp"
  42 #include "utilities/align.hpp"
  43 #include "utilities/copy.hpp"
  44 #include "utilities/globalDefinitions.hpp"
  45 #include "utilities/macros.hpp"
  46 #if INCLUDE_SERIALGC
  47 #include "gc/serial/defNewGeneration.hpp"
  48 #endif
  49 
  50 HeapWord* DirtyCardToOopClosure::get_actual_top(HeapWord* top,
  51                                                 HeapWord* top_obj) {
  52   if (top_obj != NULL) {
  53     if (_sp->block_is_obj(top_obj)) {
  54       if (_precision == CardTable::ObjHeadPreciseArray) {
  55         if (oop(top_obj)->is_objArray() || oop(top_obj)->is_typeArray()) {
  56           // An arrayOop is starting on the dirty card - since we do exact
  57           // store checks for objArrays we are done.
  58         } else {
  59           // Otherwise, it is possible that the object starting on the dirty
  60           // card spans the entire card, and that the store happened on a
  61           // later card.  Figure out where the object ends.
  62           // Use the block_size() method of the space over which
  63           // the iteration is being done.  That space (e.g. CMS) may have
  64           // specific requirements on object sizes which will
  65           // be reflected in the block_size() method.
  66           top = top_obj + oop(top_obj)->size();
  67         }
  68       }


 397     q->forward_to(oop(compact_top));
 398     assert(q->is_gc_marked(), "encoding the pointer should preserve the mark");
 399   } else {
 400     // if the object isn't moving we can just set the mark to the default
 401     // mark and handle it specially later on.
 402     q->init_mark_raw();
 403     assert(q->forwardee() == NULL, "should be forwarded to NULL");
 404   }
 405 
 406   compact_top += size;
 407 
 408   // we need to update the offset table so that the beginnings of objects can be
 409   // found during scavenge.  Note that we are updating the offset table based on
 410   // where the object will be once the compaction phase finishes.
 411   if (compact_top > cp->threshold)
 412     cp->threshold =
 413       cp->space->cross_threshold(compact_top - size, compact_top);
 414   return compact_top;
 415 }
 416 
 417 #if INCLUDE_SERIALGC
 418 
 419 void ContiguousSpace::prepare_for_compaction(CompactPoint* cp) {
 420   scan_and_forward(this, cp);
 421 }
 422 
 423 void CompactibleSpace::adjust_pointers() {
 424   // Check first is there is any work to do.
 425   if (used() == 0) {
 426     return;   // Nothing to do.
 427   }
 428 
 429   scan_and_adjust_pointers(this);
 430 }
 431 
 432 void CompactibleSpace::compact() {
 433   scan_and_compact(this);
 434 }
 435 
 436 #endif // INCLUDE_SERIALGC
 437 
 438 void Space::print_short() const { print_short_on(tty); }
 439 
 440 void Space::print_short_on(outputStream* st) const {
 441   st->print(" space " SIZE_FORMAT "K, %3d%% used", capacity() / K,
 442               (int) ((double) used() * 100 / capacity()));
 443 }
 444 
 445 void Space::print() const { print_on(tty); }
 446 
 447 void Space::print_on(outputStream* st) const {
 448   print_short_on(st);
 449   st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 450                 p2i(bottom()), p2i(end()));
 451 }
 452 
 453 void ContiguousSpace::print_on(outputStream* st) const {
 454   print_short_on(st);
 455   st->print_cr(" [" INTPTR_FORMAT ", " INTPTR_FORMAT ", " INTPTR_FORMAT ")",
 456                 p2i(bottom()), p2i(top()), p2i(end()));
 457 }


 473     p += oop(p)->size();
 474   }
 475   guarantee(p == top(), "end of last object must match end of space");
 476   if (top() != end()) {
 477     guarantee(top() == block_start_const(end()-1) &&
 478               top() == block_start_const(top()),
 479               "top should be start of unallocated block, if it exists");
 480   }
 481 }
 482 
 483 void Space::oop_iterate(ExtendedOopClosure* blk) {
 484   ObjectToOopClosure blk2(blk);
 485   object_iterate(&blk2);
 486 }
 487 
 488 bool Space::obj_is_alive(const HeapWord* p) const {
 489   assert (block_is_obj(p), "The address should point to an object");
 490   return true;
 491 }
 492 
 493 #if INCLUDE_CMSGC
 494 #define ContigSpace_PAR_OOP_ITERATE_DEFN(OopClosureType, nv_suffix)         \
 495                                                                             \
 496   void ContiguousSpace::par_oop_iterate(MemRegion mr, OopClosureType* blk) {\
 497     HeapWord* obj_addr = mr.start();                                        \
 498     HeapWord* t = mr.end();                                                 \
 499     while (obj_addr < t) {                                                  \
 500       assert(oopDesc::is_oop(oop(obj_addr)), "Should be an oop");           \
 501       obj_addr += oop(obj_addr)->oop_iterate_size(blk);                     \
 502     }                                                                       \
 503   }
 504 
 505   ALL_PAR_OOP_ITERATE_CLOSURES(ContigSpace_PAR_OOP_ITERATE_DEFN)
 506 
 507 #undef ContigSpace_PAR_OOP_ITERATE_DEFN
 508 #endif // INCLUDE_CMSGC
 509 
 510 void ContiguousSpace::oop_iterate(ExtendedOopClosure* blk) {
 511   if (is_empty()) return;
 512   HeapWord* obj_addr = bottom();
 513   HeapWord* t = top();
 514   // Could call objects iterate, but this is easier.
 515   while (obj_addr < t) {
 516     obj_addr += oop(obj_addr)->oop_iterate_size(blk);
 517   }
 518 }
 519 
 520 void ContiguousSpace::object_iterate(ObjectClosure* blk) {
 521   if (is_empty()) return;
 522   object_iterate_from(bottom(), blk);
 523 }
 524 
 525 // For a ContiguousSpace object_iterate() and safe_object_iterate()
 526 // are the same.
 527 void ContiguousSpace::safe_object_iterate(ObjectClosure* blk) {
 528   object_iterate(blk);


< prev index next >