91 friend class MallocTracker; 92 public: 93 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel) 94 95 private: 96 static OSThread* _starting_thread; 97 static address _polling_page; 98 static volatile int32_t * _mem_serialize_page; 99 static uintptr_t _serialize_page_mask; 100 public: 101 static size_t _page_sizes[page_sizes_max]; 102 103 private: 104 static void init_page_sizes(size_t default_page_size) { 105 _page_sizes[0] = default_page_size; 106 _page_sizes[1] = 0; // sentinel 107 } 108 109 static char* pd_reserve_memory(size_t bytes, char* addr = 0, 110 size_t alignment_hint = 0); 111 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); 112 static void pd_split_reserved_memory(char *base, size_t size, 113 size_t split, bool realloc); 114 static bool pd_commit_memory(char* addr, size_t bytes, bool executable); 115 static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, 116 bool executable); 117 // Same as pd_commit_memory() that either succeeds or calls 118 // vm_exit_out_of_memory() with the specified mesg. 119 static void pd_commit_memory_or_exit(char* addr, size_t bytes, 120 bool executable, const char* mesg); 121 static void pd_commit_memory_or_exit(char* addr, size_t size, 122 size_t alignment_hint, 123 bool executable, const char* mesg); 124 static bool pd_uncommit_memory(char* addr, size_t bytes); 125 static bool pd_release_memory(char* addr, size_t bytes); 126 127 static char* pd_map_memory(int fd, const char* file_name, size_t file_offset, 128 char *addr, size_t bytes, bool read_only = false, 129 bool allow_exec = false); 130 static char* pd_remap_memory(int fd, const char* file_name, size_t file_offset, 131 char *addr, size_t bytes, bool read_only, 284 // The region_{min,max}_size parameters should be the values 285 // passed to page_size_for_region() and page_size should be the result of that 286 // call. The (optional) base and size parameters should come from the 287 // ReservedSpace base() and size() methods. 288 static void trace_page_sizes(const char* str, const size_t* page_sizes, int count); 289 static void trace_page_sizes(const char* str, 290 const size_t region_min_size, 291 const size_t region_max_size, 292 const size_t page_size, 293 const char* base, 294 const size_t size); 295 static void trace_page_sizes_for_requested_size(const char* str, 296 const size_t requested_size, 297 const size_t page_size, 298 const size_t alignment, 299 const char* base, 300 const size_t size); 301 302 static int vm_allocation_granularity(); 303 static char* reserve_memory(size_t bytes, char* addr = 0, 304 size_t alignment_hint = 0); 305 static char* reserve_memory(size_t bytes, char* addr, 306 size_t alignment_hint, MEMFLAGS flags); 307 static char* reserve_memory_aligned(size_t size, size_t alignment); 308 static char* attempt_reserve_memory_at(size_t bytes, char* addr); 309 static void split_reserved_memory(char *base, size_t size, 310 size_t split, bool realloc); 311 static bool commit_memory(char* addr, size_t bytes, bool executable); 312 static bool commit_memory(char* addr, size_t size, size_t alignment_hint, 313 bool executable); 314 // Same as commit_memory() that either succeeds or calls 315 // vm_exit_out_of_memory() with the specified mesg. 316 static void commit_memory_or_exit(char* addr, size_t bytes, 317 bool executable, const char* mesg); 318 static void commit_memory_or_exit(char* addr, size_t size, 319 size_t alignment_hint, 320 bool executable, const char* mesg); 321 static bool uncommit_memory(char* addr, size_t bytes); 322 static bool release_memory(char* addr, size_t bytes); 323 324 // Touch memory pages that cover the memory range from start to end (exclusive) 325 // to make the OS back the memory range with actual memory. 326 // Current implementation may not touch the last page if unaligned addresses 327 // are passed. 328 static void pretouch_memory(void* start, void* end, size_t page_size = vm_page_size()); 329 330 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX }; 331 static bool protect_memory(char* addr, size_t bytes, ProtType prot, 332 bool is_committed = true); 333 334 static bool guard_memory(char* addr, size_t bytes); 335 static bool unguard_memory(char* addr, size_t bytes); 336 static bool create_stack_guard_pages(char* addr, size_t bytes); 337 static bool pd_create_stack_guard_pages(char* addr, size_t bytes); 338 static bool remove_stack_guard_pages(char* addr, size_t bytes); 339 340 static char* map_memory(int fd, const char* file_name, size_t file_offset, 341 char *addr, size_t bytes, bool read_only = false, 342 bool allow_exec = false); 343 static char* remap_memory(int fd, const char* file_name, size_t file_offset, 344 char *addr, size_t bytes, bool read_only, 345 bool allow_exec); 346 static bool unmap_memory(char *addr, size_t bytes); 347 static void free_memory(char *addr, size_t bytes, size_t alignment_hint); 348 static void realign_memory(char *addr, size_t bytes, size_t alignment_hint); 349 350 // NUMA-specific interface 351 static bool numa_has_static_binding(); 352 static bool numa_has_group_homing(); 353 static void numa_make_local(char *addr, size_t bytes, int lgrp_hint); 354 static void numa_make_global(char *addr, size_t bytes); 355 static size_t numa_get_groups_num(); 356 static size_t numa_get_leaf_groups(int *ids, size_t size); 357 static bool numa_topology_changed(); 358 static int numa_get_group_id(); | 91 friend class MallocTracker; 92 public: 93 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel) 94 95 private: 96 static OSThread* _starting_thread; 97 static address _polling_page; 98 static volatile int32_t * _mem_serialize_page; 99 static uintptr_t _serialize_page_mask; 100 public: 101 static size_t _page_sizes[page_sizes_max]; 102 103 private: 104 static void init_page_sizes(size_t default_page_size) { 105 _page_sizes[0] = default_page_size; 106 _page_sizes[1] = 0; // sentinel 107 } 108 109 static char* pd_reserve_memory(size_t bytes, char* addr = 0, 110 size_t alignment_hint = 0); 111 #if defined(AIX) 112 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr, bool use_SHM = true); 113 #else 114 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); 115 #endif 116 static void pd_split_reserved_memory(char *base, size_t size, 117 size_t split, bool realloc); 118 static bool pd_commit_memory(char* addr, size_t bytes, bool executable); 119 static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, 120 bool executable); 121 // Same as pd_commit_memory() that either succeeds or calls 122 // vm_exit_out_of_memory() with the specified mesg. 123 static void pd_commit_memory_or_exit(char* addr, size_t bytes, 124 bool executable, const char* mesg); 125 static void pd_commit_memory_or_exit(char* addr, size_t size, 126 size_t alignment_hint, 127 bool executable, const char* mesg); 128 static bool pd_uncommit_memory(char* addr, size_t bytes); 129 static bool pd_release_memory(char* addr, size_t bytes); 130 131 static char* pd_map_memory(int fd, const char* file_name, size_t file_offset, 132 char *addr, size_t bytes, bool read_only = false, 133 bool allow_exec = false); 134 static char* pd_remap_memory(int fd, const char* file_name, size_t file_offset, 135 char *addr, size_t bytes, bool read_only, 288 // The region_{min,max}_size parameters should be the values 289 // passed to page_size_for_region() and page_size should be the result of that 290 // call. The (optional) base and size parameters should come from the 291 // ReservedSpace base() and size() methods. 292 static void trace_page_sizes(const char* str, const size_t* page_sizes, int count); 293 static void trace_page_sizes(const char* str, 294 const size_t region_min_size, 295 const size_t region_max_size, 296 const size_t page_size, 297 const char* base, 298 const size_t size); 299 static void trace_page_sizes_for_requested_size(const char* str, 300 const size_t requested_size, 301 const size_t page_size, 302 const size_t alignment, 303 const char* base, 304 const size_t size); 305 306 static int vm_allocation_granularity(); 307 static char* reserve_memory(size_t bytes, char* addr = 0, 308 size_t alignment_hint = 0, int file_desc = -1); 309 static char* reserve_memory(size_t bytes, char* addr, 310 size_t alignment_hint, MEMFLAGS flags); 311 static char* reserve_memory_aligned(size_t size, size_t alignment, int file_desc = -1); 312 static char* attempt_reserve_memory_at(size_t bytes, char* addr, int file_desc = -1); 313 314 static void split_reserved_memory(char *base, size_t size, 315 size_t split, bool realloc); 316 static bool commit_memory(char* addr, size_t bytes, bool executable); 317 static bool commit_memory(char* addr, size_t size, size_t alignment_hint, 318 bool executable); 319 // Same as commit_memory() that either succeeds or calls 320 // vm_exit_out_of_memory() with the specified mesg. 321 static void commit_memory_or_exit(char* addr, size_t bytes, 322 bool executable, const char* mesg); 323 static void commit_memory_or_exit(char* addr, size_t size, 324 size_t alignment_hint, 325 bool executable, const char* mesg); 326 static bool uncommit_memory(char* addr, size_t bytes); 327 static bool release_memory(char* addr, size_t bytes); 328 329 // Touch memory pages that cover the memory range from start to end (exclusive) 330 // to make the OS back the memory range with actual memory. 331 // Current implementation may not touch the last page if unaligned addresses 332 // are passed. 333 static void pretouch_memory(void* start, void* end, size_t page_size = vm_page_size()); 334 335 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX }; 336 static bool protect_memory(char* addr, size_t bytes, ProtType prot, 337 bool is_committed = true); 338 339 static bool guard_memory(char* addr, size_t bytes); 340 static bool unguard_memory(char* addr, size_t bytes); 341 static bool create_stack_guard_pages(char* addr, size_t bytes); 342 static bool pd_create_stack_guard_pages(char* addr, size_t bytes); 343 static bool remove_stack_guard_pages(char* addr, size_t bytes); 344 345 // Helper function to create a new file with template jvmheap.XXXXXX 346 static int create_file_for_heap(const char* dir, size_t size); 347 // map memory to the dax (direct access) file referred by fd 348 static char* map_memory_to_dax_file(char* base, size_t size, int fd); 349 // replace existing reserved memory with file mapping 350 static char* replace_existing_mapping_with_dax_file_mapping(char* base, size_t size, int fd); 351 352 static char* map_memory(int fd, const char* file_name, size_t file_offset, 353 char *addr, size_t bytes, bool read_only = false, 354 bool allow_exec = false); 355 static char* remap_memory(int fd, const char* file_name, size_t file_offset, 356 char *addr, size_t bytes, bool read_only, 357 bool allow_exec); 358 static bool unmap_memory(char *addr, size_t bytes); 359 static void free_memory(char *addr, size_t bytes, size_t alignment_hint); 360 static void realign_memory(char *addr, size_t bytes, size_t alignment_hint); 361 362 // NUMA-specific interface 363 static bool numa_has_static_binding(); 364 static bool numa_has_group_homing(); 365 static void numa_make_local(char *addr, size_t bytes, int lgrp_hint); 366 static void numa_make_global(char *addr, size_t bytes); 367 static size_t numa_get_groups_num(); 368 static size_t numa_get_leaf_groups(int *ids, size_t size); 369 static bool numa_topology_changed(); 370 static int numa_get_group_id(); |