Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/utilities/jfrEpochQueue.inline.hpp
41149 views
1
/*
2
* Copyright (c) 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_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP
26
#define SHARE_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP
27
28
#include "jfr/utilities/jfrEpochQueue.hpp"
29
30
#include "jfr/recorder/storage/jfrEpochStorage.inline.hpp"
31
#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp"
32
#include "runtime/thread.inline.hpp"
33
34
template <template <typename> class ElementPolicy>
35
JfrEpochQueue<ElementPolicy>::JfrEpochQueue() : _policy(), _storage(NULL) {}
36
37
template <template <typename> class ElementPolicy>
38
JfrEpochQueue<ElementPolicy>::~JfrEpochQueue() {
39
delete _storage;
40
}
41
42
template <template <typename> class ElementPolicy>
43
bool JfrEpochQueue<ElementPolicy>::initialize(size_t min_buffer_size, size_t free_list_cache_count_limit, size_t cache_prealloc_count) {
44
assert(_storage == NULL, "invariant");
45
_storage = new JfrEpochStorage();
46
return _storage != NULL && _storage->initialize(min_buffer_size, free_list_cache_count_limit, cache_prealloc_count);
47
}
48
49
template <template <typename> class ElementPolicy>
50
inline typename JfrEpochQueue<ElementPolicy>::BufferPtr
51
JfrEpochQueue<ElementPolicy>::storage_for_element(JfrEpochQueue<ElementPolicy>::TypePtr t, size_t element_size) {
52
assert(_policy.element_size(t) == element_size, "invariant");
53
Thread* const thread = Thread::current();
54
BufferPtr buffer = _policy.thread_local_storage(thread);
55
if (buffer == NULL) {
56
buffer = _storage->acquire(element_size, thread);
57
_policy.set_thread_local_storage(buffer, thread);
58
} else if (buffer->free_size() < element_size) {
59
_storage->release(buffer);
60
buffer = _storage->acquire(element_size, thread);
61
_policy.set_thread_local_storage(buffer, thread);
62
}
63
assert(buffer->free_size() >= element_size, "invariant");
64
assert(_policy.thread_local_storage(thread) == buffer, "invariant");
65
return buffer;
66
}
67
68
template <template <typename> class ElementPolicy>
69
void JfrEpochQueue<ElementPolicy>::enqueue(JfrEpochQueue<ElementPolicy>::TypePtr t) {
70
assert(t != NULL, "invariant");
71
static size_t element_size = _policy.element_size(t);
72
BufferPtr buffer = storage_for_element(t, element_size);
73
assert(buffer != NULL, "invariant");
74
_policy.store_element(t, buffer);
75
buffer->set_pos(element_size);
76
}
77
78
template <template <typename> class ElementPolicy>
79
template <typename Callback>
80
JfrEpochQueue<ElementPolicy>::ElementDispatch<Callback>::ElementDispatch(Callback& callback, JfrEpochQueue<ElementPolicy>::Policy& policy) :
81
_callback(callback),_policy(policy) {}
82
83
template <template <typename> class ElementPolicy>
84
template <typename Callback>
85
size_t JfrEpochQueue<ElementPolicy>::ElementDispatch<Callback>::operator()(const u1* element, bool previous_epoch) {
86
assert(element != NULL, "invariant");
87
return _policy(element, _callback, previous_epoch);
88
}
89
90
template <template <typename> class ElementPolicy>
91
template <typename Callback>
92
void JfrEpochQueue<ElementPolicy>::iterate(Callback& callback, bool previous_epoch) {
93
typedef ElementDispatch<Callback> ElementDispatcher;
94
typedef EpochDispatchOp<ElementDispatcher> QueueDispatcher;
95
ElementDispatcher element_dispatcher(callback, _policy);
96
QueueDispatcher dispatch(element_dispatcher, previous_epoch);
97
_storage->iterate(dispatch, previous_epoch);
98
DEBUG_ONLY(_storage->verify_previous_empty();)
99
}
100
101
#endif // SHARE_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP
102
103