annotate src/share/vm/services/virtualMemoryTracker.cpp @ 27292:eb84884dbeaa

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