Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/z/zAttachedArray.inline.hpp
40961 views
1
/*
2
* Copyright (c) 2019, 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
#ifndef SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP
25
#define SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP
26
27
#include "gc/z/zAttachedArray.hpp"
28
29
#include "memory/allocation.hpp"
30
#include "utilities/align.hpp"
31
32
template <typename ObjectT, typename ArrayT>
33
inline size_t ZAttachedArray<ObjectT, ArrayT>::object_size() {
34
return align_up(sizeof(ObjectT), sizeof(ArrayT));
35
}
36
37
template <typename ObjectT, typename ArrayT>
38
inline size_t ZAttachedArray<ObjectT, ArrayT>::array_size(size_t length) {
39
return sizeof(ArrayT) * length;
40
}
41
42
template <typename ObjectT, typename ArrayT>
43
template <typename Allocator>
44
inline void* ZAttachedArray<ObjectT, ArrayT>::alloc(Allocator* allocator, size_t length) {
45
// Allocate memory for object and array
46
const size_t size = object_size() + array_size(length);
47
void* const addr = allocator->alloc(size);
48
49
// Placement new array
50
void* const array_addr = reinterpret_cast<char*>(addr) + object_size();
51
::new (array_addr) ArrayT[length];
52
53
// Return pointer to object
54
return addr;
55
}
56
57
template <typename ObjectT, typename ArrayT>
58
inline void* ZAttachedArray<ObjectT, ArrayT>::alloc(size_t length) {
59
struct Allocator {
60
void* alloc(size_t size) const {
61
return AllocateHeap(size, mtGC);
62
}
63
} allocator;
64
return alloc(&allocator, length);
65
}
66
67
template <typename ObjectT, typename ArrayT>
68
inline void ZAttachedArray<ObjectT, ArrayT>::free(ObjectT* obj) {
69
FreeHeap(obj);
70
}
71
72
template <typename ObjectT, typename ArrayT>
73
inline ZAttachedArray<ObjectT, ArrayT>::ZAttachedArray(size_t length) :
74
_length(length) {}
75
76
template <typename ObjectT, typename ArrayT>
77
inline size_t ZAttachedArray<ObjectT, ArrayT>::length() const {
78
return _length;
79
}
80
81
template <typename ObjectT, typename ArrayT>
82
inline ArrayT* ZAttachedArray<ObjectT, ArrayT>::operator()(const ObjectT* obj) const {
83
return reinterpret_cast<ArrayT*>(reinterpret_cast<uintptr_t>(obj) + object_size());
84
}
85
86
#endif // SHARE_GC_Z_ZATTACHEDARRAY_INLINE_HPP
87
88