diff --git a/src/wasm/wasm-code-manager.cc b/src/wasm/wasm-code-manager.cc index 29080a4810..ba18fddf6c 100644 --- a/src/wasm/wasm-code-manager.cc +++ b/src/wasm/wasm-code-manager.cc @@ -2070,15 +2070,9 @@ size_t WasmCodeManager::EstimateNativeModuleCodeSize(int num_functions, const size_t overhead_per_code_byte = kTurbofanCodeSizeMultiplier + (include_liftoff ? kLiftoffCodeSizeMultiplier : 0); - const size_t jump_table_size = RoundUp( - JumpTableAssembler::SizeForNumberOfSlots(num_functions)); - const size_t far_jump_table_size = - RoundUp(JumpTableAssembler::SizeForNumberOfFarJumpSlots( - WasmCode::kRuntimeStubCount, - NumWasmFunctionsInFarJumpTable(num_functions))); - return jump_table_size // jump table - + far_jump_table_size // far jump table - + overhead_per_function * num_functions // per function + // Note that the size for jump tables is added later, in {ReservationSize} / + // {OverheadPerCodeSpace}. + return overhead_per_function * num_functions // per function + overhead_per_code_byte * code_section_length // per code byte + kImportSize * num_imported_functions; // per import } @@ -2092,11 +2086,19 @@ size_t WasmCodeManager::EstimateNativeModuleMetaDataSize( // TODO(wasm): Include wire bytes size. size_t native_module_estimate = - sizeof(NativeModule) + /* NativeModule struct */ - (sizeof(WasmCode*) * num_wasm_functions) + /* code table size */ - (sizeof(WasmCode) * num_wasm_functions); /* code object size */ + sizeof(NativeModule) + // NativeModule struct + (sizeof(WasmCode*) * num_wasm_functions) + // code table size + (sizeof(WasmCode) * num_wasm_functions); // code object size - return wasm_module_estimate + native_module_estimate; + size_t jump_table_size = RoundUp( + JumpTableAssembler::SizeForNumberOfSlots(num_wasm_functions)); + size_t far_jump_table_size = + RoundUp(JumpTableAssembler::SizeForNumberOfFarJumpSlots( + WasmCode::kRuntimeStubCount, + NumWasmFunctionsInFarJumpTable(num_wasm_functions))); + + return wasm_module_estimate + native_module_estimate + jump_table_size + + far_jump_table_size; } void WasmCodeManager::SetThreadWritable(bool writable) {