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