equal
deleted
inserted
replaced
36 assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check"); |
36 assert(sizeof(_snapshot) >= sizeof(VirtualMemorySnapshot), "Sanity Check"); |
37 // Use placement operator new to initialize static data area. |
37 // Use placement operator new to initialize static data area. |
38 ::new ((void*)_snapshot) VirtualMemorySnapshot(); |
38 ::new ((void*)_snapshot) VirtualMemorySnapshot(); |
39 } |
39 } |
40 |
40 |
|
41 void VirtualMemorySummary::snapshot(VirtualMemorySnapshot* s) { |
|
42 // Snapshot current thread stacks |
|
43 VirtualMemoryTracker::snapshot_thread_stacks(); |
|
44 as_snapshot()->copy_to(s); |
|
45 } |
|
46 |
41 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions; |
47 SortedLinkedList<ReservedMemoryRegion, compare_reserved_region_base>* VirtualMemoryTracker::_reserved_regions; |
42 |
48 |
43 int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) { |
49 int compare_committed_region(const CommittedMemoryRegion& r1, const CommittedMemoryRegion& r2) { |
44 return r1.compare(r2); |
50 return r1.compare(r2); |
45 } |
51 } |
282 if (flag() != f) { |
288 if (flag() != f) { |
283 VirtualMemorySummary::move_reserved_memory(flag(), f, size()); |
289 VirtualMemorySummary::move_reserved_memory(flag(), f, size()); |
284 VirtualMemorySummary::move_committed_memory(flag(), f, committed_size()); |
290 VirtualMemorySummary::move_committed_memory(flag(), f, committed_size()); |
285 _flag = f; |
291 _flag = f; |
286 } |
292 } |
|
293 } |
|
294 |
|
295 address ReservedMemoryRegion::thread_stack_uncommitted_bottom() const { |
|
296 assert(flag() == mtThreadStack, "Only for thread stack"); |
|
297 LinkedListNode<CommittedMemoryRegion>* head = _committed_regions.head(); |
|
298 address bottom = base(); |
|
299 address top = base() + size(); |
|
300 while (head != NULL) { |
|
301 address committed_top = head->data()->base() + head->data()->size(); |
|
302 if (committed_top < top) { |
|
303 // committed stack guard pages, skip them |
|
304 bottom = head->data()->base() + head->data()->size(); |
|
305 head = head->next(); |
|
306 } else { |
|
307 assert(top == committed_top, "Sanity"); |
|
308 break; |
|
309 } |
|
310 } |
|
311 |
|
312 return bottom; |
287 } |
313 } |
288 |
314 |
289 bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) { |
315 bool VirtualMemoryTracker::initialize(NMT_TrackingLevel level) { |
290 if (level >= NMT_summary) { |
316 if (level >= NMT_summary) { |
291 VirtualMemorySummary::initialize(); |
317 VirtualMemorySummary::initialize(); |
458 } |
484 } |
459 } |
485 } |
460 } |
486 } |
461 } |
487 } |
462 |
488 |
|
489 // Walk all known thread stacks, snapshot their committed ranges. |
|
490 class SnapshotThreadStackWalker : public VirtualMemoryWalker { |
|
491 public: |
|
492 SnapshotThreadStackWalker() {} |
|
493 |
|
494 bool do_allocation_site(const ReservedMemoryRegion* rgn) { |
|
495 if (rgn->flag() == mtThreadStack) { |
|
496 address stack_bottom = rgn->thread_stack_uncommitted_bottom(); |
|
497 size_t stack_size = rgn->base() + rgn->size() - stack_bottom; |
|
498 size_t committed_size = os::committed_stack_size(stack_bottom, stack_size); |
|
499 if (committed_size > 0) { |
|
500 ReservedMemoryRegion* region = const_cast<ReservedMemoryRegion*>(rgn); |
|
501 NativeCallStack ncs; // empty stack |
|
502 |
|
503 // Stack grows downward |
|
504 region->add_committed_region(rgn->base() + rgn->size() - committed_size, committed_size, ncs); |
|
505 } |
|
506 } |
|
507 return true; |
|
508 } |
|
509 }; |
|
510 |
|
511 void VirtualMemoryTracker::snapshot_thread_stacks() { |
|
512 SnapshotThreadStackWalker walker; |
|
513 walk_virtual_memory(&walker); |
|
514 } |
463 |
515 |
464 bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) { |
516 bool VirtualMemoryTracker::walk_virtual_memory(VirtualMemoryWalker* walker) { |
465 assert(_reserved_regions != NULL, "Sanity check"); |
517 assert(_reserved_regions != NULL, "Sanity check"); |
466 ThreadCritical tc; |
518 ThreadCritical tc; |
467 // Check that the _reserved_regions haven't been deleted. |
519 // Check that the _reserved_regions haven't been deleted. |