5#ifndef RUNTIME_VM_HANDLES_IMPL_H_
6#define RUNTIME_VM_HANDLES_IMPL_H_
14template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
18 HandlesBlock* block = zone_blocks_;
19 while (block !=
nullptr) {
20 block->VisitObjectPointers(visitor);
21 block = block->next_block();
25 VisitScopedHandles(visitor);
28template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
31 HandlesBlock* block = &first_scoped_block_;
33 block->VisitObjectPointers(visitor);
34 if (block == scoped_blocks_) {
37 block = block->next_block();
38 }
while (block !=
nullptr);
42template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
46 HandlesBlock* block = zone_blocks_;
47 while (block !=
nullptr) {
48 block->Visit(visitor);
49 block = block->next_block();
53 block = &first_scoped_block_;
55 block->Visit(visitor);
56 block = block->next_block();
57 }
while (block !=
nullptr);
60template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
64 if (zone_blocks_ !=
nullptr) {
65 DeleteHandleBlocks(zone_blocks_->next_block());
66 zone_blocks_->ReInit();
71 DeleteHandleBlocks(first_scoped_block_.next_block());
72 first_scoped_block_.ReInit();
73 scoped_blocks_ = &first_scoped_block_;
79template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
87 ASSERT(handles !=
nullptr);
93template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
102 ASSERT(handles !=
nullptr);
103 uword address = handles->AllocateHandleInZone();
110template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
116 ASSERT(thread !=
nullptr);
119 ASSERT(handles !=
nullptr);
124template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
125void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
131 DeleteHandleBlocks(zone_blocks_);
132 zone_blocks_ =
nullptr;
135 scoped_blocks_ = first_scoped_block_.next_block();
136 DeleteHandleBlocks(scoped_blocks_);
137 first_scoped_block_.ReInit();
138 scoped_blocks_ = &first_scoped_block_;
141template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
144 while (blocks !=
nullptr) {
145 HandlesBlock* block = blocks;
146 blocks = blocks->next_block();
151template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
152void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
153 SetupNextScopeBlock() {
154 if (FLAG_trace_handles) {
155 OS::PrintErr(
"*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n",
156 reinterpret_cast<intptr_t
>(
this), CountZoneHandles(),
157 CountScopedHandles());
159 if (scoped_blocks_->next_block() ==
nullptr) {
160 HandlesBlock* block =
new HandlesBlock(
nullptr);
161 scoped_blocks_->set_next_block(block);
163 scoped_blocks_ = scoped_blocks_->next_block();
164 scoped_blocks_->set_next_handle_slot(0);
166 scoped_blocks_->ZapFreeHandles();
173template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
176 const HandlesBlock* iterator = &first_scoped_block_;
177 while (iterator !=
nullptr) {
178 if (iterator->IsValidHandle(handle)) {
181 iterator = iterator->next_block();
186template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
189 const HandlesBlock* iterator = zone_blocks_;
190 while (iterator !=
nullptr) {
191 if (iterator->IsValidHandle(handle)) {
194 iterator = iterator->next_block();
199template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
202 if (FLAG_trace_handles) {
203 OS::PrintErr(
"*** Handle Counts for (0x%" Px "):Zone = %d,Scoped = %d\n",
204 reinterpret_cast<intptr_t
>(
this), CountZoneHandles(),
205 CountScopedHandles());
207 zone_blocks_ =
new HandlesBlock(zone_blocks_);
210template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
214 const HandlesBlock* block = &first_scoped_block_;
216 count += block->HandleCount();
217 if (block == scoped_blocks_) {
220 block = block->next_block();
221 }
while (block !=
nullptr);
226template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
230 const HandlesBlock* block = zone_blocks_;
231 while (block !=
nullptr) {
232 count += block->HandleCount();
233 block = block->next_block();
238template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
246template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
247void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
248 HandlesBlock::ReInit() {
249 next_handle_slot_ = 0;
250 next_block_ =
nullptr;
256template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
257void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
258 HandlesBlock::VisitObjectPointers(ObjectPointerVisitor* visitor) {
259 ASSERT(visitor !=
nullptr);
260 for (intptr_t
i = 0;
i < next_handle_slot_;
i += kHandleSizeInWords) {
261 visitor->VisitPointer(
266template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
267void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
268 HandlesBlock::Visit(HandleVisitor* visitor) {
269 ASSERT(visitor !=
nullptr);
270 for (intptr_t
i = 0;
i < next_handle_slot_;
i += kHandleSizeInWords) {
271 visitor->VisitHandle(
reinterpret_cast<uword>(&data_[
i]));
276template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
277void Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
278 HandlesBlock::ZapFreeHandles() {
280 for (intptr_t
i = next_handle_slot_;
281 i < (kHandleSizeInWords * kHandlesPerChunk);
i++) {
287template <
int kHandleSizeInWords,
int kHandlesPerChunk,
int kOffsetOfRawPtr>
288int Handles<kHandleSizeInWords, kHandlesPerChunk, kOffsetOfRawPtr>::
289 HandlesBlock::HandleCount()
const {
290 return (next_handle_slot_ / kHandleSizeInWords);
int CountZoneHandles() const
static uword AllocateZoneHandle(Zone *zone)
bool IsValidZoneHandle(uword handle) const
void Visit(HandleVisitor *visitor)
void VisitObjectPointers(ObjectPointerVisitor *visitor)
uword AllocateScopedHandle()
int CountScopedHandles() const
void VisitScopedHandles(ObjectPointerVisitor *visitor)
static uword AllocateHandle(Zone *zone)
bool IsValidScopedHandle(uword handle) const
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
static Thread * Current()
virtual bool MayAllocateHandles()
bool ContainsNestedZone(Zone *other) const
static constexpr uword kZapUninitializedWord
static constexpr int kOffsetOfRawPtr
constexpr intptr_t kWordSize