| OLD | NEW |
| 1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 Isolate* isolate = new_target->GetIsolate(); | 74 Isolate* isolate = new_target->GetIsolate(); |
| 75 Code* apply_builtin = isolate->builtins()->builtin( | 75 Code* apply_builtin = isolate->builtins()->builtin( |
| 76 Builtins::kFunctionApply); | 76 Builtins::kFunctionApply); |
| 77 if (raw_frame->unchecked_code() == apply_builtin) { | 77 if (raw_frame->unchecked_code() == apply_builtin) { |
| 78 PrintF("apply from "); | 78 PrintF("apply from "); |
| 79 it.Advance(); | 79 it.Advance(); |
| 80 raw_frame = it.frame(); | 80 raw_frame = it.frame(); |
| 81 } | 81 } |
| 82 } | 82 } |
| 83 JavaScriptFrame::PrintTop(stdout, false, true); | 83 JavaScriptFrame::PrintTop(stdout, false, true); |
| 84 PrintF(" (%c->%c)", | 84 bool new_can_grow = |
| 85 Code::GetKeyedAccessGrowMode(new_target->extra_ic_state()) == |
| 86 ALLOW_JSARRAY_GROWTH; |
| 87 PrintF(" (%c->%c%s)", |
| 85 TransitionMarkFromState(old_state), | 88 TransitionMarkFromState(old_state), |
| 86 TransitionMarkFromState(new_state)); | 89 TransitionMarkFromState(new_state), |
| 90 new_can_grow ? ".GROW" : ""); |
| 87 name->Print(); | 91 name->Print(); |
| 88 PrintF("]\n"); | 92 PrintF("]\n"); |
| 89 } | 93 } |
| 90 } | 94 } |
| 91 | 95 |
| 92 #define TRACE_GENERIC_IC(type, reason) \ | 96 #define TRACE_GENERIC_IC(type, reason) \ |
| 93 do { \ | 97 do { \ |
| 94 if (FLAG_trace_ic) { \ | 98 if (FLAG_trace_ic) { \ |
| 95 PrintF("[%s patching generic stub in ", type); \ | 99 PrintF("[%s patching generic stub in ", type); \ |
| 96 JavaScriptFrame::PrintTop(stdout, false, true); \ | 100 JavaScriptFrame::PrintTop(stdout, false, true); \ |
| (...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 343 | 347 |
| 344 void LoadIC::Clear(Address address, Code* target) { | 348 void LoadIC::Clear(Address address, Code* target) { |
| 345 if (target->ic_state() == UNINITIALIZED) return; | 349 if (target->ic_state() == UNINITIALIZED) return; |
| 346 SetTargetAtAddress(address, initialize_stub()); | 350 SetTargetAtAddress(address, initialize_stub()); |
| 347 } | 351 } |
| 348 | 352 |
| 349 | 353 |
| 350 void StoreIC::Clear(Address address, Code* target) { | 354 void StoreIC::Clear(Address address, Code* target) { |
| 351 if (target->ic_state() == UNINITIALIZED) return; | 355 if (target->ic_state() == UNINITIALIZED) return; |
| 352 SetTargetAtAddress(address, | 356 SetTargetAtAddress(address, |
| 353 (target->extra_ic_state() == kStrictMode) | 357 (Code::GetStrictMode(target->extra_ic_state()) == kStrictMode) |
| 354 ? initialize_stub_strict() | 358 ? initialize_stub_strict() |
| 355 : initialize_stub()); | 359 : initialize_stub()); |
| 356 } | 360 } |
| 357 | 361 |
| 358 | 362 |
| 359 void KeyedStoreIC::Clear(Address address, Code* target) { | 363 void KeyedStoreIC::Clear(Address address, Code* target) { |
| 360 if (target->ic_state() == UNINITIALIZED) return; | 364 if (target->ic_state() == UNINITIALIZED) return; |
| 361 SetTargetAtAddress(address, | 365 SetTargetAtAddress(address, |
| 362 (target->extra_ic_state() == kStrictMode) | 366 (Code::GetStrictMode(target->extra_ic_state()) == kStrictMode) |
| 363 ? initialize_stub_strict() | 367 ? initialize_stub_strict() |
| 364 : initialize_stub()); | 368 : initialize_stub()); |
| 365 } | 369 } |
| 366 | 370 |
| 367 | 371 |
| 368 static bool HasInterceptorGetter(JSObject* object) { | 372 static bool HasInterceptorGetter(JSObject* object) { |
| 369 return !object->GetNamedInterceptor()->getter()->IsUndefined(); | 373 return !object->GetNamedInterceptor()->getter()->IsUndefined(); |
| 370 } | 374 } |
| 371 | 375 |
| 372 | 376 |
| (...skipping 591 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 964 // GenerateMonomorphicCacheProbe. | 968 // GenerateMonomorphicCacheProbe. |
| 965 isolate()->stub_cache()->Set(*name, receiver->map(), *code); | 969 isolate()->stub_cache()->Set(*name, receiver->map(), *code); |
| 966 } | 970 } |
| 967 | 971 |
| 968 TRACE_IC("LoadIC", name, state, target()); | 972 TRACE_IC("LoadIC", name, state, target()); |
| 969 } | 973 } |
| 970 | 974 |
| 971 | 975 |
| 972 Handle<Code> KeyedLoadIC::GetElementStubWithoutMapCheck( | 976 Handle<Code> KeyedLoadIC::GetElementStubWithoutMapCheck( |
| 973 bool is_js_array, | 977 bool is_js_array, |
| 974 ElementsKind elements_kind) { | 978 ElementsKind elements_kind, |
| 979 KeyedAccessGrowMode grow_mode) { |
| 980 ASSERT(grow_mode == DO_NOT_ALLOW_JSARRAY_GROWTH); |
| 975 return KeyedLoadElementStub(elements_kind).GetCode(); | 981 return KeyedLoadElementStub(elements_kind).GetCode(); |
| 976 } | 982 } |
| 977 | 983 |
| 978 | 984 |
| 979 Handle<Code> KeyedLoadIC::ComputePolymorphicStub( | 985 Handle<Code> KeyedLoadIC::ComputePolymorphicStub( |
| 980 MapHandleList* receiver_maps, | 986 MapHandleList* receiver_maps, |
| 981 StrictModeFlag strict_mode) { | 987 StrictModeFlag strict_mode, |
| 988 KeyedAccessGrowMode growth_mode) { |
| 982 CodeHandleList handler_ics(receiver_maps->length()); | 989 CodeHandleList handler_ics(receiver_maps->length()); |
| 983 for (int i = 0; i < receiver_maps->length(); ++i) { | 990 for (int i = 0; i < receiver_maps->length(); ++i) { |
| 984 Handle<Map> receiver_map = receiver_maps->at(i); | 991 Handle<Map> receiver_map = receiver_maps->at(i); |
| 985 Handle<Code> cached_stub = ComputeMonomorphicStubWithoutMapCheck( | 992 Handle<Code> cached_stub = ComputeMonomorphicStubWithoutMapCheck( |
| 986 receiver_map, strict_mode); | 993 receiver_map, strict_mode, growth_mode); |
| 987 handler_ics.Add(cached_stub); | 994 handler_ics.Add(cached_stub); |
| 988 } | 995 } |
| 989 KeyedLoadStubCompiler compiler(isolate()); | 996 KeyedLoadStubCompiler compiler(isolate()); |
| 990 Handle<Code> code = compiler.CompileLoadPolymorphic( | 997 Handle<Code> code = compiler.CompileLoadPolymorphic( |
| 991 receiver_maps, &handler_ics); | 998 receiver_maps, &handler_ics); |
| 992 isolate()->counters()->keyed_load_polymorphic_stubs()->Increment(); | 999 isolate()->counters()->keyed_load_polymorphic_stubs()->Increment(); |
| 993 PROFILE(isolate(), | 1000 PROFILE(isolate(), |
| 994 CodeCreateEvent(Logger::KEYED_LOAD_MEGAMORPHIC_IC_TAG, *code, 0)); | 1001 CodeCreateEvent(Logger::KEYED_LOAD_MEGAMORPHIC_IC_TAG, *code, 0)); |
| 995 return code; | 1002 return code; |
| 996 } | 1003 } |
| (...skipping 464 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1461 } | 1468 } |
| 1462 } | 1469 } |
| 1463 } | 1470 } |
| 1464 | 1471 |
| 1465 | 1472 |
| 1466 Handle<Code> KeyedIC::ComputeStub(Handle<JSObject> receiver, | 1473 Handle<Code> KeyedIC::ComputeStub(Handle<JSObject> receiver, |
| 1467 StubKind stub_kind, | 1474 StubKind stub_kind, |
| 1468 StrictModeFlag strict_mode, | 1475 StrictModeFlag strict_mode, |
| 1469 Handle<Code> generic_stub) { | 1476 Handle<Code> generic_stub) { |
| 1470 State ic_state = target()->ic_state(); | 1477 State ic_state = target()->ic_state(); |
| 1478 KeyedAccessGrowMode grow_mode = IsGrowStubKind(stub_kind) |
| 1479 ? ALLOW_JSARRAY_GROWTH |
| 1480 : DO_NOT_ALLOW_JSARRAY_GROWTH; |
| 1471 if ((ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) && | 1481 if ((ic_state == UNINITIALIZED || ic_state == PREMONOMORPHIC) && |
| 1472 !IsTransitionStubKind(stub_kind)) { | 1482 !IsTransitionStubKind(stub_kind)) { |
| 1473 return ComputeMonomorphicStub( | 1483 return ComputeMonomorphicStub( |
| 1474 receiver, stub_kind, strict_mode, generic_stub); | 1484 receiver, stub_kind, strict_mode, generic_stub); |
| 1475 } | 1485 } |
| 1476 ASSERT(target() != *generic_stub); | 1486 ASSERT(target() != *generic_stub); |
| 1477 | 1487 |
| 1478 // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS | 1488 // Don't handle megamorphic property accesses for INTERCEPTORS or CALLBACKS |
| 1479 // via megamorphic stubs, since they don't have a map in their relocation info | 1489 // via megamorphic stubs, since they don't have a map in their relocation info |
| 1480 // and so the stubs can't be harvested for the object needed for a map check. | 1490 // and so the stubs can't be harvested for the object needed for a map check. |
| (...skipping 24 matching lines...) Expand all Loading... |
| 1505 return generic_stub; | 1515 return generic_stub; |
| 1506 } | 1516 } |
| 1507 | 1517 |
| 1508 // If the maximum number of receiver maps has been exceeded, use the generic | 1518 // If the maximum number of receiver maps has been exceeded, use the generic |
| 1509 // version of the IC. | 1519 // version of the IC. |
| 1510 if (target_receiver_maps.length() > kMaxKeyedPolymorphism) { | 1520 if (target_receiver_maps.length() > kMaxKeyedPolymorphism) { |
| 1511 TRACE_GENERIC_IC("KeyedIC", "max polymorph exceeded"); | 1521 TRACE_GENERIC_IC("KeyedIC", "max polymorph exceeded"); |
| 1512 return generic_stub; | 1522 return generic_stub; |
| 1513 } | 1523 } |
| 1514 | 1524 |
| 1525 if ((Code::GetKeyedAccessGrowMode(target()->extra_ic_state()) == |
| 1526 ALLOW_JSARRAY_GROWTH)) { |
| 1527 grow_mode = ALLOW_JSARRAY_GROWTH; |
| 1528 } |
| 1529 |
| 1515 Handle<PolymorphicCodeCache> cache = | 1530 Handle<PolymorphicCodeCache> cache = |
| 1516 isolate()->factory()->polymorphic_code_cache(); | 1531 isolate()->factory()->polymorphic_code_cache(); |
| 1517 Code::Flags flags = Code::ComputeFlags(kind(), MEGAMORPHIC, strict_mode); | 1532 Code::ExtraICState extra_state = Code::ComputeExtraICState(grow_mode, |
| 1533 strict_mode); |
| 1534 Code::Flags flags = Code::ComputeFlags(kind(), MEGAMORPHIC, extra_state); |
| 1518 Handle<Object> probe = cache->Lookup(&target_receiver_maps, flags); | 1535 Handle<Object> probe = cache->Lookup(&target_receiver_maps, flags); |
| 1519 if (probe->IsCode()) return Handle<Code>::cast(probe); | 1536 if (probe->IsCode()) return Handle<Code>::cast(probe); |
| 1520 | 1537 |
| 1521 Handle<Code> stub = | 1538 Handle<Code> stub = |
| 1522 ComputePolymorphicStub(&target_receiver_maps, strict_mode); | 1539 ComputePolymorphicStub(&target_receiver_maps, strict_mode, grow_mode); |
| 1523 PolymorphicCodeCache::Update(cache, &target_receiver_maps, flags, stub); | 1540 PolymorphicCodeCache::Update(cache, &target_receiver_maps, flags, stub); |
| 1524 return stub; | 1541 return stub; |
| 1525 } | 1542 } |
| 1526 | 1543 |
| 1527 | 1544 |
| 1528 Handle<Code> KeyedIC::ComputeMonomorphicStubWithoutMapCheck( | 1545 Handle<Code> KeyedIC::ComputeMonomorphicStubWithoutMapCheck( |
| 1529 Handle<Map> receiver_map, | 1546 Handle<Map> receiver_map, |
| 1530 StrictModeFlag strict_mode) { | 1547 StrictModeFlag strict_mode, |
| 1548 KeyedAccessGrowMode grow_mode) { |
| 1531 if ((receiver_map->instance_type() & kNotStringTag) == 0) { | 1549 if ((receiver_map->instance_type() & kNotStringTag) == 0) { |
| 1532 ASSERT(!string_stub().is_null()); | 1550 ASSERT(!string_stub().is_null()); |
| 1533 return string_stub(); | 1551 return string_stub(); |
| 1534 } else { | 1552 } else { |
| 1535 ASSERT(receiver_map->has_dictionary_elements() || | 1553 ASSERT(receiver_map->has_dictionary_elements() || |
| 1536 receiver_map->has_fast_elements() || | 1554 receiver_map->has_fast_elements() || |
| 1537 receiver_map->has_fast_smi_only_elements() || | 1555 receiver_map->has_fast_smi_only_elements() || |
| 1538 receiver_map->has_fast_double_elements() || | 1556 receiver_map->has_fast_double_elements() || |
| 1539 receiver_map->has_external_array_elements()); | 1557 receiver_map->has_external_array_elements()); |
| 1540 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; | 1558 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; |
| 1541 return GetElementStubWithoutMapCheck(is_js_array, | 1559 return GetElementStubWithoutMapCheck(is_js_array, |
| 1542 receiver_map->elements_kind()); | 1560 receiver_map->elements_kind(), |
| 1561 grow_mode); |
| 1543 } | 1562 } |
| 1544 } | 1563 } |
| 1545 | 1564 |
| 1546 | 1565 |
| 1547 Handle<Code> KeyedIC::ComputeMonomorphicStub(Handle<JSObject> receiver, | 1566 Handle<Code> KeyedIC::ComputeMonomorphicStub(Handle<JSObject> receiver, |
| 1548 StubKind stub_kind, | 1567 StubKind stub_kind, |
| 1549 StrictModeFlag strict_mode, | 1568 StrictModeFlag strict_mode, |
| 1550 Handle<Code> generic_stub) { | 1569 Handle<Code> generic_stub) { |
| 1551 if (receiver->HasFastElements() || | 1570 if (receiver->HasFastElements() || |
| 1552 receiver->HasFastSmiOnlyElements() || | 1571 receiver->HasFastSmiOnlyElements() || |
| 1553 receiver->HasExternalArrayElements() || | 1572 receiver->HasExternalArrayElements() || |
| 1554 receiver->HasFastDoubleElements() || | 1573 receiver->HasFastDoubleElements() || |
| 1555 receiver->HasDictionaryElements()) { | 1574 receiver->HasDictionaryElements()) { |
| 1556 return isolate()->stub_cache()->ComputeKeyedLoadOrStoreElement( | 1575 return isolate()->stub_cache()->ComputeKeyedLoadOrStoreElement( |
| 1557 receiver, stub_kind, strict_mode); | 1576 receiver, stub_kind, strict_mode); |
| 1558 } else { | 1577 } else { |
| 1559 return generic_stub; | 1578 return generic_stub; |
| 1560 } | 1579 } |
| 1561 } | 1580 } |
| 1562 | 1581 |
| 1563 | 1582 |
| 1564 Handle<Map> KeyedIC::ComputeTransitionedMap(Handle<JSObject> receiver, | 1583 Handle<Map> KeyedIC::ComputeTransitionedMap(Handle<JSObject> receiver, |
| 1565 StubKind stub_kind) { | 1584 StubKind stub_kind) { |
| 1566 switch (stub_kind) { | 1585 switch (stub_kind) { |
| 1567 case KeyedIC::STORE_TRANSITION_SMI_TO_OBJECT: | 1586 case KeyedIC::STORE_TRANSITION_SMI_TO_OBJECT: |
| 1568 case KeyedIC::STORE_TRANSITION_DOUBLE_TO_OBJECT: | 1587 case KeyedIC::STORE_TRANSITION_DOUBLE_TO_OBJECT: |
| 1588 case KeyedIC::STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT: |
| 1589 case KeyedIC::STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT: |
| 1569 return JSObject::GetElementsTransitionMap(receiver, FAST_ELEMENTS); | 1590 return JSObject::GetElementsTransitionMap(receiver, FAST_ELEMENTS); |
| 1570 break; | 1591 break; |
| 1571 case KeyedIC::STORE_TRANSITION_SMI_TO_DOUBLE: | 1592 case KeyedIC::STORE_TRANSITION_SMI_TO_DOUBLE: |
| 1593 case KeyedIC::STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE: |
| 1572 return JSObject::GetElementsTransitionMap(receiver, FAST_DOUBLE_ELEMENTS); | 1594 return JSObject::GetElementsTransitionMap(receiver, FAST_DOUBLE_ELEMENTS); |
| 1573 break; | 1595 break; |
| 1574 default: | 1596 default: |
| 1575 UNREACHABLE(); | 1597 UNREACHABLE(); |
| 1576 return Handle<Map>::null(); | 1598 return Handle<Map>::null(); |
| 1577 } | 1599 } |
| 1578 } | 1600 } |
| 1579 | 1601 |
| 1580 | 1602 |
| 1581 Handle<Code> KeyedStoreIC::GetElementStubWithoutMapCheck( | 1603 Handle<Code> KeyedStoreIC::GetElementStubWithoutMapCheck( |
| 1582 bool is_js_array, | 1604 bool is_js_array, |
| 1583 ElementsKind elements_kind) { | 1605 ElementsKind elements_kind, |
| 1584 return KeyedStoreElementStub(is_js_array, elements_kind).GetCode(); | 1606 KeyedAccessGrowMode grow_mode) { |
| 1607 return KeyedStoreElementStub(is_js_array, elements_kind, grow_mode).GetCode(); |
| 1585 } | 1608 } |
| 1586 | 1609 |
| 1587 | 1610 |
| 1588 Handle<Code> KeyedStoreIC::ComputePolymorphicStub(MapHandleList* receiver_maps, | 1611 Handle<Code> KeyedStoreIC::ComputePolymorphicStub( |
| 1589 StrictModeFlag strict_mode) { | 1612 MapHandleList* receiver_maps, |
| 1613 StrictModeFlag strict_mode, |
| 1614 KeyedAccessGrowMode grow_mode) { |
| 1590 // Collect MONOMORPHIC stubs for all target_receiver_maps. | 1615 // Collect MONOMORPHIC stubs for all target_receiver_maps. |
| 1591 CodeHandleList handler_ics(receiver_maps->length()); | 1616 CodeHandleList handler_ics(receiver_maps->length()); |
| 1592 MapHandleList transitioned_maps(receiver_maps->length()); | 1617 MapHandleList transitioned_maps(receiver_maps->length()); |
| 1593 for (int i = 0; i < receiver_maps->length(); ++i) { | 1618 for (int i = 0; i < receiver_maps->length(); ++i) { |
| 1594 Handle<Map> receiver_map(receiver_maps->at(i)); | 1619 Handle<Map> receiver_map(receiver_maps->at(i)); |
| 1595 Handle<Code> cached_stub; | 1620 Handle<Code> cached_stub; |
| 1596 Handle<Map> transitioned_map = | 1621 Handle<Map> transitioned_map = |
| 1597 receiver_map->FindTransitionedMap(receiver_maps); | 1622 receiver_map->FindTransitionedMap(receiver_maps); |
| 1598 if (!transitioned_map.is_null()) { | 1623 if (!transitioned_map.is_null()) { |
| 1599 cached_stub = ElementsTransitionAndStoreStub( | 1624 cached_stub = ElementsTransitionAndStoreStub( |
| 1600 receiver_map->elements_kind(), // original elements_kind | 1625 receiver_map->elements_kind(), // original elements_kind |
| 1601 transitioned_map->elements_kind(), | 1626 transitioned_map->elements_kind(), |
| 1602 receiver_map->instance_type() == JS_ARRAY_TYPE, // is_js_array | 1627 receiver_map->instance_type() == JS_ARRAY_TYPE, // is_js_array |
| 1603 strict_mode).GetCode(); | 1628 strict_mode, grow_mode).GetCode(); |
| 1604 } else { | 1629 } else { |
| 1605 cached_stub = ComputeMonomorphicStubWithoutMapCheck(receiver_map, | 1630 cached_stub = ComputeMonomorphicStubWithoutMapCheck(receiver_map, |
| 1606 strict_mode); | 1631 strict_mode, |
| 1632 grow_mode); |
| 1607 } | 1633 } |
| 1608 ASSERT(!cached_stub.is_null()); | 1634 ASSERT(!cached_stub.is_null()); |
| 1609 handler_ics.Add(cached_stub); | 1635 handler_ics.Add(cached_stub); |
| 1610 transitioned_maps.Add(transitioned_map); | 1636 transitioned_maps.Add(transitioned_map); |
| 1611 } | 1637 } |
| 1612 KeyedStoreStubCompiler compiler(isolate(), strict_mode); | 1638 KeyedStoreStubCompiler compiler(isolate(), strict_mode, grow_mode); |
| 1613 Handle<Code> code = compiler.CompileStorePolymorphic( | 1639 Handle<Code> code = compiler.CompileStorePolymorphic( |
| 1614 receiver_maps, &handler_ics, &transitioned_maps); | 1640 receiver_maps, &handler_ics, &transitioned_maps); |
| 1615 isolate()->counters()->keyed_store_polymorphic_stubs()->Increment(); | 1641 isolate()->counters()->keyed_store_polymorphic_stubs()->Increment(); |
| 1616 PROFILE(isolate(), | 1642 PROFILE(isolate(), |
| 1617 CodeCreateEvent(Logger::KEYED_STORE_MEGAMORPHIC_IC_TAG, *code, 0)); | 1643 CodeCreateEvent(Logger::KEYED_STORE_MEGAMORPHIC_IC_TAG, *code, 0)); |
| 1618 return code; | 1644 return code; |
| 1619 } | 1645 } |
| 1620 | 1646 |
| 1621 | 1647 |
| 1648 KeyedIC::StubKind KeyedStoreIC::GetStubKind(Handle<JSObject> receiver, |
| 1649 Handle<Object> key, |
| 1650 Handle<Object> value) { |
| 1651 ASSERT(key->IsSmi()); |
| 1652 int index = Smi::cast(*key)->value(); |
| 1653 bool allow_growth = receiver->IsJSArray() && |
| 1654 JSArray::cast(*receiver)->length()->IsSmi() && |
| 1655 index >= Smi::cast(JSArray::cast(*receiver)->length())->value(); |
| 1656 if (allow_growth) { |
| 1657 // Handle growing array in stub if necessary. |
| 1658 if (receiver->HasFastSmiOnlyElements()) { |
| 1659 if (value->IsHeapNumber()) { |
| 1660 return STORE_AND_GROW_TRANSITION_SMI_TO_DOUBLE; |
| 1661 } |
| 1662 if (value->IsHeapObject()) { |
| 1663 return STORE_AND_GROW_TRANSITION_SMI_TO_OBJECT; |
| 1664 } |
| 1665 } else if (receiver->HasFastDoubleElements()) { |
| 1666 if (!value->IsSmi() && !value->IsHeapNumber()) { |
| 1667 return STORE_AND_GROW_TRANSITION_DOUBLE_TO_OBJECT; |
| 1668 } |
| 1669 } |
| 1670 return STORE_AND_GROW_NO_TRANSITION; |
| 1671 } else { |
| 1672 // Handle only in-bounds elements accesses. |
| 1673 if (receiver->HasFastSmiOnlyElements()) { |
| 1674 if (value->IsHeapNumber()) { |
| 1675 return STORE_TRANSITION_SMI_TO_DOUBLE; |
| 1676 } else if (value->IsHeapObject()) { |
| 1677 return STORE_TRANSITION_SMI_TO_OBJECT; |
| 1678 } |
| 1679 } else if (receiver->HasFastDoubleElements()) { |
| 1680 if (!value->IsSmi() && !value->IsHeapNumber()) { |
| 1681 return STORE_TRANSITION_DOUBLE_TO_OBJECT; |
| 1682 } |
| 1683 } |
| 1684 return STORE_NO_TRANSITION; |
| 1685 } |
| 1686 } |
| 1687 |
| 1688 |
| 1622 MaybeObject* KeyedStoreIC::Store(State state, | 1689 MaybeObject* KeyedStoreIC::Store(State state, |
| 1623 StrictModeFlag strict_mode, | 1690 StrictModeFlag strict_mode, |
| 1624 Handle<Object> object, | 1691 Handle<Object> object, |
| 1625 Handle<Object> key, | 1692 Handle<Object> key, |
| 1626 Handle<Object> value, | 1693 Handle<Object> value, |
| 1627 bool force_generic) { | 1694 bool force_generic) { |
| 1628 if (key->IsSymbol()) { | 1695 if (key->IsSymbol()) { |
| 1629 Handle<String> name = Handle<String>::cast(key); | 1696 Handle<String> name = Handle<String>::cast(key); |
| 1630 | 1697 |
| 1631 // Handle proxies. | 1698 // Handle proxies. |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1674 Handle<Code> stub = (strict_mode == kStrictMode) | 1741 Handle<Code> stub = (strict_mode == kStrictMode) |
| 1675 ? generic_stub_strict() | 1742 ? generic_stub_strict() |
| 1676 : generic_stub(); | 1743 : generic_stub(); |
| 1677 if (object->IsJSObject()) { | 1744 if (object->IsJSObject()) { |
| 1678 Handle<JSObject> receiver = Handle<JSObject>::cast(object); | 1745 Handle<JSObject> receiver = Handle<JSObject>::cast(object); |
| 1679 if (receiver->elements()->map() == | 1746 if (receiver->elements()->map() == |
| 1680 isolate()->heap()->non_strict_arguments_elements_map()) { | 1747 isolate()->heap()->non_strict_arguments_elements_map()) { |
| 1681 stub = non_strict_arguments_stub(); | 1748 stub = non_strict_arguments_stub(); |
| 1682 } else if (!force_generic) { | 1749 } else if (!force_generic) { |
| 1683 if (key->IsSmi() && (target() != *non_strict_arguments_stub())) { | 1750 if (key->IsSmi() && (target() != *non_strict_arguments_stub())) { |
| 1684 StubKind stub_kind = STORE_NO_TRANSITION; | 1751 StubKind stub_kind = GetStubKind(receiver, key, value); |
| 1685 if (receiver->GetElementsKind() == FAST_SMI_ONLY_ELEMENTS) { | |
| 1686 if (value->IsHeapNumber()) { | |
| 1687 stub_kind = STORE_TRANSITION_SMI_TO_DOUBLE; | |
| 1688 } else if (value->IsHeapObject()) { | |
| 1689 stub_kind = STORE_TRANSITION_SMI_TO_OBJECT; | |
| 1690 } | |
| 1691 } else if (receiver->GetElementsKind() == FAST_DOUBLE_ELEMENTS) { | |
| 1692 if (!value->IsSmi() && !value->IsHeapNumber()) { | |
| 1693 stub_kind = STORE_TRANSITION_DOUBLE_TO_OBJECT; | |
| 1694 } | |
| 1695 } | |
| 1696 stub = ComputeStub(receiver, stub_kind, strict_mode, stub); | 1752 stub = ComputeStub(receiver, stub_kind, strict_mode, stub); |
| 1697 } | 1753 } |
| 1698 } else { | 1754 } else { |
| 1699 TRACE_GENERIC_IC("KeyedStoreIC", "force generic"); | 1755 TRACE_GENERIC_IC("KeyedStoreIC", "force generic"); |
| 1700 } | 1756 } |
| 1701 } | 1757 } |
| 1702 if (!stub.is_null()) set_target(*stub); | 1758 if (!stub.is_null()) set_target(*stub); |
| 1703 } | 1759 } |
| 1704 | 1760 |
| 1705 TRACE_IC("KeyedStoreIC", key, state, target()); | 1761 TRACE_IC("KeyedStoreIC", key, state, target()); |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1868 | 1924 |
| 1869 | 1925 |
| 1870 // Used from ic-<arch>.cc. | 1926 // Used from ic-<arch>.cc. |
| 1871 RUNTIME_FUNCTION(MaybeObject*, StoreIC_Miss) { | 1927 RUNTIME_FUNCTION(MaybeObject*, StoreIC_Miss) { |
| 1872 HandleScope scope; | 1928 HandleScope scope; |
| 1873 ASSERT(args.length() == 3); | 1929 ASSERT(args.length() == 3); |
| 1874 StoreIC ic(isolate); | 1930 StoreIC ic(isolate); |
| 1875 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); | 1931 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 1876 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); | 1932 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1877 return ic.Store(state, | 1933 return ic.Store(state, |
| 1878 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode), | 1934 Code::GetStrictMode(extra_ic_state), |
| 1879 args.at<Object>(0), | 1935 args.at<Object>(0), |
| 1880 args.at<String>(1), | 1936 args.at<String>(1), |
| 1881 args.at<Object>(2)); | 1937 args.at<Object>(2)); |
| 1882 } | 1938 } |
| 1883 | 1939 |
| 1884 | 1940 |
| 1885 RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) { | 1941 RUNTIME_FUNCTION(MaybeObject*, StoreIC_ArrayLength) { |
| 1886 NoHandleAllocation nha; | 1942 NoHandleAllocation nha; |
| 1887 | 1943 |
| 1888 ASSERT(args.length() == 2); | 1944 ASSERT(args.length() == 2); |
| (...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1944 | 2000 |
| 1945 | 2001 |
| 1946 // Used from ic-<arch>.cc. | 2002 // Used from ic-<arch>.cc. |
| 1947 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Miss) { | 2003 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Miss) { |
| 1948 HandleScope scope(isolate); | 2004 HandleScope scope(isolate); |
| 1949 ASSERT(args.length() == 3); | 2005 ASSERT(args.length() == 3); |
| 1950 KeyedStoreIC ic(isolate); | 2006 KeyedStoreIC ic(isolate); |
| 1951 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); | 2007 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 1952 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); | 2008 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1953 return ic.Store(state, | 2009 return ic.Store(state, |
| 1954 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode), | 2010 Code::GetStrictMode(extra_ic_state), |
| 1955 args.at<Object>(0), | 2011 args.at<Object>(0), |
| 1956 args.at<Object>(1), | 2012 args.at<Object>(1), |
| 1957 args.at<Object>(2), | 2013 args.at<Object>(2), |
| 1958 false); | 2014 false); |
| 1959 } | 2015 } |
| 1960 | 2016 |
| 1961 | 2017 |
| 1962 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Slow) { | 2018 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_Slow) { |
| 1963 NoHandleAllocation na; | 2019 NoHandleAllocation na; |
| 1964 ASSERT(args.length() == 3); | 2020 ASSERT(args.length() == 3); |
| 1965 KeyedStoreIC ic(isolate); | 2021 KeyedStoreIC ic(isolate); |
| 1966 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); | 2022 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1967 Handle<Object> object = args.at<Object>(0); | 2023 Handle<Object> object = args.at<Object>(0); |
| 1968 Handle<Object> key = args.at<Object>(1); | 2024 Handle<Object> key = args.at<Object>(1); |
| 1969 Handle<Object> value = args.at<Object>(2); | 2025 Handle<Object> value = args.at<Object>(2); |
| 1970 StrictModeFlag strict_mode = | 2026 StrictModeFlag strict_mode = Code::GetStrictMode(extra_ic_state); |
| 1971 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode); | |
| 1972 return Runtime::SetObjectProperty(isolate, | 2027 return Runtime::SetObjectProperty(isolate, |
| 1973 object, | 2028 object, |
| 1974 key, | 2029 key, |
| 1975 value, | 2030 value, |
| 1976 NONE, | 2031 NONE, |
| 1977 strict_mode); | 2032 strict_mode); |
| 1978 } | 2033 } |
| 1979 | 2034 |
| 1980 | 2035 |
| 1981 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_MissForceGeneric) { | 2036 RUNTIME_FUNCTION(MaybeObject*, KeyedStoreIC_MissForceGeneric) { |
| 1982 HandleScope scope(isolate); | 2037 HandleScope scope(isolate); |
| 1983 ASSERT(args.length() == 3); | 2038 ASSERT(args.length() == 3); |
| 1984 KeyedStoreIC ic(isolate); | 2039 KeyedStoreIC ic(isolate); |
| 1985 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); | 2040 IC::State state = IC::StateFrom(ic.target(), args[0], args[1]); |
| 1986 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); | 2041 Code::ExtraICState extra_ic_state = ic.target()->extra_ic_state(); |
| 1987 return ic.Store(state, | 2042 return ic.Store(state, |
| 1988 static_cast<StrictModeFlag>(extra_ic_state & kStrictMode), | 2043 Code::GetStrictMode(extra_ic_state), |
| 1989 args.at<Object>(0), | 2044 args.at<Object>(0), |
| 1990 args.at<Object>(1), | 2045 args.at<Object>(1), |
| 1991 args.at<Object>(2), | 2046 args.at<Object>(2), |
| 1992 true); | 2047 true); |
| 1993 } | 2048 } |
| 1994 | 2049 |
| 1995 | 2050 |
| 1996 void UnaryOpIC::patch(Code* code) { | 2051 void UnaryOpIC::patch(Code* code) { |
| 1997 set_target(code); | 2052 set_target(code); |
| 1998 } | 2053 } |
| (...skipping 428 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2427 #undef ADDR | 2482 #undef ADDR |
| 2428 }; | 2483 }; |
| 2429 | 2484 |
| 2430 | 2485 |
| 2431 Address IC::AddressFromUtilityId(IC::UtilityId id) { | 2486 Address IC::AddressFromUtilityId(IC::UtilityId id) { |
| 2432 return IC_utilities[id]; | 2487 return IC_utilities[id]; |
| 2433 } | 2488 } |
| 2434 | 2489 |
| 2435 | 2490 |
| 2436 } } // namespace v8::internal | 2491 } } // namespace v8::internal |
| OLD | NEW |