Commit 8b306c63 authored by clemensh's avatar clemensh Committed by Commit bot

[wasm] Refactor interface to WasmCompiledModule

The ptr_to_* methods do (often unnecessary) type checks, and can
return nullptr. This is problematic since the handlified getter
uses them, and assumes the result to be non-null. So change
them to only to a DCHECK and never return nullptr, and introduce
maybe_ptr_to_* with the old semantics.

R=titzer@chromium.org, ahaas@chromium.org

Review-Url: https://codereview.chromium.org/2509053003
Cr-Commit-Position: refs/heads/master@{#41079}
parent 53698740
...@@ -540,8 +540,8 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) { ...@@ -540,8 +540,8 @@ static void InstanceFinalizer(const v8::WeakCallbackInfo<void>& data) {
TRACE("}\n"); TRACE("}\n");
DCHECK(!current_template->has_weak_prev_instance()); DCHECK(!current_template->has_weak_prev_instance());
WeakCell* next = compiled_module->ptr_to_weak_next_instance(); WeakCell* next = compiled_module->maybe_ptr_to_weak_next_instance();
WeakCell* prev = compiled_module->ptr_to_weak_prev_instance(); WeakCell* prev = compiled_module->maybe_ptr_to_weak_prev_instance();
if (current_template == compiled_module) { if (current_template == compiled_module) {
if (next == nullptr) { if (next == nullptr) {
......
...@@ -349,7 +349,7 @@ void WasmCompiledModule::PrintInstancesChain() { ...@@ -349,7 +349,7 @@ void WasmCompiledModule::PrintInstancesChain() {
if (!FLAG_trace_wasm_instances) return; if (!FLAG_trace_wasm_instances) return;
for (WasmCompiledModule* current = this; current != nullptr;) { for (WasmCompiledModule* current = this; current != nullptr;) {
PrintF("->%d", current->instance_id()); PrintF("->%d", current->instance_id());
if (current->ptr_to_weak_next_instance() == nullptr) break; if (!current->has_weak_next_instance()) break;
CHECK(!current->ptr_to_weak_next_instance()->cleared()); CHECK(!current->ptr_to_weak_next_instance()->cleared());
current = current =
WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value()); WasmCompiledModule::cast(current->ptr_to_weak_next_instance()->value());
......
...@@ -157,12 +157,18 @@ class WasmCompiledModule : public FixedArray { ...@@ -157,12 +157,18 @@ class WasmCompiledModule : public FixedArray {
return MaybeHandle<TYPE>(); \ return MaybeHandle<TYPE>(); \
} \ } \
\ \
TYPE* ptr_to_##NAME() const { \ TYPE* maybe_ptr_to_##NAME() const { \
Object* obj = get(ID); \ Object* obj = get(ID); \
if (!obj->Is##TYPE()) return nullptr; \ if (!obj->Is##TYPE()) return nullptr; \
return TYPE::cast(obj); \ return TYPE::cast(obj); \
} \ } \
\ \
TYPE* ptr_to_##NAME() const { \
Object* obj = get(ID); \
DCHECK(obj->Is##TYPE()); \
return TYPE::cast(obj); \
} \
\
void set_##NAME(Handle<TYPE> value) { set_ptr_to_##NAME(*value); } \ void set_##NAME(Handle<TYPE> value) { set_ptr_to_##NAME(*value); } \
\ \
void set_ptr_to_##NAME(TYPE* value) { set(ID, value); } \ void set_ptr_to_##NAME(TYPE* value) { set(ID, value); } \
......
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