// Test that GC sees pointers inside static fields class Test1 { public static void main(String[] args) throws RegionInUse { int total = 0; int iters = Integer.parseInt(args[0]); // Allocate a GC list accessible only via a static field Holder.init(10, 22); // Allocate lots of memory (force a few gcs) for (int n = iters; n > 0; n--) for (int i = 0; i < 10; i++) new IList(77, null); // Should print 220 System.out.println("" + Holder.l.sum()); } } class Holder { static IList l; static void init(int n, int m) { for (int i = 0; i < n; i++) l = new IList(m, l); } } class IList { private IList cdr; private int car; IList(int pcar, IList pcdr) { cdr = pcdr; car = pcar; } int car() { return car; } IList cdr() { return cdr; } int sum() { return car + (cdr != null ? cdr.sum() : 0); } }