| Index: src/x64/lithium-codegen-x64.cc
|
| diff --git a/src/x64/lithium-codegen-x64.cc b/src/x64/lithium-codegen-x64.cc
|
| index 3d167ef8fe2557e17e21b56374c46333f481a045..cb18c28e9610d7171089ce494472d2fe4470a749 100644
|
| --- a/src/x64/lithium-codegen-x64.cc
|
| +++ b/src/x64/lithium-codegen-x64.cc
|
| @@ -5175,6 +5175,10 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) {
|
| DeoptimizeIf(not_equal, instr->environment());
|
| }
|
|
|
| + int flags = allocation_site_mode == TRACK_ALLOCATION_SITE
|
| + ? ArrayLiteral::kCreateAllocationSiteInfos
|
| + : ArrayLiteral::kNoFlags;
|
| +
|
| // Set up the parameters to the stub/runtime call.
|
| __ PushHeapObject(literals);
|
| __ Push(Smi::FromInt(instr->hydrogen()->literal_index()));
|
| @@ -5191,9 +5195,11 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) {
|
| FastCloneShallowArrayStub stub(mode, DONT_TRACK_ALLOCATION_SITE, length);
|
| CallCode(stub.GetCode(isolate()), RelocInfo::CODE_TARGET, instr);
|
| } else if (instr->hydrogen()->depth() > 1) {
|
| - CallRuntime(Runtime::kCreateArrayLiteral, 3, instr);
|
| + __ Push(Smi::FromInt(flags));
|
| + CallRuntime(Runtime::kCreateArrayLiteral, 4, instr);
|
| } else if (length > FastCloneShallowArrayStub::kMaximumClonedLength) {
|
| - CallRuntime(Runtime::kCreateArrayLiteralShallow, 3, instr);
|
| + __ Push(Smi::FromInt(flags));
|
| + CallRuntime(Runtime::kCreateArrayLiteralShallow, 4, instr);
|
| } else {
|
| FastCloneShallowArrayStub::Mode mode =
|
| boilerplate_elements_kind == FAST_DOUBLE_ELEMENTS
|
| @@ -5206,6 +5212,7 @@ void LCodeGen::DoArrayLiteral(LArrayLiteral* instr) {
|
|
|
|
|
| void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| + Handle<JSObject> original_object,
|
| Register result,
|
| Register source,
|
| int* offset,
|
| @@ -5213,11 +5220,13 @@ void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| ASSERT(!source.is(rcx));
|
| ASSERT(!result.is(rcx));
|
|
|
| + // Should we track allocation info for *this* object in the tree?
|
| bool create_allocation_site_info = mode == TRACK_ALLOCATION_SITE &&
|
| - object->map()->CanTrackAllocationSite();
|
| + object->ShouldTrackAllocationInfo();
|
|
|
| // Only elements backing stores for non-COW arrays need to be copied.
|
| Handle<FixedArrayBase> elements(object->elements());
|
| + Handle<FixedArrayBase> original_elements(original_object->elements());
|
| bool has_elements = elements->length() > 0 &&
|
| elements->map() != isolate()->heap()->fixed_cow_array_map();
|
|
|
| @@ -5254,11 +5263,14 @@ void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| isolate());
|
| if (value->IsJSObject()) {
|
| Handle<JSObject> value_object = Handle<JSObject>::cast(value);
|
| + Handle<JSObject> original_value_object = Handle<JSObject>::cast(
|
| + Handle<Object>(original_object->InObjectPropertyAt(i), isolate()));
|
| +
|
| __ lea(rcx, Operand(result, *offset));
|
| __ movq(FieldOperand(result, total_offset), rcx);
|
| __ LoadHeapObject(source, value_object);
|
| - EmitDeepCopy(value_object, result, source, offset,
|
| - DONT_TRACK_ALLOCATION_SITE);
|
| + EmitDeepCopy(value_object, original_value_object, result, source,
|
| + offset, mode);
|
| } else if (value->IsHeapObject()) {
|
| __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value));
|
| __ movq(FieldOperand(result, total_offset), rcx);
|
| @@ -5271,8 +5283,11 @@ void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| // Build Allocation Site Info if desired
|
| if (create_allocation_site_info) {
|
| __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex);
|
| - __ movq(FieldOperand(result, object_size), kScratchRegister);
|
| - __ movq(FieldOperand(result, object_size + kPointerSize), source);
|
| + __ movq(FieldOperand(result, object_size + object_offset),
|
| + kScratchRegister);
|
| + __ LoadHeapObject(rcx, original_object);
|
| + __ movq(FieldOperand(result, object_size + object_offset + kPointerSize),
|
| + rcx);
|
| }
|
|
|
| if (has_elements) {
|
| @@ -5297,16 +5312,22 @@ void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| }
|
| } else if (elements->IsFixedArray()) {
|
| Handle<FixedArray> fast_elements = Handle<FixedArray>::cast(elements);
|
| + ASSERT(original_object->HasFastObjectElements());
|
| + Handle<FixedArray> original_fast_elements =
|
| + Handle<FixedArray>::cast(original_elements);
|
| for (int i = 0; i < elements_length; i++) {
|
| int total_offset = elements_offset + FixedArray::OffsetOfElementAt(i);
|
| Handle<Object> value(fast_elements->get(i), isolate());
|
| if (value->IsJSObject()) {
|
| Handle<JSObject> value_object = Handle<JSObject>::cast(value);
|
| + Handle<JSObject> original_value_object = Handle<JSObject>::cast(
|
| + Handle<Object>(original_fast_elements->get(i), isolate()));
|
| __ lea(rcx, Operand(result, *offset));
|
| __ movq(FieldOperand(result, total_offset), rcx);
|
| __ LoadHeapObject(source, value_object);
|
| - EmitDeepCopy(value_object, result, source, offset,
|
| - DONT_TRACK_ALLOCATION_SITE);
|
| + ASSERT(!value_object.is_identical_to(original_value_object));
|
| + EmitDeepCopy(value_object, original_value_object, result, source,
|
| + offset, mode);
|
| } else if (value->IsHeapObject()) {
|
| __ LoadHeapObject(rcx, Handle<HeapObject>::cast(value));
|
| __ movq(FieldOperand(result, total_offset), rcx);
|
| @@ -5322,26 +5343,10 @@ void LCodeGen::EmitDeepCopy(Handle<JSObject> object,
|
| }
|
|
|
|
|
| -void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
|
| - int size = instr->hydrogen()->total_size();
|
| - ElementsKind boilerplate_elements_kind =
|
| - instr->hydrogen()->boilerplate()->GetElementsKind();
|
| -
|
| - // Deopt if the array literal boilerplate ElementsKind is of a type different
|
| - // than the expected one. The check isn't necessary if the boilerplate has
|
| - // already been converted to TERMINAL_FAST_ELEMENTS_KIND.
|
| - if (CanTransitionToMoreGeneralFastElementsKind(
|
| - boilerplate_elements_kind, true)) {
|
| - __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate());
|
| - __ movq(rcx, FieldOperand(rbx, HeapObject::kMapOffset));
|
| - // Load the map's "bit field 2".
|
| - __ movb(rcx, FieldOperand(rcx, Map::kBitField2Offset));
|
| - // Retrieve elements_kind from bit field 2.
|
| - __ and_(rcx, Immediate(Map::kElementsKindMask));
|
| - __ cmpb(rcx, Immediate(boilerplate_elements_kind <<
|
| - Map::kElementsKindShift));
|
| - DeoptimizeIf(not_equal, instr->environment());
|
| - }
|
| +void LCodeGen::FastLiteralHelper(LFastLiteral* instr, AllocationSiteMode mode) {
|
| + int size = mode == DONT_TRACK_ALLOCATION_SITE
|
| + ? instr->hydrogen()->size_without_allocation_sites()
|
| + : instr->hydrogen()->total_size();
|
|
|
| // Allocate all objects that are part of the literal in one big
|
| // allocation. This avoids multiple limit checks.
|
| @@ -5356,11 +5361,37 @@ void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
|
| __ bind(&allocated);
|
| int offset = 0;
|
| __ LoadHeapObject(rbx, instr->hydrogen()->boilerplate());
|
| - EmitDeepCopy(instr->hydrogen()->boilerplate(), rax, rbx, &offset,
|
| + EmitDeepCopy(instr->hydrogen()->boilerplate(),
|
| + instr->hydrogen()->original_boilerplate(),
|
| + rax, rbx, &offset,
|
| instr->hydrogen()->allocation_site_mode());
|
| ASSERT_EQ(size, offset);
|
| }
|
|
|
| +void LCodeGen::DoFastLiteral(LFastLiteral* instr) {
|
| + // TODO(mvstanton): Revisit this heuristic as site info matures.
|
| + // If allocation site mode is on, then we need the ability to turn it off
|
| + // after "awhile." Later, better options should be available, but for
|
| + // now just allow a certain number of gcs to pass.
|
| + if (instr->hydrogen()->allocation_site_mode() == TRACK_ALLOCATION_SITE) {
|
| + // How many gcs have passed?
|
| + const int maxCount = 3;
|
| + ExternalReference gc_count_address =
|
| + ExternalReference::gc_count_address(isolate());
|
| + Label continue_using, done;
|
| + __ movl(rax, masm()->ExternalOperand(gc_count_address));
|
| + __ cmpl(rax, Immediate(maxCount));
|
| + __ j(less, &continue_using);
|
| + FastLiteralHelper(instr, DONT_TRACK_ALLOCATION_SITE);
|
| + __ jmp(&done);
|
| + __ bind(&continue_using);
|
| + FastLiteralHelper(instr, TRACK_ALLOCATION_SITE);
|
| + __ bind(&done);
|
| + } else {
|
| + FastLiteralHelper(instr, DONT_TRACK_ALLOCATION_SITE);
|
| + }
|
| +}
|
| +
|
|
|
| void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) {
|
| Handle<FixedArray> literals(instr->environment()->closure()->literals());
|
| @@ -5374,6 +5405,10 @@ void LCodeGen::DoObjectLiteral(LObjectLiteral* instr) {
|
| ? ObjectLiteral::kHasFunction
|
| : ObjectLiteral::kNoFlags;
|
|
|
| + if (instr->hydrogen()->allocation_site_mode() == TRACK_ALLOCATION_SITE) {
|
| + flags |= ObjectLiteral::kCreateAllocationSiteInfos;
|
| + }
|
| +
|
| // Set up the parameters to the stub/runtime call and pick the right
|
| // runtime function or stub to call.
|
| int properties_count = constant_properties->length() / 2;
|
|
|