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