src/share/vm/gc_implementation/shared/mutableNUMASpace.hpp

Thu, 04 Oct 2012 10:40:23 -0700

author
jmasa
date
Thu, 04 Oct 2012 10:40:23 -0700
changeset 4131
097d78aaf2b5
parent 3900
d2a62e0f25eb
child 4542
db9981fd3124
permissions
-rw-r--r--

7198873: NPG: VM Does not unload classes with UseConcMarkSweepGC
Reviewed-by: johnc, mgerdin, jwilhelm

duke@435 1 /*
brutisso@3711 2 * Copyright (c) 2006, 2012, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_MUTABLENUMASPACE_HPP
stefank@2314 26 #define SHARE_VM_GC_IMPLEMENTATION_SHARED_MUTABLENUMASPACE_HPP
stefank@2314 27
stefank@2314 28 #ifndef SERIALGC
stefank@2314 29 #include "gc_implementation/shared/gcUtil.hpp"
stefank@2314 30 #include "gc_implementation/shared/mutableSpace.hpp"
stefank@2314 31 #endif
stefank@2314 32
duke@435 33 /*
duke@435 34 * The NUMA-aware allocator (MutableNUMASpace) is basically a modification
duke@435 35 * of MutableSpace which preserves interfaces but implements different
duke@435 36 * functionality. The space is split into chunks for each locality group
duke@435 37 * (resizing for adaptive size policy is also supported). For each thread
duke@435 38 * allocations are performed in the chunk corresponding to the home locality
duke@435 39 * group of the thread. Whenever any chunk fills-in the young generation
duke@435 40 * collection occurs.
duke@435 41 * The chunks can be also be adaptively resized. The idea behind the adaptive
duke@435 42 * sizing is to reduce the loss of the space in the eden due to fragmentation.
duke@435 43 * The main cause of fragmentation is uneven allocation rates of threads.
duke@435 44 * The allocation rate difference between locality groups may be caused either by
duke@435 45 * application specifics or by uneven LWP distribution by the OS. Besides,
duke@435 46 * application can have less threads then the number of locality groups.
duke@435 47 * In order to resize the chunk we measure the allocation rate of the
duke@435 48 * application between collections. After that we reshape the chunks to reflect
duke@435 49 * the allocation rate pattern. The AdaptiveWeightedAverage exponentially
duke@435 50 * decaying average is used to smooth the measurements. The NUMASpaceResizeRate
duke@435 51 * parameter is used to control the adaptation speed by restricting the number of
duke@435 52 * bytes that can be moved during the adaptation phase.
duke@435 53 * Chunks may contain pages from a wrong locality group. The page-scanner has
duke@435 54 * been introduced to address the problem. Remote pages typically appear due to
duke@435 55 * the memory shortage in the target locality group. Besides Solaris would
duke@435 56 * allocate a large page from the remote locality group even if there are small
duke@435 57 * local pages available. The page-scanner scans the pages right after the
duke@435 58 * collection and frees remote pages in hope that subsequent reallocation would
duke@435 59 * be more successful. This approach proved to be useful on systems with high
duke@435 60 * load where multiple processes are competing for the memory.
duke@435 61 */
duke@435 62
duke@435 63 class MutableNUMASpace : public MutableSpace {
duke@435 64 friend class VMStructs;
duke@435 65
zgu@3900 66 class LGRPSpace : public CHeapObj<mtGC> {
duke@435 67 int _lgrp_id;
duke@435 68 MutableSpace* _space;
duke@435 69 MemRegion _invalid_region;
duke@435 70 AdaptiveWeightedAverage *_alloc_rate;
iveresov@808 71 bool _allocation_failed;
duke@435 72
duke@435 73 struct SpaceStats {
duke@435 74 size_t _local_space, _remote_space, _unbiased_space, _uncommited_space;
duke@435 75 size_t _large_pages, _small_pages;
duke@435 76
duke@435 77 SpaceStats() {
duke@435 78 _local_space = 0;
duke@435 79 _remote_space = 0;
duke@435 80 _unbiased_space = 0;
duke@435 81 _uncommited_space = 0;
duke@435 82 _large_pages = 0;
duke@435 83 _small_pages = 0;
duke@435 84 }
duke@435 85 };
duke@435 86
duke@435 87 SpaceStats _space_stats;
duke@435 88
duke@435 89 char* _last_page_scanned;
duke@435 90 char* last_page_scanned() { return _last_page_scanned; }
duke@435 91 void set_last_page_scanned(char* p) { _last_page_scanned = p; }
duke@435 92 public:
iveresov@970 93 LGRPSpace(int l, size_t alignment) : _lgrp_id(l), _last_page_scanned(NULL), _allocation_failed(false) {
iveresov@970 94 _space = new MutableSpace(alignment);
duke@435 95 _alloc_rate = new AdaptiveWeightedAverage(NUMAChunkResizeWeight);
duke@435 96 }
duke@435 97 ~LGRPSpace() {
duke@435 98 delete _space;
duke@435 99 delete _alloc_rate;
duke@435 100 }
duke@435 101
duke@435 102 void add_invalid_region(MemRegion r) {
duke@435 103 if (!_invalid_region.is_empty()) {
duke@435 104 _invalid_region.set_start(MIN2(_invalid_region.start(), r.start()));
duke@435 105 _invalid_region.set_end(MAX2(_invalid_region.end(), r.end()));
duke@435 106 } else {
duke@435 107 _invalid_region = r;
duke@435 108 }
duke@435 109 }
duke@435 110
duke@435 111 static bool equals(void* lgrp_id_value, LGRPSpace* p) {
duke@435 112 return *(int*)lgrp_id_value == p->lgrp_id();
duke@435 113 }
duke@435 114
iveresov@808 115 // Report a failed allocation.
iveresov@808 116 void set_allocation_failed() { _allocation_failed = true; }
iveresov@808 117
duke@435 118 void sample() {
iveresov@808 119 // If there was a failed allocation make allocation rate equal
iveresov@808 120 // to the size of the whole chunk. This ensures the progress of
iveresov@808 121 // the adaptation process.
iveresov@808 122 size_t alloc_rate_sample;
iveresov@808 123 if (_allocation_failed) {
iveresov@808 124 alloc_rate_sample = space()->capacity_in_bytes();
iveresov@808 125 _allocation_failed = false;
iveresov@808 126 } else {
iveresov@808 127 alloc_rate_sample = space()->used_in_bytes();
iveresov@808 128 }
iveresov@808 129 alloc_rate()->sample(alloc_rate_sample);
duke@435 130 }
duke@435 131
duke@435 132 MemRegion invalid_region() const { return _invalid_region; }
duke@435 133 void set_invalid_region(MemRegion r) { _invalid_region = r; }
duke@435 134 int lgrp_id() const { return _lgrp_id; }
duke@435 135 MutableSpace* space() const { return _space; }
duke@435 136 AdaptiveWeightedAverage* alloc_rate() const { return _alloc_rate; }
iveresov@703 137 void clear_alloc_rate() { _alloc_rate->clear(); }
duke@435 138 SpaceStats* space_stats() { return &_space_stats; }
duke@435 139 void clear_space_stats() { _space_stats = SpaceStats(); }
duke@435 140
duke@435 141 void accumulate_statistics(size_t page_size);
duke@435 142 void scan_pages(size_t page_size, size_t page_count);
duke@435 143 };
duke@435 144
duke@435 145 GrowableArray<LGRPSpace*>* _lgrp_spaces;
duke@435 146 size_t _page_size;
duke@435 147 unsigned _adaptation_cycles, _samples_count;
duke@435 148
duke@435 149 void set_page_size(size_t psz) { _page_size = psz; }
duke@435 150 size_t page_size() const { return _page_size; }
duke@435 151
duke@435 152 unsigned adaptation_cycles() { return _adaptation_cycles; }
duke@435 153 void set_adaptation_cycles(int v) { _adaptation_cycles = v; }
duke@435 154
duke@435 155 unsigned samples_count() { return _samples_count; }
duke@435 156 void increment_samples_count() { ++_samples_count; }
duke@435 157
duke@435 158 size_t _base_space_size;
duke@435 159 void set_base_space_size(size_t v) { _base_space_size = v; }
duke@435 160 size_t base_space_size() const { return _base_space_size; }
duke@435 161
duke@435 162 // Check if the NUMA topology has changed. Add and remove spaces if needed.
duke@435 163 // The update can be forced by setting the force parameter equal to true.
duke@435 164 bool update_layout(bool force);
iveresov@576 165 // Bias region towards the lgrp.
iveresov@576 166 void bias_region(MemRegion mr, int lgrp_id);
duke@435 167 // Free pages in a given region.
duke@435 168 void free_region(MemRegion mr);
duke@435 169 // Get current chunk size.
duke@435 170 size_t current_chunk_size(int i);
duke@435 171 // Get default chunk size (equally divide the space).
duke@435 172 size_t default_chunk_size();
duke@435 173 // Adapt the chunk size to follow the allocation rate.
duke@435 174 size_t adaptive_chunk_size(int i, size_t limit);
duke@435 175 // Scan and free invalid pages.
duke@435 176 void scan_pages(size_t page_count);
duke@435 177 // Return the bottom_region and the top_region. Align them to page_size() boundary.
duke@435 178 // |------------------new_region---------------------------------|
duke@435 179 // |----bottom_region--|---intersection---|------top_region------|
duke@435 180 void select_tails(MemRegion new_region, MemRegion intersection,
duke@435 181 MemRegion* bottom_region, MemRegion *top_region);
duke@435 182 // Try to merge the invalid region with the bottom or top region by decreasing
duke@435 183 // the intersection area. Return the invalid_region aligned to the page_size()
duke@435 184 // boundary if it's inside the intersection. Return non-empty invalid_region
duke@435 185 // if it lies inside the intersection (also page-aligned).
duke@435 186 // |------------------new_region---------------------------------|
duke@435 187 // |----------------|-------invalid---|--------------------------|
duke@435 188 // |----bottom_region--|---intersection---|------top_region------|
duke@435 189 void merge_regions(MemRegion new_region, MemRegion* intersection,
duke@435 190 MemRegion *invalid_region);
duke@435 191
duke@435 192 public:
duke@435 193 GrowableArray<LGRPSpace*>* lgrp_spaces() const { return _lgrp_spaces; }
iveresov@970 194 MutableNUMASpace(size_t alignment);
duke@435 195 virtual ~MutableNUMASpace();
duke@435 196 // Space initialization.
iveresov@970 197 virtual void initialize(MemRegion mr, bool clear_space, bool mangle_space, bool setup_pages = SetupPages);
duke@435 198 // Update space layout if necessary. Do all adaptive resizing job.
duke@435 199 virtual void update();
duke@435 200 // Update allocation rate averages.
duke@435 201 virtual void accumulate_statistics();
duke@435 202
jmasa@698 203 virtual void clear(bool mangle_space);
jmasa@698 204 virtual void mangle_unused_area() PRODUCT_RETURN;
jmasa@698 205 virtual void mangle_unused_area_complete() PRODUCT_RETURN;
jmasa@698 206 virtual void mangle_region(MemRegion mr) PRODUCT_RETURN;
jmasa@698 207 virtual void check_mangled_unused_area(HeapWord* limit) PRODUCT_RETURN;
jmasa@698 208 virtual void check_mangled_unused_area_complete() PRODUCT_RETURN;
jmasa@698 209 virtual void set_top_for_allocations(HeapWord* v) PRODUCT_RETURN;
jmasa@698 210 virtual void set_top_for_allocations() PRODUCT_RETURN;
jmasa@698 211
duke@435 212 virtual void ensure_parsability();
duke@435 213 virtual size_t used_in_words() const;
duke@435 214 virtual size_t free_in_words() const;
iveresov@808 215
iveresov@808 216 using MutableSpace::capacity_in_words;
iveresov@808 217 virtual size_t capacity_in_words(Thread* thr) const;
duke@435 218 virtual size_t tlab_capacity(Thread* thr) const;
duke@435 219 virtual size_t unsafe_max_tlab_alloc(Thread* thr) const;
duke@435 220
duke@435 221 // Allocation (return NULL if full)
duke@435 222 virtual HeapWord* allocate(size_t word_size);
duke@435 223 virtual HeapWord* cas_allocate(size_t word_size);
duke@435 224
duke@435 225 // Debugging
duke@435 226 virtual void print_on(outputStream* st) const;
duke@435 227 virtual void print_short_on(outputStream* st) const;
brutisso@3711 228 virtual void verify();
duke@435 229
duke@435 230 virtual void set_top(HeapWord* value);
duke@435 231 };
stefank@2314 232
stefank@2314 233 #endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_MUTABLENUMASPACE_HPP

mercurial