Index: src/ia32/code-stubs-ia32.cc |
diff --git a/src/ia32/code-stubs-ia32.cc b/src/ia32/code-stubs-ia32.cc |
index f9bc28dd4bc03240b2f2b280600d442dcdb8c7f1..ff5149e029ce82539a4c27c455b392cf88400062 100644 |
--- a/src/ia32/code-stubs-ia32.cc |
+++ b/src/ia32/code-stubs-ia32.cc |
@@ -12,6 +12,7 @@ |
#include "src/codegen.h" |
#include "src/ic/handler-compiler.h" |
#include "src/ic/ic.h" |
+#include "src/ic/stub-cache.h" |
#include "src/isolate.h" |
#include "src/jsregexp.h" |
#include "src/regexp-macro-assembler.h" |
@@ -4399,15 +4400,234 @@ void StubFailureTrampolineStub::Generate(MacroAssembler* masm) { |
void LoadICTrampolineStub::Generate(MacroAssembler* masm) { |
EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
- VectorLoadStub stub(isolate(), state()); |
- __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
+ VectorRawLoadStub stub(isolate(), state()); |
+ stub.GenerateForTrampoline(masm); |
+ // __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
} |
void KeyedLoadICTrampolineStub::Generate(MacroAssembler* masm) { |
EmitLoadTypeFeedbackVector(masm, VectorLoadICDescriptor::VectorRegister()); |
- VectorKeyedLoadStub stub(isolate()); |
- __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
+ VectorRawKeyedLoadStub stub(isolate()); |
+ stub.GenerateForTrampoline(masm); |
+ // __ jmp(stub.GetCode(), RelocInfo::CODE_TARGET); |
+} |
+ |
+ |
+static void HandleArrayCases(MacroAssembler* masm, Register receiver, |
+ Register key, Register vector, Register slot, |
+ Register feedback, Label* miss) { |
+ // feedback initially contains the feedback array |
+ Label next, next_loop, prepare_next; |
+ Label load_smi_map, compare_map; |
+ |
+ __ push(receiver); |
+ __ push(vector); |
+ |
+ Register receiver_map = receiver; |
+ Register array_map = vector; |
+ |
+ // Receiver might not be a heap object. |
+ __ JumpIfSmi(receiver, &load_smi_map); |
+ __ mov(receiver_map, FieldOperand(receiver, 0)); |
+ __ bind(&compare_map); |
+ __ mov(array_map, FieldOperand(feedback, FixedArray::OffsetOfElementAt(0))); |
+ __ cmp(receiver_map, FieldOperand(array_map, WeakCell::kValueOffset)); |
+ __ j(not_equal, &next); |
+ // found, now call handler. |
+ __ mov(feedback, FieldOperand(feedback, FixedArray::OffsetOfElementAt(1))); |
Toon Verwaest
2015/03/11 17:55:02
feedback -> handler?
Maybe just do Register handle
mvstanton
2015/03/12 17:05:34
Done.
|
+ __ pop(vector); |
+ __ pop(receiver); |
+ __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize)); |
+ __ jmp(feedback); |
+ |
+ __ bind(&next); |
+ __ cmp(FieldOperand(feedback, FixedArray::kLengthOffset), |
+ Immediate(Smi::FromInt(2))); |
Toon Verwaest
2015/03/11 17:55:01
This isn't possible for named loads afaict.
mvstanton
2015/03/12 17:05:34
I addressed this with a boolean, is_polymorphic.
|
+ Label start_polymorphic; |
+ __ j(not_equal, &start_polymorphic); |
+ __ pop(vector); |
+ __ pop(receiver); |
+ __ jmp(miss); |
+ |
+ // Polymorphic, we have to loop from 2 to N |
+ __ bind(&start_polymorphic); |
+ __ push(key); |
Toon Verwaest
2015/03/11 17:55:02
As discussed, you don't need the key for named loa
mvstanton
2015/03/12 17:05:34
Yeah, I don't want to load it from the array very
|
+ Register counter = key; |
+ __ mov(counter, Immediate(Smi::FromInt(2))); |
+ __ bind(&next_loop); |
+ __ mov(array_map, FieldOperand(feedback, counter, times_half_pointer_size, |
+ FixedArray::kHeaderSize)); |
+ __ cmp(receiver_map, FieldOperand(array_map, WeakCell::kValueOffset)); |
+ __ j(not_equal, &prepare_next); |
+ __ mov(feedback, FieldOperand(feedback, counter, times_half_pointer_size, |
+ FixedArray::kHeaderSize + kPointerSize)); |
+ __ pop(key); |
+ __ pop(vector); |
+ __ pop(receiver); |
+ __ lea(feedback, FieldOperand(feedback, Code::kHeaderSize)); |
+ __ jmp(feedback); |
+ |
+ __ bind(&prepare_next); |
+ __ add(counter, Immediate(Smi::FromInt(2))); |
+ __ cmp(counter, FieldOperand(feedback, FixedArray::kLengthOffset)); |
+ __ j(less, &next_loop); |
+ |
+ // We exhausted our array of map handler pairs. |
+ __ pop(key); |
+ __ pop(vector); |
+ __ pop(receiver); |
+ __ jmp(miss); |
+ |
+ __ bind(&load_smi_map); |
+ __ mov(receiver_map, masm->isolate()->factory()->heap_number_map()); |
+ __ jmp(&compare_map); |
+} |
+ |
+ |
+static void HandleMonomorphicCase(MacroAssembler* masm, Register receiver, |
+ Register key, Register vector, Register slot, |
+ Register weak_cell, Label* miss) { |
+ // feedback initially contains the feedback array |
+ Label compare_smi_map; |
+ |
+ // Move the weak map into the weak_cell register. |
+ __ mov(weak_cell, FieldOperand(weak_cell, WeakCell::kValueOffset)); |
+ |
+ // Receiver might not be a heap object. |
+ __ JumpIfSmi(receiver, &compare_smi_map); |
+ __ cmp(weak_cell, FieldOperand(receiver, 0)); |
Toon Verwaest
2015/03/11 17:55:02
Register receiver_map = weak_cell;
mvstanton
2015/03/12 17:05:34
Good idea, but I called it ic_map to indicate it's
|
+ __ j(not_equal, miss); |
+ __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size, |
Toon Verwaest
2015/03/11 17:55:02
Register code_object = weak_cell;
mvstanton
2015/03/12 17:05:34
Cool, but I called it handler per your good sugges
|
+ FixedArray::kHeaderSize + kPointerSize)); |
+ __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize)); |
+ __ jmp(weak_cell); |
+ |
+ // In microbenchmarks, it made sense to unroll this code so that the call to |
+ // the handler is duplicated for a HeapObject receiver and a Smi receiver. |
+ __ bind(&compare_smi_map); |
+ __ cmp(weak_cell, masm->isolate()->factory()->heap_number_map()); |
+ __ j(not_equal, miss); |
+ __ mov(weak_cell, FieldOperand(vector, slot, times_half_pointer_size, |
+ FixedArray::kHeaderSize + kPointerSize)); |
+ __ lea(weak_cell, FieldOperand(weak_cell, Code::kHeaderSize)); |
+ __ jmp(weak_cell); |
+} |
+ |
+ |
+void VectorRawLoadStub::Generate(MacroAssembler* masm) { |
+ GenerateImpl(masm, false); |
+} |
+ |
+ |
+void VectorRawLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
+ GenerateImpl(masm, true); |
+} |
+ |
+ |
+void VectorRawLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
+ Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
+ Register name = VectorLoadICDescriptor::NameRegister(); // ecx |
+ Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
+ Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
+ Factory* factory = masm->isolate()->factory(); |
+ Register scratch = edi; |
+ __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
+ FixedArray::kHeaderSize)); |
+ |
+ // Is it a weak cell? |
+ Label try_array; |
+ Label not_array, smi_key, key_okay, miss; |
+ __ cmp(FieldOperand(scratch, 0), factory->weak_cell_map()); |
+ __ j(not_equal, &try_array); |
+ HandleMonomorphicCase(masm, receiver, name, vector, slot, scratch, &miss); |
+ __ int3(); // We shouldn't get here. |
+ |
+ // Is it a fixed array? |
+ __ bind(&try_array); |
+ __ cmp(FieldOperand(scratch, 0), factory->fixed_array_map()); |
+ __ j(not_equal, ¬_array); |
+ HandleArrayCases(masm, receiver, name, vector, slot, scratch, &miss); |
+ __ int3(); // We shouldn't get here. |
+ |
+ __ bind(¬_array); |
+ __ cmp(scratch, factory->megamorphic_symbol()); |
+ __ j(not_equal, &miss); |
+ __ push(slot); |
+ __ push(vector); |
+ Code::Flags code_flags = Code::RemoveTypeAndHolderFromFlags( |
+ Code::ComputeHandlerFlags(Code::LOAD_IC)); |
+ masm->isolate()->stub_cache()->GenerateProbe( |
+ masm, Code::LOAD_IC, code_flags, false, receiver, name, vector, scratch); |
+ __ pop(vector); |
+ __ pop(slot); |
+ |
+ __ bind(&miss); |
+ LoadIC::GenerateMiss(masm); |
+} |
+ |
+ |
+void VectorRawKeyedLoadStub::Generate(MacroAssembler* masm) { |
+ GenerateImpl(masm, false); |
+} |
+ |
+ |
+void VectorRawKeyedLoadStub::GenerateForTrampoline(MacroAssembler* masm) { |
+ GenerateImpl(masm, true); |
+} |
+ |
+ |
+void VectorRawKeyedLoadStub::GenerateImpl(MacroAssembler* masm, bool in_frame) { |
+ Register receiver = VectorLoadICDescriptor::ReceiverRegister(); // edx |
+ Register key = VectorLoadICDescriptor::NameRegister(); // ecx |
+ Register vector = VectorLoadICDescriptor::VectorRegister(); // ebx |
+ Register slot = VectorLoadICDescriptor::SlotRegister(); // eax |
+ Factory* factory = masm->isolate()->factory(); |
+ Register scratch = edi; |
+ __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
+ FixedArray::kHeaderSize)); |
+ // Is it a weak cell? |
+ Label try_array; |
+ Label not_array, smi_key, key_okay, miss; |
+ __ cmp(FieldOperand(scratch, 0), factory->weak_cell_map()); |
+ __ j(not_equal, &try_array); |
+ __ JumpIfNotSmi(key, &miss); |
+ HandleMonomorphicCase(masm, receiver, key, vector, slot, scratch, &miss); |
+ __ int3(); // We shouldn't get here. |
+ |
+ __ bind(&try_array); |
+ // Is it a fixed array? |
+ __ cmp(FieldOperand(scratch, 0), factory->fixed_array_map()); |
+ __ j(not_equal, ¬_array); |
+ // We have a polymorphic element handler. |
+ __ JumpIfNotSmi(key, &miss); |
+ |
+ Label polymorphic, try_poly_name; |
+ __ bind(&polymorphic); |
+ HandleArrayCases(masm, receiver, key, vector, slot, scratch, &miss); |
+ __ int3(); // We shouldn't get here. |
+ |
+ __ bind(¬_array); |
+ // Is it generic? |
+ __ cmp(scratch, factory->megamorphic_symbol()); |
+ __ j(not_equal, &try_poly_name); |
+ Handle<Code> megamorphic_stub = |
+ KeyedLoadIC::ChooseMegamorphicStub(masm->isolate()); |
+ __ jmp(megamorphic_stub, RelocInfo::CODE_TARGET); |
+ __ int3(); // We shouldn't get here. |
Toon Verwaest
2015/03/11 17:55:01
drop int3(), I presume we can trust __jmp to do th
mvstanton
2015/03/12 17:05:34
Done.
|
+ |
+ __ bind(&try_poly_name); |
+ // We might have a name in scratch, and a fixed array in the next slot. |
+ __ cmp(key, scratch); |
+ __ j(not_equal, &miss); |
+ // If the name comparison succeeded, we know we have a fixed array with |
+ // at least one map/handler pair. |
+ __ mov(scratch, FieldOperand(vector, slot, times_half_pointer_size, |
+ FixedArray::kHeaderSize + kPointerSize)); |
+ __ jmp(&polymorphic); |
+ |
+ __ bind(&miss); |
+ KeyedLoadIC::GenerateMiss(masm); |
} |