Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(170)

Side by Side Diff: src/arm/stub-cache-arm.cc

Issue 9310117: Implement KeyedStoreICs to grow arrays on out-of-bound stores. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Add missing WB stub Created 8 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/arm/codegen-arm.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2012 the V8 project authors. All rights reserved. 1 // Copyright 2012 the V8 project authors. All rights reserved.
2 // Redistribution and use in source and binary forms, with or without 2 // Redistribution and use in source and binary forms, with or without
3 // modification, are permitted provided that the following conditions are 3 // modification, are permitted provided that the following conditions are
4 // met: 4 // met:
5 // 5 //
6 // * Redistributions of source code must retain the above copyright 6 // * Redistributions of source code must retain the above copyright
7 // notice, this list of conditions and the following disclaimer. 7 // notice, this list of conditions and the following disclaimer.
8 // * Redistributions in binary form must reproduce the above 8 // * Redistributions in binary form must reproduce the above
9 // copyright notice, this list of conditions and the following 9 // copyright notice, this list of conditions and the following
10 // disclaimer in the documentation and/or other materials provided 10 // disclaimer in the documentation and/or other materials provided
(...skipping 3058 matching lines...) Expand 10 before | Expand all | Expand 10 after
3069 // ----------- S t a t e ------------- 3069 // ----------- S t a t e -------------
3070 // -- r0 : value 3070 // -- r0 : value
3071 // -- r1 : key 3071 // -- r1 : key
3072 // -- r2 : receiver 3072 // -- r2 : receiver
3073 // -- lr : return address 3073 // -- lr : return address
3074 // -- r3 : scratch 3074 // -- r3 : scratch
3075 // ----------------------------------- 3075 // -----------------------------------
3076 ElementsKind elements_kind = receiver_map->elements_kind(); 3076 ElementsKind elements_kind = receiver_map->elements_kind();
3077 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE; 3077 bool is_js_array = receiver_map->instance_type() == JS_ARRAY_TYPE;
3078 Handle<Code> stub = 3078 Handle<Code> stub =
3079 KeyedStoreElementStub(is_js_array, elements_kind).GetCode(); 3079 KeyedStoreElementStub(is_js_array, elements_kind, grow_mode_).GetCode();
3080 3080
3081 __ DispatchMap(r2, r3, receiver_map, stub, DO_SMI_CHECK); 3081 __ DispatchMap(r2, r3, receiver_map, stub, DO_SMI_CHECK);
3082 3082
3083 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss(); 3083 Handle<Code> ic = isolate()->builtins()->KeyedStoreIC_Miss();
3084 __ Jump(ic, RelocInfo::CODE_TARGET); 3084 __ Jump(ic, RelocInfo::CODE_TARGET);
3085 3085
3086 // Return the generated code. 3086 // Return the generated code.
3087 return GetCode(NORMAL, factory()->empty_string()); 3087 return GetCode(NORMAL, factory()->empty_string());
3088 } 3088 }
3089 3089
(...skipping 1024 matching lines...) Expand 10 before | Expand all | Expand 10 after
4114 __ bind(&miss_force_generic); 4114 __ bind(&miss_force_generic);
4115 Handle<Code> miss_ic = 4115 Handle<Code> miss_ic =
4116 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric(); 4116 masm->isolate()->builtins()->KeyedLoadIC_MissForceGeneric();
4117 __ Jump(miss_ic, RelocInfo::CODE_TARGET); 4117 __ Jump(miss_ic, RelocInfo::CODE_TARGET);
4118 } 4118 }
4119 4119
4120 4120
4121 void KeyedStoreStubCompiler::GenerateStoreFastElement( 4121 void KeyedStoreStubCompiler::GenerateStoreFastElement(
4122 MacroAssembler* masm, 4122 MacroAssembler* masm,
4123 bool is_js_array, 4123 bool is_js_array,
4124 ElementsKind elements_kind) { 4124 ElementsKind elements_kind,
4125 KeyedAccessGrowMode grow_mode) {
4125 // ----------- S t a t e ------------- 4126 // ----------- S t a t e -------------
4126 // -- r0 : value 4127 // -- r0 : value
4127 // -- r1 : key 4128 // -- r1 : key
4128 // -- r2 : receiver 4129 // -- r2 : receiver
4129 // -- lr : return address 4130 // -- lr : return address
4130 // -- r3 : scratch 4131 // -- r3 : scratch
4131 // -- r4 : scratch (elements) 4132 // -- r4 : scratch (elements)
4132 // ----------------------------------- 4133 // -----------------------------------
4133 Label miss_force_generic, transition_elements_kind; 4134 Label miss_force_generic, transition_elements_kind, grow, slow;
4135 Label finish_store, check_capacity;
4134 4136
4135 Register value_reg = r0; 4137 Register value_reg = r0;
4136 Register key_reg = r1; 4138 Register key_reg = r1;
4137 Register receiver_reg = r2; 4139 Register receiver_reg = r2;
4138 Register scratch = r3; 4140 Register scratch = r4;
4139 Register elements_reg = r4; 4141 Register elements_reg = r3;
4142 Register length_reg = r5;
4143 Register scratch2 = r6;
4140 4144
4141 // This stub is meant to be tail-jumped to, the receiver must already 4145 // This stub is meant to be tail-jumped to, the receiver must already
4142 // have been verified by the caller to not be a smi. 4146 // have been verified by the caller to not be a smi.
4143 4147
4144 // Check that the key is a smi. 4148 // Check that the key is a smi.
4145 __ JumpIfNotSmi(key_reg, &miss_force_generic); 4149 __ JumpIfNotSmi(key_reg, &miss_force_generic);
4146 4150
4147 // Get the elements array and make sure it is a fast element array, not 'cow'. 4151 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
4152 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
4153 }
4154
4155 // Check that the key is within bounds.
4148 __ ldr(elements_reg, 4156 __ ldr(elements_reg,
4149 FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); 4157 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4150 __ CheckMap(elements_reg,
4151 scratch,
4152 Heap::kFixedArrayMapRootIndex,
4153 &miss_force_generic,
4154 DONT_DO_SMI_CHECK);
4155
4156 // Check that the key is within bounds.
4157 if (is_js_array) { 4158 if (is_js_array) {
4158 __ ldr(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); 4159 __ ldr(scratch, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4159 } else { 4160 } else {
4160 __ ldr(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); 4161 __ ldr(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4161 } 4162 }
4162 // Compare smis. 4163 // Compare smis.
4163 __ cmp(key_reg, scratch); 4164 __ cmp(key_reg, scratch);
4164 __ b(hs, &miss_force_generic); 4165 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4166 __ b(hs, &grow);
4167 } else {
4168 __ b(hs, &miss_force_generic);
4169 }
4165 4170
4171 // Make sure elements is a fast element array, not 'cow'.
4172 __ CheckMap(elements_reg,
4173 scratch,
4174 Heap::kFixedArrayMapRootIndex,
4175 &miss_force_generic,
4176 DONT_DO_SMI_CHECK);
4177
4178 __ bind(&finish_store);
4166 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) { 4179 if (elements_kind == FAST_SMI_ONLY_ELEMENTS) {
4167 __ JumpIfNotSmi(value_reg, &transition_elements_kind);
4168 __ add(scratch, 4180 __ add(scratch,
4169 elements_reg, 4181 elements_reg,
4170 Operand(FixedArray::kHeaderSize - kHeapObjectTag)); 4182 Operand(FixedArray::kHeaderSize - kHeapObjectTag));
4171 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2); 4183 STATIC_ASSERT(kSmiTag == 0 && kSmiTagSize < kPointerSizeLog2);
4172 __ add(scratch, 4184 __ add(scratch,
4173 scratch, 4185 scratch,
4174 Operand(key_reg, LSL, kPointerSizeLog2 - kSmiTagSize)); 4186 Operand(key_reg, LSL, kPointerSizeLog2 - kSmiTagSize));
4175 __ str(value_reg, MemOperand(scratch)); 4187 __ str(value_reg, MemOperand(scratch));
4176 } else { 4188 } else {
4177 ASSERT(elements_kind == FAST_ELEMENTS); 4189 ASSERT(elements_kind == FAST_ELEMENTS);
(...skipping 17 matching lines...) Expand all
4195 __ Ret(); 4207 __ Ret();
4196 4208
4197 __ bind(&miss_force_generic); 4209 __ bind(&miss_force_generic);
4198 Handle<Code> ic = 4210 Handle<Code> ic =
4199 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); 4211 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4200 __ Jump(ic, RelocInfo::CODE_TARGET); 4212 __ Jump(ic, RelocInfo::CODE_TARGET);
4201 4213
4202 __ bind(&transition_elements_kind); 4214 __ bind(&transition_elements_kind);
4203 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss(); 4215 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4204 __ Jump(ic_miss, RelocInfo::CODE_TARGET); 4216 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
4217
4218 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4219 // Grow the array by a single element if possible.
4220 __ bind(&grow);
4221
4222 // Make sure the array is only growing by a single element, anything else
4223 // must be handled by the runtime. Flags already set by previous compare.
4224 __ b(ne, &miss_force_generic);
4225
4226 // Check for the empty array, and preallocate a small backing store if
4227 // possible.
4228 __ ldr(length_reg,
4229 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4230 __ ldr(elements_reg,
4231 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4232 __ CompareRoot(elements_reg, Heap::kEmptyFixedArrayRootIndex);
4233 __ b(ne, &check_capacity);
4234
4235 int size = FixedArray::SizeFor(JSArray::kPreallocatedArrayElements);
4236 __ AllocateInNewSpace(size, elements_reg, scratch, scratch2, &slow,
4237 TAG_OBJECT);
4238
4239 __ LoadRoot(scratch, Heap::kFixedArrayMapRootIndex);
4240 __ str(scratch, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4241 __ mov(scratch, Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4242 __ str(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4243 __ LoadRoot(scratch, Heap::kTheHoleValueRootIndex);
4244 for (int i = 1; i < JSArray::kPreallocatedArrayElements; ++i) {
4245 __ str(scratch, FieldMemOperand(elements_reg, FixedArray::SizeFor(i)));
4246 }
4247
4248 // Store the element at index zero.
4249 __ str(value_reg, FieldMemOperand(elements_reg, FixedArray::SizeFor(0)));
4250
4251 // Install the new backing store in the JSArray.
4252 __ str(elements_reg,
4253 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4254 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4255 scratch, kLRHasNotBeenSaved, kDontSaveFPRegs,
4256 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4257
4258 // Increment the length of the array.
4259 __ mov(length_reg, Operand(Smi::FromInt(1)));
4260 __ str(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4261 __ Ret();
4262
4263 __ bind(&check_capacity);
4264 // Check for cow elements, in general they are not handled by this stub
4265 __ CheckMap(elements_reg,
4266 scratch,
4267 Heap::kFixedCOWArrayMapRootIndex,
4268 &miss_force_generic,
4269 DONT_DO_SMI_CHECK);
4270
4271 __ ldr(scratch, FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4272 __ cmp(length_reg, scratch);
4273 __ b(hs, &slow);
4274
4275 // Grow the array and finish the store.
4276 __ add(length_reg, length_reg, Operand(Smi::FromInt(1)));
4277 __ str(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4278 __ jmp(&finish_store);
4279
4280 __ bind(&slow);
4281 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4282 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4283 }
4205 } 4284 }
4206 4285
4207 4286
4208 void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement( 4287 void KeyedStoreStubCompiler::GenerateStoreFastDoubleElement(
4209 MacroAssembler* masm, 4288 MacroAssembler* masm,
4210 bool is_js_array) { 4289 bool is_js_array,
4290 KeyedAccessGrowMode grow_mode) {
4211 // ----------- S t a t e ------------- 4291 // ----------- S t a t e -------------
4212 // -- r0 : value 4292 // -- r0 : value
4213 // -- r1 : key 4293 // -- r1 : key
4214 // -- r2 : receiver 4294 // -- r2 : receiver
4215 // -- lr : return address 4295 // -- lr : return address
4216 // -- r3 : scratch 4296 // -- r3 : scratch
4217 // -- r4 : scratch 4297 // -- r4 : scratch
4218 // -- r5 : scratch 4298 // -- r5 : scratch
4219 // ----------------------------------- 4299 // -----------------------------------
4220 Label miss_force_generic, transition_elements_kind; 4300 Label miss_force_generic, transition_elements_kind, grow, slow;
4301 Label finish_store, check_capacity;
4221 4302
4222 Register value_reg = r0; 4303 Register value_reg = r0;
4223 Register key_reg = r1; 4304 Register key_reg = r1;
4224 Register receiver_reg = r2; 4305 Register receiver_reg = r2;
4225 Register elements_reg = r3; 4306 Register elements_reg = r3;
4226 Register scratch1 = r4; 4307 Register scratch1 = r4;
4227 Register scratch2 = r5; 4308 Register scratch2 = r5;
4228 Register scratch3 = r6; 4309 Register scratch3 = r6;
4229 Register scratch4 = r7; 4310 Register scratch4 = r7;
4311 Register length_reg = r7;
4230 4312
4231 // This stub is meant to be tail-jumped to, the receiver must already 4313 // This stub is meant to be tail-jumped to, the receiver must already
4232 // have been verified by the caller to not be a smi. 4314 // have been verified by the caller to not be a smi.
4233 __ JumpIfNotSmi(key_reg, &miss_force_generic); 4315 __ JumpIfNotSmi(key_reg, &miss_force_generic);
4234 4316
4235 __ ldr(elements_reg, 4317 __ ldr(elements_reg,
4236 FieldMemOperand(receiver_reg, JSObject::kElementsOffset)); 4318 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4237 4319
4238 // Check that the key is within bounds. 4320 // Check that the key is within bounds.
4239 if (is_js_array) { 4321 if (is_js_array) {
4240 __ ldr(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset)); 4322 __ ldr(scratch1, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4241 } else { 4323 } else {
4242 __ ldr(scratch1, 4324 __ ldr(scratch1,
4243 FieldMemOperand(elements_reg, FixedArray::kLengthOffset)); 4325 FieldMemOperand(elements_reg, FixedArray::kLengthOffset));
4244 } 4326 }
4245 // Compare smis, unsigned compare catches both negative and out-of-bound 4327 // Compare smis, unsigned compare catches both negative and out-of-bound
4246 // indexes. 4328 // indexes.
4247 __ cmp(key_reg, scratch1); 4329 __ cmp(key_reg, scratch1);
4248 __ b(hs, &miss_force_generic); 4330 if (grow_mode == ALLOW_JSARRAY_GROWTH) {
4331 __ b(hs, &grow);
4332 } else {
4333 __ b(hs, &miss_force_generic);
4334 }
4249 4335
4336 __ bind(&finish_store);
4250 __ StoreNumberToDoubleElements(value_reg, 4337 __ StoreNumberToDoubleElements(value_reg,
4251 key_reg, 4338 key_reg,
4252 receiver_reg, 4339 receiver_reg,
4253 elements_reg, 4340 elements_reg,
4254 scratch1, 4341 scratch1,
4255 scratch2, 4342 scratch2,
4256 scratch3, 4343 scratch3,
4257 scratch4, 4344 scratch4,
4258 &transition_elements_kind); 4345 &transition_elements_kind);
4259 __ Ret(); 4346 __ Ret();
4260 4347
4261 // Handle store cache miss, replacing the ic with the generic stub. 4348 // Handle store cache miss, replacing the ic with the generic stub.
4262 __ bind(&miss_force_generic); 4349 __ bind(&miss_force_generic);
4263 Handle<Code> ic = 4350 Handle<Code> ic =
4264 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric(); 4351 masm->isolate()->builtins()->KeyedStoreIC_MissForceGeneric();
4265 __ Jump(ic, RelocInfo::CODE_TARGET); 4352 __ Jump(ic, RelocInfo::CODE_TARGET);
4266 4353
4267 __ bind(&transition_elements_kind); 4354 __ bind(&transition_elements_kind);
4268 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss(); 4355 Handle<Code> ic_miss = masm->isolate()->builtins()->KeyedStoreIC_Miss();
4269 __ Jump(ic_miss, RelocInfo::CODE_TARGET); 4356 __ Jump(ic_miss, RelocInfo::CODE_TARGET);
4357
4358 if (is_js_array && grow_mode == ALLOW_JSARRAY_GROWTH) {
4359 // Grow the array by a single element if possible.
4360 __ bind(&grow);
4361
4362 // Make sure the array is only growing by a single element, anything else
4363 // must be handled by the runtime. Flags already set by previous compare.
4364 __ b(ne, &miss_force_generic);
4365
4366 // Transition on values that can't be stored in a FixedDoubleArray.
4367 Label value_is_smi;
4368 __ JumpIfSmi(value_reg, &value_is_smi);
4369 __ ldr(scratch1, FieldMemOperand(value_reg, HeapObject::kMapOffset));
4370 __ CompareRoot(scratch1, Heap::kHeapNumberMapRootIndex);
4371 __ b(ne, &transition_elements_kind);
4372 __ bind(&value_is_smi);
4373
4374 // Check for the empty array, and preallocate a small backing store if
4375 // possible.
4376 __ ldr(length_reg,
4377 FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4378 __ ldr(elements_reg,
4379 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4380 __ CompareRoot(elements_reg, Heap::kEmptyFixedArrayRootIndex);
4381 __ b(ne, &check_capacity);
4382
4383 int size = FixedDoubleArray::SizeFor(JSArray::kPreallocatedArrayElements);
4384 __ AllocateInNewSpace(size, elements_reg, scratch1, scratch2, &slow,
4385 TAG_OBJECT);
4386
4387 // Initialize the new FixedDoubleArray. Leave elements unitialized for
4388 // efficiency, they are guaranteed to be initialized before use.
4389 __ LoadRoot(scratch1, Heap::kFixedDoubleArrayMapRootIndex);
4390 __ str(scratch1, FieldMemOperand(elements_reg, JSObject::kMapOffset));
4391 __ mov(scratch1,
4392 Operand(Smi::FromInt(JSArray::kPreallocatedArrayElements)));
4393 __ str(scratch1,
4394 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4395
4396 // Install the new backing store in the JSArray.
4397 __ str(elements_reg,
4398 FieldMemOperand(receiver_reg, JSObject::kElementsOffset));
4399 __ RecordWriteField(receiver_reg, JSObject::kElementsOffset, elements_reg,
4400 scratch1, kLRHasNotBeenSaved, kDontSaveFPRegs,
4401 EMIT_REMEMBERED_SET, OMIT_SMI_CHECK);
4402
4403 // Increment the length of the array.
4404 __ mov(length_reg, Operand(Smi::FromInt(1)));
4405 __ str(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4406 __ jmp(&finish_store);
4407
4408 __ bind(&check_capacity);
4409 // Make sure that the backing store can hold additional elements.
4410 __ ldr(scratch1,
4411 FieldMemOperand(elements_reg, FixedDoubleArray::kLengthOffset));
4412 __ cmp(length_reg, scratch1);
4413 __ b(hs, &slow);
4414
4415 // Grow the array and finish the store.
4416 __ add(length_reg, length_reg, Operand(Smi::FromInt(1)));
4417 __ str(length_reg, FieldMemOperand(receiver_reg, JSArray::kLengthOffset));
4418 __ jmp(&finish_store);
4419
4420 __ bind(&slow);
4421 Handle<Code> ic_slow = masm->isolate()->builtins()->KeyedStoreIC_Slow();
4422 __ Jump(ic_slow, RelocInfo::CODE_TARGET);
4423 }
4270 } 4424 }
4271 4425
4272 4426
4273 #undef __ 4427 #undef __
4274 4428
4275 } } // namespace v8::internal 4429 } } // namespace v8::internal
4276 4430
4277 #endif // V8_TARGET_ARCH_ARM 4431 #endif // V8_TARGET_ARCH_ARM
OLDNEW
« no previous file with comments | « src/arm/codegen-arm.cc ('k') | src/code-stubs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698