Path: blob/master/src/hotspot/share/jfr/utilities/jfrEpochQueue.hpp
41152 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_HPP25#define SHARE_JFR_UTILITIES_JFREPOCHQUEUE_HPP2627#include "jfr/recorder/storage/jfrEpochStorage.hpp"2829/*30* An ElmentPolicy template template argument provides the implementation for how elements31* associated with the queue is encoded and managed by exposing the following members:32*33* ElmentPolicy::Type the type of the element to be stored in the queue.34* size_t element_size(Type* t); per element storage size requirement.35* void store_element(Type* t, Buffer* buffer); encode and store element of Type into storage of type Buffer.36* Buffer* thread_local_storage(Thread* thread); quick access to thread local storage.37* void set_thread_lcoal_storage(Buffer* buffer, Thread* thread); store back capability for newly acquired storage.38*39* The ElementPolicy is also the callback when iterating elements of the queue.40* The iteration callback signature to be provided by the policy class:41*42* size_t operator()(const u1* next_element, Callback& callback, bool previous_epoch = false);43*/44template <template <typename> class ElementPolicy>45class JfrEpochQueue : public JfrCHeapObj {46public:47typedef JfrEpochStorage::Buffer Buffer;48typedef JfrEpochStorage::BufferPtr BufferPtr;49typedef typename ElementPolicy<Buffer>::Type Type;50typedef const Type* TypePtr;51JfrEpochQueue();52~JfrEpochQueue();53bool initialize(size_t min_buffer_size, size_t free_list_cache_count_limit, size_t cache_prealloc_count);54void enqueue(TypePtr t);55template <typename Callback>56void iterate(Callback& callback, bool previous_epoch = false);57private:58typedef ElementPolicy<Buffer> Policy;59Policy _policy;60JfrEpochStorage* _storage;61BufferPtr storage_for_element(TypePtr t, size_t element_size);6263template <typename Callback>64class ElementDispatch {65private:66Callback& _callback;67Policy& _policy;68public:69typedef Buffer Type;70ElementDispatch(Callback& callback, Policy& policy);71size_t operator()(const u1* element, bool previous_epoch);72};73};7475#endif // SHARE_JFR_UTILITIES_JFREPOCHQUEUE_HPP767778