OLD | NEW |
1 // Copyright 2013 the V8 project authors. All rights reserved. | 1 // Copyright 2013 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 10 matching lines...) Expand all Loading... |
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 #include "v8.h" | 28 #include "v8.h" |
29 | 29 |
30 #include "accessors.h" | 30 #include "accessors.h" |
| 31 #include "allocation-site-scopes.h" |
31 #include "api.h" | 32 #include "api.h" |
32 #include "arguments.h" | 33 #include "arguments.h" |
33 #include "bootstrapper.h" | 34 #include "bootstrapper.h" |
34 #include "codegen.h" | 35 #include "codegen.h" |
35 #include "cpu-profiler.h" | 36 #include "cpu-profiler.h" |
36 #include "debug.h" | 37 #include "debug.h" |
37 #include "deoptimizer.h" | 38 #include "deoptimizer.h" |
38 #include "date.h" | 39 #include "date.h" |
39 #include "elements.h" | 40 #include "elements.h" |
40 #include "execution.h" | 41 #include "execution.h" |
(...skipping 5557 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5598 MaybeObject* maybe_copy = map()->Copy(); | 5599 MaybeObject* maybe_copy = map()->Copy(); |
5599 if (!maybe_copy->To(&new_map)) return maybe_copy; | 5600 if (!maybe_copy->To(&new_map)) return maybe_copy; |
5600 new_map->set_is_observed(true); | 5601 new_map->set_is_observed(true); |
5601 } | 5602 } |
5602 set_map(new_map); | 5603 set_map(new_map); |
5603 | 5604 |
5604 return heap->undefined_value(); | 5605 return heap->undefined_value(); |
5605 } | 5606 } |
5606 | 5607 |
5607 | 5608 |
| 5609 Handle<JSObject> JSObject::Copy(Handle<JSObject> object, |
| 5610 AllocationSiteContext* site_context) { |
| 5611 Isolate* isolate = object->GetIsolate(); |
| 5612 CALL_HEAP_FUNCTION(isolate, |
| 5613 isolate->heap()->CopyJSObject(*object, |
| 5614 *(site_context->current())), |
| 5615 JSObject); |
| 5616 } |
| 5617 |
| 5618 |
5608 Handle<JSObject> JSObject::Copy(Handle<JSObject> object) { | 5619 Handle<JSObject> JSObject::Copy(Handle<JSObject> object) { |
5609 Isolate* isolate = object->GetIsolate(); | 5620 Isolate* isolate = object->GetIsolate(); |
5610 CALL_HEAP_FUNCTION(isolate, | 5621 CALL_HEAP_FUNCTION(isolate, |
5611 isolate->heap()->CopyJSObject(*object), JSObject); | 5622 isolate->heap()->CopyJSObject(*object), JSObject); |
5612 } | 5623 } |
5613 | 5624 |
5614 | 5625 |
5615 class JSObjectWalkVisitor { | 5626 class JSObjectWalkVisitor { |
5616 public: | 5627 public: |
5617 explicit JSObjectWalkVisitor() {} | 5628 explicit JSObjectWalkVisitor(AllocationSiteContext* site_context) : |
| 5629 site_context_(site_context) {} |
5618 virtual ~JSObjectWalkVisitor() {} | 5630 virtual ~JSObjectWalkVisitor() {} |
5619 | 5631 |
5620 Handle<JSObject> Visit(Handle<JSObject> object) { | 5632 Handle<JSObject> Visit(Handle<JSObject> object) { |
5621 return StructureWalk(object); | 5633 return StructureWalk(object); |
5622 } | 5634 } |
5623 | 5635 |
5624 // Returns true if the visitor is a copying visitor. | |
5625 virtual bool is_copying() = 0; | 5636 virtual bool is_copying() = 0; |
5626 | 5637 |
5627 protected: | 5638 protected: |
5628 Handle<JSObject> StructureWalk(Handle<JSObject> object); | 5639 Handle<JSObject> StructureWalk(Handle<JSObject> object); |
5629 | 5640 |
5630 // The returned handle should point to a new object if the visitor is a | 5641 // The returned handle will be used for the object in all |
5631 // copying visitor, otherwise it should be the same as the input object. | 5642 // subsequent usages. This allows VisitObject to make a copy |
| 5643 // of the object if desired. |
5632 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) = 0; | 5644 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) = 0; |
5633 | |
5634 // The returned handle should point to a new value if the visitor is a | |
5635 // copying visitor, otherwise it should be the same as the input value. | |
5636 virtual Handle<JSObject> VisitElementOrProperty(Handle<JSObject> object, | 5645 virtual Handle<JSObject> VisitElementOrProperty(Handle<JSObject> object, |
5637 Handle<JSObject> value) = 0; | 5646 Handle<JSObject> value) = 0; |
| 5647 |
| 5648 AllocationSiteContext* site_context() { return site_context_; } |
| 5649 |
| 5650 private: |
| 5651 AllocationSiteContext* site_context_; |
5638 }; | 5652 }; |
5639 | 5653 |
5640 | 5654 |
5641 class JSObjectCopyVisitor: public JSObjectWalkVisitor { | 5655 class JSObjectCopyVisitor: public JSObjectWalkVisitor { |
5642 public: | 5656 public: |
5643 explicit JSObjectCopyVisitor() {} | 5657 explicit JSObjectCopyVisitor(AllocationSiteContext* site_context) |
| 5658 : JSObjectWalkVisitor(site_context) {} |
5644 | 5659 |
5645 virtual bool is_copying() V8_OVERRIDE { return true; } | 5660 virtual bool is_copying() V8_OVERRIDE { return true; } |
5646 | 5661 |
5647 protected: | 5662 // The returned handle will be used for the object in all |
| 5663 // subsequent usages. This allows VisitObject to make a copy |
| 5664 // of the object if desired. |
5648 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { | 5665 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { |
5649 return JSObject::Copy(object); | 5666 // Only create a memento if |
| 5667 // 1) we have a JSArray, and |
| 5668 // 2) the elements kind is palatable |
| 5669 // 3) allow_mementos is true |
| 5670 Handle<JSObject> copy; |
| 5671 if (site_context()->activated() && |
| 5672 AllocationSite::CanTrack(object->map()->instance_type()) && |
| 5673 AllocationSite::GetMode(object->GetElementsKind()) == |
| 5674 TRACK_ALLOCATION_SITE) { |
| 5675 copy = JSObject::Copy(object, site_context()); |
| 5676 } else { |
| 5677 copy = JSObject::Copy(object); |
| 5678 } |
| 5679 |
| 5680 return copy; |
5650 } | 5681 } |
5651 | 5682 |
5652 virtual Handle<JSObject> VisitElementOrProperty( | 5683 virtual Handle<JSObject> VisitElementOrProperty( |
5653 Handle<JSObject> object, | 5684 Handle<JSObject> object, |
5654 Handle<JSObject> value) V8_OVERRIDE { | 5685 Handle<JSObject> value) V8_OVERRIDE { |
5655 return StructureWalk(value); | 5686 AllocationSiteUsageScope scope(site_context(), value); |
| 5687 value = StructureWalk(value); |
| 5688 return value; |
5656 } | 5689 } |
5657 }; | 5690 }; |
5658 | 5691 |
| 5692 |
| 5693 class JSObjectCreateAllocationSitesVisitor: public JSObjectWalkVisitor { |
| 5694 public: |
| 5695 explicit JSObjectCreateAllocationSitesVisitor( |
| 5696 AllocationSiteContext* site_context) |
| 5697 : JSObjectWalkVisitor(site_context) {} |
| 5698 |
| 5699 virtual bool is_copying() V8_OVERRIDE { return false; } |
| 5700 |
| 5701 // The returned handle will be used for the object in all |
| 5702 // subsequent usages. This allows VisitObject to make a copy |
| 5703 // of the object if desired. |
| 5704 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { |
| 5705 return object; |
| 5706 } |
| 5707 |
| 5708 virtual Handle<JSObject> VisitElementOrProperty( |
| 5709 Handle<JSObject> object, |
| 5710 Handle<JSObject> value) V8_OVERRIDE { |
| 5711 AllocationSiteCreationScope scope(site_context()); |
| 5712 value = StructureWalk(value); |
| 5713 if (!value.is_null()) { |
| 5714 scope.RecordTransitionInfo(value); |
| 5715 } |
| 5716 return value; |
| 5717 } |
| 5718 }; |
| 5719 |
5659 | 5720 |
5660 Handle<JSObject> JSObjectWalkVisitor::StructureWalk(Handle<JSObject> object) { | 5721 Handle<JSObject> JSObjectWalkVisitor::StructureWalk(Handle<JSObject> object) { |
5661 bool copying = is_copying(); | 5722 bool copying = is_copying(); |
5662 Isolate* isolate = object->GetIsolate(); | 5723 Isolate* isolate = object->GetIsolate(); |
5663 StackLimitCheck check(isolate); | 5724 StackLimitCheck check(isolate); |
5664 if (check.HasOverflowed()) { | 5725 if (check.HasOverflowed()) { |
5665 isolate->StackOverflow(); | 5726 isolate->StackOverflow(); |
5666 return Handle<JSObject>::null(); | 5727 return Handle<JSObject>::null(); |
5667 } | 5728 } |
5668 | 5729 |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5792 case EXTERNAL_DOUBLE_ELEMENTS: | 5853 case EXTERNAL_DOUBLE_ELEMENTS: |
5793 case FAST_DOUBLE_ELEMENTS: | 5854 case FAST_DOUBLE_ELEMENTS: |
5794 case FAST_HOLEY_DOUBLE_ELEMENTS: | 5855 case FAST_HOLEY_DOUBLE_ELEMENTS: |
5795 // No contained objects, nothing to do. | 5856 // No contained objects, nothing to do. |
5796 break; | 5857 break; |
5797 } | 5858 } |
5798 return copy; | 5859 return copy; |
5799 } | 5860 } |
5800 | 5861 |
5801 | 5862 |
5802 Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object) { | 5863 Handle<JSObject> JSObject::DeepWalk(Handle<JSObject> object, |
5803 JSObjectCopyVisitor v; | 5864 AllocationSiteContext* site_context) { |
| 5865 JSObjectCreateAllocationSitesVisitor v(site_context); |
| 5866 Handle<JSObject> copy = v.Visit(object); |
| 5867 ASSERT(!v.is_copying() && copy.is_identical_to(object)); |
| 5868 return copy; |
| 5869 } |
| 5870 |
| 5871 |
| 5872 Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object, |
| 5873 AllocationSiteContext* site_context) { |
| 5874 JSObjectCopyVisitor v(site_context); |
5804 Handle<JSObject> copy = v.Visit(object); | 5875 Handle<JSObject> copy = v.Visit(object); |
5805 ASSERT(v.is_copying() && !copy.is_identical_to(object)); | 5876 ASSERT(v.is_copying() && !copy.is_identical_to(object)); |
5806 return copy; | 5877 return copy; |
5807 } | 5878 } |
5808 | 5879 |
5809 | 5880 |
5810 // Tests for the fast common case for property enumeration: | 5881 // Tests for the fast common case for property enumeration: |
5811 // - This object and all prototypes has an enum cache (which means that | 5882 // - This object and all prototypes has an enum cache (which means that |
5812 // it is no proxy, has no interceptors and needs no access checks). | 5883 // it is no proxy, has no interceptors and needs no access checks). |
5813 // - This object has no elements. | 5884 // - This object has no elements. |
(...skipping 6732 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
12546 } | 12617 } |
12547 | 12618 |
12548 | 12619 |
12549 void JSObject::TransitionElementsKind(Handle<JSObject> object, | 12620 void JSObject::TransitionElementsKind(Handle<JSObject> object, |
12550 ElementsKind to_kind) { | 12621 ElementsKind to_kind) { |
12551 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), | 12622 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), |
12552 object->TransitionElementsKind(to_kind)); | 12623 object->TransitionElementsKind(to_kind)); |
12553 } | 12624 } |
12554 | 12625 |
12555 | 12626 |
| 12627 bool AllocationSite::IsNestedSite() { |
| 12628 ASSERT(FLAG_trace_track_allocation_sites); |
| 12629 Object* current = GetHeap()->allocation_sites_list(); |
| 12630 while (current != NULL && current->IsAllocationSite()) { |
| 12631 AllocationSite* current_site = AllocationSite::cast(current); |
| 12632 if (current_site->nested_site() == this) { |
| 12633 return true; |
| 12634 } |
| 12635 current = current_site->weak_next(); |
| 12636 } |
| 12637 return false; |
| 12638 } |
| 12639 |
| 12640 |
12556 MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { | 12641 MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { |
12557 if (!FLAG_track_allocation_sites || !IsJSArray()) { | 12642 if (!FLAG_track_allocation_sites || !IsJSArray()) { |
12558 return this; | 12643 return this; |
12559 } | 12644 } |
12560 | 12645 |
12561 AllocationMemento* memento = AllocationMemento::FindForJSObject(this); | 12646 AllocationMemento* memento = AllocationMemento::FindForJSObject(this); |
12562 if (memento == NULL || !memento->IsValid()) { | 12647 if (memento == NULL || !memento->IsValid()) { |
12563 return this; | 12648 return this; |
12564 } | 12649 } |
12565 | 12650 |
12566 // Walk through to the Allocation Site | 12651 // Walk through to the Allocation Site |
12567 AllocationSite* site = memento->GetAllocationSite(); | 12652 AllocationSite* site = memento->GetAllocationSite(); |
12568 if (site->IsLiteralSite()) { | 12653 if (site->SitePointsToLiteral() && |
| 12654 site->transition_info()->IsJSArray()) { |
12569 JSArray* transition_info = JSArray::cast(site->transition_info()); | 12655 JSArray* transition_info = JSArray::cast(site->transition_info()); |
12570 ElementsKind kind = transition_info->GetElementsKind(); | 12656 ElementsKind kind = transition_info->GetElementsKind(); |
12571 // if kind is holey ensure that to_kind is as well. | 12657 // if kind is holey ensure that to_kind is as well. |
12572 if (IsHoleyElementsKind(kind)) { | 12658 if (IsHoleyElementsKind(kind)) { |
12573 to_kind = GetHoleyElementsKind(to_kind); | 12659 to_kind = GetHoleyElementsKind(to_kind); |
12574 } | 12660 } |
12575 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { | 12661 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { |
12576 // If the array is huge, it's not likely to be defined in a local | 12662 // If the array is huge, it's not likely to be defined in a local |
12577 // function, so we shouldn't make new instances of it very often. | 12663 // function, so we shouldn't make new instances of it very often. |
12578 uint32_t length = 0; | 12664 uint32_t length = 0; |
12579 CHECK(transition_info->length()->ToArrayIndex(&length)); | 12665 CHECK(transition_info->length()->ToArrayIndex(&length)); |
12580 if (length <= AllocationSite::kMaximumArrayBytesToPretransition) { | 12666 if (length <= AllocationSite::kMaximumArrayBytesToPretransition) { |
12581 if (FLAG_trace_track_allocation_sites) { | 12667 if (FLAG_trace_track_allocation_sites) { |
| 12668 bool is_nested = site->IsNestedSite(); |
12582 PrintF( | 12669 PrintF( |
12583 "AllocationSite: JSArray %p boilerplate updated %s->%s\n", | 12670 "AllocationSite: JSArray %p boilerplate %s updated %s->%s\n", |
12584 reinterpret_cast<void*>(this), | 12671 reinterpret_cast<void*>(this), |
| 12672 is_nested ? "(nested)" : "", |
12585 ElementsKindToString(kind), | 12673 ElementsKindToString(kind), |
12586 ElementsKindToString(to_kind)); | 12674 ElementsKindToString(to_kind)); |
12587 } | 12675 } |
12588 return transition_info->TransitionElementsKind(to_kind); | 12676 return transition_info->TransitionElementsKind(to_kind); |
12589 } | 12677 } |
12590 } | 12678 } |
12591 } else { | 12679 } else { |
12592 ElementsKind kind = site->GetElementsKind(); | 12680 ElementsKind kind = site->GetElementsKind(); |
12593 // if kind is holey ensure that to_kind is as well. | 12681 // if kind is holey ensure that to_kind is as well. |
12594 if (IsHoleyElementsKind(kind)) { | 12682 if (IsHoleyElementsKind(kind)) { |
(...skipping 3659 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
16254 #define ERROR_MESSAGES_TEXTS(C, T) T, | 16342 #define ERROR_MESSAGES_TEXTS(C, T) T, |
16255 static const char* error_messages_[] = { | 16343 static const char* error_messages_[] = { |
16256 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) | 16344 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) |
16257 }; | 16345 }; |
16258 #undef ERROR_MESSAGES_TEXTS | 16346 #undef ERROR_MESSAGES_TEXTS |
16259 return error_messages_[reason]; | 16347 return error_messages_[reason]; |
16260 } | 16348 } |
16261 | 16349 |
16262 | 16350 |
16263 } } // namespace v8::internal | 16351 } } // namespace v8::internal |
OLD | NEW |