# HG changeset patch # User mlarsson # Date 1449259499 0 # Node ID cc2e5d4a7ac5c5b73777c12697fdc88f93e6bc66 # Parent 445881c8c46ee584ade99828c0447d0c058637bb# Parent 9b9298044d233cb2e225594db60b889521d6499a Merge diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logConfiguration.cpp --- a/hotspot/src/share/vm/logging/logConfiguration.cpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logConfiguration.cpp Fri Dec 04 20:04:59 2015 +0000 @@ -39,6 +39,7 @@ LogOutput** LogConfiguration::_outputs = NULL; size_t LogConfiguration::_n_outputs = 0; +bool LogConfiguration::_post_initialized = false; void LogConfiguration::post_initialize() { assert(LogConfiguration_lock != NULL, "Lock must be initialized before post-initialization"); @@ -51,6 +52,8 @@ MutexLocker ml(LogConfiguration_lock); describe(log.trace_stream()); } + + _post_initialized = true; } void LogConfiguration::initialize(jlong vm_start_time) { @@ -422,3 +425,12 @@ "\t Turn off all logging, including warnings and errors,\n" "\t and then enable messages tagged with 'rt' using 'trace' level to file 'rttrace.txt'.\n"); } + +void LogConfiguration::rotate_all_outputs() { + for (size_t idx = 0; idx < _n_outputs; idx++) { + if (_outputs[idx]->is_rotatable()) { + _outputs[idx]->rotate(true); + } + } +} + diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logConfiguration.hpp --- a/hotspot/src/share/vm/logging/logConfiguration.hpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logConfiguration.hpp Fri Dec 04 20:04:59 2015 +0000 @@ -40,6 +40,7 @@ private: static LogOutput** _outputs; static size_t _n_outputs; + static bool _post_initialized; // Create a new output. Returns NULL if failed. static LogOutput* new_output(char* name, const char* options = NULL); @@ -94,6 +95,13 @@ // Prints usage help for command line log configuration. static void print_command_line_help(FILE* out); + + static bool is_post_initialized() { + return _post_initialized; + } + + // Rotates all LogOutput + static void rotate_all_outputs(); }; #endif // SHARE_VM_LOGGING_LOGCONFIGURATION_HPP diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logDiagnosticCommand.cpp --- a/hotspot/src/share/vm/logging/logDiagnosticCommand.cpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logDiagnosticCommand.cpp Fri Dec 04 20:04:59 2015 +0000 @@ -35,13 +35,15 @@ _what("what", "Configures what tags to log.", "STRING", false), _decorators("decorators", "Configures which decorators to use. Use 'none' or an empty value to remove all.", "STRING", false), _disable("disable", "Turns off all logging and clears the log configuration.", "BOOLEAN", false), - _list("list", "Lists current log configuration.", "BOOLEAN", false) { + _list("list", "Lists current log configuration.", "BOOLEAN", false), + _rotate("rotate", "Rotates all logs.", "BOOLEAN", false) { _dcmdparser.add_dcmd_option(&_output); _dcmdparser.add_dcmd_option(&_output_options); _dcmdparser.add_dcmd_option(&_what); _dcmdparser.add_dcmd_option(&_decorators); _dcmdparser.add_dcmd_option(&_disable); _dcmdparser.add_dcmd_option(&_list); + _dcmdparser.add_dcmd_option(&_rotate); } int LogDiagnosticCommand::num_arguments() { @@ -86,6 +88,11 @@ any_command = true; } + if (_rotate.has_value()) { + LogConfiguration::rotate_all_outputs(); + any_command = true; + } + if (!any_command) { // If no argument was provided, print usage print_help(LogDiagnosticCommand::name()); diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logDiagnosticCommand.hpp --- a/hotspot/src/share/vm/logging/logDiagnosticCommand.hpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logDiagnosticCommand.hpp Fri Dec 04 20:04:59 2015 +0000 @@ -43,6 +43,7 @@ DCmdArgument _decorators; DCmdArgument _disable; DCmdArgument _list; + DCmdArgument _rotate; public: LogDiagnosticCommand(outputStream* output, bool heap_allocated); @@ -55,7 +56,7 @@ } static const char* description() { - return "Lists, enables, disables or changes a log output configuration."; + return "Lists current log configuration, enables/disables/configures a log output, or rotates all logs."; } // Used by SecurityManager. This DCMD requires ManagementPermission = control. diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logFileOutput.cpp --- a/hotspot/src/share/vm/logging/logFileOutput.cpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logFileOutput.cpp Fri Dec 04 20:04:59 2015 +0000 @@ -155,12 +155,7 @@ int written = LogFileStreamOutput::write(decorations, msg); _current_size += written; - if (should_rotate()) { - MutexLockerEx ml(&_rotation_lock, true /* no safepoint check */); - if (should_rotate()) { - rotate(); - } - } + rotate(false); return written; } @@ -182,7 +177,14 @@ } } -void LogFileOutput::rotate() { +void LogFileOutput::rotate(bool force) { + + if (!should_rotate(force)) { + return; + } + + MutexLockerEx ml(&_rotation_lock, true /* no safepoint check */); + // Archive the current log file archive(); diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logFileOutput.hpp --- a/hotspot/src/share/vm/logging/logFileOutput.hpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logFileOutput.hpp Fri Dec 04 20:04:59 2015 +0000 @@ -58,13 +58,13 @@ size_t _current_size; void archive(); - void rotate(); bool configure_rotation(const char* options); char *make_file_name(const char* file_name, const char* pid_string, const char* timestamp_string); static size_t parse_value(const char* value_str); - bool should_rotate() const { - return _file_count > 0 && _rotate_size > 0 && _current_size >= _rotate_size; + bool should_rotate(bool force) { + return is_rotatable() && + (force || (_rotate_size > 0 && _current_size >= _rotate_size)); } public: @@ -73,6 +73,12 @@ virtual bool initialize(const char* options); virtual int write(const LogDecorations& decorations, const char* msg); + virtual bool is_rotatable() { + return LogConfiguration::is_post_initialized() && (_file_count > 0); + } + + virtual void rotate(bool force); + virtual const char* name() const { return _name; } diff -r 445881c8c46e -r cc2e5d4a7ac5 hotspot/src/share/vm/logging/logOutput.hpp --- a/hotspot/src/share/vm/logging/logOutput.hpp Fri Dec 04 16:19:09 2015 +0000 +++ b/hotspot/src/share/vm/logging/logOutput.hpp Fri Dec 04 20:04:59 2015 +0000 @@ -75,6 +75,14 @@ virtual const char* name() const = 0; virtual bool initialize(const char* options) = 0; virtual int write(const LogDecorations &decorations, const char* msg) = 0; + + virtual bool is_rotatable() { + return false; + } + + virtual void rotate(bool force) { + // Do nothing by default. + } }; #endif // SHARE_VM_LOGGING_LOGOUTPUT_HPP