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

Unified Diff: src/runtime/runtime-typedarray.cc

Issue 1069883002: WIP SharedArrayBuffer implementation (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: update MakeTypeError calls 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 side-by-side diff with in-line comments
Download patch
Index: src/runtime/runtime-typedarray.cc
diff --git a/src/runtime/runtime-typedarray.cc b/src/runtime/runtime-typedarray.cc
index 02b5579bf82715a362a40c87f55d43af6f42e726..bbc0a9629dad2d57cbc3c67d35f46854a72264cc 100644
--- a/src/runtime/runtime-typedarray.cc
+++ b/src/runtime/runtime-typedarray.cc
@@ -26,9 +26,15 @@ void Runtime::FreeArrayBuffer(Isolate* isolate,
reinterpret_cast<v8::Isolate*>(isolate)
->AdjustAmountOfExternalAllocatedMemory(
-static_cast<int64_t>(allocated_length));
- CHECK(V8::ArrayBufferAllocator() != NULL);
- V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store(),
- allocated_length);
+ if (phantom_array_buffer->is_shared()) {
+ CHECK(V8::SharedArrayBufferAllocator() != NULL);
+ V8::SharedArrayBufferAllocator()->Free(
+ phantom_array_buffer->backing_store(), allocated_length);
+ } else {
+ CHECK(V8::ArrayBufferAllocator() != NULL);
+ V8::ArrayBufferAllocator()->Free(phantom_array_buffer->backing_store(),
+ allocated_length);
+ }
}
@@ -70,16 +76,27 @@ bool Runtime::SetupArrayBufferAllocatingData(Isolate* isolate,
Handle<JSArrayBuffer> array_buffer,
size_t allocated_length,
bool initialize) {
+ bool is_shared = array_buffer->is_shared();
Jarin 2015/04/29 04:46:01 This should be array_buffer->is_shared() == SHARED
binji 2015/04/29 18:27:22 Done.
void* data;
- CHECK(V8::ArrayBufferAllocator() != NULL);
+ CHECK(is_shared ? V8::SharedArrayBufferAllocator() != NULL
+ : V8::ArrayBufferAllocator() != NULL);
// Prevent creating array buffers when serializing.
DCHECK(!isolate->serializer_enabled());
if (allocated_length != 0) {
- if (initialize) {
- data = V8::ArrayBufferAllocator()->Allocate(allocated_length);
+ if (is_shared) {
+ if (initialize) {
+ data = V8::SharedArrayBufferAllocator()->Allocate(allocated_length);
+ } else {
+ data = V8::SharedArrayBufferAllocator()->AllocateUninitialized(
+ allocated_length);
+ }
} else {
- data =
- V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length);
+ if (initialize) {
+ data = V8::ArrayBufferAllocator()->Allocate(allocated_length);
+ } else {
+ data =
+ V8::ArrayBufferAllocator()->AllocateUninitialized(allocated_length);
+ }
}
if (data == NULL) return false;
} else {
@@ -133,6 +150,14 @@ RUNTIME_FUNCTION(Runtime_ArrayBufferGetByteLength) {
}
+RUNTIME_FUNCTION(Runtime_ArrayBufferIsShared) {
+ SealHandleScope shs(isolate);
+ DCHECK(args.length() == 1);
+ CONVERT_ARG_CHECKED(JSArrayBuffer, holder, 0);
+ return isolate->heap()->ToBoolean(holder->is_shared());
+}
+
+
RUNTIME_FUNCTION(Runtime_ArrayBufferSliceImpl) {
HandleScope scope(isolate);
DCHECK(args.length() == 3);
@@ -172,6 +197,8 @@ RUNTIME_FUNCTION(Runtime_ArrayBufferNeuter) {
CHECK(Smi::FromInt(0) == array_buffer->byte_length());
return isolate->heap()->undefined_value();
}
+ // Shared array buffers should never be neutered.
+ DCHECK(!array_buffer->is_shared());
jochen (gone - plz use gerrit) 2015/04/28 18:31:46 why? What about ArrayBuffer.transfer?
Jarin 2015/04/29 04:46:01 The whole idea of SharedArrayBuffer is that it can
binji 2015/04/29 18:27:22 I asked about this on the spec doc, but I think it
DCHECK(!array_buffer->is_external());
void* backing_store = array_buffer->backing_store();
size_t byte_length = NumberToSize(isolate, array_buffer->byte_length());
@@ -442,6 +469,13 @@ RUNTIME_FUNCTION(Runtime_TypedArraySetFastCases) {
Handle<JSTypedArray> target(JSTypedArray::cast(*target_obj));
Handle<JSTypedArray> source(JSTypedArray::cast(*source_obj));
+
+ if (target->is_shared() != source->is_shared()) {
+ THROW_NEW_ERROR_RETURN_FAILURE(
+ isolate,
+ NewTypeError("invalid_argument", HandleVector<Object>(NULL, 0)));
+ }
+
size_t offset = 0;
RUNTIME_ASSERT(TryNumberToSize(isolate, *offset_obj, &offset));
size_t target_length = NumberToSize(isolate, target->length());

Powered by Google App Engine
This is Rietveld 408576698