287 _ParkEvent = ParkEvent::Allocate (this) ;
288 _SleepEvent = ParkEvent::Allocate (this) ;
289 _MutexEvent = ParkEvent::Allocate (this) ;
290 _MuxEvent = ParkEvent::Allocate (this) ;
291
292 #ifdef CHECK_UNHANDLED_OOPS
293 if (CheckUnhandledOops) {
294 _unhandled_oops = new UnhandledOops(this);
295 }
296 #endif // CHECK_UNHANDLED_OOPS
297 #ifdef ASSERT
298 if (UseBiasedLocking) {
299 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
300 assert(this == _real_malloc_address ||
301 this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment),
302 "bug in forced alignment of thread objects");
303 }
304 #endif /* ASSERT */
305
306 _oom_during_evac = 0;
307 }
308
309 void Thread::set_oom_during_evac(bool oom) {
310 if (oom) {
311 _oom_during_evac |= 1;
312 } else {
313 _oom_during_evac &= ~1;
314 }
315 }
316
317 bool Thread::is_oom_during_evac() const {
318 return (_oom_during_evac & 1) == 1;
319 }
320
321 #ifdef ASSERT
322 void Thread::set_evac_allowed(bool evac_allowed) {
323 if (evac_allowed) {
324 _oom_during_evac |= 2;
325 } else {
326 _oom_during_evac &= ~2;
1519 set_thread_profiler(pp);
1520 }
1521
1522 // Setup safepoint state info for this thread
1523 ThreadSafepointState::create(this);
1524
1525 debug_only(_java_call_counter = 0);
1526
1527 // JVMTI PopFrame support
1528 _popframe_condition = popframe_inactive;
1529 _popframe_preserved_args = NULL;
1530 _popframe_preserved_args_size = 0;
1531 _frames_to_pop_failed_realloc = 0;
1532
1533 pd_initialize();
1534 }
1535
1536 #if INCLUDE_ALL_GCS
1537 SATBMarkQueueSet JavaThread::_satb_mark_queue_set;
1538 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
1539 char JavaThread::_gc_state_global = 0;
1540 #endif // INCLUDE_ALL_GCS
1541
1542 JavaThread::JavaThread(bool is_attaching_via_jni) :
1543 Thread()
1544 #if INCLUDE_ALL_GCS
1545 , _satb_mark_queue(&_satb_mark_queue_set),
1546 _dirty_card_queue(&_dirty_card_queue_set),
1547 _gc_state(_gc_state_global)
1548 #endif // INCLUDE_ALL_GCS
1549 {
1550 initialize();
1551 if (is_attaching_via_jni) {
1552 _jni_attach_state = _attaching_via_jni;
1553 } else {
1554 _jni_attach_state = _not_attaching_via_jni;
1555 }
1556 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1557 }
1558
1559 bool JavaThread::reguard_stack(address cur_sp) {
1560 if (_stack_guard_state != stack_guard_yellow_disabled) {
1561 return true; // Stack already guarded or guard pages not needed.
1562 }
1563
1564 if (register_stack_overflow()) {
1565 // For those architectures which have separate register and
1566 // memory stacks, we must check the register stack to see if
1567 // it has overflowed.
1584 }
1585
1586
1587 void JavaThread::block_if_vm_exited() {
1588 if (_terminated == _vm_exited) {
1589 // _vm_exited is set at safepoint, and Threads_lock is never released
1590 // we will block here forever
1591 Threads_lock->lock_without_safepoint_check();
1592 ShouldNotReachHere();
1593 }
1594 }
1595
1596
1597 // Remove this ifdef when C1 is ported to the compiler interface.
1598 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1599
1600 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
1601 Thread()
1602 #if INCLUDE_ALL_GCS
1603 , _satb_mark_queue(&_satb_mark_queue_set),
1604 _dirty_card_queue(&_dirty_card_queue_set),
1605 _gc_state(_gc_state_global)
1606 #endif // INCLUDE_ALL_GCS
1607 {
1608 if (TraceThreadEvents) {
1609 tty->print_cr("creating thread %p", this);
1610 }
1611 initialize();
1612 _jni_attach_state = _not_attaching_via_jni;
1613 set_entry_point(entry_point);
1614 // Create the native thread itself.
1615 // %note runtime_23
1616 os::ThreadType thr_type = os::java_thread;
1617 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread :
1618 os::java_thread;
1619 os::create_thread(this, thr_type, stack_sz);
1620 // The _osthread may be NULL here because we ran out of memory (too many threads active).
1621 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller
1622 // may hold a lock and all locks must be unlocked before throwing the exception (throwing
1623 // the exception consists of creating the exception object & initializing it, initialization
1624 // will leave the VM via a JavaCall and then all locks must be unlocked).
1625 //
1990 satb_queue.set_active(true);
1991 }
1992
1993 DirtyCardQueue& dirty_queue = dirty_card_queue();
1994 // The dirty card queue should have been constructed with its
1995 // active field set to true.
1996 assert(dirty_queue.is_active(), "dirty card queue should be active");
1997
1998 _gc_state = _gc_state_global;
1999 }
2000
2001 void JavaThread::set_gc_state(char in_prog) {
2002 _gc_state = in_prog;
2003 }
2004
2005 void JavaThread::set_gc_state_all_threads(char in_prog) {
2006 assert_locked_or_safepoint(Threads_lock);
2007 _gc_state_global = in_prog;
2008 for (JavaThread* t = Threads::first(); t != NULL; t = t->next()) {
2009 t->set_gc_state(in_prog);
2010 }
2011 }
2012 #endif // INCLUDE_ALL_GCS
2013
2014 void JavaThread::cleanup_failed_attach_current_thread() {
2015 if (get_thread_profiler() != NULL) {
2016 get_thread_profiler()->disengage();
2017 ResourceMark rm;
2018 get_thread_profiler()->print(get_thread_name());
2019 }
2020
2021 if (active_handles() != NULL) {
2022 JNIHandleBlock* block = active_handles();
2023 set_active_handles(NULL);
2024 JNIHandleBlock::release_block(block);
2025 }
2026
2027 if (free_handle_block() != NULL) {
2028 JNIHandleBlock* block = free_handle_block();
2029 set_free_handle_block(NULL);
|
287 _ParkEvent = ParkEvent::Allocate (this) ;
288 _SleepEvent = ParkEvent::Allocate (this) ;
289 _MutexEvent = ParkEvent::Allocate (this) ;
290 _MuxEvent = ParkEvent::Allocate (this) ;
291
292 #ifdef CHECK_UNHANDLED_OOPS
293 if (CheckUnhandledOops) {
294 _unhandled_oops = new UnhandledOops(this);
295 }
296 #endif // CHECK_UNHANDLED_OOPS
297 #ifdef ASSERT
298 if (UseBiasedLocking) {
299 assert((((uintptr_t) this) & (markOopDesc::biased_lock_alignment - 1)) == 0, "forced alignment of thread object failed");
300 assert(this == _real_malloc_address ||
301 this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment),
302 "bug in forced alignment of thread objects");
303 }
304 #endif /* ASSERT */
305
306 _oom_during_evac = 0;
307 #if INCLUDE_ALL_GCS
308 _gc_state = _gc_state_global;
309 _worker_id = (uint)(-1); // Actually, ShenandoahWorkerSession::INVALID_WORKER_ID, but avoid dependencies.
310 _force_satb_flush = false;
311 #endif
312 }
313
314 void Thread::set_oom_during_evac(bool oom) {
315 if (oom) {
316 _oom_during_evac |= 1;
317 } else {
318 _oom_during_evac &= ~1;
319 }
320 }
321
322 bool Thread::is_oom_during_evac() const {
323 return (_oom_during_evac & 1) == 1;
324 }
325
326 #ifdef ASSERT
327 void Thread::set_evac_allowed(bool evac_allowed) {
328 if (evac_allowed) {
329 _oom_during_evac |= 2;
330 } else {
331 _oom_during_evac &= ~2;
1524 set_thread_profiler(pp);
1525 }
1526
1527 // Setup safepoint state info for this thread
1528 ThreadSafepointState::create(this);
1529
1530 debug_only(_java_call_counter = 0);
1531
1532 // JVMTI PopFrame support
1533 _popframe_condition = popframe_inactive;
1534 _popframe_preserved_args = NULL;
1535 _popframe_preserved_args_size = 0;
1536 _frames_to_pop_failed_realloc = 0;
1537
1538 pd_initialize();
1539 }
1540
1541 #if INCLUDE_ALL_GCS
1542 SATBMarkQueueSet JavaThread::_satb_mark_queue_set;
1543 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
1544 char Thread::_gc_state_global = 0;
1545 #endif // INCLUDE_ALL_GCS
1546
1547 JavaThread::JavaThread(bool is_attaching_via_jni) :
1548 Thread()
1549 #if INCLUDE_ALL_GCS
1550 , _satb_mark_queue(&_satb_mark_queue_set),
1551 _dirty_card_queue(&_dirty_card_queue_set)
1552 #endif // INCLUDE_ALL_GCS
1553 {
1554 initialize();
1555 if (is_attaching_via_jni) {
1556 _jni_attach_state = _attaching_via_jni;
1557 } else {
1558 _jni_attach_state = _not_attaching_via_jni;
1559 }
1560 assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1561 }
1562
1563 bool JavaThread::reguard_stack(address cur_sp) {
1564 if (_stack_guard_state != stack_guard_yellow_disabled) {
1565 return true; // Stack already guarded or guard pages not needed.
1566 }
1567
1568 if (register_stack_overflow()) {
1569 // For those architectures which have separate register and
1570 // memory stacks, we must check the register stack to see if
1571 // it has overflowed.
1588 }
1589
1590
1591 void JavaThread::block_if_vm_exited() {
1592 if (_terminated == _vm_exited) {
1593 // _vm_exited is set at safepoint, and Threads_lock is never released
1594 // we will block here forever
1595 Threads_lock->lock_without_safepoint_check();
1596 ShouldNotReachHere();
1597 }
1598 }
1599
1600
1601 // Remove this ifdef when C1 is ported to the compiler interface.
1602 static void compiler_thread_entry(JavaThread* thread, TRAPS);
1603
1604 JavaThread::JavaThread(ThreadFunction entry_point, size_t stack_sz) :
1605 Thread()
1606 #if INCLUDE_ALL_GCS
1607 , _satb_mark_queue(&_satb_mark_queue_set),
1608 _dirty_card_queue(&_dirty_card_queue_set)
1609 #endif // INCLUDE_ALL_GCS
1610 {
1611 if (TraceThreadEvents) {
1612 tty->print_cr("creating thread %p", this);
1613 }
1614 initialize();
1615 _jni_attach_state = _not_attaching_via_jni;
1616 set_entry_point(entry_point);
1617 // Create the native thread itself.
1618 // %note runtime_23
1619 os::ThreadType thr_type = os::java_thread;
1620 thr_type = entry_point == &compiler_thread_entry ? os::compiler_thread :
1621 os::java_thread;
1622 os::create_thread(this, thr_type, stack_sz);
1623 // The _osthread may be NULL here because we ran out of memory (too many threads active).
1624 // We need to throw and OutOfMemoryError - however we cannot do this here because the caller
1625 // may hold a lock and all locks must be unlocked before throwing the exception (throwing
1626 // the exception consists of creating the exception object & initializing it, initialization
1627 // will leave the VM via a JavaCall and then all locks must be unlocked).
1628 //
1993 satb_queue.set_active(true);
1994 }
1995
1996 DirtyCardQueue& dirty_queue = dirty_card_queue();
1997 // The dirty card queue should have been constructed with its
1998 // active field set to true.
1999 assert(dirty_queue.is_active(), "dirty card queue should be active");
2000
2001 _gc_state = _gc_state_global;
2002 }
2003
2004 void JavaThread::set_gc_state(char in_prog) {
2005 _gc_state = in_prog;
2006 }
2007
2008 void JavaThread::set_gc_state_all_threads(char in_prog) {
2009 assert_locked_or_safepoint(Threads_lock);
2010 _gc_state_global = in_prog;
2011 for (JavaThread* t = Threads::first(); t != NULL; t = t->next()) {
2012 t->set_gc_state(in_prog);
2013 }
2014 }
2015
2016 void JavaThread::set_force_satb_flush_all_threads(bool value) {
2017 assert_locked_or_safepoint(Threads_lock);
2018 for (JavaThread* t = Threads::first(); t != NULL; t = t->next()) {
2019 t->set_force_satb_flush(value);
2020 }
2021 }
2022 #endif // INCLUDE_ALL_GCS
2023
2024 void JavaThread::cleanup_failed_attach_current_thread() {
2025 if (get_thread_profiler() != NULL) {
2026 get_thread_profiler()->disengage();
2027 ResourceMark rm;
2028 get_thread_profiler()->print(get_thread_name());
2029 }
2030
2031 if (active_handles() != NULL) {
2032 JNIHandleBlock* block = active_handles();
2033 set_active_handles(NULL);
2034 JNIHandleBlock::release_block(block);
2035 }
2036
2037 if (free_handle_block() != NULL) {
2038 JNIHandleBlock* block = free_handle_block();
2039 set_free_handle_block(NULL);
|