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

Side by Side Diff: test/mjsunit/string-slices.js

Issue 7833033: Promote and inflate string slices during scavenging GC. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 9 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 | « test/cctest/test-strings.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
1 // Copyright 2008 the V8 project authors. All rights reserved. 1 // Copyright 2008 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
11 // with the distribution. 11 // with the distribution.
12 // * Neither the name of Google Inc. nor the names of its 12 // * Neither the name of Google Inc. nor the names of its
13 // contributors may be used to endorse or promote products derived 13 // contributors may be used to endorse or promote products derived
14 // from this software without specific prior written permission. 14 // from this software without specific prior written permission.
15 // 15 //
16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 16 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 17 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 18 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 19 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 20 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 21 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 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. 26 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 27
28 // Flags: --string-slices --expose-externalize-string 28 // Flags: --string-slices --expose-externalize-string --expose-gc
29 29
30 var s = 'abcdefghijklmn'; 30 var s = 'abcdefghijklmn';
31 assertEquals(s, s.substr()); 31 assertEquals(s, s.substr());
32 assertEquals(s, s.substr(0)); 32 assertEquals(s, s.substr(0));
33 assertEquals(s, s.substr('0')); 33 assertEquals(s, s.substr('0'));
34 assertEquals(s, s.substr(void 0)); 34 assertEquals(s, s.substr(void 0));
35 assertEquals(s, s.substr(null)); 35 assertEquals(s, s.substr(null));
36 assertEquals(s, s.substr(false)); 36 assertEquals(s, s.substr(false));
37 assertEquals(s, s.substr(0.9)); 37 assertEquals(s, s.substr(0.9));
38 assertEquals(s, s.substr({ valueOf: function() { return 0; } })); 38 assertEquals(s, s.substr({ valueOf: function() { return 0; } }));
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
106 x += x; 106 x += x;
107 x += x; 107 x += x;
108 x += x; // 2^10 108 x += x; // 2^10
109 x += x; 109 x += x;
110 x += x; 110 x += x;
111 var xl = x.length; 111 var xl = x.length;
112 var cache = []; 112 var cache = [];
113 for (var i = 0; i < 1000; i++) { 113 for (var i = 0; i < 1000; i++) {
114 var z = x.substring(i % xl); 114 var z = x.substring(i % xl);
115 assertEquals(xl - (i % xl), z.length); 115 assertEquals(xl - (i % xl), z.length);
116 cache.push(z);
117 } 116 }
118 117
119 118
120 // Same with two-byte strings 119 // Same with two-byte strings
121 var x = "\u2028123456789ABCDEF"; 120 var x = "\u2028123456789ABCDEF";
122 x += x; // 2^5 121 x += x; // 2^5
123 x += x; 122 x += x;
124 x += x; 123 x += x;
125 x += x; 124 x += x;
126 x += x; 125 x += x;
127 x += x; // 2^10 126 x += x; // 2^10
128 x += x; 127 x += x;
129 x += x; 128 x += x;
129 x += x;
130 x += x;
131 x += x;
132 x += x;
133 x += x;
130 var xl = x.length; 134 var xl = x.length;
131 var cache = []; 135 var cache = [];
132 for (var i = 0; i < 1000; i++) { 136 for (var i = 0; i < 1000; i++) {
133 var z = x.substring(i % xl); 137 var z = x.substring(i % xl);
134 assertEquals(xl - (i % xl), z.length); 138 assertEquals(xl - (i % xl), z.length);
135 cache.push(z);
136 } 139 }
137 140
138 // Substring of substring. 141 // Substring of substring.
139 var cache = []; 142 var cache = [];
140 var last = x; 143 var last = x;
141 var offset = 0; 144 for (var i = 0; i < 100000; i++) {
142 for (var i = 0; i < 64; i++) { 145 var z = last.substring(1);
143 var z = last.substring(i);
144 last = z; 146 last = z;
145 cache.push(z); 147 cache.push(z);
146 offset += i;
147 } 148 }
148 for (var i = 63; i >= 0; i--) { 149
150 // Fill up new space with junk and then invoke GC.
151 var fill = [];
152 for (var i = 0; i < 1000000; i++) {
153 fill.push(i + " ");
154 }
155 gc(true);
156
157 for (var i = 100000; i > 0; i--) {
149 var z = cache.pop(); 158 var z = cache.pop();
150 assertTrue(/\u2028123456789ABCDEF/.test(z)); 159 assertTrue(/\u2028123456789ABCDEF/.test(z));
151 assertEquals(xl - offset, z.length); 160 assertEquals(xl - i, z.length);
152 assertEquals(x.charAt(i*(i+1)/2), z.charAt(0)); 161 assertEquals(x.charAt(i), z.charAt(0));
153 offset -= i;
154 } 162 }
155 163
156 // Test charAt for different strings. 164 // Test charAt for different strings.
157 function f(s1, s2, s3, i) { 165 function f(s1, s2, s3, i) {
158 assertEquals(String.fromCharCode(97+i%11), s1.charAt(i%11)); 166 assertEquals(String.fromCharCode(97+i%11), s1.charAt(i%11));
159 assertEquals(String.fromCharCode(97+i%11), s2.charAt(i%11)); 167 assertEquals(String.fromCharCode(97+i%11), s2.charAt(i%11));
160 assertEquals(String.fromCharCode(98+i%11), s3.charAt(i%11)); 168 assertEquals(String.fromCharCode(98+i%11), s3.charAt(i%11));
161 assertEquals(String.fromCharCode(101), s3.charAt(3)); 169 assertEquals(String.fromCharCode(101), s3.charAt(3));
162 } 170 }
163 171
(...skipping 26 matching lines...) Expand all
190 utf.substring(5,1) + utf.substring(3,7)); 198 utf.substring(5,1) + utf.substring(3,7));
191 199
192 /* 200 /*
193 // Externalizing strings. 201 // Externalizing strings.
194 var a = "123456789qwertyuiopasdfghjklzxcvbnm"; 202 var a = "123456789qwertyuiopasdfghjklzxcvbnm";
195 var b = a.slice(1,-1); 203 var b = a.slice(1,-1);
196 assertEquals(a.slice(1,-1), b); 204 assertEquals(a.slice(1,-1), b);
197 externalizeString(a); 205 externalizeString(a);
198 assertEquals(a.slice(1,-1), b); 206 assertEquals(a.slice(1,-1), b);
199 */ 207 */
OLDNEW
« no previous file with comments | « test/cctest/test-strings.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698