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

Side by Side Diff: src/objects.cc

Issue 26539010: Revert "AllocationSites for all literals" (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('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 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"
32 #include "api.h" 31 #include "api.h"
33 #include "arguments.h" 32 #include "arguments.h"
34 #include "bootstrapper.h" 33 #include "bootstrapper.h"
35 #include "codegen.h" 34 #include "codegen.h"
36 #include "cpu-profiler.h" 35 #include "cpu-profiler.h"
37 #include "debug.h" 36 #include "debug.h"
38 #include "deoptimizer.h" 37 #include "deoptimizer.h"
39 #include "date.h" 38 #include "date.h"
40 #include "elements.h" 39 #include "elements.h"
41 #include "execution.h" 40 #include "execution.h"
(...skipping 5567 matching lines...) Expand 10 before | Expand all | Expand 10 after
5609 MaybeObject* maybe_copy = map()->Copy(); 5608 MaybeObject* maybe_copy = map()->Copy();
5610 if (!maybe_copy->To(&new_map)) return maybe_copy; 5609 if (!maybe_copy->To(&new_map)) return maybe_copy;
5611 new_map->set_is_observed(true); 5610 new_map->set_is_observed(true);
5612 } 5611 }
5613 set_map(new_map); 5612 set_map(new_map);
5614 5613
5615 return heap->undefined_value(); 5614 return heap->undefined_value();
5616 } 5615 }
5617 5616
5618 5617
5619 Handle<JSObject> JSObject::Copy(Handle<JSObject> object,
5620 Handle<AllocationSite> site) {
5621 Isolate* isolate = object->GetIsolate();
5622 CALL_HEAP_FUNCTION(isolate,
5623 isolate->heap()->CopyJSObject(*object, *site), JSObject);
5624 }
5625
5626
5627 Handle<JSObject> JSObject::Copy(Handle<JSObject> object) { 5618 Handle<JSObject> JSObject::Copy(Handle<JSObject> object) {
5628 Isolate* isolate = object->GetIsolate(); 5619 Isolate* isolate = object->GetIsolate();
5629 CALL_HEAP_FUNCTION(isolate, 5620 CALL_HEAP_FUNCTION(isolate,
5630 isolate->heap()->CopyJSObject(*object), JSObject); 5621 isolate->heap()->CopyJSObject(*object), JSObject);
5631 } 5622 }
5632 5623
5633 5624
5634 class JSObjectWalkVisitor { 5625 class JSObjectWalkVisitor {
5635 public: 5626 public:
5636 explicit JSObjectWalkVisitor(AllocationSiteContext* site_context) : 5627 explicit JSObjectWalkVisitor() {}
5637 site_context_(site_context) {}
5638 virtual ~JSObjectWalkVisitor() {} 5628 virtual ~JSObjectWalkVisitor() {}
5639 5629
5640 Handle<JSObject> Visit(Handle<JSObject> object) { 5630 Handle<JSObject> Visit(Handle<JSObject> object) {
5641 return StructureWalk(object); 5631 return StructureWalk(object);
5642 } 5632 }
5643 5633
5634 // Returns true if the visitor is a copying visitor.
5644 virtual bool is_copying() = 0; 5635 virtual bool is_copying() = 0;
5645 5636
5646 protected: 5637 protected:
5647 Handle<JSObject> StructureWalk(Handle<JSObject> object); 5638 Handle<JSObject> StructureWalk(Handle<JSObject> object);
5648 5639
5649 // The returned handle will be used for the object in all subsequent usages. 5640 // The returned handle should point to a new object if the visitor is a
5650 // This allows VisitObject to make a copy of the object if desired. 5641 // copying visitor, otherwise it should be the same as the input object.
5651 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) = 0; 5642 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) = 0;
5643
5644 // The returned handle should point to a new value if the visitor is a
5645 // copying visitor, otherwise it should be the same as the input value.
5652 virtual Handle<JSObject> VisitElementOrProperty(Handle<JSObject> object, 5646 virtual Handle<JSObject> VisitElementOrProperty(Handle<JSObject> object,
5653 Handle<JSObject> value) = 0; 5647 Handle<JSObject> value) = 0;
5654
5655 AllocationSiteContext* site_context() { return site_context_; }
5656
5657 private:
5658 AllocationSiteContext* site_context_;
5659 }; 5648 };
5660 5649
5661 5650
5662 class JSObjectCopyVisitor: public JSObjectWalkVisitor { 5651 class JSObjectCopyVisitor: public JSObjectWalkVisitor {
5663 public: 5652 public:
5664 explicit JSObjectCopyVisitor(AllocationSiteContext* site_context) 5653 explicit JSObjectCopyVisitor() {}
5665 : JSObjectWalkVisitor(site_context) {}
5666 5654
5667 virtual bool is_copying() V8_OVERRIDE { return true; } 5655 virtual bool is_copying() V8_OVERRIDE { return true; }
5668 5656
5669 // The returned handle will be used for the object in all 5657 protected:
5670 // subsequent usages. This allows VisitObject to make a copy
5671 // of the object if desired.
5672 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { 5658 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE {
5673 // Only create a memento if 5659 return JSObject::Copy(object);
5674 // 1) we have a JSArray, and
5675 // 2) the elements kind is palatable
5676 // 3) allow_mementos is true
5677 Handle<JSObject> copy;
5678 if (site_context()->activated() &&
5679 AllocationSite::CanTrack(object->map()->instance_type()) &&
5680 AllocationSite::GetMode(object->GetElementsKind()) ==
5681 TRACK_ALLOCATION_SITE) {
5682 copy = JSObject::Copy(object, site_context()->current());
5683 } else {
5684 copy = JSObject::Copy(object);
5685 }
5686
5687 return copy;
5688 } 5660 }
5689 5661
5690 virtual Handle<JSObject> VisitElementOrProperty( 5662 virtual Handle<JSObject> VisitElementOrProperty(
5691 Handle<JSObject> object, 5663 Handle<JSObject> object,
5692 Handle<JSObject> value) V8_OVERRIDE { 5664 Handle<JSObject> value) V8_OVERRIDE {
5693 Handle<AllocationSite> current_site = site_context()->EnterNewScope(); 5665 return StructureWalk(value);
5694 Handle<JSObject> copy_of_value = StructureWalk(value);
5695 site_context()->ExitScope(current_site, value);
5696 return copy_of_value;
5697 } 5666 }
5698 }; 5667 };
5699 5668
5700
5701 class JSObjectCreateAllocationSitesVisitor: public JSObjectWalkVisitor {
5702 public:
5703 explicit JSObjectCreateAllocationSitesVisitor(
5704 AllocationSiteContext* site_context)
5705 : JSObjectWalkVisitor(site_context) {}
5706
5707 virtual bool is_copying() V8_OVERRIDE { return false; }
5708
5709 // The returned handle will be used for the object in all
5710 // subsequent usages. This allows VisitObject to make a copy
5711 // of the object if desired.
5712 virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE {
5713 return object;
5714 }
5715
5716 virtual Handle<JSObject> VisitElementOrProperty(
5717 Handle<JSObject> object,
5718 Handle<JSObject> value) V8_OVERRIDE {
5719 Handle<AllocationSite> current_site = site_context()->EnterNewScope();
5720 value = StructureWalk(value);
5721 site_context()->ExitScope(current_site, value);
5722 return value;
5723 }
5724 };
5725
5726 5669
5727 Handle<JSObject> JSObjectWalkVisitor::StructureWalk(Handle<JSObject> object) { 5670 Handle<JSObject> JSObjectWalkVisitor::StructureWalk(Handle<JSObject> object) {
5728 bool copying = is_copying(); 5671 bool copying = is_copying();
5729 Isolate* isolate = object->GetIsolate(); 5672 Isolate* isolate = object->GetIsolate();
5730 StackLimitCheck check(isolate); 5673 StackLimitCheck check(isolate);
5731 if (check.HasOverflowed()) { 5674 if (check.HasOverflowed()) {
5732 isolate->StackOverflow(); 5675 isolate->StackOverflow();
5733 return Handle<JSObject>::null(); 5676 return Handle<JSObject>::null();
5734 } 5677 }
5735 5678
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after
5859 case EXTERNAL_DOUBLE_ELEMENTS: 5802 case EXTERNAL_DOUBLE_ELEMENTS:
5860 case FAST_DOUBLE_ELEMENTS: 5803 case FAST_DOUBLE_ELEMENTS:
5861 case FAST_HOLEY_DOUBLE_ELEMENTS: 5804 case FAST_HOLEY_DOUBLE_ELEMENTS:
5862 // No contained objects, nothing to do. 5805 // No contained objects, nothing to do.
5863 break; 5806 break;
5864 } 5807 }
5865 return copy; 5808 return copy;
5866 } 5809 }
5867 5810
5868 5811
5869 Handle<JSObject> JSObject::DeepWalk(Handle<JSObject> object, 5812 Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object) {
5870 AllocationSiteContext* site_context) { 5813 JSObjectCopyVisitor v;
5871 JSObjectCreateAllocationSitesVisitor v(site_context);
5872 Handle<JSObject> copy = v.Visit(object);
5873 ASSERT(!v.is_copying() && copy.is_identical_to(object));
5874 return copy;
5875 }
5876
5877
5878 Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object,
5879 AllocationSiteContext* site_context) {
5880 JSObjectCopyVisitor v(site_context);
5881 Handle<JSObject> copy = v.Visit(object); 5814 Handle<JSObject> copy = v.Visit(object);
5882 ASSERT(v.is_copying() && !copy.is_identical_to(object)); 5815 ASSERT(v.is_copying() && !copy.is_identical_to(object));
5883 return copy; 5816 return copy;
5884 } 5817 }
5885 5818
5886 5819
5887 // Tests for the fast common case for property enumeration: 5820 // Tests for the fast common case for property enumeration:
5888 // - This object and all prototypes has an enum cache (which means that 5821 // - This object and all prototypes has an enum cache (which means that
5889 // it is no proxy, has no interceptors and needs no access checks). 5822 // it is no proxy, has no interceptors and needs no access checks).
5890 // - This object has no elements. 5823 // - This object has no elements.
(...skipping 6742 matching lines...) Expand 10 before | Expand all | Expand 10 after
12633 } 12566 }
12634 12567
12635 12568
12636 void JSObject::TransitionElementsKind(Handle<JSObject> object, 12569 void JSObject::TransitionElementsKind(Handle<JSObject> object,
12637 ElementsKind to_kind) { 12570 ElementsKind to_kind) {
12638 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(), 12571 CALL_HEAP_FUNCTION_VOID(object->GetIsolate(),
12639 object->TransitionElementsKind(to_kind)); 12572 object->TransitionElementsKind(to_kind));
12640 } 12573 }
12641 12574
12642 12575
12643 bool AllocationSite::IsNestedSite() {
12644 ASSERT(FLAG_trace_track_allocation_sites);
12645 Object* current = GetHeap()->allocation_sites_list();
12646 while (current != NULL && current->IsAllocationSite()) {
12647 AllocationSite* current_site = AllocationSite::cast(current);
12648 if (current_site->nested_site() == this) {
12649 return true;
12650 }
12651 current = current_site->weak_next();
12652 }
12653 return false;
12654 }
12655
12656
12657 MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { 12576 MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) {
12658 if (!FLAG_track_allocation_sites || !IsJSArray()) { 12577 if (!FLAG_track_allocation_sites || !IsJSArray()) {
12659 return this; 12578 return this;
12660 } 12579 }
12661 12580
12662 AllocationMemento* memento = AllocationMemento::FindForJSObject(this); 12581 AllocationMemento* memento = AllocationMemento::FindForJSObject(this);
12663 if (memento == NULL || !memento->IsValid()) { 12582 if (memento == NULL || !memento->IsValid()) {
12664 return this; 12583 return this;
12665 } 12584 }
12666 12585
12667 // Walk through to the Allocation Site 12586 // Walk through to the Allocation Site
12668 AllocationSite* site = memento->GetAllocationSite(); 12587 AllocationSite* site = memento->GetAllocationSite();
12669 if (site->SitePointsToLiteral() && 12588 if (site->IsLiteralSite()) {
12670 site->transition_info()->IsJSArray()) {
12671 JSArray* transition_info = JSArray::cast(site->transition_info()); 12589 JSArray* transition_info = JSArray::cast(site->transition_info());
12672 ElementsKind kind = transition_info->GetElementsKind(); 12590 ElementsKind kind = transition_info->GetElementsKind();
12673 // if kind is holey ensure that to_kind is as well. 12591 // if kind is holey ensure that to_kind is as well.
12674 if (IsHoleyElementsKind(kind)) { 12592 if (IsHoleyElementsKind(kind)) {
12675 to_kind = GetHoleyElementsKind(to_kind); 12593 to_kind = GetHoleyElementsKind(to_kind);
12676 } 12594 }
12677 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) { 12595 if (IsMoreGeneralElementsKindTransition(kind, to_kind)) {
12678 // If the array is huge, it's not likely to be defined in a local 12596 // If the array is huge, it's not likely to be defined in a local
12679 // function, so we shouldn't make new instances of it very often. 12597 // function, so we shouldn't make new instances of it very often.
12680 uint32_t length = 0; 12598 uint32_t length = 0;
12681 CHECK(transition_info->length()->ToArrayIndex(&length)); 12599 CHECK(transition_info->length()->ToArrayIndex(&length));
12682 if (length <= AllocationSite::kMaximumArrayBytesToPretransition) { 12600 if (length <= AllocationSite::kMaximumArrayBytesToPretransition) {
12683 if (FLAG_trace_track_allocation_sites) { 12601 if (FLAG_trace_track_allocation_sites) {
12684 bool is_nested = site->IsNestedSite();
12685 PrintF( 12602 PrintF(
12686 "AllocationSite: JSArray %p boilerplate %s updated %s->%s\n", 12603 "AllocationSite: JSArray %p boilerplate updated %s->%s\n",
12687 reinterpret_cast<void*>(this), 12604 reinterpret_cast<void*>(this),
12688 is_nested ? "(nested)" : "",
12689 ElementsKindToString(kind), 12605 ElementsKindToString(kind),
12690 ElementsKindToString(to_kind)); 12606 ElementsKindToString(to_kind));
12691 } 12607 }
12692 return transition_info->TransitionElementsKind(to_kind); 12608 return transition_info->TransitionElementsKind(to_kind);
12693 } 12609 }
12694 } 12610 }
12695 } else { 12611 } else {
12696 ElementsKind kind = site->GetElementsKind(); 12612 ElementsKind kind = site->GetElementsKind();
12697 // if kind is holey ensure that to_kind is as well. 12613 // if kind is holey ensure that to_kind is as well.
12698 if (IsHoleyElementsKind(kind)) { 12614 if (IsHoleyElementsKind(kind)) {
(...skipping 3659 matching lines...) Expand 10 before | Expand all | Expand 10 after
16358 #define ERROR_MESSAGES_TEXTS(C, T) T, 16274 #define ERROR_MESSAGES_TEXTS(C, T) T,
16359 static const char* error_messages_[] = { 16275 static const char* error_messages_[] = {
16360 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS) 16276 ERROR_MESSAGES_LIST(ERROR_MESSAGES_TEXTS)
16361 }; 16277 };
16362 #undef ERROR_MESSAGES_TEXTS 16278 #undef ERROR_MESSAGES_TEXTS
16363 return error_messages_[reason]; 16279 return error_messages_[reason];
16364 } 16280 }
16365 16281
16366 16282
16367 } } // namespace v8::internal 16283 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects.h ('k') | src/runtime.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698