os.hpp revision 1320
/*
* Copyright 1997-2009 Sun Microsystems, Inc. All Rights Reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* under the terms of the GNU General Public License version 2 only, as
* published by the Free Software Foundation.
*
* This code is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* version 2 for more details (a copy is included in the LICENSE file that
* accompanied this code).
*
* You should have received a copy of the GNU General Public License version
* 2 along with this work; if not, write to the Free Software Foundation,
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
*
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
* CA 95054 USA or visit www.sun.com if you need additional information or
* have any questions.
*
*/
// os defines the interface to operating system; this includes traditional
// OS services (time, I/O) as well as other functionality with system-
// dependent code.
typedef void (*dll_func)(...);
class Thread;
class JavaThread;
class Event;
class DLL;
class FileHandle;
template<class E> class GrowableArray;
// %%%%% Moved ThreadState, START_FN, OSThread to new osThread.hpp. -- Rose
// Platform-independent error return values from OS functions
enum OSReturn {
OS_OK = 0, // Operation was successful
};
enum ThreadPriority { // JLS 20.20.1-3
// ensures that VMThread doesn't starve profiler
};
// Typedef for structured exception handling support
typedef void (*java_call_t)(JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
public:
private:
static OSThread* _starting_thread;
static address _polling_page;
static volatile int32_t * _mem_serialize_page;
static uintptr_t _serialize_page_mask;
public:
private:
_page_sizes[0] = default_page_size;
}
public:
static void init(void); // Called before command line parsing
// File names are case-insensitive on windows only
// Override me as needed
static bool have_special_privileges();
static jlong javaTimeMillis();
static jlong javaTimeNanos();
static void run_periodic_checks();
// Returns the elapsed time in seconds since the vm started.
static double elapsedTime();
// Returns real time in seconds since an arbitrary point
// in the past.
static bool getTimesSecs(double* process_real_time,
double* process_user_time,
double* process_system_time);
// Interface to the performance counter
static jlong elapsed_counter();
static jlong elapsed_frequency();
// The "virtual time" of a thread is the amount of time a thread has
// actually run. The first function indicates whether the OS supports
// this functionality for the current thread, and if so:
// * the second enables vtime tracking (if that is required).
// * the third tells whether vtime is enabled.
// * the fourth returns the elapsed virtual time for the current
// thread.
static bool supports_vtime();
static bool enable_vtime();
static bool vtime_enabled();
static double elapsedVTime();
// Return current local time in a string (YYYY-MM-DD HH:MM:SS).
// It is MT safe, but not async-safe, as reading time zone
// information may require a lock on some platforms.
// Fill in buffer with current local time as an ISO-8601 string.
// E.g., YYYY-MM-DDThh:mm:ss.mmm+zzzz.
// Returns buffer, or NULL if it failed.
// Interface for detecting multiprocessor system
static inline bool is_MP() {
return _processor_count > 1;
}
static julong available_memory();
static julong physical_memory();
static bool is_server_class_machine();
// number of CPUs
static int processor_count() {
return _processor_count;
}
// Returns the number of CPUs this process is currently allowed to run on.
// Note that on some OSes this can change dynamically.
static int active_processor_count();
// Bind processes to processors.
// This is a two step procedure:
// first you generate a distribution of processes to processors,
// then you bind processes according to that distribution.
// Compute a distribution for number of processes to processors.
// Stores the processor id's into the distribution array argument.
// Returns true if it worked, false if it didn't.
// Binds the current process to a processor.
// Returns true if it worked, false if it didn't.
// Interface for stack banging (predetect possible stack overflow for
// exception processing) There are guard pages, and above that shadow
// pages for stack overflow checking.
static bool uses_stack_guard_pages();
static bool allocate_stack_guard_pages();
static void bang_stack_shadow_pages();
// OS interface to Virtual Memory
// Return the default page size.
static int vm_page_size();
// Return the page size to use for a region of memory. The min_pages argument
// is a hint intended to limit fragmentation; it says the returned page size
// should be <= region_max_size / min_pages. Because min_pages is a hint,
// this routine may return a size larger than region_max_size / min_pages.
//
// The current implementation ignores min_pages if a larger page size is an
// exact multiple of both region_min_size and region_max_size. This allows
// larger pages to be used when doing so would not cause fragmentation; in
// particular, a single page can be used when region_min_size ==
// region_max_size == a supported page size.
// Method for tracing page sizes returned by the above method; enabled by
// TracePageSizes. The region_{min,max}_size parameters should be the values
// passed to page_size_for_region() and page_size should be the result of that
// call. The (optional) base and size parameters should come from the
// ReservedSpace base() and size() methods.
const size_t region_max_size,
static int vm_allocation_granularity();
size_t alignment_hint = 0);
bool executable = false);
bool executable = false);
bool is_committed = true);
bool allow_exec = false);
bool allow_exec);
// NUMA-specific interface
static bool numa_has_static_binding();
static bool numa_has_group_homing();
static size_t numa_get_groups_num();
static bool numa_topology_changed();
static int numa_get_group_id();
// Page manipulation
struct page_info {
int lgrp_id;
};
static char* non_memory_address_word();
// reserve, commit and pin the entire memory region
bool executable = false);
static bool large_page_init();
static size_t large_page_size();
static bool can_commit_large_page_memory();
static bool can_execute_large_page_memory();
// OS interface to polling page
static bool is_poll_address(address addr) { return addr >= _polling_page && addr < (_polling_page + os::vm_page_size()); }
static void make_polling_page_unreadable();
static void make_polling_page_readable();
// Routines used to serialize the thread state without using membars
static void serialize_thread_states();
// Since we write to the serialize page from every thread, we
// want stores to be on unique cache lines whenever possible
// in order to minimize CPU cross talk. We pre-compute the
// amount to shift the thread* to make this offset unique to
// each thread.
static int get_serialize_page_shift_count() {
return SerializePageShiftCount;
}
}
static unsigned int get_serialize_page_mask() {
return _serialize_page_mask;
}
static address get_memory_serialize_page() {
return (address)_mem_serialize_page;
}
}
if (UseMembar) return false;
// Previously this function calculated the exact address of this
// thread's serialize page, and checked if the faulting address
// was equal. However, some platforms mask off faulting addresses
// to the page size, so now we just check that the address is
// within the page. This makes the thread argument unnecessary,
// but we retain the NULL check to preserve existing behaviour.
}
static void block_on_serialize_page_trap();
// threads
enum ThreadType {
cgc_thread, // Concurrent GC thread
pgc_thread, // Parallel GC thread
};
size_t stack_size = 0);
static void initialize_thread();
// thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit
static intx current_thread_id();
static int current_process_id();
// hpi::read for calls from non native state
// For performance, hpi::read is only callable from _thread_in_native
static int naked_sleep();
static void infinite_sleep(); // never returns, use with CAUTION
static void yield(); // Yields to all threads with same priority
enum YieldResult {
YIELD_NONEREADY = 0, // No other runnable/ready threads.
// platform-specific yield return immediately
// YIELD_SWITCHED and YIELD_NONREADY imply the platform supports a "strong"
// yield that can be used in lieu of blocking.
} ;
static YieldResult NakedYield () ;
static void loop_breaker(int attempts); // called from within tight loops to possibly influence time-sharing
static void breakpoint();
static address current_stack_pointer();
static address current_stack_base();
static size_t current_stack_size();
static char* do_you_want_to_debug(const char* message);
// run cmd in a separate process and return its exit code; or -1 on failures
static int fork_and_exec(char *cmd);
// Set file to send error reports.
static void set_error_file(const char *logfile);
// os::exit() is merged with vm_exit()
// static void exit(int num);
// Terminate the VM, but don't exit the process
static void shutdown();
// Terminate with an error. Default is to generate a core file on platforms
// that support such things. This calls shutdown() and then aborts.
// Die immediately, no exit hook, no abort hook, no cleanup.
static void die();
// Reading directories.
static int readdir_buf_size(const char *path);
// Dynamic library extension
static const char* dll_file_extension();
static const char* get_temp_directory();
// Builds a platform-specific full library path given a ld path and lib name
// Symbol lookup, find nearest function name; basically it implements
// dladdr() for all platforms. Name of the nearest function is copied
// to buf. Distance from its base address is returned as offset.
// If function name is not found, buf[0] is set to '\0' and offset is
// set to -1.
// buf, and offset is set to be the distance between addr and the
// library's base address. On failure, buf[0] is set to '\0' and
// offset is set to -1.
// Loads .dll/.so and
// in case of error it checks if .dll/.so was built for the
// same architecture as Hotspot is running on
// lookup symbol in a shared library
// Print out system information; they are called by fatal error handler.
// Output format may be different on different platforms.
static void print_environment_variables(outputStream* st, const char** env_list, char* buffer, int len);
// The following two functions are used by fatal error handler to trace
// walk C frames.
//
// We don't attempt to become a debugger, so we only follow frames if that
// does not require a lookup in the unwind table, which is part of the binary
// file but may be unsafe to read after a fatal error. So on x86, we can
// only walk stack if %ebp is used as frame pointer; on ia64, it's not
// possible to walk C stack without having the unwind table.
// return current frame. pc() and sp() are set to NULL on failure.
static frame current_frame();
// Returns native Java library, loads if necessary
static void* native_java_library();
// JNI names
// File conventions
static const char* file_separator();
static const char* line_separator();
static const char* path_separator();
// Init os specific system properties values
static void init_system_properties_values();
// IO operations, non-JVM_ version.
static bool dir_is_empty(const char* path);
// IO operations on binary files
// Thread Local Storage
static int allocate_thread_local_storage();
static void* thread_local_storage_at(int index);
static void free_thread_local_storage(int index);
// General allocation (must be MT-safe)
static char* strdup(const char *); // Like strdup
#ifndef PRODUCT
static int num_mallocs; // # of calls to malloc/realloc
static int num_frees; // # of calls to free
#endif
// Printing 64 bit integers
static const char* jlong_format_specifier();
static const char* julong_format_specifier();
// Support for signals (see JVM_RaiseSignal, JVM_RegisterSignal)
static void signal_init();
static void signal_init_pd();
static void signal_notify(int signal_number);
static void signal_raise(int signal_number);
static int signal_wait();
static int signal_lookup();
static void* user_handler();
static void terminate_signal_thread();
static int sigexitnum_pd();
// random number generation
static long random(); // return 32bit pseudorandom number
// Structured OS Exception support
static void os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread);
// JVMTI & JVM monitoring and management support
// The thread_cpu_time() and current_thread_cpu_time() are only
// supported if is_thread_cpu_time_supported() returns true.
// They are not supported on Solaris T1.
// Thread CPU Time - return the fast estimate on a platform
// On Solaris - call gethrvtime (fast) - user time only
// On Linux - fast clock_gettime where available - user+sys
// - otherwise: very slow /proc fs - user+sys
// On Windows - GetThreadTimes - user+sys
static jlong current_thread_cpu_time();
// Thread CPU Time with user_sys_cpu_time parameter.
//
// If user_sys_cpu_time is true, user+sys time is returned.
// Otherwise, only user time is returned
// Return a bunch of info about the timers.
// Note that the returned info for these two functions may be different
// on some platforms
static bool is_thread_cpu_time_supported();
// System loadavg support. Returns -1 if load average cannot be obtained.
// Hook for os specific jvm options that we don't want to abort on seeing
// Platform dependent stuff
#include "incls/_os_pd.hpp.incl"
// debugging support (mostly used by debug.cpp)
static bool find(address pc) PRODUCT_RETURN0; // OS specific function to make sense out of an address
static bool dont_yield(); // when true, JVM_Yield() is nop
static void print_statistics();
// Thread priority helpers (implemented in OS-specific part)
// Hint to the underlying OS that a task switch would not be good.
// Void return because it's a hint and can fail.
static void hint_no_preempt();
// Used at creation if requested by the diagnostic flag PauseAtStartup.
// Causes the VM to wait until an external stimulus has been applied
// (for Unix, that stimulus is a signal, for Windows, an external
// ResumeThread call)
static void pause();
protected:
static long _rand_seed; // seed for random number generator
static int _processor_count; // number of processors
static char* format_boot_path(const char* format_string,
const char* home,
int home_len,
char fileSep,
char pathSep);
static char** split_path(const char* path, int* n);
};
// Note that "PAUSE" is almost always used with synchronization
// so arguably we should provide Atomic::SpinPause() instead
// of the global SpinPause() with C linkage.
// It'd also be eligible for inlining on many platforms.
extern "C" int SpinPause () ;