| OLD | NEW |
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. | 5 #include "vm/globals.h" // Needed here to get TARGET_ARCH_X64. |
| 6 #if defined(TARGET_ARCH_X64) | 6 #if defined(TARGET_ARCH_X64) |
| 7 | 7 |
| 8 #include "vm/intermediate_language.h" | 8 #include "vm/intermediate_language.h" |
| 9 | 9 |
| 10 #include "vm/dart_entry.h" | 10 #include "vm/dart_entry.h" |
| (...skipping 1865 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1876 } | 1876 } |
| 1877 | 1877 |
| 1878 | 1878 |
| 1879 // Inlines array allocation for known constant values. | 1879 // Inlines array allocation for known constant values. |
| 1880 static void InlineArrayAllocation(FlowGraphCompiler* compiler, | 1880 static void InlineArrayAllocation(FlowGraphCompiler* compiler, |
| 1881 intptr_t num_elements, | 1881 intptr_t num_elements, |
| 1882 Label* slow_path, | 1882 Label* slow_path, |
| 1883 Label* done) { | 1883 Label* done) { |
| 1884 const Register kLengthReg = R10; | 1884 const Register kLengthReg = R10; |
| 1885 const Register kElemTypeReg = RBX; | 1885 const Register kElemTypeReg = RBX; |
| 1886 const intptr_t kArraySize = Array::InstanceSize(num_elements); | 1886 const intptr_t instance_size = Array::InstanceSize(num_elements); |
| 1887 | 1887 |
| 1888 Isolate* isolate = Isolate::Current(); | 1888 __ TryAllocateArray(kArrayCid, instance_size, slow_path, Assembler::kFarJump, |
| 1889 Heap* heap = isolate->heap(); | 1889 RAX, // instance |
| 1890 | 1890 RCX); // end address |
| 1891 __ movq(RAX, Immediate(heap->TopAddress())); | |
| 1892 __ movq(RAX, Address(RAX, 0)); | |
| 1893 __ movq(RCX, RAX); | |
| 1894 | |
| 1895 __ addq(RCX, Immediate(kArraySize)); | |
| 1896 __ j(CARRY, slow_path); | |
| 1897 | |
| 1898 // Check if the allocation fits into the remaining space. | |
| 1899 // RAX: potential new object start. | |
| 1900 // RCX: potential next object start. | |
| 1901 __ movq(R13, Immediate(heap->EndAddress())); | |
| 1902 __ cmpq(RCX, Address(R13, 0)); | |
| 1903 __ j(ABOVE_EQUAL, slow_path); | |
| 1904 | |
| 1905 // Successfully allocated the object(s), now update top to point to | |
| 1906 // next object start and initialize the object. | |
| 1907 __ movq(R13, Immediate(heap->TopAddress())); | |
| 1908 __ movq(Address(R13, 0), RCX); | |
| 1909 __ addq(RAX, Immediate(kHeapObjectTag)); | |
| 1910 __ movq(R13, Immediate(kArraySize)); | |
| 1911 __ UpdateAllocationStatsWithSize(kArrayCid, R13); | |
| 1912 | |
| 1913 // Initialize the tags. | |
| 1914 // RAX: new object start as a tagged pointer. | |
| 1915 { | |
| 1916 uword tags = 0; | |
| 1917 tags = RawObject::ClassIdTag::update(kArrayCid, tags); | |
| 1918 tags = RawObject::SizeTag::update(kArraySize, tags); | |
| 1919 __ movq(FieldAddress(RAX, Array::tags_offset()), Immediate(tags)); | |
| 1920 } | |
| 1921 | 1891 |
| 1922 // RAX: new object start as a tagged pointer. | 1892 // RAX: new object start as a tagged pointer. |
| 1923 // Store the type argument field. | 1893 // Store the type argument field. |
| 1924 __ StoreIntoObjectNoBarrier(RAX, | 1894 __ StoreIntoObjectNoBarrier(RAX, |
| 1925 FieldAddress(RAX, Array::type_arguments_offset()), | 1895 FieldAddress(RAX, Array::type_arguments_offset()), |
| 1926 kElemTypeReg); | 1896 kElemTypeReg); |
| 1927 | 1897 |
| 1928 // Set the length field. | 1898 // Set the length field. |
| 1929 __ StoreIntoObjectNoBarrier(RAX, | 1899 __ StoreIntoObjectNoBarrier(RAX, |
| 1930 FieldAddress(RAX, Array::length_offset()), | 1900 FieldAddress(RAX, Array::length_offset()), |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2211 kInstantiateTypeArgumentsRuntimeEntry, | 2181 kInstantiateTypeArgumentsRuntimeEntry, |
| 2212 2, | 2182 2, |
| 2213 locs()); | 2183 locs()); |
| 2214 __ Drop(2); // Drop instantiator and uninstantiated type arguments. | 2184 __ Drop(2); // Drop instantiator and uninstantiated type arguments. |
| 2215 __ popq(result_reg); // Pop instantiated type arguments. | 2185 __ popq(result_reg); // Pop instantiated type arguments. |
| 2216 __ Bind(&type_arguments_instantiated); | 2186 __ Bind(&type_arguments_instantiated); |
| 2217 ASSERT(instantiator_reg == result_reg); | 2187 ASSERT(instantiator_reg == result_reg); |
| 2218 } | 2188 } |
| 2219 | 2189 |
| 2220 | 2190 |
| 2191 LocationSummary* AllocateUninitializedContextInstr::MakeLocationSummary( |
| 2192 Isolate* isolate, |
| 2193 bool opt) const { |
| 2194 ASSERT(opt); |
| 2195 const intptr_t kNumInputs = 0; |
| 2196 const intptr_t kNumTemps = 1; |
| 2197 LocationSummary* locs = new(isolate) LocationSummary( |
| 2198 isolate, kNumInputs, kNumTemps, LocationSummary::kCallOnSlowPath); |
| 2199 locs->set_temp(0, Location::RegisterLocation(R10)); |
| 2200 locs->set_out(0, Location::RegisterLocation(RAX)); |
| 2201 return locs; |
| 2202 } |
| 2203 |
| 2204 |
| 2205 class AllocateContextSlowPath : public SlowPathCode { |
| 2206 public: |
| 2207 explicit AllocateContextSlowPath( |
| 2208 AllocateUninitializedContextInstr* instruction) |
| 2209 : instruction_(instruction) { } |
| 2210 |
| 2211 virtual void EmitNativeCode(FlowGraphCompiler* compiler) { |
| 2212 __ Comment("AllocateContextSlowPath"); |
| 2213 __ Bind(entry_label()); |
| 2214 |
| 2215 LocationSummary* locs = instruction_->locs(); |
| 2216 locs->live_registers()->Remove(locs->out(0)); |
| 2217 |
| 2218 compiler->SaveLiveRegisters(locs); |
| 2219 |
| 2220 __ LoadImmediate(R10, Immediate(instruction_->num_context_variables()), PP); |
| 2221 StubCode* stub_code = compiler->isolate()->stub_code(); |
| 2222 const ExternalLabel label(stub_code->AllocateContextEntryPoint()); |
| 2223 compiler->GenerateCall(instruction_->token_pos(), |
| 2224 &label, |
| 2225 RawPcDescriptors::kOther, |
| 2226 locs); |
| 2227 ASSERT(instruction_->locs()->out(0).reg() == RAX); |
| 2228 compiler->RestoreLiveRegisters(instruction_->locs()); |
| 2229 __ jmp(exit_label()); |
| 2230 } |
| 2231 |
| 2232 private: |
| 2233 AllocateUninitializedContextInstr* instruction_; |
| 2234 }; |
| 2235 |
| 2236 |
| 2237 void AllocateUninitializedContextInstr::EmitNativeCode( |
| 2238 FlowGraphCompiler* compiler) { |
| 2239 ASSERT(compiler->is_optimizing()); |
| 2240 Register temp = locs()->temp(0).reg(); |
| 2241 Register result = locs()->out(0).reg(); |
| 2242 // Try allocate the object. |
| 2243 AllocateContextSlowPath* slow_path = new AllocateContextSlowPath(this); |
| 2244 compiler->AddSlowPathCode(slow_path); |
| 2245 intptr_t instance_size = Context::InstanceSize(num_context_variables()); |
| 2246 |
| 2247 __ TryAllocateArray(kContextCid, instance_size, slow_path->entry_label(), |
| 2248 Assembler::kFarJump, |
| 2249 result, // instance |
| 2250 temp); // end address |
| 2251 |
| 2252 // Setup up number of context variables field. |
| 2253 __ movq(FieldAddress(result, Context::num_variables_offset()), |
| 2254 Immediate(num_context_variables())); |
| 2255 |
| 2256 // Setup isolate field. |
| 2257 __ movq(FieldAddress(result, Context::isolate_offset()), |
| 2258 Immediate(reinterpret_cast<intptr_t>(Isolate::Current()))); |
| 2259 |
| 2260 __ Bind(slow_path->exit_label()); |
| 2261 } |
| 2262 |
| 2263 |
| 2221 LocationSummary* AllocateContextInstr::MakeLocationSummary(Isolate* isolate, | 2264 LocationSummary* AllocateContextInstr::MakeLocationSummary(Isolate* isolate, |
| 2222 bool opt) const { | 2265 bool opt) const { |
| 2223 const intptr_t kNumInputs = 0; | 2266 const intptr_t kNumInputs = 0; |
| 2224 const intptr_t kNumTemps = 1; | 2267 const intptr_t kNumTemps = 1; |
| 2225 LocationSummary* locs = new(isolate) LocationSummary( | 2268 LocationSummary* locs = new(isolate) LocationSummary( |
| 2226 isolate, kNumInputs, kNumTemps, LocationSummary::kCall); | 2269 isolate, kNumInputs, kNumTemps, LocationSummary::kCall); |
| 2227 locs->set_temp(0, Location::RegisterLocation(R10)); | 2270 locs->set_temp(0, Location::RegisterLocation(R10)); |
| 2228 locs->set_out(0, Location::RegisterLocation(RAX)); | 2271 locs->set_out(0, Location::RegisterLocation(RAX)); |
| 2229 return locs; | 2272 return locs; |
| 2230 } | 2273 } |
| (...skipping 3537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 5768 __ movq(R10, Immediate(kInvalidObjectPointer)); | 5811 __ movq(R10, Immediate(kInvalidObjectPointer)); |
| 5769 __ movq(RBX, Immediate(kInvalidObjectPointer)); | 5812 __ movq(RBX, Immediate(kInvalidObjectPointer)); |
| 5770 #endif | 5813 #endif |
| 5771 } | 5814 } |
| 5772 | 5815 |
| 5773 } // namespace dart | 5816 } // namespace dart |
| 5774 | 5817 |
| 5775 #undef __ | 5818 #undef __ |
| 5776 | 5819 |
| 5777 #endif // defined TARGET_ARCH_X64 | 5820 #endif // defined TARGET_ARCH_X64 |
| OLD | NEW |