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_RECORDER_STORAGE_JFRFULLSTORAGE_HPP 26 #define SHARE_JFR_RECORDER_STORAGE_JFRFULLSTORAGE_HPP 27 28 #include "jfr/utilities/jfrAllocation.hpp" 29 #include "jfr/utilities/jfrConcurrentQueue.hpp" 30 31 class JfrStorageControl; 32 33 /* 34 * For full storage management. 35 * 36 * In essence, full storage is added to a FIFO queue, where the insertion order 37 * is used to represent the "is older" relation. Removes oldest data first. 38 * 39 * FullType the type of the data value to be stored in the list. 40 * 41 * NodeType template class for the node to store a value of FullType. 42 * 43 * AllocPolicy memory alloction. 44 */ 45 template <typename FullType, template <typename> class NodeType, typename AllocPolicy = JfrCHeapObj> 46 class JfrFullStorage : public AllocPolicy { 47 public: 48 typedef FullType Value; 49 typedef NodeType<Value>* NodePtr; 50 typedef NodeType<Value> Node; 51 JfrFullStorage(JfrStorageControl& control); 52 ~JfrFullStorage(); 53 bool initialize(size_t free_list_prealloc_count); 54 bool is_empty() const; 55 bool is_nonempty() const; 56 bool add(Value value); 57 Value remove(); 58 template <typename Callback> 59 void iterate(Callback& cb); 60 private: 61 JfrStorageControl& _control; 62 JfrConcurrentQueue<Node, AllocPolicy>* _free_node_list; 63 JfrConcurrentQueue<Node, AllocPolicy>* _queue; 64 NodePtr acquire(); 65 void release(NodePtr node); 66 }; 67 68 #endif // SHARE_JFR_RECORDER_STORAGE_JFRFULLSTORAGE_HPP 69