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

Side by Side Diff: src/runtime.cc

Issue 15172003: Preallocate transitioned maps for TypedArrays. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 7 years, 7 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
« src/heap.h ('K') | « src/objects-inl.h ('k') | no next file » | 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 777 matching lines...) Expand 10 before | Expand all | Expand 10 after
788 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { 788 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
789 HandleScope scope(isolate); 789 HandleScope scope(isolate);
790 ASSERT(args.length() == 5); 790 ASSERT(args.length() == 5);
791 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 791 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
792 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 792 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
793 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); 793 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2);
794 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); 794 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3);
795 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); 795 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);
796 796
797 ExternalArrayType arrayType; 797 ExternalArrayType arrayType;
798 ElementsKind elementsKind;
799 size_t elementSize; 798 size_t elementSize;
800 switch (arrayId) { 799 switch (arrayId) {
801 case ARRAY_ID_UINT8: 800 case ARRAY_ID_UINT8:
802 elementsKind = EXTERNAL_UNSIGNED_BYTE_ELEMENTS;
803 arrayType = kExternalUnsignedByteArray; 801 arrayType = kExternalUnsignedByteArray;
804 elementSize = 1; 802 elementSize = 1;
805 break; 803 break;
806 case ARRAY_ID_INT8: 804 case ARRAY_ID_INT8:
807 elementsKind = EXTERNAL_BYTE_ELEMENTS;
808 arrayType = kExternalByteArray; 805 arrayType = kExternalByteArray;
809 elementSize = 1; 806 elementSize = 1;
810 break; 807 break;
811 case ARRAY_ID_UINT16: 808 case ARRAY_ID_UINT16:
812 elementsKind = EXTERNAL_UNSIGNED_SHORT_ELEMENTS;
813 arrayType = kExternalUnsignedShortArray; 809 arrayType = kExternalUnsignedShortArray;
814 elementSize = 2; 810 elementSize = 2;
815 break; 811 break;
816 case ARRAY_ID_INT16: 812 case ARRAY_ID_INT16:
817 elementsKind = EXTERNAL_SHORT_ELEMENTS;
818 arrayType = kExternalShortArray; 813 arrayType = kExternalShortArray;
819 elementSize = 2; 814 elementSize = 2;
820 break; 815 break;
821 case ARRAY_ID_UINT32: 816 case ARRAY_ID_UINT32:
822 elementsKind = EXTERNAL_UNSIGNED_INT_ELEMENTS;
823 arrayType = kExternalUnsignedIntArray; 817 arrayType = kExternalUnsignedIntArray;
824 elementSize = 4; 818 elementSize = 4;
825 break; 819 break;
826 case ARRAY_ID_INT32: 820 case ARRAY_ID_INT32:
827 elementsKind = EXTERNAL_INT_ELEMENTS;
828 arrayType = kExternalIntArray; 821 arrayType = kExternalIntArray;
829 elementSize = 4; 822 elementSize = 4;
830 break; 823 break;
831 case ARRAY_ID_FLOAT32: 824 case ARRAY_ID_FLOAT32:
832 elementsKind = EXTERNAL_FLOAT_ELEMENTS;
833 arrayType = kExternalFloatArray; 825 arrayType = kExternalFloatArray;
834 elementSize = 4; 826 elementSize = 4;
835 break; 827 break;
836 case ARRAY_ID_FLOAT64: 828 case ARRAY_ID_FLOAT64:
837 elementsKind = EXTERNAL_DOUBLE_ELEMENTS;
838 arrayType = kExternalDoubleArray; 829 arrayType = kExternalDoubleArray;
839 elementSize = 8; 830 elementSize = 8;
840 break; 831 break;
841 case ARRAY_ID_UINT8C: 832 case ARRAY_ID_UINT8C:
842 elementsKind = EXTERNAL_PIXEL_ELEMENTS;
843 arrayType = kExternalPixelArray; 833 arrayType = kExternalPixelArray;
844 elementSize = 1; 834 elementSize = 1;
845 break; 835 break;
846 default: 836 default:
847 UNREACHABLE(); 837 UNREACHABLE();
848 return NULL; 838 return NULL;
849 } 839 }
850 840
851 holder->set_buffer(*buffer); 841 holder->set_buffer(*buffer);
852 holder->set_byte_offset(*byte_offset_object); 842 holder->set_byte_offset(*byte_offset_object);
853 holder->set_byte_length(*byte_length_object); 843 holder->set_byte_length(*byte_length_object);
854 844
855 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); 845 size_t byte_offset = NumberToSize(isolate, *byte_offset_object);
856 size_t byte_length = NumberToSize(isolate, *byte_length_object); 846 size_t byte_length = NumberToSize(isolate, *byte_length_object);
857 ASSERT(byte_length % elementSize == 0); 847 ASSERT(byte_length % elementSize == 0);
858 size_t length = byte_length / elementSize; 848 size_t length = byte_length / elementSize;
859 849
860 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 850 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
861 holder->set_length(*length_obj); 851 holder->set_length(*length_obj);
862 852
863 Handle<ExternalArray> elements = 853 Handle<ExternalArray> elements =
864 isolate->factory()->NewExternalArray( 854 isolate->factory()->NewExternalArray(
865 static_cast<int>(length), arrayType, 855 static_cast<int>(length), arrayType,
866 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 856 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
867 Handle<Map> map =
868 isolate->factory()->GetElementsTransitionMap(holder, elementsKind);
869 holder->set_map(*map);
870 holder->set_elements(*elements); 857 holder->set_elements(*elements);
871 return isolate->heap()->undefined_value(); 858 return isolate->heap()->undefined_value();
872 } 859 }
873 860
874 861
875 #define TYPED_ARRAY_GETTER(getter, accessor) \ 862 #define TYPED_ARRAY_GETTER(getter, accessor) \
876 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \ 863 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \
877 HandleScope scope(isolate); \ 864 HandleScope scope(isolate); \
878 ASSERT(args.length() == 1); \ 865 ASSERT(args.length() == 1); \
879 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \ 866 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \
(...skipping 12628 matching lines...) Expand 10 before | Expand all | Expand 10 after
13508 // Handle last resort GC and make sure to allow future allocations 13495 // Handle last resort GC and make sure to allow future allocations
13509 // to grow the heap without causing GCs (if possible). 13496 // to grow the heap without causing GCs (if possible).
13510 isolate->counters()->gc_last_resort_from_js()->Increment(); 13497 isolate->counters()->gc_last_resort_from_js()->Increment();
13511 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 13498 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13512 "Runtime::PerformGC"); 13499 "Runtime::PerformGC");
13513 } 13500 }
13514 } 13501 }
13515 13502
13516 13503
13517 } } // namespace v8::internal 13504 } } // namespace v8::internal
OLDNEW
« src/heap.h ('K') | « src/objects-inl.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698