1 /*
2 * Copyright (c) 2001, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
208 HeapWord* PSOldGen::allocate(size_t word_size) {
209 assert_locked_or_safepoint(Heap_lock);
210 HeapWord* res = allocate_noexpand(word_size);
211
212 if (res == NULL) {
213 res = expand_and_allocate(word_size);
214 }
215
216 // Allocations in the old generation need to be reported
217 if (res != NULL) {
218 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
219 heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
220 }
221
222 return res;
223 }
224
225 HeapWord* PSOldGen::expand_and_allocate(size_t word_size) {
226 expand(word_size*HeapWordSize);
227 if (GCExpandToAllocateDelayMillis > 0) {
228 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
229 }
230 return allocate_noexpand(word_size);
231 }
232
233 HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
234 expand(word_size*HeapWordSize);
235 if (GCExpandToAllocateDelayMillis > 0) {
236 os::sleep(Thread::current(), GCExpandToAllocateDelayMillis, false);
237 }
238 return cas_allocate_noexpand(word_size);
239 }
240
241 void PSOldGen::expand(size_t bytes) {
242 if (bytes == 0) {
243 return;
244 }
245 MutexLocker x(ExpandHeap_lock);
246 const size_t alignment = virtual_space()->alignment();
247 size_t aligned_bytes = align_up(bytes, alignment);
248 size_t aligned_expand_bytes = align_up(MinHeapDeltaBytes, alignment);
249
250 if (UseNUMA) {
251 // With NUMA we use round-robin page allocation for the old gen. Expand by at least
252 // providing a page per lgroup. Alignment is larger or equal to the page size.
253 aligned_expand_bytes = MAX2(aligned_expand_bytes, alignment * os::numa_get_groups_num());
254 }
255 if (aligned_bytes == 0){
256 // The alignment caused the number of bytes to wrap. An expand_by(0) will
|
1 /*
2 * Copyright (c) 2001, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
208 HeapWord* PSOldGen::allocate(size_t word_size) {
209 assert_locked_or_safepoint(Heap_lock);
210 HeapWord* res = allocate_noexpand(word_size);
211
212 if (res == NULL) {
213 res = expand_and_allocate(word_size);
214 }
215
216 // Allocations in the old generation need to be reported
217 if (res != NULL) {
218 ParallelScavengeHeap* heap = ParallelScavengeHeap::heap();
219 heap->size_policy()->tenured_allocation(word_size * HeapWordSize);
220 }
221
222 return res;
223 }
224
225 HeapWord* PSOldGen::expand_and_allocate(size_t word_size) {
226 expand(word_size*HeapWordSize);
227 if (GCExpandToAllocateDelayMillis > 0) {
228 os::naked_sleep(GCExpandToAllocateDelayMillis);
229 }
230 return allocate_noexpand(word_size);
231 }
232
233 HeapWord* PSOldGen::expand_and_cas_allocate(size_t word_size) {
234 expand(word_size*HeapWordSize);
235 if (GCExpandToAllocateDelayMillis > 0) {
236 os::naked_sleep(GCExpandToAllocateDelayMillis);
237 }
238 return cas_allocate_noexpand(word_size);
239 }
240
241 void PSOldGen::expand(size_t bytes) {
242 if (bytes == 0) {
243 return;
244 }
245 MutexLocker x(ExpandHeap_lock);
246 const size_t alignment = virtual_space()->alignment();
247 size_t aligned_bytes = align_up(bytes, alignment);
248 size_t aligned_expand_bytes = align_up(MinHeapDeltaBytes, alignment);
249
250 if (UseNUMA) {
251 // With NUMA we use round-robin page allocation for the old gen. Expand by at least
252 // providing a page per lgroup. Alignment is larger or equal to the page size.
253 aligned_expand_bytes = MAX2(aligned_expand_bytes, alignment * os::numa_get_groups_num());
254 }
255 if (aligned_bytes == 0){
256 // The alignment caused the number of bytes to wrap. An expand_by(0) will
|