8140556: Add force rotation option to VM.log jcmd
Summary: Rotate JVM log files via jcmd
Reviewed-by: sla, mlarsson
--- a/hotspot/src/share/vm/logging/logConfiguration.cpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logConfiguration.cpp Thu Dec 03 22:42:28 2015 +0900
@@ -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);
+ }
+ }
+}
+
--- a/hotspot/src/share/vm/logging/logConfiguration.hpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logConfiguration.hpp Thu Dec 03 22:42:28 2015 +0900
@@ -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
--- a/hotspot/src/share/vm/logging/logDiagnosticCommand.cpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logDiagnosticCommand.cpp Thu Dec 03 22:42:28 2015 +0900
@@ -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());
--- a/hotspot/src/share/vm/logging/logDiagnosticCommand.hpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logDiagnosticCommand.hpp Thu Dec 03 22:42:28 2015 +0900
@@ -43,6 +43,7 @@
DCmdArgument<char *> _decorators;
DCmdArgument<bool> _disable;
DCmdArgument<bool> _list;
+ DCmdArgument<bool> _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.
--- a/hotspot/src/share/vm/logging/logFileOutput.cpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logFileOutput.cpp Thu Dec 03 22:42:28 2015 +0900
@@ -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();
--- a/hotspot/src/share/vm/logging/logFileOutput.hpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logFileOutput.hpp Thu Dec 03 22:42:28 2015 +0900
@@ -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;
}
--- a/hotspot/src/share/vm/logging/logOutput.hpp Fri Dec 04 04:06:37 2015 -0500
+++ b/hotspot/src/share/vm/logging/logOutput.hpp Thu Dec 03 22:42:28 2015 +0900
@@ -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