Mercurial > hg > truffle
comparison src/os/solaris/vm/os_solaris.cpp @ 1980:828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
Summary: move functions from hpi library to hotspot, communicate with licensees and open source community, check jdk for dependency, file CCC request
Reviewed-by: coleenp, acorn, dsamersoff
author | ikrylov |
---|---|
date | Wed, 01 Dec 2010 18:26:32 -0500 |
parents | f95d63e2154a |
children | 54f5dd2aa1d9 c04052fd6ae1 |
comparison
equal
deleted
inserted
replaced
1972:f95d63e2154a | 1980:828eafbd85cc |
---|---|
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" |
113 # include <sys/rtpriocntl.h> | 112 # include <sys/rtpriocntl.h> |
114 # include <sys/tspriocntl.h> | 113 # include <sys/tspriocntl.h> |
115 # include <sys/iapriocntl.h> | 114 # include <sys/iapriocntl.h> |
116 # include <sys/loadavg.h> | 115 # include <sys/loadavg.h> |
117 # include <string.h> | 116 # include <string.h> |
117 # include <stdio.h> | |
118 | 118 |
119 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later | 119 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later |
120 # include <sys/procfs.h> // see comment in <sys/procfs.h> | 120 # include <sys/procfs.h> // see comment in <sys/procfs.h> |
121 | 121 |
122 #define MAX_PATH (2 * K) | 122 #define MAX_PATH (2 * K) |
217 80, 96, 112, 124, 127 }; | 217 80, 96, 112, 124, 127 }; |
218 | 218 |
219 // System parameters used internally | 219 // System parameters used internally |
220 static clock_t clock_tics_per_sec = 100; | 220 static clock_t clock_tics_per_sec = 100; |
221 | 221 |
222 // Track if we have called enable_extended_FILE_stdio (on Solaris 10u4+) | |
223 static bool enabled_extended_FILE_stdio = false; | |
224 | |
222 // For diagnostics to print a message once. see run_periodic_checks | 225 // For diagnostics to print a message once. see run_periodic_checks |
223 static bool check_addr0_done = false; | 226 static bool check_addr0_done = false; |
224 static sigset_t check_signal_done; | 227 static sigset_t check_signal_done; |
225 static bool check_signals = true; | 228 static bool check_signals = true; |
226 | 229 |
384 // setup_interruptible saves the thread state before going into an | 387 // setup_interruptible saves the thread state before going into an |
385 // interruptible system call. | 388 // interruptible system call. |
386 // The saved state is used to restore the thread to | 389 // The saved state is used to restore the thread to |
387 // its former state whether or not an interrupt is received. | 390 // its former state whether or not an interrupt is received. |
388 // Used by classloader os::read | 391 // Used by classloader os::read |
389 // hpi calls skip this layer and stay in _thread_in_native | 392 // os::restartable_read calls skip this layer and stay in _thread_in_native |
390 | 393 |
391 void os::Solaris::setup_interruptible(JavaThread* thread) { | 394 void os::Solaris::setup_interruptible(JavaThread* thread) { |
392 | 395 |
393 JavaThreadState thread_state = thread->thread_state(); | 396 JavaThreadState thread_state = thread->thread_state(); |
394 | 397 |
1748 } | 1751 } |
1749 | 1752 |
1750 bool os::supports_vtime() { return true; } | 1753 bool os::supports_vtime() { return true; } |
1751 | 1754 |
1752 bool os::enable_vtime() { | 1755 bool os::enable_vtime() { |
1753 int fd = open("/proc/self/ctl", O_WRONLY); | 1756 int fd = ::open("/proc/self/ctl", O_WRONLY); |
1754 if (fd == -1) | 1757 if (fd == -1) |
1755 return false; | 1758 return false; |
1756 | 1759 |
1757 long cmd[] = { PCSET, PR_MSACCT }; | 1760 long cmd[] = { PCSET, PR_MSACCT }; |
1758 int res = write(fd, cmd, sizeof(long) * 2); | 1761 int res = ::write(fd, cmd, sizeof(long) * 2); |
1759 close(fd); | 1762 ::close(fd); |
1760 if (res != sizeof(long) * 2) | 1763 if (res != sizeof(long) * 2) |
1761 return false; | 1764 return false; |
1762 | 1765 |
1763 return true; | 1766 return true; |
1764 } | 1767 } |
1765 | 1768 |
1766 bool os::vtime_enabled() { | 1769 bool os::vtime_enabled() { |
1767 int fd = open("/proc/self/status", O_RDONLY); | 1770 int fd = ::open("/proc/self/status", O_RDONLY); |
1768 if (fd == -1) | 1771 if (fd == -1) |
1769 return false; | 1772 return false; |
1770 | 1773 |
1771 pstatus_t status; | 1774 pstatus_t status; |
1772 int res = read(fd, (void*) &status, sizeof(pstatus_t)); | 1775 int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); |
1773 close(fd); | 1776 ::close(fd); |
1774 if (res != sizeof(pstatus_t)) | 1777 if (res != sizeof(pstatus_t)) |
1775 return false; | 1778 return false; |
1776 | 1779 |
1777 return status.pr_flags & PR_MSACCT; | 1780 return status.pr_flags & PR_MSACCT; |
1778 } | 1781 } |
1884 return os::stat(filename, &statbuf) == 0; | 1887 return os::stat(filename, &statbuf) == 0; |
1885 } | 1888 } |
1886 | 1889 |
1887 void os::dll_build_name(char* buffer, size_t buflen, | 1890 void os::dll_build_name(char* buffer, size_t buflen, |
1888 const char* pname, const char* fname) { | 1891 const char* pname, const char* fname) { |
1889 // Copied from libhpi | |
1890 const size_t pnamelen = pname ? strlen(pname) : 0; | 1892 const size_t pnamelen = pname ? strlen(pname) : 0; |
1891 | 1893 |
1892 // Quietly truncate on buffer overflow. Should be an error. | 1894 // Quietly truncate on buffer overflow. Should be an error. |
1893 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { | 1895 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { |
1894 *buffer = '\0'; | 1896 *buffer = '\0'; |
2180 | 2182 |
2181 void* os::dll_lookup(void* handle, const char* name) { | 2183 void* os::dll_lookup(void* handle, const char* name) { |
2182 return dlsym(handle, name); | 2184 return dlsym(handle, name); |
2183 } | 2185 } |
2184 | 2186 |
2185 | 2187 int os::stat(const char *path, struct stat *sbuf) { |
2186 bool _print_ascii_file(const char* filename, outputStream* st) { | 2188 char pathbuf[MAX_PATH]; |
2187 int fd = open(filename, O_RDONLY); | 2189 if (strlen(path) > MAX_PATH - 1) { |
2190 errno = ENAMETOOLONG; | |
2191 return -1; | |
2192 } | |
2193 os::native_path(strcpy(pathbuf, path)); | |
2194 return ::stat(pathbuf, sbuf); | |
2195 } | |
2196 | |
2197 static bool _print_ascii_file(const char* filename, outputStream* st) { | |
2198 int fd = ::open(filename, O_RDONLY); | |
2188 if (fd == -1) { | 2199 if (fd == -1) { |
2189 return false; | 2200 return false; |
2190 } | 2201 } |
2191 | 2202 |
2192 char buf[32]; | 2203 char buf[32]; |
2193 int bytes; | 2204 int bytes; |
2194 while ((bytes = read(fd, buf, sizeof(buf))) > 0) { | 2205 while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { |
2195 st->print_raw(buf, bytes); | 2206 st->print_raw(buf, bytes); |
2196 } | 2207 } |
2197 | 2208 |
2198 close(fd); | 2209 ::close(fd); |
2199 | 2210 |
2200 return true; | 2211 return true; |
2201 } | 2212 } |
2202 | 2213 |
2203 void os::print_os_info(outputStream* st) { | 2214 void os::print_os_info(outputStream* st) { |
2256 } | 2267 } |
2257 | 2268 |
2258 | 2269 |
2259 static bool check_addr0(outputStream* st) { | 2270 static bool check_addr0(outputStream* st) { |
2260 jboolean status = false; | 2271 jboolean status = false; |
2261 int fd = open("/proc/self/map",O_RDONLY); | 2272 int fd = ::open("/proc/self/map",O_RDONLY); |
2262 if (fd >= 0) { | 2273 if (fd >= 0) { |
2263 prmap_t p; | 2274 prmap_t p; |
2264 while(read(fd, &p, sizeof(p)) > 0) { | 2275 while(::read(fd, &p, sizeof(p)) > 0) { |
2265 if (p.pr_vaddr == 0x0) { | 2276 if (p.pr_vaddr == 0x0) { |
2266 st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); | 2277 st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); |
2267 st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); | 2278 st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); |
2268 st->print("Access:"); | 2279 st->print("Access:"); |
2269 st->print("%s",(p.pr_mflags & MA_READ) ? "r" : "-"); | 2280 st->print("%s",(p.pr_mflags & MA_READ) ? "r" : "-"); |
2270 st->print("%s",(p.pr_mflags & MA_WRITE) ? "w" : "-"); | 2281 st->print("%s",(p.pr_mflags & MA_WRITE) ? "w" : "-"); |
2271 st->print("%s",(p.pr_mflags & MA_EXEC) ? "x" : "-"); | 2282 st->print("%s",(p.pr_mflags & MA_EXEC) ? "x" : "-"); |
2272 st->cr(); | 2283 st->cr(); |
2273 status = true; | 2284 status = true; |
2274 } | 2285 } |
2275 close(fd); | 2286 ::close(fd); |
2276 } | 2287 } |
2277 } | 2288 } |
2278 return status; | 2289 return status; |
2279 } | 2290 } |
2280 | 2291 |
2518 | 2529 |
2519 if (0 == access(buf, F_OK)) { | 2530 if (0 == access(buf, F_OK)) { |
2520 // Use current module name "libjvm[_g].so" instead of | 2531 // Use current module name "libjvm[_g].so" instead of |
2521 // "libjvm"debug_only("_g")".so" since for fastdebug version | 2532 // "libjvm"debug_only("_g")".so" since for fastdebug version |
2522 // we should have "libjvm.so" but debug_only("_g") adds "_g"! | 2533 // we should have "libjvm.so" but debug_only("_g") adds "_g"! |
2523 // It is used when we are choosing the HPI library's name | |
2524 // "libhpi[_g].so" in hpi::initialize_get_interface(). | |
2525 len = strlen(buf); | 2534 len = strlen(buf); |
2526 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); | 2535 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); |
2527 } else { | 2536 } else { |
2528 // Go back to path of .so | 2537 // Go back to path of .so |
2529 realpath((char *)dlinfo.dli_fname, buf); | 2538 realpath((char *)dlinfo.dli_fname, buf); |
2541 } | 2550 } |
2542 | 2551 |
2543 | 2552 |
2544 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { | 2553 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { |
2545 // no suffix required | 2554 // no suffix required |
2555 } | |
2556 | |
2557 // This method is a copy of JDK's sysGetLastErrorString | |
2558 // from src/solaris/hpi/src/system_md.c | |
2559 | |
2560 size_t os::lasterror(char *buf, size_t len) { | |
2561 | |
2562 if (errno == 0) return 0; | |
2563 | |
2564 const char *s = ::strerror(errno); | |
2565 size_t n = ::strlen(s); | |
2566 if (n >= len) { | |
2567 n = len - 1; | |
2568 } | |
2569 ::strncpy(buf, s, n); | |
2570 buf[n] = '\0'; | |
2571 return n; | |
2546 } | 2572 } |
2547 | 2573 |
2548 | 2574 |
2549 // sun.misc.Signal | 2575 // sun.misc.Signal |
2550 | 2576 |
3450 } | 3476 } |
3451 | 3477 |
3452 // Read calls from inside the vm need to perform state transitions | 3478 // Read calls from inside the vm need to perform state transitions |
3453 size_t os::read(int fd, void *buf, unsigned int nBytes) { | 3479 size_t os::read(int fd, void *buf, unsigned int nBytes) { |
3454 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); | 3480 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); |
3481 } | |
3482 | |
3483 size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { | |
3484 INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); | |
3455 } | 3485 } |
3456 | 3486 |
3457 int os::sleep(Thread* thread, jlong millis, bool interruptible) { | 3487 int os::sleep(Thread* thread, jlong millis, bool interruptible) { |
3458 assert(thread == Thread::current(), "thread consistency check"); | 3488 assert(thread == Thread::current(), "thread consistency check"); |
3459 | 3489 |
4621 bool isT2 = false; | 4651 bool isT2 = false; |
4622 | 4652 |
4623 #define ADR(x) ((uintptr_t)(x)) | 4653 #define ADR(x) ((uintptr_t)(x)) |
4624 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) | 4654 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) |
4625 | 4655 |
4626 lwpFile = open("/proc/self/lstatus", O_RDONLY, 0); | 4656 lwpFile = ::open("/proc/self/lstatus", O_RDONLY, 0); |
4627 if (lwpFile < 0) { | 4657 if (lwpFile < 0) { |
4628 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); | 4658 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); |
4629 return false; | 4659 return false; |
4630 } | 4660 } |
4631 lwpSize = 16*1024; | 4661 lwpSize = 16*1024; |
4632 for (;;) { | 4662 for (;;) { |
4633 lseek (lwpFile, 0, SEEK_SET); | 4663 ::lseek64 (lwpFile, 0, SEEK_SET); |
4634 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); | 4664 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); |
4635 if (read(lwpFile, lwpArray, lwpSize) < 0) { | 4665 if (::read(lwpFile, lwpArray, lwpSize) < 0) { |
4636 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); | 4666 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); |
4637 break; | 4667 break; |
4638 } | 4668 } |
4639 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { | 4669 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { |
4640 // We got a good snapshot - now iterate over the list. | 4670 // We got a good snapshot - now iterate over the list. |
4651 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; | 4681 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; |
4652 FREE_C_HEAP_ARRAY(char, lwpArray); // retry. | 4682 FREE_C_HEAP_ARRAY(char, lwpArray); // retry. |
4653 } | 4683 } |
4654 | 4684 |
4655 FREE_C_HEAP_ARRAY(char, lwpArray); | 4685 FREE_C_HEAP_ARRAY(char, lwpArray); |
4656 close (lwpFile); | 4686 ::close (lwpFile); |
4657 if (ThreadPriorityVerbose) { | 4687 if (ThreadPriorityVerbose) { |
4658 if (isT2) tty->print_cr("We are running with a T2 libthread\n"); | 4688 if (isT2) tty->print_cr("We are running with a T2 libthread\n"); |
4659 else tty->print_cr("We are not running with a T2 libthread\n"); | 4689 else tty->print_cr("We are not running with a T2 libthread\n"); |
4660 } | 4690 } |
4661 return isT2; | 4691 return isT2; |
4847 | 4877 |
4848 // Initialize misc. symbols as soon as possible, so we can use them | 4878 // Initialize misc. symbols as soon as possible, so we can use them |
4849 // if we need them. | 4879 // if we need them. |
4850 Solaris::misc_sym_init(); | 4880 Solaris::misc_sym_init(); |
4851 | 4881 |
4852 int fd = open("/dev/zero", O_RDWR); | 4882 int fd = ::open("/dev/zero", O_RDWR); |
4853 if (fd < 0) { | 4883 if (fd < 0) { |
4854 fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); | 4884 fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); |
4855 } else { | 4885 } else { |
4856 Solaris::set_dev_zero_fd(fd); | 4886 Solaris::set_dev_zero_fd(fd); |
4857 | 4887 |
5017 perror("os::init_2 setrlimit failed"); | 5047 perror("os::init_2 setrlimit failed"); |
5018 } | 5048 } |
5019 } | 5049 } |
5020 } | 5050 } |
5021 | 5051 |
5022 // Initialize HPI. | |
5023 jint hpi_result = hpi::initialize(); | |
5024 if (hpi_result != JNI_OK) { | |
5025 tty->print_cr("There was an error trying to initialize the HPI library."); | |
5026 return hpi_result; | |
5027 } | |
5028 | |
5029 // Calculate theoretical max. size of Threads to guard gainst | 5052 // Calculate theoretical max. size of Threads to guard gainst |
5030 // artifical out-of-memory situations, where all available address- | 5053 // artifical out-of-memory situations, where all available address- |
5031 // space has been reserved by thread stacks. Default stack size is 1Mb. | 5054 // space has been reserved by thread stacks. Default stack size is 1Mb. |
5032 size_t pre_thread_stack_size = (JavaThread::stack_size_at_create()) ? | 5055 size_t pre_thread_stack_size = (JavaThread::stack_size_at_create()) ? |
5033 JavaThread::stack_size_at_create() : (1*K*K); | 5056 JavaThread::stack_size_at_create() : (1*K*K); |
5082 if( mprotect((char *)_polling_page, page_size, PROT_READ) != 0 ) | 5105 if( mprotect((char *)_polling_page, page_size, PROT_READ) != 0 ) |
5083 fatal("Could not enable polling page"); | 5106 fatal("Could not enable polling page"); |
5084 }; | 5107 }; |
5085 | 5108 |
5086 // OS interface. | 5109 // OS interface. |
5087 | |
5088 int os::stat(const char *path, struct stat *sbuf) { | |
5089 char pathbuf[MAX_PATH]; | |
5090 if (strlen(path) > MAX_PATH - 1) { | |
5091 errno = ENAMETOOLONG; | |
5092 return -1; | |
5093 } | |
5094 hpi::native_path(strcpy(pathbuf, path)); | |
5095 return ::stat(pathbuf, sbuf); | |
5096 } | |
5097 | |
5098 | 5110 |
5099 bool os::check_heap(bool force) { return true; } | 5111 bool os::check_heap(bool force) { return true; } |
5100 | 5112 |
5101 typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); | 5113 typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); |
5102 static vsnprintf_t sol_vsnprintf = NULL; | 5114 static vsnprintf_t sol_vsnprintf = NULL; |
5138 } | 5150 } |
5139 closedir(dir); | 5151 closedir(dir); |
5140 return result; | 5152 return result; |
5141 } | 5153 } |
5142 | 5154 |
5155 // This code originates from JDK's sysOpen and open64_w | |
5156 // from src/solaris/hpi/src/system_md.c | |
5157 | |
5158 #ifndef O_DELETE | |
5159 #define O_DELETE 0x10000 | |
5160 #endif | |
5161 | |
5162 // Open a file. Unlink the file immediately after open returns | |
5163 // if the specified oflag has the O_DELETE flag set. | |
5164 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c | |
5165 | |
5166 int os::open(const char *path, int oflag, int mode) { | |
5167 if (strlen(path) > MAX_PATH - 1) { | |
5168 errno = ENAMETOOLONG; | |
5169 return -1; | |
5170 } | |
5171 int fd; | |
5172 int o_delete = (oflag & O_DELETE); | |
5173 oflag = oflag & ~O_DELETE; | |
5174 | |
5175 fd = ::open(path, oflag, mode); | |
5176 if (fd == -1) return -1; | |
5177 | |
5178 //If the open succeeded, the file might still be a directory | |
5179 { | |
5180 struct stat64 buf64; | |
5181 int ret = ::fstat64(fd, &buf64); | |
5182 int st_mode = buf64.st_mode; | |
5183 | |
5184 if (ret != -1) { | |
5185 if ((st_mode & S_IFMT) == S_IFDIR) { | |
5186 errno = EISDIR; | |
5187 ::close(fd); | |
5188 return -1; | |
5189 } | |
5190 } else { | |
5191 ::close(fd); | |
5192 return -1; | |
5193 } | |
5194 } | |
5195 /* | |
5196 * 32-bit Solaris systems suffer from: | |
5197 * | |
5198 * - an historical default soft limit of 256 per-process file | |
5199 * descriptors that is too low for many Java programs. | |
5200 * | |
5201 * - a design flaw where file descriptors created using stdio | |
5202 * fopen must be less than 256, _even_ when the first limit above | |
5203 * has been raised. This can cause calls to fopen (but not calls to | |
5204 * open, for example) to fail mysteriously, perhaps in 3rd party | |
5205 * native code (although the JDK itself uses fopen). One can hardly | |
5206 * criticize them for using this most standard of all functions. | |
5207 * | |
5208 * We attempt to make everything work anyways by: | |
5209 * | |
5210 * - raising the soft limit on per-process file descriptors beyond | |
5211 * 256 | |
5212 * | |
5213 * - As of Solaris 10u4, we can request that Solaris raise the 256 | |
5214 * stdio fopen limit by calling function enable_extended_FILE_stdio. | |
5215 * This is done in init_2 and recorded in enabled_extended_FILE_stdio | |
5216 * | |
5217 * - If we are stuck on an old (pre 10u4) Solaris system, we can | |
5218 * workaround the bug by remapping non-stdio file descriptors below | |
5219 * 256 to ones beyond 256, which is done below. | |
5220 * | |
5221 * See: | |
5222 * 1085341: 32-bit stdio routines should support file descriptors >255 | |
5223 * 6533291: Work around 32-bit Solaris stdio limit of 256 open files | |
5224 * 6431278: Netbeans crash on 32 bit Solaris: need to call | |
5225 * enable_extended_FILE_stdio() in VM initialisation | |
5226 * Giri Mandalika's blog | |
5227 * http://technopark02.blogspot.com/2005_05_01_archive.html | |
5228 */ | |
5229 #ifndef _LP64 | |
5230 if ((!enabled_extended_FILE_stdio) && fd < 256) { | |
5231 int newfd = ::fcntl(fd, F_DUPFD, 256); | |
5232 if (newfd != -1) { | |
5233 ::close(fd); | |
5234 fd = newfd; | |
5235 } | |
5236 } | |
5237 #endif // 32-bit Solaris | |
5238 /* | |
5239 * All file descriptors that are opened in the JVM and not | |
5240 * specifically destined for a subprocess should have the | |
5241 * close-on-exec flag set. If we don't set it, then careless 3rd | |
5242 * party native code might fork and exec without closing all | |
5243 * appropriate file descriptors (e.g. as we do in closeDescriptors in | |
5244 * UNIXProcess.c), and this in turn might: | |
5245 * | |
5246 * - cause end-of-file to fail to be detected on some file | |
5247 * descriptors, resulting in mysterious hangs, or | |
5248 * | |
5249 * - might cause an fopen in the subprocess to fail on a system | |
5250 * suffering from bug 1085341. | |
5251 * | |
5252 * (Yes, the default setting of the close-on-exec flag is a Unix | |
5253 * design flaw) | |
5254 * | |
5255 * See: | |
5256 * 1085341: 32-bit stdio routines should support file descriptors >255 | |
5257 * 4843136: (process) pipe file descriptor from Runtime.exec not being closed | |
5258 * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 | |
5259 */ | |
5260 #ifdef FD_CLOEXEC | |
5261 { | |
5262 int flags = ::fcntl(fd, F_GETFD); | |
5263 if (flags != -1) | |
5264 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); | |
5265 } | |
5266 #endif | |
5267 | |
5268 if (o_delete != 0) { | |
5269 ::unlink(path); | |
5270 } | |
5271 return fd; | |
5272 } | |
5273 | |
5143 // create binary file, rewriting existing file if required | 5274 // create binary file, rewriting existing file if required |
5144 int os::create_binary_file(const char* path, bool rewrite_existing) { | 5275 int os::create_binary_file(const char* path, bool rewrite_existing) { |
5145 int oflags = O_WRONLY | O_CREAT; | 5276 int oflags = O_WRONLY | O_CREAT; |
5146 if (!rewrite_existing) { | 5277 if (!rewrite_existing) { |
5147 oflags |= O_EXCL; | 5278 oflags |= O_EXCL; |
5155 } | 5286 } |
5156 | 5287 |
5157 // move file pointer to the specified offset | 5288 // move file pointer to the specified offset |
5158 jlong os::seek_to_file_offset(int fd, jlong offset) { | 5289 jlong os::seek_to_file_offset(int fd, jlong offset) { |
5159 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); | 5290 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); |
5291 } | |
5292 | |
5293 jlong os::lseek(int fd, jlong offset, int whence) { | |
5294 return (jlong) ::lseek64(fd, offset, whence); | |
5295 } | |
5296 | |
5297 char * os::native_path(char *path) { | |
5298 return path; | |
5299 } | |
5300 | |
5301 int os::ftruncate(int fd, jlong length) { | |
5302 return ::ftruncate64(fd, length); | |
5303 } | |
5304 | |
5305 int os::fsync(int fd) { | |
5306 RESTARTABLE_RETURN_INT(::fsync(fd)); | |
5307 } | |
5308 | |
5309 int os::available(int fd, jlong *bytes) { | |
5310 jlong cur, end; | |
5311 int mode; | |
5312 struct stat64 buf64; | |
5313 | |
5314 if (::fstat64(fd, &buf64) >= 0) { | |
5315 mode = buf64.st_mode; | |
5316 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { | |
5317 /* | |
5318 * XXX: is the following call interruptible? If so, this might | |
5319 * need to go through the INTERRUPT_IO() wrapper as for other | |
5320 * blocking, interruptible calls in this file. | |
5321 */ | |
5322 int n,ioctl_return; | |
5323 | |
5324 INTERRUPTIBLE(::ioctl(fd, FIONREAD, &n),ioctl_return,os::Solaris::clear_interrupted); | |
5325 if (ioctl_return>= 0) { | |
5326 *bytes = n; | |
5327 return 1; | |
5328 } | |
5329 } | |
5330 } | |
5331 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { | |
5332 return 0; | |
5333 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { | |
5334 return 0; | |
5335 } else if (::lseek64(fd, cur, SEEK_SET) == -1) { | |
5336 return 0; | |
5337 } | |
5338 *bytes = end - cur; | |
5339 return 1; | |
5160 } | 5340 } |
5161 | 5341 |
5162 // Map a block of memory. | 5342 // Map a block of memory. |
5163 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | 5343 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
5164 char *addr, size_t bytes, bool read_only, | 5344 char *addr, size_t bytes, bool read_only, |
5215 } | 5395 } |
5216 | 5396 |
5217 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 5397 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
5218 if (fd != -1) { | 5398 if (fd != -1) { |
5219 struct stat buf; | 5399 struct stat buf; |
5220 close(fd); | 5400 ::close(fd); |
5221 while (::stat(filename, &buf) == 0) { | 5401 while (::stat(filename, &buf) == 0) { |
5222 (void)::poll(NULL, 0, 100); | 5402 (void)::poll(NULL, 0, 100); |
5223 } | 5403 } |
5224 } else { | 5404 } else { |
5225 jio_fprintf(stderr, | 5405 jio_fprintf(stderr, |
5412 int fd; | 5592 int fd; |
5413 | 5593 |
5414 sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", | 5594 sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", |
5415 getpid(), | 5595 getpid(), |
5416 thread->osthread()->lwp_id()); | 5596 thread->osthread()->lwp_id()); |
5417 fd = open(proc_name, O_RDONLY); | 5597 fd = ::open(proc_name, O_RDONLY); |
5418 if ( fd == -1 ) return -1; | 5598 if ( fd == -1 ) return -1; |
5419 | 5599 |
5420 do { | 5600 do { |
5421 count = pread(fd, | 5601 count = ::pread(fd, |
5422 (void *)&prusage.pr_utime, | 5602 (void *)&prusage.pr_utime, |
5423 thr_time_size, | 5603 thr_time_size, |
5424 thr_time_off); | 5604 thr_time_off); |
5425 } while (count < 0 && errno == EINTR); | 5605 } while (count < 0 && errno == EINTR); |
5426 close(fd); | 5606 ::close(fd); |
5427 if ( count < 0 ) return -1; | 5607 if ( count < 0 ) return -1; |
5428 | 5608 |
5429 if (user_sys_cpu_time) { | 5609 if (user_sys_cpu_time) { |
5430 // user + system CPU time | 5610 // user + system CPU time |
5431 lwp_time = (((jlong)prusage.pr_stime.tv_sec + | 5611 lwp_time = (((jlong)prusage.pr_stime.tv_sec + |
6093 if (::stat(libmawtpath, &statbuf) == 0) return false; | 6273 if (::stat(libmawtpath, &statbuf) == 0) return false; |
6094 | 6274 |
6095 return true; | 6275 return true; |
6096 } | 6276 } |
6097 | 6277 |
6098 | 6278 size_t os::write(int fd, const void *buf, unsigned int nBytes) { |
6279 INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted); | |
6280 } | |
6281 | |
6282 int os::close(int fd) { | |
6283 RESTARTABLE_RETURN_INT(::close(fd)); | |
6284 } | |
6285 | |
6286 int os::socket_close(int fd) { | |
6287 RESTARTABLE_RETURN_INT(::close(fd)); | |
6288 } | |
6289 | |
6290 int os::recv(int fd, char *buf, int nBytes, int flags) { | |
6291 INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); | |
6292 } | |
6293 | |
6294 | |
6295 int os::send(int fd, char *buf, int nBytes, int flags) { | |
6296 INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); | |
6297 } | |
6298 | |
6299 int os::raw_send(int fd, char *buf, int nBytes, int flags) { | |
6300 RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); | |
6301 } | |
6302 | |
6303 // As both poll and select can be interrupted by signals, we have to be | |
6304 // prepared to restart the system call after updating the timeout, unless | |
6305 // a poll() is done with timeout == -1, in which case we repeat with this | |
6306 // "wait forever" value. | |
6307 | |
6308 int os::timeout(int fd, long timeout) { | |
6309 int res; | |
6310 struct timeval t; | |
6311 julong prevtime, newtime; | |
6312 static const char* aNull = 0; | |
6313 struct pollfd pfd; | |
6314 pfd.fd = fd; | |
6315 pfd.events = POLLIN; | |
6316 | |
6317 gettimeofday(&t, &aNull); | |
6318 prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; | |
6319 | |
6320 for(;;) { | |
6321 INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted); | |
6322 if(res == OS_ERR && errno == EINTR) { | |
6323 if(timeout != -1) { | |
6324 gettimeofday(&t, &aNull); | |
6325 newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000; | |
6326 timeout -= newtime - prevtime; | |
6327 if(timeout <= 0) | |
6328 return OS_OK; | |
6329 prevtime = newtime; | |
6330 } | |
6331 } else return res; | |
6332 } | |
6333 } | |
6334 | |
6335 int os::connect(int fd, struct sockaddr *him, int len) { | |
6336 int _result; | |
6337 INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result, | |
6338 os::Solaris::clear_interrupted); | |
6339 | |
6340 // Depending on when thread interruption is reset, _result could be | |
6341 // one of two values when errno == EINTR | |
6342 | |
6343 if (((_result == OS_INTRPT) || (_result == OS_ERR)) | |
6344 && (errno == EINTR)) { | |
6345 /* restarting a connect() changes its errno semantics */ | |
6346 INTERRUPTIBLE(::connect(fd, him, len), _result, | |
6347 os::Solaris::clear_interrupted); | |
6348 /* undo these changes */ | |
6349 if (_result == OS_ERR) { | |
6350 if (errno == EALREADY) { | |
6351 errno = EINPROGRESS; /* fall through */ | |
6352 } else if (errno == EISCONN) { | |
6353 errno = 0; | |
6354 return OS_OK; | |
6355 } | |
6356 } | |
6357 } | |
6358 return _result; | |
6359 } | |
6360 | |
6361 int os::accept(int fd, struct sockaddr *him, int *len) { | |
6362 if (fd < 0) | |
6363 return OS_ERR; | |
6364 INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him,\ | |
6365 (socklen_t*) len), os::Solaris::clear_interrupted); | |
6366 } | |
6367 | |
6368 int os::recvfrom(int fd, char *buf, int nBytes, int flags, | |
6369 sockaddr *from, int *fromlen) { | |
6370 //%%note jvm_r11 | |
6371 INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes,\ | |
6372 flags, from, fromlen), os::Solaris::clear_interrupted); | |
6373 } | |
6374 | |
6375 int os::sendto(int fd, char *buf, int len, int flags, | |
6376 struct sockaddr *to, int tolen) { | |
6377 //%%note jvm_r11 | |
6378 INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, flags,\ | |
6379 to, tolen), os::Solaris::clear_interrupted); | |
6380 } | |
6381 | |
6382 int os::socket_available(int fd, jint *pbytes) { | |
6383 if (fd < 0) | |
6384 return OS_OK; | |
6385 | |
6386 int ret; | |
6387 | |
6388 RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret); | |
6389 | |
6390 //%% note ioctl can return 0 when successful, JVM_SocketAvailable | |
6391 // is expected to return 0 on failure and 1 on success to the jdk. | |
6392 | |
6393 return (ret == OS_ERR) ? 0 : 1; | |
6394 } | |
6395 | |
6396 | |
6397 int os::bind(int fd, struct sockaddr *him, int len) { | |
6398 INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),\ | |
6399 os::Solaris::clear_interrupted); | |
6400 } | |
6401 |