Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 1 | // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/v8.h" |
| 6 | |
| 7 | #if V8_TARGET_ARCH_ARM64 |
| 8 | |
| 9 | #include "src/ic/call-optimization.h" |
| 10 | #include "src/ic/handler-compiler.h" |
| 11 | #include "src/ic/ic.h" |
| 12 | |
| 13 | namespace v8 { |
| 14 | namespace internal { |
| 15 | |
| 16 | #define __ ACCESS_MASM(masm) |
| 17 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 18 | void PropertyHandlerCompiler::PushVectorAndSlot(Register vector, |
| 19 | Register slot) { |
| 20 | MacroAssembler* masm = this->masm(); |
| 21 | __ Push(vector); |
| 22 | __ Push(slot); |
| 23 | } |
| 24 | |
| 25 | |
| 26 | void PropertyHandlerCompiler::PopVectorAndSlot(Register vector, Register slot) { |
| 27 | MacroAssembler* masm = this->masm(); |
| 28 | __ Pop(slot); |
| 29 | __ Pop(vector); |
| 30 | } |
| 31 | |
| 32 | |
| 33 | void PropertyHandlerCompiler::DiscardVectorAndSlot() { |
| 34 | MacroAssembler* masm = this->masm(); |
| 35 | // Remove vector and slot. |
| 36 | __ Drop(2); |
| 37 | } |
| 38 | |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 39 | |
| 40 | void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup( |
| 41 | MacroAssembler* masm, Label* miss_label, Register receiver, |
| 42 | Handle<Name> name, Register scratch0, Register scratch1) { |
| 43 | DCHECK(!AreAliased(receiver, scratch0, scratch1)); |
| 44 | DCHECK(name->IsUniqueName()); |
| 45 | Counters* counters = masm->isolate()->counters(); |
| 46 | __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1); |
| 47 | __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 48 | |
| 49 | Label done; |
| 50 | |
| 51 | const int kInterceptorOrAccessCheckNeededMask = |
| 52 | (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); |
| 53 | |
| 54 | // Bail out if the receiver has a named interceptor or requires access checks. |
| 55 | Register map = scratch1; |
| 56 | __ Ldr(map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 57 | __ Ldrb(scratch0, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 58 | __ Tst(scratch0, kInterceptorOrAccessCheckNeededMask); |
| 59 | __ B(ne, miss_label); |
| 60 | |
| 61 | // Check that receiver is a JSObject. |
| 62 | __ Ldrb(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 63 | __ Cmp(scratch0, FIRST_SPEC_OBJECT_TYPE); |
| 64 | __ B(lt, miss_label); |
| 65 | |
| 66 | // Load properties array. |
| 67 | Register properties = scratch0; |
| 68 | __ Ldr(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 69 | // Check that the properties array is a dictionary. |
| 70 | __ Ldr(map, FieldMemOperand(properties, HeapObject::kMapOffset)); |
| 71 | __ JumpIfNotRoot(map, Heap::kHashTableMapRootIndex, miss_label); |
| 72 | |
| 73 | NameDictionaryLookupStub::GenerateNegativeLookup( |
| 74 | masm, miss_label, &done, receiver, properties, name, scratch1); |
| 75 | __ Bind(&done); |
| 76 | __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 77 | } |
| 78 | |
| 79 | |
| 80 | void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype( |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 81 | MacroAssembler* masm, int index, Register result, Label* miss) { |
| 82 | __ Ldr(result, GlobalObjectMemOperand()); |
| 83 | __ Ldr(result, FieldMemOperand(result, GlobalObject::kNativeContextOffset)); |
| 84 | __ Ldr(result, ContextMemOperand(result, index)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 85 | // Load its initial map. The global functions all have initial maps. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 86 | __ Ldr(result, |
| 87 | FieldMemOperand(result, JSFunction::kPrototypeOrInitialMapOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 88 | // Load the prototype from the initial map. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 89 | __ Ldr(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 90 | } |
| 91 | |
| 92 | |
| 93 | void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype( |
| 94 | MacroAssembler* masm, Register receiver, Register scratch1, |
| 95 | Register scratch2, Label* miss_label) { |
| 96 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
| 97 | // TryGetFunctionPrototype can't put the result directly in x0 because the |
| 98 | // 3 inputs registers can't alias and we call this function from |
| 99 | // LoadIC::GenerateFunctionPrototype, where receiver is x0. So we explicitly |
| 100 | // move the result in x0. |
| 101 | __ Mov(x0, scratch1); |
| 102 | __ Ret(); |
| 103 | } |
| 104 | |
| 105 | |
| 106 | // Generate code to check that a global property cell is empty. Create |
| 107 | // the property cell at compilation time if no cell exists for the |
| 108 | // property. |
| 109 | void PropertyHandlerCompiler::GenerateCheckPropertyCell( |
| 110 | MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name, |
| 111 | Register scratch, Label* miss) { |
| 112 | Handle<Cell> cell = JSGlobalObject::EnsurePropertyCell(global, name); |
| 113 | DCHECK(cell->value()->IsTheHole()); |
| 114 | __ Mov(scratch, Operand(cell)); |
| 115 | __ Ldr(scratch, FieldMemOperand(scratch, Cell::kValueOffset)); |
| 116 | __ JumpIfNotRoot(scratch, Heap::kTheHoleValueRootIndex, miss); |
| 117 | } |
| 118 | |
| 119 | |
| 120 | static void PushInterceptorArguments(MacroAssembler* masm, Register receiver, |
| 121 | Register holder, Register name, |
| 122 | Handle<JSObject> holder_obj) { |
| 123 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0); |
| 124 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1); |
| 125 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2); |
| 126 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3); |
| 127 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4); |
| 128 | |
| 129 | __ Push(name); |
| 130 | Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor()); |
| 131 | DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor)); |
| 132 | Register scratch = name; |
| 133 | __ Mov(scratch, Operand(interceptor)); |
| 134 | __ Push(scratch, receiver, holder); |
| 135 | } |
| 136 | |
| 137 | |
| 138 | static void CompileCallLoadPropertyWithInterceptor( |
| 139 | MacroAssembler* masm, Register receiver, Register holder, Register name, |
| 140 | Handle<JSObject> holder_obj, IC::UtilityId id) { |
| 141 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
| 142 | |
| 143 | __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()), |
| 144 | NamedLoadHandlerCompiler::kInterceptorArgsLength); |
| 145 | } |
| 146 | |
| 147 | |
| 148 | // Generate call to api function. |
| 149 | void PropertyHandlerCompiler::GenerateFastApiCall( |
| 150 | MacroAssembler* masm, const CallOptimization& optimization, |
| 151 | Handle<Map> receiver_map, Register receiver, Register scratch, |
| 152 | bool is_store, int argc, Register* values) { |
| 153 | DCHECK(!AreAliased(receiver, scratch)); |
| 154 | |
| 155 | MacroAssembler::PushPopQueue queue(masm); |
| 156 | queue.Queue(receiver); |
| 157 | // Write the arguments to the stack frame. |
| 158 | for (int i = 0; i < argc; i++) { |
| 159 | Register arg = values[argc - 1 - i]; |
| 160 | DCHECK(!AreAliased(receiver, scratch, arg)); |
| 161 | queue.Queue(arg); |
| 162 | } |
| 163 | queue.PushQueued(); |
| 164 | |
| 165 | DCHECK(optimization.is_simple_api_call()); |
| 166 | |
| 167 | // Abi for CallApiFunctionStub. |
| 168 | Register callee = x0; |
| 169 | Register call_data = x4; |
| 170 | Register holder = x2; |
| 171 | Register api_function_address = x1; |
| 172 | |
| 173 | // Put holder in place. |
| 174 | CallOptimization::HolderLookup holder_lookup; |
| 175 | Handle<JSObject> api_holder = |
| 176 | optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup); |
| 177 | switch (holder_lookup) { |
| 178 | case CallOptimization::kHolderIsReceiver: |
| 179 | __ Mov(holder, receiver); |
| 180 | break; |
| 181 | case CallOptimization::kHolderFound: |
| 182 | __ LoadObject(holder, api_holder); |
| 183 | break; |
| 184 | case CallOptimization::kHolderNotFound: |
| 185 | UNREACHABLE(); |
| 186 | break; |
| 187 | } |
| 188 | |
| 189 | Isolate* isolate = masm->isolate(); |
| 190 | Handle<JSFunction> function = optimization.constant_function(); |
| 191 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 192 | Handle<Object> call_data_obj(api_call_info->data(), isolate); |
| 193 | |
| 194 | // Put callee in place. |
| 195 | __ LoadObject(callee, function); |
| 196 | |
| 197 | bool call_data_undefined = false; |
| 198 | // Put call_data in place. |
| 199 | if (isolate->heap()->InNewSpace(*call_data_obj)) { |
| 200 | __ LoadObject(call_data, api_call_info); |
| 201 | __ Ldr(call_data, FieldMemOperand(call_data, CallHandlerInfo::kDataOffset)); |
| 202 | } else if (call_data_obj->IsUndefined()) { |
| 203 | call_data_undefined = true; |
| 204 | __ LoadRoot(call_data, Heap::kUndefinedValueRootIndex); |
| 205 | } else { |
| 206 | __ LoadObject(call_data, call_data_obj); |
| 207 | } |
| 208 | |
| 209 | // Put api_function_address in place. |
| 210 | Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 211 | ApiFunction fun(function_address); |
| 212 | ExternalReference ref = ExternalReference( |
| 213 | &fun, ExternalReference::DIRECT_API_CALL, masm->isolate()); |
| 214 | __ Mov(api_function_address, ref); |
| 215 | |
| 216 | // Jump to stub. |
| 217 | CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc); |
| 218 | __ TailCallStub(&stub); |
| 219 | } |
| 220 | |
| 221 | |
| 222 | void NamedStoreHandlerCompiler::GenerateStoreViaSetter( |
| 223 | MacroAssembler* masm, Handle<HeapType> type, Register receiver, |
| 224 | Handle<JSFunction> setter) { |
| 225 | // ----------- S t a t e ------------- |
| 226 | // -- lr : return address |
| 227 | // ----------------------------------- |
| 228 | Label miss; |
| 229 | |
| 230 | { |
| 231 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 232 | |
| 233 | // Save value register, so we can restore it later. |
| 234 | __ Push(value()); |
| 235 | |
| 236 | if (!setter.is_null()) { |
| 237 | // Call the JavaScript setter with receiver and value on the stack. |
| 238 | if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { |
| 239 | // Swap in the global receiver. |
| 240 | __ Ldr(receiver, |
| 241 | FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); |
| 242 | } |
| 243 | __ Push(receiver, value()); |
| 244 | ParameterCount actual(1); |
| 245 | ParameterCount expected(setter); |
| 246 | __ InvokeFunction(setter, expected, actual, CALL_FUNCTION, |
| 247 | NullCallWrapper()); |
| 248 | } else { |
| 249 | // If we generate a global code snippet for deoptimization only, remember |
| 250 | // the place to continue after deoptimization. |
| 251 | masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset()); |
| 252 | } |
| 253 | |
| 254 | // We have to return the passed value, not the return value of the setter. |
| 255 | __ Pop(x0); |
| 256 | |
| 257 | // Restore context register. |
| 258 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 259 | } |
| 260 | __ Ret(); |
| 261 | } |
| 262 | |
| 263 | |
| 264 | void NamedLoadHandlerCompiler::GenerateLoadViaGetter( |
| 265 | MacroAssembler* masm, Handle<HeapType> type, Register receiver, |
| 266 | Handle<JSFunction> getter) { |
| 267 | { |
| 268 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 269 | |
| 270 | if (!getter.is_null()) { |
| 271 | // Call the JavaScript getter with the receiver on the stack. |
| 272 | if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { |
| 273 | // Swap in the global receiver. |
| 274 | __ Ldr(receiver, |
| 275 | FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); |
| 276 | } |
| 277 | __ Push(receiver); |
| 278 | ParameterCount actual(0); |
| 279 | ParameterCount expected(getter); |
| 280 | __ InvokeFunction(getter, expected, actual, CALL_FUNCTION, |
| 281 | NullCallWrapper()); |
| 282 | } else { |
| 283 | // If we generate a global code snippet for deoptimization only, remember |
| 284 | // the place to continue after deoptimization. |
| 285 | masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset()); |
| 286 | } |
| 287 | |
| 288 | // Restore context register. |
| 289 | __ Ldr(cp, MemOperand(fp, StandardFrameConstants::kContextOffset)); |
| 290 | } |
| 291 | __ Ret(); |
| 292 | } |
| 293 | |
| 294 | |
| 295 | void NamedStoreHandlerCompiler::GenerateSlow(MacroAssembler* masm) { |
| 296 | // Push receiver, name and value for runtime call. |
| 297 | __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(), |
| 298 | StoreDescriptor::ValueRegister()); |
| 299 | |
| 300 | // The slow case calls into the runtime to complete the store without causing |
| 301 | // an IC miss that would otherwise cause a transition to the generic stub. |
| 302 | ExternalReference ref = |
| 303 | ExternalReference(IC_Utility(IC::kStoreIC_Slow), masm->isolate()); |
| 304 | __ TailCallExternalReference(ref, 3, 1); |
| 305 | } |
| 306 | |
| 307 | |
| 308 | void ElementHandlerCompiler::GenerateStoreSlow(MacroAssembler* masm) { |
| 309 | ASM_LOCATION("ElementHandlerCompiler::GenerateStoreSlow"); |
| 310 | |
| 311 | // Push receiver, key and value for runtime call. |
| 312 | __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(), |
| 313 | StoreDescriptor::ValueRegister()); |
| 314 | |
| 315 | // The slow case calls into the runtime to complete the store without causing |
| 316 | // an IC miss that would otherwise cause a transition to the generic stub. |
| 317 | ExternalReference ref = |
| 318 | ExternalReference(IC_Utility(IC::kKeyedStoreIC_Slow), masm->isolate()); |
| 319 | __ TailCallExternalReference(ref, 3, 1); |
| 320 | } |
| 321 | |
| 322 | |
| 323 | #undef __ |
| 324 | #define __ ACCESS_MASM(masm()) |
| 325 | |
| 326 | |
| 327 | Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal( |
| 328 | Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) { |
| 329 | Label miss; |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 330 | if (IC::ICUseVector(kind())) { |
| 331 | PushVectorAndSlot(); |
| 332 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 333 | FrontendHeader(receiver(), name, &miss); |
| 334 | |
| 335 | // Get the value from the cell. |
| 336 | Register result = StoreDescriptor::ValueRegister(); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 337 | Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell); |
| 338 | __ LoadWeakValue(result, weak_cell, &miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 339 | __ Ldr(result, FieldMemOperand(result, Cell::kValueOffset)); |
| 340 | |
| 341 | // Check for deleted property if property can actually be deleted. |
| 342 | if (is_configurable) { |
| 343 | __ JumpIfRoot(result, Heap::kTheHoleValueRootIndex, &miss); |
| 344 | } |
| 345 | |
| 346 | Counters* counters = isolate()->counters(); |
| 347 | __ IncrementCounter(counters->named_load_global_stub(), 1, x1, x3); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 348 | if (IC::ICUseVector(kind())) { |
| 349 | DiscardVectorAndSlot(); |
| 350 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 351 | __ Ret(); |
| 352 | |
| 353 | FrontendFooter(name, &miss); |
| 354 | |
| 355 | // Return the generated code. |
| 356 | return GetCode(kind(), Code::NORMAL, name); |
| 357 | } |
| 358 | |
| 359 | |
| 360 | Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor( |
| 361 | Handle<Name> name) { |
| 362 | Label miss; |
| 363 | |
| 364 | ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreInterceptor"); |
| 365 | |
| 366 | __ Push(receiver(), this->name(), value()); |
| 367 | |
| 368 | // Do tail-call to the runtime system. |
| 369 | ExternalReference store_ic_property = ExternalReference( |
| 370 | IC_Utility(IC::kStorePropertyWithInterceptor), isolate()); |
| 371 | __ TailCallExternalReference(store_ic_property, 3, 1); |
| 372 | |
| 373 | // Return the generated code. |
| 374 | return GetCode(kind(), Code::FAST, name); |
| 375 | } |
| 376 | |
| 377 | |
| 378 | Register NamedStoreHandlerCompiler::value() { |
| 379 | return StoreDescriptor::ValueRegister(); |
| 380 | } |
| 381 | |
| 382 | |
| 383 | void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label, |
| 384 | Handle<Name> name) { |
| 385 | if (!label->is_unused()) { |
| 386 | __ Bind(label); |
| 387 | __ Mov(this->name(), Operand(name)); |
| 388 | } |
| 389 | } |
| 390 | |
| 391 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 392 | void NamedStoreHandlerCompiler::GenerateRestoreName(Handle<Name> name) { |
| 393 | __ Mov(this->name(), Operand(name)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 397 | void NamedStoreHandlerCompiler::GenerateRestoreMap(Handle<Map> transition, |
| 398 | Register scratch, |
| 399 | Label* miss) { |
| 400 | Handle<WeakCell> cell = Map::WeakCellForMap(transition); |
| 401 | Register map_reg = StoreTransitionDescriptor::MapRegister(); |
| 402 | DCHECK(!map_reg.is(scratch)); |
| 403 | __ LoadWeakValue(map_reg, cell, miss); |
| 404 | if (transition->CanBeDeprecated()) { |
| 405 | __ Ldrsw(scratch, FieldMemOperand(map_reg, Map::kBitField3Offset)); |
| 406 | __ TestAndBranchIfAnySet(scratch, Map::Deprecated::kMask, miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 407 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 408 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 409 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 410 | |
| 411 | void NamedStoreHandlerCompiler::GenerateConstantCheck(Register map_reg, |
| 412 | int descriptor, |
| 413 | Register value_reg, |
| 414 | Register scratch, |
| 415 | Label* miss_label) { |
| 416 | DCHECK(!map_reg.is(scratch)); |
| 417 | DCHECK(!map_reg.is(value_reg)); |
| 418 | DCHECK(!value_reg.is(scratch)); |
| 419 | __ LoadInstanceDescriptors(map_reg, scratch); |
| 420 | __ Ldr(scratch, |
| 421 | FieldMemOperand(scratch, DescriptorArray::GetValueOffset(descriptor))); |
| 422 | __ Cmp(value_reg, scratch); |
| 423 | __ B(ne, miss_label); |
| 424 | } |
| 425 | |
| 426 | |
| 427 | void NamedStoreHandlerCompiler::GenerateFieldTypeChecks(HeapType* field_type, |
| 428 | Register value_reg, |
| 429 | Label* miss_label) { |
| 430 | __ JumpIfSmi(value_reg, miss_label); |
| 431 | HeapType::Iterator<Map> it = field_type->Classes(); |
| 432 | if (!it.Done()) { |
| 433 | __ Ldr(scratch1(), FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 434 | Label do_store; |
| 435 | while (true) { |
| 436 | __ CompareMap(scratch1(), it.Current()); |
| 437 | it.Advance(); |
| 438 | if (it.Done()) { |
| 439 | __ B(ne, miss_label); |
| 440 | break; |
| 441 | } |
| 442 | __ B(eq, &do_store); |
| 443 | } |
| 444 | __ Bind(&do_store); |
| 445 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 446 | } |
| 447 | |
| 448 | |
| 449 | Register PropertyHandlerCompiler::CheckPrototypes( |
| 450 | Register object_reg, Register holder_reg, Register scratch1, |
| 451 | Register scratch2, Handle<Name> name, Label* miss, |
| 452 | PrototypeCheckType check) { |
| 453 | Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate())); |
| 454 | |
| 455 | // object_reg and holder_reg registers can alias. |
| 456 | DCHECK(!AreAliased(object_reg, scratch1, scratch2)); |
| 457 | DCHECK(!AreAliased(holder_reg, scratch1, scratch2)); |
| 458 | |
| 459 | // Keep track of the current object in register reg. |
| 460 | Register reg = object_reg; |
| 461 | int depth = 0; |
| 462 | |
| 463 | Handle<JSObject> current = Handle<JSObject>::null(); |
| 464 | if (type()->IsConstant()) { |
| 465 | current = Handle<JSObject>::cast(type()->AsConstant()->Value()); |
| 466 | } |
| 467 | Handle<JSObject> prototype = Handle<JSObject>::null(); |
| 468 | Handle<Map> current_map = receiver_map; |
| 469 | Handle<Map> holder_map(holder()->map()); |
| 470 | // Traverse the prototype chain and check the maps in the prototype chain for |
| 471 | // fast and global objects or do negative lookup for normal objects. |
| 472 | while (!current_map.is_identical_to(holder_map)) { |
| 473 | ++depth; |
| 474 | |
| 475 | // Only global objects and objects that do not require access |
| 476 | // checks are allowed in stubs. |
| 477 | DCHECK(current_map->IsJSGlobalProxyMap() || |
| 478 | !current_map->is_access_check_needed()); |
| 479 | |
| 480 | prototype = handle(JSObject::cast(current_map->prototype())); |
| 481 | if (current_map->is_dictionary_map() && |
| 482 | !current_map->IsJSGlobalObjectMap()) { |
| 483 | DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast. |
| 484 | if (!name->IsUniqueName()) { |
| 485 | DCHECK(name->IsString()); |
| 486 | name = factory()->InternalizeString(Handle<String>::cast(name)); |
| 487 | } |
| 488 | DCHECK(current.is_null() || (current->property_dictionary()->FindEntry( |
| 489 | name) == NameDictionary::kNotFound)); |
| 490 | |
| 491 | GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1, |
| 492 | scratch2); |
| 493 | |
| 494 | __ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 495 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 496 | __ Ldr(reg, FieldMemOperand(scratch1, Map::kPrototypeOffset)); |
| 497 | } else { |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 498 | Register map_reg = scratch1; |
| 499 | __ Ldr(map_reg, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 500 | |
| 501 | if (depth != 1 || check == CHECK_ALL_MAPS) { |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 502 | Handle<WeakCell> cell = Map::WeakCellForMap(current_map); |
| 503 | __ CmpWeakValue(map_reg, cell, scratch2); |
| 504 | __ B(ne, miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 505 | } |
| 506 | |
| 507 | // Check access rights to the global object. This has to happen after |
| 508 | // the map check so that we know that the object is actually a global |
| 509 | // object. |
| 510 | // This allows us to install generated handlers for accesses to the |
| 511 | // global proxy (as opposed to using slow ICs). See corresponding code |
| 512 | // in LookupForRead(). |
| 513 | if (current_map->IsJSGlobalProxyMap()) { |
| 514 | UseScratchRegisterScope temps(masm()); |
| 515 | __ CheckAccessGlobalProxy(reg, scratch2, temps.AcquireX(), miss); |
| 516 | } else if (current_map->IsJSGlobalObjectMap()) { |
| 517 | GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current), |
| 518 | name, scratch2, miss); |
| 519 | } |
| 520 | |
| 521 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 522 | |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 523 | __ Ldr(reg, FieldMemOperand(map_reg, Map::kPrototypeOffset)); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 524 | } |
| 525 | |
| 526 | // Go to the next object in the prototype chain. |
| 527 | current = prototype; |
| 528 | current_map = handle(current->map()); |
| 529 | } |
| 530 | |
| 531 | // Log the check depth. |
| 532 | LOG(isolate(), IntEvent("check-maps-depth", depth + 1)); |
| 533 | |
| 534 | // Check the holder map. |
| 535 | if (depth != 0 || check == CHECK_ALL_MAPS) { |
| 536 | // Check the holder map. |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 537 | __ Ldr(scratch1, FieldMemOperand(reg, HeapObject::kMapOffset)); |
| 538 | Handle<WeakCell> cell = Map::WeakCellForMap(current_map); |
| 539 | __ CmpWeakValue(scratch1, cell, scratch2); |
| 540 | __ B(ne, miss); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | // Perform security check for access to the global object. |
| 544 | DCHECK(current_map->IsJSGlobalProxyMap() || |
| 545 | !current_map->is_access_check_needed()); |
| 546 | if (current_map->IsJSGlobalProxyMap()) { |
| 547 | __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); |
| 548 | } |
| 549 | |
| 550 | // Return the register containing the holder. |
| 551 | return reg; |
| 552 | } |
| 553 | |
| 554 | |
| 555 | void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { |
| 556 | if (!miss->is_unused()) { |
| 557 | Label success; |
| 558 | __ B(&success); |
| 559 | |
| 560 | __ Bind(miss); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 561 | if (IC::ICUseVector(kind())) { |
| 562 | DCHECK(kind() == Code::LOAD_IC); |
| 563 | PopVectorAndSlot(); |
| 564 | } |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 565 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
| 566 | |
| 567 | __ Bind(&success); |
| 568 | } |
| 569 | } |
| 570 | |
| 571 | |
| 572 | void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { |
| 573 | if (!miss->is_unused()) { |
| 574 | Label success; |
| 575 | __ B(&success); |
| 576 | |
| 577 | GenerateRestoreName(miss, name); |
| 578 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
| 579 | |
| 580 | __ Bind(&success); |
| 581 | } |
| 582 | } |
| 583 | |
| 584 | |
| 585 | void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) { |
| 586 | // Return the constant value. |
| 587 | __ LoadObject(x0, value); |
| 588 | __ Ret(); |
| 589 | } |
| 590 | |
| 591 | |
| 592 | void NamedLoadHandlerCompiler::GenerateLoadCallback( |
| 593 | Register reg, Handle<ExecutableAccessorInfo> callback) { |
| 594 | DCHECK(!AreAliased(scratch2(), scratch3(), scratch4(), reg)); |
| 595 | |
| 596 | // Build ExecutableAccessorInfo::args_ list on the stack and push property |
| 597 | // name below the exit frame to make GC aware of them and store pointers to |
| 598 | // them. |
| 599 | STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0); |
| 600 | STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1); |
| 601 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2); |
| 602 | STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3); |
| 603 | STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4); |
| 604 | STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5); |
| 605 | STATIC_ASSERT(PropertyCallbackArguments::kArgsLength == 6); |
| 606 | |
| 607 | __ Push(receiver()); |
| 608 | |
| 609 | if (heap()->InNewSpace(callback->data())) { |
| 610 | __ Mov(scratch3(), Operand(callback)); |
| 611 | __ Ldr(scratch3(), |
| 612 | FieldMemOperand(scratch3(), ExecutableAccessorInfo::kDataOffset)); |
| 613 | } else { |
| 614 | __ Mov(scratch3(), Operand(Handle<Object>(callback->data(), isolate()))); |
| 615 | } |
| 616 | __ LoadRoot(scratch4(), Heap::kUndefinedValueRootIndex); |
| 617 | __ Mov(scratch2(), Operand(ExternalReference::isolate_address(isolate()))); |
| 618 | __ Push(scratch3(), scratch4(), scratch4(), scratch2(), reg, name()); |
| 619 | |
| 620 | Register args_addr = scratch2(); |
| 621 | __ Add(args_addr, __ StackPointer(), kPointerSize); |
| 622 | |
| 623 | // Stack at this point: |
| 624 | // sp[40] callback data |
| 625 | // sp[32] undefined |
| 626 | // sp[24] undefined |
| 627 | // sp[16] isolate |
| 628 | // args_addr -> sp[8] reg |
| 629 | // sp[0] name |
| 630 | |
| 631 | // Abi for CallApiGetter. |
| 632 | Register getter_address_reg = x2; |
| 633 | |
| 634 | // Set up the call. |
| 635 | Address getter_address = v8::ToCData<Address>(callback->getter()); |
| 636 | ApiFunction fun(getter_address); |
| 637 | ExternalReference::Type type = ExternalReference::DIRECT_GETTER_CALL; |
| 638 | ExternalReference ref = ExternalReference(&fun, type, isolate()); |
| 639 | __ Mov(getter_address_reg, ref); |
| 640 | |
| 641 | CallApiGetterStub stub(isolate()); |
| 642 | __ TailCallStub(&stub); |
| 643 | } |
| 644 | |
| 645 | |
| 646 | void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup( |
| 647 | LookupIterator* it, Register holder_reg) { |
| 648 | DCHECK(!AreAliased(receiver(), this->name(), scratch1(), scratch2(), |
| 649 | scratch3())); |
| 650 | DCHECK(holder()->HasNamedInterceptor()); |
| 651 | DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); |
| 652 | |
| 653 | // Compile the interceptor call, followed by inline code to load the |
| 654 | // property from further up the prototype chain if the call fails. |
| 655 | // Check that the maps haven't changed. |
| 656 | DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1())); |
| 657 | |
| 658 | // Preserve the receiver register explicitly whenever it is different from the |
| 659 | // holder and it is needed should the interceptor return without any result. |
| 660 | // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD |
| 661 | // case might cause a miss during the prototype check. |
| 662 | bool must_perform_prototype_check = |
| 663 | !holder().is_identical_to(it->GetHolder<JSObject>()); |
| 664 | bool must_preserve_receiver_reg = |
| 665 | !receiver().is(holder_reg) && |
| 666 | (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check); |
| 667 | |
| 668 | // Save necessary data before invoking an interceptor. |
| 669 | // Requires a frame to make GC aware of pushed pointers. |
| 670 | { |
| 671 | FrameScope frame_scope(masm(), StackFrame::INTERNAL); |
| 672 | if (must_preserve_receiver_reg) { |
| 673 | __ Push(receiver(), holder_reg, this->name()); |
| 674 | } else { |
| 675 | __ Push(holder_reg, this->name()); |
| 676 | } |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 677 | InterceptorVectorSlotPush(holder_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 678 | // Invoke an interceptor. Note: map checks from receiver to |
| 679 | // interceptor's holder has been compiled before (see a caller |
| 680 | // of this method.) |
| 681 | CompileCallLoadPropertyWithInterceptor( |
| 682 | masm(), receiver(), holder_reg, this->name(), holder(), |
| 683 | IC::kLoadPropertyWithInterceptorOnly); |
| 684 | |
| 685 | // Check if interceptor provided a value for property. If it's |
| 686 | // the case, return immediately. |
| 687 | Label interceptor_failed; |
| 688 | __ JumpIfRoot(x0, Heap::kNoInterceptorResultSentinelRootIndex, |
| 689 | &interceptor_failed); |
| 690 | frame_scope.GenerateLeaveFrame(); |
| 691 | __ Ret(); |
| 692 | |
| 693 | __ Bind(&interceptor_failed); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 694 | InterceptorVectorSlotPop(holder_reg); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 695 | if (must_preserve_receiver_reg) { |
| 696 | __ Pop(this->name(), holder_reg, receiver()); |
| 697 | } else { |
| 698 | __ Pop(this->name(), holder_reg); |
| 699 | } |
| 700 | // Leave the internal frame. |
| 701 | } |
| 702 | |
| 703 | GenerateLoadPostInterceptor(it, holder_reg); |
| 704 | } |
| 705 | |
| 706 | |
| 707 | void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) { |
| 708 | // Call the runtime system to load the interceptor. |
| 709 | DCHECK(holder()->HasNamedInterceptor()); |
| 710 | DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); |
| 711 | PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(), |
| 712 | holder()); |
| 713 | |
| 714 | ExternalReference ref = ExternalReference( |
| 715 | IC_Utility(IC::kLoadPropertyWithInterceptor), isolate()); |
| 716 | __ TailCallExternalReference( |
| 717 | ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1); |
| 718 | } |
| 719 | |
| 720 | |
| 721 | Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( |
| 722 | Handle<JSObject> object, Handle<Name> name, |
| 723 | Handle<ExecutableAccessorInfo> callback) { |
| 724 | ASM_LOCATION("NamedStoreHandlerCompiler::CompileStoreCallback"); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame^] | 725 | Register holder_reg = Frontend(name); |
Ben Murdoch | b8a8cc1 | 2014-11-26 15:28:44 +0000 | [diff] [blame] | 726 | |
| 727 | // Stub never generated for non-global objects that require access checks. |
| 728 | DCHECK(holder()->IsJSGlobalProxy() || !holder()->IsAccessCheckNeeded()); |
| 729 | |
| 730 | // receiver() and holder_reg can alias. |
| 731 | DCHECK(!AreAliased(receiver(), scratch1(), scratch2(), value())); |
| 732 | DCHECK(!AreAliased(holder_reg, scratch1(), scratch2(), value())); |
| 733 | __ Mov(scratch1(), Operand(callback)); |
| 734 | __ Mov(scratch2(), Operand(name)); |
| 735 | __ Push(receiver(), holder_reg, scratch1(), scratch2(), value()); |
| 736 | |
| 737 | // Do tail-call to the runtime system. |
| 738 | ExternalReference store_callback_property = |
| 739 | ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate()); |
| 740 | __ TailCallExternalReference(store_callback_property, 5, 1); |
| 741 | |
| 742 | // Return the generated code. |
| 743 | return GetCode(kind(), Code::FAST, name); |
| 744 | } |
| 745 | |
| 746 | |
| 747 | #undef __ |
| 748 | } |
| 749 | } // namespace v8::internal |
| 750 | |
| 751 | #endif // V8_TARGET_ARCH_IA32 |