Mercurial > hg > graal-compiler
comparison src/os/solaris/vm/os_solaris.cpp @ 2023:54f5dd2aa1d9
Merge
author | zgu |
---|---|
date | Sat, 11 Dec 2010 13:46:36 -0500 |
parents | 2d4762ec74af 828eafbd85cc |
children | 1e637defdda6 |
comparison
equal
deleted
inserted
replaced
2022:2d4762ec74af | 2023:54f5dd2aa1d9 |
---|---|
40 #include "prims/jvm.h" | 40 #include "prims/jvm.h" |
41 #include "prims/jvm_misc.hpp" | 41 #include "prims/jvm_misc.hpp" |
42 #include "runtime/arguments.hpp" | 42 #include "runtime/arguments.hpp" |
43 #include "runtime/extendedPC.hpp" | 43 #include "runtime/extendedPC.hpp" |
44 #include "runtime/globals.hpp" | 44 #include "runtime/globals.hpp" |
45 #include "runtime/hpi.hpp" | |
46 #include "runtime/interfaceSupport.hpp" | 45 #include "runtime/interfaceSupport.hpp" |
47 #include "runtime/java.hpp" | 46 #include "runtime/java.hpp" |
48 #include "runtime/javaCalls.hpp" | 47 #include "runtime/javaCalls.hpp" |
49 #include "runtime/mutexLocker.hpp" | 48 #include "runtime/mutexLocker.hpp" |
50 #include "runtime/objectMonitor.hpp" | 49 #include "runtime/objectMonitor.hpp" |
114 # include <sys/rtpriocntl.h> | 113 # include <sys/rtpriocntl.h> |
115 # include <sys/tspriocntl.h> | 114 # include <sys/tspriocntl.h> |
116 # include <sys/iapriocntl.h> | 115 # include <sys/iapriocntl.h> |
117 # include <sys/loadavg.h> | 116 # include <sys/loadavg.h> |
118 # include <string.h> | 117 # include <string.h> |
118 # include <stdio.h> | |
119 | 119 |
120 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later | 120 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later |
121 # include <sys/procfs.h> // see comment in <sys/procfs.h> | 121 # include <sys/procfs.h> // see comment in <sys/procfs.h> |
122 | 122 |
123 #define MAX_PATH (2 * K) | 123 #define MAX_PATH (2 * K) |
218 80, 96, 112, 124, 127 }; | 218 80, 96, 112, 124, 127 }; |
219 | 219 |
220 // System parameters used internally | 220 // System parameters used internally |
221 static clock_t clock_tics_per_sec = 100; | 221 static clock_t clock_tics_per_sec = 100; |
222 | 222 |
223 // Track if we have called enable_extended_FILE_stdio (on Solaris 10u4+) | |
224 static bool enabled_extended_FILE_stdio = false; | |
225 | |
223 // For diagnostics to print a message once. see run_periodic_checks | 226 // For diagnostics to print a message once. see run_periodic_checks |
224 static bool check_addr0_done = false; | 227 static bool check_addr0_done = false; |
225 static sigset_t check_signal_done; | 228 static sigset_t check_signal_done; |
226 static bool check_signals = true; | 229 static bool check_signals = true; |
227 | 230 |
385 // setup_interruptible saves the thread state before going into an | 388 // setup_interruptible saves the thread state before going into an |
386 // interruptible system call. | 389 // interruptible system call. |
387 // The saved state is used to restore the thread to | 390 // The saved state is used to restore the thread to |
388 // its former state whether or not an interrupt is received. | 391 // its former state whether or not an interrupt is received. |
389 // Used by classloader os::read | 392 // Used by classloader os::read |
390 // hpi calls skip this layer and stay in _thread_in_native | 393 // os::restartable_read calls skip this layer and stay in _thread_in_native |
391 | 394 |
392 void os::Solaris::setup_interruptible(JavaThread* thread) { | 395 void os::Solaris::setup_interruptible(JavaThread* thread) { |
393 | 396 |
394 JavaThreadState thread_state = thread->thread_state(); | 397 JavaThreadState thread_state = thread->thread_state(); |
395 | 398 |
1749 } | 1752 } |
1750 | 1753 |
1751 bool os::supports_vtime() { return true; } | 1754 bool os::supports_vtime() { return true; } |
1752 | 1755 |
1753 bool os::enable_vtime() { | 1756 bool os::enable_vtime() { |
1754 int fd = open("/proc/self/ctl", O_WRONLY); | 1757 int fd = ::open("/proc/self/ctl", O_WRONLY); |
1755 if (fd == -1) | 1758 if (fd == -1) |
1756 return false; | 1759 return false; |
1757 | 1760 |
1758 long cmd[] = { PCSET, PR_MSACCT }; | 1761 long cmd[] = { PCSET, PR_MSACCT }; |
1759 int res = write(fd, cmd, sizeof(long) * 2); | 1762 int res = ::write(fd, cmd, sizeof(long) * 2); |
1760 close(fd); | 1763 ::close(fd); |
1761 if (res != sizeof(long) * 2) | 1764 if (res != sizeof(long) * 2) |
1762 return false; | 1765 return false; |
1763 | 1766 |
1764 return true; | 1767 return true; |
1765 } | 1768 } |
1766 | 1769 |
1767 bool os::vtime_enabled() { | 1770 bool os::vtime_enabled() { |
1768 int fd = open("/proc/self/status", O_RDONLY); | 1771 int fd = ::open("/proc/self/status", O_RDONLY); |
1769 if (fd == -1) | 1772 if (fd == -1) |
1770 return false; | 1773 return false; |
1771 | 1774 |
1772 pstatus_t status; | 1775 pstatus_t status; |
1773 int res = read(fd, (void*) &status, sizeof(pstatus_t)); | 1776 int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); |
1774 close(fd); | 1777 ::close(fd); |
1775 if (res != sizeof(pstatus_t)) | 1778 if (res != sizeof(pstatus_t)) |
1776 return false; | 1779 return false; |
1777 | 1780 |
1778 return status.pr_flags & PR_MSACCT; | 1781 return status.pr_flags & PR_MSACCT; |
1779 } | 1782 } |
1885 return os::stat(filename, &statbuf) == 0; | 1888 return os::stat(filename, &statbuf) == 0; |
1886 } | 1889 } |
1887 | 1890 |
1888 void os::dll_build_name(char* buffer, size_t buflen, | 1891 void os::dll_build_name(char* buffer, size_t buflen, |
1889 const char* pname, const char* fname) { | 1892 const char* pname, const char* fname) { |
1890 // Copied from libhpi | |
1891 const size_t pnamelen = pname ? strlen(pname) : 0; | 1893 const size_t pnamelen = pname ? strlen(pname) : 0; |
1892 | 1894 |
1893 // Quietly truncate on buffer overflow. Should be an error. | 1895 // Quietly truncate on buffer overflow. Should be an error. |
1894 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { | 1896 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { |
1895 *buffer = '\0'; | 1897 *buffer = '\0'; |
2196 | 2198 |
2197 void* os::dll_lookup(void* handle, const char* name) { | 2199 void* os::dll_lookup(void* handle, const char* name) { |
2198 return dlsym(handle, name); | 2200 return dlsym(handle, name); |
2199 } | 2201 } |
2200 | 2202 |
2201 | 2203 int os::stat(const char *path, struct stat *sbuf) { |
2202 bool _print_ascii_file(const char* filename, outputStream* st) { | 2204 char pathbuf[MAX_PATH]; |
2203 int fd = open(filename, O_RDONLY); | 2205 if (strlen(path) > MAX_PATH - 1) { |
2206 errno = ENAMETOOLONG; | |
2207 return -1; | |
2208 } | |
2209 os::native_path(strcpy(pathbuf, path)); | |
2210 return ::stat(pathbuf, sbuf); | |
2211 } | |
2212 | |
2213 static bool _print_ascii_file(const char* filename, outputStream* st) { | |
2214 int fd = ::open(filename, O_RDONLY); | |
2204 if (fd == -1) { | 2215 if (fd == -1) { |
2205 return false; | 2216 return false; |
2206 } | 2217 } |
2207 | 2218 |
2208 char buf[32]; | 2219 char buf[32]; |
2209 int bytes; | 2220 int bytes; |
2210 while ((bytes = read(fd, buf, sizeof(buf))) > 0) { | 2221 while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { |
2211 st->print_raw(buf, bytes); | 2222 st->print_raw(buf, bytes); |
2212 } | 2223 } |
2213 | 2224 |
2214 close(fd); | 2225 ::close(fd); |
2215 | 2226 |
2216 return true; | 2227 return true; |
2217 } | 2228 } |
2218 | 2229 |
2219 void os::print_os_info(outputStream* st) { | 2230 void os::print_os_info(outputStream* st) { |
2272 } | 2283 } |
2273 | 2284 |
2274 | 2285 |
2275 static bool check_addr0(outputStream* st) { | 2286 static bool check_addr0(outputStream* st) { |
2276 jboolean status = false; | 2287 jboolean status = false; |
2277 int fd = open("/proc/self/map",O_RDONLY); | 2288 int fd = ::open("/proc/self/map",O_RDONLY); |
2278 if (fd >= 0) { | 2289 if (fd >= 0) { |
2279 prmap_t p; | 2290 prmap_t p; |
2280 while(read(fd, &p, sizeof(p)) > 0) { | 2291 while(::read(fd, &p, sizeof(p)) > 0) { |
2281 if (p.pr_vaddr == 0x0) { | 2292 if (p.pr_vaddr == 0x0) { |
2282 st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); | 2293 st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); |
2283 st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); | 2294 st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); |
2284 st->print("Access:"); | 2295 st->print("Access:"); |
2285 st->print("%s",(p.pr_mflags & MA_READ) ? "r" : "-"); | 2296 st->print("%s",(p.pr_mflags & MA_READ) ? "r" : "-"); |
2286 st->print("%s",(p.pr_mflags & MA_WRITE) ? "w" : "-"); | 2297 st->print("%s",(p.pr_mflags & MA_WRITE) ? "w" : "-"); |
2287 st->print("%s",(p.pr_mflags & MA_EXEC) ? "x" : "-"); | 2298 st->print("%s",(p.pr_mflags & MA_EXEC) ? "x" : "-"); |
2288 st->cr(); | 2299 st->cr(); |
2289 status = true; | 2300 status = true; |
2290 } | 2301 } |
2291 close(fd); | 2302 ::close(fd); |
2292 } | 2303 } |
2293 } | 2304 } |
2294 return status; | 2305 return status; |
2295 } | 2306 } |
2296 | 2307 |
2534 | 2545 |
2535 if (0 == access(buf, F_OK)) { | 2546 if (0 == access(buf, F_OK)) { |
2536 // Use current module name "libjvm[_g].so" instead of | 2547 // Use current module name "libjvm[_g].so" instead of |
2537 // "libjvm"debug_only("_g")".so" since for fastdebug version | 2548 // "libjvm"debug_only("_g")".so" since for fastdebug version |
2538 // we should have "libjvm.so" but debug_only("_g") adds "_g"! | 2549 // we should have "libjvm.so" but debug_only("_g") adds "_g"! |
2539 // It is used when we are choosing the HPI library's name | |
2540 // "libhpi[_g].so" in hpi::initialize_get_interface(). | |
2541 len = strlen(buf); | 2550 len = strlen(buf); |
2542 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); | 2551 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); |
2543 } else { | 2552 } else { |
2544 // Go back to path of .so | 2553 // Go back to path of .so |
2545 realpath((char *)dlinfo.dli_fname, buf); | 2554 realpath((char *)dlinfo.dli_fname, buf); |
2557 } | 2566 } |
2558 | 2567 |
2559 | 2568 |
2560 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { | 2569 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { |
2561 // no suffix required | 2570 // no suffix required |
2571 } | |
2572 | |
2573 // This method is a copy of JDK's sysGetLastErrorString | |
2574 // from src/solaris/hpi/src/system_md.c | |
2575 | |
2576 size_t os::lasterror(char *buf, size_t len) { | |
2577 | |
2578 if (errno == 0) return 0; | |
2579 | |
2580 const char *s = ::strerror(errno); | |
2581 size_t n = ::strlen(s); | |
2582 if (n >= len) { | |
2583 n = len - 1; | |
2584 } | |
2585 ::strncpy(buf, s, n); | |
2586 buf[n] = '\0'; | |
2587 return n; | |
2562 } | 2588 } |
2563 | 2589 |
2564 | 2590 |
2565 // sun.misc.Signal | 2591 // sun.misc.Signal |
2566 | 2592 |
3466 } | 3492 } |
3467 | 3493 |
3468 // Read calls from inside the vm need to perform state transitions | 3494 // Read calls from inside the vm need to perform state transitions |
3469 size_t os::read(int fd, void *buf, unsigned int nBytes) { | 3495 size_t os::read(int fd, void *buf, unsigned int nBytes) { |
3470 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); | 3496 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); |
3497 } | |
3498 | |
3499 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { | |
3500 INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); | |
3471 } | 3501 } |
3472 | 3502 |
3473 int os::sleep(Thread* thread, jlong millis, bool interruptible) { | 3503 int os::sleep(Thread* thread, jlong millis, bool interruptible) { |
3474 assert(thread == Thread::current(), "thread consistency check"); | 3504 assert(thread == Thread::current(), "thread consistency check"); |
3475 | 3505 |
4637 bool isT2 = false; | 4667 bool isT2 = false; |
4638 | 4668 |
4639 #define ADR(x) ((uintptr_t)(x)) | 4669 #define ADR(x) ((uintptr_t)(x)) |
4640 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) | 4670 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) |
4641 | 4671 |
4642 lwpFile = open("/proc/self/lstatus", O_RDONLY, 0); | 4672 lwpFile = ::open("/proc/self/lstatus", O_RDONLY, 0); |
4643 if (lwpFile < 0) { | 4673 if (lwpFile < 0) { |
4644 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); | 4674 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); |
4645 return false; | 4675 return false; |
4646 } | 4676 } |
4647 lwpSize = 16*1024; | 4677 lwpSize = 16*1024; |
4648 for (;;) { | 4678 for (;;) { |
4649 lseek (lwpFile, 0, SEEK_SET); | 4679 ::lseek64 (lwpFile, 0, SEEK_SET); |
4650 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); | 4680 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); |
4651 if (read(lwpFile, lwpArray, lwpSize) < 0) { | 4681 if (::read(lwpFile, lwpArray, lwpSize) < 0) { |
4652 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); | 4682 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); |
4653 break; | 4683 break; |
4654 } | 4684 } |
4655 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { | 4685 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { |
4656 // We got a good snapshot - now iterate over the list. | 4686 // We got a good snapshot - now iterate over the list. |
4667 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; | 4697 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; |
4668 FREE_C_HEAP_ARRAY(char, lwpArray); // retry. | 4698 FREE_C_HEAP_ARRAY(char, lwpArray); // retry. |
4669 } | 4699 } |
4670 | 4700 |
4671 FREE_C_HEAP_ARRAY(char, lwpArray); | 4701 FREE_C_HEAP_ARRAY(char, lwpArray); |
4672 close (lwpFile); | 4702 ::close (lwpFile); |
4673 if (ThreadPriorityVerbose) { | 4703 if (ThreadPriorityVerbose) { |
4674 if (isT2) tty->print_cr("We are running with a T2 libthread\n"); | 4704 if (isT2) tty->print_cr("We are running with a T2 libthread\n"); |
4675 else tty->print_cr("We are not running with a T2 libthread\n"); | 4705 else tty->print_cr("We are not running with a T2 libthread\n"); |
4676 } | 4706 } |
4677 return isT2; | 4707 return isT2; |
4863 | 4893 |
4864 // Initialize misc. symbols as soon as possible, so we can use them | 4894 // Initialize misc. symbols as soon as possible, so we can use them |
4865 // if we need them. | 4895 // if we need them. |
4866 Solaris::misc_sym_init(); | 4896 Solaris::misc_sym_init(); |
4867 | 4897 |
4868 int fd = open("/dev/zero", O_RDWR); | 4898 int fd = ::open("/dev/zero", O_RDWR); |
4869 if (fd < 0) { | 4899 if (fd < 0) { |
4870 fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); | 4900 fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); |
4871 } else { | 4901 } else { |
4872 Solaris::set_dev_zero_fd(fd); | 4902 Solaris::set_dev_zero_fd(fd); |
4873 | 4903 |
5033 perror("os::init_2 setrlimit failed"); | 5063 perror("os::init_2 setrlimit failed"); |
5034 } | 5064 } |
5035 } | 5065 } |
5036 } | 5066 } |
5037 | 5067 |
5038 // Initialize HPI. | |
5039 jint hpi_result = hpi::initialize(); | |
5040 if (hpi_result != JNI_OK) { | |
5041 tty->print_cr("There was an error trying to initialize the HPI library."); | |
5042 return hpi_result; | |
5043 } | |
5044 | |
5045 // Calculate theoretical max. size of Threads to guard gainst | 5068 // Calculate theoretical max. size of Threads to guard gainst |
5046 // artifical out-of-memory situations, where all available address- | 5069 // artifical out-of-memory situations, where all available address- |
5047 // space has been reserved by thread stacks. Default stack size is 1Mb. | 5070 // space has been reserved by thread stacks. Default stack size is 1Mb. |
5048 size_t pre_thread_stack_size = (JavaThread::stack_size_at_create()) ? | 5071 size_t pre_thread_stack_size = (JavaThread::stack_size_at_create()) ? |
5049 JavaThread::stack_size_at_create() : (1*K*K); | 5072 JavaThread::stack_size_at_create() : (1*K*K); |
5098 if( mprotect((char *)_polling_page, page_size, PROT_READ) != 0 ) | 5121 if( mprotect((char *)_polling_page, page_size, PROT_READ) != 0 ) |
5099 fatal("Could not enable polling page"); | 5122 fatal("Could not enable polling page"); |
5100 }; | 5123 }; |
5101 | 5124 |
5102 // OS interface. | 5125 // OS interface. |
5103 | |
5104 int os::stat(const char *path, struct stat *sbuf) { | |
5105 char pathbuf[MAX_PATH]; | |
5106 if (strlen(path) > MAX_PATH - 1) { | |
5107 errno = ENAMETOOLONG; | |
5108 return -1; | |
5109 } | |
5110 hpi::native_path(strcpy(pathbuf, path)); | |
5111 return ::stat(pathbuf, sbuf); | |
5112 } | |
5113 | |
5114 | 5126 |
5115 bool os::check_heap(bool force) { return true; } | 5127 bool os::check_heap(bool force) { return true; } |
5116 | 5128 |
5117 typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); | 5129 typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); |
5118 static vsnprintf_t sol_vsnprintf = NULL; | 5130 static vsnprintf_t sol_vsnprintf = NULL; |
5154 } | 5166 } |
5155 closedir(dir); | 5167 closedir(dir); |
5156 return result; | 5168 return result; |
5157 } | 5169 } |
5158 | 5170 |
5171 // This code originates from JDK's sysOpen and open64_w | |
5172 // from src/solaris/hpi/src/system_md.c | |
5173 | |
5174 #ifndef O_DELETE | |
5175 #define O_DELETE 0x10000 | |
5176 #endif | |
5177 | |
5178 // Open a file. Unlink the file immediately after open returns | |
5179 // if the specified oflag has the O_DELETE flag set. | |
5180 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c | |
5181 | |
5182 int os::open(const char *path, int oflag, int mode) { | |
5183 if (strlen(path) > MAX_PATH - 1) { | |
5184 errno = ENAMETOOLONG; | |
5185 return -1; | |
5186 } | |
5187 int fd; | |
5188 int o_delete = (oflag & O_DELETE); | |
5189 oflag = oflag & ~O_DELETE; | |
5190 | |
5191 fd = ::open(path, oflag, mode); | |
5192 if (fd == -1) return -1; | |
5193 | |
5194 //If the open succeeded, the file might still be a directory | |
5195 { | |
5196 struct stat64 buf64; | |
5197 int ret = ::fstat64(fd, &buf64); | |
5198 int st_mode = buf64.st_mode; | |
5199 | |
5200 if (ret != -1) { | |
5201 if ((st_mode & S_IFMT) == S_IFDIR) { | |
5202 errno = EISDIR; | |
5203 ::close(fd); | |
5204 return -1; | |
5205 } | |
5206 } else { | |
5207 ::close(fd); | |
5208 return -1; | |
5209 } | |
5210 } | |
5211 /* | |
5212 * 32-bit Solaris systems suffer from: | |
5213 * | |
5214 * - an historical default soft limit of 256 per-process file | |
5215 * descriptors that is too low for many Java programs. | |
5216 * | |
5217 * - a design flaw where file descriptors created using stdio | |
5218 * fopen must be less than 256, _even_ when the first limit above | |
5219 * has been raised. This can cause calls to fopen (but not calls to | |
5220 * open, for example) to fail mysteriously, perhaps in 3rd party | |
5221 * native code (although the JDK itself uses fopen). One can hardly | |
5222 * criticize them for using this most standard of all functions. | |
5223 * | |
5224 * We attempt to make everything work anyways by: | |
5225 * | |
5226 * - raising the soft limit on per-process file descriptors beyond | |
5227 * 256 | |
5228 * | |
5229 * - As of Solaris 10u4, we can request that Solaris raise the 256 | |
5230 * stdio fopen limit by calling function enable_extended_FILE_stdio. | |
5231 * This is done in init_2 and recorded in enabled_extended_FILE_stdio | |
5232 * | |
5233 * - If we are stuck on an old (pre 10u4) Solaris system, we can | |
5234 * workaround the bug by remapping non-stdio file descriptors below | |
5235 * 256 to ones beyond 256, which is done below. | |
5236 * | |
5237 * See: | |
5238 * 1085341: 32-bit stdio routines should support file descriptors >255 | |
5239 * 6533291: Work around 32-bit Solaris stdio limit of 256 open files | |
5240 * 6431278: Netbeans crash on 32 bit Solaris: need to call | |
5241 * enable_extended_FILE_stdio() in VM initialisation | |
5242 * Giri Mandalika's blog | |
5243 * http://technopark02.blogspot.com/2005_05_01_archive.html | |
5244 */ | |
5245 #ifndef _LP64 | |
5246 if ((!enabled_extended_FILE_stdio) && fd < 256) { | |
5247 int newfd = ::fcntl(fd, F_DUPFD, 256); | |
5248 if (newfd != -1) { | |
5249 ::close(fd); | |
5250 fd = newfd; | |
5251 } | |
5252 } | |
5253 #endif // 32-bit Solaris | |
5254 /* | |
5255 * All file descriptors that are opened in the JVM and not | |
5256 * specifically destined for a subprocess should have the | |
5257 * close-on-exec flag set. If we don't set it, then careless 3rd | |
5258 * party native code might fork and exec without closing all | |
5259 * appropriate file descriptors (e.g. as we do in closeDescriptors in | |
5260 * UNIXProcess.c), and this in turn might: | |
5261 * | |
5262 * - cause end-of-file to fail to be detected on some file | |
5263 * descriptors, resulting in mysterious hangs, or | |
5264 * | |
5265 * - might cause an fopen in the subprocess to fail on a system | |
5266 * suffering from bug 1085341. | |
5267 * | |
5268 * (Yes, the default setting of the close-on-exec flag is a Unix | |
5269 * design flaw) | |
5270 * | |
5271 * See: | |
5272 * 1085341: 32-bit stdio routines should support file descriptors >255 | |
5273 * 4843136: (process) pipe file descriptor from Runtime.exec not being closed | |
5274 * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 | |
5275 */ | |
5276 #ifdef FD_CLOEXEC | |
5277 { | |
5278 int flags = ::fcntl(fd, F_GETFD); | |
5279 if (flags != -1) | |
5280 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); | |
5281 } | |
5282 #endif | |
5283 | |
5284 if (o_delete != 0) { | |
5285 ::unlink(path); | |
5286 } | |
5287 return fd; | |
5288 } | |
5289 | |
5159 // create binary file, rewriting existing file if required | 5290 // create binary file, rewriting existing file if required |
5160 int os::create_binary_file(const char* path, bool rewrite_existing) { | 5291 int os::create_binary_file(const char* path, bool rewrite_existing) { |
5161 int oflags = O_WRONLY | O_CREAT; | 5292 int oflags = O_WRONLY | O_CREAT; |
5162 if (!rewrite_existing) { | 5293 if (!rewrite_existing) { |
5163 oflags |= O_EXCL; | 5294 oflags |= O_EXCL; |
5171 } | 5302 } |
5172 | 5303 |
5173 // move file pointer to the specified offset | 5304 // move file pointer to the specified offset |
5174 jlong os::seek_to_file_offset(int fd, jlong offset) { | 5305 jlong os::seek_to_file_offset(int fd, jlong offset) { |
5175 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); | 5306 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); |
5307 } | |
5308 | |
5309 jlong os::lseek(int fd, jlong offset, int whence) { | |
5310 return (jlong) ::lseek64(fd, offset, whence); | |
5311 } | |
5312 | |
5313 char * os::native_path(char *path) { | |
5314 return path; | |
5315 } | |
5316 | |
5317 int os::ftruncate(int fd, jlong length) { | |
5318 return ::ftruncate64(fd, length); | |
5319 } | |
5320 | |
5321 int os::fsync(int fd) { | |
5322 RESTARTABLE_RETURN_INT(::fsync(fd)); | |
5323 } | |
5324 | |
5325 int os::available(int fd, jlong *bytes) { | |
5326 jlong cur, end; | |
5327 int mode; | |
5328 struct stat64 buf64; | |
5329 | |
5330 if (::fstat64(fd, &buf64) >= 0) { | |
5331 mode = buf64.st_mode; | |
5332 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { | |
5333 /* | |
5334 * XXX: is the following call interruptible? If so, this might | |
5335 * need to go through the INTERRUPT_IO() wrapper as for other | |
5336 * blocking, interruptible calls in this file. | |
5337 */ | |
5338 int n,ioctl_return; | |
5339 | |
5340 INTERRUPTIBLE(::ioctl(fd, FIONREAD, &n),ioctl_return,os::Solaris::clear_interrupted); | |
5341 if (ioctl_return>= 0) { | |
5342 *bytes = n; | |
5343 return 1; | |
5344 } | |
5345 } | |
5346 } | |
5347 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { | |
5348 return 0; | |
5349 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { | |
5350 return 0; | |
5351 } else if (::lseek64(fd, cur, SEEK_SET) == -1) { | |
5352 return 0; | |
5353 } | |
5354 *bytes = end - cur; | |
5355 return 1; | |
5176 } | 5356 } |
5177 | 5357 |
5178 // Map a block of memory. | 5358 // Map a block of memory. |
5179 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | 5359 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
5180 char *addr, size_t bytes, bool read_only, | 5360 char *addr, size_t bytes, bool read_only, |
5231 } | 5411 } |
5232 | 5412 |
5233 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 5413 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
5234 if (fd != -1) { | 5414 if (fd != -1) { |
5235 struct stat buf; | 5415 struct stat buf; |
5236 close(fd); | 5416 ::close(fd); |
5237 while (::stat(filename, &buf) == 0) { | 5417 while (::stat(filename, &buf) == 0) { |
5238 (void)::poll(NULL, 0, 100); | 5418 (void)::poll(NULL, 0, 100); |
5239 } | 5419 } |
5240 } else { | 5420 } else { |
5241 jio_fprintf(stderr, | 5421 jio_fprintf(stderr, |
5428 int fd; | 5608 int fd; |
5429 | 5609 |
5430 sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", | 5610 sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", |
5431 getpid(), | 5611 getpid(), |
5432 thread->osthread()->lwp_id()); | 5612 thread->osthread()->lwp_id()); |
5433 fd = open(proc_name, O_RDONLY); | 5613 fd = ::open(proc_name, O_RDONLY); |
5434 if ( fd == -1 ) return -1; | 5614 if ( fd == -1 ) return -1; |
5435 | 5615 |
5436 do { | 5616 do { |
5437 count = pread(fd, | 5617 count = ::pread(fd, |
5438 (void *)&prusage.pr_utime, | 5618 (void *)&prusage.pr_utime, |
5439 thr_time_size, | 5619 thr_time_size, |
5440 thr_time_off); | 5620 thr_time_off); |
5441 } while (count < 0 && errno == EINTR); | 5621 } while (count < 0 && errno == EINTR); |
5442 close(fd); | 5622 ::close(fd); |
5443 if ( count < 0 ) return -1; | 5623 if ( count < 0 ) return -1; |
5444 | 5624 |
5445 if (user_sys_cpu_time) { | 5625 if (user_sys_cpu_time) { |
5446 // user + system CPU time | 5626 // user + system CPU time |
5447 lwp_time = (((jlong)prusage.pr_stime.tv_sec + | 5627 lwp_time = (((jlong)prusage.pr_stime.tv_sec + |
6109 if (::stat(libmawtpath, &statbuf) == 0) return false; | 6289 if (::stat(libmawtpath, &statbuf) == 0) return false; |
6110 | 6290 |
6111 return true; | 6291 return true; |
6112 } | 6292 } |
6113 | 6293 |
6114 | 6294 size_t os::write(int fd, const void *buf, unsigned int nBytes) { |
6295 INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted); | |
6296 } | |
6297 | |
6298 int os::close(int fd) { | |
6299 RESTARTABLE_RETURN_INT(::close(fd)); | |
6300 } | |
6301 | |
6302 int os::socket_close(int fd) { | |
6303 RESTARTABLE_RETURN_INT(::close(fd)); | |
6304 } | |
6305 | |
6306 int os::recv(int fd, char *buf, int nBytes, int flags) { | |
6307 INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); | |
6308 } | |
6309 | |
6310 | |
6311 int os::send(int fd, char *buf, int nBytes, int flags) { | |
6312 INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); | |
6313 } | |
6314 | |
6315 int os::raw_send(int fd, char *buf, int nBytes, int flags) { | |
6316 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); | |
6317 } | |
6318 | |
6319 // As both poll and select can be interrupted by signals, we have to be | |
6320 // prepared to restart the system call after updating the timeout, unless | |
6321 // a poll() is done with timeout == -1, in which case we repeat with this | |
6322 // "wait forever" value. | |
6323 | |
6324 int os::timeout(int fd, long timeout) { | |
6325 int res; | |
6326 struct timeval t; | |
6327 julong prevtime, newtime; | |
6328 static const char* aNull = 0; | |
6329 struct pollfd pfd; | |
6330 pfd.fd = fd; | |
6331 pfd.events = POLLIN; | |
6332 | |
6333 gettimeofday(&t, &aNull); | |
6334 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
6335 | |
6336 for(;;) { | |
6337 INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted); | |
6338 if(res == OS_ERR && errno == EINTR) { | |
6339 if(timeout != -1) { | |
6340 gettimeofday(&t, &aNull); | |
6341 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000; | |
6342 timeout -= newtime - prevtime; | |
6343 if(timeout <= 0) | |
6344 return OS_OK; | |
6345 prevtime = newtime; | |
6346 } | |
6347 } else return res; | |
6348 } | |
6349 } | |
6350 | |
6351 int os::connect(int fd, struct sockaddr *him, int len) { | |
6352 int _result; | |
6353 INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result, | |
6354 os::Solaris::clear_interrupted); | |
6355 | |
6356 // Depending on when thread interruption is reset, _result could be | |
6357 // one of two values when errno == EINTR | |
6358 | |
6359 if (((_result == OS_INTRPT) || (_result == OS_ERR)) | |
6360 && (errno == EINTR)) { | |
6361 /* restarting a connect() changes its errno semantics */ | |
6362 INTERRUPTIBLE(::connect(fd, him, len), _result, | |
6363 os::Solaris::clear_interrupted); | |
6364 /* undo these changes */ | |
6365 if (_result == OS_ERR) { | |
6366 if (errno == EALREADY) { | |
6367 errno = EINPROGRESS; /* fall through */ | |
6368 } else if (errno == EISCONN) { | |
6369 errno = 0; | |
6370 return OS_OK; | |
6371 } | |
6372 } | |
6373 } | |
6374 return _result; | |
6375 } | |
6376 | |
6377 int os::accept(int fd, struct sockaddr *him, int *len) { | |
6378 if (fd < 0) | |
6379 return OS_ERR; | |
6380 INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him,\ | |
6381 (socklen_t*) len), os::Solaris::clear_interrupted); | |
6382 } | |
6383 | |
6384 int os::recvfrom(int fd, char *buf, int nBytes, int flags, | |
6385 sockaddr *from, int *fromlen) { | |
6386 //%%note jvm_r11 | |
6387 INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes,\ | |
6388 flags, from, fromlen), os::Solaris::clear_interrupted); | |
6389 } | |
6390 | |
6391 int os::sendto(int fd, char *buf, int len, int flags, | |
6392 struct sockaddr *to, int tolen) { | |
6393 //%%note jvm_r11 | |
6394 INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, flags,\ | |
6395 to, tolen), os::Solaris::clear_interrupted); | |
6396 } | |
6397 | |
6398 int os::socket_available(int fd, jint *pbytes) { | |
6399 if (fd < 0) | |
6400 return OS_OK; | |
6401 | |
6402 int ret; | |
6403 | |
6404 RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret); | |
6405 | |
6406 //%% note ioctl can return 0 when successful, JVM_SocketAvailable | |
6407 // is expected to return 0 on failure and 1 on success to the jdk. | |
6408 | |
6409 return (ret == OS_ERR) ? 0 : 1; | |
6410 } | |
6411 | |
6412 | |
6413 int os::bind(int fd, struct sockaddr *him, int len) { | |
6414 INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),\ | |
6415 os::Solaris::clear_interrupted); | |
6416 } | |
6417 |