8280941: os::print_memory_mappings() prints segment preceeding the inclusion range

Reviewed-by: stefank, minqi
This commit is contained in:
Thomas Stuefe 2022-02-01 17:19:26 +00:00
parent 4532c3a163
commit d1cc5fda8f

View File

@ -5380,21 +5380,20 @@ bool os::supports_map_sync() {
} }
void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) { void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {
// Note: all ranges are "[..)"
unsigned long long start = (unsigned long long)addr; unsigned long long start = (unsigned long long)addr;
unsigned long long end = start + bytes; unsigned long long end = start + bytes;
FILE* f = os::fopen("/proc/self/maps", "r"); FILE* f = os::fopen("/proc/self/maps", "r");
int num_found = 0; int num_found = 0;
if (f != NULL) { if (f != NULL) {
st->print("Range [%llx-%llx) contains: ", start, end); st->print_cr("Range [%llx-%llx) contains: ", start, end);
char line[512]; char line[512];
while(fgets(line, sizeof(line), f) == line) { while(fgets(line, sizeof(line), f) == line) {
unsigned long long a1 = 0; unsigned long long segment_start = 0;
unsigned long long a2 = 0; unsigned long long segment_end = 0;
if (::sscanf(line, "%llx-%llx", &a1, &a2) == 2) { if (::sscanf(line, "%llx-%llx", &segment_start, &segment_end) == 2) {
// Lets print out every range which touches ours. // Lets print out every range which touches ours.
if ((a1 >= start && a1 < end) || // left leg in if (segment_start < end && segment_end > start) {
(a2 >= start && a2 < end) || // right leg in
(a1 < start && a2 >= end)) { // superimposition
num_found ++; num_found ++;
st->print("%s", line); // line includes \n st->print("%s", line); // line includes \n
} }
@ -5402,7 +5401,7 @@ void os::print_memory_mappings(char* addr, size_t bytes, outputStream* st) {
} }
::fclose(f); ::fclose(f);
if (num_found == 0) { if (num_found == 0) {
st->print("nothing."); st->print_cr("nothing.");
} }
st->cr(); st->cr();
} }