author | alanb |
Fri, 07 Apr 2017 08:05:54 +0000 | |
changeset 44545 | 83b611b88ac8 |
parent 40684 | 2e37c119dc2a |
permissions | -rw-r--r-- |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
1 |
/* |
40684
2e37c119dc2a
8164982: Fix legal notices in java/lang, java/net, java/util tests.
shurailine
parents:
30355
diff
changeset
|
2 |
* Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
4 |
* |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
8 |
* |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
13 |
* accompanied this code). |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
14 |
* |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
18 |
* |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
21 |
* questions. |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
22 |
*/ |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
23 |
|
26193
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
24 |
import java.io.File; |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
25 |
import java.io.FileWriter; |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
26 |
import java.util.regex.Matcher; |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
27 |
import java.util.regex.Pattern; |
26193
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
28 |
import java.util.Arrays; |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
29 |
import java.util.stream.Collectors; |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
30 |
import java.lang.management.ManagementFactory; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
31 |
import javax.management.MalformedObjectNameException; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
32 |
import javax.management.ObjectName; |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
33 |
|
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
34 |
public class NMTHelper |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
35 |
{ |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
36 |
public static void baseline() { |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
37 |
executeDcmd("vmNativeMemory", "baseline"); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
38 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
39 |
|
25997
cd7dd678d9e2
8055012: [TESTBUG] NMTHelper fails to parse NMT output
ctornqvi
parents:
21347
diff
changeset
|
40 |
// Total: reserved=3484685KB +293KB, committed=266629KB +293KB |
cd7dd678d9e2
8055012: [TESTBUG] NMTHelper fails to parse NMT output
ctornqvi
parents:
21347
diff
changeset
|
41 |
private static Pattern totalLine = Pattern.compile("^Total: reserved=\\d+KB .*KB, committed=\\d+KB (.*)KB$"); |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
42 |
|
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
43 |
public static long committedDiff() throws Exception { |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
44 |
String res = (String) executeDcmd("vmNativeMemory", "detail.diff"); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
45 |
String[] lines = res.split("\n"); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
46 |
for (String line : lines) { |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
47 |
Matcher matcher = totalLine.matcher(line); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
48 |
if (matcher.matches()) { |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
49 |
String committed = matcher.group(1); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
50 |
return Long.parseLong(committed); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
51 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
52 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
53 |
throw new Exception("Could not find the Total line in the NMT output."); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
54 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
55 |
|
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
56 |
private static String executeDcmd(String cmd, String ... args) { |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
57 |
ObjectName oname = null; |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
58 |
try { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
59 |
oname = ObjectName.getInstance("com.sun.management:type=DiagnosticCommand"); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
60 |
} catch (MalformedObjectNameException mone) { |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
61 |
throw new RuntimeException(mone); |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
62 |
} |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
63 |
Object[] dcmdArgs = {args}; |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
64 |
String[] signature = {String[].class.getName()}; |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
65 |
|
26193
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
66 |
String cmdString = cmd + " " + |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
67 |
Arrays.stream(args).collect(Collectors.joining(" ")); |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
68 |
File f = new File("dcmdoutput-" + cmd + "-" + System.currentTimeMillis() + ".txt"); |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
69 |
System.out.println("Output from Dcmd '" + cmdString + "' is being written to file " + f); |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
70 |
try (FileWriter fw = new FileWriter(f)) { |
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
71 |
fw.write("> " + cmdString + ":"); |
30355
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
72 |
String result = (String)ManagementFactory.getPlatformMBeanServer(). |
e37c7eba132f
8042901: Allow com.sun.management to be in a different module to java.lang.management
sjiang
parents:
26193
diff
changeset
|
73 |
invoke(oname, cmd, dcmdArgs, signature); |
26193
09edb0e9f15a
8055677: java/lang/instrument/RedefineBigClass.sh RetransformBigClass.sh start failing after JDK-8055012
sla
parents:
25997
diff
changeset
|
74 |
fw.write(result); |
21347
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
75 |
return result; |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
76 |
} catch(Exception ex) { |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
77 |
ex.printStackTrace(); |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
78 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
79 |
return null; |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
80 |
} |
21c6a82adf04
8026789: Update test/java/lang/instrument/Re(transform|define)BigClass.sh test to use NMT for memory leak detection
sla
parents:
diff
changeset
|
81 |
} |