269 {
270 public:
272
274 : compressed_pointer_(
275 static_cast<uint32_t>(static_cast<
uword>(uncompressed))) {}
277 : compressed_pointer_(static_cast<uint32_t>(tagged)) {}
278
280 return static_cast<ObjectPtr
>(
static_cast<uword>(compressed_pointer_) +
281 heap_base);
282 }
283
284 ObjectPtr DecompressSmi() const {
285 ASSERT((compressed_pointer_ & kSmiTagMask) != kHeapObjectTag);
286 return static_cast<ObjectPtr
>(
static_cast<uword>(compressed_pointer_));
287 }
288
289 const ObjectPtr& operator=(const ObjectPtr& other) {
290 compressed_pointer_ =
static_cast<uint32_t
>(
static_cast<uword>(other));
291 return other;
292 }
293
294 protected:
295 uint32_t compressed_pointer_;
296};
297
298template <typename T>
299struct is_compressed_ptr<
301 typename
std::enable_if<std::is_base_of<CompressedObjectPtr, T>::value,
302 void>
::type> : std::true_type {};
303template <typename T>
304struct base_ptr_type<
306 typename
std::enable_if<std::is_base_of<CompressedObjectPtr, T>::value,
309};
310
311#define DEFINE_COMPRESSED_POINTER(klass, base) \
312 class Compressed##klass##Ptr : public Compressed##base##Ptr { \
313 public: \
314 Compressed##klass##Ptr* operator->() { \
315 return this; \
316 } \
317 const Compressed##klass##Ptr* operator->() const { \
318 return this; \
319 } \
320 explicit Compressed##klass##Ptr(klass##Ptr uncompressed) \
321 : Compressed##base##Ptr(uncompressed) {} \
322 const klass##Ptr& operator=(const klass##Ptr& other) { \
323 compressed_pointer_ = static_cast<uint32_t>(static_cast<uword>(other)); \
324 return other; \
325 } \
326 klass##Ptr Decompress(uword heap_base) const { \
327 return klass##Ptr(CompressedObjectPtr::Decompress(heap_base)); \
328 } \
329 };
330#endif
331
332#define DEFINE_TAGGED_POINTER(klass, base) \
333 class Untagged##klass; \
334 class klass##Ptr : public base##Ptr { \
335 public: \
336 klass##Ptr* operator->() { \
337 return this; \
338 } \
339 const klass##Ptr* operator->() const { \
340 return this; \
341 } \
342 Untagged##klass* untag() { \
343 return reinterpret_cast<Untagged##klass*>(untagged_pointer()); \
344 } \
345 \
346 Untagged##klass* untag() const { \
347 return reinterpret_cast<Untagged##klass*>(untagged_pointer()); \
348 } \
349 klass##Ptr& operator=(const klass##Ptr& other) = default; \
350 constexpr klass##Ptr(const klass##Ptr& other) = default; \
351 explicit constexpr klass##Ptr(const ObjectPtr& other) \
352 : base##Ptr(other) {} \
353 klass##Ptr() : base##Ptr() {} \
354 explicit constexpr klass##Ptr(uword tagged) : base##Ptr(tagged) {} \
355 explicit constexpr klass##Ptr(intptr_t tagged) : base##Ptr(tagged) {} \
356 constexpr klass##Ptr(std::nullptr_t) : base##Ptr(nullptr) {} \
357 explicit klass##Ptr(const UntaggedObject* untagged) \
358 : base##Ptr(reinterpret_cast<uword>(untagged) + kHeapObjectTag) {} \
359 klass##Ptr Decompress(uword heap_base) const { \
360 return *this; \
361 } \
362 }; \
363 DEFINE_COMPRESSED_POINTER(klass, base)
364
457#undef DEFINE_TAGGED_POINTER
458
459inline intptr_t
RawSmiValue(
const SmiPtr raw_value) {
460#if !defined(DART_COMPRESSED_POINTERS)
461 const intptr_t
value =
static_cast<intptr_t
>(raw_value);
462#else
463 const intptr_t
value =
static_cast<intptr_t
>(
static_cast<int32_t
>(
464 static_cast<uint32_t>(static_cast<uintptr_t>(raw_value))));
465#endif
466 ASSERT((value & kSmiTagMask) == kSmiTag);
467 return (value >> kSmiTagShift);
468}
469
470}
471
472#endif
void Decompress(const uint8_t *input, intptr_t input_len, uint8_t **output, intptr_t *output_length)
intptr_t RawSmiValue(const SmiPtr raw_value)
ObjectPtr CompressedObjectPtr
#define DEFINE_TAGGED_POINTER(klass, base)
#define OBJECT_POINTER_CORE_FUNCTIONS(type, ptr)