Commit fb430215 authored by clemensh's avatar clemensh Committed by Commit bot

[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}
parent 73afbaa8
......@@ -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 {
......
......@@ -20,23 +20,25 @@
namespace v8 {
namespace internal {
namespace {
Handle<WasmInstanceObject> 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<WasmInstanceObject> 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<WasmInstanceObject> 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<WasmInstanceObject> 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<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate);
return *isolate->factory()->NewNumberFromInt(
wasm::GrowMemory(isolate, instance, delta_pages));
}
......
......@@ -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);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment