737 os::interrupt(thread);
738 }
739
740 bool Thread::is_interrupted(Thread* thread, bool clear_interrupted) {
741 debug_only(check_for_dangling_thread_pointer(thread);)
742 // Note: If clear_interrupted==false, this simply fetches and
743 // returns the value of the field osthread()->interrupted().
744 return os::is_interrupted(thread, clear_interrupted);
745 }
746
747
748 // GC Support
749 bool Thread::claim_oops_do_par_case(int strong_roots_parity) {
750 jint thread_parity = _oops_do_parity;
751 if (thread_parity != strong_roots_parity) {
752 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity);
753 if (res == thread_parity) {
754 return true;
755 } else {
756 guarantee(res == strong_roots_parity, "Or else what?");
757 assert(SharedHeap::heap()->workers()->active_workers() > 0,
758 "Should only fail when parallel.");
759 return false;
760 }
761 }
762 assert(SharedHeap::heap()->workers()->active_workers() > 0,
763 "Should only fail when parallel.");
764 return false;
765 }
766
767 void Thread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
768 active_handles()->oops_do(f);
769 // Do oop for ThreadShadow
770 f->do_oop((oop*)&_pending_exception);
771 handle_area()->oops_do(f);
772 }
773
774 void Thread::nmethods_do(CodeBlobClosure* cf) {
775 // no nmethods in a generic thread...
776 }
777
778 void Thread::metadata_handles_do(void f(Metadata*)) {
779 // Only walk the Handles in Thread.
780 if (metadata_handles() != NULL) {
781 for (int i = 0; i< metadata_handles()->length(); i++) {
782 f(metadata_handles()->at(i));
783 }
4049 void Threads::change_thread_claim_parity() {
4050 // Set the new claim parity.
4051 assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4052 "Not in range.");
4053 _thread_claim_parity++;
4054 if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4055 assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4056 "Not in range.");
4057 }
4058
4059 #ifndef PRODUCT
4060 void Threads::assert_all_threads_claimed() {
4061 ALL_JAVA_THREADS(p) {
4062 const int thread_parity = p->oops_do_parity();
4063 assert((thread_parity == _thread_claim_parity),
4064 err_msg("Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity));
4065 }
4066 }
4067 #endif // PRODUCT
4068
4069 void Threads::possibly_parallel_oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
4070 // Introduce a mechanism allowing parallel threads to claim threads as
4071 // root groups. Overhead should be small enough to use all the time,
4072 // even in sequential code.
4073 SharedHeap* sh = SharedHeap::heap();
4074 // Cannot yet substitute active_workers for n_par_threads
4075 // because of G1CollectedHeap::verify() use of
4076 // SharedHeap::process_roots(). n_par_threads == 0 will
4077 // turn off parallelism in process_roots while active_workers
4078 // is being used for parallelism elsewhere.
4079 bool is_par = sh->n_par_threads() > 0;
4080 assert(!is_par ||
4081 (SharedHeap::heap()->n_par_threads() ==
4082 SharedHeap::heap()->workers()->active_workers()), "Mismatch");
4083 int cp = Threads::thread_claim_parity();
4084 ALL_JAVA_THREADS(p) {
4085 if (p->claim_oops_do(is_par, cp)) {
4086 p->oops_do(f, cld_f, cf);
4087 }
4088 }
4089 VMThread* vmt = VMThread::vm_thread();
4090 if (vmt->claim_oops_do(is_par, cp)) {
4091 vmt->oops_do(f, cld_f, cf);
4092 }
4093 }
4094
4095 #if INCLUDE_ALL_GCS
4096 // Used by ParallelScavenge
4097 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
4098 ALL_JAVA_THREADS(p) {
4099 q->enqueue(new ThreadRootsTask(p));
4100 }
4101 q->enqueue(new ThreadRootsTask(VMThread::vm_thread()));
4102 }
|
737 os::interrupt(thread);
738 }
739
740 bool Thread::is_interrupted(Thread* thread, bool clear_interrupted) {
741 debug_only(check_for_dangling_thread_pointer(thread);)
742 // Note: If clear_interrupted==false, this simply fetches and
743 // returns the value of the field osthread()->interrupted().
744 return os::is_interrupted(thread, clear_interrupted);
745 }
746
747
748 // GC Support
749 bool Thread::claim_oops_do_par_case(int strong_roots_parity) {
750 jint thread_parity = _oops_do_parity;
751 if (thread_parity != strong_roots_parity) {
752 jint res = Atomic::cmpxchg(strong_roots_parity, &_oops_do_parity, thread_parity);
753 if (res == thread_parity) {
754 return true;
755 } else {
756 guarantee(res == strong_roots_parity, "Or else what?");
757 return false;
758 }
759 }
760 return false;
761 }
762
763 void Thread::oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
764 active_handles()->oops_do(f);
765 // Do oop for ThreadShadow
766 f->do_oop((oop*)&_pending_exception);
767 handle_area()->oops_do(f);
768 }
769
770 void Thread::nmethods_do(CodeBlobClosure* cf) {
771 // no nmethods in a generic thread...
772 }
773
774 void Thread::metadata_handles_do(void f(Metadata*)) {
775 // Only walk the Handles in Thread.
776 if (metadata_handles() != NULL) {
777 for (int i = 0; i< metadata_handles()->length(); i++) {
778 f(metadata_handles()->at(i));
779 }
4045 void Threads::change_thread_claim_parity() {
4046 // Set the new claim parity.
4047 assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4048 "Not in range.");
4049 _thread_claim_parity++;
4050 if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4051 assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4052 "Not in range.");
4053 }
4054
4055 #ifndef PRODUCT
4056 void Threads::assert_all_threads_claimed() {
4057 ALL_JAVA_THREADS(p) {
4058 const int thread_parity = p->oops_do_parity();
4059 assert((thread_parity == _thread_claim_parity),
4060 err_msg("Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity));
4061 }
4062 }
4063 #endif // PRODUCT
4064
4065 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
4066 int cp = Threads::thread_claim_parity();
4067 ALL_JAVA_THREADS(p) {
4068 if (p->claim_oops_do(is_par, cp)) {
4069 p->oops_do(f, cld_f, cf);
4070 }
4071 }
4072 VMThread* vmt = VMThread::vm_thread();
4073 if (vmt->claim_oops_do(is_par, cp)) {
4074 vmt->oops_do(f, cld_f, cf);
4075 }
4076 }
4077
4078 #if INCLUDE_ALL_GCS
4079 // Used by ParallelScavenge
4080 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
4081 ALL_JAVA_THREADS(p) {
4082 q->enqueue(new ThreadRootsTask(p));
4083 }
4084 q->enqueue(new ThreadRootsTask(VMThread::vm_thread()));
4085 }
|