hotspot/test/gc/metaspace/TestMetaspaceSizeFlags.java
author sundar
Fri, 22 Aug 2014 22:50:38 +0530
changeset 26238 829648e12198
parent 19991 d0d0186a8cd6
child 29678 dd2f3932c21e
permissions -rw-r--r--
8055830: JDK-8015969.js is silently failing Reviewed-by: lagergren, jlaskey, hannesw
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
19991
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     1
/*
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     2
 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     4
 *
d0d0186a8cd6 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
d0d0186a8cd6 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
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     7
 * published by the Free Software Foundation.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
     8
 *
d0d0186a8cd6 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
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    10
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    11
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
d0d0186a8cd6 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
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    13
 * accompanied this code).
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    14
 *
d0d0186a8cd6 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
d0d0186a8cd6 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,
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    17
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    18
 *
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    19
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
d0d0186a8cd6 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
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    21
 * questions.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    22
 */
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    23
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    24
import com.oracle.java.testlibrary.Asserts;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    25
import com.oracle.java.testlibrary.OutputAnalyzer;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    26
import com.oracle.java.testlibrary.ProcessTools;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    27
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    28
/*
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    29
 * @test TestMetaspaceSizeFlags
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    30
 * @key gc
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    31
 * @bug 8024650
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    32
 * @summary Test that metaspace size flags can be set correctly
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    33
 * @library /testlibrary
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    34
 */
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    35
public class TestMetaspaceSizeFlags {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    36
  public static final long K = 1024L;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    37
  public static final long M = 1024L * K;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    38
d0d0186a8cd6 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.
d0d0186a8cd6 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).
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    41
  public static final long MAX_ALIGNMENT = 32 * M;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    42
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    43
  public static void main(String [] args) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    44
    testMaxMetaspaceSizeEQMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    45
    // 8024650: MaxMetaspaceSize was adjusted instead of MetaspaceSize.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    46
    testMaxMetaspaceSizeLTMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT * 2);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    47
    testMaxMetaspaceSizeGTMetaspaceSize(MAX_ALIGNMENT * 2, MAX_ALIGNMENT);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    48
    testTooSmallInitialMetaspace(0, 0);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    49
    testTooSmallInitialMetaspace(0, MAX_ALIGNMENT);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    50
    testTooSmallInitialMetaspace(MAX_ALIGNMENT, 0);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    51
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    52
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    53
  private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    54
    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    55
    Asserts.assertEQ(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    56
    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    57
    Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    58
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    59
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    60
  private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    61
    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    62
    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    63
    Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    64
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    65
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    66
  private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    67
    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    68
    Asserts.assertGT(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    69
    Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    70
    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    71
    Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    72
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    73
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    74
  private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    75
    OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    76
    output.shouldContain("Too small initial Metaspace size");
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    77
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    78
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    79
  private static MetaspaceFlags runAndGetValue(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    80
    OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    81
    output.shouldNotMatch("Error occurred during initialization of VM\n.*");
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    82
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    83
    String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    84
    String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1);
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    85
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    86
    return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize),
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    87
                              Long.parseLong(stringMetaspaceSize));
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    88
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    89
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    90
  private static OutputAnalyzer run(long maxMetaspaceSize, long metaspaceSize) throws Exception {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    91
    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    92
        "-XX:MaxMetaspaceSize=" + maxMetaspaceSize,
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    93
        "-XX:MetaspaceSize=" + metaspaceSize,
d0d0186a8cd6 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.
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    95
        "-XX:+PrintFlagsFinal",
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    96
        "-version");
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    97
    return new OutputAnalyzer(pb.start());
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    98
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
    99
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   100
  private static class MetaspaceFlags {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   101
    public long maxMetaspaceSize;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   102
    public long metaspaceSize;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   103
    public MetaspaceFlags(long maxMetaspaceSize, long metaspaceSize) {
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   104
      this.maxMetaspaceSize = maxMetaspaceSize;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   105
      this.metaspaceSize = metaspaceSize;
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   106
    }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   107
  }
d0d0186a8cd6 8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
stefank
parents:
diff changeset
   108
}