48 return r1.compare(r2); 49 } 50 51 bool ReservedMemoryRegion::add_committed_region(address addr, size_t size, const NativeCallStack& stack) { 52 assert(addr != NULL, "Invalid address"); 53 assert(size > 0, "Invalid size"); 54 assert(contain_region(addr, size), "Not contain this region"); 55 56 if (all_committed()) return true; 57 58 CommittedMemoryRegion committed_rgn(addr, size, stack); 59 LinkedListNode<CommittedMemoryRegion>* node = _committed_regions.head(); 60 61 while (node != NULL) { 62 CommittedMemoryRegion* rgn = node->data(); 63 if (rgn->same_region(addr, size)) { 64 return true; 65 } 66 67 if (rgn->adjacent_to(addr, size)) { 68 // special case to expand prior region if there is no next region 69 LinkedListNode<CommittedMemoryRegion>* next = node->next(); 70 if (next == NULL && rgn->call_stack()->equals(stack)) { 71 VirtualMemorySummary::record_uncommitted_memory(rgn->size(), flag()); 72 // the two adjacent regions have the same call stack, merge them 73 rgn->expand_region(addr, size); 74 VirtualMemorySummary::record_committed_memory(rgn->size(), flag()); 75 return true; 76 } 77 } 78 79 if (rgn->overlap_region(addr, size)) { 80 // Clear a space for this region in the case it overlaps with any regions. 81 remove_uncommitted_region(addr, size); 82 break; // commit below 83 } 84 if (rgn->end() >= addr + size){ 85 break; 86 } 87 node = node->next(); 88 } 89 90 // New committed region 91 VirtualMemorySummary::record_committed_memory(size, flag()); 92 return add_committed_region(committed_rgn); 93 } 94 95 void ReservedMemoryRegion::set_all_committed(bool b) { 96 if (all_committed() != b) { 97 _all_committed = b; 98 if (b) { 99 VirtualMemorySummary::record_committed_memory(size(), flag()); 100 } 101 } 102 } 103 104 bool ReservedMemoryRegion::remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node, 105 address addr, size_t size) { 106 assert(addr != NULL, "Invalid address"); 107 assert(size > 0, "Invalid size"); 108 109 CommittedMemoryRegion* rgn = node->data(); 110 assert(rgn->contain_region(addr, size), "Has to be contained"); 111 assert(!rgn->same_region(addr, size), "Can not be the same region"); 112 113 if (rgn->base() == addr || | 48 return r1.compare(r2); 49 } 50 51 bool ReservedMemoryRegion::add_committed_region(address addr, size_t size, const NativeCallStack& stack) { 52 assert(addr != NULL, "Invalid address"); 53 assert(size > 0, "Invalid size"); 54 assert(contain_region(addr, size), "Not contain this region"); 55 56 if (all_committed()) return true; 57 58 CommittedMemoryRegion committed_rgn(addr, size, stack); 59 LinkedListNode<CommittedMemoryRegion>* node = _committed_regions.head(); 60 61 while (node != NULL) { 62 CommittedMemoryRegion* rgn = node->data(); 63 if (rgn->same_region(addr, size)) { 64 return true; 65 } 66 67 if (rgn->adjacent_to(addr, size)) { 68 if (rgn->call_stack()->equals(stack)) { 69 // the two adjacent regions have the same call stack, merge them 70 rgn->expand_region(addr, size); 71 VirtualMemorySummary::record_committed_memory(size, flag()); 72 73 // maybe merge with the next region 74 LinkedListNode<CommittedMemoryRegion>* next_node = node->next(); 75 if (next_node != NULL) { 76 CommittedMemoryRegion* next = next_node->data(); 77 if (next->call_stack()->equals(stack) && rgn->adjacent_to(next->base(), next->size())) { 78 // the two adjacent regions have the same call stack, merge them 79 rgn->expand_region(next->base(), next->size()); 80 81 // the merge next_node needs to be removed from the list 82 _committed_regions.remove(next_node); 83 } 84 } 85 return true; 86 } 87 } 88 89 if (rgn->overlap_region(addr, size)) { 90 // Clear a space for this region in the case it overlaps with any regions. 91 remove_uncommitted_region(addr, size); 92 break; // commit below 93 } 94 if (rgn->end() >= addr + size){ 95 break; 96 } 97 node = node->next(); 98 } 99 100 // New committed region 101 VirtualMemorySummary::record_committed_memory(size, flag()); 102 return add_committed_region(committed_rgn); 103 } 104 105 void ReservedMemoryRegion::set_all_committed(bool b) { 106 if (all_committed() != b) { 107 _all_committed = b; 108 if (b) { 109 VirtualMemorySummary::record_committed_memory(size(), flag()); 110 } 111 } 112 } 113 114 bool ReservedMemoryRegion::remove_uncommitted_region(LinkedListNode<CommittedMemoryRegion>* node, 115 address addr, size_t size) { 116 assert(addr != NULL, "Invalid address"); 117 assert(size > 0, "Invalid size"); 118 119 CommittedMemoryRegion* rgn = node->data(); 120 assert(rgn->contain_region(addr, size), "Has to be contained"); 121 assert(!rgn->same_region(addr, size), "Can not be the same region"); 122 123 if (rgn->base() == addr || |