src/hotspot/share/runtime/thread.cpp
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File open Sdiff src/hotspot/share/runtime

src/hotspot/share/runtime/thread.cpp

Print this page




1574 jlong* JavaThread::_jvmci_old_thread_counters;
1575 
1576 bool jvmci_counters_include(JavaThread* thread) {
1577   return !JVMCICountersExcludeCompiler || !thread->is_Compiler_thread();
1578 }
1579 
1580 void JavaThread::collect_counters(jlong* array, int length) {
1581   assert(length == JVMCICounterSize, "wrong value");
1582   for (int i = 0; i < length; i++) {
1583     array[i] = _jvmci_old_thread_counters[i];
1584   }
1585   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *tp = jtiwh.next(); ) {
1586     if (jvmci_counters_include(tp)) {
1587       for (int i = 0; i < length; i++) {
1588         array[i] += tp->_jvmci_counters[i];
1589       }
1590     }
1591   }
1592 }
1593 








































































1594 #endif // INCLUDE_JVMCI
1595 
1596 // A JavaThread is a normal Java thread
1597 
1598 void JavaThread::initialize() {
1599   // Initialize fields
1600 
1601   set_saved_exception_pc(NULL);
1602   set_threadObj(NULL);
1603   _anchor.clear();
1604   set_entry_point(NULL);
1605   set_jni_functions(jni_functions());
1606   set_callee_target(NULL);
1607   set_vm_result(NULL);
1608   set_vm_result_2(NULL);
1609   set_vframe_array_head(NULL);
1610   set_vframe_array_last(NULL);
1611   set_deferred_locals(NULL);
1612   set_deopt_mark(NULL);
1613   set_deopt_compiled_method(NULL);
1614   clear_must_deopt_id();
1615   set_monitor_chunks(NULL);
1616   _on_thread_list = false;
1617   set_thread_state(_thread_new);
1618   _terminated = _not_terminated;
1619   _array_for_gc = NULL;
1620   _suspend_equivalent = false;
1621   _in_deopt_handler = 0;
1622   _doing_unsafe_access = false;
1623   _stack_guard_state = stack_guard_unused;
1624 #if INCLUDE_JVMCI
1625   _pending_monitorenter = false;
1626   _pending_deoptimization = -1;
1627   _pending_failed_speculation = 0;
1628   _pending_transfer_to_interpreter = false;
1629   _in_retryable_allocation = false;
1630   _jvmci._alternate_call_target = NULL;
1631   assert(_jvmci._implicit_exception_pc == NULL, "must be");
1632   if (JVMCICounterSize > 0) {
1633     _jvmci_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtInternal);
1634     memset(_jvmci_counters, 0, sizeof(jlong) * JVMCICounterSize);
1635   } else {
1636     _jvmci_counters = NULL;


1637   }
1638 #endif // INCLUDE_JVMCI
1639   _reserved_stack_activation = NULL;  // stack base not known yet
1640   (void)const_cast<oop&>(_exception_oop = oop(NULL));
1641   _exception_pc  = 0;
1642   _exception_handler_pc = 0;
1643   _is_method_handle_return = 0;
1644   _jvmti_thread_state= NULL;
1645   _should_post_on_exceptions_flag = JNI_FALSE;
1646   _interp_only_mode    = 0;
1647   _special_runtime_exit_condition = _no_async_condition;
1648   _pending_async_exception = NULL;
1649   _thread_stat = NULL;
1650   _thread_stat = new ThreadStatistics();
1651   _blocked_on_compilation = false;
1652   _jni_active_critical = 0;
1653   _pending_jni_exception_check_fn = NULL;
1654   _do_not_unlock_if_synchronized = false;
1655   _cached_monitor_info = NULL;
1656   _parker = Parker::Allocate(this);


3752   // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
3753   // Must be before create_vm_init_agents()
3754   if (Arguments::init_libraries_at_startup()) {
3755     convert_vm_init_libraries_to_agents();
3756   }
3757 
3758   // Launch -agentlib/-agentpath and converted -Xrun agents
3759   if (Arguments::init_agents_at_startup()) {
3760     create_vm_init_agents();
3761   }
3762 
3763   // Initialize Threads state
3764   _number_of_threads = 0;
3765   _number_of_non_daemon_threads = 0;
3766 
3767   // Initialize global data structures and create system classes in heap
3768   vm_init_globals();
3769 
3770 #if INCLUDE_JVMCI
3771   if (JVMCICounterSize > 0) {
3772     JavaThread::_jvmci_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtInternal);
3773     memset(JavaThread::_jvmci_old_thread_counters, 0, sizeof(jlong) * JVMCICounterSize);
3774   } else {
3775     JavaThread::_jvmci_old_thread_counters = NULL;
3776   }
3777 #endif // INCLUDE_JVMCI
3778 
3779   // Attach the main thread to this os thread
3780   JavaThread* main_thread = new JavaThread();
3781   main_thread->set_thread_state(_thread_in_vm);
3782   main_thread->initialize_thread_current();
3783   // must do this before set_active_handles
3784   main_thread->record_stack_base_and_size();
3785   main_thread->register_thread_stack_with_NMT();
3786   main_thread->set_active_handles(JNIHandleBlock::allocate_block());
3787 
3788   if (!main_thread->set_as_starting_thread()) {
3789     vm_shutdown_during_initialization(
3790                                       "Failed necessary internal allocation. Out of swap space");
3791     main_thread->smr_delete();
3792     *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again




1574 jlong* JavaThread::_jvmci_old_thread_counters;
1575 
1576 bool jvmci_counters_include(JavaThread* thread) {
1577   return !JVMCICountersExcludeCompiler || !thread->is_Compiler_thread();
1578 }
1579 
1580 void JavaThread::collect_counters(jlong* array, int length) {
1581   assert(length == JVMCICounterSize, "wrong value");
1582   for (int i = 0; i < length; i++) {
1583     array[i] = _jvmci_old_thread_counters[i];
1584   }
1585   for (JavaThreadIteratorWithHandle jtiwh; JavaThread *tp = jtiwh.next(); ) {
1586     if (jvmci_counters_include(tp)) {
1587       for (int i = 0; i < length; i++) {
1588         array[i] += tp->_jvmci_counters[i];
1589       }
1590     }
1591   }
1592 }
1593 
1594 // Attempt to enlarge the array for per thread counters.
1595 jlong* resize_counters_array(jlong* old_counters, int current_size, int new_size) {
1596   jlong* new_counters = NEW_C_HEAP_ARRAY(jlong, new_size, mtJVMCI);
1597   if (new_counters == NULL) {
1598     return NULL;
1599   }
1600   if (old_counters == NULL) {
1601     old_counters = new_counters;
1602     memset(old_counters, 0, sizeof(jlong) * new_size);
1603   } else {
1604     for (int i = 0; i < MIN2((int) current_size, new_size); i++) {
1605       new_counters[i] = old_counters[i];
1606     }
1607     if (new_size > current_size) {
1608       memset(new_counters + current_size, 0, sizeof(jlong) * (new_size - current_size));
1609     }
1610     FREE_C_HEAP_ARRAY(jlong, old_counters);
1611   }
1612   return new_counters;
1613 }
1614 
1615 // Attempt to enlarge the array for per thread counters.
1616 bool JavaThread::resize_counters(int current_size, int new_size) {
1617   jlong* new_counters = resize_counters_array(_jvmci_counters, current_size, new_size);
1618   if (new_counters == NULL) {
1619     return false;
1620   } else {
1621     _jvmci_counters = new_counters;
1622     return true;
1623   }
1624 }
1625 
1626 class VM_JVMCIResizeCounters : public VM_Operation {
1627  private:
1628   int _new_size;
1629   bool _failed;
1630 
1631  public:
1632   VM_JVMCIResizeCounters(int new_size) : _new_size(new_size), _failed(false) { }
1633   VMOp_Type type()                  const        { return VMOp_JVMCIResizeCounters; }
1634   bool allow_nested_vm_operations() const        { return true; }
1635   void doit() {
1636     // Resize the old thread counters array
1637     jlong* new_counters = resize_counters_array(JavaThread::_jvmci_old_thread_counters, JVMCICounterSize, _new_size);
1638     if (new_counters == NULL) {
1639       _failed = true;
1640       return;
1641     } else {
1642       JavaThread::_jvmci_old_thread_counters = new_counters;
1643     }
1644 
1645     // Now resize each threads array
1646     for (JavaThreadIteratorWithHandle jtiwh; JavaThread *tp = jtiwh.next(); ) {
1647       if (!tp->resize_counters(JVMCICounterSize, _new_size)) {
1648         _failed = true;
1649         break;
1650       }
1651     }
1652     if (!_failed) {
1653       JVMCICounterSize = _new_size;
1654     }
1655   }
1656 
1657   bool failed() { return _failed; }
1658 };
1659 
1660 bool JavaThread::resize_all_jvmci_counters(int new_size) {
1661   VM_JVMCIResizeCounters op(new_size);
1662   VMThread::execute(&op);
1663   return !op.failed();
1664 }
1665 
1666 #endif // INCLUDE_JVMCI
1667 
1668 // A JavaThread is a normal Java thread
1669 
1670 void JavaThread::initialize() {
1671   // Initialize fields
1672 
1673   set_saved_exception_pc(NULL);
1674   set_threadObj(NULL);
1675   _anchor.clear();
1676   set_entry_point(NULL);
1677   set_jni_functions(jni_functions());
1678   set_callee_target(NULL);
1679   set_vm_result(NULL);
1680   set_vm_result_2(NULL);
1681   set_vframe_array_head(NULL);
1682   set_vframe_array_last(NULL);
1683   set_deferred_locals(NULL);
1684   set_deopt_mark(NULL);
1685   set_deopt_compiled_method(NULL);
1686   clear_must_deopt_id();
1687   set_monitor_chunks(NULL);
1688   _on_thread_list = false;
1689   set_thread_state(_thread_new);
1690   _terminated = _not_terminated;
1691   _array_for_gc = NULL;
1692   _suspend_equivalent = false;
1693   _in_deopt_handler = 0;
1694   _doing_unsafe_access = false;
1695   _stack_guard_state = stack_guard_unused;
1696 #if INCLUDE_JVMCI
1697   _pending_monitorenter = false;
1698   _pending_deoptimization = -1;
1699   _pending_failed_speculation = 0;
1700   _pending_transfer_to_interpreter = false;
1701   _in_retryable_allocation = false;
1702   _jvmci._alternate_call_target = NULL;
1703   assert(_jvmci._implicit_exception_pc == NULL, "must be");




1704   _jvmci_counters = NULL;
1705   if (JVMCICounterSize > 0) {
1706     resize_counters(0, (int) JVMCICounterSize);
1707   }
1708 #endif // INCLUDE_JVMCI
1709   _reserved_stack_activation = NULL;  // stack base not known yet
1710   (void)const_cast<oop&>(_exception_oop = oop(NULL));
1711   _exception_pc  = 0;
1712   _exception_handler_pc = 0;
1713   _is_method_handle_return = 0;
1714   _jvmti_thread_state= NULL;
1715   _should_post_on_exceptions_flag = JNI_FALSE;
1716   _interp_only_mode    = 0;
1717   _special_runtime_exit_condition = _no_async_condition;
1718   _pending_async_exception = NULL;
1719   _thread_stat = NULL;
1720   _thread_stat = new ThreadStatistics();
1721   _blocked_on_compilation = false;
1722   _jni_active_critical = 0;
1723   _pending_jni_exception_check_fn = NULL;
1724   _do_not_unlock_if_synchronized = false;
1725   _cached_monitor_info = NULL;
1726   _parker = Parker::Allocate(this);


3822   // Convert -Xrun to -agentlib: if there is no JVM_OnLoad
3823   // Must be before create_vm_init_agents()
3824   if (Arguments::init_libraries_at_startup()) {
3825     convert_vm_init_libraries_to_agents();
3826   }
3827 
3828   // Launch -agentlib/-agentpath and converted -Xrun agents
3829   if (Arguments::init_agents_at_startup()) {
3830     create_vm_init_agents();
3831   }
3832 
3833   // Initialize Threads state
3834   _number_of_threads = 0;
3835   _number_of_non_daemon_threads = 0;
3836 
3837   // Initialize global data structures and create system classes in heap
3838   vm_init_globals();
3839 
3840 #if INCLUDE_JVMCI
3841   if (JVMCICounterSize > 0) {
3842     JavaThread::_jvmci_old_thread_counters = NEW_C_HEAP_ARRAY(jlong, JVMCICounterSize, mtJVMCI);
3843     memset(JavaThread::_jvmci_old_thread_counters, 0, sizeof(jlong) * JVMCICounterSize);
3844   } else {
3845     JavaThread::_jvmci_old_thread_counters = NULL;
3846   }
3847 #endif // INCLUDE_JVMCI
3848 
3849   // Attach the main thread to this os thread
3850   JavaThread* main_thread = new JavaThread();
3851   main_thread->set_thread_state(_thread_in_vm);
3852   main_thread->initialize_thread_current();
3853   // must do this before set_active_handles
3854   main_thread->record_stack_base_and_size();
3855   main_thread->register_thread_stack_with_NMT();
3856   main_thread->set_active_handles(JNIHandleBlock::allocate_block());
3857 
3858   if (!main_thread->set_as_starting_thread()) {
3859     vm_shutdown_during_initialization(
3860                                       "Failed necessary internal allocation. Out of swap space");
3861     main_thread->smr_delete();
3862     *canTryAgain = false; // don't let caller call JNI_CreateJavaVM again


src/hotspot/share/runtime/thread.cpp
Index Unified diffs Context diffs Sdiffs Frames Patch New Old Previous File Next File