40 } |
40 } |
41 } |
41 } |
42 |
42 |
43 class TestUseCompressedOopsErgoTools { |
43 class TestUseCompressedOopsErgoTools { |
44 |
44 |
45 private static long getClassMetaspaceSize() { |
45 private static long getCompressedClassSpaceSize() { |
46 HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); |
46 HotSpotDiagnosticMXBean diagnostic = ManagementFactoryHelper.getDiagnosticMXBean(); |
47 |
47 |
48 VMOption option = diagnostic.getVMOption("ClassMetaspaceSize"); |
48 VMOption option = diagnostic.getVMOption("CompressedClassSpaceSize"); |
49 return Long.parseLong(option.getValue()); |
49 return Long.parseLong(option.getValue()); |
50 } |
50 } |
51 |
51 |
52 |
52 |
53 public static long getMaxHeapForCompressedOops(String[] vmargs) throws Exception { |
53 public static long getMaxHeapForCompressedOops(String[] vmargs) throws Exception { |
130 |
130 |
131 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops, true); |
131 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops, true); |
132 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops - 1, true); |
132 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops - 1, true); |
133 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops + 1, false); |
133 checkUseCompressedOops(join(gcflags, "-XX:ObjectAlignmentInBytes=16"), maxHeapForCompressedOops + 1, false); |
134 |
134 |
135 // use a different ClassMetaspaceSize |
135 // use a different CompressedClassSpaceSize |
136 String classMetaspaceSizeArg = "-XX:ClassMetaspaceSize=" + 2 * getClassMetaspaceSize(); |
136 String compressedClassSpaceSizeArg = "-XX:CompressedClassSpaceSize=" + 2 * getCompressedClassSpaceSize(); |
137 maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, classMetaspaceSizeArg)); |
137 maxHeapForCompressedOops = getMaxHeapForCompressedOops(join(gcflags, compressedClassSpaceSizeArg)); |
138 |
138 |
139 checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops, true); |
139 checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops, true); |
140 checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops - 1, true); |
140 checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops - 1, true); |
141 checkUseCompressedOops(join(gcflags, classMetaspaceSizeArg), maxHeapForCompressedOops + 1, false); |
141 checkUseCompressedOops(join(gcflags, compressedClassSpaceSizeArg), maxHeapForCompressedOops + 1, false); |
142 } |
142 } |
143 |
143 |
144 private static void checkUseCompressedOops(String[] args, long heapsize, boolean expectUseCompressedOops) throws Exception { |
144 private static void checkUseCompressedOops(String[] args, long heapsize, boolean expectUseCompressedOops) throws Exception { |
145 ArrayList<String> finalargs = new ArrayList<String>(); |
145 ArrayList<String> finalargs = new ArrayList<String>(); |
146 finalargs.addAll(Arrays.asList(args)); |
146 finalargs.addAll(Arrays.asList(args)); |
150 |
150 |
151 String output = expectValid(finalargs.toArray(new String[0])); |
151 String output = expectValid(finalargs.toArray(new String[0])); |
152 |
152 |
153 boolean actualUseCompressedOops = getFlagBoolValue(" UseCompressedOops", output); |
153 boolean actualUseCompressedOops = getFlagBoolValue(" UseCompressedOops", output); |
154 |
154 |
155 if (expectUseCompressedOops != actualUseCompressedOops) { |
155 Asserts.assertEQ(expectUseCompressedOops, actualUseCompressedOops); |
156 throw new RuntimeException("Expected use of compressed oops: " + expectUseCompressedOops + " but was: " + actualUseCompressedOops); |
|
157 } |
|
158 } |
156 } |
159 |
157 |
160 private static boolean getFlagBoolValue(String flag, String where) { |
158 private static boolean getFlagBoolValue(String flag, String where) { |
161 Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where); |
159 Matcher m = Pattern.compile(flag + "\\s+:?= (true|false)").matcher(where); |
162 if (!m.find()) { |
160 if (!m.find()) { |
163 throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
161 throw new RuntimeException("Could not find value for flag " + flag + " in output string"); |
164 } |
162 } |
165 String match = m.group(1).equals("true"); |
163 return m.group(1).equals("true"); |
166 } |
164 } |
167 |
165 |
168 private static String expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { |
166 private static String expect(String[] flags, boolean hasWarning, boolean hasError, int errorcode) throws Exception { |
169 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); |
167 ProcessBuilder pb = ProcessTools.createJavaProcessBuilder(flags); |
170 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |
168 OutputAnalyzer output = new OutputAnalyzer(pb.start()); |