--- old/src/share/vm/logging/logTag.hpp 2016-09-27 15:18:42.419176110 -0400 +++ new/src/share/vm/logging/logTag.hpp 2016-09-27 15:18:40.075176192 -0400 @@ -105,6 +105,7 @@ LOG_TAG(scavenge) \ LOG_TAG(scrub) \ LOG_TAG(stacktrace) \ + LOG_TAG(stackwalk) \ LOG_TAG(start) \ LOG_TAG(startuptime) \ LOG_TAG(state) \ --- old/src/share/vm/prims/stackwalk.cpp 2016-09-27 15:18:45.803175992 -0400 +++ new/src/share/vm/prims/stackwalk.cpp 2016-09-27 15:18:44.951176022 -0400 @@ -26,6 +26,7 @@ #include "classfile/javaClasses.hpp" #include "classfile/javaClasses.inline.hpp" #include "classfile/vmSymbols.hpp" +#include "logging/log.hpp" #include "memory/oopFactory.hpp" #include "oops/oop.inline.hpp" #include "oops/objArrayOop.inline.hpp" @@ -105,10 +106,8 @@ int max_nframes, int start_index, objArrayHandle frames_array, int& end_index, TRAPS) { - if (TraceStackWalk) { - tty->print_cr("fill_in_frames limit=%d start=%d frames length=%d", - max_nframes, start_index, frames_array->length()); - } + log_trace(stackwalk)("fill_in_frames limit=%d start=%d frames length=%d", + max_nframes, start_index, frames_array->length()); assert(max_nframes > 0, "invalid max_nframes"); assert(start_index + max_nframes <= frames_array->length(), "oob"); @@ -122,18 +121,24 @@ // not set) and when StackWalker::getCallerClass is called if (!ShowHiddenFrames && (skip_hidden_frames(mode) || get_caller_class(mode))) { if (method->is_hidden()) { - if (TraceStackWalk) { - tty->print(" hidden method: "); method->print_short_name(); - tty->print("\n"); + { + ResourceMark rm; + outputStream* st = Log(stackwalk)::trace_stream(); + st->print(" hidden method: "); + method->print_short_name(st); + st->cr(); } continue; } } int index = end_index++; - if (TraceStackWalk) { - tty->print(" %d: frame method: ", index); method->print_short_name(); - tty->print_cr(" bci=%d", stream.bci()); + { + ResourceMark rm; + outputStream* st = Log(stackwalk)::trace_stream(); + st->print(" %d: frame method: ", index); + method->print_short_name(st); + st->print_cr(" bci=%d", stream.bci()); } if (!need_method_info(mode) && get_caller_class(mode) && @@ -317,10 +322,8 @@ TRAPS) { ResourceMark rm(THREAD); JavaThread* jt = (JavaThread*)THREAD; - if (TraceStackWalk) { - tty->print_cr("Start walking: mode " JLONG_FORMAT " skip %d frames batch size %d", - mode, skip_frames, frame_count); - } + log_trace(stackwalk)("Start walking: mode " JLONG_FORMAT " skip %d frames batch size %d", + mode, skip_frames, frame_count); if (frames_array.is_null()) { THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", NULL); @@ -355,8 +358,12 @@ break; } - if (TraceStackWalk) { - tty->print(" skip "); stream.method()->print_short_name(); tty->print("\n"); + { + ResourceMark rm; + outputStream* st = Log(stackwalk)::trace_stream(); + st->print(" skip "); + stream.method()->print_short_name(st); + st->cr(); } stream.next(); } @@ -364,9 +371,11 @@ // stack frame has been traversed individually and resume stack walk // from the stack frame at depth == skip_frames. for (int n=0; n < skip_frames && !stream.at_end(); stream.next(), n++) { - if (TraceStackWalk) { - tty->print(" skip "); stream.method()->print_short_name(); tty->cr(); - } + ResourceMark rm; + outputStream* st = Log(stackwalk)::trace_stream(); + st->print(" skip "); + stream.method()->print_short_name(st); + tty->cr(); } } @@ -438,10 +447,12 @@ THROW_MSG_(vmSymbols::java_lang_NullPointerException(), "frames_array is NULL", 0L); } - if (TraceStackWalk) { - tty->print_cr("StackWalk::fetchNextBatch frame_count %d existing_stream " PTR_FORMAT " start %d frames %d", - frame_count, p2i(existing_stream), start_index, frames_array->length()); - } + log_trace(stackwalk)("StackWalk::fetchNextBatch frame_count %d existing_stream " + PTR_FORMAT " start %d frames %d", + frame_count, + p2i(existing_stream), + start_index, + frames_array->length()); int end_index = start_index; if (frame_count <= 0) { return end_index; // No operation. --- old/src/share/vm/runtime/globals.hpp 2016-09-27 15:18:47.699175926 -0400 +++ new/src/share/vm/runtime/globals.hpp 2016-09-27 15:18:47.191175944 -0400 @@ -2884,9 +2884,6 @@ "exceptions (0 means all)") \ range(0, max_jint/2) \ \ - develop(bool, TraceStackWalk, false, \ - "Trace stack walking") \ - \ /* notice: the max range value here is max_jint, not max_intx */ \ /* because of overflow issue */ \ diagnostic(intx, GuaranteedSafepointInterval, 1000, \ --- /dev/null 2016-09-01 14:58:10.527173586 -0400 +++ new/test/runtime/LocalLong/StackwalkLoggingTest.java 2016-09-27 15:18:48.919175884 -0400 @@ -0,0 +1,63 @@ +/* + * 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 StackwalkLoggingTest + * @bug 8160064 + * @modules java.base/jdk.internal.misc + * @library /test/lib + * @compile LocalLongHelper.java + * @run driver StackwalkLoggingTest + */ + +import jdk.test.lib.Platform; +import jdk.test.lib.process.ProcessTools; +import jdk.test.lib.process.OutputAnalyzer; + +public class StackwalkLoggingTest { + static void analyzeOutputOn(ProcessBuilder pb) throws Exception { + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldContain("Start walking"); + output.shouldContain("fill_in_frames"); + output.shouldHaveExitValue(0); + } + + static void analyzeOutputOff(ProcessBuilder pb) throws Exception { + OutputAnalyzer output = new OutputAnalyzer(pb.start()); + output.shouldNotContain("[stackwalk]"); + output.shouldHaveExitValue(0); + } + + public static void main(String... args) throws Exception { + if (Platform.is64bit()) { + ProcessBuilder pb = ProcessTools.createJavaProcessBuilder("-Xlog:stackwalk=trace", + "LocalLongHelper"); + analyzeOutputOn(pb); + + pb = ProcessTools.createJavaProcessBuilder("-Xlog:stackwalk=off", + "LocalLongHelper"); + analyzeOutputOff(pb); + } + }; +}