src/share/vm/memory/freeList.hpp

Tue, 30 Apr 2013 11:56:52 -0700

author
ccheung
date
Tue, 30 Apr 2013 11:56:52 -0700
changeset 4993
746b070f5022
parent 4196
685df3c6f84b
child 5166
7c5a1b62f53d
permissions
-rw-r--r--

8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
Reviewed-by: coleenp, zgu, hseigel

duke@435 1 /*
mikael@4153 2 * Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
jmasa@3730 25 #ifndef SHARE_VM_MEMORY_FREELIST_HPP
jmasa@3730 26 #define SHARE_VM_MEMORY_FREELIST_HPP
stefank@2314 27
stefank@2314 28 #include "gc_implementation/shared/allocationStats.hpp"
stefank@2314 29
duke@435 30 class CompactibleFreeListSpace;
duke@435 31
jmasa@3730 32 // A class for maintaining a free list of Chunk's. The FreeList
duke@435 33 // maintains a the structure of the list (head, tail, etc.) plus
duke@435 34 // statistics for allocations from the list. The links between items
duke@435 35 // are not part of FreeList. The statistics are
jmasa@3730 36 // used to make decisions about coalescing Chunk's when they
duke@435 37 // are swept during collection.
duke@435 38 //
duke@435 39 // See the corresponding .cpp file for a description of the specifics
duke@435 40 // for that implementation.
duke@435 41
duke@435 42 class Mutex;
duke@435 43
jmasa@4196 44 template <class Chunk_t>
duke@435 45 class FreeList VALUE_OBJ_CLASS_SPEC {
duke@435 46 friend class CompactibleFreeListSpace;
dcubed@587 47 friend class VMStructs;
ysr@1580 48
ysr@1580 49 private:
jmasa@4196 50 Chunk_t* _head; // Head of list of free chunks
jmasa@4196 51 Chunk_t* _tail; // Tail of list of free chunks
ysr@1580 52 size_t _size; // Size in Heap words of each chunk
duke@435 53 ssize_t _count; // Number of entries in list
duke@435 54
jmasa@4196 55 protected:
duke@435 56
duke@435 57 #ifdef ASSERT
duke@435 58 Mutex* _protecting_lock;
duke@435 59 #endif
duke@435 60
duke@435 61 // Asserts false if the protecting lock (if any) is not held.
duke@435 62 void assert_proper_lock_protection_work() const PRODUCT_RETURN;
duke@435 63 void assert_proper_lock_protection() const {
duke@435 64 #ifdef ASSERT
duke@435 65 if (_protecting_lock != NULL)
duke@435 66 assert_proper_lock_protection_work();
duke@435 67 #endif
duke@435 68 }
duke@435 69
ysr@1580 70 void increment_count() {
ysr@1580 71 _count++;
ysr@1580 72 }
ysr@1580 73
duke@435 74 void decrement_count() {
duke@435 75 _count--;
ysr@447 76 assert(_count >= 0, "Count should not be negative");
ysr@447 77 }
duke@435 78
duke@435 79 public:
duke@435 80 // Constructor
duke@435 81 // Construct a list without any entries.
duke@435 82 FreeList();
duke@435 83 // Construct a list with "fc" as the first (and lone) entry in the list.
jmasa@4196 84 FreeList(Chunk_t* fc);
duke@435 85
jmasa@4196 86 // Do initialization
jmasa@4196 87 void initialize();
jmasa@4196 88
jmasa@4196 89 // Reset the head, tail, and count of a free list.
jmasa@4196 90 void reset();
duke@435 91
duke@435 92 // Declare the current free list to be protected by the given lock.
duke@435 93 #ifdef ASSERT
jmasa@4196 94 Mutex* protecting_lock() const { return _protecting_lock; }
jmasa@4196 95 void set_protecting_lock(Mutex* v) {
jmasa@4196 96 _protecting_lock = v;
duke@435 97 }
duke@435 98 #endif
duke@435 99
duke@435 100 // Accessors.
jmasa@4196 101 Chunk_t* head() const {
duke@435 102 assert_proper_lock_protection();
duke@435 103 return _head;
duke@435 104 }
jmasa@4196 105 void set_head(Chunk_t* v) {
duke@435 106 assert_proper_lock_protection();
duke@435 107 _head = v;
duke@435 108 assert(!_head || _head->size() == _size, "bad chunk size");
duke@435 109 }
duke@435 110 // Set the head of the list and set the prev field of non-null
duke@435 111 // values to NULL.
jmasa@4196 112 void link_head(Chunk_t* v);
duke@435 113
jmasa@4196 114 Chunk_t* tail() const {
duke@435 115 assert_proper_lock_protection();
duke@435 116 return _tail;
duke@435 117 }
jmasa@4196 118 void set_tail(Chunk_t* v) {
duke@435 119 assert_proper_lock_protection();
duke@435 120 _tail = v;
duke@435 121 assert(!_tail || _tail->size() == _size, "bad chunk size");
duke@435 122 }
duke@435 123 // Set the tail of the list and set the next field of non-null
duke@435 124 // values to NULL.
jmasa@4196 125 void link_tail(Chunk_t* v) {
duke@435 126 assert_proper_lock_protection();
duke@435 127 set_tail(v);
duke@435 128 if (v != NULL) {
jmasa@3732 129 v->clear_next();
duke@435 130 }
duke@435 131 }
duke@435 132
duke@435 133 // No locking checks in read-accessors: lock-free reads (only) are benign.
duke@435 134 // Readers are expected to have the lock if they are doing work that
duke@435 135 // requires atomicity guarantees in sections of code.
duke@435 136 size_t size() const {
duke@435 137 return _size;
duke@435 138 }
duke@435 139 void set_size(size_t v) {
duke@435 140 assert_proper_lock_protection();
duke@435 141 _size = v;
duke@435 142 }
jmasa@4196 143 ssize_t count() const { return _count; }
jmasa@4196 144 void set_count(ssize_t v) { _count = v;}
duke@435 145
jmasa@4196 146 size_t get_better_size() { return size(); }
duke@435 147
jmasa@4196 148 size_t returned_bytes() const { ShouldNotReachHere(); return 0; }
jmasa@4196 149 void set_returned_bytes(size_t v) {}
jmasa@4196 150 void increment_returned_bytes_by(size_t v) {}
duke@435 151
duke@435 152 // Unlink head of list and return it. Returns NULL if
duke@435 153 // the list is empty.
jmasa@4196 154 Chunk_t* get_chunk_at_head();
duke@435 155
duke@435 156 // Remove the first "n" or "count", whichever is smaller, chunks from the
duke@435 157 // list, setting "fl", which is required to be empty, to point to them.
jmasa@4196 158 void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl);
duke@435 159
duke@435 160 // Unlink this chunk from it's free list
jmasa@4196 161 void remove_chunk(Chunk_t* fc);
duke@435 162
duke@435 163 // Add this chunk to this free list.
jmasa@4196 164 void return_chunk_at_head(Chunk_t* fc);
jmasa@4196 165 void return_chunk_at_tail(Chunk_t* fc);
duke@435 166
duke@435 167 // Similar to returnChunk* but also records some diagnostic
duke@435 168 // information.
jmasa@4196 169 void return_chunk_at_head(Chunk_t* fc, bool record_return);
jmasa@4196 170 void return_chunk_at_tail(Chunk_t* fc, bool record_return);
duke@435 171
duke@435 172 // Prepend "fl" (whose size is required to be the same as that of "this")
duke@435 173 // to the front of "this" list.
jmasa@4196 174 void prepend(FreeList<Chunk_t>* fl);
duke@435 175
duke@435 176 // Verify that the chunk is in the list.
duke@435 177 // found. Return NULL if "fc" is not found.
jmasa@4196 178 bool verify_chunk_in_free_list(Chunk_t* fc) const;
ysr@447 179
ysr@1580 180 // Stats verification
jmasa@4196 181 // void verify_stats() const { ShouldNotReachHere(); };
ysr@1580 182
ysr@447 183 // Printing support
ysr@447 184 static void print_labels_on(outputStream* st, const char* c);
ysr@447 185 void print_on(outputStream* st, const char* c = NULL) const;
duke@435 186 };
stefank@2314 187
jmasa@3730 188 #endif // SHARE_VM_MEMORY_FREELIST_HPP

mercurial