1 /*
2 * Copyright (c) 2001, 2014, 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 *
580
581 DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
582 }
583
584 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
585 bool is_tlab,
586 bool* gc_overhead_limit_was_exceeded) {
587 GenCollectedHeap *gch = GenCollectedHeap::heap();
588
589 debug_only(gch->check_for_valid_allocation_state());
590 assert(gch->no_gc_in_progress(), "Allocation during gc not allowed");
591
592 // In general gc_overhead_limit_was_exceeded should be false so
593 // set it so here and reset it to true only if the gc time
594 // limit is being exceeded as checked below.
595 *gc_overhead_limit_was_exceeded = false;
596
597 HeapWord* result = NULL;
598
599 // Loop until the allocation is satisfied, or unsatisfied after GC.
600 for (int try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
601 HandleMark hm; // Discard any handles allocated in each iteration.
602
603 // First allocation attempt is lock-free.
604 Generation *young = gch->get_gen(0);
605 assert(young->supports_inline_contig_alloc(),
606 "Otherwise, must do alloc within heap lock");
607 if (young->should_allocate(size, is_tlab)) {
608 result = young->par_allocate(size, is_tlab);
609 if (result != NULL) {
610 assert(gch->is_in_reserved(result), "result not in heap");
611 return result;
612 }
613 }
614 unsigned int gc_count_before; // Read inside the Heap_lock locked region.
615 {
616 MutexLocker ml(Heap_lock);
617 if (PrintGC && Verbose) {
618 gclog_or_tty->print_cr("TwoGenerationCollectorPolicy::mem_allocate_work:"
619 " attempting locked slow path allocation");
620 }
621 // Note that only large objects get a shot at being
622 // allocated in later generations.
623 bool first_only = ! should_try_older_generation_allocation(size);
624
625 result = gch->attempt_allocation(size, is_tlab, first_only);
626 if (result != NULL) {
627 assert(gch->is_in_reserved(result), "result not in heap");
628 return result;
629 }
630
631 if (GC_locker::is_active_and_needs_gc()) {
632 if (is_tlab) {
633 return NULL; // Caller will retry allocating individual object.
634 }
|
1 /*
2 * Copyright (c) 2001, 2015, 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 *
580
581 DEBUG_ONLY(GenCollectorPolicy::assert_size_info();)
582 }
583
584 HeapWord* GenCollectorPolicy::mem_allocate_work(size_t size,
585 bool is_tlab,
586 bool* gc_overhead_limit_was_exceeded) {
587 GenCollectedHeap *gch = GenCollectedHeap::heap();
588
589 debug_only(gch->check_for_valid_allocation_state());
590 assert(gch->no_gc_in_progress(), "Allocation during gc not allowed");
591
592 // In general gc_overhead_limit_was_exceeded should be false so
593 // set it so here and reset it to true only if the gc time
594 // limit is being exceeded as checked below.
595 *gc_overhead_limit_was_exceeded = false;
596
597 HeapWord* result = NULL;
598
599 // Loop until the allocation is satisfied, or unsatisfied after GC.
600 for (uint try_count = 1, gclocker_stalled_count = 0; /* return or throw */; try_count += 1) {
601 HandleMark hm; // Discard any handles allocated in each iteration.
602
603 // First allocation attempt is lock-free.
604 Generation *young = gch->get_gen(0);
605 assert(young->supports_inline_contig_alloc(),
606 "Otherwise, must do alloc within heap lock");
607 if (young->should_allocate(size, is_tlab)) {
608 result = young->par_allocate(size, is_tlab);
609 if (result != NULL) {
610 assert(gch->is_in_reserved(result), "result not in heap");
611 return result;
612 }
613 }
614 uint gc_count_before; // Read inside the Heap_lock locked region.
615 {
616 MutexLocker ml(Heap_lock);
617 if (PrintGC && Verbose) {
618 gclog_or_tty->print_cr("TwoGenerationCollectorPolicy::mem_allocate_work:"
619 " attempting locked slow path allocation");
620 }
621 // Note that only large objects get a shot at being
622 // allocated in later generations.
623 bool first_only = ! should_try_older_generation_allocation(size);
624
625 result = gch->attempt_allocation(size, is_tlab, first_only);
626 if (result != NULL) {
627 assert(gch->is_in_reserved(result), "result not in heap");
628 return result;
629 }
630
631 if (GC_locker::is_active_and_needs_gc()) {
632 if (is_tlab) {
633 return NULL; // Caller will retry allocating individual object.
634 }
|