1 /* 2 * Copyright (c) 2014, 2024, 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 id=invalid 26 * @bug 8022865 27 * @summary Tests for the -XX:CompressedClassSpaceSize command line option 28 * @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true 29 * @requires vm.flagless 30 * @library /test/lib 31 * @modules java.base/jdk.internal.misc java.management 32 * @run driver CompressedClassSpaceSize invalid 33 */ 34 35 /* 36 * @test id=valid_small 37 * @bug 8022865 38 * @summary Tests for the -XX:CompressedClassSpaceSize command line option 39 * @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true 40 * @requires vm.flagless 41 * @library /test/lib 42 * @modules java.base/jdk.internal.misc java.management 43 * @run driver CompressedClassSpaceSize valid_small 44 */ 45 46 /* 47 * @test id=valid_large_nocds 48 * @bug 8022865 49 * @summary Tests for the -XX:CompressedClassSpaceSize command line option 50 * @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true 51 * @requires vm.flagless 52 * @library /test/lib 53 * @modules java.base/jdk.internal.misc java.management 54 * @run driver CompressedClassSpaceSize valid_large_nocds 55 */ 56 57 /* 58 * @test id=valid_large_cds 59 * @bug 8022865 60 * @summary Tests for the -XX:CompressedClassSpaceSize command line option 61 * @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true & vm.cds 62 * @requires vm.flagless 63 * @library /test/lib 64 * @modules java.base/jdk.internal.misc java.management 65 * @run driver CompressedClassSpaceSize valid_large_cds 66 */ 67 68 import jdk.test.lib.process.ProcessTools; 69 import jdk.test.lib.process.OutputAnalyzer; 70 71 public class CompressedClassSpaceSize { 72 73 final static long MB = 1024 * 1024; 74 75 final static long minAllowedClassSpaceSize = MB; 76 final static long minRealClassSpaceSize = 16 * MB; 77 final static long maxClassSpaceSize = 512 * MB; 78 79 // For the valid_large_cds sub test: we need to have a notion of what archive size to 80 // maximally expect, with a generous fudge factor to avoid having to tweak this test 81 // ofent. Note: today's default archives are around 16-20 MB. 82 final static long maxExpectedArchiveSize = 512 * MB; 83 84 public static void main(String[] args) throws Exception { 85 ProcessBuilder pb; 86 OutputAnalyzer output; 87 88 switch (args[0]) { 89 case "invalid": { 90 // < Minimum size 91 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=0", 92 "-version"); 93 output = new OutputAnalyzer(pb.start()); 94 output.shouldContain("outside the allowed range") 95 .shouldHaveExitValue(1); 96 97 // Invalid size of -1 should be handled correctly 98 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=-1", 99 "-version"); 100 output = new OutputAnalyzer(pb.start()); 101 output.shouldContain("Improperly specified VM option 'CompressedClassSpaceSize=-1'") 102 .shouldHaveExitValue(1); 103 104 // > Maximum size 105 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize + 1, 106 "-version"); 107 output = new OutputAnalyzer(pb.start()); 108 output.shouldContain("outside the allowed range") 109 .shouldHaveExitValue(1); 110 111 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:-UseCompressedClassPointers", 112 "-XX:CompressedClassSpaceSize=" + minAllowedClassSpaceSize, 113 "-version"); 114 output = new OutputAnalyzer(pb.start()); 115 output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used") 116 .shouldHaveExitValue(0); 117 } 118 break; 119 case "valid_small": { 120 // Make sure the minimum size is set correctly and printed 121 // (Note: ccs size are rounded up to the next larger root chunk boundary (16m). 122 // Note that this is **reserved** size and does not affect rss. 123 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", 124 "-XX:CompressedClassSpaceSize=" + minAllowedClassSpaceSize, 125 "-Xlog:gc+metaspace", 126 "-version"); 127 output = new OutputAnalyzer(pb.start()); 128 output.shouldMatch("Compressed class space.*" + minRealClassSpaceSize) 129 .shouldHaveExitValue(0); 130 } 131 break; 132 case "valid_large_nocds": { 133 // Without CDS, we should get 4G 134 pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize, 135 "-Xshare:off", "-Xlog:metaspace*", "-version"); 136 output = new OutputAnalyzer(pb.start()); 137 output.shouldMatch("Compressed class space.*" + maxClassSpaceSize) 138 .shouldHaveExitValue(0); 139 } 140 break; 141 case "valid_large_cds": { 142 // TODO: Does not currently work with +UseCompactObjectHeaders. 143 // // Create archive 144 // pb = ProcessTools.createLimitedTestJavaProcessBuilder( 145 // "-XX:SharedArchiveFile=./abc.jsa", "-Xshare:dump", "-version"); 146 // output = new OutputAnalyzer(pb.start()); 147 // output.shouldHaveExitValue(0); 148 149 // // With CDS, class space should fill whatever the CDS archive leaves us (modulo alignment) 150 // pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize, 151 // "-XX:SharedArchiveFile=./abc.jsa", "-Xshare:on", "-Xlog:metaspace*", "-version"); 152 // output = new OutputAnalyzer(pb.start()); 153 // output.shouldHaveExitValue(0); 154 // long reducedSize = Long.parseLong( 155 // output.firstMatch("reducing class space size from " + maxClassSpaceSize + " to (\\d+)", 1)); 156 // if (reducedSize < (maxClassSpaceSize - maxExpectedArchiveSize)) { 157 // output.reportDiagnosticSummary(); 158 // throw new RuntimeException("Class space size too small?"); 159 // } 160 // output.shouldMatch("Compressed class space.*" + reducedSize); 161 } 162 break; 163 default: 164 throw new RuntimeException("invalid sub test " + args[0]); 165 } 166 } 167 }