Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/gc/z/zArray.inline.hpp
40961 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
#ifndef SHARE_GC_Z_ZARRAY_INLINE_HPP
25
#define SHARE_GC_Z_ZARRAY_INLINE_HPP
26
27
#include "gc/z/zArray.hpp"
28
29
#include "runtime/atomic.hpp"
30
31
template <typename T, bool Parallel>
32
inline bool ZArrayIteratorImpl<T, Parallel>::next_serial(T* elem) {
33
if (_next == _end) {
34
return false;
35
}
36
37
*elem = *_next;
38
_next++;
39
40
return true;
41
}
42
43
template <typename T, bool Parallel>
44
inline bool ZArrayIteratorImpl<T, Parallel>::next_parallel(T* elem) {
45
const T* old_next = Atomic::load(&_next);
46
47
for (;;) {
48
if (old_next == _end) {
49
return false;
50
}
51
52
const T* const new_next = old_next + 1;
53
const T* const prev_next = Atomic::cmpxchg(&_next, old_next, new_next);
54
if (prev_next == old_next) {
55
*elem = *old_next;
56
return true;
57
}
58
59
old_next = prev_next;
60
}
61
}
62
63
template <typename T, bool Parallel>
64
inline ZArrayIteratorImpl<T, Parallel>::ZArrayIteratorImpl(const T* array, size_t length) :
65
_next(array),
66
_end(array + length) {}
67
68
template <typename T, bool Parallel>
69
inline ZArrayIteratorImpl<T, Parallel>::ZArrayIteratorImpl(const ZArray<T>* array) :
70
ZArrayIteratorImpl<T, Parallel>(array->is_empty() ? NULL : array->adr_at(0), array->length()) {}
71
72
template <typename T, bool Parallel>
73
inline bool ZArrayIteratorImpl<T, Parallel>::next(T* elem) {
74
if (Parallel) {
75
return next_parallel(elem);
76
} else {
77
return next_serial(elem);
78
}
79
}
80
81
#endif // SHARE_GC_Z_ZARRAY_INLINE_HPP
82
83