Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/g1/g1AllocRegion.inline.hpp
40960 views
1
/*
2
* Copyright (c) 2011, 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
*
23
*/
24
25
#ifndef SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP
26
#define SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP
27
28
#include "gc/g1/g1AllocRegion.hpp"
29
30
#include "gc/g1/heapRegion.inline.hpp"
31
32
#define assert_alloc_region(p, message) \
33
do { \
34
assert((p), "[%s] %s c: %u b: %s r: " PTR_FORMAT " u: " SIZE_FORMAT, \
35
_name, (message), _count, BOOL_TO_STR(_bot_updates), \
36
p2i(_alloc_region), _used_bytes_before); \
37
} while (0)
38
39
40
inline void G1AllocRegion::reset_alloc_region() {
41
_alloc_region = _dummy_region;
42
}
43
44
inline HeapWord* G1AllocRegion::allocate(HeapRegion* alloc_region,
45
size_t word_size) {
46
assert(alloc_region != NULL, "pre-condition");
47
48
if (!_bot_updates) {
49
return alloc_region->allocate_no_bot_updates(word_size);
50
} else {
51
return alloc_region->allocate(word_size);
52
}
53
}
54
55
inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region, size_t word_size) {
56
size_t temp;
57
return par_allocate(alloc_region, word_size, word_size, &temp);
58
}
59
60
inline HeapWord* G1AllocRegion::par_allocate(HeapRegion* alloc_region,
61
size_t min_word_size,
62
size_t desired_word_size,
63
size_t* actual_word_size) {
64
assert(alloc_region != NULL, "pre-condition");
65
assert(!alloc_region->is_empty(), "pre-condition");
66
67
if (!_bot_updates) {
68
return alloc_region->par_allocate_no_bot_updates(min_word_size, desired_word_size, actual_word_size);
69
} else {
70
return alloc_region->par_allocate(min_word_size, desired_word_size, actual_word_size);
71
}
72
}
73
74
inline HeapWord* G1AllocRegion::attempt_allocation(size_t word_size) {
75
size_t temp;
76
return attempt_allocation(word_size, word_size, &temp);
77
}
78
79
inline HeapWord* G1AllocRegion::attempt_allocation(size_t min_word_size,
80
size_t desired_word_size,
81
size_t* actual_word_size) {
82
HeapRegion* alloc_region = _alloc_region;
83
assert_alloc_region(alloc_region != NULL, "not initialized properly");
84
85
HeapWord* result = par_allocate(alloc_region, min_word_size, desired_word_size, actual_word_size);
86
if (result != NULL) {
87
trace("alloc", min_word_size, desired_word_size, *actual_word_size, result);
88
return result;
89
}
90
trace("alloc failed", min_word_size, desired_word_size);
91
return NULL;
92
}
93
94
inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t word_size) {
95
size_t temp;
96
return attempt_allocation_locked(word_size, word_size, &temp);
97
}
98
99
inline HeapWord* G1AllocRegion::attempt_allocation_locked(size_t min_word_size,
100
size_t desired_word_size,
101
size_t* actual_word_size) {
102
// First we have to redo the allocation, assuming we're holding the
103
// appropriate lock, in case another thread changed the region while
104
// we were waiting to get the lock.
105
HeapWord* result = attempt_allocation(min_word_size, desired_word_size, actual_word_size);
106
if (result != NULL) {
107
return result;
108
}
109
110
retire(true /* fill_up */);
111
result = new_alloc_region_and_allocate(desired_word_size, false /* force */);
112
if (result != NULL) {
113
*actual_word_size = desired_word_size;
114
trace("alloc locked (second attempt)", min_word_size, desired_word_size, *actual_word_size, result);
115
return result;
116
}
117
trace("alloc locked failed", min_word_size, desired_word_size);
118
return NULL;
119
}
120
121
inline HeapWord* G1AllocRegion::attempt_allocation_force(size_t word_size) {
122
assert_alloc_region(_alloc_region != NULL, "not initialized properly");
123
124
trace("forcing alloc", word_size, word_size);
125
HeapWord* result = new_alloc_region_and_allocate(word_size, true /* force */);
126
if (result != NULL) {
127
trace("alloc forced", word_size, word_size, word_size, result);
128
return result;
129
}
130
trace("alloc forced failed", word_size, word_size);
131
return NULL;
132
}
133
134
inline HeapWord* MutatorAllocRegion::attempt_retained_allocation(size_t min_word_size,
135
size_t desired_word_size,
136
size_t* actual_word_size) {
137
if (_retained_alloc_region != NULL) {
138
HeapWord* result = par_allocate(_retained_alloc_region, min_word_size, desired_word_size, actual_word_size);
139
if (result != NULL) {
140
trace("alloc retained", min_word_size, desired_word_size, *actual_word_size, result);
141
return result;
142
}
143
}
144
return NULL;
145
}
146
147
#endif // SHARE_GC_G1_G1ALLOCREGION_INLINE_HPP
148
149