11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8133747 8218458
27 * @summary Running with NMT detail should produce expected stack traces.
28 * @library /test/lib
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @run driver CheckForProperDetailStackTrace
32 */
33
34 import jdk.test.lib.Platform;
35 import jdk.test.lib.process.ProcessTools;
36 import jdk.test.lib.process.OutputAnalyzer;
37 import java.util.regex.Matcher;
38 import java.util.regex.Pattern;
39
40 /**
41 * We are checking for details that should be seen with NMT detail enabled.
42 * In particular the stack traces from os::malloc call sites should have 4
43 * (based on NMT detail stack depth setting) 'interesting' frames and skip
44 * the higher-level allocation frames and frames specific to the NMT logic.
45 * The actual stack trace is affected by the native compiler's inlining ability
46 * and the type of build, so we need to check for a number of possible stacks.
47 * This information does not change often enough that we are concerned about the
48 * stability of this test - rather we prefer to detect changes in compiler behaviour
49 * through this test and update it accordingly.
50 */
51 public class CheckForProperDetailStackTrace {
52
53 /* The stack trace we look for by default. Note that :: has been replaced by .*
54 to make sure it matches even if the symbol is not unmangled.
55 */
56 private static String stackTraceDefault =
57 ".*Hashtable.*allocate_new_entry.*\n" +
58 ".*ModuleEntryTable.*new_entry.*\n" +
59 ".*ModuleEntryTable.*locked_create_entry.*\n" +
60 ".*Modules.*define_module.*\n";
61
62 /* Alternate stacktrace that we check if the default fails, because
63 new_entry may be inlined.
64 */
65 private static String stackTraceAlternate =
66 ".*Hashtable.*allocate_new_entry.*\n" +
67 ".*ModuleEntryTable.*locked_create_entry.*\n" +
68 ".*Modules.*define_module.*\n" +
69 ".*JVM_DefineModule.*\n";
70
71 /* The stack trace we look for on AIX and Windows slowdebug builds.
72 ALWAYSINLINE is only a hint and is ignored for AllocateHeap on the
73 aforementioned platforms. When that happens allocate_new_entry is
74 inlined instead.
75 */
76 private static String stackTraceAllocateHeap =
77 ".*AllocateHeap.*\n" +
78 ".*ModuleEntryTable.*new_entry.*\n" +
79 ".*ModuleEntryTable.*locked_create_entry.*\n" +
80 ".*Modules.*define_module.*\n";
81
82 /* A symbol that should always be present in NMT detail output. */
83 private static String expectedSymbol = "locked_create_entry";
84
85 public static void main(String args[]) throws Exception {
86 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
87 "-XX:+UnlockDiagnosticVMOptions",
88 "-XX:NativeMemoryTracking=detail",
89 "-XX:+PrintNMTStatistics",
90 "-version");
91 OutputAnalyzer output = new OutputAnalyzer(pb.start());
92
93 output.shouldHaveExitValue(0);
94
95 // We should never see either of these frames because they are supposed to be skipped.
96 output.shouldNotContain("NativeCallStack::NativeCallStack");
97 output.shouldNotContain("os::get_native_stack");
98
99 // AllocateHeap shouldn't be in the output because it is supposed to always be inlined.
100 // We check for that here, but allow it for Aix and Windows slowdebug builds
101 // because the compiler ends up not inlining AllocateHeap.
102 Boolean okToHaveAllocateHeap = Platform.isSlowDebugBuild() &&
103 (Platform.isAix() || Platform.isWindows());
104 if (!okToHaveAllocateHeap) {
105 output.shouldNotContain("AllocateHeap");
106 }
107
108 // See if we have any stack trace symbols in the output
109 boolean hasSymbols = output.getStdout().contains(expectedSymbol) ||
110 output.getStderr().contains(expectedSymbol);
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 */
23
24 /*
25 * @test
26 * @bug 8133747 8218458
27 * @summary Running with NMT detail should produce expected stack traces.
28 * @library /test/lib
29 * @modules java.base/jdk.internal.misc
30 * java.management
31 * @compile ../modules/CompilerUtils.java
32 * @run driver CheckForProperDetailStackTrace
33 */
34
35 import jdk.test.lib.Platform;
36 import jdk.test.lib.process.ProcessTools;
37 import jdk.test.lib.process.OutputAnalyzer;
38 import java.nio.file.Path;
39 import java.nio.file.Paths;
40 import java.util.regex.Matcher;
41 import java.util.regex.Pattern;
42
43 /**
44 * We are checking for details that should be seen with NMT detail enabled.
45 * In particular the stack traces from os::malloc call sites should have 4
46 * (based on NMT detail stack depth setting) 'interesting' frames and skip
47 * the higher-level allocation frames and frames specific to the NMT logic.
48 * The actual stack trace is affected by the native compiler's inlining ability
49 * and the type of build, so we need to check for a number of possible stacks.
50 * This information does not change often enough that we are concerned about the
51 * stability of this test - rather we prefer to detect changes in compiler behaviour
52 * through this test and update it accordingly.
53 */
54 public class CheckForProperDetailStackTrace {
55 private static final String TEST_SRC = System.getProperty("test.src");
56 private static final String TEST_CLASSES = System.getProperty("test.classes");
57
58 private static final Path SRC_DIR = Paths.get(TEST_SRC, "src");
59 private static final Path MODS_DIR = Paths.get(TEST_CLASSES, "mods");
60
61 /* The stack trace we look for by default. Note that :: has been replaced by .*
62 to make sure it matches even if the symbol is not unmangled.
63 */
64 private static String stackTraceDefault =
65 ".*Hashtable.*allocate_new_entry.*\n" +
66 ".*ModuleEntryTable.*new_entry.*\n" +
67 ".*ModuleEntryTable.*locked_create_entry.*\n" +
68 ".*Modules.*define_module.*\n";
69
70 /* Alternate stacktrace that we check if the default fails, because
71 new_entry may be inlined.
72 */
73 private static String stackTraceAlternate =
74 ".*Hashtable.*allocate_new_entry.*\n" +
75 ".*ModuleEntryTable.*locked_create_entry.*\n" +
76 ".*Modules.*define_module.*\n" +
77 ".*JVM_DefineModule.*\n";
78
79 /* The stack trace we look for on AIX and Windows slowdebug builds.
80 ALWAYSINLINE is only a hint and is ignored for AllocateHeap on the
81 aforementioned platforms. When that happens allocate_new_entry is
82 inlined instead.
83 */
84 private static String stackTraceAllocateHeap =
85 ".*AllocateHeap.*\n" +
86 ".*ModuleEntryTable.*new_entry.*\n" +
87 ".*ModuleEntryTable.*locked_create_entry.*\n" +
88 ".*Modules.*define_module.*\n";
89
90 /* A symbol that should always be present in NMT detail output. */
91 private static String expectedSymbol = "locked_create_entry";
92
93 public static void main(String args[]) throws Exception {
94 boolean compiled;
95 // Compile module jdk.test declaration
96 compiled = CompilerUtils.compile(
97 SRC_DIR.resolve("jdk.test"),
98 MODS_DIR.resolve("jdk.test"));
99 if (!compiled) {
100 throw new RuntimeException("Test failed to compile module jdk.test");
101 }
102
103 // If modules in the system image have been archived in CDS, they will not be
104 // created again at run time. Explicitly use an external module to make sure
105 // we have a runtime-defined ModuleEntry
106 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
107 "-XX:+UnlockDiagnosticVMOptions",
108 "-XX:NativeMemoryTracking=detail",
109 "-XX:+PrintNMTStatistics",
110 "-p", MODS_DIR.toString(),
111 "-m", "jdk.test/test.Main");
112 OutputAnalyzer output = new OutputAnalyzer(pb.start());
113
114 output.shouldHaveExitValue(0);
115
116 // We should never see either of these frames because they are supposed to be skipped.
117 output.shouldNotContain("NativeCallStack::NativeCallStack");
118 output.shouldNotContain("os::get_native_stack");
119
120 // AllocateHeap shouldn't be in the output because it is supposed to always be inlined.
121 // We check for that here, but allow it for Aix and Windows slowdebug builds
122 // because the compiler ends up not inlining AllocateHeap.
123 Boolean okToHaveAllocateHeap = Platform.isSlowDebugBuild() &&
124 (Platform.isAix() || Platform.isWindows());
125 if (!okToHaveAllocateHeap) {
126 output.shouldNotContain("AllocateHeap");
127 }
128
129 // See if we have any stack trace symbols in the output
130 boolean hasSymbols = output.getStdout().contains(expectedSymbol) ||
131 output.getStderr().contains(expectedSymbol);
|