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

Side by Side Diff: test/mjsunit/compiler/inline-accessors.js

Issue 10836133: Inline simple setter calls. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Made VisitReturnStatement and TryInline more similar. Simplified AddLeaveInlined. Created 8 years, 4 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
« src/hydrogen.cc ('K') | « src/x64/lithium-x64.cc ('k') | no next file » | 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 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are
4 // met:
5 //
6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission.
15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27
28 // Flags: --allow-natives-syntax --inline-accessors
29
30 var accessorCallCount, setterValue, obj;
31 function Constr1() { }
32 function Constr2() { }
33 function Constr3() { }
Michael Starzinger 2012/08/08 13:05:33 Can we move the constructors down, right before th
Sven Panne 2012/08/08 14:15:20 Done.
34
35 // -----------------------------------------------------------------------------
36 // Helpers for testing inlining of getters.
37
38 function TestInlinedGetter(context) {
39 accessorCallCount = 0;
40
41 assertEquals(1234, context());
42 assertEquals(1, accessorCallCount);
43
44 assertEquals(1234, context());
45 assertEquals(2, accessorCallCount);
46
47 %OptimizeFunctionOnNextCall(context);
48 assertEquals(1234, context());
49 assertEquals(3, accessorCallCount);
50
51 %DeoptimizeFunction(context);
52 %ClearFunctionTypeFeedback(context);
53 }
54
55
56 function TestGetterInAllContexts(obj) {
57 function value_context() {
58 return obj.getterProperty;
59 }
60 TestInlinedGetter(value_context);
61
62 function test_context() {
63 if (!obj.getterProperty) {
64 assertUnreachable("should not happen");
65 }
66 return 1234;
67 }
68 TestInlinedGetter(test_context);
69
70 function effect_context() {
71 obj.getterProperty;
72 return 1234;
73 }
74 TestInlinedGetter(effect_context);
75 }
76
77 // -----------------------------------------------------------------------------
78 // Test getter in all contexts.
79 function getter1() {
80 accessorCallCount++;
81 return 1234;
Michael Starzinger 2012/08/08 13:05:33 You might want to consider returning a global "get
Sven Panne 2012/08/08 14:15:20 As discussed offline, this will be done via an exp
82 }
83
84 obj = Object.defineProperty(new Constr1(), "getterProperty", { get: getter1 });
85 TestGetterInAllContexts(obj);
86 TestGetterInAllContexts(Object.create(obj));
Michael Starzinger 2012/08/08 13:05:33 Also test a getter that falls off the function end
Sven Panne 2012/08/08 14:15:20 Done.
87
88 // -----------------------------------------------------------------------------
89 // Helpers for testing inlining of setters.
90
91 function TestInlinedSetter(context) {
92 accessorCallCount = 0;
93
94 assertEquals(112, context(111));
95 assertEquals(114, setterValue);
96 assertEquals(1, accessorCallCount);
97
98 assertEquals(223, context(222));
99 assertEquals(225, setterValue);
100 assertEquals(2, accessorCallCount);
101
102 %OptimizeFunctionOnNextCall(context);
103 assertEquals(334, context(333));
104 assertEquals(336, setterValue);
105 assertEquals(3, accessorCallCount);
106
107 %DeoptimizeFunction(context);
108 %ClearFunctionTypeFeedback(context);
109 }
110
111 function TestSetterInAllContexts(obj) {
112 function value_context(value) {
113 return obj.setterProperty = value + 1;
Michael Starzinger 2012/08/08 13:05:33 I wouldn't use an addition on the RHS, otherwise i
Sven Panne 2012/08/08 14:15:20 Done.
114 }
115 TestInlinedSetter(value_context);
116
117 function test_context(value) {
118 if (!(obj.setterProperty = value + 1)) {
119 assertUnreachable("should not happen");
120 }
121 return value + 1;
122 }
123 TestInlinedSetter(test_context);
124
125 function effect_context(value) {
126 obj.setterProperty = value + 1;
127 return value + 1;
128 }
129 TestInlinedSetter(effect_context);
130 }
131
132 // -----------------------------------------------------------------------------
133 // Test setter returning nothing in all contexts.
134 function setter1(value) {
135 accessorCallCount++;
136 setterValue = value + 2;
137 }
138
139 obj = Object.defineProperty(new Constr2(), "setterProperty", { set: setter1 });
140 TestSetterInAllContexts(obj);
141 TestSetterInAllContexts(Object.create(obj));
142
143 // -----------------------------------------------------------------------------
144 // Test setter returning something different than the RHS in all contexts.
145 function setter2(value) {
146 accessorCallCount++;
147 setterValue = value + 2;
148 return value + 1000000;
149 }
150
151 obj = Object.defineProperty(new Constr3(), "setterProperty", { set: setter2 });
152 TestSetterInAllContexts(obj);
153 TestSetterInAllContexts(Object.create(obj));
Michael Starzinger 2012/08/08 13:05:33 We also need tests for arguments mismatch of both
Sven Panne 2012/08/08 14:15:20 Still a TODO...
OLDNEW
« src/hydrogen.cc ('K') | « src/x64/lithium-x64.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698