annotate src/share/vm/services/virtualMemoryTracker.cpp @ 28785:0db82451a124

Merge.
author Doug Simon <doug.simon@oracle.com>
date Thu, 09 Jun 2016 23:17:56 +0200
parents 5b24bff4ad46 51ff9e7c2b51
children
rev   line source
zgu@6853 1 /*
jiangli@27292 2 * Copyright (c) 2013, 2016, Oracle and/or its affiliates. All rights reserved.
zgu@6853 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
zgu@6853 4 *
zgu@6853 5 * This code is free software; you can redistribute it and/or modify it
zgu@6853 6 * under the terms of the GNU General Public License version 2 only, as
zgu@6853 7 * published by the Free Software Foundation.
zgu@6853 8 *
zgu@6853 9 * This code is distributed in the hope that it will be useful, but WITHOUT
zgu@6853 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
zgu@6853 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
zgu@6853 12 * version 2 for more details (a copy is included in the LICENSE file that
zgu@6853 13 * accompanied this code).
zgu@6853 14 *
zgu@6853 15 * You should have received a copy of the GNU General Public License version
zgu@6853 16 * 2 along with this work; if not, write to the Free Software Foundation,
zgu@6853 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
zgu@6853 18 *
zgu@6853 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
zgu@6853 20 * or visit www.oracle.com if you need additional information or have any
zgu@6853 21 * questions.
zgu@6853 22 *
zgu@6853 23 */
zgu@6853 24 #include "precompiled.hpp"
zgu@6853 25
mockner@28769 26 #include "runtime/atomic.inline.hpp"
mockner@28769 27 #include "runtime/os.hpp"
zgu@6853 28 #include "runtime/threadCritical.hpp"
mockner@28769 29 #include "services/memTracker.hpp"
zgu@6853 30 #include "services/virtualMemoryTracker.hpp"
zgu@6853 31
zgu@6853 32 size_t VirtualMemorySummary::_snapshot[CALC_OBJ_SIZE_IN_TYPE(VirtualMemorySnapshot, size_t)];
zgu@6853 33
zgu@6853 34 void VirtualMemorySummary::initialize() {
zgu@6853 35 assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check");
zgu@6853 36 // Use placement operator new to initialize static data area.
zgu@6853 37 ::new ((void*)_snapshot) VirtualMemorySnapshot();
zgu@6853 38 }
zgu@6853 39
zgu@6873 40 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions;
zgu@6853 41
zgu@6853 42 int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) {
zgu@6853 43 return r1.compare(r2);
zgu@6853 44 }
zgu@6853 45
zgu@6853 46 int compare_reserved_region_base(const ReservedMemoryRegion& r1, const ReservedMemoryRegion& r2) {
zgu@6853 47 return r1.compare(r2);
zgu@6853 48 }
zgu@6853 49
zgu@6853 50 bool ReservedMemoryRegion::add_committed_region(address addr, size_t size, const NativeCallStack& stack) {
zgu@6853 51 assert(addr != NULL, "Invalid address");
zgu@6853 52 assert(size > 0, "Invalid size");
zgu@6853 53 assert(contain_region(addr, size), "Not contain this region");
zgu@6853 54
zgu@6853 55 if (all_committed()) return true;
zgu@6853 56
zgu@6853 57 CommittedMemoryRegion committed_rgn(addr, size, stack);
mockner@28769 58 LinkedListNode<CommittedMemoryRegion>* node = _committed_regions.head();
mockner@28769 59
mockner@28769 60 while (node != NULL) {
zgu@6853 61 CommittedMemoryRegion* rgn = node->data();
zgu@6853 62 if (rgn->same_region(addr, size)) {
zgu@6853 63 return true;
zgu@6853 64 }
zgu@6853 65
zgu@6853 66 if (rgn->adjacent_to(addr, size)) {
mockner@28769 67 // special case to expand prior region if there is no next region
mockner@28769 68 LinkedListNode<CommittedMemoryRegion>* next = node->next();
mockner@28769 69 if (next == NULL && rgn->call_stack()->equals(stack)) {
zgu@6853 70 VirtualMemorySummary::record_uncommitted_memory(rgn->size(), flag());
zgu@6853 71 // the two adjacent regions have the same call stack, merge them
zgu@6853 72 rgn->expand_region(addr, size);
zgu@6853 73 VirtualMemorySummary::record_committed_memory(rgn->size(), flag());
zgu@6853 74 return true;
zgu@6853 75 }
zgu@6853 76 }
mockner@28769 77
mockner@28769 78 if (rgn->overlap_region(addr, size)) {
mockner@28769 79 // Clear a space for this region in the case it overlaps with any regions.
mockner@28769 80 remove_uncommitted_region(addr, size);
mockner@28769 81 break; // commit below
zgu@6853 82 }
mockner@28769 83 if (rgn->end() >= addr + size){
mockner@28769 84 break;
mockner@28769 85 }
mockner@28769 86 node = node->next();
mockner@28769 87 }
mockner@28769 88
zgu@6853 89 // New committed region
zgu@6853 90 VirtualMemorySummary::record_committed_memory(size, flag());
zgu@6853 91 return add_committed_region(committed_rgn);
zgu@6853 92 }
zgu@6853 93
zgu@6853 94 void ReservedMemoryRegion::set_all_committed(bool b) {
zgu@6853 95 if (all_committed() != b) {
zgu@6853 96 _all_committed = b;
zgu@6853 97 if (b) {
zgu@6853 98 VirtualMemorySummary::record_committed_memory(size(), flag());
zgu@6853 99 }
zgu@6853 100 }
zgu@6853 101 }
zgu@6853 102
zgu@6853 103 bool ReservedMemoryRegion::remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node,
zgu@6853 104 address addr, size_t size) {
zgu@6853 105 assert(addr != NULL, "Invalid address");
zgu@6853 106 assert(size > 0, "Invalid size");
zgu@6853 107
zgu@6853 108 CommittedMemoryRegion* rgn = node->data();
zgu@6853 109 assert(rgn->contain_region(addr, size), "Has to be contained");
zgu@6853 110 assert(!rgn->same_region(addr, size), "Can not be the same region");
zgu@6853 111
zgu@6853 112 if (rgn->base() == addr ||
zgu@6853 113 rgn->end() == addr + size) {
zgu@6853 114 rgn->exclude_region(addr, size);
zgu@6853 115 return true;
zgu@6853 116 } else {
zgu@6853 117 // split this region
zgu@6853 118 address top =rgn->end();
zgu@6853 119 // use this region for lower part
zgu@6853 120 size_t exclude_size = rgn->end() - addr;
zgu@6853 121 rgn->exclude_region(addr, exclude_size);
zgu@6853 122
zgu@6853 123 // higher part
zgu@6853 124 address high_base = addr + size;
zgu@6853 125 size_t high_size = top - high_base;
zgu@6853 126
zgu@6853 127 CommittedMemoryRegion high_rgn(high_base, high_size, *rgn->call_stack());
zgu@6853 128 LinkedListNode<CommittedMemoryRegion>* high_node = _committed_regions.add(high_rgn);
zgu@6853 129 assert(high_node == NULL || node->next() == high_node, "Should be right after");
zgu@6853 130 return (high_node != NULL);
zgu@6853 131 }
zgu@6853 132
zgu@6853 133 return false;
zgu@6853 134 }
zgu@6853 135
zgu@6853 136 bool ReservedMemoryRegion::remove_uncommitted_region(address addr, size_t sz) {
zgu@6853 137 // uncommit stack guard pages
zgu@6853 138 if (flag() == mtThreadStack && !same_region(addr, sz)) {
zgu@6853 139 return true;
zgu@6853 140 }
zgu@6853 141
zgu@6853 142 assert(addr != NULL, "Invalid address");
zgu@6853 143 assert(sz > 0, "Invalid size");
zgu@6853 144
zgu@6853 145 if (all_committed()) {
zgu@6853 146 assert(_committed_regions.is_empty(), "Sanity check");
zgu@6853 147 assert(contain_region(addr, sz), "Reserved region does not contain this region");
zgu@6853 148 set_all_committed(false);
zgu@6853 149 VirtualMemorySummary::record_uncommitted_memory(sz, flag());
zgu@6853 150 if (same_region(addr, sz)) {
zgu@6853 151 return true;
zgu@6853 152 } else {
zgu@6853 153 CommittedMemoryRegion rgn(base(), size(), *call_stack());
zgu@6853 154 if (rgn.base() == addr || rgn.end() == (addr + sz)) {
zgu@6853 155 rgn.exclude_region(addr, sz);
zgu@6853 156 return add_committed_region(rgn);
zgu@6853 157 } else {
zgu@6853 158 // split this region
zgu@6853 159 // top of the whole region
zgu@6853 160 address top =rgn.end();
zgu@6853 161 // use this region for lower part
zgu@6853 162 size_t exclude_size = rgn.end() - addr;
zgu@6853 163 rgn.exclude_region(addr, exclude_size);
zgu@6853 164 if (add_committed_region(rgn)) {
zgu@6853 165 // higher part
zgu@6853 166 address high_base = addr + sz;
zgu@6853 167 size_t high_size = top - high_base;
zgu@6881 168 CommittedMemoryRegion high_rgn(high_base, high_size, NativeCallStack::EMPTY_STACK);
zgu@6853 169 return add_committed_region(high_rgn);
zgu@6853 170 } else {
zgu@6853 171 return false;
zgu@6853 172 }
zgu@6853 173 }
zgu@6853 174 }
zgu@6853 175 } else {
mockner@28769 176 CommittedMemoryRegion del_rgn(addr, sz, *call_stack());
mockner@28769 177 address end = addr + sz;
mockner@28769 178
mockner@28769 179 LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head();
zgu@6853 180 LinkedListNode<CommittedMemoryRegion>* prev = NULL;
mockner@28769 181 CommittedMemoryRegion* crgn;
zgu@6853 182
mockner@28769 183 while (head != NULL) {
mockner@28769 184 crgn = head->data();
mockner@28769 185
mockner@28769 186 if (crgn->same_region(addr, sz)) {
mockner@28769 187 VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
zgu@6853 188 _committed_regions.remove_after(prev);
zgu@6853 189 return true;
mockner@28769 190 }
mockner@28769 191
mockner@28769 192 // del_rgn contains crgn
mockner@28769 193 if (del_rgn.contain_region(crgn->base(), crgn->size())) {
zgu@6853 194 VirtualMemorySummary::record_uncommitted_memory(crgn->size(), flag());
zgu@6853 195 head = head->next();
zgu@6853 196 _committed_regions.remove_after(prev);
mockner@28769 197 continue; // don't update head or prev
zgu@6853 198 }
mockner@28769 199
mockner@28769 200 // Found addr in the current crgn. There are 2 subcases:
mockner@28769 201 if (crgn->contain_address(addr)) {
mockner@28769 202
mockner@28769 203 // (1) Found addr+size in current crgn as well. (del_rgn is contained in crgn)
mockner@28769 204 if (crgn->contain_address(end - 1)) {
mockner@28769 205 VirtualMemorySummary::record_uncommitted_memory(sz, flag());
mockner@28769 206 return remove_uncommitted_region(head, addr, sz); // done!
mockner@28769 207 } else {
mockner@28769 208 // (2) Did not find del_rgn's end in crgn.
mockner@28769 209 size_t size = crgn->end() - del_rgn.base();
mockner@28769 210 crgn->exclude_region(addr, size);
mockner@28769 211 VirtualMemorySummary::record_uncommitted_memory(size, flag());
zgu@6853 212 }
mockner@28769 213
mockner@28769 214 } else if (crgn->contain_address(end - 1)) {
mockner@28769 215 // Found del_rgn's end, but not its base addr.
mockner@28769 216 size_t size = del_rgn.end() - crgn->base();
mockner@28769 217 crgn->exclude_region(crgn->base(), size);
mockner@28769 218 VirtualMemorySummary::record_uncommitted_memory(size, flag());
mockner@28769 219 return true; // should be done if the list is sorted properly!
mockner@28769 220 }
mockner@28769 221
zgu@6853 222 prev = head;
zgu@6853 223 head = head->next();
zgu@6853 224 }
zgu@6853 225 }
zgu@6853 226
zgu@6853 227 return true;
zgu@6853 228 }
zgu@6853 229
zgu@6853 230 void ReservedMemoryRegion::move_committed_regions(address addr, ReservedMemoryRegion& rgn) {
zgu@6853 231 assert(addr != NULL, "Invalid address");
zgu@6853 232
zgu@6853 233 // split committed regions
zgu@6853 234 LinkedListNode<CommittedMemoryRegion>* head =
zgu@6853 235 _committed_regions.head();
zgu@6853 236 LinkedListNode<CommittedMemoryRegion>* prev = NULL;
zgu@6853 237
zgu@6853 238 while (head != NULL) {
zgu@6853 239 if (head->data()->base() >= addr) {
zgu@6853 240 break;
zgu@6853 241 }
zgu@6853 242 prev = head;
zgu@6853 243 head = head->next();
zgu@6853 244 }
zgu@6853 245
zgu@6853 246 if (head != NULL) {
zgu@6853 247 if (prev != NULL) {
zgu@6853 248 prev->set_next(head->next());
zgu@6853 249 } else {
zgu@6853 250 _committed_regions.set_head(NULL);
zgu@6853 251 }
zgu@6853 252 }
zgu@6853 253
zgu@6853 254 rgn._committed_regions.set_head(head);
zgu@6853 255 }
zgu@6853 256
zgu@6853 257 size_t ReservedMemoryRegion::committed_size() const {
zgu@6853 258 if (all_committed()) {
zgu@6853 259 return size();
zgu@6853 260 } else {
zgu@6853 261 size_t committed = 0;
zgu@6853 262 LinkedListNode<CommittedMemoryRegion>* head =
zgu@6853 263 _committed_regions.head();
zgu@6853 264 while (head != NULL) {
zgu@6853 265 committed += head->data()->size();
zgu@6853 266 head = head->next();
zgu@6853 267 }
zgu@6853 268 return committed;
zgu@6853 269 }
zgu@6853 270 }
zgu@6853 271
zgu@6853 272 void ReservedMemoryRegion::set_flag(MEMFLAGS f) {
zgu@6853 273 assert((flag() == mtNone || flag() == f), "Overwrite memory type");
zgu@6853 274 if (flag() != f) {
zgu@6853 275 VirtualMemorySummary::move_reserved_memory(flag(), f, size());
zgu@6853 276 VirtualMemorySummary::move_committed_memory(flag(), f, committed_size());
zgu@6853 277 _flag = f;
zgu@6853 278 }
zgu@6853 279 }
zgu@6853 280
zgu@6853 281 bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) {
zgu@6853 282 if (level >= NMT_summary) {
zgu@6853 283 VirtualMemorySummary::initialize();
zgu@6853 284 }
zgu@6853 285 return true;
zgu@6853 286 }
zgu@6853 287
zgu@6873 288 bool VirtualMemoryTracker::late_initialize(NMT_TrackingLevel level) {
zgu@6873 289 if (level >= NMT_summary) {
zgu@6873 290 _reserved_regions = new (std::nothrow, ResourceObj::C_HEAP, mtNMT)
zgu@6873 291 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>();
zgu@6873 292 return (_reserved_regions != NULL);
zgu@6873 293 }
zgu@6873 294 return true;
zgu@6873 295 }
zgu@6873 296
zgu@6853 297 bool VirtualMemoryTracker::add_reserved_region(address base_addr, size_t size,
zgu@6853 298 const NativeCallStack& stack, MEMFLAGS flag, bool all_committed) {
zgu@6853 299 assert(base_addr != NULL, "Invalid address");
zgu@6853 300 assert(size > 0, "Invalid size");
zgu@6873 301 assert(_reserved_regions != NULL, "Sanity check");
zgu@6853 302 ReservedMemoryRegion rgn(base_addr, size, stack, flag);
zgu@6873 303 ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
zgu@6853 304 LinkedListNode<ReservedMemoryRegion>* node;
zgu@6853 305 if (reserved_rgn == NULL) {
zgu@6853 306 VirtualMemorySummary::record_reserved_memory(size, flag);
zgu@6873 307 node = _reserved_regions->add(rgn);
zgu@6853 308 if (node != NULL) {
zgu@6853 309 node->data()->set_all_committed(all_committed);
zgu@6853 310 return true;
zgu@6853 311 } else {
zgu@6853 312 return false;
zgu@6853 313 }
zgu@6853 314 } else {
zgu@6853 315 if (reserved_rgn->same_region(base_addr, size)) {
zgu@6853 316 reserved_rgn->set_call_stack(stack);
zgu@6853 317 reserved_rgn->set_flag(flag);
zgu@6853 318 return true;
zgu@6853 319 } else if (reserved_rgn->adjacent_to(base_addr, size)) {
zgu@6853 320 VirtualMemorySummary::record_reserved_memory(size, flag);
zgu@6853 321 reserved_rgn->expand_region(base_addr, size);
zgu@6853 322 reserved_rgn->set_call_stack(stack);
zgu@6853 323 return true;
zgu@6853 324 } else {
zgu@6853 325 // Overlapped reservation.
zgu@6853 326 // It can happen when the regions are thread stacks, as JNI
zgu@6853 327 // thread does not detach from VM before exits, and leads to
zgu@6853 328 // leak JavaThread object
zgu@6853 329 if (reserved_rgn->flag() == mtThreadStack) {
zgu@6853 330 guarantee(!CheckJNICalls, "Attached JNI thread exited without being detached");
zgu@6853 331 // Overwrite with new region
zgu@6853 332
zgu@6853 333 // Release old region
zgu@6853 334 VirtualMemorySummary::record_uncommitted_memory(reserved_rgn->committed_size(), reserved_rgn->flag());
zgu@6853 335 VirtualMemorySummary::record_released_memory(reserved_rgn->size(), reserved_rgn->flag());
zgu@6853 336
zgu@6853 337 // Add new region
zgu@6853 338 VirtualMemorySummary::record_reserved_memory(rgn.size(), flag);
zgu@6853 339
zgu@6853 340 *reserved_rgn = rgn;
zgu@6853 341 return true;
zgu@6853 342 }
zgu@6883 343
zgu@6883 344 // CDS mapping region.
zgu@6883 345 // CDS reserves the whole region for mapping CDS archive, then maps each section into the region.
zgu@6883 346 // NMT reports CDS as a whole.
zgu@6883 347 if (reserved_rgn->flag() == mtClassShared) {
zgu@6883 348 assert(reserved_rgn->contain_region(base_addr, size), "Reserved CDS region should contain this mapping region");
zgu@6883 349 return true;
zgu@6883 350 }
zgu@6883 351
jiangli@8543 352 // Mapped CDS string region.
jiangli@8543 353 // The string region(s) is part of the java heap.
jiangli@8543 354 if (reserved_rgn->flag() == mtJavaHeap) {
jiangli@8543 355 assert(reserved_rgn->contain_region(base_addr, size), "Reserved heap region should contain this mapping region");
jiangli@8543 356 return true;
jiangli@8543 357 }
jiangli@8543 358
zgu@6883 359 ShouldNotReachHere();
zgu@6883 360 return false;
zgu@6853 361 }
zgu@6853 362 }
zgu@6853 363 }
zgu@6853 364
zgu@6853 365 void VirtualMemoryTracker::set_reserved_region_type(address addr, MEMFLAGS flag) {
zgu@6853 366 assert(addr != NULL, "Invalid address");
zgu@6873 367 assert(_reserved_regions != NULL, "Sanity check");
zgu@6853 368
zgu@6853 369 ReservedMemoryRegion rgn(addr, 1);
zgu@6873 370 ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
zgu@6853 371 if (reserved_rgn != NULL) {
zgu@6853 372 assert(reserved_rgn->contain_address(addr), "Containment");
zgu@6853 373 if (reserved_rgn->flag() != flag) {
zgu@6853 374 assert(reserved_rgn->flag() == mtNone, "Overwrite memory type");
zgu@6853 375 reserved_rgn->set_flag(flag);
zgu@6853 376 }
zgu@6853 377 }
zgu@6853 378 }
zgu@6853 379
zgu@6853 380 bool VirtualMemoryTracker::add_committed_region(address addr, size_t size,
zgu@6853 381 const NativeCallStack& stack) {
zgu@6853 382 assert(addr != NULL, "Invalid address");
zgu@6853 383 assert(size > 0, "Invalid size");
zgu@6873 384 assert(_reserved_regions != NULL, "Sanity check");
zgu@6873 385
zgu@6853 386 ReservedMemoryRegion rgn(addr, size);
zgu@6873 387 ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
zgu@6853 388
zgu@6853 389 assert(reserved_rgn != NULL, "No reserved region");
zgu@6853 390 assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
mockner@28769 391 bool result = reserved_rgn->add_committed_region(addr, size, stack);
mockner@28769 392 return result;
zgu@6853 393 }
zgu@6853 394
zgu@6853 395 bool VirtualMemoryTracker::remove_uncommitted_region(address addr, size_t size) {
zgu@6853 396 assert(addr != NULL, "Invalid address");
zgu@6853 397 assert(size > 0, "Invalid size");
zgu@6873 398 assert(_reserved_regions != NULL, "Sanity check");
zgu@6873 399
zgu@6853 400 ReservedMemoryRegion rgn(addr, size);
zgu@6873 401 ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
zgu@6853 402 assert(reserved_rgn != NULL, "No reserved region");
zgu@6853 403 assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
mockner@28769 404 bool result = reserved_rgn->remove_uncommitted_region(addr, size);
mockner@28769 405 return result;
zgu@6853 406 }
zgu@6853 407
zgu@6853 408 bool VirtualMemoryTracker::remove_released_region(address addr, size_t size) {
zgu@6853 409 assert(addr != NULL, "Invalid address");
zgu@6853 410 assert(size > 0, "Invalid size");
zgu@6873 411 assert(_reserved_regions != NULL, "Sanity check");
zgu@6853 412
zgu@6853 413 ReservedMemoryRegion rgn(addr, size);
zgu@6873 414 ReservedMemoryRegion* reserved_rgn = _reserved_regions->find(rgn);
zgu@6853 415
zgu@6853 416 assert(reserved_rgn != NULL, "No reserved region");
zgu@6853 417
zgu@6853 418 // uncommit regions within the released region
zgu@6853 419 if (!reserved_rgn->remove_uncommitted_region(addr, size)) {
zgu@6853 420 return false;
zgu@6853 421 }
zgu@6853 422
jiangli@27292 423 if (reserved_rgn->flag() == mtClassShared &&
jiangli@27292 424 reserved_rgn->contain_region(addr, size) &&
jiangli@27292 425 !reserved_rgn->same_region(addr, size)) {
jiangli@27292 426 // This is an unmapped CDS region, which is part of the reserved shared
jiangli@27292 427 // memory region.
jiangli@27292 428 // See special handling in VirtualMemoryTracker::add_reserved_region also.
jiangli@27292 429 return true;
jiangli@27292 430 }
zgu@6853 431
zgu@6853 432 VirtualMemorySummary::record_released_memory(size, reserved_rgn->flag());
zgu@6853 433
zgu@6853 434 if (reserved_rgn->same_region(addr, size)) {
zgu@6873 435 return _reserved_regions->remove(rgn);
zgu@6853 436 } else {
zgu@6853 437 assert(reserved_rgn->contain_region(addr, size), "Not completely contained");
zgu@6853 438 if (reserved_rgn->base() == addr ||
zgu@6853 439 reserved_rgn->end() == addr + size) {
zgu@6853 440 reserved_rgn->exclude_region(addr, size);
zgu@6853 441 return true;
zgu@6853 442 } else {
zgu@6853 443 address top = reserved_rgn->end();
zgu@6853 444 address high_base = addr + size;
zgu@6853 445 ReservedMemoryRegion high_rgn(high_base, top - high_base,
zgu@6853 446 *reserved_rgn->call_stack(), reserved_rgn->flag());
zgu@6853 447
zgu@6853 448 // use original region for lower region
zgu@6853 449 reserved_rgn->exclude_region(addr, top - addr);
zgu@6873 450 LinkedListNode<ReservedMemoryRegion>* new_rgn = _reserved_regions->add(high_rgn);
zgu@6853 451 if (new_rgn == NULL) {
zgu@6853 452 return false;
zgu@6853 453 } else {
zgu@6853 454 reserved_rgn->move_committed_regions(addr, *new_rgn->data());
zgu@6853 455 return true;
zgu@6853 456 }
zgu@6853 457 }
zgu@6853 458 }
zgu@6853 459 }
zgu@6853 460
zgu@6853 461
zgu@6853 462 bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) {
zgu@6873 463 assert(_reserved_regions != NULL, "Sanity check");
zgu@6853 464 ThreadCritical tc;
coleenp@7233 465 // Check that the _reserved_regions haven't been deleted.
coleenp@7233 466 if (_reserved_regions != NULL) {
coleenp@7233 467 LinkedListNode<ReservedMemoryRegion>* head = _reserved_regions->head();
coleenp@7233 468 while (head != NULL) {
coleenp@7233 469 const ReservedMemoryRegion* rgn = head->peek();
coleenp@7233 470 if (!walker->do_allocation_site(rgn)) {
coleenp@7233 471 return false;
coleenp@7233 472 }
coleenp@7233 473 head = head->next();
zgu@6853 474 }
coleenp@7233 475 }
zgu@6853 476 return true;
zgu@6853 477 }
zgu@6853 478
zgu@6853 479 // Transition virtual memory tracking level.
zgu@6853 480 bool VirtualMemoryTracker::transition(NMT_TrackingLevel from, NMT_TrackingLevel to) {
coleenp@7233 481 assert (from != NMT_minimal, "cannot convert from the lowest tracking level to anything");
coleenp@7233 482 if (to == NMT_minimal) {
zgu@6853 483 assert(from == NMT_summary || from == NMT_detail, "Just check");
zgu@6853 484 // Clean up virtual memory tracking data structures.
zgu@6853 485 ThreadCritical tc;
coleenp@7233 486 // Check for potential race with other thread calling transition
zgu@6873 487 if (_reserved_regions != NULL) {
zgu@6873 488 delete _reserved_regions;
zgu@6873 489 _reserved_regions = NULL;
zgu@6873 490 }
zgu@6853 491 }
zgu@6853 492
zgu@6853 493 return true;
zgu@6853 494 }