2245 2246 // attach to the region 2247 addr = (char*)shmat(shmid, req_addr, 0); 2248 int err = errno; 2249 2250 // Remove shmid. If shmat() is successful, the actual shared memory segment 2251 // will be deleted when it's detached by shmdt() or when the process 2252 // terminates. If shmat() is not successful this will remove the shared 2253 // segment immediately. 2254 shmctl(shmid, IPC_RMID, NULL); 2255 2256 if ((intptr_t)addr == -1) { 2257 if (warn_on_failure) { 2258 jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err); 2259 warning(msg); 2260 } 2261 return NULL; 2262 } 2263 2264 // The memory is committed 2265 address pc = CALLER_PC; 2266 MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc); 2267 MemTracker::record_virtual_memory_commit((address)addr, bytes, pc); 2268 2269 return addr; 2270 } 2271 2272 bool os::release_memory_special(char* base, size_t bytes) { 2273 // detaching the SHM segment will also delete it, see reserve_memory_special() 2274 int rslt = shmdt(base); 2275 if (rslt == 0) { 2276 MemTracker::record_virtual_memory_uncommit((address)base, bytes); 2277 MemTracker::record_virtual_memory_release((address)base, bytes); 2278 return true; 2279 } else { 2280 return false; 2281 } 2282 2283 } 2284 2285 size_t os::large_page_size() { 2286 return _large_page_size; 2287 } 2288 2289 // HugeTLBFS allows application to commit large page memory on demand; 2290 // with SysV SHM the entire memory region must be allocated as shared 2291 // memory. 2292 bool os::can_commit_large_page_memory() { 2293 return UseHugeTLBFS; 2294 } 2295 2296 bool os::can_execute_large_page_memory() { 2297 return UseHugeTLBFS; 2298 } 2299 | 2245 2246 // attach to the region 2247 addr = (char*)shmat(shmid, req_addr, 0); 2248 int err = errno; 2249 2250 // Remove shmid. If shmat() is successful, the actual shared memory segment 2251 // will be deleted when it's detached by shmdt() or when the process 2252 // terminates. If shmat() is not successful this will remove the shared 2253 // segment immediately. 2254 shmctl(shmid, IPC_RMID, NULL); 2255 2256 if ((intptr_t)addr == -1) { 2257 if (warn_on_failure) { 2258 jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err); 2259 warning(msg); 2260 } 2261 return NULL; 2262 } 2263 2264 // The memory is committed 2265 NMTTrackOp op(NMTTrackOp::ReserveAndCommitOp); 2266 op.execute_op((address)addr, bytes, 0, CALLER_PC); 2267 2268 return addr; 2269 } 2270 2271 bool os::release_memory_special(char* base, size_t bytes) { 2272 // detaching the SHM segment will also delete it, see reserve_memory_special() 2273 NMTTrackOp op(NMTTrackOp::ReleaseOp); 2274 int rslt = shmdt(base); 2275 if (rslt == 0) { 2276 op.execute_op((address)base, bytes); 2277 return true; 2278 } else { 2279 op.abort_op(); 2280 return false; 2281 } 2282 2283 } 2284 2285 size_t os::large_page_size() { 2286 return _large_page_size; 2287 } 2288 2289 // HugeTLBFS allows application to commit large page memory on demand; 2290 // with SysV SHM the entire memory region must be allocated as shared 2291 // memory. 2292 bool os::can_commit_large_page_memory() { 2293 return UseHugeTLBFS; 2294 } 2295 2296 bool os::can_execute_large_page_memory() { 2297 return UseHugeTLBFS; 2298 } 2299 |