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

Side by Side Diff: test/mjsunit/compiler/inlined-call.js

Issue 335683002: Optimize Function.prototype.call (Closed) Base URL: https://github.com/v8/v8.git@master
Patch Set: Call the correct functions Created 6 years, 6 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
« no previous file with comments | « src/objects.h ('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 2014 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 --noalways-opt
29
30 var array = [];
31 for (var i = 0; i < 100; ++i) {
32 array[i] = i;
33 }
34
35 var copy = array.slice();
36
37 function unshiftsArray(num) {
38 [].unshift.call(array, num);
39 }
40
41 unshiftsArray(50);
42 unshiftsArray(60);
43 %OptimizeFunctionOnNextCall(unshiftsArray);
44 unshiftsArray(80);
45 unshiftsArray(50);
46 unshiftsArray(60);
47
48 copy.unshift(50);
49 copy.unshift(60);
50 copy.unshift(80);
51 copy.unshift(50);
52 copy.unshift(60);
53
54 assertOptimized(unshiftsArray);
55 assertArrayEquals(array, copy);
56
57
58 var called = 0;
59 var funRecv;
60 // For the HConstant
61 Array.prototype.fun = function() {
62 funRecv = this;
63 called++;
64 assertEquals(0, arguments.length);
65 };
66
67 function callNoArgs() {
68 [].fun.call();
69 }
70
71 callNoArgs();
72 callNoArgs();
73 assertEquals(this, funRecv);
74 %OptimizeFunctionOnNextCall(callNoArgs);
75 callNoArgs();
76 assertEquals(this, funRecv);
77 assertEquals(3, called);
78 assertOptimized(callNoArgs);
79
80 var funStrictRecv;
81 called = 0;
82 Array.prototype.funStrict = function() {
83 "use strict";
84 funStrictRecv = this;
85 called++;
86 assertEquals(0, arguments.length);
87 };
88
89 function callStrictNoArgs() {
90 [].funStrict.call();
91 }
92
93 callStrictNoArgs();
94 callStrictNoArgs();
95 assertEquals(undefined, funStrictRecv);
96 %OptimizeFunctionOnNextCall(callStrictNoArgs);
97 callStrictNoArgs();
98 assertEquals(undefined, funStrictRecv);
99 assertEquals(3, called);
100 assertOptimized(callStrictNoArgs);
101
102 called = 0;
103 Array.prototype.manyArgs = function() {
104 "use strict";
105 assertEquals(5, arguments.length);
106 assertEquals(0, this);
107 assertEquals(5, arguments[4]);
108 called++;
109 }
110
111 function callManyArgs() {
112 [].manyArgs.call(0, 1, 2, 3, 4, 5);
113 }
114
115 callManyArgs();
116 callManyArgs();
117 %OptimizeFunctionOnNextCall(callManyArgs);
118 callManyArgs();
119 assertOptimized(callManyArgs);
120 assertEquals(called, 3);
121
122 called = 0;
123 Array.prototype.manyArgsSloppy = function() {
124 assertTrue(this instanceof Number);
125 assertEquals(5, arguments.length);
126 assertEquals(0, this.valueOf());
127 assertEquals(5, arguments[4]);
128 called++;
129 }
130
131 function callManyArgsSloppy() {
132 [].manyArgsSloppy.call(0, 1, 2, 3, 4, 5);
133 }
134
135 callManyArgsSloppy();
136 callManyArgsSloppy();
137 %OptimizeFunctionOnNextCall(callManyArgsSloppy);
138 callManyArgsSloppy();
139 assertOptimized(callManyArgsSloppy);
140 assertEquals(called, 3);
141
142 var str = "hello";
143 var code = str.charCodeAt(3);
144 called = 0;
145 function callBuiltinIndirectly() {
146 called++;
147 return "".charCodeAt.call(str, 3);
148 }
149
150 callBuiltinIndirectly();
151 callBuiltinIndirectly();
152 %OptimizeFunctionOnNextCall(callBuiltinIndirectly);
153 assertEquals(code, callBuiltinIndirectly());
154 assertOptimized(callBuiltinIndirectly);
155 assertEquals(3, called);
156
157 this.array = [1,2,3,4,5,6,7,8,9];
158 var copy = this.array.slice();
159 called = 0;
160
161 function callInlineableBuiltinIndirectlyWhileInlined() {
162 called++;
163 return [].push.apply(array, arguments);
164 }
165
166 function callInlined(num) {
167 return callInlineableBuiltinIndirectlyWhileInlined(num);
168 }
169
170 callInlined(1);
171 callInlined(2);
172 %OptimizeFunctionOnNextCall(callInlineableBuiltinIndirectlyWhileInlined);
173 %OptimizeFunctionOnNextCall(callInlined);
174 callInlined(3);
175 copy.push(1, 2, 3);
176 assertOptimized(callInlined);
177 assertOptimized(callInlineableBuiltinIndirectlyWhileInlined);
178 assertArrayEquals(copy, this.array);
179 assertEquals(3, called);
OLDNEW
« no previous file with comments | « src/objects.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698