55767
|
1 |
/*
|
|
2 |
* Copyright (c) 2017, Red Hat, Inc. and/or its affiliates.
|
|
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"
|
55939
|
25 |
#include "gc/epsilon/epsilonHeap.hpp"
|
55767
|
26 |
|
55939
|
27 |
jint EpsilonHeap::initialize() {
|
55767
|
28 |
CollectedHeap::pre_initialize();
|
|
29 |
|
|
30 |
size_t init_byte_size = _policy->initial_heap_byte_size();
|
|
31 |
size_t max_byte_size = _policy->max_heap_byte_size();
|
|
32 |
size_t align = _policy->heap_alignment();
|
|
33 |
|
|
34 |
ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, align);
|
|
35 |
_virtual_space.initialize(heap_rs, init_byte_size);
|
|
36 |
|
|
37 |
MemRegion committed_region((HeapWord*)_virtual_space.low(), (HeapWord*)_virtual_space.high());
|
|
38 |
MemRegion reserved_region((HeapWord*)_virtual_space.low_boundary(), (HeapWord*)_virtual_space.high_boundary());
|
|
39 |
|
|
40 |
initialize_reserved_region(reserved_region.start(), reserved_region.end());
|
|
41 |
|
|
42 |
_space = new ContiguousSpace();
|
|
43 |
_space->initialize(committed_region, true, true);
|
|
44 |
|
|
45 |
EpsilonBarrierSet* bs = new EpsilonBarrierSet();
|
|
46 |
set_barrier_set(bs);
|
|
47 |
|
|
48 |
_max_tlab_size = MIN2(CollectedHeap::max_tlab_size(), EpsilonMaxTLABSize / HeapWordSize);
|
|
49 |
|
|
50 |
_monitoring_support = new EpsilonMonitoringSupport(this);
|
|
51 |
_last_counter_update = 0;
|
|
52 |
|
|
53 |
if (init_byte_size != max_byte_size) {
|
|
54 |
log_info(gc)("Initialized with " SIZE_FORMAT "M heap, resizeable to up to " SIZE_FORMAT "M heap with " SIZE_FORMAT "M steps",
|
|
55 |
init_byte_size / M, max_byte_size / M, EpsilonMinHeapExpand / M);
|
|
56 |
} else {
|
|
57 |
log_info(gc)("Initialized with " SIZE_FORMAT "M non-resizeable heap", init_byte_size / M);
|
|
58 |
}
|
|
59 |
if (UseTLAB) {
|
|
60 |
log_info(gc)("Using TLAB allocation; min: " SIZE_FORMAT "K, max: " SIZE_FORMAT "K",
|
|
61 |
ThreadLocalAllocBuffer::min_size()*HeapWordSize / K,
|
|
62 |
_max_tlab_size*HeapWordSize / K);
|
|
63 |
} else {
|
|
64 |
log_info(gc)("Not using TLAB allocation");
|
|
65 |
}
|
|
66 |
|
|
67 |
return JNI_OK;
|
|
68 |
}
|
|
69 |
|
55939
|
70 |
size_t EpsilonHeap::unsafe_max_tlab_alloc(Thread *thr) const {
|
55767
|
71 |
// This is the only way we can control TLAB sizes without having safepoints.
|
|
72 |
// Implement exponential expansion within [MinTLABSize; _max_tlab_size], based
|
|
73 |
// on previously "used" TLAB size.
|
|
74 |
|
|
75 |
size_t size = MIN2(_max_tlab_size * HeapWordSize, MAX2(MinTLABSize, thr->tlab().used() * HeapWordSize * 2));
|
|
76 |
|
|
77 |
if (log_is_enabled(Trace, gc)) {
|
|
78 |
ResourceMark rm;
|
|
79 |
log_trace(gc)(
|
|
80 |
"Selecting TLAB size for \"%s\" (Desired: " SIZE_FORMAT "K, Used: " SIZE_FORMAT "K) -> " SIZE_FORMAT "K",
|
|
81 |
Thread::current()->name(),
|
|
82 |
thr->tlab().desired_size() * HeapWordSize / K,
|
|
83 |
thr->tlab().used() * HeapWordSize / K,
|
|
84 |
size / K);
|
|
85 |
}
|
|
86 |
|
|
87 |
return size;
|
|
88 |
}
|
|
89 |
|
55939
|
90 |
EpsilonHeap* EpsilonHeap::heap() {
|
55767
|
91 |
CollectedHeap* heap = Universe::heap();
|
55939
|
92 |
assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()");
|
|
93 |
assert(heap->kind() == CollectedHeap::EpsilonHeap, "Not a EpsilonHeap");
|
|
94 |
return (EpsilonHeap*)heap;
|
55767
|
95 |
}
|
|
96 |
|
55939
|
97 |
HeapWord* EpsilonHeap::allocate_work(size_t size) {
|
55767
|
98 |
HeapWord* res = _space->par_allocate(size);
|
|
99 |
|
|
100 |
while (res == NULL) {
|
|
101 |
// Allocation failed, attempt expansion, and retry:
|
|
102 |
MutexLockerEx ml(Heap_lock);
|
|
103 |
if (!_virtual_space.expand_by(MAX2(size, EpsilonMinHeapExpand))) {
|
|
104 |
return NULL;
|
|
105 |
}
|
|
106 |
_space->set_end((HeapWord *) _virtual_space.high());
|
|
107 |
res = _space->par_allocate(size);
|
|
108 |
}
|
|
109 |
|
|
110 |
size_t used = _space->used();
|
|
111 |
if (used - _last_counter_update >= 1024 * 1024) {
|
|
112 |
_last_counter_update = used;
|
|
113 |
_monitoring_support->update_counters();
|
|
114 |
}
|
|
115 |
return res;
|
|
116 |
}
|
|
117 |
|
55939
|
118 |
HeapWord* EpsilonHeap::allocate_new_tlab(size_t size) {
|
55767
|
119 |
return allocate_work(size);
|
|
120 |
}
|
|
121 |
|
55939
|
122 |
HeapWord* EpsilonHeap::mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded) {
|
55767
|
123 |
*gc_overhead_limit_was_exceeded = false;
|
|
124 |
return allocate_work(size);
|
|
125 |
}
|
|
126 |
|
55939
|
127 |
void EpsilonHeap::collect(GCCause::Cause cause) {
|
55767
|
128 |
log_info(gc)("GC was triggered with cause \"%s\". Ignoring.", GCCause::to_string(cause));
|
|
129 |
_monitoring_support->update_counters();
|
|
130 |
}
|
|
131 |
|
55939
|
132 |
void EpsilonHeap::do_full_collection(bool clear_all_soft_refs) {
|
55767
|
133 |
log_info(gc)("Full GC was triggered with cause \"%s\". Ignoring.", GCCause::to_string(gc_cause()));
|
|
134 |
_monitoring_support->update_counters();
|
|
135 |
}
|
|
136 |
|
55939
|
137 |
void EpsilonHeap::safe_object_iterate(ObjectClosure *cl) {
|
55767
|
138 |
_space->safe_object_iterate(cl);
|
|
139 |
}
|
|
140 |
|
55939
|
141 |
void EpsilonHeap::print_on(outputStream *st) const {
|
55767
|
142 |
st->print_cr("Epsilon Heap");
|
|
143 |
|
|
144 |
// Cast away constness:
|
|
145 |
((VirtualSpace)_virtual_space).print_on(st);
|
|
146 |
|
|
147 |
st->print_cr("Allocation space:");
|
|
148 |
_space->print_on(st);
|
|
149 |
}
|
|
150 |
|
55939
|
151 |
void EpsilonHeap::print_tracing_info() const {
|
55767
|
152 |
Log(gc) log;
|
|
153 |
size_t allocated_kb = used() / K;
|
|
154 |
log.info("Total allocated: " SIZE_FORMAT " KB",
|
|
155 |
allocated_kb);
|
|
156 |
log.info("Average allocation rate: " SIZE_FORMAT " KB/sec",
|
|
157 |
allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter());
|
|
158 |
}
|