5#ifndef RUNTIME_VM_HEAP_WEAK_TABLE_H_
6#define RUNTIME_VM_HEAP_WEAK_TABLE_H_
24 if (
size < kMinSize) {
28 const intptr_t kMaxSize =
31 if (
size > kMaxSize) {
36 data_ =
reinterpret_cast<intptr_t*
>(
malloc(size_ * kEntrySize *
kWordSize));
37 for (intptr_t
i = 0;
i < size_;
i++) {
38 data_[ObjectIndex(
i)] = kNoEntry;
49 intptr_t
size()
const {
return size_; }
50 intptr_t
used()
const {
return used_; }
51 intptr_t
count()
const {
return count_; }
82 (data_[ObjectIndex(
i)] == kNoEntry ||
83 data_[ObjectIndex(
i)] == kDeletedEntry)) ||
85 data_[ObjectIndex(
i)] != kDeletedEntry));
86 return (data_[ValueIndex(
i)] != 0);
97 return static_cast<ObjectPtr>(data_[ObjectIndex(
i)]);
103 return data_[ValueIndex(
i)];
110 intptr_t mask =
size() - 1;
111 intptr_t idx = Hash(
key) & mask;
113 while (obj !=
static_cast<ObjectPtr>(kNoEntry)) {
117 idx = (idx + 1) & mask;
127 intptr_t mask =
size() - 1;
128 intptr_t idx = Hash(
key) & mask;
130 while (obj !=
static_cast<ObjectPtr>(kNoEntry)) {
136 idx = (idx + 1) & mask;
157 static constexpr intptr_t kNoEntry = 1;
158 static constexpr intptr_t kDeletedEntry = 3;
159 static constexpr intptr_t kMinSize = 8;
161 static intptr_t SizeFor(intptr_t
count, intptr_t
size);
162 static intptr_t LimitFor(intptr_t
size) {
164 return 3 * (
size / 4);
166 intptr_t limit()
const {
return LimitFor(
size()); }
168 intptr_t index(intptr_t
i)
const {
return i * kEntrySize; }
170 void set_used(intptr_t val) {
175 void set_count(intptr_t val) {
181 intptr_t ObjectIndex(intptr_t
i)
const {
return index(
i) + kObjectOffset; }
183 intptr_t ValueIndex(intptr_t
i)
const {
return index(
i) + kValueOffset; }
185 ObjectPtr* ObjectPointerAt(intptr_t
i)
const {
188 return reinterpret_cast<ObjectPtr*
>(&data_[ObjectIndex(
i)]);
191 void SetObjectAt(intptr_t
i, ObjectPtr
key) {
194 data_[ObjectIndex(
i)] =
static_cast<intptr_t
>(
key);
197 void SetValueAt(intptr_t
i, intptr_t val) {
202 data_[ObjectIndex(
i)] = kDeletedEntry;
203 set_count(
count() - 1);
205 data_[ValueIndex(
i)] = val;
static constexpr bool IsPowerOfTwo(T x)
static constexpr intptr_t kNoValue
static WeakTable * NewFrom(WeakTable *original)
bool MarkValueExclusive(ObjectPtr key, intptr_t val)
intptr_t ValueAtExclusive(intptr_t i) const
intptr_t RemoveValueExclusive(ObjectPtr key)
void SetValueExclusive(ObjectPtr key, intptr_t val)
intptr_t GetValue(ObjectPtr key)
intptr_t GetValueExclusive(ObjectPtr key) const
bool IsValidEntryAtExclusive(intptr_t i) const
intptr_t SetValueIfNonExistent(ObjectPtr key, intptr_t val)
void ReportSurvivingAllocations(Dart_HeapSamplingReportCallback callback, void *context)
ObjectPtr ObjectAtExclusive(intptr_t i) const
void Forward(ObjectPointerVisitor *visitor)
void SetValue(ObjectPtr key, intptr_t val)
void InvalidateAtExclusive(intptr_t i)
void CleanupValues(Dart_HeapSamplingDeleteCallback cleanup)
void(* Dart_HeapSamplingDeleteCallback)(void *data)
void(* Dart_HeapSamplingReportCallback)(void *context, void *data)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
constexpr intptr_t kBitsPerWord
void * malloc(size_t size)
constexpr intptr_t kIntptrOne
constexpr intptr_t kWordSize