src/share/vm/runtime/os.hpp

Fri, 29 Apr 2016 00:06:10 +0800

author
aoqi
date
Fri, 29 Apr 2016 00:06:10 +0800
changeset 1
2d8a650513c2
parent 0
f90c822e73f8
child 25
873fd82b133d
permissions
-rw-r--r--

Added MIPS 64-bit port.

aoqi@0 1 /*
aoqi@0 2 * Copyright (c) 1997, 2014, 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@1 25 /*
aoqi@1 26 * This file has been modified by Loongson Technology in 2015. These
aoqi@1 27 * modifications are Copyright (c) 2015 Loongson Technology, and are made
aoqi@1 28 * available on the same license terms set forth above.
aoqi@1 29 */
aoqi@1 30
aoqi@0 31 #ifndef SHARE_VM_RUNTIME_OS_HPP
aoqi@0 32 #define SHARE_VM_RUNTIME_OS_HPP
aoqi@0 33
aoqi@0 34 #include "jvmtifiles/jvmti.h"
aoqi@0 35 #include "runtime/atomic.hpp"
aoqi@0 36 #include "runtime/extendedPC.hpp"
aoqi@0 37 #include "runtime/handles.hpp"
aoqi@0 38 #include "utilities/top.hpp"
aoqi@0 39 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 40 # include "jvm_linux.h"
aoqi@0 41 # include <setjmp.h>
aoqi@0 42 #endif
aoqi@0 43 #ifdef TARGET_OS_FAMILY_solaris
aoqi@0 44 # include "jvm_solaris.h"
aoqi@0 45 # include <setjmp.h>
aoqi@0 46 #endif
aoqi@0 47 #ifdef TARGET_OS_FAMILY_windows
aoqi@0 48 # include "jvm_windows.h"
aoqi@0 49 #endif
aoqi@0 50 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 51 # include "jvm_aix.h"
aoqi@0 52 # include <setjmp.h>
aoqi@0 53 #endif
aoqi@0 54 #ifdef TARGET_OS_FAMILY_bsd
aoqi@0 55 # include "jvm_bsd.h"
aoqi@0 56 # include <setjmp.h>
aoqi@0 57 # ifdef __APPLE__
aoqi@0 58 # include <mach/mach_time.h>
aoqi@0 59 # endif
aoqi@0 60 #endif
aoqi@0 61
aoqi@0 62 class AgentLibrary;
aoqi@0 63
aoqi@0 64 // os defines the interface to operating system; this includes traditional
aoqi@0 65 // OS services (time, I/O) as well as other functionality with system-
aoqi@0 66 // dependent code.
aoqi@0 67
aoqi@0 68 typedef void (*dll_func)(...);
aoqi@0 69
aoqi@0 70 class Thread;
aoqi@0 71 class JavaThread;
aoqi@0 72 class Event;
aoqi@0 73 class DLL;
aoqi@0 74 class FileHandle;
aoqi@0 75 template<class E> class GrowableArray;
aoqi@0 76
aoqi@0 77 // %%%%% Moved ThreadState, START_FN, OSThread to new osThread.hpp. -- Rose
aoqi@0 78
aoqi@0 79 // Platform-independent error return values from OS functions
aoqi@0 80 enum OSReturn {
aoqi@0 81 OS_OK = 0, // Operation was successful
aoqi@0 82 OS_ERR = -1, // Operation failed
aoqi@0 83 OS_INTRPT = -2, // Operation was interrupted
aoqi@0 84 OS_TIMEOUT = -3, // Operation timed out
aoqi@0 85 OS_NOMEM = -5, // Operation failed for lack of memory
aoqi@0 86 OS_NORESOURCE = -6 // Operation failed for lack of nonmemory resource
aoqi@0 87 };
aoqi@0 88
aoqi@0 89 enum ThreadPriority { // JLS 20.20.1-3
aoqi@0 90 NoPriority = -1, // Initial non-priority value
aoqi@0 91 MinPriority = 1, // Minimum priority
aoqi@0 92 NormPriority = 5, // Normal (non-daemon) priority
aoqi@0 93 NearMaxPriority = 9, // High priority, used for VMThread
aoqi@0 94 MaxPriority = 10, // Highest priority, used for WatcherThread
aoqi@0 95 // ensures that VMThread doesn't starve profiler
aoqi@0 96 CriticalPriority = 11 // Critical thread priority
aoqi@0 97 };
aoqi@0 98
aoqi@0 99 // Executable parameter flag for os::commit_memory() and
aoqi@0 100 // os::commit_memory_or_exit().
aoqi@0 101 const bool ExecMem = true;
aoqi@0 102
aoqi@0 103 // Typedef for structured exception handling support
aoqi@0 104 typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
aoqi@0 105
aoqi@0 106 class os: AllStatic {
aoqi@0 107 friend class VMStructs;
aoqi@0 108
aoqi@0 109 public:
aoqi@0 110 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel)
aoqi@0 111
aoqi@0 112 private:
aoqi@0 113 static OSThread* _starting_thread;
aoqi@0 114 static address _polling_page;
aoqi@0 115 static volatile int32_t * _mem_serialize_page;
aoqi@0 116 static uintptr_t _serialize_page_mask;
aoqi@0 117 public:
aoqi@0 118 static size_t _page_sizes[page_sizes_max];
aoqi@0 119
aoqi@0 120 private:
aoqi@0 121 static void init_page_sizes(size_t default_page_size) {
aoqi@0 122 _page_sizes[0] = default_page_size;
aoqi@0 123 _page_sizes[1] = 0; // sentinel
aoqi@0 124 }
aoqi@0 125
aoqi@0 126 static char* pd_reserve_memory(size_t bytes, char* addr = 0,
aoqi@0 127 size_t alignment_hint = 0);
aoqi@0 128 static char* pd_attempt_reserve_memory_at(size_t bytes, char* addr);
aoqi@0 129 static void pd_split_reserved_memory(char *base, size_t size,
aoqi@0 130 size_t split, bool realloc);
aoqi@0 131 static bool pd_commit_memory(char* addr, size_t bytes, bool executable);
aoqi@0 132 static bool pd_commit_memory(char* addr, size_t size, size_t alignment_hint,
aoqi@0 133 bool executable);
aoqi@0 134 // Same as pd_commit_memory() that either succeeds or calls
aoqi@0 135 // vm_exit_out_of_memory() with the specified mesg.
aoqi@0 136 static void pd_commit_memory_or_exit(char* addr, size_t bytes,
aoqi@0 137 bool executable, const char* mesg);
aoqi@0 138 static void pd_commit_memory_or_exit(char* addr, size_t size,
aoqi@0 139 size_t alignment_hint,
aoqi@0 140 bool executable, const char* mesg);
aoqi@0 141 static bool pd_uncommit_memory(char* addr, size_t bytes);
aoqi@0 142 static bool pd_release_memory(char* addr, size_t bytes);
aoqi@0 143
aoqi@0 144 static char* pd_map_memory(int fd, const char* file_name, size_t file_offset,
aoqi@0 145 char *addr, size_t bytes, bool read_only = false,
aoqi@0 146 bool allow_exec = false);
aoqi@0 147 static char* pd_remap_memory(int fd, const char* file_name, size_t file_offset,
aoqi@0 148 char *addr, size_t bytes, bool read_only,
aoqi@0 149 bool allow_exec);
aoqi@0 150 static bool pd_unmap_memory(char *addr, size_t bytes);
aoqi@0 151 static void pd_free_memory(char *addr, size_t bytes, size_t alignment_hint);
aoqi@0 152 static void pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint);
aoqi@0 153
aoqi@0 154
aoqi@0 155 public:
aoqi@0 156 static void init(void); // Called before command line parsing
aoqi@0 157 static void init_before_ergo(void); // Called after command line parsing
aoqi@0 158 // before VM ergonomics processing.
aoqi@0 159 static jint init_2(void); // Called after command line parsing
aoqi@0 160 // and VM ergonomics processing
aoqi@0 161 static void init_globals(void) { // Called from init_globals() in init.cpp
aoqi@0 162 init_globals_ext();
aoqi@0 163 }
aoqi@0 164 static void init_3(void); // Called at the end of vm init
aoqi@0 165
aoqi@0 166 // File names are case-insensitive on windows only
aoqi@0 167 // Override me as needed
aoqi@0 168 static int file_name_strcmp(const char* s1, const char* s2);
aoqi@0 169
aoqi@0 170 static bool getenv(const char* name, char* buffer, int len);
aoqi@0 171 static bool have_special_privileges();
aoqi@0 172
aoqi@0 173 static jlong javaTimeMillis();
aoqi@0 174 static jlong javaTimeNanos();
aoqi@0 175 static void javaTimeNanos_info(jvmtiTimerInfo *info_ptr);
aoqi@0 176 static void run_periodic_checks();
aoqi@0 177
aoqi@0 178
aoqi@0 179 // Returns the elapsed time in seconds since the vm started.
aoqi@0 180 static double elapsedTime();
aoqi@0 181
aoqi@0 182 // Returns real time in seconds since an arbitrary point
aoqi@0 183 // in the past.
aoqi@0 184 static bool getTimesSecs(double* process_real_time,
aoqi@0 185 double* process_user_time,
aoqi@0 186 double* process_system_time);
aoqi@0 187
aoqi@0 188 // Interface to the performance counter
aoqi@0 189 static jlong elapsed_counter();
aoqi@0 190 static jlong elapsed_frequency();
aoqi@0 191
aoqi@0 192 // The "virtual time" of a thread is the amount of time a thread has
aoqi@0 193 // actually run. The first function indicates whether the OS supports
aoqi@0 194 // this functionality for the current thread, and if so:
aoqi@0 195 // * the second enables vtime tracking (if that is required).
aoqi@0 196 // * the third tells whether vtime is enabled.
aoqi@0 197 // * the fourth returns the elapsed virtual time for the current
aoqi@0 198 // thread.
aoqi@0 199 static bool supports_vtime();
aoqi@0 200 static bool enable_vtime();
aoqi@0 201 static bool vtime_enabled();
aoqi@0 202 static double elapsedVTime();
aoqi@0 203
aoqi@0 204 // Return current local time in a string (YYYY-MM-DD HH:MM:SS).
aoqi@0 205 // It is MT safe, but not async-safe, as reading time zone
aoqi@0 206 // information may require a lock on some platforms.
aoqi@0 207 static char* local_time_string(char *buf, size_t buflen);
aoqi@0 208 static struct tm* localtime_pd (const time_t* clock, struct tm* res);
aoqi@0 209 // Fill in buffer with current local time as an ISO-8601 string.
aoqi@0 210 // E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
aoqi@0 211 // Returns buffer, or NULL if it failed.
aoqi@0 212 static char* iso8601_time(char* buffer, size_t buffer_length);
aoqi@0 213
aoqi@0 214 // Interface for detecting multiprocessor system
aoqi@0 215 static inline bool is_MP() {
aoqi@0 216 assert(_processor_count > 0, "invalid processor count");
aoqi@0 217 return _processor_count > 1 || AssumeMP;
aoqi@0 218 }
aoqi@0 219 static julong available_memory();
aoqi@0 220 static julong physical_memory();
aoqi@0 221 static bool has_allocatable_memory_limit(julong* limit);
aoqi@0 222 static bool is_server_class_machine();
aoqi@0 223
aoqi@0 224 // number of CPUs
aoqi@0 225 static int processor_count() {
aoqi@0 226 return _processor_count;
aoqi@0 227 }
aoqi@0 228 static void set_processor_count(int count) { _processor_count = count; }
aoqi@0 229
aoqi@0 230 // Returns the number of CPUs this process is currently allowed to run on.
aoqi@0 231 // Note that on some OSes this can change dynamically.
aoqi@0 232 static int active_processor_count();
aoqi@0 233
aoqi@0 234 // Bind processes to processors.
aoqi@0 235 // This is a two step procedure:
aoqi@0 236 // first you generate a distribution of processes to processors,
aoqi@0 237 // then you bind processes according to that distribution.
aoqi@0 238 // Compute a distribution for number of processes to processors.
aoqi@0 239 // Stores the processor id's into the distribution array argument.
aoqi@0 240 // Returns true if it worked, false if it didn't.
aoqi@0 241 static bool distribute_processes(uint length, uint* distribution);
aoqi@0 242 // Binds the current process to a processor.
aoqi@0 243 // Returns true if it worked, false if it didn't.
aoqi@0 244 static bool bind_to_processor(uint processor_id);
aoqi@0 245
aoqi@0 246 // Give a name to the current thread.
aoqi@0 247 static void set_native_thread_name(const char *name);
aoqi@0 248
aoqi@0 249 // Interface for stack banging (predetect possible stack overflow for
aoqi@0 250 // exception processing) There are guard pages, and above that shadow
aoqi@0 251 // pages for stack overflow checking.
aoqi@0 252 static bool uses_stack_guard_pages();
aoqi@0 253 static bool allocate_stack_guard_pages();
aoqi@0 254 static void bang_stack_shadow_pages();
aoqi@0 255 static bool stack_shadow_pages_available(Thread *thread, methodHandle method);
aoqi@0 256
aoqi@0 257 // OS interface to Virtual Memory
aoqi@0 258
aoqi@0 259 // Return the default page size.
aoqi@0 260 static int vm_page_size();
aoqi@0 261
aoqi@0 262 // Return the page size to use for a region of memory. The min_pages argument
aoqi@0 263 // is a hint intended to limit fragmentation; it says the returned page size
aoqi@0 264 // should be <= region_max_size / min_pages. Because min_pages is a hint,
aoqi@0 265 // this routine may return a size larger than region_max_size / min_pages.
aoqi@0 266 //
aoqi@0 267 // The current implementation ignores min_pages if a larger page size is an
aoqi@0 268 // exact multiple of both region_min_size and region_max_size. This allows
aoqi@0 269 // larger pages to be used when doing so would not cause fragmentation; in
aoqi@0 270 // particular, a single page can be used when region_min_size ==
aoqi@0 271 // region_max_size == a supported page size.
aoqi@0 272 static size_t page_size_for_region(size_t region_min_size,
aoqi@0 273 size_t region_max_size,
aoqi@0 274 uint min_pages);
aoqi@0 275 // Return the largest page size that can be used
aoqi@0 276 static size_t max_page_size() {
aoqi@0 277 // The _page_sizes array is sorted in descending order.
aoqi@0 278 return _page_sizes[0];
aoqi@0 279 }
aoqi@0 280
aoqi@0 281 // Methods for tracing page sizes returned by the above method; enabled by
aoqi@0 282 // TracePageSizes. The region_{min,max}_size parameters should be the values
aoqi@0 283 // passed to page_size_for_region() and page_size should be the result of that
aoqi@0 284 // call. The (optional) base and size parameters should come from the
aoqi@0 285 // ReservedSpace base() and size() methods.
aoqi@0 286 static void trace_page_sizes(const char* str, const size_t* page_sizes,
aoqi@0 287 int count) PRODUCT_RETURN;
aoqi@0 288 static void trace_page_sizes(const char* str, const size_t region_min_size,
aoqi@0 289 const size_t region_max_size,
aoqi@0 290 const size_t page_size,
aoqi@0 291 const char* base = NULL,
aoqi@0 292 const size_t size = 0) PRODUCT_RETURN;
aoqi@0 293
aoqi@0 294 static int vm_allocation_granularity();
aoqi@0 295 static char* reserve_memory(size_t bytes, char* addr = 0,
aoqi@0 296 size_t alignment_hint = 0);
aoqi@0 297 static char* reserve_memory(size_t bytes, char* addr,
aoqi@0 298 size_t alignment_hint, MEMFLAGS flags);
aoqi@0 299 static char* reserve_memory_aligned(size_t size, size_t alignment);
aoqi@0 300 static char* attempt_reserve_memory_at(size_t bytes, char* addr);
aoqi@0 301 static void split_reserved_memory(char *base, size_t size,
aoqi@0 302 size_t split, bool realloc);
aoqi@0 303 static bool commit_memory(char* addr, size_t bytes, bool executable);
aoqi@0 304 static bool commit_memory(char* addr, size_t size, size_t alignment_hint,
aoqi@0 305 bool executable);
aoqi@0 306 // Same as commit_memory() that either succeeds or calls
aoqi@0 307 // vm_exit_out_of_memory() with the specified mesg.
aoqi@0 308 static void commit_memory_or_exit(char* addr, size_t bytes,
aoqi@0 309 bool executable, const char* mesg);
aoqi@0 310 static void commit_memory_or_exit(char* addr, size_t size,
aoqi@0 311 size_t alignment_hint,
aoqi@0 312 bool executable, const char* mesg);
aoqi@0 313 static bool uncommit_memory(char* addr, size_t bytes);
aoqi@0 314 static bool release_memory(char* addr, size_t bytes);
aoqi@0 315
aoqi@0 316 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX };
aoqi@0 317 static bool protect_memory(char* addr, size_t bytes, ProtType prot,
aoqi@0 318 bool is_committed = true);
aoqi@0 319
aoqi@0 320 static bool guard_memory(char* addr, size_t bytes);
aoqi@0 321 static bool unguard_memory(char* addr, size_t bytes);
aoqi@0 322 static bool create_stack_guard_pages(char* addr, size_t bytes);
aoqi@0 323 static bool pd_create_stack_guard_pages(char* addr, size_t bytes);
aoqi@0 324 static bool remove_stack_guard_pages(char* addr, size_t bytes);
aoqi@0 325
aoqi@0 326 static char* map_memory(int fd, const char* file_name, size_t file_offset,
aoqi@0 327 char *addr, size_t bytes, bool read_only = false,
aoqi@0 328 bool allow_exec = false);
aoqi@0 329 static char* remap_memory(int fd, const char* file_name, size_t file_offset,
aoqi@0 330 char *addr, size_t bytes, bool read_only,
aoqi@0 331 bool allow_exec);
aoqi@0 332 static bool unmap_memory(char *addr, size_t bytes);
aoqi@0 333 static void free_memory(char *addr, size_t bytes, size_t alignment_hint);
aoqi@0 334 static void realign_memory(char *addr, size_t bytes, size_t alignment_hint);
aoqi@0 335
aoqi@0 336 // NUMA-specific interface
aoqi@0 337 static bool numa_has_static_binding();
aoqi@0 338 static bool numa_has_group_homing();
aoqi@0 339 static void numa_make_local(char *addr, size_t bytes, int lgrp_hint);
aoqi@0 340 static void numa_make_global(char *addr, size_t bytes);
aoqi@0 341 static size_t numa_get_groups_num();
aoqi@0 342 static size_t numa_get_leaf_groups(int *ids, size_t size);
aoqi@0 343 static bool numa_topology_changed();
aoqi@0 344 static int numa_get_group_id();
aoqi@1 345 static int numa_get_cpu_id();
aoqi@0 346
aoqi@0 347 // Page manipulation
aoqi@0 348 struct page_info {
aoqi@0 349 size_t size;
aoqi@0 350 int lgrp_id;
aoqi@0 351 };
aoqi@0 352 static bool get_page_info(char *start, page_info* info);
aoqi@0 353 static char* scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found);
aoqi@0 354
aoqi@0 355 static char* non_memory_address_word();
aoqi@0 356 // reserve, commit and pin the entire memory region
aoqi@0 357 static char* reserve_memory_special(size_t size, size_t alignment,
aoqi@0 358 char* addr, bool executable);
aoqi@0 359 static bool release_memory_special(char* addr, size_t bytes);
aoqi@0 360 static void large_page_init();
aoqi@0 361 static size_t large_page_size();
aoqi@0 362 static bool can_commit_large_page_memory();
aoqi@0 363 static bool can_execute_large_page_memory();
aoqi@0 364
aoqi@0 365 // OS interface to polling page
aoqi@0 366 static address get_polling_page() { return _polling_page; }
aoqi@0 367 static void set_polling_page(address page) { _polling_page = page; }
aoqi@0 368 static bool is_poll_address(address addr) { return addr >= _polling_page && addr < (_polling_page + os::vm_page_size()); }
aoqi@0 369 static void make_polling_page_unreadable();
aoqi@0 370 static void make_polling_page_readable();
aoqi@0 371
aoqi@0 372 // Routines used to serialize the thread state without using membars
aoqi@0 373 static void serialize_thread_states();
aoqi@0 374
aoqi@0 375 // Since we write to the serialize page from every thread, we
aoqi@0 376 // want stores to be on unique cache lines whenever possible
aoqi@0 377 // in order to minimize CPU cross talk. We pre-compute the
aoqi@0 378 // amount to shift the thread* to make this offset unique to
aoqi@0 379 // each thread.
aoqi@0 380 static int get_serialize_page_shift_count() {
aoqi@0 381 return SerializePageShiftCount;
aoqi@0 382 }
aoqi@0 383
aoqi@0 384 static void set_serialize_page_mask(uintptr_t mask) {
aoqi@0 385 _serialize_page_mask = mask;
aoqi@0 386 }
aoqi@0 387
aoqi@0 388 static unsigned int get_serialize_page_mask() {
aoqi@0 389 return _serialize_page_mask;
aoqi@0 390 }
aoqi@0 391
aoqi@0 392 static void set_memory_serialize_page(address page);
aoqi@0 393
aoqi@0 394 static address get_memory_serialize_page() {
aoqi@0 395 return (address)_mem_serialize_page;
aoqi@0 396 }
aoqi@0 397
aoqi@0 398 static inline void write_memory_serialize_page(JavaThread *thread) {
aoqi@0 399 uintptr_t page_offset = ((uintptr_t)thread >>
aoqi@0 400 get_serialize_page_shift_count()) &
aoqi@0 401 get_serialize_page_mask();
aoqi@0 402 *(volatile int32_t *)((uintptr_t)_mem_serialize_page+page_offset) = 1;
aoqi@0 403 }
aoqi@0 404
aoqi@0 405 static bool is_memory_serialize_page(JavaThread *thread, address addr) {
aoqi@0 406 if (UseMembar) return false;
aoqi@0 407 // Previously this function calculated the exact address of this
aoqi@0 408 // thread's serialize page, and checked if the faulting address
aoqi@0 409 // was equal. However, some platforms mask off faulting addresses
aoqi@0 410 // to the page size, so now we just check that the address is
aoqi@0 411 // within the page. This makes the thread argument unnecessary,
aoqi@0 412 // but we retain the NULL check to preserve existing behaviour.
aoqi@0 413 if (thread == NULL) return false;
aoqi@0 414 address page = (address) _mem_serialize_page;
aoqi@0 415 return addr >= page && addr < (page + os::vm_page_size());
aoqi@0 416 }
aoqi@0 417
aoqi@0 418 static void block_on_serialize_page_trap();
aoqi@0 419
aoqi@0 420 // threads
aoqi@0 421
aoqi@0 422 enum ThreadType {
aoqi@0 423 vm_thread,
aoqi@0 424 cgc_thread, // Concurrent GC thread
aoqi@0 425 pgc_thread, // Parallel GC thread
aoqi@0 426 java_thread,
aoqi@0 427 compiler_thread,
aoqi@0 428 watcher_thread,
aoqi@0 429 os_thread
aoqi@0 430 };
aoqi@0 431
aoqi@0 432 static bool create_thread(Thread* thread,
aoqi@0 433 ThreadType thr_type,
aoqi@0 434 size_t stack_size = 0);
aoqi@0 435 static bool create_main_thread(JavaThread* thread);
aoqi@0 436 static bool create_attached_thread(JavaThread* thread);
aoqi@0 437 static void pd_start_thread(Thread* thread);
aoqi@0 438 static void start_thread(Thread* thread);
aoqi@0 439
aoqi@0 440 static void initialize_thread(Thread* thr);
aoqi@0 441 static void free_thread(OSThread* osthread);
aoqi@0 442
aoqi@0 443 // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
aoqi@0 444 static intx current_thread_id();
aoqi@0 445 static int current_process_id();
aoqi@0 446 static int sleep(Thread* thread, jlong ms, bool interruptable);
aoqi@0 447 // Short standalone OS sleep suitable for slow path spin loop.
aoqi@0 448 // Ignores Thread.interrupt() (so keep it short).
aoqi@0 449 // ms = 0, will sleep for the least amount of time allowed by the OS.
aoqi@0 450 static void naked_short_sleep(jlong ms);
aoqi@0 451 static void infinite_sleep(); // never returns, use with CAUTION
aoqi@0 452 static void yield(); // Yields to all threads with same priority
aoqi@0 453 enum YieldResult {
aoqi@0 454 YIELD_SWITCHED = 1, // caller descheduled, other ready threads exist & ran
aoqi@0 455 YIELD_NONEREADY = 0, // No other runnable/ready threads.
aoqi@0 456 // platform-specific yield return immediately
aoqi@0 457 YIELD_UNKNOWN = -1 // Unknown: platform doesn't support _SWITCHED or _NONEREADY
aoqi@0 458 // YIELD_SWITCHED and YIELD_NONREADY imply the platform supports a "strong"
aoqi@0 459 // yield that can be used in lieu of blocking.
aoqi@0 460 } ;
aoqi@0 461 static YieldResult NakedYield () ;
aoqi@0 462 static void yield_all(int attempts = 0); // Yields to all other threads including lower priority
aoqi@0 463 static void loop_breaker(int attempts); // called from within tight loops to possibly influence time-sharing
aoqi@0 464 static OSReturn set_priority(Thread* thread, ThreadPriority priority);
aoqi@0 465 static OSReturn get_priority(const Thread* const thread, ThreadPriority& priority);
aoqi@0 466
aoqi@0 467 static void interrupt(Thread* thread);
aoqi@0 468 static bool is_interrupted(Thread* thread, bool clear_interrupted);
aoqi@0 469
aoqi@0 470 static int pd_self_suspend_thread(Thread* thread);
aoqi@0 471
aoqi@0 472 static ExtendedPC fetch_frame_from_context(void* ucVoid, intptr_t** sp, intptr_t** fp);
aoqi@0 473 static frame fetch_frame_from_context(void* ucVoid);
aoqi@0 474
aoqi@0 475 static ExtendedPC get_thread_pc(Thread *thread);
aoqi@0 476 static void breakpoint();
aoqi@0 477
aoqi@0 478 static address current_stack_pointer();
aoqi@0 479 static address current_stack_base();
aoqi@0 480 static size_t current_stack_size();
aoqi@0 481
aoqi@0 482 static void verify_stack_alignment() PRODUCT_RETURN;
aoqi@0 483
aoqi@0 484 static int message_box(const char* title, const char* message);
aoqi@0 485 static char* do_you_want_to_debug(const char* message);
aoqi@0 486
aoqi@0 487 // run cmd in a separate process and return its exit code; or -1 on failures
aoqi@0 488 static int fork_and_exec(char *cmd);
aoqi@0 489
aoqi@0 490 // os::exit() is merged with vm_exit()
aoqi@0 491 // static void exit(int num);
aoqi@0 492
aoqi@0 493 // Terminate the VM, but don't exit the process
aoqi@0 494 static void shutdown();
aoqi@0 495
aoqi@0 496 // Terminate with an error. Default is to generate a core file on platforms
aoqi@0 497 // that support such things. This calls shutdown() and then aborts.
aoqi@0 498 static void abort(bool dump_core = true);
aoqi@0 499
aoqi@0 500 // Die immediately, no exit hook, no abort hook, no cleanup.
aoqi@0 501 static void die();
aoqi@0 502
aoqi@0 503 // File i/o operations
aoqi@0 504 static const int default_file_open_flags();
aoqi@0 505 static int open(const char *path, int oflag, int mode);
aoqi@0 506 static FILE* open(int fd, const char* mode);
aoqi@0 507 static int close(int fd);
aoqi@0 508 static jlong lseek(int fd, jlong offset, int whence);
aoqi@0 509 static char* native_path(char *path);
aoqi@0 510 static int ftruncate(int fd, jlong length);
aoqi@0 511 static int fsync(int fd);
aoqi@0 512 static int available(int fd, jlong *bytes);
aoqi@0 513
aoqi@0 514 //File i/o operations
aoqi@0 515
aoqi@0 516 static size_t read(int fd, void *buf, unsigned int nBytes);
aoqi@0 517 static size_t restartable_read(int fd, void *buf, unsigned int nBytes);
aoqi@0 518 static size_t write(int fd, const void *buf, unsigned int nBytes);
aoqi@0 519
aoqi@0 520 // Reading directories.
aoqi@0 521 static DIR* opendir(const char* dirname);
aoqi@0 522 static int readdir_buf_size(const char *path);
aoqi@0 523 static struct dirent* readdir(DIR* dirp, dirent* dbuf);
aoqi@0 524 static int closedir(DIR* dirp);
aoqi@0 525
aoqi@0 526 // Dynamic library extension
aoqi@0 527 static const char* dll_file_extension();
aoqi@0 528
aoqi@0 529 static const char* get_temp_directory();
aoqi@0 530 static const char* get_current_directory(char *buf, size_t buflen);
aoqi@0 531
aoqi@0 532 // Builds a platform-specific full library path given a ld path and lib name
aoqi@0 533 // Returns true if buffer contains full path to existing file, false otherwise
aoqi@0 534 static bool dll_build_name(char* buffer, size_t size,
aoqi@0 535 const char* pathname, const char* fname);
aoqi@0 536
aoqi@0 537 // Symbol lookup, find nearest function name; basically it implements
aoqi@0 538 // dladdr() for all platforms. Name of the nearest function is copied
aoqi@0 539 // to buf. Distance from its base address is optionally returned as offset.
aoqi@0 540 // If function name is not found, buf[0] is set to '\0' and offset is
aoqi@0 541 // set to -1 (if offset is non-NULL).
aoqi@0 542 static bool dll_address_to_function_name(address addr, char* buf,
aoqi@0 543 int buflen, int* offset);
aoqi@0 544
aoqi@0 545 // Locate DLL/DSO. On success, full path of the library is copied to
aoqi@0 546 // buf, and offset is optionally set to be the distance between addr
aoqi@0 547 // and the library's base address. On failure, buf[0] is set to '\0'
aoqi@0 548 // and offset is set to -1 (if offset is non-NULL).
aoqi@0 549 static bool dll_address_to_library_name(address addr, char* buf,
aoqi@0 550 int buflen, int* offset);
aoqi@0 551
aoqi@0 552 // Find out whether the pc is in the static code for jvm.dll/libjvm.so.
aoqi@0 553 static bool address_is_in_vm(address addr);
aoqi@0 554
aoqi@0 555 // Loads .dll/.so and
aoqi@0 556 // in case of error it checks if .dll/.so was built for the
aoqi@0 557 // same architecture as Hotspot is running on
aoqi@0 558 static void* dll_load(const char *name, char *ebuf, int ebuflen);
aoqi@0 559
aoqi@0 560 // lookup symbol in a shared library
aoqi@0 561 static void* dll_lookup(void* handle, const char* name);
aoqi@0 562
aoqi@0 563 // Unload library
aoqi@0 564 static void dll_unload(void *lib);
aoqi@0 565
aoqi@0 566 // Return the handle of this process
aoqi@0 567 static void* get_default_process_handle();
aoqi@0 568
aoqi@0 569 // Check for static linked agent library
aoqi@0 570 static bool find_builtin_agent(AgentLibrary *agent_lib, const char *syms[],
aoqi@0 571 size_t syms_len);
aoqi@0 572
aoqi@0 573 // Find agent entry point
aoqi@0 574 static void *find_agent_function(AgentLibrary *agent_lib, bool check_lib,
aoqi@0 575 const char *syms[], size_t syms_len);
aoqi@0 576
aoqi@0 577 // Print out system information; they are called by fatal error handler.
aoqi@0 578 // Output format may be different on different platforms.
aoqi@0 579 static void print_os_info(outputStream* st);
aoqi@0 580 static void print_os_info_brief(outputStream* st);
aoqi@0 581 static void print_cpu_info(outputStream* st);
aoqi@0 582 static void pd_print_cpu_info(outputStream* st);
aoqi@0 583 static void print_memory_info(outputStream* st);
aoqi@0 584 static void print_dll_info(outputStream* st);
aoqi@0 585 static void print_environment_variables(outputStream* st, const char** env_list, char* buffer, int len);
aoqi@0 586 static void print_context(outputStream* st, void* context);
aoqi@0 587 static void print_register_info(outputStream* st, void* context);
aoqi@0 588 static void print_siginfo(outputStream* st, void* siginfo);
aoqi@0 589 static void print_signal_handlers(outputStream* st, char* buf, size_t buflen);
aoqi@0 590 static void print_date_and_time(outputStream* st);
aoqi@0 591
aoqi@0 592 static void print_location(outputStream* st, intptr_t x, bool verbose = false);
aoqi@0 593 static size_t lasterror(char *buf, size_t len);
aoqi@0 594 static int get_last_error();
aoqi@0 595
aoqi@0 596 // Determines whether the calling process is being debugged by a user-mode debugger.
aoqi@0 597 static bool is_debugger_attached();
aoqi@0 598
aoqi@0 599 // wait for a key press if PauseAtExit is set
aoqi@0 600 static void wait_for_keypress_at_exit(void);
aoqi@0 601
aoqi@0 602 // The following two functions are used by fatal error handler to trace
aoqi@0 603 // native (C) frames. They are not part of frame.hpp/frame.cpp because
aoqi@0 604 // frame.hpp/cpp assume thread is JavaThread, and also because different
aoqi@0 605 // OS/compiler may have different convention or provide different API to
aoqi@0 606 // walk C frames.
aoqi@0 607 //
aoqi@0 608 // We don't attempt to become a debugger, so we only follow frames if that
aoqi@0 609 // does not require a lookup in the unwind table, which is part of the binary
aoqi@0 610 // file but may be unsafe to read after a fatal error. So on x86, we can
aoqi@0 611 // only walk stack if %ebp is used as frame pointer; on ia64, it's not
aoqi@0 612 // possible to walk C stack without having the unwind table.
aoqi@0 613 static bool is_first_C_frame(frame *fr);
aoqi@0 614 static frame get_sender_for_C_frame(frame *fr);
aoqi@0 615
aoqi@0 616 // return current frame. pc() and sp() are set to NULL on failure.
aoqi@0 617 static frame current_frame();
aoqi@0 618
aoqi@0 619 static void print_hex_dump(outputStream* st, address start, address end, int unitsize);
aoqi@0 620
aoqi@0 621 // returns a string to describe the exception/signal;
aoqi@0 622 // returns NULL if exception_code is not an OS exception/signal.
aoqi@0 623 static const char* exception_name(int exception_code, char* buf, size_t buflen);
aoqi@0 624
aoqi@0 625 // Returns native Java library, loads if necessary
aoqi@0 626 static void* native_java_library();
aoqi@0 627
aoqi@0 628 // Fills in path to jvm.dll/libjvm.so (used by the Disassembler)
aoqi@0 629 static void jvm_path(char *buf, jint buflen);
aoqi@0 630
aoqi@0 631 // Returns true if we are running in a headless jre.
aoqi@0 632 static bool is_headless_jre();
aoqi@0 633
aoqi@0 634 // JNI names
aoqi@0 635 static void print_jni_name_prefix_on(outputStream* st, int args_size);
aoqi@0 636 static void print_jni_name_suffix_on(outputStream* st, int args_size);
aoqi@0 637
aoqi@0 638 // File conventions
aoqi@0 639 static const char* file_separator();
aoqi@0 640 static const char* line_separator();
aoqi@0 641 static const char* path_separator();
aoqi@0 642
aoqi@0 643 // Init os specific system properties values
aoqi@0 644 static void init_system_properties_values();
aoqi@0 645
aoqi@0 646 // IO operations, non-JVM_ version.
aoqi@0 647 static int stat(const char* path, struct stat* sbuf);
aoqi@0 648 static bool dir_is_empty(const char* path);
aoqi@0 649
aoqi@0 650 // IO operations on binary files
aoqi@0 651 static int create_binary_file(const char* path, bool rewrite_existing);
aoqi@0 652 static jlong current_file_offset(int fd);
aoqi@0 653 static jlong seek_to_file_offset(int fd, jlong offset);
aoqi@0 654
aoqi@0 655 // Thread Local Storage
aoqi@0 656 static int allocate_thread_local_storage();
aoqi@0 657 static void thread_local_storage_at_put(int index, void* value);
aoqi@0 658 static void* thread_local_storage_at(int index);
aoqi@0 659 static void free_thread_local_storage(int index);
aoqi@0 660
aoqi@0 661 // Stack walk
aoqi@0 662 static address get_caller_pc(int n = 0);
aoqi@0 663
aoqi@0 664 // General allocation (must be MT-safe)
aoqi@0 665 static void* malloc (size_t size, MEMFLAGS flags, address caller_pc = 0);
aoqi@0 666 static void* realloc (void *memblock, size_t size, MEMFLAGS flags, address caller_pc = 0);
aoqi@0 667 static void free (void *memblock, MEMFLAGS flags = mtNone);
aoqi@0 668 static bool check_heap(bool force = false); // verify C heap integrity
aoqi@0 669 static char* strdup(const char *, MEMFLAGS flags = mtInternal); // Like strdup
aoqi@0 670
aoqi@0 671 #ifndef PRODUCT
aoqi@0 672 static julong num_mallocs; // # of calls to malloc/realloc
aoqi@0 673 static julong alloc_bytes; // # of bytes allocated
aoqi@0 674 static julong num_frees; // # of calls to free
aoqi@0 675 static julong free_bytes; // # of bytes freed
aoqi@0 676 #endif
aoqi@0 677
aoqi@0 678 // SocketInterface (ex HPI SocketInterface )
aoqi@0 679 static int socket(int domain, int type, int protocol);
aoqi@0 680 static int socket_close(int fd);
aoqi@0 681 static int socket_shutdown(int fd, int howto);
aoqi@0 682 static int recv(int fd, char* buf, size_t nBytes, uint flags);
aoqi@0 683 static int send(int fd, char* buf, size_t nBytes, uint flags);
aoqi@0 684 static int raw_send(int fd, char* buf, size_t nBytes, uint flags);
aoqi@0 685 static int timeout(int fd, long timeout);
aoqi@0 686 static int listen(int fd, int count);
aoqi@0 687 static int connect(int fd, struct sockaddr* him, socklen_t len);
aoqi@0 688 static int bind(int fd, struct sockaddr* him, socklen_t len);
aoqi@0 689 static int accept(int fd, struct sockaddr* him, socklen_t* len);
aoqi@0 690 static int recvfrom(int fd, char* buf, size_t nbytes, uint flags,
aoqi@0 691 struct sockaddr* from, socklen_t* fromlen);
aoqi@0 692 static int get_sock_name(int fd, struct sockaddr* him, socklen_t* len);
aoqi@0 693 static int sendto(int fd, char* buf, size_t len, uint flags,
aoqi@0 694 struct sockaddr* to, socklen_t tolen);
aoqi@0 695 static int socket_available(int fd, jint* pbytes);
aoqi@0 696
aoqi@0 697 static int get_sock_opt(int fd, int level, int optname,
aoqi@0 698 char* optval, socklen_t* optlen);
aoqi@0 699 static int set_sock_opt(int fd, int level, int optname,
aoqi@0 700 const char* optval, socklen_t optlen);
aoqi@0 701 static int get_host_name(char* name, int namelen);
aoqi@0 702
aoqi@0 703 static struct hostent* get_host_by_name(char* name);
aoqi@0 704
aoqi@0 705 // Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
aoqi@0 706 static void signal_init();
aoqi@0 707 static void signal_init_pd();
aoqi@0 708 static void signal_notify(int signal_number);
aoqi@0 709 static void* signal(int signal_number, void* handler);
aoqi@0 710 static void signal_raise(int signal_number);
aoqi@0 711 static int signal_wait();
aoqi@0 712 static int signal_lookup();
aoqi@0 713 static void* user_handler();
aoqi@0 714 static void terminate_signal_thread();
aoqi@0 715 static int sigexitnum_pd();
aoqi@0 716
aoqi@0 717 // random number generation
aoqi@0 718 static long random(); // return 32bit pseudorandom number
aoqi@0 719 static void init_random(long initval); // initialize random sequence
aoqi@0 720
aoqi@0 721 // Structured OS Exception support
aoqi@0 722 static void os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
aoqi@0 723
aoqi@0 724 // On Windows this will create an actual minidump, on Linux/Solaris it will simply check core dump limits
aoqi@0 725 static void check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize);
aoqi@0 726
aoqi@0 727 // Get the default path to the core file
aoqi@0 728 // Returns the length of the string
aoqi@0 729 static int get_core_path(char* buffer, size_t bufferSize);
aoqi@0 730
aoqi@0 731 // JVMTI & JVM monitoring and management support
aoqi@0 732 // The thread_cpu_time() and current_thread_cpu_time() are only
aoqi@0 733 // supported if is_thread_cpu_time_supported() returns true.
aoqi@0 734 // They are not supported on Solaris T1.
aoqi@0 735
aoqi@0 736 // Thread CPU Time - return the fast estimate on a platform
aoqi@0 737 // On Solaris - call gethrvtime (fast) - user time only
aoqi@0 738 // On Linux - fast clock_gettime where available - user+sys
aoqi@0 739 // - otherwise: very slow /proc fs - user+sys
aoqi@0 740 // On Windows - GetThreadTimes - user+sys
aoqi@0 741 static jlong current_thread_cpu_time();
aoqi@0 742 static jlong thread_cpu_time(Thread* t);
aoqi@0 743
aoqi@0 744 // Thread CPU Time with user_sys_cpu_time parameter.
aoqi@0 745 //
aoqi@0 746 // If user_sys_cpu_time is true, user+sys time is returned.
aoqi@0 747 // Otherwise, only user time is returned
aoqi@0 748 static jlong current_thread_cpu_time(bool user_sys_cpu_time);
aoqi@0 749 static jlong thread_cpu_time(Thread* t, bool user_sys_cpu_time);
aoqi@0 750
aoqi@0 751 // Return a bunch of info about the timers.
aoqi@0 752 // Note that the returned info for these two functions may be different
aoqi@0 753 // on some platforms
aoqi@0 754 static void current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr);
aoqi@0 755 static void thread_cpu_time_info(jvmtiTimerInfo *info_ptr);
aoqi@0 756
aoqi@0 757 static bool is_thread_cpu_time_supported();
aoqi@0 758
aoqi@0 759 // System loadavg support. Returns -1 if load average cannot be obtained.
aoqi@0 760 static int loadavg(double loadavg[], int nelem);
aoqi@0 761
aoqi@0 762 // Hook for os specific jvm options that we don't want to abort on seeing
aoqi@0 763 static bool obsolete_option(const JavaVMOption *option);
aoqi@0 764
aoqi@0 765 // Extensions
aoqi@0 766 #include "runtime/os_ext.hpp"
aoqi@0 767
aoqi@0 768 public:
aoqi@0 769 class CrashProtectionCallback : public StackObj {
aoqi@0 770 public:
aoqi@0 771 virtual void call() = 0;
aoqi@0 772 };
aoqi@0 773
aoqi@0 774 // Platform dependent stuff
aoqi@0 775 #ifdef TARGET_OS_FAMILY_linux
aoqi@0 776 # include "os_linux.hpp"
aoqi@0 777 # include "os_posix.hpp"
aoqi@0 778 #endif
aoqi@0 779 #ifdef TARGET_OS_FAMILY_solaris
aoqi@0 780 # include "os_solaris.hpp"
aoqi@0 781 # include "os_posix.hpp"
aoqi@0 782 #endif
aoqi@0 783 #ifdef TARGET_OS_FAMILY_windows
aoqi@0 784 # include "os_windows.hpp"
aoqi@0 785 #endif
aoqi@0 786 #ifdef TARGET_OS_FAMILY_aix
aoqi@0 787 # include "os_aix.hpp"
aoqi@0 788 # include "os_posix.hpp"
aoqi@0 789 #endif
aoqi@0 790 #ifdef TARGET_OS_FAMILY_bsd
aoqi@0 791 # include "os_posix.hpp"
aoqi@0 792 # include "os_bsd.hpp"
aoqi@0 793 #endif
aoqi@0 794 #ifdef TARGET_OS_ARCH_linux_x86
aoqi@0 795 # include "os_linux_x86.hpp"
aoqi@0 796 #endif
aoqi@1 797 #ifdef TARGET_OS_ARCH_linux_mips
aoqi@1 798 # include "os_linux_mips.hpp"
aoqi@1 799 #endif
aoqi@0 800 #ifdef TARGET_OS_ARCH_linux_sparc
aoqi@0 801 # include "os_linux_sparc.hpp"
aoqi@0 802 #endif
aoqi@0 803 #ifdef TARGET_OS_ARCH_linux_zero
aoqi@0 804 # include "os_linux_zero.hpp"
aoqi@0 805 #endif
aoqi@0 806 #ifdef TARGET_OS_ARCH_solaris_x86
aoqi@0 807 # include "os_solaris_x86.hpp"
aoqi@0 808 #endif
aoqi@0 809 #ifdef TARGET_OS_ARCH_solaris_sparc
aoqi@0 810 # include "os_solaris_sparc.hpp"
aoqi@0 811 #endif
aoqi@0 812 #ifdef TARGET_OS_ARCH_windows_x86
aoqi@0 813 # include "os_windows_x86.hpp"
aoqi@0 814 #endif
aoqi@0 815 #ifdef TARGET_OS_ARCH_linux_arm
aoqi@0 816 # include "os_linux_arm.hpp"
aoqi@0 817 #endif
aoqi@0 818 #ifdef TARGET_OS_ARCH_linux_ppc
aoqi@0 819 # include "os_linux_ppc.hpp"
aoqi@0 820 #endif
aoqi@0 821 #ifdef TARGET_OS_ARCH_aix_ppc
aoqi@0 822 # include "os_aix_ppc.hpp"
aoqi@0 823 #endif
aoqi@0 824 #ifdef TARGET_OS_ARCH_bsd_x86
aoqi@0 825 # include "os_bsd_x86.hpp"
aoqi@0 826 #endif
aoqi@0 827 #ifdef TARGET_OS_ARCH_bsd_zero
aoqi@0 828 # include "os_bsd_zero.hpp"
aoqi@0 829 #endif
aoqi@0 830
aoqi@0 831 public:
aoqi@0 832 #ifndef PLATFORM_PRINT_NATIVE_STACK
aoqi@0 833 // No platform-specific code for printing the native stack.
aoqi@0 834 static bool platform_print_native_stack(outputStream* st, void* context,
aoqi@0 835 char *buf, int buf_size) {
aoqi@0 836 return false;
aoqi@0 837 }
aoqi@0 838 #endif
aoqi@0 839
aoqi@0 840 // debugging support (mostly used by debug.cpp but also fatal error handler)
aoqi@0 841 static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address
aoqi@0 842
aoqi@0 843 static bool dont_yield(); // when true, JVM_Yield() is nop
aoqi@0 844 static void print_statistics();
aoqi@0 845
aoqi@0 846 // Thread priority helpers (implemented in OS-specific part)
aoqi@0 847 static OSReturn set_native_priority(Thread* thread, int native_prio);
aoqi@0 848 static OSReturn get_native_priority(const Thread* const thread, int* priority_ptr);
aoqi@0 849 static int java_to_os_priority[CriticalPriority + 1];
aoqi@0 850 // Hint to the underlying OS that a task switch would not be good.
aoqi@0 851 // Void return because it's a hint and can fail.
aoqi@0 852 static void hint_no_preempt();
aoqi@0 853
aoqi@0 854 // Used at creation if requested by the diagnostic flag PauseAtStartup.
aoqi@0 855 // Causes the VM to wait until an external stimulus has been applied
aoqi@0 856 // (for Unix, that stimulus is a signal, for Windows, an external
aoqi@0 857 // ResumeThread call)
aoqi@0 858 static void pause();
aoqi@0 859
aoqi@0 860 // Builds a platform dependent Agent_OnLoad_<libname> function name
aoqi@0 861 // which is used to find statically linked in agents.
aoqi@0 862 static char* build_agent_function_name(const char *sym, const char *cname,
aoqi@0 863 bool is_absolute_path);
aoqi@0 864
aoqi@0 865 class SuspendedThreadTaskContext {
aoqi@0 866 public:
aoqi@0 867 SuspendedThreadTaskContext(Thread* thread, void *ucontext) : _thread(thread), _ucontext(ucontext) {}
aoqi@0 868 Thread* thread() const { return _thread; }
aoqi@0 869 void* ucontext() const { return _ucontext; }
aoqi@0 870 private:
aoqi@0 871 Thread* _thread;
aoqi@0 872 void* _ucontext;
aoqi@0 873 };
aoqi@0 874
aoqi@0 875 class SuspendedThreadTask {
aoqi@0 876 public:
aoqi@0 877 SuspendedThreadTask(Thread* thread) : _thread(thread), _done(false) {}
aoqi@0 878 virtual ~SuspendedThreadTask() {}
aoqi@0 879 void run();
aoqi@0 880 bool is_done() { return _done; }
aoqi@0 881 virtual void do_task(const SuspendedThreadTaskContext& context) = 0;
aoqi@0 882 protected:
aoqi@0 883 private:
aoqi@0 884 void internal_do_task();
aoqi@0 885 Thread* _thread;
aoqi@0 886 bool _done;
aoqi@0 887 };
aoqi@0 888
aoqi@0 889 #ifndef TARGET_OS_FAMILY_windows
aoqi@0 890 // Suspend/resume support
aoqi@0 891 // Protocol:
aoqi@0 892 //
aoqi@0 893 // a thread starts in SR_RUNNING
aoqi@0 894 //
aoqi@0 895 // SR_RUNNING can go to
aoqi@0 896 // * SR_SUSPEND_REQUEST when the WatcherThread wants to suspend it
aoqi@0 897 // SR_SUSPEND_REQUEST can go to
aoqi@0 898 // * SR_RUNNING if WatcherThread decides it waited for SR_SUSPENDED too long (timeout)
aoqi@0 899 // * SR_SUSPENDED if the stopped thread receives the signal and switches state
aoqi@0 900 // SR_SUSPENDED can go to
aoqi@0 901 // * SR_WAKEUP_REQUEST when the WatcherThread has done the work and wants to resume
aoqi@0 902 // SR_WAKEUP_REQUEST can go to
aoqi@0 903 // * SR_RUNNING when the stopped thread receives the signal
aoqi@0 904 // * SR_WAKEUP_REQUEST on timeout (resend the signal and try again)
aoqi@0 905 class SuspendResume {
aoqi@0 906 public:
aoqi@0 907 enum State {
aoqi@0 908 SR_RUNNING,
aoqi@0 909 SR_SUSPEND_REQUEST,
aoqi@0 910 SR_SUSPENDED,
aoqi@0 911 SR_WAKEUP_REQUEST
aoqi@0 912 };
aoqi@0 913
aoqi@0 914 private:
aoqi@0 915 volatile State _state;
aoqi@0 916
aoqi@0 917 private:
aoqi@0 918 /* try to switch state from state "from" to state "to"
aoqi@0 919 * returns the state set after the method is complete
aoqi@0 920 */
aoqi@0 921 State switch_state(State from, State to);
aoqi@0 922
aoqi@0 923 public:
aoqi@0 924 SuspendResume() : _state(SR_RUNNING) { }
aoqi@0 925
aoqi@0 926 State state() const { return _state; }
aoqi@0 927
aoqi@0 928 State request_suspend() {
aoqi@0 929 return switch_state(SR_RUNNING, SR_SUSPEND_REQUEST);
aoqi@0 930 }
aoqi@0 931
aoqi@0 932 State cancel_suspend() {
aoqi@0 933 return switch_state(SR_SUSPEND_REQUEST, SR_RUNNING);
aoqi@0 934 }
aoqi@0 935
aoqi@0 936 State suspended() {
aoqi@0 937 return switch_state(SR_SUSPEND_REQUEST, SR_SUSPENDED);
aoqi@0 938 }
aoqi@0 939
aoqi@0 940 State request_wakeup() {
aoqi@0 941 return switch_state(SR_SUSPENDED, SR_WAKEUP_REQUEST);
aoqi@0 942 }
aoqi@0 943
aoqi@0 944 State running() {
aoqi@0 945 return switch_state(SR_WAKEUP_REQUEST, SR_RUNNING);
aoqi@0 946 }
aoqi@0 947
aoqi@0 948 bool is_running() const {
aoqi@0 949 return _state == SR_RUNNING;
aoqi@0 950 }
aoqi@0 951
aoqi@0 952 bool is_suspend_request() const {
aoqi@0 953 return _state == SR_SUSPEND_REQUEST;
aoqi@0 954 }
aoqi@0 955
aoqi@0 956 bool is_suspended() const {
aoqi@0 957 return _state == SR_SUSPENDED;
aoqi@0 958 }
aoqi@0 959 };
aoqi@0 960 #endif
aoqi@0 961
aoqi@0 962
aoqi@0 963 protected:
aoqi@0 964 static long _rand_seed; // seed for random number generator
aoqi@0 965 static int _processor_count; // number of processors
aoqi@0 966
aoqi@0 967 static char* format_boot_path(const char* format_string,
aoqi@0 968 const char* home,
aoqi@0 969 int home_len,
aoqi@0 970 char fileSep,
aoqi@0 971 char pathSep);
aoqi@0 972 static bool set_boot_path(char fileSep, char pathSep);
aoqi@0 973 static char** split_path(const char* path, int* n);
aoqi@0 974
aoqi@0 975 };
aoqi@0 976
aoqi@0 977 // Note that "PAUSE" is almost always used with synchronization
aoqi@0 978 // so arguably we should provide Atomic::SpinPause() instead
aoqi@0 979 // of the global SpinPause() with C linkage.
aoqi@0 980 // It'd also be eligible for inlining on many platforms.
aoqi@0 981
aoqi@0 982 extern "C" int SpinPause();
aoqi@0 983
aoqi@0 984 #endif // SHARE_VM_RUNTIME_OS_HPP

mercurial