author | erikj |
Thu, 14 Apr 2016 15:13:42 +0200 | |
changeset 37299 | db3b0d4c3bda |
parent 36851 | 03e2f4d0a421 |
child 40631 | ed82623d7831 |
permissions | -rw-r--r-- |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
1 |
/* |
36576 | 2 |
* Copyright (c) 2014, 2016, Oracle and/or its affiliates. All rights reserved. |
25350
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 |
36576 | 28 |
* @requires vm.gc=="null" |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
29 |
* @key gc |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
30 |
* @library /testlibrary |
36851 | 31 |
* @modules java.base/jdk.internal.misc |
29678
dd2f3932c21e
8075586: Add @modules as needed to the open hotspot tests
ykantser
parents:
25350
diff
changeset
|
32 |
* java.management |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
33 |
*/ |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
34 |
|
30604
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
35 |
import jdk.test.lib.ProcessTools; |
b8d532cb6420
8067013: Rename the com.oracle.java.testlibary package
ykantser
parents:
29678
diff
changeset
|
36 |
import jdk.test.lib.OutputAnalyzer; |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
37 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
38 |
public class TestGCId { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
39 |
public static void main(String[] args) throws Exception { |
35061 | 40 |
testGCId("UseParallelGC"); |
41 |
testGCId("UseG1GC"); |
|
42 |
testGCId("UseConcMarkSweepGC"); |
|
43 |
testGCId("UseSerialGC"); |
|
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
44 |
} |
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 |
private static void verifyContainsGCIDs(OutputAnalyzer output) { |
35061 | 47 |
output.shouldMatch("\\[.*\\]\\[.*\\]\\[.*\\] GC\\(0\\) "); |
48 |
output.shouldMatch("\\[.*\\]\\[.*\\]\\[.*\\] GC\\(1\\) "); |
|
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
49 |
output.shouldHaveExitValue(0); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
50 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
51 |
|
35061 | 52 |
private static void testGCId(String gcFlag) throws Exception { |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
53 |
ProcessBuilder pb_default = |
35061 | 54 |
ProcessTools.createJavaProcessBuilder("-XX:+" + gcFlag, "-Xlog:gc", "-Xmx10M", GCTest.class.getName()); |
25350
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
55 |
verifyContainsGCIDs(new OutputAnalyzer(pb_default.start())); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
56 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
57 |
|
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
58 |
static class GCTest { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
59 |
private static byte[] garbage; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
60 |
public static void main(String [] args) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
61 |
System.out.println("Creating garbage"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
62 |
// 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
|
63 |
for (int i = 0; i < 1024; i++) { |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
64 |
garbage = new byte[128 * 1024]; |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
65 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
66 |
// 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
|
67 |
System.gc(); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
68 |
System.out.println("Done"); |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
69 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
70 |
} |
6423a57e5451
8043607: Add a GC id as a log decoration similar to PrintGCTimeStamps
brutisso
parents:
diff
changeset
|
71 |
} |