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/runtime/runtime-typedarray.cc

Issue 1069883002: WIP SharedArrayBuffer implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: merge master Created 5 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
« no previous file with comments | « src/objects-printer.cc ('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 2014 the V8 project authors. All rights reserved. 1 // Copyright 2014 the V8 project authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "src/v8.h" 5 #include "src/v8.h"
6 6
7 #include "src/arguments.h" 7 #include "src/arguments.h"
8 #include "src/messages.h" 8 #include "src/messages.h"
9 #include "src/runtime/runtime.h" 9 #include "src/runtime/runtime.h"
10 #include "src/runtime/runtime-utils.h" 10 #include "src/runtime/runtime-utils.h"
(...skipping 24 matching lines...) Expand all
35 if (data && !is_external) { 35 if (data && !is_external) {
36 isolate->heap()->RegisterNewArrayBuffer(data, allocated_length); 36 isolate->heap()->RegisterNewArrayBuffer(data, allocated_length);
37 } 37 }
38 } 38 }
39 39
40 40
41 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, 41 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
42 Handle<JSArrayBuffer> array_buffer, 42 Handle<JSArrayBuffer> array_buffer,
43 size_t allocated_length, 43 size_t allocated_length,
44 bool initialize) { 44 bool initialize) {
45 v8::ArrayBuffer::Allocator* allocator =
46 array_buffer->is_shared() ? isolate->shared_array_buffer_allocator()
47 : isolate->array_buffer_allocator();
48 CHECK(allocator != NULL);
45 void* data; 49 void* data;
46 CHECK(isolate->array_buffer_allocator() != NULL);
47 // Prevent creating array buffers when serializing. 50 // Prevent creating array buffers when serializing.
48 DCHECK(!isolate->serializer_enabled()); 51 DCHECK(!isolate->serializer_enabled());
49 if (allocated_length != 0) { 52 if (allocated_length != 0) {
50 if (initialize) { 53 if (initialize) {
51 data = isolate->array_buffer_allocator()->Allocate(allocated_length); 54 data = allocator->Allocate(allocated_length);
52 } else { 55 } else {
53 data = isolate->array_buffer_allocator()->AllocateUninitialized( 56 data = allocator->AllocateUninitialized(allocated_length);
54 allocated_length);
55 } 57 }
56 if (data == NULL) return false; 58 if (data == NULL) return false;
57 } else { 59 } else {
58 data = NULL; 60 data = NULL;
59 } 61 }
60 62
61 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 63 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
62 return true; 64 return true;
63 } 65 }
64 66
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 133
132 134
133 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { 135 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) {
134 HandleScope scope(isolate); 136 HandleScope scope(isolate);
135 DCHECK(args.length() == 1); 137 DCHECK(args.length() == 1);
136 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); 138 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0);
137 if (array_buffer->backing_store() == NULL) { 139 if (array_buffer->backing_store() == NULL) {
138 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); 140 CHECK(Smi::FromInt(0) == array_buffer->byte_length());
139 return isolate->heap()->undefined_value(); 141 return isolate->heap()->undefined_value();
140 } 142 }
143 // Shared array buffers should never be neutered.
144 DCHECK(!array_buffer->is_shared());
141 DCHECK(!array_buffer->is_external()); 145 DCHECK(!array_buffer->is_external());
142 void* backing_store = array_buffer->backing_store(); 146 void* backing_store = array_buffer->backing_store();
143 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); 147 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length());
144 array_buffer->set_is_external(true); 148 array_buffer->set_is_external(true);
145 Runtime::NeuterArrayBuffer(array_buffer); 149 Runtime::NeuterArrayBuffer(array_buffer);
146 isolate->heap()->UnregisterArrayBuffer(backing_store); 150 isolate->heap()->UnregisterArrayBuffer(backing_store);
147 isolate->array_buffer_allocator()->Free(backing_store, byte_length); 151 isolate->array_buffer_allocator()->Free(backing_store, byte_length);
148 return isolate->heap()->undefined_value(); 152 return isolate->heap()->undefined_value();
149 } 153 }
150 154
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
400 404
401 if (!args[1]->IsJSTypedArray()) 405 if (!args[1]->IsJSTypedArray())
402 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY); 406 return Smi::FromInt(TYPED_ARRAY_SET_NON_TYPED_ARRAY);
403 407
404 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0); 408 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, target_obj, 0);
405 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1); 409 CONVERT_ARG_HANDLE_CHECKED(JSTypedArray, source_obj, 1);
406 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2); 410 CONVERT_NUMBER_ARG_HANDLE_CHECKED(offset_obj, 2);
407 411
408 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj)); 412 Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
409 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj)); 413 Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
414
415 if (target->is_shared() != source->is_shared()) {
416 THROW_NEW_ERROR_RETURN_FAILURE(
417 isolate, NewTypeError(MessageTemplate::kInvalidArgument));
418 }
419
410 size_t offset = 0; 420 size_t offset = 0;
411 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset)); 421 RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset));
412 size_t target_length = NumberToSize(isolate, target->length()); 422 size_t target_length = NumberToSize(isolate, target->length());
413 size_t source_length = NumberToSize(isolate, source->length()); 423 size_t source_length = NumberToSize(isolate, source->length());
414 size_t target_byte_length = NumberToSize(isolate, target->byte_length()); 424 size_t target_byte_length = NumberToSize(isolate, target->byte_length());
415 size_t source_byte_length = NumberToSize(isolate, source->byte_length()); 425 size_t source_byte_length = NumberToSize(isolate, source->byte_length());
416 if (offset > target_length || offset + source_length > target_length || 426 if (offset > target_length || offset + source_length > target_length ||
417 offset + source_length < offset) { // overflow 427 offset + source_length < offset) { // overflow
418 THROW_NEW_ERROR_RETURN_FAILURE( 428 THROW_NEW_ERROR_RETURN_FAILURE(
419 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge)); 429 isolate, NewRangeError(MessageTemplate::kTypedArraySetSourceTooLarge));
(...skipping 293 matching lines...) Expand 10 before | Expand all | Expand 10 after
713 DATA_VIEW_SETTER(Uint16, uint16_t) 723 DATA_VIEW_SETTER(Uint16, uint16_t)
714 DATA_VIEW_SETTER(Int16, int16_t) 724 DATA_VIEW_SETTER(Int16, int16_t)
715 DATA_VIEW_SETTER(Uint32, uint32_t) 725 DATA_VIEW_SETTER(Uint32, uint32_t)
716 DATA_VIEW_SETTER(Int32, int32_t) 726 DATA_VIEW_SETTER(Int32, int32_t)
717 DATA_VIEW_SETTER(Float32, float) 727 DATA_VIEW_SETTER(Float32, float)
718 DATA_VIEW_SETTER(Float64, double) 728 DATA_VIEW_SETTER(Float64, double)
719 729
720 #undef DATA_VIEW_SETTER 730 #undef DATA_VIEW_SETTER
721 } 731 }
722 } // namespace v8::internal 732 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-printer.cc ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698