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