author | prr |
Tue, 17 Mar 2015 15:18:11 -0700 | |
changeset 29730 | eab36f5cc7ac |
parent 25350 | 6423a57e5451 |
child 29678 | dd2f3932c21e |
permissions | -rw-r--r-- |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
1 |
/* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
2 |
* Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved. |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
4 |
* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
8 |
* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
13 |
* accompanied this code). |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
14 |
* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
18 |
* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
21 |
* questions. |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
22 |
*/ |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
23 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
24 |
/* |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
25 |
* @test TestGCId |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
26 |
* @bug 8043607 |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
27 |
* @summary Ensure that the GCId is logged |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
28 |
* @key gc |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
29 |
* @library /testlibrary |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
30 |
*/ |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
31 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
32 |
import com.oracle.java.testlibrary.ProcessTools; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
33 |
import com.oracle.java.testlibrary.OutputAnalyzer; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
34 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
35 |
public class TestGCId { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
36 |
public static void main(String[] args) throws Exception { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
37 |
testGCId("UseParallelGC", "PrintGC"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
38 |
testGCId("UseParallelGC", "PrintGCDetails"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
39 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
40 |
testGCId("UseG1GC", "PrintGC"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
41 |
testGCId("UseG1GC", "PrintGCDetails"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
42 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
43 |
testGCId("UseConcMarkSweepGC", "PrintGC"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
44 |
testGCId("UseConcMarkSweepGC", "PrintGCDetails"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
45 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
46 |
testGCId("UseSerialGC", "PrintGC"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
47 |
testGCId("UseSerialGC", "PrintGCDetails"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
48 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
49 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
50 |
private static void verifyContainsGCIDs(OutputAnalyzer output) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
51 |
output.shouldMatch("^#0: \\["); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
52 |
output.shouldMatch("^#1: \\["); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
53 |
output.shouldHaveExitValue(0); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
54 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
55 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
56 |
private static void verifyContainsNoGCIDs(OutputAnalyzer output) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
57 |
output.shouldNotMatch("^#[0-9]+: \\["); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
58 |
output.shouldHaveExitValue(0); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
59 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
60 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
61 |
private static void testGCId(String gcFlag, String logFlag) throws Exception { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
62 |
// GCID logging enabled |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
63 |
ProcessBuilder pb_enabled = |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
64 |
ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:+PrintGCID", GCTest.class.getName()); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
65 |
verifyContainsGCIDs(new OutputAnalyzer(pb_enabled.start())); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
66 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
67 |
// GCID logging disabled |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
68 |
ProcessBuilder pb_disabled = |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
69 |
ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", "-XX:-PrintGCID", GCTest.class.getName()); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
70 |
verifyContainsNoGCIDs(new OutputAnalyzer(pb_disabled.start())); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
71 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
72 |
// GCID logging default |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
73 |
ProcessBuilder pb_default = |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
74 |
ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-XX:+" + logFlag, "-Xmx10M", GCTest.class.getName()); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
75 |
verifyContainsGCIDs(new OutputAnalyzer(pb_default.start())); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
76 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
77 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
78 |
static class GCTest { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
79 |
private static byte[] garbage; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
80 |
public static void main(String [] args) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
81 |
System.out.println("Creating garbage"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
82 |
// create 128MB of garbage. This should result in at least one GC |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
83 |
for (int i = 0; i < 1024; i++) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
84 |
garbage = new byte[128 * 1024]; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
85 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
86 |
// do a system gc to get one more gc |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
87 |
System.gc(); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
88 |
System.out.println("Done"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
89 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
90 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
91 |
} |