Flutter Engine
The Flutter Engine
handles.cc
Go to the documentation of this file.
1// Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file
2// for details. All rights reserved. Use of this source code is governed by a
3// BSD-style license that can be found in the LICENSE file.
4
5#include "vm/handles.h"
6
7#include "platform/assert.h"
8#include "platform/utils.h"
9#include "vm/dart_api_state.h"
10#include "vm/flags.h"
11#include "vm/os.h"
12#include "vm/raw_object.h"
13#include "vm/visitor.h"
14#include "vm/zone.h"
15
16#include "vm/handles_impl.h"
17
18namespace dart {
19
23}
24
25#if defined(DEBUG)
26static bool IsCurrentApiNativeScope(Zone* zone) {
28 return (scope != nullptr) && (scope->zone() == zone);
29}
30#endif // DEBUG
31
33 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone));
36#if defined(DEBUG)
37 *reinterpret_cast<uword*>(handle + kOffsetOfIsZoneHandle * kWordSize) = 0;
38#endif
39 return handle;
40}
41
43 DEBUG_ASSERT(!IsCurrentApiNativeScope(zone));
46#if defined(DEBUG)
47 *reinterpret_cast<uword*>(handle + kOffsetOfIsZoneHandle * kWordSize) = 1;
48#endif
49 return handle;
50}
51
52#if defined(DEBUG)
53bool VMHandles::IsZoneHandle(uword handle) {
54 return *reinterpret_cast<uword*>(handle +
55 kOffsetOfIsZoneHandle * kWordSize) != 0;
56}
57#endif
58
60 Thread* thread = Thread::Current();
61 ASSERT(thread->zone() != nullptr);
62 VMHandles* handles = thread->zone()->handles();
63 return handles->CountScopedHandles();
64}
65
67 Thread* thread = Thread::Current();
68 ASSERT(thread->zone() != nullptr);
69 VMHandles* handles = thread->zone()->handles();
70 return handles->CountZoneHandles();
71}
72
73void HandleScope::Initialize() {
74 ASSERT(thread()->MayAllocateHandles());
75 VMHandles* handles = thread()->zone()->handles();
76 ASSERT(handles != nullptr);
77 saved_handle_block_ = handles->scoped_blocks_;
78 saved_handle_slot_ = handles->scoped_blocks_->next_handle_slot();
79#if defined(DEBUG)
80 link_ = thread()->top_handle_scope();
82#endif
83}
84
86 Initialize();
87}
88
90 ASSERT(thread()->zone() != nullptr);
91 VMHandles* handles = thread()->zone()->handles();
92 ASSERT(handles != nullptr);
93#if defined(DEBUG)
94 VMHandles::HandlesBlock* last = handles->scoped_blocks_;
95#endif
96 handles->scoped_blocks_ = saved_handle_block_;
97 handles->scoped_blocks_->set_next_handle_slot(saved_handle_slot_);
98#if defined(DEBUG)
99 VMHandles::HandlesBlock* block = handles->scoped_blocks_;
100 for (;;) {
101 block->ZapFreeHandles();
102 if (block == last) break;
103 block = block->next_block();
104 }
105 ASSERT(thread()->top_handle_scope() == this);
107#endif
108}
109
110} // namespace dart
#define DEBUG_ASSERT(cond)
Definition: assert.h:321
static ApiNativeScope * Current()
HandleScope(ThreadState *thread)
Definition: handles.cc:85
int CountZoneHandles() const
Definition: handles_impl.h:228
int CountScopedHandles() const
Definition: handles_impl.h:212
ThreadState * thread() const
Definition: allocation.h:33
Zone * zone() const
Definition: thread_state.h:37
void set_top_handle_scope(HandleScope *handle_scope)
Definition: thread_state.h:65
HandleScope * top_handle_scope() const
Definition: thread_state.h:57
static Thread * Current()
Definition: thread.h:362
static int ZoneHandleCount()
Definition: handles.cc:66
static uword AllocateZoneHandle(Zone *zone)
Definition: handles.cc:42
static uword AllocateHandle(Zone *zone)
Definition: handles.cc:32
void VisitObjectPointers(ObjectPointerVisitor *visitor)
Definition: handles.cc:20
static int ScopedHandleCount()
Definition: handles.cc:59
VMHandles * handles()
Definition: zone.h:73
#define ASSERT(E)
Definition: dart_vm.cc:33
static constexpr int kVMHandleSizeInWords
Definition: handles.h:238
static constexpr int kVMHandlesPerChunk
Definition: handles.h:240
uintptr_t uword
Definition: globals.h:501
static constexpr int kOffsetOfRawPtr
Definition: handles.h:241
constexpr intptr_t kWordSize
Definition: globals.h:509