8279969: NULL return from map_bitmap_region() needs to be checked

Reviewed-by: ccheung, coleenp
This commit is contained in:
Ioi Lam 2022-02-17 06:40:46 +00:00
parent 1eec16b47b
commit 1864481df1
3 changed files with 22 additions and 3 deletions

View file

@ -2168,6 +2168,15 @@ void FileMapInfo::map_heap_regions_impl() {
assert(is_aligned(relocated_closed_heap_region_bottom, HeapRegion::GrainBytes),
"must be");
if (_heap_pointers_need_patching) {
char* bitmap_base = map_bitmap_region();
if (bitmap_base == NULL) {
log_info(cds)("CDS heap cannot be used because bitmap region cannot be mapped");
_heap_pointers_need_patching = false;
return;
}
}
// Map the closed heap regions: GC does not write into these regions.
if (map_heap_regions(MetaspaceShared::first_closed_heap_region,
MetaspaceShared::max_num_closed_heap_regions,
@ -2297,9 +2306,7 @@ void FileMapInfo::patch_heap_embedded_pointers() {
void FileMapInfo::patch_heap_embedded_pointers(MemRegion* regions, int num_regions,
int first_region_idx) {
char* bitmap_base = map_bitmap_region();
if (bitmap_base == NULL) {
return;
}
assert(bitmap_base != NULL, "must have already been mapped");
for (int i=0; i<num_regions; i++) {
FileMapRegion* si = space_at(i + first_region_idx);
HeapShared::patch_embedded_pointers(

View file

@ -1679,6 +1679,10 @@ void HeapShared::sort_loaded_regions(LoadedArchiveHeapRegion* loaded_regions, in
bool HeapShared::load_regions(FileMapInfo* mapinfo, LoadedArchiveHeapRegion* loaded_regions,
int num_loaded_regions, uintptr_t buffer) {
uintptr_t bitmap_base = (uintptr_t)mapinfo->map_bitmap_region();
if (bitmap_base == 0) {
_loading_failed = true;
return false; // OOM or CRC error
}
uintptr_t load_address = buffer;
for (int i = 0; i < num_loaded_regions; i++) {
LoadedArchiveHeapRegion* ri = &loaded_regions[i];

View file

@ -80,6 +80,14 @@ public class SharedArchiveConsistency {
OutputAnalyzer output = shareAuto ? TestCommon.execAuto(execArgs) : TestCommon.execCommon(execArgs);
String stdtxt = output.getOutput();
System.out.println("Note: this test may fail in very rare occasions due to CRC32 checksum collision");
for (String opt : execArgs) {
if (opt.equals("-XX:+VerifySharedSpaces")) {
// If VerifySharedSpaces is enabled, the VM should never crash even if the archive
// is corrupted (unless if we are so lucky that the corrupted archive ends up
// have the same checksum as recoreded in the header)
output.shouldNotContain("A fatal error has been detected by the Java Runtime Environment");
}
}
for (String message : matchMessages) {
if (stdtxt.contains(message)) {
// match any to return