61 // Platform-independent error return values from OS functions 62 enum OSReturn { 63 OS_OK = 0, // Operation was successful 64 OS_ERR = -1, // Operation failed 65 OS_INTRPT = -2, // Operation was interrupted 66 OS_TIMEOUT = -3, // Operation timed out 67 OS_NOMEM = -5, // Operation failed for lack of memory 68 OS_NORESOURCE = -6 // Operation failed for lack of nonmemory resource 69 }; 70 71 enum ThreadPriority { // JLS 20.20.1-3 72 NoPriority = -1, // Initial non-priority value 73 MinPriority = 1, // Minimum priority 74 NormPriority = 5, // Normal (non-daemon) priority 75 NearMaxPriority = 9, // High priority, used for VMThread 76 MaxPriority = 10, // Highest priority, used for WatcherThread 77 // ensures that VMThread doesn't starve profiler 78 CriticalPriority = 11 // Critical thread priority 79 }; 80 81 // Typedef for structured exception handling support 82 typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread); 83 84 class os: AllStatic { 85 public: 86 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel) 87 88 private: 89 static OSThread* _starting_thread; 90 static address _polling_page; 91 static volatile int32_t * _mem_serialize_page; 92 static uintptr_t _serialize_page_mask; 93 public: 94 static size_t _page_sizes[page_sizes_max]; 95 96 private: 97 static void init_page_sizes(size_t default_page_size) { 98 _page_sizes[0] = default_page_size; 99 _page_sizes[1] = 0; // sentinel 100 } 101 102 static char* pd_reserve_memory(size_t bytes, char* addr = 0, 103 size_t alignment_hint = 0); 104 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); 105 static void pd_split_reserved_memory(char *base, size_t size, 106 size_t split, bool realloc); 107 static bool pd_commit_memory(char* addr, size_t bytes, bool executable = false); 108 static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, 109 bool executable = false); 110 static bool pd_uncommit_memory(char* addr, size_t bytes); 111 static bool pd_release_memory(char* addr, size_t bytes); 112 113 static char* pd_map_memory(int fd, const char* file_name, size_t file_offset, 114 char *addr, size_t bytes, bool read_only = false, 115 bool allow_exec = false); 116 static char* pd_remap_memory(int fd, const char* file_name, size_t file_offset, 117 char *addr, size_t bytes, bool read_only, 118 bool allow_exec); 119 static bool pd_unmap_memory(char *addr, size_t bytes); 120 static void pd_free_memory(char *addr, size_t bytes, size_t alignment_hint); 121 static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint); 122 123 124 public: 125 static void init(void); // Called before command line parsing 126 static jint init_2(void); // Called after command line parsing 127 static void init_globals(void) { // Called from init_globals() in init.cpp 128 init_globals_ext(); 129 } 244 // passed to page_size_for_region() and page_size should be the result of that 245 // call. The (optional) base and size parameters should come from the 246 // ReservedSpace base() and size() methods. 247 static void trace_page_sizes(const char* str, const size_t* page_sizes, 248 int count) PRODUCT_RETURN; 249 static void trace_page_sizes(const char* str, const size_t region_min_size, 250 const size_t region_max_size, 251 const size_t page_size, 252 const char* base = NULL, 253 const size_t size = 0) PRODUCT_RETURN; 254 255 static int vm_allocation_granularity(); 256 static char* reserve_memory(size_t bytes, char* addr = 0, 257 size_t alignment_hint = 0); 258 static char* reserve_memory(size_t bytes, char* addr, 259 size_t alignment_hint, MEMFLAGS flags); 260 static char* reserve_memory_aligned(size_t size, size_t alignment); 261 static char* attempt_reserve_memory_at(size_t bytes, char* addr); 262 static void split_reserved_memory(char *base, size_t size, 263 size_t split, bool realloc); 264 static bool commit_memory(char* addr, size_t bytes, bool executable = false); 265 static bool commit_memory(char* addr, size_t size, size_t alignment_hint, 266 bool executable = false); 267 static bool uncommit_memory(char* addr, size_t bytes); 268 static bool release_memory(char* addr, size_t bytes); 269 270 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX }; 271 static bool protect_memory(char* addr, size_t bytes, ProtType prot, 272 bool is_committed = true); 273 274 static bool guard_memory(char* addr, size_t bytes); 275 static bool unguard_memory(char* addr, size_t bytes); 276 static bool create_stack_guard_pages(char* addr, size_t bytes); 277 static bool pd_create_stack_guard_pages(char* addr, size_t bytes); 278 static bool remove_stack_guard_pages(char* addr, size_t bytes); 279 280 static char* map_memory(int fd, const char* file_name, size_t file_offset, 281 char *addr, size_t bytes, bool read_only = false, 282 bool allow_exec = false); 283 static char* remap_memory(int fd, const char* file_name, size_t file_offset, 284 char *addr, size_t bytes, bool read_only, 285 bool allow_exec); 286 static bool unmap_memory(char *addr, size_t bytes); | 61 // Platform-independent error return values from OS functions 62 enum OSReturn { 63 OS_OK = 0, // Operation was successful 64 OS_ERR = -1, // Operation failed 65 OS_INTRPT = -2, // Operation was interrupted 66 OS_TIMEOUT = -3, // Operation timed out 67 OS_NOMEM = -5, // Operation failed for lack of memory 68 OS_NORESOURCE = -6 // Operation failed for lack of nonmemory resource 69 }; 70 71 enum ThreadPriority { // JLS 20.20.1-3 72 NoPriority = -1, // Initial non-priority value 73 MinPriority = 1, // Minimum priority 74 NormPriority = 5, // Normal (non-daemon) priority 75 NearMaxPriority = 9, // High priority, used for VMThread 76 MaxPriority = 10, // Highest priority, used for WatcherThread 77 // ensures that VMThread doesn't starve profiler 78 CriticalPriority = 11 // Critical thread priority 79 }; 80 81 // Executable parameter flag for os::commit_memory() and 82 // os::commit_memory_or_exit(). 83 enum ExecMemFlag { 84 ExecMem = true 85 }; 86 87 // Typedef for structured exception handling support 88 typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread); 89 90 class os: AllStatic { 91 public: 92 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel) 93 94 private: 95 static OSThread* _starting_thread; 96 static address _polling_page; 97 static volatile int32_t * _mem_serialize_page; 98 static uintptr_t _serialize_page_mask; 99 public: 100 static size_t _page_sizes[page_sizes_max]; 101 102 private: 103 static void init_page_sizes(size_t default_page_size) { 104 _page_sizes[0] = default_page_size; 105 _page_sizes[1] = 0; // sentinel 106 } 107 108 static char* pd_reserve_memory(size_t bytes, char* addr = 0, 109 size_t alignment_hint = 0); 110 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr); 111 static void pd_split_reserved_memory(char *base, size_t size, 112 size_t split, bool realloc); 113 static bool pd_commit_memory(char* addr, size_t bytes, bool executable); 114 static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint, 115 bool executable); 116 // Same as pd_commit_memory() that either succeeds or calls 117 // vm_exit_out_of_memory() with the specified mesg. 118 static void pd_commit_memory_or_exit(char* addr, size_t bytes, 119 bool executable, const char* mesg); 120 static void pd_commit_memory_or_exit(char* addr, size_t size, 121 size_t alignment_hint, 122 bool executable, const char* mesg); 123 static bool pd_uncommit_memory(char* addr, size_t bytes); 124 static bool pd_release_memory(char* addr, size_t bytes); 125 126 static char* pd_map_memory(int fd, const char* file_name, size_t file_offset, 127 char *addr, size_t bytes, bool read_only = false, 128 bool allow_exec = false); 129 static char* pd_remap_memory(int fd, const char* file_name, size_t file_offset, 130 char *addr, size_t bytes, bool read_only, 131 bool allow_exec); 132 static bool pd_unmap_memory(char *addr, size_t bytes); 133 static void pd_free_memory(char *addr, size_t bytes, size_t alignment_hint); 134 static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint); 135 136 137 public: 138 static void init(void); // Called before command line parsing 139 static jint init_2(void); // Called after command line parsing 140 static void init_globals(void) { // Called from init_globals() in init.cpp 141 init_globals_ext(); 142 } 257 // passed to page_size_for_region() and page_size should be the result of that 258 // call. The (optional) base and size parameters should come from the 259 // ReservedSpace base() and size() methods. 260 static void trace_page_sizes(const char* str, const size_t* page_sizes, 261 int count) PRODUCT_RETURN; 262 static void trace_page_sizes(const char* str, const size_t region_min_size, 263 const size_t region_max_size, 264 const size_t page_size, 265 const char* base = NULL, 266 const size_t size = 0) PRODUCT_RETURN; 267 268 static int vm_allocation_granularity(); 269 static char* reserve_memory(size_t bytes, char* addr = 0, 270 size_t alignment_hint = 0); 271 static char* reserve_memory(size_t bytes, char* addr, 272 size_t alignment_hint, MEMFLAGS flags); 273 static char* reserve_memory_aligned(size_t size, size_t alignment); 274 static char* attempt_reserve_memory_at(size_t bytes, char* addr); 275 static void split_reserved_memory(char *base, size_t size, 276 size_t split, bool realloc); 277 static bool commit_memory(char* addr, size_t bytes, bool executable); 278 static bool commit_memory(char* addr, size_t size, size_t alignment_hint, 279 bool executable); 280 // Same as commit_memory() that either succeeds or calls 281 // vm_exit_out_of_memory() with the specified mesg. 282 static void commit_memory_or_exit(char* addr, size_t bytes, 283 bool executable, const char* mesg); 284 static void commit_memory_or_exit(char* addr, size_t size, 285 size_t alignment_hint, 286 bool executable, const char* mesg); 287 static bool uncommit_memory(char* addr, size_t bytes); 288 static bool release_memory(char* addr, size_t bytes); 289 290 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX }; 291 static bool protect_memory(char* addr, size_t bytes, ProtType prot, 292 bool is_committed = true); 293 294 static bool guard_memory(char* addr, size_t bytes); 295 static bool unguard_memory(char* addr, size_t bytes); 296 static bool create_stack_guard_pages(char* addr, size_t bytes); 297 static bool pd_create_stack_guard_pages(char* addr, size_t bytes); 298 static bool remove_stack_guard_pages(char* addr, size_t bytes); 299 300 static char* map_memory(int fd, const char* file_name, size_t file_offset, 301 char *addr, size_t bytes, bool read_only = false, 302 bool allow_exec = false); 303 static char* remap_memory(int fd, const char* file_name, size_t file_offset, 304 char *addr, size_t bytes, bool read_only, 305 bool allow_exec); 306 static bool unmap_memory(char *addr, size_t bytes); |