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

changeset 7653
b6a1bf5222c5
parent 7652
ae374055ebce
child 7994
04ff2f6cd0eb
equal deleted inserted replaced
7652:ae374055ebce 7653:b6a1bf5222c5
1 /* 1 /*
2 * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 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 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
52 // 52 //
53 // This can significantly reduce the overhead of the write barrier 53 // This can significantly reduce the overhead of the write barrier
54 // code, increasing throughput. 54 // code, increasing throughput.
55 55
56 class G1HotCardCache: public CHeapObj<mtGC> { 56 class G1HotCardCache: public CHeapObj<mtGC> {
57 G1CollectedHeap* _g1h; 57
58 G1CollectedHeap* _g1h;
59
60 bool _use_cache;
61
62 G1CardCounts _card_counts;
58 63
59 // The card cache table 64 // The card cache table
60 jbyte** _hot_cache; 65 jbyte** _hot_cache;
61 66
62 int _hot_cache_size; 67 size_t _hot_cache_size;
63 int _n_hot;
64 int _hot_cache_idx;
65 68
66 int _hot_cache_par_chunk_size; 69 int _hot_cache_par_chunk_size;
67 volatile int _hot_cache_par_claimed_idx;
68 70
69 bool _use_cache; 71 // Avoids false sharing when concurrently updating _hot_cache_idx or
72 // _hot_cache_par_claimed_idx. These are never updated at the same time
73 // thus it's not necessary to separate them as well
74 char _pad_before[DEFAULT_CACHE_LINE_SIZE];
70 75
71 G1CardCounts _card_counts; 76 volatile size_t _hot_cache_idx;
77
78 volatile size_t _hot_cache_par_claimed_idx;
79
80 char _pad_after[DEFAULT_CACHE_LINE_SIZE];
72 81
73 // The number of cached cards a thread claims when flushing the cache 82 // The number of cached cards a thread claims when flushing the cache
74 static const int ClaimChunkSize = 32; 83 static const int ClaimChunkSize = 32;
75 84
76 bool default_use_cache() const { 85 bool default_use_cache() const {
111 120
112 // Resets the hot card cache and discards the entries. 121 // Resets the hot card cache and discards the entries.
113 void reset_hot_cache() { 122 void reset_hot_cache() {
114 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); 123 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint");
115 assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); 124 assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread");
116 _hot_cache_idx = 0; _n_hot = 0; 125 if (default_use_cache()) {
126 reset_hot_cache_internal();
127 }
117 } 128 }
118
119 bool hot_cache_is_empty() { return _n_hot == 0; }
120 129
121 // Zeros the values in the card counts table for entire committed heap 130 // Zeros the values in the card counts table for entire committed heap
122 void reset_card_counts(); 131 void reset_card_counts();
123 132
124 // Zeros the values in the card counts table for the given region 133 // Zeros the values in the card counts table for the given region
125 void reset_card_counts(HeapRegion* hr); 134 void reset_card_counts(HeapRegion* hr);
135
136 private:
137 void reset_hot_cache_internal() {
138 assert(_hot_cache != NULL, "Logic");
139 _hot_cache_idx = 0;
140 for (size_t i = 0; i < _hot_cache_size; i++) {
141 _hot_cache[i] = NULL;
142 }
143 }
126 }; 144 };
127 145
128 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP 146 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP

mercurial