events.hpp revision 4121
df8bdeb362277e8d95a74d6c097341fe97409948johnz/*
df8bdeb362277e8d95a74d6c097341fe97409948johnz * Copyright (c) 1997, 2012, Oracle and/or its affiliates. All rights reserved.
df8bdeb362277e8d95a74d6c097341fe97409948johnz * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
df8bdeb362277e8d95a74d6c097341fe97409948johnz *
df8bdeb362277e8d95a74d6c097341fe97409948johnz * This code is free software; you can redistribute it and/or modify it
df8bdeb362277e8d95a74d6c097341fe97409948johnz * under the terms of the GNU General Public License version 2 only, as
df8bdeb362277e8d95a74d6c097341fe97409948johnz * published by the Free Software Foundation.
df8bdeb362277e8d95a74d6c097341fe97409948johnz *
df8bdeb362277e8d95a74d6c097341fe97409948johnz * This code is distributed in the hope that it will be useful, but WITHOUT
df8bdeb362277e8d95a74d6c097341fe97409948johnz * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
df8bdeb362277e8d95a74d6c097341fe97409948johnz * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
df8bdeb362277e8d95a74d6c097341fe97409948johnz * version 2 for more details (a copy is included in the LICENSE file that
df8bdeb362277e8d95a74d6c097341fe97409948johnz * accompanied this code).
df8bdeb362277e8d95a74d6c097341fe97409948johnz *
df8bdeb362277e8d95a74d6c097341fe97409948johnz * You should have received a copy of the GNU General Public License version
df8bdeb362277e8d95a74d6c097341fe97409948johnz * 2 along with this work; if not, write to the Free Software Foundation,
df8bdeb362277e8d95a74d6c097341fe97409948johnz * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
df8bdeb362277e8d95a74d6c097341fe97409948johnz *
df8bdeb362277e8d95a74d6c097341fe97409948johnz * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
df8bdeb362277e8d95a74d6c097341fe97409948johnz * or visit www.oracle.com if you need additional information or have any
df8bdeb362277e8d95a74d6c097341fe97409948johnz * questions.
df8bdeb362277e8d95a74d6c097341fe97409948johnz *
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll */
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz#ifndef SHARE_VM_UTILITIES_EVENTS_HPP
df8bdeb362277e8d95a74d6c097341fe97409948johnz#define SHARE_VM_UTILITIES_EVENTS_HPP
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz#include "memory/allocation.hpp"
df8bdeb362277e8d95a74d6c097341fe97409948johnz#include "runtime/mutexLocker.hpp"
df8bdeb362277e8d95a74d6c097341fe97409948johnz#include "runtime/thread.hpp"
df8bdeb362277e8d95a74d6c097341fe97409948johnz#include "utilities/top.hpp"
df8bdeb362277e8d95a74d6c097341fe97409948johnz#include "utilities/vmError.hpp"
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz// Events and EventMark provide interfaces to log events taking place in the vm.
df8bdeb362277e8d95a74d6c097341fe97409948johnz// This facility is extremly useful for post-mortem debugging. The eventlog
df8bdeb362277e8d95a74d6c097341fe97409948johnz// often provides crucial information about events leading up to the crash.
df8bdeb362277e8d95a74d6c097341fe97409948johnz//
df8bdeb362277e8d95a74d6c097341fe97409948johnz// Abstractly the logs can record whatever they way but normally they
df8bdeb362277e8d95a74d6c097341fe97409948johnz// would record at least a timestamp and the current Thread, along
df8bdeb362277e8d95a74d6c097341fe97409948johnz// with whatever data they need in a ring buffer. Commonly fixed
df8bdeb362277e8d95a74d6c097341fe97409948johnz// length text messages are recorded for simplicity but other
df8bdeb362277e8d95a74d6c097341fe97409948johnz// strategies could be used. Several logs are provided by default but
df8bdeb362277e8d95a74d6c097341fe97409948johnz// new instances can be created as needed.
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz// The base event log dumping class that is registered for dumping at
df8bdeb362277e8d95a74d6c097341fe97409948johnz// crash time. This is a very generic interface that is mainly here
df8bdeb362277e8d95a74d6c097341fe97409948johnz// for completeness. Normally the templated EventLogBase would be
df8bdeb362277e8d95a74d6c097341fe97409948johnz// subclassed to provide different log types.
df8bdeb362277e8d95a74d6c097341fe97409948johnzclass EventLog : public CHeapObj<mtInternal> {
df8bdeb362277e8d95a74d6c097341fe97409948johnz friend class Events;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz private:
df8bdeb362277e8d95a74d6c097341fe97409948johnz EventLog* _next;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
735564919188238196dbd0d320770dda59b38369Anthony Scarpino EventLog* next() const { return _next; }
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpino public:
735564919188238196dbd0d320770dda59b38369Anthony Scarpino // Automatically registers the log so that it will be printed during
df8bdeb362277e8d95a74d6c097341fe97409948johnz // crashes.
df8bdeb362277e8d95a74d6c097341fe97409948johnz EventLog();
df8bdeb362277e8d95a74d6c097341fe97409948johnz
735564919188238196dbd0d320770dda59b38369Anthony Scarpino virtual void print_log_on(outputStream* out) = 0;
df8bdeb362277e8d95a74d6c097341fe97409948johnz};
df8bdeb362277e8d95a74d6c097341fe97409948johnz
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
df8bdeb362277e8d95a74d6c097341fe97409948johnz// A templated subclass of EventLog that provides basic ring buffer
df8bdeb362277e8d95a74d6c097341fe97409948johnz// functionality. Most event loggers should subclass this, possibly
df8bdeb362277e8d95a74d6c097341fe97409948johnz// providing a more featureful log function if the existing copy
df8bdeb362277e8d95a74d6c097341fe97409948johnz// semantics aren't appropriate. The name is used as the label of the
df8bdeb362277e8d95a74d6c097341fe97409948johnz// log when it is dumped during a crash.
df8bdeb362277e8d95a74d6c097341fe97409948johnztemplate <class T> class EventLogBase : public EventLog {
df8bdeb362277e8d95a74d6c097341fe97409948johnz template <class X> class EventRecord {
df8bdeb362277e8d95a74d6c097341fe97409948johnz public:
df8bdeb362277e8d95a74d6c097341fe97409948johnz double timestamp;
df8bdeb362277e8d95a74d6c097341fe97409948johnz Thread* thread;
df8bdeb362277e8d95a74d6c097341fe97409948johnz X data;
df8bdeb362277e8d95a74d6c097341fe97409948johnz };
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz protected:
df8bdeb362277e8d95a74d6c097341fe97409948johnz Mutex _mutex;
df8bdeb362277e8d95a74d6c097341fe97409948johnz const char* _name;
df8bdeb362277e8d95a74d6c097341fe97409948johnz int _length;
df8bdeb362277e8d95a74d6c097341fe97409948johnz int _index;
df8bdeb362277e8d95a74d6c097341fe97409948johnz int _count;
df8bdeb362277e8d95a74d6c097341fe97409948johnz EventRecord<T>* _records;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz public:
df8bdeb362277e8d95a74d6c097341fe97409948johnz EventLogBase<T>(const char* name, int length = LogEventsBufferEntries):
df8bdeb362277e8d95a74d6c097341fe97409948johnz _name(name),
df8bdeb362277e8d95a74d6c097341fe97409948johnz _length(length),
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM _count(0),
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM _index(0),
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM _mutex(Mutex::event, name) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz _records = new EventRecord<T>[length];
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz double fetch_timestamp() {
df8bdeb362277e8d95a74d6c097341fe97409948johnz return os::elapsedTime();
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // move the ring buffer to next open slot and return the index of
df8bdeb362277e8d95a74d6c097341fe97409948johnz // the slot to use for the current message. Should only be called
df8bdeb362277e8d95a74d6c097341fe97409948johnz // while mutex is held.
735564919188238196dbd0d320770dda59b38369Anthony Scarpino int compute_log_index() {
df8bdeb362277e8d95a74d6c097341fe97409948johnz int index = _index;
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (_count < _length) _count++;
df8bdeb362277e8d95a74d6c097341fe97409948johnz _index++;
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (_index >= _length) _index = 0;
735564919188238196dbd0d320770dda59b38369Anthony Scarpino return index;
735564919188238196dbd0d320770dda59b38369Anthony Scarpino }
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpino bool should_log() {
735564919188238196dbd0d320770dda59b38369Anthony Scarpino // Don't bother adding new entries when we're crashing. This also
735564919188238196dbd0d320770dda59b38369Anthony Scarpino // avoids mutating the ring buffer when printing the log.
735564919188238196dbd0d320770dda59b38369Anthony Scarpino return !VMError::fatal_error_in_progress();
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Print the contents of the log
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM void print_log_on(outputStream* out);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM private:
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM void print_log_impl(outputStream* out);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM // Print a single element. A templated implementation might need to
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM // be declared by subclasses.
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM void print(outputStream* out, T& e);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
df8bdeb362277e8d95a74d6c097341fe97409948johnz void print(outputStream* out, EventRecord<T>& e) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz out->print("Event: %.3f ", e.timestamp);
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (e.thread != NULL) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz out->print("Thread " INTPTR_FORMAT " ", e.thread);
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz print(out, e.data);
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz};
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz// A simple wrapper class for fixed size text messages.
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMclass StringLogMessage : public FormatBuffer<256> {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM public:
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM // Wrap this buffer in a stringStream.
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM stringStream stream() {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM return stringStream(_buf, size());
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM};
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM// A simple ring buffer of fixed size text messages.
df8bdeb362277e8d95a74d6c097341fe97409948johnzclass StringEventLog : public EventLogBase<StringLogMessage> {
df8bdeb362277e8d95a74d6c097341fe97409948johnz public:
df8bdeb362277e8d95a74d6c097341fe97409948johnz StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz void logv(Thread* thread, const char* format, va_list ap) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (!should_log()) return;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz double timestamp = fetch_timestamp();
df8bdeb362277e8d95a74d6c097341fe97409948johnz MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
735564919188238196dbd0d320770dda59b38369Anthony Scarpino int index = compute_log_index();
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll _records[index].thread = thread;
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll _records[index].timestamp = timestamp;
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll _records[index].data.printv(format, ap);
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll }
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll void log(Thread* thread, const char* format, ...) {
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll va_list ap;
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll va_start(ap, format);
9f0bc604621fbb9b9b038e6de7da8f9c46e28608Wyllys Ingersoll logv(thread, format, ap);
735564919188238196dbd0d320770dda59b38369Anthony Scarpino va_end(ap);
735564919188238196dbd0d320770dda59b38369Anthony Scarpino }
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpino};
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpino
735564919188238196dbd0d320770dda59b38369Anthony Scarpinoclass Events : AllStatic {
735564919188238196dbd0d320770dda59b38369Anthony Scarpino friend class EventLog;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz private:
df8bdeb362277e8d95a74d6c097341fe97409948johnz static EventLog* _logs;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // A log for generic messages that aren't well categorized.
df8bdeb362277e8d95a74d6c097341fe97409948johnz static StringEventLog* _messages;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // A log for internal exception related messages, like internal
df8bdeb362277e8d95a74d6c097341fe97409948johnz // throws and implicit exceptions.
df8bdeb362277e8d95a74d6c097341fe97409948johnz static StringEventLog* _exceptions;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Deoptization related messages
df8bdeb362277e8d95a74d6c097341fe97409948johnz static StringEventLog* _deopt_messages;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz public:
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void print_all(outputStream* out);
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Dump all events to the tty
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void print();
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Logs a generic message with timestamp and format as printf.
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void log(Thread* thread, const char* format, ...);
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Log exception related message
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void log_exception(Thread* thread, const char* format, ...);
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void log_deopt_message(Thread* thread, const char* format, ...);
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Register default loggers
df8bdeb362277e8d95a74d6c097341fe97409948johnz static void init();
df8bdeb362277e8d95a74d6c097341fe97409948johnz};
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnzinline void Events::log(Thread* thread, const char* format, ...) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (LogEvents) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_list ap;
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_start(ap, format);
df8bdeb362277e8d95a74d6c097341fe97409948johnz _messages->logv(thread, format, ap);
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_end(ap);
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz}
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnzinline void Events::log_exception(Thread* thread, const char* format, ...) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (LogEvents) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_list ap;
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_start(ap, format);
df8bdeb362277e8d95a74d6c097341fe97409948johnz _exceptions->logv(thread, format, ap);
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_end(ap);
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
df8bdeb362277e8d95a74d6c097341fe97409948johnz}
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnzinline void Events::log_deopt_message(Thread* thread, const char* format, ...) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (LogEvents) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_list ap;
df8bdeb362277e8d95a74d6c097341fe97409948johnz va_start(ap, format);
df8bdeb362277e8d95a74d6c097341fe97409948johnz _deopt_messages->logv(thread, format, ap);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM va_end(ap);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM}
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMtemplate <class T>
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMinline void EventLogBase<T>::print_log_on(outputStream* out) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz if (ThreadLocalStorage::get_thread_slow() == NULL) {
df8bdeb362277e8d95a74d6c097341fe97409948johnz // Not a regular Java thread so don't bother locking
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM print_log_impl(out);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM } else {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM MutexLockerEx ml(&_mutex, Mutex::_no_safepoint_check_flag);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM print_log_impl(out);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM}
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM// Dump the ring buffer entries that current have entries.
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMtemplate <class T>
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMinline void EventLogBase<T>::print_log_impl(outputStream* out) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->print_cr("%s (%d events):", _name, _count);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM if (_count == 0) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->print_cr("No events");
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->cr();
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM return;
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM if (_count < _length) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM for (int i = 0; i < _count; i++) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM print(out, _records[i]);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
df8bdeb362277e8d95a74d6c097341fe97409948johnz } else {
df8bdeb362277e8d95a74d6c097341fe97409948johnz for (int i = _index; i < _length; i++) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM print(out, _records[i]);
df8bdeb362277e8d95a74d6c097341fe97409948johnz }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM for (int i = 0; i < _index; i++) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM print(out, _records[i]);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM }
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->cr();
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM}
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM// Implement a printing routine for the StringLogMessage
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMtemplate <>
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COMinline void EventLogBase<StringLogMessage>::print(outputStream* out, StringLogMessage& lm) {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->print_raw(lm);
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM out->cr();
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM}
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz// Place markers for the beginning and end up of a set of events.
df8bdeb362277e8d95a74d6c097341fe97409948johnz// These end up in the default log.
df8bdeb362277e8d95a74d6c097341fe97409948johnzclass EventMark : public StackObj {
8bab47abcb471dffa36ddbf409a8ef5303398ddfJohn.Zolnowsky@Sun.COM StringLogMessage _buffer;
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz public:
df8bdeb362277e8d95a74d6c097341fe97409948johnz // log a begin event, format as printf
df8bdeb362277e8d95a74d6c097341fe97409948johnz EventMark(const char* format, ...);
df8bdeb362277e8d95a74d6c097341fe97409948johnz // log an end event
df8bdeb362277e8d95a74d6c097341fe97409948johnz ~EventMark();
df8bdeb362277e8d95a74d6c097341fe97409948johnz};
df8bdeb362277e8d95a74d6c097341fe97409948johnz
df8bdeb362277e8d95a74d6c097341fe97409948johnz#endif // SHARE_VM_UTILITIES_EVENTS_HPP
df8bdeb362277e8d95a74d6c097341fe97409948johnz