1008 if (cur != Compile_lock) return true; |
1008 if (cur != Compile_lock) return true; |
1009 } |
1009 } |
1010 return false; |
1010 return false; |
1011 } |
1011 } |
1012 |
1012 |
1013 |
1013 // Checks safepoint allowed and clears unhandled oops at potential safepoints. |
1014 #endif |
1014 void Thread::check_possible_safepoint() { |
1015 |
1015 if (!is_Java_thread()) return; |
1016 #ifndef PRODUCT |
1016 |
|
1017 if (_no_safepoint_count > 0) { |
|
1018 fatal("Possible safepoint reached by thread that does not allow it"); |
|
1019 } |
|
1020 #ifdef CHECK_UNHANDLED_OOPS |
|
1021 // Clear unhandled oops in JavaThreads so we get a crash right away. |
|
1022 clear_unhandled_oops(); |
|
1023 #endif // CHECK_UNHANDLED_OOPS |
|
1024 } |
1017 |
1025 |
1018 // The flag: potential_vm_operation notifies if this particular safepoint state could potentially |
1026 // The flag: potential_vm_operation notifies if this particular safepoint state could potentially |
1019 // invoke the vm-thread (e.g., an oop allocation). In that case, we also have to make sure that |
1027 // invoke the vm-thread (e.g., an oop allocation). In that case, we also have to make sure that |
1020 // no locks which allow_vm_block's are held |
1028 // no locks which allow_vm_block's are held |
1021 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) { |
1029 void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) { |
1022 // Check if current thread is allowed to block at a safepoint |
1030 if (!is_Java_thread()) return; |
1023 if (_no_safepoint_count > 0) { |
1031 |
1024 fatal("Possible safepoint reached by thread that does not allow it"); |
1032 check_possible_safepoint(); |
1025 } |
1033 |
1026 if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) { |
1034 if (((JavaThread*)this)->thread_state() != _thread_in_vm) { |
1027 fatal("LEAF method calling lock?"); |
1035 fatal("LEAF method calling lock?"); |
1028 } |
1036 } |
1029 |
1037 |
1030 #ifdef ASSERT |
1038 if (potential_vm_operation && !Universe::is_bootstrapping()) { |
1031 if (potential_vm_operation && is_Java_thread() |
|
1032 && !Universe::is_bootstrapping()) { |
|
1033 // Make sure we do not hold any locks that the VM thread also uses. |
1039 // Make sure we do not hold any locks that the VM thread also uses. |
1034 // This could potentially lead to deadlocks |
1040 // This could potentially lead to deadlocks |
1035 for (Monitor *cur = _owned_locks; cur; cur = cur->next()) { |
1041 for (Monitor *cur = _owned_locks; cur; cur = cur->next()) { |
1036 // Threads_lock is special, since the safepoint synchronization will not start before this is |
1042 // Threads_lock is special, since the safepoint synchronization will not start before this is |
1037 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, |
1043 // acquired. Hence, a JavaThread cannot be holding it at a safepoint. So is VMOperationRequest_lock, |
1050 |
1056 |
1051 if (GCALotAtAllSafepoints) { |
1057 if (GCALotAtAllSafepoints) { |
1052 // We could enter a safepoint here and thus have a gc |
1058 // We could enter a safepoint here and thus have a gc |
1053 InterfaceSupport::check_gc_alot(); |
1059 InterfaceSupport::check_gc_alot(); |
1054 } |
1060 } |
1055 #endif |
1061 } |
1056 } |
1062 #endif // ASSERT |
1057 #endif |
|
1058 |
1063 |
1059 bool Thread::is_in_stack(address adr) const { |
1064 bool Thread::is_in_stack(address adr) const { |
1060 assert(Thread::current() == this, "is_in_stack can only be called from current thread"); |
1065 assert(Thread::current() == this, "is_in_stack can only be called from current thread"); |
1061 address end = os::current_stack_pointer(); |
1066 address end = os::current_stack_pointer(); |
1062 // Allow non Java threads to call this without stack_base |
1067 // Allow non Java threads to call this without stack_base |