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