Chromium Code Reviews| Index: runtime/vm/stub_code_mips.cc |
| =================================================================== |
| --- runtime/vm/stub_code_mips.cc (revision 36194) |
| +++ runtime/vm/stub_code_mips.cc (working copy) |
| @@ -682,130 +682,118 @@ |
| // Called for inline allocation of arrays. |
| // Input parameters: |
| // RA: return address. |
| -// A1: Array length as Smi. |
| +// A1: Array length as Smi (must be preserved). |
| // A0: array element type (either NULL or an instantiated type). |
| // NOTE: A1 cannot be clobbered here as the caller relies on it being saved. |
| // The newly allocated object is returned in V0. |
| void StubCode::GenerateAllocateArrayStub(Assembler* assembler) { |
| __ TraceSimMsg("AllocateArrayStub"); |
| Label slow_case; |
| - if (FLAG_inline_alloc) { |
| - // Compute the size to be allocated, it is based on the array length |
| - // and is computed as: |
| - // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)). |
| - // Assert that length is a Smi. |
| - __ andi(CMPRES1, A1, Immediate(kSmiTagMask)); |
| - if (FLAG_use_slow_path) { |
| - __ b(&slow_case); |
| - } else { |
| - __ bne(CMPRES1, ZR, &slow_case); |
| - } |
| - __ bltz(A1, &slow_case); |
| - // Check for maximum allowed length. |
| - const intptr_t max_len = |
| - reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements)); |
| - __ BranchUnsignedGreater(A1, max_len, &slow_case); |
| - __ lw(T0, FieldAddress(CTX, Context::isolate_offset())); |
| - __ lw(T0, Address(T0, Isolate::heap_offset())); |
| - __ lw(T0, Address(T0, Heap::new_space_offset())); |
| + // Compute the size to be allocated, it is based on the array length |
| + // and is computed as: |
| + // RoundedAllocationSize((array_length * kwordSize) + sizeof(RawArray)). |
| + __ mov(T3, A1); // Array length. |
| - // Calculate and align allocation size. |
| - // Load new object start and calculate next object start. |
| - // A0: array element type. |
| - // A1: Array length as Smi. |
| - // T0: Points to new space object. |
| - __ lw(V0, Address(T0, Scavenger::top_offset())); |
| - intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1; |
| - __ LoadImmediate(T3, fixed_size); |
| - __ sll(TMP, A1, 1); // A1 is Smi. |
| - __ addu(T3, T3, TMP); |
| - ASSERT(kSmiTagShift == 1); |
| - __ LoadImmediate(TMP, ~(kObjectAlignment - 1)); |
| - __ and_(T3, T3, TMP); |
| + // Check that length is a positive Smi. |
| + __ andi(CMPRES1, T3, Immediate(kSmiTagMask)); |
| + __ bne(CMPRES1, ZR, &slow_case); |
| + __ bltz(T3, &slow_case); |
| - __ AdduDetectOverflow(T2, T3, V0, CMPRES1); |
| - __ bltz(CMPRES1, &slow_case); // CMPRES1 < 0 on overflow. |
| + // Check for maximum allowed length. |
| + const intptr_t max_len = |
| + reinterpret_cast<int32_t>(Smi::New(Array::kMaxElements)); |
| + __ BranchUnsignedGreater(T3, max_len, &slow_case); |
| - // Check if the allocation fits into the remaining space. |
| - // V0: potential new object start. |
| - // A0: array element type. |
| - // A1: array length as Smi. |
| - // T0: points to new space object. |
| - // T2: potential next object start. |
| - // T3: array size. |
| - __ lw(CMPRES1, Address(T0, Scavenger::end_offset())); |
| - __ BranchUnsignedGreaterEqual(T2, CMPRES1, &slow_case); |
| + const intptr_t fixed_size = sizeof(RawArray) + kObjectAlignment - 1; |
| + __ LoadImmediate(T2, fixed_size); |
| + __ sll(T3, T3, 1); // T3 is a Smi. |
| + __ addu(T2, T2, T3); |
| + ASSERT(kSmiTagShift == 1); |
| + __ LoadImmediate(T3, ~(kObjectAlignment - 1)); |
| + __ and_(T2, T2, T3); |
| - // Successfully allocated the object(s), now update top to point to |
| - // next object start and initialize the object. |
| - // V0: potential new object start. |
| - // T2: potential next object start. |
| - // T0: Points to new space object. |
| - __ sw(T2, Address(T0, Scavenger::top_offset())); |
| - __ addiu(V0, V0, Immediate(kHeapObjectTag)); |
| - // T1: Size of allocation in bytes. |
| - __ subu(T1, T2, V0); |
| - __ UpdateAllocationStatsWithSize(kArrayCid, T1, T5); |
| + // T2: Allocation size. |
| - // V0: new object start as a tagged pointer. |
| - // A0: array element type. |
| - // A1: Array length as Smi. |
| - // T2: new object end address. |
| + Isolate* isolate = Isolate::Current(); |
| + Heap* heap = isolate->heap(); |
| - // Store the type argument field. |
| - __ StoreIntoObjectNoBarrier( |
| - V0, |
| - FieldAddress(V0, Array::type_arguments_offset()), |
| - A0); |
| + __ LoadImmediate(T3, heap->TopAddress()); |
| + __ lw(T0, Address(T3, 0)); // Potential new object start. |
| - // Set the length field. |
| - __ StoreIntoObjectNoBarrier( |
| - V0, |
| - FieldAddress(V0, Array::length_offset()), |
| - A1); |
| + __ AdduDetectOverflow(T1, T0, T2, CMPRES1); // Potential next object start. |
| + __ bltz(CMPRES1, &slow_case); // CMPRES1 < 0 on overflow. |
| - // Calculate the size tag. |
| - // V0: new object start as a tagged pointer. |
| - // A1: Array length as Smi. |
| - // T2: new object end address. |
| - // T3: array size. |
| + // Check if the allocation fits into the remaining space. |
| + // T0: potential new object start. |
| + // T1: potential next object start. |
| + // T2: allocation size. |
| + __ LoadImmediate(T4, heap->EndAddress()); |
| + __ lw(T4, Address(T4, 0)); |
| + __ BranchUnsignedGreaterEqual(T1, T4, &slow_case); |
| + |
| + // Successfully allocated the object(s), now update top to point to |
| + // next object start and initialize the object. |
| + __ sw(T1, Address(T3, 0)); |
| + __ addiu(T0, T0, Immediate(kHeapObjectTag)); |
| + __ UpdateAllocationStatsWithSize(kArrayCid, T2, T4); |
| + |
| + // Initialize the tags. |
| + // T0: new object start as a tagged pointer. |
| + // T1: new object end address. |
| + // T2: allocation size. |
| + { |
| + Label overflow, done; |
| const intptr_t shift = RawObject::kSizeTagPos - kObjectAlignmentLog2; |
| - // If no size tag overflow, shift T3 left, else set T3 to zero. |
| - __ LoadImmediate(T4, RawObject::SizeTag::kMaxSizeTag); |
| - __ sltu(CMPRES1, T4, T3); // CMPRES1 = T4 < T3 ? 1 : 0 |
| - __ sll(TMP, T3, shift); // TMP = T3 << shift; |
| - __ movz(T3, TMP, CMPRES1); // T3 = T4 >= T3 ? 0 : T3 |
| - __ movn(T3, ZR, CMPRES1); // T3 = T4 < T3 ? TMP : T3 |
| + const Class& cls = Class::Handle(isolate->object_store()->array_class()); |
| + __ BranchUnsignedGreater(T2, RawObject::SizeTag::kMaxSizeTag, &overflow); |
| + __ b(&done); |
| + __ delay_slot()->sll(T2, T2, shift); |
| + __ Bind(&overflow); |
| + __ mov(T2, ZR); |
| + __ Bind(&done); |
| + |
| // Get the class index and insert it into the tags. |
| - __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(kArrayCid)); |
| - __ or_(T3, T3, TMP); |
| - __ sw(T3, FieldAddress(V0, Array::tags_offset())); |
| + // T2: size and bit tags. |
| + __ LoadImmediate(TMP, RawObject::ClassIdTag::encode(cls.id())); |
| + __ or_(T2, T2, TMP); |
| + __ sw(T2, FieldAddress(T0, Array::tags_offset())); // Store tags. |
| + } |
| - // Initialize all array elements to raw_null. |
| - // V0: new object start as a tagged pointer. |
| - // T2: new object end address. |
| - // A1: Array length as Smi. |
| - __ AddImmediate(T3, V0, Array::data_offset() - kHeapObjectTag); |
| - // T3: iterator which initially points to the start of the variable |
| - // data area to be initialized. |
| + // T0: new object start as a tagged pointer. |
| + // T1: new object end address. |
| + // Store the type argument field. |
| + __ StoreIntoObjectNoBarrier(T0, |
| + FieldAddress(T0, Array::type_arguments_offset()), |
| + A0); |
| - __ LoadImmediate(T7, reinterpret_cast<intptr_t>(Object::null())); |
| - Label loop, loop_exit; |
| - __ BranchUnsignedGreaterEqual(T3, T2, &loop_exit); |
| - __ Bind(&loop); |
| - __ addiu(T3, T3, Immediate(kWordSize)); |
| - __ bne(T3, T2, &loop); |
| - __ delay_slot()->sw(T7, Address(T3, -kWordSize)); |
| - __ Bind(&loop_exit); |
| + // Set the length field. |
| + __ StoreIntoObjectNoBarrier(T0, |
| + FieldAddress(T0, Array::length_offset()), |
| + A1); |
| - // Done allocating and initializing the array. |
| - // V0: new object. |
| - // A1: Array length as Smi (preserved for the caller.) |
| - __ Ret(); |
| - } |
| + __ LoadImmediate(T7, reinterpret_cast<int32_t>(Object::null())); |
| + // Initialize all array elements to raw_null. |
| + // T0: new object start as a tagged pointer. |
| + // T1: new object end address. |
| + // T2: iterator which initially points to the start of the variable |
| + // data area to be initialized. |
| + // T7: null |
|
zra
2014/05/15 16:20:26
missing .
srdjan
2014/05/15 16:52:34
Done.
|
| + __ AddImmediate(T2, T0, sizeof(RawArray) - kHeapObjectTag); |
| + Label done; |
| + Label init_loop; |
| + __ Bind(&init_loop); |
| + __ BranchUnsignedGreaterEqual(T2, T1, &done); |
| + __ sw(T7, Address(T2, 0)); |
| + __ b(&init_loop); |
| + __ delay_slot()->addiu(T2, T2, Immediate(kWordSize)); |
| + __ Bind(&done); |
| + |
| + __ Ret(); // Returns the newly allocated object in V0. |
| + __ delay_slot()->mov(V0, T0); |
| + |
| // Unable to allocate the array using the fast inline code, just call |
| // into the runtime. |
| __ Bind(&slow_case); |