From 1cf88f1e0504dd99992018d882633291bcce36c8 Mon Sep 17 00:00:00 2001 From: Peter Varga Date: Tue, 15 Nov 2022 14:43:01 +0100 Subject: [Backport] [PA] Remove inline assembly This CL removes some inline assembly from `PartitionRoot::RawFree()` when building under MSVC. A small MSVC-specific kludge is added to hopefully prevent optimization of the store instruction, but it is not certain to work and needs verification. Bug: 1351310 Change-Id: If86346f943a07167a1af75132ad6d5efddc23e60 Review-URL: https://chromium-review.googlesource.com/c/chromium/src/+/3874547 Cr-Commit-Position: refs/heads/main@{#1043308} Reviewed-on: https://codereview.qt-project.org/c/qt/qtwebengine-chromium/+/443565 Reviewed-by: Allan Sandfeld Jensen --- .../base/allocator/partition_allocator/partition_root.h | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/chromium/base/allocator/partition_allocator/partition_root.h b/chromium/base/allocator/partition_allocator/partition_root.h index f4be80bfb06..34cfe5ae24e 100644 --- a/chromium/base/allocator/partition_allocator/partition_root.h +++ b/chromium/base/allocator/partition_allocator/partition_root.h @@ -1336,6 +1336,14 @@ PA_ALWAYS_INLINE void PartitionRoot::RawFree( RawFree(slot_start, slot_span); } +#if defined(COMPILER_MSVC) && !defined(__clang__) +// MSVC only supports inline assembly on x86. This preprocessor directive +// is intended to be a replacement for the same. +// +// TODO(crbug.com/1351310): Make sure inlining doesn't degrade this into +// a no-op or similar. The documentation doesn't say. +#pragma optimize("", off) +#endif template PA_ALWAYS_INLINE void PartitionRoot::RawFree(uintptr_t slot_start, SlotSpan* slot_span) { @@ -1370,15 +1378,16 @@ PA_ALWAYS_INLINE void PartitionRoot::RawFree(uintptr_t slot_start, // OS page. No need to write to the second one as well. // // Do not move the store above inside the locked section. -#if defined(__clang__) || defined(COMPILER_GCC) +#if !(defined(COMPILER_MSVC) && !defined(__clang__)) __asm__ __volatile__("" : : "r"(slot_start) : "memory"); -#else - _ReadBarrier(); #endif ::partition_alloc::internal::ScopedGuard guard{lock_}; FreeInSlotSpan(slot_start, slot_span); } +#if defined(COMPILER_MSVC) && !defined(__clang__) +#pragma optimize("", on) +#endif template PA_ALWAYS_INLINE void PartitionRoot::RawFreeBatch( -- cgit v1.2.1