< prev index next >

src/hotspot/share/gc/shared/space.inline.hpp

Print this page
rev 49290 : [mq]: JDK-8199735.01.patch
   1 /*
   2  * Copyright (c) 2000, 2016, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
  26 #define SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
  27 
  28 #include "gc/serial/markSweep.inline.hpp"
  29 #include "gc/shared/collectedHeap.hpp"
  30 #include "gc/shared/generation.hpp"
  31 #include "gc/shared/space.hpp"
  32 #include "gc/shared/spaceDecorator.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/oopsHierarchy.hpp"

  35 #include "runtime/prefetch.inline.hpp"
  36 #include "runtime/safepoint.hpp"
  37 
  38 inline HeapWord* Space::block_start(const void* p) {
  39   return block_start_const(p);
  40 }
  41 
  42 inline HeapWord* OffsetTableContigSpace::allocate(size_t size) {
  43   HeapWord* res = ContiguousSpace::allocate(size);
  44   if (res != NULL) {
  45     _offsets.alloc_block(res, size);
  46   }
  47   return res;
  48 }
  49 
  50 // Because of the requirement of keeping "_offsets" up to date with the
  51 // allocations, we sequentialize these with a lock.  Therefore, best if
  52 // this is used for larger LAB allocations only.
  53 inline HeapWord* OffsetTableContigSpace::par_allocate(size_t size) {
  54   MutexLocker x(&_par_alloc_lock);


  95       // by the MarkSweepAlwaysCompactCount parameter.
  96       if ((MarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0) {
  97         _allowed_deadspace_words = (space->capacity() * ratio / 100) / HeapWordSize;
  98       } else {
  99         _active = false;
 100       }
 101     }
 102   }
 103 
 104 
 105   bool insert_deadspace(HeapWord* dead_start, HeapWord* dead_end) {
 106     if (!_active) {
 107       return false;
 108     }
 109 
 110     size_t dead_length = pointer_delta(dead_end, dead_start);
 111     if (_allowed_deadspace_words >= dead_length) {
 112       _allowed_deadspace_words -= dead_length;
 113       CollectedHeap::fill_with_object(dead_start, dead_length);
 114       oop obj = oop(dead_start);
 115       obj->set_mark(obj->mark()->set_marked());
 116 
 117       assert(dead_length == (size_t)obj->size(), "bad filler object size");
 118       log_develop_trace(gc, compaction)("Inserting object to dead space: " PTR_FORMAT ", " PTR_FORMAT ", " SIZE_FORMAT "b",
 119           p2i(dead_start), p2i(dead_end), dead_length * HeapWordSize);
 120 
 121       return true;
 122     } else {
 123       _active = false;
 124       return false;
 125     }
 126   }
 127 
 128 };
 129 
 130 template <class SpaceType>
 131 inline void CompactibleSpace::scan_and_forward(SpaceType* space, CompactPoint* cp) {
 132   // Compute the new addresses for the live objects and store it in the mark
 133   // Used by universe::mark_sweep_phase2()
 134 
 135   // We're sure to be here before any objects are compacted into this


 142     assert(cp->gen->first_compaction_space() == space, "just checking");
 143     cp->space = cp->gen->first_compaction_space();
 144     cp->threshold = cp->space->initialize_threshold();
 145     cp->space->set_compaction_top(cp->space->bottom());
 146   }
 147 
 148   HeapWord* compact_top = cp->space->compaction_top(); // This is where we are currently compacting to.
 149 
 150   DeadSpacer dead_spacer(space);
 151 
 152   HeapWord*  end_of_live = space->bottom();  // One byte beyond the last byte of the last live object.
 153   HeapWord*  first_dead = NULL; // The first dead object.
 154 
 155   const intx interval = PrefetchScanIntervalInBytes;
 156 
 157   HeapWord* cur_obj = space->bottom();
 158   HeapWord* scan_limit = space->scan_limit();
 159 
 160   while (cur_obj < scan_limit) {
 161     assert(!space->scanned_block_is_obj(cur_obj) ||
 162            oop(cur_obj)->mark()->is_marked() || oop(cur_obj)->mark()->is_unlocked() ||
 163            oop(cur_obj)->mark()->has_bias_pattern(),
 164            "these are the only valid states during a mark sweep");
 165     if (space->scanned_block_is_obj(cur_obj) && oop(cur_obj)->is_gc_marked()) {
 166       // prefetch beyond cur_obj
 167       Prefetch::write(cur_obj, interval);
 168       size_t size = space->scanned_block_size(cur_obj);
 169       compact_top = cp->space->forward(oop(cur_obj), size, cp, compact_top);
 170       cur_obj += size;
 171       end_of_live = cur_obj;
 172     } else {
 173       // run over all the contiguous dead objects
 174       HeapWord* end = cur_obj;
 175       do {
 176         // prefetch beyond end
 177         Prefetch::write(end, interval);
 178         end += space->scanned_block_size(end);
 179       } while (end < scan_limit && (!space->scanned_block_is_obj(end) || !oop(end)->is_gc_marked()));
 180 
 181       // see if we might want to pretend this object is alive so that
 182       // we don't have to compact quite as often.
 183       if (cur_obj == compact_top && dead_spacer.insert_deadspace(cur_obj, end)) {


 318   while (cur_obj < end_of_live) {
 319     if (!oop(cur_obj)->is_gc_marked()) {
 320       debug_only(prev_obj = cur_obj);
 321       // The first word of the dead object contains a pointer to the next live object or end of space.
 322       cur_obj = *(HeapWord**)cur_obj;
 323       assert(cur_obj > prev_obj, "we should be moving forward through memory");
 324     } else {
 325       // prefetch beyond q
 326       Prefetch::read(cur_obj, scan_interval);
 327 
 328       // size and destination
 329       size_t size = space->obj_size(cur_obj);
 330       HeapWord* compaction_top = (HeapWord*)oop(cur_obj)->forwardee();
 331 
 332       // prefetch beyond compaction_top
 333       Prefetch::write(compaction_top, copy_interval);
 334 
 335       // copy object and reinit its mark
 336       assert(cur_obj != compaction_top, "everything in this pass should be moving");
 337       Copy::aligned_conjoint_words(cur_obj, compaction_top, size);
 338       oop(compaction_top)->init_mark();
 339       assert(oop(compaction_top)->klass() != NULL, "should have a class");
 340 
 341       debug_only(prev_obj = cur_obj);
 342       cur_obj += size;
 343     }
 344   }
 345 
 346   clear_empty_region(space);
 347 }
 348 
 349 size_t ContiguousSpace::scanned_block_size(const HeapWord* addr) const {
 350   return oop(addr)->size();
 351 }
 352 
 353 #endif // SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
   1 /*
   2  * Copyright (c) 2000, 2018, 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  *
  23  */
  24 
  25 #ifndef SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
  26 #define SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
  27 
  28 #include "gc/serial/markSweep.inline.hpp"
  29 #include "gc/shared/collectedHeap.hpp"
  30 #include "gc/shared/generation.hpp"
  31 #include "gc/shared/space.hpp"
  32 #include "gc/shared/spaceDecorator.hpp"
  33 #include "memory/universe.hpp"
  34 #include "oops/oopsHierarchy.hpp"
  35 #include "oops/oop.inline.hpp"
  36 #include "runtime/prefetch.inline.hpp"
  37 #include "runtime/safepoint.hpp"
  38 
  39 inline HeapWord* Space::block_start(const void* p) {
  40   return block_start_const(p);
  41 }
  42 
  43 inline HeapWord* OffsetTableContigSpace::allocate(size_t size) {
  44   HeapWord* res = ContiguousSpace::allocate(size);
  45   if (res != NULL) {
  46     _offsets.alloc_block(res, size);
  47   }
  48   return res;
  49 }
  50 
  51 // Because of the requirement of keeping "_offsets" up to date with the
  52 // allocations, we sequentialize these with a lock.  Therefore, best if
  53 // this is used for larger LAB allocations only.
  54 inline HeapWord* OffsetTableContigSpace::par_allocate(size_t size) {
  55   MutexLocker x(&_par_alloc_lock);


  96       // by the MarkSweepAlwaysCompactCount parameter.
  97       if ((MarkSweep::total_invocations() % MarkSweepAlwaysCompactCount) != 0) {
  98         _allowed_deadspace_words = (space->capacity() * ratio / 100) / HeapWordSize;
  99       } else {
 100         _active = false;
 101       }
 102     }
 103   }
 104 
 105 
 106   bool insert_deadspace(HeapWord* dead_start, HeapWord* dead_end) {
 107     if (!_active) {
 108       return false;
 109     }
 110 
 111     size_t dead_length = pointer_delta(dead_end, dead_start);
 112     if (_allowed_deadspace_words >= dead_length) {
 113       _allowed_deadspace_words -= dead_length;
 114       CollectedHeap::fill_with_object(dead_start, dead_length);
 115       oop obj = oop(dead_start);
 116       obj->set_mark_raw(obj->mark_raw()->set_marked());
 117 
 118       assert(dead_length == (size_t)obj->size(), "bad filler object size");
 119       log_develop_trace(gc, compaction)("Inserting object to dead space: " PTR_FORMAT ", " PTR_FORMAT ", " SIZE_FORMAT "b",
 120           p2i(dead_start), p2i(dead_end), dead_length * HeapWordSize);
 121 
 122       return true;
 123     } else {
 124       _active = false;
 125       return false;
 126     }
 127   }
 128 
 129 };
 130 
 131 template <class SpaceType>
 132 inline void CompactibleSpace::scan_and_forward(SpaceType* space, CompactPoint* cp) {
 133   // Compute the new addresses for the live objects and store it in the mark
 134   // Used by universe::mark_sweep_phase2()
 135 
 136   // We're sure to be here before any objects are compacted into this


 143     assert(cp->gen->first_compaction_space() == space, "just checking");
 144     cp->space = cp->gen->first_compaction_space();
 145     cp->threshold = cp->space->initialize_threshold();
 146     cp->space->set_compaction_top(cp->space->bottom());
 147   }
 148 
 149   HeapWord* compact_top = cp->space->compaction_top(); // This is where we are currently compacting to.
 150 
 151   DeadSpacer dead_spacer(space);
 152 
 153   HeapWord*  end_of_live = space->bottom();  // One byte beyond the last byte of the last live object.
 154   HeapWord*  first_dead = NULL; // The first dead object.
 155 
 156   const intx interval = PrefetchScanIntervalInBytes;
 157 
 158   HeapWord* cur_obj = space->bottom();
 159   HeapWord* scan_limit = space->scan_limit();
 160 
 161   while (cur_obj < scan_limit) {
 162     assert(!space->scanned_block_is_obj(cur_obj) ||
 163            oop(cur_obj)->mark_raw()->is_marked() || oop(cur_obj)->mark_raw()->is_unlocked() ||
 164            oop(cur_obj)->mark_raw()->has_bias_pattern(),
 165            "these are the only valid states during a mark sweep");
 166     if (space->scanned_block_is_obj(cur_obj) && oop(cur_obj)->is_gc_marked()) {
 167       // prefetch beyond cur_obj
 168       Prefetch::write(cur_obj, interval);
 169       size_t size = space->scanned_block_size(cur_obj);
 170       compact_top = cp->space->forward(oop(cur_obj), size, cp, compact_top);
 171       cur_obj += size;
 172       end_of_live = cur_obj;
 173     } else {
 174       // run over all the contiguous dead objects
 175       HeapWord* end = cur_obj;
 176       do {
 177         // prefetch beyond end
 178         Prefetch::write(end, interval);
 179         end += space->scanned_block_size(end);
 180       } while (end < scan_limit && (!space->scanned_block_is_obj(end) || !oop(end)->is_gc_marked()));
 181 
 182       // see if we might want to pretend this object is alive so that
 183       // we don't have to compact quite as often.
 184       if (cur_obj == compact_top && dead_spacer.insert_deadspace(cur_obj, end)) {


 319   while (cur_obj < end_of_live) {
 320     if (!oop(cur_obj)->is_gc_marked()) {
 321       debug_only(prev_obj = cur_obj);
 322       // The first word of the dead object contains a pointer to the next live object or end of space.
 323       cur_obj = *(HeapWord**)cur_obj;
 324       assert(cur_obj > prev_obj, "we should be moving forward through memory");
 325     } else {
 326       // prefetch beyond q
 327       Prefetch::read(cur_obj, scan_interval);
 328 
 329       // size and destination
 330       size_t size = space->obj_size(cur_obj);
 331       HeapWord* compaction_top = (HeapWord*)oop(cur_obj)->forwardee();
 332 
 333       // prefetch beyond compaction_top
 334       Prefetch::write(compaction_top, copy_interval);
 335 
 336       // copy object and reinit its mark
 337       assert(cur_obj != compaction_top, "everything in this pass should be moving");
 338       Copy::aligned_conjoint_words(cur_obj, compaction_top, size);
 339       oop(compaction_top)->init_mark_raw();
 340       assert(oop(compaction_top)->klass() != NULL, "should have a class");
 341 
 342       debug_only(prev_obj = cur_obj);
 343       cur_obj += size;
 344     }
 345   }
 346 
 347   clear_empty_region(space);
 348 }
 349 
 350 size_t ContiguousSpace::scanned_block_size(const HeapWord* addr) const {
 351   return oop(addr)->size();
 352 }
 353 
 354 #endif // SHARE_VM_GC_SHARED_SPACE_INLINE_HPP
< prev index next >