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 "gc/shenandoah/heuristics/shenandoahYoungHeuristics.hpp"
26 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
27 #include "gc/shenandoah/shenandoahFreeSet.hpp"
28 #include "gc/shenandoah/shenandoahGeneration.hpp"
29 #include "gc/shenandoah/shenandoahGenerationalHeap.hpp"
30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
31 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
32 #include "gc/shenandoah/shenandoahOldGC.hpp"
33 #include "gc/shenandoah/shenandoahOldGeneration.hpp"
34 #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
35 #include "prims/jvmtiTagMap.hpp"
36 #include "utilities/events.hpp"
37
38
39 ShenandoahOldGC::ShenandoahOldGC(ShenandoahOldGeneration* generation, ShenandoahSharedFlag& allow_preemption) :
40 ShenandoahConcurrentGC(generation, false), _old_generation(generation), _allow_preemption(allow_preemption) {
41 }
42
43 // Final mark for old-gen is different for young than old, so we
44 // override the implementation.
45 void ShenandoahOldGC::op_final_mark() {
46
47 ShenandoahGenerationalHeap* const heap = ShenandoahGenerationalHeap::heap();
48 assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at safepoint");
49 assert(!heap->has_forwarded_objects(), "No forwarded objects on this path");
50
51 if (ShenandoahVerify) {
52 heap->verifier()->verify_roots_no_forwarded(_old_generation);
53 }
56 assert(_mark.generation()->is_old(), "Generation of Old-Gen GC should be OLD");
57 _mark.finish_mark();
58 assert(!heap->cancelled_gc(), "STW mark cannot OOM");
59
60 // Old collection is complete, the young generation no longer needs this
61 // reference to the old concurrent mark so clean it up.
62 heap->young_generation()->set_old_gen_task_queues(nullptr);
63
64 // We need to do this because weak root cleaning reports the number of dead handles
65 JvmtiTagMap::set_needs_cleaning();
66
67 _generation->prepare_regions_and_collection_set(true);
68
69 heap->set_unload_classes(false);
70 heap->prepare_concurrent_roots();
71
72 if (VerifyAfterGC) {
73 Universe::verify();
74 }
75
76 {
77 ShenandoahTimingsTracker timing(ShenandoahPhaseTimings::final_mark_propagate_gc_state);
78 heap->propagate_gc_state_to_all_threads();
79 }
80 }
81 }
82
83 bool ShenandoahOldGC::collect(GCCause::Cause cause) {
84 auto heap = ShenandoahGenerationalHeap::heap();
85 assert(!_old_generation->is_doing_mixed_evacuations(), "Should not start an old gc with pending mixed evacuations");
86 assert(!_old_generation->is_preparing_for_mark(), "Old regions need to be parsable during concurrent mark.");
87
88 // Enable preemption of old generation mark.
89 _allow_preemption.set();
90
91 // Continue concurrent mark, do not reset regions, do not mark roots, do not collect $200.
92 entry_mark();
93
94 // If we failed to unset the preemption flag, it means another thread has already unset it.
95 if (!_allow_preemption.try_unset()) {
117 // We aren't dealing with old generation evacuation yet. Our heuristic
118 // should not have built a cset in final mark.
119 assert(!heap->is_evacuation_in_progress(), "Old gen evacuations are not supported");
120
121 // Process weak roots that might still point to regions that would be broken by cleanup
122 if (heap->is_concurrent_weak_root_in_progress()) {
123 entry_weak_refs();
124 entry_weak_roots();
125 }
126
127 // Final mark might have reclaimed some immediate garbage, kick cleanup to reclaim
128 // the space. This would be the last action if there is nothing to evacuate.
129 entry_cleanup_early();
130
131 assert(!heap->is_concurrent_strong_root_in_progress(), "No evacuations during old gc.");
132
133 // We must execute this vm operation if we completed final mark. We cannot
134 // return from here with weak roots in progress. This is not a valid gc state
135 // for any young collections (or allocation failures) that interrupt the old
136 // collection.
137 heap->concurrent_final_roots();
138
139 // After concurrent old marking finishes, we reclaim immediate garbage. Further, we may also want to expand OLD in order
140 // to make room for anticipated promotions and/or for mixed evacuations. Mixed evacuations are especially likely to
141 // follow the end of OLD marking.
142 heap->rebuild_free_set_within_phase();
143 heap->free_set()->log_status_under_lock();
144 return true;
145 }
|
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 "gc/shenandoah/heuristics/shenandoahYoungHeuristics.hpp"
26 #include "gc/shenandoah/shenandoahClosures.inline.hpp"
27 #include "gc/shenandoah/shenandoahFreeSet.hpp"
28 #include "gc/shenandoah/shenandoahGeneration.hpp"
29 #include "gc/shenandoah/shenandoahGenerationalHeap.hpp"
30 #include "gc/shenandoah/shenandoahHeap.inline.hpp"
31 #include "gc/shenandoah/shenandoahMonitoringSupport.hpp"
32 #include "gc/shenandoah/shenandoahOldGC.hpp"
33 #include "gc/shenandoah/shenandoahOldGeneration.hpp"
34 #include "gc/shenandoah/shenandoahStackWatermark.hpp"
35 #include "gc/shenandoah/shenandoahYoungGeneration.hpp"
36 #include "prims/jvmtiTagMap.hpp"
37 #include "utilities/events.hpp"
38
39
40 ShenandoahOldGC::ShenandoahOldGC(ShenandoahOldGeneration* generation, ShenandoahSharedFlag& allow_preemption) :
41 ShenandoahConcurrentGC(generation, false), _old_generation(generation), _allow_preemption(allow_preemption) {
42 }
43
44 // Final mark for old-gen is different for young than old, so we
45 // override the implementation.
46 void ShenandoahOldGC::op_final_mark() {
47
48 ShenandoahGenerationalHeap* const heap = ShenandoahGenerationalHeap::heap();
49 assert(ShenandoahSafepoint::is_at_shenandoah_safepoint(), "Should be at safepoint");
50 assert(!heap->has_forwarded_objects(), "No forwarded objects on this path");
51
52 if (ShenandoahVerify) {
53 heap->verifier()->verify_roots_no_forwarded(_old_generation);
54 }
57 assert(_mark.generation()->is_old(), "Generation of Old-Gen GC should be OLD");
58 _mark.finish_mark();
59 assert(!heap->cancelled_gc(), "STW mark cannot OOM");
60
61 // Old collection is complete, the young generation no longer needs this
62 // reference to the old concurrent mark so clean it up.
63 heap->young_generation()->set_old_gen_task_queues(nullptr);
64
65 // We need to do this because weak root cleaning reports the number of dead handles
66 JvmtiTagMap::set_needs_cleaning();
67
68 _generation->prepare_regions_and_collection_set(true);
69
70 heap->set_unload_classes(false);
71 heap->prepare_concurrent_roots();
72
73 if (VerifyAfterGC) {
74 Universe::verify();
75 }
76
77 // Arm nmethods/stack for concurrent processing
78 ShenandoahCodeRoots::arm_nmethods();
79 ShenandoahStackWatermark::change_epoch_id();
80
81 {
82 ShenandoahTimingsTracker timing(ShenandoahPhaseTimings::final_mark_propagate_gc_state);
83 heap->propagate_gc_state_to_all_threads();
84 }
85 }
86 }
87
88 bool ShenandoahOldGC::collect(GCCause::Cause cause) {
89 auto heap = ShenandoahGenerationalHeap::heap();
90 assert(!_old_generation->is_doing_mixed_evacuations(), "Should not start an old gc with pending mixed evacuations");
91 assert(!_old_generation->is_preparing_for_mark(), "Old regions need to be parsable during concurrent mark.");
92
93 // Enable preemption of old generation mark.
94 _allow_preemption.set();
95
96 // Continue concurrent mark, do not reset regions, do not mark roots, do not collect $200.
97 entry_mark();
98
99 // If we failed to unset the preemption flag, it means another thread has already unset it.
100 if (!_allow_preemption.try_unset()) {
122 // We aren't dealing with old generation evacuation yet. Our heuristic
123 // should not have built a cset in final mark.
124 assert(!heap->is_evacuation_in_progress(), "Old gen evacuations are not supported");
125
126 // Process weak roots that might still point to regions that would be broken by cleanup
127 if (heap->is_concurrent_weak_root_in_progress()) {
128 entry_weak_refs();
129 entry_weak_roots();
130 }
131
132 // Final mark might have reclaimed some immediate garbage, kick cleanup to reclaim
133 // the space. This would be the last action if there is nothing to evacuate.
134 entry_cleanup_early();
135
136 assert(!heap->is_concurrent_strong_root_in_progress(), "No evacuations during old gc.");
137
138 // We must execute this vm operation if we completed final mark. We cannot
139 // return from here with weak roots in progress. This is not a valid gc state
140 // for any young collections (or allocation failures) that interrupt the old
141 // collection.
142 // Arm the nmethods to possibly flip the barriers to idle.
143 vmop_entry_final_roots(true);
144
145 // Now we are back at concurrent phase, process nmethods to fix their barriers.
146 // TODO: Is it safe to do when young GC is running?
147 {
148 ShenandoahConcurrentPhase gc_phase("Concurrent disarm", ShenandoahPhaseTimings::conc_disarm);
149 ShenandoahCodeRoots::disarm_nmethods();
150 }
151
152 // After concurrent old marking finishes, we reclaim immediate garbage. Further, we may also want to expand OLD in order
153 // to make room for anticipated promotions and/or for mixed evacuations. Mixed evacuations are especially likely to
154 // follow the end of OLD marking.
155 heap->rebuild_free_set_within_phase();
156 heap->free_set()->log_status_under_lock();
157 return true;
158 }
|