annotate src/share/vm/memory/freeList.cpp @ 8001:db9981fd3124

8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS Summary: Rename INCLUDE_ALTERNATE_GCS to INCLUDE_ALL_GCS and replace SERIALGC with INCLUDE_ALL_GCS. Reviewed-by: coleenp, stefank
author jprovino
date Wed, 23 Jan 2013 13:02:39 -0500
parents 685df3c6f84b
children 7c5a1b62f53d
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
a61af66fc99e Initial load
duke
parents:
diff changeset
1 /*
6842
b9a9ed0f8eeb 7197424: update copyright year to match last edit in jdk8 hotspot repository
mikael
parents: 6028
diff changeset
2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
a61af66fc99e Initial load
duke
parents:
diff changeset
4 *
a61af66fc99e Initial load
duke
parents:
diff changeset
5 * This code is free software; you can redistribute it and/or modify it
a61af66fc99e Initial load
duke
parents:
diff changeset
6 * under the terms of the GNU General Public License version 2 only, as
a61af66fc99e Initial load
duke
parents:
diff changeset
7 * published by the Free Software Foundation.
a61af66fc99e Initial load
duke
parents:
diff changeset
8 *
a61af66fc99e Initial load
duke
parents:
diff changeset
9 * This code is distributed in the hope that it will be useful, but WITHOUT
a61af66fc99e Initial load
duke
parents:
diff changeset
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
a61af66fc99e Initial load
duke
parents:
diff changeset
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
a61af66fc99e Initial load
duke
parents:
diff changeset
12 * version 2 for more details (a copy is included in the LICENSE file that
a61af66fc99e Initial load
duke
parents:
diff changeset
13 * accompanied this code).
a61af66fc99e Initial load
duke
parents:
diff changeset
14 *
a61af66fc99e Initial load
duke
parents:
diff changeset
15 * You should have received a copy of the GNU General Public License version
a61af66fc99e Initial load
duke
parents:
diff changeset
16 * 2 along with this work; if not, write to the Free Software Foundation,
a61af66fc99e Initial load
duke
parents:
diff changeset
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
a61af66fc99e Initial load
duke
parents:
diff changeset
18 *
1552
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
20 * or visit www.oracle.com if you need additional information or have any
c18cbe5936b8 6941466: Oracle rebranding changes for Hotspot repositories
trims
parents: 1145
diff changeset
21 * questions.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
22 *
a61af66fc99e Initial load
duke
parents:
diff changeset
23 */
a61af66fc99e Initial load
duke
parents:
diff changeset
24
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
25 #include "precompiled.hpp"
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
26 #include "memory/freeBlockDictionary.hpp"
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
27 #include "memory/freeList.hpp"
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
28 #include "memory/metablock.hpp"
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
29 #include "memory/metachunk.hpp"
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
30 #include "memory/sharedHeap.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
31 #include "runtime/globals.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
32 #include "runtime/mutex.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1777
diff changeset
33 #include "runtime/vmThread.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6885
diff changeset
34 #include "utilities/macros.hpp"
0
a61af66fc99e Initial load
duke
parents:
diff changeset
35
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6885
diff changeset
36 #if INCLUDE_ALL_GCS
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
37 #include "gc_implementation/concurrentMarkSweep/freeChunk.hpp"
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6885
diff changeset
38 #endif // INCLUDE_ALL_GCS
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
39
0
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // Free list. A FreeList is used to access a linked list of chunks
a61af66fc99e Initial load
duke
parents:
diff changeset
41 // of space in the heap. The head and tail are maintained so that
a61af66fc99e Initial load
duke
parents:
diff changeset
42 // items can be (as in the current implementation) added at the
a61af66fc99e Initial load
duke
parents:
diff changeset
43 // at the tail of the list and removed from the head of the list to
a61af66fc99e Initial load
duke
parents:
diff changeset
44 // maintain a FIFO queue.
a61af66fc99e Initial load
duke
parents:
diff changeset
45
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
46 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
47 FreeList<Chunk>::FreeList() :
0
a61af66fc99e Initial load
duke
parents:
diff changeset
48 _head(NULL), _tail(NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
49 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
50 , _protecting_lock(NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
51 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
52 {
a61af66fc99e Initial load
duke
parents:
diff changeset
53 _size = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
54 _count = 0;
a61af66fc99e Initial load
duke
parents:
diff changeset
55 }
a61af66fc99e Initial load
duke
parents:
diff changeset
56
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
57 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
58 FreeList<Chunk>::FreeList(Chunk* fc) :
0
a61af66fc99e Initial load
duke
parents:
diff changeset
59 _head(fc), _tail(fc)
a61af66fc99e Initial load
duke
parents:
diff changeset
60 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
61 , _protecting_lock(NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
62 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
63 {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 _size = fc->size();
a61af66fc99e Initial load
duke
parents:
diff changeset
65 _count = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
66 }
a61af66fc99e Initial load
duke
parents:
diff changeset
67
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
68 template <class Chunk>
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
69 void FreeList<Chunk>::link_head(Chunk* v) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
70 assert_proper_lock_protection();
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
71 set_head(v);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
72 // If this method is not used (just set the head instead),
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
73 // this check can be avoided.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
74 if (v != NULL) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
75 v->link_prev(NULL);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
76 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
77 }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
78
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
79
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
80
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
81 template <class Chunk>
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
82 void FreeList<Chunk>::reset() {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
83 // Don't set the _size to 0 because this method is
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
84 // used with a existing list that has a size but which has
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
85 // been emptied.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
86 // Don't clear the _protecting_lock of an existing list.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
87 set_count(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
88 set_head(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
89 set_tail(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
90 }
a61af66fc99e Initial load
duke
parents:
diff changeset
91
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
92 template <class Chunk>
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
93 void FreeList<Chunk>::initialize() {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
94 #ifdef ASSERT
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
95 // Needed early because it might be checked in other initializing code.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
96 set_protecting_lock(NULL);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
97 #endif
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
98 reset();
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
99 set_size(0);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
100 }
a61af66fc99e Initial load
duke
parents:
diff changeset
101
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
102 template <class Chunk_t>
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
103 Chunk_t* FreeList<Chunk_t>::get_chunk_at_head() {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
104 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
105 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
107 Chunk_t* fc = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
108 if (fc != NULL) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
109 Chunk_t* nextFC = fc->next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
110 if (nextFC != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // The chunk fc being removed has a "next". Set the "next" to the
a61af66fc99e Initial load
duke
parents:
diff changeset
112 // "prev" of fc.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
113 nextFC->link_prev(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
114 } else { // removed tail of list
a61af66fc99e Initial load
duke
parents:
diff changeset
115 link_tail(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
116 }
a61af66fc99e Initial load
duke
parents:
diff changeset
117 link_head(nextFC);
a61af66fc99e Initial load
duke
parents:
diff changeset
118 decrement_count();
a61af66fc99e Initial load
duke
parents:
diff changeset
119 }
a61af66fc99e Initial load
duke
parents:
diff changeset
120 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 return fc;
a61af66fc99e Initial load
duke
parents:
diff changeset
123 }
a61af66fc99e Initial load
duke
parents:
diff changeset
124
a61af66fc99e Initial load
duke
parents:
diff changeset
125
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
126 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
127 void FreeList<Chunk>::getFirstNChunksFromList(size_t n, FreeList<Chunk>* fl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
128 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
129 assert(fl->count() == 0, "Precondition");
a61af66fc99e Initial load
duke
parents:
diff changeset
130 if (count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
131 int k = 1;
a61af66fc99e Initial load
duke
parents:
diff changeset
132 fl->set_head(head()); n--;
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
133 Chunk* tl = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
134 while (tl->next() != NULL && n > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
135 tl = tl->next(); n--; k++;
a61af66fc99e Initial load
duke
parents:
diff changeset
136 }
a61af66fc99e Initial load
duke
parents:
diff changeset
137 assert(tl != NULL, "Loop Inv.");
a61af66fc99e Initial load
duke
parents:
diff changeset
138
a61af66fc99e Initial load
duke
parents:
diff changeset
139 // First, fix up the list we took from.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
140 Chunk* new_head = tl->next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
141 set_head(new_head);
a61af66fc99e Initial load
duke
parents:
diff changeset
142 set_count(count() - k);
a61af66fc99e Initial load
duke
parents:
diff changeset
143 if (new_head == NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
144 set_tail(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
145 } else {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
146 new_head->link_prev(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
147 }
a61af66fc99e Initial load
duke
parents:
diff changeset
148 // Now we can fix up the tail.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
149 tl->link_next(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
150 // And return the result.
a61af66fc99e Initial load
duke
parents:
diff changeset
151 fl->set_tail(tl);
a61af66fc99e Initial load
duke
parents:
diff changeset
152 fl->set_count(k);
a61af66fc99e Initial load
duke
parents:
diff changeset
153 }
a61af66fc99e Initial load
duke
parents:
diff changeset
154 }
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Remove this chunk from the list
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
157 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
158 void FreeList<Chunk>::remove_chunk(Chunk*fc) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
159 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
160 assert(head() != NULL, "Remove from empty list");
a61af66fc99e Initial load
duke
parents:
diff changeset
161 assert(fc != NULL, "Remove a NULL chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
162 assert(size() == fc->size(), "Wrong list");
a61af66fc99e Initial load
duke
parents:
diff changeset
163 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
164 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
165
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
166 Chunk* prevFC = fc->prev();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
167 Chunk* nextFC = fc->next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
168 if (nextFC != NULL) {
a61af66fc99e Initial load
duke
parents:
diff changeset
169 // The chunk fc being removed has a "next". Set the "next" to the
a61af66fc99e Initial load
duke
parents:
diff changeset
170 // "prev" of fc.
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
171 nextFC->link_prev(prevFC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
172 } else { // removed tail of list
a61af66fc99e Initial load
duke
parents:
diff changeset
173 link_tail(prevFC);
a61af66fc99e Initial load
duke
parents:
diff changeset
174 }
a61af66fc99e Initial load
duke
parents:
diff changeset
175 if (prevFC == NULL) { // removed head of list
a61af66fc99e Initial load
duke
parents:
diff changeset
176 link_head(nextFC);
a61af66fc99e Initial load
duke
parents:
diff changeset
177 assert(nextFC == NULL || nextFC->prev() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
178 "Prev of head should be NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
179 } else {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
180 prevFC->link_next(nextFC);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
181 assert(tail() != prevFC || prevFC->next() == NULL,
a61af66fc99e Initial load
duke
parents:
diff changeset
182 "Next of tail should be NULL");
a61af66fc99e Initial load
duke
parents:
diff changeset
183 }
a61af66fc99e Initial load
duke
parents:
diff changeset
184 decrement_count();
1777
179464550c7d 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 1552
diff changeset
185 assert(((head() == NULL) + (tail() == NULL) + (count() == 0)) % 3 == 0,
179464550c7d 6983930: CMS: Various small cleanups ca September 2010
ysr
parents: 1552
diff changeset
186 "H/T/C Inconsistency");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
187 // clear next and prev fields of fc, debug only
a61af66fc99e Initial load
duke
parents:
diff changeset
188 NOT_PRODUCT(
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
189 fc->link_prev(NULL);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
190 fc->link_next(NULL);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
191 )
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
192 assert(fc->is_free(), "Should still be a free chunk");
0
a61af66fc99e Initial load
duke
parents:
diff changeset
193 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
194 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
195 assert(head() == NULL || head()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
196 assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
197 }
a61af66fc99e Initial load
duke
parents:
diff changeset
198
a61af66fc99e Initial load
duke
parents:
diff changeset
199 // Add this chunk at the head of the list.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
200 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
201 void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk, bool record_return) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
202 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
203 assert(chunk != NULL, "insert a NULL chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
204 assert(size() == chunk->size(), "Wrong size");
a61af66fc99e Initial load
duke
parents:
diff changeset
205 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
206 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
207
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
208 Chunk* oldHead = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
209 assert(chunk != oldHead, "double insertion");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
210 chunk->link_after(oldHead);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
211 link_head(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
212 if (oldHead == NULL) { // only chunk in list
a61af66fc99e Initial load
duke
parents:
diff changeset
213 assert(tail() == NULL, "inconsistent FreeList");
a61af66fc99e Initial load
duke
parents:
diff changeset
214 link_tail(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
215 }
a61af66fc99e Initial load
duke
parents:
diff changeset
216 increment_count(); // of # of chunks in list
a61af66fc99e Initial load
duke
parents:
diff changeset
217 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
218 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
219 assert(head() == NULL || head()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
220 assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
221 }
a61af66fc99e Initial load
duke
parents:
diff changeset
222
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
223 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
224 void FreeList<Chunk>::return_chunk_at_head(Chunk* chunk) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
225 assert_proper_lock_protection();
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
226 return_chunk_at_head(chunk, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
227 }
a61af66fc99e Initial load
duke
parents:
diff changeset
228
a61af66fc99e Initial load
duke
parents:
diff changeset
229 // Add this chunk at the tail of the list.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
230 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
231 void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk, bool record_return) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
232 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
233 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
234 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
235 assert(chunk != NULL, "insert a NULL chunk");
a61af66fc99e Initial load
duke
parents:
diff changeset
236 assert(size() == chunk->size(), "wrong size");
a61af66fc99e Initial load
duke
parents:
diff changeset
237
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
238 Chunk* oldTail = tail();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
239 assert(chunk != oldTail, "double insertion");
a61af66fc99e Initial load
duke
parents:
diff changeset
240 if (oldTail != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
241 oldTail->link_after(chunk);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
242 } else { // only chunk in list
a61af66fc99e Initial load
duke
parents:
diff changeset
243 assert(head() == NULL, "inconsistent FreeList");
a61af66fc99e Initial load
duke
parents:
diff changeset
244 link_head(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
245 }
a61af66fc99e Initial load
duke
parents:
diff changeset
246 link_tail(chunk);
a61af66fc99e Initial load
duke
parents:
diff changeset
247 increment_count(); // of # of chunks in list
a61af66fc99e Initial load
duke
parents:
diff changeset
248 assert(head() == NULL || head()->prev() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
249 assert(tail() == NULL || tail()->next() == NULL, "list invariant");
a61af66fc99e Initial load
duke
parents:
diff changeset
250 assert(head() == NULL || head()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
251 assert(tail() == NULL || tail()->size() == size(), "wrong item on list");
a61af66fc99e Initial load
duke
parents:
diff changeset
252 }
a61af66fc99e Initial load
duke
parents:
diff changeset
253
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
254 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
255 void FreeList<Chunk>::return_chunk_at_tail(Chunk* chunk) {
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
256 return_chunk_at_tail(chunk, true);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
257 }
a61af66fc99e Initial load
duke
parents:
diff changeset
258
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
259 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
260 void FreeList<Chunk>::prepend(FreeList<Chunk>* fl) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
261 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
262 if (fl->count() > 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
263 if (count() == 0) {
a61af66fc99e Initial load
duke
parents:
diff changeset
264 set_head(fl->head());
a61af66fc99e Initial load
duke
parents:
diff changeset
265 set_tail(fl->tail());
a61af66fc99e Initial load
duke
parents:
diff changeset
266 set_count(fl->count());
a61af66fc99e Initial load
duke
parents:
diff changeset
267 } else {
a61af66fc99e Initial load
duke
parents:
diff changeset
268 // Both are non-empty.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
269 Chunk* fl_tail = fl->tail();
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
270 Chunk* this_head = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
271 assert(fl_tail->next() == NULL, "Well-formedness of fl");
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
272 fl_tail->link_next(this_head);
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
273 this_head->link_prev(fl_tail);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
274 set_head(fl->head());
a61af66fc99e Initial load
duke
parents:
diff changeset
275 set_count(count() + fl->count());
a61af66fc99e Initial load
duke
parents:
diff changeset
276 }
a61af66fc99e Initial load
duke
parents:
diff changeset
277 fl->set_head(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
278 fl->set_tail(NULL);
a61af66fc99e Initial load
duke
parents:
diff changeset
279 fl->set_count(0);
a61af66fc99e Initial load
duke
parents:
diff changeset
280 }
a61af66fc99e Initial load
duke
parents:
diff changeset
281 }
a61af66fc99e Initial load
duke
parents:
diff changeset
282
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
283 // verify_chunk_in_free_lists() is used to verify that an item is in this free list.
0
a61af66fc99e Initial load
duke
parents:
diff changeset
284 // It is used as a debugging aid.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
285 template <class Chunk>
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
286 bool FreeList<Chunk>::verify_chunk_in_free_list(Chunk* fc) const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
287 // This is an internal consistency check, not part of the check that the
a61af66fc99e Initial load
duke
parents:
diff changeset
288 // chunk is in the free lists.
a61af66fc99e Initial load
duke
parents:
diff changeset
289 guarantee(fc->size() == size(), "Wrong list is being searched");
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
290 Chunk* curFC = head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
291 while (curFC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
292 // This is an internal consistency check.
a61af66fc99e Initial load
duke
parents:
diff changeset
293 guarantee(size() == curFC->size(), "Chunk is in wrong list.");
a61af66fc99e Initial load
duke
parents:
diff changeset
294 if (fc == curFC) {
a61af66fc99e Initial load
duke
parents:
diff changeset
295 return true;
a61af66fc99e Initial load
duke
parents:
diff changeset
296 }
a61af66fc99e Initial load
duke
parents:
diff changeset
297 curFC = curFC->next();
a61af66fc99e Initial load
duke
parents:
diff changeset
298 }
a61af66fc99e Initial load
duke
parents:
diff changeset
299 return false;
a61af66fc99e Initial load
duke
parents:
diff changeset
300 }
a61af66fc99e Initial load
duke
parents:
diff changeset
301
a61af66fc99e Initial load
duke
parents:
diff changeset
302 #ifndef PRODUCT
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
303 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
304 void FreeList<Chunk>::assert_proper_lock_protection_work() const {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
305 assert(protecting_lock() != NULL, "Don't call this directly");
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
306 assert(ParallelGCThreads > 0, "Don't call this directly");
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
307 Thread* thr = Thread::current();
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
308 if (thr->is_VM_thread() || thr->is_ConcurrentGC_thread()) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
309 // assert that we are holding the freelist lock
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
310 } else if (thr->is_GC_task_thread()) {
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
311 assert(protecting_lock()->owned_by_self(), "FreeList RACE DETECTED");
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
312 } else if (thr->is_Java_thread()) {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
313 assert(!SafepointSynchronize::is_at_safepoint(), "Should not be executing");
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
314 } else {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
315 ShouldNotReachHere(); // unaccounted thread type?
0
a61af66fc99e Initial load
duke
parents:
diff changeset
316 }
a61af66fc99e Initial load
duke
parents:
diff changeset
317 }
a61af66fc99e Initial load
duke
parents:
diff changeset
318 #endif
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
319
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
320 // Print the "label line" for free list stats.
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
321 template <class Chunk>
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
322 void FreeList<Chunk>::print_labels_on(outputStream* st, const char* c) {
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
323 st->print("%16s\t", c);
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
324 st->print("%14s\t" "%14s\t" "%14s\t" "%14s\t" "%14s\t"
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
325 "%14s\t" "%14s\t" "%14s\t" "%14s\t" "%14s\t" "\n",
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
326 "bfrsurp", "surplus", "desired", "prvSwep", "bfrSwep",
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
327 "count", "cBirths", "cDeaths", "sBirths", "sDeaths");
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
328 }
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
329
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
330 // Print the AllocationStats for the given free list. If the second argument
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
331 // to the call is a non-null string, it is printed in the first column;
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
332 // otherwise, if the argument is null (the default), then the size of the
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
333 // (free list) block is printed in the first column.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
334 template <class Chunk_t>
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
335 void FreeList<Chunk_t>::print_on(outputStream* st, const char* c) const {
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
336 if (c != NULL) {
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
337 st->print("%16s", c);
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
338 } else {
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
339 st->print(SIZE_FORMAT_W(16), size());
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
340 }
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
341 }
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
342
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
343 template class FreeList<Metablock>;
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
344 template class FreeList<Metachunk>;
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6885
diff changeset
345 #if INCLUDE_ALL_GCS
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 3775
diff changeset
346 template class FreeList<FreeChunk>;
8001
db9981fd3124 8005915: Unify SERIALGC and INCLUDE_ALTERNATE_GCS
jprovino
parents: 6885
diff changeset
347 #endif // INCLUDE_ALL_GCS