1 /*
   2  * Copyright (c) 2014, 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 /*
  25  * @test
  26  * @bug 8022865
  27  * @summary Tests for the -XX:CompressedClassSpaceSize command line option
  28  * @library /testlibrary
  29  * @run main CompressedClassSpaceSize
  30  */
  31 import com.oracle.java.testlibrary.*;
  32 
  33 public class CompressedClassSpaceSize {
  34 
  35     public static void main(String[] args) throws Exception {
  36         ProcessBuilder pb;
  37         OutputAnalyzer output;
  38         if (Platform.is64bit()) {
  39             // Minimum size is 1MB
  40             pb = ProcessTools.createJavaProcessBuilder("-XX:CompressedClassSpaceSize=0",
  41                                                        "-version");
  42             output = new OutputAnalyzer(pb.start());
  43             output.shouldContain("CompressedClassSpaceSize of 0 is invalid")
  44                   .shouldHaveExitValue(1);
  45 
  46             // Invalid size of -1 should be handled correctly
  47             pb = ProcessTools.createJavaProcessBuilder("-XX:CompressedClassSpaceSize=-1",
  48                                                        "-version");
  49             output = new OutputAnalyzer(pb.start());
  50             output.shouldContain("Improperly specified VM option 'CompressedClassSpaceSize=-1'")
  51                   .shouldHaveExitValue(1);
  52 
  53 
  54             // Maximum size is 3GB
  55             pb = ProcessTools.createJavaProcessBuilder("-XX:CompressedClassSpaceSize=4g",
  56                                                        "-version");
  57             output = new OutputAnalyzer(pb.start());
  58             output.shouldContain("CompressedClassSpaceSize of 4294967296 is invalid")
  59                   .shouldHaveExitValue(1);
  60 
  61 
  62             // Make sure the minimum size is set correctly and printed
  63             pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions",
  64                                                        "-XX:CompressedClassSpaceSize=1m",
  65                                                        "-XX:+PrintCompressedOopsMode",
  66                                                        "-version");
  67             output = new OutputAnalyzer(pb.start());
  68             output.shouldContain("Compressed class space size: 1048576")
  69                   .shouldHaveExitValue(0);
  70 
  71 
  72             // Make sure the maximum size is set correctly and printed
  73             pb = ProcessTools.createJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions",
  74                                                        "-XX:CompressedClassSpaceSize=3g",
  75                                                        "-XX:+PrintCompressedOopsMode",
  76                                                        "-version");
  77             output = new OutputAnalyzer(pb.start());
  78             output.shouldContain("Compressed class space size: 3221225472")
  79                   .shouldHaveExitValue(0);
  80 
  81 
  82             pb = ProcessTools.createJavaProcessBuilder("-XX:-UseCompressedOops",
  83                                                        "-XX:CompressedClassSpaceSize=1m",
  84                                                        "-version");
  85             output = new OutputAnalyzer(pb.start());
  86             output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used")
  87                   .shouldHaveExitValue(0);
  88 
  89 
  90             pb = ProcessTools.createJavaProcessBuilder("-XX:-UseCompressedClassPointers",
  91                                                        "-XX:CompressedClassSpaceSize=1m",
  92                                                        "-version");
  93             output = new OutputAnalyzer(pb.start());
  94             output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used")
  95                   .shouldHaveExitValue(0);
  96         } else {
  97             // 32bit platforms doesn't have compressed oops
  98             pb = ProcessTools.createJavaProcessBuilder("-XX:CompressedClassSpaceSize=1m",
  99                                                        "-version");
 100             output = new OutputAnalyzer(pb.start());
 101             output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used")
 102                   .shouldHaveExitValue(0);
 103         }
 104     }
 105 }