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

Side by Side Diff: src/objects.cc

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

Powered by Google App Engine
This is Rietveld 408576698