src/share/vm/gc_implementation/concurrentMarkSweep/adaptiveFreeList.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/gc_implementation/concurrentMarkSweep/adaptiveFreeList.hpp	Wed Apr 27 01:25:04 2016 +0800
     1.3 @@ -0,0 +1,231 @@
     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_ADAPTIVEFREELIST_HPP
    1.29 +#define SHARE_VM_MEMORY_ADAPTIVEFREELIST_HPP
    1.30 +
    1.31 +#include "memory/freeList.hpp"
    1.32 +#include "gc_implementation/shared/allocationStats.hpp"
    1.33 +
    1.34 +class CompactibleFreeListSpace;
    1.35 +
    1.36 +// A class for maintaining a free list of Chunk's.  The FreeList
    1.37 +// maintains a the structure of the list (head, tail, etc.) plus
    1.38 +// statistics for allocations from the list.  The links between items
    1.39 +// are not part of FreeList.  The statistics are
    1.40 +// used to make decisions about coalescing Chunk's when they
    1.41 +// are swept during collection.
    1.42 +//
    1.43 +// See the corresponding .cpp file for a description of the specifics
    1.44 +// for that implementation.
    1.45 +
    1.46 +class Mutex;
    1.47 +
    1.48 +template <class Chunk>
    1.49 +class AdaptiveFreeList : public FreeList<Chunk> {
    1.50 +  friend class CompactibleFreeListSpace;
    1.51 +  friend class VMStructs;
    1.52 +  // friend class PrintTreeCensusClosure<Chunk, FreeList_t>;
    1.53 +
    1.54 +  size_t        _hint;          // next larger size list with a positive surplus
    1.55 +
    1.56 +  AllocationStats _allocation_stats; // allocation-related statistics
    1.57 +
    1.58 + public:
    1.59 +
    1.60 +  AdaptiveFreeList();
    1.61 +
    1.62 +  using FreeList<Chunk>::assert_proper_lock_protection;
    1.63 +#ifdef ASSERT
    1.64 +  using FreeList<Chunk>::protecting_lock;
    1.65 +#endif
    1.66 +  using FreeList<Chunk>::count;
    1.67 +  using FreeList<Chunk>::size;
    1.68 +  using FreeList<Chunk>::verify_chunk_in_free_list;
    1.69 +  using FreeList<Chunk>::getFirstNChunksFromList;
    1.70 +  using FreeList<Chunk>::print_on;
    1.71 +  void return_chunk_at_head(Chunk* fc, bool record_return);
    1.72 +  void return_chunk_at_head(Chunk* fc);
    1.73 +  void return_chunk_at_tail(Chunk* fc, bool record_return);
    1.74 +  void return_chunk_at_tail(Chunk* fc);
    1.75 +  using FreeList<Chunk>::return_chunk_at_tail;
    1.76 +  using FreeList<Chunk>::remove_chunk;
    1.77 +  using FreeList<Chunk>::prepend;
    1.78 +  using FreeList<Chunk>::print_labels_on;
    1.79 +  using FreeList<Chunk>::get_chunk_at_head;
    1.80 +
    1.81 +  // Initialize.
    1.82 +  void initialize();
    1.83 +
    1.84 +  // Reset the head, tail, hint, and count of a free list.
    1.85 +  void reset(size_t hint);
    1.86 +
    1.87 +  void assert_proper_lock_protection_work() const PRODUCT_RETURN;
    1.88 +
    1.89 +  void print_on(outputStream* st, const char* c = NULL) const;
    1.90 +
    1.91 +  size_t hint() const {
    1.92 +    return _hint;
    1.93 +  }
    1.94 +  void set_hint(size_t v) {
    1.95 +    assert_proper_lock_protection();
    1.96 +    assert(v == 0 || size() < v, "Bad hint");
    1.97 +    _hint = v;
    1.98 +  }
    1.99 +
   1.100 +  size_t get_better_size();
   1.101 +
   1.102 +  // Accessors for statistics
   1.103 +  void init_statistics(bool split_birth = false);
   1.104 +
   1.105 +  AllocationStats* allocation_stats() {
   1.106 +    assert_proper_lock_protection();
   1.107 +    return &_allocation_stats;
   1.108 +  }
   1.109 +
   1.110 +  ssize_t desired() const {
   1.111 +    return _allocation_stats.desired();
   1.112 +  }
   1.113 +  void set_desired(ssize_t v) {
   1.114 +    assert_proper_lock_protection();
   1.115 +    _allocation_stats.set_desired(v);
   1.116 +  }
   1.117 +  void compute_desired(float inter_sweep_current,
   1.118 +                       float inter_sweep_estimate,
   1.119 +                       float intra_sweep_estimate) {
   1.120 +    assert_proper_lock_protection();
   1.121 +    _allocation_stats.compute_desired(count(),
   1.122 +                                      inter_sweep_current,
   1.123 +                                      inter_sweep_estimate,
   1.124 +                                      intra_sweep_estimate);
   1.125 +  }
   1.126 +  ssize_t coal_desired() const {
   1.127 +    return _allocation_stats.coal_desired();
   1.128 +  }
   1.129 +  void set_coal_desired(ssize_t v) {
   1.130 +    assert_proper_lock_protection();
   1.131 +    _allocation_stats.set_coal_desired(v);
   1.132 +  }
   1.133 +
   1.134 +  ssize_t surplus() const {
   1.135 +    return _allocation_stats.surplus();
   1.136 +  }
   1.137 +  void set_surplus(ssize_t v) {
   1.138 +    assert_proper_lock_protection();
   1.139 +    _allocation_stats.set_surplus(v);
   1.140 +  }
   1.141 +  void increment_surplus() {
   1.142 +    assert_proper_lock_protection();
   1.143 +    _allocation_stats.increment_surplus();
   1.144 +  }
   1.145 +  void decrement_surplus() {
   1.146 +    assert_proper_lock_protection();
   1.147 +    _allocation_stats.decrement_surplus();
   1.148 +  }
   1.149 +
   1.150 +  ssize_t bfr_surp() const {
   1.151 +    return _allocation_stats.bfr_surp();
   1.152 +  }
   1.153 +  void set_bfr_surp(ssize_t v) {
   1.154 +    assert_proper_lock_protection();
   1.155 +    _allocation_stats.set_bfr_surp(v);
   1.156 +  }
   1.157 +  ssize_t prev_sweep() const {
   1.158 +    return _allocation_stats.prev_sweep();
   1.159 +  }
   1.160 +  void set_prev_sweep(ssize_t v) {
   1.161 +    assert_proper_lock_protection();
   1.162 +    _allocation_stats.set_prev_sweep(v);
   1.163 +  }
   1.164 +  ssize_t before_sweep() const {
   1.165 +    return _allocation_stats.before_sweep();
   1.166 +  }
   1.167 +  void set_before_sweep(ssize_t v) {
   1.168 +    assert_proper_lock_protection();
   1.169 +    _allocation_stats.set_before_sweep(v);
   1.170 +  }
   1.171 +
   1.172 +  ssize_t coal_births() const {
   1.173 +    return _allocation_stats.coal_births();
   1.174 +  }
   1.175 +  void set_coal_births(ssize_t v) {
   1.176 +    assert_proper_lock_protection();
   1.177 +    _allocation_stats.set_coal_births(v);
   1.178 +  }
   1.179 +  void increment_coal_births() {
   1.180 +    assert_proper_lock_protection();
   1.181 +    _allocation_stats.increment_coal_births();
   1.182 +  }
   1.183 +
   1.184 +  ssize_t coal_deaths() const {
   1.185 +    return _allocation_stats.coal_deaths();
   1.186 +  }
   1.187 +  void set_coal_deaths(ssize_t v) {
   1.188 +    assert_proper_lock_protection();
   1.189 +    _allocation_stats.set_coal_deaths(v);
   1.190 +  }
   1.191 +  void increment_coal_deaths() {
   1.192 +    assert_proper_lock_protection();
   1.193 +    _allocation_stats.increment_coal_deaths();
   1.194 +  }
   1.195 +
   1.196 +  ssize_t split_births() const {
   1.197 +    return _allocation_stats.split_births();
   1.198 +  }
   1.199 +  void set_split_births(ssize_t v) {
   1.200 +    assert_proper_lock_protection();
   1.201 +    _allocation_stats.set_split_births(v);
   1.202 +  }
   1.203 +  void increment_split_births() {
   1.204 +    assert_proper_lock_protection();
   1.205 +    _allocation_stats.increment_split_births();
   1.206 +  }
   1.207 +
   1.208 +  ssize_t split_deaths() const {
   1.209 +    return _allocation_stats.split_deaths();
   1.210 +  }
   1.211 +  void set_split_deaths(ssize_t v) {
   1.212 +    assert_proper_lock_protection();
   1.213 +    _allocation_stats.set_split_deaths(v);
   1.214 +  }
   1.215 +  void increment_split_deaths() {
   1.216 +    assert_proper_lock_protection();
   1.217 +    _allocation_stats.increment_split_deaths();
   1.218 +  }
   1.219 +
   1.220 +#ifndef PRODUCT
   1.221 +  // For debugging.  The "_returned_bytes" in all the lists are summed
   1.222 +  // and compared with the total number of bytes swept during a
   1.223 +  // collection.
   1.224 +  size_t returned_bytes() const { return _allocation_stats.returned_bytes(); }
   1.225 +  void set_returned_bytes(size_t v) { _allocation_stats.set_returned_bytes(v); }
   1.226 +  void increment_returned_bytes_by(size_t v) {
   1.227 +    _allocation_stats.set_returned_bytes(_allocation_stats.returned_bytes() + v);
   1.228 +  }
   1.229 +  // Stats verification
   1.230 +  void verify_stats() const;
   1.231 +#endif  // NOT PRODUCT
   1.232 +};
   1.233 +
   1.234 +#endif // SHARE_VM_MEMORY_ADAPTIVEFREELIST_HPP

mercurial