This repository has been archived by the owner. It is now read-only.
Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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
Showing
with
164 additions
and 5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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()); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters