|
1 /* |
|
2 * Copyright (c) 2018, Red Hat, Inc. All rights reserved. |
|
3 * |
|
4 * This code is free software; you can redistribute it and/or modify it |
|
5 * under the terms of the GNU General Public License version 2 only, as |
|
6 * published by the Free Software Foundation. |
|
7 * |
|
8 * This code is distributed in the hope that it will be useful, but WITHOUT |
|
9 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
10 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
11 * version 2 for more details (a copy is included in the LICENSE file that |
|
12 * accompanied this code). |
|
13 * |
|
14 * You should have received a copy of the GNU General Public License version |
|
15 * 2 along with this work; if not, write to the Free Software Foundation, |
|
16 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
17 * |
|
18 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
|
19 * or visit www.oracle.com if you need additional information or have any |
|
20 * questions. |
|
21 * |
|
22 */ |
|
23 |
|
24 #include "precompiled.hpp" |
|
25 |
|
26 #include "gc/shenandoah/heuristics/shenandoahPassiveHeuristics.hpp" |
|
27 #include "gc/shenandoah/shenandoahCollectionSet.hpp" |
|
28 #include "gc/shenandoah/shenandoahHeapRegion.hpp" |
|
29 #include "logging/log.hpp" |
|
30 #include "logging/logTag.hpp" |
|
31 |
|
32 ShenandoahPassiveHeuristics::ShenandoahPassiveHeuristics() : ShenandoahHeuristics() { |
|
33 // Do not allow concurrent cycles. |
|
34 FLAG_SET_DEFAULT(ExplicitGCInvokesConcurrent, false); |
|
35 FLAG_SET_DEFAULT(ShenandoahImplicitGCInvokesConcurrent, false); |
|
36 |
|
37 // Passive runs with max speed, reacts on allocation failure. |
|
38 FLAG_SET_DEFAULT(ShenandoahPacing, false); |
|
39 |
|
40 // No need for evacuation reserve with Full GC, only for Degenerated GC. |
|
41 if (!ShenandoahDegeneratedGC) { |
|
42 SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahEvacReserve, 0); |
|
43 } |
|
44 |
|
45 // Disable known barriers by default. |
|
46 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahSATBBarrier); |
|
47 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahKeepAliveBarrier); |
|
48 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahWriteBarrier); |
|
49 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahReadBarrier); |
|
50 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahStoreValEnqueueBarrier); |
|
51 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahStoreValReadBarrier); |
|
52 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCASBarrier); |
|
53 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahAcmpBarrier); |
|
54 SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahCloneBarrier); |
|
55 |
|
56 // Final configuration checks |
|
57 // No barriers are required to run. |
|
58 } |
|
59 |
|
60 bool ShenandoahPassiveHeuristics::should_start_normal_gc() const { |
|
61 // Never do concurrent GCs. |
|
62 return false; |
|
63 } |
|
64 |
|
65 bool ShenandoahPassiveHeuristics::should_process_references() { |
|
66 // Always process references, if we can. |
|
67 return can_process_references(); |
|
68 } |
|
69 |
|
70 bool ShenandoahPassiveHeuristics::should_unload_classes() { |
|
71 // Always unload classes, if we can. |
|
72 return can_unload_classes(); |
|
73 } |
|
74 |
|
75 bool ShenandoahPassiveHeuristics::should_degenerate_cycle() { |
|
76 // Always fail to Degenerated GC, if enabled |
|
77 return ShenandoahDegeneratedGC; |
|
78 } |
|
79 |
|
80 void ShenandoahPassiveHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* cset, |
|
81 RegionData* data, size_t size, |
|
82 size_t actual_free) { |
|
83 assert(ShenandoahDegeneratedGC, "This path is only taken for Degenerated GC"); |
|
84 |
|
85 // Do not select too large CSet that would overflow the available free space. |
|
86 // Take at least the entire evacuation reserve, and be free to overflow to free space. |
|
87 size_t capacity = ShenandoahHeap::heap()->capacity(); |
|
88 size_t available = MAX2(ShenandoahEvacReserve * capacity / 100, actual_free); |
|
89 size_t max_cset = (size_t)(available / ShenandoahEvacWaste); |
|
90 |
|
91 log_info(gc, ergo)("CSet Selection. Actual Free: " SIZE_FORMAT "M, Max CSet: " SIZE_FORMAT "M", |
|
92 actual_free / M, max_cset / M); |
|
93 |
|
94 size_t threshold = ShenandoahHeapRegion::region_size_bytes() * ShenandoahGarbageThreshold / 100; |
|
95 |
|
96 size_t live_cset = 0; |
|
97 for (size_t idx = 0; idx < size; idx++) { |
|
98 ShenandoahHeapRegion* r = data[idx]._region; |
|
99 size_t new_cset = live_cset + r->get_live_data_bytes(); |
|
100 if (new_cset < max_cset && r->garbage() > threshold) { |
|
101 live_cset = new_cset; |
|
102 cset->add_region(r); |
|
103 } |
|
104 } |
|
105 } |
|
106 |
|
107 const char* ShenandoahPassiveHeuristics::name() { |
|
108 return "passive"; |
|
109 } |
|
110 |
|
111 bool ShenandoahPassiveHeuristics::is_diagnostic() { |
|
112 return true; |
|
113 } |
|
114 |
|
115 bool ShenandoahPassiveHeuristics::is_experimental() { |
|
116 return false; |
|
117 } |