jmasa@4196: /* mikael@6198: * Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved. jmasa@4196: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jmasa@4196: * jmasa@4196: * This code is free software; you can redistribute it and/or modify it jmasa@4196: * under the terms of the GNU General Public License version 2 only, as jmasa@4196: * published by the Free Software Foundation. jmasa@4196: * jmasa@4196: * This code is distributed in the hope that it will be useful, but WITHOUT jmasa@4196: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jmasa@4196: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jmasa@4196: * version 2 for more details (a copy is included in the LICENSE file that jmasa@4196: * accompanied this code). jmasa@4196: * jmasa@4196: * You should have received a copy of the GNU General Public License version jmasa@4196: * 2 along with this work; if not, write to the Free Software Foundation, jmasa@4196: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jmasa@4196: * jmasa@4196: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA jmasa@4196: * or visit www.oracle.com if you need additional information or have any jmasa@4196: * questions. jmasa@4196: * jmasa@4196: */ jmasa@4196: jmasa@4196: #ifndef SHARE_VM_MEMORY_ADAPTIVEFREELIST_HPP jmasa@4196: #define SHARE_VM_MEMORY_ADAPTIVEFREELIST_HPP jmasa@4196: jmasa@4196: #include "memory/freeList.hpp" jmasa@4196: #include "gc_implementation/shared/allocationStats.hpp" jmasa@4196: jmasa@4196: class CompactibleFreeListSpace; jmasa@4196: jmasa@4196: // A class for maintaining a free list of Chunk's. The FreeList jmasa@4196: // maintains a the structure of the list (head, tail, etc.) plus jmasa@4196: // statistics for allocations from the list. The links between items jmasa@4196: // are not part of FreeList. The statistics are jmasa@4196: // used to make decisions about coalescing Chunk's when they jmasa@4196: // are swept during collection. jmasa@4196: // jmasa@4196: // See the corresponding .cpp file for a description of the specifics jmasa@4196: // for that implementation. jmasa@4196: jmasa@4196: class Mutex; jmasa@4196: jmasa@4196: template jmasa@4196: class AdaptiveFreeList : public FreeList { jmasa@4196: friend class CompactibleFreeListSpace; jmasa@4196: friend class VMStructs; jmasa@4196: // friend class PrintTreeCensusClosure; jmasa@4196: jmasa@4196: size_t _hint; // next larger size list with a positive surplus jmasa@4196: jmasa@4196: AllocationStats _allocation_stats; // allocation-related statistics jmasa@4196: jmasa@4196: public: jmasa@4196: jmasa@4196: AdaptiveFreeList(); jmasa@4196: jmasa@4196: using FreeList::assert_proper_lock_protection; jmasa@4196: #ifdef ASSERT jmasa@4196: using FreeList::protecting_lock; jmasa@4196: #endif jmasa@4196: using FreeList::count; jmasa@4196: using FreeList::size; jmasa@4196: using FreeList::verify_chunk_in_free_list; jmasa@4196: using FreeList::getFirstNChunksFromList; jmasa@4196: using FreeList::print_on; jmasa@4196: void return_chunk_at_head(Chunk* fc, bool record_return); jmasa@4196: void return_chunk_at_head(Chunk* fc); jmasa@4196: void return_chunk_at_tail(Chunk* fc, bool record_return); jmasa@4196: void return_chunk_at_tail(Chunk* fc); jmasa@4196: using FreeList::return_chunk_at_tail; jmasa@4196: using FreeList::remove_chunk; jmasa@4196: using FreeList::prepend; jmasa@4196: using FreeList::print_labels_on; jmasa@4196: using FreeList::get_chunk_at_head; jmasa@4196: jmasa@4196: // Initialize. jmasa@4196: void initialize(); jmasa@4196: jmasa@4196: // Reset the head, tail, hint, and count of a free list. jmasa@4196: void reset(size_t hint); jmasa@4196: jmasa@4196: void assert_proper_lock_protection_work() const PRODUCT_RETURN; jmasa@4196: jmasa@4196: void print_on(outputStream* st, const char* c = NULL) const; jmasa@4196: jmasa@4196: size_t hint() const { jmasa@4196: return _hint; jmasa@4196: } jmasa@4196: void set_hint(size_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: assert(v == 0 || size() < v, "Bad hint"); jmasa@4196: _hint = v; jmasa@4196: } jmasa@4196: jmasa@4196: size_t get_better_size(); jmasa@4196: jmasa@4196: // Accessors for statistics jmasa@4196: void init_statistics(bool split_birth = false); jmasa@4196: jmasa@4196: AllocationStats* allocation_stats() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: return &_allocation_stats; jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t desired() const { jmasa@4196: return _allocation_stats.desired(); jmasa@4196: } jmasa@4196: void set_desired(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_desired(v); jmasa@4196: } jmasa@4196: void compute_desired(float inter_sweep_current, jmasa@4196: float inter_sweep_estimate, jmasa@4196: float intra_sweep_estimate) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.compute_desired(count(), jmasa@4196: inter_sweep_current, jmasa@4196: inter_sweep_estimate, jmasa@4196: intra_sweep_estimate); jmasa@4196: } jmasa@4196: ssize_t coal_desired() const { jmasa@4196: return _allocation_stats.coal_desired(); jmasa@4196: } jmasa@4196: void set_coal_desired(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_coal_desired(v); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t surplus() const { jmasa@4196: return _allocation_stats.surplus(); jmasa@4196: } jmasa@4196: void set_surplus(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_surplus(v); jmasa@4196: } jmasa@4196: void increment_surplus() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.increment_surplus(); jmasa@4196: } jmasa@4196: void decrement_surplus() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.decrement_surplus(); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t bfr_surp() const { jmasa@4196: return _allocation_stats.bfr_surp(); jmasa@4196: } jmasa@4196: void set_bfr_surp(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_bfr_surp(v); jmasa@4196: } jmasa@4196: ssize_t prev_sweep() const { jmasa@4196: return _allocation_stats.prev_sweep(); jmasa@4196: } jmasa@4196: void set_prev_sweep(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_prev_sweep(v); jmasa@4196: } jmasa@4196: ssize_t before_sweep() const { jmasa@4196: return _allocation_stats.before_sweep(); jmasa@4196: } jmasa@4196: void set_before_sweep(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_before_sweep(v); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t coal_births() const { jmasa@4196: return _allocation_stats.coal_births(); jmasa@4196: } jmasa@4196: void set_coal_births(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_coal_births(v); jmasa@4196: } jmasa@4196: void increment_coal_births() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.increment_coal_births(); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t coal_deaths() const { jmasa@4196: return _allocation_stats.coal_deaths(); jmasa@4196: } jmasa@4196: void set_coal_deaths(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_coal_deaths(v); jmasa@4196: } jmasa@4196: void increment_coal_deaths() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.increment_coal_deaths(); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t split_births() const { jmasa@4196: return _allocation_stats.split_births(); jmasa@4196: } jmasa@4196: void set_split_births(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_split_births(v); jmasa@4196: } jmasa@4196: void increment_split_births() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.increment_split_births(); jmasa@4196: } jmasa@4196: jmasa@4196: ssize_t split_deaths() const { jmasa@4196: return _allocation_stats.split_deaths(); jmasa@4196: } jmasa@4196: void set_split_deaths(ssize_t v) { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.set_split_deaths(v); jmasa@4196: } jmasa@4196: void increment_split_deaths() { jmasa@4196: assert_proper_lock_protection(); jmasa@4196: _allocation_stats.increment_split_deaths(); jmasa@4196: } jmasa@4196: jmasa@4196: #ifndef PRODUCT jmasa@4196: // For debugging. The "_returned_bytes" in all the lists are summed jmasa@4196: // and compared with the total number of bytes swept during a jmasa@4196: // collection. jmasa@4196: size_t returned_bytes() const { return _allocation_stats.returned_bytes(); } jmasa@4196: void set_returned_bytes(size_t v) { _allocation_stats.set_returned_bytes(v); } jmasa@4196: void increment_returned_bytes_by(size_t v) { jmasa@4196: _allocation_stats.set_returned_bytes(_allocation_stats.returned_bytes() + v); jmasa@4196: } jmasa@4196: // Stats verification jmasa@4196: void verify_stats() const; jmasa@4196: #endif // NOT PRODUCT jmasa@4196: }; jmasa@4196: jmasa@4196: #endif // SHARE_VM_MEMORY_ADAPTIVEFREELIST_HPP