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