Index: src/wasm/wasm-module.cc |
diff --git a/src/wasm/wasm-module.cc b/src/wasm/wasm-module.cc |
index 13773f21bedc2f4a4d0acef219e307012ba2d1f9..60136c05fef3d889d19e408ebd69f008fa0d6810 100644 |
--- a/src/wasm/wasm-module.cc |
+++ b/src/wasm/wasm-module.cc |
@@ -144,6 +144,18 @@ Handle<JSFunction> WrapExportCodeAsJSFunction( |
return function; |
} |
+Object* GetOwningWasmInstance(Object* undefined, Code* code) { |
bradnelson
2016/08/29 19:09:48
Why pass undefined in instead of the isolate?
Mircea Trofin
2016/08/29 19:12:22
Because undefined is the only needed value, rather
|
+ DCHECK(code->kind() == Code::WASM_FUNCTION); |
+ DisallowHeapAllocation no_gc; |
+ FixedArray* deopt_data = code->deoptimization_data(); |
+ DCHECK_NOT_NULL(deopt_data); |
+ DCHECK(deopt_data->length() == 2); |
+ Object* weak_link = deopt_data->get(0); |
+ if (weak_link == undefined) return undefined; |
+ WeakCell* cell = WeakCell::cast(weak_link); |
+ return cell->value(); |
+} |
+ |
namespace { |
// Internal constants for the layout of the module object. |
const int kWasmModuleFunctionTable = 0; |
@@ -434,6 +446,24 @@ void FlushAssemblyCache(Isolate* isolate, Handle<FixedArray> functions) { |
} |
} |
+void SetRuntimeSupport(Isolate* isolate, Handle<JSObject> js_object) { |
+ Handle<FixedArray> functions = Handle<FixedArray>( |
+ FixedArray::cast(js_object->GetInternalField(kWasmModuleCodeTable))); |
+ Handle<WeakCell> weak_link = isolate->factory()->NewWeakCell(js_object); |
+ |
+ for (int i = FLAG_skip_compiling_wasm_funcs; i < functions->length(); ++i) { |
+ Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); |
+ DCHECK(code->deoptimization_data() == nullptr || |
+ code->deoptimization_data()->length() == 0); |
+ Handle<FixedArray> deopt_data = |
+ isolate->factory()->NewFixedArray(2, TENURED); |
+ deopt_data->set(0, *weak_link); |
+ deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); |
+ deopt_data->set_length(2); |
+ code->set_deoptimization_data(*deopt_data); |
+ } |
+} |
+ |
} // namespace |
WasmModule::WasmModule(byte* module_start) |
@@ -873,21 +903,6 @@ void SetDebugSupport(Factory* factory, Handle<FixedArray> compiled_module, |
js_object->SetInternalField(kWasmModuleBytesString, |
*module_bytes_string.ToHandleChecked()); |
} |
- Handle<FixedArray> functions = Handle<FixedArray>( |
- FixedArray::cast(js_object->GetInternalField(kWasmModuleCodeTable))); |
- |
- for (int i = FLAG_skip_compiling_wasm_funcs; i < functions->length(); ++i) { |
- Handle<Code> code = functions->GetValueChecked<Code>(isolate, i); |
- DCHECK(code->deoptimization_data() == nullptr || |
- code->deoptimization_data()->length() == 0); |
- Handle<FixedArray> deopt_data = factory->NewFixedArray(2, TENURED); |
- if (!js_object.is_null()) { |
- deopt_data->set(0, *js_object); |
- } |
- deopt_data->set(1, Smi::FromInt(static_cast<int>(i))); |
- deopt_data->set_length(2); |
- code->set_deoptimization_data(*deopt_data); |
- } |
MaybeHandle<ByteArray> function_name_table = |
compiled_module->GetValue<ByteArray>(isolate, kFunctionNameTable); |
@@ -1397,6 +1412,7 @@ MaybeHandle<JSObject> WasmModule::Instantiate( |
} |
SetDebugSupport(factory, compiled_module, js_object); |
+ SetRuntimeSupport(isolate, js_object); |
FlushAssemblyCache(isolate, code_table); |