2
* Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
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.
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).
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.
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
24
#include "precompiled.hpp"
25
#include "gc/shared/gcId.hpp"
26
#include "gc/x/xGlobals.hpp"
27
#include "gc/x/xStat.hpp"
28
#include "gc/x/xTracer.hpp"
29
#include "jfr/jfrEvents.hpp"
30
#include "runtime/safepointVerifiers.hpp"
31
#include "utilities/debug.hpp"
32
#include "utilities/macros.hpp"
34
#include "jfr/metadata/jfrSerializer.hpp"
39
class XPageTypeConstant : public JfrSerializer {
41
virtual void serialize(JfrCheckpointWriter& writer) {
42
writer.write_count(3);
43
writer.write_key(XPageTypeSmall);
44
writer.write("Small");
45
writer.write_key(XPageTypeMedium);
46
writer.write("Medium");
47
writer.write_key(XPageTypeLarge);
48
writer.write("Large");
52
class XStatisticsCounterTypeConstant : public JfrSerializer {
54
virtual void serialize(JfrCheckpointWriter& writer) {
55
writer.write_count(XStatCounter::count());
56
for (XStatCounter* counter = XStatCounter::first(); counter != nullptr; counter = counter->next()) {
57
writer.write_key(counter->id());
58
writer.write(counter->name());
63
class XStatisticsSamplerTypeConstant : public JfrSerializer {
65
virtual void serialize(JfrCheckpointWriter& writer) {
66
writer.write_count(XStatSampler::count());
67
for (XStatSampler* sampler = XStatSampler::first(); sampler != nullptr; sampler = sampler->next()) {
68
writer.write_key(sampler->id());
69
writer.write(sampler->name());
74
static void register_jfr_type_serializers() {
75
JfrSerializer::register_serializer(TYPE_ZPAGETYPETYPE,
76
true /* permit_cache */,
77
new XPageTypeConstant());
78
JfrSerializer::register_serializer(TYPE_ZSTATISTICSCOUNTERTYPE,
79
true /* permit_cache */,
80
new XStatisticsCounterTypeConstant());
81
JfrSerializer::register_serializer(TYPE_ZSTATISTICSSAMPLERTYPE,
82
true /* permit_cache */,
83
new XStatisticsSamplerTypeConstant());
88
XTracer* XTracer::_tracer = nullptr;
93
void XTracer::initialize() {
94
assert(_tracer == nullptr, "Already initialized");
95
_tracer = new XTracer();
96
JFR_ONLY(register_jfr_type_serializers();)
99
void XTracer::send_stat_counter(const XStatCounter& counter, uint64_t increment, uint64_t value) {
100
NoSafepointVerifier nsv;
102
EventZStatisticsCounter e;
103
if (e.should_commit()) {
104
e.set_id(counter.id());
105
e.set_increment(increment);
111
void XTracer::send_stat_sampler(const XStatSampler& sampler, uint64_t value) {
112
NoSafepointVerifier nsv;
114
EventZStatisticsSampler e;
115
if (e.should_commit()) {
116
e.set_id(sampler.id());
122
void XTracer::send_thread_phase(const char* name, const Ticks& start, const Ticks& end) {
123
NoSafepointVerifier nsv;
125
EventZThreadPhase e(UNTIMED);
126
if (e.should_commit()) {
127
e.set_gcId(GCId::current_or_undefined());
129
e.set_starttime(start);
135
void XTracer::send_thread_debug(const char* name, const Ticks& start, const Ticks& end) {
136
NoSafepointVerifier nsv;
138
EventZThreadDebug e(UNTIMED);
139
if (e.should_commit()) {
140
e.set_gcId(GCId::current_or_undefined());
142
e.set_starttime(start);