Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246405: Add GCLogPrecious functionality to log and report debug errors
Reviewed-by: pliden, eosterlund
  • Loading branch information
stefank committed Jun 5, 2020
1 parent aee7490 commit 1c27ce30b47d9e8fdbefa1158c65b79f0df6f6d9
Showing with 53 additions and 4 deletions.
  1. +20 −0 src/hotspot/share/gc/shared/gcLogPrecious.cpp
  2. +33 −4 src/hotspot/share/gc/shared/gcLogPrecious.hpp
@@ -49,13 +49,33 @@ void GCLogPrecious::vwrite_inner(LogTargetHandle log, const char* format, va_lis

// Log it to UL
log.print("%s", _temp->base());

// Leave _temp buffer to be used by vwrite_and_debug
}

void GCLogPrecious::vwrite(LogTargetHandle log, const char* format, va_list args) {
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
vwrite_inner(log, format, args);
}

void GCLogPrecious::vwrite_and_debug(LogTargetHandle log,
const char* format,
va_list args
DEBUG_ONLY(COMMA const char* file)
DEBUG_ONLY(COMMA int line)) {
DEBUG_ONLY(const char* debug_message;)

{
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
vwrite_inner(log, format, args);
DEBUG_ONLY(debug_message = strdup(_temp->base()));
}

// report error outside lock scope, since report_vm_error will call print_on_error
DEBUG_ONLY(report_vm_error(file, line, debug_message);)
DEBUG_ONLY(BREAKPOINT;)
}

void GCLogPrecious::print_on_error(outputStream* st) {
if (_lines != NULL) {
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
@@ -27,22 +27,30 @@
#include "utilities/globalDefinitions.hpp"
#include "logging/logHandle.hpp"
#include "memory/allocation.hpp"
#include "utilities/debug.hpp"

class Mutex;
class stringStream;

// Log lines to both unified logging and save them to a buffer.
// The lines will be printed when hs_err files are created.

#define log_level_p(level, ...) \
GCLogPreciousHandle(LogTargetHandle::create<LogLevel::level, LOG_TAGS(__VA_ARGS__)>())
#define log_level_p(level, ...) \
GCLogPreciousHandle( \
LogTargetHandle::create<LogLevel::level, LOG_TAGS(__VA_ARGS__)>() \
DEBUG_ONLY(COMMA __FILE__ COMMA __LINE__))

#define log_info_p(...) log_level_p(Info, __VA_ARGS__).write
#define log_debug_p(...) log_level_p(Debug, __VA_ARGS__).write
#define log_trace_p(...) log_level_p(Trace, __VA_ARGS__).write
#define log_warning_p(...) log_level_p(Warning, __VA_ARGS__).write
#define log_error_p(...) log_level_p(Error, __VA_ARGS__).write

// ... and report error in debug builds
#define log_error_pd(...) \
DEBUG_ONLY(TOUCH_ASSERT_POISON;) \
log_level_p(Error, __VA_ARGS__).write_and_debug

class GCLogPrecious : public AllStatic {
private:
// Saved precious lines
@@ -63,21 +71,42 @@ class GCLogPrecious : public AllStatic {
const char* format,
va_list args) ATTRIBUTE_PRINTF(2, 0);

static void vwrite_and_debug(LogTargetHandle log,
const char* format,
va_list args
DEBUG_ONLY(COMMA const char* file)
DEBUG_ONLY(COMMA int line)) ATTRIBUTE_PRINTF(2, 0);

static void print_on_error(outputStream* st);
};

class GCLogPreciousHandle {
LogTargetHandle _log;
DEBUG_ONLY(const char* _file);
DEBUG_ONLY(int _line);

public:
GCLogPreciousHandle(LogTargetHandle log) : _log(log) {}
public:
GCLogPreciousHandle(LogTargetHandle log
DEBUG_ONLY(COMMA const char* file)
DEBUG_ONLY(COMMA int line)) :
_log(log)
DEBUG_ONLY(COMMA _file(file))
DEBUG_ONLY(COMMA _line(line))
{}

void write(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
va_list args;
va_start(args, format);
GCLogPrecious::vwrite(_log, format, args);
va_end(args);
}

void write_and_debug(const char* format, ...) ATTRIBUTE_PRINTF(2, 3) {
va_list args;
va_start(args, format);
GCLogPrecious::vwrite_and_debug(_log, format, args DEBUG_ONLY(COMMA _file COMMA _line));
va_end(args);
}
};

#endif // SHARE_GC_SHARED_GCLOGPRECIOUS_HPP

0 comments on commit 1c27ce3

Please sign in to comment.