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

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

Issue 1107843002: Reland "Remove the weak list of views from array buffers" (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: use bounds check Created 5 years, 8 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-inl.h ('k') | src/snapshot/serialize.cc » ('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/runtime/runtime.h" 8 #include "src/runtime/runtime.h"
9 #include "src/runtime/runtime-utils.h" 9 #include "src/runtime/runtime-utils.h"
10 10
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 array_buffer->set_weak_next(isolate->heap()->array_buffers_list()); 56 array_buffer->set_weak_next(isolate->heap()->array_buffers_list());
57 isolate->heap()->set_array_buffers_list(*array_buffer); 57 isolate->heap()->set_array_buffers_list(*array_buffer);
58 if (isolate->heap()->last_array_buffer_in_list()->IsUndefined()) { 58 if (isolate->heap()->last_array_buffer_in_list()->IsUndefined()) {
59 isolate->heap()->set_last_array_buffer_in_list(*array_buffer); 59 isolate->heap()->set_last_array_buffer_in_list(*array_buffer);
60 } 60 }
61 } else { 61 } else {
62 JSArrayBuffer::cast(isolate->heap()->last_array_buffer_in_list()) 62 JSArrayBuffer::cast(isolate->heap()->last_array_buffer_in_list())
63 ->set_weak_next(*array_buffer); 63 ->set_weak_next(*array_buffer);
64 isolate->heap()->set_last_array_buffer_in_list(*array_buffer); 64 isolate->heap()->set_last_array_buffer_in_list(*array_buffer);
65 } 65 }
66 array_buffer->set_weak_first_view(isolate->heap()->undefined_value());
67 } 66 }
68 67
69 68
70 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, 69 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
71 Handle<JSArrayBuffer> array_buffer, 70 Handle<JSArrayBuffer> array_buffer,
72 size_t allocated_length, 71 size_t allocated_length,
73 bool initialize) { 72 bool initialize) {
74 void* data; 73 void* data;
75 CHECK(V8::ArrayBufferAllocator() != NULL); 74 CHECK(V8::ArrayBufferAllocator() != NULL);
76 // Prevent creating array buffers when serializing. 75 // Prevent creating array buffers when serializing.
(...skipping 13 matching lines...) Expand all
90 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 89 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
91 90
92 reinterpret_cast<v8::Isolate*>(isolate) 91 reinterpret_cast<v8::Isolate*>(isolate)
93 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); 92 ->AdjustAmountOfExternalAllocatedMemory(allocated_length);
94 93
95 return true; 94 return true;
96 } 95 }
97 96
98 97
99 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) { 98 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) {
100 Isolate* isolate = array_buffer->GetIsolate();
101 // Firstly, iterate over the views which are referenced directly by the array
102 // buffer.
103 for (Handle<Object> view_obj(array_buffer->weak_first_view(), isolate);
104 !view_obj->IsUndefined();) {
105 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj));
106 if (view->IsJSTypedArray()) {
107 JSTypedArray::cast(*view)->Neuter();
108 } else if (view->IsJSDataView()) {
109 JSDataView::cast(*view)->Neuter();
110 } else {
111 UNREACHABLE();
112 }
113 view_obj = handle(view->weak_next(), isolate);
114 }
115
116 // Secondly, iterate over the global list of new space views to find views
117 // that belong to the neutered array buffer.
118 Heap* heap = isolate->heap();
119 for (Handle<Object> view_obj(heap->new_array_buffer_views_list(), isolate);
120 !view_obj->IsUndefined();) {
121 Handle<JSArrayBufferView> view(JSArrayBufferView::cast(*view_obj));
122 if (view->buffer() == *array_buffer) {
123 if (view->IsJSTypedArray()) {
124 JSTypedArray::cast(*view)->Neuter();
125 } else if (view->IsJSDataView()) {
126 JSDataView::cast(*view)->Neuter();
127 } else {
128 UNREACHABLE();
129 }
130 }
131 view_obj = handle(view->weak_next(), isolate);
132 }
133 array_buffer->Neuter(); 99 array_buffer->Neuter();
134 } 100 }
135 101
136 102
137 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { 103 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) {
138 HandleScope scope(isolate); 104 HandleScope scope(isolate);
139 DCHECK(args.length() == 2); 105 DCHECK(args.length() == 2);
140 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); 106 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0);
141 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); 107 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1);
142 if (!holder->byte_length()->IsUndefined()) { 108 if (!holder->byte_length()->IsUndefined()) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
288 DCHECK(holder->GetInternalFieldCount() == 254 DCHECK(holder->GetInternalFieldCount() ==
289 v8::ArrayBufferView::kInternalFieldCount); 255 v8::ArrayBufferView::kInternalFieldCount);
290 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 256 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
291 holder->SetInternalField(i, Smi::FromInt(0)); 257 holder->SetInternalField(i, Smi::FromInt(0));
292 } 258 }
293 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 259 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
294 holder->set_length(*length_obj); 260 holder->set_length(*length_obj);
295 holder->set_byte_offset(*byte_offset_object); 261 holder->set_byte_offset(*byte_offset_object);
296 holder->set_byte_length(*byte_length_object); 262 holder->set_byte_length(*byte_length_object);
297 263
298 Heap* heap = isolate->heap();
299 if (!maybe_buffer->IsNull()) { 264 if (!maybe_buffer->IsNull()) {
300 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); 265 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer);
301 holder->set_buffer(*buffer); 266 holder->set_buffer(*buffer);
302 267
303 if (heap->InNewSpace(*holder)) {
304 holder->set_weak_next(heap->new_array_buffer_views_list());
305 heap->set_new_array_buffer_views_list(*holder);
306 } else {
307 holder->set_weak_next(buffer->weak_first_view());
308 buffer->set_weak_first_view(*holder);
309 }
310
311 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( 268 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
312 static_cast<int>(length), array_type, 269 static_cast<int>(length), array_type,
313 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 270 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
314 Handle<Map> map = 271 Handle<Map> map =
315 JSObject::GetElementsTransitionMap(holder, external_elements_kind); 272 JSObject::GetElementsTransitionMap(holder, external_elements_kind);
316 JSObject::SetMapAndElements(holder, map, elements); 273 JSObject::SetMapAndElements(holder, map, elements);
317 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); 274 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind()));
318 } else { 275 } else {
319 holder->set_buffer(Smi::FromInt(0)); 276 holder->set_buffer(Smi::FromInt(0));
320 holder->set_weak_next(isolate->heap()->undefined_value());
321 Handle<FixedTypedArrayBase> elements = 277 Handle<FixedTypedArrayBase> elements =
322 isolate->factory()->NewFixedTypedArray(static_cast<int>(length), 278 isolate->factory()->NewFixedTypedArray(static_cast<int>(length),
323 array_type); 279 array_type);
324 holder->set_elements(*elements); 280 holder->set_elements(*elements);
325 } 281 }
326 return isolate->heap()->undefined_value(); 282 return isolate->heap()->undefined_value();
327 } 283 }
328 284
329 285
330 // Initializes a typed array from an array-like object. 286 // Initializes a typed array from an array-like object.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
398 HandleVector<Object>(NULL, 0))); 354 HandleVector<Object>(NULL, 0)));
399 } 355 }
400 356
401 holder->set_buffer(*buffer); 357 holder->set_buffer(*buffer);
402 holder->set_byte_offset(Smi::FromInt(0)); 358 holder->set_byte_offset(Smi::FromInt(0));
403 Handle<Object> byte_length_obj( 359 Handle<Object> byte_length_obj(
404 isolate->factory()->NewNumberFromSize(byte_length)); 360 isolate->factory()->NewNumberFromSize(byte_length));
405 holder->set_byte_length(*byte_length_obj); 361 holder->set_byte_length(*byte_length_obj);
406 holder->set_length(*length_obj); 362 holder->set_length(*length_obj);
407 363
408 Heap* heap = isolate->heap();
409 if (heap->InNewSpace(*holder)) {
410 holder->set_weak_next(heap->new_array_buffer_views_list());
411 heap->set_new_array_buffer_views_list(*holder);
412 } else {
413 holder->set_weak_next(buffer->weak_first_view());
414 buffer->set_weak_first_view(*holder);
415 }
416
417 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( 364 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
418 static_cast<int>(length), array_type, 365 static_cast<int>(length), array_type,
419 static_cast<uint8_t*>(buffer->backing_store())); 366 static_cast<uint8_t*>(buffer->backing_store()));
420 Handle<Map> map = 367 Handle<Map> map =
421 JSObject::GetElementsTransitionMap(holder, external_elements_kind); 368 JSObject::GetElementsTransitionMap(holder, external_elements_kind);
422 JSObject::SetMapAndElements(holder, map, elements); 369 JSObject::SetMapAndElements(holder, map, elements);
423 370
424 if (source->IsJSTypedArray()) { 371 if (source->IsJSTypedArray()) {
425 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); 372 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source));
426 373
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
579 // Entire range [offset, offset + length] must be in bounds. 526 // Entire range [offset, offset + length] must be in bounds.
580 RUNTIME_ASSERT(offset <= buffer_length); 527 RUNTIME_ASSERT(offset <= buffer_length);
581 RUNTIME_ASSERT(offset + length <= buffer_length); 528 RUNTIME_ASSERT(offset + length <= buffer_length);
582 // No overflow. 529 // No overflow.
583 RUNTIME_ASSERT(offset + length >= offset); 530 RUNTIME_ASSERT(offset + length >= offset);
584 531
585 holder->set_buffer(*buffer); 532 holder->set_buffer(*buffer);
586 holder->set_byte_offset(*byte_offset); 533 holder->set_byte_offset(*byte_offset);
587 holder->set_byte_length(*byte_length); 534 holder->set_byte_length(*byte_length);
588 535
589 Heap* heap = isolate->heap();
590 if (heap->InNewSpace(*holder)) {
591 holder->set_weak_next(heap->new_array_buffer_views_list());
592 heap->set_new_array_buffer_views_list(*holder);
593 } else {
594 holder->set_weak_next(buffer->weak_first_view());
595 buffer->set_weak_first_view(*holder);
596 }
597
598 return isolate->heap()->undefined_value(); 536 return isolate->heap()->undefined_value();
599 } 537 }
600 538
601 539
602 inline static bool NeedToFlipBytes(bool is_little_endian) { 540 inline static bool NeedToFlipBytes(bool is_little_endian) {
603 #ifdef V8_TARGET_LITTLE_ENDIAN 541 #ifdef V8_TARGET_LITTLE_ENDIAN
604 return !is_little_endian; 542 return !is_little_endian;
605 #else 543 #else
606 return is_little_endian; 544 return is_little_endian;
607 #endif 545 #endif
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
811 DATA_VIEW_SETTER(Uint16, uint16_t) 749 DATA_VIEW_SETTER(Uint16, uint16_t)
812 DATA_VIEW_SETTER(Int16, int16_t) 750 DATA_VIEW_SETTER(Int16, int16_t)
813 DATA_VIEW_SETTER(Uint32, uint32_t) 751 DATA_VIEW_SETTER(Uint32, uint32_t)
814 DATA_VIEW_SETTER(Int32, int32_t) 752 DATA_VIEW_SETTER(Int32, int32_t)
815 DATA_VIEW_SETTER(Float32, float) 753 DATA_VIEW_SETTER(Float32, float)
816 DATA_VIEW_SETTER(Float64, double) 754 DATA_VIEW_SETTER(Float64, double)
817 755
818 #undef DATA_VIEW_SETTER 756 #undef DATA_VIEW_SETTER
819 } 757 }
820 } // namespace v8::internal 758 } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/objects-inl.h ('k') | src/snapshot/serialize.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698