OLD | NEW |
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 298 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 // Need to collect. Call into runtime system. | 309 // Need to collect. Call into runtime system. |
310 __ bind(&gc); | 310 __ bind(&gc); |
311 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); | 311 __ TailCallRuntime(Runtime::kPushBlockContext, 2, 1); |
312 } | 312 } |
313 | 313 |
314 | 314 |
315 static void GenerateFastCloneShallowArrayCommon( | 315 static void GenerateFastCloneShallowArrayCommon( |
316 MacroAssembler* masm, | 316 MacroAssembler* masm, |
317 int length, | 317 int length, |
318 FastCloneShallowArrayStub::Mode mode, | 318 FastCloneShallowArrayStub::Mode mode, |
| 319 AllocationSiteInfoMode allocation_site_info_mode, |
319 Label* fail) { | 320 Label* fail) { |
320 // Registers on entry: | 321 // Registers on entry: |
321 // | 322 // |
322 // rcx: boilerplate literal array. | 323 // rcx: boilerplate literal array. |
323 ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); | 324 ASSERT(mode != FastCloneShallowArrayStub::CLONE_ANY_ELEMENTS); |
324 | 325 |
325 // All sizes here are multiples of kPointerSize. | 326 // All sizes here are multiples of kPointerSize. |
326 int elements_size = 0; | 327 int elements_size = 0; |
327 if (length > 0) { | 328 if (length > 0) { |
328 elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS | 329 elements_size = mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS |
329 ? FixedDoubleArray::SizeFor(length) | 330 ? FixedDoubleArray::SizeFor(length) |
330 : FixedArray::SizeFor(length); | 331 : FixedArray::SizeFor(length); |
331 } | 332 } |
332 int size = JSArray::kSize + elements_size; | 333 int size = JSArray::kSize; |
| 334 int allocation_info_start = size; |
| 335 if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { |
| 336 size += AllocationSiteInfo::kSize; |
| 337 } |
| 338 size += elements_size; |
333 | 339 |
334 // Allocate both the JS array and the elements array in one big | 340 // Allocate both the JS array and the elements array in one big |
335 // allocation. This avoids multiple limit checks. | 341 // allocation. This avoids multiple limit checks. |
336 AllocationFlags flags = TAG_OBJECT; | 342 AllocationFlags flags = TAG_OBJECT; |
337 if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { | 343 if (mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS) { |
338 flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); | 344 flags = static_cast<AllocationFlags>(DOUBLE_ALIGNMENT | flags); |
339 } | 345 } |
340 __ AllocateInNewSpace(size, rax, rbx, rdx, fail, flags); | 346 __ AllocateInNewSpace(size, rax, rbx, rdx, fail, flags); |
341 | 347 |
| 348 if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { |
| 349 __ LoadRoot(kScratchRegister, Heap::kAllocationSiteInfoMapRootIndex); |
| 350 __ movq(FieldOperand(rax, allocation_info_start), kScratchRegister); |
| 351 __ movq(FieldOperand(rax, allocation_info_start + kPointerSize), rcx); |
| 352 } |
| 353 |
342 // Copy the JS array part. | 354 // Copy the JS array part. |
343 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { | 355 for (int i = 0; i < JSArray::kSize; i += kPointerSize) { |
344 if ((i != JSArray::kElementsOffset) || (length == 0)) { | 356 if ((i != JSArray::kElementsOffset) || (length == 0)) { |
345 __ movq(rbx, FieldOperand(rcx, i)); | 357 __ movq(rbx, FieldOperand(rcx, i)); |
346 __ movq(FieldOperand(rax, i), rbx); | 358 __ movq(FieldOperand(rax, i), rbx); |
347 } | 359 } |
348 } | 360 } |
349 | 361 |
350 if (length > 0) { | 362 if (length > 0) { |
351 // Get hold of the elements array of the boilerplate and setup the | 363 // Get hold of the elements array of the boilerplate and setup the |
352 // elements pointer in the resulting object. | 364 // elements pointer in the resulting object. |
353 __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); | 365 __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); |
354 __ lea(rdx, Operand(rax, JSArray::kSize)); | 366 if (allocation_site_info_mode == TRACK_ALLOCATION_SITE_INFO) { |
| 367 __ lea(rdx, Operand(rax, JSArray::kSize + AllocationSiteInfo::kSize)); |
| 368 } else { |
| 369 __ lea(rdx, Operand(rax, JSArray::kSize)); |
| 370 } |
355 __ movq(FieldOperand(rax, JSArray::kElementsOffset), rdx); | 371 __ movq(FieldOperand(rax, JSArray::kElementsOffset), rdx); |
356 | 372 |
357 // Copy the elements array. | 373 // Copy the elements array. |
358 if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { | 374 if (mode == FastCloneShallowArrayStub::CLONE_ELEMENTS) { |
359 for (int i = 0; i < elements_size; i += kPointerSize) { | 375 for (int i = 0; i < elements_size; i += kPointerSize) { |
360 __ movq(rbx, FieldOperand(rcx, i)); | 376 __ movq(rbx, FieldOperand(rcx, i)); |
361 __ movq(FieldOperand(rdx, i), rbx); | 377 __ movq(FieldOperand(rdx, i), rbx); |
362 } | 378 } |
363 } else { | 379 } else { |
364 ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); | 380 ASSERT(mode == FastCloneShallowArrayStub::CLONE_DOUBLE_ELEMENTS); |
(...skipping 26 matching lines...) Expand all Loading... |
391 SmiIndex index = masm->SmiToIndex(rax, rax, kPointerSizeLog2); | 407 SmiIndex index = masm->SmiToIndex(rax, rax, kPointerSizeLog2); |
392 __ movq(rcx, | 408 __ movq(rcx, |
393 FieldOperand(rcx, index.reg, index.scale, FixedArray::kHeaderSize)); | 409 FieldOperand(rcx, index.reg, index.scale, FixedArray::kHeaderSize)); |
394 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); | 410 __ CompareRoot(rcx, Heap::kUndefinedValueRootIndex); |
395 Label slow_case; | 411 Label slow_case; |
396 __ j(equal, &slow_case); | 412 __ j(equal, &slow_case); |
397 | 413 |
398 FastCloneShallowArrayStub::Mode mode = mode_; | 414 FastCloneShallowArrayStub::Mode mode = mode_; |
399 // rcx is boilerplate object. | 415 // rcx is boilerplate object. |
400 Factory* factory = masm->isolate()->factory(); | 416 Factory* factory = masm->isolate()->factory(); |
| 417 AllocationSiteInfoMode allocation_site_info_mode = |
| 418 DONT_TRACK_ALLOCATION_SITE_INFO; |
| 419 if (mode == CLONE_ANY_ELEMENTS_WITH_ALLOCATION_SITE_INFO) { |
| 420 mode = CLONE_ANY_ELEMENTS; |
| 421 allocation_site_info_mode = TRACK_ALLOCATION_SITE_INFO; |
| 422 } |
| 423 |
401 if (mode == CLONE_ANY_ELEMENTS) { | 424 if (mode == CLONE_ANY_ELEMENTS) { |
402 Label double_elements, check_fast_elements; | 425 Label double_elements, check_fast_elements; |
403 __ movq(rbx, FieldOperand(rcx, JSArray::kElementsOffset)); | 426 __ movq(rbx, FieldOperand(rcx, JSArray::kElementsOffset)); |
404 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), | 427 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
405 factory->fixed_cow_array_map()); | 428 factory->fixed_cow_array_map()); |
406 __ j(not_equal, &check_fast_elements); | 429 __ j(not_equal, &check_fast_elements); |
407 GenerateFastCloneShallowArrayCommon(masm, 0, | 430 GenerateFastCloneShallowArrayCommon(masm, 0, |
408 COPY_ON_WRITE_ELEMENTS, &slow_case); | 431 COPY_ON_WRITE_ELEMENTS, |
| 432 allocation_site_info_mode, |
| 433 &slow_case); |
409 __ ret(3 * kPointerSize); | 434 __ ret(3 * kPointerSize); |
410 | 435 |
411 __ bind(&check_fast_elements); | 436 __ bind(&check_fast_elements); |
412 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), | 437 __ Cmp(FieldOperand(rbx, HeapObject::kMapOffset), |
413 factory->fixed_array_map()); | 438 factory->fixed_array_map()); |
414 __ j(not_equal, &double_elements); | 439 __ j(not_equal, &double_elements); |
415 GenerateFastCloneShallowArrayCommon(masm, length_, | 440 GenerateFastCloneShallowArrayCommon(masm, length_, |
416 CLONE_ELEMENTS, &slow_case); | 441 CLONE_ELEMENTS, |
| 442 allocation_site_info_mode, |
| 443 &slow_case); |
417 __ ret(3 * kPointerSize); | 444 __ ret(3 * kPointerSize); |
418 | 445 |
419 __ bind(&double_elements); | 446 __ bind(&double_elements); |
420 mode = CLONE_DOUBLE_ELEMENTS; | 447 mode = CLONE_DOUBLE_ELEMENTS; |
421 // Fall through to generate the code to handle double elements. | 448 // Fall through to generate the code to handle double elements. |
422 } | 449 } |
423 | 450 |
424 if (FLAG_debug_code) { | 451 if (FLAG_debug_code) { |
425 const char* message; | 452 const char* message; |
426 Heap::RootListIndex expected_map_index; | 453 Heap::RootListIndex expected_map_index; |
427 if (mode == CLONE_ELEMENTS) { | 454 if (mode == CLONE_ELEMENTS) { |
428 message = "Expected (writable) fixed array"; | 455 message = "Expected (writable) fixed array"; |
429 expected_map_index = Heap::kFixedArrayMapRootIndex; | 456 expected_map_index = Heap::kFixedArrayMapRootIndex; |
430 } else if (mode == CLONE_DOUBLE_ELEMENTS) { | 457 } else if (mode == CLONE_DOUBLE_ELEMENTS) { |
431 message = "Expected (writable) fixed double array"; | 458 message = "Expected (writable) fixed double array"; |
432 expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; | 459 expected_map_index = Heap::kFixedDoubleArrayMapRootIndex; |
433 } else { | 460 } else { |
434 ASSERT(mode == COPY_ON_WRITE_ELEMENTS); | 461 ASSERT(mode == COPY_ON_WRITE_ELEMENTS); |
435 message = "Expected copy-on-write fixed array"; | 462 message = "Expected copy-on-write fixed array"; |
436 expected_map_index = Heap::kFixedCOWArrayMapRootIndex; | 463 expected_map_index = Heap::kFixedCOWArrayMapRootIndex; |
437 } | 464 } |
438 __ push(rcx); | 465 __ push(rcx); |
439 __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); | 466 __ movq(rcx, FieldOperand(rcx, JSArray::kElementsOffset)); |
440 __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset), | 467 __ CompareRoot(FieldOperand(rcx, HeapObject::kMapOffset), |
441 expected_map_index); | 468 expected_map_index); |
442 __ Assert(equal, message); | 469 __ Assert(equal, message); |
443 __ pop(rcx); | 470 __ pop(rcx); |
444 } | 471 } |
445 | 472 |
446 GenerateFastCloneShallowArrayCommon(masm, length_, mode, &slow_case); | 473 GenerateFastCloneShallowArrayCommon(masm, length_, mode, |
| 474 allocation_site_info_mode, &slow_case); |
447 __ ret(3 * kPointerSize); | 475 __ ret(3 * kPointerSize); |
448 | 476 |
449 __ bind(&slow_case); | 477 __ bind(&slow_case); |
450 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); | 478 __ TailCallRuntime(Runtime::kCreateArrayLiteralShallow, 3, 1); |
451 } | 479 } |
452 | 480 |
453 | 481 |
454 void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { | 482 void FastCloneShallowObjectStub::Generate(MacroAssembler* masm) { |
455 // Stack layout on entry: | 483 // Stack layout on entry: |
456 // | 484 // |
(...skipping 6027 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6484 #endif | 6512 #endif |
6485 | 6513 |
6486 __ Ret(); | 6514 __ Ret(); |
6487 } | 6515 } |
6488 | 6516 |
6489 #undef __ | 6517 #undef __ |
6490 | 6518 |
6491 } } // namespace v8::internal | 6519 } } // namespace v8::internal |
6492 | 6520 |
6493 #endif // V8_TARGET_ARCH_X64 | 6521 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |