8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize

Fri, 13 Sep 2013 22:22:14 +0200

author
stefank
date
Fri, 13 Sep 2013 22:22:14 +0200
changeset 5706
9e11762cee52
parent 5705
335b388c4b28
child 5707
8227700da288

8024650: Don't adjust MaxMetaspaceSize up to MetaspaceSize
Reviewed-by: jwilhelm, brutisso, tschatzl

src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp file | annotate | diff | comparison | revisions
src/share/vm/memory/collectorPolicy.cpp file | annotate | diff | comparison | revisions
test/gc/metaspace/TestMetaspaceSizeFlags.java file | annotate | diff | comparison | revisions
test/testlibrary/OutputAnalyzerTest.java file | annotate | diff | comparison | revisions
test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp	Fri Sep 13 22:21:06 2013 +0200
     1.2 +++ b/src/share/vm/gc_implementation/parallelScavenge/generationSizer.hpp	Fri Sep 13 22:22:14 2013 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     1.7   * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.8   *
     1.9   * This code is free software; you can redistribute it and/or modify it
    1.10 @@ -68,9 +68,6 @@
    1.11    size_t min_old_gen_size()   { return _min_gen1_size; }
    1.12    size_t old_gen_size()       { return _initial_gen1_size; }
    1.13    size_t max_old_gen_size()   { return _max_gen1_size; }
    1.14 -
    1.15 -  size_t metaspace_size()      { return MetaspaceSize; }
    1.16 -  size_t max_metaspace_size()  { return MaxMetaspaceSize; }
    1.17  };
    1.18  
    1.19  #endif // SHARE_VM_GC_IMPLEMENTATION_PARALLELSCAVENGE_GENERATIONSIZER_HPP
     2.1 --- a/src/share/vm/memory/collectorPolicy.cpp	Fri Sep 13 22:21:06 2013 +0200
     2.2 +++ b/src/share/vm/memory/collectorPolicy.cpp	Fri Sep 13 22:22:14 2013 +0200
     2.3 @@ -47,6 +47,11 @@
     2.4  
     2.5  // CollectorPolicy methods.
     2.6  
     2.7 +// Align down. If the aligning result in 0, return 'alignment'.
     2.8 +static size_t restricted_align_down(size_t size, size_t alignment) {
     2.9 +  return MAX2(alignment, align_size_down_(size, alignment));
    2.10 +}
    2.11 +
    2.12  void CollectorPolicy::initialize_flags() {
    2.13    assert(max_alignment() >= min_alignment(),
    2.14        err_msg("max_alignment: " SIZE_FORMAT " less than min_alignment: " SIZE_FORMAT,
    2.15 @@ -59,18 +64,24 @@
    2.16      vm_exit_during_initialization("Incompatible initial and maximum heap sizes specified");
    2.17    }
    2.18  
    2.19 -  if (MetaspaceSize > MaxMetaspaceSize) {
    2.20 -    MaxMetaspaceSize = MetaspaceSize;
    2.21 -  }
    2.22 -  MetaspaceSize = MAX2(min_alignment(), align_size_down_(MetaspaceSize, min_alignment()));
    2.23 -  // Don't increase Metaspace size limit above specified.
    2.24 -  MaxMetaspaceSize = align_size_down(MaxMetaspaceSize, max_alignment());
    2.25 -  if (MetaspaceSize > MaxMetaspaceSize) {
    2.26 -    MetaspaceSize = MaxMetaspaceSize;
    2.27 +  if (!is_size_aligned(MaxMetaspaceSize, max_alignment())) {
    2.28 +    FLAG_SET_ERGO(uintx, MaxMetaspaceSize,
    2.29 +        restricted_align_down(MaxMetaspaceSize, max_alignment()));
    2.30    }
    2.31  
    2.32 -  MinMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MinMetaspaceExpansion, min_alignment()));
    2.33 -  MaxMetaspaceExpansion = MAX2(min_alignment(), align_size_down_(MaxMetaspaceExpansion, min_alignment()));
    2.34 +  if (MetaspaceSize > MaxMetaspaceSize) {
    2.35 +    FLAG_SET_ERGO(uintx, MetaspaceSize, MaxMetaspaceSize);
    2.36 +  }
    2.37 +
    2.38 +  if (!is_size_aligned(MetaspaceSize, min_alignment())) {
    2.39 +    FLAG_SET_ERGO(uintx, MetaspaceSize,
    2.40 +        restricted_align_down(MetaspaceSize, min_alignment()));
    2.41 +  }
    2.42 +
    2.43 +  assert(MetaspaceSize <= MaxMetaspaceSize, "Must be");
    2.44 +
    2.45 +  MinMetaspaceExpansion = restricted_align_down(MinMetaspaceExpansion, min_alignment());
    2.46 +  MaxMetaspaceExpansion = restricted_align_down(MaxMetaspaceExpansion, min_alignment());
    2.47  
    2.48    MinHeapDeltaBytes = align_size_up(MinHeapDeltaBytes, min_alignment());
    2.49  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/test/gc/metaspace/TestMetaspaceSizeFlags.java	Fri Sep 13 22:22:14 2013 +0200
     3.3 @@ -0,0 +1,108 @@
     3.4 +/*
     3.5 + * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved.
     3.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     3.7 + *
     3.8 + * This code is free software; you can redistribute it and/or modify it
     3.9 + * under the terms of the GNU General Public License version 2 only, as
    3.10 + * published by the Free Software Foundation.
    3.11 + *
    3.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    3.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    3.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    3.15 + * version 2 for more details (a copy is included in the LICENSE file that
    3.16 + * accompanied this code).
    3.17 + *
    3.18 + * You should have received a copy of the GNU General Public License version
    3.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    3.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    3.21 + *
    3.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    3.23 + * or visit www.oracle.com if you need additional information or have any
    3.24 + * questions.
    3.25 + */
    3.26 +
    3.27 +import com.oracle.java.testlibrary.Asserts;
    3.28 +import com.oracle.java.testlibrary.OutputAnalyzer;
    3.29 +import com.oracle.java.testlibrary.ProcessTools;
    3.30 +
    3.31 +/*
    3.32 + * @test TestMetaspaceSizeFlags
    3.33 + * @key gc
    3.34 + * @bug 8024650
    3.35 + * @summary Test that metaspace size flags can be set correctly
    3.36 + * @library /testlibrary
    3.37 + */
    3.38 +public class TestMetaspaceSizeFlags {
    3.39 +  public static final long K = 1024L;
    3.40 +  public static final long M = 1024L * K;
    3.41 +
    3.42 +  // HotSpot uses a number of different values to align memory size flags.
    3.43 +  // This is currently the largest alignment (unless huge large pages are used).
    3.44 +  public static final long MAX_ALIGNMENT = 32 * M;
    3.45 +
    3.46 +  public static void main(String [] args) throws Exception {
    3.47 +    testMaxMetaspaceSizeEQMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT);
    3.48 +    // 8024650: MaxMetaspaceSize was adjusted instead of MetaspaceSize.
    3.49 +    testMaxMetaspaceSizeLTMetaspaceSize(MAX_ALIGNMENT, MAX_ALIGNMENT * 2);
    3.50 +    testMaxMetaspaceSizeGTMetaspaceSize(MAX_ALIGNMENT * 2, MAX_ALIGNMENT);
    3.51 +    testTooSmallInitialMetaspace(0, 0);
    3.52 +    testTooSmallInitialMetaspace(0, MAX_ALIGNMENT);
    3.53 +    testTooSmallInitialMetaspace(MAX_ALIGNMENT, 0);
    3.54 +  }
    3.55 +
    3.56 +  private static void testMaxMetaspaceSizeEQMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.57 +    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
    3.58 +    Asserts.assertEQ(maxMetaspaceSize, metaspaceSize);
    3.59 +    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
    3.60 +    Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
    3.61 +  }
    3.62 +
    3.63 +  private static void testMaxMetaspaceSizeLTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.64 +    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
    3.65 +    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
    3.66 +    Asserts.assertEQ(mf.metaspaceSize, maxMetaspaceSize);
    3.67 +  }
    3.68 +
    3.69 +  private static void testMaxMetaspaceSizeGTMetaspaceSize(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.70 +    MetaspaceFlags mf = runAndGetValue(maxMetaspaceSize, metaspaceSize);
    3.71 +    Asserts.assertGT(maxMetaspaceSize, metaspaceSize);
    3.72 +    Asserts.assertGT(mf.maxMetaspaceSize, mf.metaspaceSize);
    3.73 +    Asserts.assertEQ(mf.maxMetaspaceSize, maxMetaspaceSize);
    3.74 +    Asserts.assertEQ(mf.metaspaceSize, metaspaceSize);
    3.75 +  }
    3.76 +
    3.77 +  private static void testTooSmallInitialMetaspace(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.78 +    OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
    3.79 +    output.shouldContain("Too small initial Metaspace size");
    3.80 +  }
    3.81 +
    3.82 +  private static MetaspaceFlags runAndGetValue(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.83 +    OutputAnalyzer output = run(maxMetaspaceSize, metaspaceSize);
    3.84 +    output.shouldNotMatch("Error occurred during initialization of VM\n.*");
    3.85 +
    3.86 +    String stringMaxMetaspaceSize = output.firstMatch(".* MaxMetaspaceSize .* := (\\d+).*", 1);
    3.87 +    String stringMetaspaceSize = output.firstMatch(".* MetaspaceSize .* := (\\d+).*", 1);
    3.88 +
    3.89 +    return new MetaspaceFlags(Long.parseLong(stringMaxMetaspaceSize),
    3.90 +                              Long.parseLong(stringMetaspaceSize));
    3.91 +  }
    3.92 +
    3.93 +  private static OutputAnalyzer run(long maxMetaspaceSize, long metaspaceSize) throws Exception {
    3.94 +    ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    3.95 +        "-XX:MaxMetaspaceSize=" + maxMetaspaceSize,
    3.96 +        "-XX:MetaspaceSize=" + metaspaceSize,
    3.97 +        "-XX:-UseLargePages", // Prevent us from using 2GB large pages on solaris + sparc.
    3.98 +        "-XX:+PrintFlagsFinal",
    3.99 +        "-version");
   3.100 +    return new OutputAnalyzer(pb.start());
   3.101 +  }
   3.102 +
   3.103 +  private static class MetaspaceFlags {
   3.104 +    public long maxMetaspaceSize;
   3.105 +    public long metaspaceSize;
   3.106 +    public MetaspaceFlags(long maxMetaspaceSize, long metaspaceSize) {
   3.107 +      this.maxMetaspaceSize = maxMetaspaceSize;
   3.108 +      this.metaspaceSize = metaspaceSize;
   3.109 +    }
   3.110 +  }
   3.111 +}
     4.1 --- a/test/testlibrary/OutputAnalyzerTest.java	Fri Sep 13 22:21:06 2013 +0200
     4.2 +++ b/test/testlibrary/OutputAnalyzerTest.java	Fri Sep 13 22:22:14 2013 +0200
     4.3 @@ -172,5 +172,22 @@
     4.4      } catch (RuntimeException e) {
     4.5          // expected
     4.6      }
     4.7 +
     4.8 +    {
     4.9 +      String aaaa = "aaaa";
    4.10 +      String result = output.firstMatch(aaaa);
    4.11 +      if (!aaaa.equals(result)) {
    4.12 +        throw new Exception("firstMatch(String) faild to match. Expected: " + aaaa + " got: " + result);
    4.13 +      }
    4.14 +    }
    4.15 +
    4.16 +    {
    4.17 +      String aa = "aa";
    4.18 +      String aa_grouped_aa = aa + "(" + aa + ")";
    4.19 +      String result = output.firstMatch(aa_grouped_aa, 1);
    4.20 +      if (!aa.equals(result)) {
    4.21 +        throw new Exception("firstMatch(String, int) failed to match. Expected: " + aa + " got: " + result);
    4.22 +      }
    4.23 +    }
    4.24    }
    4.25  }
     5.1 --- a/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java	Fri Sep 13 22:21:06 2013 +0200
     5.2 +++ b/test/testlibrary/com/oracle/java/testlibrary/OutputAnalyzer.java	Fri Sep 13 22:22:14 2013 +0200
     5.3 @@ -211,13 +211,13 @@
     5.4        if (matcher.find()) {
     5.5            reportDiagnosticSummary();
     5.6            throw new RuntimeException("'" + pattern
     5.7 -                  + "' found in stdout \n");
     5.8 +                  + "' found in stdout: '" + matcher.group() + "' \n");
     5.9        }
    5.10        matcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
    5.11        if (matcher.find()) {
    5.12            reportDiagnosticSummary();
    5.13            throw new RuntimeException("'" + pattern
    5.14 -                  + "' found in stderr \n");
    5.15 +                  + "' found in stderr: '" + matcher.group() + "' \n");
    5.16        }
    5.17    }
    5.18  
    5.19 @@ -254,6 +254,37 @@
    5.20    }
    5.21  
    5.22    /**
    5.23 +   * Get the captured group of the first string matching the pattern.
    5.24 +   * stderr is searched before stdout.
    5.25 +   *
    5.26 +   * @param pattern The multi-line pattern to match
    5.27 +   * @param group The group to capture
    5.28 +   * @return The matched string or null if no match was found
    5.29 +   */
    5.30 +  public String firstMatch(String pattern, int group) {
    5.31 +    Matcher stderrMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stderr);
    5.32 +    Matcher stdoutMatcher = Pattern.compile(pattern, Pattern.MULTILINE).matcher(stdout);
    5.33 +    if (stderrMatcher.find()) {
    5.34 +      return stderrMatcher.group(group);
    5.35 +    }
    5.36 +    if (stdoutMatcher.find()) {
    5.37 +      return stdoutMatcher.group(group);
    5.38 +    }
    5.39 +    return null;
    5.40 +  }
    5.41 +
    5.42 +  /**
    5.43 +   * Get the first string matching the pattern.
    5.44 +   * stderr is searched before stdout.
    5.45 +   *
    5.46 +   * @param pattern The multi-line pattern to match
    5.47 +   * @return The matched string or null if no match was found
    5.48 +   */
    5.49 +  public String firstMatch(String pattern) {
    5.50 +    return firstMatch(pattern, 0);
    5.51 +  }
    5.52 +
    5.53 +  /**
    5.54     * Verify the exit value of the process
    5.55     *
    5.56     * @param expectedExitValue Expected exit value from process

mercurial