7164841: Improvements to the GC log file rotation

Made changes to easily identify current log file in rotation. Parameterize the input with %t for time replacement in file name.

Reviewed-by: ccheung, tschatzl, tamao, zgu
This commit is contained in:
Yumin Qi 2013-09-16 15:35:04 -07:00 committed by Yumin Qi
parent dffefd9ecf
commit 0cd7bc2cde
4 changed files with 357 additions and 102 deletions

View file

@ -1839,7 +1839,7 @@ void check_gclog_consistency() {
(NumberOfGCLogFiles == 0) ||
(GCLogFileSize == 0)) {
jio_fprintf(defaultStream::output_stream(),
"To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>\n"
"To enable GC log rotation, use -Xloggc:<filename> -XX:+UseGCLogFileRotation -XX:NumberOfGCLogFiles=<num_of_files> -XX:GCLogFileSize=<num_of_size>[k|K|m|M|g|G]\n"
"where num_of_file > 0 and num_of_size > 0\n"
"GC log rotation is turned off\n");
UseGCLogFileRotation = false;
@ -1853,6 +1853,51 @@ void check_gclog_consistency() {
}
}
// This function is called for -Xloggc:<filename>, it can be used
// to check if a given file name(or string) conforms to the following
// specification:
// A valid string only contains "[A-Z][a-z][0-9].-_%[p|t]"
// %p and %t only allowed once. We only limit usage of filename not path
bool is_filename_valid(const char *file_name) {
const char* p = file_name;
char file_sep = os::file_separator()[0];
const char* cp;
// skip prefix path
for (cp = file_name; *cp != '\0'; cp++) {
if (*cp == '/' || *cp == file_sep) {
p = cp + 1;
}
}
int count_p = 0;
int count_t = 0;
while (*p != '\0') {
if ((*p >= '0' && *p <= '9') ||
(*p >= 'A' && *p <= 'Z') ||
(*p >= 'a' && *p <= 'z') ||
*p == '-' ||
*p == '_' ||
*p == '.') {
p++;
continue;
}
if (*p == '%') {
if(*(p + 1) == 'p') {
p += 2;
count_p ++;
continue;
}
if (*(p + 1) == 't') {
p += 2;
count_t ++;
continue;
}
}
return false;
}
return count_p < 2 && count_t < 2;
}
// Check consistency of GC selection
bool Arguments::check_gc_consistency() {
check_gclog_consistency();
@ -2806,6 +2851,13 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
// ostream_init_log(), when called will use this filename
// to initialize a fileStream.
_gc_log_filename = strdup(tail);
if (!is_filename_valid(_gc_log_filename)) {
jio_fprintf(defaultStream::output_stream(),
"Invalid file name for use with -Xloggc: Filename can only contain the "
"characters [A-Z][a-z][0-9]-_.%%[p|t] but it has been %s\n"
"Note %%p or %%t can only be used once\n", _gc_log_filename);
return JNI_EINVAL;
}
FLAG_SET_CMDLINE(bool, PrintGC, true);
FLAG_SET_CMDLINE(bool, PrintGCTimeStamps, true);