1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/src/share/vm/jfr/leakprofiler/chains/edgeStore.hpp Mon Aug 12 18:30:40 2019 +0300 1.3 @@ -0,0 +1,119 @@ 1.4 +/* 1.5 + * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. 1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.7 + * 1.8 + * This code is free software; you can redistribute it and/or modify it 1.9 + * under the terms of the GNU General Public License version 2 only, as 1.10 + * published by the Free Software Foundation. 1.11 + * 1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT 1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 1.14 + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 1.15 + * version 2 for more details (a copy is included in the LICENSE file that 1.16 + * accompanied this code). 1.17 + * 1.18 + * You should have received a copy of the GNU General Public License version 1.19 + * 2 along with this work; if not, write to the Free Software Foundation, 1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 1.21 + * 1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 1.23 + * or visit www.oracle.com if you need additional information or have any 1.24 + * questions. 1.25 + * 1.26 + */ 1.27 + 1.28 +#ifndef SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP 1.29 +#define SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP 1.30 + 1.31 +#include "jfr/utilities/jfrHashtable.hpp" 1.32 +#include "jfr/leakprofiler/chains/edge.hpp" 1.33 +#include "memory/allocation.hpp" 1.34 + 1.35 +typedef u8 traceid; 1.36 + 1.37 +class RoutableEdge : public Edge { 1.38 + private: 1.39 + mutable const RoutableEdge* _skip_edge; 1.40 + mutable size_t _skip_length; 1.41 + mutable bool _processed; 1.42 + 1.43 + public: 1.44 + RoutableEdge(); 1.45 + RoutableEdge(const Edge* parent, const oop* reference); 1.46 + RoutableEdge(const Edge& edge); 1.47 + RoutableEdge(const RoutableEdge& edge); 1.48 + void operator=(const RoutableEdge& edge); 1.49 + 1.50 + const RoutableEdge* skip_edge() const { return _skip_edge; } 1.51 + size_t skip_length() const { return _skip_length; } 1.52 + 1.53 + bool is_skip_edge() const { return _skip_edge != NULL; } 1.54 + bool processed() const { return _processed; } 1.55 + bool is_sentinel() const { 1.56 + return _skip_edge == NULL && _skip_length == 1; 1.57 + } 1.58 + 1.59 + void set_skip_edge(const RoutableEdge* edge) const { 1.60 + assert(!is_skip_edge(), "invariant"); 1.61 + assert(edge != this, "invariant"); 1.62 + _skip_edge = edge; 1.63 + } 1.64 + 1.65 + void set_skip_length(size_t length) const { 1.66 + _skip_length = length; 1.67 + } 1.68 + 1.69 + void set_processed() const { 1.70 + assert(!_processed, "invariant"); 1.71 + _processed = true; 1.72 + } 1.73 + 1.74 + // true navigation according to physical tree representation 1.75 + const RoutableEdge* physical_parent() const { 1.76 + return static_cast<const RoutableEdge*>(parent()); 1.77 + } 1.78 + 1.79 + // logical navigation taking skip levels into account 1.80 + const RoutableEdge* logical_parent() const { 1.81 + return is_skip_edge() ? skip_edge() : physical_parent(); 1.82 + } 1.83 + 1.84 + size_t logical_distance_to_root() const; 1.85 +}; 1.86 + 1.87 +class EdgeStore : public CHeapObj<mtTracing> { 1.88 + typedef HashTableHost<RoutableEdge, traceid, Entry, EdgeStore> EdgeHashTable; 1.89 + typedef EdgeHashTable::HashEntry EdgeEntry; 1.90 + template <typename, 1.91 + typename, 1.92 + template<typename, typename> class, 1.93 + typename, 1.94 + size_t> 1.95 + friend class HashTableHost; 1.96 + private: 1.97 + static traceid _edge_id_counter; 1.98 + EdgeHashTable* _edges; 1.99 + 1.100 + // Hash table callbacks 1.101 + void assign_id(EdgeEntry* entry); 1.102 + bool equals(const Edge& query, uintptr_t hash, const EdgeEntry* entry); 1.103 + 1.104 + const Edge* get_edge(const Edge* edge) const; 1.105 + const Edge* put(const Edge* edge); 1.106 + 1.107 + public: 1.108 + EdgeStore(); 1.109 + ~EdgeStore(); 1.110 + 1.111 + void add_chain(const Edge* chain, size_t length); 1.112 + bool is_empty() const; 1.113 + size_t number_of_entries() const; 1.114 + 1.115 + traceid get_id(const Edge* edge) const; 1.116 + traceid get_root_id(const Edge* edge) const; 1.117 + 1.118 + template <typename T> 1.119 + void iterate_edges(T& functor) const { _edges->iterate_value<T>(functor); } 1.120 +}; 1.121 + 1.122 +#endif // SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP