ysr@777: /* xdono@905: * Copyright 2001-2008 Sun Microsystems, Inc. All Rights Reserved. ysr@777: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ysr@777: * ysr@777: * This code is free software; you can redistribute it and/or modify it ysr@777: * under the terms of the GNU General Public License version 2 only, as ysr@777: * published by the Free Software Foundation. ysr@777: * ysr@777: * This code is distributed in the hope that it will be useful, but WITHOUT ysr@777: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ysr@777: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ysr@777: * version 2 for more details (a copy is included in the LICENSE file that ysr@777: * accompanied this code). ysr@777: * ysr@777: * You should have received a copy of the GNU General Public License version ysr@777: * 2 along with this work; if not, write to the Free Software Foundation, ysr@777: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ysr@777: * ysr@777: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, ysr@777: * CA 95054 USA or visit www.sun.com if you need additional information or ysr@777: * have any questions. ysr@777: * ysr@777: */ ysr@777: ysr@777: class HeapRegion; ysr@777: class HeapRegionClosure; ysr@777: ysr@777: class HeapRegionSeq: public CHeapObj { ysr@777: ysr@777: // _regions is kept sorted by start address order, and no two regions are ysr@777: // overlapping. ysr@777: GrowableArray _regions; ysr@777: ysr@777: // The index in "_regions" at which to start the next allocation search. ysr@777: // (For efficiency only; private to obj_allocate after initialization.) ysr@777: int _alloc_search_start; ysr@777: ysr@777: // Attempts to allocate a block of the (assumed humongous) word_size, ysr@777: // starting at the region "ind". ysr@777: HeapWord* alloc_obj_from_region_index(int ind, size_t word_size); ysr@777: ysr@777: // Currently, we're choosing collection sets in a round-robin fashion, ysr@777: // starting here. ysr@777: int _next_rr_candidate; ysr@777: ysr@777: // The bottom address of the bottom-most region, or else NULL if there ysr@777: // are no regions in the sequence. ysr@777: char* _seq_bottom; ysr@777: ysr@777: public: ysr@777: // Initializes "this" to the empty sequence of regions. iveresov@828: HeapRegionSeq(const size_t max_size); ysr@777: ysr@777: // Adds "hr" to "this" sequence. Requires "hr" not to overlap with ysr@777: // any region already in "this". (Will perform better if regions are ysr@777: // inserted in ascending address order.) ysr@777: void insert(HeapRegion* hr); ysr@777: ysr@777: // Given a HeapRegion*, returns its index within _regions, ysr@777: // or returns -1 if not found. ysr@777: int find(HeapRegion* hr); ysr@777: ysr@777: // Requires the index to be valid, and return the region at the index. ysr@777: HeapRegion* at(size_t i) { return _regions.at((int)i); } ysr@777: ysr@777: // Return the number of regions in the sequence. ysr@777: size_t length(); ysr@777: ysr@777: // Returns the number of contiguous regions at the end of the sequence ysr@777: // that are available for allocation. ysr@777: size_t free_suffix(); ysr@777: ysr@777: // Requires "word_size" to be humongous (in the technical sense). If ysr@777: // possible, allocates a contiguous subsequence of the heap regions to ysr@777: // satisfy the allocation, and returns the address of the beginning of ysr@777: // that sequence, otherwise returns NULL. ysr@777: HeapWord* obj_allocate(size_t word_size); ysr@777: ysr@777: // Apply the "doHeapRegion" method of "blk" to all regions in "this", ysr@777: // in address order, terminating the iteration early ysr@777: // if the "doHeapRegion" method returns "true". ysr@777: void iterate(HeapRegionClosure* blk); ysr@777: ysr@777: // Apply the "doHeapRegion" method of "blk" to all regions in "this", ysr@777: // starting at "r" (or first region, if "r" is NULL), in a circular ysr@777: // manner, terminating the iteration early if the "doHeapRegion" method ysr@777: // returns "true". ysr@777: void iterate_from(HeapRegion* r, HeapRegionClosure* blk); ysr@777: ysr@777: // As above, but start from a given index in the sequence ysr@777: // instead of a given heap region. ysr@777: void iterate_from(int idx, HeapRegionClosure* blk); ysr@777: ysr@777: // Requires "shrink_bytes" to be a multiple of the page size and heap ysr@777: // region granularity. Deletes as many "rightmost" completely free heap ysr@777: // regions from the sequence as comprise shrink_bytes bytes. Returns the ysr@777: // MemRegion indicating the region those regions comprised, and sets ysr@777: // "num_regions_deleted" to the number of regions deleted. ysr@777: MemRegion shrink_by(size_t shrink_bytes, size_t& num_regions_deleted); ysr@777: ysr@777: // If "addr" falls within a region in the sequence, return that region, ysr@777: // or else NULL. ysr@777: HeapRegion* addr_to_region(const void* addr); ysr@777: ysr@777: void print(); ysr@777: apetrusenko@1112: // Prints out runs of empty regions. apetrusenko@1112: void print_empty_runs(); ysr@777: ysr@777: };