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