Skip to content
This repository has been archived by the owner. It is now read-only.
Permalink
Browse files
8246135: Save important GC log lines and print them when dumping hs_e…
…rr files

Reviewed-by: sjohanss, pliden, eosterlund
  • Loading branch information
stefank committed Jun 3, 2020
1 parent 1314ca8 commit 5fc89b6e72d243797eb7bdcd003618841c2dde51
@@ -0,0 +1,67 @@
/*
* Copyright (c) 2020, 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.
*/

#include "precompiled.hpp"
#include "gc/shared/gcLogPrecious.hpp"
#include "runtime/mutex.hpp"
#include "runtime/mutexLocker.hpp"

stringStream* GCLogPrecious::_lines = NULL;
stringStream* GCLogPrecious::_temp = NULL;
Mutex* GCLogPrecious::_lock = NULL;

void GCLogPrecious::initialize() {
_lines = new (ResourceObj::C_HEAP, mtGC) stringStream();
_temp = new (ResourceObj::C_HEAP, mtGC) stringStream();
_lock = new Mutex(Mutex::tty,
"GCLogPrecious Lock",
true,
Mutex::_safepoint_check_never);
}

void GCLogPrecious::vwrite_inner(LogTargetHandle log, const char* format, va_list args) {
// Generate the string in the temp buffer
_temp->reset();
_temp->vprint(format, args);

// Save it in the precious lines buffer
_lines->print_cr(" %s", _temp->base());

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

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::print_on_error(outputStream* st) {
if (_lines != NULL) {
MutexLocker locker(_lock, Mutex::_no_safepoint_check_flag);
if (_lines->size() > 0) {
st->print_cr("GC Precious Log:");
st->print_cr("%s", _lines->base());
}
}
}
@@ -0,0 +1,83 @@
/*
* Copyright (c) 2020, 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.
*/

#ifndef SHARE_GC_SHARED_GCLOGPRECIOUS_HPP
#define SHARE_GC_SHARED_GCLOGPRECIOUS_HPP

#include "utilities/globalDefinitions.hpp"
#include "logging/logHandle.hpp"
#include "memory/allocation.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_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

class GCLogPrecious : public AllStatic {
private:
// Saved precious lines
static stringStream* _lines;
// Temporary line buffer
static stringStream* _temp;
// Protects the buffers
static Mutex* _lock;

static void vwrite_inner(LogTargetHandle log,
const char* format,
va_list args) ATTRIBUTE_PRINTF(2, 0);

public:
static void initialize();

static void vwrite(LogTargetHandle log,
const char* format,
va_list args) ATTRIBUTE_PRINTF(2, 0);

static void print_on_error(outputStream* st);
};

class GCLogPreciousHandle {
LogTargetHandle _log;

public:
GCLogPreciousHandle(LogTargetHandle log) : _log(log) {}

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

#endif // SHARE_GC_SHARED_GCLOGPRECIOUS_HPP
@@ -37,6 +37,7 @@
#include "gc/shared/collectedHeap.inline.hpp"
#include "gc/shared/gcArguments.hpp"
#include "gc/shared/gcConfig.hpp"
#include "gc/shared/gcLogPrecious.hpp"
#include "gc/shared/gcTraceTime.inline.hpp"
#include "interpreter/interpreter.hpp"
#include "logging/log.hpp"
@@ -651,6 +652,8 @@ jint universe_init() {

initialize_global_behaviours();

GCLogPrecious::initialize();

GCConfig::arguments()->initialize_heap_sizes();

jint status = Universe::initialize_heap();
@@ -28,6 +28,7 @@
#include "compiler/compileBroker.hpp"
#include "compiler/disassembler.hpp"
#include "gc/shared/gcConfig.hpp"
#include "gc/shared/gcLogPrecious.hpp"
#include "logging/logConfiguration.hpp"
#include "memory/metaspace.hpp"
#include "memory/metaspaceShared.hpp"
@@ -927,11 +928,15 @@ void VMError::report(outputStream* st, bool _verbose) {

STEP("printing heap information")

if (_verbose && Universe::is_fully_initialized()) {
Universe::heap()->print_on_error(st);
st->cr();
st->print_cr("Polling page: " INTPTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));
st->cr();
if (_verbose) {
GCLogPrecious::print_on_error(st);

if (Universe::is_fully_initialized()) {
Universe::heap()->print_on_error(st);
st->cr();
st->print_cr("Polling page: " INTPTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));
st->cr();
}
}

STEP("printing metaspace information")
@@ -1133,6 +1138,7 @@ void VMError::print_vm_info(outputStream* st) {

if (Universe::is_fully_initialized()) {
MutexLocker hl(Heap_lock);
GCLogPrecious::print_on_error(st);
Universe::heap()->print_on_error(st);
st->cr();
st->print_cr("Polling page: " INTPTR_FORMAT, p2i(SafepointMechanism::get_polling_page()));

0 comments on commit 5fc89b6

Please sign in to comment.