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