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

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

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