< prev index next >

src/hotspot/share/runtime/thread.hpp

Print this page
rev 60137 : 8227745: Enable Escape Analysis for Better Performance in the Presence of JVMTI Agents
Reviewed-by: mdoerr, goetz
rev 60138 : 8227745: delta webrev.5 -> webrev.6


  64 class ThreadStatistics;
  65 class ConcurrentLocksDump;
  66 class ParkEvent;
  67 class Parker;
  68 class MonitorInfo;
  69 
  70 class AbstractCompiler;
  71 class ciEnv;
  72 class CompileThread;
  73 class CompileLog;
  74 class CompileTask;
  75 class CompileQueue;
  76 class CompilerCounters;
  77 
  78 class vframeArray;
  79 class vframe;
  80 class javaVFrame;
  81 
  82 class DeoptResourceMark;
  83 class JvmtiDeferredUpdates;
  84 class jvmtiDeferredLocalVariableSet;
  85 
  86 class ThreadClosure;
  87 class ICRefillVerifier;
  88 class IdealGraphPrinter;
  89 
  90 class JVMCIEnv;
  91 class JVMCIPrimitiveArray;
  92 
  93 class Metadata;
  94 class ResourceArea;
  95 
  96 DEBUG_ONLY(class ResourceMark;)
  97 
  98 class WorkerThread;
  99 
 100 // Class hierarchy
 101 // - Thread
 102 //   - JavaThread
 103 //     - various subclasses eg CompilerThread, ServiceThread
 104 //   - NonJavaThread


 275   //
 276   // 2. It would be more natural if set_external_suspend() is private and
 277   // part of java_suspend(), but that probably would affect the suspend/query
 278   // performance. Need more investigation on this.
 279 
 280   // suspend/resume lock: used for self-suspend
 281   Monitor* _SR_lock;
 282 
 283  protected:
 284   enum SuspendFlags {
 285     // NOTE: avoid using the sign-bit as cc generates different test code
 286     //       when the sign-bit is used, and sometimes incorrectly - see CR 6398077
 287 
 288     _external_suspend       = 0x20000000U, // thread is asked to self suspend
 289     _ext_suspended          = 0x40000000U, // thread has self-suspended
 290 
 291     _has_async_exception    = 0x00000001U, // there is a pending async exception
 292     _critical_native_unlock = 0x00000002U, // Must call back to unlock JNI critical lock
 293 
 294     _trace_flag             = 0x00000004U, // call tracing backend
 295     _ea_obj_deopt           = 0x00000008U  // suspend for object reallocation and relocking for JVMTI agent
 296   };
 297 
 298   // various suspension related flags - atomically updated
 299   // overloaded for async exception checking in check_special_condition_for_native_trans.
 300   volatile uint32_t _suspend_flags;
 301 
 302  private:
 303   int _num_nested_signal;
 304 
 305   DEBUG_ONLY(bool _suspendible_thread;)
 306 
 307  public:
 308   void enter_signal_handler() { _num_nested_signal++; }
 309   void leave_signal_handler() { _num_nested_signal--; }
 310   bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
 311 
 312   // Determines if a heap allocation failure will be retried
 313   // (e.g., by deoptimizing and re-executing in the interpreter).
 314   // In this case, the failed allocation must raise
 315   // Universe::out_of_memory_error_retry() and omit side effects


 526   }
 527 
 528   Monitor* SR_lock() const                       { return _SR_lock; }
 529 
 530   bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
 531 
 532   inline void set_suspend_flag(SuspendFlags f);
 533   inline void clear_suspend_flag(SuspendFlags f);
 534 
 535   inline void set_has_async_exception();
 536   inline void clear_has_async_exception();
 537 
 538   bool do_critical_native_unlock() const { return (_suspend_flags & _critical_native_unlock) != 0; }
 539 
 540   inline void set_critical_native_unlock();
 541   inline void clear_critical_native_unlock();
 542 
 543   inline void set_trace_flag();
 544   inline void clear_trace_flag();
 545 
 546   inline void set_ea_obj_deopt_flag();
 547   inline void clear_ea_obj_deopt_flag();
 548 
 549   // Support for Unhandled Oop detection
 550   // Add the field for both, fastdebug and debug, builds to keep
 551   // Thread's fields layout the same.
 552   // Note: CHECK_UNHANDLED_OOPS is defined only for fastdebug build.
 553 #ifdef CHECK_UNHANDLED_OOPS
 554  private:
 555   UnhandledOops* _unhandled_oops;
 556 #elif defined(ASSERT)
 557  private:
 558   void* _unhandled_oops;
 559 #endif
 560 #ifdef CHECK_UNHANDLED_OOPS
 561  public:
 562   UnhandledOops* unhandled_oops() { return _unhandled_oops; }
 563   // Mark oop safe for gc.  It may be stack allocated but won't move.
 564   void allow_unhandled_oop(oop *op) {
 565     if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
 566   }
 567   // Clear oops at safepoint so crashes point to unhandled oop violator


 603   ThreadLocalAllocBuffer& tlab()                 { return _tlab; }
 604   void initialize_tlab() {
 605     if (UseTLAB) {
 606       tlab().initialize();
 607     }
 608   }
 609 
 610   jlong allocated_bytes()               { return _allocated_bytes; }
 611   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 612   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 613   inline jlong cooked_allocated_bytes();
 614 
 615   ThreadHeapSampler& heap_sampler()     { return _heap_sampler; }
 616 
 617   ThreadStatisticalInfo& statistical_info() { return _statistical_info; }
 618 
 619   JFR_ONLY(DEFINE_THREAD_LOCAL_ACCESSOR_JFR;)
 620 
 621   bool is_trace_suspend()               { return (_suspend_flags & _trace_flag) != 0; }
 622 
 623   bool is_ea_obj_deopt_suspend()        { return (_suspend_flags & _ea_obj_deopt) != 0; }
 624 
 625   // VM operation support
 626   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 627   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 628   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 629 
 630   // For tracking the heavyweight monitor the thread is pending on.
 631   ObjectMonitor* current_pending_monitor() {
 632     return _current_pending_monitor;
 633   }
 634   void set_current_pending_monitor(ObjectMonitor* monitor) {
 635     _current_pending_monitor = monitor;
 636   }
 637   void set_current_pending_monitor_is_from_java(bool from_java) {
 638     _current_pending_monitor_is_from_java = from_java;
 639   }
 640   bool current_pending_monitor_is_from_java() {
 641     return _current_pending_monitor_is_from_java;
 642   }
 643 


1429   // We cannot allow wait_for_ext_suspend_completion() to run forever or
1430   // we could hang. SuspendRetryCount and SuspendRetryDelay are normally
1431   // passed as the count and delay parameters. Experiments with specific
1432   // calls to wait_for_ext_suspend_completion() can be done by passing
1433   // other values in the code. Experiments with all calls can be done
1434   // via the appropriate -XX options.
1435   bool wait_for_ext_suspend_completion(int count, int delay, uint32_t *bits);
1436 
1437   // test for suspend - most (all?) of these should go away
1438   bool is_thread_fully_suspended(bool wait_for_suspend, uint32_t *bits);
1439 
1440   inline void set_external_suspend();
1441   inline void clear_external_suspend();
1442 
1443   bool is_external_suspend() const {
1444     return (_suspend_flags & _external_suspend) != 0;
1445   }
1446   // Whenever a thread transitions from native to vm/java it must suspend
1447   // if external|deopt suspend is present.
1448   bool is_suspend_after_native() const {
1449     return (_suspend_flags & (_external_suspend | _ea_obj_deopt JFR_ONLY(| _trace_flag))) != 0;
1450   }
1451 
1452   // external suspend request is completed
1453   bool is_ext_suspended() const {
1454     return (_suspend_flags & _ext_suspended) != 0;
1455   }
1456 
1457   bool is_external_suspend_with_lock() const {
1458     MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1459     return is_external_suspend();
1460   }
1461 
1462   // Special method to handle a pending external suspend request
1463   // when a suspend equivalent condition lifts.
1464   bool handle_special_suspend_equivalent_condition() {
1465     assert(is_suspend_equivalent(),
1466            "should only be called in a suspend equivalence condition");
1467     MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1468     bool ret = is_external_suspend();
1469     if (!ret) {


1502   bool has_async_condition() { return (_special_runtime_exit_condition != _no_async_condition); }
1503 
1504   void check_and_handle_async_exceptions(bool check_unsafe_error = true);
1505 
1506   // these next two are also used for self-suspension and async exception support
1507   void handle_special_runtime_exit_condition(bool check_asyncs = true);
1508 
1509   // Return true if JavaThread has an asynchronous condition or
1510   // if external suspension is requested.
1511   bool has_special_runtime_exit_condition() {
1512     // Because we don't use is_external_suspend_with_lock
1513     // it is possible that we won't see an asynchronous external suspend
1514     // request that has just gotten started, i.e., SR_lock grabbed but
1515     // _external_suspend field change either not made yet or not visible
1516     // yet. However, this is okay because the request is asynchronous and
1517     // we will see the new flag value the next time through. It's also
1518     // possible that the external suspend request is dropped after
1519     // we have checked is_external_suspend(), we will recheck its value
1520     // under SR_lock in java_suspend_self().
1521     return (_special_runtime_exit_condition != _no_async_condition) ||
1522             is_external_suspend() || is_trace_suspend() || is_ea_obj_deopt_suspend();
1523   }
1524 
1525   void set_pending_unsafe_access_error()          { _special_runtime_exit_condition = _async_unsafe_access_error; }
1526 
1527   inline void set_pending_async_exception(oop e);
1528 
1529   // Fast-locking support
1530   bool is_lock_owned(address adr) const;
1531 
1532   // Accessors for vframe array top
1533   // The linked list of vframe arrays are sorted on sp. This means when we
1534   // unpack the head must contain the vframe array to unpack.
1535   void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
1536   vframeArray* vframe_array_head() const         { return _vframe_array_head;  }
1537 
1538   // Side structure for deferring update of java frame locals until deopt occurs
1539   JvmtiDeferredUpdates* deferred_updates() const      { return _jvmti_deferred_updates; }
1540   void set_deferred_updates(JvmtiDeferredUpdates* du) { _jvmti_deferred_updates = du; }
1541 
1542   // These only really exist to make debugging deopt problems simpler




  64 class ThreadStatistics;
  65 class ConcurrentLocksDump;
  66 class ParkEvent;
  67 class Parker;
  68 class MonitorInfo;
  69 
  70 class AbstractCompiler;
  71 class ciEnv;
  72 class CompileThread;
  73 class CompileLog;
  74 class CompileTask;
  75 class CompileQueue;
  76 class CompilerCounters;
  77 
  78 class vframeArray;
  79 class vframe;
  80 class javaVFrame;
  81 
  82 class DeoptResourceMark;
  83 class JvmtiDeferredUpdates;

  84 
  85 class ThreadClosure;
  86 class ICRefillVerifier;
  87 class IdealGraphPrinter;
  88 
  89 class JVMCIEnv;
  90 class JVMCIPrimitiveArray;
  91 
  92 class Metadata;
  93 class ResourceArea;
  94 
  95 DEBUG_ONLY(class ResourceMark;)
  96 
  97 class WorkerThread;
  98 
  99 // Class hierarchy
 100 // - Thread
 101 //   - JavaThread
 102 //     - various subclasses eg CompilerThread, ServiceThread
 103 //   - NonJavaThread


 274   //
 275   // 2. It would be more natural if set_external_suspend() is private and
 276   // part of java_suspend(), but that probably would affect the suspend/query
 277   // performance. Need more investigation on this.
 278 
 279   // suspend/resume lock: used for self-suspend
 280   Monitor* _SR_lock;
 281 
 282  protected:
 283   enum SuspendFlags {
 284     // NOTE: avoid using the sign-bit as cc generates different test code
 285     //       when the sign-bit is used, and sometimes incorrectly - see CR 6398077
 286 
 287     _external_suspend       = 0x20000000U, // thread is asked to self suspend
 288     _ext_suspended          = 0x40000000U, // thread has self-suspended
 289 
 290     _has_async_exception    = 0x00000001U, // there is a pending async exception
 291     _critical_native_unlock = 0x00000002U, // Must call back to unlock JNI critical lock
 292 
 293     _trace_flag             = 0x00000004U, // call tracing backend
 294     _obj_deopt              = 0x00000008U  // suspend for object reallocation and relocking for JVMTI agent
 295   };
 296 
 297   // various suspension related flags - atomically updated
 298   // overloaded for async exception checking in check_special_condition_for_native_trans.
 299   volatile uint32_t _suspend_flags;
 300 
 301  private:
 302   int _num_nested_signal;
 303 
 304   DEBUG_ONLY(bool _suspendible_thread;)
 305 
 306  public:
 307   void enter_signal_handler() { _num_nested_signal++; }
 308   void leave_signal_handler() { _num_nested_signal--; }
 309   bool is_inside_signal_handler() const { return _num_nested_signal > 0; }
 310 
 311   // Determines if a heap allocation failure will be retried
 312   // (e.g., by deoptimizing and re-executing in the interpreter).
 313   // In this case, the failed allocation must raise
 314   // Universe::out_of_memory_error_retry() and omit side effects


 525   }
 526 
 527   Monitor* SR_lock() const                       { return _SR_lock; }
 528 
 529   bool has_async_exception() const { return (_suspend_flags & _has_async_exception) != 0; }
 530 
 531   inline void set_suspend_flag(SuspendFlags f);
 532   inline void clear_suspend_flag(SuspendFlags f);
 533 
 534   inline void set_has_async_exception();
 535   inline void clear_has_async_exception();
 536 
 537   bool do_critical_native_unlock() const { return (_suspend_flags & _critical_native_unlock) != 0; }
 538 
 539   inline void set_critical_native_unlock();
 540   inline void clear_critical_native_unlock();
 541 
 542   inline void set_trace_flag();
 543   inline void clear_trace_flag();
 544 
 545   inline void set_obj_deopt_flag();
 546   inline void clear_obj_deopt_flag();
 547 
 548   // Support for Unhandled Oop detection
 549   // Add the field for both, fastdebug and debug, builds to keep
 550   // Thread's fields layout the same.
 551   // Note: CHECK_UNHANDLED_OOPS is defined only for fastdebug build.
 552 #ifdef CHECK_UNHANDLED_OOPS
 553  private:
 554   UnhandledOops* _unhandled_oops;
 555 #elif defined(ASSERT)
 556  private:
 557   void* _unhandled_oops;
 558 #endif
 559 #ifdef CHECK_UNHANDLED_OOPS
 560  public:
 561   UnhandledOops* unhandled_oops() { return _unhandled_oops; }
 562   // Mark oop safe for gc.  It may be stack allocated but won't move.
 563   void allow_unhandled_oop(oop *op) {
 564     if (CheckUnhandledOops) unhandled_oops()->allow_unhandled_oop(op);
 565   }
 566   // Clear oops at safepoint so crashes point to unhandled oop violator


 602   ThreadLocalAllocBuffer& tlab()                 { return _tlab; }
 603   void initialize_tlab() {
 604     if (UseTLAB) {
 605       tlab().initialize();
 606     }
 607   }
 608 
 609   jlong allocated_bytes()               { return _allocated_bytes; }
 610   void set_allocated_bytes(jlong value) { _allocated_bytes = value; }
 611   void incr_allocated_bytes(jlong size) { _allocated_bytes += size; }
 612   inline jlong cooked_allocated_bytes();
 613 
 614   ThreadHeapSampler& heap_sampler()     { return _heap_sampler; }
 615 
 616   ThreadStatisticalInfo& statistical_info() { return _statistical_info; }
 617 
 618   JFR_ONLY(DEFINE_THREAD_LOCAL_ACCESSOR_JFR;)
 619 
 620   bool is_trace_suspend()               { return (_suspend_flags & _trace_flag) != 0; }
 621 
 622   bool is_obj_deopt_suspend()           { return (_suspend_flags & _obj_deopt) != 0; }
 623 
 624   // VM operation support
 625   int vm_operation_ticket()                      { return ++_vm_operation_started_count; }
 626   int vm_operation_completed_count()             { return _vm_operation_completed_count; }
 627   void increment_vm_operation_completed_count()  { _vm_operation_completed_count++; }
 628 
 629   // For tracking the heavyweight monitor the thread is pending on.
 630   ObjectMonitor* current_pending_monitor() {
 631     return _current_pending_monitor;
 632   }
 633   void set_current_pending_monitor(ObjectMonitor* monitor) {
 634     _current_pending_monitor = monitor;
 635   }
 636   void set_current_pending_monitor_is_from_java(bool from_java) {
 637     _current_pending_monitor_is_from_java = from_java;
 638   }
 639   bool current_pending_monitor_is_from_java() {
 640     return _current_pending_monitor_is_from_java;
 641   }
 642 


1428   // We cannot allow wait_for_ext_suspend_completion() to run forever or
1429   // we could hang. SuspendRetryCount and SuspendRetryDelay are normally
1430   // passed as the count and delay parameters. Experiments with specific
1431   // calls to wait_for_ext_suspend_completion() can be done by passing
1432   // other values in the code. Experiments with all calls can be done
1433   // via the appropriate -XX options.
1434   bool wait_for_ext_suspend_completion(int count, int delay, uint32_t *bits);
1435 
1436   // test for suspend - most (all?) of these should go away
1437   bool is_thread_fully_suspended(bool wait_for_suspend, uint32_t *bits);
1438 
1439   inline void set_external_suspend();
1440   inline void clear_external_suspend();
1441 
1442   bool is_external_suspend() const {
1443     return (_suspend_flags & _external_suspend) != 0;
1444   }
1445   // Whenever a thread transitions from native to vm/java it must suspend
1446   // if external|deopt suspend is present.
1447   bool is_suspend_after_native() const {
1448     return (_suspend_flags & (_external_suspend | _obj_deopt JFR_ONLY(| _trace_flag))) != 0;
1449   }
1450 
1451   // external suspend request is completed
1452   bool is_ext_suspended() const {
1453     return (_suspend_flags & _ext_suspended) != 0;
1454   }
1455 
1456   bool is_external_suspend_with_lock() const {
1457     MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1458     return is_external_suspend();
1459   }
1460 
1461   // Special method to handle a pending external suspend request
1462   // when a suspend equivalent condition lifts.
1463   bool handle_special_suspend_equivalent_condition() {
1464     assert(is_suspend_equivalent(),
1465            "should only be called in a suspend equivalence condition");
1466     MutexLocker ml(SR_lock(), Mutex::_no_safepoint_check_flag);
1467     bool ret = is_external_suspend();
1468     if (!ret) {


1501   bool has_async_condition() { return (_special_runtime_exit_condition != _no_async_condition); }
1502 
1503   void check_and_handle_async_exceptions(bool check_unsafe_error = true);
1504 
1505   // these next two are also used for self-suspension and async exception support
1506   void handle_special_runtime_exit_condition(bool check_asyncs = true);
1507 
1508   // Return true if JavaThread has an asynchronous condition or
1509   // if external suspension is requested.
1510   bool has_special_runtime_exit_condition() {
1511     // Because we don't use is_external_suspend_with_lock
1512     // it is possible that we won't see an asynchronous external suspend
1513     // request that has just gotten started, i.e., SR_lock grabbed but
1514     // _external_suspend field change either not made yet or not visible
1515     // yet. However, this is okay because the request is asynchronous and
1516     // we will see the new flag value the next time through. It's also
1517     // possible that the external suspend request is dropped after
1518     // we have checked is_external_suspend(), we will recheck its value
1519     // under SR_lock in java_suspend_self().
1520     return (_special_runtime_exit_condition != _no_async_condition) ||
1521             is_external_suspend() || is_trace_suspend() || is_obj_deopt_suspend();
1522   }
1523 
1524   void set_pending_unsafe_access_error()          { _special_runtime_exit_condition = _async_unsafe_access_error; }
1525 
1526   inline void set_pending_async_exception(oop e);
1527 
1528   // Fast-locking support
1529   bool is_lock_owned(address adr) const;
1530 
1531   // Accessors for vframe array top
1532   // The linked list of vframe arrays are sorted on sp. This means when we
1533   // unpack the head must contain the vframe array to unpack.
1534   void set_vframe_array_head(vframeArray* value) { _vframe_array_head = value; }
1535   vframeArray* vframe_array_head() const         { return _vframe_array_head;  }
1536 
1537   // Side structure for deferring update of java frame locals until deopt occurs
1538   JvmtiDeferredUpdates* deferred_updates() const      { return _jvmti_deferred_updates; }
1539   void set_deferred_updates(JvmtiDeferredUpdates* du) { _jvmti_deferred_updates = du; }
1540 
1541   // These only really exist to make debugging deopt problems simpler


< prev index next >