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

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

Issue 1061753008: Revert of Remove the weak list of views from array buffers (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: 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());
66 } 67 }
67 68
68 69
69 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate, 70 bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
70 Handle<JSArrayBuffer> array_buffer, 71 Handle<JSArrayBuffer> array_buffer,
71 size_t allocated_length, 72 size_t allocated_length,
72 bool initialize) { 73 bool initialize) {
73 void* data; 74 void* data;
74 CHECK(V8::ArrayBufferAllocator() != NULL); 75 CHECK(V8::ArrayBufferAllocator() != NULL);
75 // Prevent creating array buffers when serializing. 76 // Prevent creating array buffers when serializing.
(...skipping 13 matching lines...) Expand all
89 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length); 90 SetupArrayBuffer(isolate, array_buffer, false, data, allocated_length);
90 91
91 reinterpret_cast<v8::Isolate*>(isolate) 92 reinterpret_cast<v8::Isolate*>(isolate)
92 ->AdjustAmountOfExternalAllocatedMemory(allocated_length); 93 ->AdjustAmountOfExternalAllocatedMemory(allocated_length);
93 94
94 return true; 95 return true;
95 } 96 }
96 97
97 98
98 void Runtime::NeuterArrayBuffer(Handle<JSArrayBuffer> array_buffer) { 99 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 }
99 array_buffer->Neuter(); 133 array_buffer->Neuter();
100 } 134 }
101 135
102 136
103 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) { 137 RUNTIME_FUNCTION(Runtime_ArrayBufferInitialize) {
104 HandleScope scope(isolate); 138 HandleScope scope(isolate);
105 DCHECK(args.length() == 2); 139 DCHECK(args.length() == 2);
106 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0); 140 CONVERT_ARG_HANDLE_CHECKED(JSArrayBuffer, holder, 0);
107 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1); 141 CONVERT_NUMBER_ARG_HANDLE_CHECKED(byteLength, 1);
108 if (!holder->byte_length()->IsUndefined()) { 142 if (!holder->byte_length()->IsUndefined()) {
(...skipping 145 matching lines...) Expand 10 before | Expand all | Expand 10 after
254 DCHECK(holder->GetInternalFieldCount() == 288 DCHECK(holder->GetInternalFieldCount() ==
255 v8::ArrayBufferView::kInternalFieldCount); 289 v8::ArrayBufferView::kInternalFieldCount);
256 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) { 290 for (int i = 0; i < v8::ArrayBufferView::kInternalFieldCount; i++) {
257 holder->SetInternalField(i, Smi::FromInt(0)); 291 holder->SetInternalField(i, Smi::FromInt(0));
258 } 292 }
259 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length); 293 Handle<Object> length_obj = isolate->factory()->NewNumberFromSize(length);
260 holder->set_length(*length_obj); 294 holder->set_length(*length_obj);
261 holder->set_byte_offset(*byte_offset_object); 295 holder->set_byte_offset(*byte_offset_object);
262 holder->set_byte_length(*byte_length_object); 296 holder->set_byte_length(*byte_length_object);
263 297
298 Heap* heap = isolate->heap();
264 if (!maybe_buffer->IsNull()) { 299 if (!maybe_buffer->IsNull()) {
265 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer); 300 Handle<JSArrayBuffer> buffer = Handle<JSArrayBuffer>::cast(maybe_buffer);
266 holder->set_buffer(*buffer); 301 holder->set_buffer(*buffer);
267 302
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
268 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( 311 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
269 static_cast<int>(length), array_type, 312 static_cast<int>(length), array_type,
270 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset); 313 static_cast<uint8_t*>(buffer->backing_store()) + byte_offset);
271 Handle<Map> map = 314 Handle<Map> map =
272 JSObject::GetElementsTransitionMap(holder, external_elements_kind); 315 JSObject::GetElementsTransitionMap(holder, external_elements_kind);
273 JSObject::SetMapAndElements(holder, map, elements); 316 JSObject::SetMapAndElements(holder, map, elements);
274 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind())); 317 DCHECK(IsExternalArrayElementsKind(holder->map()->elements_kind()));
275 } else { 318 } else {
276 holder->set_buffer(Smi::FromInt(0)); 319 holder->set_buffer(Smi::FromInt(0));
320 holder->set_weak_next(isolate->heap()->undefined_value());
277 Handle<FixedTypedArrayBase> elements = 321 Handle<FixedTypedArrayBase> elements =
278 isolate->factory()->NewFixedTypedArray(static_cast<int>(length), 322 isolate->factory()->NewFixedTypedArray(static_cast<int>(length),
279 array_type); 323 array_type);
280 holder->set_elements(*elements); 324 holder->set_elements(*elements);
281 } 325 }
282 return isolate->heap()->undefined_value(); 326 return isolate->heap()->undefined_value();
283 } 327 }
284 328
285 329
286 // Initializes a typed array from an array-like object. 330 // Initializes a typed array from an array-like object.
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 HandleVector<Object>(NULL, 0))); 398 HandleVector<Object>(NULL, 0)));
355 } 399 }
356 400
357 holder->set_buffer(*buffer); 401 holder->set_buffer(*buffer);
358 holder->set_byte_offset(Smi::FromInt(0)); 402 holder->set_byte_offset(Smi::FromInt(0));
359 Handle<Object> byte_length_obj( 403 Handle<Object> byte_length_obj(
360 isolate->factory()->NewNumberFromSize(byte_length)); 404 isolate->factory()->NewNumberFromSize(byte_length));
361 holder->set_byte_length(*byte_length_obj); 405 holder->set_byte_length(*byte_length_obj);
362 holder->set_length(*length_obj); 406 holder->set_length(*length_obj);
363 407
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
364 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray( 417 Handle<ExternalArray> elements = isolate->factory()->NewExternalArray(
365 static_cast<int>(length), array_type, 418 static_cast<int>(length), array_type,
366 static_cast<uint8_t*>(buffer->backing_store())); 419 static_cast<uint8_t*>(buffer->backing_store()));
367 Handle<Map> map = 420 Handle<Map> map =
368 JSObject::GetElementsTransitionMap(holder, external_elements_kind); 421 JSObject::GetElementsTransitionMap(holder, external_elements_kind);
369 JSObject::SetMapAndElements(holder, map, elements); 422 JSObject::SetMapAndElements(holder, map, elements);
370 423
371 if (source->IsJSTypedArray()) { 424 if (source->IsJSTypedArray()) {
372 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source)); 425 Handle<JSTypedArray> typed_array(JSTypedArray::cast(*source));
373 426
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
526 // Entire range [offset, offset + length] must be in bounds. 579 // Entire range [offset, offset + length] must be in bounds.
527 RUNTIME_ASSERT(offset <= buffer_length); 580 RUNTIME_ASSERT(offset <= buffer_length);
528 RUNTIME_ASSERT(offset + length <= buffer_length); 581 RUNTIME_ASSERT(offset + length <= buffer_length);
529 // No overflow. 582 // No overflow.
530 RUNTIME_ASSERT(offset + length >= offset); 583 RUNTIME_ASSERT(offset + length >= offset);
531 584
532 holder->set_buffer(*buffer); 585 holder->set_buffer(*buffer);
533 holder->set_byte_offset(*byte_offset); 586 holder->set_byte_offset(*byte_offset);
534 holder->set_byte_length(*byte_length); 587 holder->set_byte_length(*byte_length);
535 588
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
536 return isolate->heap()->undefined_value(); 598 return isolate->heap()->undefined_value();
537 } 599 }
538 600
539 601
540 inline static bool NeedToFlipBytes(bool is_little_endian) { 602 inline static bool NeedToFlipBytes(bool is_little_endian) {
541 #ifdef V8_TARGET_LITTLE_ENDIAN 603 #ifdef V8_TARGET_LITTLE_ENDIAN
542 return !is_little_endian; 604 return !is_little_endian;
543 #else 605 #else
544 return is_little_endian; 606 return is_little_endian;
545 #endif 607 #endif
(...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 DATA_VIEW_SETTER(Uint16, uint16_t) 811 DATA_VIEW_SETTER(Uint16, uint16_t)
750 DATA_VIEW_SETTER(Int16, int16_t) 812 DATA_VIEW_SETTER(Int16, int16_t)
751 DATA_VIEW_SETTER(Uint32, uint32_t) 813 DATA_VIEW_SETTER(Uint32, uint32_t)
752 DATA_VIEW_SETTER(Int32, int32_t) 814 DATA_VIEW_SETTER(Int32, int32_t)
753 DATA_VIEW_SETTER(Float32, float) 815 DATA_VIEW_SETTER(Float32, float)
754 DATA_VIEW_SETTER(Float64, double) 816 DATA_VIEW_SETTER(Float64, double)
755 817
756 #undef DATA_VIEW_SETTER 818 #undef DATA_VIEW_SETTER
757 } 819 }
758 } // namespace v8::internal 820 } // 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