1 /* |
1 /* |
2 * Copyright (c) 2001, 2017, Oracle and/or its affiliates. All rights reserved. |
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. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * |
4 * |
5 * This code is free software; you can redistribute it and/or modify it |
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 |
6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. |
7 * published by the Free Software Foundation. |
123 class G1CollectedHeap : public CollectedHeap { |
123 class G1CollectedHeap : public CollectedHeap { |
124 friend class G1FreeCollectionSetTask; |
124 friend class G1FreeCollectionSetTask; |
125 friend class VM_CollectForMetadataAllocation; |
125 friend class VM_CollectForMetadataAllocation; |
126 friend class VM_G1CollectForAllocation; |
126 friend class VM_G1CollectForAllocation; |
127 friend class VM_G1CollectFull; |
127 friend class VM_G1CollectFull; |
128 friend class VM_G1IncCollectionPause; |
|
129 friend class VMStructs; |
128 friend class VMStructs; |
130 friend class MutatorAllocRegion; |
129 friend class MutatorAllocRegion; |
131 friend class G1FullCollector; |
130 friend class G1FullCollector; |
132 friend class G1GCAllocRegion; |
131 friend class G1GCAllocRegion; |
133 friend class G1HeapVerifier; |
132 friend class G1HeapVerifier; |
452 virtual HeapWord* allocate_new_tlab(size_t word_size); |
451 virtual HeapWord* allocate_new_tlab(size_t word_size); |
453 |
452 |
454 virtual HeapWord* mem_allocate(size_t word_size, |
453 virtual HeapWord* mem_allocate(size_t word_size, |
455 bool* gc_overhead_limit_was_exceeded); |
454 bool* gc_overhead_limit_was_exceeded); |
456 |
455 |
457 // The following three methods take a gc_count_before_ret |
|
458 // parameter which is used to return the GC count if the method |
|
459 // returns NULL. Given that we are required to read the GC count |
|
460 // while holding the Heap_lock, and these paths will take the |
|
461 // Heap_lock at some point, it's easier to get them to read the GC |
|
462 // count while holding the Heap_lock before they return NULL instead |
|
463 // of the caller (namely: mem_allocate()) having to also take the |
|
464 // Heap_lock just to read the GC count. |
|
465 |
|
466 // First-level mutator allocation attempt: try to allocate out of |
456 // First-level mutator allocation attempt: try to allocate out of |
467 // the mutator alloc region without taking the Heap_lock. This |
457 // the mutator alloc region without taking the Heap_lock. This |
468 // should only be used for non-humongous allocations. |
458 // should only be used for non-humongous allocations. |
469 inline HeapWord* attempt_allocation(size_t word_size, |
459 inline HeapWord* attempt_allocation(size_t word_size); |
470 uint* gc_count_before_ret, |
|
471 uint* gclocker_retry_count_ret); |
|
472 |
460 |
473 // Second-level mutator allocation attempt: take the Heap_lock and |
461 // Second-level mutator allocation attempt: take the Heap_lock and |
474 // retry the allocation attempt, potentially scheduling a GC |
462 // retry the allocation attempt, potentially scheduling a GC |
475 // pause. This should only be used for non-humongous allocations. |
463 // pause. This should only be used for non-humongous allocations. |
476 HeapWord* attempt_allocation_slow(size_t word_size, |
464 HeapWord* attempt_allocation_slow(size_t word_size, |
477 AllocationContext_t context, |
465 AllocationContext_t context); |
478 uint* gc_count_before_ret, |
|
479 uint* gclocker_retry_count_ret); |
|
480 |
466 |
481 // Takes the Heap_lock and attempts a humongous allocation. It can |
467 // Takes the Heap_lock and attempts a humongous allocation. It can |
482 // potentially schedule a GC pause. |
468 // potentially schedule a GC pause. |
483 HeapWord* attempt_allocation_humongous(size_t word_size, |
469 HeapWord* attempt_allocation_humongous(size_t word_size); |
484 uint* gc_count_before_ret, |
|
485 uint* gclocker_retry_count_ret); |
|
486 |
470 |
487 // Allocation attempt that should be called during safepoints (e.g., |
471 // Allocation attempt that should be called during safepoints (e.g., |
488 // at the end of a successful GC). expect_null_mutator_alloc_region |
472 // at the end of a successful GC). expect_null_mutator_alloc_region |
489 // specifies whether the mutator alloc region is expected to be NULL |
473 // specifies whether the mutator alloc region is expected to be NULL |
490 // or not. |
474 // or not. |
1076 |
1060 |
1077 virtual bool is_maximal_no_gc() const { |
1061 virtual bool is_maximal_no_gc() const { |
1078 return _hrm.available() == 0; |
1062 return _hrm.available() == 0; |
1079 } |
1063 } |
1080 |
1064 |
|
1065 // Returns whether there are any regions left in the heap for allocation. |
|
1066 bool has_regions_left_for_allocation() const { |
|
1067 return !is_maximal_no_gc() || num_free_regions() != 0; |
|
1068 } |
|
1069 |
1081 // The current number of regions in the heap. |
1070 // The current number of regions in the heap. |
1082 uint num_regions() const { return _hrm.length(); } |
1071 uint num_regions() const { return _hrm.length(); } |
1083 |
1072 |
1084 // The max number of regions in the heap. |
1073 // The max number of regions in the heap. |
1085 uint max_regions() const { return _hrm.max_length(); } |
1074 uint max_regions() const { return _hrm.max_length(); } |