8003705: CDS failed on Windows: can not map in the CDS

Map memory only once to prevent 'already mapped' failures.

Reviewed-by: acorn, zgu
This commit is contained in:
Harold Seigel 2013-01-07 15:32:51 -05:00
parent 64499d9494
commit 89e575df23
2 changed files with 20 additions and 4 deletions

View file

@ -211,7 +211,11 @@ void FileMapInfo::open_for_write() {
// Remove the existing file in case another process has it open.
remove(_full_path);
#ifdef _WINDOWS // if 0444 is used on Windows, then remove() will fail.
int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0744);
#else
int fd = open(_full_path, O_RDWR | O_CREAT | O_TRUNC | O_BINARY, 0444);
#endif
if (fd < 0) {
fail_stop("Unable to create shared archive file %s.", _full_path);
}
@ -370,9 +374,8 @@ ReservedSpace FileMapInfo::reserve_shared_memory() {
return rs;
}
// the reserved virtual memory is for mapping class data sharing archive
if (MemTracker::is_on()) {
MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
}
MemTracker::record_virtual_memory_type((address)rs.base(), mtClassShared);
return rs;
}
@ -394,6 +397,11 @@ char* FileMapInfo::map_region(int i) {
fail_continue(err_msg("Unable to map %s shared space at required address.", shared_region_name[i]));
return NULL;
}
#ifdef _WINDOWS
// This call is Windows-only because the memory_type gets recorded for the other platforms
// in method FileMapInfo::reserve_shared_memory(), which is not called on Windows.
MemTracker::record_virtual_memory_type((address)base, mtClassShared);
#endif
return base;
}