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

Tue, 23 Nov 2010 13:22:55 -0800

author
stefank
date
Tue, 23 Nov 2010 13:22:55 -0800
changeset 2314
f95d63e2154a
parent 1934
e9ff18c4ace7
child 3156
f08d439fab8c
permissions
-rw-r--r--

6989984: Use standard include model for Hospot
Summary: Replaced MakeDeps and the includeDB files with more standardized solutions.
Reviewed-by: coleenp, kvn, kamg

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

mercurial