comparison test/runtime/NMT/SummarySanityCheck.java @ 20361:ac12996df59b

8044140: Create NMT (Native Memory Tracking) tests for NMT2 Summary: Create new/modify existing tests for NMT2, which is an internal redesign to address scalability issues in the first implementation. Reviewed-by: ctornqvi, zgu Contributed-by: George Triantafillou <george.triantafillou@oracle.com>
author zgu
date Wed, 27 Aug 2014 08:35:03 -0400
parents 1b0dc9f87e75
children 6640f982c1be
comparison
equal deleted inserted replaced
20360:833b0f92429a 20361:ac12996df59b
1 /* 1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2013, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
25 * @test 25 * @test
26 * @key nmt jcmd 26 * @key nmt jcmd
27 * @summary Sanity check the output of NMT 27 * @summary Sanity check the output of NMT
28 * @library /testlibrary /testlibrary/whitebox 28 * @library /testlibrary /testlibrary/whitebox
29 * @build SummarySanityCheck 29 * @build SummarySanityCheck
30 * @ignore
30 * @run main ClassFileInstaller sun.hotspot.WhiteBox 31 * @run main ClassFileInstaller sun.hotspot.WhiteBox
31 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+WhiteBoxAPI SummarySanityCheck 32 * @run main/othervm -Xbootclasspath/a:. -XX:+UnlockDiagnosticVMOptions -XX:NativeMemoryTracking=summary -XX:+WhiteBoxAPI SummarySanityCheck
32 */ 33 */
33 34
34 import com.oracle.java.testlibrary.*; 35 import com.oracle.java.testlibrary.*;
41 42
42 private static String jcmdout; 43 private static String jcmdout;
43 public static void main(String args[]) throws Exception { 44 public static void main(String args[]) throws Exception {
44 // Grab my own PID 45 // Grab my own PID
45 String pid = Integer.toString(ProcessTools.getProcessId()); 46 String pid = Integer.toString(ProcessTools.getProcessId());
46
47 // Use WB API to ensure that all data has been merged before we continue
48 if (!WhiteBox.getWhiteBox().NMTWaitForDataMerge()) {
49 throw new Exception("Call to WB API NMTWaitForDataMerge() failed");
50 }
51 47
52 ProcessBuilder pb = new ProcessBuilder(); 48 ProcessBuilder pb = new ProcessBuilder();
53 49
54 // Run 'jcmd <pid> VM.native_memory summary scale=KB' 50 // Run 'jcmd <pid> VM.native_memory summary scale=KB'
55 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary", "scale=KB"}); 51 pb.command(new String[] { JDKToolFinder.getJDKTool("jcmd"), pid, "VM.native_memory", "summary", "scale=KB"});
67 int totalCommittedSum = 0, totalReservedSum = 0; 63 int totalCommittedSum = 0, totalReservedSum = 0;
68 64
69 // Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB) 65 // Match '- <mtType> (reserved=<reserved>KB, committed=<committed>KB)
70 Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)"); 66 Pattern mtTypePattern = Pattern.compile("-\\s+(?<typename>[\\w\\s]+)\\(reserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB\\)");
71 // Match 'Total: reserved=<reserved>KB, committed=<committed>KB' 67 // Match 'Total: reserved=<reserved>KB, committed=<committed>KB'
72 Pattern totalMemoryPattern = Pattern.compile("Total\\:\\s\\sreserved=(?<reserved>\\d+)KB,\\s\\scommitted=(?<committed>\\d+)KB"); 68 Pattern totalMemoryPattern = Pattern.compile("Total\\:\\sreserved=(?<reserved>\\d+)KB,\\scommitted=(?<committed>\\d+)KB");
73 69
74 for (int i = 0; i < lines.length; i++) { 70 for (int i = 0; i < lines.length; i++) {
75 if (lines[i].startsWith("Total")) { 71 if (lines[i].startsWith("Total")) {
76 Matcher totalMemoryMatcher = totalMemoryPattern.matcher(lines[i]); 72 Matcher totalMemoryMatcher = totalMemoryPattern.matcher(lines[i]);
77 73
78 if (totalMemoryMatcher.matches() && totalMemoryMatcher.groupCount() == 2) { 74 if (totalMemoryMatcher.matches()) {
79 totalCommitted = Integer.parseInt(totalMemoryMatcher.group("committed")); 75 totalCommitted = Integer.parseInt(totalMemoryMatcher.group("committed"));
80 totalReserved = Integer.parseInt(totalMemoryMatcher.group("reserved")); 76 totalReserved = Integer.parseInt(totalMemoryMatcher.group("reserved"));
81 } else { 77 } else {
82 throwTestException("Failed to match the expected groups in 'Total' memory part"); 78 throwTestException("Failed to match the expected groups in 'Total' memory part");
83 } 79 }