src/share/vm/runtime/thread.cpp

Print this page
rev 4029 : 8001384: G1: assert(!is_null(v)) failed: narrow oop value can never be zero
Summary: Flush any deferred card mark before a Java thread exits.
Reviewed-by:


1483 }
1484 
1485 #ifndef SERIALGC
1486 SATBMarkQueueSet JavaThread::_satb_mark_queue_set;
1487 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
1488 #endif // !SERIALGC
1489 
1490 JavaThread::JavaThread(bool is_attaching_via_jni) :
1491   Thread()
1492 #ifndef SERIALGC
1493   , _satb_mark_queue(&_satb_mark_queue_set),
1494   _dirty_card_queue(&_dirty_card_queue_set)
1495 #endif // !SERIALGC
1496 {
1497   initialize();
1498   if (is_attaching_via_jni) {
1499     _jni_attach_state = _attaching_via_jni;
1500   } else {
1501     _jni_attach_state = _not_attaching_via_jni;
1502   }
1503   assert(_deferred_card_mark.is_empty(), "Default MemRegion ctor");
1504   _safepoint_visible = false;
1505 }
1506 
1507 bool JavaThread::reguard_stack(address cur_sp) {
1508   if (_stack_guard_state != stack_guard_yellow_disabled) {
1509     return true; // Stack already guarded or guard pages not needed.
1510   }
1511 
1512   if (register_stack_overflow()) {
1513     // For those architectures which have separate register and
1514     // memory stacks, we must check the register stack to see if
1515     // it has overflowed.
1516     return false;
1517   }
1518 
1519   // Java code never executes within the yellow zone: the latter is only
1520   // there to provoke an exception during stack banging.  If java code
1521   // is executing there, either StackShadowPages should be larger, or
1522   // some exception code in c1, c2 or the interpreter isn't unwinding
1523   // when it should.


1879     JNIHandleBlock::release_block(block);
1880   }
1881 
1882   if (free_handle_block() != NULL) {
1883     JNIHandleBlock* block = free_handle_block();
1884     set_free_handle_block(NULL);
1885     JNIHandleBlock::release_block(block);
1886   }
1887 
1888   // These have to be removed while this is still a valid thread.
1889   remove_stack_guard_pages();
1890 
1891   if (UseTLAB) {
1892     tlab().make_parsable(true);  // retire TLAB
1893   }
1894 
1895   if (JvmtiEnv::environments_might_exist()) {
1896     JvmtiExport::cleanup_thread(this);
1897   }
1898 






1899 #ifndef SERIALGC
1900   // We must flush G1-related buffers before removing a thread from
1901   // the list of active threads.
1902   if (UseG1GC) {
1903     flush_barrier_queues();
1904   }
1905 #endif
1906 
1907   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
1908   Threads::remove(this);
1909 }
1910 
1911 #ifndef SERIALGC
1912 // Flush G1-related queues.
1913 void JavaThread::flush_barrier_queues() {
1914   satb_mark_queue().flush();
1915   dirty_card_queue().flush();
1916 }
1917 
1918 void JavaThread::initialize_queues() {




1483 }
1484 
1485 #ifndef SERIALGC
1486 SATBMarkQueueSet JavaThread::_satb_mark_queue_set;
1487 DirtyCardQueueSet JavaThread::_dirty_card_queue_set;
1488 #endif // !SERIALGC
1489 
1490 JavaThread::JavaThread(bool is_attaching_via_jni) :
1491   Thread()
1492 #ifndef SERIALGC
1493   , _satb_mark_queue(&_satb_mark_queue_set),
1494   _dirty_card_queue(&_dirty_card_queue_set)
1495 #endif // !SERIALGC
1496 {
1497   initialize();
1498   if (is_attaching_via_jni) {
1499     _jni_attach_state = _attaching_via_jni;
1500   } else {
1501     _jni_attach_state = _not_attaching_via_jni;
1502   }
1503   assert(deferred_card_mark().is_empty(), "Default MemRegion ctor");
1504   _safepoint_visible = false;
1505 }
1506 
1507 bool JavaThread::reguard_stack(address cur_sp) {
1508   if (_stack_guard_state != stack_guard_yellow_disabled) {
1509     return true; // Stack already guarded or guard pages not needed.
1510   }
1511 
1512   if (register_stack_overflow()) {
1513     // For those architectures which have separate register and
1514     // memory stacks, we must check the register stack to see if
1515     // it has overflowed.
1516     return false;
1517   }
1518 
1519   // Java code never executes within the yellow zone: the latter is only
1520   // there to provoke an exception during stack banging.  If java code
1521   // is executing there, either StackShadowPages should be larger, or
1522   // some exception code in c1, c2 or the interpreter isn't unwinding
1523   // when it should.


1879     JNIHandleBlock::release_block(block);
1880   }
1881 
1882   if (free_handle_block() != NULL) {
1883     JNIHandleBlock* block = free_handle_block();
1884     set_free_handle_block(NULL);
1885     JNIHandleBlock::release_block(block);
1886   }
1887 
1888   // These have to be removed while this is still a valid thread.
1889   remove_stack_guard_pages();
1890 
1891   if (UseTLAB) {
1892     tlab().make_parsable(true);  // retire TLAB
1893   }
1894 
1895   if (JvmtiEnv::environments_might_exist()) {
1896     JvmtiExport::cleanup_thread(this);
1897   }
1898 
1899   // Flush any deferred card marks. Flushing may add cards to this
1900   // thread's G1 dirty card queue so we have to do this before
1901   // flushing the G1 barrier queues.
1902   Universe::heap()->flush_deferred_store_barrier(this);
1903   assert(deferred_card_mark().is_empty(), "Should have been flushed");
1904 
1905 #ifndef SERIALGC
1906   // We must flush G1-related buffers before removing a thread from
1907   // the list of active threads.
1908   if (UseG1GC) {
1909     flush_barrier_queues();
1910   }
1911 #endif
1912 
1913   // Remove from list of active threads list, and notify VM thread if we are the last non-daemon thread
1914   Threads::remove(this);
1915 }
1916 
1917 #ifndef SERIALGC
1918 // Flush G1-related queues.
1919 void JavaThread::flush_barrier_queues() {
1920   satb_mark_queue().flush();
1921   dirty_card_queue().flush();
1922 }
1923 
1924 void JavaThread::initialize_queues() {