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 /* @test LimitSharedSizes 25 * @summary Test handling of limits on shared space size 26 * @library /testlibrary 27 * @run main LimitSharedSizes 28 */ 29 30 import com.oracle.java.testlibrary.*; 31 32 public class LimitSharedSizes { 33 private static class SharedSizeTestData { 34 public String optionName; 35 public String optionValue; 36 public String expectedErrorMsg; 37 38 public SharedSizeTestData(String name, String value, String msg) { 39 optionName = name; 40 optionValue = value; 41 expectedErrorMsg = msg; 42 } 43 } 44 45 private static final SharedSizeTestData[] testTable = { 46 // values in this part of the test table should cause failure 47 // (shared space sizes are deliberately too small) 48 new SharedSizeTestData("-XX:SharedReadOnlySize", "4M", "read only"), 49 new SharedSizeTestData("-XX:SharedReadWriteSize","4M", "read write"), 50 51 // Known issue, JDK-8038422 (assert() on Windows) 52 // new SharedSizeTestData("-XX:SharedMiscDataSize", "500k", "miscellaneous data"), 53 54 // Too small of a misc code size should not cause a vm crash. 55 // It should result in the following error message: 56 // The shared miscellaneous code space is not large enough 57 // to preload requested classes. Use -XX:SharedMiscCodeSize= 58 // to increase the initial size of shared miscellaneous code space. 59 new SharedSizeTestData("-XX:SharedMiscCodeSize", "20k", "miscellaneous code"), 60 61 // these values are larger than default ones, but should 62 // be acceptable and not cause failure 63 new SharedSizeTestData("-XX:SharedReadOnlySize", "20M", null), 64 new SharedSizeTestData("-XX:SharedReadWriteSize", "20M", null), 65 new SharedSizeTestData("-XX:SharedMiscDataSize", "20M", null), 66 new SharedSizeTestData("-XX:SharedMiscCodeSize", "20M", null) 67 }; 68 69 public static void main(String[] args) throws Exception { 70 String fileName = "test.jsa"; 71 72 for (SharedSizeTestData td : testTable) { 73 String option = td.optionName + "=" + td.optionValue; 74 System.out.println("testing option <" + option + ">"); 75 76 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 77 "-XX:+UnlockDiagnosticVMOptions", 78 "-XX:SharedArchiveFile=./" + fileName, 79 option, 80 "-Xshare:dump"); 81 82 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 83 84 if (td.expectedErrorMsg != null) { 85 output.shouldContain("The shared " + td.expectedErrorMsg 86 + " space is not large enough"); 87 88 output.shouldHaveExitValue(2); 89 } else { 90 output.shouldNotContain("space is not large enough"); 91 output.shouldHaveExitValue(0); 92 } 93 } 94 } 95 } | 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 /* @test LimitSharedSizes 25 * @summary Test handling of limits on shared space size 26 * @library /testlibrary 27 * @run main LimitSharedSizes 28 */ 29 30 import com.oracle.java.testlibrary.*; 31 32 public class LimitSharedSizes { 33 static enum Region { 34 RO, RW, MD, MC 35 } 36 37 private static class SharedSizeTestData { 38 public String optionName; 39 public String optionValue; 40 public String expectedErrorMsg; 41 42 public SharedSizeTestData(Region region, String value, String msg) { 43 optionName = getName(region); 44 optionValue = value; 45 expectedErrorMsg = msg; 46 } 47 48 public SharedSizeTestData(Region region, String msg) { 49 optionName = getName(region); 50 optionValue = getValue(region); 51 expectedErrorMsg = msg; 52 } 53 54 private String getName(Region region) { 55 String name; 56 switch (region) { 57 case RO: 58 name = "-XX:SharedReadOnlySize"; 59 break; 60 case RW: 61 name = "-XX:SharedReadWriteSize"; 62 break; 63 case MD: 64 name = "-XX:SharedMiscDataSize"; 65 break; 66 case MC: 67 name = "-XX:SharedMiscCodeSize"; 68 break; 69 default: 70 name = "Unknown"; 71 break; 72 } 73 return name; 74 } 75 76 private String getValue(Region region) { 77 String value; 78 switch (region) { 79 case RO: 80 value = Platform.is64bit() ? "9M" : "8M"; 81 break; 82 case RW: 83 value = Platform.is64bit() ? "12M" : "7M"; 84 break; 85 case MD: 86 value = Platform.is64bit() ? "4M" : "2M"; 87 break; 88 case MC: 89 value = "120k"; 90 break; 91 default: 92 value = "0M"; 93 break; 94 } 95 return value; 96 } 97 } 98 99 private static final SharedSizeTestData[] testTable = { 100 // Too small of a region size should not cause a vm crash. 101 // It should result in an error message like the following: 102 // The shared miscellaneous code space is not large enough 103 // to preload requested classes. Use -XX:SharedMiscCodeSize= 104 // to increase the initial size of shared miscellaneous code space. 105 new SharedSizeTestData(Region.RO, "4M", "read only"), 106 new SharedSizeTestData(Region.RW, "4M", "read write"), 107 new SharedSizeTestData(Region.MD, "50k", "miscellaneous data"), 108 new SharedSizeTestData(Region.MC, "20k", "miscellaneous code"), 109 110 // these values are larger than default ones, but should 111 // be acceptable and not cause failure 112 new SharedSizeTestData(Region.RO, "20M", null), 113 new SharedSizeTestData(Region.RW, "20M", null), 114 new SharedSizeTestData(Region.MD, "20M", null), 115 new SharedSizeTestData(Region.MC, "20M", null), 116 117 // test with sizes which just meet the minimum required sizes 118 // the following tests also attempt to use the shared archive 119 new SharedSizeTestData(Region.RO, "UseArchive"), 120 new SharedSizeTestData(Region.RW, "UseArchive"), 121 new SharedSizeTestData(Region.MD, "UseArchive"), 122 new SharedSizeTestData(Region.MC, "UseArchive") 123 }; 124 125 public static void main(String[] args) throws Exception { 126 String fileName = "test.jsa"; 127 128 for (SharedSizeTestData td : testTable) { 129 String option = td.optionName + "=" + td.optionValue; 130 System.out.println("testing option <" + option + ">"); 131 132 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( 133 "-XX:+UnlockDiagnosticVMOptions", 134 "-XX:SharedArchiveFile=./" + fileName, 135 option, 136 "-Xshare:dump"); 137 138 OutputAnalyzer output = new OutputAnalyzer(pb.start()); 139 140 if (td.expectedErrorMsg != null) { 141 if (!td.expectedErrorMsg.equals("UseArchive")) { 142 output.shouldContain("The shared " + td.expectedErrorMsg 143 + " space is not large enough"); 144 145 output.shouldHaveExitValue(2); 146 } else { 147 output.shouldNotContain("space is not large enough"); 148 output.shouldHaveExitValue(0); 149 150 // try to use the archive 151 pb = ProcessTools.createJavaProcessBuilder( 152 "-XX:+UnlockDiagnosticVMOptions", 153 "-XX:SharedArchiveFile=./" + fileName, 154 "-XX:+PrintSharedArchiveAndExit", 155 "-version"); 156 157 output = new OutputAnalyzer(pb.start()); 158 try { 159 output.shouldContain("archive is valid"); 160 } catch (RuntimeException e) { 161 // if sharing failed due to ASLR or similar reasons, 162 // check whether sharing was attempted at all (UseSharedSpaces) 163 output.shouldContain("Unable to use shared archive"); 164 output.shouldHaveExitValue(1); 165 } 166 output.shouldHaveExitValue(0); 167 } 168 } else { 169 output.shouldNotContain("space is not large enough"); 170 output.shouldHaveExitValue(0); 171 } 172 } 173 } 174 } |