# HG changeset patch # User dcubed # Date 1410371536 21600 # Node ID d1221849ea3db76b855414fb768f5d2385512378 # Parent a02753d5a0b28d18a76fc44b430c8c8ae0fe64a8 8057109: manual cleanup of white space issues prior to Contended Locking reorder and cache line bucket Reviewed-by: fparain, sspitsyn, coleenp diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/bsd/vm/os_bsd.cpp --- a/hotspot/src/os/bsd/vm/os_bsd.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/bsd/vm/os_bsd.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -106,18 +106,18 @@ # include #if defined(__FreeBSD__) || defined(__NetBSD__) -# include + #include #endif #ifdef __APPLE__ -# include // semaphore_* API -# include -# include -# include + #include // semaphore_* API + #include + #include + #include #endif #ifndef MAP_ANONYMOUS -#define MAP_ANONYMOUS MAP_ANON + #define MAP_ANONYMOUS MAP_ANON #endif #define MAX_PATH (2 * K) @@ -152,9 +152,9 @@ static pid_t _initial_pid = 0; -/* Signal number used to suspend/resume a thread */ - -/* do not use any signal number less than SIGSEGV, see 4355769 */ +// Signal number used to suspend/resume a thread + +// do not use any signal number less than SIGSEGV, see 4355769 static int SR_signum = SIGUSR2; sigset_t SR_sigset; @@ -232,20 +232,20 @@ #elif defined(PPC32) static char cpu_arch[] = "ppc"; #elif defined(SPARC) -# ifdef _LP64 + #ifdef _LP64 static char cpu_arch[] = "sparcv9"; -# else + #else static char cpu_arch[] = "sparc"; -# endif + #endif #else -#error Add appropriate cpu_arch setting + #error Add appropriate cpu_arch setting #endif // Compiler variant #ifdef COMPILER2 -#define COMPILER_VARIANT "server" + #define COMPILER_VARIANT "server" #else -#define COMPILER_VARIANT "client" + #define COMPILER_VARIANT "client" #endif @@ -255,21 +255,19 @@ int cpu_val; julong mem_val; - /* get processors count via hw.ncpus sysctl */ + // get processors count via hw.ncpus sysctl mib[0] = CTL_HW; mib[1] = HW_NCPU; len = sizeof(cpu_val); if (sysctl(mib, 2, &cpu_val, &len, NULL, 0) != -1 && cpu_val >= 1) { assert(len == sizeof(cpu_val), "unexpected data size"); set_processor_count(cpu_val); - } - else { + } else { set_processor_count(1); // fallback } - /* get physical memory via hw.memsize sysctl (hw.memsize is used - * since it returns a 64 bit value) - */ + // get physical memory via hw.memsize sysctl (hw.memsize is used + // since it returns a 64 bit value) mib[0] = CTL_HW; #if defined (HW_MEMSIZE) // Apple @@ -287,7 +285,7 @@ assert(len == sizeof(mem_val), "unexpected data size"); _physical_memory = mem_val; } else { - _physical_memory = 256*1024*1024; // fallback (XXXBSD?) + _physical_memory = 256 * 1024 * 1024; // fallback (XXXBSD?) } #ifdef __OpenBSD__ @@ -342,14 +340,14 @@ // Important note: if the location of libjvm.so changes this // code needs to be changed accordingly. -// See ld(1): -// The linker uses the following search paths to locate required -// shared libraries: -// 1: ... -// ... -// 7: The default directories, normally /lib and /usr/lib. + // See ld(1): + // The linker uses the following search paths to locate required + // shared libraries: + // 1: ... + // ... + // 7: The default directories, normally /lib and /usr/lib. #ifndef DEFAULT_LIBPATH -#define DEFAULT_LIBPATH "/lib:/usr/lib" + #define DEFAULT_LIBPATH "/lib:/usr/lib" #endif // Base path of extensions installed on the system. @@ -435,8 +433,8 @@ #else // __APPLE__ -#define SYS_EXTENSIONS_DIR "/Library/Java/Extensions" -#define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java" + #define SYS_EXTENSIONS_DIR "/Library/Java/Extensions" + #define SYS_EXTENSIONS_DIRS SYS_EXTENSIONS_DIR ":/Network" SYS_EXTENSIONS_DIR ":/System" SYS_EXTENSIONS_DIR ":/usr/lib/java" const char *user_home_dir = get_home(); // The null in SYS_EXTENSIONS_DIRS counts for the size of the colon after user_home_dir. @@ -565,10 +563,11 @@ sigaction(sig, (struct sigaction*)NULL, &oact); void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) : CAST_FROM_FN_PTR(void*, oact.sa_handler); - if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) + if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { return true; - else + } else { return false; + } } void os::Bsd::signal_sets_init() { @@ -611,8 +610,9 @@ } // Fill in signals that are blocked by all but the VM thread. sigemptyset(&vm_sigs); - if (!ReduceSignalUsage) + if (!ReduceSignalUsage) { sigaddset(&vm_sigs, BREAK_SIGNAL); + } debug_only(signal_sets_initialized = true); } @@ -671,8 +671,8 @@ #ifdef __APPLE__ // library handle for calling objc_registerThreadWithCollector() // without static linking to the libobjc library -#define OBJC_LIB "/usr/lib/libobjc.dylib" -#define OBJC_GCREGISTER "objc_registerThreadWithCollector" + #define OBJC_LIB "/usr/lib/libobjc.dylib" + #define OBJC_GCREGISTER "objc_registerThreadWithCollector" typedef void (*objc_registerThreadWithCollector_t)(); extern "C" objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction; objc_registerThreadWithCollector_t objc_registerThreadWithCollectorFunction = NULL; @@ -997,9 +997,9 @@ } #ifndef __APPLE__ -#ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC (1) -#endif + #ifndef CLOCK_MONOTONIC + #define CLOCK_MONOTONIC (1) + #endif #endif #ifdef __APPLE__ @@ -1176,7 +1176,6 @@ // from src/solaris/hpi/src/system_md.c size_t os::lasterror(char *buf, size_t len) { - if (errno == 0) return 0; const char *s = ::strerror(errno); @@ -1246,9 +1245,9 @@ #define JNI_LIB_PREFIX "lib" #ifdef __APPLE__ -#define JNI_LIB_SUFFIX ".dylib" + #define JNI_LIB_SUFFIX ".dylib" #else -#define JNI_LIB_SUFFIX ".so" + #define JNI_LIB_SUFFIX ".so" #endif const char* os::dll_file_extension() { return JNI_LIB_SUFFIX; } @@ -1269,9 +1268,9 @@ } return temp_path; } -#else /* __APPLE__ */ +#else // __APPLE__ const char* os::get_temp_directory() { return "/tmp"; } -#endif /* __APPLE__ */ +#endif // __APPLE__ static bool file_exists(const char* filename) { struct stat statbuf; @@ -1378,8 +1377,7 @@ // Handle non-dynamic manually: if (dlinfo.dli_fbase != NULL && - Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset, - dlinfo.dli_fbase)) { + Decoder::decode(addr, localbuf, MACH_MAXSYMLEN, offset, dlinfo.dli_fbase)) { if (!Decoder::demangle(localbuf, buf, buflen)) { jio_snprintf(buf, buflen, "%s", localbuf); } @@ -1433,8 +1431,7 @@ return NULL; } #else -void * os::dll_load(const char *filename, char *ebuf, int ebuflen) -{ +void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { // Successful loading @@ -1482,27 +1479,27 @@ } arch_t; #ifndef EM_486 - #define EM_486 6 /* Intel 80486 */ + #define EM_486 6 /* Intel 80486 */ #endif #ifndef EM_MIPS_RS3_LE - #define EM_MIPS_RS3_LE 10 /* MIPS */ + #define EM_MIPS_RS3_LE 10 /* MIPS */ #endif #ifndef EM_PPC64 - #define EM_PPC64 21 /* PowerPC64 */ + #define EM_PPC64 21 /* PowerPC64 */ #endif #ifndef EM_S390 - #define EM_S390 22 /* IBM System/390 */ + #define EM_S390 22 /* IBM System/390 */ #endif #ifndef EM_IA_64 - #define EM_IA_64 50 /* HP/Intel IA-64 */ + #define EM_IA_64 50 /* HP/Intel IA-64 */ #endif #ifndef EM_X86_64 - #define EM_X86_64 62 /* AMD x86-64 */ + #define EM_X86_64 62 /* AMD x86-64 */ #endif static const arch_t arch_array[]={ @@ -1608,7 +1605,7 @@ return NULL; } -#endif /* !__APPLE__ */ +#endif // !__APPLE__ void* os::get_default_process_handle() { #ifdef __APPLE__ @@ -1792,8 +1789,9 @@ if (ret && dli_fname[0] != '\0') { rp = realpath(dli_fname, buf); } - if (rp == NULL) + if (rp == NULL) { return; + } if (Arguments::sun_java_launcher_is_altjvm()) { // Support for the java launcher's '-XXaltjvm=' option. Typical @@ -1822,8 +1820,9 @@ assert(strstr(p, "/libjvm") == p, "invalid library name"); rp = realpath(java_home_var, buf); - if (rp == NULL) + if (rp == NULL) { return; + } // determine if this is a legacy image or modules image // modules image doesn't have "jre" subdirectory @@ -1855,8 +1854,9 @@ } else { // Fall back to path of current library rp = realpath(dli_fname, buf); - if (rp == NULL) + if (rp == NULL) { return; + } } } } @@ -1878,13 +1878,13 @@ static volatile jint sigint_count = 0; -static void -UserHandler(int sig, void *siginfo, void *context) { +static void UserHandler(int sig, void *siginfo, void *context) { // 4511530 - sem_post is serialized and handled by the manager thread. When // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We // don't want to flood the manager thread with sem_post requests. - if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) + if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) { return; + } // Ctrl-C is pressed during error reporting, likely because the error // handler fails to abort. Let VM die immediately. @@ -1923,10 +1923,8 @@ ::raise(signal_number); } -/* - * The following code is moved from os.cpp for making this - * code platform specific, which it is by its very nature. - */ +// The following code is moved from os.cpp for making this +// code platform specific, which it is by its very nature. // Will be modified when max signal is changed to be dynamic int os::sigexitnum_pd() { @@ -1939,16 +1937,18 @@ // Bsd(POSIX) specific hand shaking semaphore. #ifdef __APPLE__ typedef semaphore_t os_semaphore_t; -#define SEM_INIT(sem, value) semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, value) -#define SEM_WAIT(sem) semaphore_wait(sem) -#define SEM_POST(sem) semaphore_signal(sem) -#define SEM_DESTROY(sem) semaphore_destroy(mach_task_self(), sem) + + #define SEM_INIT(sem, value) semaphore_create(mach_task_self(), &sem, SYNC_POLICY_FIFO, value) + #define SEM_WAIT(sem) semaphore_wait(sem) + #define SEM_POST(sem) semaphore_signal(sem) + #define SEM_DESTROY(sem) semaphore_destroy(mach_task_self(), sem) #else typedef sem_t os_semaphore_t; -#define SEM_INIT(sem, value) sem_init(&sem, 0, value) -#define SEM_WAIT(sem) sem_wait(&sem) -#define SEM_POST(sem) sem_post(&sem) -#define SEM_DESTROY(sem) sem_destroy(&sem) + + #define SEM_INIT(sem, value) sem_init(&sem, 0, value) + #define SEM_WAIT(sem) sem_wait(&sem) + #define SEM_POST(sem) sem_post(&sem) + #define SEM_DESTROY(sem) sem_destroy(&sem) #endif class Semaphore : public StackObj { @@ -2087,12 +2087,10 @@ // were we externally suspended while we were waiting? threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); if (threadIsSuspended) { - // // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. - // ::SEM_POST(sig_sem); thread->java_suspend_self(); @@ -2393,9 +2391,8 @@ char *addr; bool warn_on_failure = UseLargePages && - (!FLAG_IS_DEFAULT(UseLargePages) || - !FLAG_IS_DEFAULT(LargePageSizeInBytes) - ); + (!FLAG_IS_DEFAULT(UseLargePages) || + !FLAG_IS_DEFAULT(LargePageSizeInBytes)); // Create a large shared memory region to attach to based on size. // Currently, size is the total size of the heap @@ -2573,8 +2570,7 @@ req.tv_sec = 0; if (ms > 0) { req.tv_nsec = (ms % 1000) * 1000000; - } - else { + } else { req.tv_nsec = 1; } @@ -2637,7 +2633,7 @@ 31 // 11 CriticalPriority }; #else -/* Using Mach high-level priority assignments */ +// Using Mach high-level priority assignments int os::java_to_os_priority[CriticalPriority + 1] = { 0, // 0 Entry should never be used (MINPRI_USER) @@ -2690,12 +2686,14 @@ int policy; pthread_t self = pthread_self(); - if (pthread_getschedparam(self, &policy, &sp) != 0) + if (pthread_getschedparam(self, &policy, &sp) != 0) { return OS_ERR; + } sp.sched_priority = newpri; - if (pthread_setschedparam(self, policy, &sp) != 0) + if (pthread_setschedparam(self, policy, &sp) != 0) { return OS_ERR; + } return OS_OK; #else @@ -2751,7 +2749,6 @@ // - sends signal to end the sigsuspend loop in the SR_handler // // Note that the SR_lock plays no role in this suspend/resume protocol. -// static void resume_clear_context(OSThread *osthread) { osthread->set_ucontext(NULL); @@ -2763,7 +2760,6 @@ osthread->set_siginfo(siginfo); } -// // Handler function invoked when a thread's execution is suspended or // resumed. We have to be careful that only async-safe functions are // called here (Note: most pthread functions are not async safe and @@ -2835,7 +2831,7 @@ static int SR_initialize() { struct sigaction act; char *s; - /* Get signal number to use for suspend/resume */ + // Get signal number to use for suspend/resume if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) { int sig = ::strtol(s, 0, 10); if (sig > 0 || sig < NSIG) { @@ -2849,7 +2845,7 @@ sigemptyset(&SR_sigset); sigaddset(&SR_sigset, SR_signum); - /* Set up signal handler for suspend/resume */ + // Set up signal handler for suspend/resume act.sa_flags = SA_RESTART|SA_SIGINFO; act.sa_handler = (void (*)(int)) SR_handler; @@ -2975,9 +2971,9 @@ // Note that the VM will print warnings if it detects conflicting signal // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". // -extern "C" JNIEXPORT int -JVM_handle_bsd_signal(int signo, siginfo_t* siginfo, - void* ucontext, int abort_if_unrecognized); +extern "C" JNIEXPORT int JVM_handle_bsd_signal(int signo, siginfo_t* siginfo, + void* ucontext, + int abort_if_unrecognized); void signalHandler(int sig, siginfo_t* info, void* uc) { assert(info != NULL && uc != NULL, "it must be old kernel"); @@ -3243,7 +3239,7 @@ // We will never set this flag, and we should // ignore this flag in our diagnostic #ifdef SIGNIFICANT_SIGNAL_MASK -#undef SIGNIFICANT_SIGNAL_MASK + #undef SIGNIFICANT_SIGNAL_MASK #endif #define SIGNIFICANT_SIGNAL_MASK (~0x04000000) @@ -3315,9 +3311,12 @@ } -#define DO_SIGNAL_CHECK(sig) \ - if (!sigismember(&check_signal_done, sig)) \ - os::Bsd::check_signal_handler(sig) +#define DO_SIGNAL_CHECK(sig) \ + do { \ + if (!sigismember(&check_signal_done, sig)) { \ + os::Bsd::check_signal_handler(sig); \ + } \ + } while (0) // This method is a periodic task to check for misbehaving JNI applications // under CheckJNI, we can add any periodic checks here @@ -3432,7 +3431,8 @@ } } -extern void report_error(char* file_name, int line_no, char* title, char* format, ...); +extern void report_error(char* file_name, int line_no, char* title, + char* format, ...); extern bool signal_name(int signo, char* buf, size_t len); @@ -3450,7 +3450,7 @@ // this is called _before_ the most of global arguments have been parsed void os::init(void) { - char dummy; /* used to get a guess on initial stack address */ + char dummy; // used to get a guess on initial stack address // first_hrtime = gethrtime(); // With BsdThreads the JavaMain thread pid (primordial thread) @@ -3503,8 +3503,7 @@ } // this is called _after_ the global arguments have been parsed -jint os::init_2(void) -{ +jint os::init_2(void) { // Allocate a single page and mark it as readable for safepoint polling address polling_page = (address) ::mmap(NULL, Bsd::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); guarantee(polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page"); @@ -3512,8 +3511,10 @@ os::set_polling_page(polling_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", + (intptr_t)polling_page); + } #endif if (!UseMembar) { @@ -3522,8 +3523,10 @@ os::set_memory_serialize_page(mem_serialize_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", + (intptr_t)mem_serialize_page); + } #endif } @@ -3565,8 +3568,9 @@ struct rlimit nbr_files; int status = getrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 getrlimit failed"); + } } else { nbr_files.rlim_cur = nbr_files.rlim_max; @@ -3579,8 +3583,9 @@ status = setrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 setrlimit failed"); + } } } } @@ -3623,16 +3628,17 @@ // Mark the polling page as unreadable void os::make_polling_page_unreadable(void) { - if (!guard_memory((char*)_polling_page, Bsd::page_size())) + if (!guard_memory((char*)_polling_page, Bsd::page_size())) { fatal("Could not disable polling page"); -}; + } +} // Mark the polling page as readable void os::make_polling_page_readable(void) { if (!bsd_mprotect((char *)_polling_page, Bsd::page_size(), PROT_READ)) { fatal("Could not enable polling page"); } -}; +} int os::active_processor_count() { return _processor_count; @@ -3707,8 +3713,9 @@ return fetcher.result(); } -int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) -{ +int os::Bsd::safe_cond_timedwait(pthread_cond_t *_cond, + pthread_mutex_t *_mutex, + const struct timespec *_abstime) { return pthread_cond_timedwait(_cond, _mutex, _abstime); } @@ -3745,8 +3752,9 @@ if (begin < lowest) begin = lowest; Dl_info dlinfo2; if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr - && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) + && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) { end = (address) dlinfo2.dli_saddr; + } Disassembler::decode(begin, end, st); } return true; @@ -3760,9 +3768,9 @@ // This does not do anything on Bsd. This is basically a hook for being // able to use structured exception handling (thread-local exception filters) // on, e.g., Win32. -void -os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, - JavaCallArguments* args, Thread* thread) { +void os::os_exception_wrapper(java_call_t f, JavaValue* value, + methodHandle* method, JavaCallArguments* args, + Thread* thread) { f(value, method, args, thread); } @@ -3803,7 +3811,8 @@ } ATTRIBUTE_PRINTF(3, 0) -int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) { +int local_vsnprintf(char* buf, size_t count, const char* format, + va_list args) { return ::vsnprintf(buf, count, format, args); } @@ -3815,7 +3824,7 @@ dir = opendir(path); if (dir == NULL) return true; - /* Scan the directory */ + // Scan the directory bool result = true; char buf[sizeof(struct dirent) + MAX_PATH]; while (result && (ptr = ::readdir(dir)) != NULL) { @@ -3831,7 +3840,7 @@ // from src/solaris/hpi/src/system_md.c #ifndef O_DELETE -#define O_DELETE 0x10000 + #define O_DELETE 0x10000 #endif // Open a file. Unlink the file immediately after open returns @@ -3839,7 +3848,6 @@ // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c int os::open(const char *path, int oflag, int mode) { - if (strlen(path) > MAX_PATH - 1) { errno = ENAMETOOLONG; return -1; @@ -3851,7 +3859,7 @@ fd = ::open(path, oflag, mode); if (fd == -1) return -1; - //If the open succeeded, the file might still be a directory + // If the open succeeded, the file might still be a directory { struct stat buf; int ret = ::fstat(fd, &buf); @@ -3869,33 +3877,33 @@ } } - /* - * All file descriptors that are opened in the JVM and not - * specifically destined for a subprocess should have the - * close-on-exec flag set. If we don't set it, then careless 3rd - * party native code might fork and exec without closing all - * appropriate file descriptors (e.g. as we do in closeDescriptors in - * UNIXProcess.c), and this in turn might: - * - * - cause end-of-file to fail to be detected on some file - * descriptors, resulting in mysterious hangs, or - * - * - might cause an fopen in the subprocess to fail on a system - * suffering from bug 1085341. - * - * (Yes, the default setting of the close-on-exec flag is a Unix - * design flaw) - * - * See: - * 1085341: 32-bit stdio routines should support file descriptors >255 - * 4843136: (process) pipe file descriptor from Runtime.exec not being closed - * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 - */ + // All file descriptors that are opened in the JVM and not + // specifically destined for a subprocess should have the + // close-on-exec flag set. If we don't set it, then careless 3rd + // party native code might fork and exec without closing all + // appropriate file descriptors (e.g. as we do in closeDescriptors in + // UNIXProcess.c), and this in turn might: + // + // - cause end-of-file to fail to be detected on some file + // descriptors, resulting in mysterious hangs, or + // + // - might cause an fopen in the subprocess to fail on a system + // suffering from bug 1085341. + // + // (Yes, the default setting of the close-on-exec flag is a Unix + // design flaw) + // + // See: + // 1085341: 32-bit stdio routines should support file descriptors >255 + // 4843136: (process) pipe file descriptor from Runtime.exec not being closed + // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 + // #ifdef FD_CLOEXEC { int flags = ::fcntl(fd, F_GETFD); - if (flags != -1) + if (flags != -1) { ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } } #endif @@ -3936,11 +3944,9 @@ if (::fstat(fd, &buf) >= 0) { mode = buf.st_mode; if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { - /* - * XXX: is the following call interruptible? If so, this might - * need to go through the INTERRUPT_IO() wrapper as for other - * blocking, interruptible calls in this file. - */ + // XXX: is the following call interruptible? If so, this might + // need to go through the INTERRUPT_IO() wrapper as for other + // blocking, interruptible calls in this file. int n; if (::ioctl(fd, FIONREAD, &n) >= 0) { *bytes = n; @@ -3960,8 +3966,9 @@ } int os::socket_available(int fd, jint *pbytes) { - if (fd < 0) + if (fd < 0) { return OS_OK; + } int ret; @@ -4063,8 +4070,9 @@ mach_thread = thread->osthread()->thread_id(); kr = thread_info(mach_thread, THREAD_BASIC_INFO, (thread_info_t)&tinfo, &tcount); - if (kr != KERN_SUCCESS) + if (kr != KERN_SUCCESS) { return -1; + } if (user_sys_cpu_time) { jlong nanos; @@ -4195,7 +4203,8 @@ // abstime will be the absolute timeout time // TODO: replace compute_abstime() with unpackTime() -static struct timespec* compute_abstime(struct timespec* abstime, jlong millis) { +static struct timespec* compute_abstime(struct timespec* abstime, + jlong millis) { if (millis < 0) millis = 0; struct timeval now; int status = gettimeofday(&now, NULL); @@ -4358,36 +4367,33 @@ // JSR166 // ------------------------------------------------------- -/* - * The solaris and bsd implementations of park/unpark are fairly - * conservative for now, but can be improved. They currently use a - * mutex/condvar pair, plus a a count. - * Park decrements count if > 0, else does a condvar wait. Unpark - * sets count to 1 and signals condvar. Only one thread ever waits - * on the condvar. Contention seen when trying to park implies that someone - * is unparking you, so don't wait. And spurious returns are fine, so there - * is no need to track notifications. - */ +// The solaris and bsd implementations of park/unpark are fairly +// conservative for now, but can be improved. They currently use a +// mutex/condvar pair, plus a a count. +// Park decrements count if > 0, else does a condvar wait. Unpark +// sets count to 1 and signals condvar. Only one thread ever waits +// on the condvar. Contention seen when trying to park implies that someone +// is unparking you, so don't wait. And spurious returns are fine, so there +// is no need to track notifications. #define MAX_SECS 100000000 -/* - * This code is common to bsd and solaris and will be moved to a - * common place in dolphin. - * - * The passed in time value is either a relative time in nanoseconds - * or an absolute time in milliseconds. Either way it has to be unpacked - * into suitable seconds and nanoseconds components and stored in the - * given timespec structure. - * Given time is a 64-bit value and the time_t used in the timespec is only - * a signed-32-bit value (except on 64-bit Bsd) we have to watch for - * overflow if times way in the future are given. Further on Solaris versions - * prior to 10 there is a restriction (see cond_timedwait) that the specified - * number of seconds, in abstime, is less than current_time + 100,000,000. - * As it will be 28 years before "now + 100000000" will overflow we can - * ignore overflow and just impose a hard-limit on seconds using the value - * of "now + 100,000,000". This places a limit on the timeout of about 3.17 - * years from "now". - */ + +// This code is common to bsd and solaris and will be moved to a +// common place in dolphin. +// +// The passed in time value is either a relative time in nanoseconds +// or an absolute time in milliseconds. Either way it has to be unpacked +// into suitable seconds and nanoseconds components and stored in the +// given timespec structure. +// Given time is a 64-bit value and the time_t used in the timespec is only +// a signed-32-bit value (except on 64-bit Bsd) we have to watch for +// overflow if times way in the future are given. Further on Solaris versions +// prior to 10 there is a restriction (see cond_timedwait) that the specified +// number of seconds, in abstime, is less than current_time + 100,000,000. +// As it will be 28 years before "now + 100000000" will overflow we can +// ignore overflow and just impose a hard-limit on seconds using the value +// of "now + 100,000,000". This places a limit on the timeout of about 3.17 +// years from "now". static void unpackTime(struct timespec* absTime, bool isAbsolute, jlong time) { assert(time > 0, "convertTime"); @@ -4402,19 +4408,16 @@ jlong secs = time / 1000; if (secs > max_secs) { absTime->tv_sec = max_secs; - } - else { + } else { absTime->tv_sec = secs; } absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; - } - else { + } else { jlong secs = time / NANOSECS_PER_SEC; if (secs >= MAX_SECS) { absTime->tv_sec = max_secs; absTime->tv_nsec = 0; - } - else { + } else { absTime->tv_sec = now.tv_sec + secs; absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; if (absTime->tv_nsec >= NANOSECS_PER_SEC) { @@ -4550,10 +4553,10 @@ } -/* Darwin has no "environ" in a dynamic library. */ +// Darwin has no "environ" in a dynamic library. #ifdef __APPLE__ -#include -#define environ (*_NSGetEnviron()) + #include + #define environ (*_NSGetEnviron()) #else extern char** environ; #endif @@ -4649,13 +4652,19 @@ // Get rid of libjvm.so p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // Get rid of client or server p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // check xawt/libmawt.so strcpy(libmawtpath, buf); diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/bsd/vm/os_bsd.hpp --- a/hotspot/src/os/bsd/vm/os_bsd.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/bsd/vm/os_bsd.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -30,8 +30,8 @@ // Information about the protection of the page at address '0' on this os. static bool zero_page_read_protected() { return true; } -/* pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 */ -typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *); +// pthread_getattr_np comes with BsdThreads-0.9-7 on RedHat 7.1 +typedef int (*pthread_getattr_func_type)(pthread_t, pthread_attr_t *); #ifdef __APPLE__ // Mac OS X doesn't support clock_gettime. Stub out the type, it is @@ -205,9 +205,9 @@ public: PlatformEvent() { int status; - status = pthread_cond_init (_cond, NULL); + status = pthread_cond_init(_cond, NULL); assert_status(status == 0, status, "cond_init"); - status = pthread_mutex_init (_mutex, NULL); + status = pthread_mutex_init(_mutex, NULL); assert_status(status == 0, status, "mutex_init"); _Event = 0; _nParked = 0; @@ -234,9 +234,9 @@ public: PlatformParker() { int status; - status = pthread_cond_init (_cond, NULL); + status = pthread_cond_init(_cond, NULL); assert_status(status == 0, status, "cond_init"); - status = pthread_mutex_init (_mutex, NULL); + status = pthread_mutex_init(_mutex, NULL); assert_status(status == 0, status, "mutex_init"); } }; diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/linux/vm/os_linux.cpp --- a/hotspot/src/os/linux/vm/os_linux.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/linux/vm/os_linux.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -109,7 +109,7 @@ // if RUSAGE_THREAD for getrusage() has not been defined, do it here. The code calling // getrusage() is prepared to handle the associated failure. #ifndef RUSAGE_THREAD -#define RUSAGE_THREAD (1) /* only the calling thread */ + #define RUSAGE_THREAD (1) /* only the calling thread */ #endif #define MAX_PATH (2 * K) @@ -150,13 +150,13 @@ static pid_t _initial_pid = 0; -/* Signal number used to suspend/resume a thread */ - -/* do not use any signal number less than SIGSEGV, see 4355769 */ +// Signal number used to suspend/resume a thread + +// do not use any signal number less than SIGSEGV, see 4355769 static int SR_signum = SIGUSR2; sigset_t SR_sigset; -/* Used to protect dlsym() calls */ +// Used to protect dlsym() calls static pthread_mutex_t dl_mutex; // Declarations @@ -240,17 +240,17 @@ #ifndef SYS_gettid // i386: 224, ia64: 1105, amd64: 186, sparc 143 -#ifdef __ia64__ -#define SYS_gettid 1105 -#elif __i386__ -#define SYS_gettid 224 -#elif __amd64__ -#define SYS_gettid 186 -#elif __sparc__ -#define SYS_gettid 143 -#else -#error define gettid for the arch -#endif + #ifdef __ia64__ + #define SYS_gettid 1105 + #elif __i386__ + #define SYS_gettid 224 + #elif __amd64__ + #define SYS_gettid 186 + #elif __sparc__ + #define SYS_gettid 143 + #else + #error define gettid for the arch + #endif #endif // Cpu architecture string @@ -269,13 +269,13 @@ #elif defined(PPC64) static char cpu_arch[] = "ppc64"; #elif defined(SPARC) -# ifdef _LP64 + #ifdef _LP64 static char cpu_arch[] = "sparcv9"; -# else + #else static char cpu_arch[] = "sparc"; -# endif + #endif #else -#error Add appropriate cpu_arch setting + #error Add appropriate cpu_arch setting #endif @@ -350,16 +350,16 @@ // Important note: if the location of libjvm.so changes this // code needs to be changed accordingly. -// See ld(1): -// The linker uses the following search paths to locate required -// shared libraries: -// 1: ... -// ... -// 7: The default directories, normally /lib and /usr/lib. + // See ld(1): + // The linker uses the following search paths to locate required + // shared libraries: + // 1: ... + // ... + // 7: The default directories, normally /lib and /usr/lib. #if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) -#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" + #define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" #else -#define DEFAULT_LIBPATH "/lib:/usr/lib" + #define DEFAULT_LIBPATH "/lib:/usr/lib" #endif // Base path of extensions installed on the system. @@ -469,10 +469,11 @@ sigaction(sig, (struct sigaction*)NULL, &oact); void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) : CAST_FROM_FN_PTR(void*, oact.sa_handler); - if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) + if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { return true; - else + } else { return false; + } } void os::Linux::signal_sets_init() { @@ -518,8 +519,9 @@ } // Fill in signals that are blocked by all but the VM thread. sigemptyset(&vm_sigs); - if (!ReduceSignalUsage) + if (!ReduceSignalUsage) { sigaddset(&vm_sigs, BREAK_SIGNAL); + } debug_only(signal_sets_initialized = true); } @@ -574,12 +576,12 @@ // and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a // generic name for earlier versions. // Define macros here so we can build HotSpot on old systems. -# ifndef _CS_GNU_LIBC_VERSION -# define _CS_GNU_LIBC_VERSION 2 -# endif -# ifndef _CS_GNU_LIBPTHREAD_VERSION -# define _CS_GNU_LIBPTHREAD_VERSION 3 -# endif +#ifndef _CS_GNU_LIBC_VERSION + #define _CS_GNU_LIBC_VERSION 2 +#endif +#ifndef _CS_GNU_LIBPTHREAD_VERSION + #define _CS_GNU_LIBPTHREAD_VERSION 3 +#endif size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); if (n > 0) { @@ -683,9 +685,9 @@ // should always be true if the function is not inlined. #if __GNUC__ < 3 // gcc 2.x does not support noinline attribute -#define NOINLINE + #define NOINLINE #else -#define NOINLINE __attribute__ ((noinline)) + #define NOINLINE __attribute__ ((noinline)) #endif static void _expand_stack_to(address bottom) NOINLINE; @@ -832,7 +834,8 @@ return 0; } -bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { +bool os::create_thread(Thread* thread, ThreadType thr_type, + size_t stack_size) { assert(thread->osthread() == NULL, "caller responsible"); // Allocate the OSThread object @@ -1084,9 +1087,11 @@ initial_thread_stack_size() != 0, "os::init did not locate initial thread's stack region"); if ((address)&dummy >= initial_thread_stack_bottom() && - (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) + (address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) { return true; - else return false; + } else { + return false; + } } // Find the virtual memory area that contains addr @@ -1136,8 +1141,9 @@ // in case other parts in glibc still assumes 2M max stack size. // FIXME: alt signal stack is gone, maybe we can relax this constraint? // Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small - if (stack_size > 2 * K * K IA64_ONLY(*2)) + if (stack_size > 2 * K * K IA64_ONLY(*2)) { stack_size = 2 * K * K IA64_ONLY(*2); + } // Try to figure out where the stack base (top) is. This is harder. // // When an application is started, glibc saves the initial stack pointer in @@ -1221,35 +1227,35 @@ #define _UFM UINTX_FORMAT #define _DFM INTX_FORMAT - /* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */ - /* 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */ + // 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 + // 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM, - &state, /* 3 %c */ - &ppid, /* 4 %d */ - &pgrp, /* 5 %d */ - &session, /* 6 %d */ - &nr, /* 7 %d */ - &tpgrp, /* 8 %d */ - &flags, /* 9 %lu */ - &minflt, /* 10 %lu */ - &cminflt, /* 11 %lu */ - &majflt, /* 12 %lu */ - &cmajflt, /* 13 %lu */ - &utime, /* 14 %lu */ - &stime, /* 15 %lu */ - &cutime, /* 16 %ld */ - &cstime, /* 17 %ld */ - &prio, /* 18 %ld */ - &nice, /* 19 %ld */ - &junk, /* 20 %ld */ - &it_real, /* 21 %ld */ - &start, /* 22 UINTX_FORMAT */ - &vsize, /* 23 UINTX_FORMAT */ - &rss, /* 24 INTX_FORMAT */ - &rsslim, /* 25 UINTX_FORMAT */ - &scodes, /* 26 UINTX_FORMAT */ - &ecode, /* 27 UINTX_FORMAT */ - &stack_start); /* 28 UINTX_FORMAT */ + &state, // 3 %c + &ppid, // 4 %d + &pgrp, // 5 %d + &session, // 6 %d + &nr, // 7 %d + &tpgrp, // 8 %d + &flags, // 9 %lu + &minflt, // 10 %lu + &cminflt, // 11 %lu + &majflt, // 12 %lu + &cmajflt, // 13 %lu + &utime, // 14 %lu + &stime, // 15 %lu + &cutime, // 16 %ld + &cstime, // 17 %ld + &prio, // 18 %ld + &nice, // 19 %ld + &junk, // 20 %ld + &it_real, // 21 %ld + &start, // 22 UINTX_FORMAT + &vsize, // 23 UINTX_FORMAT + &rss, // 24 INTX_FORMAT + &rsslim, // 25 UINTX_FORMAT + &scodes, // 26 UINTX_FORMAT + &ecode, // 27 UINTX_FORMAT + &stack_start); // 28 UINTX_FORMAT } #undef _UFM @@ -1348,7 +1354,7 @@ } #ifndef CLOCK_MONOTONIC -#define CLOCK_MONOTONIC (1) + #define CLOCK_MONOTONIC (1) #endif void os::Linux::clock_init() { @@ -1391,17 +1397,15 @@ } #ifndef SYS_clock_getres - -#if defined(IA32) || defined(AMD64) -#define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) -#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) + #if defined(IA32) || defined(AMD64) + #define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) + #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) + #else + #warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" + #define sys_clock_getres(x,y) -1 + #endif #else -#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" -#define sys_clock_getres(x,y) -1 -#endif - -#else -#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) + #define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) #endif void os::Linux::fast_thread_clock_init() { @@ -1425,7 +1429,6 @@ if (pthread_getcpuclockid_func && pthread_getcpuclockid_func(_main_thread, &clockid) == 0 && sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) { - _supports_fast_thread_cpu_time = true; _pthread_getcpuclockid = pthread_getcpuclockid_func; } @@ -1558,7 +1561,6 @@ // from src/solaris/hpi/src/system_md.c size_t os::lasterror(char *buf, size_t len) { - if (errno == 0) return 0; const char *s = ::strerror(errno); @@ -1818,8 +1820,7 @@ void* loaded_library() { return _lib; } }; -void * os::dll_load(const char *filename, char *ebuf, int ebuflen) -{ +void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { void * result = NULL; bool load_attempted = false; @@ -1921,9 +1922,9 @@ char* name; // String representation } arch_t; - #ifndef EM_486 +#ifndef EM_486 #define EM_486 6 /* Intel 80486 */ - #endif +#endif static const arch_t arch_array[]={ {EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, @@ -1948,38 +1949,38 @@ {EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} }; - #if (defined IA32) +#if (defined IA32) static Elf32_Half running_arch_code=EM_386; - #elif (defined AMD64) +#elif (defined AMD64) static Elf32_Half running_arch_code=EM_X86_64; - #elif (defined IA64) +#elif (defined IA64) static Elf32_Half running_arch_code=EM_IA_64; - #elif (defined __sparc) && (defined _LP64) +#elif (defined __sparc) && (defined _LP64) static Elf32_Half running_arch_code=EM_SPARCV9; - #elif (defined __sparc) && (!defined _LP64) +#elif (defined __sparc) && (!defined _LP64) static Elf32_Half running_arch_code=EM_SPARC; - #elif (defined __powerpc64__) +#elif (defined __powerpc64__) static Elf32_Half running_arch_code=EM_PPC64; - #elif (defined __powerpc__) +#elif (defined __powerpc__) static Elf32_Half running_arch_code=EM_PPC; - #elif (defined ARM) +#elif (defined ARM) static Elf32_Half running_arch_code=EM_ARM; - #elif (defined S390) +#elif (defined S390) static Elf32_Half running_arch_code=EM_S390; - #elif (defined ALPHA) +#elif (defined ALPHA) static Elf32_Half running_arch_code=EM_ALPHA; - #elif (defined MIPSEL) +#elif (defined MIPSEL) static Elf32_Half running_arch_code=EM_MIPS_RS3_LE; - #elif (defined PARISC) +#elif (defined PARISC) static Elf32_Half running_arch_code=EM_PARISC; - #elif (defined MIPS) +#elif (defined MIPS) static Elf32_Half running_arch_code=EM_MIPS; - #elif (defined M68K) +#elif (defined M68K) static Elf32_Half running_arch_code=EM_68K; - #else +#else #error Method os::dll_load requires that one of following is defined:\ IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K - #endif +#endif // Identify compatability class for VM's architecture and library's architecture // Obtain string descriptions for architectures @@ -2033,7 +2034,8 @@ return NULL; } -void * os::Linux::dlopen_helper(const char *filename, char *ebuf, int ebuflen) { +void * os::Linux::dlopen_helper(const char *filename, char *ebuf, + int ebuflen) { void * result = ::dlopen(filename, RTLD_LAZY); if (result == NULL) { ::strncpy(ebuf, ::dlerror(), ebuflen - 1); @@ -2042,7 +2044,8 @@ return result; } -void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, int ebuflen) { +void * os::Linux::dll_load_in_vmthread(const char *filename, char *ebuf, + int ebuflen) { void * result = NULL; if (LoadExecStackDllInVMThread) { result = dlopen_helper(filename, ebuf, ebuflen); @@ -2074,11 +2077,10 @@ return result; } -/* - * glibc-2.0 libdl is not MT safe. If you are building with any glibc, - * chances are you might want to run the generated bits against glibc-2.0 - * libdl.so, so always use locking for any version of glibc. - */ +// glibc-2.0 libdl is not MT safe. If you are building with any glibc, +// chances are you might want to run the generated bits against glibc-2.0 +// libdl.so, so always use locking for any version of glibc. +// void* os::dll_lookup(void* handle, const char* name) { pthread_mutex_lock(&dl_mutex); void* res = dlsym(handle, name); @@ -2308,8 +2310,9 @@ if (ret && dli_fname[0] != '\0') { rp = realpath(dli_fname, buf); } - if (rp == NULL) + if (rp == NULL) { return; + } if (Arguments::sun_java_launcher_is_altjvm()) { // Support for the java launcher's '-XXaltjvm=' option. Typical @@ -2337,8 +2340,9 @@ assert(strstr(p, "/libjvm") == p, "invalid library name"); rp = realpath(java_home_var, buf); - if (rp == NULL) + if (rp == NULL) { return; + } // determine if this is a legacy image or modules image // modules image doesn't have "jre" subdirectory @@ -2357,8 +2361,9 @@ } else { // Go back to path of .so rp = realpath(dli_fname, buf); - if (rp == NULL) + if (rp == NULL) { return; + } } } } @@ -2380,13 +2385,13 @@ static volatile jint sigint_count = 0; -static void -UserHandler(int sig, void *siginfo, void *context) { +static void UserHandler(int sig, void *siginfo, void *context) { // 4511530 - sem_post is serialized and handled by the manager thread. When // the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We // don't want to flood the manager thread with sem_post requests. - if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) + if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) { return; + } // Ctrl-C is pressed during error reporting, likely because the error // handler fails to abort. Let VM die immediately. @@ -2489,10 +2494,8 @@ ::raise(signal_number); } -/* - * The following code is moved from os.cpp for making this - * code platform specific, which it is by its very nature. - */ +// The following code is moved from os.cpp for making this +// code platform specific, which it is by its very nature. // Will be modified when max signal is changed to be dynamic int os::sigexitnum_pd() { @@ -2543,12 +2546,10 @@ // were we externally suspended while we were waiting? threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); if (threadIsSuspended) { - // // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. - // ::sem_post(&sig_sem); thread->java_suspend_self(); @@ -2696,12 +2697,12 @@ // Define MAP_HUGETLB here so we can build HotSpot on old systems. #ifndef MAP_HUGETLB -#define MAP_HUGETLB 0x40000 + #define MAP_HUGETLB 0x40000 #endif // Define MADV_HUGEPAGE here so we can build HotSpot on old systems. #ifndef MADV_HUGEPAGE -#define MADV_HUGEPAGE 14 + #define MADV_HUGEPAGE 14 #endif int os::Linux::commit_memory_impl(char* addr, size_t size, @@ -2769,7 +2770,7 @@ Linux::numa_tonode_memory(addr, bytes, lgrp_hint); } -bool os::numa_topology_changed() { return false; } +bool os::numa_topology_changed() { return false; } size_t os::numa_get_groups_num() { int max_node = Linux::numa_max_node(); @@ -2798,7 +2799,8 @@ return false; } -char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { +char *os::scan_pages(char *start, char* end, page_info* page_expected, + page_info* page_found) { return end; } @@ -2808,17 +2810,17 @@ int retval = -1; #if defined(IA32) -# ifndef SYS_getcpu -# define SYS_getcpu 318 -# endif + #ifndef SYS_getcpu + #define SYS_getcpu 318 + #endif retval = syscall(SYS_getcpu, &cpu, NULL, NULL); #elif defined(AMD64) // Unfortunately we have to bring all these macros here from vsyscall.h // to be able to compile on old linuxes. -# define __NR_vgetcpu 2 -# define VSYSCALL_START (-10UL << 20) -# define VSYSCALL_SIZE 1024 -# define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) + #define __NR_vgetcpu 2 + #define VSYSCALL_START (-10UL << 20) + #define VSYSCALL_SIZE 1024 + #define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); retval = vgetcpu(&cpu, NULL, NULL); @@ -2851,8 +2853,10 @@ dlsym(RTLD_DEFAULT, "sched_getcpu"))); // If it's not, try a direct syscall. - if (sched_getcpu() == -1) - set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall)); + if (sched_getcpu() == -1) { + set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, + (void*)&sched_getcpu_syscall)); + } if (sched_getcpu() != -1) { // Does it work? void *handle = dlopen("libnuma.so.1", RTLD_LAZY); @@ -2944,8 +2948,7 @@ return res != (uintptr_t) MAP_FAILED; } -static -address get_stack_commited_bottom(address bottom, size_t size) { +static address get_stack_commited_bottom(address bottom, size_t size) { address nbot = bottom; address ntop = bottom + size; @@ -3019,7 +3022,6 @@ // mapping. This only affects the main/initial thread bool os::pd_create_stack_guard_pages(char* addr, size_t size) { - if (os::Linux::is_initial_thread()) { // As we manually grow stack up to bottom inside create_attached_thread(), // it's likely that os::Linux::initial_thread_stack_bottom is mapped and @@ -3156,7 +3158,8 @@ return linux_mprotect(addr, size, PROT_READ|PROT_WRITE); } -bool os::Linux::transparent_huge_pages_sanity_check(bool warn, size_t page_size) { +bool os::Linux::transparent_huge_pages_sanity_check(bool warn, + size_t page_size) { bool result = false; void *p = mmap(NULL, page_size * 2, PROT_READ|PROT_WRITE, MAP_ANONYMOUS|MAP_PRIVATE, @@ -3211,20 +3214,19 @@ return result; } -/* -* Set the coredump_filter bits to include largepages in core dump (bit 6) -* -* From the coredump_filter documentation: -* -* - (bit 0) anonymous private memory -* - (bit 1) anonymous shared memory -* - (bit 2) file-backed private memory -* - (bit 3) file-backed shared memory -* - (bit 4) ELF header pages in file-backed private memory areas (it is -* effective only if the bit 2 is cleared) -* - (bit 5) hugetlb private memory -* - (bit 6) hugetlb shared memory -*/ +// Set the coredump_filter bits to include largepages in core dump (bit 6) +// +// From the coredump_filter documentation: +// +// - (bit 0) anonymous private memory +// - (bit 1) anonymous shared memory +// - (bit 2) file-backed private memory +// - (bit 3) file-backed shared memory +// - (bit 4) ELF header pages in file-backed private memory areas (it is +// effective only if the bit 2 is cleared) +// - (bit 5) hugetlb private memory +// - (bit 6) hugetlb shared memory +// static void set_coredump_filter(void) { FILE *f; long cdm; @@ -3377,10 +3379,11 @@ } #ifndef SHM_HUGETLB -#define SHM_HUGETLB 04000 + #define SHM_HUGETLB 04000 #endif -char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, char* req_addr, bool exec) { +char* os::Linux::reserve_memory_special_shm(size_t bytes, size_t alignment, + char* req_addr, bool exec) { // "exec" is passed in but not used. Creating the shared image for // the code cache doesn't have an SHM_X executable permission to check. assert(UseLargePages && UseSHM, "only for SHM large pages"); @@ -3396,8 +3399,7 @@ bool warn_on_failure = UseLargePages && (!FLAG_IS_DEFAULT(UseLargePages) || !FLAG_IS_DEFAULT(UseSHM) || - !FLAG_IS_DEFAULT(LargePageSizeInBytes) - ); + !FLAG_IS_DEFAULT(LargePageSizeInBytes)); char msg[128]; // Create a large shared memory region to attach to based on size. @@ -3446,7 +3448,8 @@ return addr; } -static void warn_on_large_pages_failure(char* req_addr, size_t bytes, int error) { +static void warn_on_large_pages_failure(char* req_addr, size_t bytes, + int error) { assert(error == ENOMEM, "Only expect to fail if no memory is available"); bool warn_on_failure = UseLargePages && @@ -3462,7 +3465,9 @@ } } -char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, char* req_addr, bool exec) { +char* os::Linux::reserve_memory_special_huge_tlbfs_only(size_t bytes, + char* req_addr, + bool exec) { assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); assert(is_size_aligned(bytes, os::large_page_size()), "Unaligned size"); assert(is_ptr_aligned(req_addr, os::large_page_size()), "Unaligned address"); @@ -3482,7 +3487,10 @@ return addr; } -char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes, size_t alignment, char* req_addr, bool exec) { +char* os::Linux::reserve_memory_special_huge_tlbfs_mixed(size_t bytes, + size_t alignment, + char* req_addr, + bool exec) { size_t large_page_size = os::large_page_size(); assert(bytes >= large_page_size, "Shouldn't allocate large pages for small sizes"); @@ -3574,7 +3582,10 @@ return start; } -char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, size_t alignment, char* req_addr, bool exec) { +char* os::Linux::reserve_memory_special_huge_tlbfs(size_t bytes, + size_t alignment, + char* req_addr, + bool exec) { assert(UseLargePages && UseHugeTLBFS, "only for Huge TLBFS large pages"); assert(is_ptr_aligned(req_addr, alignment), "Must be"); assert(is_power_of_2(alignment), "Must be"); @@ -3588,7 +3599,8 @@ } } -char* os::reserve_memory_special(size_t bytes, size_t alignment, char* req_addr, bool exec) { +char* os::reserve_memory_special(size_t bytes, size_t alignment, + char* req_addr, bool exec) { assert(UseLargePages, "only for large pages"); char* addr; @@ -3758,7 +3770,6 @@ return ::read(fd, buf, nBytes); } -// // Short sleep, direct OS call. // // Note: certain versions of Linux CFS scheduler (since 2.6.23) do not guarantee @@ -3777,8 +3788,7 @@ req.tv_sec = 0; if (ms > 0) { req.tv_nsec = (ms % 1000) * 1000000; - } - else { + } else { req.tv_nsec = 1; } @@ -3865,7 +3875,8 @@ return (ret == 0) ? OS_OK : OS_ERR; } -OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) { +OSReturn os::get_native_priority(const Thread* const thread, + int *priority_ptr) { if (!UseThreadPriorities || ThreadPriorityPolicy == 0) { *priority_ptr = java_to_os_priority[NormPriority]; return OS_OK; @@ -3902,19 +3913,18 @@ // - sends signal to end the sigsuspend loop in the SR_handler // // Note that the SR_lock plays no role in this suspend/resume protocol. -// static void resume_clear_context(OSThread *osthread) { osthread->set_ucontext(NULL); osthread->set_siginfo(NULL); } -static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) { +static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, + ucontext_t* context) { osthread->set_ucontext(context); osthread->set_siginfo(siginfo); } -// // Handler function invoked when a thread's execution is suspended or // resumed. We have to be careful that only async-safe functions are // called here (Note: most pthread functions are not async safe and @@ -3984,7 +3994,7 @@ static int SR_initialize() { struct sigaction act; char *s; - /* Get signal number to use for suspend/resume */ + // Get signal number to use for suspend/resume if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) { int sig = ::strtol(s, 0, 10); if (sig > 0 || sig < _NSIG) { @@ -3998,7 +4008,7 @@ sigemptyset(&SR_sigset); sigaddset(&SR_sigset, SR_signum); - /* Set up signal handler for suspend/resume */ + // Set up signal handler for suspend/resume act.sa_flags = SA_RESTART|SA_SIGINFO; act.sa_handler = (void (*)(int)) SR_handler; @@ -4124,9 +4134,10 @@ // Note that the VM will print warnings if it detects conflicting signal // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". // -extern "C" JNIEXPORT int -JVM_handle_linux_signal(int signo, siginfo_t* siginfo, - void* ucontext, int abort_if_unrecognized); +extern "C" JNIEXPORT int JVM_handle_linux_signal(int signo, + siginfo_t* siginfo, + void* ucontext, + int abort_if_unrecognized); void signalHandler(int sig, siginfo_t* info, void* uc) { assert(info != NULL && uc != NULL, "it must be old kernel"); @@ -4375,7 +4386,7 @@ // We will never set this flag, and we should // ignore this flag in our diagnostic #ifdef SIGNIFICANT_SIGNAL_MASK -#undef SIGNIFICANT_SIGNAL_MASK + #undef SIGNIFICANT_SIGNAL_MASK #endif #define SIGNIFICANT_SIGNAL_MASK (~0x04000000) @@ -4447,15 +4458,17 @@ } -#define DO_SIGNAL_CHECK(sig) \ - if (!sigismember(&check_signal_done, sig)) \ - os::Linux::check_signal_handler(sig) +#define DO_SIGNAL_CHECK(sig) \ + do { \ + if (!sigismember(&check_signal_done, sig)) { \ + os::Linux::check_signal_handler(sig); \ + } \ + } while (0) // This method is a periodic task to check for misbehaving JNI applications // under CheckJNI, we can add any periodic checks here void os::run_periodic_checks() { - if (check_signals == false) return; // SEGV and BUS if overridden could potentially prevent @@ -4566,7 +4579,8 @@ } } -extern void report_error(char* file_name, int line_no, char* title, char* format, ...); +extern void report_error(char* file_name, int line_no, char* title, + char* format, ...); extern bool signal_name(int signo, char* buf, size_t len); @@ -4584,7 +4598,7 @@ // this is called _before_ the most of global arguments have been parsed void os::init(void) { - char dummy; /* used to get a guess on initial stack address */ + char dummy; // used to get a guess on initial stack address // first_hrtime = gethrtime(); // With LinuxThreads the JavaMain thread pid (primordial thread) @@ -4657,8 +4671,7 @@ } // this is called _after_ the global arguments have been parsed -jint os::init_2(void) -{ +jint os::init_2(void) { Linux::fast_thread_clock_init(); // Allocate a single page and mark it as readable for safepoint polling @@ -4668,8 +4681,10 @@ os::set_polling_page(polling_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", + (intptr_t)polling_page); + } #endif if (!UseMembar) { @@ -4678,8 +4693,10 @@ os::set_memory_serialize_page(mem_serialize_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", + (intptr_t)mem_serialize_page); + } #endif } @@ -4767,14 +4784,16 @@ struct rlimit nbr_files; int status = getrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 getrlimit failed"); + } } else { nbr_files.rlim_cur = nbr_files.rlim_max; status = setrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 setrlimit failed"); + } } } } @@ -4820,16 +4839,17 @@ // Mark the polling page as unreadable void os::make_polling_page_unreadable(void) { - if (!guard_memory((char*)_polling_page, Linux::page_size())) + if (!guard_memory((char*)_polling_page, Linux::page_size())) { fatal("Could not disable polling page"); -}; + } +} // Mark the polling page as readable void os::make_polling_page_readable(void) { if (!linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) { fatal("Could not enable polling page"); } -}; +} int os::active_processor_count() { // Linux doesn't yet have a (official) notion of processor sets, @@ -4902,8 +4922,9 @@ return fetcher.result(); } -int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) -{ +int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, + pthread_mutex_t *_mutex, + const struct timespec *_abstime) { if (is_NPTL()) { return pthread_cond_timedwait(_cond, _mutex, _abstime); } else { @@ -4950,8 +4971,9 @@ if (begin < lowest) begin = lowest; Dl_info dlinfo2; if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr - && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) + && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) { end = (address) dlinfo2.dli_saddr; + } Disassembler::decode(begin, end, st); } return true; @@ -5007,7 +5029,8 @@ return true; } -int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) { +int local_vsnprintf(char* buf, size_t count, const char* format, + va_list args) { return ::vsnprintf(buf, count, format, args); } @@ -5019,7 +5042,7 @@ dir = opendir(path); if (dir == NULL) return true; - /* Scan the directory */ + // Scan the directory bool result = true; char buf[sizeof(struct dirent) + MAX_PATH]; while (result && (ptr = ::readdir(dir)) != NULL) { @@ -5035,7 +5058,7 @@ // from src/solaris/hpi/src/system_md.c #ifndef O_DELETE -#define O_DELETE 0x10000 + #define O_DELETE 0x10000 #endif // Open a file. Unlink the file immediately after open returns @@ -5043,7 +5066,6 @@ // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c int os::open(const char *path, int oflag, int mode) { - if (strlen(path) > MAX_PATH - 1) { errno = ENAMETOOLONG; return -1; @@ -5073,33 +5095,33 @@ } } - /* - * All file descriptors that are opened in the JVM and not - * specifically destined for a subprocess should have the - * close-on-exec flag set. If we don't set it, then careless 3rd - * party native code might fork and exec without closing all - * appropriate file descriptors (e.g. as we do in closeDescriptors in - * UNIXProcess.c), and this in turn might: - * - * - cause end-of-file to fail to be detected on some file - * descriptors, resulting in mysterious hangs, or - * - * - might cause an fopen in the subprocess to fail on a system - * suffering from bug 1085341. - * - * (Yes, the default setting of the close-on-exec flag is a Unix - * design flaw) - * - * See: - * 1085341: 32-bit stdio routines should support file descriptors >255 - * 4843136: (process) pipe file descriptor from Runtime.exec not being closed - * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 - */ + // All file descriptors that are opened in the JVM and not + // specifically destined for a subprocess should have the + // close-on-exec flag set. If we don't set it, then careless 3rd + // party native code might fork and exec without closing all + // appropriate file descriptors (e.g. as we do in closeDescriptors in + // UNIXProcess.c), and this in turn might: + // + // - cause end-of-file to fail to be detected on some file + // descriptors, resulting in mysterious hangs, or + // + // - might cause an fopen in the subprocess to fail on a system + // suffering from bug 1085341. + // + // (Yes, the default setting of the close-on-exec flag is a Unix + // design flaw) + // + // See: + // 1085341: 32-bit stdio routines should support file descriptors >255 + // 4843136: (process) pipe file descriptor from Runtime.exec not being closed + // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 + // #ifdef FD_CLOEXEC { int flags = ::fcntl(fd, F_GETFD); - if (flags != -1) + if (flags != -1) { ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } } #endif @@ -5140,11 +5162,9 @@ if (::fstat64(fd, &buf64) >= 0) { mode = buf64.st_mode; if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { - /* - * XXX: is the following call interruptible? If so, this might - * need to go through the INTERRUPT_IO() wrapper as for other - * blocking, interruptible calls in this file. - */ + // XXX: is the following call interruptible? If so, this might + // need to go through the INTERRUPT_IO() wrapper as for other + // blocking, interruptible calls in this file. int n; if (::ioctl(fd, FIONREAD, &n) >= 0) { *bytes = n; @@ -5270,10 +5290,7 @@ } } -// // -1 on error. -// - static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { pid_t tid = thread->osthread()->thread_id(); char *s; @@ -5606,35 +5623,31 @@ // JSR166 // ------------------------------------------------------- -/* - * The solaris and linux implementations of park/unpark are fairly - * conservative for now, but can be improved. They currently use a - * mutex/condvar pair, plus a a count. - * Park decrements count if > 0, else does a condvar wait. Unpark - * sets count to 1 and signals condvar. Only one thread ever waits - * on the condvar. Contention seen when trying to park implies that someone - * is unparking you, so don't wait. And spurious returns are fine, so there - * is no need to track notifications. - */ - -/* - * This code is common to linux and solaris and will be moved to a - * common place in dolphin. - * - * The passed in time value is either a relative time in nanoseconds - * or an absolute time in milliseconds. Either way it has to be unpacked - * into suitable seconds and nanoseconds components and stored in the - * given timespec structure. - * Given time is a 64-bit value and the time_t used in the timespec is only - * a signed-32-bit value (except on 64-bit Linux) we have to watch for - * overflow if times way in the future are given. Further on Solaris versions - * prior to 10 there is a restriction (see cond_timedwait) that the specified - * number of seconds, in abstime, is less than current_time + 100,000,000. - * As it will be 28 years before "now + 100000000" will overflow we can - * ignore overflow and just impose a hard-limit on seconds using the value - * of "now + 100,000,000". This places a limit on the timeout of about 3.17 - * years from "now". - */ +// The solaris and linux implementations of park/unpark are fairly +// conservative for now, but can be improved. They currently use a +// mutex/condvar pair, plus a a count. +// Park decrements count if > 0, else does a condvar wait. Unpark +// sets count to 1 and signals condvar. Only one thread ever waits +// on the condvar. Contention seen when trying to park implies that someone +// is unparking you, so don't wait. And spurious returns are fine, so there +// is no need to track notifications. + +// This code is common to linux and solaris and will be moved to a +// common place in dolphin. +// +// The passed in time value is either a relative time in nanoseconds +// or an absolute time in milliseconds. Either way it has to be unpacked +// into suitable seconds and nanoseconds components and stored in the +// given timespec structure. +// Given time is a 64-bit value and the time_t used in the timespec is only +// a signed-32-bit value (except on 64-bit Linux) we have to watch for +// overflow if times way in the future are given. Further on Solaris versions +// prior to 10 there is a restriction (see cond_timedwait) that the specified +// number of seconds, in abstime, is less than current_time + 100,000,000. +// As it will be 28 years before "now + 100000000" will overflow we can +// ignore overflow and just impose a hard-limit on seconds using the value +// of "now + 100,000,000". This places a limit on the timeout of about 3.17 +// years from "now". static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { assert(time > 0, "convertTime"); @@ -5805,14 +5818,14 @@ if (_cur_index != -1) { // thread is definitely parked if (WorkAroundNPTLTimedWaitHang) { - status = pthread_cond_signal (&_cond[_cur_index]); + status = pthread_cond_signal(&_cond[_cur_index]); assert(status == 0, "invariant"); status = pthread_mutex_unlock(_mutex); assert(status == 0, "invariant"); } else { status = pthread_mutex_unlock(_mutex); assert(status == 0, "invariant"); - status = pthread_cond_signal (&_cond[_cur_index]); + status = pthread_cond_signal(&_cond[_cur_index]); assert(status == 0, "invariant"); } } else { @@ -5829,11 +5842,11 @@ extern char** environ; #ifndef __NR_fork -#define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57) + #define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57) #endif #ifndef __NR_execve -#define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59) + #define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59) #endif // Run the specified command in a separate process. Return its exit value, @@ -5925,13 +5938,19 @@ // Get rid of libjvm.so p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // Get rid of client or server p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // check xawt/libmawt.so strcpy(libmawtpath, buf); @@ -6018,12 +6037,11 @@ } } -// // See if the /dev/mem_notify device exists, and if so, start a thread to monitor it. // void MemNotifyThread::start() { - int fd; - fd = open ("/dev/mem_notify", O_RDONLY, 0); + int fd; + fd = open("/dev/mem_notify", O_RDONLY, 0); if (fd < 0) { return; } @@ -6040,12 +6058,12 @@ #ifndef PRODUCT -#define test_log(...) \ - do {\ - if (VerboseInternalVMTests) { \ - tty->print_cr(__VA_ARGS__); \ - tty->flush(); \ - }\ +#define test_log(...) \ + do { \ + if (VerboseInternalVMTests) { \ + tty->print_cr(__VA_ARGS__); \ + tty->flush(); \ + } \ } while (false) class TestReserveMemorySpecial : AllStatic { diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/linux/vm/os_linux.hpp --- a/hotspot/src/os/linux/vm/os_linux.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/linux/vm/os_linux.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -27,8 +27,8 @@ // Linux_OS defines the interface to Linux operating systems -/* pthread_getattr_np comes with LinuxThreads-0.9-7 on RedHat 7.1 */ -typedef int (*pthread_getattr_func_type) (pthread_t, pthread_attr_t *); +// pthread_getattr_np comes with LinuxThreads-0.9-7 on RedHat 7.1 +typedef int (*pthread_getattr_func_type)(pthread_t, pthread_attr_t *); // Information about the protection of the page at address '0' on this os. static bool zero_page_read_protected() { return true; } @@ -302,9 +302,9 @@ public: PlatformEvent() { int status; - status = pthread_cond_init (_cond, os::Linux::condAttr()); + status = pthread_cond_init(_cond, os::Linux::condAttr()); assert_status(status == 0, status, "cond_init"); - status = pthread_mutex_init (_mutex, NULL); + status = pthread_mutex_init(_mutex, NULL); assert_status(status == 0, status, "mutex_init"); _Event = 0; _nParked = 0; @@ -336,11 +336,11 @@ public: PlatformParker() { int status; - status = pthread_cond_init (&_cond[REL_INDEX], os::Linux::condAttr()); + status = pthread_cond_init(&_cond[REL_INDEX], os::Linux::condAttr()); assert_status(status == 0, status, "cond_init rel"); - status = pthread_cond_init (&_cond[ABS_INDEX], NULL); + status = pthread_cond_init(&_cond[ABS_INDEX], NULL); assert_status(status == 0, status, "cond_init abs"); - status = pthread_mutex_init (_mutex, NULL); + status = pthread_mutex_init(_mutex, NULL); assert_status(status == 0, status, "mutex_init"); _cur_index = -1; // mark as unused } diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/solaris/vm/os_solaris.cpp --- a/hotspot/src/os/solaris/vm/os_solaris.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/solaris/vm/os_solaris.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -124,17 +124,17 @@ // compile on older systems without this header file. #ifndef MADV_ACCESS_LWP -# define MADV_ACCESS_LWP 7 /* next LWP to access heavily */ + #define MADV_ACCESS_LWP 7 /* next LWP to access heavily */ #endif #ifndef MADV_ACCESS_MANY -# define MADV_ACCESS_MANY 8 /* many processes to access heavily */ + #define MADV_ACCESS_MANY 8 /* many processes to access heavily */ #endif #ifndef LGRP_RSRC_CPU -# define LGRP_RSRC_CPU 0 /* CPU resources */ + #define LGRP_RSRC_CPU 0 /* CPU resources */ #endif #ifndef LGRP_RSRC_MEM -# define LGRP_RSRC_MEM 1 /* memory resources */ + #define LGRP_RSRC_MEM 1 /* memory resources */ #endif // see thr_setprio(3T) for the basis of these numbers @@ -190,7 +190,7 @@ Thread* ThreadLocalStorage::_get_thread_cache[ThreadLocalStorage::_pd_cache_size] = {NULL}; #ifndef PRODUCT -#define _PCT(n,d) ((100.0*(double)(n))/(double)(d)) + #define _PCT(n,d) ((100.0*(double)(n))/(double)(d)) int ThreadLocalStorage::_tcacheHit = 0; int ThreadLocalStorage::_tcacheMiss = 0; @@ -200,7 +200,7 @@ tty->print_cr("Thread cache hits %d misses %d total %d percent %f\n", _tcacheHit, _tcacheMiss, total, _PCT(_tcacheHit, total)); } -#undef _PCT + #undef _PCT #endif // PRODUCT Thread* ThreadLocalStorage::get_thread_via_cache_slowly(uintptr_t raw_id, @@ -356,8 +356,9 @@ void os::Solaris::initialize_system_info() { set_processor_count(sysconf(_SC_NPROCESSORS_CONF)); - _processors_online = sysconf (_SC_NPROCESSORS_ONLN); - _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE); + _processors_online = sysconf(_SC_NPROCESSORS_ONLN); + _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * + (julong)sysconf(_SC_PAGESIZE); } int os::active_processor_count() { @@ -556,9 +557,8 @@ bool os::getenv(const char* name, char* buffer, int len) { char* val = ::getenv(name); - if (val == NULL - || strlen(val) + 1 > len ) { - if (len > 0) buffer[0] = 0; // return a null string + if (val == NULL || strlen(val) + 1 > len) { + if (len > 0) buffer[0] = 0; // return a null string return false; } strcpy(buffer, val); @@ -780,8 +780,7 @@ BREAKPOINT; } -bool os::obsolete_option(const JavaVMOption *option) -{ +bool os::obsolete_option(const JavaVMOption *option) { if (!strncmp(option->optionString, "-Xt", 3)) { return true; } else if (!strncmp(option->optionString, "-Xtm", 4)) { @@ -906,7 +905,6 @@ } void os::Solaris::hotspot_sigmask(Thread* thread) { - //Save caller's signal mask sigset_t sigmask; thr_sigsetmask(SIG_SETMASK, NULL, &sigmask); @@ -970,7 +968,8 @@ } -bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { +bool os::create_thread(Thread* thread, ThreadType thr_type, + size_t stack_size) { // Allocate the OSThread object OSThread* osthread = new OSThread(NULL, NULL); if (osthread == NULL) { @@ -1088,14 +1087,14 @@ return true; } -/* defined for >= Solaris 10. This allows builds on earlier versions - * of Solaris to take advantage of the newly reserved Solaris JVM signals - * With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2 - * and -XX:+UseAltSigs does nothing since these should have no conflict - */ +// defined for >= Solaris 10. This allows builds on earlier versions +// of Solaris to take advantage of the newly reserved Solaris JVM signals +// With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2 +// and -XX:+UseAltSigs does nothing since these should have no conflict +// #if !defined(SIGJVM1) -#define SIGJVM1 39 -#define SIGJVM2 40 + #define SIGJVM1 39 + #define SIGJVM2 40 #endif debug_only(static bool signal_sets_initialized = false); @@ -1108,10 +1107,11 @@ sigaction(sig, (struct sigaction*)NULL, &oact); void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) : CAST_FROM_FN_PTR(void*, oact.sa_handler); - if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) + if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) { return true; - else + } else { return false; + } } // Note: SIGRTMIN is a macro that calls sysconf() so it will @@ -1173,8 +1173,9 @@ } // Fill in signals that are blocked by all but the VM thread. sigemptyset(&vm_sigs); - if (!ReduceSignalUsage) + if (!ReduceSignalUsage) { sigaddset(&vm_sigs, BREAK_SIGNAL); + } debug_only(signal_sets_initialized = true); // For diagnostics only used in run_periodic_checks @@ -1244,14 +1245,13 @@ assert(stack_size > 0, "Stack size calculation problem"); if (stack_size > jt->stack_size()) { - NOT_PRODUCT( - struct rlimit limits; - getrlimit(RLIMIT_STACK, &limits); - size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur); - assert(size >= jt->stack_size(), "Stack size problem in main thread"); - ) - tty->print_cr( - "Stack size of %d Kb exceeds current limit of %d Kb.\n" +#ifndef PRODUCT + struct rlimit limits; + getrlimit(RLIMIT_STACK, &limits); + size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur); + assert(size >= jt->stack_size(), "Stack size problem in main thread"); +#endif + tty->print_cr("Stack size of %d Kb exceeds current limit of %d Kb.\n" "(Stack sizes are rounded up to a multiple of the system page size.)\n" "See limit(1) to increase the stack size limit.", stack_size / K, jt->stack_size() / K); @@ -1325,20 +1325,23 @@ // JavaThread in Java code, and have stubs simply // treat %g2 as a caller-save register, preserving it in a %lN. thread_key_t tk; - if (thr_keycreate( &tk, NULL)) + if (thr_keycreate(&tk, NULL)) { fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed " "(%s)", strerror(errno))); + } return int(tk); } void os::free_thread_local_storage(int index) { // %%% don't think we need anything here - // if ( pthread_key_delete((pthread_key_t) tk) ) + // if (pthread_key_delete((pthread_key_t) tk)) { // fatal("os::free_thread_local_storage: pthread_key_delete failed"); -} - -#define SMALLINT 32 // libthread allocate for tsd_common is a version specific + // } +} + +// libthread allocate for tsd_common is a version specific // small number - point is NO swap space available +#define SMALLINT 32 void os::thread_local_storage_at_put(int index, void* value) { // %%% this is used only in threadLocalStorage.cpp if (thr_setspecific((thread_key_t)index, value)) { @@ -1431,29 +1434,31 @@ bool os::enable_vtime() { int fd = ::open("/proc/self/ctl", O_WRONLY); - if (fd == -1) + if (fd == -1) { return false; + } long cmd[] = { PCSET, PR_MSACCT }; int res = ::write(fd, cmd, sizeof(long) * 2); ::close(fd); - if (res != sizeof(long) * 2) + if (res != sizeof(long) * 2) { return false; - + } return true; } bool os::vtime_enabled() { int fd = ::open("/proc/self/status", O_RDONLY); - if (fd == -1) + if (fd == -1) { return false; + } pstatus_t status; int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); ::close(fd); - if (res != sizeof(pstatus_t)) + if (res != sizeof(pstatus_t)) { return false; - + } return status.pr_flags & PR_MSACCT; } @@ -1471,8 +1476,9 @@ // Must return millis since Jan 1 1970 for JVM_CurrentTimeMillis jlong os::javaTimeMillis() { timeval t; - if (gettimeofday( &t, NULL) == -1) + if (gettimeofday(&t, NULL) == -1) { fatal(err_msg("os::javaTimeMillis: gettimeofday (%s)", strerror(errno))); + } return jlong(t.tv_sec) * 1000 + jlong(t.tv_usec) / 1000; } @@ -1625,7 +1631,7 @@ return false; } -typedef int (*dladdr1_func_type) (void *, Dl_info *, void **, int); +typedef int (*dladdr1_func_type)(void *, Dl_info *, void **, int); static dladdr1_func_type dladdr1_func = NULL; bool os::dll_address_to_function_name(address addr, char *buf, @@ -1643,9 +1649,9 @@ // available even if the vm is built on a machine that does // not have dladdr1 support. Make sure there is a value for // RTLD_DL_SYMENT. - #ifndef RTLD_DL_SYMENT - #define RTLD_DL_SYMENT 1 - #endif +#ifndef RTLD_DL_SYMENT + #define RTLD_DL_SYMENT 1 +#endif #ifdef _LP64 Elf64_Sym * info; #else @@ -1763,8 +1769,7 @@ // in case of error it checks if .dll/.so was built for the // same architecture as Hotspot is running on -void * os::dll_load(const char *filename, char *ebuf, int ebuflen) -{ +void * os::dll_load(const char *filename, char *ebuf, int ebuflen) { void * result= ::dlopen(filename, RTLD_LAZY); if (result != NULL) { // Successful loading @@ -1824,26 +1829,26 @@ {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"} }; - #if (defined IA32) +#if (defined IA32) static Elf32_Half running_arch_code=EM_386; - #elif (defined AMD64) +#elif (defined AMD64) static Elf32_Half running_arch_code=EM_X86_64; - #elif (defined IA64) +#elif (defined IA64) static Elf32_Half running_arch_code=EM_IA_64; - #elif (defined __sparc) && (defined _LP64) +#elif (defined __sparc) && (defined _LP64) static Elf32_Half running_arch_code=EM_SPARCV9; - #elif (defined __sparc) && (!defined _LP64) +#elif (defined __sparc) && (!defined _LP64) static Elf32_Half running_arch_code=EM_SPARC; - #elif (defined __powerpc64__) +#elif (defined __powerpc64__) static Elf32_Half running_arch_code=EM_PPC64; - #elif (defined __powerpc__) +#elif (defined __powerpc__) static Elf32_Half running_arch_code=EM_PPC; - #elif (defined ARM) +#elif (defined ARM) static Elf32_Half running_arch_code=EM_ARM; - #else - #error Method os::dll_load requires that one of following is defined:\ - IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM - #endif +#else + #error Method os::dll_load requires that one of following is defined:\ + IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM +#endif // Identify compatability class for VM's architecture and library's architecture // Obtain string descriptions for architectures @@ -2219,7 +2224,6 @@ // from src/solaris/hpi/src/system_md.c size_t os::lasterror(char *buf, size_t len) { - if (errno == 0) return 0; const char *s = ::strerror(errno); @@ -2314,9 +2318,10 @@ sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND; sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler); - if (sigaction(signal_number, &sigAct, &oldSigAct)) + if (sigaction(signal_number, &sigAct, &oldSigAct)) { // -1 means registration failed return (void *)-1; + } return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler); } @@ -2325,10 +2330,8 @@ raise(signal_number); } -/* - * The following code is moved from os.cpp for making this - * code platform specific, which it is by its very nature. - */ +// The following code is moved from os.cpp for making this +// code platform specific, which it is by its very nature. // a counter for each possible signal value static int Sigexit = 0; @@ -2366,7 +2369,7 @@ preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1), mtInternal); memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1))); } - ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1 ), mtInternal); + ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1), mtInternal); memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1)); } @@ -2411,12 +2414,10 @@ // were we externally suspended while we were waiting? threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); if (threadIsSuspended) { - // // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. - // ret = ::sema_post(&sig_sem); assert(ret == 0, "sema_post() failed"); @@ -2714,7 +2715,8 @@ // Scan the pages from start to end until a page different than // the one described in the info parameter is encountered. -char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { +char *os::scan_pages(char *start, char* end, page_info* page_expected, + page_info* page_found) { const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE }; const size_t types = sizeof(info_types) / sizeof(info_types[0]); uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT + 1]; @@ -2741,8 +2743,7 @@ if (outdata[types * i + 1] != page_expected->size) { break; } - } else - if (page_expected->size != 0) { + } else if (page_expected->size != 0) { break; } @@ -2795,11 +2796,13 @@ return b; } -char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed) { +char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, + size_t alignment_hint, bool fixed) { char* addr = requested_addr; int flags = MAP_PRIVATE | MAP_NORESERVE; - assert(!(fixed && (alignment_hint > 0)), "alignment hint meaningless with fixed mmap"); + assert(!(fixed && (alignment_hint > 0)), + "alignment hint meaningless with fixed mmap"); if (fixed) { flags |= MAP_FIXED; @@ -2814,8 +2817,10 @@ return mmap_chunk(addr, bytes, flags, PROT_NONE); } -char* os::pd_reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) { - char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL)); +char* os::pd_reserve_memory(size_t bytes, char* requested_addr, + size_t alignment_hint) { + char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, + (requested_addr != NULL)); guarantee(requested_addr == NULL || requested_addr == addr, "OS failed to return requested mmap address."); @@ -3080,7 +3085,8 @@ } } -bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes, size_t align) { +bool os::Solaris::setup_large_pages(caddr_t start, size_t bytes, + size_t align) { // Signal to OS that we want large pages for addresses // from addr, addr + bytes struct memcntl_mha mpss_struct; @@ -3095,7 +3101,8 @@ return true; } -char* os::reserve_memory_special(size_t size, size_t alignment, char* addr, bool exec) { +char* os::reserve_memory_special(size_t size, size_t alignment, char* addr, + bool exec) { fatal("os::reserve_memory_special should not be called on Solaris."); return NULL; } @@ -3160,14 +3167,14 @@ static hrtime_t last_time = 0; hrtime_t diff = getTimeNanos() - last_time; - if (diff < DontYieldALotInterval * 1000000) + if (diff < DontYieldALotInterval * 1000000) { return true; + } last_time += diff; return false; - } - else { + } else { return false; } } @@ -3362,8 +3369,10 @@ myMax = MIN2(myMax, (int)fxInfo->fx_uprilim); // clamp - restrict } else { // No clue - punt - if (ThreadPriorityVerbose) - tty->print_cr("Unknown scheduling class: %s ... \n", ClassInfo.pc_clname); + if (ThreadPriorityVerbose) { + tty->print_cr("Unknown scheduling class: %s ... \n", + ClassInfo.pc_clname); + } return EINVAL; // no clue, punt } @@ -3386,9 +3395,7 @@ // Convert from the libthread "thr_setprio" scale to our current // lwp scheduling class scale. // -static -int scale_to_lwp_priority (int rMin, int rMax, int x) -{ +static int scale_to_lwp_priority(int rMin, int rMax, int x) { int v; if (x == 127) return rMax; // avoid round-down @@ -3415,8 +3422,9 @@ // If something went wrong on init, don't change priorities. if (!priocntl_enable) { - if (ThreadPriorityVerbose) + if (ThreadPriorityVerbose) { tty->print_cr("Trying to set priority but init failed, ignoring"); + } return EINVAL; } @@ -3578,7 +3586,6 @@ // Maximum priority an so on. This will cause VM threads // to get unfair treatment against other Solaris processes // which do not explicitly alter their thread priorities. -// int os::java_to_os_priority[CriticalPriority + 1] = { -99999, // 0 Entry should never be used @@ -3641,7 +3648,8 @@ } -OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) { +OSReturn os::get_native_priority(const Thread* const thread, + int *priority_ptr) { int p; if (!UseThreadPriorities) { *priority_ptr = NormalPriority; @@ -3870,7 +3878,9 @@ // This does not do anything on Solaris. This is basically a hook for being // able to use structured exception handling (thread-local exception filters) on, e.g., Win32. -void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) { +void os::os_exception_wrapper(java_call_t f, JavaValue* value, + methodHandle* method, JavaCallArguments* args, + Thread* thread) { f(value, method, args, thread); } @@ -3901,9 +3911,10 @@ // Note that the VM will print warnings if it detects conflicting signal // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". // -extern "C" JNIEXPORT int -JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, - int abort_if_unrecognized); +extern "C" JNIEXPORT int JVM_handle_solaris_signal(int signo, + siginfo_t* siginfo, + void* ucontext, + int abort_if_unrecognized); void signalHandler(int sig, siginfo_t* info, void* ucVoid) { @@ -3912,11 +3923,11 @@ errno = orig_errno; } -/* Do not delete - if guarantee is ever removed, a signal handler (even empty) - is needed to provoke threads blocked on IO to return an EINTR - Note: this explicitly does NOT call JVM_handle_solaris_signal and - does NOT participate in signal chaining due to requirement for - NOT setting SA_RESTART to make EINTR work. */ +// Do not delete - if guarantee is ever removed, a signal handler (even empty) +// is needed to provoke threads blocked on IO to return an EINTR +// Note: this explicitly does NOT call JVM_handle_solaris_signal and +// does NOT participate in signal chaining due to requirement for +// NOT setting SA_RESTART to make EINTR work. extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) { if (UseSignalChaining) { struct sigaction *actp = os::Solaris::get_chained_signal_action(sig); @@ -4008,27 +4019,31 @@ } struct sigaction* os::Solaris::get_preinstalled_handler(int sig) { - assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); + assert((chainedsigactions != (struct sigaction *)NULL) && + (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); if (preinstalled_sigs[sig] != 0) { return &chainedsigactions[sig]; } return NULL; } -void os::Solaris::save_preinstalled_handler(int sig, struct sigaction& oldAct) { - +void os::Solaris::save_preinstalled_handler(int sig, + struct sigaction& oldAct) { assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); - assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); + assert((chainedsigactions != (struct sigaction *)NULL) && + (preinstalled_sigs != (int *)NULL), "signals not yet initialized"); chainedsigactions[sig] = oldAct; preinstalled_sigs[sig] = 1; } -void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) { +void os::Solaris::set_signal_handler(int sig, bool set_installed, + bool oktochain) { // Check for overwrite. struct sigaction oldAct; sigaction(sig, (struct sigaction*)NULL, &oldAct); - void* oldhand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) - : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); + void* oldhand = + oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) + : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) && oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) && oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) { @@ -4059,9 +4074,9 @@ // not using stack banging if (!UseStackBanging && sig == SIGSEGV) { sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; + } else if (sig == os::Solaris::SIGinterrupt()) { // Interruptible i/o requires SA_RESTART cleared so EINTR // is returned instead of restarting system calls - } else if (sig == os::Solaris::SIGinterrupt()) { sigemptyset(&sigAct.sa_mask); sigAct.sa_handler = NULL; sigAct.sa_flags = SA_SIGINFO; @@ -4079,9 +4094,12 @@ } -#define DO_SIGNAL_CHECK(sig) \ - if (!sigismember(&check_signal_done, sig)) \ - os::Solaris::check_signal_handler(sig) +#define DO_SIGNAL_CHECK(sig) \ + do { \ + if (!sigismember(&check_signal_done, sig)) { \ + os::Solaris::check_signal_handler(sig); \ + } \ + } while (0) // This method is a periodic task to check for misbehaving JNI applications // under CheckJNI, we can add any periodic checks here @@ -4275,7 +4293,8 @@ } -void report_error(const char* file_name, int line_no, const char* title, const char* format, ...); +void report_error(const char* file_name, int line_no, const char* title, + const char* format, ...); const char * signames[] = { "SIG0", @@ -4389,8 +4408,7 @@ os::Solaris::set_cond_init(lwp_cond_init); os::Solaris::set_cond_destroy(lwp_cond_destroy); os::Solaris::set_cond_scope(USYNC_THREAD); - } - else { + } else { os::Solaris::set_mutex_scope(USYNC_THREAD); os::Solaris::set_cond_scope(USYNC_THREAD); @@ -4407,8 +4425,7 @@ os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast"))); os::Solaris::set_cond_init(pthread_cond_default_init); os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy"))); - } - else { + } else { os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock"))); os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock"))); os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock"))); @@ -4489,9 +4506,10 @@ init_random(1234567); page_size = sysconf(_SC_PAGESIZE); - if (page_size == -1) + if (page_size == -1) { fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)", strerror(errno))); + } init_page_sizes((size_t) page_size); Solaris::initialize_system_info(); @@ -4517,8 +4535,9 @@ // and is available on linker patches for 5.7 and 5.8. // libdl.so must have been loaded, this call is just an entry lookup void * hdl = dlopen("libdl.so", RTLD_NOW); - if (hdl) + if (hdl) { dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1")); + } // (Solaris only) this switches to calls that actually do locking. ThreadCritical::initialize(); @@ -4566,8 +4585,10 @@ os::set_polling_page(polling_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", + (intptr_t)polling_page); + } #endif if (!UseMembar) { @@ -4576,8 +4597,10 @@ os::set_memory_serialize_page(mem_serialize_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", + (intptr_t)mem_serialize_page); + } #endif } @@ -4656,14 +4679,16 @@ struct rlimit nbr_files; int status = getrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 getrlimit failed"); + } } else { nbr_files.rlim_cur = nbr_files.rlim_max; status = setrlimit(RLIMIT_NOFILE, &nbr_files); if (status != 0) { - if (PrintMiscellaneous && (Verbose || WizardMode)) + if (PrintMiscellaneous && (Verbose || WizardMode)) { perror("os::init_2 setrlimit failed"); + } } } } @@ -4715,15 +4740,17 @@ // Mark the polling page as unreadable void os::make_polling_page_unreadable(void) { - if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) + if (mprotect((char *)_polling_page, page_size, PROT_NONE) != 0) { fatal("Could not disable polling page"); -}; + } +} // Mark the polling page as readable void os::make_polling_page_readable(void) { - if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) + if (mprotect((char *)_polling_page, page_size, PROT_READ) != 0) { fatal("Could not enable polling page"); -}; + } +} // OS interface. @@ -4736,13 +4763,15 @@ if (!sol_vsnprintf) { //search for the named symbol in the objects that were loaded after libjvm void* where = RTLD_NEXT; - if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) + if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) { sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); + } if (!sol_vsnprintf){ //search for the named symbol in the objects that were loaded before libjvm where = RTLD_DEFAULT; - if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) + if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) { sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); + } assert(sol_vsnprintf != NULL, "vsnprintf not found"); } } @@ -4758,7 +4787,7 @@ dir = opendir(path); if (dir == NULL) return true; - /* Scan the directory */ + // Scan the directory bool result = true; char buf[sizeof(struct dirent) + MAX_PATH]; struct dirent *dbuf = (struct dirent *) buf; @@ -4775,7 +4804,7 @@ // from src/solaris/hpi/src/system_md.c #ifndef O_DELETE -#define O_DELETE 0x10000 + #define O_DELETE 0x10000 #endif // Open a file. Unlink the file immediately after open returns @@ -4794,7 +4823,7 @@ fd = ::open64(path, oflag, mode); if (fd == -1) return -1; - //If the open succeeded, the file might still be a directory + // If the open succeeded, the file might still be a directory { struct stat64 buf64; int ret = ::fstat64(fd, &buf64); @@ -4811,40 +4840,40 @@ return -1; } } - /* - * 32-bit Solaris systems suffer from: - * - * - an historical default soft limit of 256 per-process file - * descriptors that is too low for many Java programs. - * - * - a design flaw where file descriptors created using stdio - * fopen must be less than 256, _even_ when the first limit above - * has been raised. This can cause calls to fopen (but not calls to - * open, for example) to fail mysteriously, perhaps in 3rd party - * native code (although the JDK itself uses fopen). One can hardly - * criticize them for using this most standard of all functions. - * - * We attempt to make everything work anyways by: - * - * - raising the soft limit on per-process file descriptors beyond - * 256 - * - * - As of Solaris 10u4, we can request that Solaris raise the 256 - * stdio fopen limit by calling function enable_extended_FILE_stdio. - * This is done in init_2 and recorded in enabled_extended_FILE_stdio - * - * - If we are stuck on an old (pre 10u4) Solaris system, we can - * workaround the bug by remapping non-stdio file descriptors below - * 256 to ones beyond 256, which is done below. - * - * See: - * 1085341: 32-bit stdio routines should support file descriptors >255 - * 6533291: Work around 32-bit Solaris stdio limit of 256 open files - * 6431278: Netbeans crash on 32 bit Solaris: need to call - * enable_extended_FILE_stdio() in VM initialisation - * Giri Mandalika's blog - * http://technopark02.blogspot.com/2005_05_01_archive.html - */ + + // 32-bit Solaris systems suffer from: + // + // - an historical default soft limit of 256 per-process file + // descriptors that is too low for many Java programs. + // + // - a design flaw where file descriptors created using stdio + // fopen must be less than 256, _even_ when the first limit above + // has been raised. This can cause calls to fopen (but not calls to + // open, for example) to fail mysteriously, perhaps in 3rd party + // native code (although the JDK itself uses fopen). One can hardly + // criticize them for using this most standard of all functions. + // + // We attempt to make everything work anyways by: + // + // - raising the soft limit on per-process file descriptors beyond + // 256 + // + // - As of Solaris 10u4, we can request that Solaris raise the 256 + // stdio fopen limit by calling function enable_extended_FILE_stdio. + // This is done in init_2 and recorded in enabled_extended_FILE_stdio + // + // - If we are stuck on an old (pre 10u4) Solaris system, we can + // workaround the bug by remapping non-stdio file descriptors below + // 256 to ones beyond 256, which is done below. + // + // See: + // 1085341: 32-bit stdio routines should support file descriptors >255 + // 6533291: Work around 32-bit Solaris stdio limit of 256 open files + // 6431278: Netbeans crash on 32 bit Solaris: need to call + // enable_extended_FILE_stdio() in VM initialisation + // Giri Mandalika's blog + // http://technopark02.blogspot.com/2005_05_01_archive.html + // #ifndef _LP64 if ((!enabled_extended_FILE_stdio) && fd < 256) { int newfd = ::fcntl(fd, F_DUPFD, 256); @@ -4854,33 +4883,34 @@ } } #endif // 32-bit Solaris - /* - * All file descriptors that are opened in the JVM and not - * specifically destined for a subprocess should have the - * close-on-exec flag set. If we don't set it, then careless 3rd - * party native code might fork and exec without closing all - * appropriate file descriptors (e.g. as we do in closeDescriptors in - * UNIXProcess.c), and this in turn might: - * - * - cause end-of-file to fail to be detected on some file - * descriptors, resulting in mysterious hangs, or - * - * - might cause an fopen in the subprocess to fail on a system - * suffering from bug 1085341. - * - * (Yes, the default setting of the close-on-exec flag is a Unix - * design flaw) - * - * See: - * 1085341: 32-bit stdio routines should support file descriptors >255 - * 4843136: (process) pipe file descriptor from Runtime.exec not being closed - * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 - */ + + // All file descriptors that are opened in the JVM and not + // specifically destined for a subprocess should have the + // close-on-exec flag set. If we don't set it, then careless 3rd + // party native code might fork and exec without closing all + // appropriate file descriptors (e.g. as we do in closeDescriptors in + // UNIXProcess.c), and this in turn might: + // + // - cause end-of-file to fail to be detected on some file + // descriptors, resulting in mysterious hangs, or + // + // - might cause an fopen in the subprocess to fail on a system + // suffering from bug 1085341. + // + // (Yes, the default setting of the close-on-exec flag is a Unix + // design flaw) + // + // See: + // 1085341: 32-bit stdio routines should support file descriptors >255 + // 4843136: (process) pipe file descriptor from Runtime.exec not being closed + // 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 + // #ifdef FD_CLOEXEC { int flags = ::fcntl(fd, F_GETFD); - if (flags != -1) + if (flags != -1) { ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } } #endif @@ -5035,9 +5065,8 @@ class RecordSynch { char* _name; public: - RecordSynch(char* name) :_name(name) - { record_synch(_name, false); } - ~RecordSynch() { record_synch(_name, true); } + RecordSynch(char* name) :_name(name) { record_synch(_name, false); } + ~RecordSynch() { record_synch(_name, true); } }; #define CHECK_SYNCH_OP(ret, name, params, args, inner) \ @@ -5067,7 +5096,7 @@ if (!CHECK_POINTER_OK(p)) fatal(false, "Pointer must be in C heap only."); #define CHECK_MUTEX(mutex_op) \ -CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU); + CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU); CHECK_MUTEX( mutex_lock) CHECK_MUTEX( _mutex_lock) @@ -5077,14 +5106,14 @@ CHECK_MUTEX(_mutex_trylock) #define CHECK_COND(cond_op) \ -CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU;CHECK_CV); + CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU; CHECK_CV); CHECK_COND( cond_wait); CHECK_COND(_cond_wait); CHECK_COND(_cond_wait_cancel); #define CHECK_COND2(cond_op) \ -CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU;CHECK_CV); + CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU; CHECK_CV); CHECK_COND2( cond_timedwait); CHECK_COND2(_cond_timedwait); @@ -5275,10 +5304,11 @@ st->print(PTR_FORMAT ": ", addr); if (dlinfo.dli_sname != NULL && dlinfo.dli_saddr != NULL) { st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr); - } else if (dlinfo.dli_fbase != NULL) + } else if (dlinfo.dli_fbase != NULL) { st->print("", addr-(intptr_t)dlinfo.dli_fbase); - else + } else { st->print(""); + } if (dlinfo.dli_fname != NULL) { st->print(" in %s", dlinfo.dli_fname); } @@ -5296,8 +5326,9 @@ if (begin < lowest) begin = lowest; Dl_info dlinfo2; if (dladdr(end, &dlinfo2) != 0 && dlinfo2.dli_saddr != dlinfo.dli_saddr - && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) + && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) { end = (address) dlinfo2.dli_saddr; + } Disassembler::decode(begin, end, st); } return true; @@ -5554,36 +5585,34 @@ // JSR166 // ------------------------------------------------------- -/* - * The solaris and linux implementations of park/unpark are fairly - * conservative for now, but can be improved. They currently use a - * mutex/condvar pair, plus _counter. - * Park decrements _counter if > 0, else does a condvar wait. Unpark - * sets count to 1 and signals condvar. Only one thread ever waits - * on the condvar. Contention seen when trying to park implies that someone - * is unparking you, so don't wait. And spurious returns are fine, so there - * is no need to track notifications. - */ +// The solaris and linux implementations of park/unpark are fairly +// conservative for now, but can be improved. They currently use a +// mutex/condvar pair, plus _counter. +// Park decrements _counter if > 0, else does a condvar wait. Unpark +// sets count to 1 and signals condvar. Only one thread ever waits +// on the condvar. Contention seen when trying to park implies that someone +// is unparking you, so don't wait. And spurious returns are fine, so there +// is no need to track notifications. #define MAX_SECS 100000000 -/* - * This code is common to linux and solaris and will be moved to a - * common place in dolphin. - * - * The passed in time value is either a relative time in nanoseconds - * or an absolute time in milliseconds. Either way it has to be unpacked - * into suitable seconds and nanoseconds components and stored in the - * given timespec structure. - * Given time is a 64-bit value and the time_t used in the timespec is only - * a signed-32-bit value (except on 64-bit Linux) we have to watch for - * overflow if times way in the future are given. Further on Solaris versions - * prior to 10 there is a restriction (see cond_timedwait) that the specified - * number of seconds, in abstime, is less than current_time + 100,000,000. - * As it will be 28 years before "now + 100000000" will overflow we can - * ignore overflow and just impose a hard-limit on seconds using the value - * of "now + 100,000,000". This places a limit on the timeout of about 3.17 - * years from "now". - */ + +// This code is common to linux and solaris and will be moved to a +// common place in dolphin. +// +// The passed in time value is either a relative time in nanoseconds +// or an absolute time in milliseconds. Either way it has to be unpacked +// into suitable seconds and nanoseconds components and stored in the +// given timespec structure. +// Given time is a 64-bit value and the time_t used in the timespec is only +// a signed-32-bit value (except on 64-bit Linux) we have to watch for +// overflow if times way in the future are given. Further on Solaris versions +// prior to 10 there is a restriction (see cond_timedwait) that the specified +// number of seconds, in abstime, is less than current_time + 100,000,000. +// As it will be 28 years before "now + 100000000" will overflow we can +// ignore overflow and just impose a hard-limit on seconds using the value +// of "now + 100,000,000". This places a limit on the timeout of about 3.17 +// years from "now". +// static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { assert(time > 0, "convertTime"); @@ -5597,19 +5626,16 @@ jlong secs = time / 1000; if (secs > max_secs) { absTime->tv_sec = max_secs; - } - else { + } else { absTime->tv_sec = secs; } absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; - } - else { + } else { jlong secs = time / NANOSECS_PER_SEC; if (secs >= MAX_SECS) { absTime->tv_sec = max_secs; absTime->tv_nsec = 0; - } - else { + } else { absTime->tv_sec = now.tv_sec + secs; absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; if (absTime->tv_nsec >= NANOSECS_PER_SEC) { @@ -5831,13 +5857,19 @@ // Get rid of libjvm.so p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // Get rid of client or server p = strrchr(buf, '/'); - if (p == NULL) return false; - else *p = '\0'; + if (p == NULL) { + return false; + } else { + *p = '\0'; + } // check xawt/libmawt.so strcpy(libmawtpath, buf); @@ -5911,8 +5943,9 @@ gettimeofday(&t, &aNull); newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000; timeout -= newtime - prevtime; - if (timeout <= 0) + if (timeout <= 0) { return OS_OK; + } prevtime = newtime; } } else return res; @@ -5943,12 +5976,12 @@ // // EISCONN The socket is already connected. if (_result == OS_ERR && errno == EINTR) { - /* restarting a connect() changes its errno semantics */ + // restarting a connect() changes its errno semantics RESTARTABLE(::connect(fd, him, len), _result); - /* undo these changes */ + // undo these changes if (_result == OS_ERR) { if (errno == EALREADY) { - errno = EINPROGRESS; /* fall through */ + errno = EINPROGRESS; // fall through } else if (errno == EISCONN) { errno = 0; return OS_OK; diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/solaris/vm/os_solaris.hpp --- a/hotspot/src/os/solaris/vm/os_solaris.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/solaris/vm/os_solaris.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -36,10 +36,10 @@ private: // Support for "new" libthread APIs for getting & setting thread context (2.8) - #define TRS_VALID 0 - #define TRS_NONVOLATILE 1 - #define TRS_LWPID 2 - #define TRS_INVALID 3 +#define TRS_VALID 0 +#define TRS_NONVOLATILE 1 +#define TRS_LWPID 2 +#define TRS_INVALID 3 // initialized to libthread or lwp synchronization primitives depending on UseLWPSychronization static int_fnP_mutex_tP _mutex_lock; @@ -61,8 +61,8 @@ typedef id_t lgrp_id_t; typedef int lgrp_rsrc_t; typedef enum lgrp_view { - LGRP_VIEW_CALLER, /* what's available to the caller */ - LGRP_VIEW_OS /* what's available to operating system */ + LGRP_VIEW_CALLER, // what's available to the caller + LGRP_VIEW_OS // what's available to operating system } lgrp_view_t; typedef uint_t (*getisax_func_t)(uint32_t* array, uint_t n); @@ -216,8 +216,7 @@ static void set_mutex_destroy(int_fnP_mutex_tP func) { _mutex_destroy = func; } static void set_mutex_scope(int scope) { _mutex_scope = scope; } - static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst) - { return _cond_timedwait(cv, mx, abst); } + static int cond_timedwait(cond_t *cv, mutex_t *mx, timestruc_t *abst) { return _cond_timedwait(cv, mx, abst); } static int cond_wait(cond_t *cv, mutex_t *mx) { return _cond_wait(cv, mx); } static int cond_signal(cond_t *cv) { return _cond_signal(cv); } static int cond_broadcast(cond_t *cv) { return _cond_broadcast(cv); } @@ -225,8 +224,7 @@ static int cond_destroy(cond_t *cv) { return _cond_destroy(cv); } static int cond_scope() { return _cond_scope; } - static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func) - { _cond_timedwait = func; } + static void set_cond_timedwait(int_fnP_cond_tP_mutex_tP_timestruc_tP func) { _cond_timedwait = func; } static void set_cond_wait(int_fnP_cond_tP_mutex_tP func) { _cond_wait = func; } static void set_cond_signal(int_fnP_cond_tP func) { _cond_signal = func; } static void set_cond_broadcast(int_fnP_cond_tP func) { _cond_broadcast = func; } @@ -247,7 +245,7 @@ static id_t lgrp_home(idtype_t type, id_t id) { return _lgrp_home != NULL ? _lgrp_home(type, id) : -1; } static lgrp_cookie_t lgrp_init(lgrp_view_t view) { return _lgrp_init != NULL ? _lgrp_init(view) : 0; } static int lgrp_fini(lgrp_cookie_t cookie) { return _lgrp_fini != NULL ? _lgrp_fini(cookie) : -1; } - static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; }; + static lgrp_id_t lgrp_root(lgrp_cookie_t cookie) { return _lgrp_root != NULL ? _lgrp_root(cookie) : -1; } static int lgrp_children(lgrp_cookie_t cookie, lgrp_id_t parent, lgrp_id_t *lgrp_array, uint_t lgrp_array_size) { return _lgrp_children != NULL ? _lgrp_children(cookie, parent, lgrp_array, lgrp_array_size) : -1; diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/os/windows/vm/os_windows.cpp --- a/hotspot/src/os/windows/vm/os_windows.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/os/windows/vm/os_windows.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -92,7 +92,7 @@ #include #include // For _beginthreadex(), _endthreadex() #include // For os::dll_address_to_function_name -/* for enumerating dll libraries */ +// for enumerating dll libraries #include // for timer info max values which include all bits @@ -113,11 +113,11 @@ static FILETIME process_kernel_time; #ifdef _M_IA64 -#define __CPU__ ia64 + #define __CPU__ ia64 #elif _M_AMD64 -#define __CPU__ amd64 + #define __CPU__ amd64 #else -#define __CPU__ i486 + #define __CPU__ i486 #endif // save DLL module handle, used by GetModuleFileName @@ -128,13 +128,14 @@ switch (reason) { case DLL_PROCESS_ATTACH: vm_lib_handle = hinst; - if (ForceTimeHighResolution) + if (ForceTimeHighResolution) { timeBeginPeriod(1L); + } break; case DLL_PROCESS_DETACH: - if (ForceTimeHighResolution) + if (ForceTimeHighResolution) { timeEndPeriod(1L); - + } break; default: break; @@ -179,8 +180,9 @@ static LPTOP_LEVEL_EXCEPTION_FILTER prev_uef_handler = NULL; LONG WINAPI Handle_FLT_Exception(struct _EXCEPTION_POINTERS* exceptionInfo); + void os::init_system_properties_values() { - /* sysclasspath, java_home, dll_dir */ + // sysclasspath, java_home, dll_dir { char *home_path; char *dll_path; @@ -192,47 +194,51 @@ os::jvm_path(home_dir, sizeof(home_dir)); // Found the full path to jvm.dll. // Now cut the path to /jre if we can. - *(strrchr(home_dir, '\\')) = '\0'; /* get rid of \jvm.dll */ + *(strrchr(home_dir, '\\')) = '\0'; // get rid of \jvm.dll pslash = strrchr(home_dir, '\\'); if (pslash != NULL) { - *pslash = '\0'; /* get rid of \{client|server} */ + *pslash = '\0'; // get rid of \{client|server} pslash = strrchr(home_dir, '\\'); - if (pslash != NULL) - *pslash = '\0'; /* get rid of \bin */ + if (pslash != NULL) { + *pslash = '\0'; // get rid of \bin + } } } home_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + 1, mtInternal); - if (home_path == NULL) + if (home_path == NULL) { return; + } strcpy(home_path, home_dir); Arguments::set_java_home(home_path); - dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1, mtInternal); - if (dll_path == NULL) + dll_path = NEW_C_HEAP_ARRAY(char, strlen(home_dir) + strlen(bin) + 1, + mtInternal); + if (dll_path == NULL) { return; + } strcpy(dll_path, home_dir); strcat(dll_path, bin); Arguments::set_dll_dir(dll_path); - if (!set_boot_path('\\', ';')) + if (!set_boot_path('\\', ';')) { return; - } - - /* library_path */ - #define EXT_DIR "\\lib\\ext" - #define BIN_DIR "\\bin" - #define PACKAGE_DIR "\\Sun\\Java" + } + } + +// library_path +#define EXT_DIR "\\lib\\ext" +#define BIN_DIR "\\bin" +#define PACKAGE_DIR "\\Sun\\Java" { - /* Win32 library search order (See the documentation for LoadLibrary): - * - * 1. The directory from which application is loaded. - * 2. The system wide Java Extensions directory (Java only) - * 3. System directory (GetSystemDirectory) - * 4. Windows directory (GetWindowsDirectory) - * 5. The PATH environment variable - * 6. The current directory - */ + // Win32 library search order (See the documentation for LoadLibrary): + // + // 1. The directory from which application is loaded. + // 2. The system wide Java Extensions directory (Java only) + // 3. System directory (GetSystemDirectory) + // 4. Windows directory (GetWindowsDirectory) + // 5. The PATH environment variable + // 6. The current directory char *library_path; char tmp[MAX_PATH]; @@ -271,7 +277,7 @@ FREE_C_HEAP_ARRAY(char, library_path, mtInternal); } - /* Default extensions directory */ + // Default extensions directory { char path[MAX_PATH]; char buf[2 * MAX_PATH + 2 * sizeof(EXT_DIR) + sizeof(PACKAGE_DIR) + 1]; @@ -284,14 +290,14 @@ #undef BIN_DIR #undef PACKAGE_DIR - /* Default endorsed standards directory. */ + // Default endorsed standards directory. { - #define ENDORSED_DIR "\\lib\\endorsed" +#define ENDORSED_DIR "\\lib\\endorsed" size_t len = strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR); char * buf = NEW_C_HEAP_ARRAY(char, len, mtInternal); sprintf(buf, "%s%s", Arguments::get_java_home(), ENDORSED_DIR); Arguments::set_endorsed_dirs(buf); - #undef ENDORSED_DIR +#undef ENDORSED_DIR } #ifndef _WIN64 @@ -312,14 +318,13 @@ os::breakpoint(); } -/* - * RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP. - * So far, this method is only used by Native Memory Tracking, which is - * only supported on Windows XP or later. - */ +// RtlCaptureStackBackTrace Windows API may not exist prior to Windows XP. +// So far, this method is only used by Native Memory Tracking, which is +// only supported on Windows XP or later. +// int os::get_native_stack(address* stack, int frames, int toSkip) { #ifdef _NMT_NOINLINE_ - toSkip ++; + toSkip++; #endif int captured = Kernel32Dll::RtlCaptureStackBackTrace(toSkip + 1, frames, (PVOID*)stack, NULL); @@ -347,13 +352,13 @@ // Add up the sizes of all the regions with the same // AllocationBase. - while (1) - { + while (1) { VirtualQuery(stack_bottom+stack_size, &minfo, sizeof(minfo)); - if (stack_bottom == (address)minfo.AllocationBase) + if (stack_bottom == (address)minfo.AllocationBase) { stack_size += minfo.RegionSize; - else + } else { break; + } } #ifdef _M_IA64 @@ -466,7 +471,8 @@ return 0; } -static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, int thread_id) { +static OSThread* create_os_thread(Thread* thread, HANDLE thread_handle, + int thread_id) { // Allocate the OSThread object OSThread* osthread = new OSThread(NULL, NULL); if (osthread == NULL) return NULL; @@ -538,7 +544,8 @@ } // Allocate and initialize a new OSThread -bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { +bool os::create_thread(Thread* thread, ThreadType thr_type, + size_t stack_size) { unsigned thread_id; // Allocate the OSThread object @@ -562,8 +569,9 @@ switch (thr_type) { case os::java_thread: // Java threads use ThreadStackSize which default value can be changed with the flag -Xss - if (JavaThread::stack_size_at_create() > 0) + if (JavaThread::stack_size_at_create() > 0) { stack_size = JavaThread::stack_size_at_create(); + } break; case os::compiler_thread: if (CompilerThreadStackSize > 0) { @@ -602,7 +610,7 @@ // flag appears to work with _beginthredex() as well. #ifndef STACK_SIZE_PARAM_IS_A_RESERVATION -#define STACK_SIZE_PARAM_IS_A_RESERVATION (0x10000) + #define STACK_SIZE_PARAM_IS_A_RESERVATION (0x10000) #endif HANDLE thread_handle = @@ -941,7 +949,6 @@ } void os::shutdown() { - // allow PerfMemory to attempt cleanup of any persistent resources perfMemory_exit(); @@ -956,8 +963,10 @@ } -static BOOL (WINAPI *_MiniDumpWriteDump) ( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, - PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION); +static BOOL (WINAPI *_MiniDumpWriteDump)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, + PMINIDUMP_EXCEPTION_INFORMATION, + PMINIDUMP_USER_STREAM_INFORMATION, + PMINIDUMP_CALLBACK_INFORMATION); void os::check_or_create_dump(void* exceptionRecord, void* contextRecord, char* buffer, size_t bufferSize) { HINSTANCE dbghelp; @@ -996,10 +1005,13 @@ return; } - _MiniDumpWriteDump = CAST_TO_FN_PTR( - BOOL(WINAPI *)( HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, PMINIDUMP_EXCEPTION_INFORMATION, - PMINIDUMP_USER_STREAM_INFORMATION, PMINIDUMP_CALLBACK_INFORMATION), - GetProcAddress(dbghelp, "MiniDumpWriteDump")); + _MiniDumpWriteDump = + CAST_TO_FN_PTR(BOOL(WINAPI *)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE, + PMINIDUMP_EXCEPTION_INFORMATION, + PMINIDUMP_USER_STREAM_INFORMATION, + PMINIDUMP_CALLBACK_INFORMATION), + GetProcAddress(dbghelp, + "MiniDumpWriteDump")); if (_MiniDumpWriteDump == NULL) { VMError::report_coredump_status("Failed to find MiniDumpWriteDump() in module dbghelp.dll", false); @@ -1063,8 +1075,7 @@ -void os::abort(bool dump_core) -{ +void os::abort(bool dump_core) { os::shutdown(); // no core dump on Windows ::exit(1); @@ -1080,12 +1091,10 @@ // // The declarations for DIR and struct dirent are in jvm_win32.h. -/* Caller must have already run dirname through JVM_NativePath, which removes - duplicate slashes and converts all instances of '/' into '\\'. */ - -DIR * -os::opendir(const char *dirname) -{ +// Caller must have already run dirname through JVM_NativePath, which removes +// duplicate slashes and converts all instances of '/' into '\\'. + +DIR * os::opendir(const char *dirname) { assert(dirname != NULL, "just checking"); // hotspot change DIR *dirp = (DIR *)malloc(sizeof(DIR), mtInternal); DWORD fattr; // hotspot change @@ -1096,11 +1105,10 @@ return 0; } - /* - * Win32 accepts "\" in its POSIX stat(), but refuses to treat it - * as a directory in FindFirstFile(). We detect this case here and - * prepend the current drive name. - */ + // Win32 accepts "\" in its POSIX stat(), but refuses to treat it + // as a directory in FindFirstFile(). We detect this case here and + // prepend the current drive name. + // if (dirname[1] == '\0' && dirname[0] == '\\') { alt_dirname[0] = _getdrive() + 'A' - 1; alt_dirname[1] = ':'; @@ -1130,11 +1138,11 @@ return 0; } - /* Append "*.*", or possibly "\\*.*", to path */ - if (dirp->path[1] == ':' - && (dirp->path[2] == '\0' - || (dirp->path[2] == '\\' && dirp->path[3] == '\0'))) { - /* No '\\' needed for cases like "Z:" or "Z:\" */ + // Append "*.*", or possibly "\\*.*", to path + if (dirp->path[1] == ':' && + (dirp->path[2] == '\0' || + (dirp->path[2] == '\\' && dirp->path[3] == '\0'))) { + // No '\\' needed for cases like "Z:" or "Z:\" strcat(dirp->path, "*.*"); } else { strcat(dirp->path, "\\*.*"); @@ -1152,11 +1160,8 @@ return dirp; } -/* parameter dbuf unused on Windows */ - -struct dirent * -os::readdir(DIR *dirp, dirent *dbuf) -{ +// parameter dbuf unused on Windows +struct dirent * os::readdir(DIR *dirp, dirent *dbuf) { assert(dirp != NULL, "just checking"); // hotspot change if (dirp->handle == INVALID_HANDLE_VALUE) { return 0; @@ -1176,9 +1181,7 @@ return &dirp->dirent; } -int -os::closedir(DIR *dirp) -{ +int os::closedir(DIR *dirp) { assert(dirp != NULL, "just checking"); // hotspot change if (dirp->handle != INVALID_HANDLE_VALUE) { if (!FindClose(dirp->handle)) { @@ -1196,10 +1199,10 @@ // directory not the java application's temp directory, ala java.io.tmpdir. const char* os::get_temp_directory() { static char path_buf[MAX_PATH]; - if (GetTempPath(MAX_PATH, path_buf)>0) + if (GetTempPath(MAX_PATH, path_buf) > 0) { return path_buf; - else{ - path_buf[0]='\0'; + } else { + path_buf[0] = '\0'; return path_buf; } } @@ -1282,22 +1285,23 @@ // Helper routine which returns true if address in // within the NTDLL address space. // -static bool _addr_in_ntdll( address addr ) -{ +static bool _addr_in_ntdll(address addr) { HMODULE hmod; MODULEINFO minfo; hmod = GetModuleHandle("NTDLL.DLL"); if (hmod == NULL) return false; - if (!os::PSApiDll::GetModuleInformation( GetCurrentProcess(), hmod, - &minfo, sizeof(MODULEINFO)) ) + if (!os::PSApiDll::GetModuleInformation(GetCurrentProcess(), hmod, + &minfo, sizeof(MODULEINFO))) { return false; + } if ((addr >= minfo.lpBaseOfDll) && - (addr < (address)((uintptr_t)minfo.lpBaseOfDll + (uintptr_t)minfo.SizeOfImage))) + (addr < (address)((uintptr_t)minfo.lpBaseOfDll + (uintptr_t)minfo.SizeOfImage))) { return true; - else + } else { return false; + } } #endif @@ -1319,11 +1323,11 @@ typedef int (*EnumModulesCallbackFunc)(int, char *, address, unsigned, void *); // enumerate_modules for Windows NT, using PSAPI -static int _enumerate_modules_winnt( int pid, EnumModulesCallbackFunc func, void * param) -{ +static int _enumerate_modules_winnt(int pid, EnumModulesCallbackFunc func, + void * param) { HANDLE hProcess; -# define MAX_NUM_MODULES 128 +#define MAX_NUM_MODULES 128 HMODULE modules[MAX_NUM_MODULES]; static char filename[MAX_PATH]; int result = 0; @@ -1372,8 +1376,8 @@ // enumerate_modules for Windows 95/98/ME, using TOOLHELP -static int _enumerate_modules_windows( int pid, EnumModulesCallbackFunc func, void *param) -{ +static int _enumerate_modules_windows(int pid, EnumModulesCallbackFunc func, + void *param) { HANDLE hSnapShot; static MODULEENTRY32 modentry; int result = 0; @@ -1390,7 +1394,7 @@ // iterate through all modules modentry.dwSize = sizeof(MODULEENTRY32); - bool not_done = os::Kernel32Dll::Module32First( hSnapShot, &modentry ) != 0; + bool not_done = os::Kernel32Dll::Module32First(hSnapShot, &modentry) != 0; while (not_done) { // invoke the callback @@ -1399,20 +1403,22 @@ if (result) break; modentry.dwSize = sizeof(MODULEENTRY32); - not_done = os::Kernel32Dll::Module32Next( hSnapShot, &modentry ) != 0; + not_done = os::Kernel32Dll::Module32Next(hSnapShot, &modentry) != 0; } CloseHandle(hSnapShot); return result; } -int enumerate_modules( int pid, EnumModulesCallbackFunc func, void * param ) -{ +int enumerate_modules(int pid, EnumModulesCallbackFunc func, void * param) { // Get current process ID if caller doesn't provide it. if (!pid) pid = os::current_process_id(); - if (os::win32::is_nt()) return _enumerate_modules_winnt (pid, func, param); - else return _enumerate_modules_windows(pid, func, param); + if (os::win32::is_nt()) { + return _enumerate_modules_winnt (pid, func, param); + } else { + return _enumerate_modules_windows(pid, func, param); + } } struct _modinfo { @@ -1522,18 +1528,16 @@ // Loads .dll/.so and // in case of error it checks if .dll/.so was built for the // same architecture as Hotspot is running on -void * os::dll_load(const char *name, char *ebuf, int ebuflen) -{ +void * os::dll_load(const char *name, char *ebuf, int ebuflen) { void * result = LoadLibrary(name); - if (result != NULL) - { + if (result != NULL) { return result; } DWORD errcode = GetLastError(); if (errcode == ERROR_MOD_NOT_FOUND) { - strncpy(ebuf, "Can't find dependent libraries", ebuflen-1); - ebuf[ebuflen-1]='\0'; + strncpy(ebuf, "Can't find dependent libraries", ebuflen - 1); + ebuf[ebuflen - 1] = '\0'; return NULL; } @@ -1546,99 +1550,91 @@ // Read system error message into ebuf // It may or may not be overwritten below (in the for loop and just above) lasterror(ebuf, (size_t) ebuflen); - ebuf[ebuflen-1]='\0'; - int file_descriptor=::open(name, O_RDONLY | O_BINARY, 0); - if (file_descriptor<0) - { + ebuf[ebuflen - 1] = '\0'; + int fd = ::open(name, O_RDONLY | O_BINARY, 0); + if (fd < 0) { return NULL; } uint32_t signature_offset; - uint16_t lib_arch=0; - bool failed_to_get_lib_arch= - ( - //Go to position 3c in the dll - (os::seek_to_file_offset(file_descriptor,IMAGE_FILE_PTR_TO_SIGNATURE)<0) + uint16_t lib_arch = 0; + bool failed_to_get_lib_arch = + ( // Go to position 3c in the dll + (os::seek_to_file_offset(fd, IMAGE_FILE_PTR_TO_SIGNATURE) < 0) || - // Read loacation of signature - (sizeof(signature_offset)!= - (os::read(file_descriptor, (void*)&signature_offset,sizeof(signature_offset)))) + // Read location of signature + (sizeof(signature_offset) != + (os::read(fd, (void*)&signature_offset, sizeof(signature_offset)))) || - //Go to COFF File Header in dll - //that is located after"signature" (4 bytes long) - (os::seek_to_file_offset(file_descriptor, - signature_offset+IMAGE_FILE_SIGNATURE_LENGTH)<0) + // Go to COFF File Header in dll + // that is located after "signature" (4 bytes long) + (os::seek_to_file_offset(fd, + signature_offset + IMAGE_FILE_SIGNATURE_LENGTH) < 0) || - //Read field that contains code of architecture - // that dll was build for - (sizeof(lib_arch)!= - (os::read(file_descriptor, (void*)&lib_arch,sizeof(lib_arch)))) + // Read field that contains code of architecture + // that dll was built for + (sizeof(lib_arch) != (os::read(fd, (void*)&lib_arch, sizeof(lib_arch)))) ); - ::close(file_descriptor); - if (failed_to_get_lib_arch) - { + ::close(fd); + if (failed_to_get_lib_arch) { // file i/o error - report os::lasterror(...) msg return NULL; } - typedef struct - { + typedef struct { uint16_t arch_code; char* arch_name; } arch_t; - static const arch_t arch_array[]={ + static const arch_t arch_array[] = { {IMAGE_FILE_MACHINE_I386, (char*)"IA 32"}, {IMAGE_FILE_MACHINE_AMD64, (char*)"AMD 64"}, {IMAGE_FILE_MACHINE_IA64, (char*)"IA 64"} }; - #if (defined _M_IA64) - static const uint16_t running_arch=IMAGE_FILE_MACHINE_IA64; - #elif (defined _M_AMD64) - static const uint16_t running_arch=IMAGE_FILE_MACHINE_AMD64; - #elif (defined _M_IX86) - static const uint16_t running_arch=IMAGE_FILE_MACHINE_I386; - #else - #error Method os::dll_load requires that one of following \ - is defined :_M_IA64,_M_AMD64 or _M_IX86 - #endif +#if (defined _M_IA64) + static const uint16_t running_arch = IMAGE_FILE_MACHINE_IA64; +#elif (defined _M_AMD64) + static const uint16_t running_arch = IMAGE_FILE_MACHINE_AMD64; +#elif (defined _M_IX86) + static const uint16_t running_arch = IMAGE_FILE_MACHINE_I386; +#else + #error Method os::dll_load requires that one of following \ + is defined :_M_IA64,_M_AMD64 or _M_IX86 +#endif // Obtain a string for printf operation // lib_arch_str shall contain string what platform this .dll was built for // running_arch_str shall string contain what platform Hotspot was built for - char *running_arch_str=NULL,*lib_arch_str=NULL; - for (unsigned int i=0;ihandle_special_suspend_equivalent_condition(); if (threadIsSuspended) { - // // The semaphore has been incremented, but while we were waiting // another thread suspended us. We don't want to continue running // while suspended because that would surprise the thread that // suspended us. - // ret = ::ReleaseSemaphore(sig_sem, 1, NULL); assert(ret != 0, "ReleaseSemaphore() failed"); @@ -2105,7 +2097,8 @@ // Implicit OS exception handling -LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo, address handler) { +LONG Handle_Exception(struct _EXCEPTION_POINTERS* exceptionInfo, + address handler) { JavaThread* thread = JavaThread::current(); // Save pc in thread #ifdef _M_IA64 @@ -2163,7 +2156,7 @@ // Handle NAT Bit consumption on IA64. #ifdef _M_IA64 -#define EXCEPTION_REG_NAT_CONSUMPTION STATUS_REG_NAT_CONSUMPTION + #define EXCEPTION_REG_NAT_CONSUMPTION STATUS_REG_NAT_CONSUMPTION #endif // Windows Vista/2008 heap corruption check @@ -2292,10 +2285,9 @@ return (prev_uef_handler)(exceptionInfo); } #else // !_WIN64 -/* - On Windows, the mxcsr control bits are non-volatile across calls - See also CR 6192333 - */ + // On Windows, the mxcsr control bits are non-volatile across calls + // See also CR 6192333 + // jint MxCsr = INITIAL_MXCSR; // we can't use StubRoutines::addr_mxcsr_std() // because in Win64 mxcsr is not saved there @@ -2497,9 +2489,9 @@ // update the enabled status, even if the zone contains only one page. thread->disable_stack_yellow_zone(); // If not in java code, return and hope for the best. - return in_java ? Handle_Exception(exceptionInfo, - SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)) - : EXCEPTION_CONTINUE_EXECUTION; + return in_java + ? Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)) + : EXCEPTION_CONTINUE_EXECUTION; } else { // Fatal red zone violation. thread->disable_stack_red_zone(); @@ -2532,11 +2524,9 @@ return Handle_Exception(exceptionInfo, SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW)); } - // // Check for safepoint polling and implicit null // We only expect null pointers in the stubs (vtable) // the rest are checked explicitly now. - // CodeBlob* cb = CodeCache::find_blob(pc); if (cb != NULL) { if (os::is_poll_address(addr)) { @@ -2546,7 +2536,6 @@ } { #ifdef _WIN64 - // // If it's a legal stack address map the entire region in // PEXCEPTION_RECORD exceptionRecord = exceptionInfo->ExceptionRecord; @@ -2557,8 +2546,7 @@ os::commit_memory((char *)addr, thread->stack_base() - addr, !ExecMem); return EXCEPTION_CONTINUE_EXECUTION; - } - else + } else #endif { // Null pointer exception. @@ -2652,8 +2640,7 @@ } if (((thread->thread_state() == _thread_in_Java) || (thread->thread_state() == _thread_in_native)) && - exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) - { + exception_code != EXCEPTION_UNCAUGHT_CXX_EXCEPTION) { LONG result=Handle_FLT_Exception(exceptionInfo); if (result==EXCEPTION_CONTINUE_EXECUTION) return result; } @@ -2684,14 +2671,19 @@ return EXCEPTION_CONTINUE_SEARCH; } -#define DEFINE_FAST_GETFIELD(Return,Fieldname,Result) \ -Return JNICALL jni_fast_Get##Result##Field_wrapper(JNIEnv *env, jobject obj, jfieldID fieldID) { \ - __try { \ - return (*JNI_FastGetField::jni_fast_Get##Result##Field_fp)(env, obj, fieldID); \ - } __except(fastJNIAccessorExceptionFilter((_EXCEPTION_POINTERS*)_exception_info())) { \ - } \ - return 0; \ -} +#define DEFINE_FAST_GETFIELD(Return, Fieldname, Result) \ + Return JNICALL jni_fast_Get##Result##Field_wrapper(JNIEnv *env, \ + jobject obj, \ + jfieldID fieldID) { \ + __try { \ + return (*JNI_FastGetField::jni_fast_Get##Result##Field_fp)(env, \ + obj, \ + fieldID); \ + } __except(fastJNIAccessorExceptionFilter((_EXCEPTION_POINTERS*) \ + _exception_info())) { \ + } \ + return 0; \ + } DEFINE_FAST_GETFIELD(jboolean, bool, Boolean) DEFINE_FAST_GETFIELD(jbyte, byte, Byte) @@ -2755,7 +2747,7 @@ // in the future, if so the code below needs to be revisited. #ifndef MEM_LARGE_PAGES -#define MEM_LARGE_PAGES 0x20000000 + #define MEM_LARGE_PAGES 0x20000000 #endif static HANDLE _hProcess; @@ -2857,7 +2849,7 @@ // print a warning if UseNUMAInterleaving flag is specified on command line bool warn_on_failure = use_numa_interleaving_specified; -# define WARN(msg) if (warn_on_failure) { warning(msg); } +#define WARN(msg) if (warn_on_failure) { warning(msg); } // NUMAInterleaveGranularity cannot be less than vm_allocation_granularity (or _large_page_size if using large pages) size_t min_interleave_granularity = UseLargePages ? _large_page_size : os::vm_allocation_granularity(); @@ -2891,8 +2883,9 @@ // Reasons for doing this: // * UseLargePagesIndividualAllocation was set (normally only needed on WS2003 but possible to be set otherwise) // * UseNUMAInterleaving requires a separate node for each piece -static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, DWORD prot, - bool should_inject_error=false) { +static char* allocate_pages_individually(size_t bytes, char* addr, DWORD flags, + DWORD prot, + bool should_inject_error = false) { char * p_buf; // note: at setup time we guaranteed that NUMAInterleaveGranularity was aligned up to a page size size_t page_size = UseLargePages ? _large_page_size : os::vm_allocation_granularity(); @@ -3020,7 +3013,7 @@ !FLAG_IS_DEFAULT(LargePageSizeInBytes); bool success = false; -# define WARN(msg) if (warn_on_failure) { warning(msg); } +#define WARN(msg) if (warn_on_failure) { warning(msg); } if (resolve_functions_for_large_page_init()) { if (request_lock_memory_privilege()) { size_t s = os::Kernel32Dll::GetLargePageMinimum(); @@ -3161,7 +3154,8 @@ return true; } -char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr, bool exec) { +char* os::reserve_memory_special(size_t bytes, size_t alignment, char* addr, + bool exec) { assert(UseLargePages, "only for large pages"); if (!is_size_aligned(bytes, os::large_page_size()) || alignment > os::large_page_size()) { @@ -3397,7 +3391,8 @@ return false; } -char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { +char *os::scan_pages(char *start, char* end, page_info* page_expected, + page_info* page_found) { return end; } @@ -3458,8 +3453,9 @@ while (ms > limit) { int res; - if ((res = sleep(thread, limit, interruptable)) != OS_TIMEOUT) + if ((res = sleep(thread, limit, interruptable)) != OS_TIMEOUT) { return res; + } ms -= limit; } @@ -3479,8 +3475,9 @@ HANDLE events[1]; events[0] = osthread->interrupt_event(); HighResolutionInterval *phri=NULL; - if (!ForceTimeHighResolution) + if (!ForceTimeHighResolution) { phri = new HighResolutionInterval(ms); + } if (WaitForMultipleObjects(1, events, FALSE, (DWORD)ms) == WAIT_TIMEOUT) { result = OS_TIMEOUT; } else { @@ -3500,7 +3497,6 @@ return result; } -// // Short sleep, direct OS call. // // ms = 0, means allow others (if any) to run. @@ -3583,7 +3579,8 @@ return ret ? OS_OK : OS_ERR; } -OSReturn os::get_native_priority(const Thread* const thread, int* priority_ptr) { +OSReturn os::get_native_priority(const Thread* const thread, + int* priority_ptr) { if (!UseThreadPriorities) { *priority_ptr = java_to_os_priority[NormPriority]; return OS_OK; @@ -3603,7 +3600,8 @@ void os::hint_no_preempt() {} void os::interrupt(Thread* thread) { - assert(!thread->is_Java_thread() || Thread::current() == thread || Threads_lock->owned_by_self(), + assert(!thread->is_Java_thread() || Thread::current() == thread || + Threads_lock->owned_by_self(), "possibility of dangling Thread pointer"); OSThread* osthread = thread->osthread(); @@ -3615,12 +3613,12 @@ OrderAccess::release(); SetEvent(osthread->interrupt_event()); // For JSR166: unpark after setting status - if (thread->is_Java_thread()) + if (thread->is_Java_thread()) { ((JavaThread*)thread)->parker()->unpark(); + } ParkEvent * ev = thread->_ParkEvent; if (ev != NULL) ev->unpark(); - } @@ -3667,31 +3665,30 @@ } // GetCurrentThreadId() returns DWORD -intx os::current_thread_id() { return GetCurrentThreadId(); } +intx os::current_thread_id() { return GetCurrentThreadId(); } static int _initial_pid = 0; -int os::current_process_id() -{ +int os::current_process_id() { return (_initial_pid ? _initial_pid : _getpid()); } -int os::win32::_vm_page_size = 0; +int os::win32::_vm_page_size = 0; int os::win32::_vm_allocation_granularity = 0; -int os::win32::_processor_type = 0; +int os::win32::_processor_type = 0; // Processor level is not available on non-NT systems, use vm_version instead -int os::win32::_processor_level = 0; -julong os::win32::_physical_memory = 0; -size_t os::win32::_default_stack_size = 0; - -intx os::win32::_os_thread_limit = 0; +int os::win32::_processor_level = 0; +julong os::win32::_physical_memory = 0; +size_t os::win32::_default_stack_size = 0; + +intx os::win32::_os_thread_limit = 0; volatile intx os::win32::_os_thread_count = 0; -bool os::win32::_is_nt = false; -bool os::win32::_is_windows_2003 = false; -bool os::win32::_is_windows_server = false; - -bool os::win32::_has_performance_count = 0; +bool os::win32::_is_nt = false; +bool os::win32::_is_windows_2003 = false; +bool os::win32::_is_windows_server = false; + +bool os::win32::_has_performance_count = 0; void os::win32::initialize_system_info() { SYSTEM_INFO si; @@ -3749,7 +3746,8 @@ } -HINSTANCE os::win32::load_Windows_dll(const char* name, char *ebuf, int ebuflen) { +HINSTANCE os::win32::load_Windows_dll(const char* name, char *ebuf, + int ebuflen) { char path[MAX_PATH]; DWORD size; DWORD pathLen = (DWORD)sizeof(path); @@ -3904,8 +3902,10 @@ os::set_polling_page(polling_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", + (intptr_t)polling_page); + } #endif if (!UseMembar) { @@ -3918,8 +3918,10 @@ os::set_memory_serialize_page(mem_serialize_page); #ifndef PRODUCT - if (Verbose && PrintMiscellaneous) - tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); + if (Verbose && PrintMiscellaneous) { + tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", + (intptr_t)mem_serialize_page); + } #endif } @@ -4034,16 +4036,20 @@ // Mark the polling page as unreadable void os::make_polling_page_unreadable(void) { DWORD old_status; - if (!VirtualProtect((char *)_polling_page, os::vm_page_size(), PAGE_NOACCESS, &old_status)) + if (!VirtualProtect((char *)_polling_page, os::vm_page_size(), + PAGE_NOACCESS, &old_status)) { fatal("Could not disable polling page"); -}; + } +} // Mark the polling page as readable void os::make_polling_page_readable(void) { DWORD old_status; - if (!VirtualProtect((char *)_polling_page, os::vm_page_size(), PAGE_READONLY, &old_status)) + if (!VirtualProtect((char *)_polling_page, os::vm_page_size(), + PAGE_READONLY, &old_status)) { fatal("Could not enable polling page"); -}; + } +} int os::stat(const char *path, struct stat *sbuf) { @@ -4119,12 +4125,11 @@ FILETIME KernelTime; FILETIME UserTime; - if (GetThreadTimes(thread->osthread()->thread_handle(), - &CreationTime, &ExitTime, &KernelTime, &UserTime) == 0) + if (GetThreadTimes(thread->osthread()->thread_handle(), &CreationTime, + &ExitTime, &KernelTime, &UserTime) == 0) { return -1; - else - if (user_sys_cpu_time) { - return (FT2INT64(UserTime) + FT2INT64(KernelTime)) * 100; + } else if (user_sys_cpu_time) { + return (FT2INT64(UserTime) + FT2INT64(KernelTime)) * 100; } else { return FT2INT64(UserTime) * 100; } @@ -4155,11 +4160,12 @@ FILETIME KernelTime; FILETIME UserTime; - if (GetThreadTimes(GetCurrentThread(), - &CreationTime, &ExitTime, &KernelTime, &UserTime) == 0) + if (GetThreadTimes(GetCurrentThread(), &CreationTime, &ExitTime, + &KernelTime, &UserTime) == 0) { return false; - else + } else { return true; + } } else { return false; } @@ -4252,39 +4258,36 @@ // This method is a slightly reworked copy of JDK's sysNativePath // from src/windows/hpi/src/path_md.c -/* Convert a pathname to native format. On win32, this involves forcing all - separators to be '\\' rather than '/' (both are legal inputs, but Win95 - sometimes rejects '/') and removing redundant separators. The input path is - assumed to have been converted into the character encoding used by the local - system. Because this might be a double-byte encoding, care is taken to - treat double-byte lead characters correctly. - - This procedure modifies the given path in place, as the result is never - longer than the original. There is no error return; this operation always - succeeds. */ +// Convert a pathname to native format. On win32, this involves forcing all +// separators to be '\\' rather than '/' (both are legal inputs, but Win95 +// sometimes rejects '/') and removing redundant separators. The input path is +// assumed to have been converted into the character encoding used by the local +// system. Because this might be a double-byte encoding, care is taken to +// treat double-byte lead characters correctly. +// +// This procedure modifies the given path in place, as the result is never +// longer than the original. There is no error return; this operation always +// succeeds. char * os::native_path(char *path) { char *src = path, *dst = path, *end = path; - char *colon = NULL; /* If a drive specifier is found, this will - point to the colon following the drive - letter */ - - /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */ - assert(((!::IsDBCSLeadByte('/')) - && (!::IsDBCSLeadByte('\\')) - && (!::IsDBCSLeadByte(':'))), - "Illegal lead byte"); - - /* Check for leading separators */ + char *colon = NULL; // If a drive specifier is found, this will + // point to the colon following the drive letter + + // Assumption: '/', '\\', ':', and drive letters are never lead bytes + assert(((!::IsDBCSLeadByte('/')) && (!::IsDBCSLeadByte('\\')) + && (!::IsDBCSLeadByte(':'))), "Illegal lead byte"); + + // Check for leading separators #define isfilesep(c) ((c) == '/' || (c) == '\\') while (isfilesep(*src)) { src++; } if (::isalpha(*src) && !::IsDBCSLeadByte(*src) && src[1] == ':') { - /* Remove leading separators if followed by drive specifier. This - hack is necessary to support file URLs containing drive - specifiers (e.g., "file://c:/path"). As a side effect, - "/c:/path" can be used as an alternative to "c:/path". */ + // Remove leading separators if followed by drive specifier. This + // hack is necessary to support file URLs containing drive + // specifiers (e.g., "file://c:/path"). As a side effect, + // "/c:/path" can be used as an alternative to "c:/path". *dst++ = *src++; colon = dst; *dst++ = ':'; @@ -4292,55 +4295,55 @@ } else { src = path; if (isfilesep(src[0]) && isfilesep(src[1])) { - /* UNC pathname: Retain first separator; leave src pointed at - second separator so that further separators will be collapsed - into the second separator. The result will be a pathname - beginning with "\\\\" followed (most likely) by a host name. */ + // UNC pathname: Retain first separator; leave src pointed at + // second separator so that further separators will be collapsed + // into the second separator. The result will be a pathname + // beginning with "\\\\" followed (most likely) by a host name. src = dst = path + 1; - path[0] = '\\'; /* Force first separator to '\\' */ + path[0] = '\\'; // Force first separator to '\\' } } end = dst; - /* Remove redundant separators from remainder of path, forcing all - separators to be '\\' rather than '/'. Also, single byte space - characters are removed from the end of the path because those - are not legal ending characters on this operating system. - */ + // Remove redundant separators from remainder of path, forcing all + // separators to be '\\' rather than '/'. Also, single byte space + // characters are removed from the end of the path because those + // are not legal ending characters on this operating system. + // while (*src != '\0') { if (isfilesep(*src)) { *dst++ = '\\'; src++; while (isfilesep(*src)) src++; if (*src == '\0') { - /* Check for trailing separator */ + // Check for trailing separator end = dst; - if (colon == dst - 2) break; /* "z:\\" */ - if (dst == path + 1) break; /* "\\" */ + if (colon == dst - 2) break; // "z:\\" + if (dst == path + 1) break; // "\\" if (dst == path + 2 && isfilesep(path[0])) { - /* "\\\\" is not collapsed to "\\" because "\\\\" marks the - beginning of a UNC pathname. Even though it is not, by - itself, a valid UNC pathname, we leave it as is in order - to be consistent with the path canonicalizer as well - as the win32 APIs, which treat this case as an invalid - UNC pathname rather than as an alias for the root - directory of the current drive. */ + // "\\\\" is not collapsed to "\\" because "\\\\" marks the + // beginning of a UNC pathname. Even though it is not, by + // itself, a valid UNC pathname, we leave it as is in order + // to be consistent with the path canonicalizer as well + // as the win32 APIs, which treat this case as an invalid + // UNC pathname rather than as an alias for the root + // directory of the current drive. break; } - end = --dst; /* Path does not denote a root directory, so - remove trailing separator */ + end = --dst; // Path does not denote a root directory, so + // remove trailing separator break; } end = dst; } else { - if (::IsDBCSLeadByte(*src)) { /* Copy a double-byte character */ + if (::IsDBCSLeadByte(*src)) { // Copy a double-byte character *dst++ = *src++; if (*src) *dst++ = *src++; end = dst; - } else { /* Copy a single-byte character */ + } else { // Copy a single-byte character char c = *src++; *dst++ = c; - /* Space is not a legal ending character */ + // Space is not a legal ending character if (c != ' ') end = dst; } } @@ -4348,7 +4351,7 @@ *end = '\0'; - /* For "z:", add "." to work around a bug in the C runtime library */ + // For "z:", add "." to work around a bug in the C runtime library if (colon == dst - 1) { path[2] = '.'; path[3] = '\0'; @@ -4390,8 +4393,8 @@ HANDLE handle = (HANDLE)::_get_osfhandle(fd); if ((!::FlushFileBuffers(handle)) && - (GetLastError() != ERROR_ACCESS_DENIED) ) { - /* from winerror.h */ + (GetLastError() != ERROR_ACCESS_DENIED)) { + // from winerror.h return -1; } return 0; @@ -4441,12 +4444,10 @@ // from src/windows/hpi/src/sys_api_md.c static int nonSeekAvailable(int fd, long *pbytes) { - /* This is used for available on non-seekable devices - * (like both named and anonymous pipes, such as pipes - * connected to an exec'd process). - * Standard Input is a special case. - * - */ + // This is used for available on non-seekable devices + // (like both named and anonymous pipes, such as pipes + // connected to an exec'd process). + // Standard Input is a special case. HANDLE han; if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) { @@ -4454,12 +4455,12 @@ } if (! ::PeekNamedPipe(han, NULL, 0, NULL, (LPDWORD)pbytes, NULL)) { - /* PeekNamedPipe fails when at EOF. In that case we - * simply make *pbytes = 0 which is consistent with the - * behavior we get on Solaris when an fd is at EOF. - * The only alternative is to raise an Exception, - * which isn't really warranted. - */ + // PeekNamedPipe fails when at EOF. In that case we + // simply make *pbytes = 0 which is consistent with the + // behavior we get on Solaris when an fd is at EOF. + // The only alternative is to raise an Exception, + // which isn't really warranted. + // if (::GetLastError() != ERROR_BROKEN_PIPE) { return FALSE; } @@ -4475,25 +4476,25 @@ static int stdinAvailable(int fd, long *pbytes) { HANDLE han; - DWORD numEventsRead = 0; /* Number of events read from buffer */ - DWORD numEvents = 0; /* Number of events in buffer */ - DWORD i = 0; /* Loop index */ - DWORD curLength = 0; /* Position marker */ - DWORD actualLength = 0; /* Number of bytes readable */ - BOOL error = FALSE; /* Error holder */ - INPUT_RECORD *lpBuffer; /* Pointer to records of input events */ + DWORD numEventsRead = 0; // Number of events read from buffer + DWORD numEvents = 0; // Number of events in buffer + DWORD i = 0; // Loop index + DWORD curLength = 0; // Position marker + DWORD actualLength = 0; // Number of bytes readable + BOOL error = FALSE; // Error holder + INPUT_RECORD *lpBuffer; // Pointer to records of input events if ((han = ::GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { return FALSE; } - /* Construct an array of input records in the console buffer */ + // Construct an array of input records in the console buffer error = ::GetNumberOfConsoleInputEvents(han, &numEvents); if (error == 0) { return nonSeekAvailable(fd, pbytes); } - /* lpBuffer must fit into 64K or else PeekConsoleInput fails */ + // lpBuffer must fit into 64K or else PeekConsoleInput fails if (numEvents > MAX_INPUT_EVENTS) { numEvents = MAX_INPUT_EVENTS; } @@ -4509,7 +4510,7 @@ return FALSE; } - /* Examine input records for the number of bytes available */ + // Examine input records for the number of bytes available for (i=0; iis_Watcher_thread(), "Must be WatcherThread"); } -/* - * See the caveats for this class in os_windows.hpp - * Protects the callback call so that raised OS EXCEPTIONS causes a jump back - * into this method and returns false. If no OS EXCEPTION was raised, returns - * true. - * The callback is supposed to provide the method that should be protected. - */ +// See the caveats for this class in os_windows.hpp +// Protects the callback call so that raised OS EXCEPTIONS causes a jump back +// into this method and returns false. If no OS EXCEPTION was raised, returns +// true. +// The callback is supposed to provide the method that should be protected. +// bool os::WatcherThreadCrashProtection::call(os::CrashProtectionCallback& cb) { assert(Thread::current()->is_Watcher_thread(), "Only for WatcherThread"); assert(!WatcherThread::watcher_thread()->has_crash_protection(), @@ -4787,7 +4787,7 @@ // Another possible encoding of _Event would be // with explicit "PARKED" and "SIGNALED" bits. -int os::PlatformEvent::park (jlong Millis) { +int os::PlatformEvent::park(jlong Millis) { guarantee(_ParkHandle != NULL , "Invariant"); guarantee(Millis > 0 , "Invariant"); int v; @@ -4895,32 +4895,28 @@ // JSR166 // ------------------------------------------------------- -/* - * The Windows implementation of Park is very straightforward: Basic - * operations on Win32 Events turn out to have the right semantics to - * use them directly. We opportunistically resuse the event inherited - * from Monitor. - */ - +// The Windows implementation of Park is very straightforward: Basic +// operations on Win32 Events turn out to have the right semantics to +// use them directly. We opportunistically resuse the event inherited +// from Monitor. void Parker::park(bool isAbsolute, jlong time) { guarantee(_ParkEvent != NULL, "invariant"); // First, demultiplex/decode time arguments if (time < 0) { // don't wait return; - } - else if (time == 0 && !isAbsolute) { + } else if (time == 0 && !isAbsolute) { time = INFINITE; - } - else if (isAbsolute) { + } else if (isAbsolute) { time -= os::javaTimeMillis(); // convert to relative time - if (time <= 0) // already elapsed + if (time <= 0) { // already elapsed return; - } - else { // relative - time /= 1000000; // Must coarsen from nanos to millis - if (time == 0) // Wait for the minimal time unit if zero + } + } else { // relative + time /= 1000000; // Must coarsen from nanos to millis + if (time == 0) { // Wait for the minimal time unit if zero time = 1; + } } JavaThread* thread = (JavaThread*)(Thread::current()); @@ -4932,8 +4928,7 @@ WaitForSingleObject(_ParkEvent, 0) == WAIT_OBJECT_0) { ResetEvent(_ParkEvent); return; - } - else { + } else { ThreadBlockInVM tbivm(jt); OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); jt->set_suspend_equivalent(); @@ -5042,8 +5037,9 @@ PEXCEPTION_RECORD exceptionRecord = e->ExceptionRecord; address addr = (address) exceptionRecord->ExceptionInformation[1]; - if (os::is_memory_serialize_page(thread, addr)) + if (os::is_memory_serialize_page(thread, addr)) { return EXCEPTION_CONTINUE_EXECUTION; + } } return EXCEPTION_CONTINUE_SEARCH; @@ -5163,9 +5159,9 @@ // WINDOWS CONTEXT Flags for THREAD_SAMPLING #if defined(IA32) -# define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS) + #define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT | CONTEXT_EXTENDED_REGISTERS) #elif defined (AMD64) -# define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT) + #define sampling_context_flags (CONTEXT_FULL | CONTEXT_FLOATING_POINT) #endif // returns true if thread could be suspended, @@ -5189,13 +5185,13 @@ // retrieve a suspend/resume context capable handle // from the tid. Caller validates handle return value. -void get_thread_handle_for_extended_context(HANDLE* h, OSThread::thread_id_t tid) { +void get_thread_handle_for_extended_context(HANDLE* h, + OSThread::thread_id_t tid) { if (h != NULL) { *h = OpenThread(THREAD_SUSPEND_RESUME | THREAD_GET_CONTEXT | THREAD_QUERY_INFORMATION, FALSE, tid); } } -// // Thread sampling implementation // void os::SuspendedThreadTask::internal_do_task() { @@ -5229,9 +5225,9 @@ // Kernel32 API typedef SIZE_T (WINAPI* GetLargePageMinimum_Fn)(void); -typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn) (HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); -typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn) (PULONG); -typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn) (UCHAR, PULONGLONG); +typedef LPVOID (WINAPI *VirtualAllocExNuma_Fn)(HANDLE, LPVOID, SIZE_T, DWORD, DWORD, DWORD); +typedef BOOL (WINAPI *GetNumaHighestNodeNumber_Fn)(PULONG); +typedef BOOL (WINAPI *GetNumaNodeProcessorMask_Fn)(UCHAR, PULONGLONG); typedef USHORT (WINAPI* RtlCaptureStackBackTrace_Fn)(ULONG, ULONG, PVOID*, PULONG); GetLargePageMinimum_Fn os::Kernel32Dll::_GetLargePageMinimum = NULL; @@ -5262,7 +5258,9 @@ return _VirtualAllocExNuma != NULL; } -LPVOID os::Kernel32Dll::VirtualAllocExNuma(HANDLE hProc, LPVOID addr, SIZE_T bytes, DWORD flags, DWORD prot, DWORD node) { +LPVOID os::Kernel32Dll::VirtualAllocExNuma(HANDLE hProc, LPVOID addr, + SIZE_T bytes, DWORD flags, + DWORD prot, DWORD node) { assert(initialized && _VirtualAllocExNuma != NULL, "NUMACallsAvailable() not yet called"); @@ -5276,7 +5274,8 @@ return _GetNumaHighestNodeNumber(ptr_highest_node_number); } -BOOL os::Kernel32Dll::GetNumaNodeProcessorMask(UCHAR node, PULONGLONG proc_mask) { +BOOL os::Kernel32Dll::GetNumaNodeProcessorMask(UCHAR node, + PULONGLONG proc_mask) { assert(initialized && _GetNumaNodeProcessorMask != NULL, "NUMACallsAvailable() not yet called"); @@ -5284,7 +5283,9 @@ } USHORT os::Kernel32Dll::RtlCaptureStackBackTrace(ULONG FrameToSkip, - ULONG FrameToCapture, PVOID* BackTrace, PULONG BackTraceHash) { + ULONG FrameToCapture, + PVOID* BackTrace, + PULONG BackTraceHash) { if (!initialized) { initialize(); } @@ -5333,15 +5334,18 @@ return true; } -inline HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags,DWORD th32ProcessId) { +inline HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags, + DWORD th32ProcessId) { return ::CreateToolhelp32Snapshot(dwFlags, th32ProcessId); } -inline BOOL os::Kernel32Dll::Module32First(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { +inline BOOL os::Kernel32Dll::Module32First(HANDLE hSnapshot, + LPMODULEENTRY32 lpme) { return ::Module32First(hSnapshot, lpme); } -inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { +inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot, + LPMODULEENTRY32 lpme) { return ::Module32Next(hSnapshot, lpme); } @@ -5355,15 +5359,23 @@ } // PSAPI API -inline BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, DWORD cb, LPDWORD lpcbNeeded) { +inline BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, + HMODULE *lpModule, DWORD cb, + LPDWORD lpcbNeeded) { return ::EnumProcessModules(hProcess, lpModule, cb, lpcbNeeded); } -inline DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize) { +inline DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, + HMODULE hModule, + LPTSTR lpFilename, + DWORD nSize) { return ::GetModuleFileNameEx(hProcess, hModule, lpFilename, nSize); } -inline BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb) { +inline BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, + HMODULE hModule, + LPMODULEINFO lpmodinfo, + DWORD cb) { return ::GetModuleInformation(hProcess, hModule, lpmodinfo, cb); } @@ -5373,7 +5385,8 @@ // WinSock2 API -inline BOOL os::WinSock2Dll::WSAStartup(WORD wVersionRequested, LPWSADATA lpWSAData) { +inline BOOL os::WinSock2Dll::WSAStartup(WORD wVersionRequested, + LPWSADATA lpWSAData) { return ::WSAStartup(wVersionRequested, lpWSAData); } @@ -5387,18 +5400,24 @@ // Advapi API inline BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, - BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, - PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { + BOOL DisableAllPrivileges, + PTOKEN_PRIVILEGES NewState, + DWORD BufferLength, + PTOKEN_PRIVILEGES PreviousState, + PDWORD ReturnLength) { return ::AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength); } -inline BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, +inline BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, + DWORD DesiredAccess, PHANDLE TokenHandle) { return ::OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); } -inline BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { +inline BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, + LPCTSTR lpName, + PLUID lpLuid) { return ::LookupPrivilegeValue(lpSystemName, lpName, lpLuid); } @@ -5478,9 +5497,9 @@ #else // Kernel32 API typedef BOOL (WINAPI* SwitchToThread_Fn)(void); -typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD,DWORD); -typedef BOOL (WINAPI* Module32First_Fn)(HANDLE,LPMODULEENTRY32); -typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE,LPMODULEENTRY32); +typedef HANDLE (WINAPI* CreateToolhelp32Snapshot_Fn)(DWORD, DWORD); +typedef BOOL (WINAPI* Module32First_Fn)(HANDLE, LPMODULEENTRY32); +typedef BOOL (WINAPI* Module32Next_Fn)(HANDLE, LPMODULEENTRY32); typedef void (WINAPI* GetNativeSystemInfo_Fn)(LPSYSTEM_INFO); SwitchToThread_Fn os::Kernel32Dll::_SwitchToThread = NULL; @@ -5530,7 +5549,8 @@ _Module32Next != NULL; } -HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags,DWORD th32ProcessId) { +HANDLE os::Kernel32Dll::CreateToolhelp32Snapshot(DWORD dwFlags, + DWORD th32ProcessId) { assert(initialized && _CreateToolhelp32Snapshot != NULL, "HelpToolsAvailable() not yet called"); @@ -5544,7 +5564,8 @@ return _Module32First(hSnapshot, lpme); } -inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot,LPMODULEENTRY32 lpme) { +inline BOOL os::Kernel32Dll::Module32Next(HANDLE hSnapshot, + LPMODULEENTRY32 lpme) { assert(initialized && _Module32Next != NULL, "HelpToolsAvailable() not yet called"); @@ -5570,7 +5591,7 @@ typedef BOOL (WINAPI *EnumProcessModules_Fn)(HANDLE, HMODULE *, DWORD, LPDWORD); -typedef BOOL (WINAPI *GetModuleFileNameEx_Fn)(HANDLE, HMODULE, LPTSTR, DWORD);; +typedef BOOL (WINAPI *GetModuleFileNameEx_Fn)(HANDLE, HMODULE, LPTSTR, DWORD); typedef BOOL (WINAPI *GetModuleInformation_Fn)(HANDLE, HMODULE, LPMODULEINFO, DWORD); EnumProcessModules_Fn os::PSApiDll::_EnumProcessModules = NULL; @@ -5595,19 +5616,22 @@ -BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, DWORD cb, LPDWORD lpcbNeeded) { +BOOL os::PSApiDll::EnumProcessModules(HANDLE hProcess, HMODULE *lpModule, + DWORD cb, LPDWORD lpcbNeeded) { assert(initialized && _EnumProcessModules != NULL, "PSApiAvailable() not yet called"); return _EnumProcessModules(hProcess, lpModule, cb, lpcbNeeded); } -DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, LPTSTR lpFilename, DWORD nSize) { +DWORD os::PSApiDll::GetModuleFileNameEx(HANDLE hProcess, HMODULE hModule, + LPTSTR lpFilename, DWORD nSize) { assert(initialized && _GetModuleFileNameEx != NULL, "PSApiAvailable() not yet called"); return _GetModuleFileNameEx(hProcess, hModule, lpFilename, nSize); } -BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, LPMODULEINFO lpmodinfo, DWORD cb) { +BOOL os::PSApiDll::GetModuleInformation(HANDLE hProcess, HMODULE hModule, + LPMODULEINFO lpmodinfo, DWORD cb) { assert(initialized && _GetModuleInformation != NULL, "PSApiAvailable() not yet called"); return _GetModuleInformation(hProcess, hModule, lpmodinfo, cb); @@ -5688,22 +5712,27 @@ } BOOL os::Advapi32Dll::AdjustTokenPrivileges(HANDLE TokenHandle, - BOOL DisableAllPrivileges, PTOKEN_PRIVILEGES NewState, DWORD BufferLength, - PTOKEN_PRIVILEGES PreviousState, PDWORD ReturnLength) { + BOOL DisableAllPrivileges, + PTOKEN_PRIVILEGES NewState, + DWORD BufferLength, + PTOKEN_PRIVILEGES PreviousState, + PDWORD ReturnLength) { assert(initialized && _AdjustTokenPrivileges != NULL, "AdvapiAvailable() not yet called"); return _AdjustTokenPrivileges(TokenHandle, DisableAllPrivileges, NewState, BufferLength, PreviousState, ReturnLength); } -BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, DWORD DesiredAccess, +BOOL os::Advapi32Dll::OpenProcessToken(HANDLE ProcessHandle, + DWORD DesiredAccess, PHANDLE TokenHandle) { assert(initialized && _OpenProcessToken != NULL, "AdvapiAvailable() not yet called"); return _OpenProcessToken(ProcessHandle, DesiredAccess, TokenHandle); } -BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, LPCTSTR lpName, PLUID lpLuid) { +BOOL os::Advapi32Dll::LookupPrivilegeValue(LPCTSTR lpSystemName, + LPCTSTR lpName, PLUID lpLuid) { assert(initialized && _LookupPrivilegeValue != NULL, "AdvapiAvailable() not yet called"); return _LookupPrivilegeValue(lpSystemName, lpName, lpLuid); diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/atomic.hpp --- a/hotspot/src/share/vm/runtime/atomic.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/atomic.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -74,12 +74,12 @@ inline static intptr_t add_ptr(intptr_t add_value, volatile intptr_t* dest); inline static void* add_ptr(intptr_t add_value, volatile void* dest); // See comment above about using jlong atomics on 32-bit platforms - static jlong add (jlong add_value, volatile jlong* dest); + static jlong add (jlong add_value, volatile jlong* dest); // Atomically increment location. inc*() provide: // increment-dest inline static void inc (volatile jint* dest); - static void inc (volatile jshort* dest); + static void inc (volatile jshort* dest); inline static void inc (volatile size_t* dest); inline static void inc_ptr(volatile intptr_t* dest); inline static void inc_ptr(volatile void* dest); @@ -87,7 +87,7 @@ // Atomically decrement a location. dec*() provide: // decrement-dest inline static void dec (volatile jint* dest); - static void dec (volatile jshort* dest); + static void dec (volatile jshort* dest); inline static void dec (volatile size_t* dest); inline static void dec_ptr(volatile intptr_t* dest); inline static void dec_ptr(volatile void* dest); @@ -95,27 +95,22 @@ // Performs atomic exchange of *dest with exchange_value. Returns old // prior value of *dest. xchg*() provide: // exchange-value-with-dest - inline static jint xchg(jint exchange_value, volatile jint* dest); - static unsigned int xchg(unsigned int exchange_value, volatile unsigned int* dest); - - inline static intptr_t xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest); - inline static void* xchg_ptr(void* exchange_value, volatile void* dest); + inline static jint xchg (jint exchange_value, volatile jint* dest); + static unsigned int xchg (unsigned int exchange_value, volatile unsigned int* dest); + inline static intptr_t xchg_ptr(intptr_t exchange_value, volatile intptr_t* dest); + inline static void* xchg_ptr(void* exchange_value, volatile void* dest); // Performs atomic compare of *dest and compare_value, and exchanges // *dest with exchange_value if the comparison succeeded. Returns prior // value of *dest. cmpxchg*() provide: // compare-and-exchange - static jbyte cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); - inline static jint cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value); + static jbyte cmpxchg (jbyte exchange_value, volatile jbyte* dest, jbyte compare_value); + inline static jint cmpxchg (jint exchange_value, volatile jint* dest, jint compare_value); // See comment above about using jlong atomics on 32-bit platforms - inline static jlong cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value); - - static unsigned int cmpxchg(unsigned int exchange_value, - volatile unsigned int* dest, - unsigned int compare_value); - - inline static intptr_t cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value); - inline static void* cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value); + inline static jlong cmpxchg (jlong exchange_value, volatile jlong* dest, jlong compare_value); + static unsigned int cmpxchg (unsigned int exchange_value, volatile unsigned int* dest, unsigned int compare_value); + inline static intptr_t cmpxchg_ptr(intptr_t exchange_value, volatile intptr_t* dest, intptr_t compare_value); + inline static void* cmpxchg_ptr(void* exchange_value, volatile void* dest, void* compare_value); }; // To use Atomic::inc(jshort* dest) and Atomic::dec(jshort* dest), the address must be specially @@ -129,12 +124,12 @@ // ); #ifdef VM_LITTLE_ENDIAN -#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ - non_atomic_decl; \ + #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ + non_atomic_decl; \ atomic_decl #else -#define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ - atomic_decl; \ + #define ATOMIC_SHORT_PAIR(atomic_decl, non_atomic_decl) \ + atomic_decl; \ non_atomic_decl #endif diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/mutex.cpp --- a/hotspot/src/share/vm/runtime/mutex.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/mutex.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -267,15 +267,24 @@ // CASPTR() uses the canonical argument order that dominates in the literature. // Our internal cmpxchg_ptr() uses a bastardized ordering to accommodate Sun .il templates. -#define CASPTR(a,c,s) intptr_t(Atomic::cmpxchg_ptr ((void *)(s),(void *)(a),(void *)(c))) +#define CASPTR(a, c, s) \ + intptr_t(Atomic::cmpxchg_ptr((void *)(s), (void *)(a), (void *)(c))) #define UNS(x) (uintptr_t(x)) -#define TRACE(m) { static volatile int ctr = 0; int x = ++ctr; if ((x & (x-1))==0) { ::printf ("%d:%s\n", x, #m); ::fflush(stdout); }} +#define TRACE(m) \ + { \ + static volatile int ctr = 0; \ + int x = ++ctr; \ + if ((x & (x - 1)) == 0) { \ + ::printf("%d:%s\n", x, #m); \ + ::fflush(stdout); \ + } \ + } // Simplistic low-quality Marsaglia SHIFT-XOR RNG. // Bijective except for the trailing mask operation. // Useful for spin loops as the compiler can't optimize it away. -static inline jint MarsagliaXORV (jint x) { +static inline jint MarsagliaXORV(jint x) { if (x == 0) x = 1|os::random(); x ^= x << 6; x ^= ((unsigned)x) >> 21; @@ -283,7 +292,7 @@ return x & 0x7FFFFFFF; } -static int Stall (int its) { +static int Stall(int its) { static volatile jint rv = 1; volatile int OnFrame = 0; jint v = rv ^ UNS(OnFrame); @@ -341,7 +350,7 @@ // Clamp spinning at approximately 1/2 of a context-switch round-trip. // See synchronizer.cpp for details and rationale. -int Monitor::TrySpin (Thread * const Self) { +int Monitor::TrySpin(Thread * const Self) { if (TryLock()) return 1; if (!os::is_MP()) return 0; @@ -403,7 +412,7 @@ } } -static int ParkCommon (ParkEvent * ev, jlong timo) { +static int ParkCommon(ParkEvent * ev, jlong timo) { // Diagnostic support - periodically unwedge blocked threads intx nmt = NativeMonitorTimeout; if (nmt > 0 && (nmt < timo || timo <= 0)) { @@ -418,7 +427,7 @@ return err; } -inline int Monitor::AcquireOrPush (ParkEvent * ESelf) { +inline int Monitor::AcquireOrPush(ParkEvent * ESelf) { intptr_t v = _LockWord.FullWord; for (;;) { if ((v & _LBIT) == 0) { @@ -443,7 +452,7 @@ // Note that ILock and IWait do *not* access _owner. // _owner is a higher-level logical concept. -void Monitor::ILock (Thread * Self) { +void Monitor::ILock(Thread * Self) { assert(_OnDeck != Self->_MutexEvent, "invariant"); if (TryFast()) { @@ -514,7 +523,7 @@ goto Exeunt; } -void Monitor::IUnlock (bool RelaxAssert) { +void Monitor::IUnlock(bool RelaxAssert) { assert(ILocked(), "invariant"); // Conceptually we need a MEMBAR #storestore|#loadstore barrier or fence immediately // before the store that releases the lock. Crucially, all the stores and loads in the @@ -589,8 +598,8 @@ _EntryList = w->ListNext; // as a diagnostic measure consider setting w->_ListNext = BAD assert(UNS(_OnDeck) == _LBIT, "invariant"); - _OnDeck = w; // pass OnDeck to w. - // w will clear OnDeck once it acquires the outer lock + _OnDeck = w; // pass OnDeck to w. + // w will clear OnDeck once it acquires the outer lock // Another optional optimization ... // For heavily contended locks it's not uncommon that some other @@ -724,7 +733,7 @@ return true; } -int Monitor::IWait (Thread * Self, jlong timo) { +int Monitor::IWait(Thread * Self, jlong timo) { assert(ILocked(), "invariant"); // Phases: @@ -885,7 +894,7 @@ // sneaking or dependence on any any clever invariants or subtle implementation properties // of Mutex-Monitor and instead directly address the underlying design flaw. -void Monitor::lock (Thread * Self) { +void Monitor::lock(Thread * Self) { #ifdef CHECK_UNHANDLED_OOPS // Clear unhandled oops so we get a crash right away. Only clear for non-vm // or GC threads. @@ -895,7 +904,7 @@ #endif // CHECK_UNHANDLED_OOPS debug_only(check_prelock_state(Self)); - assert(_owner != Self , "invariant"); + assert(_owner != Self, "invariant"); assert(_OnDeck != Self->_MutexEvent, "invariant"); if (TryFast()) { @@ -943,7 +952,7 @@ // that is guaranteed not to block while running inside the VM. If this is called with // thread state set to be in VM, the safepoint synchronization code will deadlock! -void Monitor::lock_without_safepoint_check (Thread * Self) { +void Monitor::lock_without_safepoint_check(Thread * Self) { assert(_owner != Self, "invariant"); ILock(Self); assert(_owner == NULL, "invariant"); @@ -983,8 +992,8 @@ } void Monitor::unlock() { - assert(_owner == Thread::current(), "invariant"); - assert(_OnDeck != Thread::current()->_MutexEvent , "invariant"); + assert(_owner == Thread::current(), "invariant"); + assert(_OnDeck != Thread::current()->_MutexEvent, "invariant"); set_owner(NULL); if (_snuck) { assert(SafepointSynchronize::is_at_safepoint() && Thread::current()->is_VM_thread(), "sneak"); @@ -1071,7 +1080,8 @@ IUnlock(false); } -bool Monitor::wait(bool no_safepoint_check, long timeout, bool as_suspend_equivalent) { +bool Monitor::wait(bool no_safepoint_check, long timeout, + bool as_suspend_equivalent) { Thread * const Self = Thread::current(); assert(_owner == Self, "invariant"); assert(ILocked(), "invariant"); @@ -1140,7 +1150,7 @@ assert((UNS(_owner)|UNS(_LockWord.FullWord)|UNS(_EntryList)|UNS(_WaitSet)|UNS(_OnDeck)) == 0, ""); } -void Monitor::ClearMonitor (Monitor * m, const char *name) { +void Monitor::ClearMonitor(Monitor * m, const char *name) { m->_owner = NULL; m->_snuck = false; if (name == NULL) { @@ -1158,7 +1168,7 @@ Monitor::Monitor() { ClearMonitor(this); } -Monitor::Monitor (int Rank, const char * name, bool allow_vm_block) { +Monitor::Monitor(int Rank, const char * name, bool allow_vm_block) { ClearMonitor(this, name); #ifdef ASSERT _allow_vm_block = allow_vm_block; @@ -1170,7 +1180,7 @@ assert((UNS(_owner)|UNS(_LockWord.FullWord)|UNS(_EntryList)|UNS(_WaitSet)|UNS(_OnDeck)) == 0, ""); } -Mutex::Mutex (int Rank, const char * name, bool allow_vm_block) { +Mutex::Mutex(int Rank, const char * name, bool allow_vm_block) { ClearMonitor((Monitor *) this, name); #ifdef ASSERT _allow_vm_block = allow_vm_block; @@ -1247,8 +1257,9 @@ bool Monitor::contains(Monitor* locks, Monitor * lock) { for (; locks != NULL; locks = locks->next()) { - if (locks == lock) + if (locks == lock) { return true; + } } return false; } @@ -1279,7 +1290,7 @@ // link "this" into the owned locks list - #ifdef ASSERT // Thread::_owned_locks is under the same ifdef +#ifdef ASSERT // Thread::_owned_locks is under the same ifdef Monitor* locks = get_least_ranked_lock(new_owner->owned_locks()); // Mutex::set_owner_implementation is a friend of Thread @@ -1312,7 +1323,7 @@ this->_next = new_owner->_owned_locks; new_owner->_owned_locks = this; - #endif +#endif } else { // the thread is releasing this lock @@ -1325,7 +1336,7 @@ _owner = NULL; // set the owner - #ifdef ASSERT +#ifdef ASSERT Monitor *locks = old_owner->owned_locks(); // remove "this" from the owned locks list @@ -1345,7 +1356,7 @@ prev->_next = _next; } _next = NULL; - #endif +#endif } } diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/objectMonitor.cpp --- a/hotspot/src/share/vm/runtime/objectMonitor.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/objectMonitor.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -70,10 +70,10 @@ #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \ { \ - if (DTraceMonitorProbes) { \ + if (DTraceMonitorProbes) { \ DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ HOTSPOT_MONITOR_WAIT(jtid, \ - (monitor), bytes, len, (millis)); \ + (monitor), bytes, len, (millis)); \ } \ } @@ -85,10 +85,10 @@ #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \ { \ - if (DTraceMonitorProbes) { \ + if (DTraceMonitorProbes) { \ DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ - HOTSPOT_MONITOR_##probe(jtid, \ - (uintptr_t)(monitor), bytes, len); \ + HOTSPOT_MONITOR_##probe(jtid, \ + (uintptr_t)(monitor), bytes, len); \ } \ } @@ -278,8 +278,8 @@ void * cur = Atomic::cmpxchg_ptr (Self, &_owner, NULL); if (cur == NULL) { // Either ASSERT _recursions == 0 or explicitly set _recursions = 0. - assert(_recursions == 0 , "invariant"); - assert(_owner == Self, "invariant"); + assert(_recursions == 0, "invariant"); + assert(_owner == Self, "invariant"); // CONSIDER: set or assert OwnerIsThread == 1 return; } @@ -310,20 +310,20 @@ // Note that if we acquire the monitor from an initial spin // we forgo posting JVMTI events and firing DTRACE probes. if (Knob_SpinEarly && TrySpin (Self) > 0) { - assert(_owner == Self , "invariant"); - assert(_recursions == 0 , "invariant"); + assert(_owner == Self, "invariant"); + assert(_recursions == 0, "invariant"); assert(((oop)(object()))->mark() == markOopDesc::encode(this), "invariant"); Self->_Stalled = 0; return; } - assert(_owner != Self , "invariant"); - assert(_succ != Self , "invariant"); - assert(Self->is_Java_thread() , "invariant"); + assert(_owner != Self, "invariant"); + assert(_succ != Self, "invariant"); + assert(Self->is_Java_thread(), "invariant"); JavaThread * jt = (JavaThread *) Self; assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); - assert(jt->thread_state() != _thread_blocked , "invariant"); - assert(this->object() != NULL , "invariant"); + assert(jt->thread_state() != _thread_blocked, "invariant"); + assert(this->object() != NULL, "invariant"); assert(_count >= 0, "invariant"); // Prevent deflation at STW-time. See deflate_idle_monitors() and is_busy(). @@ -361,7 +361,6 @@ if (!ExitSuspendEquivalent(jt)) break; - // // We have acquired the contended monitor, but while we were // waiting another thread suspended us. We don't want to enter // the monitor while suspended because that would surprise the @@ -390,9 +389,9 @@ Self->_Stalled = 0; // Must either set _recursions = 0 or ASSERT _recursions == 0. - assert(_recursions == 0 , "invariant"); - assert(_owner == Self , "invariant"); - assert(_succ != Self , "invariant"); + assert(_recursions == 0, "invariant"); + assert(_owner == Self, "invariant"); + assert(_succ != Self, "invariant"); assert(((oop)(object()))->mark() == markOopDesc::encode(this), "invariant"); // The thread -- now the owner -- is back in vm mode. @@ -434,7 +433,7 @@ // Caveat: TryLock() is not necessarily serializing if it returns failure. // Callers must compensate as needed. -int ObjectMonitor::TryLock (Thread * Self) { +int ObjectMonitor::TryLock(Thread * Self) { void * own = _owner; if (own != NULL) return 0; if (Atomic::cmpxchg_ptr (Self, &_owner, NULL) == NULL) { @@ -451,16 +450,16 @@ return -1; } -void NOINLINE ObjectMonitor::EnterI (TRAPS) { +void NOINLINE ObjectMonitor::EnterI(TRAPS) { Thread * const Self = THREAD; assert(Self->is_Java_thread(), "invariant"); - assert(((JavaThread *) Self)->thread_state() == _thread_blocked , "invariant"); + assert(((JavaThread *) Self)->thread_state() == _thread_blocked, "invariant"); // Try the lock - TATAS if (TryLock (Self) > 0) { - assert(_succ != Self , "invariant"); - assert(_owner == Self , "invariant"); - assert(_Responsible != Self , "invariant"); + assert(_succ != Self, "invariant"); + assert(_owner == Self, "invariant"); + assert(_Responsible != Self, "invariant"); return; } @@ -474,16 +473,16 @@ // effects. if (TrySpin (Self) > 0) { - assert(_owner == Self , "invariant"); - assert(_succ != Self , "invariant"); - assert(_Responsible != Self , "invariant"); + assert(_owner == Self, "invariant"); + assert(_succ != Self, "invariant"); + assert(_Responsible != Self, "invariant"); return; } // The Spin failed -- Enqueue and park the thread ... - assert(_succ != Self , "invariant"); - assert(_owner != Self , "invariant"); - assert(_Responsible != Self , "invariant"); + assert(_succ != Self, "invariant"); + assert(_owner != Self, "invariant"); + assert(_Responsible != Self, "invariant"); // Enqueue "Self" on ObjectMonitor's _cxq. // @@ -493,7 +492,6 @@ // Java objects. This would avoid awkward lifecycle and liveness issues, // as well as eliminate a subset of ABA issues. // TODO: eliminate ObjectWaiter and enqueue either Threads or Events. - // ObjectWaiter node(Self); Self->_ParkEvent->reset(); @@ -512,9 +510,9 @@ // Interference - the CAS failed because _cxq changed. Just retry. // As an optional optimization we retry the lock. if (TryLock (Self) > 0) { - assert(_succ != Self , "invariant"); - assert(_owner == Self , "invariant"); - assert(_Responsible != Self , "invariant"); + assert(_succ != Self, "invariant"); + assert(_owner == Self, "invariant"); + assert(_Responsible != Self, "invariant"); return; } } @@ -629,8 +627,8 @@ // The head of cxq is volatile but the interior is stable. // In addition, Self.TState is stable. - assert(_owner == Self , "invariant"); - assert(object() != NULL , "invariant"); + assert(_owner == Self, "invariant"); + assert(object() != NULL, "invariant"); // I'd like to write: // guarantee (((oop)(object()))->mark() == markOopDesc::encode(this), "invariant") ; // but as we're at a safepoint that's not safe. @@ -700,12 +698,12 @@ // Knob_Reset and Knob_SpinAfterFutile support and restructuring the // loop accordingly. -void NOINLINE ObjectMonitor::ReenterI (Thread * Self, ObjectWaiter * SelfNode) { - assert(Self != NULL , "invariant"); - assert(SelfNode != NULL , "invariant"); - assert(SelfNode->_thread == Self , "invariant"); - assert(_waiters > 0 , "invariant"); - assert(((oop)(object()))->mark() == markOopDesc::encode(this) , "invariant"); +void NOINLINE ObjectMonitor::ReenterI(Thread * Self, ObjectWaiter * SelfNode) { + assert(Self != NULL, "invariant"); + assert(SelfNode != NULL, "invariant"); + assert(SelfNode->_thread == Self, "invariant"); + assert(_waiters > 0, "invariant"); + assert(((oop)(object()))->mark() == markOopDesc::encode(this), "invariant"); assert(((JavaThread *)Self)->thread_state() != _thread_blocked, "invariant"); JavaThread * jt = (JavaThread *) Self; @@ -792,8 +790,7 @@ // after the thread acquires the lock in ::enter(). Equally, we could defer // unlinking the thread until ::exit()-time. -void ObjectMonitor::UnlinkAfterAcquire (Thread * Self, ObjectWaiter * SelfNode) -{ +void ObjectMonitor::UnlinkAfterAcquire(Thread *Self, ObjectWaiter *SelfNode) { assert(_owner == Self, "invariant"); assert(SelfNode->_thread == Self, "invariant"); @@ -980,7 +977,7 @@ // Instead, I use release_store(), which is implemented as just a simple // ST on x64, x86 and SPARC. OrderAccess::release_store_ptr(&_owner, NULL); // drop the lock - OrderAccess::storeload(); // See if we need to wake a successor + OrderAccess::storeload(); // See if we need to wake a successor if ((intptr_t(_EntryList)|intptr_t(_cxq)) == 0 || _succ != NULL) { TEVENT(Inflated exit - simple egress); return; @@ -1017,7 +1014,6 @@ // The dropped lock needs to become visible to the spinner, and then // the acquisition of the lock by the spinner must become visible to // the exiting thread). - // // It appears that an heir-presumptive (successor) must be made ready. // Only the current lock owner can manipulate the EntryList or @@ -1081,7 +1077,7 @@ // This policy ensure that recently-run threads live at the head of EntryList. // Drain _cxq into EntryList - bulk transfer. // First, detach _cxq. - // The following loop is tantamount to: w = swap (&cxq, NULL) + // The following loop is tantamount to: w = swap(&cxq, NULL) w = _cxq; for (;;) { assert(w != NULL, "Invariant"); @@ -1089,7 +1085,7 @@ if (u == w) break; w = u; } - assert(w != NULL , "invariant"); + assert(w != NULL, "invariant"); ObjectWaiter * q = NULL; ObjectWaiter * p; @@ -1103,7 +1099,9 @@ // Append the RATs to the EntryList // TODO: organize EntryList as a CDLL so we can locate the tail in constant-time. ObjectWaiter * Tail; - for (Tail = _EntryList; Tail != NULL && Tail->_next != NULL; Tail = Tail->_next); + for (Tail = _EntryList; Tail != NULL && Tail->_next != NULL; + Tail = Tail->_next) + /* empty */; if (Tail == NULL) { _EntryList = w; } else { @@ -1120,7 +1118,7 @@ // Drain _cxq into EntryList - bulk transfer. // First, detach _cxq. - // The following loop is tantamount to: w = swap (&cxq, NULL) + // The following loop is tantamount to: w = swap(&cxq, NULL) w = _cxq; for (;;) { assert(w != NULL, "Invariant"); @@ -1128,7 +1126,7 @@ if (u == w) break; w = u; } - assert(w != NULL , "invariant"); + assert(w != NULL, "invariant"); ObjectWaiter * q = NULL; ObjectWaiter * p; @@ -1174,7 +1172,7 @@ // Drain _cxq into EntryList - bulk transfer. // First, detach _cxq. - // The following loop is tantamount to: w = swap (&cxq, NULL) + // The following loop is tantamount to: w = swap(&cxq, NULL) for (;;) { assert(w != NULL, "Invariant"); ObjectWaiter * u = (ObjectWaiter *) Atomic::cmpxchg_ptr(NULL, &_cxq, w); @@ -1183,8 +1181,8 @@ } TEVENT(Inflated exit - drain cxq into EntryList); - assert(w != NULL , "invariant"); - assert(_EntryList == NULL , "invariant"); + assert(w != NULL, "invariant"); + assert(_EntryList == NULL, "invariant"); // Convert the LIFO SLL anchored by _cxq into a DLL. // The list reorganization step operates in O(LENGTH(w)) time. @@ -1277,7 +1275,7 @@ // decreased. - Dave -bool ObjectMonitor::ExitSuspendEquivalent (JavaThread * jSelf) { +bool ObjectMonitor::ExitSuspendEquivalent(JavaThread * jSelf) { const int Mode = Knob_FastHSSEC; if (Mode && !jSelf->is_external_suspend()) { assert(jSelf->is_suspend_equivalent(), "invariant"); @@ -1292,7 +1290,7 @@ } -void ObjectMonitor::ExitEpilog (Thread * Self, ObjectWaiter * Wakee) { +void ObjectMonitor::ExitEpilog(Thread * Self, ObjectWaiter * Wakee) { assert(_owner == Self, "invariant"); // Exit protocol: @@ -1346,7 +1344,7 @@ if (THREAD != _owner) { if (THREAD->is_lock_owned ((address)_owner)) { assert(_recursions == 0, "internal state error"); - _owner = THREAD; /* Convert from basiclock addr to Thread addr */ + _owner = THREAD; // Convert from basiclock addr to Thread addr _recursions = 0; OwnerIsThread = 1; } @@ -1381,18 +1379,18 @@ // which use this (which is why we don't put this into check_slow and // call it with a CHECK argument). -#define CHECK_OWNER() \ - do { \ - if (THREAD != _owner) { \ - if (THREAD->is_lock_owned((address) _owner)) { \ - _owner = THREAD; /* Convert from basiclock addr to Thread addr */ \ - _recursions = 0; \ - OwnerIsThread = 1; \ - } else { \ - TEVENT(Throw IMSX); \ - THROW(vmSymbols::java_lang_IllegalMonitorStateException()); \ - } \ - } \ +#define CHECK_OWNER() \ + do { \ + if (THREAD != _owner) { \ + if (THREAD->is_lock_owned((address) _owner)) { \ + _owner = THREAD; /* Convert from basiclock addr to Thread addr */ \ + _recursions = 0; \ + OwnerIsThread = 1; \ + } else { \ + TEVENT(Throw IMSX); \ + THROW(vmSymbols::java_lang_IllegalMonitorStateException()); \ + } \ + } \ } while (false) // check_slow() is a misnomer. It's called to simply to throw an IMSX exception. @@ -1404,9 +1402,9 @@ THROW_MSG(vmSymbols::java_lang_IllegalMonitorStateException(), "current thread not owner"); } -static int Adjust (volatile int * adr, int dx) { +static int Adjust(volatile int * adr, int dx) { int v; - for (v = *adr; Atomic::cmpxchg(v + dx, adr, v) != v; v = *adr); + for (v = *adr; Atomic::cmpxchg(v + dx, adr, v) != v; v = *adr) /* empty */; return v; } @@ -1517,8 +1515,7 @@ if (interruptible && (Thread::is_interrupted(THREAD, false) || HAS_PENDING_EXCEPTION)) { // Intentionally empty - } else - if (node._notified == 0) { + } else if (node._notified == 0) { if (millis <= 0) { Self->_ParkEvent->park(); } else { @@ -1534,7 +1531,6 @@ } // Exit thread safepoint: transition _thread_blocked -> _thread_in_vm - // Node may be on the WaitSet, the EntryList (or cxq), or in transition // from the WaitSet to the EntryList. // See if we need to remove Node from the WaitSet. @@ -1625,7 +1621,7 @@ // want residual elements associated with this thread left on any lists. guarantee(node.TState == ObjectWaiter::TS_RUN, "invariant"); assert(_owner == Self, "invariant"); - assert(_succ != Self , "invariant"); + assert(_succ != Self, "invariant"); } // OSThreadWaitState() jt->set_current_waiting_monitor(NULL); @@ -1635,8 +1631,8 @@ _waiters--; // decrement the number of waiters // Verify a few postconditions - assert(_owner == Self , "invariant"); - assert(_succ != Self , "invariant"); + assert(_owner == Self, "invariant"); + assert(_succ != Self, "invariant"); assert(((oop)(object()))->mark() == markOopDesc::encode(this), "invariant"); if (SyncFlags & 32) { @@ -1703,8 +1699,7 @@ iterator->_prev = NULL; _EntryList = iterator; } - } else - if (Policy == 1) { // append to EntryList + } else if (Policy == 1) { // append to EntryList if (List == NULL) { iterator->_next = iterator->_prev = NULL; _EntryList = iterator; @@ -1713,14 +1708,13 @@ // the EntryList. We can make tail access constant-time by converting to // a CDLL instead of using our current DLL. ObjectWaiter * Tail; - for (Tail = List; Tail->_next != NULL; Tail = Tail->_next); + for (Tail = List; Tail->_next != NULL; Tail = Tail->_next) /* empty */; assert(Tail != NULL && Tail->_next == NULL, "invariant"); Tail->_next = iterator; iterator->_prev = Tail; iterator->_next = NULL; } - } else - if (Policy == 2) { // prepend to cxq + } else if (Policy == 2) { // prepend to cxq // prepend to cxq if (List == NULL) { iterator->_next = iterator->_prev = NULL; @@ -1735,8 +1729,7 @@ } } } - } else - if (Policy == 3) { // append to cxq + } else if (Policy == 3) { // append to cxq iterator->TState = ObjectWaiter::TS_CXQ; for (;;) { ObjectWaiter * Tail; @@ -1832,8 +1825,7 @@ iterator->_prev = NULL; _EntryList = iterator; } - } else - if (Policy == 1) { // append to EntryList + } else if (Policy == 1) { // append to EntryList if (List == NULL) { iterator->_next = iterator->_prev = NULL; _EntryList = iterator; @@ -1842,14 +1834,13 @@ // the EntryList. We can make tail access constant-time by converting to // a CDLL instead of using our current DLL. ObjectWaiter * Tail; - for (Tail = List; Tail->_next != NULL; Tail = Tail->_next); + for (Tail = List; Tail->_next != NULL; Tail = Tail->_next) /* empty */; assert(Tail != NULL && Tail->_next == NULL, "invariant"); Tail->_next = iterator; iterator->_prev = Tail; iterator->_next = NULL; } - } else - if (Policy == 2) { // prepend to cxq + } else if (Policy == 2) { // prepend to cxq // prepend to cxq iterator->TState = ObjectWaiter::TS_CXQ; for (;;) { @@ -1859,8 +1850,7 @@ break; } } - } else - if (Policy == 3) { // append to cxq + } else if (Policy == 3) { // append to cxq iterator->TState = ObjectWaiter::TS_CXQ; for (;;) { ObjectWaiter * Tail; @@ -1969,7 +1959,6 @@ // situation is not dire. The state is benign -- there's no need to add // hysteresis control to damp the transition rate between spinning and // not spinning. -// intptr_t ObjectMonitor::SpinCallbackArgument = 0; int (*ObjectMonitor::SpinCallbackFunction)(intptr_t, int) = NULL; @@ -1977,8 +1966,7 @@ // Spinning: Fixed frequency (100%), vary duration -int ObjectMonitor::TrySpin_VaryDuration (Thread * Self) { - +int ObjectMonitor::TrySpin_VaryDuration(Thread * Self) { // Dumb, brutal spin. Good for comparative measurements against adaptive spinning. int ctr = Knob_FixedSpin; if (ctr != 0) { @@ -2241,7 +2229,7 @@ // Spinning, in general, is probabilistic anyway. -int ObjectMonitor::NotRunnable (Thread * Self, Thread * ox) { +int ObjectMonitor::NotRunnable(Thread * Self, Thread * ox) { // Check either OwnerIsThread or ox->TypeTag == 2BAD. if (!OwnerIsThread) return 0; @@ -2378,8 +2366,16 @@ InitializationCompleted = 1; if (UsePerfData) { EXCEPTION_MARK; - #define NEWPERFCOUNTER(n) {n = PerfDataManager::create_counter(SUN_RT, #n, PerfData::U_Events,CHECK); } - #define NEWPERFVARIABLE(n) {n = PerfDataManager::create_variable(SUN_RT, #n, PerfData::U_Events,CHECK); } +#define NEWPERFCOUNTER(n) \ + { \ + n = PerfDataManager::create_counter(SUN_RT, #n, PerfData::U_Events, \ + CHECK); \ + } +#define NEWPERFVARIABLE(n) \ + { \ + n = PerfDataManager::create_variable(SUN_RT, #n, PerfData::U_Events, \ + CHECK); \ + } NEWPERFCOUNTER(_sync_Inflations); NEWPERFCOUNTER(_sync_Deflations); NEWPERFCOUNTER(_sync_ContendedLockAttempts); @@ -2398,7 +2394,8 @@ NEWPERFCOUNTER(_sync_MonInCirculation); NEWPERFCOUNTER(_sync_MonScavenged); NEWPERFVARIABLE(_sync_MonExtant); - #undef NEWPERFCOUNTER +#undef NEWPERFCOUNTER +#undef NEWPERFVARIABLE } } @@ -2416,7 +2413,7 @@ } -static char * kvGet (char * kvList, const char * Key) { +static char * kvGet(char * kvList, const char * Key) { if (kvList == NULL) return NULL; size_t n = strlen(Key); char * Search; @@ -2429,7 +2426,7 @@ return NULL; } -static int kvGetInt (char * kvList, const char * Key, int Default) { +static int kvGetInt(char * kvList, const char * Key, int Default) { char * v = kvGet(kvList, Key); int rslt = v ? ::strtol(v, NULL, 0) : Default; if (Knob_ReportSettings && v != NULL) { @@ -2442,7 +2439,7 @@ void ObjectMonitor::DeferredInitialize() { if (InitDone > 0) return; if (Atomic::cmpxchg (-1, &InitDone, 0) != 0) { - while (InitDone != 1); + while (InitDone != 1) /* empty */; return; } @@ -2466,7 +2463,7 @@ if (*p == ':') *p = 0; } - #define SETKNOB(x) { Knob_##x = kvGetInt (knobs, #x, Knob_##x); } + #define SETKNOB(x) { Knob_##x = kvGetInt(knobs, #x, Knob_##x); } SETKNOB(ReportSettings); SETKNOB(Verbose); SETKNOB(VerifyInUse); diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/objectMonitor.hpp --- a/hotspot/src/share/vm/runtime/objectMonitor.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/objectMonitor.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -87,18 +87,18 @@ public: // TODO-FIXME: the "offset" routines should return a type of off_t instead of int ... // ByteSize would also be an appropriate type. - static int header_offset_in_bytes() { return offset_of(ObjectMonitor, _header); } - static int object_offset_in_bytes() { return offset_of(ObjectMonitor, _object); } - static int owner_offset_in_bytes() { return offset_of(ObjectMonitor, _owner); } - static int count_offset_in_bytes() { return offset_of(ObjectMonitor, _count); } + static int header_offset_in_bytes() { return offset_of(ObjectMonitor, _header); } + static int object_offset_in_bytes() { return offset_of(ObjectMonitor, _object); } + static int owner_offset_in_bytes() { return offset_of(ObjectMonitor, _owner); } + static int count_offset_in_bytes() { return offset_of(ObjectMonitor, _count); } static int recursions_offset_in_bytes() { return offset_of(ObjectMonitor, _recursions); } - static int cxq_offset_in_bytes() { return offset_of(ObjectMonitor, _cxq); } - static int succ_offset_in_bytes() { return offset_of(ObjectMonitor, _succ); } - static int EntryList_offset_in_bytes() { return offset_of(ObjectMonitor, _EntryList); } - static int FreeNext_offset_in_bytes() { return offset_of(ObjectMonitor, FreeNext); } - static int WaitSet_offset_in_bytes() { return offset_of(ObjectMonitor, _WaitSet); } + static int cxq_offset_in_bytes() { return offset_of(ObjectMonitor, _cxq); } + static int succ_offset_in_bytes() { return offset_of(ObjectMonitor, _succ); } + static int EntryList_offset_in_bytes() { return offset_of(ObjectMonitor, _EntryList); } + static int FreeNext_offset_in_bytes() { return offset_of(ObjectMonitor, FreeNext); } + static int WaitSet_offset_in_bytes() { return offset_of(ObjectMonitor, _WaitSet); } static int Responsible_offset_in_bytes() { return offset_of(ObjectMonitor, _Responsible); } - static int Spinner_offset_in_bytes() { return offset_of(ObjectMonitor, _Spinner); } + static int Spinner_offset_in_bytes() { return offset_of(ObjectMonitor, _Spinner); } public: // Eventually we'll make provisions for multiple callbacks, but @@ -140,8 +140,8 @@ ObjectMonitor() { _header = NULL; _count = 0; - _waiters = 0, - _recursions = 0; + _waiters = 0; + _recursions = 0; _object = NULL; _owner = NULL; _WaitSet = NULL; @@ -240,7 +240,7 @@ volatile markOop _header; // displaced object header word - mark void* volatile _object; // backward object pointer - strong root - double SharingPad[1]; // temp to reduce false sharing + double SharingPad[1]; // temp to reduce false sharing // All the following fields must be machine word aligned // The VM assumes write ordering wrt these fields, which can be @@ -248,25 +248,25 @@ protected: // protected for jvmtiRawMonitor void * volatile _owner; // pointer to owning thread OR BasicLock - volatile jlong _previous_owner_tid; // thread id of the previous owner of the monitor + volatile jlong _previous_owner_tid; // thread id of the previous owner of the monitor volatile intptr_t _recursions; // recursion count, 0 for first entry private: - int OwnerIsThread; // _owner is (Thread *) vs SP/BasicLock - ObjectWaiter * volatile _cxq; // LL of recently-arrived threads blocked on entry. - // The list is actually composed of WaitNodes, acting - // as proxies for Threads. + int OwnerIsThread; // _owner is (Thread *) vs SP/BasicLock + ObjectWaiter * volatile _cxq; // LL of recently-arrived threads blocked on entry. + // The list is actually composed of WaitNodes, acting + // as proxies for Threads. protected: - ObjectWaiter * volatile _EntryList; // Threads blocked on entry or reentry. + ObjectWaiter * volatile _EntryList; // Threads blocked on entry or reentry. private: Thread * volatile _succ; // Heir presumptive thread - used for futile wakeup throttling Thread * volatile _Responsible; - int _PromptDrain; // rqst to drain cxq into EntryList ASAP + int _PromptDrain; // rqst to drain cxq into EntryList ASAP - volatile int _Spinner; // for exit->spinner handoff optimization - volatile int _SpinFreq; // Spin 1-out-of-N attempts: success rate + volatile int _Spinner; // for exit->spinner handoff optimization + volatile int _SpinFreq; // Spin 1-out-of-N attempts: success rate volatile int _SpinClock; volatile int _SpinDuration; - volatile intptr_t _SpinState; // MCS/CLH list of spinners + volatile intptr_t _SpinState; // MCS/CLH list of spinners // TODO-FIXME: _count, _waiters and _recursions should be of // type int, or int32_t but not intptr_t. There's no reason @@ -284,8 +284,8 @@ volatile int _WaitSetLock; // protects Wait Queue - simple spinlock public: - int _QMix; // Mixed prepend queue discipline - ObjectMonitor * FreeNext; // Free list linkage + int _QMix; // Mixed prepend queue discipline + ObjectMonitor * FreeNext; // Free list linkage intptr_t StatA, StatsB; public: @@ -328,9 +328,17 @@ }; #undef TEVENT -#define TEVENT(nom) {if (SyncVerbose) FEVENT(nom); } +#define TEVENT(nom) { if (SyncVerbose) FEVENT(nom); } -#define FEVENT(nom) { static volatile int ctr = 0; int v = ++ctr; if ((v & (v-1)) == 0) { ::printf (#nom " : %d \n", v); ::fflush(stdout); }} +#define FEVENT(nom) \ + { \ + static volatile int ctr = 0; \ + int v = ++ctr; \ + if ((v & (v - 1)) == 0) { \ + ::printf(#nom " : %d\n", v); \ + ::fflush(stdout); \ + } \ + } #undef TEVENT #define TEVENT(nom) {;} diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/sharedRuntime.hpp --- a/hotspot/src/share/vm/runtime/sharedRuntime.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/sharedRuntime.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -271,35 +271,33 @@ // used by native wrappers to reenable yellow if overflow happened in native code static void reguard_yellow_pages(); - /** - * Fill in the "X cannot be cast to a Y" message for ClassCastException - * - * @param thr the current thread - * @param name the name of the class of the object attempted to be cast - * @return the dynamically allocated exception message (must be freed - * by the caller using a resource mark) - * - * BCP must refer to the current 'checkcast' opcode for the frame - * on top of the stack. - * The caller (or one of it's callers) must use a ResourceMark - * in order to correctly free the result. - */ + // Fill in the "X cannot be cast to a Y" message for ClassCastException + // + // @param thr the current thread + // @param name the name of the class of the object attempted to be cast + // @return the dynamically allocated exception message (must be freed + // by the caller using a resource mark) + // + // BCP must refer to the current 'checkcast' opcode for the frame + // on top of the stack. + // The caller (or one of it's callers) must use a ResourceMark + // in order to correctly free the result. + // static char* generate_class_cast_message(JavaThread* thr, const char* name); - /** - * Fill in the "X cannot be cast to a Y" message for ClassCastException - * - * @param name the name of the class of the object attempted to be cast - * @param klass the name of the target klass attempt - * @param gripe the specific kind of problem being reported - * @return the dynamically allocated exception message (must be freed - * by the caller using a resource mark) - * - * This version does not require access the frame, so it can be called - * from interpreted code - * The caller (or one of it's callers) must use a ResourceMark - * in order to correctly free the result. - */ + // Fill in the "X cannot be cast to a Y" message for ClassCastException + // + // @param name the name of the class of the object attempted to be cast + // @param klass the name of the target klass attempt + // @param gripe the specific kind of problem being reported + // @return the dynamically allocated exception message (must be freed + // by the caller using a resource mark) + // + // This version does not require access the frame, so it can be called + // from interpreted code + // The caller (or one of it's callers) must use a ResourceMark + // in order to correctly free the result. + // static char* generate_class_cast_message(const char* name, const char* klass, const char* gripe = " cannot be cast to "); @@ -422,17 +420,17 @@ // pointer to the C heap storage. This pointer is the return value from // OSR_migration_begin. - static intptr_t* OSR_migration_begin( JavaThread *thread); + static intptr_t* OSR_migration_begin(JavaThread *thread); // OSR_migration_end is a trivial routine. It is called after the compiled // method has extracted the jvm state from the C heap that OSR_migration_begin // created. It's entire job is to simply free this storage. - static void OSR_migration_end ( intptr_t* buf); + static void OSR_migration_end(intptr_t* buf); // Convert a sig into a calling convention register layout // and find interesting things about it. static VMRegPair* find_callee_arguments(Symbol* sig, bool has_receiver, bool has_appendix, int *arg_size); - static VMReg name_for_receiver(); + static VMReg name_for_receiver(); // "Top of Stack" slots that may be unused by the calling convention but must // otherwise be preserved. @@ -691,7 +689,7 @@ static bool contains(CodeBlob* b); #ifndef PRODUCT static void print_statistics(); -#endif /* PRODUCT */ +#endif // PRODUCT }; diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/synchronizer.cpp --- a/hotspot/src/share/vm/runtime/synchronizer.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/synchronizer.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -57,7 +57,6 @@ // for instance. If you make changes here, make sure to modify the // interpreter, and both C1 and C2 fast-path inline locking code emission. // -// // ----------------------------------------------------------------------------- #ifdef DTRACE_ENABLED @@ -77,10 +76,10 @@ #define DTRACE_MONITOR_WAIT_PROBE(monitor, obj, thread, millis) \ { \ - if (DTraceMonitorProbes) { \ + if (DTraceMonitorProbes) { \ DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ HOTSPOT_MONITOR_WAIT(jtid, \ - (uintptr_t)(monitor), bytes, len, (millis)); \ + (uintptr_t)(monitor), bytes, len, (millis)); \ } \ } @@ -88,10 +87,10 @@ #define DTRACE_MONITOR_PROBE(probe, monitor, obj, thread) \ { \ - if (DTraceMonitorProbes) { \ + if (DTraceMonitorProbes) { \ DTRACE_MONITOR_PROBE_COMMON(obj, thread); \ HOTSPOT_MONITOR_PROBE_##probe(jtid, /* probe = waited */ \ - (uintptr_t)(monitor), bytes, len); \ + (uintptr_t)(monitor), bytes, len); \ } \ } @@ -116,8 +115,8 @@ ObjectMonitor * volatile ObjectSynchronizer::gOmInUseList = NULL; int ObjectSynchronizer::gOmInUseCount = 0; static volatile intptr_t ListLock = 0; // protects global monitor free-list cache -static volatile int MonitorFreeCount = 0; // # on gFreeList -static volatile int MonitorPopulation = 0; // # Extant -- in circulation +static volatile int MonitorFreeCount = 0; // # on gFreeList +static volatile int MonitorPopulation = 0; // # Extant -- in circulation #define CHAINMARKER (cast_to_oop(-1)) // ----------------------------------------------------------------------------- @@ -127,7 +126,8 @@ // if the following function is changed. The implementation is // extremely sensitive to race condition. Be careful. -void ObjectSynchronizer::fast_enter(Handle obj, BasicLock* lock, bool attempt_rebias, TRAPS) { +void ObjectSynchronizer::fast_enter(Handle obj, BasicLock* lock, + bool attempt_rebias, TRAPS) { if (UseBiasedLocking) { if (!SafepointSynchronize::is_at_safepoint()) { BiasedLocking::Condition cond = BiasedLocking::revoke_and_rebias(obj, attempt_rebias, THREAD); @@ -198,8 +198,8 @@ return; } // Fall through to inflate() ... - } else - if (mark->has_locker() && THREAD->is_lock_owned((address)mark->locker())) { + } else if (mark->has_locker() && + THREAD->is_lock_owned((address)mark->locker())) { assert(lock != mark->locker(), "must not re-lock the same lock"); assert(lock != (BasicLock*)obj->mark(), "don't relock with same BasicLock"); lock->set_displaced_header(NULL); @@ -261,7 +261,7 @@ // ----------------------------------------------------------------------------- // JNI locks on java objects // NOTE: must use heavy weight monitor to handle jni monitor enter -void ObjectSynchronizer::jni_enter(Handle obj, TRAPS) { // possible entry from jni enter +void ObjectSynchronizer::jni_enter(Handle obj, TRAPS) { // the current locking is from JNI instead of Java code TEVENT(jni_enter); if (UseBiasedLocking) { @@ -349,7 +349,7 @@ return dtrace_waited_probe(monitor, obj, THREAD); } -void ObjectSynchronizer::waitUninterruptibly (Handle obj, jlong millis, TRAPS) { +void ObjectSynchronizer::waitUninterruptibly(Handle obj, jlong millis, TRAPS) { if (UseBiasedLocking) { BiasedLocking::revoke_and_rebias(obj, false, THREAD); assert(!obj->mark()->has_bias_pattern(), "biases should be revoked by now"); @@ -426,7 +426,7 @@ static int MonitorScavengeThreshold = 1000000; static volatile int ForceMonitorScavenge = 0; // Scavenge required and pending -static markOop ReadStableMark (oop obj) { +static markOop ReadStableMark(oop obj) { markOop mark = obj->mark(); if (!mark->is_being_inflated()) { return mark; // normal fast-path return @@ -510,7 +510,6 @@ // result in hashtable collisions and reduced hashtable efficiency. // There are simple ways to "diffuse" the middle address bits over the // generated hashCode values: -// static inline intptr_t get_next_hash(Thread * Self, oop obj) { intptr_t value = 0; @@ -520,21 +519,17 @@ // On MP system we'll have lots of RW access to a global, so the // mechanism induces lots of coherency traffic. value = os::random(); - } else - if (hashCode == 1) { + } else if (hashCode == 1) { // This variation has the property of being stable (idempotent) // between STW operations. This can be useful in some of the 1-0 // synchronization schemes. intptr_t addrBits = cast_from_oop(obj) >> 3; value = addrBits ^ (addrBits >> 5) ^ GVars.stwRandom; - } else - if (hashCode == 2) { + } else if (hashCode == 2) { value = 1; // for sensitivity testing - } else - if (hashCode == 3) { + } else if (hashCode == 3) { value = ++GVars.hcSequence; - } else - if (hashCode == 4) { + } else if (hashCode == 4) { value = cast_from_oop(obj); } else { // Marsaglia's xor-shift scheme with thread-specific state @@ -557,8 +552,8 @@ TEVENT(hashCode: GENERATE); return value; } -// -intptr_t ObjectSynchronizer::FastHashCode (Thread * Self, oop obj) { + +intptr_t ObjectSynchronizer::FastHashCode(Thread * Self, oop obj) { if (UseBiasedLocking) { // NOTE: many places throughout the JVM do not expect a safepoint // to be taken here, in particular most operations on perm gen @@ -592,7 +587,7 @@ ObjectMonitor* monitor = NULL; markOop temp, test; intptr_t hash; - markOop mark = ReadStableMark (obj); + markOop mark = ReadStableMark(obj); // object should remain ineligible for biased locking assert(!mark->has_bias_pattern(), "invariant"); @@ -706,7 +701,7 @@ // The caller must beware this method can revoke bias, and // revocation can result in a safepoint. assert(!SafepointSynchronize::is_at_safepoint(), "invariant"); - assert(self->thread_state() != _thread_blocked , "invariant"); + assert(self->thread_state() != _thread_blocked, "invariant"); // Possible mark states: neutral, biased, stack-locked, inflated @@ -841,7 +836,6 @@ // -- unassigned and on a thread's private omFreeList // -- assigned to an object. The object is inflated and the mark refers // to the objectmonitor. -// // Constraining monitor pool growth via MonitorBound ... @@ -859,9 +853,8 @@ // See also: GuaranteedSafepointInterval // // The current implementation uses asynchronous VM operations. -// -static void InduceScavenge (Thread * Self, const char * Whence) { +static void InduceScavenge(Thread * Self, const char * Whence) { // Induce STW safepoint to trim monitors // Ultimately, this results in a call to deflate_idle_monitors() in the near future. // More precisely, trigger an asynchronous STW safepoint as the number @@ -886,7 +879,7 @@ } } -void ObjectSynchronizer::verifyInUse (Thread *Self) { +void ObjectSynchronizer::verifyInUse(Thread *Self) { ObjectMonitor* mid; int inusetally = 0; for (mid = Self->omInUseList; mid != NULL; mid = mid->FreeNext) { @@ -901,7 +894,7 @@ assert(freetally == Self->omFreeCount, "free count off"); } -ObjectMonitor * NOINLINE ObjectSynchronizer::omAlloc (Thread * Self) { +ObjectMonitor * NOINLINE ObjectSynchronizer::omAlloc(Thread * Self) { // A large MAXPRIVATE value reduces both list lock contention // and list coherency traffic, but also tends to increase the // number of objectMonitors in circulation as well as the STW @@ -1032,9 +1025,9 @@ // omRelease is to return a monitor to the free list after a CAS // attempt failed. This doesn't allow unbounded #s of monitors to // accumulate on a thread's free list. -// -void ObjectSynchronizer::omRelease (Thread * Self, ObjectMonitor * m, bool fromPerThreadAlloc) { +void ObjectSynchronizer::omRelease(Thread * Self, ObjectMonitor * m, + bool fromPerThreadAlloc) { guarantee(m->object() == NULL, "invariant"); // Remove from omInUseList @@ -1086,7 +1079,7 @@ // be not inopportune interleavings between omFlush() and the scavenge // operator. -void ObjectSynchronizer::omFlush (Thread * Self) { +void ObjectSynchronizer::omFlush(Thread * Self) { ObjectMonitor * List = Self->omFreeList; // Null-terminated SLL Self->omFreeList = NULL; ObjectMonitor * Tail = NULL; @@ -1152,7 +1145,8 @@ // multiple locks occupy the same $ line. Padding might be appropriate. -ObjectMonitor * NOINLINE ObjectSynchronizer::inflate (Thread * Self, oop object) { +ObjectMonitor * NOINLINE ObjectSynchronizer::inflate(Thread * Self, + oop object) { // Inflate mutates the heap ... // Relaxing assertion for bug 6320749. assert(Universe::verify_in_progress() || @@ -1373,7 +1367,6 @@ // typically drives the scavenge rate. Large heaps can mean infrequent GC, // which in turn can mean large(r) numbers of objectmonitors in circulation. // This is an unfortunate aspect of this design. -// enum ManifestConstants { ClearResponsibleAtSTW = 0, @@ -1383,7 +1376,8 @@ // Deflate a single monitor if not in use // Return true if deflated, false if in use bool ObjectSynchronizer::deflate_monitor(ObjectMonitor* mid, oop obj, - ObjectMonitor** freeHeadp, ObjectMonitor** freeTailp) { + ObjectMonitor** freeHeadp, + ObjectMonitor** freeTailp) { bool deflated; // Normal case ... The monitor is associated with obj. guarantee(obj->mark() == markOopDesc::encode(mid), "invariant"); @@ -1427,7 +1421,8 @@ // Caller acquires ListLock int ObjectSynchronizer::walk_monitor_list(ObjectMonitor** listheadp, - ObjectMonitor** freeHeadp, ObjectMonitor** freeTailp) { + ObjectMonitor** freeHeadp, + ObjectMonitor** freeTailp) { ObjectMonitor* mid; ObjectMonitor* next; ObjectMonitor* curmidinuse = NULL; diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/synchronizer.hpp --- a/hotspot/src/share/vm/runtime/synchronizer.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/synchronizer.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -52,25 +52,26 @@ // assembly copies of these routines. Please keep them synchronized. // // attempt_rebias flag is used by UseBiasedLocking implementation - static void fast_enter (Handle obj, BasicLock* lock, bool attempt_rebias, TRAPS); - static void fast_exit (oop obj, BasicLock* lock, Thread* THREAD); + static void fast_enter(Handle obj, BasicLock* lock, bool attempt_rebias, + TRAPS); + static void fast_exit(oop obj, BasicLock* lock, Thread* THREAD); // WARNING: They are ONLY used to handle the slow cases. They should // only be used when the fast cases failed. Use of these functions // without previous fast case check may cause fatal error. - static void slow_enter (Handle obj, BasicLock* lock, TRAPS); - static void slow_exit (oop obj, BasicLock* lock, Thread* THREAD); + static void slow_enter(Handle obj, BasicLock* lock, TRAPS); + static void slow_exit(oop obj, BasicLock* lock, Thread* THREAD); // Used only to handle jni locks or other unmatched monitor enter/exit // Internally they will use heavy weight monitor. - static void jni_enter (Handle obj, TRAPS); + static void jni_enter(Handle obj, TRAPS); static bool jni_try_enter(Handle obj, Thread* THREAD); // Implements Unsafe.tryMonitorEnter - static void jni_exit (oop obj, Thread* THREAD); + static void jni_exit(oop obj, Thread* THREAD); // Handle all interpreter, compiler and jni cases - static int wait (Handle obj, jlong millis, TRAPS); - static void notify (Handle obj, TRAPS); - static void notifyall (Handle obj, TRAPS); + static int wait(Handle obj, jlong millis, TRAPS); + static void notify(Handle obj, TRAPS); + static void notifyall(Handle obj, TRAPS); // Special internal-use-only method for use by JVM infrastructure // that needs to wait() on a java-level object but that can't risk @@ -80,13 +81,14 @@ // used by classloading to free classloader object lock, // wait on an internal lock, and reclaim original lock // with original recursion count - static intptr_t complete_exit (Handle obj, TRAPS); - static void reenter (Handle obj, intptr_t recursion, TRAPS); + static intptr_t complete_exit(Handle obj, TRAPS); + static void reenter (Handle obj, intptr_t recursion, TRAPS); // thread-specific and global objectMonitor free list accessors static void verifyInUse(Thread * Self); static ObjectMonitor * omAlloc(Thread * Self); - static void omRelease(Thread * Self, ObjectMonitor * m, bool FromPerThreadAlloc); + static void omRelease(Thread * Self, ObjectMonitor * m, + bool FromPerThreadAlloc); static void omFlush(Thread * Self); // Inflate light weight monitor to heavy weight monitor @@ -116,7 +118,8 @@ static int walk_monitor_list(ObjectMonitor** listheadp, ObjectMonitor** freeHeadp, ObjectMonitor** freeTailp); - static bool deflate_monitor(ObjectMonitor* mid, oop obj, ObjectMonitor** freeHeadp, + static bool deflate_monitor(ObjectMonitor* mid, oop obj, + ObjectMonitor** freeHeadp, ObjectMonitor** freeTailp); static void oops_do(OopClosure* f); @@ -159,13 +162,13 @@ ~ObjectLocker(); // Monitor behavior - void wait (TRAPS) { ObjectSynchronizer::wait (_obj, 0, CHECK); } // wait forever - void notify_all(TRAPS) { ObjectSynchronizer::notifyall(_obj, CHECK); } - void waitUninterruptibly (TRAPS) { ObjectSynchronizer::waitUninterruptibly (_obj, 0, CHECK); } + void wait(TRAPS) { ObjectSynchronizer::wait(_obj, 0, CHECK); } // wait forever + void notify_all(TRAPS) { ObjectSynchronizer::notifyall(_obj, CHECK); } + void waitUninterruptibly(TRAPS) { ObjectSynchronizer::waitUninterruptibly(_obj, 0, CHECK); } // complete_exit gives up lock completely, returning recursion count // reenter reclaims lock with original recursion count - intptr_t complete_exit(TRAPS) { return ObjectSynchronizer::complete_exit(_obj, CHECK_0); } - void reenter(intptr_t recursion, TRAPS) { ObjectSynchronizer::reenter(_obj, recursion, CHECK); } + intptr_t complete_exit(TRAPS) { return ObjectSynchronizer::complete_exit(_obj, CHECK_0); } + void reenter(intptr_t recursion, TRAPS) { ObjectSynchronizer::reenter(_obj, recursion, CHECK); } }; #endif // SHARE_VM_RUNTIME_SYNCHRONIZER_HPP diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/thread.cpp --- a/hotspot/src/share/vm/runtime/thread.cpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/thread.cpp Wed Sep 10 11:52:16 2014 -0600 @@ -109,25 +109,25 @@ // Only bother with this argument setup if dtrace is available -#define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START -#define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_STOP - -#define DTRACE_THREAD_PROBE(probe, javathread) \ - { \ - ResourceMark rm(this); \ - int len = 0; \ - const char* name = (javathread)->get_thread_name(); \ - len = strlen(name); \ - HOTSPOT_THREAD_PROBE_##probe( /* probe = start, stop */ \ - (char *) name, len, \ - java_lang_Thread::thread_id((javathread)->threadObj()), \ - (uintptr_t) (javathread)->osthread()->thread_id(), \ - java_lang_Thread::is_daemon((javathread)->threadObj())); \ - } + #define HOTSPOT_THREAD_PROBE_start HOTSPOT_THREAD_START + #define HOTSPOT_THREAD_PROBE_stop HOTSPOT_THREAD_STOP + + #define DTRACE_THREAD_PROBE(probe, javathread) \ + { \ + ResourceMark rm(this); \ + int len = 0; \ + const char* name = (javathread)->get_thread_name(); \ + len = strlen(name); \ + HOTSPOT_THREAD_PROBE_##probe(/* probe = start, stop */ \ + (char *) name, len, \ + java_lang_Thread::thread_id((javathread)->threadObj()), \ + (uintptr_t) (javathread)->osthread()->thread_id(), \ + java_lang_Thread::is_daemon((javathread)->threadObj())); \ + } #else // ndef DTRACE_ENABLED -#define DTRACE_THREAD_PROBE(probe, javathread) + #define DTRACE_THREAD_PROBE(probe, javathread) #endif // ndef DTRACE_ENABLED @@ -154,9 +154,10 @@ ((uintptr_t) real_malloc_addr + (uintptr_t) aligned_size), "JavaThread alignment code overflowed allocated storage"); if (TraceBiasedLocking) { - if (aligned_addr != real_malloc_addr) + if (aligned_addr != real_malloc_addr) { tty->print_cr("Aligned thread " INTPTR_FORMAT " to " INTPTR_FORMAT, real_malloc_addr, aligned_addr); + } } ((Thread*) aligned_addr)->_real_malloc_address = real_malloc_addr; return aligned_addr; @@ -264,7 +265,7 @@ this == (void*) align_size_up((intptr_t) _real_malloc_address, markOopDesc::biased_lock_alignment), "bug in forced alignment of thread objects"); } -#endif /* ASSERT */ +#endif // ASSERT } void Thread::initialize_thread_local_storage() { @@ -445,7 +446,6 @@ } -// // Check if an external suspend request has completed (or has been // cancelled). Returns true if the thread is externally suspended and // false otherwise. @@ -470,7 +470,6 @@ // 0x00080000 - suspend request cancelled in loop (return false) // 0x00100000 - thread suspended in loop (return true) // 0x00200000 - suspend not completed during retry loop (return false) -// // Helper class for tracing suspend wait debug bits. // @@ -528,7 +527,8 @@ #undef DEBUG_FALSE_BITS -bool JavaThread::is_ext_suspend_completed(bool called_by_wait, int delay, uint32_t *bits) { +bool JavaThread::is_ext_suspend_completed(bool called_by_wait, int delay, + uint32_t *bits) { TraceSuspendDebugBits tsdb(this, false /* !is_wait */, called_by_wait, bits); bool did_trans_retry = false; // only do thread_in_native_trans retry once @@ -649,7 +649,6 @@ return false; } -// // Wait for an external suspend request to complete (or be cancelled). // Returns true if the thread is externally suspended and false otherwise. // @@ -737,20 +736,21 @@ } #ifndef PRODUCT -void JavaThread::record_jump(address target, address instr, const char* file, int line) { +void JavaThread::record_jump(address target, address instr, const char* file, + int line) { // This should not need to be atomic as the only way for simultaneous // updates is via interrupts. Even then this should be rare or non-existent // and we don't care that much anyway. int index = _jmp_ring_index; - _jmp_ring_index = (index + 1 ) & (jump_ring_buffer_size - 1); + _jmp_ring_index = (index + 1) & (jump_ring_buffer_size - 1); _jmp_ring[index]._target = (intptr_t) target; _jmp_ring[index]._instruction = (intptr_t) instr; _jmp_ring[index]._file = file; _jmp_ring[index]._line = line; } -#endif /* PRODUCT */ +#endif // PRODUCT // Called by flat profiler // Callers have already called wait_for_ext_suspend_completion @@ -834,13 +834,13 @@ // Thread::print_on_error() is called by fatal error handler. Don't use // any lock or allocate memory. void Thread::print_on_error(outputStream* st, char* buf, int buflen) const { - if (is_VM_thread()) st->print("VMThread"); - else if (is_Compiler_thread()) st->print("CompilerThread"); - else if (is_Java_thread()) st->print("JavaThread"); - else if (is_GC_task_thread()) st->print("GCTaskThread"); - else if (is_Watcher_thread()) st->print("WatcherThread"); - else if (is_ConcurrentGC_thread()) st->print("ConcurrentGCThread"); - else st->print("Thread"); + if (is_VM_thread()) st->print("VMThread"); + else if (is_Compiler_thread()) st->print("CompilerThread"); + else if (is_Java_thread()) st->print("JavaThread"); + else if (is_GC_task_thread()) st->print("GCTaskThread"); + else if (is_Watcher_thread()) st->print("WatcherThread"); + else if (is_ConcurrentGC_thread()) st->print("ConcurrentGCThread"); + else st->print("Thread"); st->print(" [stack: " PTR_FORMAT "," PTR_FORMAT "]", _stack_base - _stack_size, _stack_base); @@ -883,8 +883,9 @@ // no threads which allow_vm_block's are held void Thread::check_for_valid_safepoint_state(bool potential_vm_operation) { // Check if current thread is allowed to block at a safepoint - if (!(_allow_safepoint_count == 0)) + if (!(_allow_safepoint_count == 0)) { fatal("Possible safepoint reached by thread that does not allow it"); + } if (is_Java_thread() && ((JavaThread*)this)->thread_state() != _thread_in_vm) { fatal("LEAF method calling lock?"); } @@ -991,7 +992,8 @@ } // Creates the initial Thread -static oop create_initial_thread(Handle thread_group, JavaThread* thread, TRAPS) { +static oop create_initial_thread(Handle thread_group, JavaThread* thread, + TRAPS) { Klass* k = SystemDictionary::resolve_or_fail(vmSymbols::java_lang_Thread(), true, CHECK_NULL); instanceKlassHandle klass (THREAD, k); instanceHandle thread_oop = klass->allocate_instance_handle(CHECK_NULL); @@ -1035,8 +1037,9 @@ vmSymbols::string_signature(), &fd); if (found) { oop name_oop = k->java_mirror()->obj_field(fd.offset()); - if (name_oop == NULL) + if (name_oop == NULL) { return NULL; + } const char* name = java_lang_String::as_utf8_string(name_oop, java_runtime_name, sizeof(java_runtime_name)); @@ -1056,8 +1059,9 @@ vmSymbols::string_signature(), &fd); if (found) { oop name_oop = k->java_mirror()->obj_field(fd.offset()); - if (name_oop == NULL) + if (name_oop == NULL) { return NULL; + } const char* name = java_lang_String::as_utf8_string(name_oop, java_runtime_version, sizeof(java_runtime_version)); @@ -1107,7 +1111,8 @@ } -void JavaThread::allocate_threadObj(Handle thread_group, char* thread_name, bool daemon, TRAPS) { +void JavaThread::allocate_threadObj(Handle thread_group, char* thread_name, + bool daemon, TRAPS) { assert(thread_group.not_null(), "thread group should be specified"); assert(threadObj() == NULL, "should only create Java thread object once"); @@ -1268,8 +1273,9 @@ } remaining -= time_slept; - if (remaining <= 0) + if (remaining <= 0) { break; + } } return time_slept; @@ -1387,7 +1393,9 @@ } void WatcherThread::unpark() { - MutexLockerEx ml(PeriodicTask_lock->owned_by_self() ? NULL : PeriodicTask_lock, Mutex::_no_safepoint_check_flag); + MutexLockerEx ml(PeriodicTask_lock->owned_by_self() + ? NULL + : PeriodicTask_lock, Mutex::_no_safepoint_check_flag); PeriodicTask_lock->notify(); } @@ -1455,7 +1463,7 @@ for (int ji = 0; ji < jump_ring_buffer_size; ji++) { record_jump(NULL, NULL, NULL, 0); } -#endif /* PRODUCT */ +#endif // PRODUCT set_thread_profiler(NULL); if (FlatProfiler::is_active()) { @@ -2061,19 +2069,16 @@ condition == _async_unsafe_access_error && !has_pending_exception()) { condition = _no_async_condition; // done switch (thread_state()) { - case _thread_in_vm: - { + case _thread_in_vm: { JavaThread* THREAD = this; THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); } - case _thread_in_native: - { + case _thread_in_native: { ThreadInVMfromNative tiv(this); JavaThread* THREAD = this; THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in an unsafe memory access operation"); } - case _thread_in_Java: - { + case _thread_in_Java: { ThreadInVMfromJava tiv(this); JavaThread* THREAD = this; THROW_MSG(vmSymbols::java_lang_InternalError(), "a fault occurred in a recent unsafe memory access operation in compiled Java code"); @@ -2214,7 +2219,7 @@ // SR_lock to allow the thread to reach a stable thread state if // it is currently in a transient thread state. if (is_ext_suspend_completed(false /* !called_by_wait */, - SuspendRetryDelay, &debug_bits) ) { + SuspendRetryDelay, &debug_bits)) { return; } } @@ -2292,8 +2297,7 @@ MutexLockerEx ml(Threads_lock, Mutex::_no_safepoint_check_flag); assert(!Threads::includes(this), "java thread shouldn't have been published yet!"); - } - else { + } else { assert(!Threads::includes(this), "java thread shouldn't have been published yet!"); } @@ -2570,7 +2574,7 @@ // search for the current bci in that string. address pc = fst.current()->pc(); nmethod* nm = (nmethod*) fst.current()->cb(); - ScopeDesc* sd = nm->scope_desc_at( pc); + ScopeDesc* sd = nm->scope_desc_at(pc); char buffer[8]; jio_snprintf(buffer, sizeof(buffer), "%d", sd->bci()); size_t len = strlen(buffer); @@ -2779,7 +2783,7 @@ }; void JavaThread::print_thread_state() const { print_thread_state_on(tty); -}; +} #endif // PRODUCT // Called by Threads::print() for VM_PrintThreads operation @@ -2865,20 +2869,18 @@ typeArrayOop name = java_lang_Thread::name(thread_obj); if (name != NULL) { if (buf == NULL) { - name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length()); - } - else { - name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), name->length(), buf, buflen); + name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), + name->length()); + } else { + name_str = UNICODE::as_utf8((jchar*) name->base(T_CHAR), + name->length(), buf, buflen); } - } - else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306 + } else if (is_attaching_via_jni()) { // workaround for 6412693 - see 6404306 name_str = ""; - } - else { + } else { name_str = Thread::name(); } - } - else { + } else { name_str = Thread::name(); } assert(name_str != NULL, "unexpected NULL thread name"); @@ -3165,8 +3167,9 @@ } // Create a CompilerThread -CompilerThread::CompilerThread(CompileQueue* queue, CompilerCounters* counters) -: JavaThread(&compiler_thread_entry) { +CompilerThread::CompilerThread(CompileQueue* queue, + CompilerCounters* counters) + : JavaThread(&compiler_thread_entry) { _env = NULL; _log = NULL; _task = NULL; @@ -3231,8 +3234,9 @@ // way to prevent termination of WatcherThread would be to acquire // Terminator_lock, but we can't do that without violating the lock rank // checking in some cases. - if (wt != NULL) + if (wt != NULL) { tc->do_thread(wt); + } // If CompilerThreads ever become non-JavaThreads, add them here } @@ -3290,7 +3294,6 @@ } jint Threads::create_vm(JavaVMInitArgs* args, bool* canTryAgain) { - extern void JDK_Version_init(); // Check version @@ -3422,8 +3425,10 @@ VMThread::create(); Thread* vmthread = VMThread::vm_thread(); - if (!os::create_thread(vmthread, os::vm_thread)) - vm_exit_during_initialization("Cannot create VM thread. Out of system resources."); + if (!os::create_thread(vmthread, os::vm_thread)) { + vm_exit_during_initialization("Cannot create VM thread. " + "Out of system resources."); + } // Wait for the VM thread to become ready, and VMThread::run to initialize // Monitors can have spurious returns, must always check another state flag @@ -3613,7 +3618,9 @@ // Find a command line agent library and return its entry point for // -agentlib: -agentpath: -Xrun // num_symbol_entries must be passed-in since only the caller knows the number of symbols in the array. -static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, const char *on_load_symbols[], size_t num_symbol_entries) { +static OnLoadEntry_t lookup_on_load(AgentLibrary* agent, + const char *on_load_symbols[], + size_t num_symbol_entries) { OnLoadEntry_t on_load_entry = NULL; void *library = NULL; @@ -4006,8 +4013,9 @@ // Only one thread left, do a notify on the Threads_lock so a thread waiting // on destroy_vm will wake up. - if (number_of_non_daemon_threads() == 1) + if (number_of_non_daemon_threads() == 1) { Threads_lock->notify_all(); + } } ThreadService::remove_thread(p, daemon); @@ -4113,7 +4121,8 @@ // Get count Java threads that are waiting to enter the specified monitor. GrowableArray* Threads::get_pending_threads(int count, - address monitor, bool doLock) { + address monitor, + bool doLock) { assert(doLock || SafepointSynchronize::is_at_safepoint(), "must grab Threads_lock or be at safepoint"); GrowableArray* result = new GrowableArray(count); @@ -4135,7 +4144,8 @@ } -JavaThread *Threads::owning_thread_from_monitor_owner(address owner, bool doLock) { +JavaThread *Threads::owning_thread_from_monitor_owner(address owner, + bool doLock) { assert(doLock || Threads_lock->owned_by_self() || SafepointSynchronize::is_at_safepoint(), @@ -4156,7 +4166,6 @@ // like deadlock detection. if (UseHeavyMonitors) return NULL; - // // If we didn't find a matching Java thread and we didn't force use of // heavyweight monitors, then the owner is the stack address of the // Lock Word in the owning Java thread's stack. @@ -4176,15 +4185,15 @@ } // Threads::print_on() is called at safepoint by VM_PrintThreads operation. -void Threads::print_on(outputStream* st, bool print_stacks, bool internal_format, bool print_concurrent_locks) { +void Threads::print_on(outputStream* st, bool print_stacks, + bool internal_format, bool print_concurrent_locks) { char buf[32]; st->print_cr("%s", os::local_time_string(buf, sizeof(buf))); st->print_cr("Full thread dump %s (%s %s):", Abstract_VM_Version::vm_name(), Abstract_VM_Version::vm_release(), - Abstract_VM_Version::vm_info_string() - ); + Abstract_VM_Version::vm_info_string()); st->cr(); #if INCLUDE_ALL_GCS @@ -4229,7 +4238,8 @@ // that VM is not at safepoint and/or current thread is inside signal handler. // Don't print stack trace, as the stack may not be walkable. Don't allocate // memory (even in resource area), it might deadlock the error handler. -void Threads::print_on_error(outputStream* st, Thread* current, char* buf, int buflen) { +void Threads::print_on_error(outputStream* st, Thread* current, char* buf, + int buflen) { bool found_current = false; st->print_cr("Java Threads: ( => current thread )"); ALL_JAVA_THREADS(thread) { @@ -4301,7 +4311,7 @@ typedef volatile int SpinLockT; -void Thread::SpinAcquire (volatile int * adr, const char * LockName) { +void Thread::SpinAcquire(volatile int * adr, const char * LockName) { if (Atomic::cmpxchg (1, adr, 0) == 0) { return; // normal fast-path return } @@ -4328,7 +4338,7 @@ } } -void Thread::SpinRelease (volatile int * adr) { +void Thread::SpinRelease(volatile int * adr) { assert(*adr != 0, "invariant"); OrderAccess::fence(); // guarantee at least release consistency. // Roach-motel semantics. @@ -4397,7 +4407,7 @@ typedef volatile intptr_t MutexT; // Mux Lock-word enum MuxBits { LOCKBIT = 1 }; -void Thread::muxAcquire (volatile intptr_t * Lock, const char * LockName) { +void Thread::muxAcquire(volatile intptr_t * Lock, const char * LockName) { intptr_t w = Atomic::cmpxchg_ptr(LOCKBIT, Lock, 0); if (w == 0) return; if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { @@ -4443,7 +4453,7 @@ } } -void Thread::muxAcquireW (volatile intptr_t * Lock, ParkEvent * ev) { +void Thread::muxAcquireW(volatile intptr_t * Lock, ParkEvent * ev) { intptr_t w = Atomic::cmpxchg_ptr(LOCKBIT, Lock, 0); if (w == 0) return; if ((w & LOCKBIT) == 0 && Atomic::cmpxchg_ptr (w|LOCKBIT, Lock, w) == w) { @@ -4528,7 +4538,7 @@ // bidirectional fence/MEMBAR semantics, ensuring that all prior memory operations // executed within the critical section are complete and globally visible before the // store (CAS) to the lock-word that releases the lock becomes globally visible. -void Thread::muxRelease (volatile intptr_t * Lock) { +void Thread::muxRelease(volatile intptr_t * Lock) { for (;;) { const intptr_t w = Atomic::cmpxchg_ptr(0, Lock, LOCKBIT); assert(w & LOCKBIT, "invariant"); diff -r a02753d5a0b2 -r d1221849ea3d hotspot/src/share/vm/runtime/thread.hpp --- a/hotspot/src/share/vm/runtime/thread.hpp Wed Sep 10 11:48:20 2014 -0600 +++ b/hotspot/src/share/vm/runtime/thread.hpp Wed Sep 10 11:52:16 2014 -0600 @@ -178,7 +178,6 @@ // 2. It would be more natural if set_external_suspend() is private and // part of java_suspend(), but that probably would affect the suspend/query // performance. Need more investigation on this. - // // suspend/resume lock: used for self-suspend Monitor* _SR_lock; @@ -514,7 +513,7 @@ void record_stack_base_and_size(); bool on_local_stack(address adr) const { - /* QQQ this has knowledge of direction, ought to be a stack method */ + // QQQ this has knowledge of direction, ought to be a stack method return (_stack_base >= adr && adr >= (_stack_base - _stack_size)); } @@ -624,8 +623,8 @@ inline Thread* Thread::current() { #ifdef ASSERT -// This function is very high traffic. Define PARANOID to enable expensive -// asserts. + // This function is very high traffic. Define PARANOID to enable expensive + // asserts. #ifdef PARANOID // Signal handler should call ThreadLocalStorage::get_thread_slow() Thread* t = ThreadLocalStorage::get_thread_slow(); @@ -843,8 +842,8 @@ jint _in_deopt_handler; // count of deoptimization // handlers thread is in volatile bool _doing_unsafe_access; // Thread may fault due to unsafe access - bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was - // never locked) when throwing an exception. Used by interpreter only. + bool _do_not_unlock_if_synchronized; // Do not unlock the receiver of a synchronized method (since it was + // never locked) when throwing an exception. Used by interpreter only. // JNI attach states: enum JNIAttachStates { @@ -904,7 +903,7 @@ const char* _file; int _line; } _jmp_ring[jump_ring_buffer_size]; -#endif /* PRODUCT */ +#endif // PRODUCT #if INCLUDE_ALL_GCS // Support for G1 barriers @@ -1071,7 +1070,7 @@ // Warning: is_ext_suspend_completed() may temporarily drop the // SR_lock to allow the thread to reach a stable thread state if // it is currently in a transient thread state. - return is_ext_suspend_completed(false /*!called_by_wait */, + return is_ext_suspend_completed(false /* !called_by_wait */, SuspendRetryDelay, bits); } @@ -1096,7 +1095,7 @@ // Whenever a thread transitions from native to vm/java it must suspend // if external|deopt suspend is present. bool is_suspend_after_native() const { - return (_suspend_flags & (_external_suspend | _deopt_suspend) ) != 0; + return (_suspend_flags & (_external_suspend | _deopt_suspend)) != 0; } // external suspend request is completed @@ -1137,8 +1136,8 @@ bool is_suspend_equivalent() const { return _suspend_equivalent; } - void set_suspend_equivalent() { _suspend_equivalent = true; }; - void clear_suspend_equivalent() { _suspend_equivalent = false; }; + void set_suspend_equivalent() { _suspend_equivalent = true; } + void clear_suspend_equivalent() { _suspend_equivalent = false; } // Thread.stop support void send_thread_stop(oop throwable); @@ -1238,18 +1237,25 @@ // Stack overflow support inline size_t stack_available(address cur_sp); - address stack_yellow_zone_base() - { return (address)(stack_base() - (stack_size() - (stack_red_zone_size() + stack_yellow_zone_size()))); } - size_t stack_yellow_zone_size() - { return StackYellowPages * os::vm_page_size(); } - address stack_red_zone_base() - { return (address)(stack_base() - (stack_size() - stack_red_zone_size())); } - size_t stack_red_zone_size() - { return StackRedPages * os::vm_page_size(); } - bool in_stack_yellow_zone(address a) - { return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); } - bool in_stack_red_zone(address a) - { return (a <= stack_red_zone_base()) && (a >= (address)((intptr_t)stack_base() - stack_size())); } + address stack_yellow_zone_base() { + return (address)(stack_base() - + (stack_size() - + (stack_red_zone_size() + stack_yellow_zone_size()))); + } + size_t stack_yellow_zone_size() { + return StackYellowPages * os::vm_page_size(); + } + address stack_red_zone_base() { + return (address)(stack_base() - (stack_size() - stack_red_zone_size())); + } + size_t stack_red_zone_size() { return StackRedPages * os::vm_page_size(); } + bool in_stack_yellow_zone(address a) { + return (a <= stack_yellow_zone_base()) && (a >= stack_red_zone_base()); + } + bool in_stack_red_zone(address a) { + return (a <= stack_red_zone_base()) && + (a >= (address)((intptr_t)stack_base() - stack_size())); + } void create_stack_guard_pages(); void remove_stack_guard_pages(); @@ -1289,14 +1295,14 @@ #ifndef PRODUCT void record_jump(address target, address instr, const char* file, int line); -#endif /* PRODUCT */ +#endif // PRODUCT // For assembly stub generation static ByteSize threadObj_offset() { return byte_offset_of(JavaThread, _threadObj); } #ifndef PRODUCT static ByteSize jmp_ring_index_offset() { return byte_offset_of(JavaThread, _jmp_ring_index); } static ByteSize jmp_ring_offset() { return byte_offset_of(JavaThread, _jmp_ring); } -#endif /* PRODUCT */ +#endif // PRODUCT static ByteSize jni_environment_offset() { return byte_offset_of(JavaThread, _jni_environment); } static ByteSize last_Java_sp_offset() { return byte_offset_of(JavaThread, _anchor) + JavaFrameAnchor::last_Java_sp_offset(); @@ -1349,15 +1355,18 @@ // JNI critical regions. These can nest. bool in_critical() { return _jni_active_critical > 0; } bool in_last_critical() { return _jni_active_critical == 1; } - void enter_critical() { assert(Thread::current() == this || - Thread::current()->is_VM_thread() && SafepointSynchronize::is_synchronizing(), - "this must be current thread or synchronizing"); - _jni_active_critical++; } - void exit_critical() { assert(Thread::current() == this, - "this must be current thread"); - _jni_active_critical--; - assert(_jni_active_critical >= 0, - "JNI critical nesting problem?"); } + void enter_critical() { + assert(Thread::current() == this || + (Thread::current()->is_VM_thread() && + SafepointSynchronize::is_synchronizing()), + "this must be current thread or synchronizing"); + _jni_active_critical++; + } + void exit_critical() { + assert(Thread::current() == this, "this must be current thread"); + _jni_active_critical--; + assert(_jni_active_critical >= 0, "JNI critical nesting problem?"); + } // Checked JNI, is the programmer required to check for exceptions, specify which function name bool is_pending_jni_exception_check() const { return _pending_jni_exception_check_fn != NULL; } @@ -1406,8 +1415,8 @@ char* name() const { return (char*)get_thread_name(); } void print_on(outputStream* st) const; void print_value(); - void print_thread_state_on(outputStream* ) const PRODUCT_RETURN; - void print_thread_state() const PRODUCT_RETURN; + void print_thread_state_on(outputStream*) const PRODUCT_RETURN; + void print_thread_state() const PRODUCT_RETURN; void print_on_error(outputStream* st, char* buf, int buflen) const; void verify(); const char* get_thread_name() const; @@ -1766,7 +1775,7 @@ void set_env(ciEnv* env) { _env = env; } BufferBlob* get_buffer_blob() const { return _buffer_blob; } - void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; }; + void set_buffer_blob(BufferBlob* b) { _buffer_blob = b; } // Get/set the thread's logging information CompileLog* log() { return _log; }