2007-07-16 01:03:02 +00:00
|
|
|
public class GC {
|
2007-06-21 01:37:43 +00:00
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
private static void small() {
|
2007-06-21 22:51:13 +00:00
|
|
|
for (int i = 0; i < 1024; ++i) {
|
|
|
|
byte[] a = new byte[4 * 1024];
|
|
|
|
}
|
2007-06-22 23:17:13 +00:00
|
|
|
}
|
2007-06-21 22:51:13 +00:00
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
private static void medium() {
|
2007-06-22 22:47:57 +00:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
2007-06-21 22:51:13 +00:00
|
|
|
Object[] array = new Object[32];
|
|
|
|
for (int j = 0; j < 32; ++j) {
|
|
|
|
array[j] = new byte[32 * 1024];
|
|
|
|
}
|
2007-06-21 18:35:24 +00:00
|
|
|
}
|
2007-06-22 23:17:13 +00:00
|
|
|
}
|
2007-06-22 22:47:57 +00:00
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
private static void large() {
|
2007-06-22 22:47:57 +00:00
|
|
|
for (int i = 0; i < 8; ++i) {
|
|
|
|
byte[] a = new byte[16 * 1024 * 1024];
|
|
|
|
}
|
2007-10-28 01:54:30 +00: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-21 01:37:43 +00:00
|
|
|
}
|
|
|
|
|
2008-01-06 19:20:30 +00:00
|
|
|
private static void lifetime1(boolean predicate) {
|
|
|
|
if (predicate) {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
small();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void lifetime2(boolean predicate) {
|
|
|
|
if (predicate) {
|
|
|
|
int a = 42;
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
small();
|
|
|
|
}
|
|
|
|
|
|
|
|
private static void lifetime3(boolean predicate) {
|
|
|
|
int i = 2;
|
|
|
|
if (predicate) {
|
|
|
|
Object a = null;
|
|
|
|
} else {
|
|
|
|
Object a = null;
|
|
|
|
}
|
|
|
|
|
|
|
|
do {
|
|
|
|
small();
|
|
|
|
int a = 42;
|
|
|
|
-- i;
|
|
|
|
} while (i >= 0);
|
|
|
|
}
|
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
public static void main(String[] args) {
|
2008-01-02 01:09:05 +00:00
|
|
|
Object[] array = new Object[1024 * 1024];
|
|
|
|
array[0] = new Object();
|
|
|
|
|
2007-12-23 18:48:22 +00:00
|
|
|
small();
|
2008-01-02 01:09:05 +00:00
|
|
|
|
|
|
|
array[1] = new Object();
|
|
|
|
|
2007-06-22 23:17:13 +00:00
|
|
|
medium();
|
2008-01-02 01:09:05 +00:00
|
|
|
|
|
|
|
array[2] = new Object();
|
|
|
|
|
2007-12-23 18:48:22 +00:00
|
|
|
large();
|
2008-01-02 01:09:05 +00:00
|
|
|
|
|
|
|
array[0].toString();
|
|
|
|
array[1].toString();
|
|
|
|
array[2].toString();
|
2008-01-06 19:20:30 +00:00
|
|
|
|
|
|
|
lifetime1(true);
|
|
|
|
lifetime1(false);
|
|
|
|
|
|
|
|
lifetime2(true);
|
|
|
|
lifetime2(false);
|
|
|
|
|
|
|
|
lifetime3(true);
|
|
|
|
lifetime3(false);
|
2007-06-22 23:17:13 +00:00
|
|
|
}
|
|
|
|
|
2007-06-21 01:37:43 +00:00
|
|
|
}
|