Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/jfr/leakprofiler/leakProfiler.cpp
41149 views
1
/*
2
* Copyright (c) 2014, 2020, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4
*
5
* This code is free software; you can redistribute it and/or modify it
6
* under the terms of the GNU General Public License version 2 only, as
7
* published by the Free Software Foundation.
8
*
9
* This code is distributed in the hope that it will be useful, but WITHOUT
10
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12
* version 2 for more details (a copy is included in the LICENSE file that
13
* accompanied this code).
14
*
15
* You should have received a copy of the GNU General Public License version
16
* 2 along with this work; if not, write to the Free Software Foundation,
17
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18
*
19
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20
* or visit www.oracle.com if you need additional information or have any
21
* questions.
22
*
23
*/
24
25
#include "precompiled.hpp"
26
#include "jfr/leakprofiler/leakProfiler.hpp"
27
#include "jfr/leakprofiler/startOperation.hpp"
28
#include "jfr/leakprofiler/stopOperation.hpp"
29
#include "jfr/leakprofiler/checkpoint/eventEmitter.hpp"
30
#include "jfr/leakprofiler/sampling/objectSampler.hpp"
31
#include "jfr/recorder/service/jfrOptionSet.hpp"
32
#include "logging/log.hpp"
33
#include "memory/iterator.hpp"
34
#include "runtime/thread.inline.hpp"
35
#include "runtime/vmThread.hpp"
36
37
bool LeakProfiler::is_running() {
38
return ObjectSampler::is_created();
39
}
40
41
bool LeakProfiler::start(int sample_count) {
42
if (is_running()) {
43
return true;
44
}
45
46
// Allows user to disable leak profiler on command line by setting queue size to zero.
47
if (sample_count == 0) {
48
return false;
49
}
50
51
assert(!is_running(), "invariant");
52
assert(sample_count > 0, "invariant");
53
54
// schedule the safepoint operation for installing the object sampler
55
StartOperation op(sample_count);
56
VMThread::execute(&op);
57
58
if (!is_running()) {
59
log_trace(jfr, system)("Object sampling could not be started because the sampler could not be allocated");
60
return false;
61
}
62
assert(is_running(), "invariant");
63
log_trace(jfr, system)("Object sampling started");
64
return true;
65
}
66
67
bool LeakProfiler::stop() {
68
if (!is_running()) {
69
return false;
70
}
71
72
// schedule the safepoint operation for uninstalling and destroying the object sampler
73
StopOperation op;
74
VMThread::execute(&op);
75
76
assert(!is_running(), "invariant");
77
log_trace(jfr, system)("Object sampling stopped");
78
return true;
79
}
80
81
void LeakProfiler::emit_events(int64_t cutoff_ticks, bool emit_all, bool skip_bfs) {
82
if (!is_running()) {
83
return;
84
}
85
// exclusive access to object sampler instance
86
ObjectSampler* const sampler = ObjectSampler::acquire();
87
assert(sampler != NULL, "invariant");
88
EventEmitter::emit(sampler, cutoff_ticks, emit_all, skip_bfs);
89
ObjectSampler::release();
90
}
91
92
void LeakProfiler::sample(HeapWord* object, size_t size, JavaThread* thread) {
93
assert(is_running(), "invariant");
94
assert(thread != NULL, "invariant");
95
assert(thread->thread_state() == _thread_in_vm, "invariant");
96
97
// exclude compiler threads and code sweeper thread
98
if (thread->is_hidden_from_external_view()) {
99
return;
100
}
101
102
ObjectSampler::sample(object, size, thread);
103
}
104
105