diff options
author | 2023-09-27 20:45:38 +0100 | |
---|---|---|
committer | 2023-11-21 00:22:38 +0000 | |
commit | 9b0038be3332ca4229ec1822d515d1dc41bcf050 (patch) | |
tree | ca04eb58a48b9250e09bfe5c574bab6c4fa51cd6 | |
parent | b522e4b460bba1a0821c0ebab46b8b3bb22f8a3a (diff) |
Make MapAnonymousAligned agnostic to page size
This patch is part of the chain preparing for making kPageSize
non-constexpr in a future patch.
Test: Same as for I5430741a8494b340ed7fd2d8692c41a59ad9c530.
The whole patches chain was tested as a whole.
Change-Id: I27c37e6cf6d52ebea74bbd6825b52f1cb516a8a0
-rw-r--r-- | libartbase/base/mem_map.cc | 18 | ||||
-rw-r--r-- | libartbase/base/mem_map.h | 20 | ||||
-rw-r--r-- | libartbase/base/mem_map_windows.cc | 6 |
3 files changed, 43 insertions, 1 deletions
diff --git a/libartbase/base/mem_map.cc b/libartbase/base/mem_map.cc index ee9e69ca81..5f5dd13473 100644 --- a/libartbase/base/mem_map.cc +++ b/libartbase/base/mem_map.cc @@ -393,11 +393,27 @@ MemMap MemMap::MapAnonymousAligned(const char* name, size_t alignment, /*out=*/std::string* error_msg) { DCHECK(IsPowerOfTwo(alignment)); + +#ifdef ART_PAGE_SIZE_AGNOSTIC + // In page size agnostic configuration, the kPageSize is not known + // statically, so this interface has to support the case when alignment + // requested is greater than minimum page size however lower or equal to + // the actual page size. + DCHECK_GT(alignment, kMinPageSize); + if (alignment <= kPageSize) { + return MapAnonymous(name, byte_count, prot, low_4gb, error_msg); + } +#else DCHECK_GT(alignment, kPageSize); +#endif + // Allocate extra 'alignment - kPageSize' bytes so that the mapping can be aligned. MemMap ret = MapAnonymous(name, /*addr=*/nullptr, - byte_count + alignment - kPageSize, + // AlignBy requires the size to be page-aligned, so + // rounding it here. It is corrected afterwards with + // SetSize after AlignBy. + RoundUp(byte_count, kPageSize) + alignment - kPageSize, prot, low_4gb, /*reuse=*/false, diff --git a/libartbase/base/mem_map.h b/libartbase/base/mem_map.h index db85f08c08..120caa3b13 100644 --- a/libartbase/base/mem_map.h +++ b/libartbase/base/mem_map.h @@ -25,6 +25,8 @@ #include <string> #include "android-base/thread_annotations.h" +#include "bit_utils.h" +#include "globals.h" #include "macros.h" namespace art { @@ -179,6 +181,24 @@ class MemMap { error_msg); } + // Request an aligned anonymous region with statically known alignment. + // This is a wrapper choosing between MapAnonymousAligned and MapAnonymous + // depends on whether MapAnonymous would guarantee the requested alignment. + template<size_t alignment> + static MemMap MapAnonymousAligned(const char* name, + size_t byte_count, + int prot, + bool low_4gb, + /*out*/std::string* error_msg) { + static_assert(IsPowerOfTwo(alignment)); + + if (alignment <= kMinPageSize) { + return MapAnonymous(name, byte_count, prot, low_4gb, error_msg); + } else { + return MapAnonymousAligned(name, byte_count, prot, low_4gb, alignment, error_msg); + } + } + // Create placeholder for a region allocated by direct call to mmap. // This is useful when we do not have control over the code calling mmap, // but when we still want to keep track of it in the list. diff --git a/libartbase/base/mem_map_windows.cc b/libartbase/base/mem_map_windows.cc index dfa75a1d4f..3edf48a147 100644 --- a/libartbase/base/mem_map_windows.cc +++ b/libartbase/base/mem_map_windows.cc @@ -17,6 +17,12 @@ #include "mem_map.h" #include <windows.h> +// This include needs to be here due to the coding conventions. Unfortunately +// it drags in the definition of the ERROR macro. Similarly to base/utils.cc, +// undefine the macro here. See also, the comment at android-base/logging.h. +#ifdef ERROR +#undef ERROR +#endif #include "android-base/logging.h" #include "android-base/stringprintf.h" |