-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFSTGCMark.java
150 lines (141 loc) · 5.36 KB
/
FSTGCMark.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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
import java.util.HashMap;
import java.util.Random;
import java.awt.Dimension;
public class FSTGCMark {
static class UseLessWrapper {
Object wrapped;
UseLessWrapper(Object wrapped) {
this.wrapped = wrapped;
}
}
static HashMap map = new HashMap();
static int hmFillRange = 5000000;//1000000 * 30; //
static int mutatingRange = 200000;//2000000; //
static int operationStep = 1000;
int operCount;
int milliDelayCount[] = new int[100];
int hundredMilliDelayCount[] = new int[100];
int secondDelayCount[] = new int[100];
Random rand = new Random(1000);
int stepCount = 0;
public void operateStep() {
stepCount++;
if ( stepCount%100 == 0 ) {
// enforce some tenuring
for ( int i = 0; i < operationStep; i++) {
int key = (int) (rand.nextDouble() * mutatingRange)+mutatingRange;
map.put(key, new UseLessWrapper(new UseLessWrapper(""+stepCount)));
}
}
if ( stepCount%200 == 199 ) {
// enforce some tenuring
for ( int i = 0; i < operationStep; i++) {
int key = (int) (rand.nextDouble() * mutatingRange)+mutatingRange*2;
map.put(key, new UseLessWrapper(new UseLessWrapper("a"+stepCount)));
}
}
if ( stepCount%400 == 299 ) {
// enforce some tenuring
for ( int i = 0; i < operationStep; i++) {
int key = (int) (rand.nextDouble() * mutatingRange)+mutatingRange*3;
map.put(key, new UseLessWrapper(new UseLessWrapper("a"+stepCount)));
}
}
if ( stepCount%1000 == 999 ) {
// enforce some tenuring
for ( int i = 0; i < operationStep; i++) {
int key = (int) (rand.nextDouble() * hmFillRange);
map.put(key, new UseLessWrapper(new UseLessWrapper("a"+stepCount)));
}
}
for ( int i = 0; i < operationStep/2; i++) {
int key = (int) (rand.nextDouble() * mutatingRange);
map.put(key, new UseLessWrapper(new Dimension(key,key)));
}
for ( int i = 0; i < operationStep/8; i++) {
int key = (int) (rand.nextDouble() * mutatingRange);
map.put(key, new UseLessWrapper(new UseLessWrapper(new UseLessWrapper(new UseLessWrapper(new UseLessWrapper("pok"+i))))));
}
for ( int i = 0; i < operationStep/16; i++) {
int key = (int) (rand.nextDouble() * mutatingRange);
map.put(key, new UseLessWrapper(new int[50]));
}
for ( int i = 0; i < operationStep/32; i++) {
int key = (int) (rand.nextDouble() * mutatingRange);
map.put(key, ""+new UseLessWrapper(new int[100]));
}
for ( int i = 0; i < operationStep/32; i++) {
int key = (int) (rand.nextDouble() * mutatingRange);
Object[] wrapped = new Object[100];
for (int j = 0; j < wrapped.length; j++) {
wrapped[j] = ""+j;
}
map.put(key, new UseLessWrapper(wrapped));
}
for ( int i = 0; i < operationStep/64; i++) {
int key = (int) (rand.nextDouble() * mutatingRange /64);
map.put(key, new UseLessWrapper(new int[1000]));
}
for ( int i = 0; i < 4; i++) {
int key = (int) (rand.nextDouble() * 16);
map.put(key, new UseLessWrapper(new byte[1000000]));
}
}
public void fillMap() {
for ( int i = 0; i < hmFillRange; i++) {
map.put(i, new UseLessWrapper(new UseLessWrapper(""+i)));
}
}
public void run() {
fillMap();
System.gc();
System.out.println("static alloc " + (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1000 / 1000 + "mb");
long time = System.currentTimeMillis();
int count = 0;
while ( (System.currentTimeMillis()-time) < runtime) {
count++;
long tim = System.currentTimeMillis();
operateStep();
int dur = (int) (System.currentTimeMillis()-tim);
if ( dur < 100 )
milliDelayCount[dur]++;
else if ( dur < 10*100 )
hundredMilliDelayCount[dur/100]++;
else {
secondDelayCount[dur/1000]++;
}
}
System.out.println("Iterations "+count);
}
public void dumpResult() {
for (int i = 0; i < milliDelayCount.length; i++) {
int i1 = milliDelayCount[i];
milliDelayCount[i] = 0;
if ( i1 > 0 ) {
System.out.println("["+i+"]\t"+i1);
}
}
for (int i = 0; i < hundredMilliDelayCount.length; i++) {
int i1 = hundredMilliDelayCount[i];
hundredMilliDelayCount[i] = 0;
if ( i1 > 0 ) {
System.out.println("["+i*100+"]\t"+i1);
}
}
for (int i = 0; i < secondDelayCount.length; i++) {
int i1 = secondDelayCount[i];
secondDelayCount[i] = 0;
if ( i1 > 0 ) {
System.out.println("["+i*1000+"]\t"+i1);
}
}
}
int runtime = 60000 * 5;
public static void main( String arg[] ) {
FSTGCMark fstgcMark = new FSTGCMark();
for (int i = 0; i < 2; i++) {
fstgcMark.run();
fstgcMark.dumpResult();
}
}
}