Skip to content

Commit

Permalink
Print memory stats on OOM
Browse files Browse the repository at this point in the history
  • Loading branch information
crschnick committed May 9, 2024
1 parent 3bd9022 commit 423fd36
Showing 1 changed file with 5 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,11 @@ public final synchronized ArrayNode parse(String name, byte[] input, int start,

// Special case for out of memory
if (t instanceof OutOfMemoryError ooe) {
throw new ParseException("Not enough free RAM available to load file " + name + " with size " + (input.length / 1_000_000) + "Mb.", ooe);
long heapSize = Runtime.getRuntime().totalMemory();
long heapMaxSize = Runtime.getRuntime().maxMemory();
long heapFreeSize = Runtime.getRuntime().freeMemory();
var m = "" + (heapSize / 1_000_000) + "Mb / " + (heapMaxSize / 1_000_000) + "Mb (" + (heapFreeSize / 1_000_000) + "Mb free)";
throw new ParseException("Not enough free RAM available to load file " + name + " with size " + (input.length / 1_000_000) + "Mb. " + m, ooe);
}

throw new ParseException(t);
Expand Down

0 comments on commit 423fd36

Please sign in to comment.