Path: blob/master/src/hotspot/share/jfr/leakprofiler/leakProfiler.cpp
41149 views
/*1* Copyright (c) 2014, 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#include "precompiled.hpp"25#include "jfr/leakprofiler/leakProfiler.hpp"26#include "jfr/leakprofiler/startOperation.hpp"27#include "jfr/leakprofiler/stopOperation.hpp"28#include "jfr/leakprofiler/checkpoint/eventEmitter.hpp"29#include "jfr/leakprofiler/sampling/objectSampler.hpp"30#include "jfr/recorder/service/jfrOptionSet.hpp"31#include "logging/log.hpp"32#include "memory/iterator.hpp"33#include "runtime/thread.inline.hpp"34#include "runtime/vmThread.hpp"3536bool LeakProfiler::is_running() {37return ObjectSampler::is_created();38}3940bool LeakProfiler::start(int sample_count) {41if (is_running()) {42return true;43}4445// Allows user to disable leak profiler on command line by setting queue size to zero.46if (sample_count == 0) {47return false;48}4950assert(!is_running(), "invariant");51assert(sample_count > 0, "invariant");5253// schedule the safepoint operation for installing the object sampler54StartOperation op(sample_count);55VMThread::execute(&op);5657if (!is_running()) {58log_trace(jfr, system)("Object sampling could not be started because the sampler could not be allocated");59return false;60}61assert(is_running(), "invariant");62log_trace(jfr, system)("Object sampling started");63return true;64}6566bool LeakProfiler::stop() {67if (!is_running()) {68return false;69}7071// schedule the safepoint operation for uninstalling and destroying the object sampler72StopOperation op;73VMThread::execute(&op);7475assert(!is_running(), "invariant");76log_trace(jfr, system)("Object sampling stopped");77return true;78}7980void LeakProfiler::emit_events(int64_t cutoff_ticks, bool emit_all, bool skip_bfs) {81if (!is_running()) {82return;83}84// exclusive access to object sampler instance85ObjectSampler* const sampler = ObjectSampler::acquire();86assert(sampler != NULL, "invariant");87EventEmitter::emit(sampler, cutoff_ticks, emit_all, skip_bfs);88ObjectSampler::release();89}9091void LeakProfiler::sample(HeapWord* object, size_t size, JavaThread* thread) {92assert(is_running(), "invariant");93assert(thread != NULL, "invariant");94assert(thread->thread_state() == _thread_in_vm, "invariant");9596// exclude compiler threads and code sweeper thread97if (thread->is_hidden_from_external_view()) {98return;99}100101ObjectSampler::sample(object, size, thread);102}103104105