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