< prev index next >

src/share/vm/gc_implementation/g1/g1StringDedup.hpp

Print this page




  73 // Interned strings are a bit special. They are explicitly deduplicated just before
  74 // being inserted into the StringTable (to avoid counteracting C2 optimizations done
  75 // on string literals), then they also become deduplication candidates if they reach
  76 // the deduplication age threshold or are evacuated to an old heap region. The second
  77 // attempt to deduplicate such strings will be in vain, but we have no fast way of
  78 // filtering them out. This has not shown to be a problem, as the number of interned
  79 // strings is usually dwarfed by the number of normal (non-interned) strings.
  80 //
  81 // For additional information on string deduplication, please see JEP 192,
  82 // http://openjdk.java.net/jeps/192
  83 //
  84 
  85 #include "memory/allocation.hpp"
  86 #include "oops/oop.hpp"
  87 
  88 class OopClosure;
  89 class BoolObjectClosure;
  90 class ThreadClosure;
  91 class outputStream;
  92 class G1StringDedupTable;

  93 
  94 //
  95 // Main interface for interacting with string deduplication.
  96 //
  97 class G1StringDedup : public AllStatic {
  98 private:
  99   // Single state for checking if both G1 and string deduplication is enabled.
 100   static bool _enabled;
 101 
 102   // Candidate selection policies, returns true if the given object is
 103   // candidate for string deduplication.
 104   static bool is_candidate_from_mark(oop obj);
 105   static bool is_candidate_from_evacuation(bool from_young, bool to_young, oop obj);
 106 
 107 public:
 108   // Returns true if both G1 and string deduplication is enabled.
 109   static bool is_enabled() {
 110     return _enabled;
 111   }
 112 
 113   // Initialize string deduplication.
 114   static void initialize();
 115 
 116   // Stop the deduplication thread.
 117   static void stop();
 118 
 119   // Immediately deduplicates the given String object, bypassing the
 120   // the deduplication queue.
 121   static void deduplicate(oop java_string);
 122 
 123   // Enqueues a deduplication candidate for later processing by the deduplication
 124   // thread. Before enqueuing, these functions apply the appropriate candidate
 125   // selection policy to filters out non-candidates.
 126   static void enqueue_from_mark(oop java_string);
 127   static void enqueue_from_evacuation(bool from_young, bool to_young,
 128                                       unsigned int queue, oop java_string);
 129 
 130   static void oops_do(OopClosure* keep_alive);
 131   static void unlink(BoolObjectClosure* is_alive);
 132   static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive,
 133                                 bool allow_resize_and_rehash = true);
 134 
 135   static void threads_do(ThreadClosure* tc);
 136   static void print_worker_threads_on(outputStream* st);
 137   static void verify();
 138 };
 139 
 140 //
 141 // This closure encapsulates the state and the closures needed when scanning
 142 // the deduplication queue and table during the unlink_or_oops_do() operation.
 143 // A single instance of this closure is created and then shared by all worker
 144 // threads participating in the scan. The _next_queue and _next_bucket fields
 145 // provide a simple mechanism for GC workers to claim exclusive access to a
 146 // queue or a table partition.
 147 //
 148 class G1StringDedupUnlinkOrOopsDoClosure : public StackObj {
 149 private:
 150   BoolObjectClosure*  _is_alive;
 151   OopClosure*         _keep_alive;
 152   G1StringDedupTable* _resized_table;
 153   G1StringDedupTable* _rehashed_table;




  73 // Interned strings are a bit special. They are explicitly deduplicated just before
  74 // being inserted into the StringTable (to avoid counteracting C2 optimizations done
  75 // on string literals), then they also become deduplication candidates if they reach
  76 // the deduplication age threshold or are evacuated to an old heap region. The second
  77 // attempt to deduplicate such strings will be in vain, but we have no fast way of
  78 // filtering them out. This has not shown to be a problem, as the number of interned
  79 // strings is usually dwarfed by the number of normal (non-interned) strings.
  80 //
  81 // For additional information on string deduplication, please see JEP 192,
  82 // http://openjdk.java.net/jeps/192
  83 //
  84 
  85 #include "memory/allocation.hpp"
  86 #include "oops/oop.hpp"
  87 
  88 class OopClosure;
  89 class BoolObjectClosure;
  90 class ThreadClosure;
  91 class outputStream;
  92 class G1StringDedupTable;
  93 class G1GCPhaseTimes;
  94 
  95 //
  96 // Main interface for interacting with string deduplication.
  97 //
  98 class G1StringDedup : public AllStatic {
  99 private:
 100   // Single state for checking if both G1 and string deduplication is enabled.
 101   static bool _enabled;
 102 
 103   // Candidate selection policies, returns true if the given object is
 104   // candidate for string deduplication.
 105   static bool is_candidate_from_mark(oop obj);
 106   static bool is_candidate_from_evacuation(bool from_young, bool to_young, oop obj);
 107 
 108 public:
 109   // Returns true if both G1 and string deduplication is enabled.
 110   static bool is_enabled() {
 111     return _enabled;
 112   }
 113 
 114   // Initialize string deduplication.
 115   static void initialize();
 116 
 117   // Stop the deduplication thread.
 118   static void stop();
 119 
 120   // Immediately deduplicates the given String object, bypassing the
 121   // the deduplication queue.
 122   static void deduplicate(oop java_string);
 123 
 124   // Enqueues a deduplication candidate for later processing by the deduplication
 125   // thread. Before enqueuing, these functions apply the appropriate candidate
 126   // selection policy to filters out non-candidates.
 127   static void enqueue_from_mark(oop java_string);
 128   static void enqueue_from_evacuation(bool from_young, bool to_young,
 129                                       unsigned int queue, oop java_string);
 130 
 131   static void oops_do(OopClosure* keep_alive);
 132   static void unlink(BoolObjectClosure* is_alive);
 133   static void unlink_or_oops_do(BoolObjectClosure* is_alive, OopClosure* keep_alive,
 134                                 bool allow_resize_and_rehash, G1GCPhaseTimes* phase_times = NULL);
 135 
 136   static void threads_do(ThreadClosure* tc);
 137   static void print_worker_threads_on(outputStream* st);
 138   static void verify();
 139 };
 140 
 141 //
 142 // This closure encapsulates the state and the closures needed when scanning
 143 // the deduplication queue and table during the unlink_or_oops_do() operation.
 144 // A single instance of this closure is created and then shared by all worker
 145 // threads participating in the scan. The _next_queue and _next_bucket fields
 146 // provide a simple mechanism for GC workers to claim exclusive access to a
 147 // queue or a table partition.
 148 //
 149 class G1StringDedupUnlinkOrOopsDoClosure : public StackObj {
 150 private:
 151   BoolObjectClosure*  _is_alive;
 152   OopClosure*         _keep_alive;
 153   G1StringDedupTable* _resized_table;
 154   G1StringDedupTable* _rehashed_table;


< prev index next >