Path: blob/aarch64-shenandoah-jdk8u272-b10/hotspot/src/share/vm/memory/freeList.hpp
32285 views
/*1* Copyright (c) 2001, 2013, Oracle and/or its affiliates. All rights reserved.2* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.3*4* This code is free software; you can redistribute it and/or modify it5* under the terms of the GNU General Public License version 2 only, as6* published by the Free Software Foundation.7*8* This code is distributed in the hope that it will be useful, but WITHOUT9* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or10* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License11* version 2 for more details (a copy is included in the LICENSE file that12* accompanied this code).13*14* You should have received a copy of the GNU General Public License version15* 2 along with this work; if not, write to the Free Software Foundation,16* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.17*18* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA19* or visit www.oracle.com if you need additional information or have any20* questions.21*22*/2324#ifndef SHARE_VM_MEMORY_FREELIST_HPP25#define SHARE_VM_MEMORY_FREELIST_HPP2627#include "gc_implementation/shared/allocationStats.hpp"2829class CompactibleFreeListSpace;3031// A class for maintaining a free list of Chunk's. The FreeList32// maintains a the structure of the list (head, tail, etc.) plus33// statistics for allocations from the list. The links between items34// are not part of FreeList. The statistics are35// used to make decisions about coalescing Chunk's when they36// are swept during collection.37//38// See the corresponding .cpp file for a description of the specifics39// for that implementation.4041class Mutex;4243template <class Chunk_t>44class FreeList VALUE_OBJ_CLASS_SPEC {45friend class CompactibleFreeListSpace;46friend class VMStructs;4748private:49Chunk_t* _head; // Head of list of free chunks50Chunk_t* _tail; // Tail of list of free chunks51size_t _size; // Size in Heap words of each chunk52ssize_t _count; // Number of entries in list5354protected:5556#ifdef ASSERT57Mutex* _protecting_lock;58#endif5960// Asserts false if the protecting lock (if any) is not held.61void assert_proper_lock_protection_work() const PRODUCT_RETURN;62void assert_proper_lock_protection() const {63#ifdef ASSERT64if (_protecting_lock != NULL)65assert_proper_lock_protection_work();66#endif67}6869void increment_count() {70_count++;71}7273void decrement_count() {74_count--;75assert(_count >= 0, "Count should not be negative");76}7778public:79// Constructor80// Construct a list without any entries.81FreeList();8283// Do initialization84void initialize();8586// Reset the head, tail, and count of a free list.87void reset();8889// Declare the current free list to be protected by the given lock.90#ifdef ASSERT91Mutex* protecting_lock() const { return _protecting_lock; }92void set_protecting_lock(Mutex* v) {93_protecting_lock = v;94}95#endif9697// Accessors.98Chunk_t* head() const {99assert_proper_lock_protection();100return _head;101}102void set_head(Chunk_t* v) {103assert_proper_lock_protection();104_head = v;105assert(!_head || _head->size() == _size, "bad chunk size");106}107// Set the head of the list and set the prev field of non-null108// values to NULL.109void link_head(Chunk_t* v);110111Chunk_t* tail() const {112assert_proper_lock_protection();113return _tail;114}115void set_tail(Chunk_t* v) {116assert_proper_lock_protection();117_tail = v;118assert(!_tail || _tail->size() == _size, "bad chunk size");119}120// Set the tail of the list and set the next field of non-null121// values to NULL.122void link_tail(Chunk_t* v) {123assert_proper_lock_protection();124set_tail(v);125if (v != NULL) {126v->clear_next();127}128}129130// No locking checks in read-accessors: lock-free reads (only) are benign.131// Readers are expected to have the lock if they are doing work that132// requires atomicity guarantees in sections of code.133size_t size() const {134return _size;135}136void set_size(size_t v) {137assert_proper_lock_protection();138_size = v;139}140ssize_t count() const { return _count; }141void set_count(ssize_t v) { _count = v;}142143size_t get_better_size() { return size(); }144145size_t returned_bytes() const { ShouldNotReachHere(); return 0; }146void set_returned_bytes(size_t v) {}147void increment_returned_bytes_by(size_t v) {}148149// Unlink head of list and return it. Returns NULL if150// the list is empty.151Chunk_t* get_chunk_at_head();152153// Remove the first "n" or "count", whichever is smaller, chunks from the154// list, setting "fl", which is required to be empty, to point to them.155void getFirstNChunksFromList(size_t n, FreeList<Chunk_t>* fl);156157// Unlink this chunk from it's free list158void remove_chunk(Chunk_t* fc);159160// Add this chunk to this free list.161void return_chunk_at_head(Chunk_t* fc);162void return_chunk_at_tail(Chunk_t* fc);163164// Similar to returnChunk* but also records some diagnostic165// information.166void return_chunk_at_head(Chunk_t* fc, bool record_return);167void return_chunk_at_tail(Chunk_t* fc, bool record_return);168169// Prepend "fl" (whose size is required to be the same as that of "this")170// to the front of "this" list.171void prepend(FreeList<Chunk_t>* fl);172173// Verify that the chunk is in the list.174// found. Return NULL if "fc" is not found.175bool verify_chunk_in_free_list(Chunk_t* fc) const;176177// Printing support178static void print_labels_on(outputStream* st, const char* c);179void print_on(outputStream* st, const char* c = NULL) const;180};181182#endif // SHARE_VM_MEMORY_FREELIST_HPP183184185