557 assert(_starting_thread != nullptr, "invariant");
558 return t == _starting_thread;
559 }
560 #endif // ASSERT
561
562 bool Thread::set_as_starting_thread(JavaThread* jt) {
563 assert(jt != nullptr, "invariant");
564 assert(_starting_thread == nullptr, "already initialized: "
565 "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
566 // NOTE: this must be called from Threads::create_vm().
567 DEBUG_ONLY(_starting_thread = jt;)
568 return os::create_main_thread(jt);
569 }
570
571 // Ad-hoc mutual exclusion primitive: spin lock
572 //
573 // We employ a spin lock _only for low-contention, fixed-length
574 // short-duration critical sections where we're concerned
575 // about native mutex_t or HotSpot Mutex:: latency.
576
577 void Thread::SpinAcquire(volatile int * adr) {
578 if (AtomicAccess::cmpxchg(adr, 0, 1) == 0) {
579 return; // normal fast-path return
580 }
581
582 // Slow-path : We've encountered contention -- Spin/Yield/Block strategy.
583 int ctr = 0;
584 int Yields = 0;
585 for (;;) {
586 while (*adr != 0) {
587 ++ctr;
588 if ((ctr & 0xFFF) == 0 || !os::is_MP()) {
589 if (Yields > 5) {
590 os::naked_short_sleep(1);
591 } else {
592 os::naked_yield();
593 ++Yields;
594 }
595 } else {
596 SpinPause();
|
557 assert(_starting_thread != nullptr, "invariant");
558 return t == _starting_thread;
559 }
560 #endif // ASSERT
561
562 bool Thread::set_as_starting_thread(JavaThread* jt) {
563 assert(jt != nullptr, "invariant");
564 assert(_starting_thread == nullptr, "already initialized: "
565 "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
566 // NOTE: this must be called from Threads::create_vm().
567 DEBUG_ONLY(_starting_thread = jt;)
568 return os::create_main_thread(jt);
569 }
570
571 // Ad-hoc mutual exclusion primitive: spin lock
572 //
573 // We employ a spin lock _only for low-contention, fixed-length
574 // short-duration critical sections where we're concerned
575 // about native mutex_t or HotSpot Mutex:: latency.
576
577 bool Thread::TrySpinAcquire(volatile int * adr) {
578 return AtomicAccess::cmpxchg(adr, 0, 1) == 0;
579 }
580
581 void Thread::SpinAcquire(volatile int * adr) {
582 if (AtomicAccess::cmpxchg(adr, 0, 1) == 0) {
583 return; // normal fast-path return
584 }
585
586 // Slow-path : We've encountered contention -- Spin/Yield/Block strategy.
587 int ctr = 0;
588 int Yields = 0;
589 for (;;) {
590 while (*adr != 0) {
591 ++ctr;
592 if ((ctr & 0xFFF) == 0 || !os::is_MP()) {
593 if (Yields > 5) {
594 os::naked_short_sleep(1);
595 } else {
596 os::naked_yield();
597 ++Yields;
598 }
599 } else {
600 SpinPause();
|