22 EXPECT_EQ(
false, mutex->TryLock());
24 EXPECT_EQ(
true, mutex->TryLock());
28 EXPECT_EQ(
false, mutex->TryLock());
46 EXPECT_EQ(
true, monitor->TryEnter());
49 const int kNumAttempts = 5;
51 while (attempts < kNumAttempts) {
54 int64_t wait_time = 2017;
64 const int kAcceptableTimeJitter = 20;
65 const int kAcceptableWakeupDelay = 150;
66 if (((wait_time - kAcceptableTimeJitter) <= wakeup_time) &&
67 (wakeup_time <= (wait_time + kAcceptableWakeupDelay))) {
74 EXPECT_LT(attempts, kNumAttempts);
89 for (
ObjectPtr* current = first; current <= last; ++current) {
90 if (*current == obj_->
ptr()) {
96#if defined(DART_COMPRESSED_POINTERS)
101 if (current->Decompress(heap_base) == obj_->
ptr()) {
108 intptr_t
count()
const {
return count_; }
121 : isolate_group_(isolate_group),
126 const bool kBypassSafepoint =
false;
134 EXPECT_EQ(zone, stack_zone.
GetZone());
137 for (intptr_t i = 0; i < 100000; ++i) {
145 const intptr_t unique_smi = id_ + 928327281;
154 EXPECT_EQ(1, counter.
count());
172 EXPECT_EQ(1, str_counter.
count());
191 const int kTaskCount = 100;
193 bool done[kTaskCount];
194 auto isolate = thread->isolate();
195 auto isolate_group = thread->isolate_group();
196 for (
int i = 0; i < kTaskCount; i++) {
201 bool in_isolate =
true;
202 for (
int i = 0; i < kTaskCount; i++) {
235 intptr_t* done_count,
238 isolate_group_(isolate_group),
239 thread_ptr_(thread_ptr),
242 done_count_(done_count),
246 const bool kBypassSafepoint =
false;
251 *thread_ptr_ = thread;
252 CreateStackZones(id_);
264 void CreateStackZones(intptr_t num) {
266 *thread_ptr_ = thread;
270 EXPECT_EQ(zone, stack_zone.GetZone());
275 for (intptr_t i = 0; i < 1000 * num + id_; ++i) {
282 CreateStackZones(num);
287 MonitorLocker ml(monitor_);
293 MonitorLocker sync_ml(sync_);
301 IsolateGroup* isolate_group_;
302 Thread** thread_ptr_;
305 intptr_t* done_count_;
310 const int kTaskCount = 10;
313 Thread* threads[kTaskCount];
315 intptr_t done_count = 0;
322 for (intptr_t i = 0; i < kTaskCount; i++) {
324 (i + 1), isolate_group, &threads[i], &sync, &monitor, &done_count,
330 while (done_count < kTaskCount) {
346 while (done_count < kTaskCount) {
361 EXPECT(zone0 != orig_zone);
371 EXPECT(zone1 != orig_zone);
377 EXPECT_STREQ(
"foo", orig_str);
386 const Array& ic_datas,
389 std::atomic<bool>*
done)
390 : isolate_group_(isolate_group),
392 len_(ic_datas.Length()),
398 const bool kBypassSafepoint =
false;
410 for (intptr_t cnt = 0; cnt < 0x1000; cnt++) {
411 for (intptr_t i = 0; i < len_; i++) {
414 intptr_t num_checks = arr.
Length() / 3;
415 if (num_checks < 0 || num_checks > 5) {
422 if (done_->load(std::memory_order_acquire)) {
440 const Array& ic_datas_;
444 std::atomic<bool>* done_;
458 signature,
function_name, UntaggedFunction::kRegularFunction,
true,
false,
459 false,
false,
false, owner_class, TokenPosition::kNoSource));
470 std::atomic<bool>
done = {
false};
472 const intptr_t kNumICData = 0x10;
478 const Array& args_desc =
480 for (intptr_t i = 0; i < kNumICData; i++) {
481 ic_data = ICData::New(owner,
name, args_desc, 0,
482 1, ICData::kInstance,
483 Object::null_abstract_type());
492 for (
int i = 0; i < 0x10000; i++) {
493 for (intptr_t i = 0; i < kNumICData; i++) {
494 ic_data ^= ic_datas.
At(i);
499 ic_data = ICData::New(owner,
name, args_desc, 0,
500 1, ICData::kInstance,
501 Object::null_abstract_type());
508 done.store(
true, std::memory_order_release);
529 intptr_t* expected_count,
530 intptr_t* total_done,
534 expected_count_(expected_count),
535 total_done_(total_done),
537 local_done_(
false) {}
540 const bool kBypassSafepoint =
false;
548 for (
int i =
reinterpret_cast<intptr_t
>(thread);; ++i) {
551 const intptr_t kUniqueSmi = 928327281;
553 if ((i % 100) != 0) {
565 EXPECT_EQ(*expected_count_, counter.
count());
572 if (*expected_count_ ==
kTaskCount && !local_done_) {
602 intptr_t* expected_count_;
603 intptr_t* total_done_;
616 intptr_t expected_count = 0;
617 intptr_t total_done = 0;
621 isolate, &monitor, &expected_count, &total_done, &exited);
627#if defined(USING_SIMULATOR)
628 const intptr_t kLoopCount = 12345678;
630 const intptr_t kLoopCount = 1234567890;
634 "import 'dart:developer';\n"
637 " new UserTag('foo').makeCurrent();\n"
638 " for (dummy = 0; dummy < %" Pd
640 " dummy += (dummy & 1);\n"
667 intptr_t expected_count = 0;
668 intptr_t total_done = 0;
672 isolate, &monitor, &expected_count, &total_done, &exited);
702 intptr_t thread_count_0 = 0;
703 intptr_t thread_count_1 = 0;
709 EXPECT(thread !=
nullptr);
718 EXPECT(thread !=
nullptr);
723 EXPECT(thread_count_0 > 0);
724 EXPECT(thread_count_1 > 0);
725 EXPECT(thread_count_0 >= thread_count_1);
743 EXPECT(thread !=
nullptr);
746 params->spawned_thread_id = thread->
id();
788 intptr_t expected_count = 0;
789 intptr_t total_done = 0;
793 isolate, &monitor, &expected_count, &total_done, &exited);
795 bool all_helpers =
false;
804 }
while (!all_helpers);
819 intptr_t expected_count = 0;
820 intptr_t total_done = 0;
824 isolate, &monitor, &expected_count, &total_done, &exited);
826 bool all_helpers =
false;
836 }
while (!all_helpers);
840 bool all_exited =
false;
850 }
while (!all_exited);
856 : isolate_group_(isolate_group),
857 done_monitor_(done_monitor),
861 const bool kBypassSafepoint =
false;
909 : isolate_group_(isolate_group),
910 done_monitor_(done_monitor),
914 const bool kBypassSafepoint =
false;
921 int count = 100 * 1000;
922 while (
count-- > 0) {
943 const int NUMBER_TEST_THREADS = 10;
944 Monitor done_monitor[NUMBER_TEST_THREADS];
945 bool done[NUMBER_TEST_THREADS];
947 for (
int i = 0; i < NUMBER_TEST_THREADS; i++) {
950 isolate_group, &done_monitor[i], &
done[i]);
953 for (
int i = 0; i < NUMBER_TEST_THREADS; i++) {
1029template <
typename LockType,
typename LockerType>
1031 const intptr_t kNumIterations = 5;
1032 volatile intptr_t execution_count = 0;
1033 volatile intptr_t thrown_count = 0;
1035 for (intptr_t i = 0; i < kNumIterations; ++i) {
1037 if (setjmp(*jump.
Set()) == 0) {
1041 1, Object::background_compilation_error());
1044 Object::background_compilation_error().ptr());
1048 EXPECT_EQ(kNumIterations, execution_count);
1049 EXPECT_EQ(kNumIterations, thrown_count);
1052 RunLockerWithLongJumpTest<SafepointRwLock, SafepointWriteRwLocker>();
1056 RunLockerWithLongJumpTest<SafepointRwLock, SafepointReadRwLocker>();
1060 RunLockerWithLongJumpTest<Mutex, SafepointMutexLocker>();
1079 state->child_started =
true;
1082 const bool kBypassSafepoint =
false;
1087 intptr_t observed_value = -1;
1090 observed_value =
state->value;
1092 state->observed_value = observed_value;
1103 state.isolate_group = isolate_group;
1105 state.child_started =
false;
1118 FATAL(
"Could not start worker thread");
1123 while (!
state.child_started) {
1138 delete state.monitor;
static void done(const char *config, const char *src, const char *srcOptions, const char *name)
AllocAndGCTask(IsolateGroup *isolate_group, Monitor *done_monitor, bool *done)
AllocateGlobsOfMemoryTask(IsolateGroup *isolate_group, Monitor *done_monitor, bool *done)
static ArrayPtr NewBoxed(intptr_t type_args_len, intptr_t num_arguments, const Array &optional_arguments_names, Heap::Space space=Heap::kOld)
ObjectPtr AtAcquire(intptr_t index) const
static ArrayPtr New(intptr_t len, Heap::Space space=Heap::kNew)
void SetAtRelease(intptr_t index, const Object &value) const
ObjectPtr At(intptr_t index) const
static ClassPtr New(IsolateGroup *isolate_group, bool register_class=true)
static ThreadPool * thread_pool()
static FunctionTypePtr New(intptr_t num_parent_type_arguments=0, Nullability nullability=Nullability::kLegacy, Heap::Space space=Heap::kOld)
static FunctionPtr New(const FunctionType &signature, const String &name, UntaggedFunction::Kind kind, bool is_static, bool is_const, bool is_abstract, bool is_external, bool is_native, const Object &owner, TokenPosition token_pos, Heap::Space space=Heap::kOld)
void IterateStackPointers(ObjectPointerVisitor *visitor, ValidationPolicy validate_frames)
void CollectAllGarbage(GCReason reason=GCReason::kFull, bool compact=false)
ICDataTestTask(IsolateGroup *isolate_group, const Array &ic_datas, Monitor *monitor, intptr_t *exited, std::atomic< bool > *done)
static constexpr intptr_t kTaskCount
void AddReceiverCheck(intptr_t receiver_class_id, const Function &target, intptr_t count=1, StaticTypeExactnessState exactness=StaticTypeExactnessState::NotTracking()) const
intptr_t NumberOfChecks() const
static IsolateGroup * Current()
UserTagPtr current_tag() const
UserTagPtr default_tag() const
IsolateGroup * group() const
void set_current_tag(const UserTag &tag)
DART_NORETURN void Jump(int value, const Error &error)
Monitor::WaitResult WaitWithSafepointCheck(Thread *thread, int64_t millis=Monitor::kNoTimeout)
Monitor::WaitResult Wait(int64_t millis=Monitor::kNoTimeout)
bool IsOwnedByCurrentThread() const
static int Start(const char *name, ThreadStartFunction function, uword parameter)
void DisableThreadInterrupts()
static void Join(ThreadJoinId id)
static OSThread * Current()
static const ThreadId kInvalidThreadId
static ThreadJoinId GetCurrentThreadJoinId(OSThread *thread)
static bool IsThreadInList(ThreadId id)
static const ThreadJoinId kInvalidThreadJoinId
static int64_t GetCurrentMonotonicMicros()
static void static void PrintErr(const char *format,...) PRINTF_ATTRIBUTE(1
ObjectCounter(IsolateGroup *isolate_group, const Object *obj)
void VisitPointers(ObjectPtr *first, ObjectPtr *last) override
IsolateGroup * isolate_group() const
void VisitCompressedPointers(uword heap_base, CompressedObjectPtr *first, CompressedObjectPtr *last)
static Object & ZoneHandle()
bool IsCurrentThreadWriter()
SafepointTestTask(Isolate *isolate, Monitor *monitor, intptr_t *expected_count, intptr_t *total_done, intptr_t *exited)
static constexpr intptr_t kTaskCount
SimpleTaskWithZoneAllocation(intptr_t id, IsolateGroup *isolate_group, Thread **thread_ptr, Monitor *sync, Monitor *monitor, intptr_t *done_count, bool *wait)
static SmiPtr New(intptr_t value)
bool Equals(const String &str) const
static StringPtr New(const char *cstr, Heap::Space space=Heap::kNew)
static StringPtr New(Thread *thread, const char *cstr)
TaskWithZoneAllocation(IsolateGroup *isolate_group, Monitor *monitor, bool *done, intptr_t id)
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 CreateTestIsolate(const char *name=nullptr, void *isolate_group_data=nullptr, void *isolate_data=nullptr)
bool Run(Args &&... args)
LongJumpScope * long_jump_base() const
bool OwnsSafepoint() const
bool force_growth() const
static Thread * Current()
static void ExitIsolateGroupAsHelper(bool bypass_safepoint)
Isolate * isolate() const
IsolateGroup * isolate_group() const
static void EnterIsolate(Isolate *isolate)
static void ExitIsolate(bool isolate_shutdown=false)
static bool EnterIsolateGroupAsHelper(IsolateGroup *isolate_group, TaskKind kind, bool bypass_safepoint)
static UserTagPtr New(const String &label, Heap::Space space=Heap::kOld)
static int SNPrint(char *str, size_t size, const char *format,...) PRINTF_ATTRIBUTE(3
char * PrintToString(const char *format,...) PRINTF_ATTRIBUTE(2
struct _Dart_Handle * Dart_Handle
struct _Dart_Isolate * Dart_Isolate
const EmbeddedViewParams * params
static const uint8_t buffer[]
Dart_NativeFunction function
#define HANDLESCOPE(thread)
constexpr intptr_t kMicrosecondsPerMillisecond
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)
const char *const class_name
void ThreadIteratorTestMain(uword parameter)
DART_EXPORT void Dart_ExitIsolate()
Dart_Handle NewString(const char *str)
static void RunLockerWithLongJumpTest()
static FunctionPtr CreateFunction(const char *name)
const char *const function_name
DART_EXPORT void Dart_ShutdownIsolate()
IsolateGroup * isolate_group
SafepointRwLock * rw_lock
ThreadId spawned_thread_id
ThreadJoinId spawned_thread_join_id
#define VM_UNIT_TEST_CASE(name)
#define ISOLATE_UNIT_TEST_CASE(name)
#define EXPECT_VALID(handle)