Skip to content
Browse files
Debug build for GCUtil
  • Loading branch information
LadyCailin committed Nov 5, 2019
1 parent a1a86eb commit 6f79faf29c1c039009452f6bb164e89b3ec0e173
Showing with 14 additions and 1 deletion.
  1. +14 −1 src/main/java/com/laytonsmith/PureUtilities/
@@ -3,6 +3,7 @@
import com.laytonsmith.PureUtilities.Common.StringUtils;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -20,7 +21,7 @@ public static void main(String[] args) {

private static boolean debug = false;
private static boolean debug = true;

* This method calls System.gc, but it blocks until it detects that a garbage collection has run. This
@@ -30,9 +31,21 @@ public static void main(String[] args) {
* to out of memory error. So if that garbage collector is the only one, then we just throw without blocking.
* In such a situation, since no garbage collection will ever occur anyways, whatever was trying to be
* accomplished by calling this method will never happen anyways.
* <p>
* If -XX:+DisableExplicitGC was specified on the command line, this function respects that, and silently returns
* (otherwise we would block for quite some time waiting for a natural garbage collection to happen).
public static void BlockUntilGC() {
debug(() -> "Starting");

RuntimeMXBean runtimeMxBean = ManagementFactory.getRuntimeMXBean();
List<String> arguments = runtimeMxBean.getInputArguments();
for(String arg : arguments) {
if(arg.matches("(?i)\\+DisableExplicitGC")) {
debug(() -> "Found +DisableExplicitGC, returning with no action.");
There may be multiple garbage collectors on a system, for instance, old generations and new generations.
We want to ensure that at least one has run before moving on. There is one caveat, the Epsilon GC does

0 comments on commit 6f79faf

Please sign in to comment.