--- a/hotspot/src/share/vm/logging/logTag.hpp Tue Dec 15 16:01:00 2015 +0000
+++ b/hotspot/src/share/vm/logging/logTag.hpp Tue Dec 15 17:57:08 2015 +0000
@@ -55,6 +55,7 @@
LOG_TAG(logging) \
LOG_TAG(marking) \
LOG_TAG(metaspace) \
+ LOG_TAG(monitorinflation) \
LOG_TAG(phases) \
LOG_TAG(plab) \
LOG_TAG(promotion) \
--- a/hotspot/src/share/vm/runtime/arguments.cpp Tue Dec 15 16:01:00 2015 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.cpp Tue Dec 15 17:57:08 2015 +0000
@@ -399,6 +399,12 @@
{ NULL, NULL}
};
+static AliasedFlag const aliased_jvm_logging_flags[] = {
+ { "-XX:+TraceMonitorInflation", "-Xlog:monitorinflation=debug" },
+ { "-XX:-TraceMonitorInflation", "-Xlog:monitorinflation=off" },
+ { NULL, NULL }
+};
+
// Return true if "v" is less than "other", where "other" may be "undefined".
static bool version_less_than(JDK_Version v, JDK_Version other) {
assert(!v.is_undefined(), "must be defined");
@@ -929,6 +935,20 @@
return NULL;
}
+// lookup_logging_aliases
+// Called from parse_each_vm_init_arg(). Should be called on -XX options before specific cases are checked.
+// If arg matches any aliased_jvm_logging_flags entry, look up the real name and copy it into buffer.
+bool Arguments::lookup_logging_aliases(const char* arg, char* buffer) {
+ for (size_t i = 0; aliased_jvm_logging_flags[i].alias_name != NULL; i++) {
+ const AliasedFlag& flag_status = aliased_jvm_logging_flags[i];
+ if (strcmp(flag_status.alias_name, arg) == 0) {
+ strcpy(buffer, flag_status.real_name);
+ return true;
+ }
+ }
+ return false;
+}
+
bool Arguments::parse_argument(const char* arg, Flag::Flags origin) {
// range of acceptable characters spelled out for portability reasons
@@ -2605,7 +2625,7 @@
for (int index = 0; index < args->nOptions; index++) {
bool is_absolute_path = false; // for -agentpath vs -agentlib
- const JavaVMOption* option = args->options + index;
+ JavaVMOption* option = args->options + index;
if (!match_option(option, "-Djava.class.path", &tail) &&
!match_option(option, "-Dsun.java.command", &tail) &&
@@ -2619,6 +2639,16 @@
build_jvm_args(option->optionString);
}
+ // char buffer to store looked up logging option.
+ char aliased_logging_option[256];
+
+ // Catch -XX options which are aliased to Unified logging commands.
+ if (match_option(option, "-XX:", &tail)) {
+ if (lookup_logging_aliases(option->optionString, aliased_logging_option)) {
+ option->optionString = aliased_logging_option;
+ }
+ }
+
// -verbose:[class/gc/jni]
if (match_option(option, "-verbose", &tail)) {
if (!strcmp(tail, ":class") || !strcmp(tail, "")) {
--- a/hotspot/src/share/vm/runtime/arguments.hpp Tue Dec 15 16:01:00 2015 +0000
+++ b/hotspot/src/share/vm/runtime/arguments.hpp Tue Dec 15 17:57:08 2015 +0000
@@ -445,6 +445,7 @@
// Return the "real" name for option arg if arg is an alias, and print a warning if arg is deprecated.
// Return NULL if the arg has expired.
static const char* handle_aliases_and_deprecation(const char* arg, bool warn);
+ static bool lookup_logging_aliases(const char* arg, char* buffer);
static short CompileOnlyClassesNum;
static short CompileOnlyClassesMax;
--- a/hotspot/src/share/vm/runtime/globals.hpp Tue Dec 15 16:01:00 2015 +0000
+++ b/hotspot/src/share/vm/runtime/globals.hpp Tue Dec 15 17:57:08 2015 +0000
@@ -1506,9 +1506,6 @@
product(bool, TraceBiasedLocking, false, \
"Trace biased locking in JVM") \
\
- product(bool, TraceMonitorInflation, false, \
- "Trace monitor inflation in JVM") \
- \
/* gc */ \
\
product(bool, UseSerialGC, false, \
--- a/hotspot/src/share/vm/runtime/synchronizer.cpp Tue Dec 15 16:01:00 2015 +0000
+++ b/hotspot/src/share/vm/runtime/synchronizer.cpp Tue Dec 15 17:57:08 2015 +0000
@@ -24,6 +24,7 @@
#include "precompiled.hpp"
#include "classfile/vmSymbols.hpp"
+#include "logging/log.hpp"
#include "memory/metaspaceShared.hpp"
#include "memory/padded.hpp"
#include "memory/resourceArea.hpp"
@@ -1414,12 +1415,12 @@
// to avoid false sharing on MP systems ...
OM_PERFDATA_OP(Inflations, inc());
TEVENT(Inflate: overwrite stacklock);
- if (TraceMonitorInflation) {
+ if (log_is_enabled(Debug, monitorinflation)) {
if (object->is_instance()) {
ResourceMark rm;
- tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
- p2i(object), p2i(object->mark()),
- object->klass()->external_name());
+ log_debug(monitorinflation)("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
+ p2i(object), p2i(object->mark()),
+ object->klass()->external_name());
}
}
return m;
@@ -1462,12 +1463,12 @@
// cache lines to avoid false sharing on MP systems ...
OM_PERFDATA_OP(Inflations, inc());
TEVENT(Inflate: overwrite neutral);
- if (TraceMonitorInflation) {
+ if (log_is_enabled(Debug, monitorinflation)) {
if (object->is_instance()) {
ResourceMark rm;
- tty->print_cr("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
- p2i(object), p2i(object->mark()),
- object->klass()->external_name());
+ log_debug(monitorinflation)("Inflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
+ p2i(object), p2i(object->mark()),
+ object->klass()->external_name());
}
}
return m;
@@ -1526,11 +1527,13 @@
// It's idle - scavenge and return to the global free list
// plain old deflation ...
TEVENT(deflate_idle_monitors - scavenge1);
- if (TraceMonitorInflation) {
+ if (log_is_enabled(Debug, monitorinflation)) {
if (obj->is_instance()) {
ResourceMark rm;
- tty->print_cr("Deflating object " INTPTR_FORMAT " , mark " INTPTR_FORMAT " , type %s",
- p2i(obj), p2i(obj->mark()), obj->klass()->external_name());
+ log_debug(monitorinflation)("Deflating object " INTPTR_FORMAT " , "
+ "mark " INTPTR_FORMAT " , type %s",
+ p2i(obj), p2i(obj->mark()),
+ obj->klass()->external_name());
}
}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/hotspot/test/runtime/logging/MonitorInflationTest.java Tue Dec 15 17:57:08 2015 +0000
@@ -0,0 +1,68 @@
+/*
+ * 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 8133885
+ * @summary monitorinflation=debug should have logging from each of the statements in the code
+ * @library /testlibrary
+ * @modules java.base/sun.misc
+ * java.management
+ * @build MonitorInflationTest
+ * @run driver MonitorInflationTest
+ */
+
+import jdk.test.lib.*;
+
+public class MonitorInflationTest {
+ static void analyzeOutputOn(ProcessBuilder pb) throws Exception {
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+ output.shouldContain("Inflating object");
+ output.shouldContain("Deflating object ");
+ output.shouldHaveExitValue(0);
+ }
+
+ static void analyzeOutputOff(ProcessBuilder pb) throws Exception {
+ OutputAnalyzer output = new OutputAnalyzer(pb.start());
+ output.shouldNotContain("[monitorinflation]");
+ output.shouldHaveExitValue(0);
+ }
+
+ public static void main(String[] args) throws Exception {
+ ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
+ "-Xlog:monitorinflation=debug", "-version");
+ analyzeOutputOn(pb);
+
+ pb = ProcessTools.createJavaProcessBuilder(
+ "-XX:+TraceMonitorInflation", "-version");
+ analyzeOutputOn(pb);
+
+ pb = ProcessTools.createJavaProcessBuilder(
+ "-Xlog:monitorinflation=off", "-version");
+ analyzeOutputOff(pb);
+
+ pb = ProcessTools.createJavaProcessBuilder(
+ "-XX:-TraceMonitorInflation", "-version");
+ analyzeOutputOff(pb);
+ }
+}