/* * Copyright (c) 1997, 2022, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions. *
*/
// Events and EventMark provide interfaces to log events taking place in the vm. // This facility is extremely useful for post-mortem debugging. The eventlog // often provides crucial information about events leading up to the crash. // // Abstractly the logs can record whatever they way but normally they // would record at least a timestamp and the current Thread, along // with whatever data they need in a ring buffer. Commonly fixed // length text messages are recorded for simplicity but other // strategies could be used. Several logs are provided by default but // new instances can be created as needed.
// The base event log dumping class that is registered for dumping at // crash time. This is a very generic interface that is mainly here // for completeness. Normally the templated EventLogBase would be // subclassed to provide different log types. class EventLog : public CHeapObj<mtInternal> { friendclass Events;
private:
EventLog* _next;
EventLog* next() const { return _next; }
public: // Automatically registers the log so that it will be printed during // crashes.
EventLog();
// Print log to output stream. virtualvoid print_log_on(outputStream* out, int max = -1) = 0;
// Returns true if s matches either the log name or the log handle. virtualbool matches_name_or_handle(constchar* s) const = 0;
// Print log names (for help output of VM.events). virtualvoid print_names(outputStream* out) const = 0;
};
// A templated subclass of EventLog that provides basic ring buffer // functionality. Most event loggers should subclass this, possibly // providing a more featureful log function if the existing copy // semantics aren't appropriate. The name is used as the label of the // log when it is dumped during a crash. template <class T> class EventLogBase : public EventLog { template <class X> class EventRecord : public CHeapObj<mtInternal> { public: double timestamp;
Thread* thread;
X data;
};
protected:
Mutex _mutex; // Name is printed out as a header. constchar* _name; // Handle is a short specifier used to select this particular event log // for printing (see VM.events command). constchar* _handle; int _length; int _index; int _count;
EventRecord<T>* _records;
// move the ring buffer to next open slot and return the index of // the slot to use for the current message. Should only be called // while mutex is held. int compute_log_index() { int index = _index; if (_count < _length) _count++;
_index++; if (_index >= _length) _index = 0; return index;
}
bool should_log() { // Don't bother adding new entries when we're crashing. This also // avoids mutating the ring buffer when printing the log. return !VMError::is_error_reported();
}
// Print the contents of the log void print_log_on(outputStream* out, int max = -1);
// Returns true if s matches either the log name or the log handle. bool matches_name_or_handle(constchar* s) const;
// Print log names (for help output of VM.events). void print_names(outputStream* out) const;
private: void print_log_impl(outputStream* out, int max = -1);
// Print a single element. A templated implementation might need to // be declared by subclasses. void print(outputStream* out, T& e);
// A simple wrapper class for fixed size text messages. template <size_t bufsz> class FormatStringLogMessage : public FormatBuffer<bufsz> {
}; typedef FormatStringLogMessage<256> StringLogMessage; typedef FormatStringLogMessage<512> ExtendedStringLogMessage;
// A simple ring buffer of fixed size text messages. template <size_t bufsz> class FormatStringEventLog : public EventLogBase< FormatStringLogMessage<bufsz> > { public:
FormatStringEventLog(constchar* name, constchar* short_name, int count = LogEventsBufferEntries)
: EventLogBase< FormatStringLogMessage<bufsz> >(name, short_name, count) {}
void logv(Thread* thread, constchar* format, va_list ap) ATTRIBUTE_PRINTF(3, 0) { if (!this->should_log()) return;
double timestamp = this->fetch_timestamp();
MutexLocker ml(&this->_mutex, Mutex::_no_safepoint_check_flag); int index = this->compute_log_index();
this->_records[index].thread = thread;
this->_records[index].timestamp = timestamp;
this->_records[index].data.printv(format, ap);
}
// Event log for class unloading events to materialize the class name in place in the log stream. class UnloadingEventLog : public EventLogBase<StringLogMessage> { public:
UnloadingEventLog(constchar* name, constchar* short_name, int count = LogEventsBufferEntries)
: EventLogBase<StringLogMessage>(name, short_name, count) {}
void log(Thread* thread, InstanceKlass* ik);
};
// Event log for exceptions class ExceptionsEventLog : public ExtendedStringEventLog { public:
ExceptionsEventLog(constchar* name, constchar* short_name, int count = LogEventsBufferEntries)
: ExtendedStringEventLog(name, short_name, count) {}
// A log for generic messages that aren't well categorized. static StringEventLog* _messages;
// A log for VM Operations static StringEventLog* _vm_operations;
// A log for internal exception related messages, like internal // throws and implicit exceptions. static ExceptionsEventLog* _exceptions;
// Deoptization related messages static StringEventLog* _deopt_messages;
// dynamic lib related messages static StringEventLog* _dll_messages;
// Redefinition related messages static StringEventLog* _redefinitions;
// Class unloading events static UnloadingEventLog* _class_unloading;
// Class loading events static StringEventLog* _class_loading; public:
// Print all event logs; limit number of events per event log to be printed with max // (max == -1 prints all events). staticvoid print_all(outputStream* out, int max = -1);
// Print a single event log specified by name or handle. staticvoid print_one(outputStream* out, constchar* log_name, int max = -1);
// Dump all events to the tty staticvoid print();
// Logs a generic message with timestamp and format as printf. staticvoid log(Thread* thread, constchar* format, ...) ATTRIBUTE_PRINTF(2, 3);
staticvoid log_vm_operation(Thread* thread, constchar* format, ...) ATTRIBUTE_PRINTF(2, 3);
// Log exception related message staticvoid log_exception(Thread* thread, constchar* format, ...) ATTRIBUTE_PRINTF(2, 3); staticvoid log_exception(Thread* thread, Handle h_exception, constchar* message, constchar* file, int line);
staticvoid log_redefinition(Thread* thread, constchar* format, ...) ATTRIBUTE_PRINTF(2, 3);
// Dump the ring buffer entries that current have entries. template <class T> inlinevoid EventLogBase<T>::print_log_impl(outputStream* out, int max) {
out->print_cr("%s (%d events):", _name, _count); if (_count == 0) {
out->print_cr("No events");
out->cr(); return;
}
int printed = 0; if (_count < _length) { for (int i = 0; i < _count; i++) { if (max > 0 && printed == max) { break;
}
print(out, _records[i]);
printed ++;
}
} else { for (int i = _index; i < _length; i++) { if (max > 0 && printed == max) { break;
}
print(out, _records[i]);
printed ++;
} for (int i = 0; i < _index; i++) { if (max > 0 && printed == max) { break;
}
print(out, _records[i]);
printed ++;
}
}
if (printed == max) {
out->print_cr("...(skipped)");
}
out->cr();
}
// Implement a printing routine for the StringLogMessage template <> inlinevoid EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
out->print_raw(lm);
out->cr();
}
// Implement a printing routine for the ExtendedStringLogMessage template <> inlinevoid EventLogBase<ExtendedStringLogMessage>::print(outputStream* out, ExtendedStringLogMessage& lm) {
out->print_raw(lm);
out->cr();
}
typedefvoid (*EventLogFunction)(Thread* thread, constchar* format, ...);
class EventMarkBase : public StackObj {
EventLogFunction _log_function;
StringLogMessage _buffer;
NONCOPYABLE(EventMarkBase);
protected: void log_start(constchar* format, va_list argp) ATTRIBUTE_PRINTF(2, 0); void log_end();
EventMarkBase(EventLogFunction log_function);
};
// Place markers for the beginning and end up of a set of events. template <EventLogFunction log_function> class EventMarkWithLogFunction : public EventMarkBase {
StringLogMessage _buffer;
public: // log a begin event, format as printf
EventMarkWithLogFunction(constchar* format, ...) ATTRIBUTE_PRINTF(2, 3) :
EventMarkBase(log_function) { if (LogEvents) {
va_list ap;
va_start(ap, format);
log_start(format, ap);
va_end(ap);
}
} // log an end event
~EventMarkWithLogFunction() { if (LogEvents) {
log_end();
}
}
};
// These end up in the default log. typedef EventMarkWithLogFunction<Events::log> EventMark;
// These end up in the vm_operation log. typedef EventMarkWithLogFunction<Events::log_vm_operation> EventMarkVMOperation;
// These end up in the class loading log. typedef EventMarkWithLogFunction<Events::log_class_loading> EventMarkClassLoading;
#endif// SHARE_UTILITIES_EVENTS_HPP
Messung V0.5
¤ Dauer der Verarbeitung: 0.17 Sekunden
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.