Chromium Code Reviews| Index: src/ia32/stub-cache-ia32.cc |
| diff --git a/src/ia32/stub-cache-ia32.cc b/src/ia32/stub-cache-ia32.cc |
| index e5e6b47f9cee64863ff2d0c564d09dde21c8006d..27a0e4476146c8d5447f338f0ff7201b3aa77385 100644 |
| --- a/src/ia32/stub-cache-ia32.cc |
| +++ b/src/ia32/stub-cache-ia32.cc |
| @@ -713,6 +713,14 @@ void StubCompiler::GenerateLoadMiss(MacroAssembler* masm, Code::Kind kind) { |
| } |
| +void StubCompiler::GenerateKeyedLoadMissForceGeneric(MacroAssembler* masm) { |
| + Code* code = masm->isolate()->builtins()->builtin( |
| + Builtins::kKeyedLoadIC_MissForceGeneric); |
|
Mads Ager (chromium)
2011/05/10 13:38:06
four-space indent?
danno
2011/05/11 14:20:19
Done.
|
| + Handle<Code> ic(code); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| +} |
| + |
| + |
| // Both name_reg and receiver_reg are preserved on jumps to miss_label, |
| // but may be destroyed if store is successful. |
| void StubCompiler::GenerateStoreField(MacroAssembler* masm, |
| @@ -2654,60 +2662,56 @@ MaybeObject* KeyedStoreStubCompiler::CompileStoreField(JSObject* object, |
| } |
| -MaybeObject* KeyedStoreStubCompiler::CompileStoreSpecialized( |
| - JSObject* receiver) { |
| +MaybeObject* KeyedStoreStubCompiler::CompileStoreFastElement( |
| + Map* receiver_map) { |
| // ----------- S t a t e ------------- |
| // -- eax : value |
| // -- ecx : key |
| // -- edx : receiver |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - Label miss; |
| + KeyedStoreIC keyed_store_ic(isolate()); |
| + MaybeObject* maybe_stub = |
| + keyed_store_ic.ComputeMonomorphicBuiltinFastElementStub( |
| + receiver_map->instance_type() == JS_ARRAY_TYPE); |
| + Code* stub; |
| + if (!maybe_stub->To(&stub)) return maybe_stub; |
| + __ DispatchMap(edx, |
| + Handle<Map>(receiver_map), |
| + Handle<Code>(stub), |
| + false); |
| - // Check that the receiver isn't a smi. |
| - __ test(edx, Immediate(kSmiTagMask)); |
| - __ j(zero, &miss, not_taken); |
| + Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss(); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| - // Check that the map matches. |
| - __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| - Immediate(Handle<Map>(receiver->map()))); |
| - __ j(not_equal, &miss, not_taken); |
| + // Return the generated code. |
| + return GetCode(NORMAL, NULL); |
| +} |
| - // Check that the key is a smi. |
| - __ test(ecx, Immediate(kSmiTagMask)); |
| - __ j(not_zero, &miss, not_taken); |
| - // Get the elements array and make sure it is a fast element array, not 'cow'. |
| - __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
| - __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| - Immediate(factory()->fixed_array_map())); |
| - __ j(not_equal, &miss, not_taken); |
| +MaybeObject* KeyedStoreStubCompiler::CompileStoreMegamorphic( |
| + MapList* receiver_maps, |
| + CodeList* handler_ics) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : value |
| + // -- ecx : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + Label miss; |
| + __ JumpIfSmi(edx, &miss); |
| - // Check that the key is within bounds. |
| - if (receiver->IsJSArray()) { |
| - __ cmp(ecx, FieldOperand(edx, JSArray::kLengthOffset)); // Compare smis. |
| - __ j(above_equal, &miss, not_taken); |
| - } else { |
| - __ cmp(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); // Compare smis. |
| - __ j(above_equal, &miss, not_taken); |
| + int receiver_count = receiver_maps->length(); |
| + for (int current = 0; current < receiver_count; ++current) { |
| + Handle<Map> map(receiver_maps->at(current)); |
| + __ DispatchMap(edx, map, Handle<Code>(handler_ics->at(current)), true); |
| } |
| - |
| - // Do the store and update the write barrier. Make sure to preserve |
| - // the value in register eax. |
| - __ mov(edx, Operand(eax)); |
| - __ mov(FieldOperand(edi, ecx, times_2, FixedArray::kHeaderSize), eax); |
| - __ RecordWrite(edi, 0, edx, ecx); |
| - |
| - // Done. |
| - __ ret(0); |
| - |
| - // Handle store cache miss. |
| __ bind(&miss); |
| - Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss(); |
| - __ jmp(ic, RelocInfo::CODE_TARGET); |
| + Handle<Code> miss_ic = isolate()->builtins()->KeyedStoreIC_Miss(); |
| + __ jmp(miss_ic, RelocInfo::CODE_TARGET); |
| // Return the generated code. |
| - return GetCode(NORMAL, NULL); |
| + return GetCode(NORMAL, NULL, MEGAMORPHIC); |
| } |
| @@ -3120,48 +3124,51 @@ MaybeObject* KeyedLoadStubCompiler::CompileLoadFunctionPrototype(String* name) { |
| } |
| -MaybeObject* KeyedLoadStubCompiler::CompileLoadSpecialized(JSObject* receiver) { |
| +MaybeObject* KeyedLoadStubCompiler::CompileLoadFastElement(Map* receiver_map) { |
| // ----------- S t a t e ------------- |
| // -- eax : key |
| // -- edx : receiver |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - Label miss; |
| + KeyedLoadIC keyed_load_ic(isolate()); |
| + MaybeObject* maybe_stub = |
| + keyed_load_ic.ComputeMonomorphicBuiltinFastElementStub( |
| + receiver_map->instance_type() == JS_ARRAY_TYPE); |
| + Code* stub; |
| + if (!maybe_stub->To(&stub)) return maybe_stub; |
| + __ DispatchMap(edx, |
| + Handle<Map>(receiver_map), |
| + Handle<Code>(stub), |
| + false); |
| - // Check that the receiver isn't a smi. |
| - __ test(edx, Immediate(kSmiTagMask)); |
| - __ j(zero, &miss, not_taken); |
| - |
| - // Check that the map matches. |
| - __ cmp(FieldOperand(edx, HeapObject::kMapOffset), |
| - Immediate(Handle<Map>(receiver->map()))); |
| - __ j(not_equal, &miss, not_taken); |
| - |
| - // Check that the key is a smi. |
| - __ test(eax, Immediate(kSmiTagMask)); |
| - __ j(not_zero, &miss, not_taken); |
| + GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| - // Get the elements array. |
| - __ mov(ecx, FieldOperand(edx, JSObject::kElementsOffset)); |
| - __ AssertFastElements(ecx); |
| + // Return the generated code. |
| + return GetCode(NORMAL, NULL); |
| +} |
| - // Check that the key is within bounds. |
| - __ cmp(eax, FieldOperand(ecx, FixedArray::kLengthOffset)); |
| - __ j(above_equal, &miss, not_taken); |
| - // Load the result and make sure it's not the hole. |
| - __ mov(ebx, Operand(ecx, eax, times_2, |
| - FixedArray::kHeaderSize - kHeapObjectTag)); |
| - __ cmp(ebx, factory()->the_hole_value()); |
| - __ j(equal, &miss, not_taken); |
| - __ mov(eax, ebx); |
| - __ ret(0); |
| +MaybeObject* KeyedLoadStubCompiler::CompileLoadMegamorphic( |
| + MapList* receiver_maps, |
| + CodeList* handler_ics) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + Label miss; |
| + __ JumpIfSmi(edx, &miss); |
| + int receiver_count = receiver_maps->length(); |
| + for (int current = 0; current < receiver_count; ++current) { |
| + Handle<Map> map(receiver_maps->at(current)); |
| + __ DispatchMap(edx, map, Handle<Code>(handler_ics->at(current)), true); |
| + } |
| __ bind(&miss); |
| GenerateLoadMiss(masm(), Code::KEYED_LOAD_IC); |
| // Return the generated code. |
| - return GetCode(NORMAL, NULL); |
| + return GetCode(NORMAL, NULL, MEGAMORPHIC); |
| } |
| @@ -3304,36 +3311,75 @@ MaybeObject* ConstructStubCompiler::CompileConstructStub(JSFunction* function) { |
| } |
| -MaybeObject* ExternalArrayStubCompiler::CompileKeyedLoadStub( |
| - JSObject*receiver, ExternalArrayType array_type, Code::Flags flags) { |
| +MaybeObject* ExternalArrayLoadStubCompiler::CompileLoad( |
| + JSObject*receiver, ExternalArrayType array_type) { |
| // ----------- S t a t e ------------- |
| // -- eax : key |
| // -- edx : receiver |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - Label slow, failed_allocation; |
| + KeyedLoadIC load_ic(isolate()); |
| + MaybeObject* maybe_stub = |
| + load_ic.ComputeMonomorphicBuiltinExternalArrayStub(array_type); |
| + Code* stub; |
| + if (!maybe_stub->To(&stub)) return maybe_stub; |
| + __ DispatchMap(edx, Handle<Map>(receiver->map()), Handle<Code>(stub), false); |
| + |
| + Handle<Code> ic = isolate()->builtins()->KeyedLoadIC_Miss(); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| - // Check that the object isn't a smi. |
| - __ test(edx, Immediate(kSmiTagMask)); |
| - __ j(zero, &slow, not_taken); |
| + // Return the generated code. |
| + return GetCode(); |
| +} |
| + |
| + |
| +MaybeObject* ExternalArrayStoreStubCompiler::CompileStore( |
| + JSObject* receiver, ExternalArrayType array_type) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : value |
| + // -- ecx : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + KeyedStoreIC store_ic(isolate()); |
| + MaybeObject* maybe_stub = |
| + store_ic.ComputeMonomorphicBuiltinExternalArrayStub(array_type); |
| + Code* stub; |
| + if (!maybe_stub->To(&stub)) return maybe_stub; |
| + __ DispatchMap(edx, Handle<Map>(receiver->map()), Handle<Code>(stub), false); |
| + |
| + Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Slow(); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| + |
| + return GetCode(); |
| +} |
| + |
| + |
| +#undef __ |
| +#define __ ACCESS_MASM(masm) |
| + |
| + |
| +void KeyedLoadStubCompiler::GenerateLoadExternalArray( |
| + MacroAssembler* masm, |
| + ExternalArrayType array_type) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + Label miss_force_generic, failed_allocation, slow; |
| // Check that the key is a smi. |
| __ test(eax, Immediate(kSmiTagMask)); |
| - __ j(not_zero, &slow, not_taken); |
| - |
| - // Check that the map matches. |
| - __ CheckMap(edx, Handle<Map>(receiver->map()), &slow, false); |
| - __ mov(ebx, FieldOperand(edx, JSObject::kElementsOffset)); |
| + __ j(not_zero, &miss_force_generic, not_taken); |
| - // eax: key, known to be a smi. |
| - // edx: receiver, known to be a JSObject. |
| - // ebx: elements object, known to be an external array. |
| // Check that the index is in range. |
| __ mov(ecx, eax); |
| __ SmiUntag(ecx); // Untag the index. |
| + __ mov(ebx, FieldOperand(edx, JSObject::kElementsOffset)); |
| __ cmp(ecx, FieldOperand(ebx, ExternalArray::kLengthOffset)); |
| // Unsigned comparison catches both negative and too-large values. |
| - __ j(above_equal, &slow); |
| + __ j(above_equal, &miss_force_generic); |
| __ mov(ebx, FieldOperand(ebx, ExternalArray::kExternalPointerOffset)); |
| // ebx: base pointer of external storage |
| switch (array_type) { |
| @@ -3440,47 +3486,45 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedLoadStub( |
| // Slow case: Jump to runtime. |
| __ bind(&slow); |
| - Counters* counters = isolate()->counters(); |
| + Counters* counters = masm->isolate()->counters(); |
| __ IncrementCounter(counters->keyed_load_external_array_slow(), 1); |
| + |
| // ----------- S t a t e ------------- |
| // -- eax : key |
| // -- edx : receiver |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - __ pop(ebx); |
| - __ push(edx); // receiver |
| - __ push(eax); // name |
| - __ push(ebx); // return address |
| + Handle<Code> ic = masm->isolate()->builtins()->KeyedLoadIC_Slow(); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| - // Perform tail call to the entry. |
| - __ TailCallRuntime(Runtime::kKeyedGetProperty, 2, 1); |
| + // ----------- S t a t e ------------- |
| + // -- eax : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| - // Return the generated code. |
| - return GetCode(flags); |
| + // Miss case: Jump to runtime. |
| + __ bind(&miss_force_generic); |
| + Handle<Code> miss_ic = |
| + masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| + __ jmp(miss_ic, RelocInfo::CODE_TARGET); |
| } |
| -MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| - JSObject* receiver, ExternalArrayType array_type, Code::Flags flags) { |
| +void KeyedStoreStubCompiler::GenerateStoreExternalArray( |
| + MacroAssembler* masm, |
| + ExternalArrayType array_type) { |
| // ----------- S t a t e ------------- |
| - // -- eax : value |
| - // -- ecx : key |
| + // -- eax : key |
| // -- edx : receiver |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - Label slow, check_heap_number; |
| - |
| - // Check that the object isn't a smi. |
| - __ test(edx, Immediate(kSmiTagMask)); |
| - __ j(zero, &slow); |
| - |
| - // Check that the map matches. |
| - __ CheckMap(edx, Handle<Map>(receiver->map()), &slow, false); |
| + Label miss_force_generic, slow, check_heap_number; |
| // Check that the key is a smi. |
| __ test(ecx, Immediate(kSmiTagMask)); |
| - __ j(not_zero, &slow); |
| + __ j(not_zero, &miss_force_generic); |
| // Check that the index is in range. |
| __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
| @@ -3511,9 +3555,9 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| switch (array_type) { |
| case kExternalPixelArray: |
| { // Clamp the value to [0..255]. |
| - Label done; |
| + NearLabel done; |
| __ test(ecx, Immediate(0xFFFFFF00)); |
| - __ j(zero, &done, Label::kNear); |
| + __ j(zero, &done); |
| __ setcc(negative, ecx); // 1 if negative, 0 if positive. |
| __ dec_b(ecx); // 0 if negative, 255 if positive. |
| __ bind(&done); |
| @@ -3559,7 +3603,7 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| // edi: elements array |
| // ebx: untagged index |
| __ cmp(FieldOperand(eax, HeapObject::kMapOffset), |
| - Immediate(factory()->heap_number_map())); |
| + Immediate(masm->isolate()->factory()->heap_number_map())); |
| __ j(not_equal, &slow); |
| // The WebGL specification leaves the behavior of storing NaN and |
| @@ -3594,9 +3638,9 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| switch (array_type) { |
| case kExternalPixelArray: |
| { // Clamp the value to [0..255]. |
| - Label done; |
| + NearLabel done; |
|
Mads Ager (chromium)
2011/05/10 13:38:06
Accidental edit? There are more than this one I th
danno
2011/05/11 14:20:19
Done.
|
| __ test(ecx, Immediate(0xFFFFFF00)); |
| - __ j(zero, &done, Label::kNear); |
| + __ j(zero, &done); |
| __ setcc(negative, ecx); // 1 if negative, 0 if positive. |
| __ dec_b(ecx); // 0 if negative, 255 if positive. |
| __ bind(&done); |
| @@ -3654,6 +3698,9 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| // Slow case: call runtime. |
| __ bind(&slow); |
| + Counters* counters = masm->isolate()->counters(); |
| + __ IncrementCounter(counters->keyed_store_external_array_slow(), 1); |
| + |
| // ----------- S t a t e ------------- |
| // -- eax : value |
| // -- ecx : key |
| @@ -3661,19 +3708,104 @@ MaybeObject* ExternalArrayStubCompiler::CompileKeyedStoreStub( |
| // -- esp[0] : return address |
| // ----------------------------------- |
| - __ pop(ebx); |
| - __ push(edx); |
| - __ push(ecx); |
| - __ push(eax); |
| - __ push(Immediate(Smi::FromInt(NONE))); // PropertyAttributes |
| - __ push(Immediate(Smi::FromInt( |
| - Code::ExtractExtraICStateFromFlags(flags) & kStrictMode))); |
| - __ push(ebx); // return address |
| + Handle<Code> ic = masm->isolate()->builtins()->KeyedStoreIC_Slow(); |
| + __ jmp(ic, RelocInfo::CODE_TARGET); |
| + |
| + // ----------- S t a t e ------------- |
| + // -- eax : value |
| + // -- ecx : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + |
| + __ bind(&miss_force_generic); |
| + Handle<Code> miss_ic = |
| + masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); |
| + __ jmp(miss_ic, RelocInfo::CODE_TARGET); |
| +} |
| + |
| + |
| + |
| - // Do tail-call to runtime routine. |
| - __ TailCallRuntime(Runtime::kSetProperty, 5, 1); |
| +void KeyedLoadStubCompiler::GenerateLoadFastElement(MacroAssembler* masm) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + Label miss_force_generic; |
| + |
| + // Check that the key is a smi. |
| + __ test(eax, Immediate(kSmiTagMask)); |
| + __ j(not_zero, &miss_force_generic, not_taken); |
| + |
| + // Get the elements array. |
| + __ mov(ecx, FieldOperand(edx, JSObject::kElementsOffset)); |
| + __ AssertFastElements(ecx); |
| + |
| + // Check that the key is within bounds. |
| + __ cmp(eax, FieldOperand(ecx, FixedArray::kLengthOffset)); |
| + __ j(above_equal, &miss_force_generic, not_taken); |
| + |
| + // Load the result and make sure it's not the hole. |
| + __ mov(ebx, Operand(ecx, eax, times_2, |
| + FixedArray::kHeaderSize - kHeapObjectTag)); |
| + __ cmp(ebx, masm->isolate()->factory()->the_hole_value()); |
| + __ j(equal, &miss_force_generic, not_taken); |
| + __ mov(eax, ebx); |
| + __ ret(0); |
| + |
| + __ bind(&miss_force_generic); |
| + Handle<Code> miss_ic = |
| + masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); |
| + __ jmp(miss_ic, RelocInfo::CODE_TARGET); |
| +} |
| + |
| + |
| +void KeyedStoreStubCompiler::GenerateStoreFastElement(MacroAssembler* masm, |
| + bool is_js_array) { |
| + // ----------- S t a t e ------------- |
| + // -- eax : key |
| + // -- edx : receiver |
| + // -- esp[0] : return address |
| + // ----------------------------------- |
| + Label miss_force_generic; |
| + |
| + // Check that the key is a smi. |
| + __ test(ecx, Immediate(kSmiTagMask)); |
| + __ j(not_zero, &miss_force_generic, not_taken); |
| + |
| + // Get the elements array and make sure it is a fast element array, not 'cow'. |
| + __ mov(edi, FieldOperand(edx, JSObject::kElementsOffset)); |
| + __ cmp(FieldOperand(edi, HeapObject::kMapOffset), |
| + Immediate(masm->isolate()->factory()->fixed_array_map())); |
| + __ j(not_equal, &miss_force_generic, not_taken); |
| + |
| + if (is_js_array) { |
| + // Check that the key is within bounds. |
| + __ cmp(ecx, FieldOperand(edx, JSArray::kLengthOffset)); // smis. |
| + __ j(above_equal, &miss_force_generic, not_taken); |
| + |
| + } else { |
| + // Check that the key is within bounds. |
| + __ cmp(ecx, FieldOperand(edi, FixedArray::kLengthOffset)); // smis. |
| + __ j(above_equal, &miss_force_generic, not_taken); |
| + } |
| + |
| + // Do the store and update the write barrier. Make sure to preserve |
| + // the value in register eax. |
| + __ mov(edx, Operand(eax)); |
| + __ mov(FieldOperand(edi, ecx, times_2, FixedArray::kHeaderSize), eax); |
| + __ RecordWrite(edi, 0, edx, ecx); |
| + |
| + // Done. |
| + __ ret(0); |
| - return GetCode(flags); |
| + // Handle store cache miss, replacing the ic with the generic stub. |
| + __ bind(&miss_force_generic); |
| + Handle<Code> ic_force_generic = |
| + masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); |
| + __ jmp(ic_force_generic, RelocInfo::CODE_TARGET); |
| } |