/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* 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.
*
*/
#ifndef SHARE_VM_UTILITIES_EVENTS_HPP
#define SHARE_VM_UTILITIES_EVENTS_HPP
#include "memory/allocation.hpp"
#include "runtime/mutexLocker.hpp"
#include "runtime/thread.hpp"
#include "utilities/vmError.hpp"
// Events and EventMark provide interfaces to log events taking place in the vm.
// This facility is extremly 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.
friend class Events;
private:
public:
// Automatically registers the log so that it will be printed during
// crashes.
EventLog();
};
// 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 X> class EventRecord {
public:
double timestamp;
X data;
};
protected:
const char* _name;
int _length;
int _index;
int _count;
public:
_count(0),
_index(0),
}
double fetch_timestamp() {
return os::elapsedTime();
}
// 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() {
_index++;
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::fatal_error_in_progress();
}
// Print the contents of the log
private:
// Print a single element. A templated implementation might need to
// be declared by subclasses.
}
}
};
// A simple wrapper class for fixed size text messages.
public:
// Wrap this buffer in a stringStream.
}
};
// A simple ring buffer of fixed size text messages.
public:
StringEventLog(const char* name, int count = LogEventsBufferEntries) : EventLogBase<StringLogMessage>(name, count) {}
if (!should_log()) return;
}
}
};
friend class EventLog;
private:
// A log for generic messages that aren't well categorized.
// A log for internal exception related messages, like internal
// throws and implicit exceptions.
// Deoptization related messages
public:
// Dump all events to the tty
static void print();
// Logs a generic message with timestamp and format as printf.
// Log exception related message
// Register default loggers
static void init();
};
if (LogEvents) {
}
}
if (LogEvents) {
}
}
if (LogEvents) {
}
}
template <class T>
// Not a regular Java thread so don't bother locking
} else {
}
}
// Dump the ring buffer entries that current have entries.
template <class T>
if (_count == 0) {
return;
}
for (int i = 0; i < _count; i++) {
}
} else {
}
for (int i = 0; i < _index; i++) {
}
}
}
// Implement a printing routine for the StringLogMessage
template <>
}
// Place markers for the beginning and end up of a set of events.
// These end up in the default log.
public:
// log a begin event, format as printf
// log an end event
~EventMark();
};
#endif // SHARE_VM_UTILITIES_EVENTS_HPP