Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 1 | // Copyright 2015 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 | #if V8_TARGET_ARCH_S390 |
| 6 | |
| 7 | #include "src/ic/handler-compiler.h" |
| 8 | |
| 9 | #include "src/api-arguments.h" |
| 10 | #include "src/field-type.h" |
| 11 | #include "src/ic/call-optimization.h" |
| 12 | #include "src/ic/ic.h" |
| 13 | #include "src/isolate-inl.h" |
| 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | |
| 18 | #define __ ACCESS_MASM(masm) |
| 19 | |
| 20 | void NamedLoadHandlerCompiler::GenerateLoadViaGetter( |
| 21 | MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder, |
| 22 | int accessor_index, int expected_arguments, Register scratch) { |
| 23 | // ----------- S t a t e ------------- |
| 24 | // -- r2 : receiver |
| 25 | // -- r4 : name |
| 26 | // -- lr : return address |
| 27 | // ----------------------------------- |
| 28 | { |
| 29 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 30 | |
| 31 | // Save context register |
| 32 | __ push(cp); |
| 33 | |
| 34 | if (accessor_index >= 0) { |
| 35 | DCHECK(!holder.is(scratch)); |
| 36 | DCHECK(!receiver.is(scratch)); |
| 37 | // Call the JavaScript getter with the receiver on the stack. |
| 38 | if (map->IsJSGlobalObjectMap()) { |
| 39 | // Swap in the global receiver. |
| 40 | __ LoadP(scratch, |
| 41 | FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); |
| 42 | receiver = scratch; |
| 43 | } |
| 44 | __ Push(receiver); |
| 45 | __ LoadAccessor(r3, holder, accessor_index, ACCESSOR_GETTER); |
| 46 | __ LoadImmP(r2, Operand::Zero()); |
| 47 | __ Call(masm->isolate()->builtins()->CallFunction( |
| 48 | ConvertReceiverMode::kNotNullOrUndefined), |
| 49 | RelocInfo::CODE_TARGET); |
| 50 | } else { |
| 51 | // If we generate a global code snippet for deoptimization only, remember |
| 52 | // the place to continue after deoptimization. |
| 53 | masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset()); |
| 54 | } |
| 55 | |
| 56 | // Restore context register. |
| 57 | __ pop(cp); |
| 58 | } |
| 59 | __ Ret(); |
| 60 | } |
| 61 | |
| 62 | void NamedStoreHandlerCompiler::GenerateStoreViaSetter( |
| 63 | MacroAssembler* masm, Handle<Map> map, Register receiver, Register holder, |
| 64 | int accessor_index, int expected_arguments, Register scratch) { |
| 65 | // ----------- S t a t e ------------- |
| 66 | // -- lr : return address |
| 67 | // ----------------------------------- |
| 68 | { |
| 69 | FrameScope scope(masm, StackFrame::INTERNAL); |
| 70 | |
| 71 | // Save context register |
| 72 | // Save value register, so we can restore it later. |
| 73 | __ Push(cp, value()); |
| 74 | |
| 75 | if (accessor_index >= 0) { |
| 76 | DCHECK(!holder.is(scratch)); |
| 77 | DCHECK(!receiver.is(scratch)); |
| 78 | DCHECK(!value().is(scratch)); |
| 79 | // Call the JavaScript setter with receiver and value on the stack. |
| 80 | if (map->IsJSGlobalObjectMap()) { |
| 81 | // Swap in the global receiver. |
| 82 | __ LoadP(scratch, |
| 83 | FieldMemOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); |
| 84 | receiver = scratch; |
| 85 | } |
| 86 | __ Push(receiver, value()); |
| 87 | __ LoadAccessor(r3, holder, accessor_index, ACCESSOR_SETTER); |
| 88 | __ LoadImmP(r2, Operand(1)); |
| 89 | __ Call(masm->isolate()->builtins()->CallFunction( |
| 90 | ConvertReceiverMode::kNotNullOrUndefined), |
| 91 | RelocInfo::CODE_TARGET); |
| 92 | } else { |
| 93 | // If we generate a global code snippet for deoptimization only, remember |
| 94 | // the place to continue after deoptimization. |
| 95 | masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset()); |
| 96 | } |
| 97 | |
| 98 | // We have to return the passed value, not the return value of the setter. |
| 99 | // Restore context register. |
| 100 | __ Pop(cp, r2); |
| 101 | } |
| 102 | __ Ret(); |
| 103 | } |
| 104 | |
| 105 | void PropertyHandlerCompiler::PushVectorAndSlot(Register vector, |
| 106 | Register slot) { |
| 107 | MacroAssembler* masm = this->masm(); |
| 108 | __ Push(vector, slot); |
| 109 | } |
| 110 | |
| 111 | void PropertyHandlerCompiler::PopVectorAndSlot(Register vector, Register slot) { |
| 112 | MacroAssembler* masm = this->masm(); |
| 113 | __ Pop(vector, slot); |
| 114 | } |
| 115 | |
| 116 | void PropertyHandlerCompiler::DiscardVectorAndSlot() { |
| 117 | MacroAssembler* masm = this->masm(); |
| 118 | // Remove vector and slot. |
| 119 | __ la(sp, MemOperand(sp, 2 * kPointerSize)); |
| 120 | } |
| 121 | |
| 122 | void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup( |
| 123 | MacroAssembler* masm, Label* miss_label, Register receiver, |
| 124 | Handle<Name> name, Register scratch0, Register scratch1) { |
| 125 | DCHECK(name->IsUniqueName()); |
| 126 | DCHECK(!receiver.is(scratch0)); |
| 127 | Counters* counters = masm->isolate()->counters(); |
| 128 | __ IncrementCounter(counters->negative_lookups(), 1, scratch0, scratch1); |
| 129 | __ IncrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 130 | |
| 131 | Label done; |
| 132 | |
| 133 | const int kInterceptorOrAccessCheckNeededMask = |
| 134 | (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); |
| 135 | |
| 136 | // Bail out if the receiver has a named interceptor or requires access checks. |
| 137 | Register map = scratch1; |
| 138 | __ LoadP(map, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 139 | __ LoadlB(scratch0, FieldMemOperand(map, Map::kBitFieldOffset)); |
| 140 | __ AndP(r0, scratch0, Operand(kInterceptorOrAccessCheckNeededMask)); |
| 141 | __ bne(miss_label); |
| 142 | |
| 143 | // Check that receiver is a JSObject. |
| 144 | // TODO(joransiu): Merge into SI compare |
| 145 | __ LoadlB(scratch0, FieldMemOperand(map, Map::kInstanceTypeOffset)); |
| 146 | __ CmpP(scratch0, Operand(FIRST_JS_RECEIVER_TYPE)); |
| 147 | __ blt(miss_label); |
| 148 | |
| 149 | // Load properties array. |
| 150 | Register properties = scratch0; |
| 151 | __ LoadP(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 152 | // Check that the properties array is a dictionary. |
| 153 | __ LoadP(map, FieldMemOperand(properties, HeapObject::kMapOffset)); |
| 154 | __ CompareRoot(map, Heap::kHashTableMapRootIndex); |
| 155 | __ bne(miss_label); |
| 156 | |
| 157 | // Restore the temporarily used register. |
| 158 | __ LoadP(properties, FieldMemOperand(receiver, JSObject::kPropertiesOffset)); |
| 159 | |
| 160 | NameDictionaryLookupStub::GenerateNegativeLookup( |
| 161 | masm, miss_label, &done, receiver, properties, name, scratch1); |
| 162 | __ bind(&done); |
| 163 | __ DecrementCounter(counters->negative_lookups_miss(), 1, scratch0, scratch1); |
| 164 | } |
| 165 | |
| 166 | void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype( |
| 167 | MacroAssembler* masm, int index, Register result, Label* miss) { |
| 168 | __ LoadNativeContextSlot(index, result); |
| 169 | // Load its initial map. The global functions all have initial maps. |
| 170 | __ LoadP(result, |
| 171 | FieldMemOperand(result, JSFunction::kPrototypeOrInitialMapOffset)); |
| 172 | // Load the prototype from the initial map. |
| 173 | __ LoadP(result, FieldMemOperand(result, Map::kPrototypeOffset)); |
| 174 | } |
| 175 | |
| 176 | void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype( |
| 177 | MacroAssembler* masm, Register receiver, Register scratch1, |
| 178 | Register scratch2, Label* miss_label) { |
| 179 | __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); |
| 180 | __ LoadRR(r2, scratch1); |
| 181 | __ Ret(); |
| 182 | } |
| 183 | |
| 184 | // Generate code to check that a global property cell is empty. Create |
| 185 | // the property cell at compilation time if no cell exists for the |
| 186 | // property. |
| 187 | void PropertyHandlerCompiler::GenerateCheckPropertyCell( |
| 188 | MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name, |
| 189 | Register scratch, Label* miss) { |
| 190 | Handle<PropertyCell> cell = JSGlobalObject::EnsurePropertyCell(global, name); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 191 | Isolate* isolate = masm->isolate(); |
| 192 | DCHECK(cell->value()->IsTheHole(isolate)); |
| 193 | Handle<WeakCell> weak_cell = isolate->factory()->NewWeakCell(cell); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 194 | __ LoadWeakValue(scratch, weak_cell, miss); |
| 195 | __ LoadP(scratch, FieldMemOperand(scratch, PropertyCell::kValueOffset)); |
| 196 | __ CompareRoot(scratch, Heap::kTheHoleValueRootIndex); |
| 197 | __ bne(miss); |
| 198 | } |
| 199 | |
| 200 | static void PushInterceptorArguments(MacroAssembler* masm, Register receiver, |
| 201 | Register holder, Register name, |
| 202 | Handle<JSObject> holder_obj) { |
| 203 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0); |
| 204 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 1); |
| 205 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 2); |
| 206 | STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 3); |
| 207 | __ Push(name); |
| 208 | __ Push(receiver); |
| 209 | __ Push(holder); |
| 210 | } |
| 211 | |
| 212 | static void CompileCallLoadPropertyWithInterceptor( |
| 213 | MacroAssembler* masm, Register receiver, Register holder, Register name, |
| 214 | Handle<JSObject> holder_obj, Runtime::FunctionId id) { |
| 215 | DCHECK(NamedLoadHandlerCompiler::kInterceptorArgsLength == |
| 216 | Runtime::FunctionForId(id)->nargs); |
| 217 | PushInterceptorArguments(masm, receiver, holder, name, holder_obj); |
| 218 | __ CallRuntime(id); |
| 219 | } |
| 220 | |
| 221 | // Generate call to api function. |
| 222 | void PropertyHandlerCompiler::GenerateApiAccessorCall( |
| 223 | MacroAssembler* masm, const CallOptimization& optimization, |
| 224 | Handle<Map> receiver_map, Register receiver, Register scratch_in, |
| 225 | bool is_store, Register store_parameter, Register accessor_holder, |
| 226 | int accessor_index) { |
| 227 | DCHECK(!accessor_holder.is(scratch_in)); |
| 228 | DCHECK(!receiver.is(scratch_in)); |
| 229 | __ Push(receiver); |
| 230 | // Write the arguments to stack frame. |
| 231 | if (is_store) { |
| 232 | DCHECK(!receiver.is(store_parameter)); |
| 233 | DCHECK(!scratch_in.is(store_parameter)); |
| 234 | __ Push(store_parameter); |
| 235 | } |
| 236 | DCHECK(optimization.is_simple_api_call()); |
| 237 | |
| 238 | // Abi for CallApiCallbackStub. |
| 239 | Register callee = r2; |
| 240 | Register data = r6; |
| 241 | Register holder = r4; |
| 242 | Register api_function_address = r3; |
| 243 | |
| 244 | // Put callee in place. |
| 245 | __ LoadAccessor(callee, accessor_holder, accessor_index, |
| 246 | is_store ? ACCESSOR_SETTER : ACCESSOR_GETTER); |
| 247 | |
| 248 | // Put holder in place. |
| 249 | CallOptimization::HolderLookup holder_lookup; |
| 250 | int holder_depth = 0; |
| 251 | optimization.LookupHolderOfExpectedType(receiver_map, &holder_lookup, |
| 252 | &holder_depth); |
| 253 | switch (holder_lookup) { |
| 254 | case CallOptimization::kHolderIsReceiver: |
| 255 | __ Move(holder, receiver); |
| 256 | break; |
| 257 | case CallOptimization::kHolderFound: |
| 258 | __ LoadP(holder, FieldMemOperand(receiver, HeapObject::kMapOffset)); |
| 259 | __ LoadP(holder, FieldMemOperand(holder, Map::kPrototypeOffset)); |
| 260 | for (int i = 1; i < holder_depth; i++) { |
| 261 | __ LoadP(holder, FieldMemOperand(holder, HeapObject::kMapOffset)); |
| 262 | __ LoadP(holder, FieldMemOperand(holder, Map::kPrototypeOffset)); |
| 263 | } |
| 264 | break; |
| 265 | case CallOptimization::kHolderNotFound: |
| 266 | UNREACHABLE(); |
| 267 | break; |
| 268 | } |
| 269 | |
| 270 | Isolate* isolate = masm->isolate(); |
| 271 | Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); |
| 272 | bool call_data_undefined = false; |
| 273 | // Put call data in place. |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 274 | if (api_call_info->data()->IsUndefined(isolate)) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 275 | call_data_undefined = true; |
| 276 | __ LoadRoot(data, Heap::kUndefinedValueRootIndex); |
| 277 | } else { |
| 278 | if (optimization.is_constant_call()) { |
| 279 | __ LoadP(data, |
| 280 | FieldMemOperand(callee, JSFunction::kSharedFunctionInfoOffset)); |
| 281 | __ LoadP(data, |
| 282 | FieldMemOperand(data, SharedFunctionInfo::kFunctionDataOffset)); |
| 283 | __ LoadP(data, |
| 284 | FieldMemOperand(data, FunctionTemplateInfo::kCallCodeOffset)); |
| 285 | } else { |
| 286 | __ LoadP(data, |
| 287 | FieldMemOperand(callee, FunctionTemplateInfo::kCallCodeOffset)); |
| 288 | } |
| 289 | __ LoadP(data, FieldMemOperand(data, CallHandlerInfo::kDataOffset)); |
| 290 | } |
| 291 | |
| 292 | if (api_call_info->fast_handler()->IsCode()) { |
| 293 | // Just tail call into the fast handler if present. |
| 294 | __ Jump(handle(Code::cast(api_call_info->fast_handler())), |
| 295 | RelocInfo::CODE_TARGET); |
| 296 | return; |
| 297 | } |
| 298 | |
| 299 | // Put api_function_address in place. |
| 300 | Address function_address = v8::ToCData<Address>(api_call_info->callback()); |
| 301 | ApiFunction fun(function_address); |
| 302 | ExternalReference::Type type = ExternalReference::DIRECT_API_CALL; |
| 303 | ExternalReference ref = ExternalReference(&fun, type, masm->isolate()); |
| 304 | __ mov(api_function_address, Operand(ref)); |
| 305 | |
| 306 | // Jump to stub. |
| 307 | CallApiCallbackStub stub(isolate, is_store, call_data_undefined, |
| 308 | !optimization.is_constant_call()); |
| 309 | __ TailCallStub(&stub); |
| 310 | } |
| 311 | |
| 312 | static void StoreIC_PushArgs(MacroAssembler* masm) { |
| 313 | __ Push(StoreDescriptor::ReceiverRegister(), StoreDescriptor::NameRegister(), |
| 314 | StoreDescriptor::ValueRegister(), |
| 315 | VectorStoreICDescriptor::SlotRegister(), |
| 316 | VectorStoreICDescriptor::VectorRegister()); |
| 317 | } |
| 318 | |
| 319 | void NamedStoreHandlerCompiler::GenerateSlow(MacroAssembler* masm) { |
| 320 | StoreIC_PushArgs(masm); |
| 321 | |
| 322 | // The slow case calls into the runtime to complete the store without causing |
| 323 | // an IC miss that would otherwise cause a transition to the generic stub. |
| 324 | __ TailCallRuntime(Runtime::kStoreIC_Slow); |
| 325 | } |
| 326 | |
| 327 | void ElementHandlerCompiler::GenerateStoreSlow(MacroAssembler* masm) { |
| 328 | StoreIC_PushArgs(masm); |
| 329 | |
| 330 | // The slow case calls into the runtime to complete the store without causing |
| 331 | // an IC miss that would otherwise cause a transition to the generic stub. |
| 332 | __ TailCallRuntime(Runtime::kKeyedStoreIC_Slow); |
| 333 | } |
| 334 | |
| 335 | #undef __ |
| 336 | #define __ ACCESS_MASM(masm()) |
| 337 | |
| 338 | void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label, |
| 339 | Handle<Name> name) { |
| 340 | if (!label->is_unused()) { |
| 341 | __ bind(label); |
| 342 | __ mov(this->name(), Operand(name)); |
| 343 | } |
| 344 | } |
| 345 | |
| 346 | void NamedStoreHandlerCompiler::GenerateRestoreName(Handle<Name> name) { |
| 347 | __ mov(this->name(), Operand(name)); |
| 348 | } |
| 349 | |
| 350 | void NamedStoreHandlerCompiler::RearrangeVectorAndSlot( |
| 351 | Register current_map, Register destination_map) { |
| 352 | DCHECK(false); // Not implemented. |
| 353 | } |
| 354 | |
| 355 | void NamedStoreHandlerCompiler::GenerateRestoreMap(Handle<Map> transition, |
| 356 | Register map_reg, |
| 357 | Register scratch, |
| 358 | Label* miss) { |
| 359 | Handle<WeakCell> cell = Map::WeakCellForMap(transition); |
| 360 | DCHECK(!map_reg.is(scratch)); |
| 361 | __ LoadWeakValue(map_reg, cell, miss); |
| 362 | if (transition->CanBeDeprecated()) { |
| 363 | __ LoadlW(scratch, FieldMemOperand(map_reg, Map::kBitField3Offset)); |
| 364 | __ DecodeField<Map::Deprecated>(r0, scratch); |
| 365 | __ bne(miss); |
| 366 | } |
| 367 | } |
| 368 | |
| 369 | void NamedStoreHandlerCompiler::GenerateConstantCheck(Register map_reg, |
| 370 | int descriptor, |
| 371 | Register value_reg, |
| 372 | Register scratch, |
| 373 | Label* miss_label) { |
| 374 | DCHECK(!map_reg.is(scratch)); |
| 375 | DCHECK(!map_reg.is(value_reg)); |
| 376 | DCHECK(!value_reg.is(scratch)); |
| 377 | __ LoadInstanceDescriptors(map_reg, scratch); |
| 378 | __ CmpP(value_reg, FieldMemOperand( |
| 379 | scratch, DescriptorArray::GetValueOffset(descriptor))); |
| 380 | __ bne(miss_label); |
| 381 | } |
| 382 | |
| 383 | void NamedStoreHandlerCompiler::GenerateFieldTypeChecks(FieldType* field_type, |
| 384 | Register value_reg, |
| 385 | Label* miss_label) { |
| 386 | Register map_reg = scratch1(); |
| 387 | Register scratch = scratch2(); |
| 388 | DCHECK(!value_reg.is(map_reg)); |
| 389 | DCHECK(!value_reg.is(scratch)); |
| 390 | __ JumpIfSmi(value_reg, miss_label); |
| 391 | if (field_type->IsClass()) { |
| 392 | __ LoadP(map_reg, FieldMemOperand(value_reg, HeapObject::kMapOffset)); |
| 393 | __ CmpWeakValue(map_reg, Map::WeakCellForMap(field_type->AsClass()), |
| 394 | scratch); |
| 395 | __ bne(miss_label); |
| 396 | } |
| 397 | } |
| 398 | |
| 399 | Register PropertyHandlerCompiler::CheckPrototypes( |
| 400 | Register object_reg, Register holder_reg, Register scratch1, |
| 401 | Register scratch2, Handle<Name> name, Label* miss, PrototypeCheckType check, |
| 402 | ReturnHolder return_what) { |
| 403 | Handle<Map> receiver_map = map(); |
| 404 | |
| 405 | // Make sure there's no overlap between holder and object registers. |
| 406 | DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); |
| 407 | DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) && |
| 408 | !scratch2.is(scratch1)); |
| 409 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 410 | Handle<Cell> validity_cell = |
| 411 | Map::GetOrCreatePrototypeChainValidityCell(receiver_map, isolate()); |
| 412 | if (!validity_cell.is_null()) { |
| 413 | DCHECK_EQ(Smi::FromInt(Map::kPrototypeChainValid), validity_cell->value()); |
| 414 | __ mov(scratch1, Operand(validity_cell)); |
| 415 | __ LoadP(scratch1, FieldMemOperand(scratch1, Cell::kValueOffset)); |
| 416 | __ CmpSmiLiteral(scratch1, Smi::FromInt(Map::kPrototypeChainValid), r0); |
| 417 | __ bne(miss); |
| 418 | } |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 419 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 420 | // The prototype chain of primitives (and their JSValue wrappers) depends |
| 421 | // on the native context, which can't be guarded by validity cells. |
| 422 | // |object_reg| holds the native context specific prototype in this case; |
| 423 | // we need to check its map. |
| 424 | if (check == CHECK_ALL_MAPS) { |
| 425 | __ LoadP(scratch1, FieldMemOperand(object_reg, HeapObject::kMapOffset)); |
| 426 | Handle<WeakCell> cell = Map::WeakCellForMap(receiver_map); |
| 427 | __ CmpWeakValue(scratch1, cell, scratch2); |
| 428 | __ b(ne, miss); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | // Keep track of the current object in register reg. |
| 432 | Register reg = object_reg; |
| 433 | int depth = 0; |
| 434 | |
| 435 | Handle<JSObject> current = Handle<JSObject>::null(); |
| 436 | if (receiver_map->IsJSGlobalObjectMap()) { |
| 437 | current = isolate()->global_object(); |
| 438 | } |
| 439 | // Check access rights to the global object. This has to happen after |
| 440 | // the map check so that we know that the object is actually a global |
| 441 | // object. |
| 442 | // This allows us to install generated handlers for accesses to the |
| 443 | // global proxy (as opposed to using slow ICs). See corresponding code |
| 444 | // in LookupForRead(). |
| 445 | if (receiver_map->IsJSGlobalProxyMap()) { |
| 446 | __ CheckAccessGlobalProxy(reg, scratch2, miss); |
| 447 | } |
| 448 | |
| 449 | Handle<JSObject> prototype = Handle<JSObject>::null(); |
| 450 | Handle<Map> current_map = receiver_map; |
| 451 | Handle<Map> holder_map(holder()->map()); |
| 452 | // Traverse the prototype chain and check the maps in the prototype chain for |
| 453 | // fast and global objects or do negative lookup for normal objects. |
| 454 | while (!current_map.is_identical_to(holder_map)) { |
| 455 | ++depth; |
| 456 | |
| 457 | // Only global objects and objects that do not require access |
| 458 | // checks are allowed in stubs. |
| 459 | DCHECK(current_map->IsJSGlobalProxyMap() || |
| 460 | !current_map->is_access_check_needed()); |
| 461 | |
| 462 | prototype = handle(JSObject::cast(current_map->prototype())); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 463 | if (current_map->IsJSGlobalObjectMap()) { |
| 464 | GenerateCheckPropertyCell(masm(), Handle<JSGlobalObject>::cast(current), |
| 465 | name, scratch2, miss); |
| 466 | } else if (current_map->is_dictionary_map()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 467 | DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast. |
| 468 | if (!name->IsUniqueName()) { |
| 469 | DCHECK(name->IsString()); |
| 470 | name = factory()->InternalizeString(Handle<String>::cast(name)); |
| 471 | } |
| 472 | DCHECK(current.is_null() || |
| 473 | current->property_dictionary()->FindEntry(name) == |
| 474 | NameDictionary::kNotFound); |
| 475 | |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 476 | if (depth > 1) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 477 | // TODO(jkummerow): Cache and re-use weak cell. |
| 478 | __ LoadWeakValue(reg, isolate()->factory()->NewWeakCell(current), miss); |
| 479 | } |
| 480 | GenerateDictionaryNegativeLookup(masm(), miss, reg, name, scratch1, |
| 481 | scratch2); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 482 | } |
| 483 | |
| 484 | reg = holder_reg; // From now on the object will be in holder_reg. |
| 485 | // Go to the next object in the prototype chain. |
| 486 | current = prototype; |
| 487 | current_map = handle(current->map()); |
| 488 | } |
| 489 | |
| 490 | DCHECK(!current_map->IsJSGlobalProxyMap()); |
| 491 | |
| 492 | // Log the check depth. |
| 493 | LOG(isolate(), IntEvent("check-maps-depth", depth + 1)); |
| 494 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 495 | bool return_holder = return_what == RETURN_HOLDER; |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 496 | if (return_holder && depth != 0) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 497 | __ LoadWeakValue(reg, isolate()->factory()->NewWeakCell(current), miss); |
| 498 | } |
| 499 | |
| 500 | // Return the register containing the holder. |
| 501 | return return_holder ? reg : no_reg; |
| 502 | } |
| 503 | |
| 504 | void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { |
| 505 | if (!miss->is_unused()) { |
| 506 | Label success; |
| 507 | __ b(&success); |
| 508 | __ bind(miss); |
| 509 | if (IC::ICUseVector(kind())) { |
| 510 | DCHECK(kind() == Code::LOAD_IC); |
| 511 | PopVectorAndSlot(); |
| 512 | } |
| 513 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
| 514 | __ bind(&success); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { |
| 519 | if (!miss->is_unused()) { |
| 520 | Label success; |
| 521 | __ b(&success); |
| 522 | GenerateRestoreName(miss, name); |
| 523 | if (IC::ICUseVector(kind())) PopVectorAndSlot(); |
| 524 | TailCallBuiltin(masm(), MissBuiltin(kind())); |
| 525 | __ bind(&success); |
| 526 | } |
| 527 | } |
| 528 | |
| 529 | void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) { |
| 530 | // Return the constant value. |
| 531 | __ Move(r2, value); |
| 532 | __ Ret(); |
| 533 | } |
| 534 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 535 | void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup( |
| 536 | LookupIterator* it, Register holder_reg) { |
| 537 | DCHECK(holder()->HasNamedInterceptor()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 538 | DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined(isolate())); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 539 | |
| 540 | // Compile the interceptor call, followed by inline code to load the |
| 541 | // property from further up the prototype chain if the call fails. |
| 542 | // Check that the maps haven't changed. |
| 543 | DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1())); |
| 544 | |
| 545 | // Preserve the receiver register explicitly whenever it is different from the |
| 546 | // holder and it is needed should the interceptor return without any result. |
| 547 | // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD |
| 548 | // case might cause a miss during the prototype check. |
| 549 | bool must_perform_prototype_check = |
| 550 | !holder().is_identical_to(it->GetHolder<JSObject>()); |
| 551 | bool must_preserve_receiver_reg = |
| 552 | !receiver().is(holder_reg) && |
| 553 | (it->state() == LookupIterator::ACCESSOR || must_perform_prototype_check); |
| 554 | |
| 555 | // Save necessary data before invoking an interceptor. |
| 556 | // Requires a frame to make GC aware of pushed pointers. |
| 557 | { |
| 558 | FrameScope frame_scope(masm(), StackFrame::INTERNAL); |
| 559 | if (must_preserve_receiver_reg) { |
| 560 | __ Push(receiver(), holder_reg, this->name()); |
| 561 | } else { |
| 562 | __ Push(holder_reg, this->name()); |
| 563 | } |
| 564 | InterceptorVectorSlotPush(holder_reg); |
| 565 | // Invoke an interceptor. Note: map checks from receiver to |
| 566 | // interceptor's holder has been compiled before (see a caller |
| 567 | // of this method.) |
| 568 | CompileCallLoadPropertyWithInterceptor( |
| 569 | masm(), receiver(), holder_reg, this->name(), holder(), |
| 570 | Runtime::kLoadPropertyWithInterceptorOnly); |
| 571 | |
| 572 | // Check if interceptor provided a value for property. If it's |
| 573 | // the case, return immediately. |
| 574 | Label interceptor_failed; |
| 575 | __ CompareRoot(r2, Heap::kNoInterceptorResultSentinelRootIndex); |
| 576 | __ beq(&interceptor_failed, Label::kNear); |
| 577 | frame_scope.GenerateLeaveFrame(); |
| 578 | __ Ret(); |
| 579 | |
| 580 | __ bind(&interceptor_failed); |
| 581 | InterceptorVectorSlotPop(holder_reg); |
| 582 | __ Pop(this->name()); |
| 583 | __ Pop(holder_reg); |
| 584 | if (must_preserve_receiver_reg) { |
| 585 | __ Pop(receiver()); |
| 586 | } |
| 587 | // Leave the internal frame. |
| 588 | } |
| 589 | |
| 590 | GenerateLoadPostInterceptor(it, holder_reg); |
| 591 | } |
| 592 | |
| 593 | void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) { |
| 594 | // Call the runtime system to load the interceptor. |
| 595 | DCHECK(holder()->HasNamedInterceptor()); |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 596 | DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined(isolate())); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 597 | PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(), |
| 598 | holder()); |
| 599 | |
| 600 | __ TailCallRuntime(Runtime::kLoadPropertyWithInterceptor); |
| 601 | } |
| 602 | |
| 603 | Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( |
| 604 | Handle<JSObject> object, Handle<Name> name, Handle<AccessorInfo> callback, |
| 605 | LanguageMode language_mode) { |
| 606 | Register holder_reg = Frontend(name); |
| 607 | |
| 608 | __ Push(receiver(), holder_reg); // receiver |
| 609 | |
| 610 | // If the callback cannot leak, then push the callback directly, |
| 611 | // otherwise wrap it in a weak cell. |
Ben Murdoch | 61f157c | 2016-09-16 13:49:30 +0100 | [diff] [blame] | 612 | if (callback->data()->IsUndefined(isolate()) || callback->data()->IsSmi()) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 613 | __ mov(ip, Operand(callback)); |
| 614 | } else { |
| 615 | Handle<WeakCell> cell = isolate()->factory()->NewWeakCell(callback); |
| 616 | __ mov(ip, Operand(cell)); |
| 617 | } |
| 618 | __ Push(ip); |
| 619 | __ mov(ip, Operand(name)); |
| 620 | __ Push(ip, value()); |
| 621 | __ Push(Smi::FromInt(language_mode)); |
| 622 | |
| 623 | // Do tail-call to the runtime system. |
| 624 | __ TailCallRuntime(Runtime::kStoreCallbackProperty); |
| 625 | |
| 626 | // Return the generated code. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 627 | return GetCode(kind(), name); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 628 | } |
| 629 | |
| 630 | Register NamedStoreHandlerCompiler::value() { |
| 631 | return StoreDescriptor::ValueRegister(); |
| 632 | } |
| 633 | |
| 634 | Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal( |
| 635 | Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) { |
| 636 | Label miss; |
| 637 | if (IC::ICUseVector(kind())) { |
| 638 | PushVectorAndSlot(); |
| 639 | } |
| 640 | FrontendHeader(receiver(), name, &miss, DONT_RETURN_ANYTHING); |
| 641 | |
| 642 | // Get the value from the cell. |
| 643 | Register result = StoreDescriptor::ValueRegister(); |
| 644 | Handle<WeakCell> weak_cell = factory()->NewWeakCell(cell); |
| 645 | __ LoadWeakValue(result, weak_cell, &miss); |
| 646 | __ LoadP(result, FieldMemOperand(result, PropertyCell::kValueOffset)); |
| 647 | |
| 648 | // Check for deleted property if property can actually be deleted. |
| 649 | if (is_configurable) { |
| 650 | __ CompareRoot(result, Heap::kTheHoleValueRootIndex); |
| 651 | __ beq(&miss); |
| 652 | } |
| 653 | |
| 654 | Counters* counters = isolate()->counters(); |
| 655 | __ IncrementCounter(counters->ic_named_load_global_stub(), 1, r3, r5); |
| 656 | if (IC::ICUseVector(kind())) { |
| 657 | DiscardVectorAndSlot(); |
| 658 | } |
| 659 | __ Ret(); |
| 660 | |
| 661 | FrontendFooter(name, &miss); |
| 662 | |
| 663 | // Return the generated code. |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame] | 664 | return GetCode(kind(), name); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | #undef __ |
| 668 | } // namespace internal |
| 669 | } // namespace v8 |
| 670 | |
| 671 | #endif // V8_TARGET_ARCH_ARM |