Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/compiler/compilerEvent.cpp
40930 views
1
/*
2
* Copyright (c) 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
#include "precompiled.hpp"
25
#include "ci/ciMethod.hpp"
26
#include "compiler/compilerEvent.hpp"
27
#include "jfr/jfr.hpp"
28
#include "jfr/jfrEvents.hpp"
29
#include "jfr/metadata/jfrSerializer.hpp"
30
#include "runtime/semaphore.inline.hpp"
31
#include "utilities/growableArray.hpp"
32
33
// Synchronizes access to phases_names.
34
class PhaseTypeGuard : public StackObj {
35
private:
36
static Semaphore _mutex_semaphore;
37
bool _enabled;
38
public:
39
PhaseTypeGuard(bool enabled=true) {
40
if (enabled) {
41
_mutex_semaphore.wait();
42
_enabled = true;
43
} else {
44
_enabled = false;
45
}
46
}
47
~PhaseTypeGuard() {
48
if (_enabled) {
49
_mutex_semaphore.signal();
50
}
51
}
52
};
53
54
Semaphore PhaseTypeGuard::_mutex_semaphore(1);
55
56
// Table for mapping compiler phases names to int identifiers.
57
static GrowableArray<const char*>* phase_names = NULL;
58
59
class CompilerPhaseTypeConstant : public JfrSerializer {
60
public:
61
void serialize(JfrCheckpointWriter& writer) {
62
PhaseTypeGuard guard;
63
assert(phase_names != NULL, "invariant");
64
assert(phase_names->is_nonempty(), "invariant");
65
const u4 nof_entries = phase_names->length();
66
writer.write_count(nof_entries);
67
for (u4 i = 0; i < nof_entries; i++) {
68
writer.write_key(i);
69
writer.write(phase_names->at(i));
70
}
71
}
72
};
73
74
static int lookup_phase(const char* phase_name) {
75
for (int i = 0; i < phase_names->length(); i++) {
76
const char* name = phase_names->at(i);
77
if (strcmp(name, phase_name) == 0) {
78
return i;
79
}
80
}
81
return -1;
82
}
83
84
int CompilerEvent::PhaseEvent::get_phase_id(const char* phase_name, bool may_exist, bool use_strdup, bool sync) {
85
int index;
86
bool register_jfr_serializer = false;
87
{
88
PhaseTypeGuard guard(sync);
89
if (phase_names == NULL) {
90
phase_names = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<const char*>(100, mtCompiler);
91
register_jfr_serializer = true;
92
} else if (may_exist) {
93
index = lookup_phase(phase_name);
94
if (index != -1) {
95
return index;
96
}
97
} else {
98
assert((index = lookup_phase(phase_name)) == -1, "phase name \"%s\" already registered: %d", phase_name, index);
99
}
100
101
index = phase_names->length();
102
phase_names->append(use_strdup ? strdup(phase_name) : phase_name);
103
}
104
if (register_jfr_serializer) {
105
JfrSerializer::register_serializer(TYPE_COMPILERPHASETYPE, false, new CompilerPhaseTypeConstant());
106
} else if (Jfr::is_recording()) {
107
// serialize new phase.
108
JfrCheckpointWriter writer;
109
writer.write_type(TYPE_COMPILERPHASETYPE);
110
writer.write_count(1);
111
writer.write_key(index);
112
writer.write(phase_name);
113
}
114
return index;
115
}
116
117
void CompilerEvent::CompilationEvent::post(EventCompilation& event, int compile_id, CompilerType compiler_type, Method* method, int compile_level, bool success, bool is_osr, int code_size, int inlined_bytecodes) {
118
event.set_compileId(compile_id);
119
event.set_compiler(compiler_type);
120
event.set_method(method);
121
event.set_compileLevel((short)compile_level);
122
event.set_succeded(success);
123
event.set_isOsr(is_osr);
124
event.set_codeSize(code_size);
125
event.set_inlinedBytes(inlined_bytecodes);
126
event.commit();
127
}
128
129
void CompilerEvent::CompilationFailureEvent::post(EventCompilationFailure& event, int compile_id, const char* reason) {
130
event.set_compileId(compile_id);
131
event.set_failureMessage(reason);
132
event.commit();
133
}
134
135
void CompilerEvent::PhaseEvent::post(EventCompilerPhase& event, const Ticks& start_time, int phase, int compile_id, int level) {
136
event.set_starttime(start_time);
137
event.set_phase((u1) phase);
138
event.set_compileId(compile_id);
139
event.set_phaseLevel((short)level);
140
event.commit();
141
}
142
143
void CompilerEvent::InlineEvent::post(EventCompilerInlining& event, int compile_id, Method* caller, const JfrStructCalleeMethod& callee, bool success, const char* msg, int bci) {
144
event.set_compileId(compile_id);
145
event.set_caller(caller);
146
event.set_callee(callee);
147
event.set_succeeded(success);
148
event.set_message(msg);
149
event.set_bci(bci);
150
event.commit();
151
}
152
153
void CompilerEvent::InlineEvent::post(EventCompilerInlining& event, int compile_id, Method* caller, Method* callee, bool success, const char* msg, int bci) {
154
JfrStructCalleeMethod callee_struct;
155
callee_struct.set_type(callee->klass_name()->as_utf8());
156
callee_struct.set_name(callee->name()->as_utf8());
157
callee_struct.set_descriptor(callee->signature()->as_utf8());
158
post(event, compile_id, caller, callee_struct, success, msg, bci);
159
}
160
161
void CompilerEvent::InlineEvent::post(EventCompilerInlining& event, int compile_id, Method* caller, ciMethod* callee, bool success, const char* msg, int bci) {
162
JfrStructCalleeMethod callee_struct;
163
callee_struct.set_type(callee->holder()->name()->as_utf8());
164
callee_struct.set_name(callee->name()->as_utf8());
165
callee_struct.set_descriptor(callee->signature()->as_symbol()->as_utf8());
166
post(event, compile_id, caller, callee_struct, success, msg, bci);
167
}
168
169