src/hotspot/share/gc/g1/g1BarrierSet.cpp
changeset 49752 93d84f667d12
parent 49751 c3a10df652c0
child 49906 4bb58f644e4e
--- a/src/hotspot/share/gc/g1/g1BarrierSet.cpp	Thu Apr 12 08:25:30 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1BarrierSet.cpp	Thu Apr 12 08:25:56 2018 +0200
@@ -27,6 +27,7 @@
 #include "gc/g1/g1BarrierSetAssembler.hpp"
 #include "gc/g1/g1CardTable.inline.hpp"
 #include "gc/g1/g1CollectedHeap.inline.hpp"
+#include "gc/g1/g1ThreadLocalData.hpp"
 #include "gc/g1/heapRegion.hpp"
 #include "gc/g1/satbMarkQueue.hpp"
 #include "logging/log.hpp"
@@ -52,8 +53,7 @@
   if (!_satb_mark_queue_set.is_active()) return;
   Thread* thr = Thread::current();
   if (thr->is_Java_thread()) {
-    JavaThread* jt = (JavaThread*)thr;
-    jt->satb_mark_queue().enqueue(pre_val);
+    G1ThreadLocalData::satb_mark_queue(thr).enqueue(pre_val);
   } else {
     MutexLockerEx x(Shared_SATB_Q_lock, Mutex::_no_safepoint_check_flag);
     _satb_mark_queue_set.shared_satb_queue()->enqueue(pre_val);
@@ -107,8 +107,7 @@
     *byte = G1CardTable::dirty_card_val();
     Thread* thr = Thread::current();
     if (thr->is_Java_thread()) {
-      JavaThread* jt = (JavaThread*)thr;
-      jt->dirty_card_queue().enqueue(byte);
+      G1ThreadLocalData::dirty_card_queue(thr).enqueue(byte);
     } else {
       MutexLockerEx x(Shared_DirtyCardQ_lock,
                       Mutex::_no_safepoint_check_flag);
@@ -131,14 +130,13 @@
     OrderAccess::storeload();
     // Enqueue if necessary.
     if (thr->is_Java_thread()) {
-      JavaThread* jt = (JavaThread*)thr;
       for (; byte <= last_byte; byte++) {
         if (*byte == G1CardTable::g1_young_card_val()) {
           continue;
         }
         if (*byte != G1CardTable::dirty_card_val()) {
           *byte = G1CardTable::dirty_card_val();
-          jt->dirty_card_queue().enqueue(byte);
+          G1ThreadLocalData::dirty_card_queue(thr).enqueue(byte);
         }
       }
     } else {
@@ -157,6 +155,16 @@
   }
 }
 
+void G1BarrierSet::on_thread_create(Thread* thread) {
+  // Create thread local data
+  G1ThreadLocalData::create(thread);
+}
+
+void G1BarrierSet::on_thread_destroy(Thread* thread) {
+  // Destroy thread local data
+  G1ThreadLocalData::destroy(thread);
+}
+
 void G1BarrierSet::on_thread_attach(JavaThread* thread) {
   // This method initializes the SATB and dirty card queues before a
   // JavaThread is added to the Java thread list. Right now, we don't
@@ -176,20 +184,20 @@
   // thread being added to the Java thread list (an example of this is
   // when the structure for the DestroyJavaVM thread is created).
   assert(!SafepointSynchronize::is_at_safepoint(), "We should not be at a safepoint");
-  assert(!thread->satb_mark_queue().is_active(), "SATB queue should not be active");
-  assert(thread->satb_mark_queue().is_empty(), "SATB queue should be empty");
-  assert(thread->dirty_card_queue().is_active(), "Dirty card queue should be active");
+  assert(!G1ThreadLocalData::satb_mark_queue(thread).is_active(), "SATB queue should not be active");
+  assert(G1ThreadLocalData::satb_mark_queue(thread).is_empty(), "SATB queue should be empty");
+  assert(G1ThreadLocalData::dirty_card_queue(thread).is_active(), "Dirty card queue should be active");
 
   // If we are creating the thread during a marking cycle, we should
   // set the active field of the SATB queue to true.
   if (_satb_mark_queue_set.is_active()) {
-    thread->satb_mark_queue().set_active(true);
+    G1ThreadLocalData::satb_mark_queue(thread).set_active(true);
   }
 }
 
 void G1BarrierSet::on_thread_detach(JavaThread* thread) {
   // Flush any deferred card marks, SATB buffers and dirty card queue buffers
   CardTableBarrierSet::on_thread_detach(thread);
-  thread->satb_mark_queue().flush();
-  thread->dirty_card_queue().flush();
+  G1ThreadLocalData::satb_mark_queue(thread).flush();
+  G1ThreadLocalData::dirty_card_queue(thread).flush();
 }