Mercurial > hg > truffle
comparison test/gc/metaspace/TestMetaspaceSizeFlags.java @ 12238:9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
Reviewed-by: jwilhelm, brutisso, tschatzl
author | stefank |
---|---|
date | Fri, 13 Sep 2013 22:22:14 +0200 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
12237:335b388c4b28 | 12238:9e11762cee52 |
---|---|
1 /* | |
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. | |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | |
4 * | |
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 | |
7 * published by the Free Software Foundation. | |
8 * | |
9 * This code is distributed in the hope that it will be useful, but WITHOUT | |
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
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 import com.oracle.java.testlibrary.Asserts; | |
25 import com.oracle.java.testlibrary.OutputAnalyzer; | |
26 import com.oracle.java.testlibrary.ProcessTools; | |
27 | |
28 /* | |
29 * @test TestMetaspaceSizeFlags | |
30 * @key gc | |
31 * @bug 8024650 | |
32 * @summary Test that metaspace size flags can be set correctly | |
33 * @library /testlibrary | |
34 */ | |
35 public class TestMetaspaceSizeFlags { | |
36 public static final long K = 1024L; | |
37 public static final long M = 1024L * K; | |
38 | |
39 // HotSpot uses a number of different values to align memory size flags. | |
40 // This is currently the largest alignment (unless huge large pages are used). | |
41 public static final long MAX_ALIGNMENT = 32 * M; | |
42 | |
43 public static void main(String [] args) throws Exception { | |
44 testMaxMetaspaceSizeEQMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT); | |
45 // 8024650: MaxMetaspaceSize was adjusted instead of MetaspaceSize. | |
46 testMaxMetaspaceSizeLTMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT * 2); | |
47 testMaxMetaspaceSizeGTMetaspaceSize(MAX_ALIGNMENT * 2, MAX_ALIGNMENT); | |
48 testTooSmallInitialMetaspace(0, 0); | |
49 testTooSmallInitialMetaspace(0, MAX_ALIGNMENT); | |
50 testTooSmallInitialMetaspace(MAX_ALIGNMENT, 0); | |
51 } | |
52 | |
53 private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
54 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); | |
55 Asserts.assertEQ(maxMetaspaceSize, metaspaceSize); | |
56 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); | |
57 Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); | |
58 } | |
59 | |
60 private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
61 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); | |
62 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); | |
63 Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize); | |
64 } | |
65 | |
66 private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
67 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); | |
68 Asserts.assertGT(maxMetaspaceSize, metaspaceSize); | |
69 Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize); | |
70 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); | |
71 Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); | |
72 } | |
73 | |
74 private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
75 OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); | |
76 output.shouldContain("Too small initial Metaspace size"); | |
77 } | |
78 | |
79 private static MetaspaceFlags runAndGetValue(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
80 OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); | |
81 output.shouldNotMatch("Error occurred during initialization of VM\n.*"); | |
82 | |
83 String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1); | |
84 String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1); | |
85 | |
86 return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize), | |
87 Long.parseLong(stringMetaspaceSize)); | |
88 } | |
89 | |
90 private static OutputAnalyzer run(long maxMetaspaceSize, long metaspaceSize) throws Exception { | |
91 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( | |
92 "-XX:MaxMetaspaceSize=" + maxMetaspaceSize, | |
93 "-XX:MetaspaceSize=" + metaspaceSize, | |
94 "-XX:-UseLargePages", // Prevent us from using 2GB large pages on solaris + sparc. | |
95 "-XX:+PrintFlagsFinal", | |
96 "-version"); | |
97 return new OutputAnalyzer(pb.start()); | |
98 } | |
99 | |
100 private static class MetaspaceFlags { | |
101 public long maxMetaspaceSize; | |
102 public long metaspaceSize; | |
103 public MetaspaceFlags(long maxMetaspaceSize, long metaspaceSize) { | |
104 this.maxMetaspaceSize = maxMetaspaceSize; | |
105 this.metaspaceSize = metaspaceSize; | |
106 } | |
107 } | |
108 } |