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

Print this page


   1 /*
   2  * Copyright (c) 2001, 2010, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  77   enum SomePrivateConstants {
  78     epoch_bits           = 32,
  79     card_num_shift       = epoch_bits,
  80     epoch_mask           = AllBits,
  81     card_num_mask        = AllBits,
  82 
  83     // The initial cache size is approximately this fraction
  84     // of a maximal cache (i.e. the size needed for all cards
  85     // in the heap)
  86     InitialCacheFraction = 512
  87   };
  88 
  89   const static julong card_num_mask_in_place =
  90                         (julong) card_num_mask << card_num_shift;
  91 
  92   typedef struct {
  93     julong _value;      // |  card_num   |  epoch   |
  94   } CardEpochCacheEntry;
  95 
  96   julong make_epoch_entry(unsigned int card_num, unsigned int epoch) {
  97     assert(0 <= card_num && card_num < _max_n_card_counts, "Bounds");
  98     assert(0 <= epoch && epoch <= _n_periods, "must be");
  99 
 100     return ((julong) card_num << card_num_shift) | epoch;
 101   }
 102 
 103   unsigned int extract_epoch(julong v) {
 104     return (v & epoch_mask);
 105   }
 106 
 107   unsigned int extract_card_num(julong v) {
 108     return (v & card_num_mask_in_place) >> card_num_shift;
 109   }
 110 
 111   typedef struct {
 112     unsigned char _count;
 113     unsigned char _evict_count;
 114   } CardCountCacheEntry;
 115 
 116   CardCountCacheEntry* _card_counts;
 117   CardEpochCacheEntry* _card_epochs;
 118 
 119   // The current number of buckets in the card count cache
 120   unsigned _n_card_counts;
 121 
 122   // The max number of buckets required for the number of
 123   // cards for the entire reserved heap





 124   unsigned _max_n_card_counts;
 125 
 126   // Possible sizes of the cache: odd primes that roughly double in size.
 127   // (See jvmtiTagMap.cpp).
 128   static int _cc_cache_sizes[];




 129 
 130   // The index in _cc_cache_sizes corresponding to the size of
 131   // _card_counts.
 132   int _cache_size_index;
 133 
 134   bool _expand_card_counts;
 135 
 136   const jbyte* _ct_bot;
 137 
 138   jbyte**      _hot_cache;
 139   int          _hot_cache_size;
 140   int          _n_hot;
 141   int          _hot_cache_idx;
 142 
 143   int          _hot_cache_par_chunk_size;
 144   volatile int _hot_cache_par_claimed_idx;
 145 
 146   // Needed to workaround 6817995
 147   CardTableModRefBS* _ct_bs;
 148   G1CollectedHeap*   _g1h;
 149 
 150   // Expands the array that holds the card counts to the next size up
 151   void expand_card_count_cache();










 152 
 153   // hash a given key (index of card_ptr) with the specified size
 154   static unsigned int hash(size_t key, int size) {
 155     return (unsigned int) key % size;
 156   }
 157 
 158   // hash a given key (index of card_ptr)
 159   unsigned int hash(size_t key) {
 160     return hash(key, _n_card_counts);
 161   }
 162 
 163   unsigned ptr_2_card_num(jbyte* card_ptr) {
 164     return (unsigned) (card_ptr - _ct_bot);
 165   }
 166 
 167   jbyte* card_num_2_ptr(unsigned card_num) {
 168     return (jbyte*) (_ct_bot + card_num);
 169   }
 170 
 171   // Returns the count of this card after incrementing it.


   1 /*
   2  * Copyright (c) 2001, 2011, Oracle and/or its affiliates. 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *


  77   enum SomePrivateConstants {
  78     epoch_bits           = 32,
  79     card_num_shift       = epoch_bits,
  80     epoch_mask           = AllBits,
  81     card_num_mask        = AllBits,
  82 
  83     // The initial cache size is approximately this fraction
  84     // of a maximal cache (i.e. the size needed for all cards
  85     // in the heap)
  86     InitialCacheFraction = 512
  87   };
  88 
  89   const static julong card_num_mask_in_place =
  90                         (julong) card_num_mask << card_num_shift;
  91 
  92   typedef struct {
  93     julong _value;      // |  card_num   |  epoch   |
  94   } CardEpochCacheEntry;
  95 
  96   julong make_epoch_entry(unsigned int card_num, unsigned int epoch) {
  97     assert(0 <= card_num && card_num < _max_cards, "Bounds");
  98     assert(0 <= epoch && epoch <= _n_periods, "must be");
  99 
 100     return ((julong) card_num << card_num_shift) | epoch;
 101   }
 102 
 103   unsigned int extract_epoch(julong v) {
 104     return (v & epoch_mask);
 105   }
 106 
 107   unsigned int extract_card_num(julong v) {
 108     return (v & card_num_mask_in_place) >> card_num_shift;
 109   }
 110 
 111   typedef struct {
 112     unsigned char _count;
 113     unsigned char _evict_count;
 114   } CardCountCacheEntry;
 115 
 116   CardCountCacheEntry* _card_counts;
 117   CardEpochCacheEntry* _card_epochs;
 118 
 119   // The current number of buckets in the card count cache
 120   unsigned _n_card_counts;
 121 
 122   // The number of cards for the entire reserved heap
 123   unsigned _max_cards;
 124 
 125   // The max number of buckets for the card counts and epochs caches.
 126   // This is the maximum that the counts and epochs will grow to.
 127   // It is specified as a fraction or percentage of _max_cards using
 128   // G1MaxHotCardCountSizePercent (currently 50%).
 129   unsigned _max_n_card_counts;
 130 
 131   // Possible sizes of the cache: odd primes that roughly double in size.
 132   // (See jvmtiTagMap.cpp).
 133   enum {
 134     MAX_CC_CACHE_INDEX = 15    // maximum index into the cache size array.
 135   };
 136 
 137   static int _cc_cache_sizes[MAX_CC_CACHE_INDEX];
 138 
 139   // The index in _cc_cache_sizes corresponding to the size of
 140   // _card_counts.
 141   int _cache_size_index;
 142 
 143   bool _expand_card_counts;
 144 
 145   const jbyte* _ct_bot;
 146 
 147   jbyte**      _hot_cache;
 148   int          _hot_cache_size;
 149   int          _n_hot;
 150   int          _hot_cache_idx;
 151 
 152   int          _hot_cache_par_chunk_size;
 153   volatile int _hot_cache_par_claimed_idx;
 154 
 155   // Needed to workaround 6817995
 156   CardTableModRefBS* _ct_bs;
 157   G1CollectedHeap*   _g1h;
 158 
 159   // Helper routine for expand_card_count_cache().
 160   // The arrays used to hold the card counts and the epochs must have
 161   // a 1:1 correspondence. Hence they are allocated and freed together.
 162   // Returns true if the allocations of both the counts and epochs
 163   // were successful; false otherwise.
 164   bool allocate_card_count_cache(int n, CardCountCacheEntry** counts,
 165                                         CardEpochCacheEntry** epochs);
 166 
 167   // Expands the arrays that hold the card counts and epochs
 168   // to the cache size at index. Returns true if the expansion/
 169   // allocation was successful; false otherwise.
 170   bool expand_card_count_cache(int index);
 171 
 172   // hash a given key (index of card_ptr) with the specified size
 173   static unsigned int hash(size_t key, int size) {
 174     return (unsigned int) key % size;
 175   }
 176 
 177   // hash a given key (index of card_ptr)
 178   unsigned int hash(size_t key) {
 179     return hash(key, _n_card_counts);
 180   }
 181 
 182   unsigned ptr_2_card_num(jbyte* card_ptr) {
 183     return (unsigned) (card_ptr - _ct_bot);
 184   }
 185 
 186   jbyte* card_num_2_ptr(unsigned card_num) {
 187     return (jbyte*) (_ct_bot + card_num);
 188   }
 189 
 190   // Returns the count of this card after incrementing it.