[runtime] Move 'copying' flag to ContextObject, don't copy named properties for array boilerplates

Bug: 
Change-Id: Ie754efaec80eb175ac18c328c750524009ca8e60
Reviewed-on: https://chromium-review.googlesource.com/517104
Reviewed-by: Igor Sheludko <ishell@chromium.org>
Commit-Queue: Toon Verwaest <verwaest@chromium.org>
Cr-Commit-Position: refs/heads/master@{#45572}
This commit is contained in:
Toon Verwaest 2017-05-26 15:08:16 +02:00 committed by Commit Bot
parent b853d7fbb3
commit fa2ed010e6
2 changed files with 68 additions and 71 deletions

View File

@ -53,6 +53,7 @@ class AllocationSiteCreationContext : public AllocationSiteContext {
Handle<AllocationSite> EnterNewScope();
void ExitScope(Handle<AllocationSite> site, Handle<JSObject> object);
static const bool kCopying = false;
};
@ -86,6 +87,7 @@ class AllocationSiteUsageContext : public AllocationSiteContext {
}
bool ShouldCreateMemento(Handle<JSObject> object);
static const bool kCopying = true;
private:
Handle<AllocationSite> top_site_;

View File

@ -7886,11 +7886,9 @@ Handle<Object> JSObject::FastPropertyAt(Handle<JSObject> object,
template <class ContextObject>
class JSObjectWalkVisitor {
public:
JSObjectWalkVisitor(ContextObject* site_context, bool copying,
JSObjectWalkVisitor(ContextObject* site_context,
JSObject::DeepCopyHints hints)
: site_context_(site_context),
copying_(copying),
hints_(hints) {}
: site_context_(site_context), hints_(hints) {}
MUST_USE_RESULT MaybeHandle<JSObject> StructureWalk(Handle<JSObject> object);
@ -7907,11 +7905,8 @@ class JSObjectWalkVisitor {
inline ContextObject* site_context() { return site_context_; }
inline Isolate* isolate() { return site_context()->isolate(); }
inline bool copying() const { return copying_; }
private:
ContextObject* site_context_;
const bool copying_;
const JSObject::DeepCopyHints hints_;
};
@ -7919,7 +7914,7 @@ template <class ContextObject>
MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
Handle<JSObject> object) {
Isolate* isolate = this->isolate();
bool copying = this->copying();
bool copying = ContextObject::kCopying;
bool shallow = hints_ == JSObject::kObjectIsShallow;
if (!shallow) {
@ -7958,33 +7953,32 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
isolate->counters()->cow_arrays_created_runtime()->Increment();
}
if (!shallow) {
if (shallow) return copy;
HandleScope scope(isolate);
// Deep copy own properties.
// Deep copy own properties. Arrays only have 1 property "length".
if (!copy->IsJSArray()) {
if (copy->HasFastProperties()) {
Handle<DescriptorArray> descriptors(copy->map()->instance_descriptors());
// Skip the length field of JSArrays.
int i = copy->IsJSArray() ? 1 : 0;
int limit = copy->map()->NumberOfOwnDescriptors();
for (; i < limit; i++) {
for (int i = 0; i < limit; i++) {
DCHECK_EQ(kField, descriptors->GetDetails(i).location());
DCHECK_EQ(kData, descriptors->GetDetails(i).kind());
FieldIndex index = FieldIndex::ForDescriptor(copy->map(), i);
if (copy->IsUnboxedDoubleField(index)) continue;
Object* raw = copy->RawFastPropertyAt(index);
if (raw->IsMutableHeapNumber()) {
if (!copying) continue;
if (raw->IsJSObject()) {
Handle<JSObject> value(JSObject::cast(raw), isolate);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, value, VisitElementOrProperty(copy, value), JSObject);
if (copying) copy->FastPropertyAtPut(index, *value);
} else if (copying && raw->IsMutableHeapNumber()) {
DCHECK(descriptors->GetDetails(i).representation().IsDouble());
uint64_t double_value = HeapNumber::cast(raw)->value_as_bits();
Handle<HeapNumber> value = isolate->factory()->NewHeapNumber(MUTABLE);
value->set_value_as_bits(double_value);
copy->FastPropertyAtPut(index, *value);
} else if (raw->IsJSObject()) {
Handle<JSObject> value(JSObject::cast(raw), isolate);
ASSIGN_RETURN_ON_EXCEPTION(
isolate, value, VisitElementOrProperty(copy, value), JSObject);
if (copying) copy->FastPropertyAtPut(index, *value);
}
}
} else {
@ -8000,6 +7994,10 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
}
}
// Assume non-arrays don't end up having elements.
if (copy->elements()->length() == 0) return copy;
}
// Deep copy own elements.
switch (kind) {
case FAST_ELEMENTS:
@ -8046,8 +8044,7 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
UNREACHABLE();
break;
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) \
case TYPE##_ELEMENTS: \
#define TYPED_ARRAY_CASE(Type, type, TYPE, ctype, size) case TYPE##_ELEMENTS:
TYPED_ARRAYS(TYPED_ARRAY_CASE)
#undef TYPED_ARRAY_CASE
@ -8063,7 +8060,6 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
// No contained objects, nothing to do.
break;
}
}
return copy;
}
@ -8072,8 +8068,7 @@ MaybeHandle<JSObject> JSObjectWalkVisitor<ContextObject>::StructureWalk(
MaybeHandle<JSObject> JSObject::DeepWalk(
Handle<JSObject> object,
AllocationSiteCreationContext* site_context) {
JSObjectWalkVisitor<AllocationSiteCreationContext> v(site_context, false,
kNoHints);
JSObjectWalkVisitor<AllocationSiteCreationContext> v(site_context, kNoHints);
MaybeHandle<JSObject> result = v.StructureWalk(object);
Handle<JSObject> for_assert;
DCHECK(!result.ToHandle(&for_assert) || for_assert.is_identical_to(object));
@ -8085,7 +8080,7 @@ MaybeHandle<JSObject> JSObject::DeepCopy(
Handle<JSObject> object,
AllocationSiteUsageContext* site_context,
DeepCopyHints hints) {
JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, true, hints);
JSObjectWalkVisitor<AllocationSiteUsageContext> v(site_context, hints);
MaybeHandle<JSObject> copy = v.StructureWalk(object);
Handle<JSObject> for_assert;
DCHECK(!copy.ToHandle(&for_assert) || !for_assert.is_identical_to(object));