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.hpp"
29 #include "gc/g1/g1FullCollector.inline.hpp"
30 #include "gc/g1/g1FullGCCompactionPoint.hpp"
31 #include "gc/g1/g1FullGCCompactTask.hpp"
32 #include "gc/g1/heapRegion.inline.hpp"
33 #include "gc/shared/gcTraceTime.inline.hpp"
34 #include "logging/log.hpp"
35 #include "oops/oop.inline.hpp"
36 #include "utilities/ticks.hpp"
37
38 // Do work for all skip-compacting regions.
39 class G1ResetSkipCompactingClosure : public HeapRegionClosure {
40 G1FullCollector* _collector;
41
42 public:
43 G1ResetSkipCompactingClosure(G1FullCollector* collector) : _collector(collector) { }
44
45 bool do_heap_region(HeapRegion* r) {
46 uint region_index = r->hrm_index();
47 // Only for skip-compaction regions; early return otherwise.
48 if (!_collector->is_skip_compacting(region_index)) {
49
50 return false;
51 }
52 assert(_collector->live_words(region_index) > _collector->scope()->region_compaction_threshold() ||
53 !r->is_starts_humongous() ||
54 _collector->mark_bitmap()->is_marked(cast_to_oop(r->bottom())),
55 "must be, otherwise reclaimed earlier");
56 r->reset_skip_compacting_after_full_gc();
57 return false;
58 }
59 };
60
61 size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
62 size_t size = obj->size();
63 HeapWord* destination = cast_from_oop<HeapWord*>(obj->forwardee());
64 if (destination == NULL) {
65 // Object not moving
66 return size;
67 }
68
69 // copy object and reinit its mark
70 HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);
71 assert(obj_addr != destination, "everything in this pass should be moving");
72 Copy::aligned_conjoint_words(obj_addr, destination, size);
73 cast_to_oop(destination)->init_mark();
74 assert(cast_to_oop(destination)->klass() != NULL, "should have a class");
75
76 return size;
77 }
78
79 void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
80 assert(!hr->is_pinned(), "Should be no pinned region in compaction queue");
81 assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
82 G1CompactRegionClosure compact(collector()->mark_bitmap());
83 hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
84 // Clear the liveness information for this region if necessary i.e. if we actually look at it
85 // for bitmap verification. Otherwise it is sufficient that we move the TAMS to bottom().
86 if (G1VerifyBitmaps) {
87 collector()->mark_bitmap()->clear_region(hr);
88 }
89 hr->reset_compacted_after_full_gc();
90 }
91
92 void G1FullGCCompactTask::work(uint worker_id) {
93 Ticks start = Ticks::now();
94 GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
95 for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
96 it != compaction_queue->end();
97 ++it) {
98 compact_region(*it);
99 }
100
101 G1ResetSkipCompactingClosure hc(collector());
102 G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&hc, &_claimer, worker_id);
103 log_task("Compaction task", worker_id, start);
|
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.hpp"
29 #include "gc/g1/g1FullCollector.inline.hpp"
30 #include "gc/g1/g1FullGCCompactionPoint.hpp"
31 #include "gc/g1/g1FullGCCompactTask.hpp"
32 #include "gc/g1/heapRegion.inline.hpp"
33 #include "gc/shared/gcTraceTime.inline.hpp"
34 #include "gc/shared/slidingForwarding.inline.hpp"
35 #include "logging/log.hpp"
36 #include "oops/oop.inline.hpp"
37 #include "utilities/ticks.hpp"
38
39 // Do work for all skip-compacting regions.
40 class G1ResetSkipCompactingClosure : public HeapRegionClosure {
41 G1FullCollector* _collector;
42
43 public:
44 G1ResetSkipCompactingClosure(G1FullCollector* collector) : _collector(collector) { }
45
46 bool do_heap_region(HeapRegion* r) {
47 uint region_index = r->hrm_index();
48 // Only for skip-compaction regions; early return otherwise.
49 if (!_collector->is_skip_compacting(region_index)) {
50
51 return false;
52 }
53 assert(_collector->live_words(region_index) > _collector->scope()->region_compaction_threshold() ||
54 !r->is_starts_humongous() ||
55 _collector->mark_bitmap()->is_marked(cast_to_oop(r->bottom())),
56 "must be, otherwise reclaimed earlier");
57 r->reset_skip_compacting_after_full_gc();
58 return false;
59 }
60 };
61
62 template <bool ALT_FWD>
63 size_t G1FullGCCompactTask::G1CompactRegionClosure<ALT_FWD>::apply(oop obj) {
64 size_t size = obj->size();
65 if (!SlidingForwarding::is_forwarded(obj)) {
66 // Object not moving
67 return size;
68 }
69
70 HeapWord* destination = cast_from_oop<HeapWord*>(SlidingForwarding::forwardee<ALT_FWD>(obj));
71
72 // copy object and reinit its mark
73 HeapWord* obj_addr = cast_from_oop<HeapWord*>(obj);
74 assert(obj_addr != destination, "everything in this pass should be moving");
75 Copy::aligned_conjoint_words(obj_addr, destination, size);
76 cast_to_oop(destination)->init_mark();
77 assert(cast_to_oop(destination)->klass() != NULL, "should have a class");
78
79 return size;
80 }
81
82 void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
83 assert(!hr->is_pinned(), "Should be no pinned region in compaction queue");
84 assert(!hr->is_humongous(), "Should be no humongous regions in compaction queue");
85 if (UseAltGCForwarding) {
86 G1CompactRegionClosure<true> compact(collector()->mark_bitmap());
87 hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
88 } else {
89 G1CompactRegionClosure<false> compact(collector()->mark_bitmap());
90 hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
91 }
92 // Clear the liveness information for this region if necessary i.e. if we actually look at it
93 // for bitmap verification. Otherwise it is sufficient that we move the TAMS to bottom().
94 if (G1VerifyBitmaps) {
95 collector()->mark_bitmap()->clear_region(hr);
96 }
97 hr->reset_compacted_after_full_gc();
98 }
99
100 void G1FullGCCompactTask::work(uint worker_id) {
101 Ticks start = Ticks::now();
102 GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
103 for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
104 it != compaction_queue->end();
105 ++it) {
106 compact_region(*it);
107 }
108
109 G1ResetSkipCompactingClosure hc(collector());
110 G1CollectedHeap::heap()->heap_region_par_iterate_from_worker_offset(&hc, &_claimer, worker_id);
111 log_task("Compaction task", worker_id, start);
|