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

Side by Side Diff: src/wasm/wasm-js.cc

Issue 2653183003: [wasm] Memory buffer should be detached after Memory.Grow (Closed)
Patch Set: Created 3 years, 11 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 | « no previous file | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 1 // Copyright 2015 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/api-natives.h" 5 #include "src/api-natives.h"
6 #include "src/api.h" 6 #include "src/api.h"
7 #include "src/asmjs/asm-js.h" 7 #include "src/asmjs/asm-js.h"
8 #include "src/asmjs/asm-typer.h" 8 #include "src/asmjs/asm-typer.h"
9 #include "src/asmjs/asm-wasm-builder.h" 9 #include "src/asmjs/asm-wasm-builder.h"
10 #include "src/assert-scope.h" 10 #include "src/assert-scope.h"
(...skipping 714 matching lines...) Expand 10 before | Expand all | Expand 10 after
725 } 725 }
726 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate); 726 i::Isolate* i_isolate = reinterpret_cast<i::Isolate*>(isolate);
727 int32_t ret = i::wasm::GrowWebAssemblyMemory( 727 int32_t ret = i::wasm::GrowWebAssemblyMemory(
728 i_isolate, receiver, static_cast<uint32_t>(delta_size)); 728 i_isolate, receiver, static_cast<uint32_t>(delta_size));
729 if (ret == -1) { 729 if (ret == -1) {
730 v8::Local<v8::Value> e = v8::Exception::RangeError( 730 v8::Local<v8::Value> e = v8::Exception::RangeError(
731 v8_str(isolate, "Unable to grow instance memory.")); 731 v8_str(isolate, "Unable to grow instance memory."));
732 isolate->ThrowException(e); 732 isolate->ThrowException(e);
733 return; 733 return;
734 } 734 }
735
736 if (delta_size != 0) {
titzer 2017/01/25 09:28:57 There was a discussion about whether a delta_size
gdeepti 2017/01/25 21:05:24 I opened that issue because I was not able to get
737 // Detach the old buffer
738 const bool has_guard_regions =
titzer 2017/01/25 09:28:56 I think it also makes sense to move the detachment
gdeepti 2017/01/25 21:05:24 Done.
739 (!old_buffer.is_null() && old_buffer->has_guard_region()) ? true
740 : false;
Eric Holk 2017/01/25 18:16:57 nit: Is the ? operator needed here? `(!old_buffer.
gdeepti 2017/01/25 18:59:19 Done.
741 DCHECK(!old_buffer->is_neuterable());
742 void* backing_store = old_buffer->backing_store();
Eric Holk 2017/01/25 18:16:57 It might not hurt to add `DCHECK(backing_store !=
gdeepti 2017/01/25 18:59:19 Done.
743 int64_t byte_length = NumberToSize(old_buffer->byte_length());
744 old_buffer->set_is_neuterable(true);
745 if (!has_guard_regions) {
746 old_buffer->set_is_external(true);
747 i_isolate->heap()->UnregisterArrayBuffer(*old_buffer);
748 }
749 old_buffer->Neuter();
750 if (!has_guard_regions) {
751 i_isolate->array_buffer_allocator()->Free(backing_store, byte_length);
752 } else {
753 base::OS::Free(backing_store, RoundUp(i::wasm::kWasmMaxHeapOffset,
754 base::OS::CommitPageSize()));
755 isolate->AdjustAmountOfExternalAllocatedMemory(-byte_length);
756 }
757 }
758
735 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue(); 759 v8::ReturnValue<v8::Value> return_value = args.GetReturnValue();
736 return_value.Set(ret); 760 return_value.Set(ret);
737 } 761 }
738 762
739 void WebAssemblyMemoryGetBuffer( 763 void WebAssemblyMemoryGetBuffer(
740 const v8::FunctionCallbackInfo<v8::Value>& args) { 764 const v8::FunctionCallbackInfo<v8::Value>& args) {
741 v8::Isolate* isolate = args.GetIsolate(); 765 v8::Isolate* isolate = args.GetIsolate();
742 Local<Context> context = isolate->GetCurrentContext(); 766 Local<Context> context = isolate->GetCurrentContext();
743 i::Handle<i::Context> i_context = Utils::OpenHandle(*context); 767 i::Handle<i::Context> i_context = Utils::OpenHandle(*context);
744 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()), 768 if (!BrandCheck(isolate, Utils::OpenHandle(*args.This()),
(...skipping 220 matching lines...) Expand 10 before | Expand all | Expand 10 after
965 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate); 989 i::Handle<i::Symbol> symbol(isolate->context()->wasm_memory_sym(), isolate);
966 return HasBrand(value, symbol); 990 return HasBrand(value, symbol);
967 } 991 }
968 992
969 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) { 993 bool WasmJs::IsWasmTableObject(Isolate* isolate, Handle<Object> value) {
970 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate); 994 i::Handle<i::Symbol> symbol(isolate->context()->wasm_table_sym(), isolate);
971 return HasBrand(value, symbol); 995 return HasBrand(value, symbol);
972 } 996 }
973 } // namespace internal 997 } // namespace internal
974 } // namespace v8 998 } // namespace v8
OLDNEW
« no previous file with comments | « no previous file | src/wasm/wasm-module.cc » ('j') | src/wasm/wasm-module.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698