Mercurial > hg > truffle
annotate test/gc/metaspace/TestMetaspaceSizeFlags.java @ 20218:828056cf311f
8040792: G1: Memory usage calculation uses sizeof(this) instead of sizeof(classname)
Summary: A few locations in the code use sizeof(this) which returns the size of the pointer instead of sizeof(classname) which returns the size of the sum of its members. This change fixes these errors and adds a few tests.
Reviewed-by: mgerdin, brutisso
author | tschatzl |
---|---|
date | Mon, 21 Jul 2014 09:40:19 +0200 |
parents | 9e11762cee52 |
children |
rev | line source |
---|---|
12238
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
1 /* |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
4 * |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
5 * This code is free software; you can redistribute it and/or modify it |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
6 * under the terms of the GNU General Public License version 2 only, as |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
7 * published by the Free Software Foundation. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
8 * |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
12 * version 2 for more details (a copy is included in the LICENSE file that |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
13 * accompanied this code). |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
14 * |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
15 * You should have received a copy of the GNU General Public License version |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
16 * 2 along with this work; if not, write to the Free Software Foundation, |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
18 * |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
21 * questions. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
22 */ |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
23 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
24 import com.oracle.java.testlibrary.Asserts; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
25 import com.oracle.java.testlibrary.OutputAnalyzer; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
26 import com.oracle.java.testlibrary.ProcessTools; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
27 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
28 /* |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
29 * @test TestMetaspaceSizeFlags |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
30 * @key gc |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
31 * @bug 8024650 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
32 * @summary Test that metaspace size flags can be set correctly |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
33 * @library /testlibrary |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
34 */ |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
35 public class TestMetaspaceSizeFlags { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
36 public static final long K = 1024L; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
37 public static final long M = 1024L * K; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
38 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
39 // HotSpot uses a number of different values to align memory size flags. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
40 // This is currently the largest alignment (unless huge large pages are used). |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
41 public static final long MAX_ALIGNMENT = 32 * M; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
42 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
43 public static void main(String [] args) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
44 testMaxMetaspaceSizeEQMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
45 // 8024650: MaxMetaspaceSize was adjusted instead of MetaspaceSize. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
46 testMaxMetaspaceSizeLTMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT * 2); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
47 testMaxMetaspaceSizeGTMetaspaceSize(MAX_ALIGNMENT * 2, MAX_ALIGNMENT); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
48 testTooSmallInitialMetaspace(0, 0); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
49 testTooSmallInitialMetaspace(0, MAX_ALIGNMENT); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
50 testTooSmallInitialMetaspace(MAX_ALIGNMENT, 0); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
51 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
52 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
53 private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
54 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
55 Asserts.assertEQ(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
56 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
57 Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
58 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
59 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
60 private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
61 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
62 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
63 Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
64 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
65 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
66 private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
67 MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
68 Asserts.assertGT(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
69 Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
70 Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
71 Asserts.assertEQ(mf.metaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
72 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
73 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
74 private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
75 OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
76 output.shouldContain("Too small initial Metaspace size"); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
77 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
78 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
79 private static MetaspaceFlags runAndGetValue(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
80 OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
81 output.shouldNotMatch("Error occurred during initialization of VM\n.*"); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
82 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
83 String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
84 String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
85 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
86 return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize), |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
87 Long.parseLong(stringMetaspaceSize)); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
88 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
89 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
90 private static OutputAnalyzer run(long maxMetaspaceSize, long metaspaceSize) throws Exception { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
91 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
92 "-XX:MaxMetaspaceSize=" + maxMetaspaceSize, |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
93 "-XX:MetaspaceSize=" + metaspaceSize, |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
94 "-XX:-UseLargePages", // Prevent us from using 2GB large pages on solaris + sparc. |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
95 "-XX:+PrintFlagsFinal", |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
96 "-version"); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
97 return new OutputAnalyzer(pb.start()); |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
98 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
99 |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
100 private static class MetaspaceFlags { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
101 public long maxMetaspaceSize; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
102 public long metaspaceSize; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
103 public MetaspaceFlags(long maxMetaspaceSize, long metaspaceSize) { |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
104 this.maxMetaspaceSize = maxMetaspaceSize; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
105 this.metaspaceSize = metaspaceSize; |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
106 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
107 } |
9e11762cee52
8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff
changeset
|
108 } |