#pragma once #include namespace lsplant::art { template class alignas(4) [[gnu::packed]] ObjectReference { static MirrorType* Decompress(uint32_t ref) { uintptr_t as_bits = kPoisonReferences ? -ref : ref; return reinterpret_cast(as_bits); } uint32_t reference_; public: MirrorType* AsMirrorPtr() const { return Decompress(reference_); } }; template class alignas(4) [[gnu::packed]] CompressedReference : public ObjectReference {}; template class alignas(4) [[gnu::packed]] StackReference : public CompressedReference {}; template // use like this: down_cast(foo); inline To down_cast(From* f) { // so we only accept pointers static_assert(std::is_base_of_v>, "down_cast unsafe as To is not a subtype of From"); return static_cast(f); } } // namespace lsplant::art