Path: blob/master/src/hotspot/share/jfr/utilities/jfrNode.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_JFRNODE_HPP25#define SHARE_JFR_UTILITIES_JFRNODE_HPP2627#include "jfr/utilities/jfrTypes.hpp"28#include "memory/allocation.hpp"29#include "runtime/atomic.hpp"3031const uint64_t JFR_NODE_LOGICAL_EXCISION_BIT = 1;32const uint64_t JFR_NODE_LOGICAL_INSERTION_BIT = 2;33const uint64_t JFR_NODE_MASK = ~(JFR_NODE_LOGICAL_INSERTION_BIT | JFR_NODE_LOGICAL_EXCISION_BIT);3435template <typename Node>36inline bool cas(Node** address, Node* current, Node* exchange) {37return Atomic::cmpxchg(address, current, exchange) == current;38}3940template <typename Node>41inline bool is_marked_for_removal(const Node* ptr) {42return ((uint64_t)ptr & JFR_NODE_LOGICAL_EXCISION_BIT) == JFR_NODE_LOGICAL_EXCISION_BIT;43}4445template <typename Node>46inline bool is_marked_for_insertion(const Node* ptr) {47return ((uint64_t)ptr & JFR_NODE_LOGICAL_INSERTION_BIT) == JFR_NODE_LOGICAL_INSERTION_BIT;48}4950template <typename Node>51inline Node* set_excision_bit(const Node* ptr) {52return (Node*)(((uint64_t)ptr) | JFR_NODE_LOGICAL_EXCISION_BIT);53}5455template <typename Node>56inline Node* set_insertion_bit(const Node* ptr) {57return (Node*)(((uint64_t)ptr) | JFR_NODE_LOGICAL_INSERTION_BIT);58}5960template <typename Node>61inline Node* unmask(const Node* ptr) {62return (Node*)(((uint64_t)ptr) & JFR_NODE_MASK);63}6465template <typename Derived, typename Version = traceid>66class JfrLinkedNode : public ResourceObj {67public:68typedef Version VersionType;69Derived* _next;70JfrLinkedNode() : _next(NULL) {}71JfrLinkedNode(JfrLinkedNode<Derived, VersionType>* next) : _next(next) {}72};7374template <typename V>75class JfrKeyIsThisNode : public JfrLinkedNode<JfrKeyIsThisNode<V> > {76private:77V _value;78public:79typedef V Value;80typedef const JfrKeyIsThisNode<V>* Key;81JfrKeyIsThisNode(const Value value = NULL) : JfrLinkedNode<JfrKeyIsThisNode<V> >(), _value(value) {}82Key key() const { return this; }83Value value() const { return _value; }84void set_value(Value value) { _value = value; }85};8687template <typename V>88class JfrValueNode : public JfrLinkedNode<JfrValueNode<V> > {89private:90V _value;91public:92typedef V Value;93typedef Value Key;94JfrValueNode(const Value value = NULL) : JfrLinkedNode<JfrValueNode<V> >(), _value(value) {}95Key key() const { return value(); }96Value value() const { return _value; }97void set_value(Value value) { _value = value; }98};99100template <typename V>101class JfrKeyIsFreeSizeNode : public JfrLinkedNode<JfrKeyIsFreeSizeNode<V> > {102private:103V _value;104public:105typedef V Value;106typedef size_t Key;107JfrKeyIsFreeSizeNode(const Value value = NULL) : JfrLinkedNode<JfrKeyIsFreeSizeNode<V> >(), _value(value) {}108Key key() const { return value()->free_size(); }109Value value() const { return _value; }110void set_value(Value value) { _value = value; }111};112113#endif // SHARE_JFR_UTILITIES_JFRNODE_HPP114115116