author | shade |
Mon, 26 Mar 2018 16:29:48 +0200 | |
branch | epsilon-gc-branch |
changeset 56352 | ebb84e128ed3 |
parent 56350 | 56014b46de69 |
child 56353 | eb96d40953f1 |
permissions | -rw-r--r-- |
55767 | 1 |
/* |
56350 | 2 |
* Copyright (c) 2017, 2018, Red Hat, Inc. All rights reserved. |
55767 | 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 |
size_t init_byte_size = _policy->initial_heap_byte_size(); |
30 |
size_t max_byte_size = _policy->max_heap_byte_size(); |
|
31 |
size_t align = _policy->heap_alignment(); |
|
32 |
||
33 |
ReservedSpace heap_rs = Universe::reserve_heap(max_byte_size, align); |
|
34 |
_virtual_space.initialize(heap_rs, init_byte_size); |
|
35 |
||
36 |
MemRegion committed_region((HeapWord*)_virtual_space.low(), (HeapWord*)_virtual_space.high()); |
|
37 |
MemRegion reserved_region((HeapWord*)_virtual_space.low_boundary(), (HeapWord*)_virtual_space.high_boundary()); |
|
38 |
||
39 |
initialize_reserved_region(reserved_region.start(), reserved_region.end()); |
|
40 |
||
41 |
_space = new ContiguousSpace(); |
|
42 |
_space->initialize(committed_region, true, true); |
|
43 |
||
56352 | 44 |
set_barrier_set(new EpsilonBarrierSet()); |
55767 | 45 |
|
46 |
_max_tlab_size = MIN2(CollectedHeap::max_tlab_size(), EpsilonMaxTLABSize / HeapWordSize); |
|
47 |
||
48 |
_monitoring_support = new EpsilonMonitoringSupport(this); |
|
49 |
_last_counter_update = 0; |
|
55979 | 50 |
_last_heap_print = 0; |
51 |
||
52 |
_step_counter_update = MIN2<size_t>(max_byte_size / 16, EpsilonUpdateCountersStep); |
|
53 |
_step_heap_print = (EpsilonPrintHeapStep == 0) ? SIZE_MAX : (max_byte_size / EpsilonPrintHeapStep); |
|
55767 | 54 |
|
55 |
if (init_byte_size != max_byte_size) { |
|
56 |
log_info(gc)("Initialized with " SIZE_FORMAT "M heap, resizeable to up to " SIZE_FORMAT "M heap with " SIZE_FORMAT "M steps", |
|
57 |
init_byte_size / M, max_byte_size / M, EpsilonMinHeapExpand / M); |
|
58 |
} else { |
|
59 |
log_info(gc)("Initialized with " SIZE_FORMAT "M non-resizeable heap", init_byte_size / M); |
|
60 |
} |
|
61 |
if (UseTLAB) { |
|
62 |
log_info(gc)("Using TLAB allocation; min: " SIZE_FORMAT "K, max: " SIZE_FORMAT "K", |
|
63 |
ThreadLocalAllocBuffer::min_size()*HeapWordSize / K, |
|
64 |
_max_tlab_size*HeapWordSize / K); |
|
65 |
} else { |
|
66 |
log_info(gc)("Not using TLAB allocation"); |
|
67 |
} |
|
68 |
||
69 |
return JNI_OK; |
|
70 |
} |
|
71 |
||
55974 | 72 |
void EpsilonHeap::post_initialize() { |
73 |
CollectedHeap::post_initialize(); |
|
74 |
} |
|
75 |
||
76 |
void EpsilonHeap::initialize_serviceability() { |
|
55975 | 77 |
_pool = new EpsilonMemoryPool(this); |
78 |
_memory_manager.add_pool(_pool); |
|
55974 | 79 |
} |
80 |
||
81 |
GrowableArray<GCMemoryManager*> EpsilonHeap::memory_managers() { |
|
55975 | 82 |
GrowableArray<GCMemoryManager*> memory_managers(1); |
83 |
memory_managers.append(&_memory_manager); |
|
55974 | 84 |
return memory_managers; |
85 |
} |
|
86 |
||
87 |
GrowableArray<MemoryPool*> EpsilonHeap::memory_pools() { |
|
88 |
GrowableArray<MemoryPool*> memory_pools(3); |
|
55975 | 89 |
memory_pools.append(_pool); |
55974 | 90 |
return memory_pools; |
91 |
} |
|
92 |
||
56352 | 93 |
size_t EpsilonHeap::unsafe_max_tlab_alloc(Thread* thr) const { |
55767 | 94 |
// This is the only way we can control TLAB sizes without having safepoints. |
95 |
// Implement exponential expansion within [MinTLABSize; _max_tlab_size], based |
|
96 |
// on previously "used" TLAB size. |
|
97 |
||
98 |
size_t size = MIN2(_max_tlab_size * HeapWordSize, MAX2(MinTLABSize, thr->tlab().used() * HeapWordSize * 2)); |
|
99 |
||
100 |
if (log_is_enabled(Trace, gc)) { |
|
101 |
ResourceMark rm; |
|
102 |
log_trace(gc)( |
|
103 |
"Selecting TLAB size for \"%s\" (Desired: " SIZE_FORMAT "K, Used: " SIZE_FORMAT "K) -> " SIZE_FORMAT "K", |
|
104 |
Thread::current()->name(), |
|
105 |
thr->tlab().desired_size() * HeapWordSize / K, |
|
106 |
thr->tlab().used() * HeapWordSize / K, |
|
107 |
size / K); |
|
108 |
} |
|
109 |
||
110 |
return size; |
|
111 |
} |
|
112 |
||
55939 | 113 |
EpsilonHeap* EpsilonHeap::heap() { |
55767 | 114 |
CollectedHeap* heap = Universe::heap(); |
55939 | 115 |
assert(heap != NULL, "Uninitialized access to EpsilonHeap::heap()"); |
116 |
assert(heap->kind() == CollectedHeap::EpsilonHeap, "Not a EpsilonHeap"); |
|
117 |
return (EpsilonHeap*)heap; |
|
55767 | 118 |
} |
119 |
||
55939 | 120 |
HeapWord* EpsilonHeap::allocate_work(size_t size) { |
55767 | 121 |
HeapWord* res = _space->par_allocate(size); |
122 |
||
123 |
while (res == NULL) { |
|
124 |
// Allocation failed, attempt expansion, and retry: |
|
125 |
MutexLockerEx ml(Heap_lock); |
|
55980
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
126 |
|
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
127 |
size_t space_left = max_capacity() - capacity(); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
128 |
size_t want_space = MAX2(size, EpsilonMinHeapExpand); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
129 |
|
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
130 |
if (want_space < space_left) { |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
131 |
// Enough space to expand in bulk: |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
132 |
bool expand = _virtual_space.expand_by(want_space); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
133 |
assert(expand, "Should be able to expand"); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
134 |
} else if (size < space_left) { |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
135 |
// No space to expand in bulk, and this allocation is still possible, |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
136 |
// take all the space left: |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
137 |
bool expand = _virtual_space.expand_by(space_left); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
138 |
assert(expand, "Should be able to expand"); |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
139 |
} else { |
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
140 |
// No space left: |
55767 | 141 |
return NULL; |
142 |
} |
|
55980
67d289ae67f5
Make sure Epsilon is able to use the last bit of expanded heap
shade
parents:
55979
diff
changeset
|
143 |
|
55767 | 144 |
_space->set_end((HeapWord *) _virtual_space.high()); |
145 |
res = _space->par_allocate(size); |
|
146 |
} |
|
147 |
||
148 |
size_t used = _space->used(); |
|
55979 | 149 |
if (used - _last_counter_update >= _step_counter_update) { |
55767 | 150 |
_last_counter_update = used; |
151 |
_monitoring_support->update_counters(); |
|
152 |
} |
|
55979 | 153 |
|
154 |
if (used - _last_heap_print >= _step_heap_print) { |
|
155 |
log_info(gc)("Heap: " SIZE_FORMAT "M reserved, " SIZE_FORMAT "M committed, " SIZE_FORMAT "M used", |
|
156 |
max_capacity() / M, capacity() / M, used / M); |
|
157 |
_last_heap_print = used; |
|
158 |
} |
|
159 |
||
55767 | 160 |
return res; |
161 |
} |
|
162 |
||
55939 | 163 |
HeapWord* EpsilonHeap::allocate_new_tlab(size_t size) { |
55767 | 164 |
return allocate_work(size); |
165 |
} |
|
166 |
||
55939 | 167 |
HeapWord* EpsilonHeap::mem_allocate(size_t size, bool *gc_overhead_limit_was_exceeded) { |
55767 | 168 |
*gc_overhead_limit_was_exceeded = false; |
169 |
return allocate_work(size); |
|
170 |
} |
|
171 |
||
55939 | 172 |
void EpsilonHeap::collect(GCCause::Cause cause) { |
55767 | 173 |
log_info(gc)("GC was triggered with cause \"%s\". Ignoring.", GCCause::to_string(cause)); |
174 |
_monitoring_support->update_counters(); |
|
175 |
} |
|
176 |
||
55939 | 177 |
void EpsilonHeap::do_full_collection(bool clear_all_soft_refs) { |
55767 | 178 |
log_info(gc)("Full GC was triggered with cause \"%s\". Ignoring.", GCCause::to_string(gc_cause())); |
179 |
_monitoring_support->update_counters(); |
|
180 |
} |
|
181 |
||
55939 | 182 |
void EpsilonHeap::safe_object_iterate(ObjectClosure *cl) { |
55767 | 183 |
_space->safe_object_iterate(cl); |
184 |
} |
|
185 |
||
55939 | 186 |
void EpsilonHeap::print_on(outputStream *st) const { |
55767 | 187 |
st->print_cr("Epsilon Heap"); |
188 |
||
189 |
// Cast away constness: |
|
190 |
((VirtualSpace)_virtual_space).print_on(st); |
|
191 |
||
192 |
st->print_cr("Allocation space:"); |
|
193 |
_space->print_on(st); |
|
194 |
} |
|
195 |
||
55939 | 196 |
void EpsilonHeap::print_tracing_info() const { |
55767 | 197 |
Log(gc) log; |
198 |
size_t allocated_kb = used() / K; |
|
199 |
log.info("Total allocated: " SIZE_FORMAT " KB", |
|
200 |
allocated_kb); |
|
201 |
log.info("Average allocation rate: " SIZE_FORMAT " KB/sec", |
|
55976 | 202 |
(size_t)(allocated_kb * NANOSECS_PER_SEC / os::elapsed_counter())); |
55767 | 203 |
} |