54 } |
65 } |
55 AF1Offset = o1; |
66 AF1Offset = o1; |
56 AF2Offset = o2; |
67 AF2Offset = o2; |
57 } |
68 } |
58 |
69 |
59 public static int unsafeSnippet0(int i1, int i2) { |
70 public static int unsafeSnippet1(double i1) { |
60 A a = new A(); |
71 A a = new A(); |
61 UNSAFE.putDouble(a, AF1Offset, i1 + i2); |
72 UNSAFE.putDouble(a, AF1Offset, i1); |
62 return UNSAFE.getInt(a, AF1Offset) + UNSAFE.getInt(a, AF2Offset); |
73 return UNSAFE.getInt(a, AF1Offset) + UNSAFE.getInt(a, AF2Offset); |
63 } |
74 } |
64 |
75 |
65 public static int unsafeSnippet1(int i1, int i2) { |
76 public static long unsafeSnippet2a(int i1) { |
66 A a = new A(); |
77 A a = new A(); |
67 UNSAFE.putDouble(a, AF1Offset, i1 + i2); |
78 UNSAFE.putDouble(a, AF1Offset, i1); |
|
79 a.f1 = i1; |
|
80 return UNSAFE.getLong(a, AF1Offset); |
|
81 } |
|
82 |
|
83 public static long unsafeSnippet2b(int i1) { |
|
84 A a = new A(); |
|
85 UNSAFE.putDouble(a, AF1Offset, i1); |
68 a.f2 = i1; |
86 a.f2 = i1; |
69 return (int) UNSAFE.getDouble(a, AF1Offset); |
87 return UNSAFE.getLong(a, AF1Offset); |
|
88 } |
|
89 |
|
90 public static long unsafeSnippet3a(int i1) { |
|
91 A a = new A(); |
|
92 UNSAFE.putDouble(a, AF1Offset, i1); |
|
93 UNSAFE.putInt(a, AF1Offset, i1); |
|
94 return UNSAFE.getLong(a, AF1Offset); |
|
95 } |
|
96 |
|
97 public static long unsafeSnippet3b(int i1) { |
|
98 A a = new A(); |
|
99 UNSAFE.putDouble(a, AF1Offset, i1); |
|
100 UNSAFE.putInt(a, AF2Offset, i1); |
|
101 return UNSAFE.getLong(a, AF1Offset); |
|
102 } |
|
103 |
|
104 public static int unsafeSnippet4(double i1) { |
|
105 A a = new A(); |
|
106 UNSAFE.putDouble(a, AF1Offset, i1); |
|
107 UNSAFE.putDouble(a, AF1Offset, i1); |
|
108 return UNSAFE.getInt(a, AF1Offset) + UNSAFE.getInt(a, AF2Offset); |
70 } |
109 } |
71 |
110 |
72 @Test |
111 @Test |
73 public void testUnsafePEA01() { |
112 public void testUnsafePEA01() { |
74 testPartialEscapeReadElimination(parseEager("unsafeSnippet0", AllowAssumptions.NO), false); |
113 testPartialEscapeReadElimination("unsafeSnippet1", false, 1.0); |
75 testPartialEscapeReadElimination(parseEager("unsafeSnippet0", AllowAssumptions.NO), true); |
114 testPartialEscapeReadElimination("unsafeSnippet1", true, 1.0); |
76 } |
115 } |
77 |
116 |
78 @Test |
117 @Test |
79 public void testUnsafePEA02() { |
118 public void testUnsafePEA02() { |
80 testPartialEscapeReadElimination(parseEager("unsafeSnippet1", AllowAssumptions.NO), false); |
119 testPartialEscapeReadElimination("unsafeSnippet2a", false, 1); |
81 testPartialEscapeReadElimination(parseEager("unsafeSnippet1", AllowAssumptions.NO), true); |
120 testPartialEscapeReadElimination("unsafeSnippet2a", true, 1); |
|
121 |
|
122 testPartialEscapeReadElimination("unsafeSnippet2b", false, 1); |
|
123 testPartialEscapeReadElimination("unsafeSnippet2b", true, 1); |
82 } |
124 } |
83 |
125 |
84 public void testPartialEscapeReadElimination(StructuredGraph graph, boolean canonicalizeBefore) { |
126 @Test |
|
127 public void testUnsafePEA03() { |
|
128 testPartialEscapeReadElimination("unsafeSnippet3a", false, 1); |
|
129 testPartialEscapeReadElimination("unsafeSnippet3a", true, 1); |
|
130 |
|
131 testPartialEscapeReadElimination("unsafeSnippet3b", false, 1); |
|
132 testPartialEscapeReadElimination("unsafeSnippet3b", true, 1); |
|
133 } |
|
134 |
|
135 @Test |
|
136 public void testUnsafePEA04() { |
|
137 testPartialEscapeReadElimination("unsafeSnippet4", false, 1.0); |
|
138 testPartialEscapeReadElimination("unsafeSnippet4", true, 1.0); |
|
139 } |
|
140 |
|
141 public void testPartialEscapeReadElimination(String snippet, boolean canonicalizeBefore, Object... args) { |
|
142 assert AF1Offset % 8 == 0 : "First of the two int-fields must be 8-byte aligned"; |
|
143 |
|
144 ResolvedJavaMethod method = getResolvedJavaMethod(snippet); |
|
145 StructuredGraph graph = parseEager(snippet, AllowAssumptions.NO); |
85 OptionValues options = graph.getOptions(); |
146 OptionValues options = graph.getOptions(); |
86 PhaseContext context = getDefaultHighTierContext(); |
147 PhaseContext context = getDefaultHighTierContext(); |
87 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
148 CanonicalizerPhase canonicalizer = new CanonicalizerPhase(); |
88 if (canonicalizeBefore) { |
149 if (canonicalizeBefore) { |
89 canonicalizer.apply(graph, context); |
150 canonicalizer.apply(graph, context); |
90 } |
151 } |
|
152 Result r = executeExpected(method, null, args); |
91 new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context); |
153 new PartialEscapePhase(true, true, canonicalizer, null, options).apply(graph, context); |
|
154 try { |
|
155 InstalledCode code = getCode(method, graph); |
|
156 Object result = code.executeVarargs(args); |
|
157 assertEquals(r, new Result(result, null)); |
|
158 } catch (Throwable e) { |
|
159 assertFalse(true, e.toString()); |
|
160 } |
92 } |
161 } |
93 |
|
94 } |
162 } |