-
Notifications
You must be signed in to change notification settings - Fork 0
/
mytest1800012748.java
69 lines (62 loc) · 1.19 KB
/
mytest1800012748.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
package test;
import benchmark.internal.BenchmarkN;
import benchmark.objects.A;
import benchmark.objects.B;
public class VirtualRecursive {
interface I {
I getField();
void setField(I x, I y);
}
static class IA1 implements I {
I fA1;
IA1() {
this.fA1 = null;
}
IA1(I fA1) {
this.fA1 = fA1;
}
public void setField(I x, I y) {
fA1 = f(x, y);
}
public I getField() {
return fA1;
}
};
static class IA2 implements I {
I fA2;
IA2() {
this.fA2 = null;
}
IA2(I fA2) {
this.fA2 = fA2;
}
public void setField(I x, I y) {
fA2 = g(x, y);
}
public I getField() {
return fA2;
}
}
static <T> T f(T x, T y) {
return x;
}
static <T> T g(T x, T y) {
return y;
}
public static void main(String[] args) {
BenchmarkN.alloc(1);
I a = new IA1();
BenchmarkN.alloc(2);
I b = new IA2(a);
I f = b.getField();
BenchmarkN.test(1, f); // 1: 1
BenchmarkN.alloc(3);
I c = new IA2(a);
a.setField(c, b);
I fa = f.getField();
BenchmarkN.test(2, fa); // 2: 3
I d = c.getField().getField();
d.setField(a, b);
I fb = fa.getField();
}
}