30 const char* kScriptChars =
32 " return [1, 2, 3];\n"
42 GCTestHelper::CollectOldSpace();
53 FLAG_marker_tasks = 0;
55 const char* kScriptChars =
57 " return [1, 2, 3];\n"
59 FLAG_verbose_gc =
true;
67 GCTestHelper::CollectOldSpace();
72 const char* kScriptChars =
74 " return List.filled(8 * 1024 * 1024, null);\n"
86 GCTestHelper::CollectOldSpace();
91 GCTestHelper::CollectOldSpace();
96static ClassPtr
GetClass(
const Library& lib,
const char*
name) {
104 const char* kScriptChars =
111 " var x = new A();\n"
116 ClassTable* class_table = isolate_group->class_table();
138 CountObjectsVisitor visitor(thread, class_table->
NumCids());
141 isolate_group->VisitWeakPersistentHandles(&visitor);
142 EXPECT_EQ(2, visitor.new_count_[
cid]);
143 EXPECT_EQ(0, visitor.old_count_[
cid]);
147 GCTestHelper::CollectNewSpace();
151 CountObjectsVisitor visitor(thread, class_table->
NumCids());
154 isolate_group->VisitWeakPersistentHandles(&visitor);
155 EXPECT_EQ(1, visitor.new_count_[
cid]);
156 EXPECT_EQ(0, visitor.old_count_[
cid]);
161 GCTestHelper::CollectNewSpace();
165 CountObjectsVisitor visitor(thread, class_table->
NumCids());
168 isolate_group->VisitWeakPersistentHandles(&visitor);
169 EXPECT_EQ(0, visitor.new_count_[
cid]);
170 EXPECT_EQ(1, visitor.old_count_[
cid]);
174 GCTestHelper::CollectNewSpace();
178 CountObjectsVisitor visitor(thread, class_table->
NumCids());
181 isolate_group->VisitWeakPersistentHandles(&visitor);
182 EXPECT_EQ(0, visitor.new_count_[
cid]);
183 EXPECT_EQ(1, visitor.old_count_[
cid]);
186 GCTestHelper::CollectOldSpace();
190 CountObjectsVisitor visitor(thread, class_table->
NumCids());
193 isolate_group->VisitWeakPersistentHandles(&visitor);
194 EXPECT_EQ(0, visitor.new_count_[
cid]);
195 EXPECT_EQ(1, visitor.old_count_[
cid]);
203 GCTestHelper::CollectOldSpace();
206 CountObjectsVisitor visitor(thread, class_table->
NumCids());
209 isolate_group->VisitWeakPersistentHandles(&visitor);
210 EXPECT_EQ(0, visitor.new_count_[
cid]);
211 EXPECT_EQ(0, visitor.old_count_[
cid]);
222 GCTestHelper::WaitForGCTasks();
237 intptr_t size_before =
249 intptr_t size_after =
252 EXPECT_EQ(size_before, size_after);
260 intptr_t size_before =
272 intptr_t size_after =
275 EXPECT_EQ(size_before, size_after);
283 intptr_t size_before =
296 intptr_t size_after =
299 EXPECT_EQ(size_before, size_after);
307 intptr_t size_before =
318 intptr_t size_after =
321 EXPECT(size_before < size_after);
329 intptr_t size_before =
340 intptr_t size_after =
343 EXPECT(size_before < size_after);
351 intptr_t size_before =
362 intptr_t size_after =
365 EXPECT(size_before < size_after);
373 intptr_t size_before =
384 intptr_t size_after =
387 EXPECT(size_before < size_after);
394 intptr_t size_before =
407 intptr_t size_after =
410 EXPECT(size_before < size_after);
417 intptr_t size_before =
430 intptr_t size_after =
433 EXPECT(size_before < size_after);
440 Heap* heap = isolate_group->heap();
448 for (intptr_t
i = 0;
i < 100;
i++) {
458 EXPECT_EQ(size_before + 100 *
MB, size_middle);
468 EXPECT_EQ(size_before, size_after);
491 const char*
name()
const {
return "merge-isolates-heaps-handler"; }
499 response_obj =
message->raw_obj();
500 }
else if (
message->IsPersistentHandle()) {
505 response_obj = handle->
ptr();
511 if (response_obj.IsString()) {
513 response ^= response_obj.
ptr();
516 ASSERT(response_obj.IsArray());
518 response_array ^= response_obj.
ptr();
521 response ^= response_array.
At(0);
528 const char*
msg()
const {
return msg_.get(); }
538 const char* TEST_MESSAGE =
"hello, world";
559 reinterpret_cast<Isolate*
>(worker)->bequeath(
560 std::unique_ptr<Bequest>(
new Bequest(handle, port_id)));
569 const char* TEST_MESSAGE =
"hello, world";
590 reinterpret_cast<Isolate*
>(worker)->bequeath(
591 std::unique_ptr<Bequest>(
new Bequest(handle, port_id)));
603 EXPECT_STREQ(handler.
msg(), TEST_MESSAGE);
608 auto isolate_group = thread->isolate_group();
609 Heap* heap = isolate_group->heap();
613 for (intptr_t
i = 0;
i < 100;
i++) {
626 CountObjectsVisitor visitor(thread,
627 isolate_group->class_table()->NumCids());
630 isolate_group->VisitWeakPersistentHandles(&visitor);
631 EXPECT_LE(visitor.old_external_size_[kArrayCid],
633 EXPECT_LE(visitor.new_external_size_[kArrayCid],
646 auto isolate_group = thread->isolate_group();
647 Heap* heap = isolate_group->heap();
654 const intptr_t data_length = 1;
655 uint8_t
data[data_length] = {0};
674 const intptr_t external_allocation_size =
677 isolate_group, external_typed_data_1,
nullptr,
NoopFinalizer,
678 external_allocation_size,
683 isolate_group, external_typed_data_2,
nullptr,
NoopFinalizer,
684 external_allocation_size,
689 isolate_group, external_typed_data_3,
nullptr,
NoopFinalizer,
690 external_allocation_size,
695 isolate_group, external_typed_data_4,
nullptr,
NoopFinalizer,
696 external_allocation_size,
701 isolate_group, external_typed_data_5,
nullptr,
NoopFinalizer,
702 external_allocation_size,
721 intptr_t kMaxListLength = 100;
722 intptr_t kNumLists = 1000;
730 for (intptr_t
i = 0;
i < kNumLists;
i++) {
732 intptr_t
length =
i % kMaxListLength;
733 for (intptr_t j = 0; j <
length; j++) {
739 intptr_t kTruncations = 100000;
740 for (intptr_t
i = 0;
i < kTruncations;
i++) {
741 list ^= lists.
At(
i % kNumLists);
743 arrays.
SetAt(
i % kNumLists, array);
746 intptr_t
length =
i % kMaxListLength;
747 for (intptr_t j = 0; j <
length; j++) {
750 lists.
SetAt(
i % kNumLists, list);
760 for (intptr_t big = 0; big < 256; big++) {
761 for (intptr_t small = 0; small < big; small++) {
783 intptr_t* done_count)
784 : isolate_group_(isolate_group),
786 done_count_(done_count) {}
789 const bool kBypassSafepoint =
false;
799 for (intptr_t
i = 0;
i < 1000;
i++) {
804 GrowableObjectArrayPtr unsafe_accumulate = accumulate.
ptr();
806 accumulate = unsafe_accumulate;
808 accumulate.
Add(element);
823 intptr_t* done_count_;
827 intptr_t task_count = 8;
829 intptr_t done_count = 0;
831 for (intptr_t
i = 0;
i < task_count;
i++) {
833 thread->isolate_group(), &monitor, &done_count);
838 while (done_count < task_count) {
871 new_weakarray.
SetAt(0, smi);
872 old_weakarray.
SetAt(0, smi);
877 GCTestHelper::CollectNewSpace();
899 bool cleared_after_minor,
900 bool cleared_after_major,
901 bool cleared_after_all) {
906 switch (property_space) {
931 switch (value_space) {
943 property.set_key(
key);
944 property.set_value(
value);
947 OS::PrintErr(
"%d %d %d\n", property_space, key_space, value_space);
949 GCTestHelper::CollectNewSpace();
950 if (cleared_after_minor) {
958 GCTestHelper::CollectOldSpace();
959 if (cleared_after_major) {
968 if (cleared_after_all) {
978 FLAG_early_tenuring_threshold = 100;
1002 bool cleared_after_minor,
1003 bool cleared_after_major,
1004 bool cleared_after_all) {
1009 switch (reference_space) {
1021 switch (target_space) {
1036 OS::PrintErr(
"%d %d\n", reference_space, target_space);
1038 GCTestHelper::CollectNewSpace();
1039 if (cleared_after_minor) {
1045 GCTestHelper::CollectOldSpace();
1046 if (cleared_after_major) {
1053 if (cleared_after_all) {
1061 FLAG_early_tenuring_threshold = 100;
1074 bool cleared_after_minor,
1075 bool cleared_after_major,
1076 bool cleared_after_all) {
1081 switch (array_space) {
1093 switch (element_space) {
1110 GCTestHelper::CollectNewSpace();
1111 if (cleared_after_minor) {
1117 GCTestHelper::CollectOldSpace();
1118 if (cleared_after_major) {
1125 if (cleared_after_all) {
1133 FLAG_early_tenuring_threshold = 100;
1145 FLAG_early_tenuring_threshold = 100;
1158 bool cleared_after_minor,
1159 bool cleared_after_major,
1160 bool cleared_after_all) {
1165 switch (entry_space) {
1177 switch (value_space) {
1194 GCTestHelper::CollectNewSpace();
1195 if (cleared_after_minor) {
1201 GCTestHelper::CollectOldSpace();
1202 if (cleared_after_major) {
1209 if (cleared_after_all) {
1217 FLAG_early_tenuring_threshold = 100;
1227#if !defined(PRODUCT) && defined(DART_HOST_OS_LINUX)
1229 auto gc_with_fragmentation = [&] {
1239 for (intptr_t
i = 0;
i < num_elements;
i++) {
1241 list.SetAt(
i, element);
1246 GCTestHelper::WaitForGCTasks();
1251 for (intptr_t
i = 0;
i < num_elements;
i++) {
1256 list.SetAt(
i, Object::null_object());
1261 GCTestHelper::WaitForGCTasks();
1266 const intptr_t
delta = after - before;
1271 FLAG_dontneed_on_sweep =
false;
1272 const intptr_t delta_normal = gc_with_fragmentation();
1275 FLAG_dontneed_on_sweep =
true;
1276 const intptr_t delta_dontneed = gc_with_fragmentation();
1280 EXPECT(delta_dontneed < delta_normal);
1293 for (intptr_t
i = 0;
i < kNumElements;
i++) {
1304 GCTestHelper::WaitForGCTasks();
1309 for (intptr_t
i = 0;
i < kNumElements;
i++) {
1310 element = array.
At(
i);
1311 EXPECT(element.IsDouble());
1327 for (intptr_t
i = 0;
i < kNumElements;
i++) {
1332 strong.
SetAt(
i, element);
1338 GCTestHelper::WaitForGCTasks();
1343 for (intptr_t
i = 0;
i < kNumElements;
i++) {
1344 element = weak.
At(
i);
1346 EXPECT(element.IsDouble());
PersistentHandle * AllocatePersistentHandle()
void FreePersistentHandle(PersistentHandle *ref)
static ObjectPtr UnwrapHandle(Dart_Handle object)
static intptr_t InstanceSize()
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
void Truncate(intptr_t new_length) const
void MakeImmutable() const
ObjectPtr At(intptr_t index) const
static ArrayPtr MakeFixedLength(const GrowableObjectArray &growable_array, bool unique=false)
void SetAt(intptr_t index, const Object &value) const
ConcurrentForceGrowthScopeTask(IsolateGroup *isolate_group, Monitor *monitor, intptr_t *done_count)
static ThreadPool * thread_pool()
static DoublePtr New(double d, Heap::Space space=Heap::kNew)
static ExternalTypedDataPtr New(intptr_t class_id, uint8_t *data, intptr_t len, Heap::Space space=Heap::kNew, bool perform_eager_msan_initialization_check=true)
static FinalizablePersistentHandle * New(IsolateGroup *isolate_group, const Object &object, void *peer, Dart_HandleFinalizer callback, intptr_t external_size, bool auto_delete)
void set_value(const Object &value) const
static FinalizerEntryPtr New(const FinalizerBase &finalizer, Heap::Space space=Heap::kNew)
void Add(const Object &value, Heap::Space space=Heap::kNew) const
static GrowableObjectArrayPtr New(Heap::Space space=Heap::kNew)
void IterateObjects(ObjectVisitor *visitor) const
static void MarkSweep(Thread *thread)
static void Scavenge(Thread *thread)
void WriteProtect(bool read_only)
void WaitForMarkerTasks(Thread *thread)
bool Verify(const char *msg, MarkExpectation mark_expectation=kForbidMarked)
void CollectAllGarbage(GCReason reason=GCReason::kFull, bool compact=false)
void WaitForSweeperTasks(Thread *thread)
bool Contains(uword addr) const
static intptr_t UnroundedSize()
static IsolateGroup * Current()
ApiState * api_state() const
static Isolate * Current()
IsolateGroup * group() const
MessageStatus HandleNextMessage()
Monitor::WaitResult WaitWithSafepointCheck(Thread *thread, int64_t millis=Monitor::kNoTimeout)
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
UntaggedObject * untag() const
static OneByteStringPtr New(intptr_t len, Heap::Space space)
intptr_t UsedInWords() const
intptr_t ExternalInWords() const
static Page * Of(ObjectPtr obj)
void set_ptr(ObjectPtr ref)
static Isolate * GetIsolate(Dart_Port id)
static void ClosePorts(MessageHandler *handler)
static Dart_Port CreatePort(MessageHandler *handler)
intptr_t ExternalInWords() const
intptr_t UsedInWords() const
virtual Isolate * isolate() const
MessageStatus HandleMessage(std::unique_ptr< Message > message)
const char * name() const
SendAndExitMessagesHandler(Isolate *owner)
~SendAndExitMessagesHandler()
static int64_t CurrentRSS()
static SmiPtr New(intptr_t value)
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static const char * ToCString(Thread *thread, StringPtr ptr)
static StringPtr New(Thread *thread, const char *cstr)
static Dart_Handle LoadTestScript(const char *script, Dart_NativeEntryResolver resolver, const char *lib_uri=RESOLVED_USER_TEST_URI, bool finalize=true, bool allow_compile_errors=false)
static Dart_Isolate CreateTestIsolateInGroup(const char *name, Dart_Isolate parent, void *group_data=nullptr, void *isolate_data=nullptr)
static Dart_Isolate CreateTestIsolate(const char *name=nullptr, void *isolate_group_data=nullptr, void *isolate_data=nullptr)
bool Run(Args &&... args)
static Thread * Current()
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
void * DataAddr(intptr_t byte_offset) const
bool IsCardRemembered() const
static uword ToAddr(const UntaggedObject *raw_obj)
static char * StrDup(const char *s)
void SetAt(intptr_t index, const Object &value) const
ObjectPtr At(intptr_t index) const
static WeakArrayPtr New(intptr_t length, Heap::Space space=Heap::kNew)
static WeakPropertyPtr New(Heap::Space space=Heap::kNew)
void set_key(const Object &key) const
static WeakReferencePtr New(Heap::Space space=Heap::kNew)
void set_target(const Object &target) const
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
#define HANDLESCOPE(thread)
bool Contains(const Container &container, const Value &value)
ObjectPtr ReadMessage(Thread *thread, Message *message)
static void WeakArray_Generations(intptr_t length, Generation array_space, Generation element_space, bool cleared_after_minor, bool cleared_after_major, bool cleared_after_all)
DART_EXPORT void Dart_EnterScope()
static void WeakReference_Generations(Generation reference_space, Generation target_space, bool cleared_after_minor, bool cleared_after_major, bool cleared_after_all)
DART_EXPORT void Dart_EnterIsolate(Dart_Isolate isolate)
DART_EXPORT Dart_Handle Dart_Invoke(Dart_Handle target, Dart_Handle name, int number_of_arguments, Dart_Handle *arguments)
constexpr intptr_t MBLog2
DART_EXPORT Dart_Isolate Dart_CurrentIsolate()
ISOLATE_UNIT_TEST_CASE(StackAllocatedDestruction)
DART_EXPORT void Dart_ExitIsolate()
ClassPtr GetClass(const Library &lib, const char *name)
static constexpr intptr_t kCompressedWordSize
TEST_CASE(DirectoryCurrent)
Dart_Handle NewString(const char *str)
static void TestCardRememberedWeakArray(bool compact)
DART_EXPORT void Dart_ExitScope()
static void NoopFinalizer(void *isolate_callback_data, void *peer)
constexpr intptr_t kWordSize
static void WeakProperty_Generations(Generation property_space, Generation key_space, Generation value_space, bool cleared_after_minor, bool cleared_after_major, bool cleared_after_all)
DART_EXPORT bool Dart_IsList(Dart_Handle object)
static void CollectAllGarbage(Thread *thread, JSONStream *js)
DART_EXPORT bool Dart_IsNull(Dart_Handle object)
static int8_t data[kExtLength]
static void FinalizerEntry_Generations(Generation entry_space, Generation value_space, bool cleared_after_minor, bool cleared_after_major, bool cleared_after_all)
static void TestCardRememberedArray(bool immutable, bool compact)
bool IsAllocatableViaFreeLists(intptr_t size)
DART_EXPORT void Dart_ShutdownIsolate()
NOT_IN_PRODUCT(LibraryPtr ReloadTestScript(const char *script))
const intptr_t kMaxAddrSpaceInWords
static constexpr intptr_t kNewAllocatableSize
const intptr_t kMaxAddrSpaceMB
DECLARE_FLAG(bool, show_invisible_frames)
VM_UNIT_TEST_CASE(DirectoryCurrentNoScope)
#define EXPECT_VALID(handle)