25 #ifndef SHARE_GC_G1_G1CONCURRENTREFINE_HPP |
25 #ifndef SHARE_GC_G1_G1CONCURRENTREFINE_HPP |
26 #define SHARE_GC_G1_G1CONCURRENTREFINE_HPP |
26 #define SHARE_GC_G1_G1CONCURRENTREFINE_HPP |
27 |
27 |
28 #include "memory/allocation.hpp" |
28 #include "memory/allocation.hpp" |
29 #include "utilities/globalDefinitions.hpp" |
29 #include "utilities/globalDefinitions.hpp" |
|
30 #include "utilities/ticks.hpp" |
30 |
31 |
31 // Forward decl |
32 // Forward decl |
32 class G1ConcurrentRefine; |
33 class G1ConcurrentRefine; |
33 class G1ConcurrentRefineThread; |
34 class G1ConcurrentRefineThread; |
34 class outputStream; |
35 class outputStream; |
58 void print_on(outputStream* st) const; |
59 void print_on(outputStream* st) const; |
59 void worker_threads_do(ThreadClosure* tc); |
60 void worker_threads_do(ThreadClosure* tc); |
60 void stop(); |
61 void stop(); |
61 }; |
62 }; |
62 |
63 |
63 // Controls refinement threads and their activation based on the number of completed |
64 // Controls refinement threads and their activation based on the number of |
64 // buffers currently available in the global dirty card queue. |
65 // cards currently available in the global dirty card queue. |
65 // Refinement threads pick work from the queue based on these thresholds. They are activated |
66 // Refinement threads obtain work from the queue (a buffer at a time) based |
66 // gradually based on the amount of work to do. |
67 // on these thresholds. They are activated gradually based on the amount of |
|
68 // work to do. |
67 // Refinement thread n activates thread n+1 if the instance of this class determines there |
69 // Refinement thread n activates thread n+1 if the instance of this class determines there |
68 // is enough work available. Threads deactivate themselves if the current amount of |
70 // is enough work available. Threads deactivate themselves if the current amount of |
69 // completed buffers falls below their individual threshold. |
71 // available cards falls below their individual threshold. |
70 class G1ConcurrentRefine : public CHeapObj<mtGC> { |
72 class G1ConcurrentRefine : public CHeapObj<mtGC> { |
71 G1ConcurrentRefineThreadControl _thread_control; |
73 G1ConcurrentRefineThreadControl _thread_control; |
72 /* |
74 /* |
73 * The value of the completed dirty card queue length falls into one of 3 zones: |
75 * The value of the completed dirty card queue length falls into one of 3 zones: |
74 * green, yellow, red. If the value is in [0, green) nothing is |
76 * green, yellow, red. If the value is in [0, green) nothing is |
75 * done, the buffers are left unprocessed to enable the caching effect of the |
77 * done, the buffered cards are left unprocessed to enable the caching effect of the |
76 * dirtied cards. In the yellow zone [green, yellow) the concurrent refinement |
78 * dirtied cards. In the yellow zone [green, yellow) the concurrent refinement |
77 * threads are gradually activated. In [yellow, red) all threads are |
79 * threads are gradually activated. In [yellow, red) all threads are |
78 * running. If the length becomes red (max queue length) the mutators start |
80 * running. If the length becomes red (max queue length) the mutators start |
79 * processing the buffers. |
81 * processing cards too. |
80 * |
82 * |
81 * There are some interesting cases (when G1UseAdaptiveConcRefinement |
83 * There are some interesting cases (when G1UseAdaptiveConcRefinement |
82 * is turned off): |
84 * is turned off): |
83 * 1) green = yellow = red = 0. In this case the mutator will process all |
85 * 1) green = yellow = red = 0. In this case the mutator will process all |
84 * buffers. Except for those that are created by the deferred updates |
86 * cards. Except for those that are created by the deferred updates |
85 * machinery during a collection. |
87 * machinery during a collection. |
86 * 2) green = 0. Means no caching. Can be a good way to minimize the |
88 * 2) green = 0. Means no caching. Can be a good way to minimize the |
87 * amount of time spent updating remembered sets during a collection. |
89 * amount of time spent updating remembered sets during a collection. |
88 */ |
90 */ |
89 size_t _green_zone; |
91 size_t _green_zone; |
95 size_t yellow_zone, |
97 size_t yellow_zone, |
96 size_t red_zone, |
98 size_t red_zone, |
97 size_t min_yellow_zone_size); |
99 size_t min_yellow_zone_size); |
98 |
100 |
99 // Update green/yellow/red zone values based on how well goals are being met. |
101 // Update green/yellow/red zone values based on how well goals are being met. |
100 void update_zones(double update_rs_time, |
102 void update_zones(double logged_cards_scan_time, |
101 size_t update_rs_processed_buffers, |
103 size_t processed_logged_cards, |
102 double goal_ms); |
104 double goal_ms); |
103 |
105 |
104 static uint worker_id_offset(); |
106 static uint worker_id_offset(); |
105 void maybe_activate_more_threads(uint worker_id, size_t num_cur_buffers); |
107 void maybe_activate_more_threads(uint worker_id, size_t num_cur_cards); |
106 |
108 |
107 jint initialize(); |
109 jint initialize(); |
108 public: |
110 public: |
109 ~G1ConcurrentRefine(); |
111 ~G1ConcurrentRefine(); |
110 |
112 |
113 static G1ConcurrentRefine* create(jint* ecode); |
115 static G1ConcurrentRefine* create(jint* ecode); |
114 |
116 |
115 void stop(); |
117 void stop(); |
116 |
118 |
117 // Adjust refinement thresholds based on work done during the pause and the goal time. |
119 // Adjust refinement thresholds based on work done during the pause and the goal time. |
118 void adjust(double update_rs_time, size_t update_rs_processed_buffers, double goal_ms); |
120 void adjust(double logged_cards_scan_time, size_t processed_logged_cards, double goal_ms); |
119 |
121 |
|
122 struct RefinementStats { |
|
123 Tickspan _time; |
|
124 size_t _cards; |
|
125 RefinementStats(Tickspan time, size_t cards) : _time(time), _cards(cards) {} |
|
126 }; |
|
127 |
|
128 RefinementStats total_refinement_stats() const; |
|
129 |
|
130 // Cards in the dirty card queue set. |
120 size_t activation_threshold(uint worker_id) const; |
131 size_t activation_threshold(uint worker_id) const; |
121 size_t deactivation_threshold(uint worker_id) const; |
132 size_t deactivation_threshold(uint worker_id) const; |
122 // Perform a single refinement step. Called by the refinement threads when woken up. |
133 |
123 bool do_refinement_step(uint worker_id); |
134 // Perform a single refinement step; called by the refinement |
|
135 // threads. Returns true if there was refinement work available. |
|
136 // Increments *total_refined_cards. |
|
137 bool do_refinement_step(uint worker_id, size_t* total_refined_cards); |
124 |
138 |
125 // Iterate over all concurrent refinement threads applying the given closure. |
139 // Iterate over all concurrent refinement threads applying the given closure. |
126 void threads_do(ThreadClosure *tc); |
140 void threads_do(ThreadClosure *tc); |
127 |
141 |
128 // Maximum number of refinement threads. |
142 // Maximum number of refinement threads. |
129 static uint max_num_threads(); |
143 static uint max_num_threads(); |
130 |
144 |
131 void print_threads_on(outputStream* st) const; |
145 void print_threads_on(outputStream* st) const; |
132 |
146 |
|
147 // Cards in the dirty card queue set. |
133 size_t green_zone() const { return _green_zone; } |
148 size_t green_zone() const { return _green_zone; } |
134 size_t yellow_zone() const { return _yellow_zone; } |
149 size_t yellow_zone() const { return _yellow_zone; } |
135 size_t red_zone() const { return _red_zone; } |
150 size_t red_zone() const { return _red_zone; } |
136 }; |
151 }; |
137 |
152 |