src/share/vm/runtime/os.hpp

Thu, 24 May 2018 18:41:44 +0800

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

mercurial