Currently the CDS "ro" region is mmapped with flags=MAP_PRIVATE with prot=PROT_READ (when no relocation is needed)
https://github.com/openjdk/jdk/blob/ea83cb960d07ffa9384aad6a1e2a0233e3ebbdd1/src/hotspot/os/linux/os_linux.cpp#L4930-L4940
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
bool allow_exec) {
int prot;
int flags = MAP_PRIVATE;
if (read_only) {
prot = PROT_READ;
} else {
prot = PROT_READ | PROT_WRITE;
}
As suggested by [~asmehra] in https://github.com/openjdk/jdk/pull/11401 :
Why do we rely on OS's cow mechanism to make ro section shareable? As far as I know cow mapping for MAP_PRIVATE is not mandated by posix. We should instead just use MAP_SHARED flag for ro sections (if relocation isn't required). That also makes it explicit that the section is meant to be shared.
https://github.com/openjdk/jdk/blob/ea83cb960d07ffa9384aad6a1e2a0233e3ebbdd1/src/hotspot/os/linux/os_linux.cpp#L4930-L4940
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset,
char *addr, size_t bytes, bool read_only,
bool allow_exec) {
int prot;
int flags = MAP_PRIVATE;
if (read_only) {
prot = PROT_READ;
} else {
prot = PROT_READ | PROT_WRITE;
}
As suggested by [~asmehra] in https://github.com/openjdk/jdk/pull/11401 :
Why do we rely on OS's cow mechanism to make ro section shareable? As far as I know cow mapping for MAP_PRIVATE is not mandated by posix. We should instead just use MAP_SHARED flag for ro sections (if relocation isn't required). That also makes it explicit that the section is meant to be shared.