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

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

Issue 2430273007: [runtime] Object.create(null) creates a slow object (Closed)
Patch Set: addressing comments Created 4 years, 2 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
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/ic/stub-cache.h" 9 #include "src/ic/stub-cache.h"
10 #include "src/isolate.h" 10 #include "src/isolate.h"
(...skipping 329 matching lines...) Expand 10 before | Expand all | Expand 10 after
340 { 340 {
341 // TryToName(<non-internalized string>) => bailout. 341 // TryToName(<non-internalized string>) => bailout.
342 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test"); 342 Handle<Object> key = isolate->factory()->NewStringFromAsciiChecked("test");
343 ft.CheckTrue(key, expect_bailout); 343 ft.CheckTrue(key, expect_bailout);
344 } 344 }
345 } 345 }
346 346
347 namespace { 347 namespace {
348 348
349 template <typename Dictionary> 349 template <typename Dictionary>
350 void TestEntryToIndex() {
351 Isolate* isolate(CcTest::InitIsolateOnce());
352
353 const int kNumParams = 1;
354 CodeStubAssemblerTester m(isolate, kNumParams);
355 {
356 Node* entry = m.SmiUntag(m.Parameter(0));
357 Node* result = m.EntryToIndex<Dictionary>(entry);
358 m.Return(m.SmiTag(result));
359 }
360
361 Handle<Code> code = m.GenerateCode();
362 FunctionTester ft(code, kNumParams);
363
364 // Test a wide range of entries but staying linear in the first 100 entries.
365 for (int entry = 0; entry < Dictionary::kMaxCapacity;
366 entry = entry * 1.01 + 1) {
367 Handle<Object> result =
368 ft.Call(handle(Smi::FromInt(entry), isolate)).ToHandleChecked();
369 CHECK_EQ(Dictionary::EntryToIndex(entry), Smi::cast(*result)->value());
370 }
371 }
372
373 TEST(NameDictionaryEntryToIndex) { TestEntryToIndex<NameDictionary>(); }
374 TEST(GlobalDictionaryEntryToIndex) { TestEntryToIndex<GlobalDictionary>(); }
375
376 } // namespace
377
378 namespace {
379
380 template <typename Dictionary>
350 void TestNameDictionaryLookup() { 381 void TestNameDictionaryLookup() {
351 typedef CodeStubAssembler::Label Label; 382 typedef CodeStubAssembler::Label Label;
352 typedef CodeStubAssembler::Variable Variable; 383 typedef CodeStubAssembler::Variable Variable;
353 Isolate* isolate(CcTest::InitIsolateOnce()); 384 Isolate* isolate(CcTest::InitIsolateOnce());
354 385
355 const int kNumParams = 4; 386 const int kNumParams = 4;
356 CodeStubAssemblerTester m(isolate, kNumParams); 387 CodeStubAssemblerTester m(isolate, kNumParams);
357 388
358 enum Result { kFound, kNotFound }; 389 enum Result { kFound, kNotFound };
359 { 390 {
(...skipping 1259 matching lines...) Expand 10 before | Expand all | Expand 10 after
1619 1650
1620 Node* result = m.AllocateJSObjectFromMap(map, properties, elements); 1651 Node* result = m.AllocateJSObjectFromMap(map, properties, elements);
1621 1652
1622 m.Return(result); 1653 m.Return(result);
1623 } 1654 }
1624 1655
1625 Handle<Code> code = m.GenerateCode(); 1656 Handle<Code> code = m.GenerateCode();
1626 FunctionTester ft(code, kNumParams); 1657 FunctionTester ft(code, kNumParams);
1627 1658
1628 Handle<Map> maps[] = { 1659 Handle<Map> maps[] = {
1629 isolate->object_with_null_prototype_map(),
1630 handle(isolate->object_function()->initial_map(), isolate), 1660 handle(isolate->object_function()->initial_map(), isolate),
1631 handle(isolate->array_function()->initial_map(), isolate), 1661 handle(isolate->array_function()->initial_map(), isolate),
1632 }; 1662 };
1633 1663
1634 #define VERIFY(result, map_value, properties_value, elements_value) \ 1664 #define VERIFY(result, map_value, properties_value, elements_value) \
1635 CHECK_EQ(result->map(), map_value); \ 1665 CHECK_EQ(result->map(), map_value); \
1636 CHECK_EQ(result->properties(), properties_value); \ 1666 CHECK_EQ(result->properties(), properties_value); \
1637 CHECK_EQ(result->elements(), elements_value); 1667 CHECK_EQ(result->elements(), elements_value);
1638 1668
1639 { 1669 {
1640 Handle<Object> empty_fixed_array = factory->empty_fixed_array(); 1670 Handle<Object> empty_fixed_array = factory->empty_fixed_array();
1641 for (int i = 0; i < arraysize(maps); i++) { 1671 for (int i = 0; i < arraysize(maps); i++) {
1642 Handle<Map> map = maps[i]; 1672 Handle<Map> map = maps[i];
1643 Handle<JSObject> result = Handle<JSObject>::cast( 1673 Handle<JSObject> result = Handle<JSObject>::cast(
1644 ft.Call(map, empty_fixed_array, empty_fixed_array).ToHandleChecked()); 1674 ft.Call(map, empty_fixed_array, empty_fixed_array).ToHandleChecked());
1645 VERIFY(result, *map, *empty_fixed_array, *empty_fixed_array); 1675 VERIFY(result, *map, *empty_fixed_array, *empty_fixed_array);
1676 CHECK(result->HasFastProperties());
1646 #ifdef VERIFY_HEAP 1677 #ifdef VERIFY_HEAP
1647 isolate->heap()->Verify(); 1678 isolate->heap()->Verify();
1648 #endif 1679 #endif
1649 } 1680 }
1650 } 1681 }
1651 1682
1652 { 1683 {
1653 // TODO(cbruni): handle in-object properties 1684 // TODO(cbruni): handle in-object properties
1654 Handle<JSObject> object = Handle<JSObject>::cast( 1685 Handle<JSObject> object = Handle<JSObject>::cast(
1655 v8::Utils::OpenHandle(*CompileRun("var object = {a:1,b:2, 1:1, 2:2}; " 1686 v8::Utils::OpenHandle(*CompileRun("var object = {a:1,b:2, 1:1, 2:2}; "
1656 "object"))); 1687 "object")));
1657 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, 0, 1688 JSObject::NormalizeProperties(object, KEEP_INOBJECT_PROPERTIES, 0,
1658 "Normalize"); 1689 "Normalize");
1659 Handle<JSObject> result = Handle<JSObject>::cast( 1690 Handle<JSObject> result = Handle<JSObject>::cast(
1660 ft.Call(handle(object->map()), handle(object->properties()), 1691 ft.Call(handle(object->map()), handle(object->properties()),
1661 handle(object->elements())) 1692 handle(object->elements()))
1662 .ToHandleChecked()); 1693 .ToHandleChecked());
1663 VERIFY(result, object->map(), object->properties(), object->elements()); 1694 VERIFY(result, object->map(), object->properties(), object->elements());
1695 CHECK(!result->HasFastProperties());
1664 #ifdef VERIFY_HEAP 1696 #ifdef VERIFY_HEAP
1665 isolate->heap()->Verify(); 1697 isolate->heap()->Verify();
1666 #endif 1698 #endif
1667 } 1699 }
1700 #undef VERIFY
1701 }
1702
1703 TEST(AllocateNameDictionary) {
1704 Isolate* isolate(CcTest::InitIsolateOnce());
1705 Factory* factory = isolate->factory();
1706
1707 const int kNumParams = 1;
1708 CodeStubAssemblerTester m(isolate, kNumParams);
1709
1710 {
1711 Node* capacity = m.Parameter(0);
1712 Node* result = m.AllocateNameDictionary(m.SmiUntag(capacity));
1713 m.Return(result);
1714 }
1715
1716 Handle<Code> code = m.GenerateCode();
1717 FunctionTester ft(code, kNumParams);
1718
1719 {
1720 Handle<Object> empty_fixed_array = factory->empty_fixed_array();
1721 for (int i = 0; i < 256; i = i * 1.1 + 1) {
1722 Handle<JSObject> result = Handle<JSObject>::cast(
1723 ft.Call(handle(Smi::FromInt(i), isolate)).ToHandleChecked());
1724 Handle<NameDictionary> dict = NameDictionary::New(isolate, i);
1725 // Both dictionaries should be memory equal.
1726 int size =
1727 FixedArrayBase::kHeaderSize + (dict->length() - 1) * kPointerSize;
1728 CHECK_EQ(0, memcmp(*dict, *result, size));
1729 }
1730 }
1668 } 1731 }
1669 1732
1670 } // namespace internal 1733 } // namespace internal
1671 } // namespace v8 1734 } // namespace v8
OLDNEW
« src/objects.h ('K') | « src/runtime/runtime-object.cc ('k') | test/mjsunit/es6/symbols.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698