1.1 --- a/src/share/vm/gc_implementation/g1/g1HotCardCache.hpp Thu Sep 18 11:27:59 2014 +0200 1.2 +++ b/src/share/vm/gc_implementation/g1/g1HotCardCache.hpp Thu Jan 29 15:05:25 2015 +0100 1.3 @@ -1,5 +1,5 @@ 1.4 /* 1.5 - * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. 1.6 + * Copyright (c) 2013, 2015, Oracle and/or its affiliates. All rights reserved. 1.7 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 1.8 * 1.9 * This code is free software; you can redistribute it and/or modify it 1.10 @@ -54,21 +54,30 @@ 1.11 // code, increasing throughput. 1.12 1.13 class G1HotCardCache: public CHeapObj<mtGC> { 1.14 - G1CollectedHeap* _g1h; 1.15 + 1.16 + G1CollectedHeap* _g1h; 1.17 + 1.18 + bool _use_cache; 1.19 + 1.20 + G1CardCounts _card_counts; 1.21 1.22 // The card cache table 1.23 - jbyte** _hot_cache; 1.24 + jbyte** _hot_cache; 1.25 1.26 - int _hot_cache_size; 1.27 - int _n_hot; 1.28 - int _hot_cache_idx; 1.29 + size_t _hot_cache_size; 1.30 1.31 - int _hot_cache_par_chunk_size; 1.32 - volatile int _hot_cache_par_claimed_idx; 1.33 + int _hot_cache_par_chunk_size; 1.34 1.35 - bool _use_cache; 1.36 + // Avoids false sharing when concurrently updating _hot_cache_idx or 1.37 + // _hot_cache_par_claimed_idx. These are never updated at the same time 1.38 + // thus it's not necessary to separate them as well 1.39 + char _pad_before[DEFAULT_CACHE_LINE_SIZE]; 1.40 1.41 - G1CardCounts _card_counts; 1.42 + volatile size_t _hot_cache_idx; 1.43 + 1.44 + volatile size_t _hot_cache_par_claimed_idx; 1.45 + 1.46 + char _pad_after[DEFAULT_CACHE_LINE_SIZE]; 1.47 1.48 // The number of cached cards a thread claims when flushing the cache 1.49 static const int ClaimChunkSize = 32; 1.50 @@ -113,16 +122,25 @@ 1.51 void reset_hot_cache() { 1.52 assert(SafepointSynchronize::is_at_safepoint(), "Should be at a safepoint"); 1.53 assert(Thread::current()->is_VM_thread(), "Current thread should be the VMthread"); 1.54 - _hot_cache_idx = 0; _n_hot = 0; 1.55 + if (default_use_cache()) { 1.56 + reset_hot_cache_internal(); 1.57 + } 1.58 } 1.59 1.60 - bool hot_cache_is_empty() { return _n_hot == 0; } 1.61 - 1.62 // Zeros the values in the card counts table for entire committed heap 1.63 void reset_card_counts(); 1.64 1.65 // Zeros the values in the card counts table for the given region 1.66 void reset_card_counts(HeapRegion* hr); 1.67 + 1.68 + private: 1.69 + void reset_hot_cache_internal() { 1.70 + assert(_hot_cache != NULL, "Logic"); 1.71 + _hot_cache_idx = 0; 1.72 + for (size_t i = 0; i < _hot_cache_size; i++) { 1.73 + _hot_cache[i] = NULL; 1.74 + } 1.75 + } 1.76 }; 1.77 1.78 #endif // SHARE_VM_GC_IMPLEMENTATION_G1_G1HOTCARDCACHE_HPP