Flutter Engine
The Flutter Engine
Loading...
Searching...
No Matches
isolate.h
Go to the documentation of this file.
1// Copyright (c) 2013, 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#ifndef RUNTIME_VM_ISOLATE_H_
6#define RUNTIME_VM_ISOLATE_H_
7
8#if defined(SHOULD_NOT_INCLUDE_RUNTIME)
9#error "Should not include runtime"
10#endif
11
12#include <functional>
13#include <memory>
14#include <utility>
15
16#include "include/dart_api.h"
17#include "platform/assert.h"
18#include "platform/atomic.h"
19#include "vm/base_isolate.h"
20#include "vm/class_table.h"
21#include "vm/dispatch_table.h"
22#include "vm/exceptions.h"
24#include "vm/field_table.h"
25#include "vm/fixed_cache.h"
26#include "vm/growable_array.h"
27#include "vm/handles.h"
28#include "vm/heap/verifier.h"
29#include "vm/intrusive_dlist.h"
31#include "vm/metrics.h"
32#include "vm/os_thread.h"
33#include "vm/random.h"
34#include "vm/tags.h"
35#include "vm/thread.h"
36#include "vm/thread_pool.h"
38#include "vm/token_position.h"
39#include "vm/virtual_memory.h"
40
41namespace dart {
42
43// Forward declarations.
44class ApiState;
45class BackgroundCompiler;
46class Become;
47class Capability;
48class CodeIndexTable;
49class Debugger;
50class DeoptContext;
51class ExternalTypedData;
52class GroupDebugger;
53class HandleScope;
54class HandleVisitor;
55class Heap;
56class ICData;
57class IsolateGroupReloadContext;
58class IsolateMessageHandler;
59class IsolateObjectStore;
60class IsolateProfilerData;
61class Log;
62class Message;
63class MessageHandler;
64class MonitorLocker;
65class Mutex;
66class Object;
67class ObjectIdRing;
68class ObjectPointerVisitor;
69class ObjectStore;
70class PersistentHandle;
71class ProgramReloadContext;
72class RwLock;
73class SafepointHandler;
74class SafepointRwLock;
75class SampleBlock;
76class SampleBlockBuffer;
77class SampleBuffer;
78class SendPort;
79class SerializedObjectBuffer;
80class ServiceIdZone;
81class Simulator;
82class StackResource;
83class StackZone;
84class StoreBuffer;
85class StubCode;
86class ThreadRegistry;
87class UserTag;
88class WeakTable;
89
91 public:
93 virtual ~IsolateVisitor() {}
94
95 virtual void VisitIsolate(Isolate* isolate) = 0;
96
97 protected:
98 // Returns true if |isolate| is the VM or service isolate.
99 bool IsSystemIsolate(Isolate* isolate) const;
100
101 private:
103};
104
105class Callable : public ValueObject {
106 public:
108 virtual ~Callable() {}
109
110 virtual void Call() = 0;
111
112 private:
114};
115
116template <typename T>
117class LambdaCallable : public Callable {
118 public:
119 explicit LambdaCallable(T& lambda) : lambda_(lambda) {}
120 void Call() { lambda_(); }
121
122 private:
123 T& lambda_;
125};
126
127// Fixed cache for exception handler lookup.
129// Fixed cache for catch entry state lookup.
131
132// List of Isolate group flags.
133//
134// V(when, name, bit-name, Dart_IsolateFlags-name, command-line-flag-name)
135//
136#define BOOL_ISOLATE_GROUP_FLAG_LIST(V) \
137 V(PRECOMPILER, obfuscate, Obfuscate, obfuscate, false) \
138 V(NONPRODUCT, asserts, EnableAsserts, enable_asserts, FLAG_enable_asserts) \
139 V(NONPRODUCT, use_field_guards, UseFieldGuards, use_field_guards, \
140 FLAG_use_field_guards) \
141 V(PRODUCT, should_load_vmservice_library, ShouldLoadVmService, \
142 load_vmservice_library, false) \
143 V(NONPRODUCT, use_osr, UseOsr, use_osr, FLAG_use_osr) \
144 V(NONPRODUCT, snapshot_is_dontneed_safe, SnapshotIsDontNeedSafe, \
145 snapshot_is_dontneed_safe, false) \
146 V(NONPRODUCT, branch_coverage, BranchCoverage, branch_coverage, \
147 FLAG_branch_coverage)
148
149// List of Isolate flags with corresponding members of Dart_IsolateFlags and
150// corresponding global command line flags.
151#define BOOL_ISOLATE_FLAG_LIST(V) \
152 V(NONPRODUCT, is_system_isolate, IsSystemIsolate, is_system_isolate, false) \
153 V(NONPRODUCT, is_service_isolate, IsServiceIsolate, is_service_isolate, \
154 false) \
155 V(NONPRODUCT, is_kernel_isolate, IsKernelIsolate, is_kernel_isolate, false)
156
157// Represents the information used for spawning the first isolate within an
158// isolate group. All isolates within a group will refer to this
159// [IsolateGroupSource].
161 public:
163 const char* name,
164 const uint8_t* snapshot_data,
165 const uint8_t* snapshot_instructions,
166 const uint8_t* kernel_buffer,
167 intptr_t kernel_buffer_size,
169 : script_uri(script_uri == nullptr ? nullptr : Utils::StrDup(script_uri)),
170 name(Utils::StrDup(name)),
175 flags(flags),
176 script_kernel_buffer(nullptr),
178 loaded_blobs_(nullptr),
179 num_blob_loads_(0) {}
181 free(script_uri);
182 free(name);
183 }
184
185 void add_loaded_blob(Zone* zone_,
186 const ExternalTypedData& external_typed_data);
187
188 // The arguments used for spawning in
189 // `Dart_CreateIsolateGroupFromKernel` / `Dart_CreateIsolate`.
191 char* name;
192 const uint8_t* snapshot_data;
193 const uint8_t* snapshot_instructions;
194 const uint8_t* kernel_buffer;
195 const intptr_t kernel_buffer_size;
197
198 // The kernel buffer used in `Dart_LoadScriptFromKernel`.
199 const uint8_t* script_kernel_buffer;
201
202 // List of weak pointers to external typed data for loaded blobs.
205};
206
207// Tracks idle time and notifies heap when idle time expired.
209 public:
211
212 // Initializes the idle time handler with the given [heap], to which
213 // idle notifications will be sent.
214 void InitializeWithHeap(Heap* heap);
215
216 // Returns whether the caller should check for idle timeouts.
217 bool ShouldCheckForIdle();
218
219 // Declares that the idle time should be reset to now.
220 void UpdateStartIdleTime();
221
222 // Returns whether idle time expired and [NotifyIdle] should be called.
223 bool ShouldNotifyIdle(int64_t* expiry);
224
225 // Notifies the heap that now is a good time to do compactions and indicates
226 // we have time for the GC until [deadline].
227 void NotifyIdle(int64_t deadline);
228
229 // Calls [NotifyIdle] with the default deadline.
231
232 private:
234
235 Mutex mutex_;
236 Heap* heap_ = nullptr;
237 intptr_t disabled_counter_ = 0;
238 int64_t idle_start_time_ = 0;
239};
240
241// Disables firing of the idle timer while this object is alive.
243 public:
244 explicit DisableIdleTimerScope(IdleTimeHandler* handler);
246
247 private:
248 IdleTimeHandler* handler_;
249};
250
252 public:
253 MutatorThreadPool(IsolateGroup* isolate_group, intptr_t max_pool_size)
254 : ThreadPool(max_pool_size), isolate_group_(isolate_group) {}
256
257 protected:
258 virtual void OnEnterIdleLocked(MonitorLocker* ml);
259
260 private:
261 void NotifyIdle();
262
263 IsolateGroup* isolate_group_ = nullptr;
264};
265
266// Represents an isolate group and is shared among all isolates within a group.
267class IsolateGroup : public IntrusiveDListEntry<IsolateGroup> {
268 public:
269 IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
270 void* embedder_data,
272 Dart_IsolateFlags api_flags,
273 bool is_vm_isolate);
274 IsolateGroup(std::shared_ptr<IsolateGroupSource> source,
275 void* embedder_data,
276 Dart_IsolateFlags api_flags,
277 bool is_vm_isolate);
279
281#if defined(DEBUG)
282 void ValidateClassTable();
283#endif
284
285 IsolateGroupSource* source() const { return source_.get(); }
286 std::shared_ptr<IsolateGroupSource> shareable_source() const {
287 return source_;
288 }
289 bool is_vm_isolate() const { return is_vm_isolate_; }
290 void* embedder_data() const { return embedder_data_; }
291
292 bool initial_spawn_successful() { return initial_spawn_successful_; }
293 void set_initial_spawn_successful() { initial_spawn_successful_ = true; }
294
295 Heap* heap() const { return heap_.get(); }
296
298#if defined(DART_PRECOMPILED_RUNTIME)
299 return nullptr;
300#else
301 return background_compiler_.get();
302#endif
303 }
304#if !defined(DART_PRECOMPILED_RUNTIME)
306 if (IsSystemIsolateGroup(this)) {
308 }
309 return FLAG_optimization_counter_threshold;
310 }
311#endif
312
313#if !defined(PRODUCT)
314 GroupDebugger* debugger() const { return debugger_; }
315#endif
316
317 IdleTimeHandler* idle_time_handler() { return &idle_time_handler_; }
318
319 // Returns true if this is the first isolate registered.
320 void RegisterIsolate(Isolate* isolate);
321 void UnregisterIsolate(Isolate* isolate);
322 // Returns `true` if this was the last isolate and the caller is responsible
323 // for deleting the isolate group.
325
327
328 void RunWithLockedGroup(std::function<void()> fun);
329
330 void ScheduleInterrupts(uword interrupt_bits);
331
332 ThreadRegistry* thread_registry() const { return thread_registry_.get(); }
333 SafepointHandler* safepoint_handler() { return safepoint_handler_.get(); }
334
335 void CreateHeap(bool is_vm_isolate, bool is_service_or_kernel_isolate);
336 void SetupImagePage(const uint8_t* snapshot_buffer, bool is_executable);
337 void Shutdown();
338
339#define ISOLATE_METRIC_ACCESSOR(type, variable, name, unit) \
340 type* Get##variable##Metric() { return &metric_##variable##_; }
342#undef ISOLATE_METRIC_ACCESSOR
343
344#if !defined(PRODUCT)
346 last_allocationprofile_accumulator_reset_timestamp_ =
348 }
349
351 return last_allocationprofile_accumulator_reset_timestamp_;
352 }
353
355 last_allocationprofile_gc_timestamp_ = OS::GetCurrentTimeMillis();
356 }
357
359 return last_allocationprofile_gc_timestamp_;
360 }
361#endif // !defined(PRODUCT)
362
363 DispatchTable* dispatch_table() const { return dispatch_table_.get(); }
365 dispatch_table_.reset(table);
366 }
367 const uint8_t* dispatch_table_snapshot() const {
368 return dispatch_table_snapshot_;
369 }
370 void set_dispatch_table_snapshot(const uint8_t* snapshot) {
371 dispatch_table_snapshot_ = snapshot;
372 }
374 return dispatch_table_snapshot_size_;
375 }
377 dispatch_table_snapshot_size_ = size;
378 }
379
381 return &class_table_allocator_;
382 }
383
384 static intptr_t class_table_offset() {
385 COMPILE_ASSERT(sizeof(IsolateGroup::class_table_) == kWordSize);
386 return OFFSET_OF(IsolateGroup, class_table_);
387 }
388
390 return cached_class_table_table_.load();
391 }
393 cached_class_table_table_.store(cached_class_table_table);
394 }
396 COMPILE_ASSERT(sizeof(IsolateGroup::cached_class_table_table_) ==
397 kWordSize);
398 return OFFSET_OF(IsolateGroup, cached_class_table_table_);
399 }
400
402 static intptr_t object_store_offset() {
403 COMPILE_ASSERT(sizeof(IsolateGroup::object_store_) == kWordSize);
404 return OFFSET_OF(IsolateGroup, object_store_);
405 }
406
407 void set_obfuscation_map(const char** map) { obfuscation_map_ = map; }
408 const char** obfuscation_map() const { return obfuscation_map_; }
409
410 Random* random() { return &random_; }
411
412 bool is_system_isolate_group() const { return is_system_isolate_group_; }
413
414 // IsolateGroup-specific flag handling.
415 static void FlagsInitialize(Dart_IsolateFlags* api_flags);
416 void FlagsCopyTo(Dart_IsolateFlags* api_flags);
417 void FlagsCopyFrom(const Dart_IsolateFlags& api_flags);
418
419#if defined(DART_PRECOMPILER)
420#define FLAG_FOR_PRECOMPILER(from_field, from_flag) (from_field)
421#else
422#define FLAG_FOR_PRECOMPILER(from_field, from_flag) (from_flag)
423#endif
424
425#if !defined(PRODUCT)
426#define FLAG_FOR_NONPRODUCT(from_field, from_flag) (from_field)
427#else
428#define FLAG_FOR_NONPRODUCT(from_field, from_flag) (from_flag)
429#endif
430
431#define FLAG_FOR_PRODUCT(from_field, from_flag) (from_field)
432
433#define DECLARE_GETTER(when, name, bitname, isolate_flag_name, flag_name) \
434 bool name() const { \
435 return FLAG_FOR_##when(bitname##Bit::decode(isolate_group_flags_), \
436 flag_name); \
437 }
439#undef FLAG_FOR_NONPRODUCT
440#undef FLAG_FOR_PRECOMPILER
441#undef FLAG_FOR_PRODUCT
442#undef DECLARE_GETTER
443
445 return ShouldLoadVmServiceBit::decode(isolate_group_flags_);
446 }
447 void set_should_load_vmservice(bool value) {
448 isolate_group_flags_ =
449 ShouldLoadVmServiceBit::update(value, isolate_group_flags_);
450 }
451
452 void set_asserts(bool value) {
453 isolate_group_flags_ =
454 EnableAssertsBit::update(value, isolate_group_flags_);
455 }
456
457 void set_branch_coverage(bool value) {
458 isolate_group_flags_ =
459 BranchCoverageBit::update(value, isolate_group_flags_);
460 }
461
462#if !defined(PRODUCT)
463#if !defined(DART_PRECOMPILED_RUNTIME)
464 bool HasAttemptedReload() const {
465 return HasAttemptedReloadBit::decode(isolate_group_flags_);
466 }
467 void SetHasAttemptedReload(bool value) {
468 isolate_group_flags_ =
469 HasAttemptedReloadBit::update(value, isolate_group_flags_);
470 }
473 return reload_every_n_stack_overflow_checks_;
474 }
475#else
476 bool HasAttemptedReload() const { return false; }
477#endif // !defined(DART_PRECOMPILED_RUNTIME)
478#endif // !defined(PRODUCT)
479
480#if defined(PRODUCT)
481 void set_use_osr(bool use_osr) { ASSERT(!use_osr); }
482#else // defined(PRODUCT)
483 void set_use_osr(bool use_osr) {
484 isolate_group_flags_ = UseOsrBit::update(use_osr, isolate_group_flags_);
485 }
486#endif // defined(PRODUCT)
487
488 // Class table for the program loaded into this isolate group.
489 //
490 // This table is modified by kernel loading.
491 ClassTable* class_table() const { return class_table_; }
492
493 // Class table used for heap walks by GC visitors. Usually it
494 // is the same table as one in |class_table_|, except when in the
495 // middle of the reload.
496 //
497 // See comment for |ClassTable| class for more details.
498 ClassTable* heap_walk_class_table() const { return heap_walk_class_table_; }
499
503
504 StoreBuffer* store_buffer() const { return store_buffer_.get(); }
505 ObjectStore* object_store() const { return object_store_.get(); }
506 Mutex* symbols_mutex() { return &symbols_mutex_; }
507 Mutex* type_canonicalization_mutex() { return &type_canonicalization_mutex_; }
509 return &type_arguments_canonicalization_mutex_;
510 }
511 Mutex* subtype_test_cache_mutex() { return &subtype_test_cache_mutex_; }
512 Mutex* megamorphic_table_mutex() { return &megamorphic_table_mutex_; }
513 Mutex* type_feedback_mutex() { return &type_feedback_mutex_; }
514 Mutex* patchable_call_mutex() { return &patchable_call_mutex_; }
516 return &constant_canonicalization_mutex_;
517 }
518 Mutex* kernel_data_lib_cache_mutex() { return &kernel_data_lib_cache_mutex_; }
520 return &kernel_data_class_cache_mutex_;
521 }
522 Mutex* kernel_constants_mutex() { return &kernel_constants_mutex_; }
523
524#if defined(DART_PRECOMPILED_RUNTIME)
525 Mutex* unlinked_call_map_mutex() { return &unlinked_call_map_mutex_; }
526#endif
527
528#if !defined(DART_PRECOMPILED_RUNTIME)
529 Mutex* initializer_functions_mutex() { return &initializer_functions_mutex_; }
530#endif // !defined(DART_PRECOMPILED_RUNTIME)
531
532 SafepointRwLock* program_lock() { return program_lock_.get(); }
533
534 static inline IsolateGroup* Current() {
535 Thread* thread = Thread::Current();
536 return thread == nullptr ? nullptr : thread->isolate_group();
537 }
538
539 void IncreaseMutatorCount(Isolate* mutator, bool is_nested_reenter);
540 void DecreaseMutatorCount(Isolate* mutator, bool is_nested_exit);
541 intptr_t MutatorCount() const {
542 MonitorLocker ml(active_mutators_monitor_.get());
543 return active_mutators_;
544 }
545
546 bool HasTagHandler() const { return library_tag_handler() != nullptr; }
548 const Object& arg1,
549 const Object& arg2);
551 return library_tag_handler_;
552 }
554 library_tag_handler_ = handler;
555 }
557 return deferred_load_handler_;
558 }
560 deferred_load_handler_ = handler;
561 }
562
563 // Prepares all threads in an isolate for Garbage Collection.
564 void ReleaseStoreBuffers();
565 void FlushMarkingStacks();
569
570 MarkingStack* marking_stack() const { return marking_stack_; }
572 return deferred_marking_stack_;
573 }
574
575 // Runs the given [function] on every isolate in the isolate group.
576 //
577 // During the duration of this function, no new isolates can be added or
578 // removed.
579 //
580 // If [at_safepoint] is `true`, then the entire isolate group must be in a
581 // safepoint. There is therefore no reason to guard against other threads
582 // adding/removing isolates, so no locks will be held.
583 void ForEachIsolate(std::function<void(Isolate* isolate)> function,
584 bool at_safepoint = false);
585 Isolate* FirstIsolate() const;
587
588 // Ensures mutators are stopped during execution of the provided function.
589 //
590 // If the current thread is the only mutator in the isolate group,
591 // [single_current_mutator] will be called. Otherwise [otherwise] will be
592 // called inside a [SafepointOperationsScope] (or
593 // [ForceGrowthSafepointOperationScope] if [use_force_growth_in_otherwise]
594 // is set).
595 //
596 // During the duration of this function, no new isolates can be added to the
597 // isolate group.
599 Callable* single_current_mutator,
600 Callable* otherwise,
601 bool use_force_growth_in_otherwise = false);
602
603 template <typename T, typename S>
604 void RunWithStoppedMutators(T single_current_mutator,
605 S otherwise,
606 bool use_force_growth_in_otherwise = false) {
607 LambdaCallable<T> single_callable(single_current_mutator);
608 LambdaCallable<S> otherwise_callable(otherwise);
609 RunWithStoppedMutatorsCallable(&single_callable, &otherwise_callable,
610 use_force_growth_in_otherwise);
611 }
612
613 template <typename T>
614 void RunWithStoppedMutators(T function, bool use_force_growth = false) {
615 LambdaCallable<T> callable(function);
616 RunWithStoppedMutatorsCallable(&callable, &callable, use_force_growth);
617 }
618
619#ifndef PRODUCT
620 void PrintJSON(JSONStream* stream, bool ref = true);
621 void PrintToJSONObject(JSONObject* jsobj, bool ref);
622
623 // Creates an object with the total heap memory usage statistics for this
624 // isolate group.
625 void PrintMemoryUsageJSON(JSONStream* stream);
626#endif
627
628#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
629 // By default the reload context is deleted. This parameter allows
630 // the caller to delete is separately if it is still needed.
631 bool ReloadSources(JSONStream* js,
632 bool force_reload,
633 const char* root_script_url = nullptr,
634 const char* packages_url = nullptr,
635 bool dont_delete_reload_context = false);
636
637 // If provided, the VM takes ownership of kernel_buffer.
638 bool ReloadKernel(JSONStream* js,
639 bool force_reload,
640 const uint8_t* kernel_buffer = nullptr,
641 intptr_t kernel_buffer_size = 0,
642 bool dont_delete_reload_context = false);
643
644 void set_last_reload_timestamp(int64_t value) {
645 last_reload_timestamp_ = value;
646 }
647 int64_t last_reload_timestamp() const { return last_reload_timestamp_; }
648
650 return group_reload_context_.get();
651 }
653 return program_reload_context_;
654 }
655
656 void DeleteReloadContext();
657 bool CanReload();
658#else
659 bool CanReload() { return false; }
660#endif // !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
661
662 bool IsReloading() const {
663#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
664 return group_reload_context_ != nullptr;
665#else
666 return false;
667#endif
668 }
669
670 Become* become() const { return become_; }
671 void set_become(Become* become) { become_ = become; }
672
673 uint64_t id() const { return id_; }
674
675 static void Init();
676 static void Cleanup();
677
678 static void ForEach(std::function<void(IsolateGroup*)> action);
679 static void RunWithIsolateGroup(uint64_t id,
680 std::function<void(IsolateGroup*)> action,
681 std::function<void()> not_found);
682
683 // Manage list of existing isolate groups.
684 static void RegisterIsolateGroup(IsolateGroup* isolate_group);
685 static void UnregisterIsolateGroup(IsolateGroup* isolate_group);
686
687 static bool HasApplicationIsolateGroups();
688 static bool HasOnlyVMIsolateGroup();
689 static bool IsSystemIsolateGroup(const IsolateGroup* group);
690
691 int64_t UptimeMicros() const;
692
693 ApiState* api_state() const { return api_state_.get(); }
694
695 // Visit all object pointers. Caller must ensure concurrent sweeper is not
696 // running, and the visitor must not allocate.
698 ValidationPolicy validate_frames);
701 ValidationPolicy validate_frames);
704
705 // In precompilation we finalize all regular classes before compiling.
707 return AllClassesFinalizedBit::decode(isolate_group_flags_);
708 }
709 void set_all_classes_finalized(bool value) {
710 isolate_group_flags_ =
711 AllClassesFinalizedBit::update(value, isolate_group_flags_);
712 }
713
714 bool remapping_cids() const {
715 return RemappingCidsBit::decode(isolate_group_flags_);
716 }
717 void set_remapping_cids(bool value) {
718 isolate_group_flags_ =
719 RemappingCidsBit::update(value, isolate_group_flags_);
720 }
721
724
725 ArrayPtr saved_unlinked_calls() const { return saved_unlinked_calls_; }
727
728 FieldTable* initial_field_table() const { return initial_field_table_.get(); }
729 std::shared_ptr<FieldTable> initial_field_table_shareable() {
730 return initial_field_table_;
731 }
732 void set_initial_field_table(std::shared_ptr<FieldTable> field_table) {
733 initial_field_table_ = field_table;
734 }
735
736 MutatorThreadPool* thread_pool() { return thread_pool_.get(); }
737
738 void RegisterClass(const Class& cls);
739 void RegisterStaticField(const Field& field, const Object& initial_value);
740 void FreeStaticField(const Field& field);
741
743 static void ExitTemporaryIsolate();
744
745 private:
746 friend class Dart; // For `object_store_ = ` in Dart::Init
747 friend class Heap;
748 friend class StackFrame; // For `[isolates_].First()`.
749 // For `object_store_shared_untag()`, `class_table_shared_untag()`
750 friend class Isolate;
751
752#define ISOLATE_GROUP_FLAG_BITS(V) \
753 V(AllClassesFinalized) \
754 V(EnableAsserts) \
755 V(HasAttemptedReload) \
756 V(RemappingCids) \
757 V(ShouldLoadVmService) \
758 V(Obfuscate) \
759 V(UseFieldGuards) \
760 V(UseOsr) \
761 V(SnapshotIsDontNeedSafe) \
762 V(BranchCoverage)
763
764 // Isolate group specific flags.
765 enum FlagBits {
766#define DECLARE_BIT(Name) k##Name##Bit,
768#undef DECLARE_BIT
769 };
770
771#define DECLARE_BITFIELD(Name) \
772 class Name##Bit : public BitField<uint32_t, bool, k##Name##Bit, 1> {};
774#undef DECLARE_BITFIELD
775
776 void set_heap(std::unique_ptr<Heap> value);
777
778 // Accessed from generated code.
779 ClassTable* class_table_;
780 AcqRelAtomic<ClassPtr*> cached_class_table_table_;
781 std::unique_ptr<ObjectStore> object_store_;
782 // End accessed from generated code.
783
784 ClassTableAllocator class_table_allocator_;
785 ClassTable* heap_walk_class_table_;
786
787 const char** obfuscation_map_ = nullptr;
788
789 bool is_vm_isolate_ = false;
790 void* embedder_data_ = nullptr;
791
792 IdleTimeHandler idle_time_handler_;
793 std::unique_ptr<MutatorThreadPool> thread_pool_;
794 std::unique_ptr<SafepointRwLock> isolates_lock_;
795 IntrusiveDList<Isolate> isolates_;
796 intptr_t isolate_count_ = 0;
797 bool initial_spawn_successful_ = false;
798 Dart_LibraryTagHandler library_tag_handler_ = nullptr;
799 Dart_DeferredLoadHandler deferred_load_handler_ = nullptr;
800 int64_t start_time_micros_;
801 bool is_system_isolate_group_;
802 Random random_;
803
804#if !defined(PRODUCT) && !defined(DART_PRECOMPILED_RUNTIME)
805 int64_t last_reload_timestamp_;
806 std::shared_ptr<IsolateGroupReloadContext> group_reload_context_;
807 // Per-isolate-group copy of FLAG_reload_every.
808 RelaxedAtomic<intptr_t> reload_every_n_stack_overflow_checks_;
809 ProgramReloadContext* program_reload_context_ = nullptr;
810#endif
811 Become* become_ = nullptr;
812
813#define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \
814 type metric_##variable##_;
816#undef ISOLATE_METRIC_VARIABLE
817
818#if !defined(PRODUCT)
819 // Timestamps of last operation via service.
820 int64_t last_allocationprofile_accumulator_reset_timestamp_ = 0;
821 int64_t last_allocationprofile_gc_timestamp_ = 0;
822
823#endif // !defined(PRODUCT)
824
825 MarkingStack* marking_stack_ = nullptr;
826 MarkingStack* deferred_marking_stack_ = nullptr;
827 std::shared_ptr<IsolateGroupSource> source_;
828 std::unique_ptr<ApiState> api_state_;
829 std::unique_ptr<ThreadRegistry> thread_registry_;
830 std::unique_ptr<SafepointHandler> safepoint_handler_;
831
832 static RwLock* isolate_groups_rwlock_;
833 static IntrusiveDList<IsolateGroup>* isolate_groups_;
834 static Random* isolate_group_random_;
835
836 uint64_t id_ = 0;
837
838 std::unique_ptr<StoreBuffer> store_buffer_;
839 std::unique_ptr<Heap> heap_;
840 std::unique_ptr<DispatchTable> dispatch_table_;
841 const uint8_t* dispatch_table_snapshot_ = nullptr;
842 intptr_t dispatch_table_snapshot_size_ = 0;
843 ArrayPtr saved_unlinked_calls_;
844 std::shared_ptr<FieldTable> initial_field_table_;
845 uint32_t isolate_group_flags_ = 0;
846
847 NOT_IN_PRECOMPILED(std::unique_ptr<BackgroundCompiler> background_compiler_);
848
849 Mutex symbols_mutex_;
850 Mutex type_canonicalization_mutex_;
851 Mutex type_arguments_canonicalization_mutex_;
852 Mutex subtype_test_cache_mutex_;
853 Mutex megamorphic_table_mutex_;
854 Mutex type_feedback_mutex_;
855 Mutex patchable_call_mutex_;
856 Mutex constant_canonicalization_mutex_;
857 Mutex kernel_data_lib_cache_mutex_;
858 Mutex kernel_data_class_cache_mutex_;
859 Mutex kernel_constants_mutex_;
860
861#if defined(DART_PRECOMPILED_RUNTIME)
862 Mutex unlinked_call_map_mutex_;
863#endif
864
865#if !defined(DART_PRECOMPILED_RUNTIME)
866 Mutex initializer_functions_mutex_;
867#endif // !defined(DART_PRECOMPILED_RUNTIME)
868
869 // Protect access to boxed_field_list_.
870 Mutex field_list_mutex_;
871 // List of fields that became boxed and that trigger deoptimization.
872 GrowableObjectArrayPtr boxed_field_list_;
873
874 // Ensures synchronized access to classes functions, fields and other
875 // program structure elements to accommodate concurrent modification done
876 // by multiple isolates and background compiler.
877 std::unique_ptr<SafepointRwLock> program_lock_;
878
879 // Allow us to ensure the number of active mutators is limited by a maximum.
880 std::unique_ptr<Monitor> active_mutators_monitor_;
881 intptr_t active_mutators_ = 0;
882 intptr_t waiting_mutators_ = 0;
883 intptr_t max_active_mutators_ = 0;
884
885 NOT_IN_PRODUCT(GroupDebugger* debugger_ = nullptr);
886};
887
888// When an isolate sends-and-exits this class represent things that it passed
889// to the beneficiary.
890class Bequest {
891 public:
894 ~Bequest();
895
896 PersistentHandle* handle() { return handle_; }
898 auto handle = handle_;
899 handle_ = nullptr;
900 return handle;
901 }
902 Dart_Port beneficiary() { return beneficiary_; }
903
904 private:
905 PersistentHandle* handle_;
906 Dart_Port beneficiary_;
907};
908
909class Isolate : public BaseIsolate, public IntrusiveDListEntry<Isolate> {
910 public:
911 // Keep both these enums in sync with isolate_patch.dart.
912 // The different Isolate API message types.
913 enum LibMsgId {
923
924 // Internal message ids.
925 kInterruptMsg = 10, // Break in the debugger.
926 kInternalKillMsg = 11, // Like kill, but does not run exit listeners, etc.
927 kDrainServiceExtensionsMsg = 12, // Invoke pending service extensions
928 kCheckForReload = 13, // Participate in other isolate group reload.
929 };
930 // The different Isolate API message priorities for ping and kill messages.
936
937 ~Isolate();
938
939 static inline Isolate* Current() {
940 Thread* thread = Thread::Current();
941 return thread == nullptr ? nullptr : thread->isolate();
942 }
943
944 bool IsScheduled() { return scheduled_mutator_thread() != nullptr; }
946
948
952
953 FieldTable* field_table() const { return field_table_; }
955 delete field_table_;
956 field_table_ = field_table;
957 T->field_table_values_ = field_table->table();
958 }
959
961 return isolate_object_store_.get();
962 }
963
965 return message_notify_callback_.load(std::memory_order_relaxed);
966 }
967
969 message_notify_callback_.store(value, std::memory_order_release);
970 }
971
973 on_shutdown_callback_ = value;
974 }
976 return on_shutdown_callback_;
977 }
979 on_cleanup_callback_ = value;
980 }
982 return on_cleanup_callback_;
983 }
984
985 void bequeath(std::unique_ptr<Bequest> bequest) {
986 bequest_ = std::move(bequest);
987 }
988
989 IsolateGroupSource* source() const { return isolate_group_->source(); }
990 IsolateGroup* group() const { return isolate_group_; }
991
992 bool HasPendingMessages();
993
994 Thread* mutator_thread() const;
995
996 const char* name() const { return name_; }
997 void set_name(const char* name);
998
999 int64_t UptimeMicros() const;
1000
1001 Dart_Port main_port() const { return main_port_; }
1003 ASSERT(main_port_ == 0); // Only set main port once.
1004 main_port_ = port;
1005 }
1007 void set_origin_id(Dart_Port id);
1008 void set_pause_capability(uint64_t value) { pause_capability_ = value; }
1009 uint64_t pause_capability() const { return pause_capability_; }
1010 void set_terminate_capability(uint64_t value) {
1011 terminate_capability_ = value;
1012 }
1013 uint64_t terminate_capability() const { return terminate_capability_; }
1014
1015 void SendInternalLibMessage(LibMsgId msg_id, uint64_t capability);
1017 LibMsgId msg_id,
1018 uint64_t capability);
1019
1020 void set_init_callback_data(void* value) { init_callback_data_ = value; }
1021 void* init_callback_data() const { return init_callback_data_; }
1022
1023 void set_finalizers(const GrowableObjectArray& value);
1024 static intptr_t finalizers_offset() {
1025 return OFFSET_OF(Isolate, finalizers_);
1026 }
1027
1029 return environment_callback_;
1030 }
1032 environment_callback_ = value;
1033 }
1034
1036 return group()->deferred_load_handler() != nullptr;
1037 }
1039
1040 void ScheduleInterrupts(uword interrupt_bits);
1041
1042 const char* MakeRunnable();
1043 void MakeRunnableLocked();
1044 void Run();
1045
1047
1048 bool is_runnable() const { return LoadIsolateFlagsBit<IsRunnableBit>(); }
1049 void set_is_runnable(bool value) {
1050 UpdateIsolateFlagsBit<IsRunnableBit>(value);
1051#if !defined(PRODUCT)
1052 if (is_runnable()) {
1054 }
1055#endif
1056 }
1057
1058 Mutex* mutex() { return &mutex_; }
1059
1060#if !defined(PRODUCT)
1061 Debugger* debugger() const { return debugger_; }
1062
1063 // Returns the current SampleBlock used to track CPU profiling samples.
1064 SampleBlock* current_sample_block() const { return current_sample_block_; }
1066 current_sample_block_ = block;
1067 }
1069
1070 // Returns the current SampleBlock used to track Dart allocation samples.
1072 return current_allocation_sample_block_;
1073 }
1075 current_allocation_sample_block_ = block;
1076 }
1077
1079 return has_completed_blocks_.exchange(0) != 0;
1080 }
1082 return has_completed_blocks_.exchange(1) == 0;
1083 }
1084
1085 void set_single_step(bool value) { single_step_ = value; }
1086 bool single_step() const { return single_step_; }
1087 static intptr_t single_step_offset() {
1088 return OFFSET_OF(Isolate, single_step_);
1089 }
1090
1092 has_resumption_breakpoints_ = value;
1093 }
1095 return has_resumption_breakpoints_;
1096 }
1098 return OFFSET_OF(Isolate, has_resumption_breakpoints_);
1099 }
1100
1101 bool ResumeRequest() const { return LoadIsolateFlagsBit<ResumeRequestBit>(); }
1102 // Lets the embedder know that a service message resulted in a resume request.
1104 UpdateIsolateFlagsBit<ResumeRequestBit>(true);
1106 }
1107
1109 last_resume_timestamp_ = OS::GetCurrentTimeMillis();
1110 }
1111
1112 int64_t last_resume_timestamp() const { return last_resume_timestamp_; }
1113
1114 // Returns whether the vm service has requested that the debugger
1115 // resume execution.
1117 return UpdateIsolateFlagsBit<ResumeRequestBit>(false);
1118 }
1119#endif
1120
1121 // Verify that the sender has the capability to pause or terminate the
1122 // isolate.
1123 bool VerifyPauseCapability(const Object& capability) const;
1124 bool VerifyTerminateCapability(const Object& capability) const;
1125
1126 // Returns true if the capability was added or removed from this isolate's
1127 // list of pause events.
1128 bool AddResumeCapability(const Capability& capability);
1129 bool RemoveResumeCapability(const Capability& capability);
1130
1131 void AddExitListener(const SendPort& listener, const Instance& response);
1132 void RemoveExitListener(const SendPort& listener);
1133 void NotifyExitListeners();
1134
1135 void AddErrorListener(const SendPort& listener);
1136 void RemoveErrorListener(const SendPort& listener);
1137 bool NotifyErrorListeners(const char* msg, const char* stacktrace);
1138
1139 bool ErrorsFatal() const { return LoadIsolateFlagsBit<ErrorsFatalBit>(); }
1140 void SetErrorsFatal(bool value) {
1141 UpdateIsolateFlagsBit<ErrorsFatalBit>(value);
1142 }
1143
1144 Random* random() { return &random_; }
1145
1146 Simulator* simulator() const { return simulator_; }
1147 void set_simulator(Simulator* value) { simulator_ = value; }
1148
1149 void IncrementSpawnCount();
1150 void DecrementSpawnCount();
1152
1154 create_group_callback_ = cb;
1155 }
1157 return create_group_callback_;
1158 }
1159
1161 initialize_callback_ = cb;
1162 }
1164 return initialize_callback_;
1165 }
1166
1168 shutdown_callback_ = cb;
1169 }
1171 return shutdown_callback_;
1172 }
1173
1175 cleanup_callback_ = cb;
1176 }
1178 return cleanup_callback_;
1179 }
1180
1182 cleanup_group_callback_ = cb;
1183 }
1185 return cleanup_group_callback_;
1186 }
1189 register_kernel_blob_callback_ = cb;
1190 }
1192 return register_kernel_blob_callback_;
1193 }
1196 unregister_kernel_blob_callback_ = cb;
1197 }
1199 return unregister_kernel_blob_callback_;
1200 }
1201
1202#if !defined(PRODUCT)
1203 ObjectIdRing* object_id_ring() const { return object_id_ring_; }
1205#endif // !defined(PRODUCT)
1206
1207 bool IsDeoptimizing() const { return deopt_context_ != nullptr; }
1208 DeoptContext* deopt_context() const { return deopt_context_; }
1210 ASSERT(value == nullptr || deopt_context_ == nullptr);
1211 deopt_context_ = value;
1212 }
1213
1215 Zone* zone,
1216 const Function& send_function,
1217 Dart_Port send_port);
1219 Zone* zone,
1220 const Function& trampoline,
1221 const Closure& target,
1222 bool keep_isolate_alive);
1226
1227 bool HasLivePorts();
1228 ReceivePortPtr CreateReceivePort(const String& debug_name);
1229 void SetReceivePortKeepAliveState(const ReceivePort& receive_port,
1230 bool keep_isolate_alive);
1231 void CloseReceivePort(const ReceivePort& receive_port);
1232
1233 // Visible for testing.
1235 return ffi_callback_list_head_;
1236 }
1237
1239 ASSERT(defer_finalization_count_ >= 0);
1240 return defer_finalization_count_++;
1241 }
1242
1244 ASSERT(defer_finalization_count_ > 0);
1245 return defer_finalization_count_--;
1246 }
1247
1249 ASSERT(defer_finalization_count_ >= 0);
1250 return defer_finalization_count_ == 0;
1251 }
1252
1253#ifndef PRODUCT
1254 void PrintJSON(JSONStream* stream, bool ref = true);
1255
1256 // Creates an object with the total heap memory usage statistics for this
1257 // isolate.
1258 void PrintMemoryUsageJSON(JSONStream* stream);
1259
1260 void PrintPauseEventJSON(JSONStream* stream);
1261#endif
1262
1263#if !defined(PRODUCT)
1264 VMTagCounters* vm_tag_counters() { return &vm_tag_counters_; }
1265#endif // !defined(PRODUCT)
1266
1267 bool IsPaused() const;
1268
1269#if !defined(PRODUCT)
1271 return LoadIsolateFlagsBit<ShouldPausePostServiceRequestBit>();
1272 }
1274 UpdateIsolateFlagsBit<ShouldPausePostServiceRequestBit>(value);
1275 }
1276#endif // !defined(PRODUCT)
1277
1278 ErrorPtr PausePostRequest();
1279
1280 uword user_tag() const { return user_tag_; }
1281 static intptr_t user_tag_offset() { return OFFSET_OF(Isolate, user_tag_); }
1282 static intptr_t current_tag_offset() {
1283 return OFFSET_OF(Isolate, current_tag_);
1284 }
1285 static intptr_t default_tag_offset() {
1286 return OFFSET_OF(Isolate, default_tag_);
1287 }
1288
1289#if !defined(PRODUCT)
1290#define ISOLATE_METRIC_ACCESSOR(type, variable, name, unit) \
1291 type* Get##variable##Metric() { return &metric_##variable##_; }
1293#undef ISOLATE_METRIC_ACCESSOR
1294#endif // !defined(PRODUCT)
1295
1296 static intptr_t IsolateListLength();
1297
1298 GrowableObjectArrayPtr tag_table() const { return tag_table_; }
1299 void set_tag_table(const GrowableObjectArray& value);
1300
1301 UserTagPtr current_tag() const { return current_tag_; }
1302 void set_current_tag(const UserTag& tag);
1303
1304 UserTagPtr default_tag() const { return default_tag_; }
1305 void set_default_tag(const UserTag& tag);
1306
1307 // Also sends a paused at exit event over the service protocol.
1308 void SetStickyError(ErrorPtr sticky_error);
1309
1310 ErrorPtr sticky_error() const { return sticky_error_; }
1312
1313#ifndef PRODUCT
1315 void AppendServiceExtensionCall(const Instance& closure,
1316 const String& method_name,
1317 const Array& parameter_keys,
1318 const Array& parameter_values,
1319 const Instance& reply_port,
1320 const Instance& id);
1322 const Instance& closure);
1323 InstancePtr LookupServiceExtensionHandler(const String& name);
1324#endif
1325
1326 static void VisitIsolates(IsolateVisitor* visitor);
1327
1328#if !defined(PRODUCT)
1329 // Handle service messages until we are told to resume execution.
1330 void PauseEventHandler();
1331#endif
1332
1333 bool is_vm_isolate() const { return LoadIsolateFlagsBit<IsVMIsolateBit>(); }
1334 void set_is_vm_isolate(bool value) {
1335 UpdateIsolateFlagsBit<IsVMIsolateBit>(value);
1336 }
1337
1339 return LoadIsolateFlagsBit<IsServiceRegisteredBit>();
1340 }
1341 void set_is_service_registered(bool value) {
1342 UpdateIsolateFlagsBit<IsServiceRegisteredBit>(value);
1343 }
1344
1345 // Isolate-specific flag handling.
1346 static void FlagsInitialize(Dart_IsolateFlags* api_flags);
1347 void FlagsCopyTo(Dart_IsolateFlags* api_flags) const;
1348 void FlagsCopyFrom(const Dart_IsolateFlags& api_flags);
1349
1350#if defined(DART_PRECOMPILER)
1351#define FLAG_FOR_PRECOMPILER(from_field, from_flag) (from_field)
1352#else
1353#define FLAG_FOR_PRECOMPILER(from_field, from_flag) (from_flag)
1354#endif
1355
1356#if !defined(PRODUCT)
1357#define FLAG_FOR_NONPRODUCT(from_field, from_flag) (from_field)
1358#else
1359#define FLAG_FOR_NONPRODUCT(from_field, from_flag) (from_flag)
1360#endif
1361
1362#define FLAG_FOR_PRODUCT(from_field, from_flag) (from_field)
1363
1364#define DECLARE_GETTER(when, name, bitname, isolate_flag_name, flag_name) \
1365 bool name() const { \
1366 return FLAG_FOR_##when(LoadIsolateFlagsBit<bitname##Bit>(), flag_name); \
1367 }
1369#undef FLAG_FOR_NONPRODUCT
1370#undef FLAG_FOR_PRECOMPILER
1371#undef FLAG_FOR_PRODUCT
1372#undef DECLARE_GETTER
1373
1375 return LoadIsolateFlagsBit<HasAttemptedSteppingBit>();
1376 }
1378 UpdateIsolateFlagsBit<HasAttemptedSteppingBit>(value);
1379 }
1380
1381 // Kills all non-system isolates.
1382 static void KillAllIsolates(LibMsgId msg_id);
1383 // Kills all system isolates, excluding the kernel service and VM service.
1384 static void KillAllSystemIsolates(LibMsgId msg_id);
1385 static void KillIfExists(Isolate* isolate, LibMsgId msg_id);
1386
1387 // Lookup an isolate by its main port. Returns nullptr if no matching isolate
1388 // is found.
1390
1391 // Lookup an isolate by its main port and return a copy of its name. Returns
1392 // nullptr if not matching isolate is found.
1393 static std::unique_ptr<char[]> LookupIsolateNameByPort(Dart_Port port);
1394
1395 static void DisableIsolateCreation();
1396 static void EnableIsolateCreation();
1397 static bool IsolateCreationEnabled();
1398 static bool IsSystemIsolate(const Isolate* isolate) {
1399 return IsolateGroup::IsSystemIsolateGroup(isolate->group());
1400 }
1401 static bool IsVMInternalIsolate(const Isolate* isolate);
1402
1403 HandlerInfoCache* handler_info_cache() { return &handler_info_cache_; }
1404
1406 return &catch_entry_moves_cache_;
1407 }
1408
1409 // The weak table used in the snapshot writer for the purpose of fast message
1410 // sending.
1411 WeakTable* forward_table_new() { return forward_table_new_.get(); }
1413
1414 WeakTable* forward_table_old() { return forward_table_old_.get(); }
1416
1419
1420 std::unique_ptr<VirtualMemory> TakeRegexpBacktrackStack() {
1421 return std::move(regexp_backtracking_stack_cache_);
1422 }
1423
1424 void CacheRegexpBacktrackStack(std::unique_ptr<VirtualMemory> stack) {
1425 regexp_backtracking_stack_cache_ = std::move(stack);
1426 }
1427
1429 bool IsPrefixLoaded(const LibraryPrefix& prefix) const;
1430 void SetPrefixIsLoaded(const LibraryPrefix& prefix);
1431
1433 return &pointers_to_verify_at_exit_;
1434 }
1435
1436 private:
1437 friend class Dart; // Init, InitOnce, Shutdown.
1438 friend class IsolateKillerVisitor; // Kill().
1440 const char* n,
1441 char** e);
1442
1443 Isolate(IsolateGroup* group, const Dart_IsolateFlags& api_flags);
1444
1445 static void InitVM();
1446 static Isolate* InitIsolate(const char* name_prefix,
1447 IsolateGroup* isolate_group,
1448 const Dart_IsolateFlags& api_flags,
1449 bool is_vm_isolate = false);
1450
1451 // The isolate_creation_monitor_ should be held when calling Kill().
1452 void KillLocked(LibMsgId msg_id);
1453
1454 void Shutdown();
1455 void RunAndCleanupFinalizersOnShutdown();
1456 void LowLevelShutdown();
1457
1458 // Unregister the [isolate] from the thread, remove it from the isolate group,
1459 // invoke the cleanup function (if any), delete the isolate and possibly
1460 // delete the isolate group (if it's the last isolate in the group).
1461 static void LowLevelCleanup(Isolate* isolate);
1462
1463 void BuildName(const char* name_prefix);
1464
1465 void ProfileIdle();
1466
1467 // Visit all object pointers. Caller must ensure concurrent sweeper is not
1468 // running, and the visitor must not allocate.
1469 void VisitObjectPointers(ObjectPointerVisitor* visitor,
1470 ValidationPolicy validate_frames);
1471 void VisitStackPointers(ObjectPointerVisitor* visitor,
1472 ValidationPolicy validate_frames);
1473
1474 void set_user_tag(uword tag) { user_tag_ = tag; }
1475
1476 void set_is_system_isolate(bool is_system_isolate) {
1477 is_system_isolate_ = is_system_isolate;
1478 }
1479
1480#if !defined(PRODUCT)
1481 GrowableObjectArrayPtr GetAndClearPendingServiceExtensionCalls();
1482 GrowableObjectArrayPtr pending_service_extension_calls() const {
1483 return pending_service_extension_calls_;
1484 }
1485 void set_pending_service_extension_calls(const GrowableObjectArray& value);
1486 GrowableObjectArrayPtr registered_service_extension_handlers() const {
1487 return registered_service_extension_handlers_;
1488 }
1489 void set_registered_service_extension_handlers(
1490 const GrowableObjectArray& value);
1491#endif // !defined(PRODUCT)
1492
1493 // DEPRECATED: Use Thread's methods instead. During migration, these default
1494 // to using the mutator thread (which must also be the current thread).
1495 Zone* current_zone() const {
1497 return mutator_thread()->zone();
1498 }
1499
1500 // Accessed from generated code.
1501 // ** This block of fields must come first! **
1502 // For AOT cross-compilation, we rely on these members having the same offsets
1503 // in SIMARM(IA32) and ARM, and the same offsets in SIMARM64(X64) and ARM64.
1504 // We use only word-sized fields to avoid differences in struct packing on the
1505 // different architectures. See also CheckOffsets in dart.cc.
1506 uword user_tag_ = 0;
1507 UserTagPtr current_tag_;
1508 UserTagPtr default_tag_;
1509 FieldTable* field_table_ = nullptr;
1510 // Used to clear out `UntaggedFinalizerBase::isolate_` pointers on isolate
1511 // shutdown to prevent usage of dangling pointers.
1512 GrowableObjectArrayPtr finalizers_;
1513 bool single_step_ = false;
1514 bool has_resumption_breakpoints_ = false;
1515 bool is_system_isolate_ = false;
1516 // End accessed from generated code.
1517
1518 IsolateGroup* const isolate_group_;
1519 IdleTimeHandler idle_time_handler_;
1520 std::unique_ptr<IsolateObjectStore> isolate_object_store_;
1521
1522#define ISOLATE_FLAG_BITS(V) \
1523 V(ErrorsFatal) \
1524 V(IsRunnable) \
1525 V(IsVMIsolate) \
1526 V(IsServiceIsolate) \
1527 V(IsKernelIsolate) \
1528 V(ResumeRequest) \
1529 V(HasAttemptedStepping) \
1530 V(ShouldPausePostServiceRequest) \
1531 V(IsSystemIsolate) \
1532 V(IsServiceRegistered)
1533
1534 // Isolate specific flags.
1535 enum FlagBits {
1536#define DECLARE_BIT(Name) k##Name##Bit,
1538#undef DECLARE_BIT
1539 };
1540
1541#define DECLARE_BITFIELD(Name) \
1542 class Name##Bit : public BitField<uint32_t, bool, k##Name##Bit, 1> {};
1544#undef DECLARE_BITFIELD
1545
1546 template <class T>
1547 bool UpdateIsolateFlagsBit(bool value) {
1548 return T::decode(value ? isolate_flags_.fetch_or(T::encode(true),
1549 std::memory_order_relaxed)
1550 : isolate_flags_.fetch_and(
1551 ~T::encode(true), std::memory_order_relaxed));
1552 }
1553 template <class T>
1554 bool LoadIsolateFlagsBit() const {
1555 return T::decode(isolate_flags_.load(std::memory_order_relaxed));
1556 }
1557 std::atomic<uint32_t> isolate_flags_;
1558
1559// Fields that aren't needed in a product build go here with boolean flags at
1560// the top.
1561#if !defined(PRODUCT)
1562 Debugger* debugger_ = nullptr;
1563
1564 // SampleBlock containing CPU profiling samples.
1565 RelaxedAtomic<SampleBlock*> current_sample_block_ = nullptr;
1566
1567 // SampleBlock containing Dart allocation profiling samples.
1568 RelaxedAtomic<SampleBlock*> current_allocation_sample_block_ = nullptr;
1569
1570 RelaxedAtomic<uword> has_completed_blocks_ = {0};
1571
1572 int64_t last_resume_timestamp_;
1573
1574 VMTagCounters vm_tag_counters_;
1575
1576 // We use 6 list entries for each pending service extension calls.
1577 enum {kPendingHandlerIndex = 0, kPendingMethodNameIndex, kPendingKeysIndex,
1578 kPendingValuesIndex, kPendingReplyPortIndex, kPendingIdIndex,
1579 kPendingEntrySize};
1580 GrowableObjectArrayPtr pending_service_extension_calls_;
1581
1582 // We use 2 list entries for each registered extension handler.
1583 enum {kRegisteredNameIndex = 0, kRegisteredHandlerIndex,
1584 kRegisteredEntrySize};
1585 GrowableObjectArrayPtr registered_service_extension_handlers_;
1586
1587 // Used to wake the isolate when it is in the pause event loop.
1588 Monitor* pause_loop_monitor_ = nullptr;
1589
1590#define ISOLATE_METRIC_VARIABLE(type, variable, name, unit) \
1591 type metric_##variable##_;
1593#undef ISOLATE_METRIC_VARIABLE
1594
1595 // Ring buffer of objects assigned an id.
1596 ObjectIdRing* object_id_ring_ = nullptr;
1597#endif // !defined(PRODUCT)
1598
1599 // All other fields go here.
1600 int64_t start_time_micros_;
1601 std::atomic<Dart_MessageNotifyCallback> message_notify_callback_;
1602 Dart_IsolateShutdownCallback on_shutdown_callback_ = nullptr;
1603 Dart_IsolateCleanupCallback on_cleanup_callback_ = nullptr;
1604 char* name_ = nullptr;
1605 Dart_Port main_port_ = 0;
1606 // Isolates created by Isolate.spawn have the same origin id.
1607 Dart_Port origin_id_ = 0;
1608 Mutex origin_id_mutex_;
1609 uint64_t pause_capability_ = 0;
1610 uint64_t terminate_capability_ = 0;
1611 void* init_callback_data_ = nullptr;
1612 Dart_EnvironmentCallback environment_callback_ = nullptr;
1613 Random random_;
1614 Simulator* simulator_ = nullptr;
1615 Mutex mutex_; // Protects compiler stats.
1616 IsolateMessageHandler* message_handler_ = nullptr;
1617 intptr_t defer_finalization_count_ = 0;
1618 DeoptContext* deopt_context_ = nullptr;
1619 FfiCallbackMetadata::Metadata* ffi_callback_list_head_ = nullptr;
1620 intptr_t ffi_callback_keep_alive_counter_ = 0;
1621
1622 GrowableObjectArrayPtr tag_table_;
1623
1624 ErrorPtr sticky_error_;
1625
1626 std::unique_ptr<Bequest> bequest_;
1627 Dart_Port beneficiary_ = 0;
1628
1629 // This guards spawn_count_. An isolate cannot complete shutdown and be
1630 // destroyed while there are child isolates in the midst of a spawn.
1631 Monitor spawn_count_monitor_;
1632 intptr_t spawn_count_ = 0;
1633
1634 HandlerInfoCache handler_info_cache_;
1635 CatchEntryMovesCache catch_entry_moves_cache_;
1636
1637 DispatchTable* dispatch_table_ = nullptr;
1638
1639 // Used during message sending of messages between isolates.
1640 std::unique_ptr<WeakTable> forward_table_new_;
1641 std::unique_ptr<WeakTable> forward_table_old_;
1642
1643 // Signals whether the isolate can receive messages (e.g. KillAllIsolates can
1644 // send a kill message).
1645 // This is protected by [isolate_creation_monitor_].
1646 bool accepts_messages_ = false;
1647
1648 std::unique_ptr<VirtualMemory> regexp_backtracking_stack_cache_ = nullptr;
1649
1650 intptr_t wake_pause_event_handler_count_;
1651
1652 // The number of open [ReceivePort]s the isolate owns.
1653 intptr_t open_ports_ = 0;
1654
1655 // The number of open [ReceivePort]s that keep the isolate alive.
1656 intptr_t open_ports_keepalive_ = 0;
1657
1658 static Dart_IsolateGroupCreateCallback create_group_callback_;
1659 static Dart_InitializeIsolateCallback initialize_callback_;
1660 static Dart_IsolateShutdownCallback shutdown_callback_;
1661 static Dart_IsolateCleanupCallback cleanup_callback_;
1662 static Dart_IsolateGroupCleanupCallback cleanup_group_callback_;
1663 static Dart_RegisterKernelBlobCallback register_kernel_blob_callback_;
1664 static Dart_UnregisterKernelBlobCallback unregister_kernel_blob_callback_;
1665
1666#if !defined(PRODUCT)
1667 static void WakePauseEventHandler(Dart_Isolate isolate);
1668#endif
1669
1670 // Manage list of existing isolates.
1671 static bool TryMarkIsolateReady(Isolate* isolate);
1672 static void UnMarkIsolateReady(Isolate* isolate);
1673 static void MaybeNotifyVMShutdown();
1674 bool AcceptsMessagesLocked() {
1675 ASSERT(isolate_creation_monitor_->IsOwnedByCurrentThread());
1676 return accepts_messages_;
1677 }
1678
1679 // This monitor protects [creation_enabled_].
1680 static Monitor* isolate_creation_monitor_;
1681 static bool creation_enabled_;
1682
1683 ArrayPtr loaded_prefixes_set_storage_;
1684
1685 MallocGrowableArray<ObjectPtr> pointers_to_verify_at_exit_;
1686
1687#define REUSABLE_FRIEND_DECLARATION(name) \
1688 friend class Reusable##name##HandleScope;
1690#undef REUSABLE_FRIEND_DECLARATION
1691
1692 friend class Become; // VisitObjectPointers
1693 friend class GCCompactor; // VisitObjectPointers
1694 friend class GCMarker; // VisitObjectPointers
1695 friend class SafepointHandler;
1696 friend class ObjectGraph; // VisitObjectPointers
1697 friend class HeapSnapshotWriter; // VisitObjectPointers
1698 friend class Scavenger; // VisitObjectPointers
1699 friend class HeapIterationScope; // VisitObjectPointers
1700 friend class ServiceIsolate;
1701 friend class Thread;
1702 friend class Timeline;
1703 friend class IsolateGroup; // reload_context_
1704
1706};
1707
1708// When we need to execute code in an isolate, we use the
1709// StartIsolateScope.
1711 public:
1712 explicit StartIsolateScope(Isolate* new_isolate)
1713 : new_isolate_(new_isolate), saved_isolate_(Isolate::Current()) {
1714 if (new_isolate_ == nullptr) {
1715 ASSERT(Isolate::Current() == nullptr);
1716 // Do nothing.
1717 return;
1718 }
1719 if (saved_isolate_ != new_isolate_) {
1720 ASSERT(Isolate::Current() == nullptr);
1721 Thread::EnterIsolate(new_isolate_);
1722 // Ensure this is not a nested 'isolate enter' with prior state.
1723 ASSERT(Thread::Current()->top_exit_frame_info() == 0);
1724 }
1725 }
1726
1728 if (new_isolate_ == nullptr) {
1729 ASSERT(Isolate::Current() == nullptr);
1730 // Do nothing.
1731 return;
1732 }
1733 if (saved_isolate_ != new_isolate_) {
1734 ASSERT(saved_isolate_ == nullptr);
1735 // ASSERT that we have bottomed out of all Dart invocations.
1736 ASSERT(Thread::Current()->top_exit_frame_info() == 0);
1738 }
1739 }
1740
1741 private:
1742 Isolate* new_isolate_;
1743 Isolate* saved_isolate_;
1744
1746};
1747
1749 public:
1750 explicit EnterIsolateGroupScope(IsolateGroup* isolate_group)
1751 : isolate_group_(isolate_group) {
1752 ASSERT(IsolateGroup::Current() == nullptr);
1754 isolate_group_, Thread::kUnknownTask, /*bypass_safepoint=*/false);
1755 ASSERT(result);
1756 }
1757
1759 Thread::ExitIsolateGroupAsHelper(/*bypass_safepoint=*/false);
1760 }
1761
1762 private:
1763 IsolateGroup* isolate_group_;
1764
1766};
1767
1768// Ensure that isolate is not available for the duration of this scope.
1769//
1770// This can be used in code (e.g. GC, Kernel Loader, Compiler) that should not
1771// operate on an individual isolate.
1773 public:
1776 : StackResource(thread), thread_(thread) {
1777 outer_ = thread_->no_active_isolate_scope_;
1778 saved_isolate_ = thread_->isolate_;
1779
1780 thread_->no_active_isolate_scope_ = this;
1781 thread_->isolate_ = nullptr;
1782 }
1784 ASSERT(thread_->isolate_ == nullptr);
1785 thread_->isolate_ = saved_isolate_;
1786 thread_->no_active_isolate_scope_ = outer_;
1787 }
1788
1789 private:
1791
1792 Thread* thread_;
1793 Isolate* saved_isolate_;
1794 NoActiveIsolateScope* outer_;
1795};
1796
1798 public:
1801 thread->no_active_isolate_scope_->saved_isolate_) {}
1802
1804 : StackResource(thread), thread_(thread) {
1805 RELEASE_ASSERT(thread->isolate() == nullptr);
1806 thread_->isolate_ = isolate;
1807 }
1809 ASSERT(thread_->isolate_ != nullptr);
1810 thread_->isolate_ = nullptr;
1811 }
1812
1813 private:
1814 Thread* thread_;
1815};
1816
1817} // namespace dart
1818
1819#endif // RUNTIME_VM_ISOLATE_H_
static void encode(uint8_t output[16], const uint32_t input[4])
Definition SkMD5.cpp:240
SI F table(const skcms_Curve *curve, F v)
#define RELEASE_ASSERT(cond)
Definition assert.h:327
#define COMPILE_ASSERT(expr)
Definition assert.h:339
T load(std::memory_order order=std::memory_order_acquire) const
Definition atomic.h:101
void store(T arg, std::memory_order order=std::memory_order_release)
Definition atomic.h:104
ActiveIsolateScope(Thread *thread, Isolate *isolate)
Definition isolate.h:1803
ActiveIsolateScope(Thread *thread)
Definition isolate.h:1799
Thread * scheduled_mutator_thread_
PersistentHandle * TakeHandle()
Definition isolate.h:897
Bequest(PersistentHandle *handle, Dart_Port beneficiary)
Definition isolate.h:892
PersistentHandle * handle()
Definition isolate.h:896
Dart_Port beneficiary()
Definition isolate.h:902
virtual void Call()=0
virtual ~Callable()
Definition isolate.h:108
EnterIsolateGroupScope(IsolateGroup *isolate_group)
Definition isolate.h:1750
ObjectPtr * table()
Definition field_table.h:42
void InitializeWithHeap(Heap *heap)
Definition isolate.cc:190
bool ShouldNotifyIdle(int64_t *expiry)
Definition isolate.cc:209
void NotifyIdleUsingDefaultDeadline()
Definition isolate.cc:240
void NotifyIdle(int64_t deadline)
Definition isolate.cc:225
const uint8_t * script_kernel_buffer
Definition isolate.h:199
Dart_IsolateFlags flags
Definition isolate.h:196
const uint8_t * kernel_buffer
Definition isolate.h:194
intptr_t script_kernel_size
Definition isolate.h:200
const intptr_t kernel_buffer_size
Definition isolate.h:195
IsolateGroupSource(const char *script_uri, const char *name, const uint8_t *snapshot_data, const uint8_t *snapshot_instructions, const uint8_t *kernel_buffer, intptr_t kernel_buffer_size, Dart_IsolateFlags flags)
Definition isolate.h:162
const uint8_t * snapshot_instructions
Definition isolate.h:193
const uint8_t * snapshot_data
Definition isolate.h:192
void add_loaded_blob(Zone *zone_, const ExternalTypedData &external_typed_data)
Definition isolate.cc:133
void IncreaseMutatorCount(Isolate *mutator, bool is_nested_reenter)
Definition isolate.cc:584
Random * random()
Definition isolate.h:410
GroupDebugger * debugger() const
Definition isolate.h:314
void RunWithLockedGroup(std::function< void()> fun)
Definition isolate.cc:460
int64_t UptimeMicros() const
Definition isolate.cc:1946
void RestoreOriginalClassTable()
Definition isolate.cc:3777
void set_use_osr(bool use_osr)
Definition isolate.h:483
bool ReloadKernel(JSONStream *js, bool force_reload, const uint8_t *kernel_buffer=nullptr, intptr_t kernel_buffer_size=0, bool dont_delete_reload_context=false)
Definition isolate.cc:2066
StoreBuffer * store_buffer() const
Definition isolate.h:504
bool remapping_cids() const
Definition isolate.h:714
void UnregisterIsolate(Isolate *isolate)
Definition isolate.cc:465
Mutex * kernel_data_class_cache_mutex()
Definition isolate.h:519
void ForEachIsolate(std::function< void(Isolate *isolate)> function, bool at_safepoint=false)
Definition isolate.cc:2798
void set_cached_class_table_table(ClassPtr *cached_class_table_table)
Definition isolate.h:392
bool UnregisterIsolateDecrementCount()
Definition isolate.cc:470
void DeleteReloadContext()
Definition isolate.cc:2095
void VisitStackPointers(ObjectPointerVisitor *visitor, ValidationPolicy validate_frames)
Definition isolate.cc:2924
MutatorThreadPool * thread_pool()
Definition isolate.h:736
bool should_load_vmservice() const
Definition isolate.h:444
static bool IsSystemIsolateGroup(const IsolateGroup *group)
Definition isolate.cc:3559
void ScheduleInterrupts(uword interrupt_bits)
Definition isolate.cc:1924
intptr_t optimization_counter_threshold() const
Definition isolate.h:305
void RegisterClass(const Class &cls)
Definition isolate.cc:763
const char ** obfuscation_map() const
Definition isolate.h:408
ClassTableAllocator * class_table_allocator()
Definition isolate.h:380
Become * become() const
Definition isolate.h:670
bool all_classes_finalized() const
Definition isolate.h:706
void * embedder_data() const
Definition isolate.h:290
void RehashConstants(Become *become)
Definition isolate.cc:851
void FlagsCopyFrom(const Dart_IsolateFlags &api_flags)
Definition isolate.cc:1586
void DropOriginalClassTable()
Definition isolate.cc:3784
MarkingStack * deferred_marking_stack() const
Definition isolate.h:571
void set_should_load_vmservice(bool value)
Definition isolate.h:447
void set_all_classes_finalized(bool value)
Definition isolate.h:709
Heap * heap() const
Definition isolate.h:295
bool initial_spawn_successful()
Definition isolate.h:292
void set_dispatch_table_snapshot(const uint8_t *snapshot)
Definition isolate.h:370
bool ContainsOnlyOneIsolate()
Definition isolate.cc:452
void FreeStaticField(const Field &field)
Definition isolate.cc:816
ObjectStore * object_store() const
Definition isolate.h:505
SafepointRwLock * program_lock()
Definition isolate.h:532
ClassPtr * cached_class_table_table()
Definition isolate.h:389
void DisableIncrementalBarrier()
Definition isolate.cc:2791
void CloneClassTableForReload()
Definition isolate.cc:3771
static IsolateGroup * Current()
Definition isolate.h:534
std::shared_ptr< IsolateGroupSource > shareable_source() const
Definition isolate.h:286
Dart_LibraryTagHandler library_tag_handler() const
Definition isolate.h:550
void RegisterStaticField(const Field &field, const Object &initial_value)
Definition isolate.cc:783
ClassTable * class_table() const
Definition isolate.h:491
void set_last_reload_timestamp(int64_t value)
Definition isolate.h:644
static intptr_t class_table_offset()
Definition isolate.h:384
static bool HasOnlyVMIsolateGroup()
Definition isolate.cc:718
bool is_system_isolate_group() const
Definition isolate.h:412
void DecreaseMutatorCount(Isolate *mutator, bool is_nested_exit)
Definition isolate.cc:612
void set_initial_field_table(std::shared_ptr< FieldTable > field_table)
Definition isolate.h:732
Mutex * type_arguments_canonicalization_mutex()
Definition isolate.h:508
void VisitObjectIdRingPointers(ObjectPointerVisitor *visitor)
Definition isolate.cc:2941
IsolateGroupReloadContext * reload_context()
Definition isolate.h:649
uint64_t id() const
Definition isolate.h:673
void set_object_store(ObjectStore *object_store)
Definition isolate.cc:1036
Mutex * initializer_functions_mutex()
Definition isolate.h:529
ApiState * api_state() const
Definition isolate.h:693
FieldTable * initial_field_table() const
Definition isolate.h:728
intptr_t reload_every_n_stack_overflow_checks() const
Definition isolate.h:472
void VisitObjectPointers(ObjectPointerVisitor *visitor, ValidationPolicy validate_frames)
Definition isolate.cc:2868
void set_library_tag_handler(Dart_LibraryTagHandler handler)
Definition isolate.h:553
IsolateGroupSource * source() const
Definition isolate.h:285
bool ReloadSources(JSONStream *js, bool force_reload, const char *root_script_url=nullptr, const char *packages_url=nullptr, bool dont_delete_reload_context=false)
Definition isolate.cc:2037
void set_saved_unlinked_calls(const Array &saved_unlinked_calls)
Definition isolate.cc:580
void SetHasAttemptedReload(bool value)
Definition isolate.h:467
void SetupImagePage(const uint8_t *snapshot_buffer, bool is_executable)
Definition isolate.cc:1917
int64_t last_allocationprofile_gc_timestamp() const
Definition isolate.h:358
ClassTable * heap_walk_class_table() const
Definition isolate.h:498
Mutex * kernel_constants_mutex()
Definition isolate.h:522
ArrayPtr saved_unlinked_calls() const
Definition isolate.h:725
void set_remapping_cids(bool value)
Definition isolate.h:717
void RunWithStoppedMutators(T single_current_mutator, S otherwise, bool use_force_growth_in_otherwise=false)
Definition isolate.h:604
Mutex * type_feedback_mutex()
Definition isolate.h:513
Isolate * FirstIsolateLocked() const
Definition isolate.cc:2830
void PrintJSON(JSONStream *stream, bool ref=true)
Definition isolate.cc:637
void EnableIncrementalBarrier(MarkingStack *marking_stack, MarkingStack *deferred_marking_stack)
Definition isolate.cc:2781
Mutex * type_canonicalization_mutex()
Definition isolate.h:507
void ReleaseStoreBuffers()
Definition isolate.cc:2740
void set_obfuscation_map(const char **map)
Definition isolate.h:407
static void ExitTemporaryIsolate()
Definition isolate.cc:844
void RememberLiveTemporaries()
Definition isolate.cc:2962
void FlagsCopyTo(Dart_IsolateFlags *api_flags)
Definition isolate.cc:1575
void RunWithStoppedMutatorsCallable(Callable *single_current_mutator, Callable *otherwise, bool use_force_growth_in_otherwise=false)
Definition isolate.cc:2834
SafepointHandler * safepoint_handler()
Definition isolate.h:333
void set_initial_spawn_successful()
Definition isolate.h:293
Mutex * patchable_call_mutex()
Definition isolate.h:514
intptr_t MutatorCount() const
Definition isolate.h:541
void set_become(Become *become)
Definition isolate.h:671
std::shared_ptr< FieldTable > initial_field_table_shareable()
Definition isolate.h:729
void VisitWeakPersistentHandles(HandleVisitor *visitor)
Definition isolate.cc:2952
static void RunWithIsolateGroup(uint64_t id, std::function< void(IsolateGroup *)> action, std::function< void()> not_found)
Definition isolate.cc:684
void set_dispatch_table_snapshot_size(intptr_t size)
Definition isolate.h:376
void DeferredMarkLiveTemporaries()
Definition isolate.cc:2956
Mutex * constant_canonicalization_mutex()
Definition isolate.h:515
bool IsReloading() const
Definition isolate.h:662
void RegisterIsolate(Isolate *isolate)
Definition isolate.cc:445
int64_t last_reload_timestamp() const
Definition isolate.h:647
Mutex * kernel_data_lib_cache_mutex()
Definition isolate.h:518
void MaybeIncreaseReloadEveryNStackOverflowChecks()
Definition isolate.cc:2496
void set_branch_coverage(bool value)
Definition isolate.h:457
intptr_t dispatch_table_snapshot_size() const
Definition isolate.h:373
DispatchTable * dispatch_table() const
Definition isolate.h:363
ISOLATE_GROUP_METRIC_LIST(ISOLATE_METRIC_ACCESSOR)
BackgroundCompiler * background_compiler() const
Definition isolate.h:297
void UpdateLastAllocationProfileAccumulatorResetTimestamp()
Definition isolate.h:345
static void RegisterIsolateGroup(IsolateGroup *isolate_group)
Definition isolate.cc:698
MarkingStack * marking_stack() const
Definition isolate.h:570
ThreadRegistry * thread_registry() const
Definition isolate.h:332
Isolate * FirstIsolate() const
Definition isolate.cc:2825
ObjectPtr CallTagHandler(Dart_LibraryTag tag, const Object &arg1, const Object &arg2)
Definition isolate.cc:1889
Mutex * symbols_mutex()
Definition isolate.h:506
Mutex * megamorphic_table_mutex()
Definition isolate.h:512
static intptr_t cached_class_table_table_offset()
Definition isolate.h:395
IdleTimeHandler * idle_time_handler()
Definition isolate.h:317
bool HasAttemptedReload() const
Definition isolate.h:464
bool is_vm_isolate() const
Definition isolate.h:289
Isolate * EnterTemporaryIsolate()
Definition isolate.cc:835
static bool HasApplicationIsolateGroups()
Definition isolate.cc:708
static void Init()
Definition isolate.cc:728
Dart_DeferredLoadHandler deferred_load_handler() const
Definition isolate.h:556
void PrintToJSONObject(JSONObject *jsobj, bool ref)
Definition isolate.cc:642
static void ForEach(std::function< void(IsolateGroup *)> action)
Definition isolate.cc:677
void FlushMarkingStacks()
Definition isolate.cc:2744
const uint8_t * dispatch_table_snapshot() const
Definition isolate.h:367
void RunWithStoppedMutators(T function, bool use_force_growth=false)
Definition isolate.h:614
Mutex * subtype_test_cache_mutex()
Definition isolate.h:511
int64_t last_allocationprofile_accumulator_reset_timestamp() const
Definition isolate.h:350
ProgramReloadContext * program_reload_context()
Definition isolate.h:652
void VisitSharedPointers(ObjectPointerVisitor *visitor)
Definition isolate.cc:2877
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
Definition isolate.cc:1564
void set_deferred_load_handler(Dart_DeferredLoadHandler handler)
Definition isolate.h:559
void set_asserts(bool value)
Definition isolate.h:452
void CreateHeap(bool is_vm_isolate, bool is_service_or_kernel_isolate)
Definition isolate.cc:476
void UpdateLastAllocationProfileGCTimestamp()
Definition isolate.h:354
static intptr_t object_store_offset()
Definition isolate.h:402
static void UnregisterIsolateGroup(IsolateGroup *isolate_group)
Definition isolate.cc:703
static void Cleanup()
Definition isolate.cc:736
bool HasTagHandler() const
Definition isolate.h:546
void PrintMemoryUsageJSON(JSONStream *stream)
Definition isolate.cc:662
void set_dispatch_table(DispatchTable *table)
Definition isolate.h:364
virtual void VisitIsolate(Isolate *isolate)=0
virtual ~IsolateVisitor()
Definition isolate.h:93
bool IsSystemIsolate(Isolate *isolate) const
Definition isolate.cc:746
static intptr_t user_tag_offset()
Definition isolate.h:1281
void set_forward_table_old(WeakTable *table)
Definition isolate.cc:2516
ReceivePortPtr CreateReceivePort(const String &debug_name)
Definition isolate.cc:3712
IsolateGroupSource * source() const
Definition isolate.h:989
void set_should_pause_post_service_request(bool value)
Definition isolate.h:1273
bool AddResumeCapability(const Capability &capability)
Definition isolate.cc:2161
bool HasLivePorts()
Definition isolate.cc:3706
intptr_t BlockClassFinalization()
Definition isolate.h:1238
bool single_step() const
Definition isolate.h:1086
Thread * scheduled_mutator_thread() const
Definition isolate.h:945
void AddExitListener(const SendPort &listener, const Instance &response)
Definition isolate.cc:2212
bool GetAndClearResumeRequest()
Definition isolate.h:1116
void AddErrorListener(const SendPort &listener)
Definition isolate.cc:2280
FfiCallbackMetadata::Trampoline CreateAsyncFfiCallback(Zone *zone, const Function &send_function, Dart_Port send_port)
Definition isolate.cc:3686
bool TrySetHasCompletedBlocks()
Definition isolate.h:1081
Dart_EnvironmentCallback environment_callback() const
Definition isolate.h:1028
ErrorPtr sticky_error() const
Definition isolate.h:1310
UserTagPtr current_tag() const
Definition isolate.h:1301
Simulator * simulator() const
Definition isolate.h:1146
int64_t last_resume_timestamp() const
Definition isolate.h:1112
FfiCallbackMetadata::Metadata * ffi_callback_list_head()
Definition isolate.h:1234
void set_deopt_context(DeoptContext *value)
Definition isolate.h:1209
static bool IsSystemIsolate(const Isolate *isolate)
Definition isolate.h:1398
FieldTable * field_table() const
Definition isolate.h:953
static void DisableIsolateCreation()
Definition isolate.cc:3544
void ScheduleInterrupts(uword interrupt_bits)
Definition isolate.cc:1931
void RememberLiveTemporaries()
Definition isolate.cc:2748
@ kDrainServiceExtensionsMsg
Definition isolate.h:927
uword user_tag() const
Definition isolate.h:1280
ObjectIdRing * object_id_ring() const
Definition isolate.h:1203
void SetResumeRequest()
Definition isolate.h:1103
static Isolate * Current()
Definition isolate.h:939
bool ErrorsFatal() const
Definition isolate.h:1139
static bool IsVMInternalIsolate(const Isolate *isolate)
Definition isolate.cc:3563
void set_on_shutdown_callback(Dart_IsolateShutdownCallback value)
Definition isolate.h:972
void DeferredMarkLiveTemporaries()
Definition isolate.cc:2754
static void KillIfExists(Isolate *isolate, LibMsgId msg_id)
Definition isolate.cc:3660
void set_has_resumption_breakpoints(bool value)
Definition isolate.h:1091
static bool IsolateCreationEnabled()
Definition isolate.cc:3554
IsolateObjectStore * isolate_object_store() const
Definition isolate.h:960
void FlagsCopyTo(Dart_IsolateFlags *api_flags) const
Definition isolate.cc:1625
bool TakeHasCompletedBlocks()
Definition isolate.h:1078
static intptr_t single_step_offset()
Definition isolate.h:1087
VMTagCounters * vm_tag_counters()
Definition isolate.h:1264
static void KillAllSystemIsolates(LibMsgId msg_id)
Definition isolate.cc:3655
static void VisitIsolates(IsolateVisitor *visitor)
Definition isolate.cc:3485
Debugger * debugger() const
Definition isolate.h:1061
bool VerifyPauseCapability(const Object &capability) const
Definition isolate.cc:2151
ISOLATE_METRIC_LIST(ISOLATE_METRIC_ACCESSOR)
void DeleteFfiCallback(FfiCallbackMetadata::Trampoline callback)
Definition isolate.cc:3755
@ kBeforeNextEventAction
Definition isolate.h:933
UserTagPtr default_tag() const
Definition isolate.h:1304
MallocGrowableArray< ObjectPtr > * pointers_to_verify_at_exit()
Definition isolate.h:1432
void NotifyExitListeners()
Definition isolate.cc:2263
bool IsPrefixLoaded(const LibraryPrefix &prefix) const
Definition isolate.cc:2766
void DecrementSpawnCount()
Definition isolate.cc:3670
bool RemoveResumeCapability(const Capability &capability)
Definition isolate.cc:2194
SafepointHandler * safepoint_handler() const
Definition isolate.h:949
void PrintJSON(JSONStream *stream, bool ref=true)
Definition isolate.cc:3038
bool has_attempted_stepping() const
Definition isolate.h:1374
bool ResumeRequest() const
Definition isolate.h:1101
void SetErrorsFatal(bool value)
Definition isolate.h:1140
MessageHandler * message_handler() const
Definition isolate.cc:2380
void set_field_table(Thread *T, FieldTable *field_table)
Definition isolate.h:954
ObjectPtr CallDeferredLoadHandler(intptr_t id)
Definition isolate.cc:1905
intptr_t UnblockClassFinalization()
Definition isolate.h:1243
void PrintPauseEventJSON(JSONStream *stream)
Definition isolate.cc:3166
static Dart_IsolateShutdownCallback ShutdownCallback()
Definition isolate.h:1170
bool is_vm_isolate() const
Definition isolate.h:1333
friend class ObjectGraph
Definition isolate.h:1696
void SetReceivePortKeepAliveState(const ReceivePort &receive_port, bool keep_isolate_alive)
Definition isolate.cc:3719
FfiCallbackMetadata::Trampoline CreateIsolateLocalFfiCallback(Zone *zone, const Function &trampoline, const Closure &target, bool keep_isolate_alive)
Definition isolate.cc:3694
void SetPrefixIsLoaded(const LibraryPrefix &prefix)
Definition isolate.cc:2774
void RegisterServiceExtensionHandler(const String &name, const Instance &closure)
Definition isolate.cc:3339
static void FlagsInitialize(Dart_IsolateFlags *api_flags)
Definition isolate.cc:1612
void PrintMemoryUsageJSON(JSONStream *stream)
Definition isolate.cc:3162
static void SetShutdownCallback(Dart_IsolateShutdownCallback cb)
Definition isolate.h:1167
static void KillAllIsolates(LibMsgId msg_id)
Definition isolate.cc:3650
static intptr_t finalizers_offset()
Definition isolate.h:1024
void set_on_cleanup_callback(Dart_IsolateCleanupCallback value)
Definition isolate.h:978
static std::unique_ptr< char[]> LookupIsolateNameByPort(Dart_Port port)
Definition isolate.cc:3515
bool HasPendingMessages()
Definition isolate.cc:1320
static intptr_t IsolateListLength()
Definition isolate.cc:3495
void set_current_sample_block(SampleBlock *block)
Definition isolate.h:1065
void * init_callback_data() const
Definition isolate.h:1021
uint64_t terminate_capability() const
Definition isolate.h:1013
ThreadRegistry * thread_registry() const
Definition isolate.h:947
void set_terminate_capability(uint64_t value)
Definition isolate.h:1010
static intptr_t default_tag_offset()
Definition isolate.h:1285
void set_is_runnable(bool value)
Definition isolate.h:1049
void CloseReceivePort(const ReceivePort &receive_port)
Definition isolate.cc:3739
void set_last_resume_timestamp()
Definition isolate.h:1108
bool HasDeferredLoadHandler() const
Definition isolate.h:1035
const char * MakeRunnable()
Definition isolate.cc:2104
Dart_IsolateShutdownCallback on_shutdown_callback()
Definition isolate.h:975
GrowableObjectArrayPtr tag_table() const
Definition isolate.h:1298
void set_simulator(Simulator *value)
Definition isolate.h:1147
void SendInternalLibMessage(LibMsgId msg_id, uint64_t capability)
Definition isolate.cc:997
bool VerifyTerminateCapability(const Object &capability) const
Definition isolate.cc:2156
Mutex * mutex()
Definition isolate.h:1058
void WaitForOutstandingSpawns()
Definition isolate.cc:3677
void set_forward_table_new(WeakTable *table)
Definition isolate.cc:2512
int64_t UptimeMicros() const
Definition isolate.cc:1950
void UpdateNativeCallableKeepIsolateAliveCounter(intptr_t delta)
Definition isolate.cc:3760
ObjectIdRing * EnsureObjectIdRing()
Definition isolate.cc:2968
static Dart_IsolateCleanupCallback CleanupCallback()
Definition isolate.h:1177
ErrorPtr InvokePendingServiceExtensionCalls()
Definition isolate.cc:3207
friend class HeapSnapshotWriter
Definition isolate.h:1697
void MakeRunnableLocked()
Definition isolate.cc:2118
SampleBlock * current_sample_block() const
Definition isolate.h:1064
void set_environment_callback(Dart_EnvironmentCallback value)
Definition isolate.h:1031
DART_WARN_UNUSED_RESULT ErrorPtr StealStickyError()
Definition isolate.cc:3187
void set_main_port(Dart_Port port)
Definition isolate.h:1002
ErrorPtr PausePostRequest()
Definition isolate.cc:1977
bool should_pause_post_service_request() const
Definition isolate.h:1270
static void EnableIsolateCreation()
Definition isolate.cc:3549
void AppendServiceExtensionCall(const Instance &closure, const String &method_name, const Array &parameter_keys, const Array &parameter_values, const Instance &reply_port, const Instance &id)
Definition isolate.cc:3286
HandlerInfoCache * handler_info_cache()
Definition isolate.h:1403
IsolateGroup * group() const
Definition isolate.h:990
static void SetCleanupCallback(Dart_IsolateCleanupCallback cb)
Definition isolate.h:1174
static intptr_t current_tag_offset()
Definition isolate.h:1282
Random * random()
Definition isolate.h:1144
static void SetInitializeCallback_(Dart_InitializeIsolateCallback cb)
Definition isolate.h:1160
static Dart_IsolateGroupCreateCallback CreateGroupCallback()
Definition isolate.h:1156
void CacheRegexpBacktrackStack(std::unique_ptr< VirtualMemory > stack)
Definition isolate.h:1424
WeakTable * forward_table_old()
Definition isolate.h:1414
void set_current_tag(const UserTag &tag)
Definition isolate.cc:3176
bool IsDeoptimizing() const
Definition isolate.h:1207
void set_has_attempted_stepping(bool value)
Definition isolate.h:1377
void set_init_callback_data(void *value)
Definition isolate.h:1020
Dart_MessageNotifyCallback message_notify_callback() const
Definition isolate.h:964
InstancePtr LookupServiceExtensionHandler(const String &name)
Definition isolate.cc:3375
CatchEntryMovesCache * catch_entry_moves_cache()
Definition isolate.h:1405
bool is_service_registered() const
Definition isolate.h:1338
void set_name(const char *name)
Definition isolate.cc:1941
static Dart_IsolateGroupCleanupCallback GroupCleanupCallback()
Definition isolate.h:1184
static void SetGroupCleanupCallback(Dart_IsolateGroupCleanupCallback cb)
Definition isolate.h:1181
std::unique_ptr< VirtualMemory > TakeRegexpBacktrackStack()
Definition isolate.h:1420
WeakTable * forward_table_new()
Definition isolate.h:1411
void FlagsCopyFrom(const Dart_IsolateFlags &api_flags)
Definition isolate.cc:1638
void set_finalizers(const GrowableObjectArray &value)
Definition isolate.cc:1965
void RemoveExitListener(const SendPort &listener)
Definition isolate.cc:2247
uint64_t pause_capability() const
Definition isolate.h:1009
static Isolate * LookupIsolateByPort(Dart_Port port)
Definition isolate.cc:3503
static Dart_UnregisterKernelBlobCallback UnregisterKernelBlobCallback()
Definition isolate.h:1198
bool NotifyErrorListeners(const char *msg, const char *stacktrace)
Definition isolate.cc:2326
bool AllowClassFinalization()
Definition isolate.h:1248
void init_loaded_prefixes_set_storage()
Definition isolate.cc:2760
void set_current_allocation_sample_block(SampleBlock *block)
Definition isolate.h:1074
bool IsPaused() const
Definition isolate.cc:1969
friend class Timeline
Definition isolate.h:1702
friend Isolate * CreateWithinExistingIsolateGroup(IsolateGroup *g, const char *n, char **e)
void set_is_service_registered(bool value)
Definition isolate.h:1341
void set_tag_table(const GrowableObjectArray &value)
Definition isolate.cc:3172
void PauseEventHandler()
Definition isolate.cc:3412
static Dart_InitializeIsolateCallback InitializeCallback()
Definition isolate.h:1163
static void SetRegisterKernelBlobCallback(Dart_RegisterKernelBlobCallback cb)
Definition isolate.h:1187
static void SetCreateGroupCallback(Dart_IsolateGroupCreateCallback cb)
Definition isolate.h:1153
Dart_IsolateCleanupCallback on_cleanup_callback()
Definition isolate.h:981
friend class IsolateGroup
Definition isolate.h:1703
DeoptContext * deopt_context() const
Definition isolate.h:1208
Thread * mutator_thread() const
Definition isolate.cc:1884
static intptr_t has_resumption_breakpoints_offset()
Definition isolate.h:1097
void set_single_step(bool value)
Definition isolate.h:1085
void set_default_tag(const UserTag &tag)
Definition isolate.cc:3183
Dart_Port origin_id()
Definition isolate.cc:1954
SampleBlock * current_allocation_sample_block() const
Definition isolate.h:1071
void IncrementSpawnCount()
Definition isolate.cc:3665
void set_origin_id(Dart_Port id)
Definition isolate.cc:1959
bool IsScheduled()
Definition isolate.h:944
static Dart_RegisterKernelBlobCallback RegisterKernelBlobCallback()
Definition isolate.h:1191
void RemoveErrorListener(const SendPort &listener)
Definition isolate.cc:2311
bool is_runnable() const
Definition isolate.h:1048
void ProcessFreeSampleBlocks(Thread *thread)
void set_message_notify_callback(Dart_MessageNotifyCallback value)
Definition isolate.h:968
void set_pause_capability(uint64_t value)
Definition isolate.h:1008
Dart_Port main_port() const
Definition isolate.h:1001
static void SetUnregisterKernelBlobCallback(Dart_UnregisterKernelBlobCallback cb)
Definition isolate.h:1194
bool has_resumption_breakpoints() const
Definition isolate.h:1094
void set_is_vm_isolate(bool value)
Definition isolate.h:1334
void SetStickyError(ErrorPtr sticky_error)
Definition isolate.cc:2368
const char * name() const
Definition isolate.h:996
bool HasOpenNativeCallables()
Definition isolate.cc:3765
void bequeath(std::unique_ptr< Bequest > bequest)
Definition isolate.h:985
LambdaCallable(T &lambda)
Definition isolate.h:119
bool IsOwnedByCurrentThread() const
Definition os_thread.h:370
MutatorThreadPool(IsolateGroup *isolate_group, intptr_t max_pool_size)
Definition isolate.h:253
virtual ~MutatorThreadPool()
Definition isolate.h:255
virtual void OnEnterIdleLocked(MonitorLocker *ml)
Definition isolate.cc:278
NoActiveIsolateScope(Thread *thread)
Definition isolate.h:1775
static int64_t GetCurrentTimeMillis()
T exchange(T arg, std::memory_order order=std::memory_order_relaxed)
Definition atomic.h:48
ThreadState * thread() const
Definition allocation.h:33
StartIsolateScope(Isolate *new_isolate)
Definition isolate.h:1712
Zone * zone() const
static Thread * Current()
Definition thread.h:361
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
Definition thread.cc:494
Isolate * isolate() const
Definition thread.h:533
IsolateGroup * isolate_group() const
Definition thread.h:540
static void EnterIsolate(Isolate *isolate)
Definition thread.cc:366
static void ExitIsolate(bool isolate_shutdown=false)
Definition thread.cc:423
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
Definition thread.cc:476
void(* Dart_UnregisterKernelBlobCallback)(const char *kernel_blob_uri)
Definition dart_api.h:893
Dart_Handle(* Dart_EnvironmentCallback)(Dart_Handle name)
Definition dart_api.h:3269
Dart_Isolate(* Dart_IsolateGroupCreateCallback)(const char *script_uri, const char *main, const char *package_root, const char *package_config, Dart_IsolateFlags *flags, void *isolate_data, char **error)
Definition dart_api.h:653
void(* Dart_IsolateCleanupCallback)(void *isolate_group_data, void *isolate_data)
Definition dart_api.h:728
int64_t Dart_Port
Definition dart_api.h:1524
void(* Dart_MessageNotifyCallback)(Dart_Isolate destination_isolate)
Definition dart_api.h:1541
const char *(* Dart_RegisterKernelBlobCallback)(const uint8_t *kernel_buffer, intptr_t kernel_buffer_size)
Definition dart_api.h:881
#define DART_WARN_UNUSED_RESULT
Definition dart_api.h:66
struct _Dart_Isolate * Dart_Isolate
Definition dart_api.h:88
bool(* Dart_InitializeIsolateCallback)(void **child_isolate_data, char **error)
Definition dart_api.h:692
void(* Dart_IsolateGroupCleanupCallback)(void *isolate_group_data)
Definition dart_api.h:744
Dart_LibraryTag
Definition dart_api.h:3339
void(* Dart_IsolateShutdownCallback)(void *isolate_group_data, void *isolate_data)
Definition dart_api.h:710
Dart_Handle(* Dart_LibraryTagHandler)(Dart_LibraryTag tag, Dart_Handle library_or_package_map_url, Dart_Handle url)
Definition dart_api.h:3378
Dart_Handle(* Dart_DeferredLoadHandler)(intptr_t loading_unit_id)
Definition dart_api.h:3413
#define ASSERT(E)
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
uint8_t value
GAsyncResult * result
uint32_t * target
constexpr intptr_t kDefaultOptimizationCounterThreshold
Definition flag_list.h:23
Dart_NativeFunction function
Definition fuchsia.cc:51
#define ISOLATE_METRIC_VARIABLE(type, variable, name, unit)
Definition isolate.h:813
#define DECLARE_BIT(Name)
Definition isolate.h:766
#define BOOL_ISOLATE_FLAG_LIST(V)
Definition isolate.h:151
#define ISOLATE_METRIC_ACCESSOR(type, variable, name, unit)
Definition isolate.h:339
#define BOOL_ISOLATE_GROUP_FLAG_LIST(V)
Definition isolate.h:136
#define ISOLATE_GROUP_FLAG_BITS(V)
Definition isolate.h:752
#define DECLARE_GETTER(when, name, bitname, isolate_flag_name, flag_name)
Definition isolate.h:433
#define DECLARE_BITFIELD(Name)
Definition isolate.h:771
#define REUSABLE_FRIEND_DECLARATION(name)
Definition isolate.h:1687
#define ISOLATE_FLAG_BITS(V)
Definition isolate.h:1522
#define ISOLATE_METRIC_LIST(V)
Definition metrics.h:49
#define ISOLATE_GROUP_METRIC_LIST(V)
Definition metrics.h:37
void Log(const char *format,...) SK_PRINTF_LIKE(1
FixedCache< intptr_t, ExceptionHandlerInfo, 16 > HandlerInfoCache
Definition isolate.h:128
uintptr_t uword
Definition globals.h:501
FixedCache< intptr_t, CatchEntryMovesRefPtr, 16 > CatchEntryMovesCache
Definition isolate.h:130
ValidationPolicy
Definition thread.h:271
constexpr intptr_t kWordSize
Definition globals.h:509
std::function< void(const T &message, const MessageReply< T > &reply)> MessageHandler
Definition ref_ptr.h:256
#define DISALLOW_COPY_AND_ASSIGN(TypeName)
Definition globals.h:581
#define T
#define REUSABLE_HANDLE_LIST(V)
Definition thread.h:78
#define NOT_IN_PRECOMPILED(code)
Definition globals.h:100
#define NOT_IN_PRODUCT(code)
Definition globals.h:84
#define OFFSET_OF(type, field)
Definition globals.h:138