[wasm] Do not count jump table size twice

The jump table sizes were added to the estimated code size, and then
again added for computing the reservation size for the code. This CL
moves the jump table size from {EstimateNativeModuleCodeSize} to
{EstimateNativeModuleMetaDataSize} so it is still considered for the
total memory associated with the {NativeModule}, but only added once for
the code space reservation.

R=ahaas@chromium.org

Bug: v8:12520
Change-Id: I871e54833659a0d466f3e8359bb3b515c85dd3cb
Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/3367622
Reviewed-by: Andreas Haas <ahaas@chromium.org>
Commit-Queue: Clemens Backes <clemensb@chromium.org>
Cr-Commit-Position: refs/heads/main@{#78491}
This commit is contained in:
Clemens Backes 2022-01-05 12:05:31 +01:00 committed by V8 LUCI CQ
parent dc3eb44971
commit 139a2f514b

View File

@ -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<kCodeAlignment>(
JumpTableAssembler::SizeForNumberOfSlots(num_functions));
const size_t far_jump_table_size =
RoundUp<kCodeAlignment>(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<kCodeAlignment>(
JumpTableAssembler::SizeForNumberOfSlots(num_wasm_functions));
size_t far_jump_table_size =
RoundUp<kCodeAlignment>(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) {