738
739 public:
740 // State of the stack guard pages for this thread.
741 enum StackGuardState {
742 stack_guard_unused, // not needed
743 stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
744 stack_guard_enabled // enabled
745 };
746
747 private:
748
749 StackGuardState _stack_guard_state;
750
751 // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
752 // used to temp. parsing values into and out of the runtime system during exception handling for compiled
753 // code)
754 volatile oop _exception_oop; // Exception thrown in compiled code
755 volatile address _exception_pc; // PC where exception happened
756 volatile address _exception_handler_pc; // PC for handler of exception
757 volatile int _exception_stack_size; // Size of frame where exception happened
758
759 // support for compilation
760 bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
761
762 // support for JNI critical regions
763 jint _jni_active_critical; // count of entries into JNI critical region
764
765 // For deadlock detection.
766 int _depth_first_number;
767
768 // JVMTI PopFrame support
769 // This is set to popframe_pending to signal that top Java frame should be popped immediately
770 int _popframe_condition;
771
772 #ifndef PRODUCT
773 int _jmp_ring_index;
774 struct {
775 // We use intptr_t instead of address so debugger doesn't try and display strings
776 intptr_t _target;
777 intptr_t _instruction;
1070
1071 intptr_t* must_deopt_id() { return _must_deopt_id; }
1072 void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; }
1073 void clear_must_deopt_id() { _must_deopt_id = NULL; }
1074
1075 methodOop callee_target() const { return _callee_target; }
1076 void set_callee_target (methodOop x) { _callee_target = x; }
1077
1078 // Oop results of vm runtime calls
1079 oop vm_result() const { return _vm_result; }
1080 void set_vm_result (oop x) { _vm_result = x; }
1081
1082 oop vm_result_2() const { return _vm_result_2; }
1083 void set_vm_result_2 (oop x) { _vm_result_2 = x; }
1084
1085 // Exception handling for compiled methods
1086 oop exception_oop() const { return _exception_oop; }
1087 int exception_stack_size() const { return _exception_stack_size; }
1088 address exception_pc() const { return _exception_pc; }
1089 address exception_handler_pc() const { return _exception_handler_pc; }
1090
1091 void set_exception_oop(oop o) { _exception_oop = o; }
1092 void set_exception_pc(address a) { _exception_pc = a; }
1093 void set_exception_handler_pc(address a) { _exception_handler_pc = a; }
1094 void set_exception_stack_size(int size) { _exception_stack_size = size; }
1095
1096 // Stack overflow support
1097 inline size_t stack_available(address cur_sp);
1098 address stack_yellow_zone_base()
1099 { return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); }
1100 size_t stack_yellow_zone_size()
1101 { return StackYellowPages * os::vm_page_size(); }
1102 address stack_red_zone_base()
1103 { return (address)(stack_base() - (stack_size() - stack_red_zone_size())); }
1104 size_t stack_red_zone_size()
1105 { return StackRedPages * os::vm_page_size(); }
1106 bool in_stack_yellow_zone(address a)
1107 { return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); }
1108 bool in_stack_red_zone(address a)
1109 { return (a <= stack_red_zone_base()) && (a >= (address)((intptr_t)stack_base() - stack_size())); }
1110
1111 void create_stack_guard_pages();
1112 void remove_stack_guard_pages();
1113
1114 void enable_stack_yellow_zone();
1148 static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
1149 static ByteSize last_Java_sp_offset() {
1150 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1151 }
1152 static ByteSize last_Java_pc_offset() {
1153 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1154 }
1155 static ByteSize frame_anchor_offset() {
1156 return byte_offset_of(JavaThread, _anchor);
1157 }
1158 static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
1159 static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
1160 static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
1161 static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
1162 static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
1163 static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
1164 static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
1165 static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
1166 static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
1167 static ByteSize exception_stack_size_offset() { return byte_offset_of(JavaThread, _exception_stack_size); }
1168 static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
1169 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
1170
1171 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
1172
1173 #ifndef SERIALGC
1174 static ByteSize satb_mark_queue_offset() { return byte_offset_of(JavaThread, _satb_mark_queue); }
1175 static ByteSize dirty_card_queue_offset() { return byte_offset_of(JavaThread, _dirty_card_queue); }
1176 #endif // !SERIALGC
1177
1178 // Returns the jni environment for this thread
1179 JNIEnv* jni_environment() { return &_jni_environment; }
1180
1181 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
1182 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
1183 // Only return NULL if thread is off the thread list; starting to
1184 // exit should not return NULL.
1185 if (thread_from_jni_env->is_terminated()) {
1186 thread_from_jni_env->block_if_vm_exited();
1187 return NULL;
|
738
739 public:
740 // State of the stack guard pages for this thread.
741 enum StackGuardState {
742 stack_guard_unused, // not needed
743 stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
744 stack_guard_enabled // enabled
745 };
746
747 private:
748
749 StackGuardState _stack_guard_state;
750
751 // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
752 // used to temp. parsing values into and out of the runtime system during exception handling for compiled
753 // code)
754 volatile oop _exception_oop; // Exception thrown in compiled code
755 volatile address _exception_pc; // PC where exception happened
756 volatile address _exception_handler_pc; // PC for handler of exception
757 volatile int _exception_stack_size; // Size of frame where exception happened
758 volatile int _is_method_handle_exception; // True if the current exception PC is at a MethodHandle call.
759
760 // support for compilation
761 bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
762
763 // support for JNI critical regions
764 jint _jni_active_critical; // count of entries into JNI critical region
765
766 // For deadlock detection.
767 int _depth_first_number;
768
769 // JVMTI PopFrame support
770 // This is set to popframe_pending to signal that top Java frame should be popped immediately
771 int _popframe_condition;
772
773 #ifndef PRODUCT
774 int _jmp_ring_index;
775 struct {
776 // We use intptr_t instead of address so debugger doesn't try and display strings
777 intptr_t _target;
778 intptr_t _instruction;
1071
1072 intptr_t* must_deopt_id() { return _must_deopt_id; }
1073 void set_must_deopt_id(intptr_t* id) { _must_deopt_id = id; }
1074 void clear_must_deopt_id() { _must_deopt_id = NULL; }
1075
1076 methodOop callee_target() const { return _callee_target; }
1077 void set_callee_target (methodOop x) { _callee_target = x; }
1078
1079 // Oop results of vm runtime calls
1080 oop vm_result() const { return _vm_result; }
1081 void set_vm_result (oop x) { _vm_result = x; }
1082
1083 oop vm_result_2() const { return _vm_result_2; }
1084 void set_vm_result_2 (oop x) { _vm_result_2 = x; }
1085
1086 // Exception handling for compiled methods
1087 oop exception_oop() const { return _exception_oop; }
1088 int exception_stack_size() const { return _exception_stack_size; }
1089 address exception_pc() const { return _exception_pc; }
1090 address exception_handler_pc() const { return _exception_handler_pc; }
1091 int is_method_handle_exception() const { return _is_method_handle_exception; }
1092
1093 void set_exception_oop(oop o) { _exception_oop = o; }
1094 void set_exception_pc(address a) { _exception_pc = a; }
1095 void set_exception_handler_pc(address a) { _exception_handler_pc = a; }
1096 void set_exception_stack_size(int size) { _exception_stack_size = size; }
1097 void set_is_method_handle_exception(int value) { _is_method_handle_exception = value; }
1098
1099 // Stack overflow support
1100 inline size_t stack_available(address cur_sp);
1101 address stack_yellow_zone_base()
1102 { return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); }
1103 size_t stack_yellow_zone_size()
1104 { return StackYellowPages * os::vm_page_size(); }
1105 address stack_red_zone_base()
1106 { return (address)(stack_base() - (stack_size() - stack_red_zone_size())); }
1107 size_t stack_red_zone_size()
1108 { return StackRedPages * os::vm_page_size(); }
1109 bool in_stack_yellow_zone(address a)
1110 { return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); }
1111 bool in_stack_red_zone(address a)
1112 { return (a <= stack_red_zone_base()) && (a >= (address)((intptr_t)stack_base() - stack_size())); }
1113
1114 void create_stack_guard_pages();
1115 void remove_stack_guard_pages();
1116
1117 void enable_stack_yellow_zone();
1151 static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
1152 static ByteSize last_Java_sp_offset() {
1153 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1154 }
1155 static ByteSize last_Java_pc_offset() {
1156 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1157 }
1158 static ByteSize frame_anchor_offset() {
1159 return byte_offset_of(JavaThread, _anchor);
1160 }
1161 static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
1162 static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
1163 static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
1164 static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
1165 static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
1166 static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
1167 static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
1168 static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
1169 static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
1170 static ByteSize exception_stack_size_offset() { return byte_offset_of(JavaThread, _exception_stack_size); }
1171 static ByteSize is_method_handle_exception_offset() { return byte_offset_of(JavaThread, _is_method_handle_exception); }
1172 static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
1173 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
1174
1175 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
1176
1177 #ifndef SERIALGC
1178 static ByteSize satb_mark_queue_offset() { return byte_offset_of(JavaThread, _satb_mark_queue); }
1179 static ByteSize dirty_card_queue_offset() { return byte_offset_of(JavaThread, _dirty_card_queue); }
1180 #endif // !SERIALGC
1181
1182 // Returns the jni environment for this thread
1183 JNIEnv* jni_environment() { return &_jni_environment; }
1184
1185 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
1186 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
1187 // Only return NULL if thread is off the thread list; starting to
1188 // exit should not return NULL.
1189 if (thread_from_jni_env->is_terminated()) {
1190 thread_from_jni_env->block_if_vm_exited();
1191 return NULL;
|