Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Classes | Namespaces | Macros | Typedefs | Functions
tagged_pointer.h File Reference
#include <type_traits>
#include "platform/assert.h"
#include "platform/utils.h"
#include "vm/class_id.h"
#include "vm/globals.h"
#include "vm/pointer_tagging.h"

Go to the source code of this file.

Classes

class  dart::ObjectPtr
 
struct  dart::is_uncompressed_ptr< T, Enable >
 
struct  dart::is_uncompressed_ptr< T, typename std::enable_if< std::is_base_of< ObjectPtr, T >::value, void >::type >
 
struct  dart::is_compressed_ptr< T, Enable >
 
struct  dart::base_ptr_type< T, Enable >
 

Namespaces

namespace  dart
 

Macros

#define OBJECT_POINTER_CORE_FUNCTIONS(type, ptr)
 
#define DEFINE_IS_CID(clazz)    bool Is##clazz() const { return ((GetClassId() == k##clazz##Cid)); }
 
#define DEFINE_IS_CID(clazz)
 
#define DEFINE_IS_CID(clazz)    bool IsFfi##clazz() const { return ((GetClassId() == kFfi##clazz##Cid)); }
 
#define DEFINE_COMPRESSED_POINTER(klass, base)    typedef klass##Ptr Compressed##klass##Ptr;
 
#define DEFINE_TAGGED_POINTER(klass, base)
 

Typedefs

typedef ObjectPtr dart::CompressedObjectPtr
 

Functions

intptr_t dart::RawSmiValue (const SmiPtr raw_value)
 

Macro Definition Documentation

◆ DEFINE_COMPRESSED_POINTER

#define DEFINE_COMPRESSED_POINTER (   klass,
  base 
)     typedef klass##Ptr Compressed##klass##Ptr;

Definition at line 266 of file tagged_pointer.h.

269 {
270 public:
271 OBJECT_POINTER_CORE_FUNCTIONS(CompressedObjectPtr, compressed_pointer_)
272
273 explicit CompressedObjectPtr(ObjectPtr uncompressed)
274 : compressed_pointer_(
275 static_cast<uint32_t>(static_cast<uword>(uncompressed))) {}
276 explicit constexpr CompressedObjectPtr(uword tagged)
277 : compressed_pointer_(static_cast<uint32_t>(tagged)) {}
278
279 ObjectPtr Decompress(uword heap_base) const {
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<
300 T,
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<
305 T,
306 typename std::enable_if<std::is_base_of<CompressedObjectPtr, T>::value,
307 void>::type> {
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 /* TODO: Return const pointer */ \
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) {} /* NOLINT */ \
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
365DEFINE_TAGGED_POINTER(Class, Object)
366DEFINE_TAGGED_POINTER(PatchClass, Object)
367DEFINE_TAGGED_POINTER(Function, Object)
368DEFINE_TAGGED_POINTER(ClosureData, Object)
369DEFINE_TAGGED_POINTER(FfiTrampolineData, Object)
370DEFINE_TAGGED_POINTER(Field, Object)
371DEFINE_TAGGED_POINTER(Script, Object)
372DEFINE_TAGGED_POINTER(Library, Object)
373DEFINE_TAGGED_POINTER(Namespace, Object)
374DEFINE_TAGGED_POINTER(KernelProgramInfo, Object)
375DEFINE_TAGGED_POINTER(WeakSerializationReference, Object)
376DEFINE_TAGGED_POINTER(WeakArray, Object)
377DEFINE_TAGGED_POINTER(Code, Object)
378DEFINE_TAGGED_POINTER(ObjectPool, Object)
379DEFINE_TAGGED_POINTER(Instructions, Object)
380DEFINE_TAGGED_POINTER(InstructionsSection, Object)
381DEFINE_TAGGED_POINTER(InstructionsTable, Object)
382DEFINE_TAGGED_POINTER(PcDescriptors, Object)
383DEFINE_TAGGED_POINTER(CodeSourceMap, Object)
384DEFINE_TAGGED_POINTER(CompressedStackMaps, Object)
385DEFINE_TAGGED_POINTER(LocalVarDescriptors, Object)
386DEFINE_TAGGED_POINTER(ExceptionHandlers, Object)
388DEFINE_TAGGED_POINTER(ContextScope, Object)
389DEFINE_TAGGED_POINTER(Sentinel, Object)
390DEFINE_TAGGED_POINTER(SingleTargetCache, Object)
391DEFINE_TAGGED_POINTER(UnlinkedCall, Object)
392DEFINE_TAGGED_POINTER(MonomorphicSmiableCall, Object)
393DEFINE_TAGGED_POINTER(CallSiteData, Object)
394DEFINE_TAGGED_POINTER(ICData, CallSiteData)
395DEFINE_TAGGED_POINTER(MegamorphicCache, CallSiteData)
396DEFINE_TAGGED_POINTER(SubtypeTestCache, Object)
397DEFINE_TAGGED_POINTER(LoadingUnit, Object)
398DEFINE_TAGGED_POINTER(Error, Object)
399DEFINE_TAGGED_POINTER(ApiError, Error)
400DEFINE_TAGGED_POINTER(LanguageError, Error)
401DEFINE_TAGGED_POINTER(UnhandledException, Error)
402DEFINE_TAGGED_POINTER(UnwindError, Error)
403DEFINE_TAGGED_POINTER(Instance, Object)
404DEFINE_TAGGED_POINTER(LibraryPrefix, Instance)
405DEFINE_TAGGED_POINTER(TypeArguments, Instance)
406DEFINE_TAGGED_POINTER(TypeParameters, Object)
407DEFINE_TAGGED_POINTER(AbstractType, Instance)
408DEFINE_TAGGED_POINTER(Type, AbstractType)
409DEFINE_TAGGED_POINTER(FunctionType, AbstractType)
410DEFINE_TAGGED_POINTER(RecordType, AbstractType)
411DEFINE_TAGGED_POINTER(TypeParameter, AbstractType)
412DEFINE_TAGGED_POINTER(Closure, Instance)
413DEFINE_TAGGED_POINTER(Number, Instance)
414DEFINE_TAGGED_POINTER(Integer, Number)
415DEFINE_TAGGED_POINTER(Smi, Integer)
416DEFINE_TAGGED_POINTER(Mint, Integer)
417DEFINE_TAGGED_POINTER(Double, Number)
418DEFINE_TAGGED_POINTER(String, Instance)
419DEFINE_TAGGED_POINTER(OneByteString, String)
420DEFINE_TAGGED_POINTER(TwoByteString, String)
421DEFINE_TAGGED_POINTER(Record, Instance)
422DEFINE_TAGGED_POINTER(PointerBase, Instance)
423DEFINE_TAGGED_POINTER(TypedDataBase, PointerBase)
424DEFINE_TAGGED_POINTER(TypedData, TypedDataBase)
425DEFINE_TAGGED_POINTER(TypedDataView, TypedDataBase)
426DEFINE_TAGGED_POINTER(Bool, Instance)
427DEFINE_TAGGED_POINTER(Array, Instance)
428DEFINE_TAGGED_POINTER(ImmutableArray, Array)
429DEFINE_TAGGED_POINTER(GrowableObjectArray, Instance)
430DEFINE_TAGGED_POINTER(LinkedHashBase, Instance)
431DEFINE_TAGGED_POINTER(Map, LinkedHashBase)
432DEFINE_TAGGED_POINTER(Set, LinkedHashBase)
433DEFINE_TAGGED_POINTER(ConstMap, Map)
434DEFINE_TAGGED_POINTER(ConstSet, Set)
435DEFINE_TAGGED_POINTER(Float32x4, Instance)
436DEFINE_TAGGED_POINTER(Int32x4, Instance)
437DEFINE_TAGGED_POINTER(Float64x2, Instance)
438DEFINE_TAGGED_POINTER(ExternalTypedData, TypedDataBase)
439DEFINE_TAGGED_POINTER(Pointer, PointerBase)
440DEFINE_TAGGED_POINTER(DynamicLibrary, Instance)
441DEFINE_TAGGED_POINTER(Capability, Instance)
442DEFINE_TAGGED_POINTER(SendPort, Instance)
443DEFINE_TAGGED_POINTER(ReceivePort, Instance)
444DEFINE_TAGGED_POINTER(TransferableTypedData, Instance)
445DEFINE_TAGGED_POINTER(StackTrace, Instance)
446DEFINE_TAGGED_POINTER(SuspendState, Instance)
447DEFINE_TAGGED_POINTER(RegExp, Instance)
448DEFINE_TAGGED_POINTER(WeakProperty, Instance)
449DEFINE_TAGGED_POINTER(WeakReference, Instance)
450DEFINE_TAGGED_POINTER(FinalizerBase, Instance)
451DEFINE_TAGGED_POINTER(Finalizer, Instance)
452DEFINE_TAGGED_POINTER(FinalizerEntry, Instance)
453DEFINE_TAGGED_POINTER(NativeFinalizer, Instance)
454DEFINE_TAGGED_POINTER(MirrorReference, Instance)
455DEFINE_TAGGED_POINTER(UserTag, Instance)
456DEFINE_TAGGED_POINTER(FutureOr, Instance)
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} // namespace dart
471
472#endif // RUNTIME_VM_TAGGED_POINTER_H_
#define ASSERT(E)
uint8_t value
void Decompress(const uint8_t *input, intptr_t input_len, uint8_t **output, intptr_t *output_length)
Definition gzip.cc:15
intptr_t RawSmiValue(const SmiPtr raw_value)
uintptr_t uword
Definition globals.h:501
ObjectPtr CompressedObjectPtr
Definition ref_ptr.h:256
#define T
#define DEFINE_TAGGED_POINTER(klass, base)
#define OBJECT_POINTER_CORE_FUNCTIONS(type, ptr)

◆ DEFINE_IS_CID [1/3]

#define DEFINE_IS_CID (   clazz)     bool Is##clazz() const { return ((GetClassId() == k##clazz##Cid)); }

Definition at line 109 of file tagged_pointer.h.

110 { return ((GetClassId() == k##clazz##Cid)); }

◆ DEFINE_IS_CID [2/3]

#define DEFINE_IS_CID (   clazz)
Value:
bool IsTypedData##clazz() const { \
return ((GetClassId() == kTypedData##clazz##Cid)); \
} \
bool IsTypedDataView##clazz() const { \
return ((GetClassId() == kTypedData##clazz##ViewCid)); \
} \
bool IsUnmodifiableTypedDataView##clazz() const { \
return ((GetClassId() == kUnmodifiableTypedData##clazz##ViewCid)); \
} \
bool IsExternalTypedData##clazz() const { \
return ((GetClassId() == kExternalTypedData##clazz##Cid)); \
}

Definition at line 109 of file tagged_pointer.h.

110 { return ((GetClassId() == k##clazz##Cid)); }

◆ DEFINE_IS_CID [3/3]

#define DEFINE_IS_CID (   clazz)     bool IsFfi##clazz() const { return ((GetClassId() == kFfi##clazz##Cid)); }

Definition at line 109 of file tagged_pointer.h.

110 { return ((GetClassId() == k##clazz##Cid)); }

◆ DEFINE_TAGGED_POINTER

#define DEFINE_TAGGED_POINTER (   klass,
  base 
)

Definition at line 332 of file tagged_pointer.h.

334 : 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 /* TODO: Return const pointer */ \
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) {} /* NOLINT */ \
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)
raw_obj untag() -> num_entries()) VARIABLE_COMPRESSED_VISITOR(Array, Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(TypedData, TypedData::ElementSizeInBytes(raw_obj->GetClassId()) *Smi::Value(raw_obj->untag() ->length())) VARIABLE_COMPRESSED_VISITOR(Record, RecordShape(raw_obj->untag() ->shape()).num_fields()) VARIABLE_NULL_VISITOR(CompressedStackMaps, CompressedStackMaps::PayloadSizeOf(raw_obj)) VARIABLE_NULL_VISITOR(OneByteString, Smi::Value(raw_obj->untag() ->length())) VARIABLE_NULL_VISITOR(TwoByteString, Smi::Value(raw_obj->untag() ->length())) intptr_t UntaggedField::VisitFieldPointers(FieldPtr raw_obj, ObjectPointerVisitor *visitor)

◆ OBJECT_POINTER_CORE_FUNCTIONS

#define OBJECT_POINTER_CORE_FUNCTIONS (   type,
  ptr 
)

Definition at line 20 of file tagged_pointer.h.

21 { \
22 return this; \
23 } \
24 const type* operator->() const { \
25 return this; \
26 } \
27 bool IsWellFormed() const { \
28 const uword value = ptr; \
29 return (value & kSmiTagMask) == 0 || \
30 Utils::IsAligned(value - kHeapObjectTag, kWordSize); \
31 } \
32 bool IsImmediateObject() const { \
33 ASSERT(IsWellFormed()); \
34 const uword value = ptr; \
35 return (value & kSmiTagMask) != kHeapObjectTag; \
36 } \
37 bool IsHeapObject() const { \
38 ASSERT(IsWellFormed()); \
39 const uword value = ptr; \
40 return (value & kSmiTagMask) == kHeapObjectTag; \
41 } \
42 /* Assumes this is a heap object. */ \
43 bool IsNewObject() const { \
44 ASSERT(IsHeapObject()); \
45 const uword addr = ptr; \
46 return (addr & kNewObjectAlignmentOffset) == kNewObjectAlignmentOffset; \
47 } \
48 bool IsNewObjectMayBeSmi() const { \
49 const uword kNewObjectBits = (kNewObjectAlignmentOffset | kHeapObjectTag); \
50 const uword addr = ptr; \
51 return (addr & kObjectAlignmentMask) == kNewObjectBits; \
52 } \
53 /* Assumes this is a heap object. */ \
54 bool IsOldObject() const { \
55 ASSERT(IsHeapObject()); \
56 const uword addr = ptr; \
57 return (addr & kNewObjectAlignmentOffset) == kOldObjectAlignmentOffset; \
58 } \
59 \
60 /* Like !IsHeapObject() || IsOldObject() but compiles to a single branch. */ \
61 bool IsImmediateOrOldObject() const { \
62 ASSERT(IsWellFormed()); \
63 const uword kNewObjectBits = (kNewObjectAlignmentOffset | kHeapObjectTag); \
64 const uword addr = ptr; \
65 return (addr & kObjectAlignmentMask) != kNewObjectBits; \
66 } \
67 \
68 /* Like !IsHeapObject() || IsNewObject() but compiles to a single branch. */ \
69 bool IsImmediateOrNewObject() const { \
70 ASSERT(IsWellFormed()); \
71 const uword kOldObjectBits = (kOldObjectAlignmentOffset | kHeapObjectTag); \
72 const uword addr = ptr; \
73 return (addr & kObjectAlignmentMask) != kOldObjectBits; \
74 } \
75 \
76 bool operator==(const type& other) { \
77 return (ptr & kSmiTagMask) == kHeapObjectTag \
78 ? ptr == other.ptr \
79 : static_cast<compressed_uword>(ptr) == \
80 static_cast<compressed_uword>(other.ptr); \
81 } \
82 bool operator!=(const type& other) { \
83 return (ptr & kSmiTagMask) == kHeapObjectTag \
84 ? ptr != other.ptr \
85 : static_cast<compressed_uword>(ptr) != \
86 static_cast<compressed_uword>(other.ptr); \
87 } \
88 constexpr bool operator==(const type& other) const { \
89 return (ptr & kSmiTagMask) == kHeapObjectTag \
90 ? ptr == other.ptr \
91 : static_cast<compressed_uword>(ptr) == \
92 static_cast<compressed_uword>(other.ptr); \
93 } \
94 constexpr bool operator!=(const type& other) const { \
95 return (ptr & kSmiTagMask) == kHeapObjectTag \
96 ? ptr != other.ptr \
97 : static_cast<compressed_uword>(ptr) != \
98 static_cast<compressed_uword>(other.ptr); \
99 }
bool operator!=(const sk_sp< T > &a, const sk_sp< U > &b)
Definition SkRefCnt.h:355
bool operator==(const FlutterPoint &a, const FlutterPoint &b)
InvalidClass kNewObjectAlignmentOffset
InvalidClass kOldObjectAlignmentOffset
@ kHeapObjectTag
uintptr_t compressed_uword
Definition globals.h:44