annotate src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp @ 342:37f87013dfd8

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