annotate src/share/vm/gc_implementation/g1/concurrentG1Refine.hpp @ 889:15c5903cf9e1

6865703: G1: Parallelize hot card cache cleanup Summary: Have the GC worker threads clear the hot card cache in parallel by having each worker thread claim a chunk of the card cache and process the cards in that chunk. The size of the chunks that each thread will claim is determined at VM initialization from the size of the card cache and the number of worker threads. Reviewed-by: jmasa, tonyp
author johnc
date Mon, 03 Aug 2009 12:59:30 -0700
parents 215f81b4d9b3
children 6cb8e9df7174
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
1 /*
579
0fbdb4381b99 6814575: Update copyright year
xdono
parents: 549
diff changeset
2 * Copyright 2001-2009 Sun Microsystems, Inc. All Rights Reserved.
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
4 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
7 * published by the Free Software Foundation.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
8 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
13 * accompanied this code).
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
14 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
18 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
19 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
20 * CA 95054 USA or visit www.sun.com if you need additional information or
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
21 * have any questions.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
22 *
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
23 */
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
24
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
25 // Forward decl
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
26 class ConcurrentG1RefineThread;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
27 class G1RemSet;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
28
549
fe3d7c11b4b7 6700941: G1: allocation spec missing for some G1 classes
apetrusenko
parents: 342
diff changeset
29 class ConcurrentG1Refine: public CHeapObj {
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 579
diff changeset
30 ConcurrentG1RefineThread** _threads;
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 579
diff changeset
31 int _n_threads;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
32 // The cache for card refinement.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
33 bool _use_cache;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
34 bool _def_use_cache;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
35 size_t _n_periods;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
36 size_t _total_cards;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
37 size_t _total_travs;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
38
889
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
39 unsigned char* _card_counts;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
40 unsigned _n_card_counts;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
41 const jbyte* _ct_bot;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
42 unsigned* _cur_card_count_histo;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
43 unsigned* _cum_card_count_histo;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
44
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
45 jbyte** _hot_cache;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
46 int _hot_cache_size;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
47 int _n_hot;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
48 int _hot_cache_idx;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
49
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
50 int _hot_cache_par_chunk_size;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
51 volatile int _hot_cache_par_claimed_idx;
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
52
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
53 // Returns the count of this card after incrementing it.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
54 int add_card_count(jbyte* card_ptr);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
55
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
56 void print_card_count_histo_range(unsigned* histo, int from, int to,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
57 float& cum_card_pct,
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
58 float& cum_travs_pct);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
59 public:
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
60 ConcurrentG1Refine();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
61 ~ConcurrentG1Refine();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
62
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
63 void init(); // Accomplish some initialization that has to wait.
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 579
diff changeset
64 void stop();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
65
794
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 579
diff changeset
66 // Iterate over the conc refine threads
315a5d70b295 6484957: G1: parallel concurrent refinement
iveresov
parents: 579
diff changeset
67 void threads_do(ThreadClosure *tc);
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
68
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
69 // If this is the first entry for the slot, writes into the cache and
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
70 // returns NULL. If it causes an eviction, returns the evicted pointer.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
71 // Otherwise, its a cache hit, and returns NULL.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
72 jbyte* cache_insert(jbyte* card_ptr);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
73
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
74 // Process the cached entries.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
75 void clean_up_cache(int worker_i, G1RemSet* g1rs);
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
76
889
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
77 // Set up for parallel processing of the cards in the hot cache
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
78 void clear_hot_cache_claimed_index() {
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
79 _hot_cache_par_claimed_idx = 0;
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
80 }
15c5903cf9e1 6865703: G1: Parallelize hot card cache cleanup
johnc
parents: 795
diff changeset
81
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
82 // Discard entries in the hot cache.
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
83 void clear_hot_cache() {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
84 _hot_cache_idx = 0; _n_hot = 0;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
85 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
86
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
87 bool hot_cache_is_empty() { return _n_hot == 0; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
88
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
89 bool use_cache() { return _use_cache; }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
90 void set_use_cache(bool b) {
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
91 if (b) _use_cache = _def_use_cache;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
92 else _use_cache = false;
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
93 }
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
94
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
95 void clear_and_record_card_counts();
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
96 void print_final_card_counts();
795
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
97
215f81b4d9b3 6841831: G1: assert(contains_reference(from),"We just added it!") fires
iveresov
parents: 794
diff changeset
98 static size_t thread_num();
342
37f87013dfd8 6711316: Open source the Garbage-First garbage collector
ysr
parents:
diff changeset
99 };