Skip to content

Commit

Permalink
Fix(EMH): avoid crash caused by madvise failure
Browse files Browse the repository at this point in the history
--story=115716678
  • Loading branch information
946918940 authored and shiyuexw committed Jan 23, 2024
1 parent c50597c commit 553c079
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 12 deletions.
4 changes: 3 additions & 1 deletion hotspot/src/share/vm/gc_implementation/g1/concurrentMark.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2326,7 +2326,9 @@ void ConcurrentMark::completeCleanup() {
for (int i = 0; i < should_be_freed_region_length && cur != NULL; i++) {
free_heap_physical_memory_total_byte_size += cur->capacity();
bool result = os::free_heap_physical_memory(((char*)cur->bottom()), cur->capacity());
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
cur = cur->next();
}
double end_sec = os::elapsedTime();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1888,7 +1888,9 @@ void G1CollectedHeap::free_heap_physical_memory_after_fullgc() {
for (int i = 0; i < reclaim_region_count && cur != NULL; i++) {
_free_heap_physical_memory_total_byte_size += cur->capacity();
bool result = os::free_heap_physical_memory(((char*)cur->bottom()), cur->capacity());
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
cur = cur->prev();
}
_reclaim_region_count = reclaim_region_count;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,9 @@ void G1PageBasedVirtualSpace::uncommit_internal(size_t start_page, size_t end_pa
//should madvise the physical memory only after uncommit operation succeed
if (res && (FreeHeapPhysicalMemory || (ElasticMaxHeap && ((G1CollectedHeap*)Universe::heap())->exp_EMH_size() > 0))) {
bool result = os::free_heap_physical_memory(start_addr, pointer_delta(bounded_end_addr(end_page), start_addr, sizeof(char)));
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ bool PSVirtualSpace::shrink_by(size_t bytes) {
//should try to madvise virtual memory [base_addr, base_addr + bytes]
//only after os::uncommit_memory succeed
bool result = os::free_heap_physical_memory(base_addr, bytes);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
}

Expand Down
16 changes: 12 additions & 4 deletions hotspot/src/share/vm/gc_implementation/shared/elasticMaxHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,9 @@ void PS_ElasticMaxHeapOp::doit() {
size_t shrink_bytes = old_high - new_old_high;
guarantee((shrink_bytes > 0) && (shrink_bytes % os::vm_page_size() == 0), "should be");
bool result = os::free_heap_physical_memory(new_old_high, shrink_bytes);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
}

Expand All @@ -205,7 +207,9 @@ void PS_ElasticMaxHeapOp::doit() {
size_t shrink_bytes = young_high - new_young_high;
guarantee((shrink_bytes > 0) && (shrink_bytes % os::vm_page_size() == 0), "should be");
bool result = os::free_heap_physical_memory(new_young_high, shrink_bytes);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
}
}
Expand Down Expand Up @@ -349,13 +353,17 @@ void Gen_ElasticMaxHeapOp::doit() {
size_t shrink_bytes = (char*)young->reserved().end() - base;
if (shrink_bytes > 0) {
bool result = os::free_heap_physical_memory(base, shrink_bytes);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
base = (char*)old->reserved().start() + old_committed;
shrink_bytes = (char*)old->reserved().end() - base;
if (shrink_bytes > 0) {
bool result = os::free_heap_physical_memory(base, shrink_bytes);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
}
}
_resize_success = true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*/

#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_OPERATION_HPP
#define SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_OPERATION_HPP
#ifndef SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_HPP
#define SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_HPP

#include "gc_implementation/shared/vmGCOperations.hpp"

Expand Down Expand Up @@ -88,4 +88,4 @@ class ElasticMaxHeapConfig: AllStatic {
_initial_max_heap_size = new_size;
}
};
#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_OPERATION_HPP
#endif // SHARE_VM_GC_IMPLEMENTATION_SHARED_ELASTIC_MAX_HEAP_HPP
4 changes: 3 additions & 1 deletion hotspot/src/share/vm/gc_interface/collectedHeap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -708,7 +708,9 @@ void CollectedHeap::free_heap_physical_memory_after_fullgc(void* start, void* e
guarantee (length % page_size == 0, "Invariant") ;
_free_heap_physical_memory_total_byte_size = length;
bool result = os::free_heap_physical_memory(start_address, length);
guarantee(result, "free heap physical memory should be successful");
if (!result) {
warning("Failed to free heap physical memory.");
}
double end_sec = os::elapsedTime();
_free_heap_physical_memory_time_sec = end_sec - start_sec;
_last_full_gc_time = end_sec;
Expand Down

0 comments on commit 553c079

Please sign in to comment.