author | rkennke |
Fri, 05 Jul 2019 11:07:09 +0200 | |
changeset 55594 | 66a748c4f3ff |
child 57817 | 1ba30faf88e5 |
permissions | -rw-r--r-- |
55594
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
1 |
/* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
2 |
* Copyright (c) 2018, 2019, Red Hat, Inc. All rights reserved. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
3 |
* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
4 |
* This code is free software; you can redistribute it and/or modify it |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
5 |
* under the terms of the GNU General Public License version 2 only, as |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
6 |
* published by the Free Software Foundation. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
7 |
* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
8 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
9 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
10 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
11 |
* version 2 for more details (a copy is included in the LICENSE file that |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
12 |
* accompanied this code). |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
13 |
* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
14 |
* You should have received a copy of the GNU General Public License version |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
15 |
* 2 along with this work; if not, write to the Free Software Foundation, |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
16 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
17 |
* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
18 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
19 |
* or visit www.oracle.com if you need additional information or have any |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
20 |
* questions. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
21 |
* |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
22 |
*/ |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
23 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
24 |
#include "precompiled.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
25 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
26 |
#include "gc/shenandoah/heuristics/shenandoahTraversalAggressiveHeuristics.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
27 |
#include "gc/shenandoah/shenandoahCollectionSet.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
28 |
#include "gc/shenandoah/shenandoahFreeSet.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
29 |
#include "gc/shenandoah/shenandoahHeap.inline.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
30 |
#include "gc/shenandoah/shenandoahHeuristics.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
31 |
#include "gc/shenandoah/shenandoahTraversalGC.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
32 |
#include "logging/log.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
33 |
#include "logging/logTag.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
34 |
#include "utilities/quickSort.hpp" |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
35 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
36 |
ShenandoahTraversalAggressiveHeuristics::ShenandoahTraversalAggressiveHeuristics() : ShenandoahHeuristics(), |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
37 |
_last_cset_select(0) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
38 |
// Do not shortcut evacuation |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
39 |
SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahImmediateThreshold, 100); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
40 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
41 |
// Aggressive runs with max speed for allocation, to capture races against mutator |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
42 |
SHENANDOAH_ERGO_DISABLE_FLAG(ShenandoahPacing); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
43 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
44 |
// Aggressive evacuates everything, so it needs as much evac space as it can get |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
45 |
SHENANDOAH_ERGO_ENABLE_FLAG(ShenandoahEvacReserveOverflow); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
46 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
47 |
// If class unloading is globally enabled, aggressive does unloading even with |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
48 |
// concurrent cycles. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
49 |
if (ClassUnloading) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
50 |
SHENANDOAH_ERGO_OVERRIDE_DEFAULT(ShenandoahUnloadClassesFrequency, 1); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
51 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
52 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
53 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
54 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
55 |
bool ShenandoahTraversalAggressiveHeuristics::is_experimental() { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
56 |
return true; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
57 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
58 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
59 |
bool ShenandoahTraversalAggressiveHeuristics::is_diagnostic() { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
60 |
return true; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
61 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
62 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
63 |
const char* ShenandoahTraversalAggressiveHeuristics::name() { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
64 |
return "traversal-aggressive"; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
65 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
66 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
67 |
void ShenandoahTraversalAggressiveHeuristics::choose_collection_set(ShenandoahCollectionSet* collection_set) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
68 |
ShenandoahHeap* heap = ShenandoahHeap::heap(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
69 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
70 |
ShenandoahTraversalGC* traversal_gc = heap->traversal_gc(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
71 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
72 |
ShenandoahHeapRegionSet* traversal_set = traversal_gc->traversal_set(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
73 |
traversal_set->clear(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
74 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
75 |
RegionData *data = get_region_data_cache(heap->num_regions()); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
76 |
size_t cnt = 0; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
77 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
78 |
// Step 0. Prepare all regions |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
79 |
for (size_t i = 0; i < heap->num_regions(); i++) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
80 |
ShenandoahHeapRegion* r = heap->get_region(i); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
81 |
if (r->used() > 0) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
82 |
if (r->is_regular()) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
83 |
data[cnt]._region = r; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
84 |
data[cnt]._garbage = r->garbage(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
85 |
data[cnt]._seqnum_last_alloc = r->seqnum_last_alloc_mutator(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
86 |
cnt++; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
87 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
88 |
traversal_set->add_region(r); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
89 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
90 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
91 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
92 |
for (size_t i = 0; i < cnt; i++) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
93 |
if (data[i]._seqnum_last_alloc > _last_cset_select) continue; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
94 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
95 |
ShenandoahHeapRegion* r = data[i]._region; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
96 |
assert (r->is_regular(), "should have been filtered before"); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
97 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
98 |
if (r->garbage() > 0) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
99 |
assert(!collection_set->is_in(r), "must not yet be in cset"); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
100 |
collection_set->add_region(r); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
101 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
102 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
103 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
104 |
// Clear liveness data |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
105 |
// TODO: Merge it with step 0, but save live data in RegionData before. |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
106 |
for (size_t i = 0; i < heap->num_regions(); i++) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
107 |
ShenandoahHeapRegion* r = heap->get_region(i); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
108 |
if (r->used() > 0) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
109 |
r->clear_live_data(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
110 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
111 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
112 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
113 |
collection_set->update_region_status(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
114 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
115 |
_last_cset_select = ShenandoahHeapRegion::seqnum_current_alloc(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
116 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
117 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
118 |
void ShenandoahTraversalAggressiveHeuristics::choose_collection_set_from_regiondata(ShenandoahCollectionSet* set, |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
119 |
RegionData* data, size_t data_size, |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
120 |
size_t free) { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
121 |
ShouldNotReachHere(); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
122 |
} |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
123 |
|
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
124 |
bool ShenandoahTraversalAggressiveHeuristics::should_start_gc() const { |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
125 |
log_info(gc)("Trigger: Start next cycle immediately"); |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
126 |
return true; |
66a748c4f3ff
8227039: Shenandoah: Aggressive heuristics for Traversal mode
rkennke
parents:
diff
changeset
|
127 |
} |