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

Side by Side Diff: src/runtime.cc

Issue 209393014: Merged r20022 into 3.24 branch. (Closed) Base URL: https://v8.googlecode.com/svn/branches/3.24
Patch Set: Created 6 years, 9 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/typedarray.js » ('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 778 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 } 789 }
790 790
791 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 791 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
792 792
793 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length); 793 isolate->heap()->AdjustAmountOfExternalAllocatedMemory(allocated_length);
794 794
795 return true; 795 return true;
796 } 796 }
797 797
798 798
799 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) {
800 Isolate* isolate = array_buffer->GetIsolate();
801 for (Handle<Object> view_obj(array_buffer->weak_first_view(), isolate);
802 !view_obj->IsUndefined();) {
803 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj));
804 if (view->IsJSTypedArray()) {
805 JSTypedArray::cast(*view)->Neuter();
806 } else if (view->IsJSDataView()) {
807 JSDataView::cast(*view)->Neuter();
808 } else {
809 UNREACHABLE();
810 }
811 view_obj = handle(view->weak_next(), isolate);
812 }
813 array_buffer->Neuter();
814 }
815
816
799 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) { 817 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferInitialize) {
800 HandleScope scope(isolate); 818 HandleScope scope(isolate);
801 ASSERT(args.length() == 2); 819 ASSERT(args.length() == 2);
802 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); 820 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0);
803 CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1); 821 CONVERT_ARG_HANDLE_CHECKED(Object, byteLength, 1);
804 size_t allocated_length; 822 size_t allocated_length;
805 if (byteLength->IsSmi()) { 823 if (byteLength->IsSmi()) {
806 allocated_length = Smi::cast(*byteLength)->value(); 824 allocated_length = Smi::cast(*byteLength)->value();
807 } else { 825 } else {
808 ASSERT(byteLength->IsHeapNumber()); 826 ASSERT(byteLength->IsHeapNumber());
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
842 HandleScope scope(isolate); 860 HandleScope scope(isolate);
843 ASSERT(args.length() == 3); 861 ASSERT(args.length() == 3);
844 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0); 862 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, source, 0);
845 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1); 863 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, target, 1);
846 CONVERT_DOUBLE_ARG_CHECKED(first, 2); 864 CONVERT_DOUBLE_ARG_CHECKED(first, 2);
847 size_t start = static_cast<size_t>(first); 865 size_t start = static_cast<size_t>(first);
848 size_t target_length = NumberToSize(isolate, target->byte_length()); 866 size_t target_length = NumberToSize(isolate, target->byte_length());
849 867
850 if (target_length == 0) return isolate->heap()->undefined_value(); 868 if (target_length == 0) return isolate->heap()->undefined_value();
851 869
852 ASSERT(NumberToSize(isolate, source->byte_length()) - target_length >= start); 870 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
871 CHECK(start <= source_byte_length);
872 CHECK(source_byte_length - start >= target_length);
853 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store()); 873 uint8_t* source_data = reinterpret_cast<uint8_t*>(source->backing_store());
854 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store()); 874 uint8_t* target_data = reinterpret_cast<uint8_t*>(target->backing_store());
855 CopyBytes(target_data, source_data + start, target_length); 875 CopyBytes(target_data, source_data + start, target_length);
856 return isolate->heap()->undefined_value(); 876 return isolate->heap()->undefined_value();
857 } 877 }
858 878
859 879
860 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) { 880 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferIsView) {
861 HandleScope scope(isolate); 881 HandleScope scope(isolate);
862 ASSERT(args.length() == 1); 882 ASSERT(args.length() == 1);
863 CONVERT_ARG_CHECKED(Object, object, 0); 883 CONVERT_ARG_CHECKED(Object, object, 0);
864 return object->IsJSArrayBufferView() 884 return object->IsJSArrayBufferView()
865 ? isolate->heap()->true_value() 885 ? isolate->heap()->true_value()
866 : isolate->heap()->false_value(); 886 : isolate->heap()->false_value();
867 } 887 }
868 888
869 889
890 RUNTIME_FUNCTION(MaybeObject*, Runtime_ArrayBufferNeuter) {
891 HandleScope scope(isolate);
892 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0);
893 ASSERT(!array_buffer->is_external());
894 void* backing_store = array_buffer->backing_store();
895 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length());
896 array_buffer->set_is_external(true);
897 Runtime::NeuterArrayBuffer(array_buffer);
898 V8::ArrayBufferAllocator()->Free(backing_store, byte_length);
899 return isolate->heap()->undefined_value();
900 }
901
902
870 void Runtime::ArrayIdToTypeAndSize( 903 void Runtime::ArrayIdToTypeAndSize(
871 int arrayId, ExternalArrayType* array_type, size_t* element_size) { 904 int arrayId, ExternalArrayType* array_type, size_t* element_size) {
872 switch (arrayId) { 905 switch (arrayId) {
873 #define ARRAY_ID_CASE(Type, type, TYPE, ctype, size) \ 906 #define ARRAY_ID_CASE(Type, type, TYPE, ctype, size) \
874 case ARRAY_ID_##TYPE: \ 907 case ARRAY_ID_##TYPE: \
875 *array_type = kExternal##Type##Array; \ 908 *array_type = kExternal##Type##Array; \
876 *element_size = size; \ 909 *element_size = size; \
877 break; 910 break;
878 911
879 TYPED_ARRAYS(ARRAY_ID_CASE) 912 TYPED_ARRAYS(ARRAY_ID_CASE)
(...skipping 23 matching lines...) Expand all
903 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization. 936 ExternalArrayType array_type = kExternalInt8Array; // Bogus initialization.
904 size_t element_size = 1; // Bogus initialization. 937 size_t element_size = 1; // Bogus initialization.
905 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size); 938 Runtime::ArrayIdToTypeAndSize(arrayId, &array_type, &element_size);
906 939
907 holder->set_buffer(*buffer); 940 holder->set_buffer(*buffer);
908 holder->set_byte_offset(*byte_offset_object); 941 holder->set_byte_offset(*byte_offset_object);
909 holder->set_byte_length(*byte_length_object); 942 holder->set_byte_length(*byte_length_object);
910 943
911 size_t byte_offset = NumberToSize(isolate, *byte_offset_object); 944 size_t byte_offset = NumberToSize(isolate, *byte_offset_object);
912 size_t byte_length = NumberToSize(isolate, *byte_length_object); 945 size_t byte_length = NumberToSize(isolate, *byte_length_object);
913 ASSERT(byte_length % element_size == 0); 946 size_t array_buffer_byte_length =
947 NumberToSize(isolate, buffer->byte_length());
948 CHECK(byte_offset <= array_buffer_byte_length);
949 CHECK(array_buffer_byte_length - byte_offset >= byte_length);
950
951 CHECK_EQ(0, static_cast<int>(byte_length % element_size));
914 size_t length = byte_length / element_size; 952 size_t length = byte_length / element_size;
915 953
916 if (length > static_cast<unsigned>(Smi::kMaxValue)) { 954 if (length > static_cast<unsigned>(Smi::kMaxValue)) {
917 return isolate->Throw(*isolate->factory()-> 955 return isolate->Throw(*isolate->factory()->
918 NewRangeError("invalid_typed_array_length", 956 NewRangeError("invalid_typed_array_length",
919 HandleVector<Object>(NULL, 0))); 957 HandleVector<Object>(NULL, 0)));
920 } 958 }
921 959
922 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 960 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
923 holder->set_length(*length_obj); 961 holder->set_length(*length_obj);
(...skipping 13945 matching lines...) Expand 10 before | Expand all | Expand 10 after
14869 // Handle last resort GC and make sure to allow future allocations 14907 // Handle last resort GC and make sure to allow future allocations
14870 // to grow the heap without causing GCs (if possible). 14908 // to grow the heap without causing GCs (if possible).
14871 isolate->counters()->gc_last_resort_from_js()->Increment(); 14909 isolate->counters()->gc_last_resort_from_js()->Increment();
14872 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags, 14910 isolate->heap()->CollectAllGarbage(Heap::kNoGCFlags,
14873 "Runtime::PerformGC"); 14911 "Runtime::PerformGC");
14874 } 14912 }
14875 } 14913 }
14876 14914
14877 14915
14878 } } // namespace v8::internal 14916 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698