annotate src/share/vm/runtime/os.hpp @ 2213:63d374c54045

7014918: Improve core/minidump handling in Hotspot Summary: Added Minidump support on Windows, enabled large page core dumps when coredump_filter is present and writing out path/rlimit for core dumps. Reviewed-by: poonam, dsamersoff, sla, coleenp
author ctornqvi
date Wed, 09 Feb 2011 11:08:10 +0100
parents b92c45f2bc75
children fb23abdd4636 850b2295a494 da091bb67459
rev   line source
duke@0 1 /*
ctornqvi@2213 2 * Copyright (c) 1997, 2011, Oracle and/or its affiliates. All rights reserved.
duke@0 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
duke@0 4 *
duke@0 5 * This code is free software; you can redistribute it and/or modify it
duke@0 6 * under the terms of the GNU General Public License version 2 only, as
duke@0 7 * published by the Free Software Foundation.
duke@0 8 *
duke@0 9 * This code is distributed in the hope that it will be useful, but WITHOUT
duke@0 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
duke@0 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
duke@0 12 * version 2 for more details (a copy is included in the LICENSE file that
duke@0 13 * accompanied this code).
duke@0 14 *
duke@0 15 * You should have received a copy of the GNU General Public License version
duke@0 16 * 2 along with this work; if not, write to the Free Software Foundation,
duke@0 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
duke@0 18 *
trims@1563 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
trims@1563 20 * or visit www.oracle.com if you need additional information or have any
trims@1563 21 * questions.
duke@0 22 *
duke@0 23 */
duke@0 24
stefank@1992 25 #ifndef SHARE_VM_RUNTIME_OS_HPP
stefank@1992 26 #define SHARE_VM_RUNTIME_OS_HPP
stefank@1992 27
stefank@1992 28 #include "jvmtifiles/jvmti.h"
stefank@1992 29 #include "runtime/atomic.hpp"
stefank@1992 30 #include "runtime/extendedPC.hpp"
stefank@1992 31 #include "runtime/handles.hpp"
stefank@1992 32 #include "utilities/top.hpp"
stefank@1992 33 #ifdef TARGET_OS_FAMILY_linux
stefank@1992 34 # include "jvm_linux.h"
stefank@1992 35 #endif
stefank@1992 36 #ifdef TARGET_OS_FAMILY_solaris
stefank@1992 37 # include "jvm_solaris.h"
stefank@1992 38 #endif
stefank@1992 39 #ifdef TARGET_OS_FAMILY_windows
stefank@1992 40 # include "jvm_windows.h"
stefank@1992 41 #endif
stefank@1992 42
duke@0 43 // os defines the interface to operating system; this includes traditional
duke@0 44 // OS services (time, I/O) as well as other functionality with system-
duke@0 45 // dependent code.
duke@0 46
duke@0 47 typedef void (*dll_func)(...);
duke@0 48
duke@0 49 class Thread;
duke@0 50 class JavaThread;
duke@0 51 class Event;
duke@0 52 class DLL;
duke@0 53 class FileHandle;
iveresov@141 54 template<class E> class GrowableArray;
duke@0 55
duke@0 56 // %%%%% Moved ThreadState, START_FN, OSThread to new osThread.hpp. -- Rose
duke@0 57
duke@0 58 // Platform-independent error return values from OS functions
duke@0 59 enum OSReturn {
duke@0 60 OS_OK = 0, // Operation was successful
duke@0 61 OS_ERR = -1, // Operation failed
duke@0 62 OS_INTRPT = -2, // Operation was interrupted
duke@0 63 OS_TIMEOUT = -3, // Operation timed out
duke@0 64 OS_NOMEM = -5, // Operation failed for lack of memory
duke@0 65 OS_NORESOURCE = -6 // Operation failed for lack of nonmemory resource
duke@0 66 };
duke@0 67
duke@0 68 enum ThreadPriority { // JLS 20.20.1-3
duke@0 69 NoPriority = -1, // Initial non-priority value
duke@0 70 MinPriority = 1, // Minimum priority
duke@0 71 NormPriority = 5, // Normal (non-daemon) priority
duke@0 72 NearMaxPriority = 9, // High priority, used for VMThread
duke@0 73 MaxPriority = 10 // Highest priority, used for WatcherThread
duke@0 74 // ensures that VMThread doesn't starve profiler
duke@0 75 };
duke@0 76
duke@0 77 // Typedef for structured exception handling support
duke@0 78 typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
duke@0 79
duke@0 80 class os: AllStatic {
phh@1197 81 public:
duke@0 82 enum { page_sizes_max = 9 }; // Size of _page_sizes array (8 plus a sentinel)
duke@0 83
phh@1197 84 private:
duke@0 85 static OSThread* _starting_thread;
duke@0 86 static address _polling_page;
duke@0 87 static volatile int32_t * _mem_serialize_page;
duke@0 88 static uintptr_t _serialize_page_mask;
phh@1197 89 public:
duke@0 90 static size_t _page_sizes[page_sizes_max];
duke@0 91
phh@1197 92 private:
duke@0 93 static void init_page_sizes(size_t default_page_size) {
duke@0 94 _page_sizes[0] = default_page_size;
duke@0 95 _page_sizes[1] = 0; // sentinel
duke@0 96 }
duke@0 97
duke@0 98 public:
bobv@1703 99
bobv@1703 100 static void init(void); // Called before command line parsing
bobv@1703 101 static jint init_2(void); // Called after command line parsing
bobv@1703 102 static void init_3(void); // Called at the end of vm init
duke@0 103
duke@0 104 // File names are case-insensitive on windows only
duke@0 105 // Override me as needed
duke@0 106 static int file_name_strcmp(const char* s1, const char* s2);
duke@0 107
duke@0 108 static bool getenv(const char* name, char* buffer, int len);
duke@0 109 static bool have_special_privileges();
duke@0 110
duke@0 111 static jlong javaTimeMillis();
duke@0 112 static jlong javaTimeNanos();
duke@0 113 static void javaTimeNanos_info(jvmtiTimerInfo *info_ptr);
duke@0 114 static void run_periodic_checks();
duke@0 115
duke@0 116
duke@0 117 // Returns the elapsed time in seconds since the vm started.
duke@0 118 static double elapsedTime();
duke@0 119
duke@0 120 // Returns real time in seconds since an arbitrary point
duke@0 121 // in the past.
duke@0 122 static bool getTimesSecs(double* process_real_time,
duke@0 123 double* process_user_time,
duke@0 124 double* process_system_time);
duke@0 125
duke@0 126 // Interface to the performance counter
duke@0 127 static jlong elapsed_counter();
duke@0 128 static jlong elapsed_frequency();
duke@0 129
ysr@345 130 // The "virtual time" of a thread is the amount of time a thread has
ysr@345 131 // actually run. The first function indicates whether the OS supports
ysr@345 132 // this functionality for the current thread, and if so:
ysr@345 133 // * the second enables vtime tracking (if that is required).
ysr@345 134 // * the third tells whether vtime is enabled.
ysr@345 135 // * the fourth returns the elapsed virtual time for the current
ysr@345 136 // thread.
ysr@345 137 static bool supports_vtime();
ysr@345 138 static bool enable_vtime();
ysr@345 139 static bool vtime_enabled();
ysr@345 140 static double elapsedVTime();
ysr@345 141
duke@0 142 // Return current local time in a string (YYYY-MM-DD HH:MM:SS).
duke@0 143 // It is MT safe, but not async-safe, as reading time zone
duke@0 144 // information may require a lock on some platforms.
ysr@580 145 static char* local_time_string(char *buf, size_t buflen);
ysr@580 146 static struct tm* localtime_pd (const time_t* clock, struct tm* res);
duke@0 147 // Fill in buffer with current local time as an ISO-8601 string.
duke@0 148 // E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
duke@0 149 // Returns buffer, or NULL if it failed.
duke@0 150 static char* iso8601_time(char* buffer, size_t buffer_length);
duke@0 151
duke@0 152 // Interface for detecting multiprocessor system
duke@0 153 static inline bool is_MP() {
duke@0 154 assert(_processor_count > 0, "invalid processor count");
duke@0 155 return _processor_count > 1;
duke@0 156 }
duke@0 157 static julong available_memory();
duke@0 158 static julong physical_memory();
duke@0 159 static julong allocatable_physical_memory(julong size);
duke@0 160 static bool is_server_class_machine();
duke@0 161
duke@0 162 // number of CPUs
duke@0 163 static int processor_count() {
duke@0 164 return _processor_count;
duke@0 165 }
phh@1197 166 static void set_processor_count(int count) { _processor_count = count; }
duke@0 167
duke@0 168 // Returns the number of CPUs this process is currently allowed to run on.
duke@0 169 // Note that on some OSes this can change dynamically.
duke@0 170 static int active_processor_count();
duke@0 171
duke@0 172 // Bind processes to processors.
duke@0 173 // This is a two step procedure:
duke@0 174 // first you generate a distribution of processes to processors,
duke@0 175 // then you bind processes according to that distribution.
duke@0 176 // Compute a distribution for number of processes to processors.
duke@0 177 // Stores the processor id's into the distribution array argument.
duke@0 178 // Returns true if it worked, false if it didn't.
duke@0 179 static bool distribute_processes(uint length, uint* distribution);
duke@0 180 // Binds the current process to a processor.
duke@0 181 // Returns true if it worked, false if it didn't.
duke@0 182 static bool bind_to_processor(uint processor_id);
duke@0 183
duke@0 184 // Interface for stack banging (predetect possible stack overflow for
duke@0 185 // exception processing) There are guard pages, and above that shadow
duke@0 186 // pages for stack overflow checking.
duke@0 187 static bool uses_stack_guard_pages();
duke@0 188 static bool allocate_stack_guard_pages();
duke@0 189 static void bang_stack_shadow_pages();
duke@0 190 static bool stack_shadow_pages_available(Thread *thread, methodHandle method);
duke@0 191
duke@0 192 // OS interface to Virtual Memory
duke@0 193
duke@0 194 // Return the default page size.
duke@0 195 static int vm_page_size();
duke@0 196
duke@0 197 // Return the page size to use for a region of memory. The min_pages argument
duke@0 198 // is a hint intended to limit fragmentation; it says the returned page size
duke@0 199 // should be <= region_max_size / min_pages. Because min_pages is a hint,
duke@0 200 // this routine may return a size larger than region_max_size / min_pages.
duke@0 201 //
duke@0 202 // The current implementation ignores min_pages if a larger page size is an
duke@0 203 // exact multiple of both region_min_size and region_max_size. This allows
duke@0 204 // larger pages to be used when doing so would not cause fragmentation; in
duke@0 205 // particular, a single page can be used when region_min_size ==
duke@0 206 // region_max_size == a supported page size.
duke@0 207 static size_t page_size_for_region(size_t region_min_size,
duke@0 208 size_t region_max_size,
duke@0 209 uint min_pages);
duke@0 210
duke@0 211 // Method for tracing page sizes returned by the above method; enabled by
duke@0 212 // TracePageSizes. The region_{min,max}_size parameters should be the values
duke@0 213 // passed to page_size_for_region() and page_size should be the result of that
duke@0 214 // call. The (optional) base and size parameters should come from the
duke@0 215 // ReservedSpace base() and size() methods.
duke@0 216 static void trace_page_sizes(const char* str, const size_t region_min_size,
duke@0 217 const size_t region_max_size,
duke@0 218 const size_t page_size,
duke@0 219 const char* base = NULL,
duke@0 220 const size_t size = 0) PRODUCT_RETURN;
duke@0 221
duke@0 222 static int vm_allocation_granularity();
duke@0 223 static char* reserve_memory(size_t bytes, char* addr = 0,
duke@0 224 size_t alignment_hint = 0);
duke@0 225 static char* attempt_reserve_memory_at(size_t bytes, char* addr);
duke@0 226 static void split_reserved_memory(char *base, size_t size,
duke@0 227 size_t split, bool realloc);
coleenp@694 228 static bool commit_memory(char* addr, size_t bytes,
coleenp@694 229 bool executable = false);
coleenp@694 230 static bool commit_memory(char* addr, size_t size, size_t alignment_hint,
coleenp@694 231 bool executable = false);
duke@0 232 static bool uncommit_memory(char* addr, size_t bytes);
duke@0 233 static bool release_memory(char* addr, size_t bytes);
coleenp@237 234
coleenp@237 235 enum ProtType { MEM_PROT_NONE, MEM_PROT_READ, MEM_PROT_RW, MEM_PROT_RWX };
coleenp@237 236 static bool protect_memory(char* addr, size_t bytes, ProtType prot,
coleenp@484 237 bool is_committed = true);
coleenp@237 238
duke@0 239 static bool guard_memory(char* addr, size_t bytes);
duke@0 240 static bool unguard_memory(char* addr, size_t bytes);
coleenp@1407 241 static bool create_stack_guard_pages(char* addr, size_t bytes);
coleenp@1407 242 static bool remove_stack_guard_pages(char* addr, size_t bytes);
coleenp@1407 243
duke@0 244 static char* map_memory(int fd, const char* file_name, size_t file_offset,
duke@0 245 char *addr, size_t bytes, bool read_only = false,
duke@0 246 bool allow_exec = false);
duke@0 247 static char* remap_memory(int fd, const char* file_name, size_t file_offset,
duke@0 248 char *addr, size_t bytes, bool read_only,
duke@0 249 bool allow_exec);
duke@0 250 static bool unmap_memory(char *addr, size_t bytes);
duke@0 251 static void free_memory(char *addr, size_t bytes);
duke@0 252 static void realign_memory(char *addr, size_t bytes, size_t alignment_hint);
duke@0 253
duke@0 254 // NUMA-specific interface
iveresov@141 255 static bool numa_has_static_binding();
iveresov@141 256 static bool numa_has_group_homing();
iveresov@141 257 static void numa_make_local(char *addr, size_t bytes, int lgrp_hint);
duke@0 258 static void numa_make_global(char *addr, size_t bytes);
duke@0 259 static size_t numa_get_groups_num();
duke@0 260 static size_t numa_get_leaf_groups(int *ids, size_t size);
duke@0 261 static bool numa_topology_changed();
duke@0 262 static int numa_get_group_id();
duke@0 263
duke@0 264 // Page manipulation
duke@0 265 struct page_info {
duke@0 266 size_t size;
duke@0 267 int lgrp_id;
duke@0 268 };
duke@0 269 static bool get_page_info(char *start, page_info* info);
duke@0 270 static char* scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found);
duke@0 271
duke@0 272 static char* non_memory_address_word();
duke@0 273 // reserve, commit and pin the entire memory region
coleenp@694 274 static char* reserve_memory_special(size_t size, char* addr = NULL,
coleenp@694 275 bool executable = false);
duke@0 276 static bool release_memory_special(char* addr, size_t bytes);
duke@0 277 static bool large_page_init();
duke@0 278 static size_t large_page_size();
duke@0 279 static bool can_commit_large_page_memory();
jcoomes@79 280 static bool can_execute_large_page_memory();
duke@0 281
duke@0 282 // OS interface to polling page
duke@0 283 static address get_polling_page() { return _polling_page; }
duke@0 284 static void set_polling_page(address page) { _polling_page = page; }
duke@0 285 static bool is_poll_address(address addr) { return addr >= _polling_page && addr < (_polling_page + os::vm_page_size()); }
duke@0 286 static void make_polling_page_unreadable();
duke@0 287 static void make_polling_page_readable();
duke@0 288
duke@0 289 // Routines used to serialize the thread state without using membars
duke@0 290 static void serialize_thread_states();
duke@0 291
duke@0 292 // Since we write to the serialize page from every thread, we
duke@0 293 // want stores to be on unique cache lines whenever possible
duke@0 294 // in order to minimize CPU cross talk. We pre-compute the
duke@0 295 // amount to shift the thread* to make this offset unique to
duke@0 296 // each thread.
duke@0 297 static int get_serialize_page_shift_count() {
duke@0 298 return SerializePageShiftCount;
duke@0 299 }
duke@0 300
duke@0 301 static void set_serialize_page_mask(uintptr_t mask) {
duke@0 302 _serialize_page_mask = mask;
duke@0 303 }
duke@0 304
duke@0 305 static unsigned int get_serialize_page_mask() {
duke@0 306 return _serialize_page_mask;
duke@0 307 }
duke@0 308
duke@0 309 static void set_memory_serialize_page(address page);
duke@0 310
duke@0 311 static address get_memory_serialize_page() {
duke@0 312 return (address)_mem_serialize_page;
duke@0 313 }
duke@0 314
duke@0 315 static inline void write_memory_serialize_page(JavaThread *thread) {
duke@0 316 uintptr_t page_offset = ((uintptr_t)thread >>
duke@0 317 get_serialize_page_shift_count()) &
duke@0 318 get_serialize_page_mask();
duke@0 319 *(volatile int32_t *)((uintptr_t)_mem_serialize_page+page_offset) = 1;
duke@0 320 }
duke@0 321
duke@0 322 static bool is_memory_serialize_page(JavaThread *thread, address addr) {
duke@0 323 if (UseMembar) return false;
twisti@1152 324 // Previously this function calculated the exact address of this
twisti@1152 325 // thread's serialize page, and checked if the faulting address
twisti@1152 326 // was equal. However, some platforms mask off faulting addresses
twisti@1152 327 // to the page size, so now we just check that the address is
twisti@1152 328 // within the page. This makes the thread argument unnecessary,
twisti@1152 329 // but we retain the NULL check to preserve existing behaviour.
duke@0 330 if (thread == NULL) return false;
twisti@1152 331 address page = (address) _mem_serialize_page;
twisti@1152 332 return addr >= page && addr < (page + os::vm_page_size());
duke@0 333 }
duke@0 334
duke@0 335 static void block_on_serialize_page_trap();
duke@0 336
duke@0 337 // threads
duke@0 338
duke@0 339 enum ThreadType {
duke@0 340 vm_thread,
duke@0 341 cgc_thread, // Concurrent GC thread
duke@0 342 pgc_thread, // Parallel GC thread
duke@0 343 java_thread,
duke@0 344 compiler_thread,
bobv@1703 345 watcher_thread,
bobv@1703 346 os_thread
duke@0 347 };
duke@0 348
duke@0 349 static bool create_thread(Thread* thread,
duke@0 350 ThreadType thr_type,
duke@0 351 size_t stack_size = 0);
duke@0 352 static bool create_main_thread(JavaThread* thread);
duke@0 353 static bool create_attached_thread(JavaThread* thread);
duke@0 354 static void pd_start_thread(Thread* thread);
duke@0 355 static void start_thread(Thread* thread);
duke@0 356
duke@0 357 static void initialize_thread();
duke@0 358 static void free_thread(OSThread* osthread);
duke@0 359
duke@0 360 // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
duke@0 361 static intx current_thread_id();
duke@0 362 static int current_process_id();
duke@0 363 static int sleep(Thread* thread, jlong ms, bool interruptable);
duke@0 364 static int naked_sleep();
duke@0 365 static void infinite_sleep(); // never returns, use with CAUTION
duke@0 366 static void yield(); // Yields to all threads with same priority
duke@0 367 enum YieldResult {
duke@0 368 YIELD_SWITCHED = 1, // caller descheduled, other ready threads exist & ran
duke@0 369 YIELD_NONEREADY = 0, // No other runnable/ready threads.
duke@0 370 // platform-specific yield return immediately
duke@0 371 YIELD_UNKNOWN = -1 // Unknown: platform doesn't support _SWITCHED or _NONEREADY
duke@0 372 // YIELD_SWITCHED and YIELD_NONREADY imply the platform supports a "strong"
duke@0 373 // yield that can be used in lieu of blocking.
duke@0 374 } ;
duke@0 375 static YieldResult NakedYield () ;
duke@0 376 static void yield_all(int attempts = 0); // Yields to all other threads including lower priority
duke@0 377 static void loop_breaker(int attempts); // called from within tight loops to possibly influence time-sharing
duke@0 378 static OSReturn set_priority(Thread* thread, ThreadPriority priority);
duke@0 379 static OSReturn get_priority(const Thread* const thread, ThreadPriority& priority);
duke@0 380
duke@0 381 static void interrupt(Thread* thread);
duke@0 382 static bool is_interrupted(Thread* thread, bool clear_interrupted);
duke@0 383
duke@0 384 static int pd_self_suspend_thread(Thread* thread);
duke@0 385
duke@0 386 static ExtendedPC fetch_frame_from_context(void* ucVoid, intptr_t** sp, intptr_t** fp);
duke@0 387 static frame fetch_frame_from_context(void* ucVoid);
duke@0 388
duke@0 389 static ExtendedPC get_thread_pc(Thread *thread);
duke@0 390 static void breakpoint();
duke@0 391
duke@0 392 static address current_stack_pointer();
duke@0 393 static address current_stack_base();
duke@0 394 static size_t current_stack_size();
duke@0 395
duke@0 396 static int message_box(const char* title, const char* message);
duke@0 397 static char* do_you_want_to_debug(const char* message);
duke@0 398
duke@0 399 // run cmd in a separate process and return its exit code; or -1 on failures
duke@0 400 static int fork_and_exec(char *cmd);
duke@0 401
duke@0 402 // Set file to send error reports.
duke@0 403 static void set_error_file(const char *logfile);
duke@0 404
duke@0 405 // os::exit() is merged with vm_exit()
duke@0 406 // static void exit(int num);
duke@0 407
duke@0 408 // Terminate the VM, but don't exit the process
duke@0 409 static void shutdown();
duke@0 410
duke@0 411 // Terminate with an error. Default is to generate a core file on platforms
duke@0 412 // that support such things. This calls shutdown() and then aborts.
duke@0 413 static void abort(bool dump_core = true);
duke@0 414
duke@0 415 // Die immediately, no exit hook, no abort hook, no cleanup.
duke@0 416 static void die();
duke@0 417
ikrylov@2000 418 // File i/o operations
ikrylov@2000 419 static const int default_file_open_flags();
ikrylov@2000 420 static int open(const char *path, int oflag, int mode);
ikrylov@2000 421 static int close(int fd);
ikrylov@2000 422 static jlong lseek(int fd, jlong offset, int whence);
ikrylov@2000 423 static char* native_path(char *path);
ikrylov@2000 424 static int ftruncate(int fd, jlong length);
ikrylov@2000 425 static int fsync(int fd);
ikrylov@2000 426 static int available(int fd, jlong *bytes);
ikrylov@2000 427
ikrylov@2000 428 //File i/o operations
ikrylov@2000 429
ikrylov@2000 430 static size_t read(int fd, void *buf, unsigned int nBytes);
ikrylov@2000 431 static size_t restartable_read(int fd, void *buf, unsigned int nBytes);
ikrylov@2000 432 static size_t write(int fd, const void *buf, unsigned int nBytes);
ikrylov@2000 433
duke@0 434 // Reading directories.
duke@0 435 static DIR* opendir(const char* dirname);
duke@0 436 static int readdir_buf_size(const char *path);
duke@0 437 static struct dirent* readdir(DIR* dirp, dirent* dbuf);
duke@0 438 static int closedir(DIR* dirp);
duke@0 439
duke@0 440 // Dynamic library extension
duke@0 441 static const char* dll_file_extension();
duke@0 442
duke@0 443 static const char* get_temp_directory();
duke@0 444 static const char* get_current_directory(char *buf, int buflen);
duke@0 445
kamg@245 446 // Builds a platform-specific full library path given a ld path and lib name
kamg@245 447 static void dll_build_name(char* buffer, size_t size,
kamg@245 448 const char* pathname, const char* fname);
kamg@245 449
duke@0 450 // Symbol lookup, find nearest function name; basically it implements
duke@0 451 // dladdr() for all platforms. Name of the nearest function is copied
duke@0 452 // to buf. Distance from its base address is returned as offset.
duke@0 453 // If function name is not found, buf[0] is set to '\0' and offset is
duke@0 454 // set to -1.
duke@0 455 static bool dll_address_to_function_name(address addr, char* buf,
duke@0 456 int buflen, int* offset);
duke@0 457
duke@0 458 // Locate DLL/DSO. On success, full path of the library is copied to
duke@0 459 // buf, and offset is set to be the distance between addr and the
duke@0 460 // library's base address. On failure, buf[0] is set to '\0' and
duke@0 461 // offset is set to -1.
duke@0 462 static bool dll_address_to_library_name(address addr, char* buf,
duke@0 463 int buflen, int* offset);
duke@0 464
duke@0 465 // Find out whether the pc is in the static code for jvm.dll/libjvm.so.
duke@0 466 static bool address_is_in_vm(address addr);
duke@0 467
duke@0 468 // Loads .dll/.so and
duke@0 469 // in case of error it checks if .dll/.so was built for the
duke@0 470 // same architecture as Hotspot is running on
duke@0 471 static void* dll_load(const char *name, char *ebuf, int ebuflen);
duke@0 472
kamg@245 473 // lookup symbol in a shared library
kamg@245 474 static void* dll_lookup(void* handle, const char* name);
kamg@245 475
ikrylov@2000 476 // Unload library
ikrylov@2000 477 static void dll_unload(void *lib);
ikrylov@2000 478
duke@0 479 // Print out system information; they are called by fatal error handler.
duke@0 480 // Output format may be different on different platforms.
duke@0 481 static void print_os_info(outputStream* st);
duke@0 482 static void print_cpu_info(outputStream* st);
duke@0 483 static void print_memory_info(outputStream* st);
duke@0 484 static void print_dll_info(outputStream* st);
duke@0 485 static void print_environment_variables(outputStream* st, const char** env_list, char* buffer, int len);
duke@0 486 static void print_context(outputStream* st, void* context);
never@1934 487 static void print_register_info(outputStream* st, void* context);
duke@0 488 static void print_siginfo(outputStream* st, void* siginfo);
duke@0 489 static void print_signal_handlers(outputStream* st, char* buf, size_t buflen);
duke@0 490 static void print_date_and_time(outputStream* st);
duke@0 491
never@1934 492 static void print_location(outputStream* st, intptr_t x, bool verbose = false);
ikrylov@2000 493 static size_t lasterror(char *buf, size_t len);
bobv@1703 494
duke@0 495 // The following two functions are used by fatal error handler to trace
duke@0 496 // native (C) frames. They are not part of frame.hpp/frame.cpp because
duke@0 497 // frame.hpp/cpp assume thread is JavaThread, and also because different
duke@0 498 // OS/compiler may have different convention or provide different API to
duke@0 499 // walk C frames.
duke@0 500 //
duke@0 501 // We don't attempt to become a debugger, so we only follow frames if that
duke@0 502 // does not require a lookup in the unwind table, which is part of the binary
duke@0 503 // file but may be unsafe to read after a fatal error. So on x86, we can
duke@0 504 // only walk stack if %ebp is used as frame pointer; on ia64, it's not
duke@0 505 // possible to walk C stack without having the unwind table.
duke@0 506 static bool is_first_C_frame(frame *fr);
duke@0 507 static frame get_sender_for_C_frame(frame *fr);
duke@0 508
duke@0 509 // return current frame. pc() and sp() are set to NULL on failure.
duke@0 510 static frame current_frame();
duke@0 511
duke@0 512 static void print_hex_dump(outputStream* st, address start, address end, int unitsize);
duke@0 513
duke@0 514 // returns a string to describe the exception/signal;
duke@0 515 // returns NULL if exception_code is not an OS exception/signal.
duke@0 516 static const char* exception_name(int exception_code, char* buf, size_t buflen);
duke@0 517
duke@0 518 // Returns native Java library, loads if necessary
duke@0 519 static void* native_java_library();
duke@0 520
ikrylov@2000 521 // Fills in path to jvm.dll/libjvm.so (used by the Disassembler)
duke@0 522 static void jvm_path(char *buf, jint buflen);
duke@0 523
bobv@1703 524 // Returns true if we are running in a headless jre.
bobv@1703 525 static bool is_headless_jre();
bobv@1703 526
duke@0 527 // JNI names
duke@0 528 static void print_jni_name_prefix_on(outputStream* st, int args_size);
duke@0 529 static void print_jni_name_suffix_on(outputStream* st, int args_size);
duke@0 530
duke@0 531 // File conventions
duke@0 532 static const char* file_separator();
duke@0 533 static const char* line_separator();
duke@0 534 static const char* path_separator();
duke@0 535
duke@0 536 // Init os specific system properties values
duke@0 537 static void init_system_properties_values();
duke@0 538
duke@0 539 // IO operations, non-JVM_ version.
duke@0 540 static int stat(const char* path, struct stat* sbuf);
duke@0 541 static bool dir_is_empty(const char* path);
duke@0 542
duke@0 543 // IO operations on binary files
duke@0 544 static int create_binary_file(const char* path, bool rewrite_existing);
duke@0 545 static jlong current_file_offset(int fd);
duke@0 546 static jlong seek_to_file_offset(int fd, jlong offset);
duke@0 547
duke@0 548 // Thread Local Storage
duke@0 549 static int allocate_thread_local_storage();
duke@0 550 static void thread_local_storage_at_put(int index, void* value);
duke@0 551 static void* thread_local_storage_at(int index);
duke@0 552 static void free_thread_local_storage(int index);
duke@0 553
duke@0 554 // General allocation (must be MT-safe)
duke@0 555 static void* malloc (size_t size);
duke@0 556 static void* realloc (void *memblock, size_t size);
duke@0 557 static void free (void *memblock);
duke@0 558 static bool check_heap(bool force = false); // verify C heap integrity
duke@0 559 static char* strdup(const char *); // Like strdup
duke@0 560
duke@0 561 #ifndef PRODUCT
duke@0 562 static int num_mallocs; // # of calls to malloc/realloc
duke@0 563 static size_t alloc_bytes; // # of bytes allocated
duke@0 564 static int num_frees; // # of calls to free
duke@0 565 #endif
duke@0 566
ikrylov@2000 567 // SocketInterface (ex HPI SocketInterface )
ikrylov@2000 568 static int socket(int domain, int type, int protocol);
ikrylov@2000 569 static int socket_close(int fd);
ikrylov@2000 570 static int socket_shutdown(int fd, int howto);
ikrylov@2000 571 static int recv(int fd, char *buf, int nBytes, int flags);
ikrylov@2000 572 static int send(int fd, char *buf, int nBytes, int flags);
ikrylov@2000 573 static int raw_send(int fd, char *buf, int nBytes, int flags);
ikrylov@2000 574 static int timeout(int fd, long timeout);
ikrylov@2000 575 static int listen(int fd, int count);
ikrylov@2000 576 static int connect(int fd, struct sockaddr *him, int len);
ikrylov@2000 577 static int bind(int fd, struct sockaddr *him, int len);
ikrylov@2000 578 static int accept(int fd, struct sockaddr *him, int *len);
ikrylov@2000 579 static int recvfrom(int fd, char *buf, int nbytes, int flags,
ikrylov@2000 580 struct sockaddr *from, int *fromlen);
ikrylov@2000 581 static int get_sock_name(int fd, struct sockaddr *him, int *len);
ikrylov@2000 582 static int sendto(int fd, char *buf, int len, int flags,
ikrylov@2000 583 struct sockaddr *to, int tolen);
ikrylov@2000 584 static int socket_available(int fd, jint *pbytes);
ikrylov@2000 585
ikrylov@2000 586 static int get_sock_opt(int fd, int level, int optname,
ikrylov@2000 587 char *optval, int* optlen);
ikrylov@2000 588 static int set_sock_opt(int fd, int level, int optname,
ikrylov@2000 589 const char *optval, int optlen);
ikrylov@2000 590 static int get_host_name(char* name, int namelen);
ikrylov@2000 591
ikrylov@2000 592 static struct hostent* get_host_by_name(char* name);
ikrylov@2000 593
duke@0 594 // Printing 64 bit integers
duke@0 595 static const char* jlong_format_specifier();
duke@0 596 static const char* julong_format_specifier();
duke@0 597
duke@0 598 // Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
duke@0 599 static void signal_init();
duke@0 600 static void signal_init_pd();
duke@0 601 static void signal_notify(int signal_number);
duke@0 602 static void* signal(int signal_number, void* handler);
duke@0 603 static void signal_raise(int signal_number);
duke@0 604 static int signal_wait();
duke@0 605 static int signal_lookup();
duke@0 606 static void* user_handler();
duke@0 607 static void terminate_signal_thread();
duke@0 608 static int sigexitnum_pd();
duke@0 609
duke@0 610 // random number generation
duke@0 611 static long random(); // return 32bit pseudorandom number
duke@0 612 static void init_random(long initval); // initialize random sequence
duke@0 613
duke@0 614 // Structured OS Exception support
duke@0 615 static void os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
duke@0 616
ctornqvi@2213 617 // On Windows this will create an actual minidump, on Linux/Solaris it will simply check core dump limits
ctornqvi@2213 618 static void check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize);
ctornqvi@2213 619
duke@0 620 // JVMTI & JVM monitoring and management support
duke@0 621 // The thread_cpu_time() and current_thread_cpu_time() are only
duke@0 622 // supported if is_thread_cpu_time_supported() returns true.
duke@0 623 // They are not supported on Solaris T1.
duke@0 624
duke@0 625 // Thread CPU Time - return the fast estimate on a platform
duke@0 626 // On Solaris - call gethrvtime (fast) - user time only
duke@0 627 // On Linux - fast clock_gettime where available - user+sys
duke@0 628 // - otherwise: very slow /proc fs - user+sys
duke@0 629 // On Windows - GetThreadTimes - user+sys
duke@0 630 static jlong current_thread_cpu_time();
duke@0 631 static jlong thread_cpu_time(Thread* t);
duke@0 632
duke@0 633 // Thread CPU Time with user_sys_cpu_time parameter.
duke@0 634 //
duke@0 635 // If user_sys_cpu_time is true, user+sys time is returned.
duke@0 636 // Otherwise, only user time is returned
duke@0 637 static jlong current_thread_cpu_time(bool user_sys_cpu_time);
duke@0 638 static jlong thread_cpu_time(Thread* t, bool user_sys_cpu_time);
duke@0 639
duke@0 640 // Return a bunch of info about the timers.
duke@0 641 // Note that the returned info for these two functions may be different
duke@0 642 // on some platforms
duke@0 643 static void current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr);
duke@0 644 static void thread_cpu_time_info(jvmtiTimerInfo *info_ptr);
duke@0 645
duke@0 646 static bool is_thread_cpu_time_supported();
duke@0 647
duke@0 648 // System loadavg support. Returns -1 if load average cannot be obtained.
duke@0 649 static int loadavg(double loadavg[], int nelem);
duke@0 650
duke@0 651 // Hook for os specific jvm options that we don't want to abort on seeing
duke@0 652 static bool obsolete_option(const JavaVMOption *option);
duke@0 653
duke@0 654 // Platform dependent stuff
stefank@1992 655 #ifdef TARGET_OS_FAMILY_linux
stefank@1992 656 # include "os_linux.hpp"
stefank@1992 657 #endif
stefank@1992 658 #ifdef TARGET_OS_FAMILY_solaris
stefank@1992 659 # include "os_solaris.hpp"
stefank@1992 660 #endif
stefank@1992 661 #ifdef TARGET_OS_FAMILY_windows
stefank@1992 662 # include "os_windows.hpp"
stefank@1992 663 #endif
stefank@1992 664 #ifdef TARGET_OS_ARCH_linux_x86
stefank@1992 665 # include "os_linux_x86.hpp"
stefank@1992 666 #endif
stefank@1992 667 #ifdef TARGET_OS_ARCH_linux_sparc
stefank@1992 668 # include "os_linux_sparc.hpp"
stefank@1992 669 #endif
stefank@1992 670 #ifdef TARGET_OS_ARCH_linux_zero
stefank@1992 671 # include "os_linux_zero.hpp"
stefank@1992 672 #endif
stefank@1992 673 #ifdef TARGET_OS_ARCH_solaris_x86
stefank@1992 674 # include "os_solaris_x86.hpp"
stefank@1992 675 #endif
stefank@1992 676 #ifdef TARGET_OS_ARCH_solaris_sparc
stefank@1992 677 # include "os_solaris_sparc.hpp"
stefank@1992 678 #endif
stefank@1992 679 #ifdef TARGET_OS_ARCH_windows_x86
stefank@1992 680 # include "os_windows_x86.hpp"
stefank@1992 681 #endif
bobv@2201 682 #ifdef TARGET_OS_ARCH_linux_arm
bobv@2201 683 # include "os_linux_arm.hpp"
bobv@2201 684 #endif
bobv@2201 685 #ifdef TARGET_OS_ARCH_linux_ppc
bobv@2201 686 # include "os_linux_ppc.hpp"
bobv@2201 687 #endif
stefank@1992 688
duke@0 689
bobv@1703 690 // debugging support (mostly used by debug.cpp but also fatal error handler)
bobv@1703 691 static bool find(address pc, outputStream* st = tty); // OS specific function to make sense out of an address
duke@0 692
duke@0 693 static bool dont_yield(); // when true, JVM_Yield() is nop
duke@0 694 static void print_statistics();
duke@0 695
duke@0 696 // Thread priority helpers (implemented in OS-specific part)
duke@0 697 static OSReturn set_native_priority(Thread* thread, int native_prio);
duke@0 698 static OSReturn get_native_priority(const Thread* const thread, int* priority_ptr);
duke@0 699 static int java_to_os_priority[MaxPriority + 1];
duke@0 700 // Hint to the underlying OS that a task switch would not be good.
duke@0 701 // Void return because it's a hint and can fail.
duke@0 702 static void hint_no_preempt();
duke@0 703
duke@0 704 // Used at creation if requested by the diagnostic flag PauseAtStartup.
duke@0 705 // Causes the VM to wait until an external stimulus has been applied
duke@0 706 // (for Unix, that stimulus is a signal, for Windows, an external
duke@0 707 // ResumeThread call)
duke@0 708 static void pause();
duke@0 709
duke@0 710 protected:
duke@0 711 static long _rand_seed; // seed for random number generator
duke@0 712 static int _processor_count; // number of processors
duke@0 713
duke@0 714 static char* format_boot_path(const char* format_string,
duke@0 715 const char* home,
duke@0 716 int home_len,
duke@0 717 char fileSep,
duke@0 718 char pathSep);
duke@0 719 static bool set_boot_path(char fileSep, char pathSep);
phh@729 720 static char** split_path(const char* path, int* n);
duke@0 721 };
duke@0 722
duke@0 723 // Note that "PAUSE" is almost always used with synchronization
duke@0 724 // so arguably we should provide Atomic::SpinPause() instead
duke@0 725 // of the global SpinPause() with C linkage.
duke@0 726 // It'd also be eligible for inlining on many platforms.
duke@0 727
duke@0 728 extern "C" int SpinPause () ;
duke@0 729 extern "C" int SafeFetch32 (int * adr, int errValue) ;
duke@0 730 extern "C" intptr_t SafeFetchN (intptr_t * adr, intptr_t errValue) ;
stefank@1992 731
stefank@1992 732 #endif // SHARE_VM_RUNTIME_OS_HPP