src/os/linux/vm/os_linux.hpp

Thu, 21 Nov 2013 18:29:34 -0800

author
goetz
date
Thu, 21 Nov 2013 18:29:34 -0800
changeset 6486
b0133e4187d3
parent 5679
2e6938dd68f2
child 6876
710a3c8b516e
child 7074
833b0f92429a
permissions
-rw-r--r--

8028471: PPC64 (part 215): opto: Extend ImplicitNullCheck optimization.
Summary: Fixed Implicit NULL check optimization for AIX, where the page at address '0' is only write-protected.
Reviewed-by: kvn

duke@435 1 /*
simonis@4675 2 * Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved.
duke@435 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@435 4 *
duke@435 5 * This code is free software; you can redistribute it and/or modify it
duke@435 6 * under the terms of the GNU General Public License version 2 only, as
duke@435 7 * published by the Free Software Foundation.
duke@435 8 *
duke@435 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@435 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@435 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@435 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@435 13 * accompanied this code).
duke@435 14 *
duke@435 15 * You should have received a copy of the GNU General Public License version
duke@435 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@435 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@435 18 *
trims@1907 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1907 20 * or visit www.oracle.com if you need additional information or have any
trims@1907 21 * questions.
duke@435 22 *
duke@435 23 */
duke@435 24
stefank@2314 25 #ifndef OS_LINUX_VM_OS_LINUX_HPP
stefank@2314 26 #define OS_LINUX_VM_OS_LINUX_HPP
stefank@2314 27
duke@435 28 // Linux_OS defines the interface to Linux operating systems
duke@435 29
duke@435 30 /* pthread_getattr_np comes with LinuxThreads-0.9-7 on RedHat 7.1 */
duke@435 31 typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *);
duke@435 32
goetz@6486 33 // Information about the protection of the page at address '0' on this os.
goetz@6486 34 static bool zero_page_read_protected() { return true; }
goetz@6486 35
duke@435 36 class Linux {
duke@435 37 friend class os;
stefank@5578 38 friend class TestReserveMemorySpecial;
duke@435 39
duke@435 40 // For signal-chaining
duke@435 41 #define MAXSIGNUM 32
duke@435 42 static struct sigaction sigact[MAXSIGNUM]; // saved preinstalled sigactions
duke@435 43 static unsigned int sigs; // mask of signals that have
duke@435 44 // preinstalled signal handlers
duke@435 45 static bool libjsig_is_loaded; // libjsig that interposes sigaction(),
duke@435 46 // __sigaction(), signal() is loaded
duke@435 47 static struct sigaction *(*get_signal_action)(int);
duke@435 48 static struct sigaction *get_preinstalled_handler(int);
duke@435 49 static void save_preinstalled_handler(int, struct sigaction&);
duke@435 50
duke@435 51 static void check_signal_handler(int sig);
duke@435 52
duke@435 53 // For signal flags diagnostics
duke@435 54 static int sigflags[MAXSIGNUM];
duke@435 55
duke@435 56 static int (*_clock_gettime)(clockid_t, struct timespec *);
duke@435 57 static int (*_pthread_getcpuclockid)(pthread_t, clockid_t *);
duke@435 58
duke@435 59 static address _initial_thread_stack_bottom;
duke@435 60 static uintptr_t _initial_thread_stack_size;
duke@435 61
xlu@634 62 static const char *_glibc_version;
xlu@634 63 static const char *_libpthread_version;
duke@435 64
duke@435 65 static bool _is_floating_stack;
duke@435 66 static bool _is_NPTL;
duke@435 67 static bool _supports_fast_thread_cpu_time;
duke@435 68
iveresov@576 69 static GrowableArray<int>* _cpu_to_node;
iveresov@576 70
duke@435 71 protected:
duke@435 72
duke@435 73 static julong _physical_memory;
duke@435 74 static pthread_t _main_thread;
duke@435 75 static Mutex* _createThread_lock;
duke@435 76 static int _page_size;
vladidan@4996 77 static const int _vm_default_page_size;
duke@435 78
duke@435 79 static julong available_memory();
duke@435 80 static julong physical_memory() { return _physical_memory; }
duke@435 81 static void initialize_system_info();
duke@435 82
dcubed@5255 83 static int commit_memory_impl(char* addr, size_t bytes, bool exec);
dcubed@5255 84 static int commit_memory_impl(char* addr, size_t bytes,
dcubed@5255 85 size_t alignment_hint, bool exec);
dcubed@5255 86
xlu@634 87 static void set_glibc_version(const char *s) { _glibc_version = s; }
xlu@634 88 static void set_libpthread_version(const char *s) { _libpthread_version = s; }
duke@435 89
duke@435 90 static bool supports_variable_stack_size();
duke@435 91
duke@435 92 static void set_is_NPTL() { _is_NPTL = true; }
duke@435 93 static void set_is_LinuxThreads() { _is_NPTL = false; }
duke@435 94 static void set_is_floating_stack() { _is_floating_stack = true; }
duke@435 95
iveresov@576 96 static void rebuild_cpu_to_node_map();
iveresov@576 97 static GrowableArray<int>* cpu_to_node() { return _cpu_to_node; }
iveresov@2818 98
stefank@5578 99 static size_t find_large_page_size();
stefank@5578 100 static size_t setup_large_page_size();
stefank@5578 101
stefank@5578 102 static bool setup_large_page_type(size_t page_size);
stefank@5578 103 static bool transparent_huge_pages_sanity_check(bool warn, size_t pages_size);
iveresov@2818 104 static bool hugetlbfs_sanity_check(bool warn, size_t page_size);
iveresov@2818 105
stefank@5578 106 static char* reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec);
stefank@5578 107 static char* reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec);
stefank@5578 108 static char* reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec);
stefank@5578 109 static char* reserve_memory_special_huge_tlbfs_mixed(size_t bytes, size_t alignment, char* req_addr, bool exec);
stefank@5578 110
stefank@5578 111 static bool release_memory_special_shm(char* base, size_t bytes);
stefank@5578 112 static bool release_memory_special_huge_tlbfs(char* base, size_t bytes);
stefank@5578 113
nloodin@3783 114 static void print_full_memory_info(outputStream* st);
nloodin@3783 115 static void print_distro_info(outputStream* st);
nloodin@3783 116 static void print_libversion_info(outputStream* st);
nloodin@3783 117
duke@435 118 public:
iklam@4710 119 static bool _stack_is_executable;
iklam@4812 120 static void *dlopen_helper(const char *name, char *ebuf, int ebuflen);
iklam@4812 121 static void *dll_load_in_vmthread(const char *name, char *ebuf, int ebuflen);
iklam@4710 122
duke@435 123 static void init_thread_fpu_state();
duke@435 124 static int get_fpu_control_word();
duke@435 125 static void set_fpu_control_word(int fpu_control);
duke@435 126 static pthread_t main_thread(void) { return _main_thread; }
duke@435 127 // returns kernel thread id (similar to LWP id on Solaris), which can be
duke@435 128 // used to access /proc
duke@435 129 static pid_t gettid();
duke@435 130 static void set_createThread_lock(Mutex* lk) { _createThread_lock = lk; }
duke@435 131 static Mutex* createThread_lock(void) { return _createThread_lock; }
duke@435 132 static void hotspot_sigmask(Thread* thread);
duke@435 133
duke@435 134 static address initial_thread_stack_bottom(void) { return _initial_thread_stack_bottom; }
duke@435 135 static uintptr_t initial_thread_stack_size(void) { return _initial_thread_stack_size; }
duke@435 136 static bool is_initial_thread(void);
duke@435 137
duke@435 138 static int page_size(void) { return _page_size; }
duke@435 139 static void set_page_size(int val) { _page_size = val; }
duke@435 140
vladidan@4996 141 static int vm_default_page_size(void) { return _vm_default_page_size; }
vladidan@4996 142
duke@435 143 static address ucontext_get_pc(ucontext_t* uc);
duke@435 144 static intptr_t* ucontext_get_sp(ucontext_t* uc);
duke@435 145 static intptr_t* ucontext_get_fp(ucontext_t* uc);
duke@435 146
duke@435 147 // For Analyzer Forte AsyncGetCallTrace profiling support:
duke@435 148 //
duke@435 149 // This interface should be declared in os_linux_i486.hpp, but
duke@435 150 // that file provides extensions to the os class and not the
duke@435 151 // Linux class.
duke@435 152 static ExtendedPC fetch_frame_from_ucontext(Thread* thread, ucontext_t* uc,
duke@435 153 intptr_t** ret_sp, intptr_t** ret_fp);
duke@435 154
duke@435 155 // This boolean allows users to forward their own non-matching signals
duke@435 156 // to JVM_handle_linux_signal, harmlessly.
duke@435 157 static bool signal_handlers_are_installed;
duke@435 158
duke@435 159 static int get_our_sigflags(int);
duke@435 160 static void set_our_sigflags(int, int);
duke@435 161 static void signal_sets_init();
duke@435 162 static void install_signal_handlers();
duke@435 163 static void set_signal_handler(int, bool);
duke@435 164 static bool is_sig_ignored(int sig);
duke@435 165
duke@435 166 static sigset_t* unblocked_signals();
duke@435 167 static sigset_t* vm_signals();
duke@435 168 static sigset_t* allowdebug_blocked_signals();
duke@435 169
duke@435 170 // For signal-chaining
duke@435 171 static struct sigaction *get_chained_signal_action(int sig);
duke@435 172 static bool chained_handler(int sig, siginfo_t* siginfo, void* context);
duke@435 173
duke@435 174 // GNU libc and libpthread version strings
xlu@634 175 static const char *glibc_version() { return _glibc_version; }
xlu@634 176 static const char *libpthread_version() { return _libpthread_version; }
duke@435 177
duke@435 178 // NPTL or LinuxThreads?
duke@435 179 static bool is_LinuxThreads() { return !_is_NPTL; }
duke@435 180 static bool is_NPTL() { return _is_NPTL; }
duke@435 181
duke@435 182 // NPTL is always floating stack. LinuxThreads could be using floating
duke@435 183 // stack or fixed stack.
duke@435 184 static bool is_floating_stack() { return _is_floating_stack; }
duke@435 185
duke@435 186 static void libpthread_init();
iveresov@897 187 static bool libnuma_init();
iveresov@1198 188 static void* libnuma_dlsym(void* handle, const char* name);
duke@435 189 // Minimum stack size a thread can be created with (allowing
duke@435 190 // the VM to completely create the thread and enter user code)
duke@435 191 static size_t min_stack_allowed;
duke@435 192
duke@435 193 // Return default stack size or guard size for the specified thread type
duke@435 194 static size_t default_stack_size(os::ThreadType thr_type);
duke@435 195 static size_t default_guard_size(os::ThreadType thr_type);
duke@435 196
duke@435 197 static void capture_initial_stack(size_t max_size);
duke@435 198
duke@435 199 // Stack overflow handling
duke@435 200 static bool manually_expand_stack(JavaThread * t, address addr);
duke@435 201 static int max_register_window_saves_before_flushing();
duke@435 202
duke@435 203 // Real-time clock functions
duke@435 204 static void clock_init(void);
duke@435 205
duke@435 206 // fast POSIX clocks support
duke@435 207 static void fast_thread_clock_init(void);
duke@435 208
johnc@4017 209 static inline bool supports_monotonic_clock() {
duke@435 210 return _clock_gettime != NULL;
duke@435 211 }
duke@435 212
duke@435 213 static int clock_gettime(clockid_t clock_id, struct timespec *tp) {
duke@435 214 return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
duke@435 215 }
duke@435 216
duke@435 217 static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
duke@435 218 return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
duke@435 219 }
duke@435 220
duke@435 221 static bool supports_fast_thread_cpu_time() {
duke@435 222 return _supports_fast_thread_cpu_time;
duke@435 223 }
duke@435 224
duke@435 225 static jlong fast_thread_cpu_time(clockid_t clockid);
duke@435 226
dholmes@5679 227 // pthread_cond clock suppport
dholmes@5679 228 private:
dholmes@5679 229 static pthread_condattr_t _condattr[1];
dholmes@5679 230
dholmes@5679 231 public:
dholmes@5679 232 static pthread_condattr_t* condAttr() { return _condattr; }
dholmes@5679 233
duke@435 234 // Stack repair handling
duke@435 235
duke@435 236 // none present
duke@435 237
duke@435 238 // LinuxThreads work-around for 6292965
duke@435 239 static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
duke@435 240
iveresov@576 241 private:
iveresov@576 242 typedef int (*sched_getcpu_func_t)(void);
iveresov@576 243 typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
iveresov@576 244 typedef int (*numa_max_node_func_t)(void);
iveresov@576 245 typedef int (*numa_available_func_t)(void);
iveresov@576 246 typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
iveresov@897 247 typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
mgerdin@5644 248 typedef void (*numa_set_bind_policy_func_t)(int policy);
iveresov@576 249
iveresov@576 250 static sched_getcpu_func_t _sched_getcpu;
iveresov@576 251 static numa_node_to_cpus_func_t _numa_node_to_cpus;
iveresov@576 252 static numa_max_node_func_t _numa_max_node;
iveresov@576 253 static numa_available_func_t _numa_available;
iveresov@576 254 static numa_tonode_memory_func_t _numa_tonode_memory;
iveresov@897 255 static numa_interleave_memory_func_t _numa_interleave_memory;
mgerdin@5644 256 static numa_set_bind_policy_func_t _numa_set_bind_policy;
iveresov@897 257 static unsigned long* _numa_all_nodes;
iveresov@576 258
iveresov@576 259 static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
iveresov@576 260 static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
iveresov@576 261 static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
iveresov@576 262 static void set_numa_available(numa_available_func_t func) { _numa_available = func; }
iveresov@576 263 static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }
iveresov@897 264 static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
mgerdin@5644 265 static void set_numa_set_bind_policy(numa_set_bind_policy_func_t func) { _numa_set_bind_policy = func; }
iveresov@897 266 static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
iveresov@3024 267 static int sched_getcpu_syscall(void);
iveresov@576 268 public:
iveresov@576 269 static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
iveresov@576 270 static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
iveresov@576 271 return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
iveresov@576 272 }
iveresov@576 273 static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }
iveresov@576 274 static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }
iveresov@576 275 static int numa_tonode_memory(void *start, size_t size, int node) {
iveresov@576 276 return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
iveresov@576 277 }
iveresov@897 278 static void numa_interleave_memory(void *start, size_t size) {
iveresov@897 279 if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {
iveresov@897 280 _numa_interleave_memory(start, size, _numa_all_nodes);
iveresov@897 281 }
iveresov@897 282 }
mgerdin@5644 283 static void numa_set_bind_policy(int policy) {
mgerdin@5644 284 if (_numa_set_bind_policy != NULL) {
mgerdin@5644 285 _numa_set_bind_policy(policy);
mgerdin@5644 286 }
mgerdin@5644 287 }
iveresov@576 288 static int get_node_by_cpu(int cpu_id);
duke@435 289 };
duke@435 290
duke@435 291
zgu@3900 292 class PlatformEvent : public CHeapObj<mtInternal> {
duke@435 293 private:
duke@435 294 double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line
duke@435 295 volatile int _Event ;
duke@435 296 volatile int _nParked ;
duke@435 297 pthread_mutex_t _mutex [1] ;
duke@435 298 pthread_cond_t _cond [1] ;
duke@435 299 double PostPad [2] ;
duke@435 300 Thread * _Assoc ;
duke@435 301
duke@435 302 public: // TODO-FIXME: make dtor private
duke@435 303 ~PlatformEvent() { guarantee (0, "invariant") ; }
duke@435 304
duke@435 305 public:
duke@435 306 PlatformEvent() {
duke@435 307 int status;
dholmes@5679 308 status = pthread_cond_init (_cond, os::Linux::condAttr());
duke@435 309 assert_status(status == 0, status, "cond_init");
duke@435 310 status = pthread_mutex_init (_mutex, NULL);
duke@435 311 assert_status(status == 0, status, "mutex_init");
duke@435 312 _Event = 0 ;
duke@435 313 _nParked = 0 ;
duke@435 314 _Assoc = NULL ;
duke@435 315 }
duke@435 316
duke@435 317 // Use caution with reset() and fired() -- they may require MEMBARs
duke@435 318 void reset() { _Event = 0 ; }
duke@435 319 int fired() { return _Event; }
duke@435 320 void park () ;
duke@435 321 void unpark () ;
duke@435 322 int TryPark () ;
dholmes@5679 323 int park (jlong millis) ; // relative timed-wait only
duke@435 324 void SetAssociation (Thread * a) { _Assoc = a ; }
duke@435 325 } ;
duke@435 326
zgu@3900 327 class PlatformParker : public CHeapObj<mtInternal> {
duke@435 328 protected:
dholmes@5679 329 enum {
dholmes@5679 330 REL_INDEX = 0,
dholmes@5679 331 ABS_INDEX = 1
dholmes@5679 332 };
dholmes@5679 333 int _cur_index; // which cond is in use: -1, 0, 1
duke@435 334 pthread_mutex_t _mutex [1] ;
dholmes@5679 335 pthread_cond_t _cond [2] ; // one for relative times and one for abs.
duke@435 336
duke@435 337 public: // TODO-FIXME: make dtor private
duke@435 338 ~PlatformParker() { guarantee (0, "invariant") ; }
duke@435 339
duke@435 340 public:
duke@435 341 PlatformParker() {
duke@435 342 int status;
dholmes@5679 343 status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr());
dholmes@5679 344 assert_status(status == 0, status, "cond_init rel");
dholmes@5679 345 status = pthread_cond_init (&_cond[ABS_INDEX], NULL);
dholmes@5679 346 assert_status(status == 0, status, "cond_init abs");
duke@435 347 status = pthread_mutex_init (_mutex, NULL);
duke@435 348 assert_status(status == 0, status, "mutex_init");
dholmes@5679 349 _cur_index = -1; // mark as unused
duke@435 350 }
sla@5237 351 };
stefank@2314 352
stefank@2314 353 #endif // OS_LINUX_VM_OS_LINUX_HPP

mercurial