hotspot/test/runtime/NMT/CheckForProperDetailStackTrace.java
author cjplummer
Mon, 15 Aug 2016 13:13:48 -0700
changeset 40383 1ebc8c5aed30
child 40631 ed82623d7831
permissions -rw-r--r--
8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used Summary: Better frame skipping logic in NativeCallStack::NativeCallStack. Reviewed-by: dholmes, zgu
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
40383
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     1
/*
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     2
 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     4
 *
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     7
 * published by the Free Software Foundation.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     8
 *
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
     9
 * This code is distributed in the hope that it will be useful, but WITHOUT
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    12
 * version 2 for more details (a copy is included in the LICENSE file that
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    13
 * accompanied this code).
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    14
 *
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    15
 * You should have received a copy of the GNU General Public License version
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    16
 * 2 along with this work; if not, write to the Free Software Foundation,
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    18
 *
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    20
 * or visit www.oracle.com if you need additional information or have any
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    21
 * questions.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    22
 */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    23
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    24
 /*
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    25
 * @test
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    26
 * @key nmt
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    27
 * @summary Running with NMT detail should produce expected stack traces.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    28
 * @library /testlibrary
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    29
 * @modules java.base/jdk.internal.misc
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    30
 *          java.management
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    31
 */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    32
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    33
import jdk.test.lib.*;
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    34
import java.util.regex.Matcher;
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    35
import java.util.regex.Pattern;
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    36
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    37
public class CheckForProperDetailStackTrace {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    38
    /* The stack trace we look for by default. Note that :: has been replaced by .*
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    39
       to make sure it maches even if the symbol is not unmangled. */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    40
    public static String stackTraceDefault =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    41
        ".*ModuleEntryTable.*new_entry.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    42
        ".*ModuleEntryTable.*locked_create_entry_or_null.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    43
        ".*Modules.*define_module.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    44
        ".*JVM_DefineModule.*\n";
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    45
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    46
    /* The stack trace we look for on Solaris and Windows slowdebug builds. For some
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    47
       reason ALWAYSINLINE for AllocateHeap is ignored, so it appears in the stack strace. */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    48
    public static String stackTraceAllocateHeap =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    49
        ".*AllocateHeap.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    50
        ".*ModuleEntryTable.*new_entry.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    51
        ".*ModuleEntryTable.*locked_create_entry_or_null.*\n" +
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    52
        ".*Modules.*define_module.*\n";
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    53
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    54
    /* A symbol that should always be present in NMT detail output. */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    55
    private static String expectedSymbol =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    56
        "locked_create_entry_or_null";
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    57
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    58
    private static final String jdkDebug = System.getProperty("jdk.debug");
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    59
    private static boolean isSlowDebugBuild() {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    60
        return (jdkDebug.toLowerCase().equals("slowdebug"));
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    61
    }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    62
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    63
    public static void main(String args[]) throws Exception {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    64
        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    65
            "-XX:+UnlockDiagnosticVMOptions",
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    66
            "-XX:NativeMemoryTracking=detail",
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    67
            "-XX:+PrintNMTStatistics",
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    68
            "-version");
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    69
        OutputAnalyzer output = new OutputAnalyzer(pb.start());
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    70
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    71
        output.shouldHaveExitValue(0);
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    72
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    73
        // We should never see either of these frames because they are supposed to be skipped. */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    74
        output.shouldNotContain("NativeCallStack::NativeCallStack");
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    75
        output.shouldNotContain("os::get_native_stack");
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    76
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    77
        // AllocateHeap shouldn't be in the output because it is suppose to always be inlined.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    78
        // We check for that here, but allow it for Windows and Solaris slowdebug builds because
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    79
        // the compiler ends up not inlining AllocateHeap.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    80
        Boolean okToHaveAllocateHeap =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    81
            isSlowDebugBuild() && (Platform.isSolaris() || Platform.isWindows());
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    82
        if (!okToHaveAllocateHeap) {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    83
            output.shouldNotContain("AllocateHeap");
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    84
        }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    85
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    86
        // See if we have any stack trace symbols in the output
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    87
        boolean hasSymbols =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    88
            output.getStdout().contains(expectedSymbol) || output.getStderr().contains(expectedSymbol);
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    89
        if (!hasSymbols) {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    90
            // It's ok for ARM not to have symbols, because it does not support NMT detail
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    91
            // when targeting thumb2. It's also ok for Windows not to have symbols, because
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    92
            // they are only available if the symbols file is included with the build.
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    93
            if (Platform.isWindows() || Platform.isARM()) {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    94
                return; // we are done
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    95
            }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    96
            output.reportDiagnosticSummary();
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    97
            throw new RuntimeException("Expected symbol missing missing from output: " + expectedSymbol);
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    98
        }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
    99
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   100
        /* Make sure the expected NMT detail stack trace is found. */
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   101
        String expectedStackTrace =
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   102
            (okToHaveAllocateHeap ? stackTraceAllocateHeap : stackTraceDefault);
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   103
        if (!stackTraceMatches(expectedStackTrace, output)) {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   104
            output.reportDiagnosticSummary();
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   105
            throw new RuntimeException("Expected stack trace missing missing from output: " + expectedStackTrace);
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   106
        }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   107
    }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   108
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   109
    public static boolean stackTraceMatches(String stackTrace, OutputAnalyzer output) {
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   110
        Matcher stdoutMatcher = Pattern.compile(stackTrace, Pattern.MULTILINE).matcher(output.getStdout());
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   111
        Matcher stderrMatcher = Pattern.compile(stackTrace, Pattern.MULTILINE).matcher(output.getStderr());
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   112
        return (stdoutMatcher.find() || stderrMatcher.find());
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   113
    }
1ebc8c5aed30 8133747: NMT includes an extra stack frame due to assumption NMT is making on tail calls being used
cjplummer
parents:
diff changeset
   114
}