src/os/linux/vm/os_linux.hpp

Thu, 26 Jul 2018 16:04:06 +0800

author
aoqi
date
Thu, 26 Jul 2018 16:04:06 +0800
changeset 9203
53eec13fbaa5
parent 9182
0f31f18d2241
parent 9041
95a08233f46c
child 9448
73d689add964
permissions
-rw-r--r--

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);
zgu@8878 193 // libnuma v2 (libnuma_1.2) symbols
zgu@8878 194 static void* libnuma_v2_dlsym(void* handle, const char* name);
aoqi@0 195 // Minimum stack size a thread can be created with (allowing
aoqi@0 196 // the VM to completely create the thread and enter user code)
aoqi@0 197 static size_t min_stack_allowed;
aoqi@0 198
aoqi@0 199 // Return default stack size or guard size for the specified thread type
aoqi@0 200 static size_t default_stack_size(os::ThreadType thr_type);
aoqi@0 201 static size_t default_guard_size(os::ThreadType thr_type);
aoqi@0 202
aoqi@0 203 static void capture_initial_stack(size_t max_size);
aoqi@0 204
aoqi@0 205 // Stack overflow handling
aoqi@0 206 static bool manually_expand_stack(JavaThread * t, address addr);
aoqi@0 207 static int max_register_window_saves_before_flushing();
aoqi@0 208
aoqi@0 209 // Real-time clock functions
aoqi@0 210 static void clock_init(void);
aoqi@0 211
aoqi@0 212 // fast POSIX clocks support
aoqi@0 213 static void fast_thread_clock_init(void);
aoqi@0 214
aoqi@0 215 static inline bool supports_monotonic_clock() {
aoqi@0 216 return _clock_gettime != NULL;
aoqi@0 217 }
aoqi@0 218
aoqi@0 219 static int clock_gettime(clockid_t clock_id, struct timespec *tp) {
aoqi@0 220 return _clock_gettime ? _clock_gettime(clock_id, tp) : -1;
aoqi@0 221 }
aoqi@0 222
aoqi@0 223 static int pthread_getcpuclockid(pthread_t tid, clockid_t *clock_id) {
aoqi@0 224 return _pthread_getcpuclockid ? _pthread_getcpuclockid(tid, clock_id) : -1;
aoqi@0 225 }
aoqi@0 226
aoqi@0 227 static bool supports_fast_thread_cpu_time() {
aoqi@0 228 return _supports_fast_thread_cpu_time;
aoqi@0 229 }
aoqi@0 230
aoqi@0 231 static jlong fast_thread_cpu_time(clockid_t clockid);
aoqi@0 232
aoqi@0 233 // pthread_cond clock suppport
aoqi@0 234 private:
aoqi@0 235 static pthread_condattr_t _condattr[1];
aoqi@0 236
aoqi@0 237 public:
aoqi@0 238 static pthread_condattr_t* condAttr() { return _condattr; }
aoqi@0 239
aoqi@0 240 // Stack repair handling
aoqi@0 241
aoqi@0 242 // none present
aoqi@0 243
aoqi@0 244 // LinuxThreads work-around for 6292965
aoqi@0 245 static int safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime);
aoqi@0 246
aoqi@0 247 private:
aoqi@0 248 typedef int (*sched_getcpu_func_t)(void);
aoqi@0 249 typedef int (*numa_node_to_cpus_func_t)(int node, unsigned long *buffer, int bufferlen);
aoqi@0 250 typedef int (*numa_max_node_func_t)(void);
gromero@8776 251 typedef int (*numa_num_configured_nodes_func_t)(void);
aoqi@0 252 typedef int (*numa_available_func_t)(void);
aoqi@0 253 typedef int (*numa_tonode_memory_func_t)(void *start, size_t size, int node);
aoqi@0 254 typedef void (*numa_interleave_memory_func_t)(void *start, size_t size, unsigned long *nodemask);
zgu@8878 255 typedef void (*numa_interleave_memory_v2_func_t)(void *start, size_t size, struct bitmask* mask);
zgu@8878 256
aoqi@0 257 typedef void (*numa_set_bind_policy_func_t)(int policy);
gromero@8776 258 typedef int (*numa_bitmask_isbitset_func_t)(struct bitmask *bmp, unsigned int n);
gromero@8776 259 typedef int (*numa_distance_func_t)(int node1, int node2);
aoqi@0 260
aoqi@0 261 static sched_getcpu_func_t _sched_getcpu;
aoqi@0 262 static numa_node_to_cpus_func_t _numa_node_to_cpus;
aoqi@0 263 static numa_max_node_func_t _numa_max_node;
gromero@8776 264 static numa_num_configured_nodes_func_t _numa_num_configured_nodes;
aoqi@0 265 static numa_available_func_t _numa_available;
aoqi@0 266 static numa_tonode_memory_func_t _numa_tonode_memory;
aoqi@0 267 static numa_interleave_memory_func_t _numa_interleave_memory;
zgu@8878 268 static numa_interleave_memory_v2_func_t _numa_interleave_memory_v2;
aoqi@0 269 static numa_set_bind_policy_func_t _numa_set_bind_policy;
gromero@8776 270 static numa_bitmask_isbitset_func_t _numa_bitmask_isbitset;
gromero@8776 271 static numa_distance_func_t _numa_distance;
aoqi@0 272 static unsigned long* _numa_all_nodes;
gromero@8776 273 static struct bitmask* _numa_all_nodes_ptr;
gromero@8776 274 static struct bitmask* _numa_nodes_ptr;
aoqi@0 275
aoqi@0 276 static void set_sched_getcpu(sched_getcpu_func_t func) { _sched_getcpu = func; }
aoqi@0 277 static void set_numa_node_to_cpus(numa_node_to_cpus_func_t func) { _numa_node_to_cpus = func; }
aoqi@0 278 static void set_numa_max_node(numa_max_node_func_t func) { _numa_max_node = func; }
gromero@8776 279 static void set_numa_num_configured_nodes(numa_num_configured_nodes_func_t func) { _numa_num_configured_nodes = func; }
aoqi@0 280 static void set_numa_available(numa_available_func_t func) { _numa_available = func; }
aoqi@0 281 static void set_numa_tonode_memory(numa_tonode_memory_func_t func) { _numa_tonode_memory = func; }
aoqi@0 282 static void set_numa_interleave_memory(numa_interleave_memory_func_t func) { _numa_interleave_memory = func; }
zgu@8878 283 static void set_numa_interleave_memory_v2(numa_interleave_memory_v2_func_t func) { _numa_interleave_memory_v2 = func; }
aoqi@0 284 static void set_numa_set_bind_policy(numa_set_bind_policy_func_t func) { _numa_set_bind_policy = func; }
gromero@8776 285 static void set_numa_bitmask_isbitset(numa_bitmask_isbitset_func_t func) { _numa_bitmask_isbitset = func; }
gromero@8776 286 static void set_numa_distance(numa_distance_func_t func) { _numa_distance = func; }
aoqi@0 287 static void set_numa_all_nodes(unsigned long* ptr) { _numa_all_nodes = ptr; }
gromero@9182 288 static void set_numa_all_nodes_ptr(struct bitmask **ptr) { _numa_all_nodes_ptr = (ptr == NULL ? NULL : *ptr); }
gromero@9182 289 static void set_numa_nodes_ptr(struct bitmask **ptr) { _numa_nodes_ptr = (ptr == NULL ? NULL : *ptr); }
aoqi@0 290 static int sched_getcpu_syscall(void);
aoqi@0 291 public:
aoqi@0 292 static int sched_getcpu() { return _sched_getcpu != NULL ? _sched_getcpu() : -1; }
aoqi@0 293 static int numa_node_to_cpus(int node, unsigned long *buffer, int bufferlen) {
aoqi@0 294 return _numa_node_to_cpus != NULL ? _numa_node_to_cpus(node, buffer, bufferlen) : -1;
aoqi@0 295 }
aoqi@0 296 static int numa_max_node() { return _numa_max_node != NULL ? _numa_max_node() : -1; }
gromero@8776 297 static int numa_num_configured_nodes() {
gromero@8776 298 return _numa_num_configured_nodes != NULL ? _numa_num_configured_nodes() : -1;
gromero@8776 299 }
aoqi@0 300 static int numa_available() { return _numa_available != NULL ? _numa_available() : -1; }
aoqi@0 301 static int numa_tonode_memory(void *start, size_t size, int node) {
aoqi@0 302 return _numa_tonode_memory != NULL ? _numa_tonode_memory(start, size, node) : -1;
aoqi@0 303 }
aoqi@0 304 static void numa_interleave_memory(void *start, size_t size) {
zgu@8878 305 // Use v2 api if available
zgu@8878 306 if (_numa_interleave_memory_v2 != NULL && _numa_all_nodes_ptr != NULL) {
zgu@8878 307 _numa_interleave_memory_v2(start, size, _numa_all_nodes_ptr);
zgu@8878 308 } else if (_numa_interleave_memory != NULL && _numa_all_nodes != NULL) {
aoqi@0 309 _numa_interleave_memory(start, size, _numa_all_nodes);
aoqi@0 310 }
aoqi@0 311 }
aoqi@0 312 static void numa_set_bind_policy(int policy) {
aoqi@0 313 if (_numa_set_bind_policy != NULL) {
aoqi@0 314 _numa_set_bind_policy(policy);
aoqi@0 315 }
aoqi@0 316 }
gromero@8776 317 static int numa_distance(int node1, int node2) {
gromero@8776 318 return _numa_distance != NULL ? _numa_distance(node1, node2) : -1;
gromero@8776 319 }
aoqi@0 320 static int get_node_by_cpu(int cpu_id);
gromero@8776 321 static int get_existing_num_nodes();
gromero@8776 322 // Check if numa node is configured (non-zero memory node).
gromero@8776 323 static bool isnode_in_configured_nodes(unsigned int n) {
gromero@8776 324 if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) {
gromero@8776 325 return _numa_bitmask_isbitset(_numa_all_nodes_ptr, n);
gromero@8776 326 } else
gromero@8776 327 return 0;
gromero@8776 328 }
gromero@8776 329 // Check if numa node exists in the system (including zero memory nodes).
gromero@8776 330 static bool isnode_in_existing_nodes(unsigned int n) {
gromero@8776 331 if (_numa_bitmask_isbitset != NULL && _numa_nodes_ptr != NULL) {
gromero@8776 332 return _numa_bitmask_isbitset(_numa_nodes_ptr, n);
gromero@9182 333 } else if (_numa_bitmask_isbitset != NULL && _numa_all_nodes_ptr != NULL) {
gromero@9182 334 // Not all libnuma API v2 implement numa_nodes_ptr, so it's not possible
gromero@9182 335 // to trust the API version for checking its absence. On the other hand,
gromero@9182 336 // numa_nodes_ptr found in libnuma 2.0.9 and above is the only way to get
gromero@9182 337 // a complete view of all numa nodes in the system, hence numa_nodes_ptr
gromero@9182 338 // is used to handle CPU and nodes on architectures (like PowerPC) where
gromero@9182 339 // there can exist nodes with CPUs but no memory or vice-versa and the
gromero@9182 340 // nodes may be non-contiguous. For most of the architectures, like
gromero@9182 341 // x86_64, numa_node_ptr presents the same node set as found in
gromero@9182 342 // numa_all_nodes_ptr so it's possible to use numa_all_nodes_ptr as a
gromero@9182 343 // substitute.
gromero@9182 344 return _numa_bitmask_isbitset(_numa_all_nodes_ptr, n);
gromero@8776 345 } else
gromero@8776 346 return 0;
gromero@8776 347 }
aoqi@0 348 };
aoqi@0 349
aoqi@0 350
aoqi@0 351 class PlatformEvent : public CHeapObj<mtInternal> {
aoqi@0 352 private:
aoqi@0 353 double CachePad [4] ; // increase odds that _mutex is sole occupant of cache line
aoqi@0 354 volatile int _Event ;
aoqi@0 355 volatile int _nParked ;
aoqi@0 356 pthread_mutex_t _mutex [1] ;
aoqi@0 357 pthread_cond_t _cond [1] ;
aoqi@0 358 double PostPad [2] ;
aoqi@0 359 Thread * _Assoc ;
aoqi@0 360
aoqi@0 361 public: // TODO-FIXME: make dtor private
aoqi@0 362 ~PlatformEvent() { guarantee (0, "invariant") ; }
aoqi@0 363
aoqi@0 364 public:
aoqi@0 365 PlatformEvent() {
aoqi@0 366 int status;
aoqi@0 367 status = pthread_cond_init (_cond, os::Linux::condAttr());
aoqi@0 368 assert_status(status == 0, status, "cond_init");
aoqi@0 369 status = pthread_mutex_init (_mutex, NULL);
aoqi@0 370 assert_status(status == 0, status, "mutex_init");
aoqi@0 371 _Event = 0 ;
aoqi@0 372 _nParked = 0 ;
aoqi@0 373 _Assoc = NULL ;
aoqi@0 374 }
aoqi@0 375
aoqi@0 376 // Use caution with reset() and fired() -- they may require MEMBARs
aoqi@0 377 void reset() { _Event = 0 ; }
aoqi@0 378 int fired() { return _Event; }
aoqi@0 379 void park () ;
aoqi@0 380 void unpark () ;
aoqi@0 381 int TryPark () ;
aoqi@0 382 int park (jlong millis) ; // relative timed-wait only
aoqi@0 383 void SetAssociation (Thread * a) { _Assoc = a ; }
aoqi@0 384 } ;
aoqi@0 385
aoqi@0 386 class PlatformParker : public CHeapObj<mtInternal> {
aoqi@0 387 protected:
aoqi@0 388 enum {
aoqi@0 389 REL_INDEX = 0,
aoqi@0 390 ABS_INDEX = 1
aoqi@0 391 };
aoqi@0 392 int _cur_index; // which cond is in use: -1, 0, 1
aoqi@0 393 pthread_mutex_t _mutex [1] ;
aoqi@0 394 pthread_cond_t _cond [2] ; // one for relative times and one for abs.
aoqi@0 395
aoqi@0 396 public: // TODO-FIXME: make dtor private
aoqi@0 397 ~PlatformParker() { guarantee (0, "invariant") ; }
aoqi@0 398
aoqi@0 399 public:
aoqi@0 400 PlatformParker() {
aoqi@0 401 int status;
aoqi@0 402 status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr());
aoqi@0 403 assert_status(status == 0, status, "cond_init rel");
aoqi@0 404 status = pthread_cond_init (&_cond[ABS_INDEX], NULL);
aoqi@0 405 assert_status(status == 0, status, "cond_init abs");
aoqi@0 406 status = pthread_mutex_init (_mutex, NULL);
aoqi@0 407 assert_status(status == 0, status, "mutex_init");
aoqi@0 408 _cur_index = -1; // mark as unused
aoqi@0 409 }
aoqi@0 410 };
aoqi@0 411
aoqi@0 412 #endif // OS_LINUX_VM_OS_LINUX_HPP

mercurial