5#ifndef RUNTIME_VM_DART_API_STATE_H_
6#define RUNTIME_VM_DART_API_STATE_H_
35 Zone* zone = thread !=
nullptr ? thread->
zone() :
nullptr;
37 if (thread !=
nullptr) {
38 thread->set_zone(&zone_);
40 if (FLAG_trace_zones) {
42 reinterpret_cast<intptr_t
>(
this),
43 reinterpret_cast<intptr_t
>(&zone_));
51 if (thread ==
nullptr) {
56 if ((thread !=
nullptr) && (thread->
zone() == &zone_)) {
57 thread->set_zone(zone_.previous_);
59 if (FLAG_trace_zones) {
61 reinterpret_cast<intptr_t
>(
this),
62 reinterpret_cast<intptr_t
>(&zone_));
69 template <
class ElementType>
71 return zone_.
Alloc<ElementType>(
len);
77 template <
class ElementType>
78 ElementType*
Realloc(ElementType* old_array,
81 return zone_.
Realloc<ElementType>(old_array, old_len, new_len);
99 if (thread ==
nullptr) {
102 zone_.Link(thread->
zone());
103 thread->set_zone(&zone_);
108 if ((thread !=
nullptr) && (thread->
zone() == &zone_)) {
109 thread->set_zone(zone_.previous_);
117 template <
typename T>
139 DISALLOW_ALLOCATION();
140 DISALLOW_COPY_AND_ASSIGN(LocalHandle);
174 PersistentHandle* Next() {
175 return reinterpret_cast<PersistentHandle*
>(
static_cast<uword>(ptr_));
177 void SetNext(PersistentHandle* free_list) {
178 ptr_ =
static_cast<ObjectPtr
>(
reinterpret_cast<uword>(free_list));
179 ASSERT(!ptr_->IsHeapObject());
181 void FreeHandle(PersistentHandle* free_list) { SetNext(free_list); }
205 void*
peer()
const {
return peer_; }
217 return ptr_ ==
static_cast<ObjectPtr>(
reinterpret_cast<uword>(
this));
231 set_external_size(
size);
233 SetExternalNewSpaceBit();
242 Finalize(isolate_group,
this);
247 if (IsSetNewSpaceBit() && (SpaceForExternal() ==
Heap::kOld)) {
249 ClearExternalNewSpaceBit();
257 set_external_size(0);
265 kExternalNewSpaceBit = 0,
266 kExternalSizeBits = 1,
271 class ExternalSizeInWordsBits :
public BitField<uword,
274 kExternalSizeBitsSize> {};
277 class ExternalNewSpaceBit
278 :
public BitField<uword, bool, kExternalNewSpaceBit, 1> {};
283 : ptr_(nullptr), peer_(nullptr), external_data_(0), callback_(nullptr) {}
286 static void Finalize(IsolateGroup* isolate_group,
287 FinalizablePersistentHandle* handle);
291 FinalizablePersistentHandle* Next() {
292 return reinterpret_cast<FinalizablePersistentHandle*
>(
293 static_cast<uword>(ptr_));
295 void SetNext(FinalizablePersistentHandle* free_list) {
296 ptr_ =
static_cast<ObjectPtr
>(
reinterpret_cast<uword>(free_list));
297 ASSERT(!ptr_->IsHeapObject());
300 void SetFinalizedNotFreed() {
305 void FreeHandle(FinalizablePersistentHandle* free_list) {
315 auto_delete_ =
false;
318 void set_ptr(ObjectPtr raw) { ptr_ = raw; }
319 void set_ptr(
const LocalHandle& ref) { ptr_ = ref.ptr(); }
320 void set_ptr(
const Object&
object) { ptr_ =
object.ptr(); }
322 void set_peer(
void*
peer) { peer_ =
peer; }
328 void set_external_size(intptr_t
size) {
332 ExternalSizeInWordsBits::update(size_in_words, external_data_);
335 bool IsSetNewSpaceBit()
const {
339 void SetExternalNewSpaceBit() {
340 external_data_ = ExternalNewSpaceBit::update(
true, external_data_);
343 void ClearExternalNewSpaceBit() {
344 external_data_ = ExternalNewSpaceBit::update(
false, external_data_);
355 uword external_data_;
368 kLocalHandlesPerChunk,
369 kOffsetOfRawPtrInLocalHandle> {
375 if (FLAG_trace_handles) {
377 reinterpret_cast<intptr_t
>(
this));
381 if (FLAG_trace_handles) {
385 reinterpret_cast<intptr_t
>(
this));
428 kPersistentHandlesPerChunk,
429 kOffsetOfRawPtrInPersistentHandle> {
435 free_list_(nullptr) {
436 if (FLAG_trace_handles) {
437 OS::PrintErr(
"*** Starting a new Persistent handle block 0x%" Px "\n",
438 reinterpret_cast<intptr_t
>(
this));
442 free_list_ =
nullptr;
443 if (FLAG_trace_handles) {
447 reinterpret_cast<intptr_t
>(
this));
473 if (free_list_ !=
nullptr) {
475 free_list_ = handle->Next();
495 while (handle !=
nullptr) {
499 handle = handle->Next();
518 :
Handles<kFinalizablePersistentHandleSizeInWords,
519 kFinalizablePersistentHandlesPerChunk,
520 kOffsetOfRawPtrInFinalizablePersistentHandle> {
526 free_list_(nullptr) {}
554 if (free_list_ !=
nullptr) {
556 free_list_ = handle->Next();
569 handle->SetFinalizedNotFreed();
588 while (handle !=
nullptr) {
592 handle = handle->Next();
622 local_handles_.
Reset();
650 reinterpret_cast<uword>(
this));
697 ApiState() : persistent_handles_(), weak_persistent_handles_() {}
731 weak_persistent_handles_.
FreeHandle(weak_ref);
769 fun(persistent_handles_);
775 fun(weak_persistent_handles_);
795 intptr_t external_size,
800 ref->set_ptr(
object);
806 state->FreeWeakPersistentHandle(ref);
static bool is_valid(SkISize dim)
ApiGrowableArray(int initial_capacity)
ApiGrowableArray(intptr_t initial_capacity, Zone *zone)
uword stack_marker() const
void Reinit(Thread *thread, ApiLocalScope *previous, uword stack_marker)
void set_previous(ApiLocalScope *value)
LocalHandles * local_handles()
ApiLocalScope(ApiLocalScope *previous, uword stack_marker)
ApiLocalScope * previous() const
void Reset(Thread *thread)
static ApiNativeScope * Current()
void VisitWeakHandlesUnlocked(HandleVisitor *visitor)
bool IsActivePersistentHandle(Dart_PersistentHandle object)
WeakTable * acquired_table()
void ClearWeakPersistentHandle(FinalizablePersistentHandle *weak_ref)
bool IsValidPersistentHandle(Dart_PersistentHandle object)
PersistentHandle * AllocatePersistentHandle()
FinalizablePersistentHandle * AllocateWeakPersistentHandle()
void RunWithLockedWeakPersistentHandles(std::function< void(FinalizablePersistentHandles &)> fun)
void VisitObjectPointersUnlocked(ObjectPointerVisitor *visitor)
void MergeOtherApiState(ApiState *api_state)
bool IsValidWeakPersistentHandle(Dart_WeakPersistentHandle object)
void FreePersistentHandle(PersistentHandle *ref)
void FreeWeakPersistentHandle(FinalizablePersistentHandle *weak_ref)
bool IsValidFinalizableHandle(Dart_FinalizableHandle object)
int CountPersistentHandles()
bool IsActiveWeakPersistentHandle(Dart_WeakPersistentHandle object)
void RunWithLockedPersistentHandles(std::function< void(PersistentHandles &)> fun)
intptr_t SizeInBytes() const
void Reinit(Thread *thread)
uword AllocUnsafe(intptr_t size)
void Reset(Thread *thread)
ElementType * Alloc(intptr_t len)
ElementType * Realloc(ElementType *old_array, intptr_t old_len, intptr_t new_len)
static FinalizablePersistentHandle * New(IsolateGroup *isolate_group, const Object &object, void *peer, Dart_HandleFinalizer callback, intptr_t external_size, bool auto_delete)
Dart_HandleFinalizer callback() const
Dart_FinalizableHandle ApiFinalizableHandle()
intptr_t external_size() const
bool IsFinalizedNotFreed() const
void UpdateUnreachable(IsolateGroup *isolate_group)
static intptr_t ptr_offset()
void EnsureFreedExternal(IsolateGroup *isolate_group)
bool SetExternalSize(intptr_t size, IsolateGroup *isolate_group)
void UpdateRelocated(IsolateGroup *isolate_group)
Dart_WeakPersistentHandle ApiWeakPersistentHandle()
static FinalizablePersistentHandle * Cast(Dart_WeakPersistentHandle handle)
void ClearHandle(FinalizablePersistentHandle *handle)
void FreeHandle(FinalizablePersistentHandle *handle)
FinalizablePersistentHandles()
FinalizablePersistentHandle * AllocateHandle()
~FinalizablePersistentHandles()
void set_free_list(FinalizablePersistentHandle *value)
bool IsFreeHandle(Dart_WeakPersistentHandle object) const
void VisitHandles(HandleVisitor *visitor)
bool IsValidHandle(Dart_WeakPersistentHandle object) const
FinalizablePersistentHandle * free_list() const
bool IsValidHandle(Dart_FinalizableHandle object) const
void VisitObjectPointers(ObjectPointerVisitor *visitor)
int CountZoneHandles() const
void Visit(HandleVisitor *visitor)
uword AllocateScopedHandle()
int CountScopedHandles() const
bool IsValidScopedHandle(uword handle) const
bool AllocatedExternal(intptr_t size, Space space)
void PromotedExternal(intptr_t size)
void FreedExternal(intptr_t size, Space space)
ApiState * api_state() const
void set_ptr(ObjectPtr ptr)
static intptr_t ptr_offset()
LocalHandle * AllocateHandle()
void VisitObjectPointers(ObjectPointerVisitor *visitor)
bool IsValidHandle(Dart_Handle object) const
static uword GetThreadLocal(ThreadLocalKey key)
static void SetThreadLocal(ThreadLocalKey key, uword value)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
void clear_gc_root_type()
void set_gc_root_type(const char *gc_root_type)
virtual bool visit_weak_persistent_handles() const
Dart_PersistentHandle apiHandle()
void set_ptr(const Object &object)
static intptr_t ptr_offset()
void set_ptr(const LocalHandle &ref)
void set_ptr(ObjectPtr ref)
static PersistentHandle * Cast(Dart_PersistentHandle handle)
PersistentHandle * AllocateHandle()
bool IsValidHandle(Dart_PersistentHandle object) const
PersistentHandle * free_list() const
void VisitObjectPointers(ObjectPointerVisitor *visitor)
void FreeHandle(PersistentHandle *handle)
void Visit(HandleVisitor *visitor)
bool IsFreeHandle(Dart_PersistentHandle object) const
void set_free_list(PersistentHandle *value)
static Thread * Current()
static constexpr T RoundUp(T x, uintptr_t alignment, uintptr_t offset=0)
void * AllocUnsafe(intptr_t size)
uintptr_t SizeInBytes() const
ElementType * Realloc(ElementType *old_array, intptr_t old_length, intptr_t new_length)
ElementType * Alloc(intptr_t length)
struct _Dart_Handle * Dart_Handle
void(* Dart_HandleFinalizer)(void *isolate_callback_data, void *peer)
Dart_Handle Dart_PersistentHandle
struct _Dart_FinalizableHandle * Dart_FinalizableHandle
struct _Dart_WeakPersistentHandle * Dart_WeakPersistentHandle
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
Dart_NativeFunction function
static constexpr int kPersistentHandlesPerChunk
static constexpr int kLocalHandlesPerChunk
constexpr intptr_t kBitsPerWord
static constexpr int kPersistentHandleSizeInWords
static constexpr int kOffsetOfRawPtrInPersistentHandle
void ProtectedHandleCallback(void *peer)
static constexpr int kOffsetOfRawPtrInLocalHandle
constexpr intptr_t kWordSizeLog2
static constexpr int kFinalizablePersistentHandleSizeInWords
static constexpr int kFinalizablePersistentHandlesPerChunk
static constexpr int kLocalHandleSizeInWords
constexpr intptr_t kWordSize
Heap::Space SpaceForExternal(FinalizerEntryPtr raw_entry)
static constexpr intptr_t kObjectAlignment
const intptr_t kMaxAddrSpaceInWords
static constexpr int kOffsetOfRawPtrInFinalizablePersistentHandle
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font Indicates whether the embedding started a prefetch of the default font manager before creating the engine run In non interactive keep the shell running after the Dart script has completed enable serial On low power devices with low core running concurrent GC tasks on threads can cause them to contend with the UI thread which could potentially lead to jank This option turns off all concurrent GC activities domain network JSON encoded network policy per domain This overrides the DisallowInsecureConnections switch Embedder can specify whether to allow or disallow insecure connections at a domain level old gen heap size
static DecodeResult decode(std::string path)
#define OFFSET_OF(type, field)