Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(825)

Side by Side Diff: tests/language/allocation_sinking_vm_test.dart

Issue 23103010: Add issue numbers to language tests status files (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: Addressed comments Created 7 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | tests/language/deopt_hoisted_smi_check_vm_test.dart » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
2 // for details. All rights reserved. Use of this source code is governed by a
3 // BSD-style license that can be found in the LICENSE file.
4 // Test allocation sinking optimization.
5 // VMOptions=--optimization-counter-threshold=10 --no-use-osr
6
7 import 'package:expect/expect.dart';
8
9 class Point {
10 var x, y;
11
12 Point(this.x, this.y);
13
14 operator * (other) {
15 return x * other.x + y * other.y;
16 }
17 }
18
19 class C {
20 var p;
21 C(this.p);
22 }
23
24 class D {
25 var p;
26 D(this.p);
27 }
28
29 // Class that is used to capture materialized Point object with * operator.
30 class F {
31 var p;
32 var val;
33
34 F(this.p);
35
36 operator * (other) {
37 Expect.isTrue(other is Point);
38 Expect.equals(42.0, other.x);
39 Expect.equals(0.5, other.y);
40
41 if (val == null) {
42 val = other;
43 } else {
44 Expect.isTrue(identical(val, other));
45 }
46
47 return this.p * other;
48 }
49 }
50
51 test1(c, x, y) {
52 var a = new Point(x - 0.5, y + 0.5);
53 var b = new Point(x + 0.5, y + 0.8);
54 var d = new Point(c.p * a, c.p * b);
55 return d * d;
56 }
57
58 effects() {
59 // This function should not be inlinable.
60 try { } catch (e) { }
61 }
62
63 testForwardingThroughEffects(c, x, y) {
64 var a = new Point(x - 0.5, y + 0.5);
65 var b = new Point(x - 0.5, y - 0.8);
66 var d = new Point(c.p * a, c.p * b);
67 // Effects can't affect neither a, b, nor d because they do not escape.
68 effects();
69 effects();
70 return ((a == null) ? 0.0 : 0.1) + (d * d);
71 }
72
73 testIdentity(x) {
74 var y = new Point(42.0, 0.5);
75 var z = y;
76 return x * y + x * z;
77 }
78
79 class PointP<T> {
80 var x, y;
81
82 PointP(this.x, this.y);
83
84 operator * (other) {
85 return x * other.x + y * other.y;
86 }
87 }
88
89 foo2() => new PointP<int>(1, 3) * new PointP<num>(5, 6);
90
91 class A<T> {
92 var x, y;
93 }
94
95 foo3(x) {
96 // Test materialization of type arguments.
97 var a = new A<int>();
98 a.x = x;
99 a.y = x;
100 if (x is int) return a.x + a.y;
101 Expect.isFalse(a is A<double>);
102 Expect.isTrue(a is A<int>);
103 Expect.isTrue(a is A);
104 return a.x - a.y;
105 }
106
107 class WithFinal {
108 final _x;
109 WithFinal(this._x);
110 }
111
112 testInitialValueForFinalField(x) {
113 new WithFinal(x);
114 }
115
116 testFinalField() {
117 for (var i = 0; i < 100; i++) {
118 testInitialValueForFinalField(1);
119 }
120 }
121
122 class V {
123 var x = 0;
124 }
125
126 test_vm_field() {
127 var obj;
128 inner() => obj.x = 42;
129 var a = new V();
130 obj = a;
131 var t1 = a.x;
132 var t2 = inner();
133 return a.x + t1 + t2;
134 }
135
136 testVMField() {
137 Expect.equals(84, test_vm_field());
138 for (var i = 0; i < 100; i++) test_vm_field();
139 Expect.equals(84, test_vm_field());
140 }
141
142 main() {
143 var c = new C(new Point(0.1, 0.2));
144
145 // Compute initial values.
146 final x0 = test1(c, 11.11, 22.22);
147 final y0 = testForwardingThroughEffects(c, 11.11, 22.22);
148 final z0 = testIdentity(c.p);
149
150 // Force optimization.
151 for (var i = 0; i < 100; i++) {
152 test1(c, i.toDouble(), i.toDouble());
153 testForwardingThroughEffects(c, i.toDouble(), i.toDouble());
154 testIdentity(c.p);
155 foo2();
156 Expect.equals(10, foo3(5));
157 }
158 Expect.equals(0.0, foo3(0.5));
159
160 // Test returned value after optimization.
161 final x1 = test1(c, 11.11, 22.22);
162 final y1 = testForwardingThroughEffects(c, 11.11, 22.22);
163
164 // Test returned value after deopt.
165 final x2 = test1(new D(c.p), 11.11, 22.22);
166 final y2 = testForwardingThroughEffects(new D(c.p), 11.11, 22.22);
167
168 Expect.equals(6465, (x0 * 100).floor());
169 Expect.equals(6465, (x1 * 100).floor());
170 Expect.equals(6465, (x2 * 100).floor());
171 Expect.equals(x0, x1);
172 Expect.equals(x0, x2);
173
174 Expect.equals(6008, (y0 * 100).floor());
175 Expect.equals(6008, (y1 * 100).floor());
176 Expect.equals(6008, (y2 * 100).floor());
177 Expect.equals(y0, y1);
178 Expect.equals(y0, y2);
179
180 // Test that identity of materialized objects is preserved correctly and
181 // no copies are materialized.
182 final z1 = testIdentity(c.p);
183 final z2 = testIdentity(new F(c.p));
184 Expect.equals(z0, z1);
185 Expect.equals(z0, z2);
186
187 testFinalField();
188 testVMField();
189 }
OLDNEW
« no previous file with comments | « no previous file | tests/language/deopt_hoisted_smi_check_vm_test.dart » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698