Path: blob/master/src/hotspot/share/jfr/utilities/jfrRelation.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_JFRRELATION_HPP25#define SHARE_JFR_UTILITIES_JFRRELATION_HPP2627#include "jfr/utilities/jfrNode.hpp"28#include "jfr/utilities/jfrTypes.hpp"2930inline int compare_traceid(const traceid& lhs, const traceid& rhs) {31return lhs > rhs ? 1 : (lhs < rhs) ? -1 : 0;32}3334inline int sort_traceid(traceid* lhs, traceid* rhs) {35return compare_traceid(*lhs, *rhs);36}3738class Klass;3940inline int compare_klasses(const Klass*const& lhs, const Klass*const& rhs) {41return lhs > rhs ? 1 : (lhs < rhs) ? -1 : 0;42}4344inline int sort_klasses(const Klass* lhs, const Klass* rhs) {45return compare_klasses(lhs, rhs);46}4748template <typename Node>49class LessThan {50private:51typename Node::Key _key;52public:53LessThan(typename Node::Key key) : _key(key) {}54bool operator()(const Node* node) { return node->key() < _key; }55};5657template <typename Node>58class GreaterThan {59private:60typename Node::Key _key;61public:62GreaterThan(typename Node::Key key) : _key(key) {}63bool operator()(const Node* node) { return node->key() > _key; }64};6566/*67* Using a contradiction as a search predicate amounts68* to using the physical order of the list (key is neglected).69* [LessThan relation -> Ascending order ] -> the minimal element.70* [GreaterThan relation -> Descending order] -> the maximal element.71*/72template <typename Node>73class HeadNode {74public:75HeadNode(const Node* node = NULL) {}76bool operator()(const Node* current, const Node* next) {77return is_marked_for_removal(next);78}79};8081/*82* Using a tautology as a search predicate amounts83* to using the physical store order of the list (key is neglected).84* [LessThan relation -> Ascending order ] -> the maximal element.85* [GreaterThan relation -> Descending order] -> the minimal element.86*/87template <typename Node>88class LastNode {89public:90LastNode(const Node* node = NULL) {}91bool operator()(const Node* current, const Node* next ) {92return true;93}94};9596template <typename Node>97class Identity {98private:99const Node* _target;100bool _found;101public:102Identity(const Node* node = NULL) : _target(node), _found(false) {}103bool operator()(const Node* current, const Node* next) {104assert(current != NULL, "invariant");105assert(next != NULL, "invariant");106if (!_found && current == _target) {107_found = true;108}109return is_marked_for_removal(next) || !_found;110}111};112113#endif // SHARE_JFR_UTILITIES_JFRRELATION_HPP114115116