< prev index next >

src/hotspot/share/gc/g1/g1FullGCCompactTask.cpp

Print this page

 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/g1CollectedHeap.hpp"
 27 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 28 #include "gc/g1/g1FullCollector.inline.hpp"
 29 #include "gc/g1/g1FullGCCompactionPoint.hpp"
 30 #include "gc/g1/g1FullGCCompactTask.hpp"
 31 #include "gc/g1/heapRegion.inline.hpp"
 32 #include "gc/shared/gcTraceTime.inline.hpp"

 33 #include "logging/log.hpp"
 34 #include "oops/oop.inline.hpp"
 35 #include "utilities/ticks.hpp"
 36 
 37 void G1FullGCCompactTask::G1CompactRegionClosure::clear_in_bitmap(oop obj) {

 38   assert(_bitmap->is_marked(obj), "Should only compact marked objects");
 39   _bitmap->clear(obj);
 40 }
 41 
 42 size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {

 43   size_t size = obj->size();
 44   if (obj->is_forwarded()) {
 45     G1FullGCCompactTask::copy_object_to_new_location(obj);
 46   }
 47 
 48   // Clear the mark for the compacted object to allow reuse of the
 49   // bitmap without an additional clearing step.
 50   clear_in_bitmap(obj);
 51   return size;
 52 }
 53 

 54 void G1FullGCCompactTask::copy_object_to_new_location(oop obj) {
 55   assert(obj->is_forwarded(), "Sanity!");
 56   assert(obj->forwardee() != obj, "Object must have a new location");
 57 
 58   size_t size = obj->size();
 59   // Copy object and reinit its mark.
 60   HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);
 61   HeapWord* destination = cast_from_oop<HeapWord*>(obj->forwardee());
 62   Copy::aligned_conjoint_words(obj_addr, destination, size);
 63 
 64   // There is no need to transform stack chunks - marking already did that.
 65   cast_to_oop(destination)->init_mark();
 66   assert(cast_to_oop(destination)->klass() != nullptr, "should have a class");
 67 }
 68 
 69 void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
 70   assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
 71 
 72   if (!collector()->is_free(hr->hrm_index())) {
 73     // The compaction closure not only copies the object to the new
 74     // location, but also clears the bitmap for it. This is needed
 75     // for bitmap verification and to be able to use the bitmap
 76     // for evacuation failures in the next young collection. Testing
 77     // showed that it was better overall to clear bit by bit, compared
 78     // to clearing the whole region at the end. This difference was
 79     // clearly seen for regions with few marks.
 80     G1CompactRegionClosure compact(collector()->mark_bitmap());
 81     hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);





 82   }
 83 
 84   hr->reset_compacted_after_full_gc(_collector->compaction_top(hr));
 85 }
 86 
 87 void G1FullGCCompactTask::work(uint worker_id) {
 88   Ticks start = Ticks::now();
 89   GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
 90   for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
 91        it != compaction_queue->end();
 92        ++it) {
 93     compact_region(*it);
 94   }
 95 }
 96 
 97 void G1FullGCCompactTask::serial_compaction() {
 98   GCTraceTime(Debug, gc, phases) tm("Phase 4: Serial Compaction", collector()->scope()->timer());
 99   GrowableArray<HeapRegion*>* compaction_queue = collector()->serial_compaction_point()->regions();
100   for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
101        it != compaction_queue->end();
102        ++it) {
103     compact_region(*it);
104   }
105 }
106 
107 void G1FullGCCompactTask::humongous_compaction() {
108   GCTraceTime(Debug, gc, phases) tm("Phase 4: Humonguous Compaction", collector()->scope()->timer());
109 
110   for (HeapRegion* hr : collector()->humongous_compaction_regions()) {
111     assert(collector()->is_compaction_target(hr->hrm_index()), "Sanity");
112     compact_humongous_obj(hr);









113   }
114 }
115 

116 void G1FullGCCompactTask::compact_humongous_obj(HeapRegion* src_hr) {
117   assert(src_hr->is_starts_humongous(), "Should be start region of the humongous object");
118 
119   oop obj = cast_to_oop(src_hr->bottom());
120   size_t word_size = obj->size();
121 
122   uint num_regions = (uint)G1CollectedHeap::humongous_obj_size_in_regions(word_size);
123   HeapWord* destination = cast_from_oop<HeapWord*>(obj->forwardee());
124 
125   assert(collector()->mark_bitmap()->is_marked(obj), "Should only compact marked objects");
126   collector()->mark_bitmap()->clear(obj);
127 
128   copy_object_to_new_location(obj);
129 
130   uint dest_start_idx = _g1h->addr_to_region(destination);
131   // Update the metadata for the destination regions.
132   _g1h->set_humongous_metadata(_g1h->region_at(dest_start_idx), num_regions, word_size, false);
133 
134   // Free the source regions that do not overlap with the destination regions.
135   uint src_start_idx = src_hr->hrm_index();
136   free_non_overlapping_regions(src_start_idx, dest_start_idx, num_regions);
137 }
138 
139 void G1FullGCCompactTask::free_non_overlapping_regions(uint src_start_idx, uint dest_start_idx, uint num_regions) {
140   uint dest_end_idx = dest_start_idx + num_regions -1;
141   uint src_end_idx  = src_start_idx + num_regions - 1;
142 
143   uint non_overlapping_start = dest_end_idx < src_start_idx ?
144                                src_start_idx :
145                                dest_end_idx + 1;
146 
147   for (uint i = non_overlapping_start; i <= src_end_idx; ++i) {
148     HeapRegion* hr = _g1h->region_at(i);

 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/g1CollectedHeap.hpp"
 27 #include "gc/g1/g1ConcurrentMarkBitMap.inline.hpp"
 28 #include "gc/g1/g1FullCollector.inline.hpp"
 29 #include "gc/g1/g1FullGCCompactionPoint.hpp"
 30 #include "gc/g1/g1FullGCCompactTask.hpp"
 31 #include "gc/g1/heapRegion.inline.hpp"
 32 #include "gc/shared/gcTraceTime.inline.hpp"
 33 #include "gc/shared/slidingForwarding.inline.hpp"
 34 #include "logging/log.hpp"
 35 #include "oops/oop.inline.hpp"
 36 #include "utilities/ticks.hpp"
 37 
 38 template <bool ALT_FWD>
 39 void G1FullGCCompactTask::G1CompactRegionClosure<ALT_FWD>::clear_in_bitmap(oop obj) {
 40   assert(_bitmap->is_marked(obj), "Should only compact marked objects");
 41   _bitmap->clear(obj);
 42 }
 43 
 44 template <bool ALT_FWD>
 45 size_t G1FullGCCompactTask::G1CompactRegionClosure<ALT_FWD>::apply(oop obj) {
 46   size_t size = obj->size();
 47   if (SlidingForwarding::is_forwarded(obj)) {
 48     G1FullGCCompactTask::copy_object_to_new_location<ALT_FWD>(obj);
 49   }
 50 
 51   // Clear the mark for the compacted object to allow reuse of the
 52   // bitmap without an additional clearing step.
 53   clear_in_bitmap(obj);
 54   return size;
 55 }
 56 
 57 template <bool ALT_FWD>
 58 void G1FullGCCompactTask::copy_object_to_new_location(oop obj) {
 59   assert(SlidingForwarding::is_forwarded(obj), "Sanity!");
 60   assert(SlidingForwarding::forwardee<ALT_FWD>(obj) != obj, "Object must have a new location");
 61 
 62   size_t size = obj->size();
 63   // Copy object and reinit its mark.
 64   HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);
 65   HeapWord* destination = cast_from_oop<HeapWord*>(SlidingForwarding::forwardee<ALT_FWD>(obj));
 66   Copy::aligned_conjoint_words(obj_addr, destination, size);
 67 
 68   // There is no need to transform stack chunks - marking already did that.
 69   cast_to_oop(destination)->init_mark();
 70   assert(cast_to_oop(destination)->klass() != nullptr, "should have a class");
 71 }
 72 
 73 void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
 74   assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
 75 
 76   if (!collector()->is_free(hr->hrm_index())) {
 77     // The compaction closure not only copies the object to the new
 78     // location, but also clears the bitmap for it. This is needed
 79     // for bitmap verification and to be able to use the bitmap
 80     // for evacuation failures in the next young collection. Testing
 81     // showed that it was better overall to clear bit by bit, compared
 82     // to clearing the whole region at the end. This difference was
 83     // clearly seen for regions with few marks.
 84     if (UseAltGCForwarding) {
 85       G1CompactRegionClosure<true> compact(collector()->mark_bitmap());
 86       hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
 87     } else {
 88       G1CompactRegionClosure<false> compact(collector()->mark_bitmap());
 89       hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
 90     }
 91   }
 92 
 93   hr->reset_compacted_after_full_gc(_collector->compaction_top(hr));
 94 }
 95 
 96 void G1FullGCCompactTask::work(uint worker_id) {
 97   Ticks start = Ticks::now();
 98   GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
 99   for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
100        it != compaction_queue->end();
101        ++it) {
102     compact_region(*it);
103   }
104 }
105 
106 void G1FullGCCompactTask::serial_compaction() {
107   GCTraceTime(Debug, gc, phases) tm("Phase 4: Serial Compaction", collector()->scope()->timer());
108   GrowableArray<HeapRegion*>* compaction_queue = collector()->serial_compaction_point()->regions();
109   for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
110        it != compaction_queue->end();
111        ++it) {
112     compact_region(*it);
113   }
114 }
115 
116 template <bool ALT_FWD>
117 void G1FullGCCompactTask::humongous_compaction_impl() {

118   for (HeapRegion* hr : collector()->humongous_compaction_regions()) {
119     assert(collector()->is_compaction_target(hr->hrm_index()), "Sanity");
120     compact_humongous_obj<ALT_FWD>(hr);
121   }
122 }
123 
124 void G1FullGCCompactTask::humongous_compaction() {
125   GCTraceTime(Debug, gc, phases) tm("Phase 4: Humonguous Compaction", collector()->scope()->timer());
126   if (UseAltGCForwarding) {
127     humongous_compaction_impl<true>();
128   } else {
129     humongous_compaction_impl<false>();
130   }
131 }
132 
133 template <bool ALT_FWD>
134 void G1FullGCCompactTask::compact_humongous_obj(HeapRegion* src_hr) {
135   assert(src_hr->is_starts_humongous(), "Should be start region of the humongous object");
136 
137   oop obj = cast_to_oop(src_hr->bottom());
138   size_t word_size = obj->size();
139 
140   uint num_regions = (uint)G1CollectedHeap::humongous_obj_size_in_regions(word_size);
141   HeapWord* destination = cast_from_oop<HeapWord*>(SlidingForwarding::forwardee<ALT_FWD>(obj));
142 
143   assert(collector()->mark_bitmap()->is_marked(obj), "Should only compact marked objects");
144   collector()->mark_bitmap()->clear(obj);
145 
146   copy_object_to_new_location<ALT_FWD>(obj);
147 
148   uint dest_start_idx = _g1h->addr_to_region(destination);
149   // Update the metadata for the destination regions.
150   _g1h->set_humongous_metadata(_g1h->region_at(dest_start_idx), num_regions, word_size, false);
151 
152   // Free the source regions that do not overlap with the destination regions.
153   uint src_start_idx = src_hr->hrm_index();
154   free_non_overlapping_regions(src_start_idx, dest_start_idx, num_regions);
155 }
156 
157 void G1FullGCCompactTask::free_non_overlapping_regions(uint src_start_idx, uint dest_start_idx, uint num_regions) {
158   uint dest_end_idx = dest_start_idx + num_regions -1;
159   uint src_end_idx  = src_start_idx + num_regions - 1;
160 
161   uint non_overlapping_start = dest_end_idx < src_start_idx ?
162                                src_start_idx :
163                                dest_end_idx + 1;
164 
165   for (uint i = non_overlapping_start; i <= src_end_idx; ++i) {
166     HeapRegion* hr = _g1h->region_at(i);
< prev index next >