342
|
1 /*
|
|
2 * Copyright 2001-2007 Sun Microsystems, Inc. All Rights Reserved.
|
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
|
4 *
|
|
5 * This code is free software; you can redistribute it and/or modify it
|
|
6 * under the terms of the GNU General Public License version 2 only, as
|
|
7 * published by the Free Software Foundation.
|
|
8 *
|
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
|
13 * accompanied this code).
|
|
14 *
|
|
15 * You should have received a copy of the GNU General Public License version
|
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
18 *
|
|
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
|
|
20 * CA 95054 USA or visit www.sun.com if you need additional information or
|
|
21 * have any questions.
|
|
22 *
|
|
23 */
|
|
24
|
|
25 // Forward decl
|
|
26 class ConcurrentG1RefineThread;
|
|
27 class G1RemSet;
|
|
28
|
|
29 // What to do after a yield:
|
|
30 enum PostYieldAction {
|
|
31 PYA_continue, // Continue the traversal
|
|
32 PYA_restart, // Restart
|
|
33 PYA_cancel // It's been completed by somebody else: cancel.
|
|
34 };
|
|
35
|
|
36 class ConcurrentG1Refine {
|
|
37 ConcurrentG1RefineThread* _cg1rThread;
|
|
38
|
|
39 volatile jint _pya;
|
|
40 PostYieldAction _last_pya;
|
|
41
|
|
42 static bool _enabled; // Protected by G1ConcRefine_mon.
|
|
43 unsigned _traversals;
|
|
44
|
|
45 // Number of cards processed during last refinement traversal.
|
|
46 unsigned _first_traversal;
|
|
47 unsigned _last_cards_during;
|
|
48
|
|
49 // The cache for card refinement.
|
|
50 bool _use_cache;
|
|
51 bool _def_use_cache;
|
|
52 size_t _n_periods;
|
|
53 size_t _total_cards;
|
|
54 size_t _total_travs;
|
|
55
|
|
56 unsigned char* _card_counts;
|
|
57 unsigned _n_card_counts;
|
|
58 const jbyte* _ct_bot;
|
|
59 unsigned* _cur_card_count_histo;
|
|
60 unsigned* _cum_card_count_histo;
|
|
61 jbyte** _hot_cache;
|
|
62 int _hot_cache_size;
|
|
63 int _n_hot;
|
|
64 int _hot_cache_idx;
|
|
65
|
|
66 // Returns the count of this card after incrementing it.
|
|
67 int add_card_count(jbyte* card_ptr);
|
|
68
|
|
69 void print_card_count_histo_range(unsigned* histo, int from, int to,
|
|
70 float& cum_card_pct,
|
|
71 float& cum_travs_pct);
|
|
72 public:
|
|
73 ConcurrentG1Refine();
|
|
74 ~ConcurrentG1Refine();
|
|
75
|
|
76 void init(); // Accomplish some initialization that has to wait.
|
|
77
|
|
78 // Enabled Conc refinement, waking up thread if necessary.
|
|
79 void enable();
|
|
80
|
|
81 // Returns the number of traversals performed since this refiner was enabled.
|
|
82 unsigned disable();
|
|
83
|
|
84 // Requires G1ConcRefine_mon to be held.
|
|
85 bool enabled() { return _enabled; }
|
|
86
|
|
87 // Returns only when G1 concurrent refinement has been enabled.
|
|
88 void wait_for_ConcurrentG1Refine_enabled();
|
|
89
|
|
90 // Do one concurrent refinement pass over the card table. Returns "true"
|
|
91 // if heuristics determine that another pass should be done immediately.
|
|
92 bool refine();
|
|
93
|
|
94 // Indicate that an in-progress refinement pass should start over.
|
|
95 void set_pya_restart();
|
|
96 // Indicate that an in-progress refinement pass should quit.
|
|
97 void set_pya_cancel();
|
|
98
|
|
99 // Get the appropriate post-yield action. Also sets last_pya.
|
|
100 PostYieldAction get_pya();
|
|
101
|
|
102 // The last PYA read by "get_pya".
|
|
103 PostYieldAction get_last_pya();
|
|
104
|
|
105 bool do_traversal();
|
|
106
|
|
107 ConcurrentG1RefineThread* cg1rThread() { return _cg1rThread; }
|
|
108
|
|
109 // If this is the first entry for the slot, writes into the cache and
|
|
110 // returns NULL. If it causes an eviction, returns the evicted pointer.
|
|
111 // Otherwise, its a cache hit, and returns NULL.
|
|
112 jbyte* cache_insert(jbyte* card_ptr);
|
|
113
|
|
114 // Process the cached entries.
|
|
115 void clean_up_cache(int worker_i, G1RemSet* g1rs);
|
|
116
|
|
117 // Discard entries in the hot cache.
|
|
118 void clear_hot_cache() {
|
|
119 _hot_cache_idx = 0; _n_hot = 0;
|
|
120 }
|
|
121
|
|
122 bool hot_cache_is_empty() { return _n_hot == 0; }
|
|
123
|
|
124 bool use_cache() { return _use_cache; }
|
|
125 void set_use_cache(bool b) {
|
|
126 if (b) _use_cache = _def_use_cache;
|
|
127 else _use_cache = false;
|
|
128 }
|
|
129
|
|
130 void clear_and_record_card_counts();
|
|
131 void print_final_card_counts();
|
|
132 };
|