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

Side by Side Diff: src/runtime.cc

Issue 149413010: A64: Synchronize with r16024. (Closed) Base URL: https://v8.googlecode.com/svn/branches/experimental/a64
Patch Set: Created 6 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/runtime.h ('k') | src/runtime-profiler.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 #include "runtime.h" 59 #include "runtime.h"
60 #include "scopeinfo.h" 60 #include "scopeinfo.h"
61 #include "smart-pointers.h" 61 #include "smart-pointers.h"
62 #include "string-search.h" 62 #include "string-search.h"
63 #include "stub-cache.h" 63 #include "stub-cache.h"
64 #include "uri.h" 64 #include "uri.h"
65 #include "v8conversions.h" 65 #include "v8conversions.h"
66 #include "v8threads.h" 66 #include "v8threads.h"
67 #include "vm-state-inl.h" 67 #include "vm-state-inl.h"
68 68
69 #ifdef V8_I18N_SUPPORT
70 #include "unicode/brkiter.h"
71 #include "unicode/coll.h"
72 #include "unicode/datefmt.h"
73 #include "unicode/numfmt.h"
74 #include "unicode/uloc.h"
75 #include "unicode/uversion.h"
76 #endif
77
69 #ifndef _STLP_VENDOR_CSTD 78 #ifndef _STLP_VENDOR_CSTD
70 // STLPort doesn't import fpclassify and isless into the std namespace. 79 // STLPort doesn't import fpclassify and isless into the std namespace.
71 using std::fpclassify; 80 using std::fpclassify;
72 using std::isless; 81 using std::isless;
73 #endif 82 #endif
74 83
75 namespace v8 { 84 namespace v8 {
76 namespace internal { 85 namespace internal {
77 86
78 87
(...skipping 626 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 714
706 array_buffer->set_weak_next(isolate->heap()->array_buffers_list()); 715 array_buffer->set_weak_next(isolate->heap()->array_buffers_list());
707 isolate->heap()->set_array_buffers_list(*array_buffer); 716 isolate->heap()->set_array_buffers_list(*array_buffer);
708 array_buffer->set_weak_first_view(isolate->heap()->undefined_value()); 717 array_buffer->set_weak_first_view(isolate->heap()->undefined_value());
709 } 718 }
710 719
711 720
712 bool Runtime::SetupArrayBufferAllocatingData( 721 bool Runtime::SetupArrayBufferAllocatingData(
713 Isolate* isolate, 722 Isolate* isolate,
714 Handle<JSArrayBuffer> array_buffer, 723 Handle<JSArrayBuffer> array_buffer,
715 size_t allocated_length) { 724 size_t allocated_length,
725 bool initialize) {
716 void* data; 726 void* data;
717 CHECK(V8::ArrayBufferAllocator() != NULL); 727 CHECK(V8::ArrayBufferAllocator() != NULL);
718 if (allocated_length != 0) { 728 if (allocated_length != 0) {
719 data = V8::ArrayBufferAllocator()->Allocate(allocated_length); 729 if (initialize) {
730 data = V8::ArrayBufferAllocator()->Allocate(allocated_length);
731 } else {
732 data =
733 V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length);
734 }
720 if (data == NULL) return false; 735 if (data == NULL) return false;
721 memset(data, 0, allocated_length);
722 } else { 736 } else {
723 data = NULL; 737 data = NULL;
724 } 738 }
725 739
726 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 740 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
727 741
728 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); 742 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length);
729 743
730 return true; 744 return true;
731 } 745 }
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
798 ARRAY_ID_INT8 = 2, 812 ARRAY_ID_INT8 = 2,
799 ARRAY_ID_UINT16 = 3, 813 ARRAY_ID_UINT16 = 3,
800 ARRAY_ID_INT16 = 4, 814 ARRAY_ID_INT16 = 4,
801 ARRAY_ID_UINT32 = 5, 815 ARRAY_ID_UINT32 = 5,
802 ARRAY_ID_INT32 = 6, 816 ARRAY_ID_INT32 = 6,
803 ARRAY_ID_FLOAT32 = 7, 817 ARRAY_ID_FLOAT32 = 7,
804 ARRAY_ID_FLOAT64 = 8, 818 ARRAY_ID_FLOAT64 = 8,
805 ARRAY_ID_UINT8C = 9 819 ARRAY_ID_UINT8C = 9
806 }; 820 };
807 821
822 static void ArrayIdToTypeAndSize(
823 int arrayId, ExternalArrayType* array_type, size_t* element_size) {
824 switch (arrayId) {
825 case ARRAY_ID_UINT8:
826 *array_type = kExternalUnsignedByteArray;
827 *element_size = 1;
828 break;
829 case ARRAY_ID_INT8:
830 *array_type = kExternalByteArray;
831 *element_size = 1;
832 break;
833 case ARRAY_ID_UINT16:
834 *array_type = kExternalUnsignedShortArray;
835 *element_size = 2;
836 break;
837 case ARRAY_ID_INT16:
838 *array_type = kExternalShortArray;
839 *element_size = 2;
840 break;
841 case ARRAY_ID_UINT32:
842 *array_type = kExternalUnsignedIntArray;
843 *element_size = 4;
844 break;
845 case ARRAY_ID_INT32:
846 *array_type = kExternalIntArray;
847 *element_size = 4;
848 break;
849 case ARRAY_ID_FLOAT32:
850 *array_type = kExternalFloatArray;
851 *element_size = 4;
852 break;
853 case ARRAY_ID_FLOAT64:
854 *array_type = kExternalDoubleArray;
855 *element_size = 8;
856 break;
857 case ARRAY_ID_UINT8C:
858 *array_type = kExternalPixelArray;
859 *element_size = 1;
860 break;
861 default:
862 UNREACHABLE();
863 }
864 }
865
808 866
809 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) { 867 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitialize) {
810 HandleScope scope(isolate); 868 HandleScope scope(isolate);
811 ASSERT(args.length() == 5); 869 ASSERT(args.length() == 5);
812 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0); 870 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
813 CONVERT_SMI_ARG_CHECKED(arrayId, 1); 871 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
814 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2); 872 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 2);
815 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3); 873 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset_object, 3);
816 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4); 874 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length_object, 4);
817 875
818 ASSERT(holder->GetInternalFieldCount() == 876 ASSERT(holder->GetInternalFieldCount() ==
819 v8::ArrayBufferView::kInternalFieldCount); 877 v8::ArrayBufferView::kInternalFieldCount);
820 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 878 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
821 holder->SetInternalField(i, Smi::FromInt(0)); 879 holder->SetInternalField(i, Smi::FromInt(0));
822 } 880 }
823 881
824 ExternalArrayType arrayType; 882 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
825 size_t elementSize; 883 size_t element_size = 1; // Bogus initialization.
826 switch (arrayId) { 884 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
827 case ARRAY_ID_UINT8:
828 arrayType = kExternalUnsignedByteArray;
829 elementSize = 1;
830 break;
831 case ARRAY_ID_INT8:
832 arrayType = kExternalByteArray;
833 elementSize = 1;
834 break;
835 case ARRAY_ID_UINT16:
836 arrayType = kExternalUnsignedShortArray;
837 elementSize = 2;
838 break;
839 case ARRAY_ID_INT16:
840 arrayType = kExternalShortArray;
841 elementSize = 2;
842 break;
843 case ARRAY_ID_UINT32:
844 arrayType = kExternalUnsignedIntArray;
845 elementSize = 4;
846 break;
847 case ARRAY_ID_INT32:
848 arrayType = kExternalIntArray;
849 elementSize = 4;
850 break;
851 case ARRAY_ID_FLOAT32:
852 arrayType = kExternalFloatArray;
853 elementSize = 4;
854 break;
855 case ARRAY_ID_FLOAT64:
856 arrayType = kExternalDoubleArray;
857 elementSize = 8;
858 break;
859 case ARRAY_ID_UINT8C:
860 arrayType = kExternalPixelArray;
861 elementSize = 1;
862 break;
863 default:
864 UNREACHABLE();
865 return NULL;
866 }
867 885
868 holder->set_buffer(*buffer); 886 holder->set_buffer(*buffer);
869 holder->set_byte_offset(*byte_offset_object); 887 holder->set_byte_offset(*byte_offset_object);
870 holder->set_byte_length(*byte_length_object); 888 holder->set_byte_length(*byte_length_object);
871 889
872 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); 890 size_t byte_offset = NumberToSize(isolate, *byte_offset_object);
873 size_t byte_length = NumberToSize(isolate, *byte_length_object); 891 size_t byte_length = NumberToSize(isolate, *byte_length_object);
874 ASSERT(byte_length % elementSize == 0); 892 ASSERT(byte_length % element_size == 0);
875 size_t length = byte_length / elementSize; 893 size_t length = byte_length / element_size;
876 894
877 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 895 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
878 holder->set_length(*length_obj); 896 holder->set_length(*length_obj);
879 holder->set_weak_next(buffer->weak_first_view()); 897 holder->set_weak_next(buffer->weak_first_view());
880 buffer->set_weak_first_view(*holder); 898 buffer->set_weak_first_view(*holder);
881 899
882 Handle<ExternalArray> elements = 900 Handle<ExternalArray> elements =
883 isolate->factory()->NewExternalArray( 901 isolate->factory()->NewExternalArray(
884 static_cast<int>(length), arrayType, 902 static_cast<int>(length), array_type,
885 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 903 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
886 holder->set_elements(*elements); 904 holder->set_elements(*elements);
887 return isolate->heap()->undefined_value(); 905 return isolate->heap()->undefined_value();
888 } 906 }
889 907
890 908
909 // Initializes a typed array from an array-like object.
910 // If an array-like object happens to be a typed array of the same type,
911 // initializes backing store using memove.
912 //
913 // Returns true if backing store was initialized or false otherwise.
914 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayInitializeFromArrayLike) {
915 HandleScope scope(isolate);
916 ASSERT(args.length() == 4);
917 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, holder, 0);
918 CONVERT_SMI_ARG_CHECKED(arrayId, 1);
919 CONVERT_ARG_HANDLE_CHECKED(Object, source, 2);
920 CONVERT_ARG_HANDLE_CHECKED(Object, length_obj, 3);
921
922 ASSERT(holder->GetInternalFieldCount() ==
923 v8::ArrayBufferView::kInternalFieldCount);
924 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
925 holder->SetInternalField(i, Smi::FromInt(0));
926 }
927
928 ExternalArrayType array_type = kExternalByteArray; // Bogus initialization.
929 size_t element_size = 1; // Bogus initialization.
930 ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
931
932 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
933 size_t length = NumberToSize(isolate, *length_obj);
934 size_t byte_length = length * element_size;
935 if (byte_length < length) { // Overflow
936 return isolate->Throw(*isolate->factory()->
937 NewRangeError("invalid_array_buffer_length",
938 HandleVector<Object>(NULL, 0)));
939 }
940
941 // We assume that the caller of this function will initialize holder
942 // with the loop
943 // for(i = 0; i < length; i++) { holder[i] = source[i]; }
944 // If source is a typed array, this loop will always run to completion,
945 // so we are sure that the backing store will be initialized.
946 // Otherwise, we do not know (the indexing operation might throw).
947 // Hence we require zero initialization unless our source is a typed array.
948 bool should_zero_initialize = !source->IsJSTypedArray();
949
950 if (!Runtime::SetupArrayBufferAllocatingData(
951 isolate, buffer, byte_length, should_zero_initialize)) {
952 return isolate->Throw(*isolate->factory()->
953 NewRangeError("invalid_array_buffer_length",
954 HandleVector<Object>(NULL, 0)));
955 }
956
957 holder->set_buffer(*buffer);
958 holder->set_byte_offset(Smi::FromInt(0));
959 Handle<Object> byte_length_obj(
960 isolate->factory()->NewNumberFromSize(byte_length));
961 holder->set_byte_length(*byte_length_obj);
962 holder->set_length(*length_obj);
963 holder->set_weak_next(buffer->weak_first_view());
964 buffer->set_weak_first_view(*holder);
965
966 Handle<ExternalArray> elements =
967 isolate->factory()->NewExternalArray(
968 static_cast<int>(length), array_type,
969 static_cast<uint8_t*>(buffer->backing_store()));
970 holder->set_elements(*elements);
971
972 if (source->IsJSTypedArray()) {
973 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source));
974
975 if (typed_array->type() == holder->type()) {
976 uint8_t* backing_store =
977 static_cast<uint8_t*>(
978 JSArrayBuffer::cast(typed_array->buffer())->backing_store());
979 size_t source_byte_offset =
980 NumberToSize(isolate, typed_array->byte_offset());
981 OS::MemCopy(
982 buffer->backing_store(),
983 backing_store + source_byte_offset,
984 byte_length);
985 return *isolate->factory()->true_value();
986 } else {
987 return *isolate->factory()->false_value();
988 }
989 }
990
991 return *isolate->factory()->false_value();
992 }
993
994
891 #define TYPED_ARRAY_GETTER(getter, accessor) \ 995 #define TYPED_ARRAY_GETTER(getter, accessor) \
892 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \ 996 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArrayGet##getter) { \
893 HandleScope scope(isolate); \ 997 HandleScope scope(isolate); \
894 ASSERT(args.length() == 1); \ 998 ASSERT(args.length() == 1); \
895 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \ 999 CONVERT_ARG_HANDLE_CHECKED(Object, holder, 0); \
896 if (!holder->IsJSTypedArray()) \ 1000 if (!holder->IsJSTypedArray()) \
897 return isolate->Throw(*isolate->factory()->NewTypeError( \ 1001 return isolate->Throw(*isolate->factory()->NewTypeError( \
898 "not_typed_array", HandleVector<Object>(NULL, 0))); \ 1002 "not_typed_array", HandleVector<Object>(NULL, 0))); \
899 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder)); \ 1003 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*holder)); \
900 return typed_array->accessor(); \ 1004 return typed_array->accessor(); \
901 } 1005 }
902 1006
903 TYPED_ARRAY_GETTER(Buffer, buffer) 1007 TYPED_ARRAY_GETTER(Buffer, buffer)
904 TYPED_ARRAY_GETTER(ByteLength, byte_length) 1008 TYPED_ARRAY_GETTER(ByteLength, byte_length)
905 TYPED_ARRAY_GETTER(ByteOffset, byte_offset) 1009 TYPED_ARRAY_GETTER(ByteOffset, byte_offset)
906 TYPED_ARRAY_GETTER(Length, length) 1010 TYPED_ARRAY_GETTER(Length, length)
907 1011
908 #undef TYPED_ARRAY_GETTER 1012 #undef TYPED_ARRAY_GETTER
909 1013
1014 // Return codes for Runtime_TypedArraySetFastCases.
1015 // Should be synchronized with typedarray.js natives.
1016 enum TypedArraySetResultCodes {
1017 // Set from typed array of the same type.
1018 // This is processed by TypedArraySetFastCases
1019 TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE = 0,
1020 // Set from typed array of the different type, overlapping in memory.
1021 TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING = 1,
1022 // Set from typed array of the different type, non-overlapping.
1023 TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING = 2,
1024 // Set from non-typed array.
1025 TYPED_ARRAY_SET_NON_TYPED_ARRAY = 3
1026 };
1027
1028
910 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArraySetFastCases) { 1029 RUNTIME_FUNCTION(MaybeObject*, Runtime_TypedArraySetFastCases) {
911 HandleScope scope(isolate); 1030 HandleScope scope(isolate);
912 CONVERT_ARG_HANDLE_CHECKED(Object, target_obj, 0); 1031 CONVERT_ARG_HANDLE_CHECKED(Object, target_obj, 0);
913 CONVERT_ARG_HANDLE_CHECKED(Object, source_obj, 1); 1032 CONVERT_ARG_HANDLE_CHECKED(Object, source_obj, 1);
914 CONVERT_ARG_HANDLE_CHECKED(Object, offset_obj, 2); 1033 CONVERT_ARG_HANDLE_CHECKED(Object, offset_obj, 2);
915 1034
916 if (!target_obj->IsJSTypedArray()) 1035 if (!target_obj->IsJSTypedArray())
917 return isolate->Throw(*isolate->factory()->NewTypeError( 1036 return isolate->Throw(*isolate->factory()->NewTypeError(
918 "not_typed_array", HandleVector<Object>(NULL, 0))); 1037 "not_typed_array", HandleVector<Object>(NULL, 0)));
919 1038
920 if (!source_obj->IsJSTypedArray()) 1039 if (!source_obj->IsJSTypedArray())
921 return isolate->heap()->false_value(); 1040 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY);
922 1041
923 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); 1042 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
924 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); 1043 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
925 size_t offset = NumberToSize(isolate, *offset_obj); 1044 size_t offset = NumberToSize(isolate, *offset_obj);
926 size_t target_length = NumberToSize(isolate, target->length()); 1045 size_t target_length = NumberToSize(isolate, target->length());
927 size_t source_length = NumberToSize(isolate, source->length()); 1046 size_t source_length = NumberToSize(isolate, source->length());
928 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); 1047 size_t target_byte_length = NumberToSize(isolate, target->byte_length());
929 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 1048 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
930 if (offset > target_length || 1049 if (offset > target_length ||
931 offset + source_length > target_length || 1050 offset + source_length > target_length ||
932 offset + source_length < offset) // overflow 1051 offset + source_length < offset) // overflow
933 return isolate->Throw(*isolate->factory()->NewRangeError( 1052 return isolate->Throw(*isolate->factory()->NewRangeError(
934 "typed_array_set_source_too_large", HandleVector<Object>(NULL, 0))); 1053 "typed_array_set_source_too_large", HandleVector<Object>(NULL, 0)));
935 1054
936 Handle<JSArrayBuffer> target_buffer(JSArrayBuffer::cast(target->buffer()));
937 Handle<JSArrayBuffer> source_buffer(JSArrayBuffer::cast(source->buffer()));
938 size_t target_offset = NumberToSize(isolate, target->byte_offset()); 1055 size_t target_offset = NumberToSize(isolate, target->byte_offset());
939 size_t source_offset = NumberToSize(isolate, source->byte_offset()); 1056 size_t source_offset = NumberToSize(isolate, source->byte_offset());
940 uint8_t* target_base = 1057 uint8_t* target_base =
941 static_cast<uint8_t*>(target_buffer->backing_store()) + target_offset; 1058 static_cast<uint8_t*>(
1059 JSArrayBuffer::cast(target->buffer())->backing_store()) + target_offset;
942 uint8_t* source_base = 1060 uint8_t* source_base =
943 static_cast<uint8_t*>(source_buffer->backing_store()) + source_offset; 1061 static_cast<uint8_t*>(
1062 JSArrayBuffer::cast(source->buffer())->backing_store()) + source_offset;
944 1063
945 // Typed arrays of the same type: use memmove. 1064 // Typed arrays of the same type: use memmove.
946 if (target->type() == source->type()) { 1065 if (target->type() == source->type()) {
947 memmove(target_base + offset * target->element_size(), 1066 memmove(target_base + offset * target->element_size(),
948 source_base, source_byte_length); 1067 source_base, source_byte_length);
949 return isolate->heap()->true_value(); 1068 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_SAME_TYPE);
950 } 1069 }
951 1070
952 // Typed arrays of different types over the same backing store 1071 // Typed arrays of different types over the same backing store
953 if ((source_base <= target_base && 1072 if ((source_base <= target_base &&
954 source_base + source_byte_length > target_base) || 1073 source_base + source_byte_length > target_base) ||
955 (target_base <= source_base && 1074 (target_base <= source_base &&
956 target_base + target_byte_length > source_base)) { 1075 target_base + target_byte_length > source_base)) {
957 size_t target_element_size = target->element_size(); 1076 // We do not support overlapping ArrayBuffers
958 size_t source_element_size = source->element_size(); 1077 ASSERT(
959 1078 JSArrayBuffer::cast(target->buffer())->backing_store() ==
960 size_t source_length = NumberToSize(isolate, source->length()); 1079 JSArrayBuffer::cast(source->buffer())->backing_store());
961 1080 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_OVERLAPPING);
962 // Copy left part
963 size_t left_index;
964 {
965 // First un-mutated byte after the next write
966 uint8_t* target_ptr = target_base + (offset + 1) * target_element_size;
967 // Next read at source_ptr. We do not care for memory changing before
968 // source_ptr - we have already copied it.
969 uint8_t* source_ptr = source_base;
970 for (left_index = 0;
971 left_index < source_length && target_ptr <= source_ptr;
972 left_index++) {
973 Handle<Object> v = Object::GetElement(
974 source, static_cast<uint32_t>(left_index));
975 JSObject::SetElement(
976 target, static_cast<uint32_t>(offset + left_index), v,
977 NONE, kNonStrictMode);
978 target_ptr += target_element_size;
979 source_ptr += source_element_size;
980 }
981 }
982 // Copy right part
983 size_t right_index;
984 {
985 // First unmutated byte before the next write
986 uint8_t* target_ptr =
987 target_base + (offset + source_length - 1) * target_element_size;
988 // Next read before source_ptr. We do not care for memory changing after
989 // source_ptr - we have already copied it.
990 uint8_t* source_ptr =
991 source_base + source_length * source_element_size;
992 for (right_index = source_length - 1;
993 right_index >= left_index && target_ptr >= source_ptr;
994 right_index--) {
995 Handle<Object> v = Object::GetElement(
996 source, static_cast<uint32_t>(right_index));
997 JSObject::SetElement(
998 target, static_cast<uint32_t>(offset + right_index), v,
999 NONE, kNonStrictMode);
1000 target_ptr -= target_element_size;
1001 source_ptr -= source_element_size;
1002 }
1003 }
1004 // There can be at most 8 entries left in the middle that need buffering
1005 // (because the largest element_size is 8 times the smallest).
1006 ASSERT((right_index + 1) - left_index <= 8);
1007 Handle<Object> temp[8];
1008 size_t idx;
1009 for (idx = left_index; idx <= right_index; idx++) {
1010 temp[idx - left_index] = Object::GetElement(
1011 source, static_cast<uint32_t>(idx));
1012 }
1013 for (idx = left_index; idx <= right_index; idx++) {
1014 JSObject::SetElement(
1015 target, static_cast<uint32_t>(offset + idx), temp[idx-left_index],
1016 NONE, kNonStrictMode);
1017 }
1018 } else { // Non-overlapping typed arrays 1081 } else { // Non-overlapping typed arrays
1019 for (size_t idx = 0; idx < source_length; idx++) { 1082 return Smi::FromInt(TYPED_ARRAY_SET_TYPED_ARRAY_NONOVERLAPPING);
1020 Handle<Object> value = Object::GetElement(
1021 source, static_cast<uint32_t>(idx));
1022 JSObject::SetElement(
1023 target, static_cast<uint32_t>(offset + idx), value,
1024 NONE, kNonStrictMode);
1025 }
1026 } 1083 }
1027
1028 return isolate->heap()->true_value();
1029 } 1084 }
1030 1085
1031 1086
1032 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) { 1087 RUNTIME_FUNCTION(MaybeObject*, Runtime_DataViewInitialize) {
1033 HandleScope scope(isolate); 1088 HandleScope scope(isolate);
1034 ASSERT(args.length() == 4); 1089 ASSERT(args.length() == 4);
1035 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0); 1090 CONVERT_ARG_HANDLE_CHECKED(JSDataView, holder, 0);
1036 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1); 1091 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, buffer, 1);
1037 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2); 1092 CONVERT_ARG_HANDLE_CHECKED(Object, byte_offset, 2);
1038 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3); 1093 CONVERT_ARG_HANDLE_CHECKED(Object, byte_length, 3);
(...skipping 1902 matching lines...) Expand 10 before | Expand all | Expand 10 after
2941 RUNTIME_FUNCTION(MaybeObject*, Runtime_ResumeJSGeneratorObject) { 2996 RUNTIME_FUNCTION(MaybeObject*, Runtime_ResumeJSGeneratorObject) {
2942 SealHandleScope shs(isolate); 2997 SealHandleScope shs(isolate);
2943 ASSERT(args.length() == 3); 2998 ASSERT(args.length() == 3);
2944 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0); 2999 CONVERT_ARG_CHECKED(JSGeneratorObject, generator_object, 0);
2945 CONVERT_ARG_CHECKED(Object, value, 1); 3000 CONVERT_ARG_CHECKED(Object, value, 1);
2946 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2); 3001 CONVERT_SMI_ARG_CHECKED(resume_mode_int, 2);
2947 JavaScriptFrameIterator stack_iterator(isolate); 3002 JavaScriptFrameIterator stack_iterator(isolate);
2948 JavaScriptFrame* frame = stack_iterator.frame(); 3003 JavaScriptFrame* frame = stack_iterator.frame();
2949 3004
2950 ASSERT_EQ(frame->function(), generator_object->function()); 3005 ASSERT_EQ(frame->function(), generator_object->function());
2951 ASSERT(frame->function()->is_compiled());
2952 3006
2953 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0); 3007 STATIC_ASSERT(JSGeneratorObject::kGeneratorExecuting <= 0);
2954 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0); 3008 STATIC_ASSERT(JSGeneratorObject::kGeneratorClosed <= 0);
2955 3009
2956 Address pc = generator_object->function()->code()->instruction_start(); 3010 Address pc = generator_object->function()->code()->instruction_start();
2957 int offset = generator_object->continuation(); 3011 int offset = generator_object->continuation();
2958 ASSERT(offset > 0); 3012 ASSERT(offset > 0);
2959 frame->set_pc(pc + offset); 3013 frame->set_pc(pc + offset);
2960 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting); 3014 generator_object->set_continuation(JSGeneratorObject::kGeneratorExecuting);
2961 3015
(...skipping 5463 matching lines...) Expand 10 before | Expand all | Expand 10 after
8425 } 8479 }
8426 bool sync_with_compiler_thread = true; 8480 bool sync_with_compiler_thread = true;
8427 if (args.length() == 2) { 8481 if (args.length() == 2) {
8428 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1); 8482 CONVERT_ARG_HANDLE_CHECKED(String, sync, 1);
8429 if (sync->IsOneByteEqualTo(STATIC_ASCII_VECTOR("no sync"))) { 8483 if (sync->IsOneByteEqualTo(STATIC_ASCII_VECTOR("no sync"))) {
8430 sync_with_compiler_thread = false; 8484 sync_with_compiler_thread = false;
8431 } 8485 }
8432 } 8486 }
8433 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0); 8487 CONVERT_ARG_HANDLE_CHECKED(JSFunction, function, 0);
8434 if (FLAG_parallel_recompilation && sync_with_compiler_thread) { 8488 if (FLAG_parallel_recompilation && sync_with_compiler_thread) {
8435 while (function->IsInRecompileQueue() || 8489 while (function->IsMarkedForParallelRecompilation() ||
8490 function->IsInRecompileQueue() ||
8436 function->IsMarkedForInstallingRecompiledCode()) { 8491 function->IsMarkedForInstallingRecompiledCode()) {
8437 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions(); 8492 isolate->optimizing_compiler_thread()->InstallOptimizedFunctions();
8438 OS::Sleep(50); 8493 OS::Sleep(50);
8439 } 8494 }
8440 } 8495 }
8441 if (FLAG_always_opt) { 8496 if (FLAG_always_opt) {
8442 // We may have always opt, but that is more best-effort than a real 8497 // We may have always opt, but that is more best-effort than a real
8443 // promise, so we still say "no" if it is not optimized. 8498 // promise, so we still say "no" if it is not optimized.
8444 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always". 8499 return function->IsOptimized() ? Smi::FromInt(3) // 3 == "always".
8445 : Smi::FromInt(2); // 2 == "no". 8500 : Smi::FromInt(2); // 2 == "no".
(...skipping 4434 matching lines...) Expand 10 before | Expand all | Expand 10 after
12880 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) { 12935 RUNTIME_FUNCTION(MaybeObject*, Runtime_DebugSetScriptSource) {
12881 HandleScope scope(isolate); 12936 HandleScope scope(isolate);
12882 ASSERT(args.length() == 2); 12937 ASSERT(args.length() == 2);
12883 12938
12884 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0); 12939 CONVERT_ARG_HANDLE_CHECKED(JSValue, script_wrapper, 0);
12885 CONVERT_ARG_HANDLE_CHECKED(String, source, 1); 12940 CONVERT_ARG_HANDLE_CHECKED(String, source, 1);
12886 12941
12887 RUNTIME_ASSERT(script_wrapper->value()->IsScript()); 12942 RUNTIME_ASSERT(script_wrapper->value()->IsScript());
12888 Handle<Script> script(Script::cast(script_wrapper->value())); 12943 Handle<Script> script(Script::cast(script_wrapper->value()));
12889 12944
12890 int compilation_state = Smi::cast(script->compilation_state())->value(); 12945 int compilation_state = script->compilation_state();
12891 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL); 12946 RUNTIME_ASSERT(compilation_state == Script::COMPILATION_STATE_INITIAL);
12892 script->set_source(*source); 12947 script->set_source(*source);
12893 12948
12894 return isolate->heap()->undefined_value(); 12949 return isolate->heap()->undefined_value();
12895 } 12950 }
12896 12951
12897 12952
12898 RUNTIME_FUNCTION(MaybeObject*, Runtime_SystemBreak) { 12953 RUNTIME_FUNCTION(MaybeObject*, Runtime_SystemBreak) {
12899 SealHandleScope shs(isolate); 12954 SealHandleScope shs(isolate);
12900 ASSERT(args.length() == 0); 12955 ASSERT(args.length() == 0);
(...skipping 408 matching lines...) Expand 10 before | Expand all | Expand 10 after
13309 int usage = static_cast<int>(isolate->heap()->SizeOfObjects()); 13364 int usage = static_cast<int>(isolate->heap()->SizeOfObjects());
13310 if (!Smi::IsValid(usage)) { 13365 if (!Smi::IsValid(usage)) {
13311 return *isolate->factory()->NewNumberFromInt(usage); 13366 return *isolate->factory()->NewNumberFromInt(usage);
13312 } 13367 }
13313 return Smi::FromInt(usage); 13368 return Smi::FromInt(usage);
13314 } 13369 }
13315 13370
13316 #endif // ENABLE_DEBUGGER_SUPPORT 13371 #endif // ENABLE_DEBUGGER_SUPPORT
13317 13372
13318 13373
13374 #ifdef V8_I18N_SUPPORT
13375 RUNTIME_FUNCTION(MaybeObject*, Runtime_CanonicalizeLanguageTag) {
13376 HandleScope scope(isolate);
13377
13378 ASSERT(args.length() == 1);
13379 CONVERT_ARG_HANDLE_CHECKED(String, locale_id_str, 0);
13380
13381 v8::String::Utf8Value locale_id(v8::Utils::ToLocal(locale_id_str));
13382
13383 // Return value which denotes invalid language tag.
13384 const char* const kInvalidTag = "invalid-tag";
13385
13386 UErrorCode error = U_ZERO_ERROR;
13387 char icu_result[ULOC_FULLNAME_CAPACITY];
13388 int icu_length = 0;
13389
13390 uloc_forLanguageTag(*locale_id, icu_result, ULOC_FULLNAME_CAPACITY,
13391 &icu_length, &error);
13392 if (U_FAILURE(error) || icu_length == 0) {
13393 return isolate->heap()->AllocateStringFromOneByte(CStrVector(kInvalidTag));
13394 }
13395
13396 char result[ULOC_FULLNAME_CAPACITY];
13397
13398 // Force strict BCP47 rules.
13399 uloc_toLanguageTag(icu_result, result, ULOC_FULLNAME_CAPACITY, TRUE, &error);
13400
13401 if (U_FAILURE(error)) {
13402 return isolate->heap()->AllocateStringFromOneByte(CStrVector(kInvalidTag));
13403 }
13404
13405 return isolate->heap()->AllocateStringFromOneByte(CStrVector(result));
13406 }
13407
13408
13409 RUNTIME_FUNCTION(MaybeObject*, Runtime_AvailableLocalesOf) {
13410 HandleScope scope(isolate);
13411
13412 ASSERT(args.length() == 1);
13413 CONVERT_ARG_HANDLE_CHECKED(String, service, 0);
13414
13415 const icu::Locale* available_locales = NULL;
13416 int32_t count = 0;
13417
13418 if (service->IsUtf8EqualTo(CStrVector("collator"))) {
13419 available_locales = icu::Collator::getAvailableLocales(count);
13420 } else if (service->IsUtf8EqualTo(CStrVector("numberformat"))) {
13421 available_locales = icu::NumberFormat::getAvailableLocales(count);
13422 } else if (service->IsUtf8EqualTo(CStrVector("dateformat"))) {
13423 available_locales = icu::DateFormat::getAvailableLocales(count);
13424 } else if (service->IsUtf8EqualTo(CStrVector("breakiterator"))) {
13425 available_locales = icu::BreakIterator::getAvailableLocales(count);
13426 }
13427
13428 UErrorCode error = U_ZERO_ERROR;
13429 char result[ULOC_FULLNAME_CAPACITY];
13430 Handle<JSObject> locales =
13431 isolate->factory()->NewJSObject(isolate->object_function());
13432
13433 for (int32_t i = 0; i < count; ++i) {
13434 const char* icu_name = available_locales[i].getName();
13435
13436 error = U_ZERO_ERROR;
13437 // No need to force strict BCP47 rules.
13438 uloc_toLanguageTag(icu_name, result, ULOC_FULLNAME_CAPACITY, FALSE, &error);
13439 if (U_FAILURE(error)) {
13440 // This shouldn't happen, but lets not break the user.
13441 continue;
13442 }
13443
13444 RETURN_IF_EMPTY_HANDLE(isolate,
13445 JSObject::SetLocalPropertyIgnoreAttributes(
13446 locales,
13447 isolate->factory()->NewStringFromAscii(CStrVector(result)),
13448 isolate->factory()->NewNumber(i),
13449 NONE));
13450 }
13451
13452 return *locales;
13453 }
13454
13455
13456 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetDefaultICULocale) {
13457 SealHandleScope shs(isolate);
13458
13459 ASSERT(args.length() == 0);
13460
13461 icu::Locale default_locale;
13462
13463 // Set the locale
13464 char result[ULOC_FULLNAME_CAPACITY];
13465 UErrorCode status = U_ZERO_ERROR;
13466 uloc_toLanguageTag(
13467 default_locale.getName(), result, ULOC_FULLNAME_CAPACITY, FALSE, &status);
13468 if (U_SUCCESS(status)) {
13469 return isolate->heap()->AllocateStringFromOneByte(CStrVector(result));
13470 }
13471
13472 return isolate->heap()->AllocateStringFromOneByte(CStrVector("und"));
13473 }
13474
13475
13476 RUNTIME_FUNCTION(MaybeObject*, Runtime_GetLanguageTagVariants) {
13477 HandleScope scope(isolate);
13478
13479 ASSERT(args.length() == 1);
13480
13481 CONVERT_ARG_HANDLE_CHECKED(JSArray, input, 0);
13482
13483 uint32_t length = static_cast<uint32_t>(input->length()->Number());
13484 Handle<FixedArray> output = isolate->factory()->NewFixedArray(length);
13485 Handle<Name> maximized =
13486 isolate->factory()->NewStringFromAscii(CStrVector("maximized"));
13487 Handle<Name> base =
13488 isolate->factory()->NewStringFromAscii(CStrVector("base"));
13489 for (unsigned int i = 0; i < length; ++i) {
13490 MaybeObject* maybe_string = input->GetElement(i);
13491 Object* locale_id;
13492 if (!maybe_string->ToObject(&locale_id) || !locale_id->IsString()) {
13493 return isolate->Throw(isolate->heap()->illegal_argument_string());
13494 }
13495
13496 v8::String::Utf8Value utf8_locale_id(
13497 v8::Utils::ToLocal(Handle<String>(String::cast(locale_id))));
13498
13499 UErrorCode error = U_ZERO_ERROR;
13500
13501 // Convert from BCP47 to ICU format.
13502 // de-DE-u-co-phonebk -> de_DE@collation=phonebook
13503 char icu_locale[ULOC_FULLNAME_CAPACITY];
13504 int icu_locale_length = 0;
13505 uloc_forLanguageTag(*utf8_locale_id, icu_locale, ULOC_FULLNAME_CAPACITY,
13506 &icu_locale_length, &error);
13507 if (U_FAILURE(error) || icu_locale_length == 0) {
13508 return isolate->Throw(isolate->heap()->illegal_argument_string());
13509 }
13510
13511 // Maximize the locale.
13512 // de_DE@collation=phonebook -> de_Latn_DE@collation=phonebook
13513 char icu_max_locale[ULOC_FULLNAME_CAPACITY];
13514 uloc_addLikelySubtags(
13515 icu_locale, icu_max_locale, ULOC_FULLNAME_CAPACITY, &error);
13516
13517 // Remove extensions from maximized locale.
13518 // de_Latn_DE@collation=phonebook -> de_Latn_DE
13519 char icu_base_max_locale[ULOC_FULLNAME_CAPACITY];
13520 uloc_getBaseName(
13521 icu_max_locale, icu_base_max_locale, ULOC_FULLNAME_CAPACITY, &error);
13522
13523 // Get original name without extensions.
13524 // de_DE@collation=phonebook -> de_DE
13525 char icu_base_locale[ULOC_FULLNAME_CAPACITY];
13526 uloc_getBaseName(
13527 icu_locale, icu_base_locale, ULOC_FULLNAME_CAPACITY, &error);
13528
13529 // Convert from ICU locale format to BCP47 format.
13530 // de_Latn_DE -> de-Latn-DE
13531 char base_max_locale[ULOC_FULLNAME_CAPACITY];
13532 uloc_toLanguageTag(icu_base_max_locale, base_max_locale,
13533 ULOC_FULLNAME_CAPACITY, FALSE, &error);
13534
13535 // de_DE -> de-DE
13536 char base_locale[ULOC_FULLNAME_CAPACITY];
13537 uloc_toLanguageTag(
13538 icu_base_locale, base_locale, ULOC_FULLNAME_CAPACITY, FALSE, &error);
13539
13540 if (U_FAILURE(error)) {
13541 return isolate->Throw(isolate->heap()->illegal_argument_string());
13542 }
13543
13544 Handle<JSObject> result =
13545 isolate->factory()->NewJSObject(isolate->object_function());
13546 RETURN_IF_EMPTY_HANDLE(isolate,
13547 JSObject::SetLocalPropertyIgnoreAttributes(
13548 result,
13549 maximized,
13550 isolate->factory()->NewStringFromAscii(CStrVector(base_max_locale)),
13551 NONE));
13552 RETURN_IF_EMPTY_HANDLE(isolate,
13553 JSObject::SetLocalPropertyIgnoreAttributes(
13554 result,
13555 base,
13556 isolate->factory()->NewStringFromAscii(CStrVector(base_locale)),
13557 NONE));
13558 output->set(i, *result);
13559 }
13560
13561 Handle<JSArray> result = isolate->factory()->NewJSArrayWithElements(output);
13562 result->set_length(Smi::FromInt(length));
13563 return *result;
13564 }
13565 #endif // V8_I18N_SUPPORT
13566
13567
13319 // Finds the script object from the script data. NOTE: This operation uses 13568 // Finds the script object from the script data. NOTE: This operation uses
13320 // heap traversal to find the function generated for the source position 13569 // heap traversal to find the function generated for the source position
13321 // for the requested break point. For lazily compiled functions several heap 13570 // for the requested break point. For lazily compiled functions several heap
13322 // traversals might be required rendering this operation as a rather slow 13571 // traversals might be required rendering this operation as a rather slow
13323 // operation. However for setting break points which is normally done through 13572 // operation. However for setting break points which is normally done through
13324 // some kind of user interaction the performance is not crucial. 13573 // some kind of user interaction the performance is not crucial.
13325 static Handle<Object> Runtime_GetScriptFromScriptName( 13574 static Handle<Object> Runtime_GetScriptFromScriptName(
13326 Handle<String> script_name) { 13575 Handle<String> script_name) {
13327 // Scan the heap for Script objects to find the script with the requested 13576 // Scan the heap for Script objects to find the script with the requested
13328 // script data. 13577 // script data.
(...skipping 578 matching lines...) Expand 10 before | Expand all | Expand 10 after
13907 // Handle last resort GC and make sure to allow future allocations 14156 // Handle last resort GC and make sure to allow future allocations
13908 // to grow the heap without causing GCs (if possible). 14157 // to grow the heap without causing GCs (if possible).
13909 isolate->counters()->gc_last_resort_from_js()->Increment(); 14158 isolate->counters()->gc_last_resort_from_js()->Increment();
13910 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14159 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
13911 "Runtime::PerformGC"); 14160 "Runtime::PerformGC");
13912 } 14161 }
13913 } 14162 }
13914 14163
13915 14164
13916 } } // namespace v8::internal 14165 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/runtime-profiler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698