src/share/vm/memory/freeList.hpp

Wed, 27 Apr 2016 01:25:04 +0800

author
aoqi
date
Wed, 27 Apr 2016 01:25:04 +0800
changeset 0
f90c822e73f8
child 6876
710a3c8b516e
permissions
-rw-r--r--

Initial load
http://hg.openjdk.java.net/jdk8u/jdk8u/hotspot/
changeset: 6782:28b50d07f6f8
tag: jdk8u25-b17

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

mercurial