src/share/vm/runtime/os.hpp

Thu, 12 Oct 2017 21:27:07 +0800

author
aoqi
date
Thu, 12 Oct 2017 21:27:07 +0800
changeset 7535
7ae4e26cb1e0
parent 7273
c12e6bac4ad0
parent 6876
710a3c8b516e
child 7994
04ff2f6cd0eb
permissions
-rw-r--r--

merge

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

mercurial