aboutsummaryrefslogtreecommitdiff
path: root/src/runtime/runtime-wasm.cc
diff options
context:
space:
mode:
authorBen Murdoch <benm@google.com>2017-01-17 12:11:28 +0000
committerBen Murdoch <benm@google.com>2017-01-18 14:32:11 +0000
commitf3b273f5e6ffd2f6ba1c18a27a17db41dfb113c3 (patch)
treee748f964837dfc9e4b961000ddacb2965c629d9f /src/runtime/runtime-wasm.cc
parenta7e90cde16bf95fddae4a5156268e449da86ee36 (diff)
downloadv8-f3b273f5e6ffd2f6ba1c18a27a17db41dfb113c3.tar.gz
Merge V8 5.5.372.32
Test: Manual, built and ran D8 Change-Id: I831a5491f74342c2675bb6fe1e24a2258e493758
Diffstat (limited to 'src/runtime/runtime-wasm.cc')
-rw-r--r--src/runtime/runtime-wasm.cc125
1 files changed, 49 insertions, 76 deletions
diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc
index 37608e61..ab69046c 100644
--- a/src/runtime/runtime-wasm.cc
+++ b/src/runtime/runtime-wasm.cc
@@ -18,17 +18,32 @@
namespace v8 {
namespace internal {
-namespace {
-const int kWasmMemArrayBuffer = 2;
+RUNTIME_FUNCTION(Runtime_WasmMemorySize) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(0, args.length());
+
+ Handle<JSObject> module_instance;
+ {
+ // Get the module JSObject
+ DisallowHeapAllocation no_allocation;
+ const Address entry = Isolate::c_entry_fp(isolate->thread_local_top());
+ Address pc =
+ Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset);
+ Code* code =
+ isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
+ Object* owning_instance = wasm::GetOwningWasmInstance(code);
+ CHECK_NOT_NULL(owning_instance);
+ module_instance = handle(JSObject::cast(owning_instance), isolate);
+ }
+ return *isolate->factory()->NewNumberFromInt(
+ wasm::GetInstanceMemorySize(isolate, module_instance));
}
RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
HandleScope scope(isolate);
DCHECK_EQ(1, args.length());
- uint32_t delta_pages = 0;
- CHECK(args[0]->ToUint32(&delta_pages));
- Handle<JSObject> module_object;
-
+ CONVERT_UINT32_ARG_CHECKED(delta_pages, 0);
+ Handle<JSObject> module_instance;
{
// Get the module JSObject
DisallowHeapAllocation no_allocation;
@@ -37,77 +52,12 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset);
Code* code =
isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
- FixedArray* deopt_data = code->deoptimization_data();
- DCHECK(deopt_data->length() == 2);
- module_object = Handle<JSObject>::cast(handle(deopt_data->get(0), isolate));
- CHECK(!module_object->IsNull(isolate));
- }
-
- Address old_mem_start, new_mem_start;
- uint32_t old_size, new_size;
-
- // Get mem buffer associated with module object
- Handle<Object> obj(module_object->GetInternalField(kWasmMemArrayBuffer),
- isolate);
-
- if (obj->IsUndefined(isolate)) {
- // If module object does not have linear memory associated with it,
- // Allocate new array buffer of given size.
- old_mem_start = nullptr;
- old_size = 0;
- // TODO(gdeepti): Fix bounds check to take into account size of memtype.
- new_size = delta_pages * wasm::WasmModule::kPageSize;
- if (delta_pages > wasm::WasmModule::kMaxMemPages) {
- return *isolate->factory()->NewNumberFromInt(-1);
- }
- new_mem_start =
- static_cast<Address>(isolate->array_buffer_allocator()->Allocate(
- static_cast<uint32_t>(new_size)));
- if (new_mem_start == NULL) {
- return *isolate->factory()->NewNumberFromInt(-1);
- }
-#if DEBUG
- // Double check the API allocator actually zero-initialized the memory.
- for (size_t i = old_size; i < new_size; i++) {
- DCHECK_EQ(0, new_mem_start[i]);
- }
-#endif
- } else {
- Handle<JSArrayBuffer> old_buffer = Handle<JSArrayBuffer>::cast(obj);
- old_mem_start = static_cast<Address>(old_buffer->backing_store());
- old_size = old_buffer->byte_length()->Number();
- // If the old memory was zero-sized, we should have been in the
- // "undefined" case above.
- DCHECK_NOT_NULL(old_mem_start);
- DCHECK_NE(0, old_size);
-
- new_size = old_size + delta_pages * wasm::WasmModule::kPageSize;
- if (new_size >
- wasm::WasmModule::kMaxMemPages * wasm::WasmModule::kPageSize) {
- return *isolate->factory()->NewNumberFromInt(-1);
- }
- new_mem_start = static_cast<Address>(realloc(old_mem_start, new_size));
- if (new_mem_start == NULL) {
- return *isolate->factory()->NewNumberFromInt(-1);
- }
- old_buffer->set_is_external(true);
- isolate->heap()->UnregisterArrayBuffer(*old_buffer);
- // Zero initializing uninitialized memory from realloc
- memset(new_mem_start + old_size, 0, new_size - old_size);
+ Object* owning_instance = wasm::GetOwningWasmInstance(code);
+ CHECK_NOT_NULL(owning_instance);
+ module_instance = handle(JSObject::cast(owning_instance), isolate);
}
-
- Handle<JSArrayBuffer> buffer = isolate->factory()->NewJSArrayBuffer();
- JSArrayBuffer::Setup(buffer, isolate, false, new_mem_start, new_size);
- buffer->set_is_neuterable(false);
-
- // Set new buffer to be wasm memory
- module_object->SetInternalField(kWasmMemArrayBuffer, *buffer);
-
- CHECK(wasm::UpdateWasmModuleMemory(module_object, old_mem_start,
- new_mem_start, old_size, new_size));
-
- return *isolate->factory()->NewNumberFromInt(old_size /
- wasm::WasmModule::kPageSize);
+ return *isolate->factory()->NewNumberFromInt(
+ wasm::GrowInstanceMemory(isolate, module_instance, delta_pages));
}
RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
@@ -116,5 +66,28 @@ RUNTIME_FUNCTION(Runtime_WasmThrowTypeError) {
THROW_NEW_ERROR_RETURN_FAILURE(
isolate, NewTypeError(MessageTemplate::kWasmTrapTypeError));
}
+
+RUNTIME_FUNCTION(Runtime_WasmThrow) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(2, args.length());
+ CONVERT_SMI_ARG_CHECKED(lower, 0);
+ CONVERT_SMI_ARG_CHECKED(upper, 1);
+
+ const int32_t thrown_value = (upper << 16) | lower;
+
+ return isolate->Throw(*isolate->factory()->NewNumberFromInt(thrown_value));
+}
+
+RUNTIME_FUNCTION(Runtime_WasmGetCaughtExceptionValue) {
+ HandleScope scope(isolate);
+ DCHECK_EQ(1, args.length());
+ Object* exception = args[0];
+ // The unwinder will only deliver exceptions to wasm if the exception is a
+ // Number or a Smi (which we have just converted to a Number.) This logic
+ // lives in Isolate::is_catchable_by_wasm(Object*).
+ CHECK(exception->IsNumber());
+ return exception;
+}
+
} // namespace internal
} // namespace v8