< 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 

 75   return next;
 76 }
 77 
 78 GrowableArray<HeapRegion*>* G1FullGCCompactionPoint::regions() {
 79   return _compaction_regions;
 80 }
 81 
 82 bool G1FullGCCompactionPoint::object_will_fit(size_t size) {
 83   size_t space_left = pointer_delta(_current_region->end(), _compaction_top);
 84   return size <= space_left;
 85 }
 86 
 87 void G1FullGCCompactionPoint::switch_region() {
 88   // Save compaction top in the region.
 89   _current_region->set_compaction_top(_compaction_top);
 90   // Get the next region and re-initialize the values.
 91   _current_region = next_region();
 92   initialize_values(true);
 93 }
 94 
 95 void G1FullGCCompactionPoint::forward(oop object, size_t size) {
 96   assert(_current_region != NULL, "Must have been initialized");
 97 
 98   // Ensure the object fit in the current region.
 99   while (!object_will_fit(size)) {
100     switch_region();
101   }
102 
103   // Store a forwarding pointer if the object should be moved.
104   if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
105     object->forward_to(cast_to_oop(_compaction_top));
106   } else {
107     if (object->forwardee() != NULL) {





108       // Object should not move but mark-word is used so it looks like the
109       // object is forwarded. Need to clear the mark and it's no problem
110       // since it will be restored by preserved marks.
111       object->init_mark();
112     } else {
113       // Make sure object has the correct mark-word set or that it will be
114       // fixed when restoring the preserved marks.
115       assert(object->mark() == markWord::prototype() || // Correct mark
116              object->mark_must_be_preserved(), // Will be restored by PreservedMarksSet
117              "should have correct prototype obj: " PTR_FORMAT " mark: " PTR_FORMAT " prototype: " PTR_FORMAT,
118              p2i(object), object->mark().value(), markWord::prototype().value());
119     }
120     assert(object->forwardee() == NULL, "should be forwarded to NULL");
121   }
122 
123   // Update compaction values.
124   _compaction_top += size;
125   _current_region->alloc_block_in_bot(_compaction_top - size, _compaction_top);
126 }
127 
128 void G1FullGCCompactionPoint::add(HeapRegion* hr) {
129   _compaction_regions->append(hr);
130 }
131 
132 HeapRegion* G1FullGCCompactionPoint::remove_last() {
133   return _compaction_regions->pop();
134 }

  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 

 76   return next;
 77 }
 78 
 79 GrowableArray<HeapRegion*>* G1FullGCCompactionPoint::regions() {
 80   return _compaction_regions;
 81 }
 82 
 83 bool G1FullGCCompactionPoint::object_will_fit(size_t size) {
 84   size_t space_left = pointer_delta(_current_region->end(), _compaction_top);
 85   return size <= space_left;
 86 }
 87 
 88 void G1FullGCCompactionPoint::switch_region() {
 89   // Save compaction top in the region.
 90   _current_region->set_compaction_top(_compaction_top);
 91   // Get the next region and re-initialize the values.
 92   _current_region = next_region();
 93   initialize_values(true);
 94 }
 95 
 96 void G1FullGCCompactionPoint::forward(SlidingForwarding* const forwarding, oop object, size_t size) {
 97   assert(_current_region != NULL, "Must have been initialized");
 98 
 99   // Ensure the object fit in the current region.
100   while (!object_will_fit(size)) {
101     switch_region();
102   }
103 
104   // Store a forwarding pointer if the object should be moved.
105   if (cast_from_oop<HeapWord*>(object) != _compaction_top) {
106     forwarding->forward_to(object, cast_to_oop(_compaction_top));
107   } else {
108     // TODO: This seems to be checking if mark-word looks like a forwarding pointer, and fix it if
109     // it doesn't. That is because compaction code (G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj))
110     // used to do the same check. However, it is more reliable to first check the lower bits (is_forwarded())
111     // instead before accepting the forwardee. The code in G1FullCompactTask has been changed accordingly,
112     // which should make this block superfluous.
113     if ((reinterpret_cast<uintptr_t>(object->mark().decode_pointer()) & 0x00000000ffffffff) != 0) {
114       // Object should not move but mark-word is used so it looks like the
115       // object is forwarded. Need to clear the mark and it's no problem
116       // since it will be restored by preserved marks.
117       object->init_mark();
118     } else {
119       // Make sure object has the correct mark-word set or that it will be
120       // fixed when restoring the preserved marks.
121       assert(object->mark() LP64_ONLY(.set_narrow_klass(0)) == markWord::prototype() || // Correct mark
122              object->mark_must_be_preserved(), // Will be restored by PreservedMarksSet
123              "should have correct prototype obj: " PTR_FORMAT " mark: " PTR_FORMAT " prototype: " PTR_FORMAT,
124              p2i(object), object->mark().value(), markWord::prototype().value());
125     }
126     assert((reinterpret_cast<uintptr_t>(object->mark().decode_pointer()) & 0x00000000ffffffff) == 0, "should be forwarded to NULL");
127   }
128 
129   // Update compaction values.
130   _compaction_top += size;
131   _current_region->alloc_block_in_bot(_compaction_top - size, _compaction_top);
132 }
133 
134 void G1FullGCCompactionPoint::add(HeapRegion* hr) {
135   _compaction_regions->append(hr);
136 }
137 
138 HeapRegion* G1FullGCCompactionPoint::remove_last() {
139   return _compaction_regions->pop();
140 }
< prev index next >