Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/jfr/leakprofiler/leakProfiler.cpp
38920 views
/*1* Copyright (c) 2014, 2019, 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 "memory/iterator.hpp"32#include "runtime/thread.inline.hpp"33#include "runtime/vmThread.hpp"3435bool LeakProfiler::is_running() {36return ObjectSampler::is_created();37}3839bool LeakProfiler::start(int sample_count) {40if (is_running()) {41return true;42}4344// Allows user to disable leak profiler on command line by setting queue size to zero.45if (sample_count == 0) {46return false;47}4849assert(!is_running(), "invariant");50assert(sample_count > 0, "invariant");5152// schedule the safepoint operation for installing the object sampler53StartOperation op(sample_count);54VMThread::execute(&op);5556if (!is_running()) {57if (LogJFR && Verbose) tty->print_cr("Object sampling could not be started because the sampler could not be allocated");58return false;59}60assert(is_running(), "invariant");61if (LogJFR && Verbose) tty->print_cr("Object sampling started");62return true;63}6465bool LeakProfiler::stop() {66if (!is_running()) {67return false;68}6970// schedule the safepoint operation for uninstalling and destroying the object sampler71StopOperation op;72VMThread::execute(&op);7374assert(!is_running(), "invariant");75if (LogJFR && Verbose) tty->print_cr("Object sampling stopped");76return true;77}7879void LeakProfiler::emit_events(int64_t cutoff_ticks, bool emit_all) {80if (!is_running()) {81return;82}83// exclusive access to object sampler instance84ObjectSampler* const sampler = ObjectSampler::acquire();85assert(sampler != NULL, "invariant");86EventEmitter::emit(sampler, cutoff_ticks, emit_all);87ObjectSampler::release();88}8990void LeakProfiler::oops_do(BoolObjectClosure* is_alive, OopClosure* f) {91assert(SafepointSynchronize::is_at_safepoint(),92"Leak Profiler::oops_do(...) may only be called during safepoint");93if (is_running()) {94ObjectSampler::oops_do(is_alive, f);95}96}9798void LeakProfiler::sample(HeapWord* object, size_t size, JavaThread* thread) {99assert(is_running(), "invariant");100assert(thread != NULL, "invariant");101assert(thread->thread_state() == _thread_in_vm, "invariant");102103// exclude compiler threads and code sweeper thread104if (thread->is_hidden_from_external_view()) {105return;106}107108ObjectSampler::sample(object, size, thread);109}110111112