Mercurial > hg > truffle
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 |
rev | line source |
---|---|
2152 | 1 /* |
2 * Copyright (c) 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 * | |
23 */ | |
24 | |
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 | 28 |
4072 | 29 // Note on the check_mt_safety() methods below: |
30 // | |
31 // Verification of the "master" heap region sets / lists that are | |
32 // maintained by G1CollectedHeap is always done during a STW pause and | |
33 // by the VM thread at the start / end of the pause. The standard | |
34 // verification methods all assert check_mt_safety(). This is | |
35 // important as it ensures that verification is done without | |
36 // concurrent updates taking place at the same time. It follows, that, | |
37 // for the "master" heap region sets / lists, the check_mt_safety() | |
38 // method should include the VM thread / STW case. | |
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 | 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 | 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 | 65 } |
66 | |
17736
58fc1b1523dc
8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents:
4072
diff
changeset
|
67 void MasterFreeRegionListMtSafeChecker::check() { |
2152 | 68 // Master Free List MT safety protocol: |
69 // (a) If we're at a safepoint, operations on the master free list | |
70 // should be invoked by either the VM thread (which will serialize | |
71 // them) or by the GC workers while holding the | |
72 // FreeList_lock. | |
73 // (b) If we're not at a safepoint, operations on the master free | |
74 // list should be invoked while holding the Heap_lock. | |
75 | |
4072 | 76 if (SafepointSynchronize::is_at_safepoint()) { |
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 | 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 | 81 } |
2152 | 82 } |
83 | |
17736
58fc1b1523dc
8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents:
4072
diff
changeset
|
84 void SecondaryFreeRegionListMtSafeChecker::check() { |
2152 | 85 // Secondary Free List MT safety protocol: |
86 // Operations on the secondary free list should always be invoked | |
87 // while holding the SecondaryFreeList_lock. | |
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 | 90 } |
91 | |
17736
58fc1b1523dc
8034079: G1: Refactor the HeapRegionSet hierarchy
brutisso
parents:
4072
diff
changeset
|
92 void OldRegionSetMtSafeChecker::check() { |
4072 | 93 // Master Old Set MT safety protocol: |
94 // (a) If we're at a safepoint, operations on the master old set | |
95 // should be invoked: | |
96 // - by the VM thread (which will serialize them), or | |
97 // - by the GC workers while holding the FreeList_lock, if we're | |
98 // at a safepoint for an evacuation pause (this lock is taken | |
99 // anyway when an GC alloc region is retired so that a new one | |
100 // is allocated from the free list), or | |
101 // - by the GC workers while holding the OldSets_lock, if we're at a | |
102 // safepoint for a cleanup pause. | |
103 // (b) If we're not at a safepoint, operations on the master old set | |
104 // should be invoked while holding the Heap_lock. | |
105 | |
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 | 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 | 112 } |
113 } | |
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 | 117 // (a) If we're at a safepoint, operations on the master humongous |
118 // set should be invoked by either the VM thread (which will | |
119 // serialize them) or by the GC workers while holding the | |
120 // OldSets_lock. | |
121 // (b) If we're not at a safepoint, operations on the master | |
122 // humongous set should be invoked while holding the Heap_lock. | |
123 | |
4072 | 124 if (SafepointSynchronize::is_at_safepoint()) { |
125 guarantee(Thread::current()->is_VM_thread() || | |
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 | 128 } else { |
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 | 131 } |
2152 | 132 } |