8202647: Add deduplicate_string function to CollectedHeap
authorstefank
Mon, 07 May 2018 14:57:25 +0200
changeset 50057 f945444fabc3
parent 50056 ca1f2d4d4ec8
child 50058 f7e564cacfbc
8202647: Add deduplicate_string function to CollectedHeap Reviewed-by: rehn, sjohanss
src/hotspot/share/classfile/stringTable.cpp
src/hotspot/share/gc/g1/g1CollectedHeap.cpp
src/hotspot/share/gc/g1/g1CollectedHeap.hpp
src/hotspot/share/gc/shared/collectedHeap.cpp
src/hotspot/share/gc/shared/collectedHeap.hpp
--- a/src/hotspot/share/classfile/stringTable.cpp	Mon May 07 14:57:23 2018 +0200
+++ b/src/hotspot/share/classfile/stringTable.cpp	Mon May 07 14:57:25 2018 +0200
@@ -28,12 +28,13 @@
 #include "classfile/javaClasses.inline.hpp"
 #include "classfile/stringTable.hpp"
 #include "classfile/systemDictionary.hpp"
-#include "gc/shared/collectedHeap.inline.hpp"
+#include "gc/shared/collectedHeap.hpp"
 #include "logging/log.hpp"
 #include "memory/allocation.inline.hpp"
 #include "memory/filemap.hpp"
 #include "memory/metaspaceShared.hpp"
 #include "memory/resourceArea.hpp"
+#include "memory/universe.hpp"
 #include "oops/access.inline.hpp"
 #include "oops/oop.inline.hpp"
 #include "oops/typeArrayOop.inline.hpp"
@@ -44,9 +45,6 @@
 #include "services/diagnosticCommand.hpp"
 #include "utilities/hashtable.inline.hpp"
 #include "utilities/macros.hpp"
-#if INCLUDE_G1GC
-#include "gc/g1/g1StringDedup.hpp"
-#endif
 
 // the number of buckets a thread claims
 const int ClaimChunkSize = 32;
@@ -260,14 +258,10 @@
     string = java_lang_String::create_from_unicode(name, len, CHECK_NULL);
   }
 
-#if INCLUDE_G1GC
-  if (G1StringDedup::is_enabled()) {
-    // Deduplicate the string before it is interned. Note that we should never
-    // deduplicate a string after it has been interned. Doing so will counteract
-    // compiler optimizations done on e.g. interned string literals.
-    G1StringDedup::deduplicate(string());
-  }
-#endif
+  // Deduplicate the string before it is interned. Note that we should never
+  // deduplicate a string after it has been interned. Doing so will counteract
+  // compiler optimizations done on e.g. interned string literals.
+  Universe::heap()->deduplicate_string(string());
 
   // Grab the StringTable_lock before getting the_table() because it could
   // change at safepoint.
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Mon May 07 14:57:23 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.cpp	Mon May 07 14:57:25 2018 +0200
@@ -2164,6 +2164,14 @@
   return ret_val;
 }
 
+void G1CollectedHeap::deduplicate_string(oop str) {
+  assert(java_lang_String::is_instance(str), "invariant");
+
+  if (G1StringDedup::is_enabled()) {
+    G1StringDedup::deduplicate(str);
+  }
+}
+
 void G1CollectedHeap::prepare_for_verify() {
   _verifier->prepare_for_verify();
 }
--- a/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Mon May 07 14:57:23 2018 +0200
+++ b/src/hotspot/share/gc/g1/g1CollectedHeap.hpp	Mon May 07 14:57:25 2018 +0200
@@ -1338,6 +1338,9 @@
   void redirty_logged_cards();
   // Verification
 
+  // Deduplicate the string
+  virtual void deduplicate_string(oop str);
+
   // Perform any cleanup actions necessary before allowing a verification.
   virtual void prepare_for_verify();
 
--- a/src/hotspot/share/gc/shared/collectedHeap.cpp	Mon May 07 14:57:23 2018 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.cpp	Mon May 07 14:57:25 2018 +0200
@@ -652,3 +652,7 @@
 void CollectedHeap::unpin_object(JavaThread* thread, oop obj) {
   ShouldNotReachHere();
 }
+
+void CollectedHeap::deduplicate_string(oop str) {
+  // Do nothing, unless overridden in subclass.
+}
--- a/src/hotspot/share/gc/shared/collectedHeap.hpp	Mon May 07 14:57:23 2018 +0200
+++ b/src/hotspot/share/gc/shared/collectedHeap.hpp	Mon May 07 14:57:25 2018 +0200
@@ -597,6 +597,9 @@
   virtual oop pin_object(JavaThread* thread, oop obj);
   virtual void unpin_object(JavaThread* thread, oop obj);
 
+  // Deduplicate the string, iff the GC supports string deduplication.
+  virtual void deduplicate_string(oop str);
+
   virtual bool is_oop(oop object) const;
 
   // Non product verification and debugging.