Chromium Code Reviews| Index: src/objects.cc |
| diff --git a/src/objects.cc b/src/objects.cc |
| index d8a6f13307b68fde02432d19acb520d202ec2a6d..ead4e2b9742d6212b7539e62150c14e343424f59 100644 |
| --- a/src/objects.cc |
| +++ b/src/objects.cc |
| @@ -28,6 +28,7 @@ |
| #include "v8.h" |
| #include "accessors.h" |
| +#include "allocation-site-scopes.h" |
| #include "api.h" |
| #include "arguments.h" |
| #include "bootstrapper.h" |
| @@ -5572,6 +5573,16 @@ MUST_USE_RESULT MaybeObject* JSObject::SetObserved(Isolate* isolate) { |
| } |
| +Handle<JSObject> JSObject::Copy(Handle<JSObject> object, |
| + AllocationSiteContext* site_context) { |
| + Isolate* isolate = object->GetIsolate(); |
| + CALL_HEAP_FUNCTION(isolate, |
| + isolate->heap()->CopyJSObject(*object, |
| + *(site_context->current())), |
| + JSObject); |
| +} |
| + |
| + |
| Handle<JSObject> JSObject::Copy(Handle<JSObject> object) { |
| Isolate* isolate = object->GetIsolate(); |
| CALL_HEAP_FUNCTION(isolate, |
| @@ -5581,45 +5592,95 @@ Handle<JSObject> JSObject::Copy(Handle<JSObject> object) { |
| class JSObjectWalkVisitor { |
| public: |
| - explicit JSObjectWalkVisitor() {} |
| + explicit JSObjectWalkVisitor(AllocationSiteContext* site_context) : |
| + site_context_(site_context) {} |
| virtual ~JSObjectWalkVisitor() {} |
| Handle<JSObject> Visit(Handle<JSObject> object) { |
| return StructureWalk(object); |
| } |
| - // Returns true if the visitor is a copying visitor. |
| virtual bool is_copying() = 0; |
| protected: |
| Handle<JSObject> StructureWalk(Handle<JSObject> object); |
| - // The returned handle should point to a new object if the visitor is a |
| - // copying visitor, otherwise it should be the same as the input object. |
| + // The returned handle will be used for the object in all |
| + // subsequent usages. This allows VisitObject to make a copy |
| + // of the object if desired. |
| virtual Handle<JSObject> VisitObject(Handle<JSObject> object) = 0; |
| - |
| - // The returned handle should point to a new value if the visitor is a |
| - // copying visitor, otherwise it should be the same as the input value. |
| virtual Handle<JSObject> VisitElementOrProperty(Handle<JSObject> object, |
| Handle<JSObject> value) = 0; |
| + |
| + AllocationSiteContext* site_context() { return site_context_; } |
| + |
| + private: |
| + AllocationSiteContext* site_context_; |
| }; |
| class JSObjectCopyVisitor: public JSObjectWalkVisitor { |
| public: |
| - explicit JSObjectCopyVisitor() {} |
| + explicit JSObjectCopyVisitor(AllocationSiteContext* site_context) |
| + : JSObjectWalkVisitor(site_context) {} |
| virtual bool is_copying() V8_OVERRIDE { return true; } |
| - protected: |
| + // The returned handle will be used for the object in all |
| + // subsequent usages. This allows VisitObject to make a copy |
| + // of the object if desired. |
| + virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { |
| + // Only create a memento if |
| + // 1) we have a JSArray, and |
|
Hannes Payer (out of office)
2013/10/11 12:55:44
What about JSObject?
mvstanton
2013/10/11 13:41:47
At this moment in the code, we only emit mementos
|
| + // 2) the elements kind is palatable |
| + // 3) allow_mementos is true |
| + Handle<JSObject> copy; |
| + if (site_context()->activated() && |
| + AllocationSite::CanTrack(object->map()->instance_type()) && |
| + AllocationSite::GetMode(object->GetElementsKind()) == |
| + TRACK_ALLOCATION_SITE) { |
| + copy = JSObject::Copy(object, site_context()); |
| + } else { |
| + copy = JSObject::Copy(object); |
| + } |
| + |
| + return copy; |
| + } |
| + |
| + virtual Handle<JSObject> VisitElementOrProperty( |
| + Handle<JSObject> object, |
| + Handle<JSObject> value) V8_OVERRIDE { |
| + AllocationSiteUsageScope scope(site_context(), value); |
| + value = StructureWalk(value); |
| + return value; |
| + } |
| +}; |
| + |
| + |
| +class JSObjectCreateAllocationSitesVisitor: public JSObjectWalkVisitor { |
| + public: |
| + explicit JSObjectCreateAllocationSitesVisitor( |
| + AllocationSiteContext* site_context) |
| + : JSObjectWalkVisitor(site_context) {} |
| + |
| + virtual bool is_copying() V8_OVERRIDE { return false; } |
| + |
| + // The returned handle will be used for the object in all |
| + // subsequent usages. This allows VisitObject to make a copy |
| + // of the object if desired. |
| virtual Handle<JSObject> VisitObject(Handle<JSObject> object) V8_OVERRIDE { |
| - return JSObject::Copy(object); |
| + return object; |
| } |
| virtual Handle<JSObject> VisitElementOrProperty( |
| Handle<JSObject> object, |
| Handle<JSObject> value) V8_OVERRIDE { |
| - return StructureWalk(value); |
| + AllocationSiteCreationScope scope(site_context()); |
| + value = StructureWalk(value); |
| + if (!value.is_null()) { |
| + scope.RecordTransitionInfo(value); |
| + } |
| + return value; |
| } |
| }; |
| @@ -5766,8 +5827,18 @@ Handle<JSObject> JSObjectWalkVisitor::StructureWalk(Handle<JSObject> object) { |
| } |
| -Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object) { |
| - JSObjectCopyVisitor v; |
| +Handle<JSObject> JSObject::DeepWalk(Handle<JSObject> object, |
| + AllocationSiteContext* site_context) { |
| + JSObjectCreateAllocationSitesVisitor v(site_context); |
| + Handle<JSObject> copy = v.Visit(object); |
| + ASSERT(!v.is_copying() && copy.is_identical_to(object)); |
| + return copy; |
| +} |
| + |
| + |
| +Handle<JSObject> JSObject::DeepCopy(Handle<JSObject> object, |
| + AllocationSiteContext* site_context) { |
| + JSObjectCopyVisitor v(site_context); |
| Handle<JSObject> copy = v.Visit(object); |
| ASSERT(v.is_copying() && !copy.is_identical_to(object)); |
| return copy; |
| @@ -12532,8 +12603,10 @@ MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { |
| // Walk through to the Allocation Site |
| AllocationSite* site = memento->GetAllocationSite(); |
| - if (site->IsLiteralSite()) { |
| + if (site->IsLiteralSite() && |
| + site->transition_info()->IsJSArray()) { |
| JSArray* transition_info = JSArray::cast(site->transition_info()); |
| + bool is_nested = !(site->nested_site()->IsSmi()); |
| ElementsKind kind = transition_info->GetElementsKind(); |
| // if kind is holey ensure that to_kind is as well. |
| if (IsHoleyElementsKind(kind)) { |
| @@ -12547,8 +12620,9 @@ MaybeObject* JSObject::UpdateAllocationSite(ElementsKind to_kind) { |
| if (length <= AllocationSite::kMaximumArrayBytesToPretransition) { |
| if (FLAG_trace_track_allocation_sites) { |
| PrintF( |
| - "AllocationSite: JSArray %p boilerplate updated %s->%s\n", |
| + "AllocationSite: JSArray %p boilerplate %s updated %s->%s\n", |
| reinterpret_cast<void*>(this), |
| + is_nested ? "(nested)" : "", |
| ElementsKindToString(kind), |
| ElementsKindToString(to_kind)); |
| } |