1001
1002 void Thread::check_for_valid_safepoint_state() {
1003 if (!is_Java_thread()) return;
1004
1005 // Check NoSafepointVerifier, which is implied by locks taken that can be
1006 // shared with the VM thread. This makes sure that no locks with allow_vm_block
1007 // are held.
1008 check_possible_safepoint();
1009
1010 if (((JavaThread*)this)->thread_state() != _thread_in_vm) {
1011 fatal("LEAF method calling lock?");
1012 }
1013
1014 if (GCALotAtAllSafepoints) {
1015 // We could enter a safepoint here and thus have a gc
1016 InterfaceSupport::check_gc_alot();
1017 }
1018 }
1019 #endif // ASSERT
1020
1021 // Check for adr in the live portion of our stack.
1022 bool Thread::is_in_stack(address adr) const {
1023 assert(Thread::current() == this, "is_in_stack can only be called from current thread");
1024 address end = os::current_stack_pointer();
1025 return (stack_base() > adr && adr >= end);
1026 }
1027
1028 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
1029 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
1030 // used for compilation in the future. If that change is made, the need for these methods
1031 // should be revisited, and they should be removed if possible.
1032
1033 bool Thread::is_lock_owned(address adr) const {
1034 return on_local_stack(adr);
1035 }
1036
1037 bool Thread::set_as_starting_thread() {
1038 assert(_starting_thread == NULL, "already initialized: "
1039 "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
1040 // NOTE: this must be called inside the main thread.
1041 DEBUG_ONLY(_starting_thread = this;)
1042 return os::create_main_thread((JavaThread*)this);
1043 }
1044
1045 static void initialize_class(Symbol* class_name, TRAPS) {
1046 Klass* klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK);
1047 InstanceKlass::cast(klass)->initialize(CHECK);
1048 }
1049
1050
1051 // Creates the initial ThreadGroup
1052 static Handle create_initial_thread_group(TRAPS) {
1053 Handle system_instance = JavaCalls::construct_new_instance(
1054 SystemDictionary::ThreadGroup_klass(),
1799 // there to provoke an exception during stack banging. If java code
1800 // is executing there, either StackShadowPages should be larger, or
1801 // some exception code in c1, c2 or the interpreter isn't unwinding
1802 // when it should.
1803 guarantee(cur_sp > stack_reserved_zone_base(),
1804 "not enough space to reguard - increase StackShadowPages");
1805 if (_stack_guard_state == stack_guard_yellow_reserved_disabled) {
1806 enable_stack_yellow_reserved_zone();
1807 if (reserved_stack_activation() != stack_base()) {
1808 set_reserved_stack_activation(stack_base());
1809 }
1810 } else if (_stack_guard_state == stack_guard_reserved_disabled) {
1811 set_reserved_stack_activation(stack_base());
1812 enable_stack_reserved_zone();
1813 }
1814 return true;
1815 }
1816
1817 bool JavaThread::reguard_stack(void) {
1818 return reguard_stack(os::current_stack_pointer());
1819 }
1820
1821
1822 // Check for adr in the usable portion of this thread's stack.
1823 bool JavaThread::is_in_usable_stack(address adr) const {
1824 size_t stack_guard_size = os::uses_stack_guard_pages() ? JavaThread::stack_guard_zone_size() : 0;
1825 size_t usable_stack_size = _stack_size - stack_guard_size;
1826
1827 return ((stack_base() > adr) && (adr >= (stack_base() - usable_stack_size)));
1828 }
1829
1830 void JavaThread::block_if_vm_exited() {
1831 if (_terminated == _vm_exited) {
1832 // _vm_exited is set at safepoint, and Threads_lock is never released
1833 // we will block here forever.
1834 // Here we can be doing a jump from a safe state to an unsafe state without
1835 // proper transition, but it happens after the final safepoint has begun.
1836 set_thread_state(_thread_in_vm);
1837 Threads_lock->lock();
1838 ShouldNotReachHere();
1839 }
1840 }
1841
1842
1843 // Remove this ifdef when C1 is ported to the compiler interface.
1844 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1845 static void sweeper_thread_entry(JavaThread* thread, TRAPS);
1846
1847 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
|
1001
1002 void Thread::check_for_valid_safepoint_state() {
1003 if (!is_Java_thread()) return;
1004
1005 // Check NoSafepointVerifier, which is implied by locks taken that can be
1006 // shared with the VM thread. This makes sure that no locks with allow_vm_block
1007 // are held.
1008 check_possible_safepoint();
1009
1010 if (((JavaThread*)this)->thread_state() != _thread_in_vm) {
1011 fatal("LEAF method calling lock?");
1012 }
1013
1014 if (GCALotAtAllSafepoints) {
1015 // We could enter a safepoint here and thus have a gc
1016 InterfaceSupport::check_gc_alot();
1017 }
1018 }
1019 #endif // ASSERT
1020
1021 // We had to move these methods here, because vm threads get into ObjectSynchronizer::enter
1022 // However, there is a note in JavaThread::is_lock_owned() about the VM threads not being
1023 // used for compilation in the future. If that change is made, the need for these methods
1024 // should be revisited, and they should be removed if possible.
1025
1026 bool Thread::is_lock_owned(address adr) const {
1027 return is_in_full_stack(adr);
1028 }
1029
1030 bool Thread::set_as_starting_thread() {
1031 assert(_starting_thread == NULL, "already initialized: "
1032 "_starting_thread=" INTPTR_FORMAT, p2i(_starting_thread));
1033 // NOTE: this must be called inside the main thread.
1034 DEBUG_ONLY(_starting_thread = this;)
1035 return os::create_main_thread((JavaThread*)this);
1036 }
1037
1038 static void initialize_class(Symbol* class_name, TRAPS) {
1039 Klass* klass = SystemDictionary::resolve_or_fail(class_name, true, CHECK);
1040 InstanceKlass::cast(klass)->initialize(CHECK);
1041 }
1042
1043
1044 // Creates the initial ThreadGroup
1045 static Handle create_initial_thread_group(TRAPS) {
1046 Handle system_instance = JavaCalls::construct_new_instance(
1047 SystemDictionary::ThreadGroup_klass(),
1792 // there to provoke an exception during stack banging. If java code
1793 // is executing there, either StackShadowPages should be larger, or
1794 // some exception code in c1, c2 or the interpreter isn't unwinding
1795 // when it should.
1796 guarantee(cur_sp > stack_reserved_zone_base(),
1797 "not enough space to reguard - increase StackShadowPages");
1798 if (_stack_guard_state == stack_guard_yellow_reserved_disabled) {
1799 enable_stack_yellow_reserved_zone();
1800 if (reserved_stack_activation() != stack_base()) {
1801 set_reserved_stack_activation(stack_base());
1802 }
1803 } else if (_stack_guard_state == stack_guard_reserved_disabled) {
1804 set_reserved_stack_activation(stack_base());
1805 enable_stack_reserved_zone();
1806 }
1807 return true;
1808 }
1809
1810 bool JavaThread::reguard_stack(void) {
1811 return reguard_stack(os::current_stack_pointer());
1812 }
1813
1814 void JavaThread::block_if_vm_exited() {
1815 if (_terminated == _vm_exited) {
1816 // _vm_exited is set at safepoint, and Threads_lock is never released
1817 // we will block here forever.
1818 // Here we can be doing a jump from a safe state to an unsafe state without
1819 // proper transition, but it happens after the final safepoint has begun.
1820 set_thread_state(_thread_in_vm);
1821 Threads_lock->lock();
1822 ShouldNotReachHere();
1823 }
1824 }
1825
1826
1827 // Remove this ifdef when C1 is ported to the compiler interface.
1828 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1829 static void sweeper_thread_entry(JavaThread* thread, TRAPS);
1830
1831 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
|