annotate src/share/vm/memory/freeList.hpp @ 10188:2f50bc369470

8013160: NPG: Remove unnecessary mark stack draining after CodeCache::do_unloading Reviewed-by: coleenp, mgerdin
author stefank
date Fri, 26 Apr 2013 10:40:36 +0200
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
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
25 #ifndef SHARE_VM_MEMORY_FREELIST_HPP
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
26 #define SHARE_VM_MEMORY_FREELIST_HPP
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
27
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
28 #include "gc_implementation/shared/allocationStats.hpp"
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
29
0
a61af66fc99e Initial load
duke
parents:
diff changeset
30 class CompactibleFreeListSpace;
a61af66fc99e Initial load
duke
parents:
diff changeset
31
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
32 // A class for maintaining a free list of Chunk's. The FreeList
0
a61af66fc99e Initial load
duke
parents:
diff changeset
33 // maintains a the structure of the list (head, tail, etc.) plus
a61af66fc99e Initial load
duke
parents:
diff changeset
34 // statistics for allocations from the list. The links between items
a61af66fc99e Initial load
duke
parents:
diff changeset
35 // are not part of FreeList. The statistics are
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
36 // used to make decisions about coalescing Chunk's when they
0
a61af66fc99e Initial load
duke
parents:
diff changeset
37 // are swept during collection.
a61af66fc99e Initial load
duke
parents:
diff changeset
38 //
a61af66fc99e Initial load
duke
parents:
diff changeset
39 // See the corresponding .cpp file for a description of the specifics
a61af66fc99e Initial load
duke
parents:
diff changeset
40 // for that implementation.
a61af66fc99e Initial load
duke
parents:
diff changeset
41
a61af66fc99e Initial load
duke
parents:
diff changeset
42 class Mutex;
a61af66fc99e Initial load
duke
parents:
diff changeset
43
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
44 template <class Chunk_t>
0
a61af66fc99e Initial load
duke
parents:
diff changeset
45 class FreeList VALUE_OBJ_CLASS_SPEC {
a61af66fc99e Initial load
duke
parents:
diff changeset
46 friend class CompactibleFreeListSpace;
152
c70a245cad3a 6670684: 4/5 SA command universe did not print out CMS space information
dcubed
parents: 12
diff changeset
47 friend class VMStructs;
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
48
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
49 private:
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
50 Chunk_t* _head; // Head of list of free chunks
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
51 Chunk_t* _tail; // Tail of list of free chunks
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
52 size_t _size; // Size in Heap words of each chunk
0
a61af66fc99e Initial load
duke
parents:
diff changeset
53 ssize_t _count; // Number of entries in list
a61af66fc99e Initial load
duke
parents:
diff changeset
54
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
55 protected:
0
a61af66fc99e Initial load
duke
parents:
diff changeset
56
a61af66fc99e Initial load
duke
parents:
diff changeset
57 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
58 Mutex* _protecting_lock;
a61af66fc99e Initial load
duke
parents:
diff changeset
59 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
60
a61af66fc99e Initial load
duke
parents:
diff changeset
61 // Asserts false if the protecting lock (if any) is not held.
a61af66fc99e Initial load
duke
parents:
diff changeset
62 void assert_proper_lock_protection_work() const PRODUCT_RETURN;
a61af66fc99e Initial load
duke
parents:
diff changeset
63 void assert_proper_lock_protection() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
64 #ifdef ASSERT
a61af66fc99e Initial load
duke
parents:
diff changeset
65 if (_protecting_lock != NULL)
a61af66fc99e Initial load
duke
parents:
diff changeset
66 assert_proper_lock_protection_work();
a61af66fc99e Initial load
duke
parents:
diff changeset
67 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
68 }
a61af66fc99e Initial load
duke
parents:
diff changeset
69
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
70 void increment_count() {
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
71 _count++;
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
72 }
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
73
0
a61af66fc99e Initial load
duke
parents:
diff changeset
74 void decrement_count() {
a61af66fc99e Initial load
duke
parents:
diff changeset
75 _count--;
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
76 assert(_count >= 0, "Count should not be negative");
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
77 }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
78
a61af66fc99e Initial load
duke
parents:
diff changeset
79 public:
a61af66fc99e Initial load
duke
parents:
diff changeset
80 // Constructor
a61af66fc99e Initial load
duke
parents:
diff changeset
81 // Construct a list without any entries.
a61af66fc99e Initial load
duke
parents:
diff changeset
82 FreeList();
a61af66fc99e Initial load
duke
parents:
diff changeset
83 // Construct a list with "fc" as the first (and lone) entry in the list.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
84 FreeList(Chunk_t* fc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
85
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
86 // Do initialization
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
87 void initialize();
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
88
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
89 // Reset the head, tail, and count of a free list.
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
90 void reset();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
91
a61af66fc99e Initial load
duke
parents:
diff changeset
92 // Declare the current free list to be protected by the given lock.
a61af66fc99e Initial load
duke
parents:
diff changeset
93 #ifdef ASSERT
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
94 Mutex* protecting_lock() const { return _protecting_lock; }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
95 void set_protecting_lock(Mutex* v) {
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
96 _protecting_lock = v;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
97 }
a61af66fc99e Initial load
duke
parents:
diff changeset
98 #endif
a61af66fc99e Initial load
duke
parents:
diff changeset
99
a61af66fc99e Initial load
duke
parents:
diff changeset
100 // Accessors.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
101 Chunk_t* head() const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
102 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
103 return _head;
a61af66fc99e Initial load
duke
parents:
diff changeset
104 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
105 void set_head(Chunk_t* v) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
106 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
107 _head = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
108 assert(!_head || _head->size() == _size, "bad chunk size");
a61af66fc99e Initial load
duke
parents:
diff changeset
109 }
a61af66fc99e Initial load
duke
parents:
diff changeset
110 // Set the head of the list and set the prev field of non-null
a61af66fc99e Initial load
duke
parents:
diff changeset
111 // values to NULL.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
112 void link_head(Chunk_t* v);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
113
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
114 Chunk_t* tail() const {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
115 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
116 return _tail;
a61af66fc99e Initial load
duke
parents:
diff changeset
117 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
118 void set_tail(Chunk_t* v) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
119 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
120 _tail = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
121 assert(!_tail || _tail->size() == _size, "bad chunk size");
a61af66fc99e Initial load
duke
parents:
diff changeset
122 }
a61af66fc99e Initial load
duke
parents:
diff changeset
123 // Set the tail of the list and set the next field of non-null
a61af66fc99e Initial load
duke
parents:
diff changeset
124 // values to NULL.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
125 void link_tail(Chunk_t* v) {
0
a61af66fc99e Initial load
duke
parents:
diff changeset
126 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
127 set_tail(v);
a61af66fc99e Initial load
duke
parents:
diff changeset
128 if (v != NULL) {
6028
f69a5d43dc19 7164144: Fix variable naming style in freeBlockDictionary.* and binaryTreeDictionary*
jmasa
parents: 6026
diff changeset
129 v->clear_next();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
130 }
a61af66fc99e Initial load
duke
parents:
diff changeset
131 }
a61af66fc99e Initial load
duke
parents:
diff changeset
132
a61af66fc99e Initial load
duke
parents:
diff changeset
133 // No locking checks in read-accessors: lock-free reads (only) are benign.
a61af66fc99e Initial load
duke
parents:
diff changeset
134 // Readers are expected to have the lock if they are doing work that
a61af66fc99e Initial load
duke
parents:
diff changeset
135 // requires atomicity guarantees in sections of code.
a61af66fc99e Initial load
duke
parents:
diff changeset
136 size_t size() const {
a61af66fc99e Initial load
duke
parents:
diff changeset
137 return _size;
a61af66fc99e Initial load
duke
parents:
diff changeset
138 }
a61af66fc99e Initial load
duke
parents:
diff changeset
139 void set_size(size_t v) {
a61af66fc99e Initial load
duke
parents:
diff changeset
140 assert_proper_lock_protection();
a61af66fc99e Initial load
duke
parents:
diff changeset
141 _size = v;
a61af66fc99e Initial load
duke
parents:
diff changeset
142 }
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
143 ssize_t count() const { return _count; }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
144 void set_count(ssize_t v) { _count = v;}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
145
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
146 size_t get_better_size() { return size(); }
0
a61af66fc99e Initial load
duke
parents:
diff changeset
147
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
148 size_t returned_bytes() const { ShouldNotReachHere(); return 0; }
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
149 void set_returned_bytes(size_t v) {}
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
150 void increment_returned_bytes_by(size_t v) {}
0
a61af66fc99e Initial load
duke
parents:
diff changeset
151
a61af66fc99e Initial load
duke
parents:
diff changeset
152 // Unlink head of list and return it. Returns NULL if
a61af66fc99e Initial load
duke
parents:
diff changeset
153 // the list is empty.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
154 Chunk_t* get_chunk_at_head();
0
a61af66fc99e Initial load
duke
parents:
diff changeset
155
a61af66fc99e Initial load
duke
parents:
diff changeset
156 // Remove the first "n" or "count", whichever is smaller, chunks from the
a61af66fc99e Initial load
duke
parents:
diff changeset
157 // list, setting "fl", which is required to be empty, to point to them.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
158 void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
159
a61af66fc99e Initial load
duke
parents:
diff changeset
160 // Unlink this chunk from it's free list
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
161 void remove_chunk(Chunk_t* fc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
162
a61af66fc99e Initial load
duke
parents:
diff changeset
163 // Add this chunk to this free list.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
164 void return_chunk_at_head(Chunk_t* fc);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
165 void return_chunk_at_tail(Chunk_t* fc);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
166
a61af66fc99e Initial load
duke
parents:
diff changeset
167 // Similar to returnChunk* but also records some diagnostic
a61af66fc99e Initial load
duke
parents:
diff changeset
168 // information.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
169 void return_chunk_at_head(Chunk_t* fc, bool record_return);
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
170 void return_chunk_at_tail(Chunk_t* fc, bool record_return);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
171
a61af66fc99e Initial load
duke
parents:
diff changeset
172 // Prepend "fl" (whose size is required to be the same as that of "this")
a61af66fc99e Initial load
duke
parents:
diff changeset
173 // to the front of "this" list.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
174 void prepend(FreeList<Chunk_t>* fl);
0
a61af66fc99e Initial load
duke
parents:
diff changeset
175
a61af66fc99e Initial load
duke
parents:
diff changeset
176 // Verify that the chunk is in the list.
a61af66fc99e Initial load
duke
parents:
diff changeset
177 // found. Return NULL if "fc" is not found.
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
178 bool verify_chunk_in_free_list(Chunk_t* fc) const;
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
179
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
180 // Stats verification
6885
685df3c6f84b 7045397: NPG: Add freelists to class loader arenas.
jmasa
parents: 6842
diff changeset
181 // void verify_stats() const { ShouldNotReachHere(); };
1145
e018e6884bd8 6631166: CMS: better heuristics when combatting fragmentation
ysr
parents: 196
diff changeset
182
12
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
183 // Printing support
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
184 static void print_labels_on(outputStream* st, const char* c);
6432c3bb6240 6668743: CMS: Consolidate block statistics reporting code
ysr
parents: 0
diff changeset
185 void print_on(outputStream* st, const char* c = NULL) const;
0
a61af66fc99e Initial load
duke
parents:
diff changeset
186 };
1972
f95d63e2154a 6989984: Use standard include model for Hospot
stefank
parents: 1552
diff changeset
187
6026
9f059abe8cf2 7131629: Generalize the CMS free list code
jmasa
parents: 1972
diff changeset
188 #endif // SHARE_VM_MEMORY_FREELIST_HPP