Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/jdk17u
Path: blob/master/src/hotspot/share/gc/g1/g1Allocator.inline.hpp
66644 views
1
/*
2
* Copyright (c) 2015, 2020, 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
*
23
*/
24
25
#ifndef SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP
26
#define SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP
27
28
#include "gc/g1/g1Allocator.hpp"
29
30
#include "gc/g1/g1AllocRegion.inline.hpp"
31
#include "gc/shared/plab.inline.hpp"
32
#include "memory/universe.hpp"
33
34
inline uint G1Allocator::current_node_index() const {
35
return _numa->index_of_current_thread();
36
}
37
38
inline MutatorAllocRegion* G1Allocator::mutator_alloc_region(uint node_index) {
39
assert(node_index < _num_alloc_regions, "Invalid index: %u", node_index);
40
return &_mutator_alloc_regions[node_index];
41
}
42
43
inline SurvivorGCAllocRegion* G1Allocator::survivor_gc_alloc_region(uint node_index) {
44
assert(node_index < _num_alloc_regions, "Invalid index: %u", node_index);
45
return &_survivor_gc_alloc_regions[node_index];
46
}
47
48
inline OldGCAllocRegion* G1Allocator::old_gc_alloc_region() {
49
return &_old_gc_alloc_region;
50
}
51
52
inline HeapWord* G1Allocator::attempt_allocation(size_t min_word_size,
53
size_t desired_word_size,
54
size_t* actual_word_size) {
55
uint node_index = current_node_index();
56
57
HeapWord* result = mutator_alloc_region(node_index)->attempt_retained_allocation(min_word_size, desired_word_size, actual_word_size);
58
if (result != NULL) {
59
return result;
60
}
61
62
return mutator_alloc_region(node_index)->attempt_allocation(min_word_size, desired_word_size, actual_word_size);
63
}
64
65
inline HeapWord* G1Allocator::attempt_allocation_using_new_region(size_t word_size) {
66
uint node_index = current_node_index();
67
size_t temp;
68
HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_using_new_region(word_size, word_size, &temp);
69
assert(result != NULL || mutator_alloc_region(node_index)->get() == NULL,
70
"Must not have a mutator alloc region if there is no memory, but is " PTR_FORMAT,
71
p2i(mutator_alloc_region(node_index)->get()));
72
return result;
73
}
74
75
inline HeapWord* G1Allocator::attempt_allocation_locked(size_t word_size) {
76
uint node_index = current_node_index();
77
HeapWord* result = mutator_alloc_region(node_index)->attempt_allocation_locked(word_size);
78
79
assert(result != NULL || mutator_alloc_region(node_index)->get() == NULL,
80
"Must not have a mutator alloc region if there is no memory, but is " PTR_FORMAT, p2i(mutator_alloc_region(node_index)->get()));
81
return result;
82
}
83
84
inline HeapWord* G1Allocator::attempt_allocation_force(size_t word_size) {
85
uint node_index = current_node_index();
86
return mutator_alloc_region(node_index)->attempt_allocation_force(word_size);
87
}
88
89
inline PLAB* G1PLABAllocator::alloc_buffer(G1HeapRegionAttr dest, uint node_index) const {
90
assert(dest.is_valid(),
91
"Allocation buffer index out of bounds: %s", dest.get_type_str());
92
assert(_alloc_buffers[dest.type()] != NULL,
93
"Allocation buffer is NULL: %s", dest.get_type_str());
94
return alloc_buffer(dest.type(), node_index);
95
}
96
97
inline PLAB* G1PLABAllocator::alloc_buffer(region_type_t dest, uint node_index) const {
98
assert(dest < G1HeapRegionAttr::Num,
99
"Allocation buffer index out of bounds: %u", dest);
100
101
if (dest == G1HeapRegionAttr::Young) {
102
assert(node_index < alloc_buffers_length(dest),
103
"Allocation buffer index out of bounds: %u, %u", dest, node_index);
104
return _alloc_buffers[dest][node_index];
105
} else {
106
return _alloc_buffers[dest][0];
107
}
108
}
109
110
inline uint G1PLABAllocator::alloc_buffers_length(region_type_t dest) const {
111
if (dest == G1HeapRegionAttr::Young) {
112
return _allocator->num_nodes();
113
} else {
114
return 1;
115
}
116
}
117
118
inline HeapWord* G1PLABAllocator::plab_allocate(G1HeapRegionAttr dest,
119
size_t word_sz,
120
uint node_index) {
121
PLAB* buffer = alloc_buffer(dest, node_index);
122
return buffer->allocate(word_sz);
123
}
124
125
inline HeapWord* G1PLABAllocator::allocate(G1HeapRegionAttr dest,
126
size_t word_sz,
127
bool* refill_failed,
128
uint node_index) {
129
HeapWord* const obj = plab_allocate(dest, word_sz, node_index);
130
if (obj != NULL) {
131
return obj;
132
}
133
return allocate_direct_or_new_plab(dest, word_sz, refill_failed, node_index);
134
}
135
136
#endif // SHARE_GC_G1_G1ALLOCATOR_INLINE_HPP
137
138