src/hotspot/share/gc/g1/g1StringDedup.cpp
changeset 50574 fa727a4d7934
parent 49722 a47d1e21b3f1
child 53536 482109fae02b
--- a/src/hotspot/share/gc/g1/g1StringDedup.cpp	Thu Jun 14 15:27:49 2018 -0700
+++ b/src/hotspot/share/gc/g1/g1StringDedup.cpp	Thu Jun 14 09:59:21 2018 -0400
@@ -29,26 +29,16 @@
 #include "gc/g1/g1StringDedup.hpp"
 #include "gc/g1/g1StringDedupQueue.hpp"
 #include "gc/g1/g1StringDedupStat.hpp"
-#include "gc/g1/g1StringDedupTable.hpp"
-#include "gc/g1/g1StringDedupThread.hpp"
+#include "gc/shared/stringdedup/stringDedup.inline.hpp"
+#include "gc/shared/stringdedup/stringDedupQueue.hpp"
+#include "gc/shared/stringdedup/stringDedupTable.hpp"
+#include "gc/shared/stringdedup/stringDedupThread.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "runtime/atomic.hpp"
 
-bool G1StringDedup::_enabled = false;
-
 void G1StringDedup::initialize() {
-  assert(UseG1GC, "String deduplication only available with G1");
-  if (UseStringDeduplication) {
-    _enabled = true;
-    G1StringDedupQueue::create();
-    G1StringDedupTable::create();
-    G1StringDedupThread::create();
-  }
-}
-
-void G1StringDedup::stop() {
-  assert(is_enabled(), "String deduplication not enabled");
-  G1StringDedupThread::thread()->stop();
+  assert(UseG1GC, "String deduplication available with G1");
+  StringDedup::initialize_impl<G1StringDedupQueue, G1StringDedupStat>();
 }
 
 bool G1StringDedup::is_candidate_from_mark(oop obj) {
@@ -99,12 +89,6 @@
   }
 }
 
-void G1StringDedup::deduplicate(oop java_string) {
-  assert(is_enabled(), "String deduplication not enabled");
-  G1StringDedupStat dummy; // Statistics from this path is never used
-  G1StringDedupTable::deduplicate(java_string, dummy);
-}
-
 void G1StringDedup::oops_do(OopClosure* keep_alive) {
   assert(is_enabled(), "String deduplication not enabled");
   unlink_or_oops_do(NULL, keep_alive, true /* allow_resize_and_rehash */);
@@ -112,8 +96,8 @@
 
 void G1StringDedup::parallel_unlink(G1StringDedupUnlinkOrOopsDoClosure* unlink, uint worker_id) {
   assert(is_enabled(), "String deduplication not enabled");
-  G1StringDedupQueue::unlink_or_oops_do(unlink);
-  G1StringDedupTable::unlink_or_oops_do(unlink, worker_id);
+  StringDedupQueue::unlink_or_oops_do(unlink);
+  StringDedupTable::unlink_or_oops_do(unlink, worker_id);
 }
 
 //
@@ -136,11 +120,11 @@
   virtual void work(uint worker_id) {
     {
       G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupQueueFixup, worker_id);
-      G1StringDedupQueue::unlink_or_oops_do(&_cl);
+      StringDedupQueue::unlink_or_oops_do(&_cl);
     }
     {
       G1GCParPhaseTimesTracker x(_phase_times, G1GCPhaseTimes::StringDedupTableFixup, worker_id);
-      G1StringDedupTable::unlink_or_oops_do(&_cl, worker_id);
+      StringDedupTable::unlink_or_oops_do(&_cl, worker_id);
     }
   }
 };
@@ -155,61 +139,3 @@
   G1CollectedHeap* g1h = G1CollectedHeap::heap();
   g1h->workers()->run_task(&task);
 }
-
-void G1StringDedup::threads_do(ThreadClosure* tc) {
-  assert(is_enabled(), "String deduplication not enabled");
-  tc->do_thread(G1StringDedupThread::thread());
-}
-
-void G1StringDedup::print_worker_threads_on(outputStream* st) {
-  assert(is_enabled(), "String deduplication not enabled");
-  G1StringDedupThread::thread()->print_on(st);
-  st->cr();
-}
-
-void G1StringDedup::verify() {
-  assert(is_enabled(), "String deduplication not enabled");
-  G1StringDedupQueue::verify();
-  G1StringDedupTable::verify();
-}
-
-G1StringDedupUnlinkOrOopsDoClosure::G1StringDedupUnlinkOrOopsDoClosure(BoolObjectClosure* is_alive,
-                                                                       OopClosure* keep_alive,
-                                                                       bool allow_resize_and_rehash) :
-  _is_alive(is_alive),
-  _keep_alive(keep_alive),
-  _resized_table(NULL),
-  _rehashed_table(NULL),
-  _next_queue(0),
-  _next_bucket(0) {
-  if (allow_resize_and_rehash) {
-    // If both resize and rehash is needed, only do resize. Rehash of
-    // the table will eventually happen if the situation persists.
-    _resized_table = G1StringDedupTable::prepare_resize();
-    if (!is_resizing()) {
-      _rehashed_table = G1StringDedupTable::prepare_rehash();
-    }
-  }
-}
-
-G1StringDedupUnlinkOrOopsDoClosure::~G1StringDedupUnlinkOrOopsDoClosure() {
-  assert(!is_resizing() || !is_rehashing(), "Can not both resize and rehash");
-  if (is_resizing()) {
-    G1StringDedupTable::finish_resize(_resized_table);
-  } else if (is_rehashing()) {
-    G1StringDedupTable::finish_rehash(_rehashed_table);
-  }
-}
-
-// Atomically claims the next available queue for exclusive access by
-// the current thread. Returns the queue number of the claimed queue.
-size_t G1StringDedupUnlinkOrOopsDoClosure::claim_queue() {
-  return Atomic::add((size_t)1, &_next_queue) - 1;
-}
-
-// Atomically claims the next available table partition for exclusive
-// access by the current thread. Returns the table bucket number where
-// the claimed partition starts.
-size_t G1StringDedupUnlinkOrOopsDoClosure::claim_table_partition(size_t partition_size) {
-  return Atomic::add(partition_size, &_next_bucket) - partition_size;
-}