Skip to content

Commit 931914a

Browse files
author
Matias Saavedra Silva
committed
8340631: assert(reserved_rgn->contain_region(base_addr, size)) failed: Reserved CDS region should contain this mapping region
Reviewed-by: iklam, jsjolen, stefank
1 parent 665c39c commit 931914a

File tree

3 files changed

+25
-9
lines changed

3 files changed

+25
-9
lines changed

src/hotspot/share/cds/filemap.cpp

+20-7
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -1508,6 +1508,7 @@ void FileMapRegion::init(int region_index, size_t mapping_offset, size_t size, b
15081508
_crc = crc;
15091509
_mapped_from_file = false;
15101510
_mapped_base = nullptr;
1511+
_in_reserved_space = false;
15111512
}
15121513

15131514
void FileMapRegion::init_oopmap(size_t offset, size_t size_in_bits) {
@@ -1889,10 +1890,11 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba
18891890
FileMapRegion* r = region_at(i);
18901891
size_t size = r->used_aligned();
18911892
char *requested_addr = mapped_base_address + r->mapping_offset();
1892-
assert(r->mapped_base() == nullptr, "must be not mapped yet");
1893+
assert(!is_mapped(), "must be not mapped yet");
18931894
assert(requested_addr != nullptr, "must be specified");
18941895

18951896
r->set_mapped_from_file(false);
1897+
r->set_in_reserved_space(false);
18961898

18971899
if (MetaspaceShared::use_windows_memory_mapping()) {
18981900
// Windows cannot remap read-only shared memory to read-write when required for
@@ -1917,7 +1919,6 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba
19171919
return MAP_ARCHIVE_OTHER_FAILURE; // oom or I/O error.
19181920
} else {
19191921
assert(r->mapped_base() != nullptr, "must be initialized");
1920-
return MAP_ARCHIVE_SUCCESS;
19211922
}
19221923
} else {
19231924
// Note that this may either be a "fresh" mapping into unreserved address
@@ -1939,9 +1940,16 @@ MapArchiveResult FileMapInfo::map_region(int i, intx addr_delta, char* mapped_ba
19391940

19401941
r->set_mapped_from_file(true);
19411942
r->set_mapped_base(requested_addr);
1943+
}
19421944

1943-
return MAP_ARCHIVE_SUCCESS;
1945+
if (rs.is_reserved()) {
1946+
char* mapped_base = r->mapped_base();
1947+
assert(rs.base() <= mapped_base && mapped_base + size <= rs.end(),
1948+
PTR_FORMAT " <= " PTR_FORMAT " < " PTR_FORMAT " <= " PTR_FORMAT,
1949+
p2i(rs.base()), p2i(mapped_base), p2i(mapped_base + size), p2i(rs.end()));
1950+
r->set_in_reserved_space(rs.is_reserved());
19441951
}
1952+
return MAP_ARCHIVE_SUCCESS;
19451953
}
19461954

19471955
// The return value is the location of the archive relocation bitmap.
@@ -2359,7 +2367,6 @@ bool FileMapInfo::map_heap_region_impl() {
23592367
if (bitmap_base == nullptr) {
23602368
log_info(cds)("CDS heap cannot be used because bitmap region cannot be mapped");
23612369
dealloc_heap_region();
2362-
unmap_region(MetaspaceShared::hp);
23632370
_heap_pointers_need_patching = false;
23642371
return false;
23652372
}
@@ -2428,8 +2435,14 @@ void FileMapInfo::unmap_region(int i) {
24282435
if (size > 0 && r->mapped_from_file()) {
24292436
log_info(cds)("Unmapping region #%d at base " INTPTR_FORMAT " (%s)", i, p2i(mapped_base),
24302437
shared_region_name[i]);
2431-
if (!os::unmap_memory(mapped_base, size)) {
2432-
fatal("os::unmap_memory failed");
2438+
if (r->in_reserved_space()) {
2439+
// This region was mapped inside a ReservedSpace. Its memory will be freed when the ReservedSpace
2440+
// is released. Zero it so that we don't accidentally read its content.
2441+
log_info(cds)("Region #%d (%s) is in a reserved space, it will be freed when the space is released", i, shared_region_name[i]);
2442+
} else {
2443+
if (!os::unmap_memory(mapped_base, size)) {
2444+
fatal("os::unmap_memory failed");
2445+
}
24332446
}
24342447
}
24352448
r->set_mapped_base(nullptr);

src/hotspot/share/cds/filemap.hpp

+3-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2003, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2003, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -163,11 +163,13 @@ class FileMapRegion: private CDSFileMapRegion {
163163
size_t oopmap_size_in_bits() const { assert_is_heap_region(); return _oopmap_size_in_bits; }
164164
size_t ptrmap_offset() const { return _ptrmap_offset; }
165165
size_t ptrmap_size_in_bits() const { return _ptrmap_size_in_bits; }
166+
bool in_reserved_space() const { return _in_reserved_space; }
166167

167168
void set_file_offset(size_t s) { _file_offset = s; }
168169
void set_read_only(bool v) { _read_only = v; }
169170
void set_mapped_base(char* p) { _mapped_base = p; }
170171
void set_mapped_from_file(bool v) { _mapped_from_file = v; }
172+
void set_in_reserved_space(bool is_reserved) { _in_reserved_space = is_reserved; }
171173
void init(int region_index, size_t mapping_offset, size_t size, bool read_only,
172174
bool allow_exec, int crc);
173175
void init_oopmap(size_t offset, size_t size_in_bits);

src/hotspot/share/include/cds.h

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2018, 2024, Oracle and/or its affiliates. All rights reserved.
2+
* Copyright (c) 2018, 2025, Oracle and/or its affiliates. All rights reserved.
33
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
44
*
55
* This code is free software; you can redistribute it and/or modify it
@@ -70,6 +70,7 @@ typedef struct CDSFileMapRegion {
7070
// (The base address is the bottom of the BM region).
7171
size_t _ptrmap_size_in_bits;
7272
char* _mapped_base; // Actually mapped address (null if this region is not mapped).
73+
bool _in_reserved_space; // Is this region in a ReservedSpace
7374
} CDSFileMapRegion;
7475

7576
// This portion of the archive file header must remain unchanged for

0 commit comments

Comments
 (0)