OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "src/v8.h" | 5 #include "src/v8.h" |
6 | 6 |
7 #if V8_TARGET_ARCH_IA32 | 7 #if V8_TARGET_ARCH_IA32 |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/bootstrapper.h" | 10 #include "src/bootstrapper.h" |
11 #include "src/code-stubs.h" | 11 #include "src/code-stubs.h" |
12 #include "src/codegen.h" | 12 #include "src/codegen.h" |
13 #include "src/ic/handler-compiler.h" | 13 #include "src/ic/handler-compiler.h" |
14 #include "src/ic/ic.h" | 14 #include "src/ic/ic.h" |
| 15 #include "src/ic/stub-cache.h" |
15 #include "src/isolate.h" | 16 #include "src/isolate.h" |
16 #include "src/jsregexp.h" | 17 #include "src/jsregexp.h" |
17 #include "src/regexp-macro-assembler.h" | 18 #include "src/regexp-macro-assembler.h" |
18 #include "src/runtime/runtime.h" | 19 #include "src/runtime/runtime.h" |
19 | 20 |
20 namespace v8 { | 21 namespace v8 { |
21 namespace internal { | 22 namespace internal { |
22 | 23 |
23 | 24 |
24 static void InitializeArrayConstructorDescriptor( | 25 static void InitializeArrayConstructorDescriptor( |
(...skipping 4367 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4392 __ pop(ecx); | 4393 __ pop(ecx); |
4393 int additional_offset = | 4394 int additional_offset = |
4394 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; | 4395 function_mode() == JS_FUNCTION_STUB_MODE ? kPointerSize : 0; |
4395 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); | 4396 __ lea(esp, MemOperand(esp, ebx, times_pointer_size, additional_offset)); |
4396 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. | 4397 __ jmp(ecx); // Return to IC Miss stub, continuation still on stack. |
4397 } | 4398 } |
4398 | 4399 |
4399 | 4400 |
4400 void LoadICTrampolineStub::Generate(MacroAssembler* masm) { | 4401 void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
4401 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); | 4402 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
4402 VectorLoadStub stub(isolate(), state()); | 4403 VectorRawLoadStub stub(isolate(), state()); |
4403 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4404 stub.GenerateForTrampoline(masm); |
4404 } | 4405 } |
4405 | 4406 |
4406 | 4407 |
4407 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { | 4408 void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
4408 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); | 4409 EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
4409 VectorKeyedLoadStub stub(isolate()); | 4410 VectorRawKeyedLoadStub stub(isolate()); |
4410 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4411 stub.GenerateForTrampoline(masm); |
4411 } | 4412 } |
4412 | 4413 |
4413 | 4414 |
| 4415 static void HandleArrayCases(MacroAssembler* masm, Register receiver, |
| 4416 Register key, Register vector, Register slot, |
| 4417 Register feedback, bool is_polymorphic, |
| 4418 Label* miss) { |
| 4419 // feedback initially contains the feedback array |
| 4420 Label next, next_loop, prepare_next; |
| 4421 Label load_smi_map, compare_map; |
| 4422 Label start_polymorphic; |
| 4423 |
| 4424 __ push(receiver); |
| 4425 __ push(vector); |
| 4426 |
| 4427 Register receiver_map = receiver; |
| 4428 Register cached_map = vector; |
| 4429 |
| 4430 // Receiver might not be a heap object. |
| 4431 __ JumpIfSmi(receiver, &load_smi_map); |
| 4432 __ mov(receiver_map, FieldOperand(receiver, 0)); |
| 4433 __ bind(&compare_map); |
| 4434 __ mov(cached_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
| 4435 |
| 4436 // A named keyed load might have a 2 element array, all other cases can count |
| 4437 // on an array with at least 2 {map, handler} pairs, so they can go right |
| 4438 // into polymorphic array handling. |
| 4439 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4440 __ j(not_equal, is_polymorphic ? &start_polymorphic : &next); |
| 4441 |
| 4442 // found, now call handler. |
| 4443 Register handler = feedback; |
| 4444 __ mov(handler, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
| 4445 __ pop(vector); |
| 4446 __ pop(receiver); |
| 4447 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4448 __ jmp(handler); |
| 4449 |
| 4450 if (!is_polymorphic) { |
| 4451 __ bind(&next); |
| 4452 __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset), |
| 4453 Immediate(Smi::FromInt(2))); |
| 4454 __ j(not_equal, &start_polymorphic); |
| 4455 __ pop(vector); |
| 4456 __ pop(receiver); |
| 4457 __ jmp(miss); |
| 4458 } |
| 4459 |
| 4460 // Polymorphic, we have to loop from 2 to N |
| 4461 __ bind(&start_polymorphic); |
| 4462 __ push(key); |
| 4463 Register counter = key; |
| 4464 __ mov(counter, Immediate(Smi::FromInt(2))); |
| 4465 __ bind(&next_loop); |
| 4466 __ mov(cached_map, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4467 FixedArray::kHeaderSize)); |
| 4468 __ cmp(receiver_map, FieldOperand(cached_map, WeakCell::kValueOffset)); |
| 4469 __ j(not_equal, &prepare_next); |
| 4470 __ mov(handler, FieldOperand(feedback, counter, times_half_pointer_size, |
| 4471 FixedArray::kHeaderSize + kPointerSize)); |
| 4472 __ pop(key); |
| 4473 __ pop(vector); |
| 4474 __ pop(receiver); |
| 4475 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4476 __ jmp(handler); |
| 4477 |
| 4478 __ bind(&prepare_next); |
| 4479 __ add(counter, Immediate(Smi::FromInt(2))); |
| 4480 __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
| 4481 __ j(less, &next_loop); |
| 4482 |
| 4483 // We exhausted our array of map handler pairs. |
| 4484 __ pop(key); |
| 4485 __ pop(vector); |
| 4486 __ pop(receiver); |
| 4487 __ jmp(miss); |
| 4488 |
| 4489 __ bind(&load_smi_map); |
| 4490 __ LoadRoot(receiver_map, Heap::kHeapNumberMapRootIndex); |
| 4491 __ jmp(&compare_map); |
| 4492 } |
| 4493 |
| 4494 |
| 4495 static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
| 4496 Register key, Register vector, Register slot, |
| 4497 Register weak_cell, Label* miss) { |
| 4498 // feedback initially contains the feedback array |
| 4499 Label compare_smi_map; |
| 4500 |
| 4501 // Move the weak map into the weak_cell register. |
| 4502 Register ic_map = weak_cell; |
| 4503 __ mov(ic_map, FieldOperand(weak_cell, WeakCell::kValueOffset)); |
| 4504 |
| 4505 // Receiver might not be a heap object. |
| 4506 __ JumpIfSmi(receiver, &compare_smi_map); |
| 4507 __ cmp(ic_map, FieldOperand(receiver, 0)); |
| 4508 __ j(not_equal, miss); |
| 4509 Register handler = weak_cell; |
| 4510 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 4511 FixedArray::kHeaderSize + kPointerSize)); |
| 4512 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4513 __ jmp(handler); |
| 4514 |
| 4515 // In microbenchmarks, it made sense to unroll this code so that the call to |
| 4516 // the handler is duplicated for a HeapObject receiver and a Smi receiver. |
| 4517 __ bind(&compare_smi_map); |
| 4518 __ CompareRoot(ic_map, Heap::kHeapNumberMapRootIndex); |
| 4519 __ j(not_equal, miss); |
| 4520 __ mov(handler, FieldOperand(vector, slot, times_half_pointer_size, |
| 4521 FixedArray::kHeaderSize + kPointerSize)); |
| 4522 __ lea(handler, FieldOperand(handler, Code::kHeaderSize)); |
| 4523 __ jmp(handler); |
| 4524 } |
| 4525 |
| 4526 |
| 4527 void VectorRawLoadStub::Generate(MacroAssembler* masm) { |
| 4528 GenerateImpl(masm, false); |
| 4529 } |
| 4530 |
| 4531 |
| 4532 void VectorRawLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4533 GenerateImpl(masm, true); |
| 4534 } |
| 4535 |
| 4536 |
| 4537 void VectorRawLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4538 Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
| 4539 Register name = VectorLoadICDescriptor::NameRegister(); // ecx |
| 4540 Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
| 4541 Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
| 4542 Register scratch = edi; |
| 4543 __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
| 4544 FixedArray::kHeaderSize)); |
| 4545 |
| 4546 // Is it a weak cell? |
| 4547 Label try_array; |
| 4548 Label not_array, smi_key, key_okay, miss; |
| 4549 __ CompareRoot(FieldOperand(scratch, 0), Heap::kWeakCellMapRootIndex); |
| 4550 __ j(not_equal, &try_array); |
| 4551 HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss); |
| 4552 |
| 4553 // Is it a fixed array? |
| 4554 __ bind(&try_array); |
| 4555 __ CompareRoot(FieldOperand(scratch, 0), Heap::kFixedArrayMapRootIndex); |
| 4556 __ j(not_equal, ¬_array); |
| 4557 HandleArrayCases(masm, receiver, name, vector, slot, scratch, true, &miss); |
| 4558 |
| 4559 __ bind(¬_array); |
| 4560 __ CompareRoot(scratch, Heap::kmegamorphic_symbolRootIndex); |
| 4561 __ j(not_equal, &miss); |
| 4562 __ push(slot); |
| 4563 __ push(vector); |
| 4564 Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
| 4565 Code::ComputeHandlerFlags(Code::LOAD_IC)); |
| 4566 masm->isolate()->stub_cache()->GenerateProbe( |
| 4567 masm, Code::LOAD_IC, code_flags, false, receiver, name, vector, scratch); |
| 4568 __ pop(vector); |
| 4569 __ pop(slot); |
| 4570 |
| 4571 __ bind(&miss); |
| 4572 LoadIC::GenerateMiss(masm); |
| 4573 } |
| 4574 |
| 4575 |
| 4576 void VectorRawKeyedLoadStub::Generate(MacroAssembler* masm) { |
| 4577 GenerateImpl(masm, false); |
| 4578 } |
| 4579 |
| 4580 |
| 4581 void VectorRawKeyedLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
| 4582 GenerateImpl(masm, true); |
| 4583 } |
| 4584 |
| 4585 |
| 4586 void VectorRawKeyedLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
| 4587 Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
| 4588 Register key = VectorLoadICDescriptor::NameRegister(); // ecx |
| 4589 Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
| 4590 Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
| 4591 Register feedback = edi; |
| 4592 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 4593 FixedArray::kHeaderSize)); |
| 4594 // Is it a weak cell? |
| 4595 Label try_array; |
| 4596 Label not_array, smi_key, key_okay, miss; |
| 4597 __ CompareRoot(FieldOperand(feedback, 0), Heap::kWeakCellMapRootIndex); |
| 4598 __ j(not_equal, &try_array); |
| 4599 __ JumpIfNotSmi(key, &miss); |
| 4600 HandleMonomorphicCase(masm, receiver, key, vector, slot, feedback, &miss); |
| 4601 |
| 4602 __ bind(&try_array); |
| 4603 // Is it a fixed array? |
| 4604 __ CompareRoot(FieldOperand(feedback, 0), Heap::kFixedArrayMapRootIndex); |
| 4605 __ j(not_equal, ¬_array); |
| 4606 // We have a polymorphic element handler. |
| 4607 __ JumpIfNotSmi(key, &miss); |
| 4608 |
| 4609 Label polymorphic, try_poly_name; |
| 4610 __ bind(&polymorphic); |
| 4611 HandleArrayCases(masm, receiver, key, vector, slot, feedback, true, &miss); |
| 4612 |
| 4613 __ bind(¬_array); |
| 4614 // Is it generic? |
| 4615 __ CompareRoot(feedback, Heap::kmegamorphic_symbolRootIndex); |
| 4616 __ j(not_equal, &try_poly_name); |
| 4617 Handle<Code> megamorphic_stub = |
| 4618 KeyedLoadIC::ChooseMegamorphicStub(masm->isolate()); |
| 4619 __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); |
| 4620 |
| 4621 __ bind(&try_poly_name); |
| 4622 // We might have a name in feedback, and a fixed array in the next slot. |
| 4623 __ cmp(key, feedback); |
| 4624 __ j(not_equal, &miss); |
| 4625 // If the name comparison succeeded, we know we have a fixed array with |
| 4626 // at least one map/handler pair. |
| 4627 __ mov(feedback, FieldOperand(vector, slot, times_half_pointer_size, |
| 4628 FixedArray::kHeaderSize + kPointerSize)); |
| 4629 HandleArrayCases(masm, receiver, key, vector, slot, feedback, false, &miss); |
| 4630 |
| 4631 __ bind(&miss); |
| 4632 KeyedLoadIC::GenerateMiss(masm); |
| 4633 } |
| 4634 |
| 4635 |
4414 void CallICTrampolineStub::Generate(MacroAssembler* masm) { | 4636 void CallICTrampolineStub::Generate(MacroAssembler* masm) { |
4415 EmitLoadTypeFeedbackVector(masm, ebx); | 4637 EmitLoadTypeFeedbackVector(masm, ebx); |
4416 CallICStub stub(isolate(), state()); | 4638 CallICStub stub(isolate(), state()); |
4417 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); | 4639 __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
4418 } | 4640 } |
4419 | 4641 |
4420 | 4642 |
4421 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) { | 4643 void CallIC_ArrayTrampolineStub::Generate(MacroAssembler* masm) { |
4422 EmitLoadTypeFeedbackVector(masm, ebx); | 4644 EmitLoadTypeFeedbackVector(masm, ebx); |
4423 CallIC_ArrayStub stub(isolate(), state()); | 4645 CallIC_ArrayStub stub(isolate(), state()); |
(...skipping 760 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5184 ApiParameterOperand(2), kStackSpace, nullptr, | 5406 ApiParameterOperand(2), kStackSpace, nullptr, |
5185 Operand(ebp, 7 * kPointerSize), NULL); | 5407 Operand(ebp, 7 * kPointerSize), NULL); |
5186 } | 5408 } |
5187 | 5409 |
5188 | 5410 |
5189 #undef __ | 5411 #undef __ |
5190 | 5412 |
5191 } } // namespace v8::internal | 5413 } } // namespace v8::internal |
5192 | 5414 |
5193 #endif // V8_TARGET_ARCH_IA32 | 5415 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |