Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
Public Types | Public Member Functions | Static Public Attributes | Friends | List of all members
dart::ObjectIdRing Class Reference

#include <object_id_ring.h>

Public Types

enum  LookupResult { kValid = 0 , kInvalid , kCollected , kExpired }
 
enum  IdPolicy { kAllocateId , kReuseId , kNumIdPolicy }
 

Public Member Functions

 ObjectIdRing ()
 
 ~ObjectIdRing ()
 
int32_t GetIdForObject (ObjectPtr raw_obj, IdPolicy policy=kAllocateId)
 
ObjectPtr GetObjectForId (int32_t id, LookupResult *kind)
 
void VisitPointers (ObjectPointerVisitor *visitor)
 
void PrintJSON (JSONStream *js)
 

Static Public Attributes

static constexpr int32_t kMaxId = 0x3FFFFFFF
 
static constexpr int32_t kInvalidId = -1
 
static constexpr int32_t kDefaultCapacity = 8192
 

Friends

class ObjectIdRingTestHelper
 

Detailed Description

Definition at line 22 of file object_id_ring.h.

Member Enumeration Documentation

◆ IdPolicy

Enumerator
kAllocateId 
kReuseId 
kNumIdPolicy 

Definition at line 31 of file object_id_ring.h.

31 {
32 kAllocateId, // Always allocate a new object id.
33 kReuseId, // If the object is already in the ring, reuse id.
34 // Otherwise allocate a new object id.
36 };

◆ LookupResult

Enumerator
kValid 
kInvalid 
kCollected 
kExpired 

Definition at line 24 of file object_id_ring.h.

24 {
25 kValid = 0,
26 kInvalid, // Malformed ring id (used in service.cc).
27 kCollected, // Entry was reclaimed due to a full GC (entries are weak).
28 kExpired, // Entry was evicted during an insertion into a full ring.
29 };

Constructor & Destructor Documentation

◆ ObjectIdRing()

dart::ObjectIdRing::ObjectIdRing ( )

Definition at line 89 of file object_id_ring.cc.

89 {
90 serial_num_ = 0;
91 wrapped_ = false;
92 table_ = nullptr;
93 SetCapacityAndMaxSerial(kDefaultCapacity, kMaxId);
94}
static constexpr int32_t kDefaultCapacity
static constexpr int32_t kMaxId

◆ ~ObjectIdRing()

dart::ObjectIdRing::~ObjectIdRing ( )

Definition at line 15 of file object_id_ring.cc.

15 {
16 ASSERT(table_ != nullptr);
17 free(table_);
18 table_ = nullptr;
19}
#define ASSERT(E)

Member Function Documentation

◆ GetIdForObject()

int32_t dart::ObjectIdRing::GetIdForObject ( ObjectPtr  raw_obj,
IdPolicy  policy = kAllocateId 
)

Definition at line 21 of file object_id_ring.cc.

21 {
22 // We do not allow inserting null because null is how we detect as entry was
23 // reclaimed by the GC.
24 ASSERT(object != Object::null());
25 if (policy == kAllocateId) {
26 return AllocateNewId(object);
27 }
28 ASSERT(policy == kReuseId);
29 int32_t id = FindExistingIdForObject(object);
30 if (id != kInvalidId) {
31 // Return a previous id for |object|.
32 return id;
33 }
34 return AllocateNewId(object);
35}
static constexpr int32_t kInvalidId
static ObjectPtr null()
Definition object.h:433
const uintptr_t id

◆ GetObjectForId()

ObjectPtr dart::ObjectIdRing::GetObjectForId ( int32_t  id,
LookupResult kind 
)

Definition at line 46 of file object_id_ring.cc.

46 {
47 int32_t index = IndexOfId(id);
48 if (index == kInvalidId) {
49 *kind = kExpired;
50 return Object::null();
51 }
52 ASSERT(index >= 0);
53 ASSERT(index < capacity_);
54 if (table_[index] == Object::null()) {
55 *kind = kCollected;
56 return Object::null();
57 }
58 *kind = kValid;
59 ASSERT(IdOfIndex(index) == id);
60 return table_[index];
61}

◆ PrintJSON()

void dart::ObjectIdRing::PrintJSON ( JSONStream js)

Definition at line 68 of file object_id_ring.cc.

68 {
69 Thread* thread = Thread::Current();
70 Zone* zone = thread->zone();
71 ASSERT(zone != nullptr);
72 JSONObject jsobj(js);
73 jsobj.AddProperty("type", "_IdZone");
74 jsobj.AddProperty("name", "default");
75 {
76 JSONArray objects(&jsobj, "objects");
77 Object& obj = Object::Handle();
78 for (int32_t i = 0; i < capacity_; i++) {
79 obj = table_[i];
80 if (obj.IsNull()) {
81 // Collected object.
82 continue;
83 }
84 objects.AddValue(obj, false);
85 }
86 }
87}
static Object & Handle()
Definition object.h:407
static Thread * Current()
Definition thread.h:361

◆ VisitPointers()

void dart::ObjectIdRing::VisitPointers ( ObjectPointerVisitor visitor)

Definition at line 63 of file object_id_ring.cc.

63 {
64 ASSERT(table_ != nullptr);
65 visitor->VisitPointers(table_, capacity_);
66}

Friends And Related Symbol Documentation

◆ ObjectIdRingTestHelper

friend class ObjectIdRingTestHelper
friend

Definition at line 57 of file object_id_ring.h.

Member Data Documentation

◆ kDefaultCapacity

constexpr int32_t dart::ObjectIdRing::kDefaultCapacity = 8192
staticconstexpr

Definition at line 40 of file object_id_ring.h.

◆ kInvalidId

constexpr int32_t dart::ObjectIdRing::kInvalidId = -1
staticconstexpr

Definition at line 39 of file object_id_ring.h.

◆ kMaxId

constexpr int32_t dart::ObjectIdRing::kMaxId = 0x3FFFFFFF
staticconstexpr

Definition at line 38 of file object_id_ring.h.


The documentation for this class was generated from the following files: