< prev index next >

src/hotspot/share/gc/g1/g1FullGCCompactionPoint.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 "gc/g1/g1FullGCCompactionPoint.hpp"
 27 #include "gc/g1/heapRegion.hpp"

 28 #include "oops/oop.inline.hpp"
 29 #include "utilities/debug.hpp"
 30 
 31 G1FullGCCompactionPoint::G1FullGCCompactionPoint() :
 32     _current_region(NULL),
 33     _compaction_top(NULL) {
 34   _compaction_regions = new (ResourceObj::C_HEAP, mtGC) GrowableArray<HeapRegion*>(32, mtGC);
 35   _compaction_region_iterator = _compaction_regions->begin();
 36 }
 37 
 38 G1FullGCCompactionPoint::~G1FullGCCompactionPoint() {
 39   delete _compaction_regions;
 40 }
 41 
 42 void G1FullGCCompactionPoint::update() {
 43   if (is_initialized()) {
 44     _current_region->set_compaction_top(_compaction_top);
 45   }
 46 }
 47 

 72   return next;
 73 }
 74 
 75 GrowableArray<HeapRegion*>* G1FullGCCompactionPoint::regions() {
 76   return _compaction_regions;
 77 }
 78 
 79 bool G1FullGCCompactionPoint::object_will_fit(size_t size) {
 80   size_t space_left = pointer_delta(_current_region->end(), _compaction_top);
 81   return size <= space_left;
 82 }
 83 
 84 void G1FullGCCompactionPoint::switch_region() {
 85   // Save compaction top in the region.
 86   _current_region->set_compaction_top(_compaction_top);
 87   // Get the next region and re-initialize the values.
 88   _current_region = next_region();
 89   initialize_values();
 90 }
 91 
 92 void G1FullGCCompactionPoint::forward(oop object, size_t size) {
 93   assert(_current_region != NULL, "Must have been initialized");
 94 
 95   // Ensure the object fit in the current region.
 96   while (!object_will_fit(size)) {
 97     switch_region();
 98   }
 99 
100   // Store a forwarding pointer if the object should be moved.
101   if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
102     object->forward_to(cast_to_oop(_compaction_top));
103     assert(object->is_forwarded(), "must be forwarded");
104   } else {
105     assert(!object->is_forwarded(), "must not be forwarded");
106   }
107 
108   // Update compaction values.
109   _compaction_top += size;
110   _current_region->update_bot_for_block(_compaction_top - size, _compaction_top);
111 }
112 
113 void G1FullGCCompactionPoint::add(HeapRegion* hr) {
114   _compaction_regions->append(hr);
115 }
116 
117 HeapRegion* G1FullGCCompactionPoint::remove_last() {
118   return _compaction_regions->pop();
119 }

  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 "gc/g1/g1FullGCCompactionPoint.hpp"
 27 #include "gc/g1/heapRegion.hpp"
 28 #include "gc/shared/slidingForwarding.inline.hpp"
 29 #include "oops/oop.inline.hpp"
 30 #include "utilities/debug.hpp"
 31 
 32 G1FullGCCompactionPoint::G1FullGCCompactionPoint() :
 33     _current_region(NULL),
 34     _compaction_top(NULL) {
 35   _compaction_regions = new (ResourceObj::C_HEAP, mtGC) GrowableArray<HeapRegion*>(32, mtGC);
 36   _compaction_region_iterator = _compaction_regions->begin();
 37 }
 38 
 39 G1FullGCCompactionPoint::~G1FullGCCompactionPoint() {
 40   delete _compaction_regions;
 41 }
 42 
 43 void G1FullGCCompactionPoint::update() {
 44   if (is_initialized()) {
 45     _current_region->set_compaction_top(_compaction_top);
 46   }
 47 }
 48 

 73   return next;
 74 }
 75 
 76 GrowableArray<HeapRegion*>* G1FullGCCompactionPoint::regions() {
 77   return _compaction_regions;
 78 }
 79 
 80 bool G1FullGCCompactionPoint::object_will_fit(size_t size) {
 81   size_t space_left = pointer_delta(_current_region->end(), _compaction_top);
 82   return size <= space_left;
 83 }
 84 
 85 void G1FullGCCompactionPoint::switch_region() {
 86   // Save compaction top in the region.
 87   _current_region->set_compaction_top(_compaction_top);
 88   // Get the next region and re-initialize the values.
 89   _current_region = next_region();
 90   initialize_values();
 91 }
 92 
 93 void G1FullGCCompactionPoint::forward(SlidingForwarding* const forwarding, oop object, size_t size) {
 94   assert(_current_region != NULL, "Must have been initialized");
 95 
 96   // Ensure the object fit in the current region.
 97   while (!object_will_fit(size)) {
 98     switch_region();
 99   }
100 
101   // Store a forwarding pointer if the object should be moved.
102   if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
103     forwarding->forward_to(object, cast_to_oop(_compaction_top));
104     assert(object->is_forwarded(), "must be forwarded");
105   } else {
106     assert(!object->is_forwarded(), "must not be forwarded");
107   }
108 
109   // Update compaction values.
110   _compaction_top += size;
111   _current_region->update_bot_for_block(_compaction_top - size, _compaction_top);
112 }
113 
114 void G1FullGCCompactionPoint::add(HeapRegion* hr) {
115   _compaction_regions->append(hr);
116 }
117 
118 HeapRegion* G1FullGCCompactionPoint::remove_last() {
119   return _compaction_regions->pop();
120 }
< prev index next >