Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/share/utilities/events.cpp
40949 views
1
/*
2
* Copyright (c) 1997, 2021, 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 "memory/allocation.inline.hpp"
27
#include "oops/instanceKlass.hpp"
28
#include "runtime/mutexLocker.hpp"
29
#include "runtime/osThread.hpp"
30
#include "runtime/thread.inline.hpp"
31
#include "runtime/threadCritical.hpp"
32
#include "runtime/timer.hpp"
33
#include "utilities/events.hpp"
34
35
36
EventLog* Events::_logs = NULL;
37
StringEventLog* Events::_messages = NULL;
38
StringEventLog* Events::_vm_operations = NULL;
39
ExceptionsEventLog* Events::_exceptions = NULL;
40
StringEventLog* Events::_redefinitions = NULL;
41
UnloadingEventLog* Events::_class_unloading = NULL;
42
StringEventLog* Events::_deopt_messages = NULL;
43
44
EventLog::EventLog() {
45
// This normally done during bootstrap when we're only single
46
// threaded but use a ThreadCritical to ensure inclusion in case
47
// some are created slightly late.
48
ThreadCritical tc;
49
_next = Events::_logs;
50
Events::_logs = this;
51
}
52
53
// For each registered event logger, print out the current contents of
54
// the buffer.
55
void Events::print_all(outputStream* out, int max) {
56
EventLog* log = _logs;
57
while (log != NULL) {
58
log->print_log_on(out, max);
59
log = log->next();
60
}
61
}
62
63
// Print a single event log specified by name.
64
void Events::print_one(outputStream* out, const char* log_name, int max) {
65
EventLog* log = _logs;
66
int num_printed = 0;
67
while (log != NULL) {
68
if (log->matches_name_or_handle(log_name)) {
69
log->print_log_on(out, max);
70
num_printed ++;
71
}
72
log = log->next();
73
}
74
// Write a short error note if no name matched.
75
if (num_printed == 0) {
76
out->print_cr("The name \"%s\" did not match any known event log. "
77
"Valid event log names are:", log_name);
78
EventLog* log = _logs;
79
while (log != NULL) {
80
log->print_names(out);
81
out->cr();
82
log = log->next();
83
}
84
}
85
}
86
87
88
void Events::print() {
89
print_all(tty);
90
}
91
92
void Events::init() {
93
if (LogEvents) {
94
_messages = new StringEventLog("Events", "events");
95
_vm_operations = new StringEventLog("VM Operations", "vmops");
96
_exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
97
_redefinitions = new StringEventLog("Classes redefined", "redef");
98
_class_unloading = new UnloadingEventLog("Classes unloaded", "unload");
99
_deopt_messages = new StringEventLog("Deoptimization events", "deopt");
100
}
101
}
102
103
void eventlog_init() {
104
Events::init();
105
}
106
107
///////////////////////////////////////////////////////////////////////////
108
// EventMark
109
110
EventMarkBase::EventMarkBase(EventLogFunction log_function) :
111
_log_function(log_function),
112
_buffer() {}
113
114
void EventMarkBase::log_start(const char* format, va_list argp) {
115
// Save a copy of begin message and log it.
116
_buffer.printv(format, argp);
117
_log_function(NULL, "%s", _buffer.buffer());
118
}
119
120
void EventMarkBase::log_end() {
121
// Append " done" to the begin message and log it
122
_buffer.append(" done");
123
_log_function(NULL, "%s", _buffer.buffer());
124
}
125
126
void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {
127
if (!should_log()) return;
128
129
double timestamp = fetch_timestamp();
130
// Unloading events are single threaded.
131
int index = compute_log_index();
132
_records[index].thread = thread;
133
_records[index].timestamp = timestamp;
134
stringStream st(_records[index].data.buffer(),
135
_records[index].data.size());
136
st.print("Unloading class " INTPTR_FORMAT " ", p2i(ik));
137
ik->name()->print_value_on(&st);
138
}
139
140
void ExceptionsEventLog::log(Thread* thread, Handle h_exception, const char* message, const char* file, int line) {
141
if (!should_log()) return;
142
143
double timestamp = fetch_timestamp();
144
MutexLocker ml(&_mutex, Mutex::_no_safepoint_check_flag);
145
int index = compute_log_index();
146
_records[index].thread = thread;
147
_records[index].timestamp = timestamp;
148
stringStream st(_records[index].data.buffer(),
149
_records[index].data.size());
150
st.print("Exception <");
151
h_exception->print_value_on(&st);
152
st.print("%s%s> (" INTPTR_FORMAT ") \n"
153
"thrown [%s, line %d]",
154
message ? ": " : "", message ? message : "",
155
p2i(h_exception()), file, line);
156
}
157
158