test/runtime/SharedArchiveFile/LimitSharedSizes.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File webrev Cdiff test/runtime/SharedArchiveFile/LimitSharedSizes.java

test/runtime/SharedArchiveFile/LimitSharedSizes.java

Print this page

        

*** 21,158 **** * questions. */ /* @test LimitSharedSizes * @summary Test handling of limits on shared space size ! * @library /testlibrary * @modules java.base/sun.misc * java.management * @run main LimitSharedSizes */ import jdk.test.lib.*; public class LimitSharedSizes { static enum Region { RO, RW, MD, MC } private static class SharedSizeTestData { public String optionName; public String optionValue; ! public String expectedErrorMsg; ! public SharedSizeTestData(Region region, String value, String msg) { ! optionName = getName(region); optionValue = value; ! expectedErrorMsg = msg; } ! public SharedSizeTestData(Region region, String msg) { ! optionName = getName(region); ! optionValue = getValue(region); ! expectedErrorMsg = msg; } private String getName(Region region) { String name; switch (region) { case RO: ! name = "-XX:SharedReadOnlySize"; break; case RW: ! name = "-XX:SharedReadWriteSize"; break; case MD: ! name = "-XX:SharedMiscDataSize"; break; case MC: ! name = "-XX:SharedMiscCodeSize"; break; default: name = "Unknown"; break; } return name; } ! private String getValue(Region region) { ! String value; ! switch (region) { ! case RO: ! value = Platform.is64bit() ? "9M" : "8M"; ! break; ! case RW: ! value = Platform.is64bit() ? "12M" : "7M"; ! break; ! case MD: ! value = Platform.is64bit() ? "4M" : "2M"; ! break; ! case MC: ! value = "120k"; ! break; ! default: ! value = "0M"; ! break; ! } ! return value; } } private static final SharedSizeTestData[] testTable = { // Too small of a region size should not cause a vm crash. ! // It should result in an error message like the following: // The shared miscellaneous code space is not large enough // to preload requested classes. Use -XX:SharedMiscCodeSize= // to increase the initial size of shared miscellaneous code space. ! new SharedSizeTestData(Region.RO, "4M", "read only"), ! new SharedSizeTestData(Region.RW, "4M", "read write"), ! new SharedSizeTestData(Region.MD, "50k", "miscellaneous data"), ! new SharedSizeTestData(Region.MC, "20k", "miscellaneous code"), ! // these values are larger than default ones, but should // be acceptable and not cause failure ! new SharedSizeTestData(Region.RO, "20M", null), ! new SharedSizeTestData(Region.RW, "20M", null), ! new SharedSizeTestData(Region.MD, "20M", null), ! new SharedSizeTestData(Region.MC, "20M", null), // test with sizes which just meet the minimum required sizes // the following tests also attempt to use the shared archive ! new SharedSizeTestData(Region.RO, "UseArchive"), ! new SharedSizeTestData(Region.RW, "UseArchive"), ! new SharedSizeTestData(Region.MD, "UseArchive"), ! new SharedSizeTestData(Region.MC, "UseArchive") }; public static void main(String[] args) throws Exception { int counter = 0; for (SharedSizeTestData td : testTable) { String fileName = "LimitSharedSizes" + counter + ".jsa"; counter++; String option = td.optionName + "=" + td.optionValue; System.out.println("testing option <" + option + ">"); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + fileName, option, "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); ! if (td.expectedErrorMsg != null) { ! if (!td.expectedErrorMsg.equals("UseArchive")) { ! output.shouldContain("The shared " + td.expectedErrorMsg ! + " space is not large enough"); ! ! output.shouldHaveExitValue(2); ! } else { output.shouldNotContain("space is not large enough"); output.shouldHaveExitValue(0); // try to use the archive pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + fileName, "-XX:+PrintSharedArchiveAndExit", --- 21,163 ---- * questions. */ /* @test LimitSharedSizes * @summary Test handling of limits on shared space size ! * @library /testlibrary /runtime/CommandLine/OptionsValidation/common * @modules java.base/sun.misc * java.management * @run main LimitSharedSizes */ import jdk.test.lib.*; + import optionsvalidation.JVMOptionsUtils; public class LimitSharedSizes { + static enum Result { + OUT_OF_RANGE, + TOO_SMALL, + VALID, + VALID_ARCHIVE + } + static enum Region { RO, RW, MD, MC } + private static final boolean fitsRange(String name, String value) throws RuntimeException { + boolean fits = true; + try { + fits = JVMOptionsUtils.fitsRange(name, value); + } catch (Exception e) { + throw new RuntimeException(e.getMessage()); + } + return fits; + } + private static class SharedSizeTestData { public String optionName; public String optionValue; ! public Result optionResult; ! public SharedSizeTestData(Region region, String value) { ! optionName = "-XX:"+getName(region); optionValue = value; ! if (fitsRange(getName(region), value) == false) { ! optionResult = Result.OUT_OF_RANGE; ! } else { ! optionResult = Result.TOO_SMALL; ! } } ! public SharedSizeTestData(Region region, String value, Result result) { ! optionName = "-XX:"+getName(region); ! optionValue = value; ! optionResult = result; } private String getName(Region region) { String name; switch (region) { case RO: ! name = "SharedReadOnlySize"; break; case RW: ! name = "SharedReadWriteSize"; break; case MD: ! name = "SharedMiscDataSize"; break; case MC: ! name = "SharedMiscCodeSize"; break; default: name = "Unknown"; break; } return name; } ! public Result getResult() { ! return optionResult; } } private static final SharedSizeTestData[] testTable = { // Too small of a region size should not cause a vm crash. ! // It should result in an error message either like the following #1: // The shared miscellaneous code space is not large enough // to preload requested classes. Use -XX:SharedMiscCodeSize= // to increase the initial size of shared miscellaneous code space. ! // or #2: ! // The shared miscellaneous code space is outside the allowed range ! new SharedSizeTestData(Region.RO, "4M"), ! new SharedSizeTestData(Region.RW, "4M"), ! new SharedSizeTestData(Region.MD, "50k"), ! new SharedSizeTestData(Region.MC, "20k"), ! // these values are larger than default ones, and should // be acceptable and not cause failure ! new SharedSizeTestData(Region.RO, "20M", Result.VALID), ! new SharedSizeTestData(Region.RW, "20M", Result.VALID), ! new SharedSizeTestData(Region.MD, "20M", Result.VALID), ! new SharedSizeTestData(Region.MC, "20M", Result.VALID), // test with sizes which just meet the minimum required sizes // the following tests also attempt to use the shared archive ! new SharedSizeTestData(Region.RO, Platform.is64bit() ? "9M":"8M", Result.VALID_ARCHIVE), ! new SharedSizeTestData(Region.RW, Platform.is64bit() ? "12M":"7M", Result.VALID_ARCHIVE), ! new SharedSizeTestData(Region.MD, Platform.is64bit() ? "4M":"2M", Result.VALID_ARCHIVE), ! new SharedSizeTestData(Region.MC, "120k", Result.VALID_ARCHIVE), }; public static void main(String[] args) throws Exception { int counter = 0; for (SharedSizeTestData td : testTable) { String fileName = "LimitSharedSizes" + counter + ".jsa"; counter++; String option = td.optionName + "=" + td.optionValue; + System.out.println("testing option number <" + counter + ">"); System.out.println("testing option <" + option + ">"); ProcessBuilder pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + fileName, option, "-Xshare:dump"); OutputAnalyzer output = new OutputAnalyzer(pb.start()); ! switch (td.getResult()) { ! case VALID: ! case VALID_ARCHIVE: ! { output.shouldNotContain("space is not large enough"); output.shouldHaveExitValue(0); + if (td.getResult() == Result.VALID_ARCHIVE) { // try to use the archive pb = ProcessTools.createJavaProcessBuilder( "-XX:+UnlockDiagnosticVMOptions", "-XX:SharedArchiveFile=./" + fileName, "-XX:+PrintSharedArchiveAndExit",
*** 173,184 **** return; } } output.shouldHaveExitValue(0); } ! } else { ! output.shouldNotContain("space is not large enough"); ! output.shouldHaveExitValue(0); } } } } --- 178,200 ---- return; } } output.shouldHaveExitValue(0); } ! } ! break; ! case TOO_SMALL: ! { ! output.shouldContain("space is not large enough"); ! output.shouldHaveExitValue(2); ! } ! break; ! case OUT_OF_RANGE: ! { ! output.shouldContain("outside the allowed range"); ! output.shouldHaveExitValue(1); ! } ! break; } } } }
test/runtime/SharedArchiveFile/LimitSharedSizes.java
Index Unified diffs Context diffs Sdiffs Wdiffs Patch New Old Previous File Next File