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

Fri, 27 Feb 2009 13:27:09 -0800

author
twisti
date
Fri, 27 Feb 2009 13:27:09 -0800
changeset 1040
98cb887364d3
parent 970
4e400c36026f
child 1063
7bb995fbd3c0
permissions
-rw-r--r--

6810672: Comment typos
Summary: I have collected some typos I have found while looking at the code.
Reviewed-by: kvn, never

duke@435 1
duke@435 2 /*
xdono@631 3 * Copyright 2006-2008 Sun Microsystems, Inc. All Rights Reserved.
duke@435 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 5 *
duke@435 6 * This code is free software; you can redistribute it and/or modify it
duke@435 7 * under the terms of the GNU General Public License version 2 only, as
duke@435 8 * published by the Free Software Foundation.
duke@435 9 *
duke@435 10 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 13 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 14 * accompanied this code).
duke@435 15 *
duke@435 16 * You should have received a copy of the GNU General Public License version
duke@435 17 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 19 *
duke@435 20 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
duke@435 21 * CA 95054 USA or visit www.sun.com if you need additional information or
duke@435 22 * have any questions.
duke@435 23 *
duke@435 24 */
duke@435 25
duke@435 26 # include "incls/_precompiled.incl"
duke@435 27 # include "incls/_mutableNUMASpace.cpp.incl"
duke@435 28
duke@435 29
iveresov@970 30 MutableNUMASpace::MutableNUMASpace(size_t alignment) : MutableSpace(alignment) {
duke@435 31 _lgrp_spaces = new (ResourceObj::C_HEAP) GrowableArray<LGRPSpace*>(0, true);
duke@435 32 _page_size = os::vm_page_size();
duke@435 33 _adaptation_cycles = 0;
duke@435 34 _samples_count = 0;
duke@435 35 update_layout(true);
duke@435 36 }
duke@435 37
duke@435 38 MutableNUMASpace::~MutableNUMASpace() {
duke@435 39 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 40 delete lgrp_spaces()->at(i);
duke@435 41 }
duke@435 42 delete lgrp_spaces();
duke@435 43 }
duke@435 44
jmasa@698 45 #ifndef PRODUCT
duke@435 46 void MutableNUMASpace::mangle_unused_area() {
jmasa@698 47 // This method should do nothing.
jmasa@698 48 // It can be called on a numa space during a full compaction.
duke@435 49 }
jmasa@698 50 void MutableNUMASpace::mangle_unused_area_complete() {
jmasa@698 51 // This method should do nothing.
jmasa@698 52 // It can be called on a numa space during a full compaction.
jmasa@698 53 }
jmasa@698 54 void MutableNUMASpace::mangle_region(MemRegion mr) {
jmasa@698 55 // This method should do nothing because numa spaces are not mangled.
jmasa@698 56 }
jmasa@698 57 void MutableNUMASpace::set_top_for_allocations(HeapWord* v) {
jmasa@698 58 assert(false, "Do not mangle MutableNUMASpace's");
jmasa@698 59 }
jmasa@698 60 void MutableNUMASpace::set_top_for_allocations() {
jmasa@698 61 // This method should do nothing.
jmasa@698 62 }
jmasa@698 63 void MutableNUMASpace::check_mangled_unused_area(HeapWord* limit) {
jmasa@698 64 // This method should do nothing.
jmasa@698 65 }
jmasa@698 66 void MutableNUMASpace::check_mangled_unused_area_complete() {
jmasa@698 67 // This method should do nothing.
jmasa@698 68 }
jmasa@698 69 #endif // NOT_PRODUCT
duke@435 70
duke@435 71 // There may be unallocated holes in the middle chunks
duke@435 72 // that should be filled with dead objects to ensure parseability.
duke@435 73 void MutableNUMASpace::ensure_parsability() {
duke@435 74 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 75 LGRPSpace *ls = lgrp_spaces()->at(i);
duke@435 76 MutableSpace *s = ls->space();
twisti@1040 77 if (s->top() < top()) { // For all spaces preceding the one containing top()
duke@435 78 if (s->free_in_words() > 0) {
iveresov@579 79 size_t area_touched_words = pointer_delta(s->end(), s->top());
jcoomes@916 80 CollectedHeap::fill_with_object(s->top(), area_touched_words);
duke@435 81 #ifndef ASSERT
duke@435 82 if (!ZapUnusedHeapArea) {
duke@435 83 area_touched_words = MIN2((size_t)align_object_size(typeArrayOopDesc::header_size(T_INT)),
duke@435 84 area_touched_words);
duke@435 85 }
duke@435 86 #endif
iveresov@576 87 if (!os::numa_has_static_binding()) {
iveresov@576 88 MemRegion invalid;
iveresov@576 89 HeapWord *crossing_start = (HeapWord*)round_to((intptr_t)s->top(), os::vm_page_size());
iveresov@576 90 HeapWord *crossing_end = (HeapWord*)round_to((intptr_t)(s->top() + area_touched_words),
iveresov@576 91 os::vm_page_size());
iveresov@576 92 if (crossing_start != crossing_end) {
iveresov@576 93 // If object header crossed a small page boundary we mark the area
iveresov@576 94 // as invalid rounding it to a page_size().
iveresov@576 95 HeapWord *start = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom());
iveresov@576 96 HeapWord *end = MIN2((HeapWord*)round_to((intptr_t)(s->top() + area_touched_words), page_size()),
iveresov@576 97 s->end());
iveresov@576 98 invalid = MemRegion(start, end);
iveresov@576 99 }
iveresov@576 100
iveresov@576 101 ls->add_invalid_region(invalid);
duke@435 102 }
duke@435 103 }
duke@435 104 } else {
iveresov@576 105 if (!os::numa_has_static_binding()) {
duke@435 106 #ifdef ASSERT
duke@435 107 MemRegion invalid(s->top(), s->end());
duke@435 108 ls->add_invalid_region(invalid);
iveresov@576 109 #else
iveresov@576 110 if (ZapUnusedHeapArea) {
iveresov@576 111 MemRegion invalid(s->top(), s->end());
iveresov@576 112 ls->add_invalid_region(invalid);
iveresov@579 113 } else {
iveresov@579 114 return;
iveresov@579 115 }
duke@435 116 #endif
iveresov@579 117 } else {
iveresov@579 118 return;
iveresov@576 119 }
duke@435 120 }
duke@435 121 }
duke@435 122 }
duke@435 123
duke@435 124 size_t MutableNUMASpace::used_in_words() const {
duke@435 125 size_t s = 0;
duke@435 126 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 127 s += lgrp_spaces()->at(i)->space()->used_in_words();
duke@435 128 }
duke@435 129 return s;
duke@435 130 }
duke@435 131
duke@435 132 size_t MutableNUMASpace::free_in_words() const {
duke@435 133 size_t s = 0;
duke@435 134 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 135 s += lgrp_spaces()->at(i)->space()->free_in_words();
duke@435 136 }
duke@435 137 return s;
duke@435 138 }
duke@435 139
duke@435 140
duke@435 141 size_t MutableNUMASpace::tlab_capacity(Thread *thr) const {
duke@435 142 guarantee(thr != NULL, "No thread");
duke@435 143 int lgrp_id = thr->lgrp_id();
iveresov@703 144 if (lgrp_id == -1) {
iveresov@703 145 // This case can occur after the topology of the system has
iveresov@703 146 // changed. Thread can change their location, the new home
iveresov@703 147 // group will be determined during the first allocation
iveresov@703 148 // attempt. For now we can safely assume that all spaces
iveresov@703 149 // have equal size because the whole space will be reinitialized.
iveresov@703 150 if (lgrp_spaces()->length() > 0) {
iveresov@703 151 return capacity_in_bytes() / lgrp_spaces()->length();
iveresov@703 152 } else {
iveresov@703 153 assert(false, "There should be at least one locality group");
iveresov@703 154 return 0;
iveresov@703 155 }
iveresov@703 156 }
iveresov@703 157 // That's the normal case, where we know the locality group of the thread.
duke@435 158 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
duke@435 159 if (i == -1) {
duke@435 160 return 0;
duke@435 161 }
duke@435 162 return lgrp_spaces()->at(i)->space()->capacity_in_bytes();
duke@435 163 }
duke@435 164
duke@435 165 size_t MutableNUMASpace::unsafe_max_tlab_alloc(Thread *thr) const {
iveresov@703 166 // Please see the comments for tlab_capacity().
duke@435 167 guarantee(thr != NULL, "No thread");
duke@435 168 int lgrp_id = thr->lgrp_id();
iveresov@703 169 if (lgrp_id == -1) {
iveresov@703 170 if (lgrp_spaces()->length() > 0) {
iveresov@703 171 return free_in_bytes() / lgrp_spaces()->length();
iveresov@703 172 } else {
iveresov@703 173 assert(false, "There should be at least one locality group");
iveresov@703 174 return 0;
iveresov@703 175 }
iveresov@703 176 }
duke@435 177 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
duke@435 178 if (i == -1) {
duke@435 179 return 0;
duke@435 180 }
duke@435 181 return lgrp_spaces()->at(i)->space()->free_in_bytes();
duke@435 182 }
duke@435 183
iveresov@808 184
iveresov@808 185 size_t MutableNUMASpace::capacity_in_words(Thread* thr) const {
iveresov@808 186 guarantee(thr != NULL, "No thread");
iveresov@808 187 int lgrp_id = thr->lgrp_id();
iveresov@808 188 if (lgrp_id == -1) {
iveresov@808 189 if (lgrp_spaces()->length() > 0) {
iveresov@808 190 return capacity_in_words() / lgrp_spaces()->length();
iveresov@808 191 } else {
iveresov@808 192 assert(false, "There should be at least one locality group");
iveresov@808 193 return 0;
iveresov@808 194 }
iveresov@808 195 }
iveresov@808 196 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
iveresov@808 197 if (i == -1) {
iveresov@808 198 return 0;
iveresov@808 199 }
iveresov@808 200 return lgrp_spaces()->at(i)->space()->capacity_in_words();
iveresov@808 201 }
iveresov@808 202
duke@435 203 // Check if the NUMA topology has changed. Add and remove spaces if needed.
duke@435 204 // The update can be forced by setting the force parameter equal to true.
duke@435 205 bool MutableNUMASpace::update_layout(bool force) {
duke@435 206 // Check if the topology had changed.
duke@435 207 bool changed = os::numa_topology_changed();
duke@435 208 if (force || changed) {
duke@435 209 // Compute lgrp intersection. Add/remove spaces.
duke@435 210 int lgrp_limit = (int)os::numa_get_groups_num();
duke@435 211 int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit);
duke@435 212 int lgrp_num = (int)os::numa_get_leaf_groups(lgrp_ids, lgrp_limit);
duke@435 213 assert(lgrp_num > 0, "There should be at least one locality group");
duke@435 214 // Add new spaces for the new nodes
duke@435 215 for (int i = 0; i < lgrp_num; i++) {
duke@435 216 bool found = false;
duke@435 217 for (int j = 0; j < lgrp_spaces()->length(); j++) {
duke@435 218 if (lgrp_spaces()->at(j)->lgrp_id() == lgrp_ids[i]) {
duke@435 219 found = true;
duke@435 220 break;
duke@435 221 }
duke@435 222 }
duke@435 223 if (!found) {
iveresov@970 224 lgrp_spaces()->append(new LGRPSpace(lgrp_ids[i], alignment()));
duke@435 225 }
duke@435 226 }
duke@435 227
duke@435 228 // Remove spaces for the removed nodes.
duke@435 229 for (int i = 0; i < lgrp_spaces()->length();) {
duke@435 230 bool found = false;
duke@435 231 for (int j = 0; j < lgrp_num; j++) {
duke@435 232 if (lgrp_spaces()->at(i)->lgrp_id() == lgrp_ids[j]) {
duke@435 233 found = true;
duke@435 234 break;
duke@435 235 }
duke@435 236 }
duke@435 237 if (!found) {
duke@435 238 delete lgrp_spaces()->at(i);
duke@435 239 lgrp_spaces()->remove_at(i);
duke@435 240 } else {
duke@435 241 i++;
duke@435 242 }
duke@435 243 }
duke@435 244
duke@435 245 FREE_C_HEAP_ARRAY(int, lgrp_ids);
duke@435 246
duke@435 247 if (changed) {
duke@435 248 for (JavaThread *thread = Threads::first(); thread; thread = thread->next()) {
duke@435 249 thread->set_lgrp_id(-1);
duke@435 250 }
duke@435 251 }
duke@435 252 return true;
duke@435 253 }
duke@435 254 return false;
duke@435 255 }
duke@435 256
duke@435 257 // Bias region towards the first-touching lgrp. Set the right page sizes.
iveresov@576 258 void MutableNUMASpace::bias_region(MemRegion mr, int lgrp_id) {
duke@435 259 HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size());
duke@435 260 HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size());
duke@435 261 if (end > start) {
duke@435 262 MemRegion aligned_region(start, end);
duke@435 263 assert((intptr_t)aligned_region.start() % page_size() == 0 &&
duke@435 264 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
duke@435 265 assert(region().contains(aligned_region), "Sanity");
iveresov@576 266 // First we tell the OS which page size we want in the given range. The underlying
iveresov@576 267 // large page can be broken down if we require small pages.
iveresov@576 268 os::realign_memory((char*)aligned_region.start(), aligned_region.byte_size(), page_size());
iveresov@576 269 // Then we uncommit the pages in the range.
duke@435 270 os::free_memory((char*)aligned_region.start(), aligned_region.byte_size());
iveresov@576 271 // And make them local/first-touch biased.
iveresov@576 272 os::numa_make_local((char*)aligned_region.start(), aligned_region.byte_size(), lgrp_id);
duke@435 273 }
duke@435 274 }
duke@435 275
duke@435 276 // Free all pages in the region.
duke@435 277 void MutableNUMASpace::free_region(MemRegion mr) {
duke@435 278 HeapWord *start = (HeapWord*)round_to((intptr_t)mr.start(), page_size());
duke@435 279 HeapWord *end = (HeapWord*)round_down((intptr_t)mr.end(), page_size());
duke@435 280 if (end > start) {
duke@435 281 MemRegion aligned_region(start, end);
duke@435 282 assert((intptr_t)aligned_region.start() % page_size() == 0 &&
duke@435 283 (intptr_t)aligned_region.byte_size() % page_size() == 0, "Bad alignment");
duke@435 284 assert(region().contains(aligned_region), "Sanity");
duke@435 285 os::free_memory((char*)aligned_region.start(), aligned_region.byte_size());
duke@435 286 }
duke@435 287 }
duke@435 288
duke@435 289 // Update space layout. Perform adaptation.
duke@435 290 void MutableNUMASpace::update() {
duke@435 291 if (update_layout(false)) {
duke@435 292 // If the topology has changed, make all chunks zero-sized.
iveresov@703 293 // And clear the alloc-rate statistics.
iveresov@703 294 // In future we may want to handle this more gracefully in order
iveresov@703 295 // to avoid the reallocation of the pages as much as possible.
duke@435 296 for (int i = 0; i < lgrp_spaces()->length(); i++) {
iveresov@703 297 LGRPSpace *ls = lgrp_spaces()->at(i);
iveresov@703 298 MutableSpace *s = ls->space();
duke@435 299 s->set_end(s->bottom());
duke@435 300 s->set_top(s->bottom());
iveresov@703 301 ls->clear_alloc_rate();
duke@435 302 }
jmasa@698 303 // A NUMA space is never mangled
jmasa@698 304 initialize(region(),
jmasa@698 305 SpaceDecorator::Clear,
jmasa@698 306 SpaceDecorator::DontMangle);
duke@435 307 } else {
duke@435 308 bool should_initialize = false;
iveresov@576 309 if (!os::numa_has_static_binding()) {
iveresov@576 310 for (int i = 0; i < lgrp_spaces()->length(); i++) {
iveresov@576 311 if (!lgrp_spaces()->at(i)->invalid_region().is_empty()) {
iveresov@576 312 should_initialize = true;
iveresov@576 313 break;
iveresov@576 314 }
duke@435 315 }
duke@435 316 }
duke@435 317
duke@435 318 if (should_initialize ||
duke@435 319 (UseAdaptiveNUMAChunkSizing && adaptation_cycles() < samples_count())) {
jmasa@698 320 // A NUMA space is never mangled
jmasa@698 321 initialize(region(),
jmasa@698 322 SpaceDecorator::Clear,
jmasa@698 323 SpaceDecorator::DontMangle);
duke@435 324 }
duke@435 325 }
duke@435 326
duke@435 327 if (NUMAStats) {
duke@435 328 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 329 lgrp_spaces()->at(i)->accumulate_statistics(page_size());
duke@435 330 }
duke@435 331 }
duke@435 332
duke@435 333 scan_pages(NUMAPageScanRate);
duke@435 334 }
duke@435 335
duke@435 336 // Scan pages. Free pages that have smaller size or wrong placement.
duke@435 337 void MutableNUMASpace::scan_pages(size_t page_count)
duke@435 338 {
duke@435 339 size_t pages_per_chunk = page_count / lgrp_spaces()->length();
duke@435 340 if (pages_per_chunk > 0) {
duke@435 341 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 342 LGRPSpace *ls = lgrp_spaces()->at(i);
duke@435 343 ls->scan_pages(page_size(), pages_per_chunk);
duke@435 344 }
duke@435 345 }
duke@435 346 }
duke@435 347
duke@435 348 // Accumulate statistics about the allocation rate of each lgrp.
duke@435 349 void MutableNUMASpace::accumulate_statistics() {
duke@435 350 if (UseAdaptiveNUMAChunkSizing) {
duke@435 351 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 352 lgrp_spaces()->at(i)->sample();
duke@435 353 }
duke@435 354 increment_samples_count();
duke@435 355 }
duke@435 356
duke@435 357 if (NUMAStats) {
duke@435 358 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 359 lgrp_spaces()->at(i)->accumulate_statistics(page_size());
duke@435 360 }
duke@435 361 }
duke@435 362 }
duke@435 363
duke@435 364 // Get the current size of a chunk.
duke@435 365 // This function computes the size of the chunk based on the
duke@435 366 // difference between chunk ends. This allows it to work correctly in
duke@435 367 // case the whole space is resized and during the process of adaptive
duke@435 368 // chunk resizing.
duke@435 369 size_t MutableNUMASpace::current_chunk_size(int i) {
duke@435 370 HeapWord *cur_end, *prev_end;
duke@435 371 if (i == 0) {
duke@435 372 prev_end = bottom();
duke@435 373 } else {
duke@435 374 prev_end = lgrp_spaces()->at(i - 1)->space()->end();
duke@435 375 }
duke@435 376 if (i == lgrp_spaces()->length() - 1) {
duke@435 377 cur_end = end();
duke@435 378 } else {
duke@435 379 cur_end = lgrp_spaces()->at(i)->space()->end();
duke@435 380 }
duke@435 381 if (cur_end > prev_end) {
duke@435 382 return pointer_delta(cur_end, prev_end, sizeof(char));
duke@435 383 }
duke@435 384 return 0;
duke@435 385 }
duke@435 386
duke@435 387 // Return the default chunk size by equally diving the space.
duke@435 388 // page_size() aligned.
duke@435 389 size_t MutableNUMASpace::default_chunk_size() {
duke@435 390 return base_space_size() / lgrp_spaces()->length() * page_size();
duke@435 391 }
duke@435 392
duke@435 393 // Produce a new chunk size. page_size() aligned.
iveresov@826 394 // This function is expected to be called on sequence of i's from 0 to
iveresov@826 395 // lgrp_spaces()->length().
duke@435 396 size_t MutableNUMASpace::adaptive_chunk_size(int i, size_t limit) {
duke@435 397 size_t pages_available = base_space_size();
duke@435 398 for (int j = 0; j < i; j++) {
duke@435 399 pages_available -= round_down(current_chunk_size(j), page_size()) / page_size();
duke@435 400 }
duke@435 401 pages_available -= lgrp_spaces()->length() - i - 1;
duke@435 402 assert(pages_available > 0, "No pages left");
duke@435 403 float alloc_rate = 0;
duke@435 404 for (int j = i; j < lgrp_spaces()->length(); j++) {
duke@435 405 alloc_rate += lgrp_spaces()->at(j)->alloc_rate()->average();
duke@435 406 }
duke@435 407 size_t chunk_size = 0;
duke@435 408 if (alloc_rate > 0) {
duke@435 409 LGRPSpace *ls = lgrp_spaces()->at(i);
iveresov@826 410 chunk_size = (size_t)(ls->alloc_rate()->average() / alloc_rate * pages_available) * page_size();
duke@435 411 }
duke@435 412 chunk_size = MAX2(chunk_size, page_size());
duke@435 413
duke@435 414 if (limit > 0) {
duke@435 415 limit = round_down(limit, page_size());
duke@435 416 if (chunk_size > current_chunk_size(i)) {
iveresov@897 417 size_t upper_bound = pages_available * page_size();
iveresov@897 418 if (upper_bound > limit &&
iveresov@897 419 current_chunk_size(i) < upper_bound - limit) {
iveresov@897 420 // The resulting upper bound should not exceed the available
iveresov@897 421 // amount of memory (pages_available * page_size()).
iveresov@897 422 upper_bound = current_chunk_size(i) + limit;
iveresov@897 423 }
iveresov@897 424 chunk_size = MIN2(chunk_size, upper_bound);
duke@435 425 } else {
iveresov@897 426 size_t lower_bound = page_size();
iveresov@897 427 if (current_chunk_size(i) > limit) { // lower_bound shouldn't underflow.
iveresov@897 428 lower_bound = current_chunk_size(i) - limit;
iveresov@897 429 }
iveresov@897 430 chunk_size = MAX2(chunk_size, lower_bound);
duke@435 431 }
duke@435 432 }
duke@435 433 assert(chunk_size <= pages_available * page_size(), "Chunk size out of range");
duke@435 434 return chunk_size;
duke@435 435 }
duke@435 436
duke@435 437
duke@435 438 // Return the bottom_region and the top_region. Align them to page_size() boundary.
duke@435 439 // |------------------new_region---------------------------------|
duke@435 440 // |----bottom_region--|---intersection---|------top_region------|
duke@435 441 void MutableNUMASpace::select_tails(MemRegion new_region, MemRegion intersection,
duke@435 442 MemRegion* bottom_region, MemRegion *top_region) {
duke@435 443 // Is there bottom?
duke@435 444 if (new_region.start() < intersection.start()) { // Yes
duke@435 445 // Try to coalesce small pages into a large one.
iveresov@970 446 if (UseLargePages && page_size() >= alignment()) {
iveresov@970 447 HeapWord* p = (HeapWord*)round_to((intptr_t) intersection.start(), alignment());
duke@435 448 if (new_region.contains(p)
iveresov@970 449 && pointer_delta(p, new_region.start(), sizeof(char)) >= alignment()) {
duke@435 450 if (intersection.contains(p)) {
duke@435 451 intersection = MemRegion(p, intersection.end());
duke@435 452 } else {
duke@435 453 intersection = MemRegion(p, p);
duke@435 454 }
duke@435 455 }
duke@435 456 }
duke@435 457 *bottom_region = MemRegion(new_region.start(), intersection.start());
duke@435 458 } else {
duke@435 459 *bottom_region = MemRegion();
duke@435 460 }
duke@435 461
duke@435 462 // Is there top?
duke@435 463 if (intersection.end() < new_region.end()) { // Yes
duke@435 464 // Try to coalesce small pages into a large one.
iveresov@970 465 if (UseLargePages && page_size() >= alignment()) {
iveresov@970 466 HeapWord* p = (HeapWord*)round_down((intptr_t) intersection.end(), alignment());
duke@435 467 if (new_region.contains(p)
iveresov@970 468 && pointer_delta(new_region.end(), p, sizeof(char)) >= alignment()) {
duke@435 469 if (intersection.contains(p)) {
duke@435 470 intersection = MemRegion(intersection.start(), p);
duke@435 471 } else {
duke@435 472 intersection = MemRegion(p, p);
duke@435 473 }
duke@435 474 }
duke@435 475 }
duke@435 476 *top_region = MemRegion(intersection.end(), new_region.end());
duke@435 477 } else {
duke@435 478 *top_region = MemRegion();
duke@435 479 }
duke@435 480 }
duke@435 481
duke@435 482 // Try to merge the invalid region with the bottom or top region by decreasing
duke@435 483 // the intersection area. Return the invalid_region aligned to the page_size()
duke@435 484 // boundary if it's inside the intersection. Return non-empty invalid_region
duke@435 485 // if it lies inside the intersection (also page-aligned).
duke@435 486 // |------------------new_region---------------------------------|
duke@435 487 // |----------------|-------invalid---|--------------------------|
duke@435 488 // |----bottom_region--|---intersection---|------top_region------|
duke@435 489 void MutableNUMASpace::merge_regions(MemRegion new_region, MemRegion* intersection,
duke@435 490 MemRegion *invalid_region) {
duke@435 491 if (intersection->start() >= invalid_region->start() && intersection->contains(invalid_region->end())) {
duke@435 492 *intersection = MemRegion(invalid_region->end(), intersection->end());
duke@435 493 *invalid_region = MemRegion();
duke@435 494 } else
duke@435 495 if (intersection->end() <= invalid_region->end() && intersection->contains(invalid_region->start())) {
duke@435 496 *intersection = MemRegion(intersection->start(), invalid_region->start());
duke@435 497 *invalid_region = MemRegion();
duke@435 498 } else
duke@435 499 if (intersection->equals(*invalid_region) || invalid_region->contains(*intersection)) {
duke@435 500 *intersection = MemRegion(new_region.start(), new_region.start());
duke@435 501 *invalid_region = MemRegion();
duke@435 502 } else
duke@435 503 if (intersection->contains(invalid_region)) {
duke@435 504 // That's the only case we have to make an additional bias_region() call.
duke@435 505 HeapWord* start = invalid_region->start();
duke@435 506 HeapWord* end = invalid_region->end();
iveresov@970 507 if (UseLargePages && page_size() >= alignment()) {
iveresov@970 508 HeapWord *p = (HeapWord*)round_down((intptr_t) start, alignment());
duke@435 509 if (new_region.contains(p)) {
duke@435 510 start = p;
duke@435 511 }
iveresov@970 512 p = (HeapWord*)round_to((intptr_t) end, alignment());
duke@435 513 if (new_region.contains(end)) {
duke@435 514 end = p;
duke@435 515 }
duke@435 516 }
duke@435 517 if (intersection->start() > start) {
duke@435 518 *intersection = MemRegion(start, intersection->end());
duke@435 519 }
duke@435 520 if (intersection->end() < end) {
duke@435 521 *intersection = MemRegion(intersection->start(), end);
duke@435 522 }
duke@435 523 *invalid_region = MemRegion(start, end);
duke@435 524 }
duke@435 525 }
duke@435 526
jmasa@698 527 void MutableNUMASpace::initialize(MemRegion mr,
jmasa@698 528 bool clear_space,
iveresov@970 529 bool mangle_space,
iveresov@970 530 bool setup_pages) {
duke@435 531 assert(clear_space, "Reallocation will destory data!");
duke@435 532 assert(lgrp_spaces()->length() > 0, "There should be at least one space");
duke@435 533
duke@435 534 MemRegion old_region = region(), new_region;
duke@435 535 set_bottom(mr.start());
duke@435 536 set_end(mr.end());
jmasa@698 537 // Must always clear the space
jmasa@698 538 clear(SpaceDecorator::DontMangle);
duke@435 539
duke@435 540 // Compute chunk sizes
duke@435 541 size_t prev_page_size = page_size();
iveresov@970 542 set_page_size(UseLargePages ? alignment() : os::vm_page_size());
duke@435 543 HeapWord* rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size());
duke@435 544 HeapWord* rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size());
duke@435 545 size_t base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
duke@435 546
duke@435 547 // Try small pages if the chunk size is too small
duke@435 548 if (base_space_size_pages / lgrp_spaces()->length() == 0
duke@435 549 && page_size() > (size_t)os::vm_page_size()) {
duke@435 550 set_page_size(os::vm_page_size());
duke@435 551 rounded_bottom = (HeapWord*)round_to((intptr_t) bottom(), page_size());
duke@435 552 rounded_end = (HeapWord*)round_down((intptr_t) end(), page_size());
duke@435 553 base_space_size_pages = pointer_delta(rounded_end, rounded_bottom, sizeof(char)) / page_size();
duke@435 554 }
duke@435 555 guarantee(base_space_size_pages / lgrp_spaces()->length() > 0, "Space too small");
duke@435 556 set_base_space_size(base_space_size_pages);
duke@435 557
duke@435 558 // Handle space resize
duke@435 559 MemRegion top_region, bottom_region;
duke@435 560 if (!old_region.equals(region())) {
duke@435 561 new_region = MemRegion(rounded_bottom, rounded_end);
duke@435 562 MemRegion intersection = new_region.intersection(old_region);
duke@435 563 if (intersection.start() == NULL ||
duke@435 564 intersection.end() == NULL ||
duke@435 565 prev_page_size > page_size()) { // If the page size got smaller we have to change
duke@435 566 // the page size preference for the whole space.
duke@435 567 intersection = MemRegion(new_region.start(), new_region.start());
duke@435 568 }
duke@435 569 select_tails(new_region, intersection, &bottom_region, &top_region);
iveresov@576 570 bias_region(bottom_region, lgrp_spaces()->at(0)->lgrp_id());
iveresov@576 571 bias_region(top_region, lgrp_spaces()->at(lgrp_spaces()->length() - 1)->lgrp_id());
duke@435 572 }
duke@435 573
duke@435 574 // Check if the space layout has changed significantly?
duke@435 575 // This happens when the space has been resized so that either head or tail
duke@435 576 // chunk became less than a page.
duke@435 577 bool layout_valid = UseAdaptiveNUMAChunkSizing &&
duke@435 578 current_chunk_size(0) > page_size() &&
duke@435 579 current_chunk_size(lgrp_spaces()->length() - 1) > page_size();
duke@435 580
duke@435 581
duke@435 582 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 583 LGRPSpace *ls = lgrp_spaces()->at(i);
duke@435 584 MutableSpace *s = ls->space();
duke@435 585 old_region = s->region();
duke@435 586
duke@435 587 size_t chunk_byte_size = 0, old_chunk_byte_size = 0;
duke@435 588 if (i < lgrp_spaces()->length() - 1) {
duke@435 589 if (!UseAdaptiveNUMAChunkSizing ||
duke@435 590 (UseAdaptiveNUMAChunkSizing && NUMAChunkResizeWeight == 0) ||
duke@435 591 samples_count() < AdaptiveSizePolicyReadyThreshold) {
duke@435 592 // No adaptation. Divide the space equally.
duke@435 593 chunk_byte_size = default_chunk_size();
duke@435 594 } else
duke@435 595 if (!layout_valid || NUMASpaceResizeRate == 0) {
duke@435 596 // Fast adaptation. If no space resize rate is set, resize
duke@435 597 // the chunks instantly.
duke@435 598 chunk_byte_size = adaptive_chunk_size(i, 0);
duke@435 599 } else {
duke@435 600 // Slow adaptation. Resize the chunks moving no more than
duke@435 601 // NUMASpaceResizeRate bytes per collection.
duke@435 602 size_t limit = NUMASpaceResizeRate /
duke@435 603 (lgrp_spaces()->length() * (lgrp_spaces()->length() + 1) / 2);
duke@435 604 chunk_byte_size = adaptive_chunk_size(i, MAX2(limit * (i + 1), page_size()));
duke@435 605 }
duke@435 606
duke@435 607 assert(chunk_byte_size >= page_size(), "Chunk size too small");
duke@435 608 assert(chunk_byte_size <= capacity_in_bytes(), "Sanity check");
duke@435 609 }
duke@435 610
duke@435 611 if (i == 0) { // Bottom chunk
duke@435 612 if (i != lgrp_spaces()->length() - 1) {
duke@435 613 new_region = MemRegion(bottom(), rounded_bottom + (chunk_byte_size >> LogHeapWordSize));
duke@435 614 } else {
duke@435 615 new_region = MemRegion(bottom(), end());
duke@435 616 }
duke@435 617 } else
duke@435 618 if (i < lgrp_spaces()->length() - 1) { // Middle chunks
duke@435 619 MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
duke@435 620 new_region = MemRegion(ps->end(),
duke@435 621 ps->end() + (chunk_byte_size >> LogHeapWordSize));
duke@435 622 } else { // Top chunk
duke@435 623 MutableSpace *ps = lgrp_spaces()->at(i - 1)->space();
duke@435 624 new_region = MemRegion(ps->end(), end());
duke@435 625 }
duke@435 626 guarantee(region().contains(new_region), "Region invariant");
duke@435 627
duke@435 628
duke@435 629 // The general case:
duke@435 630 // |---------------------|--invalid---|--------------------------|
duke@435 631 // |------------------new_region---------------------------------|
duke@435 632 // |----bottom_region--|---intersection---|------top_region------|
duke@435 633 // |----old_region----|
duke@435 634 // The intersection part has all pages in place we don't need to migrate them.
duke@435 635 // Pages for the top and bottom part should be freed and then reallocated.
duke@435 636
duke@435 637 MemRegion intersection = old_region.intersection(new_region);
duke@435 638
duke@435 639 if (intersection.start() == NULL || intersection.end() == NULL) {
duke@435 640 intersection = MemRegion(new_region.start(), new_region.start());
duke@435 641 }
duke@435 642
iveresov@576 643 if (!os::numa_has_static_binding()) {
iveresov@576 644 MemRegion invalid_region = ls->invalid_region().intersection(new_region);
iveresov@576 645 // Invalid region is a range of memory that could've possibly
iveresov@576 646 // been allocated on the other node. That's relevant only on Solaris where
iveresov@576 647 // there is no static memory binding.
iveresov@576 648 if (!invalid_region.is_empty()) {
iveresov@576 649 merge_regions(new_region, &intersection, &invalid_region);
iveresov@576 650 free_region(invalid_region);
iveresov@576 651 ls->set_invalid_region(MemRegion());
iveresov@576 652 }
duke@435 653 }
iveresov@576 654
duke@435 655 select_tails(new_region, intersection, &bottom_region, &top_region);
iveresov@576 656
iveresov@576 657 if (!os::numa_has_static_binding()) {
iveresov@576 658 // If that's a system with the first-touch policy then it's enough
iveresov@576 659 // to free the pages.
iveresov@576 660 free_region(bottom_region);
iveresov@576 661 free_region(top_region);
iveresov@576 662 } else {
iveresov@576 663 // In a system with static binding we have to change the bias whenever
iveresov@576 664 // we reshape the heap.
iveresov@576 665 bias_region(bottom_region, ls->lgrp_id());
iveresov@576 666 bias_region(top_region, ls->lgrp_id());
iveresov@576 667 }
duke@435 668
jmasa@698 669 // Clear space (set top = bottom) but never mangle.
iveresov@970 670 s->initialize(new_region, SpaceDecorator::Clear, SpaceDecorator::DontMangle, MutableSpace::DontSetupPages);
duke@435 671
duke@435 672 set_adaptation_cycles(samples_count());
duke@435 673 }
duke@435 674 }
duke@435 675
duke@435 676 // Set the top of the whole space.
duke@435 677 // Mark the the holes in chunks below the top() as invalid.
duke@435 678 void MutableNUMASpace::set_top(HeapWord* value) {
duke@435 679 bool found_top = false;
iveresov@625 680 for (int i = 0; i < lgrp_spaces()->length();) {
duke@435 681 LGRPSpace *ls = lgrp_spaces()->at(i);
duke@435 682 MutableSpace *s = ls->space();
duke@435 683 HeapWord *top = MAX2((HeapWord*)round_down((intptr_t)s->top(), page_size()), s->bottom());
duke@435 684
duke@435 685 if (s->contains(value)) {
iveresov@625 686 // Check if setting the chunk's top to a given value would create a hole less than
iveresov@625 687 // a minimal object; assuming that's not the last chunk in which case we don't care.
iveresov@625 688 if (i < lgrp_spaces()->length() - 1) {
iveresov@625 689 size_t remainder = pointer_delta(s->end(), value);
jcoomes@916 690 const size_t min_fill_size = CollectedHeap::min_fill_size();
jcoomes@916 691 if (remainder < min_fill_size && remainder > 0) {
jcoomes@916 692 // Add a minimum size filler object; it will cross the chunk boundary.
jcoomes@916 693 CollectedHeap::fill_with_object(value, min_fill_size);
jcoomes@916 694 value += min_fill_size;
iveresov@625 695 assert(!s->contains(value), "Should be in the next chunk");
iveresov@625 696 // Restart the loop from the same chunk, since the value has moved
iveresov@625 697 // to the next one.
iveresov@625 698 continue;
iveresov@625 699 }
iveresov@625 700 }
iveresov@625 701
iveresov@576 702 if (!os::numa_has_static_binding() && top < value && top < s->end()) {
duke@435 703 ls->add_invalid_region(MemRegion(top, value));
duke@435 704 }
duke@435 705 s->set_top(value);
duke@435 706 found_top = true;
duke@435 707 } else {
duke@435 708 if (found_top) {
duke@435 709 s->set_top(s->bottom());
duke@435 710 } else {
iveresov@576 711 if (!os::numa_has_static_binding() && top < s->end()) {
iveresov@576 712 ls->add_invalid_region(MemRegion(top, s->end()));
iveresov@576 713 }
iveresov@576 714 s->set_top(s->end());
duke@435 715 }
duke@435 716 }
iveresov@625 717 i++;
duke@435 718 }
duke@435 719 MutableSpace::set_top(value);
duke@435 720 }
duke@435 721
jmasa@698 722 void MutableNUMASpace::clear(bool mangle_space) {
duke@435 723 MutableSpace::set_top(bottom());
duke@435 724 for (int i = 0; i < lgrp_spaces()->length(); i++) {
jmasa@698 725 // Never mangle NUMA spaces because the mangling will
jmasa@698 726 // bind the memory to a possibly unwanted lgroup.
jmasa@698 727 lgrp_spaces()->at(i)->space()->clear(SpaceDecorator::DontMangle);
duke@435 728 }
duke@435 729 }
duke@435 730
iveresov@576 731 /*
iveresov@576 732 Linux supports static memory binding, therefore the most part of the
iveresov@576 733 logic dealing with the possible invalid page allocation is effectively
iveresov@576 734 disabled. Besides there is no notion of the home node in Linux. A
iveresov@576 735 thread is allowed to migrate freely. Although the scheduler is rather
iveresov@576 736 reluctant to move threads between the nodes. We check for the current
iveresov@576 737 node every allocation. And with a high probability a thread stays on
iveresov@576 738 the same node for some time allowing local access to recently allocated
iveresov@576 739 objects.
iveresov@576 740 */
iveresov@576 741
duke@435 742 HeapWord* MutableNUMASpace::allocate(size_t size) {
iveresov@576 743 Thread* thr = Thread::current();
iveresov@576 744 int lgrp_id = thr->lgrp_id();
iveresov@576 745 if (lgrp_id == -1 || !os::numa_has_group_homing()) {
duke@435 746 lgrp_id = os::numa_get_group_id();
iveresov@576 747 thr->set_lgrp_id(lgrp_id);
duke@435 748 }
duke@435 749
duke@435 750 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
duke@435 751
duke@435 752 // It is possible that a new CPU has been hotplugged and
duke@435 753 // we haven't reshaped the space accordingly.
duke@435 754 if (i == -1) {
duke@435 755 i = os::random() % lgrp_spaces()->length();
duke@435 756 }
duke@435 757
iveresov@808 758 LGRPSpace* ls = lgrp_spaces()->at(i);
iveresov@808 759 MutableSpace *s = ls->space();
duke@435 760 HeapWord *p = s->allocate(size);
duke@435 761
iveresov@579 762 if (p != NULL) {
iveresov@579 763 size_t remainder = s->free_in_words();
iveresov@579 764 if (remainder < (size_t)oopDesc::header_size() && remainder > 0) {
iveresov@579 765 s->set_top(s->top() - size);
iveresov@579 766 p = NULL;
iveresov@579 767 }
duke@435 768 }
duke@435 769 if (p != NULL) {
duke@435 770 if (top() < s->top()) { // Keep _top updated.
duke@435 771 MutableSpace::set_top(s->top());
duke@435 772 }
duke@435 773 }
iveresov@576 774 // Make the page allocation happen here if there is no static binding..
iveresov@576 775 if (p != NULL && !os::numa_has_static_binding()) {
duke@435 776 for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
duke@435 777 *(int*)i = 0;
duke@435 778 }
duke@435 779 }
iveresov@808 780 if (p == NULL) {
iveresov@808 781 ls->set_allocation_failed();
iveresov@808 782 }
duke@435 783 return p;
duke@435 784 }
duke@435 785
duke@435 786 // This version is lock-free.
duke@435 787 HeapWord* MutableNUMASpace::cas_allocate(size_t size) {
iveresov@576 788 Thread* thr = Thread::current();
iveresov@576 789 int lgrp_id = thr->lgrp_id();
iveresov@576 790 if (lgrp_id == -1 || !os::numa_has_group_homing()) {
duke@435 791 lgrp_id = os::numa_get_group_id();
iveresov@576 792 thr->set_lgrp_id(lgrp_id);
duke@435 793 }
duke@435 794
duke@435 795 int i = lgrp_spaces()->find(&lgrp_id, LGRPSpace::equals);
duke@435 796 // It is possible that a new CPU has been hotplugged and
duke@435 797 // we haven't reshaped the space accordingly.
duke@435 798 if (i == -1) {
duke@435 799 i = os::random() % lgrp_spaces()->length();
duke@435 800 }
iveresov@808 801 LGRPSpace *ls = lgrp_spaces()->at(i);
iveresov@808 802 MutableSpace *s = ls->space();
duke@435 803 HeapWord *p = s->cas_allocate(size);
iveresov@579 804 if (p != NULL) {
iveresov@625 805 size_t remainder = pointer_delta(s->end(), p + size);
iveresov@579 806 if (remainder < (size_t)oopDesc::header_size() && remainder > 0) {
iveresov@579 807 if (s->cas_deallocate(p, size)) {
iveresov@579 808 // We were the last to allocate and created a fragment less than
iveresov@579 809 // a minimal object.
iveresov@579 810 p = NULL;
iveresov@625 811 } else {
iveresov@625 812 guarantee(false, "Deallocation should always succeed");
iveresov@579 813 }
duke@435 814 }
duke@435 815 }
duke@435 816 if (p != NULL) {
duke@435 817 HeapWord* cur_top, *cur_chunk_top = p + size;
duke@435 818 while ((cur_top = top()) < cur_chunk_top) { // Keep _top updated.
duke@435 819 if (Atomic::cmpxchg_ptr(cur_chunk_top, top_addr(), cur_top) == cur_top) {
duke@435 820 break;
duke@435 821 }
duke@435 822 }
duke@435 823 }
duke@435 824
iveresov@576 825 // Make the page allocation happen here if there is no static binding.
iveresov@576 826 if (p != NULL && !os::numa_has_static_binding() ) {
duke@435 827 for (HeapWord *i = p; i < p + size; i += os::vm_page_size() >> LogHeapWordSize) {
duke@435 828 *(int*)i = 0;
duke@435 829 }
duke@435 830 }
iveresov@808 831 if (p == NULL) {
iveresov@808 832 ls->set_allocation_failed();
iveresov@808 833 }
duke@435 834 return p;
duke@435 835 }
duke@435 836
duke@435 837 void MutableNUMASpace::print_short_on(outputStream* st) const {
duke@435 838 MutableSpace::print_short_on(st);
duke@435 839 st->print(" (");
duke@435 840 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 841 st->print("lgrp %d: ", lgrp_spaces()->at(i)->lgrp_id());
duke@435 842 lgrp_spaces()->at(i)->space()->print_short_on(st);
duke@435 843 if (i < lgrp_spaces()->length() - 1) {
duke@435 844 st->print(", ");
duke@435 845 }
duke@435 846 }
duke@435 847 st->print(")");
duke@435 848 }
duke@435 849
duke@435 850 void MutableNUMASpace::print_on(outputStream* st) const {
duke@435 851 MutableSpace::print_on(st);
duke@435 852 for (int i = 0; i < lgrp_spaces()->length(); i++) {
duke@435 853 LGRPSpace *ls = lgrp_spaces()->at(i);
duke@435 854 st->print(" lgrp %d", ls->lgrp_id());
duke@435 855 ls->space()->print_on(st);
duke@435 856 if (NUMAStats) {
iveresov@579 857 for (int i = 0; i < lgrp_spaces()->length(); i++) {
iveresov@579 858 lgrp_spaces()->at(i)->accumulate_statistics(page_size());
iveresov@579 859 }
duke@435 860 st->print(" local/remote/unbiased/uncommitted: %dK/%dK/%dK/%dK, large/small pages: %d/%d\n",
duke@435 861 ls->space_stats()->_local_space / K,
duke@435 862 ls->space_stats()->_remote_space / K,
duke@435 863 ls->space_stats()->_unbiased_space / K,
duke@435 864 ls->space_stats()->_uncommited_space / K,
duke@435 865 ls->space_stats()->_large_pages,
duke@435 866 ls->space_stats()->_small_pages);
duke@435 867 }
duke@435 868 }
duke@435 869 }
duke@435 870
iveresov@625 871 void MutableNUMASpace::verify(bool allow_dirty) {
iveresov@625 872 // This can be called after setting an arbitary value to the space's top,
iveresov@625 873 // so an object can cross the chunk boundary. We ensure the parsablity
iveresov@625 874 // of the space and just walk the objects in linear fashion.
iveresov@625 875 ensure_parsability();
iveresov@625 876 MutableSpace::verify(allow_dirty);
duke@435 877 }
duke@435 878
duke@435 879 // Scan pages and gather stats about page placement and size.
duke@435 880 void MutableNUMASpace::LGRPSpace::accumulate_statistics(size_t page_size) {
duke@435 881 clear_space_stats();
duke@435 882 char *start = (char*)round_to((intptr_t) space()->bottom(), page_size);
duke@435 883 char* end = (char*)round_down((intptr_t) space()->end(), page_size);
duke@435 884 if (start < end) {
duke@435 885 for (char *p = start; p < end;) {
duke@435 886 os::page_info info;
duke@435 887 if (os::get_page_info(p, &info)) {
duke@435 888 if (info.size > 0) {
duke@435 889 if (info.size > (size_t)os::vm_page_size()) {
duke@435 890 space_stats()->_large_pages++;
duke@435 891 } else {
duke@435 892 space_stats()->_small_pages++;
duke@435 893 }
duke@435 894 if (info.lgrp_id == lgrp_id()) {
duke@435 895 space_stats()->_local_space += info.size;
duke@435 896 } else {
duke@435 897 space_stats()->_remote_space += info.size;
duke@435 898 }
duke@435 899 p += info.size;
duke@435 900 } else {
duke@435 901 p += os::vm_page_size();
duke@435 902 space_stats()->_uncommited_space += os::vm_page_size();
duke@435 903 }
duke@435 904 } else {
duke@435 905 return;
duke@435 906 }
duke@435 907 }
duke@435 908 }
duke@435 909 space_stats()->_unbiased_space = pointer_delta(start, space()->bottom(), sizeof(char)) +
duke@435 910 pointer_delta(space()->end(), end, sizeof(char));
duke@435 911
duke@435 912 }
duke@435 913
duke@435 914 // Scan page_count pages and verify if they have the right size and right placement.
duke@435 915 // If invalid pages are found they are freed in hope that subsequent reallocation
duke@435 916 // will be more successful.
duke@435 917 void MutableNUMASpace::LGRPSpace::scan_pages(size_t page_size, size_t page_count)
duke@435 918 {
duke@435 919 char* range_start = (char*)round_to((intptr_t) space()->bottom(), page_size);
duke@435 920 char* range_end = (char*)round_down((intptr_t) space()->end(), page_size);
duke@435 921
duke@435 922 if (range_start > last_page_scanned() || last_page_scanned() >= range_end) {
duke@435 923 set_last_page_scanned(range_start);
duke@435 924 }
duke@435 925
duke@435 926 char *scan_start = last_page_scanned();
duke@435 927 char* scan_end = MIN2(scan_start + page_size * page_count, range_end);
duke@435 928
duke@435 929 os::page_info page_expected, page_found;
duke@435 930 page_expected.size = page_size;
duke@435 931 page_expected.lgrp_id = lgrp_id();
duke@435 932
duke@435 933 char *s = scan_start;
duke@435 934 while (s < scan_end) {
duke@435 935 char *e = os::scan_pages(s, (char*)scan_end, &page_expected, &page_found);
duke@435 936 if (e == NULL) {
duke@435 937 break;
duke@435 938 }
duke@435 939 if (e != scan_end) {
duke@435 940 if ((page_expected.size != page_size || page_expected.lgrp_id != lgrp_id())
duke@435 941 && page_expected.size != 0) {
duke@435 942 os::free_memory(s, pointer_delta(e, s, sizeof(char)));
duke@435 943 }
duke@435 944 page_expected = page_found;
duke@435 945 }
duke@435 946 s = e;
duke@435 947 }
duke@435 948
duke@435 949 set_last_page_scanned(scan_end);
duke@435 950 }

mercurial