8297534: Specify the size of MEMFLAGS

Reviewed-by: stuefe, tschatzl
This commit is contained in:
Johan Sjölen 2022-11-28 09:30:53 +00:00
parent 012dafee5b
commit 81eb5fbff5
3 changed files with 7 additions and 4 deletions

@ -26,6 +26,7 @@
#define SHARE_MEMORY_ALLOCATION_HPP
#include "memory/allStatic.hpp"
#include "utilities/debug.hpp"
#include "utilities/globalDefinitions.hpp"
#include "utilities/macros.hpp"
@ -138,11 +139,13 @@ typedef AllocFailStrategy::AllocFailEnum AllocFailType;
/*
* Memory types
*/
enum class MEMFLAGS {
enum class MEMFLAGS : uint8_t {
MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_ENUM)
mt_number_of_types // number of memory types (mtDontTrack
// is not included as validate type)
};
// Extra insurance that MEMFLAGS truly has the same size as uint8_t.
STATIC_ASSERT(sizeof(MEMFLAGS) == sizeof(uint8_t));
#define MEMORY_TYPE_SHORTNAME(type, human_readable) \
constexpr MEMFLAGS type = MEMFLAGS::type;

@ -92,7 +92,7 @@ class MallocHeader {
NOT_LP64(uint32_t _alt_canary);
const size_t _size;
const uint32_t _mst_marker;
const uint8_t _flags;
const MEMFLAGS _flags;
const uint8_t _unused;
uint16_t _canary;
@ -119,7 +119,7 @@ class MallocHeader {
inline MallocHeader(size_t size, MEMFLAGS flags, uint32_t mst_marker);
inline size_t size() const { return _size; }
inline MEMFLAGS flags() const { return (MEMFLAGS)_flags; }
inline MEMFLAGS flags() const { return _flags; }
inline uint32_t mst_marker() const { return _mst_marker; }
bool get_stack(NativeCallStack& stack) const;

@ -35,7 +35,7 @@
#include "utilities/nativeCallStack.hpp"
inline MallocHeader::MallocHeader(size_t size, MEMFLAGS flags, uint32_t mst_marker)
: _size(size), _mst_marker(mst_marker), _flags(NMTUtil::flag_to_index(flags)),
: _size(size), _mst_marker(mst_marker), _flags(flags),
_unused(0), _canary(_header_canary_life_mark)
{
assert(size < max_reasonable_malloc_size, "Too large allocation size?");