Moving the ref.get() check into own method so it is not on a stack when executing the garbage collector
1.1 --- a/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Tue Dec 09 08:33:22 2014 +0100
1.2 +++ b/json-tck/src/main/java/net/java/html/js/tests/GCBodyTest.java Tue Dec 09 10:06:48 2014 +0100
1.3 @@ -85,11 +85,15 @@
1.4 }
1.5
1.6 private static void assertGC(Reference<?> ref, String msg) throws InterruptedException {
1.7 - for (int i = 0; i < 25; i++) {
1.8 - if (ref.get() == null) {
1.9 - return;
1.10 + for (int i = 0; i < 100; i++) {
1.11 + if (isGone(ref)) return;
1.12 + long then = System.currentTimeMillis();
1.13 + int size = Bodies.gc(Math.pow(2.0, i));
1.14 + long took = System.currentTimeMillis() - then;
1.15 + if (took > 3000) {
1.16 + throw new InterruptedException(msg + " - giving up after " + took + " ms at size of " + size);
1.17 }
1.18 - int size = Bodies.gc(Math.pow(2.0, i));
1.19 +
1.20 try {
1.21 System.gc();
1.22 System.runFinalization();
1.23 @@ -99,6 +103,10 @@
1.24 }
1.25 throw new InterruptedException(msg);
1.26 }
1.27 +
1.28 + private static boolean isGone(Reference<?> ref) {
1.29 + return ref.get() == null;
1.30 + }
1.31
1.32 private static void assertNotGC(Reference<?> ref, String msg) throws InterruptedException {
1.33 for (int i = 0; i < 10; i++) {