862 if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) {
863 fatal("LEAF method calling lock?");
864 }
865
866 #ifdef ASSERT
867 if (potential_vm_operation && is_Java_thread()
868 && !Universe::is_bootstrapping()) {
869 // Make sure we do not hold any locks that the VM thread also uses.
870 // This could potentially lead to deadlocks
871 for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
872 // Threads_lock is special, since the safepoint synchronization will not start before this is
873 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock,
874 // since it is used to transfer control between JavaThreads and the VMThread
875 // Do not *exclude* any locks unless you are absolutely sure it is correct. Ask someone else first!
876 if ((cur->allow_vm_block() &&
877 cur != Threads_lock &&
878 cur != Compile_lock && // Temporary: should not be necessary when we get separate compilation
879 cur != VMOperationRequest_lock &&
880 cur != VMOperationQueue_lock) ||
881 cur->rank() == Mutex::special) {
882 fatal(err_msg("Thread holding lock at safepoint that vm can block on: %s", cur->name()));
883 }
884 }
885 }
886
887 if (GCALotAtAllSafepoints) {
888 // We could enter a safepoint here and thus have a gc
889 InterfaceSupport::check_gc_alot();
890 }
891 #endif
892 }
893 #endif
894
895 bool Thread::is_in_stack(address adr) const {
896 assert(Thread::current() == this, "is_in_stack can only be called from current thread");
897 address end = os::current_stack_pointer();
898 // Allow non Java threads to call this without stack_base
899 if (_stack_base == NULL) return true;
900 if (stack_base() >= adr && adr >= end) return true;
901
902 return false;
4079 p->oops_do(f, cld_f, cf);
4080 }
4081 VMThread::vm_thread()->oops_do(f, cld_f, cf);
4082 }
4083
4084 void Threads::change_thread_claim_parity() {
4085 // Set the new claim parity.
4086 assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4087 "Not in range.");
4088 _thread_claim_parity++;
4089 if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4090 assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4091 "Not in range.");
4092 }
4093
4094 #ifdef ASSERT
4095 void Threads::assert_all_threads_claimed() {
4096 ALL_JAVA_THREADS(p) {
4097 const int thread_parity = p->oops_do_parity();
4098 assert((thread_parity == _thread_claim_parity),
4099 err_msg("Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity));
4100 }
4101 }
4102 #endif // ASSERT
4103
4104 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
4105 int cp = Threads::thread_claim_parity();
4106 ALL_JAVA_THREADS(p) {
4107 if (p->claim_oops_do(is_par, cp)) {
4108 p->oops_do(f, cld_f, cf);
4109 }
4110 }
4111 VMThread* vmt = VMThread::vm_thread();
4112 if (vmt->claim_oops_do(is_par, cp)) {
4113 vmt->oops_do(f, cld_f, cf);
4114 }
4115 }
4116
4117 #if INCLUDE_ALL_GCS
4118 // Used by ParallelScavenge
4119 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
|
862 if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) {
863 fatal("LEAF method calling lock?");
864 }
865
866 #ifdef ASSERT
867 if (potential_vm_operation && is_Java_thread()
868 && !Universe::is_bootstrapping()) {
869 // Make sure we do not hold any locks that the VM thread also uses.
870 // This could potentially lead to deadlocks
871 for (Monitor *cur = _owned_locks; cur; cur = cur->next()) {
872 // Threads_lock is special, since the safepoint synchronization will not start before this is
873 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock,
874 // since it is used to transfer control between JavaThreads and the VMThread
875 // Do not *exclude* any locks unless you are absolutely sure it is correct. Ask someone else first!
876 if ((cur->allow_vm_block() &&
877 cur != Threads_lock &&
878 cur != Compile_lock && // Temporary: should not be necessary when we get separate compilation
879 cur != VMOperationRequest_lock &&
880 cur != VMOperationQueue_lock) ||
881 cur->rank() == Mutex::special) {
882 fatal("Thread holding lock at safepoint that vm can block on: %s", cur->name());
883 }
884 }
885 }
886
887 if (GCALotAtAllSafepoints) {
888 // We could enter a safepoint here and thus have a gc
889 InterfaceSupport::check_gc_alot();
890 }
891 #endif
892 }
893 #endif
894
895 bool Thread::is_in_stack(address adr) const {
896 assert(Thread::current() == this, "is_in_stack can only be called from current thread");
897 address end = os::current_stack_pointer();
898 // Allow non Java threads to call this without stack_base
899 if (_stack_base == NULL) return true;
900 if (stack_base() >= adr && adr >= end) return true;
901
902 return false;
4079 p->oops_do(f, cld_f, cf);
4080 }
4081 VMThread::vm_thread()->oops_do(f, cld_f, cf);
4082 }
4083
4084 void Threads::change_thread_claim_parity() {
4085 // Set the new claim parity.
4086 assert(_thread_claim_parity >= 0 && _thread_claim_parity <= 2,
4087 "Not in range.");
4088 _thread_claim_parity++;
4089 if (_thread_claim_parity == 3) _thread_claim_parity = 1;
4090 assert(_thread_claim_parity >= 1 && _thread_claim_parity <= 2,
4091 "Not in range.");
4092 }
4093
4094 #ifdef ASSERT
4095 void Threads::assert_all_threads_claimed() {
4096 ALL_JAVA_THREADS(p) {
4097 const int thread_parity = p->oops_do_parity();
4098 assert((thread_parity == _thread_claim_parity),
4099 "Thread " PTR_FORMAT " has incorrect parity %d != %d", p2i(p), thread_parity, _thread_claim_parity);
4100 }
4101 }
4102 #endif // ASSERT
4103
4104 void Threads::possibly_parallel_oops_do(bool is_par, OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf) {
4105 int cp = Threads::thread_claim_parity();
4106 ALL_JAVA_THREADS(p) {
4107 if (p->claim_oops_do(is_par, cp)) {
4108 p->oops_do(f, cld_f, cf);
4109 }
4110 }
4111 VMThread* vmt = VMThread::vm_thread();
4112 if (vmt->claim_oops_do(is_par, cp)) {
4113 vmt->oops_do(f, cld_f, cf);
4114 }
4115 }
4116
4117 #if INCLUDE_ALL_GCS
4118 // Used by ParallelScavenge
4119 void Threads::create_thread_roots_tasks(GCTaskQueue* q) {
|