1 /*
2 * Copyright (c) 2001, 2013, 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 *
124 // See FreeList.
125 void return_chunk_at_head(TreeChunk<Chunk_t, FreeList_t>* tc);
126 void return_chunk_at_tail(TreeChunk<Chunk_t, FreeList_t>* tc);
127 };
128
129 // A TreeChunk is a subclass of a Chunk that additionally
130 // maintains a pointer to the free list on which it is currently
131 // linked.
132 // A TreeChunk is also used as a node in the binary tree. This
133 // allows the binary tree to be maintained without any additional
134 // storage (the free chunks are used). In a binary tree the first
135 // chunk in the free list is also the tree node. Note that the
136 // TreeChunk has an embedded TreeList for this purpose. Because
137 // the first chunk in the list is distinguished in this fashion
138 // (also is the node in the tree), it is the last chunk to be found
139 // on the free list for a node in the tree and is only removed if
140 // it is the last chunk on the free list.
141
142 template <class Chunk_t, class FreeList_t>
143 class TreeChunk : public Chunk_t {
144 friend class TreeList<Chunk_t, FreeList_t>;
145 TreeList<Chunk_t, FreeList_t>* _list;
146 TreeList<Chunk_t, FreeList_t> _embedded_list; // if non-null, this chunk is on _list
147
148 static size_t _min_tree_chunk_size;
149
150 protected:
151 TreeList<Chunk_t, FreeList_t>* embedded_list() const { return (TreeList<Chunk_t, FreeList_t>*) &_embedded_list; }
152 void set_embedded_list(TreeList<Chunk_t, FreeList_t>* v) { _embedded_list = *v; }
153 public:
154 TreeList<Chunk_t, FreeList_t>* list() { return _list; }
155 void set_list(TreeList<Chunk_t, FreeList_t>* v) { _list = v; }
156 static TreeChunk<Chunk_t, FreeList_t>* as_TreeChunk(Chunk_t* fc);
157 // Initialize fields in a TreeChunk that should be
158 // initialized when the TreeChunk is being added to
159 // a free list in the tree.
160 void initialize() { embedded_list()->initialize(); }
161
162 Chunk_t* next() const { return Chunk_t::next(); }
163 Chunk_t* prev() const { return Chunk_t::prev(); }
164 size_t size() const volatile { return Chunk_t::size(); }
165
166 static size_t min_size() {
167 return _min_tree_chunk_size;
168 }
169
170 // debugging
171 void verify_tree_chunk_list() const;
172 void assert_is_mangled() const;
173 };
174
175
176 template <class Chunk_t, class FreeList_t>
177 class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
178 friend class VMStructs;
179 size_t _total_size;
180 size_t _total_free_blocks;
181 TreeList<Chunk_t, FreeList_t>* _root;
182
183 // private accessors
184 void set_total_size(size_t v) { _total_size = v; }
185 virtual void inc_total_size(size_t v);
186 virtual void dec_total_size(size_t v);
187 void set_total_free_blocks(size_t v) { _total_free_blocks = v; }
188 TreeList<Chunk_t, FreeList_t>* root() const { return _root; }
189 void set_root(TreeList<Chunk_t, FreeList_t>* v) { _root = v; }
190
191 // This field is added and can be set to point to the
192 // the Mutex used to synchronize access to the
193 // dictionary so that assertion checking can be done.
194 // For example it is set to point to _parDictionaryAllocLock.
|
1 /*
2 * Copyright (c) 2001, 2017, 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 *
124 // See FreeList.
125 void return_chunk_at_head(TreeChunk<Chunk_t, FreeList_t>* tc);
126 void return_chunk_at_tail(TreeChunk<Chunk_t, FreeList_t>* tc);
127 };
128
129 // A TreeChunk is a subclass of a Chunk that additionally
130 // maintains a pointer to the free list on which it is currently
131 // linked.
132 // A TreeChunk is also used as a node in the binary tree. This
133 // allows the binary tree to be maintained without any additional
134 // storage (the free chunks are used). In a binary tree the first
135 // chunk in the free list is also the tree node. Note that the
136 // TreeChunk has an embedded TreeList for this purpose. Because
137 // the first chunk in the list is distinguished in this fashion
138 // (also is the node in the tree), it is the last chunk to be found
139 // on the free list for a node in the tree and is only removed if
140 // it is the last chunk on the free list.
141
142 template <class Chunk_t, class FreeList_t>
143 class TreeChunk : public Chunk_t {
144 private:
145 friend class TreeList<Chunk_t, FreeList_t>;
146 TreeList<Chunk_t, FreeList_t>* _list;
147 TreeList<Chunk_t, FreeList_t> _embedded_list; // if non-null, this chunk is on _list
148
149 static size_t _min_tree_chunk_size;
150
151 protected:
152 TreeList<Chunk_t, FreeList_t>* embedded_list() const { return (TreeList<Chunk_t, FreeList_t>*) &_embedded_list; }
153 void set_embedded_list(TreeList<Chunk_t, FreeList_t>* v) { _embedded_list = *v; }
154 public:
155 TreeList<Chunk_t, FreeList_t>* list() { return _list; }
156 void set_list(TreeList<Chunk_t, FreeList_t>* v) { _list = v; }
157 static TreeChunk<Chunk_t, FreeList_t>* as_TreeChunk(Chunk_t* fc);
158 // Initialize fields in a TreeChunk that should be
159 // initialized when the TreeChunk is being added to
160 // a free list in the tree.
161 void initialize() { embedded_list()->initialize(); }
162
163 Chunk_t* next() const { return Chunk_t::next(); }
164 Chunk_t* prev() const { return Chunk_t::prev(); }
165 size_t size() const volatile { return Chunk_t::size(); }
166
167 static size_t min_size();
168
169 // debugging
170 void verify_tree_chunk_list() const;
171 void assert_is_mangled() const;
172 };
173
174 template <class Chunk_t, class FreeList_t>
175 size_t TreeChunk<Chunk_t, FreeList_t>::_min_tree_chunk_size = sizeof(TreeChunk<Chunk_t, FreeList_t>)/HeapWordSize;
176 template <class Chunk_t, class FreeList_t>
177 size_t TreeChunk<Chunk_t, FreeList_t>::min_size() { return _min_tree_chunk_size; }
178
179 template <class Chunk_t, class FreeList_t>
180 class BinaryTreeDictionary: public FreeBlockDictionary<Chunk_t> {
181 friend class VMStructs;
182 size_t _total_size;
183 size_t _total_free_blocks;
184 TreeList<Chunk_t, FreeList_t>* _root;
185
186 // private accessors
187 void set_total_size(size_t v) { _total_size = v; }
188 virtual void inc_total_size(size_t v);
189 virtual void dec_total_size(size_t v);
190 void set_total_free_blocks(size_t v) { _total_free_blocks = v; }
191 TreeList<Chunk_t, FreeList_t>* root() const { return _root; }
192 void set_root(TreeList<Chunk_t, FreeList_t>* v) { _root = v; }
193
194 // This field is added and can be set to point to the
195 // the Mutex used to synchronize access to the
196 // dictionary so that assertion checking can be done.
197 // For example it is set to point to _parDictionaryAllocLock.
|