comparison src/os/linux/vm/os_linux.cpp @ 4970:33df1aeaebbf

Merge with http://hg.openjdk.java.net/hsx/hsx24/hotspot/
author Thomas Wuerthinger <thomas.wuerthinger@oracle.com>
date Mon, 27 Feb 2012 13:10:13 +0100
parents 04b9a2566eec de268c8a8075
children 897b7d18bebc
comparison
equal deleted inserted replaced
4703:2cfb7fb2dce7 4970:33df1aeaebbf
1 /* 1 /*
2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. 2 * Copyright (c) 1999, 2012, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 * 4 *
5 * This code is free software; you can redistribute it and/or modify it 5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as 6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. 7 * published by the Free Software Foundation.
125 125
126 #define MAX_PATH (2 * K) 126 #define MAX_PATH (2 * K)
127 127
128 // for timer info max values which include all bits 128 // for timer info max values which include all bits
129 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) 129 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF)
130 #define SEC_IN_NANOSECS 1000000000LL
131 130
132 #define LARGEPAGES_BIT (1 << 6) 131 #define LARGEPAGES_BIT (1 << 6)
133 //////////////////////////////////////////////////////////////////////////////// 132 ////////////////////////////////////////////////////////////////////////////////
134 // global variables 133 // global variables
135 julong os::Linux::_physical_memory = 0; 134 julong os::Linux::_physical_memory = 0;
1731 } 1730 }
1732 if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr; 1731 if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr;
1733 return true; 1732 return true;
1734 } else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) { 1733 } else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) {
1735 if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase), 1734 if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase),
1736 dlinfo.dli_fname, buf, buflen, offset) == Decoder::no_error) { 1735 buf, buflen, offset, dlinfo.dli_fname)) {
1737 return true; 1736 return true;
1738 } 1737 }
1739 } 1738 }
1740 1739
1741 if (buf != NULL) buf[0] = '\0'; 1740 if (buf != NULL) buf[0] = '\0';
2545 // be supported or the memory may already be backed by huge pages. 2544 // be supported or the memory may already be backed by huge pages.
2546 ::madvise(addr, bytes, MADV_HUGEPAGE); 2545 ::madvise(addr, bytes, MADV_HUGEPAGE);
2547 } 2546 }
2548 } 2547 }
2549 2548
2550 void os::free_memory(char *addr, size_t bytes) { 2549 void os::free_memory(char *addr, size_t bytes, size_t alignment_hint) {
2551 commit_memory(addr, bytes, false); 2550 commit_memory(addr, bytes, alignment_hint, false);
2552 } 2551 }
2553 2552
2554 void os::numa_make_global(char *addr, size_t bytes) { 2553 void os::numa_make_global(char *addr, size_t bytes) {
2555 Linux::numa_interleave_memory(addr, bytes); 2554 Linux::numa_interleave_memory(addr, bytes);
2556 } 2555 }
3257 // Solaris uses poll(), linux uses park(). 3256 // Solaris uses poll(), linux uses park().
3258 // Poll() is likely a better choice, assuming that Thread.interrupt() 3257 // Poll() is likely a better choice, assuming that Thread.interrupt()
3259 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with 3258 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
3260 // SIGSEGV, see 4355769. 3259 // SIGSEGV, see 4355769.
3261 3260
3262 const int NANOSECS_PER_MILLISECS = 1000000;
3263
3264 int os::sleep(Thread* thread, jlong millis, bool interruptible) { 3261 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
3265 assert(thread == Thread::current(), "thread consistency check"); 3262 assert(thread == Thread::current(), "thread consistency check");
3266 3263
3267 ParkEvent * const slp = thread->_SleepEvent ; 3264 ParkEvent * const slp = thread->_SleepEvent ;
3268 slp->reset() ; 3265 slp->reset() ;
3281 if (newtime - prevtime < 0) { 3278 if (newtime - prevtime < 0) {
3282 // time moving backwards, should only happen if no monotonic clock 3279 // time moving backwards, should only happen if no monotonic clock
3283 // not a guarantee() because JVM should not abort on kernel/glibc bugs 3280 // not a guarantee() because JVM should not abort on kernel/glibc bugs
3284 assert(!Linux::supports_monotonic_clock(), "time moving backwards"); 3281 assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3285 } else { 3282 } else {
3286 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS; 3283 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3287 } 3284 }
3288 3285
3289 if(millis <= 0) { 3286 if(millis <= 0) {
3290 return OS_OK; 3287 return OS_OK;
3291 } 3288 }
3320 if (newtime - prevtime < 0) { 3317 if (newtime - prevtime < 0) {
3321 // time moving backwards, should only happen if no monotonic clock 3318 // time moving backwards, should only happen if no monotonic clock
3322 // not a guarantee() because JVM should not abort on kernel/glibc bugs 3319 // not a guarantee() because JVM should not abort on kernel/glibc bugs
3323 assert(!Linux::supports_monotonic_clock(), "time moving backwards"); 3320 assert(!Linux::supports_monotonic_clock(), "time moving backwards");
3324 } else { 3321 } else {
3325 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISECS; 3322 millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC;
3326 } 3323 }
3327 3324
3328 if(millis <= 0) break ; 3325 if(millis <= 0) break ;
3329 3326
3330 prevtime = newtime; 3327 prevtime = newtime;
3384 // not the entire user process, and user level threads are 1:1 mapped to kernel 3381 // not the entire user process, and user level threads are 1:1 mapped to kernel
3385 // threads. It has always been the case, but could change in the future. For 3382 // threads. It has always been the case, but could change in the future. For
3386 // this reason, the code should not be used as default (ThreadPriorityPolicy=0). 3383 // this reason, the code should not be used as default (ThreadPriorityPolicy=0).
3387 // It is only used when ThreadPriorityPolicy=1 and requires root privilege. 3384 // It is only used when ThreadPriorityPolicy=1 and requires root privilege.
3388 3385
3389 int os::java_to_os_priority[MaxPriority + 1] = { 3386 int os::java_to_os_priority[CriticalPriority + 1] = {
3390 19, // 0 Entry should never be used 3387 19, // 0 Entry should never be used
3391 3388
3392 4, // 1 MinPriority 3389 4, // 1 MinPriority
3393 3, // 2 3390 3, // 2
3394 2, // 3 3391 2, // 3
3399 3396
3400 -2, // 7 3397 -2, // 7
3401 -3, // 8 3398 -3, // 8
3402 -4, // 9 NearMaxPriority 3399 -4, // 9 NearMaxPriority
3403 3400
3404 -5 // 10 MaxPriority 3401 -5, // 10 MaxPriority
3402
3403 -5 // 11 CriticalPriority
3405 }; 3404 };
3406 3405
3407 static int prio_init() { 3406 static int prio_init() {
3408 if (ThreadPriorityPolicy == 1) { 3407 if (ThreadPriorityPolicy == 1) {
3409 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 3408 // Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1
3413 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { 3412 if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) {
3414 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); 3413 warning("-XX:ThreadPriorityPolicy requires root privilege on Linux");
3415 } 3414 }
3416 ThreadPriorityPolicy = 0; 3415 ThreadPriorityPolicy = 0;
3417 } 3416 }
3417 }
3418 if (UseCriticalJavaThreadPriority) {
3419 os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority];
3418 } 3420 }
3419 return 0; 3421 return 0;
3420 } 3422 }
3421 3423
3422 OSReturn os::set_native_priority(Thread* thread, int newpri) { 3424 OSReturn os::set_native_priority(Thread* thread, int newpri) {
3929 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) { 3931 jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) {
3930 struct timespec tp; 3932 struct timespec tp;
3931 int rc = os::Linux::clock_gettime(clockid, &tp); 3933 int rc = os::Linux::clock_gettime(clockid, &tp);
3932 assert(rc == 0, "clock_gettime is expected to return 0 code"); 3934 assert(rc == 0, "clock_gettime is expected to return 0 code");
3933 3935
3934 return (tp.tv_sec * SEC_IN_NANOSECS) + tp.tv_nsec; 3936 return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec;
3935 } 3937 }
3936 3938
3937 ///// 3939 /////
3938 // glibc on Linux platform uses non-documented flag 3940 // glibc on Linux platform uses non-documented flag
3939 // to indicate, that some special sort of signal 3941 // to indicate, that some special sort of signal
5170 * on the condvar. Contention seen when trying to park implies that someone 5172 * on the condvar. Contention seen when trying to park implies that someone
5171 * is unparking you, so don't wait. And spurious returns are fine, so there 5173 * is unparking you, so don't wait. And spurious returns are fine, so there
5172 * is no need to track notifications. 5174 * is no need to track notifications.
5173 */ 5175 */
5174 5176
5175
5176 #define NANOSECS_PER_SEC 1000000000
5177 #define NANOSECS_PER_MILLISEC 1000000
5178 #define MAX_SECS 100000000 5177 #define MAX_SECS 100000000
5179 /* 5178 /*
5180 * This code is common to linux and solaris and will be moved to a 5179 * This code is common to linux and solaris and will be moved to a
5181 * common place in dolphin. 5180 * common place in dolphin.
5182 * 5181 *