From fb43021511676963898c3d166d2d921632deb5d0 Mon Sep 17 00:00:00 2001 From: clemensh Date: Tue, 20 Dec 2016 03:49:20 -0800 Subject: [PATCH] [wasm] Cleanup unneeded casts to WasmInstanceObject Plus another minor refactoring. R=titzer@chromium.org Review-Url: https://codereview.chromium.org/2590563002 Cr-Commit-Position: refs/heads/master@{#41853} --- src/frames.cc | 8 +++---- src/runtime/runtime-wasm.cc | 42 ++++++++++++++----------------------- src/wasm/wasm-module.cc | 2 +- 3 files changed, 21 insertions(+), 31 deletions(-) diff --git a/src/frames.cc b/src/frames.cc index eb06ac23b6..c2c33fad1d 100644 --- a/src/frames.cc +++ b/src/frames.cc @@ -1559,10 +1559,10 @@ Address WasmFrame::GetCallerStackPointer() const { } WasmInstanceObject* WasmFrame::wasm_instance() const { - Object* ret = wasm::GetOwningWasmInstance(LookupCode()); - // This is a live stack frame, there must be a live wasm instance available. - DCHECK_NOT_NULL(ret); - return WasmInstanceObject::cast(ret); + WasmInstanceObject* obj = wasm::GetOwningWasmInstance(LookupCode()); + // This is a live stack frame; it must have a live instance. + DCHECK_NOT_NULL(obj); + return obj; } uint32_t WasmFrame::function_index() const { diff --git a/src/runtime/runtime-wasm.cc b/src/runtime/runtime-wasm.cc index 950c2dc8ed..46782cf575 100644 --- a/src/runtime/runtime-wasm.cc +++ b/src/runtime/runtime-wasm.cc @@ -20,23 +20,25 @@ namespace v8 { namespace internal { +namespace { +Handle GetWasmInstanceOnStackTop(Isolate* isolate) { + 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; + DCHECK_EQ(Code::WASM_FUNCTION, code->kind()); + WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); + CHECK_NOT_NULL(owning_instance); + return handle(owning_instance, isolate); +} +} // namespace + RUNTIME_FUNCTION(Runtime_WasmMemorySize) { HandleScope scope(isolate); DCHECK_EQ(0, args.length()); - Handle 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; - WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); - CHECK_NOT_NULL(owning_instance); - instance = handle(owning_instance, isolate); - } + Handle instance = GetWasmInstanceOnStackTop(isolate); return *isolate->factory()->NewNumberFromInt( wasm::GetInstanceMemorySize(isolate, instance)); } @@ -45,19 +47,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { HandleScope scope(isolate); DCHECK_EQ(1, args.length()); CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); - Handle 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; - WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); - CHECK_NOT_NULL(owning_instance); - instance = handle(owning_instance, isolate); - } + Handle instance = GetWasmInstanceOnStackTop(isolate); return *isolate->factory()->NewNumberFromInt( wasm::GrowMemory(isolate, instance, delta_pages)); } diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc index 5035e91fbc..0d7d7e0850 100644 --- a/src/wasm/wasm-module.cc +++ b/src/wasm/wasm-module.cc @@ -786,7 +786,7 @@ WasmInstanceObject* wasm::GetOwningWasmInstance(Code* code) { DisallowHeapAllocation no_gc; FixedArray* deopt_data = code->deoptimization_data(); DCHECK_NOT_NULL(deopt_data); - DCHECK(deopt_data->length() == 2); + DCHECK_EQ(2, deopt_data->length()); Object* weak_link = deopt_data->get(0); DCHECK(weak_link->IsWeakCell()); WeakCell* cell = WeakCell::cast(weak_link);