Path: blob/master/src/hotspot/share/jfr/utilities/jfrEpochQueue.inline.hpp
41149 views
/*1* Copyright (c) 2020, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP25#define SHARE_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP2627#include "jfr/utilities/jfrEpochQueue.hpp"2829#include "jfr/recorder/storage/jfrEpochStorage.inline.hpp"30#include "jfr/recorder/storage/jfrStorageUtils.inline.hpp"31#include "runtime/thread.inline.hpp"3233template <template <typename> class ElementPolicy>34JfrEpochQueue<ElementPolicy>::JfrEpochQueue() : _policy(), _storage(NULL) {}3536template <template <typename> class ElementPolicy>37JfrEpochQueue<ElementPolicy>::~JfrEpochQueue() {38delete _storage;39}4041template <template <typename> class ElementPolicy>42bool JfrEpochQueue<ElementPolicy>::initialize(size_t min_buffer_size, size_t free_list_cache_count_limit, size_t cache_prealloc_count) {43assert(_storage == NULL, "invariant");44_storage = new JfrEpochStorage();45return _storage != NULL && _storage->initialize(min_buffer_size, free_list_cache_count_limit, cache_prealloc_count);46}4748template <template <typename> class ElementPolicy>49inline typename JfrEpochQueue<ElementPolicy>::BufferPtr50JfrEpochQueue<ElementPolicy>::storage_for_element(JfrEpochQueue<ElementPolicy>::TypePtr t, size_t element_size) {51assert(_policy.element_size(t) == element_size, "invariant");52Thread* const thread = Thread::current();53BufferPtr buffer = _policy.thread_local_storage(thread);54if (buffer == NULL) {55buffer = _storage->acquire(element_size, thread);56_policy.set_thread_local_storage(buffer, thread);57} else if (buffer->free_size() < element_size) {58_storage->release(buffer);59buffer = _storage->acquire(element_size, thread);60_policy.set_thread_local_storage(buffer, thread);61}62assert(buffer->free_size() >= element_size, "invariant");63assert(_policy.thread_local_storage(thread) == buffer, "invariant");64return buffer;65}6667template <template <typename> class ElementPolicy>68void JfrEpochQueue<ElementPolicy>::enqueue(JfrEpochQueue<ElementPolicy>::TypePtr t) {69assert(t != NULL, "invariant");70static size_t element_size = _policy.element_size(t);71BufferPtr buffer = storage_for_element(t, element_size);72assert(buffer != NULL, "invariant");73_policy.store_element(t, buffer);74buffer->set_pos(element_size);75}7677template <template <typename> class ElementPolicy>78template <typename Callback>79JfrEpochQueue<ElementPolicy>::ElementDispatch<Callback>::ElementDispatch(Callback& callback, JfrEpochQueue<ElementPolicy>::Policy& policy) :80_callback(callback),_policy(policy) {}8182template <template <typename> class ElementPolicy>83template <typename Callback>84size_t JfrEpochQueue<ElementPolicy>::ElementDispatch<Callback>::operator()(const u1* element, bool previous_epoch) {85assert(element != NULL, "invariant");86return _policy(element, _callback, previous_epoch);87}8889template <template <typename> class ElementPolicy>90template <typename Callback>91void JfrEpochQueue<ElementPolicy>::iterate(Callback& callback, bool previous_epoch) {92typedef ElementDispatch<Callback> ElementDispatcher;93typedef EpochDispatchOp<ElementDispatcher> QueueDispatcher;94ElementDispatcher element_dispatcher(callback, _policy);95QueueDispatcher dispatch(element_dispatcher, previous_epoch);96_storage->iterate(dispatch, previous_epoch);97DEBUG_ONLY(_storage->verify_previous_empty();)98}99100#endif // SHARE_JFR_UTILITIES_JFREPOCHQUEUE_INLINE_HPP101102103