Skip to content

Commit 4767758

Browse files
committed
8267920: Create separate Events buffer for VMOperations
Reviewed-by: coleenp, dholmes, tschatzl
1 parent dc19bac commit 4767758

File tree

3 files changed

+66
-20
lines changed

3 files changed

+66
-20
lines changed

src/hotspot/share/runtime/vmThread.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ void VMThread::inner_execute(VM_Operation* op) {
395395
_cur_vm_operation = op;
396396

397397
HandleMark hm(VMThread::vm_thread());
398-
EventMark em("Executing %s VM operation: %s", prev_vm_operation != NULL ? "nested" : "", op->name());
398+
EventMarkVMOperation em("Executing %sVM operation: %s", prev_vm_operation != NULL ? "nested " : "", op->name());
399399

400400
log_debug(vmthread)("Evaluating %s %s VM operation: %s",
401401
prev_vm_operation != NULL ? "nested" : "",

src/hotspot/share/utilities/events.cpp

Lines changed: 14 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
EventLog* Events::_logs = NULL;
3737
StringEventLog* Events::_messages = NULL;
38+
StringEventLog* Events::_vm_operations = NULL;
3839
ExceptionsEventLog* Events::_exceptions = NULL;
3940
StringEventLog* Events::_redefinitions = NULL;
4041
UnloadingEventLog* Events::_class_unloading = NULL;
@@ -91,6 +92,7 @@ void Events::print() {
9192
void Events::init() {
9293
if (LogEvents) {
9394
_messages = new StringEventLog("Events", "events");
95+
_vm_operations = new StringEventLog("VM Operations", "vmops");
9496
_exceptions = new ExceptionsEventLog("Internal exceptions", "exc");
9597
_redefinitions = new StringEventLog("Classes redefined", "redef");
9698
_class_unloading = new UnloadingEventLog("Classes unloaded", "unload");
@@ -105,23 +107,20 @@ void eventlog_init() {
105107
///////////////////////////////////////////////////////////////////////////
106108
// EventMark
107109

108-
EventMark::EventMark(const char* format, ...) {
109-
if (LogEvents) {
110-
va_list ap;
111-
va_start(ap, format);
112-
// Save a copy of begin message and log it.
113-
_buffer.printv(format, ap);
114-
Events::log(NULL, "%s", _buffer.buffer());
115-
va_end(ap);
116-
}
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());
117118
}
118119

119-
EventMark::~EventMark() {
120-
if (LogEvents) {
121-
// Append " done" to the begin message and log it
122-
_buffer.append(" done");
123-
Events::log(NULL, "%s", _buffer.buffer());
124-
}
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());
125124
}
126125

127126
void UnloadingEventLog::log(Thread* thread, InstanceKlass* ik) {

src/hotspot/share/utilities/events.hpp

Lines changed: 51 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,9 @@ class Events : AllStatic {
220220
// A log for generic messages that aren't well categorized.
221221
static StringEventLog* _messages;
222222

223+
// A log for VM Operations
224+
static StringEventLog* _vm_operations;
225+
223226
// A log for internal exception related messages, like internal
224227
// throws and implicit exceptions.
225228
static ExceptionsEventLog* _exceptions;
@@ -247,6 +250,8 @@ class Events : AllStatic {
247250
// Logs a generic message with timestamp and format as printf.
248251
static void log(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
249252

253+
static void log_vm_operation(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
254+
250255
// Log exception related message
251256
static void log_exception(Thread* thread, const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
252257
static void log_exception(Thread* thread, Handle h_exception, const char* message, const char* file, int line);
@@ -270,6 +275,15 @@ inline void Events::log(Thread* thread, const char* format, ...) {
270275
}
271276
}
272277

278+
inline void Events::log_vm_operation(Thread* thread, const char* format, ...) {
279+
if (LogEvents && _vm_operations != NULL) {
280+
va_list ap;
281+
va_start(ap, format);
282+
_vm_operations->logv(thread, format, ap);
283+
va_end(ap);
284+
}
285+
}
286+
273287
inline void Events::log_exception(Thread* thread, const char* format, ...) {
274288
if (LogEvents && _exceptions != NULL) {
275289
va_list ap;
@@ -414,16 +428,49 @@ inline void EventLogBase<ExtendedStringLogMessage>::print(outputStream* out, Ext
414428
out->cr();
415429
}
416430

431+
typedef void (*EventLogFunction)(Thread* thread, const char* format, ...);
432+
433+
class EventMarkBase : public StackObj {
434+
EventLogFunction _log_function;
435+
StringLogMessage _buffer;
436+
437+
NONCOPYABLE(EventMarkBase);
438+
439+
protected:
440+
void log_start(const char* format, va_list argp) ATTRIBUTE_PRINTF(2, 0);
441+
void log_end();
442+
443+
EventMarkBase(EventLogFunction log_function);
444+
};
445+
417446
// Place markers for the beginning and end up of a set of events.
418-
// These end up in the default log.
419-
class EventMark : public StackObj {
447+
template <EventLogFunction log_function>
448+
class EventMarkWithLogFunction : public EventMarkBase {
420449
StringLogMessage _buffer;
421450

422451
public:
423452
// log a begin event, format as printf
424-
EventMark(const char* format, ...) ATTRIBUTE_PRINTF(2, 3);
453+
EventMarkWithLogFunction(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) :
454+
EventMarkBase(log_function) {
455+
if (LogEvents) {
456+
va_list ap;
457+
va_start(ap, format);
458+
log_start(format, ap);
459+
va_end(ap);
460+
}
461+
}
425462
// log an end event
426-
~EventMark();
463+
~EventMarkWithLogFunction() {
464+
if (LogEvents) {
465+
log_end();
466+
}
467+
}
427468
};
428469

470+
// These end up in the default log.
471+
typedef EventMarkWithLogFunction<Events::log> EventMark;
472+
473+
// These end up in the vm_operation log.
474+
typedef EventMarkWithLogFunction<Events::log_vm_operation> EventMarkVMOperation;
475+
429476
#endif // SHARE_UTILITIES_EVENTS_HPP

0 commit comments

Comments
 (0)