Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/leakprofiler/chains/edgeQueue.cpp
38922 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/recorder/storage/jfrVirtualMemory.hpp"2728EdgeQueue::EdgeQueue(size_t reservation_size_bytes, size_t commit_block_size_bytes) :29_vmm(NULL),30_reservation_size_bytes(reservation_size_bytes),31_commit_block_size_bytes(commit_block_size_bytes),32_top_index(0),33_bottom_index(0) {34}3536bool EdgeQueue::initialize() {37assert(_reservation_size_bytes >= _commit_block_size_bytes, "invariant");38assert(_vmm == NULL, "invariant");39_vmm = new JfrVirtualMemory();40return _vmm != NULL && _vmm->initialize(_reservation_size_bytes, _commit_block_size_bytes, sizeof(Edge));41}4243EdgeQueue::~EdgeQueue() {44delete _vmm;45}4647void EdgeQueue::add(const Edge* parent, const oop* ref) {48assert(ref != NULL, "Null objects not allowed in EdgeQueue");49assert(!is_full(), "EdgeQueue is full. Check is_full before adding another Edge");50assert(!_vmm->is_full(), "invariant");51void* const allocation = _vmm->new_datum();52assert(allocation != NULL, "invariant");53new (allocation)Edge(parent, ref);54_top_index++;55assert(_vmm->count() == _top_index, "invariant");56}5758size_t EdgeQueue::top() const {59return _top_index;60}6162size_t EdgeQueue::bottom() const {63return EdgeQueue::_bottom_index;64}6566bool EdgeQueue::is_empty() const {67return _top_index == _bottom_index;68}6970bool EdgeQueue::is_full() const {71return _vmm->is_full();72}7374const Edge* EdgeQueue::remove() const {75assert(!is_empty(), "EdgeQueue is empty. Check if empty before removing Edge");76assert(!_vmm->is_empty(), "invariant");77return (const Edge*)_vmm->get(_bottom_index++);78}7980const Edge* EdgeQueue::element_at(size_t index) const {81assert(index >= _bottom_index, "invariant");82assert(index <_top_index, "invariant");83return (Edge*)_vmm->get(index);84}8586size_t EdgeQueue::reserved_size() const {87assert(_vmm != NULL, "invariant");88return _vmm->reserved_size();89}9091size_t EdgeQueue::live_set() const {92assert(_vmm != NULL, "invariant");93return _vmm->live_set();94}9596size_t EdgeQueue::sizeof_edge() const {97assert(_vmm != NULL, "invariant");98return _vmm->aligned_datum_size_bytes();99}100101102