Skip to content

Commit 892d08e

Browse files
committed
Increased memory to 4G for the test and add diagnostic info for OOME
1 parent bbcb213 commit 892d08e

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

src/java.base/share/classes/java/util/HexFormat.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ private String formatOptDelimiter(byte[] bytes, int fromIndex, int toIndex) {
474474
private static int checkMaxArraySize(long length) {
475475
if (length > Integer.MAX_VALUE)
476476
throw new OutOfMemoryError("String size " + length +
477-
" exceeds maximum " + (Integer.MAX_VALUE));
477+
" exceeds maximum " + Integer.MAX_VALUE);
478478
return (int)length;
479479
}
480480

test/jdk/java/util/HexFormat/HexFormatTest.java

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@
4242
/*
4343
* @test
4444
* @summary Check HexFormat formatting and parsing
45-
* @run testng/othervm HexFormatTest
45+
* @run testng/othervm -Xmx4G HexFormatTest
4646
*/
4747

4848
@Test
@@ -633,11 +633,21 @@ static void testOOME(String delimiter, String prefix, String suffix, boolean upp
633633
long remainder = max - ((len - 1) * stride);
634634
if (remainder > valueChars) {
635635
len++;
636+
remainder -= valueChars;
636637
}
637-
byte[] bytes = new byte[(int)len];
638-
Throwable ex = expectThrows(OutOfMemoryError.class,
639-
() -> hex.formatHex(bytes));
640-
System.out.println("ex: " + ex);
638+
try {
639+
byte[] bytes = new byte[(int) len];
640+
Throwable ex = expectThrows(OutOfMemoryError.class,
641+
() -> hex.formatHex(bytes));
642+
System.out.println("ex: " + ex);
643+
} catch (OutOfMemoryError oome) {
644+
System.out.printf("OOME: total mem: %08x, free mem: %08x, max mem: %08x%n",
645+
Runtime.getRuntime().totalMemory(),
646+
Runtime.getRuntime().freeMemory(),
647+
Runtime.getRuntime().maxMemory());
648+
throw oome;
649+
}
650+
641651
}
642652

643653
/**

0 commit comments

Comments
 (0)