src/share/vm/memory/freeList.hpp

changeset 0
f90c822e73f8
child 6876
710a3c8b516e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/share/vm/memory/freeList.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,183 @@
     1.4 +/*
     1.5 + * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.
     1.6 + * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
     1.7 + *
     1.8 + * This code is free software; you can redistribute it and/or modify it
     1.9 + * under the terms of the GNU General Public License version 2 only, as
    1.10 + * published by the Free Software Foundation.
    1.11 + *
    1.12 + * This code is distributed in the hope that it will be useful, but WITHOUT
    1.13 + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
    1.14 + * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
    1.15 + * version 2 for more details (a copy is included in the LICENSE file that
    1.16 + * accompanied this code).
    1.17 + *
    1.18 + * You should have received a copy of the GNU General Public License version
    1.19 + * 2 along with this work; if not, write to the Free Software Foundation,
    1.20 + * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
    1.21 + *
    1.22 + * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
    1.23 + * or visit www.oracle.com if you need additional information or have any
    1.24 + * questions.
    1.25 + *
    1.26 + */
    1.27 +
    1.28 +#ifndef SHARE_VM_MEMORY_FREELIST_HPP
    1.29 +#define SHARE_VM_MEMORY_FREELIST_HPP
    1.30 +
    1.31 +#include "gc_implementation/shared/allocationStats.hpp"
    1.32 +
    1.33 +class CompactibleFreeListSpace;
    1.34 +
    1.35 +// A class for maintaining a free list of Chunk's.  The FreeList
    1.36 +// maintains a the structure of the list (head, tail, etc.) plus
    1.37 +// statistics for allocations from the list.  The links between items
    1.38 +// are not part of FreeList.  The statistics are
    1.39 +// used to make decisions about coalescing Chunk's when they
    1.40 +// are swept during collection.
    1.41 +//
    1.42 +// See the corresponding .cpp file for a description of the specifics
    1.43 +// for that implementation.
    1.44 +
    1.45 +class Mutex;
    1.46 +
    1.47 +template <class Chunk_t>
    1.48 +class FreeList VALUE_OBJ_CLASS_SPEC {
    1.49 +  friend class CompactibleFreeListSpace;
    1.50 +  friend class VMStructs;
    1.51 +
    1.52 + private:
    1.53 +  Chunk_t*      _head;          // Head of list of free chunks
    1.54 +  Chunk_t*      _tail;          // Tail of list of free chunks
    1.55 +  size_t        _size;          // Size in Heap words of each chunk
    1.56 +  ssize_t       _count;         // Number of entries in list
    1.57 +
    1.58 + protected:
    1.59 +
    1.60 +#ifdef ASSERT
    1.61 +  Mutex*        _protecting_lock;
    1.62 +#endif
    1.63 +
    1.64 +  // Asserts false if the protecting lock (if any) is not held.
    1.65 +  void assert_proper_lock_protection_work() const PRODUCT_RETURN;
    1.66 +  void assert_proper_lock_protection() const {
    1.67 +#ifdef ASSERT
    1.68 +    if (_protecting_lock != NULL)
    1.69 +      assert_proper_lock_protection_work();
    1.70 +#endif
    1.71 +  }
    1.72 +
    1.73 +  void increment_count()    {
    1.74 +    _count++;
    1.75 +  }
    1.76 +
    1.77 +  void decrement_count() {
    1.78 +    _count--;
    1.79 +    assert(_count >= 0, "Count should not be negative");
    1.80 +  }
    1.81 +
    1.82 + public:
    1.83 +  // Constructor
    1.84 +  // Construct a list without any entries.
    1.85 +  FreeList();
    1.86 +
    1.87 +  // Do initialization
    1.88 +  void initialize();
    1.89 +
    1.90 +  // Reset the head, tail, and count of a free list.
    1.91 +  void reset();
    1.92 +
    1.93 +  // Declare the current free list to be protected by the given lock.
    1.94 +#ifdef ASSERT
    1.95 +  Mutex* protecting_lock() const { return _protecting_lock; }
    1.96 +  void set_protecting_lock(Mutex* v) {
    1.97 +    _protecting_lock = v;
    1.98 +  }
    1.99 +#endif
   1.100 +
   1.101 +  // Accessors.
   1.102 +  Chunk_t* head() const {
   1.103 +    assert_proper_lock_protection();
   1.104 +    return _head;
   1.105 +  }
   1.106 +  void set_head(Chunk_t* v) {
   1.107 +    assert_proper_lock_protection();
   1.108 +    _head = v;
   1.109 +    assert(!_head || _head->size() == _size, "bad chunk size");
   1.110 +  }
   1.111 +  // Set the head of the list and set the prev field of non-null
   1.112 +  // values to NULL.
   1.113 +  void link_head(Chunk_t* v);
   1.114 +
   1.115 +  Chunk_t* tail() const {
   1.116 +    assert_proper_lock_protection();
   1.117 +    return _tail;
   1.118 +  }
   1.119 +  void set_tail(Chunk_t* v) {
   1.120 +    assert_proper_lock_protection();
   1.121 +    _tail = v;
   1.122 +    assert(!_tail || _tail->size() == _size, "bad chunk size");
   1.123 +  }
   1.124 +  // Set the tail of the list and set the next field of non-null
   1.125 +  // values to NULL.
   1.126 +  void link_tail(Chunk_t* v) {
   1.127 +    assert_proper_lock_protection();
   1.128 +    set_tail(v);
   1.129 +    if (v != NULL) {
   1.130 +      v->clear_next();
   1.131 +    }
   1.132 +  }
   1.133 +
   1.134 +  // No locking checks in read-accessors: lock-free reads (only) are benign.
   1.135 +  // Readers are expected to have the lock if they are doing work that
   1.136 +  // requires atomicity guarantees in sections of code.
   1.137 +  size_t size() const {
   1.138 +    return _size;
   1.139 +  }
   1.140 +  void set_size(size_t v) {
   1.141 +    assert_proper_lock_protection();
   1.142 +    _size = v;
   1.143 +  }
   1.144 +  ssize_t count() const { return _count; }
   1.145 +  void set_count(ssize_t v) { _count = v;}
   1.146 +
   1.147 +  size_t get_better_size() { return size(); }
   1.148 +
   1.149 +  size_t returned_bytes() const { ShouldNotReachHere(); return 0; }
   1.150 +  void set_returned_bytes(size_t v) {}
   1.151 +  void increment_returned_bytes_by(size_t v) {}
   1.152 +
   1.153 +  // Unlink head of list and return it.  Returns NULL if
   1.154 +  // the list is empty.
   1.155 +  Chunk_t* get_chunk_at_head();
   1.156 +
   1.157 +  // Remove the first "n" or "count", whichever is smaller, chunks from the
   1.158 +  // list, setting "fl", which is required to be empty, to point to them.
   1.159 +  void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl);
   1.160 +
   1.161 +  // Unlink this chunk from it's free list
   1.162 +  void remove_chunk(Chunk_t* fc);
   1.163 +
   1.164 +  // Add this chunk to this free list.
   1.165 +  void return_chunk_at_head(Chunk_t* fc);
   1.166 +  void return_chunk_at_tail(Chunk_t* fc);
   1.167 +
   1.168 +  // Similar to returnChunk* but also records some diagnostic
   1.169 +  // information.
   1.170 +  void return_chunk_at_head(Chunk_t* fc, bool record_return);
   1.171 +  void return_chunk_at_tail(Chunk_t* fc, bool record_return);
   1.172 +
   1.173 +  // Prepend "fl" (whose size is required to be the same as that of "this")
   1.174 +  // to the front of "this" list.
   1.175 +  void prepend(FreeList<Chunk_t>* fl);
   1.176 +
   1.177 +  // Verify that the chunk is in the list.
   1.178 +  // found.  Return NULL if "fc" is not found.
   1.179 +  bool verify_chunk_in_free_list(Chunk_t* fc) const;
   1.180 +
   1.181 +  // Printing support
   1.182 +  static void print_labels_on(outputStream* st, const char* c);
   1.183 +  void print_on(outputStream* st, const char* c = NULL) const;
   1.184 +};
   1.185 +
   1.186 +#endif // SHARE_VM_MEMORY_FREELIST_HPP

mercurial