Path: blob/master/src/hotspot/share/jfr/leakprofiler/chains/edgeQueue.cpp
41153 views
/*1* Copyright (c) 2014, 2018, 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#include "precompiled.hpp"25#include "jfr/leakprofiler/chains/edgeQueue.hpp"26#include "jfr/leakprofiler/utilities/unifiedOopRef.inline.hpp"27#include "jfr/recorder/storage/jfrVirtualMemory.hpp"2829EdgeQueue::EdgeQueue(size_t reservation_size_bytes, size_t commit_block_size_bytes) :30_vmm(NULL),31_reservation_size_bytes(reservation_size_bytes),32_commit_block_size_bytes(commit_block_size_bytes),33_top_index(0),34_bottom_index(0) {35}3637bool EdgeQueue::initialize() {38assert(_reservation_size_bytes >= _commit_block_size_bytes, "invariant");39assert(_vmm == NULL, "invariant");40_vmm = new JfrVirtualMemory();41return _vmm != NULL && _vmm->initialize(_reservation_size_bytes, _commit_block_size_bytes, sizeof(Edge));42}4344EdgeQueue::~EdgeQueue() {45delete _vmm;46}4748void EdgeQueue::add(const Edge* parent, UnifiedOopRef ref) {49assert(!ref.is_null(), "Null objects not allowed in EdgeQueue");50assert(!is_full(), "EdgeQueue is full. Check is_full before adding another Edge");51assert(!_vmm->is_full(), "invariant");52void* const allocation = _vmm->new_datum();53assert(allocation != NULL, "invariant");54new (allocation)Edge(parent, ref);55_top_index++;56assert(_vmm->count() == _top_index, "invariant");57}5859size_t EdgeQueue::top() const {60return _top_index;61}6263size_t EdgeQueue::bottom() const {64return EdgeQueue::_bottom_index;65}6667bool EdgeQueue::is_empty() const {68return _top_index == _bottom_index;69}7071bool EdgeQueue::is_full() const {72return _vmm->is_full();73}7475const Edge* EdgeQueue::remove() const {76assert(!is_empty(), "EdgeQueue is empty. Check if empty before removing Edge");77assert(!_vmm->is_empty(), "invariant");78return (const Edge*)_vmm->get(_bottom_index++);79}8081const Edge* EdgeQueue::element_at(size_t index) const {82assert(index >= _bottom_index, "invariant");83assert(index <_top_index, "invariant");84return (Edge*)_vmm->get(index);85}8687size_t EdgeQueue::reserved_size() const {88assert(_vmm != NULL, "invariant");89return _vmm->reserved_size();90}9192size_t EdgeQueue::live_set() const {93assert(_vmm != NULL, "invariant");94return _vmm->live_set();95}9697size_t EdgeQueue::sizeof_edge() const {98assert(_vmm != NULL, "invariant");99return _vmm->aligned_datum_size_bytes();100}101102103