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 { ...@@ -1559,10 +1559,10 @@ Address WasmFrame::GetCallerStackPointer() const {
} }
WasmInstanceObject* WasmFrame::wasm_instance() const { WasmInstanceObject* WasmFrame::wasm_instance() const {
Object* ret = wasm::GetOwningWasmInstance(LookupCode()); WasmInstanceObject* obj = wasm::GetOwningWasmInstance(LookupCode());
// This is a live stack frame, there must be a live wasm instance available. // This is a live stack frame; it must have a live instance.
DCHECK_NOT_NULL(ret); DCHECK_NOT_NULL(obj);
return WasmInstanceObject::cast(ret); return obj;
} }
uint32_t WasmFrame::function_index() const { uint32_t WasmFrame::function_index() const {
......
...@@ -20,23 +20,25 @@ ...@@ -20,23 +20,25 @@
namespace v8 { namespace v8 {
namespace internal { namespace internal {
RUNTIME_FUNCTION(Runtime_WasmMemorySize) { namespace {
HandleScope scope(isolate); Handle<WasmInstanceObject> GetWasmInstanceOnStackTop(Isolate* isolate) {
DCHECK_EQ(0, args.length());
Handle<WasmInstanceObject> instance;
{
// Get the module JSObject
DisallowHeapAllocation no_allocation; DisallowHeapAllocation no_allocation;
const Address entry = Isolate::c_entry_fp(isolate->thread_local_top()); const Address entry = Isolate::c_entry_fp(isolate->thread_local_top());
Address pc = Address pc =
Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset); Memory::Address_at(entry + StandardFrameConstants::kCallerPCOffset);
Code* code = Code* code = isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code;
isolate->inner_pointer_to_code_cache()->GetCacheEntry(pc)->code; DCHECK_EQ(Code::WASM_FUNCTION, code->kind());
WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code); WasmInstanceObject* owning_instance = wasm::GetOwningWasmInstance(code);
CHECK_NOT_NULL(owning_instance); CHECK_NOT_NULL(owning_instance);
instance = handle(owning_instance, isolate); return handle(owning_instance, isolate);
} }
} // namespace
RUNTIME_FUNCTION(Runtime_WasmMemorySize) {
HandleScope scope(isolate);
DCHECK_EQ(0, args.length());
Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate);
return *isolate->factory()->NewNumberFromInt( return *isolate->factory()->NewNumberFromInt(
wasm::GetInstanceMemorySize(isolate, instance)); wasm::GetInstanceMemorySize(isolate, instance));
} }
...@@ -45,19 +47,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) { ...@@ -45,19 +47,7 @@ RUNTIME_FUNCTION(Runtime_WasmGrowMemory) {
HandleScope scope(isolate); HandleScope scope(isolate);
DCHECK_EQ(1, args.length()); DCHECK_EQ(1, args.length());
CONVERT_UINT32_ARG_CHECKED(delta_pages, 0); CONVERT_UINT32_ARG_CHECKED(delta_pages, 0);
Handle<WasmInstanceObject> instance; Handle<WasmInstanceObject> instance = GetWasmInstanceOnStackTop(isolate);
{
// 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);
}
return *isolate->factory()->NewNumberFromInt( return *isolate->factory()->NewNumberFromInt(
wasm::GrowMemory(isolate, instance, delta_pages)); wasm::GrowMemory(isolate, instance, delta_pages));
} }
......
...@@ -786,7 +786,7 @@ WasmInstanceObject* wasm::GetOwningWasmInstance(Code* code) { ...@@ -786,7 +786,7 @@ WasmInstanceObject* wasm::GetOwningWasmInstance(Code* code) {
DisallowHeapAllocation no_gc; DisallowHeapAllocation no_gc;
FixedArray* deopt_data = code->deoptimization_data(); FixedArray* deopt_data = code->deoptimization_data();
DCHECK_NOT_NULL(deopt_data); DCHECK_NOT_NULL(deopt_data);
DCHECK(deopt_data->length() == 2); DCHECK_EQ(2, deopt_data->length());
Object* weak_link = deopt_data->get(0); Object* weak_link = deopt_data->get(0);
DCHECK(weak_link->IsWeakCell()); DCHECK(weak_link->IsWeakCell());
WeakCell* cell = WeakCell::cast(weak_link); 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