447
448 // JVMTI PopFrame support
449 // This is set to popframe_pending to signal that top Java frame should be popped immediately
450 int _popframe_condition;
451
452 // If reallocation of scalar replaced objects fails, we throw OOM
453 // and during exception propagation, pop the top
454 // _frames_to_pop_failed_realloc frames, the ones that reference
455 // failed reallocations.
456 int _frames_to_pop_failed_realloc;
457
458 ContinuationEntry* _cont_entry;
459 intptr_t* _cont_fastpath; // the sp of the oldest known interpreted/call_stub frame inside the
460 // continuation that we know about
461 int _cont_fastpath_thread_state; // whether global thread state allows continuation fastpath (JVMTI)
462
463 // It's signed for error detection.
464 intx _held_monitor_count; // used by continuations for fast lock detection
465 intx _jni_monitor_count;
466
467 private:
468
469 friend class VMThread;
470 friend class ThreadWaitTransition;
471 friend class VM_Exit;
472
473 // Stack watermark barriers.
474 StackWatermarks _stack_watermarks;
475
476 public:
477 inline StackWatermarks* stack_watermarks() { return &_stack_watermarks; }
478
479 public:
480 // Constructor
481 JavaThread(); // delegating constructor
482 JavaThread(bool is_attaching_via_jni); // for main thread and JNI attached threads
483 JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
484 ~JavaThread();
485
486 #ifdef ASSERT
497 struct JNINativeInterface_* get_jni_functions() {
498 return (struct JNINativeInterface_ *)_jni_environment.functions;
499 }
500
501 // This function is called at thread creation to allow
502 // platform specific thread variables to be initialized.
503 void cache_global_variables();
504
505 // Executes Shutdown.shutdown()
506 void invoke_shutdown_hooks();
507
508 // Cleanup on thread exit
509 enum ExitType {
510 normal_exit,
511 jni_detach
512 };
513 void exit(bool destroy_vm, ExitType exit_type = normal_exit);
514
515 void cleanup_failed_attach_current_thread(bool is_daemon);
516
517 // Testers
518 virtual bool is_Java_thread() const { return true; }
519 virtual bool can_call_java() const { return true; }
520
521 virtual bool is_active_Java_thread() const;
522
523 // Thread oop. threadObj() can be null for initial JavaThread
524 // (or for threads attached via JNI)
525 oop threadObj() const;
526 void set_threadOopHandles(oop p);
527 oop vthread() const;
528 void set_vthread(oop p);
529 oop scopedValueCache() const;
530 void set_scopedValueCache(oop p);
531 void clear_scopedValueBindings();
532 oop jvmti_vthread() const;
533 void set_jvmti_vthread(oop p);
534 oop vthread_or_thread() const;
535
536 // Prepare thread and add to priority queue. If a priority is
537 // not specified, use the priority of the thread object. Threads_lock
538 // must be held while this function is called.
539 void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);
945
946 javaVFrame* last_java_vframe(const frame f, RegisterMap* reg_map);
947
948 // Returns method at 'depth' java or native frames down the stack
949 // Used for security checks
950 Klass* security_get_caller_class(int depth);
951
952 // Print stack trace in external format
953 // These variants print carrier/platform thread information only.
954 void print_stack_on(outputStream* st);
955 void print_stack() { print_stack_on(tty); }
956 // This prints the currently mounted virtual thread.
957 void print_vthread_stack_on(outputStream* st);
958 // This prints the active stack: either carrier/platform or virtual.
959 void print_active_stack_on(outputStream* st);
960 // Print current stack trace for checked JNI warnings and JNI fatal errors.
961 // This is the external format from above, but selecting the platform
962 // or vthread as applicable.
963 void print_jni_stack();
964
965 // Print stack traces in various internal formats
966 void trace_stack() PRODUCT_RETURN;
967 void trace_stack_from(vframe* start_vf) PRODUCT_RETURN;
968 void trace_frames() PRODUCT_RETURN;
969
970 // Print an annotated view of the stack frames
971 void print_frame_layout(int depth = 0, bool validate_only = false) NOT_DEBUG_RETURN;
972 void validate_frame_layout() {
973 print_frame_layout(0, true);
974 }
975
976 // Function for testing deoptimization
977 void deoptimize();
978 void make_zombies();
979
980 void deoptimize_marked_methods();
981
982 public:
983 // Returns the running thread as a JavaThread
984 static JavaThread* current() {
1127 #include OS_CPU_HEADER(javaThread)
1128
1129 // JSR166 per-thread parker
1130 private:
1131 Parker _parker;
1132 public:
1133 Parker* parker() { return &_parker; }
1134
1135 public:
1136 // clearing/querying jni attach status
1137 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
1138 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
1139 inline void set_done_attaching_via_jni();
1140
1141 // Stack dump assistance:
1142 // Track the class we want to initialize but for which we have to wait
1143 // on its init_lock() because it is already being initialized.
1144 void set_class_to_be_initialized(InstanceKlass* k);
1145 InstanceKlass* class_to_be_initialized() const;
1146
1147 private:
1148 InstanceKlass* _class_to_be_initialized;
1149
1150 // java.lang.Thread.sleep support
1151 ParkEvent * _SleepEvent;
1152 public:
1153 bool sleep(jlong millis);
1154 bool sleep_nanos(jlong nanos);
1155
1156 // java.lang.Thread interruption support
1157 void interrupt();
1158 bool is_interrupted(bool clear_interrupted);
1159
1160 // This is only for use by JVMTI RawMonitorWait. It emulates the actions of
1161 // the Java code in Object::wait which are not present in RawMonitorWait.
1162 bool get_and_clear_interrupted();
1163
1164 private:
1165 LockStack _lock_stack;
1166
1167 public:
1168 LockStack& lock_stack() { return _lock_stack; }
|
447
448 // JVMTI PopFrame support
449 // This is set to popframe_pending to signal that top Java frame should be popped immediately
450 int _popframe_condition;
451
452 // If reallocation of scalar replaced objects fails, we throw OOM
453 // and during exception propagation, pop the top
454 // _frames_to_pop_failed_realloc frames, the ones that reference
455 // failed reallocations.
456 int _frames_to_pop_failed_realloc;
457
458 ContinuationEntry* _cont_entry;
459 intptr_t* _cont_fastpath; // the sp of the oldest known interpreted/call_stub frame inside the
460 // continuation that we know about
461 int _cont_fastpath_thread_state; // whether global thread state allows continuation fastpath (JVMTI)
462
463 // It's signed for error detection.
464 intx _held_monitor_count; // used by continuations for fast lock detection
465 intx _jni_monitor_count;
466
467 bool _can_call_java;
468
469 private:
470
471 friend class VMThread;
472 friend class ThreadWaitTransition;
473 friend class VM_Exit;
474
475 // Stack watermark barriers.
476 StackWatermarks _stack_watermarks;
477
478 public:
479 inline StackWatermarks* stack_watermarks() { return &_stack_watermarks; }
480
481 public:
482 // Constructor
483 JavaThread(); // delegating constructor
484 JavaThread(bool is_attaching_via_jni); // for main thread and JNI attached threads
485 JavaThread(ThreadFunction entry_point, size_t stack_size = 0);
486 ~JavaThread();
487
488 #ifdef ASSERT
499 struct JNINativeInterface_* get_jni_functions() {
500 return (struct JNINativeInterface_ *)_jni_environment.functions;
501 }
502
503 // This function is called at thread creation to allow
504 // platform specific thread variables to be initialized.
505 void cache_global_variables();
506
507 // Executes Shutdown.shutdown()
508 void invoke_shutdown_hooks();
509
510 // Cleanup on thread exit
511 enum ExitType {
512 normal_exit,
513 jni_detach
514 };
515 void exit(bool destroy_vm, ExitType exit_type = normal_exit);
516
517 void cleanup_failed_attach_current_thread(bool is_daemon);
518
519 class NoJavaCodeMark : public StackObj {
520 friend JavaThread;
521 JavaThread* _target;
522 bool _orig;
523 public:
524 NoJavaCodeMark(JavaThread* t) : _target(t), _orig(t->_can_call_java) {
525 _target->_can_call_java = false;
526 }
527 ~NoJavaCodeMark() {
528 _target->_can_call_java = _orig;
529 }
530 };
531
532 // Testers
533 virtual bool is_Java_thread() const { return true; }
534 virtual bool can_call_java() const { return _can_call_java; }
535
536 virtual bool is_active_Java_thread() const;
537
538 // Thread oop. threadObj() can be null for initial JavaThread
539 // (or for threads attached via JNI)
540 oop threadObj() const;
541 void set_threadOopHandles(oop p);
542 oop vthread() const;
543 void set_vthread(oop p);
544 oop scopedValueCache() const;
545 void set_scopedValueCache(oop p);
546 void clear_scopedValueBindings();
547 oop jvmti_vthread() const;
548 void set_jvmti_vthread(oop p);
549 oop vthread_or_thread() const;
550
551 // Prepare thread and add to priority queue. If a priority is
552 // not specified, use the priority of the thread object. Threads_lock
553 // must be held while this function is called.
554 void prepare(jobject jni_thread, ThreadPriority prio=NoPriority);
960
961 javaVFrame* last_java_vframe(const frame f, RegisterMap* reg_map);
962
963 // Returns method at 'depth' java or native frames down the stack
964 // Used for security checks
965 Klass* security_get_caller_class(int depth);
966
967 // Print stack trace in external format
968 // These variants print carrier/platform thread information only.
969 void print_stack_on(outputStream* st);
970 void print_stack() { print_stack_on(tty); }
971 // This prints the currently mounted virtual thread.
972 void print_vthread_stack_on(outputStream* st);
973 // This prints the active stack: either carrier/platform or virtual.
974 void print_active_stack_on(outputStream* st);
975 // Print current stack trace for checked JNI warnings and JNI fatal errors.
976 // This is the external format from above, but selecting the platform
977 // or vthread as applicable.
978 void print_jni_stack();
979
980 void print_native_stack_on(outputStream* st);
981
982 // Print stack traces in various internal formats
983 void trace_stack() PRODUCT_RETURN;
984 void trace_stack_from(vframe* start_vf) PRODUCT_RETURN;
985 void trace_frames() PRODUCT_RETURN;
986
987 // Print an annotated view of the stack frames
988 void print_frame_layout(int depth = 0, bool validate_only = false) NOT_DEBUG_RETURN;
989 void validate_frame_layout() {
990 print_frame_layout(0, true);
991 }
992
993 // Function for testing deoptimization
994 void deoptimize();
995 void make_zombies();
996
997 void deoptimize_marked_methods();
998
999 public:
1000 // Returns the running thread as a JavaThread
1001 static JavaThread* current() {
1144 #include OS_CPU_HEADER(javaThread)
1145
1146 // JSR166 per-thread parker
1147 private:
1148 Parker _parker;
1149 public:
1150 Parker* parker() { return &_parker; }
1151
1152 public:
1153 // clearing/querying jni attach status
1154 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; }
1155 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; }
1156 inline void set_done_attaching_via_jni();
1157
1158 // Stack dump assistance:
1159 // Track the class we want to initialize but for which we have to wait
1160 // on its init_lock() because it is already being initialized.
1161 void set_class_to_be_initialized(InstanceKlass* k);
1162 InstanceKlass* class_to_be_initialized() const;
1163
1164 // The most recent active <clinit> invocation is tracked by this variable.
1165 // The setter returns the previous value, so it can be restored later if needed.
1166 InstanceKlass* set_class_being_initialized(InstanceKlass* k);
1167 InstanceKlass* class_being_initialized() const;
1168
1169 private:
1170 InstanceKlass* _class_to_be_initialized;
1171 InstanceKlass* _class_being_initialized;
1172
1173 // java.lang.Thread.sleep support
1174 ParkEvent * _SleepEvent;
1175 public:
1176 bool sleep(jlong millis);
1177 bool sleep_nanos(jlong nanos);
1178
1179 // java.lang.Thread interruption support
1180 void interrupt();
1181 bool is_interrupted(bool clear_interrupted);
1182
1183 // This is only for use by JVMTI RawMonitorWait. It emulates the actions of
1184 // the Java code in Object::wait which are not present in RawMonitorWait.
1185 bool get_and_clear_interrupted();
1186
1187 private:
1188 LockStack _lock_stack;
1189
1190 public:
1191 LockStack& lock_stack() { return _lock_stack; }
|