Commit fd3b3668 authored by Kent Tamura's avatar Kent Tamura Committed by Commit Bot

Reland: Oilpan: Reduce the size of heap_page.h.

heap_page.h is used in 6,000+ compilation units, and this CL reduces its
estimated expanded size from 1.72MB to 1.40MB.

This CL relands https://chromium-review.googlesource.com/1104080 .
With the original code, GetRandomMagic() was folded into GetMagic(), and
GetMagic() was not folded into IsValid().
With https://chromium-review.googlesource.com/1104080,
ComputeRandomMagic() was not folded into GetMagic(), and GeMagic() and
IsValid() were folded into IsValid() callsites.  So the binary size
increased.
With this CL, GetMagic() isn't folded into IsValid() like the original
code. So this CL won't increase the binary size, and should not have
performance regression.

Bug: 242216
Change-Id: I7b6cf78a454abbbf3a3e41d821ac23e208b6dbdb
Reviewed-on: https://chromium-review.googlesource.com/1105208Reviewed-by: default avatarKeishi Hattori <keishi@chromium.org>
Commit-Queue: Kent Tamura <tkent@chromium.org>
Cr-Commit-Position: refs/heads/master@{#568696}
parent b88711d9
......@@ -1770,4 +1770,67 @@ bool LargeObjectPage::Contains(Address object) {
}
#endif
ALWAYS_INLINE uint32_t RotateLeft16(uint32_t x) {
#if defined(COMPILER_MSVC)
return _lrotr(x, 16);
#else
// http://blog.regehr.org/archives/1063
return (x << 16) | (x >> (-16 & 31));
#endif
}
uint32_t ComputeRandomMagic() {
// Ignore C4319: It is OK to 0-extend into the high-order bits of the uintptr_t
// on 64-bit, in this case.
#if defined(COMPILER_MSVC)
#pragma warning(push)
#pragma warning(disable : 4319)
#endif
const uintptr_t random1 = ~(RotateLeft16(reinterpret_cast<uintptr_t>(
base::trace_event::MemoryAllocatorDump::kNameSize)));
#if defined(OS_WIN)
const uintptr_t random2 =
~(RotateLeft16(reinterpret_cast<uintptr_t>(::ReadFile)));
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
const uintptr_t random2 =
~(RotateLeft16(reinterpret_cast<uintptr_t>(::read)));
#endif
#if defined(ARCH_CPU_64_BITS)
static_assert(sizeof(uintptr_t) == sizeof(uint64_t),
"uintptr_t is not uint64_t");
const uint32_t random = static_cast<uint32_t>(
(random1 & 0x0FFFFULL) | ((random2 >> 32) & 0x0FFFF0000ULL));
#elif defined(ARCH_CPU_32_BITS)
// Although we don't use heap metadata canaries on 32-bit due to memory
// pressure, keep this code around just in case we do, someday.
static_assert(sizeof(uintptr_t) == sizeof(uint32_t),
"uintptr_t is not uint32_t");
const uint32_t random = (random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL);
#else
#error architecture not supported
#endif
#if defined(COMPILER_MSVC)
#pragma warning(pop)
#endif
return random;
}
#if defined(ARCH_CPU_64_BITS)
// Returns a random magic value.
uint32_t HeapObjectHeader::GetMagic() {
static const uint32_t magic = ComputeRandomMagic() ^ 0x6e0b6ead;
return magic;
}
#endif // defined(ARCH_CPU_64_BITS)
uint32_t BasePage::GetMagic() {
static const uint32_t magic = ComputeRandomMagic() ^ 0xba5e4a9e;
return magic;
}
} // namespace blink
......@@ -33,7 +33,6 @@
#include <stdint.h>
#include "base/bits.h"
#include "base/trace_event/memory_allocator_dump.h"
#include "build/build_config.h"
#include "third_party/blink/renderer/platform/heap/blink_gc.h"
#include "third_party/blink/renderer/platform/heap/gc_info.h"
......@@ -47,6 +46,12 @@
#include "third_party/blink/renderer/platform/wtf/container_annotations.h"
#include "third_party/blink/renderer/platform/wtf/forward.h"
namespace base {
namespace trace_event {
class MemoryAllocatorDump;
} // namespace trace_event
} // namespace base
namespace blink {
// TODO(palmer): Document the reason for 17.
......@@ -136,7 +141,7 @@ class BaseArena;
// should be fast and small, and should have the benefit of requiring
// attackers to discover and use 2 independent weak infoleak bugs, or 1
// arbitrary infoleak bug (used twice).
inline uint32_t GetRandomMagic();
uint32_t ComputeRandomMagic();
// HeapObjectHeader is a 64-bit (64-bit platforms) or 32-bit (32-bit platforms)
// object that has the following layout:
......@@ -247,7 +252,7 @@ class PLATFORM_EXPORT HeapObjectHeader {
#if defined(ARCH_CPU_64_BITS)
// Returns a random magic value.
uint32_t GetMagic() const { return GetRandomMagic() ^ 0x6e0b6ead; }
static uint32_t GetMagic();
uint32_t magic_;
#endif // defined(ARCH_CPU_64_BITS)
......@@ -418,7 +423,7 @@ class BasePage {
private:
// Returns a random magic value.
uint32_t GetMagic() const { return GetRandomMagic() ^ 0xba5e4a9e; }
PLATFORM_EXPORT static uint32_t GetMagic();
uint32_t const magic_;
PageMemory* const storage_;
......@@ -951,57 +956,6 @@ inline void HeapObjectHeader::CheckFromPayload(const void* payload) {
(void)FromPayload(payload);
}
ALWAYS_INLINE uint32_t RotateLeft16(uint32_t x) {
#if defined(COMPILER_MSVC)
return _lrotr(x, 16);
#else
// http://blog.regehr.org/archives/1063
return (x << 16) | (x >> (-16 & 31));
#endif
}
inline uint32_t GetRandomMagic() {
// Ignore C4319: It is OK to 0-extend into the high-order bits of the uintptr_t
// on 64-bit, in this case.
#if defined(COMPILER_MSVC)
#pragma warning(push)
#pragma warning(disable : 4319)
#endif
static const uintptr_t random1 = ~(RotateLeft16(reinterpret_cast<uintptr_t>(
base::trace_event::MemoryAllocatorDump::kNameSize)));
#if defined(OS_WIN)
static const uintptr_t random2 =
~(RotateLeft16(reinterpret_cast<uintptr_t>(::ReadFile)));
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
static const uintptr_t random2 =
~(RotateLeft16(reinterpret_cast<uintptr_t>(::read)));
#endif
#if defined(ARCH_CPU_64_BITS)
static_assert(sizeof(uintptr_t) == sizeof(uint64_t),
"uintptr_t is not uint64_t");
static const uint32_t random = static_cast<uint32_t>(
(random1 & 0x0FFFFULL) | ((random2 >> 32) & 0x0FFFF0000ULL));
#elif defined(ARCH_CPU_32_BITS)
// Although we don't use heap metadata canaries on 32-bit due to memory
// pressure, keep this code around just in case we do, someday.
static_assert(sizeof(uintptr_t) == sizeof(uint32_t),
"uintptr_t is not uint32_t");
static const uint32_t random =
(random1 & 0x0FFFFUL) | (random2 & 0xFFFF0000UL);
#else
#error architecture not supported
#endif
#if defined(COMPILER_MSVC)
#pragma warning(pop)
#endif
return random;
}
NO_SANITIZE_ADDRESS inline bool HeapObjectHeader::IsWrapperHeaderMarked()
const {
CheckHeader();
......
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