|
22 | 22 | */ |
23 | 23 |
|
24 | 24 | /* |
25 | | - * @test |
| 25 | + * @test id=invalid |
26 | 26 | * @bug 8022865 |
27 | 27 | * @summary Tests for the -XX:CompressedClassSpaceSize command line option |
28 | 28 | * @requires vm.bits == 64 & vm.opt.final.UseCompressedOops == true |
29 | 29 | * @requires vm.flagless |
30 | 30 | * @library /test/lib |
31 | | - * @modules java.base/jdk.internal.misc |
32 | | - * java.management |
33 | | - * @run driver CompressedClassSpaceSize |
| 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 |
34 | 66 | */ |
35 | 67 |
|
36 | 68 | import jdk.test.lib.process.ProcessTools; |
37 | 69 | import jdk.test.lib.process.OutputAnalyzer; |
38 | 70 |
|
39 | 71 | public class CompressedClassSpaceSize { |
40 | 72 |
|
41 | | - public static void main(String[] args) throws Exception { |
42 | | - ProcessBuilder pb; |
43 | | - OutputAnalyzer output; |
44 | | - // Minimum size is 1MB |
45 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=0", |
46 | | - "-version"); |
47 | | - output = new OutputAnalyzer(pb.start()); |
48 | | - output.shouldContain("outside the allowed range") |
49 | | - .shouldHaveExitValue(1); |
50 | | - |
51 | | - // Invalid size of -1 should be handled correctly |
52 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=-1", |
53 | | - "-version"); |
54 | | - output = new OutputAnalyzer(pb.start()); |
55 | | - output.shouldContain("Improperly specified VM option 'CompressedClassSpaceSize=-1'") |
56 | | - .shouldHaveExitValue(1); |
| 73 | + final static long MB = 1024 * 1024; |
57 | 74 |
|
| 75 | + final static long minAllowedClassSpaceSize = MB; |
| 76 | + final static long minRealClassSpaceSize = 16 * MB; |
| 77 | + final static long maxClassSpaceSize = 4096 * MB; |
58 | 78 |
|
59 | | - // Maximum size is 3GB |
60 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=4g", |
61 | | - "-version"); |
62 | | - output = new OutputAnalyzer(pb.start()); |
63 | | - output.shouldContain("outside the allowed range") |
64 | | - .shouldHaveExitValue(1); |
| 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; |
65 | 83 |
|
| 84 | + public static void main(String[] args) throws Exception { |
| 85 | + ProcessBuilder pb; |
| 86 | + OutputAnalyzer output; |
66 | 87 |
|
67 | | - // Make sure the minimum size is set correctly and printed |
68 | | - // (Note: ccs size are rounded up to the next larger root chunk boundary (16m). |
69 | | - // Note that this is **reserved** size and does not affect rss. |
70 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", |
71 | | - "-XX:CompressedClassSpaceSize=1m", |
72 | | - "-Xlog:gc+metaspace=trace", |
73 | | - "-version"); |
74 | | - output = new OutputAnalyzer(pb.start()); |
75 | | - output.shouldMatch("Compressed class space.*16777216") |
76 | | - .shouldHaveExitValue(0); |
| 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); |
77 | 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); |
78 | 103 |
|
79 | | - // Make sure the maximum size is set correctly and printed |
80 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:+UnlockDiagnosticVMOptions", |
81 | | - "-XX:CompressedClassSpaceSize=3g", |
82 | | - "-Xlog:gc+metaspace=trace", |
83 | | - "-version"); |
84 | | - output = new OutputAnalyzer(pb.start()); |
85 | | - output.shouldMatch("Compressed class space.*3221225472") |
86 | | - .shouldHaveExitValue(0); |
| 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); |
87 | 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 | + // Create archive |
| 143 | + pb = ProcessTools.createLimitedTestJavaProcessBuilder( |
| 144 | + "-XX:SharedArchiveFile=./abc.jsa", "-Xshare:dump", "-version"); |
| 145 | + output = new OutputAnalyzer(pb.start()); |
| 146 | + output.shouldHaveExitValue(0); |
88 | 147 |
|
89 | | - pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:-UseCompressedClassPointers", |
90 | | - "-XX:CompressedClassSpaceSize=1m", |
91 | | - "-version"); |
92 | | - output = new OutputAnalyzer(pb.start()); |
93 | | - output.shouldContain("Setting CompressedClassSpaceSize has no effect when compressed class pointers are not used") |
94 | | - .shouldHaveExitValue(0); |
| 148 | + // With CDS, class space should fill whatever the CDS archive leaves us (modulo alignment) |
| 149 | + pb = ProcessTools.createLimitedTestJavaProcessBuilder("-XX:CompressedClassSpaceSize=" + maxClassSpaceSize, |
| 150 | + "-XX:SharedArchiveFile=./abc.jsa", "-Xshare:on", "-Xlog:metaspace*", "-version"); |
| 151 | + output = new OutputAnalyzer(pb.start()); |
| 152 | + output.shouldHaveExitValue(0); |
| 153 | + long reducedSize = Long.parseLong( |
| 154 | + output.firstMatch("reducing class space size from " + maxClassSpaceSize + " to (\\d+)", 1)); |
| 155 | + if (reducedSize < (maxClassSpaceSize - maxExpectedArchiveSize)) { |
| 156 | + output.reportDiagnosticSummary(); |
| 157 | + throw new RuntimeException("Class space size too small?"); |
| 158 | + } |
| 159 | + output.shouldMatch("Compressed class space.*" + reducedSize); |
| 160 | + } |
| 161 | + break; |
| 162 | + default: |
| 163 | + throw new RuntimeException("invalid sub test " + args[0]); |
| 164 | + } |
95 | 165 | } |
96 | 166 | } |
0 commit comments