2007-07-15 19:03:02 -06:00
|
|
|
public class GC {
|
2007-06-20 19:37:43 -06:00
|
|
|
|
2007-06-22 17:17:13 -06:00
|
|
|
private static void small() {
|
2007-06-21 16:51:13 -06:00
|
|
|
for (int i = 0; i < 1024; ++i) {
|
|
|
|
byte[] a = new byte[4 * 1024];
|
|
|
|
}
|
2007-06-22 17:17:13 -06:00
|
|
|
}
|
2007-06-21 16:51:13 -06:00
|
|
|
|
2007-06-22 17:17:13 -06:00
|
|
|
private static void medium() {
|
2007-06-22 16:47:57 -06:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
2007-06-21 16:51:13 -06:00
|
|
|
Object[] array = new Object[32];
|
|
|
|
for (int j = 0; j < 32; ++j) {
|
|
|
|
array[j] = new byte[32 * 1024];
|
|
|
|
}
|
2007-06-21 12:35:24 -06:00
|
|
|
}
|
2007-06-22 17:17:13 -06:00
|
|
|
}
|
2007-06-22 16:47:57 -06:00
|
|
|
|
2007-06-22 17:17:13 -06:00
|
|
|
private static void large() {
|
2007-06-22 16:47:57 -06:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
byte[] a = new byte[16 * 1024 * 1024];
|
|
|
|
}
|
2007-10-27 19:54:30 -06:00
|
|
|
|
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
byte[] a = new byte[16 * 1024 * 1024];
|
|
|
|
for (int j = 0; j < 32; ++j) {
|
|
|
|
byte[] b = new byte[32 * 1024];
|
|
|
|
}
|
|
|
|
}
|
2007-06-20 19:37:43 -06:00
|
|
|
}
|
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
private static void stackMap1(boolean predicate) {
|
2008-01-06 12:20:30 -07:00
|
|
|
if (predicate) {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
System.gc();
|
2008-01-06 12:20:30 -07:00
|
|
|
}
|
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
private static void stackMap2(boolean predicate) {
|
2008-01-06 12:20:30 -07:00
|
|
|
if (predicate) {
|
|
|
|
int a = 42;
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
System.gc();
|
2008-01-06 12:20:30 -07:00
|
|
|
}
|
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
private static void stackMap3(boolean predicate) {
|
2008-01-07 14:32:41 -07:00
|
|
|
if (predicate) {
|
|
|
|
Object a = null;
|
|
|
|
} else {
|
|
|
|
int a = 42;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void stackMap4(boolean predicate) {
|
2008-01-06 12:20:30 -07:00
|
|
|
int i = 2;
|
|
|
|
if (predicate) {
|
|
|
|
Object a = null;
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
2008-01-07 09:01:35 -07:00
|
|
|
System.gc();
|
2008-01-06 12:20:30 -07:00
|
|
|
int a = 42;
|
|
|
|
-- i;
|
|
|
|
} while (i >= 0);
|
|
|
|
}
|
|
|
|
|
2008-01-07 14:32:41 -07:00
|
|
|
private static void noop() { }
|
|
|
|
|
|
|
|
private static void stackMap5(boolean predicate) {
|
|
|
|
if (predicate) {
|
|
|
|
noop();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (predicate) {
|
|
|
|
noop();
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
|
2008-03-05 14:44:17 -07:00
|
|
|
private static void stackMap6(boolean predicate) {
|
|
|
|
if (predicate) {
|
|
|
|
int a = 42;
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (predicate) {
|
|
|
|
noop();
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
noop();
|
|
|
|
System.gc();
|
|
|
|
}
|
|
|
|
|
2007-06-22 17:17:13 -06:00
|
|
|
public static void main(String[] args) {
|
2008-01-01 18:09:05 -07:00
|
|
|
Object[] array = new Object[1024 * 1024];
|
|
|
|
array[0] = new Object();
|
|
|
|
|
2007-12-23 11:48:22 -07:00
|
|
|
small();
|
2008-01-01 18:09:05 -07:00
|
|
|
|
|
|
|
array[1] = new Object();
|
|
|
|
|
2007-06-22 17:17:13 -06:00
|
|
|
medium();
|
2008-01-01 18:09:05 -07:00
|
|
|
|
|
|
|
array[2] = new Object();
|
|
|
|
|
2007-12-23 11:48:22 -07:00
|
|
|
large();
|
2008-01-01 18:09:05 -07:00
|
|
|
|
|
|
|
array[0].toString();
|
|
|
|
array[1].toString();
|
|
|
|
array[2].toString();
|
2008-01-06 12:20:30 -07:00
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
stackMap1(true);
|
|
|
|
stackMap1(false);
|
2008-01-06 12:20:30 -07:00
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
stackMap2(true);
|
|
|
|
stackMap2(false);
|
2008-01-06 12:20:30 -07:00
|
|
|
|
2008-01-07 09:01:35 -07:00
|
|
|
stackMap3(true);
|
|
|
|
stackMap3(false);
|
2008-01-07 14:32:41 -07:00
|
|
|
|
|
|
|
stackMap4(true);
|
|
|
|
stackMap4(false);
|
|
|
|
|
|
|
|
stackMap5(true);
|
|
|
|
stackMap5(false);
|
2008-03-05 14:44:17 -07:00
|
|
|
|
|
|
|
stackMap6(true);
|
|
|
|
stackMap6(false);
|
2007-06-22 17:17:13 -06:00
|
|
|
}
|
|
|
|
|
2007-06-20 19:37:43 -06:00
|
|
|
}
|