878 _attached_via_jni // thread has attached via JNI
879 };
880
881 // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
882 // A native thread that is attaching via JNI starts with a value
883 // of _attaching_via_jni and transitions to _attached_via_jni.
884 volatile JNIAttachStates _jni_attach_state;
885
886 public:
887 // State of the stack guard pages for this thread.
888 enum StackGuardState {
889 stack_guard_unused, // not needed
890 stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
891 stack_guard_enabled // enabled
892 };
893
894 private:
895
896 StackGuardState _stack_guard_state;
897
898 // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
899 // used to temp. parsing values into and out of the runtime system during exception handling for compiled
900 // code)
901 volatile oop _exception_oop; // Exception thrown in compiled code
902 volatile address _exception_pc; // PC where exception happened
903 volatile address _exception_handler_pc; // PC for handler of exception
904 volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site.
905
906 // support for compilation
907 bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
908
909 // support for JNI critical regions
910 jint _jni_active_critical; // count of entries into JNI critical region
911
912 // For deadlock detection.
913 int _depth_first_number;
914
915 // JVMTI PopFrame support
916 // This is set to popframe_pending to signal that top Java frame should be popped immediately
917 int _popframe_condition;
1284 void enable_stack_yellow_zone();
1285 void disable_stack_yellow_zone();
1286 void enable_stack_red_zone();
1287 void disable_stack_red_zone();
1288
1289 inline bool stack_guard_zone_unused();
1290 inline bool stack_yellow_zone_disabled();
1291 inline bool stack_yellow_zone_enabled();
1292
1293 // Attempt to reguard the stack after a stack overflow may have occurred.
1294 // Returns true if (a) guard pages are not needed on this thread, (b) the
1295 // pages are already guarded, or (c) the pages were successfully reguarded.
1296 // Returns false if there is not enough stack space to reguard the pages, in
1297 // which case the caller should unwind a frame and try again. The argument
1298 // should be the caller's (approximate) sp.
1299 bool reguard_stack(address cur_sp);
1300 // Similar to above but see if current stackpoint is out of the guard area
1301 // and reguard if possible.
1302 bool reguard_stack(void);
1303
1304 // Misc. accessors/mutators
1305 void set_do_not_unlock(void) { _do_not_unlock_if_synchronized = true; }
1306 void clr_do_not_unlock(void) { _do_not_unlock_if_synchronized = false; }
1307 bool do_not_unlock(void) { return _do_not_unlock_if_synchronized; }
1308
1309 #ifndef PRODUCT
1310 void record_jump(address target, address instr, const char* file, int line);
1311 #endif /* PRODUCT */
1312
1313 // For assembly stub generation
1314 static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj ); }
1315 #ifndef PRODUCT
1316 static ByteSize jmp_ring_index_offset() { return byte_offset_of(JavaThread, _jmp_ring_index ); }
1317 static ByteSize jmp_ring_offset() { return byte_offset_of(JavaThread, _jmp_ring ); }
1318 #endif /* PRODUCT */
1319 static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
1320 static ByteSize last_Java_sp_offset() {
1321 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1322 }
1323 static ByteSize last_Java_pc_offset() {
1324 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1325 }
1326 static ByteSize frame_anchor_offset() {
1327 return byte_offset_of(JavaThread, _anchor);
1328 }
1329 static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
1330 static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
1331 static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
1332 static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
1333 static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
1334 static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
1335 static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
1336 static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
1337 static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
1338 static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1339 static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
1340 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
1341
1342 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
1343 static ByteSize should_post_on_exceptions_flag_offset() {
1344 return byte_offset_of(JavaThread, _should_post_on_exceptions_flag);
1345 }
1346
1347 #if INCLUDE_ALL_GCS
1348 static ByteSize satb_mark_queue_offset() { return byte_offset_of(JavaThread, _satb_mark_queue); }
1349 static ByteSize dirty_card_queue_offset() { return byte_offset_of(JavaThread, _dirty_card_queue); }
1350 #endif // INCLUDE_ALL_GCS
1351
1352 // Returns the jni environment for this thread
1353 JNIEnv* jni_environment() { return &_jni_environment; }
1354
1355 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
1356 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
1357 // Only return NULL if thread is off the thread list; starting to
|
878 _attached_via_jni // thread has attached via JNI
879 };
880
881 // A regular JavaThread's _jni_attach_state is _not_attaching_via_jni.
882 // A native thread that is attaching via JNI starts with a value
883 // of _attaching_via_jni and transitions to _attached_via_jni.
884 volatile JNIAttachStates _jni_attach_state;
885
886 public:
887 // State of the stack guard pages for this thread.
888 enum StackGuardState {
889 stack_guard_unused, // not needed
890 stack_guard_yellow_disabled,// disabled (temporarily) after stack overflow
891 stack_guard_enabled // enabled
892 };
893
894 private:
895
896 StackGuardState _stack_guard_state;
897
898 // Precompute the limit of the stack as used in stack overflow checks.
899 // We load it from here to simplify the stack overflow check in assembly.
900 address _stack_overflow_limit;
901
902 // Compiler exception handling (NOTE: The _exception_oop is *NOT* the same as _pending_exception. It is
903 // used to temp. parsing values into and out of the runtime system during exception handling for compiled
904 // code)
905 volatile oop _exception_oop; // Exception thrown in compiled code
906 volatile address _exception_pc; // PC where exception happened
907 volatile address _exception_handler_pc; // PC for handler of exception
908 volatile int _is_method_handle_return; // true (== 1) if the current exception PC is a MethodHandle call site.
909
910 // support for compilation
911 bool _is_compiling; // is true if a compilation is active inthis thread (one compilation per thread possible)
912
913 // support for JNI critical regions
914 jint _jni_active_critical; // count of entries into JNI critical region
915
916 // For deadlock detection.
917 int _depth_first_number;
918
919 // JVMTI PopFrame support
920 // This is set to popframe_pending to signal that top Java frame should be popped immediately
921 int _popframe_condition;
1288 void enable_stack_yellow_zone();
1289 void disable_stack_yellow_zone();
1290 void enable_stack_red_zone();
1291 void disable_stack_red_zone();
1292
1293 inline bool stack_guard_zone_unused();
1294 inline bool stack_yellow_zone_disabled();
1295 inline bool stack_yellow_zone_enabled();
1296
1297 // Attempt to reguard the stack after a stack overflow may have occurred.
1298 // Returns true if (a) guard pages are not needed on this thread, (b) the
1299 // pages are already guarded, or (c) the pages were successfully reguarded.
1300 // Returns false if there is not enough stack space to reguard the pages, in
1301 // which case the caller should unwind a frame and try again. The argument
1302 // should be the caller's (approximate) sp.
1303 bool reguard_stack(address cur_sp);
1304 // Similar to above but see if current stackpoint is out of the guard area
1305 // and reguard if possible.
1306 bool reguard_stack(void);
1307
1308 address stack_overflow_limit() { return _stack_overflow_limit; }
1309 void set_stack_overflow_limit() {
1310 _stack_overflow_limit = _stack_base - _stack_size +
1311 ((StackShadowPages +
1312 StackYellowPages +
1313 StackRedPages) * os::vm_page_size());
1314 }
1315
1316 // Misc. accessors/mutators
1317 void set_do_not_unlock(void) { _do_not_unlock_if_synchronized = true; }
1318 void clr_do_not_unlock(void) { _do_not_unlock_if_synchronized = false; }
1319 bool do_not_unlock(void) { return _do_not_unlock_if_synchronized; }
1320
1321 #ifndef PRODUCT
1322 void record_jump(address target, address instr, const char* file, int line);
1323 #endif /* PRODUCT */
1324
1325 // For assembly stub generation
1326 static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj ); }
1327 #ifndef PRODUCT
1328 static ByteSize jmp_ring_index_offset() { return byte_offset_of(JavaThread, _jmp_ring_index ); }
1329 static ByteSize jmp_ring_offset() { return byte_offset_of(JavaThread, _jmp_ring ); }
1330 #endif /* PRODUCT */
1331 static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment ); }
1332 static ByteSize last_Java_sp_offset() {
1333 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset();
1334 }
1335 static ByteSize last_Java_pc_offset() {
1336 return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_pc_offset();
1337 }
1338 static ByteSize frame_anchor_offset() {
1339 return byte_offset_of(JavaThread, _anchor);
1340 }
1341 static ByteSize callee_target_offset() { return byte_offset_of(JavaThread, _callee_target ); }
1342 static ByteSize vm_result_offset() { return byte_offset_of(JavaThread, _vm_result ); }
1343 static ByteSize vm_result_2_offset() { return byte_offset_of(JavaThread, _vm_result_2 ); }
1344 static ByteSize thread_state_offset() { return byte_offset_of(JavaThread, _thread_state ); }
1345 static ByteSize saved_exception_pc_offset() { return byte_offset_of(JavaThread, _saved_exception_pc ); }
1346 static ByteSize osthread_offset() { return byte_offset_of(JavaThread, _osthread ); }
1347 static ByteSize exception_oop_offset() { return byte_offset_of(JavaThread, _exception_oop ); }
1348 static ByteSize exception_pc_offset() { return byte_offset_of(JavaThread, _exception_pc ); }
1349 static ByteSize exception_handler_pc_offset() { return byte_offset_of(JavaThread, _exception_handler_pc); }
1350 static ByteSize stack_overflow_limit_offset() { return byte_offset_of(JavaThread, _stack_overflow_limit); }
1351 static ByteSize is_method_handle_return_offset() { return byte_offset_of(JavaThread, _is_method_handle_return); }
1352 static ByteSize stack_guard_state_offset() { return byte_offset_of(JavaThread, _stack_guard_state ); }
1353 static ByteSize suspend_flags_offset() { return byte_offset_of(JavaThread, _suspend_flags ); }
1354
1355 static ByteSize do_not_unlock_if_synchronized_offset() { return byte_offset_of(JavaThread, _do_not_unlock_if_synchronized); }
1356 static ByteSize should_post_on_exceptions_flag_offset() {
1357 return byte_offset_of(JavaThread, _should_post_on_exceptions_flag);
1358 }
1359
1360 #if INCLUDE_ALL_GCS
1361 static ByteSize satb_mark_queue_offset() { return byte_offset_of(JavaThread, _satb_mark_queue); }
1362 static ByteSize dirty_card_queue_offset() { return byte_offset_of(JavaThread, _dirty_card_queue); }
1363 #endif // INCLUDE_ALL_GCS
1364
1365 // Returns the jni environment for this thread
1366 JNIEnv* jni_environment() { return &_jni_environment; }
1367
1368 static JavaThread* thread_from_jni_environment(JNIEnv* env) {
1369 JavaThread *thread_from_jni_env = (JavaThread*)((intptr_t)env - in_bytes(jni_environment_offset()));
1370 // Only return NULL if thread is off the thread list; starting to
|