Skip to content

Commit 81eb5fb

Browse files
committed
8297534: Specify the size of MEMFLAGS
Reviewed-by: stuefe, tschatzl
1 parent 012dafe commit 81eb5fb

File tree

3 files changed

+7
-4
lines changed

3 files changed

+7
-4
lines changed

src/hotspot/share/memory/allocation.hpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#define SHARE_MEMORY_ALLOCATION_HPP
2727

2828
#include "memory/allStatic.hpp"
29+
#include "utilities/debug.hpp"
2930
#include "utilities/globalDefinitions.hpp"
3031
#include "utilities/macros.hpp"
3132

@@ -138,11 +139,13 @@ typedef AllocFailStrategy::AllocFailEnum AllocFailType;
138139
/*
139140
* Memory types
140141
*/
141-
enum class MEMFLAGS {
142+
enum class MEMFLAGS : uint8_t {
142143
MEMORY_TYPES_DO(MEMORY_TYPE_DECLARE_ENUM)
143144
mt_number_of_types // number of memory types (mtDontTrack
144145
// is not included as validate type)
145146
};
147+
// Extra insurance that MEMFLAGS truly has the same size as uint8_t.
148+
STATIC_ASSERT(sizeof(MEMFLAGS) == sizeof(uint8_t));
146149

147150
#define MEMORY_TYPE_SHORTNAME(type, human_readable) \
148151
constexpr MEMFLAGS type = MEMFLAGS::type;

src/hotspot/share/services/mallocHeader.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ class MallocHeader {
9292
NOT_LP64(uint32_t _alt_canary);
9393
const size_t _size;
9494
const uint32_t _mst_marker;
95-
const uint8_t _flags;
95+
const MEMFLAGS _flags;
9696
const uint8_t _unused;
9797
uint16_t _canary;
9898

@@ -119,7 +119,7 @@ class MallocHeader {
119119
inline MallocHeader(size_t size, MEMFLAGS flags, uint32_t mst_marker);
120120

121121
inline size_t size() const { return _size; }
122-
inline MEMFLAGS flags() const { return (MEMFLAGS)_flags; }
122+
inline MEMFLAGS flags() const { return _flags; }
123123
inline uint32_t mst_marker() const { return _mst_marker; }
124124
bool get_stack(NativeCallStack& stack) const;
125125

src/hotspot/share/services/mallocHeader.inline.hpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
#include "utilities/nativeCallStack.hpp"
3636

3737
inline MallocHeader::MallocHeader(size_t size, MEMFLAGS flags, uint32_t mst_marker)
38-
: _size(size), _mst_marker(mst_marker), _flags(NMTUtil::flag_to_index(flags)),
38+
: _size(size), _mst_marker(mst_marker), _flags(flags),
3939
_unused(0), _canary(_header_canary_life_mark)
4040
{
4141
assert(size < max_reasonable_malloc_size, "Too large allocation size?");

0 commit comments

Comments
 (0)