changeset 34262:43560e879d6d

8143157: Convert TraceVMOperation to Unified Logging Summary: The former -XX:+TraceVMOperation flag is updated to the unified logging framework and is now replaced with -Xlog:vmoperation in product mode. Reviewed-by: coleenp, dholmes, mockner
author rprotacio
date Mon, 23 Nov 2015 16:16:46 -0500
parents 59d76c40998a
children 51465b543879
files hotspot/src/share/vm/logging/logTag.hpp hotspot/src/share/vm/runtime/globals.hpp hotspot/src/share/vm/runtime/vm_operations.cpp hotspot/test/runtime/logging/VMOperationTest.java hotspot/test/runtime/logging/VMOperationTestMain.java
diffstat 5 files changed, 103 insertions(+), 9 deletions(-) [+]
line wrap: on
line diff
--- a/hotspot/src/share/vm/logging/logTag.hpp	Fri Nov 20 12:42:21 2015 +0100
+++ b/hotspot/src/share/vm/logging/logTag.hpp	Mon Nov 23 16:16:46 2015 -0500
@@ -33,7 +33,8 @@
 #define LOG_TAG_LIST \
   LOG_TAG(defaultmethods) \
   LOG_TAG(logging) \
-  LOG_TAG(safepoint)
+  LOG_TAG(safepoint) \
+  LOG_TAG(vmoperation)
 
 #define PREFIX_LOG_TAG(T) (LogTag::T)
 
--- a/hotspot/src/share/vm/runtime/globals.hpp	Fri Nov 20 12:42:21 2015 +0100
+++ b/hotspot/src/share/vm/runtime/globals.hpp	Mon Nov 23 16:16:46 2015 -0500
@@ -1073,9 +1073,6 @@
   develop(bool, BreakAtWarning, false,                                      \
           "Execute breakpoint upon encountering VM warning")                \
                                                                             \
-  develop(bool, TraceVMOperation, false,                                    \
-          "Trace VM operations")                                            \
-                                                                            \
   develop(bool, UseFakeTimers, false,                                       \
           "Tell whether the VM should use system time or a fake timer")     \
                                                                             \
--- a/hotspot/src/share/vm/runtime/vm_operations.cpp	Fri Nov 20 12:42:21 2015 +0100
+++ b/hotspot/src/share/vm/runtime/vm_operations.cpp	Mon Nov 23 16:16:46 2015 -0500
@@ -29,6 +29,7 @@
 #include "code/codeCacheExtensions.hpp"
 #include "compiler/compileBroker.hpp"
 #include "gc/shared/isGCActiveMark.hpp"
+#include "logging/log.hpp"
 #include "memory/heapInspection.hpp"
 #include "memory/resourceArea.hpp"
 #include "oops/symbol.hpp"
@@ -55,13 +56,19 @@
 
 void VM_Operation::evaluate() {
   ResourceMark rm;
-  if (TraceVMOperation) {
-    tty->print("[");
-    NOT_PRODUCT(print();)
+  outputStream* debugstream;
+  bool enabled = log_is_enabled(Debug, vmoperation);
+  if (enabled) {
+    debugstream = LogHandle(vmoperation)::debug_stream();
+    debugstream->print("begin ");
+    print_on_error(debugstream);
+    debugstream->cr();
   }
   doit();
-  if (TraceVMOperation) {
-    tty->print_cr("]");
+  if (enabled) {
+    debugstream->print("end ");
+    print_on_error(debugstream);
+    debugstream->cr();
   }
 }
 
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/logging/VMOperationTest.java	Mon Nov 23 16:16:46 2015 -0500
@@ -0,0 +1,46 @@
+/*
+ * Copyright (c) 2015, 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
+ * @bug 8143157
+ * @summary vmoperation=debug should have logging output
+ * @library /testlibrary
+ * @compile VMOperationTestMain.java
+ * @modules java.base/sun.misc
+ *          java.management
+ * @run main VMOperationTest
+ */
+
+import jdk.test.lib.*;
+
+public class VMOperationTest {
+    public static void main(String[] args) throws Exception {
+        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+            "-Xlog:vmoperation=debug", "-Xmx64m", "-Xms64m", "VMOperationTestMain");
+        OutputAnalyzer output = new OutputAnalyzer(pb.start());
+        output.shouldContain("VM_Operation (");
+        output.shouldHaveExitValue(0);
+    }
+}
+
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/logging/VMOperationTestMain.java	Mon Nov 23 16:16:46 2015 -0500
@@ -0,0 +1,43 @@
+/*
+ * Copyright (c) 2015, 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.
+ */
+
+import java.lang.ref.WeakReference;
+
+public class VMOperationTestMain {
+    public static byte[] garbage;
+    public static volatile WeakReference<Object> weakref;
+
+    public static void createweakref() {
+        Object o = new Object();
+        weakref = new WeakReference<>(o);
+    }
+
+    // Loop until a GC runs.
+    public static void main(String[] args) throws Exception {
+        createweakref();
+        while (weakref.get() != null) {
+            garbage = new byte[8192];
+            System.gc();
+        }
+    }
+}