Mercurial > hg > graal-jvmci-8
comparison src/share/vm/runtime/thread.hpp @ 20804:7848fc12602b
Merge with jdk8u40-b25
author | Gilles Duboscq <gilles.m.duboscq@oracle.com> |
---|---|
date | Tue, 07 Apr 2015 14:58:49 +0200 |
parents | 8f2fb6bec986 d3f3f7677537 |
children | be896a1983c0 |
comparison
equal
deleted
inserted
replaced
20184:84105dcdb05b | 20804:7848fc12602b |
---|---|
38 #include "runtime/osThread.hpp" | 38 #include "runtime/osThread.hpp" |
39 #include "runtime/park.hpp" | 39 #include "runtime/park.hpp" |
40 #include "runtime/safepoint.hpp" | 40 #include "runtime/safepoint.hpp" |
41 #include "runtime/stubRoutines.hpp" | 41 #include "runtime/stubRoutines.hpp" |
42 #include "runtime/threadLocalStorage.hpp" | 42 #include "runtime/threadLocalStorage.hpp" |
43 #include "runtime/thread_ext.hpp" | |
43 #include "runtime/unhandledOops.hpp" | 44 #include "runtime/unhandledOops.hpp" |
44 #include "utilities/macros.hpp" | |
45 | |
46 #if INCLUDE_NMT | |
47 #include "services/memRecorder.hpp" | |
48 #endif // INCLUDE_NMT | |
49 | |
50 #include "trace/traceBackend.hpp" | 45 #include "trace/traceBackend.hpp" |
51 #include "trace/traceMacros.hpp" | 46 #include "trace/traceMacros.hpp" |
52 #include "utilities/exceptions.hpp" | 47 #include "utilities/exceptions.hpp" |
48 #include "utilities/macros.hpp" | |
53 #include "utilities/top.hpp" | 49 #include "utilities/top.hpp" |
54 #if INCLUDE_ALL_GCS | 50 #if INCLUDE_ALL_GCS |
55 #include "gc_implementation/g1/dirtyCardQueue.hpp" | 51 #include "gc_implementation/g1/dirtyCardQueue.hpp" |
56 #include "gc_implementation/g1/satbQueue.hpp" | 52 #include "gc_implementation/g1/satbQueue.hpp" |
57 #endif // INCLUDE_ALL_GCS | 53 #endif // INCLUDE_ALL_GCS |
83 class jvmtiDeferredLocalVariableSet; | 79 class jvmtiDeferredLocalVariableSet; |
84 | 80 |
85 class GCTaskQueue; | 81 class GCTaskQueue; |
86 class ThreadClosure; | 82 class ThreadClosure; |
87 class IdealGraphPrinter; | 83 class IdealGraphPrinter; |
84 | |
85 class Metadata; | |
86 template <class T, MEMFLAGS F> class ChunkedList; | |
87 typedef ChunkedList<Metadata*, mtInternal> MetadataOnStackBuffer; | |
88 | 88 |
89 DEBUG_ONLY(class ResourceMark;) | 89 DEBUG_ONLY(class ResourceMark;) |
90 | 90 |
91 class WorkerThread; | 91 class WorkerThread; |
92 | 92 |
257 | 257 |
258 ThreadLocalAllocBuffer _tlab; // Thread-local eden | 258 ThreadLocalAllocBuffer _tlab; // Thread-local eden |
259 jlong _allocated_bytes; // Cumulative number of bytes allocated on | 259 jlong _allocated_bytes; // Cumulative number of bytes allocated on |
260 // the Java heap | 260 // the Java heap |
261 | 261 |
262 // Thread-local buffer used by MetadataOnStackMark. | |
263 MetadataOnStackBuffer* _metadata_on_stack_buffer; | |
264 | |
262 TRACE_DATA _trace_data; // Thread-local data for tracing | 265 TRACE_DATA _trace_data; // Thread-local data for tracing |
266 | |
267 ThreadExt _ext; | |
263 | 268 |
264 int _vm_operation_started_count; // VM_Operation support | 269 int _vm_operation_started_count; // VM_Operation support |
265 int _vm_operation_completed_count; // VM_Operation support | 270 int _vm_operation_completed_count; // VM_Operation support |
266 | 271 |
267 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread | 272 ObjectMonitor* _current_pending_monitor; // ObjectMonitor this thread |
437 } | 442 } |
438 | 443 |
439 jlong allocated_bytes() { return _allocated_bytes; } | 444 jlong allocated_bytes() { return _allocated_bytes; } |
440 void set_allocated_bytes(jlong value) { _allocated_bytes = value; } | 445 void set_allocated_bytes(jlong value) { _allocated_bytes = value; } |
441 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; } | 446 void incr_allocated_bytes(jlong size) { _allocated_bytes += size; } |
442 jlong cooked_allocated_bytes() { | 447 inline jlong cooked_allocated_bytes(); |
443 jlong allocated_bytes = OrderAccess::load_acquire(&_allocated_bytes); | |
444 if (UseTLAB) { | |
445 size_t used_bytes = tlab().used_bytes(); | |
446 if ((ssize_t)used_bytes > 0) { | |
447 // More-or-less valid tlab. The load_acquire above should ensure | |
448 // that the result of the add is <= the instantaneous value | |
449 return allocated_bytes + used_bytes; | |
450 } | |
451 } | |
452 return allocated_bytes; | |
453 } | |
454 | 448 |
455 TRACE_DATA* trace_data() { return &_trace_data; } | 449 TRACE_DATA* trace_data() { return &_trace_data; } |
450 | |
451 const ThreadExt& ext() const { return _ext; } | |
452 ThreadExt& ext() { return _ext; } | |
456 | 453 |
457 // VM operation support | 454 // VM operation support |
458 int vm_operation_ticket() { return ++_vm_operation_started_count; } | 455 int vm_operation_ticket() { return ++_vm_operation_started_count; } |
459 int vm_operation_completed_count() { return _vm_operation_completed_count; } | 456 int vm_operation_completed_count() { return _vm_operation_completed_count; } |
460 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; } | 457 void increment_vm_operation_completed_count() { _vm_operation_completed_count++; } |
484 // GC support | 481 // GC support |
485 // Apply "f->do_oop" to all root oops in "this". | 482 // Apply "f->do_oop" to all root oops in "this". |
486 // Apply "cld_f->do_cld" to CLDs that are otherwise not kept alive. | 483 // Apply "cld_f->do_cld" to CLDs that are otherwise not kept alive. |
487 // Used by JavaThread::oops_do. | 484 // Used by JavaThread::oops_do. |
488 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames | 485 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
489 virtual void oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf); | 486 virtual void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
490 | 487 |
491 // Handles the parallel case for the method below. | 488 // Handles the parallel case for the method below. |
492 private: | 489 private: |
493 bool claim_oops_do_par_case(int collection_parity); | 490 bool claim_oops_do_par_case(int collection_parity); |
494 public: | 491 public: |
495 // Requires that "collection_parity" is that of the current strong roots | 492 // Requires that "collection_parity" is that of the current roots |
496 // iteration. If "is_par" is false, sets the parity of "this" to | 493 // iteration. If "is_par" is false, sets the parity of "this" to |
497 // "collection_parity", and returns "true". If "is_par" is true, | 494 // "collection_parity", and returns "true". If "is_par" is true, |
498 // uses an atomic instruction to set the current threads parity to | 495 // uses an atomic instruction to set the current threads parity to |
499 // "collection_parity", if it is not already. Returns "true" iff the | 496 // "collection_parity", if it is not already. Returns "true" iff the |
500 // calling thread does the update, this indicates that the calling thread | 497 // calling thread does the update, this indicates that the calling thread |
527 | 524 |
528 // Sets this thread as starting thread. Returns failure if thread | 525 // Sets this thread as starting thread. Returns failure if thread |
529 // creation fails due to lack of memory, too many threads etc. | 526 // creation fails due to lack of memory, too many threads etc. |
530 bool set_as_starting_thread(); | 527 bool set_as_starting_thread(); |
531 | 528 |
532 protected: | 529 void set_metadata_on_stack_buffer(MetadataOnStackBuffer* buffer) { _metadata_on_stack_buffer = buffer; } |
530 MetadataOnStackBuffer* metadata_on_stack_buffer() const { return _metadata_on_stack_buffer; } | |
531 | |
532 protected: | |
533 // OS data associated with the thread | 533 // OS data associated with the thread |
534 OSThread* _osthread; // Platform-specific thread information | 534 OSThread* _osthread; // Platform-specific thread information |
535 | 535 |
536 // Thread local resource area for temporary allocation within the VM | 536 // Thread local resource area for temporary allocation within the VM |
537 ResourceArea* _resource_area; | 537 ResourceArea* _resource_area; |
953 | 953 |
954 // JVMTI PopFrame support | 954 // JVMTI PopFrame support |
955 // This is set to popframe_pending to signal that top Java frame should be popped immediately | 955 // This is set to popframe_pending to signal that top Java frame should be popped immediately |
956 int _popframe_condition; | 956 int _popframe_condition; |
957 | 957 |
958 // If reallocation of scalar replaced objects fails, we throw OOM | |
959 // and during exception propagation, pop the top | |
960 // _frames_to_pop_failed_realloc frames, the ones that reference | |
961 // failed reallocations. | |
962 int _frames_to_pop_failed_realloc; | |
963 | |
958 #ifndef PRODUCT | 964 #ifndef PRODUCT |
959 int _jmp_ring_index; | 965 int _jmp_ring_index; |
960 struct { | 966 struct { |
961 // We use intptr_t instead of address so debugger doesn't try and display strings | 967 // We use intptr_t instead of address so debugger doesn't try and display strings |
962 intptr_t _target; | 968 intptr_t _target; |
1047 | 1053 |
1048 // Prepare thread and add to priority queue. If a priority is | 1054 // Prepare thread and add to priority queue. If a priority is |
1049 // not specified, use the priority of the thread object. Threads_lock | 1055 // not specified, use the priority of the thread object. Threads_lock |
1050 // must be held while this function is called. | 1056 // must be held while this function is called. |
1051 void prepare(jobject jni_thread, ThreadPriority prio=NoPriority); | 1057 void prepare(jobject jni_thread, ThreadPriority prio=NoPriority); |
1058 void prepare_ext(); | |
1052 | 1059 |
1053 void set_saved_exception_pc(address pc) { _saved_exception_pc = pc; } | 1060 void set_saved_exception_pc(address pc) { _saved_exception_pc = pc; } |
1054 address saved_exception_pc() { return _saved_exception_pc; } | 1061 address saved_exception_pc() { return _saved_exception_pc; } |
1055 | 1062 |
1056 | 1063 |
1076 JavaThreadState thread_state() const { return _thread_state; } | 1083 JavaThreadState thread_state() const { return _thread_state; } |
1077 void set_thread_state(JavaThreadState s) { _thread_state = s; } | 1084 void set_thread_state(JavaThreadState s) { _thread_state = s; } |
1078 #else | 1085 #else |
1079 // Use membars when accessing volatile _thread_state. See | 1086 // Use membars when accessing volatile _thread_state. See |
1080 // Threads::create_vm() for size checks. | 1087 // Threads::create_vm() for size checks. |
1081 JavaThreadState thread_state() const { | 1088 inline JavaThreadState thread_state() const; |
1082 return (JavaThreadState) OrderAccess::load_acquire((volatile jint*)&_thread_state); | 1089 inline void set_thread_state(JavaThreadState s); |
1083 } | |
1084 void set_thread_state(JavaThreadState s) { | |
1085 OrderAccess::release_store((volatile jint*)&_thread_state, (jint)s); | |
1086 } | |
1087 #endif | 1090 #endif |
1088 ThreadSafepointState *safepoint_state() const { return _safepoint_state; } | 1091 ThreadSafepointState *safepoint_state() const { return _safepoint_state; } |
1089 void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; } | 1092 void set_safepoint_state(ThreadSafepointState *state) { _safepoint_state = state; } |
1090 bool is_at_poll_safepoint() { return _safepoint_state->is_at_poll_safepoint(); } | 1093 bool is_at_poll_safepoint() { return _safepoint_state->is_at_poll_safepoint(); } |
1091 | 1094 |
1103 bool doing_unsafe_access() { return _doing_unsafe_access; } | 1106 bool doing_unsafe_access() { return _doing_unsafe_access; } |
1104 void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; } | 1107 void set_doing_unsafe_access(bool val) { _doing_unsafe_access = val; } |
1105 | 1108 |
1106 bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; } | 1109 bool do_not_unlock_if_synchronized() { return _do_not_unlock_if_synchronized; } |
1107 void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; } | 1110 void set_do_not_unlock_if_synchronized(bool val) { _do_not_unlock_if_synchronized = val; } |
1108 | |
1109 #if INCLUDE_NMT | |
1110 // native memory tracking | |
1111 inline MemRecorder* get_recorder() const { return (MemRecorder*)_recorder; } | |
1112 inline void set_recorder(MemRecorder* rc) { _recorder = rc; } | |
1113 | |
1114 private: | |
1115 // per-thread memory recorder | |
1116 MemRecorder* volatile _recorder; | |
1117 #endif // INCLUDE_NMT | |
1118 | 1111 |
1119 // Suspend/resume support for JavaThread | 1112 // Suspend/resume support for JavaThread |
1120 private: | 1113 private: |
1121 void set_ext_suspended() { set_suspend_flag (_ext_suspended); } | 1114 void set_ext_suspended() { set_suspend_flag (_ext_suspended); } |
1122 void clear_ext_suspended() { clear_suspend_flag(_ext_suspended); } | 1115 void clear_ext_suspended() { clear_suspend_flag(_ext_suspended); } |
1484 | 1477 |
1485 // Frame iteration; calls the function f for all frames on the stack | 1478 // Frame iteration; calls the function f for all frames on the stack |
1486 void frames_do(void f(frame*, const RegisterMap*)); | 1479 void frames_do(void f(frame*, const RegisterMap*)); |
1487 | 1480 |
1488 // Memory operations | 1481 // Memory operations |
1489 void oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf); | 1482 void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1490 | 1483 |
1491 // Sweeper operations | 1484 // Sweeper operations |
1492 void nmethods_do(CodeBlobClosure* cf); | 1485 void nmethods_do(CodeBlobClosure* cf); |
1493 | 1486 |
1494 // RedefineClasses Support | 1487 // RedefineClasses Support |
1566 ThreadProfiler* result = _thread_profiler; | 1559 ThreadProfiler* result = _thread_profiler; |
1567 _thread_profiler = tp; | 1560 _thread_profiler = tp; |
1568 return result; | 1561 return result; |
1569 } | 1562 } |
1570 | 1563 |
1571 // NMT (Native memory tracking) support. | |
1572 // This flag helps NMT to determine if this JavaThread will be blocked | |
1573 // at safepoint. If not, ThreadCritical is needed for writing memory records. | |
1574 // JavaThread is only safepoint visible when it is in Threads' thread list, | |
1575 // it is not visible until it is added to the list and becomes invisible | |
1576 // once it is removed from the list. | |
1577 public: | |
1578 bool is_safepoint_visible() const { return _safepoint_visible; } | |
1579 void set_safepoint_visible(bool visible) { _safepoint_visible = visible; } | |
1580 private: | |
1581 bool _safepoint_visible; | |
1582 | |
1583 // Static operations | |
1584 public: | 1564 public: |
1585 // Returns the running thread as a JavaThread | 1565 // Returns the running thread as a JavaThread |
1586 static inline JavaThread* current(); | 1566 static inline JavaThread* current(); |
1587 | 1567 |
1588 // Returns the active Java thread. Do not use this if you know you are calling | 1568 // Returns the active Java thread. Do not use this if you know you are calling |
1651 bool pop_frame_in_process(void) { return ((_popframe_condition & popframe_processing_bit) != 0); } | 1631 bool pop_frame_in_process(void) { return ((_popframe_condition & popframe_processing_bit) != 0); } |
1652 void set_pop_frame_in_process(void) { _popframe_condition |= popframe_processing_bit; } | 1632 void set_pop_frame_in_process(void) { _popframe_condition |= popframe_processing_bit; } |
1653 void clr_pop_frame_in_process(void) { _popframe_condition &= ~popframe_processing_bit; } | 1633 void clr_pop_frame_in_process(void) { _popframe_condition &= ~popframe_processing_bit; } |
1654 #endif | 1634 #endif |
1655 | 1635 |
1636 int frames_to_pop_failed_realloc() const { return _frames_to_pop_failed_realloc; } | |
1637 void set_frames_to_pop_failed_realloc(int nb) { _frames_to_pop_failed_realloc = nb; } | |
1638 void dec_frames_to_pop_failed_realloc() { _frames_to_pop_failed_realloc--; } | |
1639 | |
1656 private: | 1640 private: |
1657 // Saved incoming arguments to popped frame. | 1641 // Saved incoming arguments to popped frame. |
1658 // Used only when popped interpreted frame returns to deoptimized frame. | 1642 // Used only when popped interpreted frame returns to deoptimized frame. |
1659 void* _popframe_preserved_args; | 1643 void* _popframe_preserved_args; |
1660 int _popframe_preserved_args_size; | 1644 int _popframe_preserved_args_size; |
1815 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; } | 1799 void set_cached_monitor_info(GrowableArray<MonitorInfo*>* info) { _cached_monitor_info = info; } |
1816 | 1800 |
1817 // clearing/querying jni attach status | 1801 // clearing/querying jni attach status |
1818 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; } | 1802 bool is_attaching_via_jni() const { return _jni_attach_state == _attaching_via_jni; } |
1819 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; } | 1803 bool has_attached_via_jni() const { return is_attaching_via_jni() || _jni_attach_state == _attached_via_jni; } |
1820 void set_done_attaching_via_jni() { _jni_attach_state = _attached_via_jni; OrderAccess::fence(); } | 1804 inline void set_done_attaching_via_jni(); |
1821 private: | 1805 private: |
1822 // This field is used to determine if a thread has claimed | 1806 // This field is used to determine if a thread has claimed |
1823 // a par_id: it is UINT_MAX if the thread has not claimed a par_id; | 1807 // a par_id: it is UINT_MAX if the thread has not claimed a par_id; |
1824 // otherwise its value is the par_id that has been claimed. | 1808 // otherwise its value is the par_id that has been claimed. |
1825 uint _claimed_par_id; | 1809 uint _claimed_par_id; |
1922 } | 1906 } |
1923 | 1907 |
1924 // GC support | 1908 // GC support |
1925 // Apply "f->do_oop" to all root oops in "this". | 1909 // Apply "f->do_oop" to all root oops in "this". |
1926 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames | 1910 // Apply "cf->do_code_blob" (if !NULL) to all code blobs active in frames |
1927 void oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf); | 1911 void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1928 | 1912 |
1929 #ifndef PRODUCT | 1913 #ifndef PRODUCT |
1930 private: | 1914 private: |
1931 IdealGraphPrinter *_ideal_graph_printer; | 1915 IdealGraphPrinter *_ideal_graph_printer; |
1932 public: | 1916 public: |
1989 // Garbage collection | 1973 // Garbage collection |
1990 static void follow_other_roots(void f(oop*)); | 1974 static void follow_other_roots(void f(oop*)); |
1991 | 1975 |
1992 // Apply "f->do_oop" to all root oops in all threads. | 1976 // Apply "f->do_oop" to all root oops in all threads. |
1993 // This version may only be called by sequential code. | 1977 // This version may only be called by sequential code. |
1994 static void oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf); | 1978 static void oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1995 // This version may be called by sequential or parallel code. | 1979 // This version may be called by sequential or parallel code. |
1996 static void possibly_parallel_oops_do(OopClosure* f, CLDToOopClosure* cld_f, CodeBlobClosure* cf); | 1980 static void possibly_parallel_oops_do(OopClosure* f, CLDClosure* cld_f, CodeBlobClosure* cf); |
1997 // This creates a list of GCTasks, one per thread. | 1981 // This creates a list of GCTasks, one per thread. |
1998 static void create_thread_roots_tasks(GCTaskQueue* q); | 1982 static void create_thread_roots_tasks(GCTaskQueue* q); |
1999 // This creates a list of GCTasks, one per thread, for marking objects. | 1983 // This creates a list of GCTasks, one per thread, for marking objects. |
2000 static void create_thread_roots_marking_tasks(GCTaskQueue* q); | 1984 static void create_thread_roots_marking_tasks(GCTaskQueue* q); |
2001 | 1985 |
2044 // Number of non-daemon threads on the active threads list | 2028 // Number of non-daemon threads on the active threads list |
2045 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; } | 2029 static int number_of_non_daemon_threads() { return _number_of_non_daemon_threads; } |
2046 | 2030 |
2047 // Deoptimizes all frames tied to marked nmethods | 2031 // Deoptimizes all frames tied to marked nmethods |
2048 static void deoptimized_wrt_marked_nmethods(); | 2032 static void deoptimized_wrt_marked_nmethods(); |
2033 | |
2034 static JavaThread* find_java_thread_from_java_tid(jlong java_tid); | |
2049 | 2035 |
2050 }; | 2036 }; |
2051 | 2037 |
2052 | 2038 |
2053 // Thread iterator | 2039 // Thread iterator |