changeset 10133:9c3642cc96c2

Merge
author brutisso
date Thu, 28 Jan 2016 10:18:45 +0100
parents 269ee0058c3d 3222fbebdd06
children 33399d3a06f4 dd70920e6ee9 6d650a9f831d
files
diffstat 4 files changed, 146 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/src/share/vm/runtime/arguments.cpp	Wed Jan 27 14:50:56 2016 +0100
+++ b/src/share/vm/runtime/arguments.cpp	Thu Jan 28 10:18:45 2016 +0100
@@ -83,6 +83,7 @@
 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 @@
     // -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 @@
   }
 }
 
+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 @@
     ScavengeRootsInCode = 1;
   }
 
+  if (!handle_deprecated_print_gc_flags()) {
+    return JNI_EINVAL;
+  }
+
   // Set object alignment values.
   set_object_alignment();
 
--- a/src/share/vm/runtime/arguments.hpp	Wed Jan 27 14:50:56 2016 +0100
+++ b/src/share/vm/runtime/arguments.hpp	Thu Jan 28 10:18:45 2016 +0100
@@ -294,6 +294,7 @@
 
   // 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 @@
   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);
--- a/src/share/vm/runtime/globals.hpp	Wed Jan 27 14:50:56 2016 +0100
+++ b/src/share/vm/runtime/globals.hpp	Thu Jan 28 10:18:45 2016 +0100
@@ -2391,6 +2391,14 @@
           "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")                                         \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/gc/logging/TestDeprecatedPrintFlags.java	Thu Jan 28 10:18:45 2016 +0100
@@ -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();
+    }
+}