annotate src/share/vm/gc_implementation/g1/heapRegionSets.cpp @ 17736:58fc1b1523dc

8034079: G1: Refactor the HeapRegionSet hierarchy Reviewed-by: tschatzl, pliden
author brutisso
date Fri, 14 Mar 2014 10:15:46 +0100
parents 8aae2050e83e
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
1 /*
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
2 * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
4 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
7 * published by the Free Software Foundation.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
8 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
13 * accompanied this code).
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
14 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
18 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
21 * questions.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
22 *
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
23 */
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
24
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
25 #include "precompiled.hpp"
3777
e8b0b0392037 7046182: G1: remove unnecessary iterations over the collection set
tonyp
parents: 2361
diff changeset
26 #include "gc_implementation/g1/heapRegionRemSet.hpp"
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
27 #include "gc_implementation/g1/heapRegionSet.hpp"
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
28
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
29 // Note on the check_mt_safety() methods below:
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
30 //
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
31 // Verification of the "master" heap region sets / lists that are
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
32 // maintained by G1CollectedHeap is always done during a STW pause and
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
33 // by the VM thread at the start / end of the pause. The standard
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
34 // verification methods all assert check_mt_safety(). This is
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
35 // important as it ensures that verification is done without
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
36 // concurrent updates taking place at the same time. It follows, that,
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
37 // for the "master" heap region sets / lists, the check_mt_safety()
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
38 // method should include the VM thread / STW case.
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
39
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
40 void FreeRegionList::verify_list() {
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
41 HeapRegion* curr = head();
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
42 HeapRegion* prev1 = NULL;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
43 HeapRegion* prev0 = NULL;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
44 uint count = 0;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
45 size_t capacity = 0;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
46 while (curr != NULL) {
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
47 verify_region(curr);
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
48
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
49 count++;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
50 guarantee(count < _unrealistically_long_length,
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
51 hrs_err_msg("[%s] the calculated length: %u seems very long, is there maybe a cycle? curr: "PTR_FORMAT" prev0: "PTR_FORMAT" " "prev1: "PTR_FORMAT" length: %u", name(), count, curr, prev0, prev1, length()));
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
52
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
53 capacity += curr->capacity();
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
54
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
55 prev1 = prev0;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
56 prev0 = curr;
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
57 curr = curr->next();
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
58 }
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
59
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
60 guarantee(tail() == prev0, err_msg("Expected %s to end with %u but it ended with %u.", name(), tail()->hrs_index(), prev0->hrs_index()));
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
61
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
62 guarantee(length() == count, err_msg("%s count mismatch. Expected %u, actual %u.", name(), length(), count));
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
63 guarantee(total_capacity_bytes() == capacity, err_msg("%s capacity mismatch. Expected " SIZE_FORMAT ", actual " SIZE_FORMAT,
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
64 name(), total_capacity_bytes(), capacity));
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
65 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
66
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
67 void MasterFreeRegionListMtSafeChecker::check() {
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
68 // Master Free List MT safety protocol:
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
69 // (a) If we're at a safepoint, operations on the master free list
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
70 // should be invoked by either the VM thread (which will serialize
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
71 // them) or by the GC workers while holding the
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
72 // FreeList_lock.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
73 // (b) If we're not at a safepoint, operations on the master free
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
74 // list should be invoked while holding the Heap_lock.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
75
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
76 if (SafepointSynchronize::is_at_safepoint()) {
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
77 guarantee(Thread::current()->is_VM_thread() ||
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
78 FreeList_lock->owned_by_self(), "master free list MT safety protocol at a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
79 } else {
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
80 guarantee(Heap_lock->owned_by_self(), "master free list MT safety protocol outside a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
81 }
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
82 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
83
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
84 void SecondaryFreeRegionListMtSafeChecker::check() {
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
85 // Secondary Free List MT safety protocol:
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
86 // Operations on the secondary free list should always be invoked
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
87 // while holding the SecondaryFreeList_lock.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
88
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
89 guarantee(SecondaryFreeList_lock->owned_by_self(), "secondary free list MT safety protocol");
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
90 }
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
91
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
92 void OldRegionSetMtSafeChecker::check() {
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
93 // Master Old Set MT safety protocol:
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
94 // (a) If we're at a safepoint, operations on the master old set
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
95 // should be invoked:
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
96 // - by the VM thread (which will serialize them), or
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
97 // - by the GC workers while holding the FreeList_lock, if we're
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
98 // at a safepoint for an evacuation pause (this lock is taken
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
99 // anyway when an GC alloc region is retired so that a new one
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
100 // is allocated from the free list), or
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
101 // - by the GC workers while holding the OldSets_lock, if we're at a
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
102 // safepoint for a cleanup pause.
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
103 // (b) If we're not at a safepoint, operations on the master old set
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
104 // should be invoked while holding the Heap_lock.
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
105
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
106 if (SafepointSynchronize::is_at_safepoint()) {
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
107 guarantee(Thread::current()->is_VM_thread()
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
108 || FreeList_lock->owned_by_self() || OldSets_lock->owned_by_self(),
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
109 "master old set MT safety protocol at a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
110 } else {
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
111 guarantee(Heap_lock->owned_by_self(), "master old set MT safety protocol outside a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
112 }
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
113 }
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
114
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
115 void HumongousRegionSetMtSafeChecker::check() {
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
116 // Humongous Set MT safety protocol:
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
117 // (a) If we're at a safepoint, operations on the master humongous
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
118 // set should be invoked by either the VM thread (which will
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
119 // serialize them) or by the GC workers while holding the
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
120 // OldSets_lock.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
121 // (b) If we're not at a safepoint, operations on the master
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
122 // humongous set should be invoked while holding the Heap_lock.
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
123
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
124 if (SafepointSynchronize::is_at_safepoint()) {
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
125 guarantee(Thread::current()->is_VM_thread() ||
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
126 OldSets_lock->owned_by_self(),
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
127 "master humongous set MT safety protocol at a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
128 } else {
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
129 guarantee(Heap_lock->owned_by_self(),
17736
58fc1b1523dc 8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents: 4072
diff changeset
130 "master humongous set MT safety protocol outside a safepoint");
4072
8aae2050e83e 7092309: G1: introduce old region set
tonyp
parents: 3777
diff changeset
131 }
2152
0fa27f37d4d4 6977804: G1: remove the zero-filling thread
tonyp
parents:
diff changeset
132 }