forked from evanj/mmap-pause
-
Notifications
You must be signed in to change notification settings - Fork 0
/
MakeGarbage.java
38 lines (32 loc) · 1.23 KB
/
MakeGarbage.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
/*
javac MakeGarbage.java
java -XX:+PrintGCDetails -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -Xmx1G -Xms1G MakeGarbage
Disabled stats:
java -XX:+PrintGCDetails -XX:+PrintGC -XX:+PrintGCDateStamps -XX:+PrintGCApplicationStoppedTime -Xmx1G -Xms1G -XX:+PerfDisableSharedMem MakeGarbage &> /mnt/ej/java-no-mmap-stats.txt
This flag no longer works as of recent versions of Java: -Djava.io.tmpdir=/dev/shm
See:
http://bugs.java.com/view_bug.do?bug_id=6938627
http://bugs.java.com/view_bug.do?bug_id=7009828
Stats location is hard coded to /tmp on Linux:
http://hg.openjdk.java.net/jdk9/client/hotspot/file/c3b117fa5bde/src/os/linux/vm/os_linux.cpp#l1582
*/
public class MakeGarbage {
public static void main(String[] args) throws Exception {
final int ARRAY_SIZE = 4 << 20;
final int LOOPS = 200_000;
int sum = 0;
long start = System.currentTimeMillis();
while (true) {
for (int i = 0; i < LOOPS; i++) {
byte[] array = new byte[ARRAY_SIZE];
sum += array[0] + array.length;
}
System.out.println("hello " + sum);
if (args.length > 0) {
if (Integer.parseInt(args[0]) * 60_000L < (System.currentTimeMillis() - start)) {
break;
}
}
}
}
}