1 /*
2 * Copyright (c) 2017, 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 #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/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 "utilities/ticks.inline.hpp"
35
36 class G1ResetHumongousClosure : public HeapRegionClosure {
37 G1CMBitMap* _bitmap;
38
39 public:
40 G1ResetHumongousClosure(G1CMBitMap* bitmap) :
41 _bitmap(bitmap) { }
42
43 bool do_heap_region(HeapRegion* current) {
44 if (current->is_humongous()) {
45 if (current->is_starts_humongous()) {
46 oop obj = oop(current->bottom());
47 if (_bitmap->is_marked(obj)) {
48 // Clear bitmap and fix mark word.
49 _bitmap->clear(obj);
50 obj->init_mark();
51 } else {
52 assert(current->is_empty(), "Should have been cleared in phase 2.");
53 }
54 }
55 current->reset_during_compaction();
56 }
57 return false;
58 }
59 };
60
61 size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
62 size_t size = obj->size();
63 HeapWord* destination = (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 = (HeapWord*) obj;
71 assert(obj_addr != destination, "everything in this pass should be moving");
72 Copy::aligned_conjoint_words(obj_addr, destination, size);
73 oop(destination)->init_mark();
74 assert(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_humongous(), "Should be no humongous regions in compaction queue");
81 G1CompactRegionClosure compact(collector()->mark_bitmap());
82 hr->apply_to_marked_objects(collector()->mark_bitmap(), &compact);
83 // Once all objects have been moved the liveness information
84 // needs be cleared.
85 collector()->mark_bitmap()->clear_region(hr);
86 hr->complete_compaction();
87 }
88
89 void G1FullGCCompactTask::work(uint worker_id) {
90 Ticks start = Ticks::now();
91 GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
92 for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
93 it != compaction_queue->end();
|
1 /*
2 * Copyright (c) 2017, 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 #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/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.inline.hpp"
36
37 class G1ResetHumongousClosure : public HeapRegionClosure {
38 G1CMBitMap* _bitmap;
39
40 public:
41 G1ResetHumongousClosure(G1CMBitMap* bitmap) :
42 _bitmap(bitmap) { }
43
44 bool do_heap_region(HeapRegion* current) {
45 if (current->is_humongous()) {
46 if (current->is_starts_humongous()) {
47 oop obj = oop(current->bottom());
48 if (_bitmap->is_marked(obj)) {
49 // Clear bitmap and fix mark word.
50 _bitmap->clear(obj);
51 obj->init_mark_raw();
52 } else {
53 assert(current->is_empty(), "Should have been cleared in phase 2.");
54 }
55 }
56 current->reset_during_compaction();
57 }
58 return false;
59 }
60 };
61
62 size_t G1FullGCCompactTask::G1CompactRegionClosure::apply(oop obj) {
63 size_t size = obj->size();
64 HeapWord* destination = (HeapWord*)obj->forwardee();
65 if (destination == NULL) {
66 // Object not moving
67 return size;
68 }
69
70 // copy object and reinit its mark
71 HeapWord* obj_addr = (HeapWord*) obj;
72 assert(obj_addr != destination, "everything in this pass should be moving");
73 Copy::aligned_conjoint_words(obj_addr, destination, size);
74 oop(destination)->init_mark_raw();
75 assert(oop(destination)->klass() != NULL, "should have a class");
76
77 return size;
78 }
79
80 void G1FullGCCompactTask::compact_region(HeapRegion* hr) {
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 // Once all objects have been moved the liveness information
85 // needs be cleared.
86 collector()->mark_bitmap()->clear_region(hr);
87 hr->complete_compaction();
88 }
89
90 void G1FullGCCompactTask::work(uint worker_id) {
91 Ticks start = Ticks::now();
92 GrowableArray<HeapRegion*>* compaction_queue = collector()->compaction_point(worker_id)->regions();
93 for (GrowableArrayIterator<HeapRegion*> it = compaction_queue->begin();
94 it != compaction_queue->end();
|