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

Side by Side Diff: test/cctest/test-code-stub-assembler.cc

Issue 2549773002: Internalize strings in-place (Closed)
Patch Set: forgot one Created 4 years 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
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/base/utils/random-number-generator.h" 5 #include "src/base/utils/random-number-generator.h"
6 #include "src/code-factory.h" 6 #include "src/code-factory.h"
7 #include "src/code-stub-assembler.h" 7 #include "src/code-stub-assembler.h"
8 #include "src/compiler/node.h" 8 #include "src/compiler/node.h"
9 #include "src/isolate.h" 9 #include "src/isolate.h"
10 #include "test/cctest/compiler/code-assembler-tester.h" 10 #include "test/cctest/compiler/code-assembler-tester.h"
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
230 CodeStubAssembler m(data.state()); 230 CodeStubAssembler m(data.state());
231 231
232 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout }; 232 enum Result { kKeyIsIndex, kKeyIsUnique, kBailout };
233 { 233 {
234 Node* key = m.Parameter(0); 234 Node* key = m.Parameter(0);
235 Node* expected_result = m.Parameter(1); 235 Node* expected_result = m.Parameter(1);
236 Node* expected_arg = m.Parameter(2); 236 Node* expected_arg = m.Parameter(2);
237 237
238 Label passed(&m), failed(&m); 238 Label passed(&m), failed(&m);
239 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m); 239 Label if_keyisindex(&m), if_keyisunique(&m), if_bailout(&m);
240 Variable var_index(&m, MachineType::PointerRepresentation()); 240 {
241 Variable var_index(&m, MachineType::PointerRepresentation());
242 Variable var_unique(&m, MachineRepresentation::kTagged);
241 243
242 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &if_bailout); 244 m.TryToName(key, &if_keyisindex, &var_index, &if_keyisunique, &var_unique,
245 &if_bailout);
243 246
244 m.Bind(&if_keyisindex); 247 m.Bind(&if_keyisindex);
245 m.GotoUnless( 248 m.GotoUnless(m.WordEqual(expected_result,
246 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsIndex))), 249 m.SmiConstant(Smi::FromInt(kKeyIsIndex))),
247 &failed); 250 &failed);
248 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_index.value()), &passed, 251 m.Branch(m.WordEqual(m.SmiUntag(expected_arg), var_index.value()),
249 &failed); 252 &passed, &failed);
250 253
251 m.Bind(&if_keyisunique); 254 m.Bind(&if_keyisunique);
252 m.GotoUnless( 255 m.GotoUnless(m.WordEqual(expected_result,
253 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kKeyIsUnique))), 256 m.SmiConstant(Smi::FromInt(kKeyIsUnique))),
254 &failed); 257 &failed);
255 m.Branch(m.WordEqual(expected_arg, key), &passed, &failed); 258 m.Branch(m.WordEqual(expected_arg, var_unique.value()), &passed, &failed);
259 }
256 260
257 m.Bind(&if_bailout); 261 m.Bind(&if_bailout);
258 m.Branch( 262 m.Branch(
259 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))), 263 m.WordEqual(expected_result, m.SmiConstant(Smi::FromInt(kBailout))),
260 &passed, &failed); 264 &passed, &failed);
261 265
262 m.Bind(&passed); 266 m.Bind(&passed);
263 m.Return(m.BooleanConstant(true)); 267 m.Return(m.BooleanConstant(true));
264 268
265 m.Bind(&failed); 269 m.Bind(&failed);
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
341 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153"); 345 Handle<String> key = isolate->factory()->NewStringFromAsciiChecked("153");
342 CHECK(!key->HasHashCode()); 346 CHECK(!key->HasHashCode());
343 ft.CheckTrue(key, expect_bailout); 347 ft.CheckTrue(key, expect_bailout);
344 } 348 }
345 349
346 { 350 {
347 // TryToName(<non-internalized string>) => bailout. 351 // TryToName(<non-internalized string>) => bailout.
348 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test"); 352 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test");
349 ft.CheckTrue(key, expect_bailout); 353 ft.CheckTrue(key, expect_bailout);
350 } 354 }
355
356 {
357 // TryToName(<thin string>) => internalized version.
358 Handle<String> s = isolate->factory()->NewStringFromAsciiChecked("foo");
359 Handle<String> internalized = isolate->factory()->InternalizeString(s);
360 ft.CheckTrue(s, expect_unique, internalized);
361 }
362
363 {
364 // TryToName(<thin two-byte string>) => internalized version.
365 uc16 array1[] = {2001, 2002, 2003};
366 Vector<const uc16> str1(array1);
367 Handle<String> s =
368 isolate->factory()->NewStringFromTwoByte(str1).ToHandleChecked();
369 Handle<String> internalized = isolate->factory()->InternalizeString(s);
370 ft.CheckTrue(s, expect_unique, internalized);
371 }
351 } 372 }
352 373
353 namespace { 374 namespace {
354 375
355 template <typename Dictionary> 376 template <typename Dictionary>
356 void TestEntryToIndex() { 377 void TestEntryToIndex() {
357 Isolate* isolate(CcTest::InitIsolateOnce()); 378 Isolate* isolate(CcTest::InitIsolateOnce());
358 379
359 const int kNumParams = 1; 380 const int kNumParams = 1;
360 CodeAssemblerTester data(isolate, kNumParams); 381 CodeAssemblerTester data(isolate, kNumParams);
(...skipping 1608 matching lines...) Expand 10 before | Expand all | Expand 10 after
1969 1990
1970 result = ft.Call(isolate->factory()->empty_string()).ToHandleChecked(); 1991 result = ft.Call(isolate->factory()->empty_string()).ToHandleChecked();
1971 CHECK_EQ(isolate->heap()->false_value(), *result); 1992 CHECK_EQ(isolate->heap()->false_value(), *result);
1972 1993
1973 result = ft.Call(isolate->factory()->NewPrivateSymbol()).ToHandleChecked(); 1994 result = ft.Call(isolate->factory()->NewPrivateSymbol()).ToHandleChecked();
1974 CHECK_EQ(isolate->heap()->true_value(), *result); 1995 CHECK_EQ(isolate->heap()->true_value(), *result);
1975 } 1996 }
1976 1997
1977 } // namespace internal 1998 } // namespace internal
1978 } // namespace v8 1999 } // namespace v8
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698