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

Side by Side Diff: src/runtime/runtime-typedarray.cc

Issue 1149203003: Revert of Implement SharedArrayBuffer (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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/runtime/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 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"
11 11
12 12
13 namespace v8 { 13 namespace v8 {
14 namespace internal { 14 namespace internal {
15 15
16 void Runtime::SetupArrayBuffer(Isolate* isolate, 16 void Runtime::SetupArrayBuffer(Isolate* isolate,
17 Handle<JSArrayBuffer> array_buffer, 17 Handle<JSArrayBuffer> array_buffer,
18 bool is_external, void* data, 18 bool is_external, void* data,
19 size_t allocated_length, SharedFlag shared) { 19 size_t allocated_length) {
20 DCHECK(array_buffer->GetInternalFieldCount() == 20 DCHECK(array_buffer->GetInternalFieldCount() ==
21 v8::ArrayBuffer::kInternalFieldCount); 21 v8::ArrayBuffer::kInternalFieldCount);
22 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) { 22 for (int i = 0; i < v8::ArrayBuffer::kInternalFieldCount; i++) {
23 array_buffer->SetInternalField(i, Smi::FromInt(0)); 23 array_buffer->SetInternalField(i, Smi::FromInt(0));
24 } 24 }
25 array_buffer->set_backing_store(data); 25 array_buffer->set_backing_store(data);
26 array_buffer->set_bit_field(0); 26 array_buffer->set_bit_field(0);
27 array_buffer->set_is_external(is_external); 27 array_buffer->set_is_external(is_external);
28 array_buffer->set_is_neuterable(shared == SharedFlag::kNotShared); 28 array_buffer->set_is_neuterable(true);
29 array_buffer->set_is_shared(shared == SharedFlag::kShared);
30 29
31 Handle<Object> byte_length = 30 Handle<Object> byte_length =
32 isolate->factory()->NewNumberFromSize(allocated_length); 31 isolate->factory()->NewNumberFromSize(allocated_length);
33 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber()); 32 CHECK(byte_length->IsSmi() || byte_length->IsHeapNumber());
34 array_buffer->set_byte_length(*byte_length); 33 array_buffer->set_byte_length(*byte_length);
35 34
36 if (data && !is_external) { 35 if (data && !is_external) {
37 isolate->heap()->RegisterNewArrayBuffer(data, allocated_length); 36 isolate->heap()->RegisterNewArrayBuffer(data, allocated_length);
38 } 37 }
39 } 38 }
40 39
41 40
42 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, 41 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
43 Handle<JSArrayBuffer> array_buffer, 42 Handle<JSArrayBuffer> array_buffer,
44 size_t allocated_length, 43 size_t allocated_length,
45 bool initialize, 44 bool initialize) {
46 SharedFlag shared) {
47 void* data; 45 void* data;
48 CHECK(isolate->array_buffer_allocator() != NULL); 46 CHECK(isolate->array_buffer_allocator() != NULL);
49 // Prevent creating array buffers when serializing. 47 // Prevent creating array buffers when serializing.
50 DCHECK(!isolate->serializer_enabled()); 48 DCHECK(!isolate->serializer_enabled());
51 if (allocated_length != 0) { 49 if (allocated_length != 0) {
52 if (initialize) { 50 if (initialize) {
53 data = isolate->array_buffer_allocator()->Allocate(allocated_length); 51 data = isolate->array_buffer_allocator()->Allocate(allocated_length);
54 } else { 52 } else {
55 data = isolate->array_buffer_allocator()->AllocateUninitialized( 53 data = isolate->array_buffer_allocator()->AllocateUninitialized(
56 allocated_length); 54 allocated_length);
57 } 55 }
58 if (data == NULL) return false; 56 if (data == NULL) return false;
59 } else { 57 } else {
60 data = NULL; 58 data = NULL;
61 } 59 }
62 60
63 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length, 61 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
64 shared);
65 return true; 62 return true;
66 } 63 }
67 64
68 65
69 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) { 66 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) {
70 array_buffer->Neuter(); 67 array_buffer->Neuter();
71 } 68 }
72 69
73 70
74 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { 71 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) {
75 HandleScope scope(isolate); 72 HandleScope scope(isolate);
76 DCHECK(args.length() == 3); 73 DCHECK(args.length() == 2);
77 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); 74 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0);
78 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); 75 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1);
79 CONVERT_BOOLEAN_ARG_CHECKED(is_shared, 2);
80 if (!holder->byte_length()->IsUndefined()) { 76 if (!holder->byte_length()->IsUndefined()) {
81 // ArrayBuffer is already initialized; probably a fuzz test. 77 // ArrayBuffer is already initialized; probably a fuzz test.
82 return *holder; 78 return *holder;
83 } 79 }
84 size_t allocated_length = 0; 80 size_t allocated_length = 0;
85 if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) { 81 if (!TryNumberToSize(isolate, *byteLength, &allocated_length)) {
86 THROW_NEW_ERROR_RETURN_FAILURE( 82 THROW_NEW_ERROR_RETURN_FAILURE(
87 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); 83 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
88 } 84 }
89 if (!Runtime::SetupArrayBufferAllocatingData( 85 if (!Runtime::SetupArrayBufferAllocatingData(isolate, holder,
90 isolate, holder, allocated_length, true, 86 allocated_length)) {
91 is_shared ? SharedFlag::kShared : SharedFlag::kNotShared)) {
92 THROW_NEW_ERROR_RETURN_FAILURE( 87 THROW_NEW_ERROR_RETURN_FAILURE(
93 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength)); 88 isolate, NewRangeError(MessageTemplate::kInvalidArrayBufferLength));
94 } 89 }
95 return *holder; 90 return *holder;
96 } 91 }
97 92
98 93
99 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) { 94 RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) {
100 SealHandleScope shs(isolate); 95 SealHandleScope shs(isolate);
101 DCHECK(args.length() == 1); 96 DCHECK(args.length() == 1);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
136 131
137 132
138 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) { 133 RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) {
139 HandleScope scope(isolate); 134 HandleScope scope(isolate);
140 DCHECK(args.length() == 1); 135 DCHECK(args.length() == 1);
141 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0); 136 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, array_buffer, 0);
142 if (array_buffer->backing_store() == NULL) { 137 if (array_buffer->backing_store() == NULL) {
143 CHECK(Smi::FromInt(0) == array_buffer->byte_length()); 138 CHECK(Smi::FromInt(0) == array_buffer->byte_length());
144 return isolate->heap()->undefined_value(); 139 return isolate->heap()->undefined_value();
145 } 140 }
146 // Shared array buffers should never be neutered.
147 DCHECK(!array_buffer->is_shared());
148 DCHECK(!array_buffer->is_external()); 141 DCHECK(!array_buffer->is_external());
149 void* backing_store = array_buffer->backing_store(); 142 void* backing_store = array_buffer->backing_store();
150 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length()); 143 size_t byte_length = NumberToSize(isolate, array_buffer->byte_length());
151 array_buffer->set_is_external(true); 144 array_buffer->set_is_external(true);
152 Runtime::NeuterArrayBuffer(array_buffer); 145 Runtime::NeuterArrayBuffer(array_buffer);
153 isolate->heap()->UnregisterArrayBuffer(backing_store); 146 isolate->heap()->UnregisterArrayBuffer(backing_store);
154 isolate->array_buffer_allocator()->Free(backing_store, byte_length); 147 isolate->array_buffer_allocator()->Free(backing_store, byte_length);
155 return isolate->heap()->undefined_value(); 148 return isolate->heap()->undefined_value();
156 } 149 }
157 150
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
240 233
241 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( 234 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
242 static_cast<int>(length), array_type, 235 static_cast<int>(length), array_type,
243 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 236 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
244 Handle<Map> map = 237 Handle<Map> map =
245 JSObject::GetElementsTransitionMap(holder, external_elements_kind); 238 JSObject::GetElementsTransitionMap(holder, external_elements_kind);
246 JSObject::SetMapAndElements(holder, map, elements); 239 JSObject::SetMapAndElements(holder, map, elements);
247 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); 240 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind()));
248 } else { 241 } else {
249 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer(); 242 Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
250 Runtime::SetupArrayBuffer(isolate, buffer, true, NULL, byte_length, 243 Runtime::SetupArrayBuffer(isolate, buffer, true, NULL, byte_length);
251 SharedFlag::kNotShared);
252 holder->set_buffer(*buffer); 244 holder->set_buffer(*buffer);
253 Handle<FixedTypedArrayBase> elements = 245 Handle<FixedTypedArrayBase> elements =
254 isolate->factory()->NewFixedTypedArray(static_cast<int>(length), 246 isolate->factory()->NewFixedTypedArray(static_cast<int>(length),
255 array_type); 247 array_type);
256 holder->set_elements(*elements); 248 holder->set_elements(*elements);
257 } 249 }
258 return isolate->heap()->undefined_value(); 250 return isolate->heap()->undefined_value();
259 } 251 }
260 252
261 253
(...skipping 459 matching lines...) Expand 10 before | Expand all | Expand 10 after
721 DATA_VIEW_SETTER(Uint16, uint16_t) 713 DATA_VIEW_SETTER(Uint16, uint16_t)
722 DATA_VIEW_SETTER(Int16, int16_t) 714 DATA_VIEW_SETTER(Int16, int16_t)
723 DATA_VIEW_SETTER(Uint32, uint32_t) 715 DATA_VIEW_SETTER(Uint32, uint32_t)
724 DATA_VIEW_SETTER(Int32, int32_t) 716 DATA_VIEW_SETTER(Int32, int32_t)
725 DATA_VIEW_SETTER(Float32, float) 717 DATA_VIEW_SETTER(Float32, float)
726 DATA_VIEW_SETTER(Float64, double) 718 DATA_VIEW_SETTER(Float64, double)
727 719
728 #undef DATA_VIEW_SETTER 720 #undef DATA_VIEW_SETTER
729 } // namespace internal 721 } // namespace internal
730 } // namespace v8 722 } // namespace v8
OLDNEW
« no previous file with comments | « src/runtime/runtime.h ('k') | src/typedarray.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698