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

Side by Side Diff: src/ia32/builtins-ia32.cc

Issue 209048: Handle array construction in native code (x64 version) (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 11 years, 3 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 | « no previous file | src/x64/assembler-x64.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 2006-2009 the V8 project authors. All rights reserved. 1 // Copyright 2006-2009 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 656 matching lines...) Expand 10 before | Expand all | Expand 10 after
667 __ mov(result, 667 __ mov(result,
668 Operand(result, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX))); 668 Operand(result, Context::SlotOffset(Context::ARRAY_FUNCTION_INDEX)));
669 } 669 }
670 670
671 671
672 // Number of empty elements to allocate for an empty array. 672 // Number of empty elements to allocate for an empty array.
673 static const int kPreallocatedArrayElements = 4; 673 static const int kPreallocatedArrayElements = 4;
674 674
675 675
676 // Allocate an empty JSArray. The allocated array is put into the result 676 // Allocate an empty JSArray. The allocated array is put into the result
677 // register. If the parameter holes is larger than zero an elements backing 677 // register. If the parameter initial_capacity is larger than zero an elements
678 // store is allocated with this size and filled with the hole values. Otherwise 678 // backing store is allocated with this size and filled with the hole values.
679 // the elements backing store is set to the empty FixedArray. 679 // Otherwise the elements backing store is set to the empty FixedArray.
680 static void AllocateEmptyJSArray(MacroAssembler* masm, 680 static void AllocateEmptyJSArray(MacroAssembler* masm,
681 Register array_function, 681 Register array_function,
682 Register result, 682 Register result,
683 Register scratch1, 683 Register scratch1,
684 Register scratch2, 684 Register scratch2,
685 Register scratch3, 685 Register scratch3,
686 int holes, 686 int initial_capacity,
687 Label* gc_required) { 687 Label* gc_required) {
688 ASSERT(holes >= 0); 688 ASSERT(initial_capacity >= 0);
689 689
690 // Load the initial map from the array function. 690 // Load the initial map from the array function.
691 __ mov(scratch1, FieldOperand(array_function, 691 __ mov(scratch1, FieldOperand(array_function,
692 JSFunction::kPrototypeOrInitialMapOffset)); 692 JSFunction::kPrototypeOrInitialMapOffset));
693 693
694 // Allocate the JSArray object together with space for a fixed array with the 694 // Allocate the JSArray object together with space for a fixed array with the
695 // requested elements. 695 // requested elements.
696 int size = JSArray::kSize; 696 int size = JSArray::kSize;
697 if (holes > 0) { 697 if (initial_capacity > 0) {
698 size += FixedArray::SizeFor(holes); 698 size += FixedArray::SizeFor(initial_capacity);
699 } 699 }
700 __ AllocateObjectInNewSpace(size, 700 __ AllocateObjectInNewSpace(size,
701 result, 701 result,
702 scratch2, 702 scratch2,
703 scratch3, 703 scratch3,
704 gc_required, 704 gc_required,
705 TAG_OBJECT); 705 TAG_OBJECT);
706 706
707 // Allocated the JSArray. Now initialize the fields except for the elements 707 // Allocated the JSArray. Now initialize the fields except for the elements
708 // array. 708 // array.
709 // result: JSObject 709 // result: JSObject
710 // scratch1: initial map 710 // scratch1: initial map
711 // scratch2: start of next object 711 // scratch2: start of next object
712 __ mov(FieldOperand(result, JSObject::kMapOffset), scratch1); 712 __ mov(FieldOperand(result, JSObject::kMapOffset), scratch1);
713 __ mov(FieldOperand(result, JSArray::kPropertiesOffset), 713 __ mov(FieldOperand(result, JSArray::kPropertiesOffset),
714 Factory::empty_fixed_array()); 714 Factory::empty_fixed_array());
715 // Field JSArray::kElementsOffset is initialized later. 715 // Field JSArray::kElementsOffset is initialized later.
716 __ mov(FieldOperand(result, JSArray::kLengthOffset), Immediate(0)); 716 __ mov(FieldOperand(result, JSArray::kLengthOffset), Immediate(0));
717 717
718 // If no storage is requested for the elements array just set the empty 718 // If no storage is requested for the elements array just set the empty
719 // fixed array. 719 // fixed array.
720 if (holes == 0) { 720 if (initial_capacity == 0) {
721 __ mov(FieldOperand(result, JSArray::kElementsOffset), 721 __ mov(FieldOperand(result, JSArray::kElementsOffset),
722 Factory::empty_fixed_array()); 722 Factory::empty_fixed_array());
723 return; 723 return;
724 } 724 }
725 725
726 // Calculate the location of the elements array and set elements array member 726 // Calculate the location of the elements array and set elements array member
727 // of the JSArray. 727 // of the JSArray.
728 // result: JSObject 728 // result: JSObject
729 // scratch2: start of next object 729 // scratch2: start of next object
730 __ lea(scratch1, Operand(result, JSArray::kSize)); 730 __ lea(scratch1, Operand(result, JSArray::kSize));
731 __ mov(FieldOperand(result, JSArray::kElementsOffset), scratch1); 731 __ mov(FieldOperand(result, JSArray::kElementsOffset), scratch1);
732 732
733 // Initialize the FixedArray and fill it with holes. FixedArray length is not 733 // Initialize the FixedArray and fill it with holes. FixedArray length is not
734 // stored as a smi. 734 // stored as a smi.
735 // result: JSObject 735 // result: JSObject
736 // scratch1: elements array 736 // scratch1: elements array
737 // scratch2: start of next object 737 // scratch2: start of next object
738 __ mov(FieldOperand(scratch1, JSObject::kMapOffset), 738 __ mov(FieldOperand(scratch1, JSObject::kMapOffset),
739 Factory::fixed_array_map()); 739 Factory::fixed_array_map());
740 __ mov(FieldOperand(scratch1, Array::kLengthOffset), Immediate(holes)); 740 __ mov(FieldOperand(scratch1, Array::kLengthOffset),
741 Immediate(initial_capacity));
741 742
742 // Fill the FixedArray with the hole value. Inline the code if short. 743 // Fill the FixedArray with the hole value. Inline the code if short.
743 // Reconsider loop unfolding if kPreallocatedArrayElements gets changed. 744 // Reconsider loop unfolding if kPreallocatedArrayElements gets changed.
744 static const int kLoopUnfoldLimit = 4; 745 static const int kLoopUnfoldLimit = 4;
745 ASSERT(kPreallocatedArrayElements <= kLoopUnfoldLimit); 746 ASSERT(kPreallocatedArrayElements <= kLoopUnfoldLimit);
746 if (holes <= kLoopUnfoldLimit) { 747 if (initial_capacity <= kLoopUnfoldLimit) {
747 // Use a scratch register here to have only one reloc info when unfolding 748 // Use a scratch register here to have only one reloc info when unfolding
748 // the loop. 749 // the loop.
749 __ mov(scratch3, Factory::the_hole_value()); 750 __ mov(scratch3, Factory::the_hole_value());
750 for (int i = 0; i < holes; i++) { 751 for (int i = 0; i < initial_capacity; i++) {
751 __ mov(FieldOperand(scratch1, 752 __ mov(FieldOperand(scratch1,
752 FixedArray::kHeaderSize + i * kPointerSize), 753 FixedArray::kHeaderSize + i * kPointerSize),
753 scratch3); 754 scratch3);
754 } 755 }
755 } else { 756 } else {
756 Label loop, entry; 757 Label loop, entry;
757 __ jmp(&entry); 758 __ jmp(&entry);
758 __ bind(&loop); 759 __ bind(&loop);
759 __ mov(Operand(scratch1, 0), Factory::the_hole_value()); 760 __ mov(Operand(scratch1, 0), Factory::the_hole_value());
760 __ add(Operand(scratch1), Immediate(kPointerSize)); 761 __ add(Operand(scratch1), Immediate(kPointerSize));
(...skipping 467 matching lines...) Expand 10 before | Expand all | Expand 10 after
1228 // Dont adapt arguments. 1229 // Dont adapt arguments.
1229 // ------------------------------------------- 1230 // -------------------------------------------
1230 __ bind(&dont_adapt_arguments); 1231 __ bind(&dont_adapt_arguments);
1231 __ jmp(Operand(edx)); 1232 __ jmp(Operand(edx));
1232 } 1233 }
1233 1234
1234 1235
1235 #undef __ 1236 #undef __
1236 1237
1237 } } // namespace v8::internal 1238 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « no previous file | src/x64/assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698