apetushkov@9858: /* apetushkov@9858: * Copyright (c) 2014, 2018, Oracle and/or its affiliates. All rights reserved. apetushkov@9858: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. apetushkov@9858: * apetushkov@9858: * This code is free software; you can redistribute it and/or modify it apetushkov@9858: * under the terms of the GNU General Public License version 2 only, as apetushkov@9858: * published by the Free Software Foundation. apetushkov@9858: * apetushkov@9858: * This code is distributed in the hope that it will be useful, but WITHOUT apetushkov@9858: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or apetushkov@9858: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License apetushkov@9858: * version 2 for more details (a copy is included in the LICENSE file that apetushkov@9858: * accompanied this code). apetushkov@9858: * apetushkov@9858: * You should have received a copy of the GNU General Public License version apetushkov@9858: * 2 along with this work; if not, write to the Free Software Foundation, apetushkov@9858: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. apetushkov@9858: * apetushkov@9858: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA apetushkov@9858: * or visit www.oracle.com if you need additional information or have any apetushkov@9858: * questions. apetushkov@9858: * apetushkov@9858: */ apetushkov@9858: apetushkov@9858: #ifndef SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP apetushkov@9858: #define SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP apetushkov@9858: ddong@9885: #include "jfr/leakprofiler/chains/edge.hpp" apetushkov@9858: #include "jfr/utilities/jfrHashtable.hpp" apetushkov@9858: #include "memory/allocation.hpp" apetushkov@9858: apetushkov@9858: typedef u8 traceid; apetushkov@9858: ddong@9885: class StoredEdge : public Edge { apetushkov@9858: private: ddong@9885: mutable traceid _gc_root_id; ddong@9885: size_t _skip_length; apetushkov@9858: apetushkov@9858: public: ddong@9885: StoredEdge(); ddong@9885: StoredEdge(const Edge* parent, const oop* reference); ddong@9885: StoredEdge(const Edge& edge); ddong@9885: StoredEdge(const StoredEdge& edge); ddong@9885: void operator=(const StoredEdge& edge); apetushkov@9858: ddong@9885: traceid gc_root_id() const { return _gc_root_id; } ddong@9885: void set_gc_root_id(traceid root_id) const { _gc_root_id = root_id; } ddong@9885: ddong@9885: bool is_skip_edge() const { return _skip_length != 0; } apetushkov@9858: size_t skip_length() const { return _skip_length; } ddong@9885: void set_skip_length(size_t length) { _skip_length = length; } apetushkov@9858: ddong@9885: void set_parent(const Edge* edge) { this->_parent = edge; } ddong@9885: ddong@9885: StoredEdge* parent() const { ddong@9885: return const_cast(static_cast(Edge::parent())); apetushkov@9858: } apetushkov@9858: }; apetushkov@9858: apetushkov@9858: class EdgeStore : public CHeapObj { ddong@9885: typedef HashTableHost EdgeHashTable; apetushkov@9858: typedef EdgeHashTable::HashEntry EdgeEntry; apetushkov@9858: template class, apetushkov@9858: typename, apetushkov@9858: size_t> apetushkov@9858: friend class HashTableHost; ddong@9885: friend class EventEmitter; ddong@9885: friend class ObjectSampleWriter; ddong@9885: friend class ObjectSampleCheckpoint; apetushkov@9858: private: apetushkov@9858: static traceid _edge_id_counter; apetushkov@9858: EdgeHashTable* _edges; apetushkov@9858: apetushkov@9858: // Hash table callbacks apetushkov@9858: void assign_id(EdgeEntry* entry); apetushkov@9858: bool equals(const Edge& query, uintptr_t hash, const EdgeEntry* entry); apetushkov@9858: ddong@9885: StoredEdge* get(const oop* reference) const; ddong@9885: StoredEdge* put(const oop* reference); ddong@9885: traceid gc_root_id(const Edge* edge) const; ddong@9885: ddong@9885: bool put_edges(StoredEdge** previous, const Edge** current, size_t length); ddong@9885: bool put_skip_edge(StoredEdge** previous, const Edge** current, size_t distance_to_root); ddong@9885: void put_chain_epilogue(StoredEdge* leak_context_edge, const Edge* root) const; ddong@9885: ddong@9885: StoredEdge* associate_leak_context_with_candidate(const Edge* edge); ddong@9885: void store_gc_root_id_in_leak_context_edge(StoredEdge* leak_context_edge, const Edge* root) const; ddong@9885: StoredEdge* link_new_edge(StoredEdge** previous, const Edge** current); ddong@9885: void link_with_existing_chain(const StoredEdge* current_stored, StoredEdge** previous, size_t previous_length); ddong@9885: ddong@9885: template ddong@9885: void iterate(T& functor) const { _edges->iterate_value(functor); } ddong@9885: ddong@9885: DEBUG_ONLY(bool contains(const oop* reference) const;) apetushkov@9858: apetushkov@9858: public: apetushkov@9858: EdgeStore(); apetushkov@9858: ~EdgeStore(); apetushkov@9858: apetushkov@9858: bool is_empty() const; apetushkov@9858: traceid get_id(const Edge* edge) const; ddong@9885: void put_chain(const Edge* chain, size_t length); apetushkov@9858: }; apetushkov@9858: apetushkov@9858: #endif // SHARE_VM_LEAKPROFILER_CHAINS_EDGESTORE_HPP