mirror of
https://github.com/openjdk/jdk.git
synced 2025-08-27 14:54:52 +02:00
8145180: Add back PrintGC, PrintGCDetails and -Xloggc
Reviewed-by: sjohanss, david
This commit is contained in:
parent
1fdb299974
commit
31ca2b7010
4 changed files with 146 additions and 0 deletions
|
@ -83,6 +83,7 @@ char** Arguments::_jvm_args_array = NULL;
|
|||
int Arguments::_num_jvm_args = 0;
|
||||
char* Arguments::_java_command = NULL;
|
||||
SystemProperty* Arguments::_system_properties = NULL;
|
||||
const char* Arguments::_gc_log_filename = NULL;
|
||||
bool Arguments::_has_profile = false;
|
||||
size_t Arguments::_conservative_max_heap_alignment = 0;
|
||||
size_t Arguments::_min_heap_size = 0;
|
||||
|
@ -3090,6 +3091,10 @@ jint Arguments::parse_each_vm_init_arg(const JavaVMInitArgs* args,
|
|||
// -Xnoagent
|
||||
} else if (match_option(option, "-Xnoagent")) {
|
||||
// For compatibility with classic. HotSpot refuses to load the old style agent.dll.
|
||||
} else if (match_option(option, "-Xloggc:", &tail)) {
|
||||
// Deprecated flag to redirect GC output to a file. -Xloggc:<filename>
|
||||
log_warning(gc)("-Xloggc is deprecated. Will use -Xlog:gc:%s instead.", tail);
|
||||
_gc_log_filename = os::strdup_check_oom(tail);
|
||||
} else if (match_option(option, "-Xlog", &tail)) {
|
||||
bool ret = false;
|
||||
if (strcmp(tail, ":help") == 0) {
|
||||
|
@ -3999,6 +4004,24 @@ static void print_options(const JavaVMInitArgs *args) {
|
|||
}
|
||||
}
|
||||
|
||||
bool Arguments::handle_deprecated_print_gc_flags() {
|
||||
if (PrintGC) {
|
||||
log_warning(gc)("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead.");
|
||||
}
|
||||
if (PrintGCDetails) {
|
||||
log_warning(gc)("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");
|
||||
}
|
||||
|
||||
if (_gc_log_filename != NULL) {
|
||||
// -Xloggc was used to specify a filename
|
||||
const char* gc_conf = PrintGCDetails ? "gc*" : "gc";
|
||||
return LogConfiguration::parse_log_arguments(_gc_log_filename, gc_conf, NULL, NULL, NULL);
|
||||
} else if (PrintGC || PrintGCDetails) {
|
||||
LogConfiguration::configure_stdout(LogLevel::Info, !PrintGCDetails, LOG_TAGS(gc));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Parse entry point called from JNI_CreateJavaVM
|
||||
|
||||
jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
|
||||
|
@ -4147,6 +4170,10 @@ jint Arguments::parse(const JavaVMInitArgs* initial_cmd_args) {
|
|||
ScavengeRootsInCode = 1;
|
||||
}
|
||||
|
||||
if (!handle_deprecated_print_gc_flags()) {
|
||||
return JNI_EINVAL;
|
||||
}
|
||||
|
||||
// Set object alignment values.
|
||||
set_object_alignment();
|
||||
|
||||
|
|
|
@ -294,6 +294,7 @@ class Arguments : AllStatic {
|
|||
|
||||
// Option flags
|
||||
static bool _has_profile;
|
||||
static const char* _gc_log_filename;
|
||||
// Value of the conservative maximum heap alignment needed
|
||||
static size_t _conservative_max_heap_alignment;
|
||||
|
||||
|
@ -400,6 +401,8 @@ class Arguments : AllStatic {
|
|||
static jint match_special_option_and_act(const JavaVMInitArgs* args,
|
||||
ScopedVMInitArgs* args_out);
|
||||
|
||||
static bool handle_deprecated_print_gc_flags();
|
||||
|
||||
static jint parse_vm_init_args(const JavaVMInitArgs *java_tool_options_args,
|
||||
const JavaVMInitArgs *java_options_args,
|
||||
const JavaVMInitArgs *cmd_line_args);
|
||||
|
|
|
@ -2391,6 +2391,14 @@ public:
|
|||
"will sleep while yielding before giving up and resuming GC") \
|
||||
range(0, max_juint) \
|
||||
\
|
||||
product(bool, PrintGC, false, \
|
||||
"Print message at garbage collection. " \
|
||||
"Deprecated, use -Xlog:gc instead.") \
|
||||
\
|
||||
product(bool, PrintGCDetails, false, \
|
||||
"Print more details at garbage collection. " \
|
||||
"Deprecated, use -Xlog:gc* instead.") \
|
||||
\
|
||||
develop(intx, ConcGCYieldTimeout, 0, \
|
||||
"If non-zero, assert that GC threads yield within this " \
|
||||
"number of milliseconds") \
|
||||
|
|
108
hotspot/test/gc/logging/TestDeprecatedPrintFlags.java
Normal file
108
hotspot/test/gc/logging/TestDeprecatedPrintFlags.java
Normal file
|
@ -0,0 +1,108 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 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.
|
||||
*/
|
||||
|
||||
/*
|
||||
* @test TestDeprecatedPrintFlags
|
||||
* @bug 8145180
|
||||
* @summary Verify PrintGC, PrintGCDetails and -Xloggc
|
||||
* @key gc
|
||||
* @library /testlibrary
|
||||
* @modules java.base/sun.misc
|
||||
* java.management
|
||||
*/
|
||||
|
||||
import jdk.test.lib.*;
|
||||
import java.io.File;
|
||||
import java.nio.file.Files;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class TestDeprecatedPrintFlags {
|
||||
|
||||
public static void testPrintGC() throws Exception {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGC", "DoGC");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("-XX:+PrintGC is deprecated. Will use -Xlog:gc instead.");
|
||||
output.shouldNotContain("PrintGCDetails");
|
||||
output.stdoutShouldMatch("\\[info.*\\]\\[gc\\]");
|
||||
output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
|
||||
output.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
public static void testPrintGCDetails() throws Exception {
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "DoGC");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");
|
||||
output.shouldNotContain("PrintGC is deprecated");
|
||||
output.stdoutShouldMatch("\\[info.*\\]\\[gc\\]");
|
||||
output.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");
|
||||
output.shouldHaveExitValue(0);
|
||||
}
|
||||
|
||||
public static void testXloggc() throws Exception {
|
||||
String fileName = "gc-test.log";
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xloggc:" + fileName, "DoGC");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");
|
||||
output.shouldNotContain("PrintGCDetails");
|
||||
output.shouldNotContain("PrintGC");
|
||||
output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\]");
|
||||
output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
|
||||
output.shouldHaveExitValue(0);
|
||||
String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());
|
||||
System.out.println("lines: " + lines);
|
||||
OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");
|
||||
outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\]");
|
||||
outputLog.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
|
||||
}
|
||||
|
||||
public static void testXloggcWithPrintGCDetails() throws Exception {
|
||||
String fileName = "gc-test.log";
|
||||
ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-XX:+PrintGCDetails", "-Xloggc:" + fileName, "DoGC");
|
||||
OutputAnalyzer output = new OutputAnalyzer(pb.start());
|
||||
output.shouldContain("-XX:+PrintGCDetails is deprecated. Will use -Xlog:gc* instead.");
|
||||
output.shouldContain("-Xloggc is deprecated. Will use -Xlog:gc:gc-test.log instead.");
|
||||
output.shouldNotContain("PrintGC is deprecated");
|
||||
output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\]");
|
||||
output.stdoutShouldNotMatch("\\[info.*\\]\\[gc\\,");
|
||||
output.shouldHaveExitValue(0);
|
||||
String lines = Files.lines(Paths.get(fileName)).collect(Collectors.joining());
|
||||
OutputAnalyzer outputLog = new OutputAnalyzer(lines, "");
|
||||
outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\]");
|
||||
outputLog.stdoutShouldMatch("\\[info.*\\]\\[gc\\,");
|
||||
}
|
||||
|
||||
public static void main(String[] args) throws Exception {
|
||||
testPrintGC();
|
||||
testPrintGCDetails();
|
||||
testXloggc();
|
||||
testXloggcWithPrintGCDetails();
|
||||
}
|
||||
}
|
||||
|
||||
class DoGC {
|
||||
public static void main(String[] args) {
|
||||
System.gc();
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue