Refactor MetaEntry remote_and_sizeclass
Introduce a class that we can use to more completely separate the frontend encoding details from the backend.
This commit is contained in:
committed by
Nathaniel Wesley Filardo
parent
772e46f878
commit
7940fee00c
@@ -79,10 +79,6 @@ namespace snmalloc
|
||||
#endif
|
||||
// clang-format on
|
||||
|
||||
struct RemoteAllocator;
|
||||
class Metaslab;
|
||||
class sizeclass_t;
|
||||
|
||||
/**
|
||||
* Entry stored in the pagemap. See docs/AddressSpace.md for the full
|
||||
* MetaEntry lifecycle.
|
||||
@@ -140,41 +136,23 @@ namespace snmalloc
|
||||
* `get_remote_and_sizeclass`.
|
||||
*/
|
||||
SNMALLOC_FAST_PATH
|
||||
MetaEntry(Metaslab* meta, uintptr_t remote_and_sizeclass)
|
||||
: meta(unsafe_to_uintptr<Metaslab>(meta)),
|
||||
MetaEntry(MetaCommon* meta, uintptr_t remote_and_sizeclass)
|
||||
: meta(unsafe_to_uintptr<MetaCommon>(meta)),
|
||||
remote_and_sizeclass(remote_and_sizeclass)
|
||||
{}
|
||||
|
||||
/* See mem/metaslab.h */
|
||||
SNMALLOC_FAST_PATH
|
||||
MetaEntry(Metaslab* meta, RemoteAllocator* remote, sizeclass_t sizeclass);
|
||||
|
||||
/**
|
||||
* Return the Metaslab metadata associated with this chunk, guarded by an
|
||||
* assert that this chunk is being used as a slab (i.e., has an associated
|
||||
* owning allocator).
|
||||
*/
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH Metaslab* get_metaslab() const
|
||||
{
|
||||
SNMALLOC_ASSERT(get_remote() != nullptr);
|
||||
return unsafe_from_uintptr<Metaslab>(meta & ~META_BOUNDARY_BIT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the remote and sizeclass in an implementation-defined encoding.
|
||||
* This is not guaranteed to be stable across snmalloc releases and so the
|
||||
* only safe use for this is to pass it to the two-argument constructor of
|
||||
* this class.
|
||||
*/
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH uintptr_t get_remote_and_sizeclass() const
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH const uintptr_t&
|
||||
get_remote_and_sizeclass() const
|
||||
{
|
||||
return remote_and_sizeclass;
|
||||
}
|
||||
|
||||
/* See mem/metaslab.h */
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH RemoteAllocator* get_remote() const;
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH sizeclass_t get_sizeclass() const;
|
||||
|
||||
MetaEntry(const MetaEntry&) = delete;
|
||||
|
||||
MetaEntry& operator=(const MetaEntry& other)
|
||||
@@ -186,6 +164,16 @@ namespace snmalloc
|
||||
return *this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the Metaslab metadata associated with this chunk, guarded by an
|
||||
* assert that this chunk is being used as a slab (i.e., has an associated
|
||||
* owning allocator).
|
||||
*/
|
||||
[[nodiscard]] SNMALLOC_FAST_PATH MetaCommon* get_meta() const
|
||||
{
|
||||
return reinterpret_cast<MetaCommon*>(meta & ~META_BOUNDARY_BIT);
|
||||
}
|
||||
|
||||
void set_boundary()
|
||||
{
|
||||
meta |= META_BOUNDARY_BIT;
|
||||
@@ -201,5 +189,4 @@ namespace snmalloc
|
||||
return meta &= ~META_BOUNDARY_BIT;
|
||||
}
|
||||
};
|
||||
|
||||
} // namespace snmalloc
|
||||
|
||||
Reference in New Issue
Block a user