| OLD | NEW |
| (Empty) |
| 1 // Copyright 2012 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_X87 | |
| 8 | |
| 9 #include "src/codegen.h" | |
| 10 #include "src/ic-inl.h" | |
| 11 #include "src/stub-cache.h" | |
| 12 | |
| 13 namespace v8 { | |
| 14 namespace internal { | |
| 15 | |
| 16 #define __ ACCESS_MASM(masm) | |
| 17 | |
| 18 | |
| 19 static void ProbeTable(Isolate* isolate, | |
| 20 MacroAssembler* masm, | |
| 21 Code::Flags flags, | |
| 22 StubCache::Table table, | |
| 23 Register name, | |
| 24 Register receiver, | |
| 25 // Number of the cache entry pointer-size scaled. | |
| 26 Register offset, | |
| 27 Register extra) { | |
| 28 ExternalReference key_offset(isolate->stub_cache()->key_reference(table)); | |
| 29 ExternalReference value_offset(isolate->stub_cache()->value_reference(table)); | |
| 30 ExternalReference map_offset(isolate->stub_cache()->map_reference(table)); | |
| 31 | |
| 32 Label miss; | |
| 33 | |
| 34 // Multiply by 3 because there are 3 fields per entry (name, code, map). | |
| 35 __ lea(offset, Operand(offset, offset, times_2, 0)); | |
| 36 | |
| 37 if (extra.is_valid()) { | |
| 38 // Get the code entry from the cache. | |
| 39 __ mov(extra, Operand::StaticArray(offset, times_1, value_offset)); | |
| 40 | |
| 41 // Check that the key in the entry matches the name. | |
| 42 __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); | |
| 43 __ j(not_equal, &miss); | |
| 44 | |
| 45 // Check the map matches. | |
| 46 __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); | |
| 47 __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); | |
| 48 __ j(not_equal, &miss); | |
| 49 | |
| 50 // Check that the flags match what we're looking for. | |
| 51 __ mov(offset, FieldOperand(extra, Code::kFlagsOffset)); | |
| 52 __ and_(offset, ~Code::kFlagsNotUsedInLookup); | |
| 53 __ cmp(offset, flags); | |
| 54 __ j(not_equal, &miss); | |
| 55 | |
| 56 #ifdef DEBUG | |
| 57 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | |
| 58 __ jmp(&miss); | |
| 59 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | |
| 60 __ jmp(&miss); | |
| 61 } | |
| 62 #endif | |
| 63 | |
| 64 // Jump to the first instruction in the code stub. | |
| 65 __ add(extra, Immediate(Code::kHeaderSize - kHeapObjectTag)); | |
| 66 __ jmp(extra); | |
| 67 | |
| 68 __ bind(&miss); | |
| 69 } else { | |
| 70 // Save the offset on the stack. | |
| 71 __ push(offset); | |
| 72 | |
| 73 // Check that the key in the entry matches the name. | |
| 74 __ cmp(name, Operand::StaticArray(offset, times_1, key_offset)); | |
| 75 __ j(not_equal, &miss); | |
| 76 | |
| 77 // Check the map matches. | |
| 78 __ mov(offset, Operand::StaticArray(offset, times_1, map_offset)); | |
| 79 __ cmp(offset, FieldOperand(receiver, HeapObject::kMapOffset)); | |
| 80 __ j(not_equal, &miss); | |
| 81 | |
| 82 // Restore offset register. | |
| 83 __ mov(offset, Operand(esp, 0)); | |
| 84 | |
| 85 // Get the code entry from the cache. | |
| 86 __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); | |
| 87 | |
| 88 // Check that the flags match what we're looking for. | |
| 89 __ mov(offset, FieldOperand(offset, Code::kFlagsOffset)); | |
| 90 __ and_(offset, ~Code::kFlagsNotUsedInLookup); | |
| 91 __ cmp(offset, flags); | |
| 92 __ j(not_equal, &miss); | |
| 93 | |
| 94 #ifdef DEBUG | |
| 95 if (FLAG_test_secondary_stub_cache && table == StubCache::kPrimary) { | |
| 96 __ jmp(&miss); | |
| 97 } else if (FLAG_test_primary_stub_cache && table == StubCache::kSecondary) { | |
| 98 __ jmp(&miss); | |
| 99 } | |
| 100 #endif | |
| 101 | |
| 102 // Restore offset and re-load code entry from cache. | |
| 103 __ pop(offset); | |
| 104 __ mov(offset, Operand::StaticArray(offset, times_1, value_offset)); | |
| 105 | |
| 106 // Jump to the first instruction in the code stub. | |
| 107 __ add(offset, Immediate(Code::kHeaderSize - kHeapObjectTag)); | |
| 108 __ jmp(offset); | |
| 109 | |
| 110 // Pop at miss. | |
| 111 __ bind(&miss); | |
| 112 __ pop(offset); | |
| 113 } | |
| 114 } | |
| 115 | |
| 116 | |
| 117 void PropertyHandlerCompiler::GenerateDictionaryNegativeLookup( | |
| 118 MacroAssembler* masm, Label* miss_label, Register receiver, | |
| 119 Handle<Name> name, Register scratch0, Register scratch1) { | |
| 120 DCHECK(name->IsUniqueName()); | |
| 121 DCHECK(!receiver.is(scratch0)); | |
| 122 Counters* counters = masm->isolate()->counters(); | |
| 123 __ IncrementCounter(counters->negative_lookups(), 1); | |
| 124 __ IncrementCounter(counters->negative_lookups_miss(), 1); | |
| 125 | |
| 126 __ mov(scratch0, FieldOperand(receiver, HeapObject::kMapOffset)); | |
| 127 | |
| 128 const int kInterceptorOrAccessCheckNeededMask = | |
| 129 (1 << Map::kHasNamedInterceptor) | (1 << Map::kIsAccessCheckNeeded); | |
| 130 | |
| 131 // Bail out if the receiver has a named interceptor or requires access checks. | |
| 132 __ test_b(FieldOperand(scratch0, Map::kBitFieldOffset), | |
| 133 kInterceptorOrAccessCheckNeededMask); | |
| 134 __ j(not_zero, miss_label); | |
| 135 | |
| 136 // Check that receiver is a JSObject. | |
| 137 __ CmpInstanceType(scratch0, FIRST_SPEC_OBJECT_TYPE); | |
| 138 __ j(below, miss_label); | |
| 139 | |
| 140 // Load properties array. | |
| 141 Register properties = scratch0; | |
| 142 __ mov(properties, FieldOperand(receiver, JSObject::kPropertiesOffset)); | |
| 143 | |
| 144 // Check that the properties array is a dictionary. | |
| 145 __ cmp(FieldOperand(properties, HeapObject::kMapOffset), | |
| 146 Immediate(masm->isolate()->factory()->hash_table_map())); | |
| 147 __ j(not_equal, miss_label); | |
| 148 | |
| 149 Label done; | |
| 150 NameDictionaryLookupStub::GenerateNegativeLookup(masm, | |
| 151 miss_label, | |
| 152 &done, | |
| 153 properties, | |
| 154 name, | |
| 155 scratch1); | |
| 156 __ bind(&done); | |
| 157 __ DecrementCounter(counters->negative_lookups_miss(), 1); | |
| 158 } | |
| 159 | |
| 160 | |
| 161 void StubCache::GenerateProbe(MacroAssembler* masm, | |
| 162 Code::Flags flags, | |
| 163 Register receiver, | |
| 164 Register name, | |
| 165 Register scratch, | |
| 166 Register extra, | |
| 167 Register extra2, | |
| 168 Register extra3) { | |
| 169 Label miss; | |
| 170 | |
| 171 // Assert that code is valid. The multiplying code relies on the entry size | |
| 172 // being 12. | |
| 173 DCHECK(sizeof(Entry) == 12); | |
| 174 | |
| 175 // Assert the flags do not name a specific type. | |
| 176 DCHECK(Code::ExtractTypeFromFlags(flags) == 0); | |
| 177 | |
| 178 // Assert that there are no register conflicts. | |
| 179 DCHECK(!scratch.is(receiver)); | |
| 180 DCHECK(!scratch.is(name)); | |
| 181 DCHECK(!extra.is(receiver)); | |
| 182 DCHECK(!extra.is(name)); | |
| 183 DCHECK(!extra.is(scratch)); | |
| 184 | |
| 185 // Assert scratch and extra registers are valid, and extra2/3 are unused. | |
| 186 DCHECK(!scratch.is(no_reg)); | |
| 187 DCHECK(extra2.is(no_reg)); | |
| 188 DCHECK(extra3.is(no_reg)); | |
| 189 | |
| 190 Register offset = scratch; | |
| 191 scratch = no_reg; | |
| 192 | |
| 193 Counters* counters = masm->isolate()->counters(); | |
| 194 __ IncrementCounter(counters->megamorphic_stub_cache_probes(), 1); | |
| 195 | |
| 196 // Check that the receiver isn't a smi. | |
| 197 __ JumpIfSmi(receiver, &miss); | |
| 198 | |
| 199 // Get the map of the receiver and compute the hash. | |
| 200 __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); | |
| 201 __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); | |
| 202 __ xor_(offset, flags); | |
| 203 // We mask out the last two bits because they are not part of the hash and | |
| 204 // they are always 01 for maps. Also in the two 'and' instructions below. | |
| 205 __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift); | |
| 206 // ProbeTable expects the offset to be pointer scaled, which it is, because | |
| 207 // the heap object tag size is 2 and the pointer size log 2 is also 2. | |
| 208 DCHECK(kCacheIndexShift == kPointerSizeLog2); | |
| 209 | |
| 210 // Probe the primary table. | |
| 211 ProbeTable(isolate(), masm, flags, kPrimary, name, receiver, offset, extra); | |
| 212 | |
| 213 // Primary miss: Compute hash for secondary probe. | |
| 214 __ mov(offset, FieldOperand(name, Name::kHashFieldOffset)); | |
| 215 __ add(offset, FieldOperand(receiver, HeapObject::kMapOffset)); | |
| 216 __ xor_(offset, flags); | |
| 217 __ and_(offset, (kPrimaryTableSize - 1) << kCacheIndexShift); | |
| 218 __ sub(offset, name); | |
| 219 __ add(offset, Immediate(flags)); | |
| 220 __ and_(offset, (kSecondaryTableSize - 1) << kCacheIndexShift); | |
| 221 | |
| 222 // Probe the secondary table. | |
| 223 ProbeTable( | |
| 224 isolate(), masm, flags, kSecondary, name, receiver, offset, extra); | |
| 225 | |
| 226 // Cache miss: Fall-through and let caller handle the miss by | |
| 227 // entering the runtime system. | |
| 228 __ bind(&miss); | |
| 229 __ IncrementCounter(counters->megamorphic_stub_cache_misses(), 1); | |
| 230 } | |
| 231 | |
| 232 | |
| 233 void NamedLoadHandlerCompiler::GenerateDirectLoadGlobalFunctionPrototype( | |
| 234 MacroAssembler* masm, int index, Register prototype, Label* miss) { | |
| 235 // Get the global function with the given index. | |
| 236 Handle<JSFunction> function( | |
| 237 JSFunction::cast(masm->isolate()->native_context()->get(index))); | |
| 238 // Check we're still in the same context. | |
| 239 Register scratch = prototype; | |
| 240 const int offset = Context::SlotOffset(Context::GLOBAL_OBJECT_INDEX); | |
| 241 __ mov(scratch, Operand(esi, offset)); | |
| 242 __ mov(scratch, FieldOperand(scratch, GlobalObject::kNativeContextOffset)); | |
| 243 __ cmp(Operand(scratch, Context::SlotOffset(index)), function); | |
| 244 __ j(not_equal, miss); | |
| 245 | |
| 246 // Load its initial map. The global functions all have initial maps. | |
| 247 __ Move(prototype, Immediate(Handle<Map>(function->initial_map()))); | |
| 248 // Load the prototype from the initial map. | |
| 249 __ mov(prototype, FieldOperand(prototype, Map::kPrototypeOffset)); | |
| 250 } | |
| 251 | |
| 252 | |
| 253 void NamedLoadHandlerCompiler::GenerateLoadFunctionPrototype( | |
| 254 MacroAssembler* masm, Register receiver, Register scratch1, | |
| 255 Register scratch2, Label* miss_label) { | |
| 256 __ TryGetFunctionPrototype(receiver, scratch1, scratch2, miss_label); | |
| 257 __ mov(eax, scratch1); | |
| 258 __ ret(0); | |
| 259 } | |
| 260 | |
| 261 | |
| 262 static void PushInterceptorArguments(MacroAssembler* masm, | |
| 263 Register receiver, | |
| 264 Register holder, | |
| 265 Register name, | |
| 266 Handle<JSObject> holder_obj) { | |
| 267 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsNameIndex == 0); | |
| 268 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsInfoIndex == 1); | |
| 269 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsThisIndex == 2); | |
| 270 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsHolderIndex == 3); | |
| 271 STATIC_ASSERT(NamedLoadHandlerCompiler::kInterceptorArgsLength == 4); | |
| 272 __ push(name); | |
| 273 Handle<InterceptorInfo> interceptor(holder_obj->GetNamedInterceptor()); | |
| 274 DCHECK(!masm->isolate()->heap()->InNewSpace(*interceptor)); | |
| 275 Register scratch = name; | |
| 276 __ mov(scratch, Immediate(interceptor)); | |
| 277 __ push(scratch); | |
| 278 __ push(receiver); | |
| 279 __ push(holder); | |
| 280 } | |
| 281 | |
| 282 | |
| 283 static void CompileCallLoadPropertyWithInterceptor( | |
| 284 MacroAssembler* masm, | |
| 285 Register receiver, | |
| 286 Register holder, | |
| 287 Register name, | |
| 288 Handle<JSObject> holder_obj, | |
| 289 IC::UtilityId id) { | |
| 290 PushInterceptorArguments(masm, receiver, holder, name, holder_obj); | |
| 291 __ CallExternalReference(ExternalReference(IC_Utility(id), masm->isolate()), | |
| 292 NamedLoadHandlerCompiler::kInterceptorArgsLength); | |
| 293 } | |
| 294 | |
| 295 | |
| 296 // Generate call to api function. | |
| 297 // This function uses push() to generate smaller, faster code than | |
| 298 // the version above. It is an optimization that should will be removed | |
| 299 // when api call ICs are generated in hydrogen. | |
| 300 void PropertyHandlerCompiler::GenerateFastApiCall( | |
| 301 MacroAssembler* masm, const CallOptimization& optimization, | |
| 302 Handle<Map> receiver_map, Register receiver, Register scratch_in, | |
| 303 bool is_store, int argc, Register* values) { | |
| 304 // Copy return value. | |
| 305 __ pop(scratch_in); | |
| 306 // receiver | |
| 307 __ push(receiver); | |
| 308 // Write the arguments to stack frame. | |
| 309 for (int i = 0; i < argc; i++) { | |
| 310 Register arg = values[argc-1-i]; | |
| 311 DCHECK(!receiver.is(arg)); | |
| 312 DCHECK(!scratch_in.is(arg)); | |
| 313 __ push(arg); | |
| 314 } | |
| 315 __ push(scratch_in); | |
| 316 // Stack now matches JSFunction abi. | |
| 317 DCHECK(optimization.is_simple_api_call()); | |
| 318 | |
| 319 // Abi for CallApiFunctionStub. | |
| 320 Register callee = eax; | |
| 321 Register call_data = ebx; | |
| 322 Register holder = ecx; | |
| 323 Register api_function_address = edx; | |
| 324 Register scratch = edi; // scratch_in is no longer valid. | |
| 325 | |
| 326 // Put holder in place. | |
| 327 CallOptimization::HolderLookup holder_lookup; | |
| 328 Handle<JSObject> api_holder = optimization.LookupHolderOfExpectedType( | |
| 329 receiver_map, | |
| 330 &holder_lookup); | |
| 331 switch (holder_lookup) { | |
| 332 case CallOptimization::kHolderIsReceiver: | |
| 333 __ Move(holder, receiver); | |
| 334 break; | |
| 335 case CallOptimization::kHolderFound: | |
| 336 __ LoadHeapObject(holder, api_holder); | |
| 337 break; | |
| 338 case CallOptimization::kHolderNotFound: | |
| 339 UNREACHABLE(); | |
| 340 break; | |
| 341 } | |
| 342 | |
| 343 Isolate* isolate = masm->isolate(); | |
| 344 Handle<JSFunction> function = optimization.constant_function(); | |
| 345 Handle<CallHandlerInfo> api_call_info = optimization.api_call_info(); | |
| 346 Handle<Object> call_data_obj(api_call_info->data(), isolate); | |
| 347 | |
| 348 // Put callee in place. | |
| 349 __ LoadHeapObject(callee, function); | |
| 350 | |
| 351 bool call_data_undefined = false; | |
| 352 // Put call_data in place. | |
| 353 if (isolate->heap()->InNewSpace(*call_data_obj)) { | |
| 354 __ mov(scratch, api_call_info); | |
| 355 __ mov(call_data, FieldOperand(scratch, CallHandlerInfo::kDataOffset)); | |
| 356 } else if (call_data_obj->IsUndefined()) { | |
| 357 call_data_undefined = true; | |
| 358 __ mov(call_data, Immediate(isolate->factory()->undefined_value())); | |
| 359 } else { | |
| 360 __ mov(call_data, call_data_obj); | |
| 361 } | |
| 362 | |
| 363 // Put api_function_address in place. | |
| 364 Address function_address = v8::ToCData<Address>(api_call_info->callback()); | |
| 365 __ mov(api_function_address, Immediate(function_address)); | |
| 366 | |
| 367 // Jump to stub. | |
| 368 CallApiFunctionStub stub(isolate, is_store, call_data_undefined, argc); | |
| 369 __ TailCallStub(&stub); | |
| 370 } | |
| 371 | |
| 372 | |
| 373 // Generate code to check that a global property cell is empty. Create | |
| 374 // the property cell at compilation time if no cell exists for the | |
| 375 // property. | |
| 376 void PropertyHandlerCompiler::GenerateCheckPropertyCell( | |
| 377 MacroAssembler* masm, Handle<JSGlobalObject> global, Handle<Name> name, | |
| 378 Register scratch, Label* miss) { | |
| 379 Handle<PropertyCell> cell = | |
| 380 JSGlobalObject::EnsurePropertyCell(global, name); | |
| 381 DCHECK(cell->value()->IsTheHole()); | |
| 382 Handle<Oddball> the_hole = masm->isolate()->factory()->the_hole_value(); | |
| 383 if (masm->serializer_enabled()) { | |
| 384 __ mov(scratch, Immediate(cell)); | |
| 385 __ cmp(FieldOperand(scratch, PropertyCell::kValueOffset), | |
| 386 Immediate(the_hole)); | |
| 387 } else { | |
| 388 __ cmp(Operand::ForCell(cell), Immediate(the_hole)); | |
| 389 } | |
| 390 __ j(not_equal, miss); | |
| 391 } | |
| 392 | |
| 393 | |
| 394 void PropertyAccessCompiler::GenerateTailCall(MacroAssembler* masm, | |
| 395 Handle<Code> code) { | |
| 396 __ jmp(code, RelocInfo::CODE_TARGET); | |
| 397 } | |
| 398 | |
| 399 | |
| 400 #undef __ | |
| 401 #define __ ACCESS_MASM(masm()) | |
| 402 | |
| 403 | |
| 404 void NamedStoreHandlerCompiler::GenerateRestoreName(Label* label, | |
| 405 Handle<Name> name) { | |
| 406 if (!label->is_unused()) { | |
| 407 __ bind(label); | |
| 408 __ mov(this->name(), Immediate(name)); | |
| 409 } | |
| 410 } | |
| 411 | |
| 412 | |
| 413 // Receiver_reg is preserved on jumps to miss_label, but may be destroyed if | |
| 414 // store is successful. | |
| 415 void NamedStoreHandlerCompiler::GenerateStoreTransition( | |
| 416 Handle<Map> transition, Handle<Name> name, Register receiver_reg, | |
| 417 Register storage_reg, Register value_reg, Register scratch1, | |
| 418 Register scratch2, Register unused, Label* miss_label, Label* slow) { | |
| 419 int descriptor = transition->LastAdded(); | |
| 420 DescriptorArray* descriptors = transition->instance_descriptors(); | |
| 421 PropertyDetails details = descriptors->GetDetails(descriptor); | |
| 422 Representation representation = details.representation(); | |
| 423 DCHECK(!representation.IsNone()); | |
| 424 | |
| 425 if (details.type() == CONSTANT) { | |
| 426 Handle<Object> constant(descriptors->GetValue(descriptor), isolate()); | |
| 427 __ CmpObject(value_reg, constant); | |
| 428 __ j(not_equal, miss_label); | |
| 429 } else if (representation.IsSmi()) { | |
| 430 __ JumpIfNotSmi(value_reg, miss_label); | |
| 431 } else if (representation.IsHeapObject()) { | |
| 432 __ JumpIfSmi(value_reg, miss_label); | |
| 433 HeapType* field_type = descriptors->GetFieldType(descriptor); | |
| 434 HeapType::Iterator<Map> it = field_type->Classes(); | |
| 435 if (!it.Done()) { | |
| 436 Label do_store; | |
| 437 while (true) { | |
| 438 __ CompareMap(value_reg, it.Current()); | |
| 439 it.Advance(); | |
| 440 if (it.Done()) { | |
| 441 __ j(not_equal, miss_label); | |
| 442 break; | |
| 443 } | |
| 444 __ j(equal, &do_store, Label::kNear); | |
| 445 } | |
| 446 __ bind(&do_store); | |
| 447 } | |
| 448 } else if (representation.IsDouble()) { | |
| 449 Label do_store, heap_number; | |
| 450 __ AllocateHeapNumber(storage_reg, scratch1, scratch2, slow, MUTABLE); | |
| 451 | |
| 452 __ JumpIfNotSmi(value_reg, &heap_number); | |
| 453 __ SmiUntag(value_reg); | |
| 454 __ push(value_reg); | |
| 455 __ fild_s(Operand(esp, 0)); | |
| 456 __ pop(value_reg); | |
| 457 __ SmiTag(value_reg); | |
| 458 __ jmp(&do_store); | |
| 459 | |
| 460 __ bind(&heap_number); | |
| 461 __ CheckMap(value_reg, isolate()->factory()->heap_number_map(), miss_label, | |
| 462 DONT_DO_SMI_CHECK); | |
| 463 __ fld_d(FieldOperand(value_reg, HeapNumber::kValueOffset)); | |
| 464 | |
| 465 __ bind(&do_store); | |
| 466 __ fstp_d(FieldOperand(storage_reg, HeapNumber::kValueOffset)); | |
| 467 } | |
| 468 | |
| 469 // Stub never generated for objects that require access checks. | |
| 470 DCHECK(!transition->is_access_check_needed()); | |
| 471 | |
| 472 // Perform map transition for the receiver if necessary. | |
| 473 if (details.type() == FIELD && | |
| 474 Map::cast(transition->GetBackPointer())->unused_property_fields() == 0) { | |
| 475 // The properties must be extended before we can store the value. | |
| 476 // We jump to a runtime call that extends the properties array. | |
| 477 __ pop(scratch1); // Return address. | |
| 478 __ push(receiver_reg); | |
| 479 __ push(Immediate(transition)); | |
| 480 __ push(value_reg); | |
| 481 __ push(scratch1); | |
| 482 __ TailCallExternalReference( | |
| 483 ExternalReference(IC_Utility(IC::kSharedStoreIC_ExtendStorage), | |
| 484 isolate()), | |
| 485 3, 1); | |
| 486 return; | |
| 487 } | |
| 488 | |
| 489 // Update the map of the object. | |
| 490 __ mov(scratch1, Immediate(transition)); | |
| 491 __ mov(FieldOperand(receiver_reg, HeapObject::kMapOffset), scratch1); | |
| 492 | |
| 493 // Update the write barrier for the map field. | |
| 494 __ RecordWriteField(receiver_reg, | |
| 495 HeapObject::kMapOffset, | |
| 496 scratch1, | |
| 497 scratch2, | |
| 498 OMIT_REMEMBERED_SET, | |
| 499 OMIT_SMI_CHECK); | |
| 500 | |
| 501 if (details.type() == CONSTANT) { | |
| 502 DCHECK(value_reg.is(eax)); | |
| 503 __ ret(0); | |
| 504 return; | |
| 505 } | |
| 506 | |
| 507 int index = transition->instance_descriptors()->GetFieldIndex( | |
| 508 transition->LastAdded()); | |
| 509 | |
| 510 // Adjust for the number of properties stored in the object. Even in the | |
| 511 // face of a transition we can use the old map here because the size of the | |
| 512 // object and the number of in-object properties is not going to change. | |
| 513 index -= transition->inobject_properties(); | |
| 514 | |
| 515 SmiCheck smi_check = representation.IsTagged() | |
| 516 ? INLINE_SMI_CHECK : OMIT_SMI_CHECK; | |
| 517 // TODO(verwaest): Share this code as a code stub. | |
| 518 if (index < 0) { | |
| 519 // Set the property straight into the object. | |
| 520 int offset = transition->instance_size() + (index * kPointerSize); | |
| 521 if (representation.IsDouble()) { | |
| 522 __ mov(FieldOperand(receiver_reg, offset), storage_reg); | |
| 523 } else { | |
| 524 __ mov(FieldOperand(receiver_reg, offset), value_reg); | |
| 525 } | |
| 526 | |
| 527 if (!representation.IsSmi()) { | |
| 528 // Update the write barrier for the array address. | |
| 529 if (!representation.IsDouble()) { | |
| 530 __ mov(storage_reg, value_reg); | |
| 531 } | |
| 532 __ RecordWriteField(receiver_reg, | |
| 533 offset, | |
| 534 storage_reg, | |
| 535 scratch1, | |
| 536 EMIT_REMEMBERED_SET, | |
| 537 smi_check); | |
| 538 } | |
| 539 } else { | |
| 540 // Write to the properties array. | |
| 541 int offset = index * kPointerSize + FixedArray::kHeaderSize; | |
| 542 // Get the properties array (optimistically). | |
| 543 __ mov(scratch1, FieldOperand(receiver_reg, JSObject::kPropertiesOffset)); | |
| 544 if (representation.IsDouble()) { | |
| 545 __ mov(FieldOperand(scratch1, offset), storage_reg); | |
| 546 } else { | |
| 547 __ mov(FieldOperand(scratch1, offset), value_reg); | |
| 548 } | |
| 549 | |
| 550 if (!representation.IsSmi()) { | |
| 551 // Update the write barrier for the array address. | |
| 552 if (!representation.IsDouble()) { | |
| 553 __ mov(storage_reg, value_reg); | |
| 554 } | |
| 555 __ RecordWriteField(scratch1, | |
| 556 offset, | |
| 557 storage_reg, | |
| 558 receiver_reg, | |
| 559 EMIT_REMEMBERED_SET, | |
| 560 smi_check); | |
| 561 } | |
| 562 } | |
| 563 | |
| 564 // Return the value (register eax). | |
| 565 DCHECK(value_reg.is(eax)); | |
| 566 __ ret(0); | |
| 567 } | |
| 568 | |
| 569 | |
| 570 void NamedStoreHandlerCompiler::GenerateStoreField(LookupIterator* lookup, | |
| 571 Register value_reg, | |
| 572 Label* miss_label) { | |
| 573 DCHECK(lookup->representation().IsHeapObject()); | |
| 574 __ JumpIfSmi(value_reg, miss_label); | |
| 575 HeapType::Iterator<Map> it = lookup->GetFieldType()->Classes(); | |
| 576 Label do_store; | |
| 577 while (true) { | |
| 578 __ CompareMap(value_reg, it.Current()); | |
| 579 it.Advance(); | |
| 580 if (it.Done()) { | |
| 581 __ j(not_equal, miss_label); | |
| 582 break; | |
| 583 } | |
| 584 __ j(equal, &do_store, Label::kNear); | |
| 585 } | |
| 586 __ bind(&do_store); | |
| 587 | |
| 588 StoreFieldStub stub(isolate(), lookup->GetFieldIndex(), | |
| 589 lookup->representation()); | |
| 590 GenerateTailCall(masm(), stub.GetCode()); | |
| 591 } | |
| 592 | |
| 593 | |
| 594 Register PropertyHandlerCompiler::CheckPrototypes( | |
| 595 Register object_reg, Register holder_reg, Register scratch1, | |
| 596 Register scratch2, Handle<Name> name, Label* miss, | |
| 597 PrototypeCheckType check) { | |
| 598 Handle<Map> receiver_map(IC::TypeToMap(*type(), isolate())); | |
| 599 | |
| 600 // Make sure there's no overlap between holder and object registers. | |
| 601 DCHECK(!scratch1.is(object_reg) && !scratch1.is(holder_reg)); | |
| 602 DCHECK(!scratch2.is(object_reg) && !scratch2.is(holder_reg) | |
| 603 && !scratch2.is(scratch1)); | |
| 604 | |
| 605 // Keep track of the current object in register reg. | |
| 606 Register reg = object_reg; | |
| 607 int depth = 0; | |
| 608 | |
| 609 Handle<JSObject> current = Handle<JSObject>::null(); | |
| 610 if (type()->IsConstant()) | |
| 611 current = Handle<JSObject>::cast(type()->AsConstant()->Value()); | |
| 612 Handle<JSObject> prototype = Handle<JSObject>::null(); | |
| 613 Handle<Map> current_map = receiver_map; | |
| 614 Handle<Map> holder_map(holder()->map()); | |
| 615 // Traverse the prototype chain and check the maps in the prototype chain for | |
| 616 // fast and global objects or do negative lookup for normal objects. | |
| 617 while (!current_map.is_identical_to(holder_map)) { | |
| 618 ++depth; | |
| 619 | |
| 620 // Only global objects and objects that do not require access | |
| 621 // checks are allowed in stubs. | |
| 622 DCHECK(current_map->IsJSGlobalProxyMap() || | |
| 623 !current_map->is_access_check_needed()); | |
| 624 | |
| 625 prototype = handle(JSObject::cast(current_map->prototype())); | |
| 626 if (current_map->is_dictionary_map() && | |
| 627 !current_map->IsJSGlobalObjectMap()) { | |
| 628 DCHECK(!current_map->IsJSGlobalProxyMap()); // Proxy maps are fast. | |
| 629 if (!name->IsUniqueName()) { | |
| 630 DCHECK(name->IsString()); | |
| 631 name = factory()->InternalizeString(Handle<String>::cast(name)); | |
| 632 } | |
| 633 DCHECK(current.is_null() || | |
| 634 current->property_dictionary()->FindEntry(name) == | |
| 635 NameDictionary::kNotFound); | |
| 636 | |
| 637 GenerateDictionaryNegativeLookup(masm(), miss, reg, name, | |
| 638 scratch1, scratch2); | |
| 639 | |
| 640 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); | |
| 641 reg = holder_reg; // From now on the object will be in holder_reg. | |
| 642 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); | |
| 643 } else { | |
| 644 bool in_new_space = heap()->InNewSpace(*prototype); | |
| 645 // Two possible reasons for loading the prototype from the map: | |
| 646 // (1) Can't store references to new space in code. | |
| 647 // (2) Handler is shared for all receivers with the same prototype | |
| 648 // map (but not necessarily the same prototype instance). | |
| 649 bool load_prototype_from_map = in_new_space || depth == 1; | |
| 650 if (depth != 1 || check == CHECK_ALL_MAPS) { | |
| 651 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); | |
| 652 } | |
| 653 | |
| 654 // Check access rights to the global object. This has to happen after | |
| 655 // the map check so that we know that the object is actually a global | |
| 656 // object. | |
| 657 // This allows us to install generated handlers for accesses to the | |
| 658 // global proxy (as opposed to using slow ICs). See corresponding code | |
| 659 // in LookupForRead(). | |
| 660 if (current_map->IsJSGlobalProxyMap()) { | |
| 661 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); | |
| 662 } else if (current_map->IsJSGlobalObjectMap()) { | |
| 663 GenerateCheckPropertyCell( | |
| 664 masm(), Handle<JSGlobalObject>::cast(current), name, | |
| 665 scratch2, miss); | |
| 666 } | |
| 667 | |
| 668 if (load_prototype_from_map) { | |
| 669 // Save the map in scratch1 for later. | |
| 670 __ mov(scratch1, FieldOperand(reg, HeapObject::kMapOffset)); | |
| 671 } | |
| 672 | |
| 673 reg = holder_reg; // From now on the object will be in holder_reg. | |
| 674 | |
| 675 if (load_prototype_from_map) { | |
| 676 __ mov(reg, FieldOperand(scratch1, Map::kPrototypeOffset)); | |
| 677 } else { | |
| 678 __ mov(reg, prototype); | |
| 679 } | |
| 680 } | |
| 681 | |
| 682 // Go to the next object in the prototype chain. | |
| 683 current = prototype; | |
| 684 current_map = handle(current->map()); | |
| 685 } | |
| 686 | |
| 687 // Log the check depth. | |
| 688 LOG(isolate(), IntEvent("check-maps-depth", depth + 1)); | |
| 689 | |
| 690 if (depth != 0 || check == CHECK_ALL_MAPS) { | |
| 691 // Check the holder map. | |
| 692 __ CheckMap(reg, current_map, miss, DONT_DO_SMI_CHECK); | |
| 693 } | |
| 694 | |
| 695 // Perform security check for access to the global object. | |
| 696 DCHECK(current_map->IsJSGlobalProxyMap() || | |
| 697 !current_map->is_access_check_needed()); | |
| 698 if (current_map->IsJSGlobalProxyMap()) { | |
| 699 __ CheckAccessGlobalProxy(reg, scratch1, scratch2, miss); | |
| 700 } | |
| 701 | |
| 702 // Return the register containing the holder. | |
| 703 return reg; | |
| 704 } | |
| 705 | |
| 706 | |
| 707 void NamedLoadHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { | |
| 708 if (!miss->is_unused()) { | |
| 709 Label success; | |
| 710 __ jmp(&success); | |
| 711 __ bind(miss); | |
| 712 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
| 713 __ bind(&success); | |
| 714 } | |
| 715 } | |
| 716 | |
| 717 | |
| 718 void NamedStoreHandlerCompiler::FrontendFooter(Handle<Name> name, Label* miss) { | |
| 719 if (!miss->is_unused()) { | |
| 720 Label success; | |
| 721 __ jmp(&success); | |
| 722 GenerateRestoreName(miss, name); | |
| 723 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
| 724 __ bind(&success); | |
| 725 } | |
| 726 } | |
| 727 | |
| 728 | |
| 729 void NamedLoadHandlerCompiler::GenerateLoadCallback( | |
| 730 Register reg, Handle<ExecutableAccessorInfo> callback) { | |
| 731 // Insert additional parameters into the stack frame above return address. | |
| 732 DCHECK(!scratch3().is(reg)); | |
| 733 __ pop(scratch3()); // Get return address to place it below. | |
| 734 | |
| 735 STATIC_ASSERT(PropertyCallbackArguments::kHolderIndex == 0); | |
| 736 STATIC_ASSERT(PropertyCallbackArguments::kIsolateIndex == 1); | |
| 737 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueDefaultValueIndex == 2); | |
| 738 STATIC_ASSERT(PropertyCallbackArguments::kReturnValueOffset == 3); | |
| 739 STATIC_ASSERT(PropertyCallbackArguments::kDataIndex == 4); | |
| 740 STATIC_ASSERT(PropertyCallbackArguments::kThisIndex == 5); | |
| 741 __ push(receiver()); // receiver | |
| 742 // Push data from ExecutableAccessorInfo. | |
| 743 if (isolate()->heap()->InNewSpace(callback->data())) { | |
| 744 DCHECK(!scratch2().is(reg)); | |
| 745 __ mov(scratch2(), Immediate(callback)); | |
| 746 __ push(FieldOperand(scratch2(), ExecutableAccessorInfo::kDataOffset)); | |
| 747 } else { | |
| 748 __ push(Immediate(Handle<Object>(callback->data(), isolate()))); | |
| 749 } | |
| 750 __ push(Immediate(isolate()->factory()->undefined_value())); // ReturnValue | |
| 751 // ReturnValue default value | |
| 752 __ push(Immediate(isolate()->factory()->undefined_value())); | |
| 753 __ push(Immediate(reinterpret_cast<int>(isolate()))); | |
| 754 __ push(reg); // holder | |
| 755 | |
| 756 // Save a pointer to where we pushed the arguments. This will be | |
| 757 // passed as the const PropertyAccessorInfo& to the C++ callback. | |
| 758 __ push(esp); | |
| 759 | |
| 760 __ push(name()); // name | |
| 761 | |
| 762 __ push(scratch3()); // Restore return address. | |
| 763 | |
| 764 // Abi for CallApiGetter | |
| 765 Register getter_address = edx; | |
| 766 Address function_address = v8::ToCData<Address>(callback->getter()); | |
| 767 __ mov(getter_address, Immediate(function_address)); | |
| 768 | |
| 769 CallApiGetterStub stub(isolate()); | |
| 770 __ TailCallStub(&stub); | |
| 771 } | |
| 772 | |
| 773 | |
| 774 void NamedLoadHandlerCompiler::GenerateLoadConstant(Handle<Object> value) { | |
| 775 // Return the constant value. | |
| 776 __ LoadObject(eax, value); | |
| 777 __ ret(0); | |
| 778 } | |
| 779 | |
| 780 | |
| 781 void NamedLoadHandlerCompiler::GenerateLoadInterceptorWithFollowup( | |
| 782 LookupIterator* it, Register holder_reg) { | |
| 783 DCHECK(holder()->HasNamedInterceptor()); | |
| 784 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); | |
| 785 | |
| 786 // Compile the interceptor call, followed by inline code to load the | |
| 787 // property from further up the prototype chain if the call fails. | |
| 788 // Check that the maps haven't changed. | |
| 789 DCHECK(holder_reg.is(receiver()) || holder_reg.is(scratch1())); | |
| 790 | |
| 791 // Preserve the receiver register explicitly whenever it is different from the | |
| 792 // holder and it is needed should the interceptor return without any result. | |
| 793 // The ACCESSOR case needs the receiver to be passed into C++ code, the FIELD | |
| 794 // case might cause a miss during the prototype check. | |
| 795 bool must_perform_prototype_check = | |
| 796 !holder().is_identical_to(it->GetHolder<JSObject>()); | |
| 797 bool must_preserve_receiver_reg = | |
| 798 !receiver().is(holder_reg) && | |
| 799 (it->property_kind() == LookupIterator::ACCESSOR || | |
| 800 must_perform_prototype_check); | |
| 801 | |
| 802 // Save necessary data before invoking an interceptor. | |
| 803 // Requires a frame to make GC aware of pushed pointers. | |
| 804 { | |
| 805 FrameScope frame_scope(masm(), StackFrame::INTERNAL); | |
| 806 | |
| 807 if (must_preserve_receiver_reg) { | |
| 808 __ push(receiver()); | |
| 809 } | |
| 810 __ push(holder_reg); | |
| 811 __ push(this->name()); | |
| 812 | |
| 813 // Invoke an interceptor. Note: map checks from receiver to | |
| 814 // interceptor's holder has been compiled before (see a caller | |
| 815 // of this method.) | |
| 816 CompileCallLoadPropertyWithInterceptor( | |
| 817 masm(), receiver(), holder_reg, this->name(), holder(), | |
| 818 IC::kLoadPropertyWithInterceptorOnly); | |
| 819 | |
| 820 // Check if interceptor provided a value for property. If it's | |
| 821 // the case, return immediately. | |
| 822 Label interceptor_failed; | |
| 823 __ cmp(eax, factory()->no_interceptor_result_sentinel()); | |
| 824 __ j(equal, &interceptor_failed); | |
| 825 frame_scope.GenerateLeaveFrame(); | |
| 826 __ ret(0); | |
| 827 | |
| 828 // Clobber registers when generating debug-code to provoke errors. | |
| 829 __ bind(&interceptor_failed); | |
| 830 if (FLAG_debug_code) { | |
| 831 __ mov(receiver(), Immediate(BitCast<int32_t>(kZapValue))); | |
| 832 __ mov(holder_reg, Immediate(BitCast<int32_t>(kZapValue))); | |
| 833 __ mov(this->name(), Immediate(BitCast<int32_t>(kZapValue))); | |
| 834 } | |
| 835 | |
| 836 __ pop(this->name()); | |
| 837 __ pop(holder_reg); | |
| 838 if (must_preserve_receiver_reg) { | |
| 839 __ pop(receiver()); | |
| 840 } | |
| 841 | |
| 842 // Leave the internal frame. | |
| 843 } | |
| 844 | |
| 845 GenerateLoadPostInterceptor(it, holder_reg); | |
| 846 } | |
| 847 | |
| 848 | |
| 849 void NamedLoadHandlerCompiler::GenerateLoadInterceptor(Register holder_reg) { | |
| 850 DCHECK(holder()->HasNamedInterceptor()); | |
| 851 DCHECK(!holder()->GetNamedInterceptor()->getter()->IsUndefined()); | |
| 852 // Call the runtime system to load the interceptor. | |
| 853 __ pop(scratch2()); // save old return address | |
| 854 PushInterceptorArguments(masm(), receiver(), holder_reg, this->name(), | |
| 855 holder()); | |
| 856 __ push(scratch2()); // restore old return address | |
| 857 | |
| 858 ExternalReference ref = ExternalReference( | |
| 859 IC_Utility(IC::kLoadPropertyWithInterceptor), isolate()); | |
| 860 __ TailCallExternalReference( | |
| 861 ref, NamedLoadHandlerCompiler::kInterceptorArgsLength, 1); | |
| 862 } | |
| 863 | |
| 864 | |
| 865 Handle<Code> NamedStoreHandlerCompiler::CompileStoreCallback( | |
| 866 Handle<JSObject> object, Handle<Name> name, | |
| 867 Handle<ExecutableAccessorInfo> callback) { | |
| 868 Register holder_reg = Frontend(receiver(), name); | |
| 869 | |
| 870 __ pop(scratch1()); // remove the return address | |
| 871 __ push(receiver()); | |
| 872 __ push(holder_reg); | |
| 873 __ Push(callback); | |
| 874 __ Push(name); | |
| 875 __ push(value()); | |
| 876 __ push(scratch1()); // restore return address | |
| 877 | |
| 878 // Do tail-call to the runtime system. | |
| 879 ExternalReference store_callback_property = | |
| 880 ExternalReference(IC_Utility(IC::kStoreCallbackProperty), isolate()); | |
| 881 __ TailCallExternalReference(store_callback_property, 5, 1); | |
| 882 | |
| 883 // Return the generated code. | |
| 884 return GetCode(kind(), Code::FAST, name); | |
| 885 } | |
| 886 | |
| 887 | |
| 888 #undef __ | |
| 889 #define __ ACCESS_MASM(masm) | |
| 890 | |
| 891 | |
| 892 void NamedStoreHandlerCompiler::GenerateStoreViaSetter( | |
| 893 MacroAssembler* masm, Handle<HeapType> type, Register receiver, | |
| 894 Handle<JSFunction> setter) { | |
| 895 // ----------- S t a t e ------------- | |
| 896 // -- esp[0] : return address | |
| 897 // ----------------------------------- | |
| 898 { | |
| 899 FrameScope scope(masm, StackFrame::INTERNAL); | |
| 900 | |
| 901 // Save value register, so we can restore it later. | |
| 902 __ push(value()); | |
| 903 | |
| 904 if (!setter.is_null()) { | |
| 905 // Call the JavaScript setter with receiver and value on the stack. | |
| 906 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { | |
| 907 // Swap in the global receiver. | |
| 908 __ mov(receiver, | |
| 909 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); | |
| 910 } | |
| 911 __ push(receiver); | |
| 912 __ push(value()); | |
| 913 ParameterCount actual(1); | |
| 914 ParameterCount expected(setter); | |
| 915 __ InvokeFunction(setter, expected, actual, | |
| 916 CALL_FUNCTION, NullCallWrapper()); | |
| 917 } else { | |
| 918 // If we generate a global code snippet for deoptimization only, remember | |
| 919 // the place to continue after deoptimization. | |
| 920 masm->isolate()->heap()->SetSetterStubDeoptPCOffset(masm->pc_offset()); | |
| 921 } | |
| 922 | |
| 923 // We have to return the passed value, not the return value of the setter. | |
| 924 __ pop(eax); | |
| 925 | |
| 926 // Restore context register. | |
| 927 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
| 928 } | |
| 929 __ ret(0); | |
| 930 } | |
| 931 | |
| 932 | |
| 933 #undef __ | |
| 934 #define __ ACCESS_MASM(masm()) | |
| 935 | |
| 936 | |
| 937 Handle<Code> NamedStoreHandlerCompiler::CompileStoreInterceptor( | |
| 938 Handle<Name> name) { | |
| 939 __ pop(scratch1()); // remove the return address | |
| 940 __ push(receiver()); | |
| 941 __ push(this->name()); | |
| 942 __ push(value()); | |
| 943 __ push(scratch1()); // restore return address | |
| 944 | |
| 945 // Do tail-call to the runtime system. | |
| 946 ExternalReference store_ic_property = ExternalReference( | |
| 947 IC_Utility(IC::kStorePropertyWithInterceptor), isolate()); | |
| 948 __ TailCallExternalReference(store_ic_property, 3, 1); | |
| 949 | |
| 950 // Return the generated code. | |
| 951 return GetCode(kind(), Code::FAST, name); | |
| 952 } | |
| 953 | |
| 954 | |
| 955 Handle<Code> PropertyICCompiler::CompileKeyedStorePolymorphic( | |
| 956 MapHandleList* receiver_maps, CodeHandleList* handler_stubs, | |
| 957 MapHandleList* transitioned_maps) { | |
| 958 Label miss; | |
| 959 __ JumpIfSmi(receiver(), &miss, Label::kNear); | |
| 960 __ mov(scratch1(), FieldOperand(receiver(), HeapObject::kMapOffset)); | |
| 961 for (int i = 0; i < receiver_maps->length(); ++i) { | |
| 962 __ cmp(scratch1(), receiver_maps->at(i)); | |
| 963 if (transitioned_maps->at(i).is_null()) { | |
| 964 __ j(equal, handler_stubs->at(i)); | |
| 965 } else { | |
| 966 Label next_map; | |
| 967 __ j(not_equal, &next_map, Label::kNear); | |
| 968 __ mov(transition_map(), Immediate(transitioned_maps->at(i))); | |
| 969 __ jmp(handler_stubs->at(i), RelocInfo::CODE_TARGET); | |
| 970 __ bind(&next_map); | |
| 971 } | |
| 972 } | |
| 973 __ bind(&miss); | |
| 974 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
| 975 | |
| 976 // Return the generated code. | |
| 977 return GetCode(kind(), Code::NORMAL, factory()->empty_string(), POLYMORPHIC); | |
| 978 } | |
| 979 | |
| 980 | |
| 981 Register* PropertyAccessCompiler::load_calling_convention() { | |
| 982 // receiver, name, scratch1, scratch2, scratch3, scratch4. | |
| 983 Register receiver = LoadIC::ReceiverRegister(); | |
| 984 Register name = LoadIC::NameRegister(); | |
| 985 static Register registers[] = { receiver, name, ebx, eax, edi, no_reg }; | |
| 986 return registers; | |
| 987 } | |
| 988 | |
| 989 | |
| 990 Register* PropertyAccessCompiler::store_calling_convention() { | |
| 991 // receiver, name, scratch1, scratch2, scratch3. | |
| 992 Register receiver = StoreIC::ReceiverRegister(); | |
| 993 Register name = StoreIC::NameRegister(); | |
| 994 DCHECK(ebx.is(KeyedStoreIC::MapRegister())); | |
| 995 static Register registers[] = { receiver, name, ebx, edi, no_reg }; | |
| 996 return registers; | |
| 997 } | |
| 998 | |
| 999 | |
| 1000 Register NamedStoreHandlerCompiler::value() { return StoreIC::ValueRegister(); } | |
| 1001 | |
| 1002 | |
| 1003 #undef __ | |
| 1004 #define __ ACCESS_MASM(masm) | |
| 1005 | |
| 1006 | |
| 1007 void NamedLoadHandlerCompiler::GenerateLoadViaGetter( | |
| 1008 MacroAssembler* masm, Handle<HeapType> type, Register receiver, | |
| 1009 Handle<JSFunction> getter) { | |
| 1010 { | |
| 1011 FrameScope scope(masm, StackFrame::INTERNAL); | |
| 1012 | |
| 1013 if (!getter.is_null()) { | |
| 1014 // Call the JavaScript getter with the receiver on the stack. | |
| 1015 if (IC::TypeToMap(*type, masm->isolate())->IsJSGlobalObjectMap()) { | |
| 1016 // Swap in the global receiver. | |
| 1017 __ mov(receiver, | |
| 1018 FieldOperand(receiver, JSGlobalObject::kGlobalProxyOffset)); | |
| 1019 } | |
| 1020 __ push(receiver); | |
| 1021 ParameterCount actual(0); | |
| 1022 ParameterCount expected(getter); | |
| 1023 __ InvokeFunction(getter, expected, actual, | |
| 1024 CALL_FUNCTION, NullCallWrapper()); | |
| 1025 } else { | |
| 1026 // If we generate a global code snippet for deoptimization only, remember | |
| 1027 // the place to continue after deoptimization. | |
| 1028 masm->isolate()->heap()->SetGetterStubDeoptPCOffset(masm->pc_offset()); | |
| 1029 } | |
| 1030 | |
| 1031 // Restore context register. | |
| 1032 __ mov(esi, Operand(ebp, StandardFrameConstants::kContextOffset)); | |
| 1033 } | |
| 1034 __ ret(0); | |
| 1035 } | |
| 1036 | |
| 1037 | |
| 1038 #undef __ | |
| 1039 #define __ ACCESS_MASM(masm()) | |
| 1040 | |
| 1041 | |
| 1042 Handle<Code> NamedLoadHandlerCompiler::CompileLoadGlobal( | |
| 1043 Handle<PropertyCell> cell, Handle<Name> name, bool is_configurable) { | |
| 1044 Label miss; | |
| 1045 | |
| 1046 FrontendHeader(receiver(), name, &miss); | |
| 1047 // Get the value from the cell. | |
| 1048 Register result = StoreIC::ValueRegister(); | |
| 1049 if (masm()->serializer_enabled()) { | |
| 1050 __ mov(result, Immediate(cell)); | |
| 1051 __ mov(result, FieldOperand(result, PropertyCell::kValueOffset)); | |
| 1052 } else { | |
| 1053 __ mov(result, Operand::ForCell(cell)); | |
| 1054 } | |
| 1055 | |
| 1056 // Check for deleted property if property can actually be deleted. | |
| 1057 if (is_configurable) { | |
| 1058 __ cmp(result, factory()->the_hole_value()); | |
| 1059 __ j(equal, &miss); | |
| 1060 } else if (FLAG_debug_code) { | |
| 1061 __ cmp(result, factory()->the_hole_value()); | |
| 1062 __ Check(not_equal, kDontDeleteCellsCannotContainTheHole); | |
| 1063 } | |
| 1064 | |
| 1065 Counters* counters = isolate()->counters(); | |
| 1066 __ IncrementCounter(counters->named_load_global_stub(), 1); | |
| 1067 // The code above already loads the result into the return register. | |
| 1068 __ ret(0); | |
| 1069 | |
| 1070 FrontendFooter(name, &miss); | |
| 1071 | |
| 1072 // Return the generated code. | |
| 1073 return GetCode(kind(), Code::NORMAL, name); | |
| 1074 } | |
| 1075 | |
| 1076 | |
| 1077 Handle<Code> PropertyICCompiler::CompilePolymorphic(TypeHandleList* types, | |
| 1078 CodeHandleList* handlers, | |
| 1079 Handle<Name> name, | |
| 1080 Code::StubType type, | |
| 1081 IcCheckType check) { | |
| 1082 Label miss; | |
| 1083 | |
| 1084 if (check == PROPERTY && | |
| 1085 (kind() == Code::KEYED_LOAD_IC || kind() == Code::KEYED_STORE_IC)) { | |
| 1086 // In case we are compiling an IC for dictionary loads and stores, just | |
| 1087 // check whether the name is unique. | |
| 1088 if (name.is_identical_to(isolate()->factory()->normal_ic_symbol())) { | |
| 1089 __ JumpIfNotUniqueName(this->name(), &miss); | |
| 1090 } else { | |
| 1091 __ cmp(this->name(), Immediate(name)); | |
| 1092 __ j(not_equal, &miss); | |
| 1093 } | |
| 1094 } | |
| 1095 | |
| 1096 Label number_case; | |
| 1097 Label* smi_target = IncludesNumberType(types) ? &number_case : &miss; | |
| 1098 __ JumpIfSmi(receiver(), smi_target); | |
| 1099 | |
| 1100 // Polymorphic keyed stores may use the map register | |
| 1101 Register map_reg = scratch1(); | |
| 1102 DCHECK(kind() != Code::KEYED_STORE_IC || | |
| 1103 map_reg.is(KeyedStoreIC::MapRegister())); | |
| 1104 __ mov(map_reg, FieldOperand(receiver(), HeapObject::kMapOffset)); | |
| 1105 int receiver_count = types->length(); | |
| 1106 int number_of_handled_maps = 0; | |
| 1107 for (int current = 0; current < receiver_count; ++current) { | |
| 1108 Handle<HeapType> type = types->at(current); | |
| 1109 Handle<Map> map = IC::TypeToMap(*type, isolate()); | |
| 1110 if (!map->is_deprecated()) { | |
| 1111 number_of_handled_maps++; | |
| 1112 __ cmp(map_reg, map); | |
| 1113 if (type->Is(HeapType::Number())) { | |
| 1114 DCHECK(!number_case.is_unused()); | |
| 1115 __ bind(&number_case); | |
| 1116 } | |
| 1117 __ j(equal, handlers->at(current)); | |
| 1118 } | |
| 1119 } | |
| 1120 DCHECK(number_of_handled_maps != 0); | |
| 1121 | |
| 1122 __ bind(&miss); | |
| 1123 TailCallBuiltin(masm(), MissBuiltin(kind())); | |
| 1124 | |
| 1125 // Return the generated code. | |
| 1126 InlineCacheState state = | |
| 1127 number_of_handled_maps > 1 ? POLYMORPHIC : MONOMORPHIC; | |
| 1128 return GetCode(kind(), type, name, state); | |
| 1129 } | |
| 1130 | |
| 1131 | |
| 1132 #undef __ | |
| 1133 #define __ ACCESS_MASM(masm) | |
| 1134 | |
| 1135 | |
| 1136 void ElementHandlerCompiler::GenerateLoadDictionaryElement( | |
| 1137 MacroAssembler* masm) { | |
| 1138 // ----------- S t a t e ------------- | |
| 1139 // -- ecx : key | |
| 1140 // -- edx : receiver | |
| 1141 // -- esp[0] : return address | |
| 1142 // ----------------------------------- | |
| 1143 DCHECK(edx.is(LoadIC::ReceiverRegister())); | |
| 1144 DCHECK(ecx.is(LoadIC::NameRegister())); | |
| 1145 Label slow, miss; | |
| 1146 | |
| 1147 // This stub is meant to be tail-jumped to, the receiver must already | |
| 1148 // have been verified by the caller to not be a smi. | |
| 1149 __ JumpIfNotSmi(ecx, &miss); | |
| 1150 __ mov(ebx, ecx); | |
| 1151 __ SmiUntag(ebx); | |
| 1152 __ mov(eax, FieldOperand(edx, JSObject::kElementsOffset)); | |
| 1153 | |
| 1154 // Push receiver on the stack to free up a register for the dictionary | |
| 1155 // probing. | |
| 1156 __ push(edx); | |
| 1157 __ LoadFromNumberDictionary(&slow, eax, ecx, ebx, edx, edi, eax); | |
| 1158 // Pop receiver before returning. | |
| 1159 __ pop(edx); | |
| 1160 __ ret(0); | |
| 1161 | |
| 1162 __ bind(&slow); | |
| 1163 __ pop(edx); | |
| 1164 | |
| 1165 // ----------- S t a t e ------------- | |
| 1166 // -- ecx : key | |
| 1167 // -- edx : receiver | |
| 1168 // -- esp[0] : return address | |
| 1169 // ----------------------------------- | |
| 1170 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Slow); | |
| 1171 | |
| 1172 __ bind(&miss); | |
| 1173 // ----------- S t a t e ------------- | |
| 1174 // -- ecx : key | |
| 1175 // -- edx : receiver | |
| 1176 // -- esp[0] : return address | |
| 1177 // ----------------------------------- | |
| 1178 TailCallBuiltin(masm, Builtins::kKeyedLoadIC_Miss); | |
| 1179 } | |
| 1180 | |
| 1181 | |
| 1182 #undef __ | |
| 1183 | |
| 1184 } } // namespace v8::internal | |
| 1185 | |
| 1186 #endif // V8_TARGET_ARCH_X87 | |
| OLD | NEW |