8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize

Tue, 24 Oct 2017 22:45:26 +0900

author
ysuenaga
date
Tue, 24 Oct 2017 22:45:26 +0900
changeset 9049
ac8450bdd81c
parent 9048
935cacbb8fab
child 9050
7cf8e195651f
child 9051
519770602025

8087291: InitialBootClassLoaderMetaspaceSize and CompressedClassSpaceSize should be checked consistent from MaxMetaspaceSize
Reviewed-by: dholmes, sspitsyn, poonam

src/share/vm/memory/metaspace.cpp file | annotate | diff | comparison | revisions
test/runtime/Metaspace/MaxMetaspaceSizeTest.java file | annotate | diff | comparison | revisions
     1.1 --- a/src/share/vm/memory/metaspace.cpp	Tue Oct 31 20:29:34 2017 +0000
     1.2 +++ b/src/share/vm/memory/metaspace.cpp	Tue Oct 24 22:45:26 2017 +0900
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (c) 2011, 2014, Oracle and/or its affiliates. All rights reserved.
     1.6 + * Copyright (c) 2011, 2017, 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 @@ -3135,6 +3135,24 @@
    1.11  
    1.12    CompressedClassSpaceSize = align_size_down_bounded(CompressedClassSpaceSize, _reserve_alignment);
    1.13    set_compressed_class_space_size(CompressedClassSpaceSize);
    1.14 +
    1.15 +  // Initial virtual space size will be calculated at global_initialize()
    1.16 +  uintx min_metaspace_sz =
    1.17 +      VIRTUALSPACEMULTIPLIER * InitialBootClassLoaderMetaspaceSize;
    1.18 +  if (UseCompressedClassPointers) {
    1.19 +    if ((min_metaspace_sz + CompressedClassSpaceSize) >  MaxMetaspaceSize) {
    1.20 +      if (min_metaspace_sz >= MaxMetaspaceSize) {
    1.21 +        vm_exit_during_initialization("MaxMetaspaceSize is too small.");
    1.22 +      } else {
    1.23 +        FLAG_SET_ERGO(uintx, CompressedClassSpaceSize,
    1.24 +                      MaxMetaspaceSize - min_metaspace_sz);
    1.25 +      }
    1.26 +    }
    1.27 +  } else if (min_metaspace_sz >= MaxMetaspaceSize) {
    1.28 +    FLAG_SET_ERGO(uintx, InitialBootClassLoaderMetaspaceSize,
    1.29 +                  min_metaspace_sz);
    1.30 +  }
    1.31 +
    1.32  }
    1.33  
    1.34  void Metaspace::global_initialize() {
     2.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     2.2 +++ b/test/runtime/Metaspace/MaxMetaspaceSizeTest.java	Tue Oct 24 22:45:26 2017 +0900
     2.3 @@ -0,0 +1,47 @@
     2.4 +/*
     2.5 + * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
     2.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     2.7 + *
     2.8 + * This code is free software; you can redistribute it and/or modify it
     2.9 + * under the terms of the GNU General Public License version 2 only, as
    2.10 + * published by the Free Software Foundation.
    2.11 + *
    2.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    2.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    2.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    2.15 + * version 2 for more details (a copy is included in the LICENSE file that
    2.16 + * accompanied this code).
    2.17 + *
    2.18 + * You should have received a copy of the GNU General Public License version
    2.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    2.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    2.21 + *
    2.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    2.23 + * or visit www.oracle.com if you need additional information or have any
    2.24 + * questions.
    2.25 + */
    2.26 +
    2.27 +import com.oracle.java.testlibrary.ProcessTools;
    2.28 +import com.oracle.java.testlibrary.OutputAnalyzer;
    2.29 +
    2.30 +/*
    2.31 + * @test MaxMetaspaceSizeTest
    2.32 + * @requires vm.bits == "64"
    2.33 + * @bug 8087291
    2.34 + * @library /testlibrary
    2.35 + * @run main/othervm MaxMetaspaceSizeTest
    2.36 + */
    2.37 +
    2.38 +public class MaxMetaspaceSizeTest {
    2.39 +    public static void main(String... args) throws Exception {
    2.40 +        ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(
    2.41 +            "-Xmx1g",
    2.42 +            "-XX:InitialBootClassLoaderMetaspaceSize=4195328",
    2.43 +            "-XX:MaxMetaspaceSize=4195328",
    2.44 +            "-XX:+UseCompressedClassPointers",
    2.45 +            "-XX:CompressedClassSpaceSize=1g",
    2.46 +            "-version");
    2.47 +        OutputAnalyzer output = new OutputAnalyzer(pb.start());
    2.48 +        output.shouldContain("MaxMetaspaceSize is too small.");
    2.49 +    }
    2.50 +}

mercurial