Skip to content

Commit

Permalink
Debug build for GCUtil
Browse files Browse the repository at this point in the history
  • Loading branch information
LadyCailin committed Nov 5, 2019
1 parent a1a86eb commit 6f79faf
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion src/main/java/com/laytonsmith/PureUtilities/GCUtil.java
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.laytonsmith.PureUtilities.Common.StringUtils; import com.laytonsmith.PureUtilities.Common.StringUtils;
import java.lang.management.GarbageCollectorMXBean; import java.lang.management.GarbageCollectorMXBean;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import java.lang.management.RuntimeMXBean;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
Expand All @@ -20,7 +21,7 @@ public static void main(String[] args) {
BlockUntilGC(); BlockUntilGC();
} }


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 * This method calls System.gc, but it blocks until it detects that a garbage collection has run. This
Expand All @@ -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. * 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 * 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. * 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() { public static void BlockUntilGC() {
debug(() -> "Starting"); 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.");
return;
}
}
/* /*
There may be multiple garbage collectors on a system, for instance, old generations and new generations. 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 We want to ensure that at least one has run before moving on. There is one caveat, the Epsilon GC does
Expand Down

0 comments on commit 6f79faf

Please sign in to comment.