# HG changeset patch # User coleenp # Date 1291246370 18000 # Node ID 3c205c4f1cda1b1f71c1752440c5e0771e607d33 # Parent 01c0559441c85473184ed74431d2daec40466028# Parent 828eafbd85cc26d575f2c398420fbd301df892de Merge diff -r 01c0559441c8 -r 3c205c4f1cda src/cpu/sparc/vm/depChecker_sparc.cpp --- a/src/cpu/sparc/vm/depChecker_sparc.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/cpu/sparc/vm/depChecker_sparc.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -25,6 +25,5 @@ #include "precompiled.hpp" #include "compiler/disassembler.hpp" #include "depChecker_sparc.hpp" -#include "runtime/hpi.hpp" // Nothing to do on Sparc diff -r 01c0559441c8 -r 3c205c4f1cda src/cpu/x86/vm/depChecker_x86.cpp --- a/src/cpu/x86/vm/depChecker_x86.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/cpu/x86/vm/depChecker_x86.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -25,6 +25,5 @@ #include "precompiled.hpp" #include "compiler/disassembler.hpp" #include "depChecker_x86.hpp" -#include "runtime/hpi.hpp" // Nothing to do on i486 diff -r 01c0559441c8 -r 3c205c4f1cda src/cpu/zero/vm/depChecker_zero.cpp --- a/src/cpu/zero/vm/depChecker_zero.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/cpu/zero/vm/depChecker_zero.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -26,6 +26,5 @@ #include "precompiled.hpp" #include "compiler/disassembler.hpp" #include "depChecker_zero.hpp" -#include "runtime/hpi.hpp" // This file is intentionally empty diff -r 01c0559441c8 -r 3c205c4f1cda src/os/linux/vm/hpi_linux.cpp --- a/src/os/linux/vm/hpi_linux.cpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,88 +0,0 @@ -/* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "precompiled.hpp" -#include "oops/oop.inline.hpp" -#include "runtime/hpi.hpp" -#include "runtime/os.hpp" - -# include -# include - -typedef jint (JNICALL *init_t)(GetInterfaceFunc *, void *); - -void hpi::initialize_get_interface(vm_calls_t *callbacks) { - char buf[JVM_MAXPATHLEN]; - void *hpi_handle; - GetInterfaceFunc& getintf = _get_interface; - jint (JNICALL * DLL_Initialize)(GetInterfaceFunc *, void *); - - if (HPILibPath && HPILibPath[0]) { - strncpy(buf, HPILibPath, JVM_MAXPATHLEN - 1); - buf[JVM_MAXPATHLEN - 1] = '\0'; - } else { - const char *thread_type = "native_threads"; - - os::jvm_path(buf, JVM_MAXPATHLEN); - -#ifdef PRODUCT - const char * hpi_lib = "/libhpi.so"; -#else - char * ptr = strrchr(buf, '/'); - assert(strstr(ptr, "/libjvm") == ptr, "invalid library name"); - const char * hpi_lib = strstr(ptr, "_g") ? "/libhpi_g.so" : "/libhpi.so"; -#endif - - *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ - char* p = strrchr(buf, '/'); - if (p != NULL) p[1] = '\0'; /* get rid of hotspot */ - strcat(buf, thread_type); - strcat(buf, hpi_lib); - } - - if (TraceHPI) tty->print_cr("Loading HPI %s ", buf); -#ifdef SPARC - // On 64-bit Ubuntu Sparc RTLD_NOW leads to unresolved deps in libpthread.so -# define OPEN_MODE RTLD_LAZY -#else - // We use RTLD_NOW because of bug 4032715 -# define OPEN_MODE RTLD_NOW -#endif - hpi_handle = dlopen(buf, OPEN_MODE); -#undef OPEN_MODE - - if (hpi_handle == NULL) { - if (TraceHPI) tty->print_cr("HPI dlopen failed: %s", dlerror()); - return; - } - DLL_Initialize = CAST_TO_FN_PTR(jint (JNICALL *)(GetInterfaceFunc *, void *), - dlsym(hpi_handle, "DLL_Initialize")); - if (TraceHPI && DLL_Initialize == NULL) tty->print_cr("HPI dlsym of DLL_Initialize failed: %s", dlerror()); - if (DLL_Initialize == NULL || - (*DLL_Initialize)(&getintf, callbacks) < 0) { - if (TraceHPI) tty->print_cr("HPI DLL_Initialize failed"); - return; - } - if (TraceHPI) tty->print_cr("HPI loaded successfully"); -} diff -r 01c0559441c8 -r 3c205c4f1cda src/os/linux/vm/hpi_linux.hpp --- a/src/os/linux/vm/hpi_linux.hpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,229 +0,0 @@ -/* - * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef OS_LINUX_VM_HPI_LINUX_HPP -#define OS_LINUX_VM_HPI_LINUX_HPP - -// -// Because the interruptible IO has been dropped for HotSpot/Linux, -// the following HPI interface is very different from HotSparc. -// - -#include -#include -#include -#include -#include - -// HPI_FileInterface - -inline int hpi::close(int fd) { - return ::close(fd); -} - -inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) { - size_t res; - RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); - return res; -} - -inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) { - size_t res; - RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); - return res; -} - - -// HPI_SocketInterface - -inline int hpi::socket_close(int fd) { - return ::close(fd); -} - -inline int hpi::socket(int domain, int type, int protocol) { - return ::socket(domain, type, protocol); -} - -inline int hpi::recv(int fd, char *buf, int nBytes, int flags) { - RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags)); -} - -inline int hpi::send(int fd, char *buf, int nBytes, int flags) { - RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags)); -} - -inline int hpi::raw_send(int fd, char *buf, int nBytes, int flags) { - return send(fd, buf, nBytes, flags); -} - -inline int hpi::timeout(int fd, long timeout) { - julong prevtime,newtime; - struct timeval t; - - gettimeofday(&t, NULL); - prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; - - for(;;) { - struct pollfd pfd; - - pfd.fd = fd; - pfd.events = POLLIN | POLLERR; - - int res = ::poll(&pfd, 1, timeout); - - if (res == OS_ERR && errno == EINTR) { - - // On Linux any value < 0 means "forever" - - if(timeout >= 0) { - gettimeofday(&t, NULL); - newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; - timeout -= newtime - prevtime; - if(timeout <= 0) - return OS_OK; - prevtime = newtime; - } - } else - return res; - } -} - -inline int hpi::listen(int fd, int count) { - return ::listen(fd, count); -} - -inline int hpi::connect(int fd, struct sockaddr *him, int len) { - RESTARTABLE_RETURN_INT(::connect(fd, him, len)); -} - -inline int hpi::accept(int fd, struct sockaddr *him, int *len) { - // This cast is from int to unsigned int on linux. Since we - // only pass the parameter "len" around the vm and don't try to - // fetch it's value, this cast is safe for now. The java.net group - // may need and want to change this interface someday if socklen_t goes - // to 64 bits on some platform that we support. - // Linux doc says this can't return EINTR, unlike accept() on Solaris - - return ::accept(fd, him, (socklen_t *)len); -} - -inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags, - sockaddr *from, int *fromlen) { - RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen)); -} - -inline int hpi::sendto(int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen) { - RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen)); -} - -inline int hpi::socket_available(int fd, jint *pbytes) { - // Linux doc says EINTR not returned, unlike Solaris - int ret = ::ioctl(fd, FIONREAD, pbytes); - - //%% note ioctl can return 0 when successful, JVM_SocketAvailable - // is expected to return 0 on failure and 1 on success to the jdk. - return (ret < 0) ? 0 : 1; -} - - -// following methods have been updated to avoid problems in -// hpi's sockets calls based on sys_api_td.c (JDK1.3) - -/* -HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown, - int, "%d", - (int fd, int howto), - ("fd = %d, howto = %d", fd, howto), - (fd, howto)); - */ -inline int hpi::socket_shutdown(int fd, int howto){ - return ::shutdown(fd, howto); -} - -/* -HPIDECL(bind, "bind", _socket, Bind, - int, "%d", - (int fd, struct sockaddr *him, int len), - ("fd = %d, him = %p, len = %d", - fd, him, len), - (fd, him, len)); -*/ -inline int hpi::bind(int fd, struct sockaddr *him, int len){ - return ::bind(fd, him, len); -} - -/* -HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName, - int, "%d", - (int fd, struct sockaddr *him, int *len), - ("fd = %d, him = %p, len = %p", - fd, him, len), - (fd, him, len)); - */ -inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){ - return ::getsockname(fd, him, (socklen_t *)len); -} - -/* -HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d", - (char *hostname, int namelen), - ("hostname = %p, namelen = %d", - hostname, namelen), - (hostname, namelen)); - */ -inline int hpi::get_host_name(char* name, int namelen){ - return ::gethostname(name, namelen); -} - -/* -HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d", - (int fd, int level, int optname, char *optval, int* optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - */ -inline int hpi::get_sock_opt(int fd, int level, int optname, - char *optval, int* optlen){ - return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen); -} - -/* -HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d", - (int fd, int level, int optname, const char *optval, int optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - */ -inline int hpi::set_sock_opt(int fd, int level, int optname, - const char *optval, int optlen){ - return ::setsockopt(fd, level, optname, optval, optlen); -} - - -// Reconciliation History -// hpi_solaris.hpp 1.9 99/08/30 16:31:23 -// End - -#endif // OS_LINUX_VM_HPI_LINUX_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os/linux/vm/os_linux.cpp --- a/src/os/linux/vm/os_linux.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/linux/vm/os_linux.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -44,7 +44,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/globals.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" @@ -1565,6 +1564,24 @@ // unused on linux for now. void os::set_error_file(const char *logfile) {} + +// This method is a copy of JDK's sysGetLastErrorString +// 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); + size_t n = ::strlen(s); + if (n >= len) { + n = len - 1; + } + ::strncpy(buf, s, n); + buf[n] = '\0'; + return n; +} + intx os::current_thread_id() { return (intx)pthread_self(); } int os::current_process_id() { @@ -1929,19 +1946,19 @@ } -bool _print_ascii_file(const char* filename, outputStream* st) { - int fd = open(filename, O_RDONLY); +static bool _print_ascii_file(const char* filename, outputStream* st) { + int fd = ::open(filename, O_RDONLY); if (fd == -1) { return false; } char buf[32]; int bytes; - while ((bytes = read(fd, buf, sizeof(buf))) > 0) { + while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { st->print_raw(buf, bytes); } - close(fd); + ::close(fd); return true; } @@ -2219,8 +2236,6 @@ // Use current module name "libjvm[_g].so" instead of // "libjvm"debug_only("_g")".so" since for fastdebug version // we should have "libjvm.so" but debug_only("_g") adds "_g"! - // It is used when we are choosing the HPI library's name - // "libhpi[_g].so" in hpi::initialize_get_interface(). len = strlen(buf); snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); } else { @@ -2404,18 +2419,18 @@ os::get_temp_directory(), os::current_process_id(), num); unlink(buf); - int fd = open(buf, O_CREAT | O_RDWR, S_IRWXU); + int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU); if (fd != -1) { - off_t rv = lseek(fd, size-2, SEEK_SET); + off_t rv = ::lseek(fd, size-2, SEEK_SET); if (rv != (off_t)-1) { - if (write(fd, "", 1) == 1) { + if (::write(fd, "", 1) == 1) { mmap(base, size, PROT_READ|PROT_WRITE|PROT_EXEC, MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0); } } - close(fd); + ::close(fd); unlink(buf); } } @@ -4047,13 +4062,6 @@ // Initialize lock used to serialize thread creation (see os::create_thread) Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false)); - // Initialize HPI. - jint hpi_result = hpi::initialize(); - if (hpi_result != JNI_OK) { - tty->print_cr("There was an error trying to initialize the HPI library."); - return hpi_result; - } - // at-exit methods are called in the reverse order of their registration. // atexit functions are called on return from main or as a result of a // call to exit(3C). There can be only 32 of these functions registered @@ -4251,7 +4259,7 @@ errno = ENAMETOOLONG; return -1; } - hpi::native_path(strcpy(pathbuf, path)); + os::native_path(strcpy(pathbuf, path)); return ::stat(pathbuf, sbuf); } @@ -4283,6 +4291,85 @@ return result; } +// This code originates from JDK's sysOpen and open64_w +// from src/solaris/hpi/src/system_md.c + +#ifndef O_DELETE +#define O_DELETE 0x10000 +#endif + +// Open a file. Unlink the file immediately after open returns +// if the specified oflag has the O_DELETE flag set. +// 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; + } + int fd; + int o_delete = (oflag & O_DELETE); + oflag = oflag & ~O_DELETE; + + fd = ::open64(path, oflag, mode); + if (fd == -1) return -1; + + //If the open succeeded, the file might still be a directory + { + struct stat64 buf64; + int ret = ::fstat64(fd, &buf64); + int st_mode = buf64.st_mode; + + if (ret != -1) { + if ((st_mode & S_IFMT) == S_IFDIR) { + errno = EISDIR; + ::close(fd); + return -1; + } + } else { + ::close(fd); + return -1; + } + } + + /* + * 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) + ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } +#endif + + if (o_delete != 0) { + ::unlink(path); + } + return fd; +} + + // create binary file, rewriting existing file if required int os::create_binary_file(const char* path, bool rewrite_existing) { int oflags = O_WRONLY | O_CREAT; @@ -4302,6 +4389,40 @@ return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); } +// This code originates from JDK's sysAvailable +// from src/solaris/hpi/src/native_threads/src/sys_api_td.c + +int os::available(int fd, jlong *bytes) { + jlong cur, end; + int mode; + struct stat64 buf64; + + 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. + */ + int n; + if (::ioctl(fd, FIONREAD, &n) >= 0) { + *bytes = n; + return 1; + } + } + } + if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { + return 0; + } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { + return 0; + } else if (::lseek64(fd, cur, SEEK_SET) == -1) { + return 0; + } + *bytes = end - cur; + return 1; +} + // Map a block of memory. char* os::map_memory(int fd, const char* file_name, size_t file_offset, char *addr, size_t bytes, bool read_only, @@ -4528,7 +4649,7 @@ int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd != -1) { struct stat buf; - close(fd); + ::close(fd); while (::stat(filename, &buf) == 0) { (void)::poll(NULL, 0, 100); } diff -r 01c0559441c8 -r 3c205c4f1cda src/os/linux/vm/os_linux.inline.hpp --- a/src/os/linux/vm/os_linux.inline.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/linux/vm/os_linux.inline.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -40,6 +40,14 @@ # include "orderAccess_linux_zero.inline.hpp" #endif +// System includes + +#include +#include +#include +#include +#include + inline void* os::thread_local_storage_at(int index) { return pthread_getspecific((pthread_key_t)index); } @@ -93,6 +101,12 @@ inline void os::bang_stack_shadow_pages() { } +inline void os::dll_unload(void *lib) { + ::dlclose(lib); +} + +inline const int os::default_file_open_flags() { return 0;} + inline DIR* os::opendir(const char* dirname) { assert(dirname != NULL, "just checking"); @@ -104,6 +118,22 @@ return NAME_MAX + sizeof(dirent) + 1; } +inline jlong os::lseek(int fd, jlong offset, int whence) { + return (jlong) ::lseek64(fd, offset, whence); +} + +inline int os::fsync(int fd) { + return ::fsync(fd); +} + +inline char* os::native_path(char *path) { + return path; +} + +inline int os::ftruncate(int fd, jlong length) { + return ::ftruncate64(fd, length); +} + inline struct dirent* os::readdir(DIR* dirp, dirent *dbuf) { dirent* p; @@ -121,9 +151,8 @@ return p; } -inline int os::closedir(DIR *dirp) -{ - assert(dirp != NULL, "just checking"); +inline int os::closedir(DIR *dirp) { + assert(dirp != NULL, "argument is NULL"); return ::closedir(dirp); } @@ -142,4 +171,139 @@ inline bool os::numa_has_static_binding() { return true; } inline bool os::numa_has_group_homing() { return false; } +inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { + size_t res; + RESTARTABLE( (size_t) ::read(fd, buf, (size_t) nBytes), res); + return res; +} + +inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { + size_t res; + RESTARTABLE((size_t) ::write(fd, buf, (size_t) nBytes), res); + return res; +} + +inline int os::close(int fd) { + return ::close(fd); +} + +inline int os::socket_close(int fd) { + return ::close(fd); +} + +inline int os::socket(int domain, int type, int protocol) { + return ::socket(domain, type, protocol); +} + +inline int os::recv(int fd, char *buf, int nBytes, int flags) { + RESTARTABLE_RETURN_INT(::recv(fd, buf, nBytes, (unsigned int) flags)); +} + +inline int os::send(int fd, char *buf, int nBytes, int flags) { + RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, (unsigned int) flags)); +} + +inline int os::raw_send(int fd, char *buf, int nBytes, int flags) { + return os::send(fd, buf, nBytes, flags); +} + +inline int os::timeout(int fd, long timeout) { + julong prevtime,newtime; + struct timeval t; + + gettimeofday(&t, NULL); + prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; + + for(;;) { + struct pollfd pfd; + + pfd.fd = fd; + pfd.events = POLLIN | POLLERR; + + int res = ::poll(&pfd, 1, timeout); + + if (res == OS_ERR && errno == EINTR) { + + // On Linux any value < 0 means "forever" + + if(timeout >= 0) { + gettimeofday(&t, NULL); + newtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; + timeout -= newtime - prevtime; + if(timeout <= 0) + return OS_OK; + prevtime = newtime; + } + } else + return res; + } +} + +inline int os::listen(int fd, int count) { + return ::listen(fd, count); +} + +inline int os::connect(int fd, struct sockaddr *him, int len) { + RESTARTABLE_RETURN_INT(::connect(fd, him, len)); +} + +inline int os::accept(int fd, struct sockaddr *him, int *len) { + // This cast is from int to unsigned int on linux. Since we + // only pass the parameter "len" around the vm and don't try to + // fetch it's value, this cast is safe for now. The java.net group + // may need and want to change this interface someday if socklen_t goes + // to 64 bits on some platform that we support. + // Linux doc says this can't return EINTR, unlike accept() on Solaris + + return ::accept(fd, him, (socklen_t *)len); +} + +inline int os::recvfrom(int fd, char *buf, int nBytes, int flags, + sockaddr *from, int *fromlen) { + RESTARTABLE_RETURN_INT(::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen)); +} + +inline int os::sendto(int fd, char *buf, int len, int flags, + struct sockaddr *to, int tolen) { + RESTARTABLE_RETURN_INT(::sendto(fd, buf, len, (unsigned int) flags, to, tolen)); +} + +inline int os::socket_available(int fd, jint *pbytes) { + // Linux doc says EINTR not returned, unlike Solaris + int ret = ::ioctl(fd, FIONREAD, pbytes); + + //%% note ioctl can return 0 when successful, JVM_SocketAvailable + // is expected to return 0 on failure and 1 on success to the jdk. + return (ret < 0) ? 0 : 1; +} + + +inline int os::socket_shutdown(int fd, int howto){ + return ::shutdown(fd, howto); +} + +inline int os::bind(int fd, struct sockaddr *him, int len){ + return ::bind(fd, him, len); +} + +inline int os::get_sock_name(int fd, struct sockaddr *him, int *len){ + return ::getsockname(fd, him, (socklen_t *)len); +} + +inline int os::get_host_name(char* name, int namelen){ + return ::gethostname(name, namelen); +} + +inline struct hostent* os::get_host_by_name(char* name) { + return ::gethostbyname(name); +} +inline int os::get_sock_opt(int fd, int level, int optname, + char *optval, int* optlen){ + return ::getsockopt(fd, level, optname, optval, (socklen_t *)optlen); +} + +inline int os::set_sock_opt(int fd, int level, int optname, + const char *optval, int optlen){ + return ::setsockopt(fd, level, optname, optval, optlen); +} #endif // OS_LINUX_VM_OS_LINUX_INLINE_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os/solaris/vm/hpi_solaris.cpp --- a/src/os/solaris/vm/hpi_solaris.cpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,80 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "precompiled.hpp" -#include "oops/oop.inline.hpp" -#include "runtime/hpi.hpp" -#include "runtime/os.hpp" - -# include -# include - -typedef jint (JNICALL *init_t)(GetInterfaceFunc *, void *); - -void hpi::initialize_get_interface(vm_calls_t *callbacks) -{ - char buf[JVM_MAXPATHLEN]; - void *hpi_handle; - GetInterfaceFunc& getintf = _get_interface; - jint (JNICALL * DLL_Initialize)(GetInterfaceFunc *, void *); - - if (HPILibPath && HPILibPath[0]) { - strncpy(buf, HPILibPath, JVM_MAXPATHLEN - 1); - buf[JVM_MAXPATHLEN - 1] = '\0'; - } else { - const char *thread_type = "native_threads"; - - os::jvm_path(buf, JVM_MAXPATHLEN); - -#ifdef PRODUCT - const char * hpi_lib = "/libhpi.so"; -#else - char * ptr = strrchr(buf, '/'); - assert(strstr(ptr, "/libjvm") == ptr, "invalid library name"); - const char * hpi_lib = strstr(ptr, "_g") ? "/libhpi_g.so" : "/libhpi.so"; -#endif - - *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ - char* p = strrchr(buf, '/'); - if (p != NULL) p[1] = '\0'; /* get rid of hotspot */ - strcat(buf, thread_type); - strcat(buf, hpi_lib); - } - /* we use RTLD_NOW because of bug 4032715 */ - if (TraceHPI) tty->print_cr("Loading HPI %s ", buf); - hpi_handle = dlopen(buf, RTLD_NOW); - if (hpi_handle == NULL) { - if (TraceHPI) tty->print_cr("HPI dlopen failed: %s", dlerror()); - return; - } - DLL_Initialize = CAST_TO_FN_PTR(jint (JNICALL *)(GetInterfaceFunc *, void *), - dlsym(hpi_handle, "DLL_Initialize")); - if (TraceHPI && DLL_Initialize == NULL) tty->print_cr("HPI dlsym of DLL_Initialize failed: %s", dlerror()); - if (DLL_Initialize == NULL || - (*DLL_Initialize)(&getintf, callbacks) < 0) { - if (TraceHPI) tty->print_cr("HPI DLL_Initialize failed"); - return; - } - if (TraceHPI) tty->print_cr("HPI loaded successfully"); -} diff -r 01c0559441c8 -r 3c205c4f1cda src/os/solaris/vm/hpi_solaris.hpp --- a/src/os/solaris/vm/hpi_solaris.hpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,254 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef OS_SOLARIS_VM_HPI_SOLARIS_HPP -#define OS_SOLARIS_VM_HPI_SOLARIS_HPP - -// -// Parts of the HPI interface for which the HotSparc does not use the -// HPI (because the interruptible IO mechanims used are different). -// - -#include -#include -#include -#include -#include -#include - -// HPI_FileInterface - -// Many system calls can be interrupted by signals and must be restarted. -// Restart support was added without disturbing the extent of thread -// interruption support. - -inline int hpi::close(int fd) { - RESTARTABLE_RETURN_INT(::close(fd)); -} - -inline size_t hpi::read(int fd, void *buf, unsigned int nBytes) { - INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); -} - -inline size_t hpi::write(int fd, const void *buf, unsigned int nBytes) { - INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted); -} - - -// HPI_SocketInterface - -inline int hpi::socket_close(int fd) { - RESTARTABLE_RETURN_INT(::close(fd)); -} - -inline int hpi::socket(int domain, int type, int protocol) { - return ::socket(domain, type, protocol); -} - -inline int hpi::recv(int fd, char *buf, int nBytes, int flags) { - INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); -} - -inline int hpi::send(int fd, char *buf, int nBytes, int flags) { - INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); -} - -inline int hpi::raw_send(int fd, char *buf, int nBytes, int flags) { - RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); -} - -// As both poll and select can be interrupted by signals, we have to be -// prepared to restart the system call after updating the timeout, unless -// a poll() is done with timeout == -1, in which case we repeat with this -// "wait forever" value. - -inline int hpi::timeout(int fd, long timeout) { - int res; - struct timeval t; - julong prevtime, newtime; - static const char* aNull = 0; - - struct pollfd pfd; - pfd.fd = fd; - pfd.events = POLLIN; - - gettimeofday(&t, &aNull); - prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; - - for(;;) { - INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted); - if(res == OS_ERR && errno == EINTR) { - if(timeout != -1) { - gettimeofday(&t, &aNull); - newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000; - timeout -= newtime - prevtime; - if(timeout <= 0) - return OS_OK; - prevtime = newtime; - } - } else - return res; - } -} - -inline int hpi::listen(int fd, int count) { - if (fd < 0) - return OS_ERR; - - return ::listen(fd, count); -} - -inline int -hpi::connect(int fd, struct sockaddr *him, int len) { - do { - int _result; - INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result, - os::Solaris::clear_interrupted); - - // Depending on when thread interruption is reset, _result could be - // one of two values when errno == EINTR - - if (((_result == OS_INTRPT) || (_result == OS_ERR)) && (errno == EINTR)) { - /* restarting a connect() changes its errno semantics */ - INTERRUPTIBLE(::connect(fd, him, len), _result, - os::Solaris::clear_interrupted); - /* undo these changes */ - if (_result == OS_ERR) { - if (errno == EALREADY) errno = EINPROGRESS; /* fall through */ - else if (errno == EISCONN) { errno = 0; return OS_OK; } - } - } - return _result; - } while(false); -} - -inline int hpi::accept(int fd, struct sockaddr *him, int *len) { - if (fd < 0) - return OS_ERR; - INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him, (socklen_t*) len), os::Solaris::clear_interrupted); -} - -inline int hpi::recvfrom(int fd, char *buf, int nBytes, int flags, - sockaddr *from, int *fromlen) { - //%%note jvm_r11 - INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes, (unsigned int) flags, from, (socklen_t *)fromlen), os::Solaris::clear_interrupted); -} - -inline int hpi::sendto(int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen) { - //%%note jvm_r11 - INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, (unsigned int) flags, to, tolen),os::Solaris::clear_interrupted); -} - -inline int hpi::socket_available(int fd, jint *pbytes) { - if (fd < 0) - return OS_OK; - - int ret; - - RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret); - - //%% note ioctl can return 0 when successful, JVM_SocketAvailable - // is expected to return 0 on failure and 1 on success to the jdk. - - return (ret == OS_ERR) ? 0 : 1; -} - - -/* -HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown, - int, "%d", - (int fd, int howto), - ("fd = %d, howto = %d", fd, howto), - (fd, howto)); - */ -inline int hpi::socket_shutdown(int fd, int howto){ - return ::shutdown(fd, howto); -} - -/* -HPIDECL(bind, "bind", _socket, Bind, - int, "%d", - (int fd, struct sockaddr *him, int len), - ("fd = %d, him = %p, len = %d", - fd, him, len), - (fd, him, len)); -*/ -inline int hpi::bind(int fd, struct sockaddr *him, int len){ - INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),os::Solaris::clear_interrupted); -} - -/* -HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName, - int, "%d", - (int fd, struct sockaddr *him, int *len), - ("fd = %d, him = %p, len = %p", - fd, him, len), - (fd, him, len)); - */ -inline int hpi::get_sock_name(int fd, struct sockaddr *him, int *len){ - return ::getsockname(fd, him, (socklen_t*) len); -} - -/* -HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d", - (char *hostname, int namelen), - ("hostname = %p, namelen = %d", - hostname, namelen), - (hostname, namelen)); - */ -inline int hpi::get_host_name(char* name, int namelen){ - return ::gethostname(name, namelen); -} - -/* -HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d", - (int fd, int level, int optname, char *optval, int* optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - */ -inline int hpi::get_sock_opt(int fd, int level, int optname, - char *optval, int* optlen){ - return ::getsockopt(fd, level, optname, optval, (socklen_t*) optlen); -} - -/* -HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d", - (int fd, int level, int optname, const char *optval, int optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - */ -inline int hpi::set_sock_opt(int fd, int level, int optname, - const char *optval, int optlen){ - return ::setsockopt(fd, level, optname, optval, optlen); -} - -//Reconciliation History -// 1.3 98/10/21 18:17:14 hpi_win32.hpp -// 1.6 99/06/28 11:01:36 hpi_win32.hpp -//End - -#endif // OS_SOLARIS_VM_HPI_SOLARIS_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os/solaris/vm/os_solaris.cpp --- a/src/os/solaris/vm/os_solaris.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/solaris/vm/os_solaris.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -42,7 +42,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/globals.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" @@ -115,6 +114,7 @@ # include # include # include +# include # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later # include // see comment in @@ -219,6 +219,9 @@ // System parameters used internally static clock_t clock_tics_per_sec = 100; +// Track if we have called enable_extended_FILE_stdio (on Solaris 10u4+) +static bool enabled_extended_FILE_stdio = false; + // For diagnostics to print a message once. see run_periodic_checks static bool check_addr0_done = false; static sigset_t check_signal_done; @@ -386,7 +389,7 @@ // The saved state is used to restore the thread to // its former state whether or not an interrupt is received. // Used by classloader os::read -// hpi calls skip this layer and stay in _thread_in_native +// os::restartable_read calls skip this layer and stay in _thread_in_native void os::Solaris::setup_interruptible(JavaThread* thread) { @@ -1750,13 +1753,13 @@ bool os::supports_vtime() { return true; } bool os::enable_vtime() { - int fd = open("/proc/self/ctl", O_WRONLY); + int fd = ::open("/proc/self/ctl", O_WRONLY); if (fd == -1) return false; long cmd[] = { PCSET, PR_MSACCT }; - int res = write(fd, cmd, sizeof(long) * 2); - close(fd); + int res = ::write(fd, cmd, sizeof(long) * 2); + ::close(fd); if (res != sizeof(long) * 2) return false; @@ -1764,13 +1767,13 @@ } bool os::vtime_enabled() { - int fd = open("/proc/self/status", O_RDONLY); + int fd = ::open("/proc/self/status", O_RDONLY); if (fd == -1) return false; pstatus_t status; - int res = read(fd, (void*) &status, sizeof(pstatus_t)); - close(fd); + int res = os::read(fd, (void*) &status, sizeof(pstatus_t)); + ::close(fd); if (res != sizeof(pstatus_t)) return false; @@ -1886,7 +1889,6 @@ void os::dll_build_name(char* buffer, size_t buflen, const char* pname, const char* fname) { - // Copied from libhpi const size_t pnamelen = pname ? strlen(pname) : 0; // Quietly truncate on buffer overflow. Should be an error. @@ -2182,20 +2184,29 @@ return dlsym(handle, name); } - -bool _print_ascii_file(const char* filename, outputStream* st) { - int fd = open(filename, O_RDONLY); +int os::stat(const char *path, struct stat *sbuf) { + char pathbuf[MAX_PATH]; + if (strlen(path) > MAX_PATH - 1) { + errno = ENAMETOOLONG; + return -1; + } + os::native_path(strcpy(pathbuf, path)); + return ::stat(pathbuf, sbuf); +} + +static bool _print_ascii_file(const char* filename, outputStream* st) { + int fd = ::open(filename, O_RDONLY); if (fd == -1) { return false; } char buf[32]; int bytes; - while ((bytes = read(fd, buf, sizeof(buf))) > 0) { + while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { st->print_raw(buf, bytes); } - close(fd); + ::close(fd); return true; } @@ -2258,10 +2269,10 @@ static bool check_addr0(outputStream* st) { jboolean status = false; - int fd = open("/proc/self/map",O_RDONLY); + int fd = ::open("/proc/self/map",O_RDONLY); if (fd >= 0) { prmap_t p; - while(read(fd, &p, sizeof(p)) > 0) { + while(::read(fd, &p, sizeof(p)) > 0) { if (p.pr_vaddr == 0x0) { st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); @@ -2272,7 +2283,7 @@ st->cr(); status = true; } - close(fd); + ::close(fd); } } return status; @@ -2520,8 +2531,6 @@ // Use current module name "libjvm[_g].so" instead of // "libjvm"debug_only("_g")".so" since for fastdebug version // we should have "libjvm.so" but debug_only("_g") adds "_g"! - // It is used when we are choosing the HPI library's name - // "libhpi[_g].so" in hpi::initialize_get_interface(). len = strlen(buf); snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); } else { @@ -2545,6 +2554,23 @@ // no suffix required } +// This method is a copy of JDK's sysGetLastErrorString +// 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); + size_t n = ::strlen(s); + if (n >= len) { + n = len - 1; + } + ::strncpy(buf, s, n); + buf[n] = '\0'; + return n; +} + // sun.misc.Signal @@ -3454,6 +3480,10 @@ INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); } +size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { + INTERRUPTIBLE_RETURN_INT(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); +} + int os::sleep(Thread* thread, jlong millis, bool interruptible) { assert(thread == Thread::current(), "thread consistency check"); @@ -4623,16 +4653,16 @@ #define ADR(x) ((uintptr_t)(x)) #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) - lwpFile = open("/proc/self/lstatus", O_RDONLY, 0); + lwpFile = ::open("/proc/self/lstatus", O_RDONLY, 0); if (lwpFile < 0) { if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); return false; } lwpSize = 16*1024; for (;;) { - lseek (lwpFile, 0, SEEK_SET); + ::lseek64 (lwpFile, 0, SEEK_SET); lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); - if (read(lwpFile, lwpArray, lwpSize) < 0) { + if (::read(lwpFile, lwpArray, lwpSize) < 0) { if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); break; } @@ -4653,7 +4683,7 @@ } FREE_C_HEAP_ARRAY(char, lwpArray); - close (lwpFile); + ::close (lwpFile); if (ThreadPriorityVerbose) { if (isT2) tty->print_cr("We are running with a T2 libthread\n"); else tty->print_cr("We are not running with a T2 libthread\n"); @@ -4849,7 +4879,7 @@ // if we need them. Solaris::misc_sym_init(); - int fd = open("/dev/zero", O_RDWR); + int fd = ::open("/dev/zero", O_RDWR); if (fd < 0) { fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); } else { @@ -5019,13 +5049,6 @@ } } - // Initialize HPI. - jint hpi_result = hpi::initialize(); - if (hpi_result != JNI_OK) { - tty->print_cr("There was an error trying to initialize the HPI library."); - return hpi_result; - } - // Calculate theoretical max. size of Threads to guard gainst // artifical out-of-memory situations, where all available address- // space has been reserved by thread stacks. Default stack size is 1Mb. @@ -5085,17 +5108,6 @@ // OS interface. -int os::stat(const char *path, struct stat *sbuf) { - char pathbuf[MAX_PATH]; - if (strlen(path) > MAX_PATH - 1) { - errno = ENAMETOOLONG; - return -1; - } - hpi::native_path(strcpy(pathbuf, path)); - return ::stat(pathbuf, sbuf); -} - - bool os::check_heap(bool force) { return true; } typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); @@ -5140,6 +5152,125 @@ return result; } +// This code originates from JDK's sysOpen and open64_w +// from src/solaris/hpi/src/system_md.c + +#ifndef O_DELETE +#define O_DELETE 0x10000 +#endif + +// Open a file. Unlink the file immediately after open returns +// if the specified oflag has the O_DELETE flag set. +// 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; + } + int fd; + int o_delete = (oflag & O_DELETE); + oflag = oflag & ~O_DELETE; + + fd = ::open(path, oflag, mode); + if (fd == -1) return -1; + + //If the open succeeded, the file might still be a directory + { + struct stat64 buf64; + int ret = ::fstat64(fd, &buf64); + int st_mode = buf64.st_mode; + + if (ret != -1) { + if ((st_mode & S_IFMT) == S_IFDIR) { + errno = EISDIR; + ::close(fd); + return -1; + } + } else { + ::close(fd); + 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 + */ +#ifndef _LP64 + if ((!enabled_extended_FILE_stdio) && fd < 256) { + int newfd = ::fcntl(fd, F_DUPFD, 256); + if (newfd != -1) { + ::close(fd); + fd = newfd; + } + } +#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 + */ +#ifdef FD_CLOEXEC + { + int flags = ::fcntl(fd, F_GETFD); + if (flags != -1) + ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); + } +#endif + + if (o_delete != 0) { + ::unlink(path); + } + return fd; +} + // create binary file, rewriting existing file if required int os::create_binary_file(const char* path, bool rewrite_existing) { int oflags = O_WRONLY | O_CREAT; @@ -5159,6 +5290,55 @@ return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); } +jlong os::lseek(int fd, jlong offset, int whence) { + return (jlong) ::lseek64(fd, offset, whence); +} + +char * os::native_path(char *path) { + return path; +} + +int os::ftruncate(int fd, jlong length) { + return ::ftruncate64(fd, length); +} + +int os::fsync(int fd) { + RESTARTABLE_RETURN_INT(::fsync(fd)); +} + +int os::available(int fd, jlong *bytes) { + jlong cur, end; + int mode; + struct stat64 buf64; + + 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. + */ + int n,ioctl_return; + + INTERRUPTIBLE(::ioctl(fd, FIONREAD, &n),ioctl_return,os::Solaris::clear_interrupted); + if (ioctl_return>= 0) { + *bytes = n; + return 1; + } + } + } + if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { + return 0; + } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { + return 0; + } else if (::lseek64(fd, cur, SEEK_SET) == -1) { + return 0; + } + *bytes = end - cur; + return 1; +} + // Map a block of memory. char* os::map_memory(int fd, const char* file_name, size_t file_offset, char *addr, size_t bytes, bool read_only, @@ -5217,7 +5397,7 @@ int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd != -1) { struct stat buf; - close(fd); + ::close(fd); while (::stat(filename, &buf) == 0) { (void)::poll(NULL, 0, 100); } @@ -5414,16 +5594,16 @@ sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", getpid(), thread->osthread()->lwp_id()); - fd = open(proc_name, O_RDONLY); + fd = ::open(proc_name, O_RDONLY); if ( fd == -1 ) return -1; do { - count = pread(fd, + count = ::pread(fd, (void *)&prusage.pr_utime, thr_time_size, thr_time_off); } while (count < 0 && errno == EINTR); - close(fd); + ::close(fd); if ( count < 0 ) return -1; if (user_sys_cpu_time) { @@ -6095,4 +6275,127 @@ return true; } - +size_t os::write(int fd, const void *buf, unsigned int nBytes) { + INTERRUPTIBLE_RETURN_INT(::write(fd, buf, nBytes), os::Solaris::clear_interrupted); +} + +int os::close(int fd) { + RESTARTABLE_RETURN_INT(::close(fd)); +} + +int os::socket_close(int fd) { + RESTARTABLE_RETURN_INT(::close(fd)); +} + +int os::recv(int fd, char *buf, int nBytes, int flags) { + INTERRUPTIBLE_RETURN_INT(::recv(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); +} + + +int os::send(int fd, char *buf, int nBytes, int flags) { + INTERRUPTIBLE_RETURN_INT(::send(fd, buf, nBytes, flags), os::Solaris::clear_interrupted); +} + +int os::raw_send(int fd, char *buf, int nBytes, int flags) { + RESTARTABLE_RETURN_INT(::send(fd, buf, nBytes, flags)); +} + +// As both poll and select can be interrupted by signals, we have to be +// prepared to restart the system call after updating the timeout, unless +// a poll() is done with timeout == -1, in which case we repeat with this +// "wait forever" value. + +int os::timeout(int fd, long timeout) { + int res; + struct timeval t; + julong prevtime, newtime; + static const char* aNull = 0; + struct pollfd pfd; + pfd.fd = fd; + pfd.events = POLLIN; + + gettimeofday(&t, &aNull); + prevtime = ((julong)t.tv_sec * 1000) + t.tv_usec / 1000; + + for(;;) { + INTERRUPTIBLE_NORESTART(::poll(&pfd, 1, timeout), res, os::Solaris::clear_interrupted); + if(res == OS_ERR && errno == EINTR) { + if(timeout != -1) { + gettimeofday(&t, &aNull); + newtime = ((julong)t.tv_sec * 1000) + t.tv_usec /1000; + timeout -= newtime - prevtime; + if(timeout <= 0) + return OS_OK; + prevtime = newtime; + } + } else return res; + } +} + +int os::connect(int fd, struct sockaddr *him, int len) { + int _result; + INTERRUPTIBLE_NORESTART(::connect(fd, him, len), _result, + os::Solaris::clear_interrupted); + + // Depending on when thread interruption is reset, _result could be + // one of two values when errno == EINTR + + if (((_result == OS_INTRPT) || (_result == OS_ERR)) + && (errno == EINTR)) { + /* restarting a connect() changes its errno semantics */ + INTERRUPTIBLE(::connect(fd, him, len), _result, + os::Solaris::clear_interrupted); + /* undo these changes */ + if (_result == OS_ERR) { + if (errno == EALREADY) { + errno = EINPROGRESS; /* fall through */ + } else if (errno == EISCONN) { + errno = 0; + return OS_OK; + } + } + } + return _result; + } + +int os::accept(int fd, struct sockaddr *him, int *len) { + if (fd < 0) + return OS_ERR; + INTERRUPTIBLE_RETURN_INT((int)::accept(fd, him,\ + (socklen_t*) len), os::Solaris::clear_interrupted); + } + +int os::recvfrom(int fd, char *buf, int nBytes, int flags, + sockaddr *from, int *fromlen) { + //%%note jvm_r11 + INTERRUPTIBLE_RETURN_INT((int)::recvfrom(fd, buf, nBytes,\ + flags, from, fromlen), os::Solaris::clear_interrupted); +} + +int os::sendto(int fd, char *buf, int len, int flags, + struct sockaddr *to, int tolen) { + //%%note jvm_r11 + INTERRUPTIBLE_RETURN_INT((int)::sendto(fd, buf, len, flags,\ + to, tolen), os::Solaris::clear_interrupted); +} + +int os::socket_available(int fd, jint *pbytes) { + if (fd < 0) + return OS_OK; + + int ret; + + RESTARTABLE(::ioctl(fd, FIONREAD, pbytes), ret); + + //%% note ioctl can return 0 when successful, JVM_SocketAvailable + // is expected to return 0 on failure and 1 on success to the jdk. + + return (ret == OS_ERR) ? 0 : 1; +} + + +int os::bind(int fd, struct sockaddr *him, int len) { + INTERRUPTIBLE_RETURN_INT_NORESTART(::bind(fd, him, len),\ + os::Solaris::clear_interrupted); +} + diff -r 01c0559441c8 -r 3c205c4f1cda src/os/solaris/vm/os_solaris.inline.hpp --- a/src/os/solaris/vm/os_solaris.inline.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/solaris/vm/os_solaris.inline.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -36,6 +36,16 @@ # include "orderAccess_solaris_sparc.inline.hpp" #endif +// System includes +#include +#include +#include +#include +#include +#include +#include +#include + inline const char* os::file_separator() { return "/"; } inline const char* os::line_separator() { return "\n"; } inline const char* os::path_separator() { return ":"; } @@ -69,21 +79,19 @@ // Bang the shadow pages if they need to be touched to be mapped. inline void os::bang_stack_shadow_pages() { } +inline void os::dll_unload(void *lib) { ::dlclose(lib); } -inline DIR* os::opendir(const char* dirname) -{ +inline DIR* os::opendir(const char* dirname) { assert(dirname != NULL, "just checking"); return ::opendir(dirname); } -inline int os::readdir_buf_size(const char *path) -{ +inline int os::readdir_buf_size(const char *path) { int size = pathconf(path, _PC_NAME_MAX); return (size < 0 ? MAXPATHLEN : size) + sizeof(dirent) + 1; } -inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) -{ +inline struct dirent* os::readdir(DIR* dirp, dirent* dbuf) { assert(dirp != NULL, "just checking"); #if defined(_LP64) || defined(_GNU_SOURCE) dirent* p; @@ -99,9 +107,8 @@ #endif // defined(_LP64) || defined(_GNU_SOURCE) } -inline int os::closedir(DIR *dirp) -{ - assert(dirp != NULL, "just checking"); +inline int os::closedir(DIR *dirp) { + assert(dirp != NULL, "argument is NULL"); return ::closedir(dirp); } @@ -222,4 +229,38 @@ inline bool os::numa_has_static_binding() { return false; } inline bool os::numa_has_group_homing() { return true; } +inline int os::socket(int domain, int type, int protocol) { + return ::socket(domain, type, protocol); +} + +inline int os::listen(int fd, int count) { + if (fd < 0) return OS_ERR; + + return ::listen(fd, count); +} + +inline int os::socket_shutdown(int fd, int howto){ + return ::shutdown(fd, howto); +} + +inline int os::get_sock_name(int fd, struct sockaddr *him, int *len){ + return ::getsockname(fd, him, (socklen_t*) len); +} + +inline int os::get_host_name(char* name, int namelen){ + return ::gethostname(name, namelen); +} + +inline struct hostent* os::get_host_by_name(char* name) { + return ::gethostbyname(name); +} +inline int os::get_sock_opt(int fd, int level, int optname, + char *optval, int* optlen){ + return ::getsockopt(fd, level, optname, optval, (socklen_t*) optlen); +} + +inline int os::set_sock_opt(int fd, int level, int optname, + const char *optval, int optlen){ + return ::setsockopt(fd, level, optname, optval, optlen); +} #endif // OS_SOLARIS_VM_OS_SOLARIS_INLINE_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os/windows/vm/hpi_windows.cpp --- a/src/os/windows/vm/hpi_windows.cpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,82 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "precompiled.hpp" -#include "oops/oop.inline.hpp" -#include "runtime/hpi.hpp" -#include "runtime/os.hpp" - -typedef jint (JNICALL *init_t)(GetInterfaceFunc *, void *); - -void hpi::initialize_get_interface(vm_calls_t *callbacks) -{ - // Build name of HPI. - char lib_name[JVM_MAXPATHLEN]; - - if (HPILibPath && HPILibPath[0]) { - strncpy(lib_name, HPILibPath, JVM_MAXPATHLEN - 1); - lib_name[JVM_MAXPATHLEN - 1] = '\0'; - } else { - os::jvm_path(lib_name, sizeof lib_name); - -#ifdef PRODUCT - const char *hpi_lib = "\\hpi.dll"; -#else - char *ptr = strrchr(lib_name, '\\'); - // On Win98 GetModuleFileName() returns the path in the upper case. - assert(_strnicmp(ptr, "\\jvm",4) == 0, "invalid library name"); - const char *hpi_lib = (_strnicmp(ptr, "\\jvm_g",6) == 0) ? "\\hpi_g.dll" : "\\hpi.dll"; -#endif - - *(::strrchr(lib_name, '\\')) = '\0'; /* get rid of "\\jvm.dll" */ - char *p = ::strrchr(lib_name, '\\'); - if (p != NULL) *p = '\0'; /* get rid of "\\hotspot" */ - strcat(lib_name, hpi_lib); - } - - // Load it. - if (TraceHPI) tty->print_cr("Loading HPI %s ", lib_name); - HINSTANCE lib_handle = LoadLibrary(lib_name); - if (lib_handle == NULL) { - if (TraceHPI) tty->print_cr("LoadLibrary failed, code = %d", GetLastError()); - return; - } - - // Find hpi initializer. - init_t initer = (init_t)GetProcAddress(lib_handle, "DLL_Initialize"); - if (initer == NULL) { - if (TraceHPI) tty->print_cr("GetProcAddress failed, errcode = %d", GetLastError()); - return; - } - - // Call initializer. - jint init_result = (*initer)(&_get_interface, callbacks); - if (init_result < 0) { - if (TraceHPI) tty->print_cr("DLL_Initialize failed, returned %ld", init_result); - return; - } - - if (TraceHPI) tty->print_cr("success"); - return; -} diff -r 01c0559441c8 -r 3c205c4f1cda src/os/windows/vm/hpi_windows.hpp --- a/src/os/windows/vm/hpi_windows.hpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,175 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef OS_WINDOWS_VM_HPI_WINDOWS_HPP -#define OS_WINDOWS_VM_HPI_WINDOWS_HPP - -// Win32 delegates these to the HPI. Solaris provides its own -// implementation without using the HPI (for Interrupitble I/O). - -// HPI_FileInterface - -HPIDECL(close, "close", _file, Close, int, "%d", - (int fd), - ("fd = %d", fd), - (fd)); - -HPIDECL(read, "read", _file, Read, size_t, "%ld", - (int fd, void *buf, unsigned int nBytes), - ("fd = %d, buf = %p, nBytes = %u", fd, buf, nBytes), - (fd, buf, nBytes)); - -HPIDECL(write, "write", _file, Write, size_t, "%ld", - (int fd, const void *buf, unsigned int nBytes), - ("fd = %d, buf = %p, nBytes = %u", fd, buf, nBytes), - (fd, buf, nBytes)); - - -// HPI_SocketInterface - -HPIDECL(socket_close, "socket_close", _socket, Close, int, "%d", - (int fd), - ("fd = %d", fd), - (fd)); - -HPIDECL(socket_available, "socket_available", _socket, Available, - int, "%d", - (int fd, jint *pbytes), - ("fd = %d, pbytes = %p", fd, pbytes), - (fd, pbytes)); - -HPIDECL(socket, "socket", _socket, Socket, int, "%d", - (int domain, int type, int protocol), - ("domain = %d, type = %d, protocol = %d", domain, type, protocol), - (domain, type, protocol)); - -HPIDECL(listen, "listen", _socket, Listen, int, "%d", - (int fd, int count), - ("fd = %d, count = %d", fd, count), - (fd, count)); - -HPIDECL(connect, "connect", _socket, Connect, int, "%d", - (int fd, struct sockaddr *him, int len), - ("fd = %d, him = %p, len = %d", fd, him, len), - (fd, him, len)); - -HPIDECL(accept, "accept", _socket, Accept, int, "%d", - (int fd, struct sockaddr *him, int *len), - ("fd = %d, him = %p, len = %p", fd, him, len), - (fd, him, len)); - -HPIDECL(sendto, "sendto", _socket, SendTo, int, "%d", - (int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen), - ("fd = %d, buf = %p, len = %d, flags = %d, to = %p, tolen = %d", - fd, buf, len, flags, to, tolen), - (fd, buf, len, flags, to, tolen)); - -HPIDECL(recvfrom, "recvfrom", _socket, RecvFrom, int, "%d", - (int fd, char *buf, int nbytes, int flags, - struct sockaddr *from, int *fromlen), - ("fd = %d, buf = %p, len = %d, flags = %d, frm = %p, frmlen = %d", - fd, buf, nbytes, flags, from, fromlen), - (fd, buf, nbytes, flags, from, fromlen)); - -HPIDECL(recv, "recv", _socket, Recv, int, "%d", - (int fd, char *buf, int nBytes, int flags), - ("fd = %d, buf = %p, nBytes = %d, flags = %d", - fd, buf, nBytes, flags), - (fd, buf, nBytes, flags)); - -HPIDECL(send, "send", _socket, Send, int, "%d", - (int fd, char *buf, int nBytes, int flags), - ("fd = %d, buf = %p, nBytes = %d, flags = %d", - fd, buf, nBytes, flags), - (fd, buf, nBytes, flags)); - -inline int hpi::raw_send(int fd, char *buf, int nBytes, int flags) { - return send(fd, buf, nBytes, flags); -} - -HPIDECL(timeout, "timeout", _socket, Timeout, int, "%d", - (int fd, long timeout), - ("fd = %d, timeout = %ld", fd, timeout), - (fd, timeout)); - -HPIDECL(get_host_by_name, "get_host_by_name", _socket, GetHostByName, - struct hostent *, "(struct hostent *)%p", - (char *name), - ("%s", name), - (name)); - -HPIDECL(socket_shutdown, "socket_shutdown", _socket, SocketShutdown, - int, "%d", - (int fd, int howto), - ("fd = %d, howto = %d", fd, howto), - (fd, howto)); - -HPIDECL(bind, "bind", _socket, Bind, - int, "%d", - (int fd, struct sockaddr *him, int len), - ("fd = %d, him = %p, len = %d", - fd, him, len), - (fd, him, len)); - -HPIDECL(get_sock_name, "get_sock_name", _socket, GetSocketName, - int, "%d", - (int fd, struct sockaddr *him, int *len), - ("fd = %d, him = %p, len = %p", - fd, him, len), - (fd, him, len)); - -HPIDECL(get_host_name, "get_host_name", _socket, GetHostName, int, "%d", - (char *hostname, int namelen), - ("hostname = %p, namelen = %d", - hostname, namelen), - (hostname, namelen)); - -HPIDECL(get_host_by_addr, "get_host_by_addr", _socket, GetHostByAddr, - struct hostent *, "(struct hostent *)%p", - (const char* name, int len, int type), - ("name = %p, len = %d, type = %d", - name, len, type), - (name, len, type)); - -HPIDECL(get_sock_opt, "get_sock_opt", _socket, SocketGetOption, int, "%d", - (int fd, int level, int optname, char *optval, int* optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %p", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - -HPIDECL(set_sock_opt, "set_sock_opt", _socket, SocketSetOption, int, "%d", - (int fd, int level, int optname, const char *optval, int optlen), - ("fd = %d, level = %d, optname = %d, optval = %p, optlen = %d", - fd, level, optname, optval, optlen), - (fd, level, optname, optval, optlen)); - -HPIDECL(get_proto_by_name, "get_proto_by_name", _socket, GetProtoByName, - struct protoent *, "(struct protoent *)%p", - (char* name), - ("name = %p", - name), - (name)); - -#endif // OS_WINDOWS_VM_HPI_WINDOWS_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os/windows/vm/os_windows.cpp --- a/src/os/windows/vm/os_windows.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/windows/vm/os_windows.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -47,7 +47,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/globals.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" @@ -1044,8 +1043,6 @@ return 0; } -const char* os::dll_file_extension() { return ".dll"; } - const char* os::get_temp_directory() { const char *prop = Arguments::get_property("java.io.tmpdir"); if (prop != 0) return prop; @@ -1067,7 +1064,6 @@ void os::dll_build_name(char *buffer, size_t buflen, const char* pname, const char* fname) { - // Copied from libhpi const size_t pnamelen = pname ? strlen(pname) : 0; const char c = (pnamelen > 0) ? pname[pnamelen-1] : 0; @@ -1378,10 +1374,6 @@ return false; } -void* os::dll_lookup(void* handle, const char* name) { - return GetProcAddress((HMODULE)handle, name); -} - // save the start and end address of jvm.dll into param[0] and param[1] static int _locate_jvm_dll(int pid, char* mod_fname, address base_addr, unsigned size, void * param) { @@ -1734,6 +1726,44 @@ #endif } +// This method is a copy of JDK's sysGetLastErrorString +// from src/windows/hpi/src/system_md.c + +size_t os::lasterror(char *buf, size_t len) { + long errval; + + if ((errval = GetLastError()) != 0) { + /* DOS error */ + int n = (int)FormatMessage( + FORMAT_MESSAGE_FROM_SYSTEM|FORMAT_MESSAGE_IGNORE_INSERTS, + NULL, + errval, + 0, + buf, + (DWORD)len, + NULL); + if (n > 3) { + /* Drop final '.', CR, LF */ + if (buf[n - 1] == '\n') n--; + if (buf[n - 1] == '\r') n--; + if (buf[n - 1] == '.') n--; + buf[n] = '\0'; + } + return n; + } + + if (errno != 0) { + /* C runtime error that has no corresponding DOS error code */ + const char *s = strerror(errno); + size_t n = strlen(s); + if (n >= len) n = len - 1; + strncpy(buf, s, n); + buf[n] = '\0'; + return n; + } + return 0; +} + // sun.misc.Signal // NOTE that this is a workaround for an apparent kernel bug where if // a signal handler for SIGBREAK is installed then that signal handler @@ -2941,10 +2971,6 @@ assert(ret != SYS_THREAD_ERROR, "StartThread failed"); // should propagate back } -size_t os::read(int fd, void *buf, unsigned int nBytes) { - return ::read(fd, buf, nBytes); -} - class HighResolutionInterval { // The default timer resolution seems to be 10 milliseconds. // (Where is this written down?) @@ -3423,10 +3449,6 @@ #endif } - // Initialize HPI. - jint hpi_result = hpi::initialize(); - if (hpi_result != JNI_OK) { return hpi_result; } - // If stack_commit_size is 0, windows will reserve the default size, // but only commit a small portion of it. size_t stack_commit_size = round_to(ThreadStackSize*K, os::vm_page_size()); @@ -3531,7 +3553,7 @@ errno = ENAMETOOLONG; return -1; } - hpi::native_path(strcpy(pathbuf, path)); + os::native_path(strcpy(pathbuf, path)); int ret = ::stat(pathbuf, sbuf); if (sbuf != NULL && UseUTCFileTimestamp) { // Fix for 6539723. st_mtime returned from stat() is dependent on @@ -3675,6 +3697,20 @@ return DontYieldALot; } +// This method is a slightly reworked copy of JDK's sysOpen +// from src/windows/hpi/src/sys_api_md.c + +int os::open(const char *path, int oflag, int mode) { + char pathbuf[MAX_PATH]; + + if (strlen(path) > MAX_PATH - 1) { + errno = ENAMETOOLONG; + return -1; + } + os::native_path(strcpy(pathbuf, path)); + return ::open(pathbuf, oflag | O_BINARY | O_NOINHERIT, mode); +} + // Is a (classpath) directory empty? bool os::dir_is_empty(const char* path) { WIN32_FIND_DATA fd; @@ -3706,6 +3742,297 @@ } +jlong os::lseek(int fd, jlong offset, int whence) { + return (jlong) ::_lseeki64(fd, offset, whence); +} + +// 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. */ +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 */ +#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". */ + *dst++ = *src++; + colon = dst; + *dst++ = ':'; + src++; + } 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. */ + src = dst = path + 1; + 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. + */ + while (*src != '\0') { + if (isfilesep(*src)) { + *dst++ = '\\'; src++; + while (isfilesep(*src)) src++; + if (*src == '\0') { + /* Check for trailing separator */ + end = dst; + 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. */ + break; + } + 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 */ + *dst++ = *src++; + if (*src) *dst++ = *src++; + end = dst; + } else { /* Copy a single-byte character */ + char c = *src++; + *dst++ = c; + /* Space is not a legal ending character */ + if (c != ' ') end = dst; + } + } + } + + *end = '\0'; + + /* For "z:", add "." to work around a bug in the C runtime library */ + if (colon == dst - 1) { + path[2] = '.'; + path[3] = '\0'; + } + + #ifdef DEBUG + jio_fprintf(stderr, "sysNativePath: %s\n", path); + #endif DEBUG + return path; +} + +// This code is a copy of JDK's sysSetLength +// from src/windows/hpi/src/sys_api_md.c + +int os::ftruncate(int fd, jlong length) { + HANDLE h = (HANDLE)::_get_osfhandle(fd); + long high = (long)(length >> 32); + DWORD ret; + + if (h == (HANDLE)(-1)) { + return -1; + } + + ret = ::SetFilePointer(h, (long)(length), &high, FILE_BEGIN); + if ((ret == 0xFFFFFFFF) && (::GetLastError() != NO_ERROR)) { + return -1; + } + + if (::SetEndOfFile(h) == FALSE) { + return -1; + } + + return 0; +} + + +// This code is a copy of JDK's sysSync +// from src/windows/hpi/src/sys_api_md.c +// except for the legacy workaround for a bug in Win 98 + +int os::fsync(int fd) { + HANDLE handle = (HANDLE)::_get_osfhandle(fd); + + if ( (!::FlushFileBuffers(handle)) && + (GetLastError() != ERROR_ACCESS_DENIED) ) { + /* from winerror.h */ + return -1; + } + return 0; +} + +static int nonSeekAvailable(int, long *); +static int stdinAvailable(int, long *); + +#define S_ISCHR(mode) (((mode) & _S_IFCHR) == _S_IFCHR) +#define S_ISFIFO(mode) (((mode) & _S_IFIFO) == _S_IFIFO) + +// This code is a copy of JDK's sysAvailable +// from src/windows/hpi/src/sys_api_md.c + +int os::available(int fd, jlong *bytes) { + jlong cur, end; + struct _stati64 stbuf64; + + if (::_fstati64(fd, &stbuf64) >= 0) { + int mode = stbuf64.st_mode; + if (S_ISCHR(mode) || S_ISFIFO(mode)) { + int ret; + long lpbytes; + if (fd == 0) { + ret = stdinAvailable(fd, &lpbytes); + } else { + ret = nonSeekAvailable(fd, &lpbytes); + } + (*bytes) = (jlong)(lpbytes); + return ret; + } + if ((cur = ::_lseeki64(fd, 0L, SEEK_CUR)) == -1) { + return FALSE; + } else if ((end = ::_lseeki64(fd, 0L, SEEK_END)) == -1) { + return FALSE; + } else if (::_lseeki64(fd, cur, SEEK_SET) == -1) { + return FALSE; + } + *bytes = end - cur; + return TRUE; + } else { + return FALSE; + } +} + +// This code is a copy of JDK's nonSeekAvailable +// 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. + * + */ + HANDLE han; + + if ((han = (HANDLE) ::_get_osfhandle(fd)) == (HANDLE)(-1)) { + return FALSE; + } + + 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. + */ + if (::GetLastError() != ERROR_BROKEN_PIPE) { + return FALSE; + } + *pbytes = 0; + } + return TRUE; +} + +#define MAX_INPUT_EVENTS 2000 + +// This code is a copy of JDK's stdinAvailable +// from src/windows/hpi/src/sys_api_md.c + +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 */ + + if ((han = ::GetStdHandle(STD_INPUT_HANDLE)) == INVALID_HANDLE_VALUE) { + return FALSE; + } + + /* 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 */ + if (numEvents > MAX_INPUT_EVENTS) { + numEvents = MAX_INPUT_EVENTS; + } + + lpBuffer = (INPUT_RECORD *)os::malloc(numEvents * sizeof(INPUT_RECORD)); + if (lpBuffer == NULL) { + return FALSE; + } + + error = ::PeekConsoleInput(han, lpBuffer, numEvents, &numEventsRead); + if (error == 0) { + os::free(lpBuffer); + return FALSE; + } + + /* Examine input records for the number of bytes available */ + for(i=0; ibKeyDown == TRUE) { + CHAR *keyPressed = (CHAR *) &(keyRecord->uChar); + curLength++; + if (*keyPressed == '\r') { + actualLength = curLength; + } + } + } + } + + if(lpBuffer != NULL) { + os::free(lpBuffer); + } + + *pbytes = (long) actualLength; + return TRUE; +} + // Map a block of memory. char* os::map_memory(int fd, const char* file_name, size_t file_offset, char *addr, size_t bytes, bool read_only, @@ -3871,7 +4198,7 @@ int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); if (fd != -1) { struct stat buf; - close(fd); + ::close(fd); while (::stat(filename, &buf) == 0) { Sleep(100); } @@ -4232,3 +4559,164 @@ // We don't build a headless jre for Windows bool os::is_headless_jre() { return false; } +// OS_SocketInterface +// Not used on Windows + +// OS_SocketInterface +typedef struct hostent * (PASCAL FAR *ws2_ifn_ptr_t)(...); +ws2_ifn_ptr_t *get_host_by_name_fn = NULL; + +typedef CRITICAL_SECTION mutex_t; +#define mutexInit(m) InitializeCriticalSection(m) +#define mutexDestroy(m) DeleteCriticalSection(m) +#define mutexLock(m) EnterCriticalSection(m) +#define mutexUnlock(m) LeaveCriticalSection(m) + +static bool sockfnptrs_initialized = FALSE; +static mutex_t sockFnTableMutex; + +/* is Winsock2 loaded? better to be explicit than to rely on sockfnptrs */ +static bool winsock2Available = FALSE; + + +static void initSockFnTable() { + int (PASCAL FAR* WSAStartupPtr)(WORD, LPWSADATA); + WSADATA wsadata; + + ::mutexInit(&sockFnTableMutex); + ::mutexLock(&sockFnTableMutex); + + if (sockfnptrs_initialized == FALSE) { + HMODULE hWinsock; + + /* try to load Winsock2, and if that fails, load Winsock */ + hWinsock = ::LoadLibrary("ws2_32.dll"); + + if (hWinsock == NULL) { + jio_fprintf(stderr, "Could not load Winsock 2 (error: %d)\n", + ::GetLastError()); + return; + } + + /* If we loaded a DLL, then we might as well initialize it. */ + WSAStartupPtr = (int (PASCAL FAR *)(WORD, LPWSADATA)) + ::GetProcAddress(hWinsock, "WSAStartup"); + + if (WSAStartupPtr(MAKEWORD(1,1), &wsadata) != 0) { + jio_fprintf(stderr, "Could not initialize Winsock\n"); + } + + get_host_by_name_fn + = (ws2_ifn_ptr_t*) GetProcAddress(hWinsock, "gethostbyname"); + } + + assert(get_host_by_name_fn != NULL, + "gethostbyname function not found"); + sockfnptrs_initialized = TRUE; + ::mutexUnlock(&sockFnTableMutex); +} + +struct hostent* os::get_host_by_name(char* name) { + if (!sockfnptrs_initialized) { + initSockFnTable(); + } + + assert(sockfnptrs_initialized == TRUE && get_host_by_name_fn != NULL, + "sockfnptrs is not initialized or pointer to gethostbyname function is NULL"); + return (*get_host_by_name_fn)(name); +} + + +int os::socket_close(int fd) { + ShouldNotReachHere(); + return 0; +} + +int os::socket_available(int fd, jint *pbytes) { + ShouldNotReachHere(); + return 0; +} + +int os::socket(int domain, int type, int protocol) { + ShouldNotReachHere(); + return 0; +} + +int os::listen(int fd, int count) { + ShouldNotReachHere(); + return 0; +} + +int os::connect(int fd, struct sockaddr *him, int len) { + ShouldNotReachHere(); + return 0; +} + +int os::accept(int fd, struct sockaddr *him, int *len) { + ShouldNotReachHere(); + return 0; +} + +int os::sendto(int fd, char *buf, int len, int flags, + struct sockaddr *to, int tolen) { + ShouldNotReachHere(); + return 0; +} + +int os::recvfrom(int fd, char *buf, int nBytes, int flags, + sockaddr *from, int *fromlen) { + ShouldNotReachHere(); + return 0; +} + +int os::recv(int fd, char *buf, int nBytes, int flags) { + ShouldNotReachHere(); + return 0; +} + +int os::send(int fd, char *buf, int nBytes, int flags) { + ShouldNotReachHere(); + return 0; +} + +int os::raw_send(int fd, char *buf, int nBytes, int flags) { + ShouldNotReachHere(); + return 0; +} + +int os::timeout(int fd, long timeout) { + ShouldNotReachHere(); + return 0; +} + +int os::get_host_name(char* name, int namelen) { + ShouldNotReachHere(); + return 0; +} + +int os::socket_shutdown(int fd, int howto) { + ShouldNotReachHere(); + return 0; +} + +int os::bind(int fd, struct sockaddr *him, int len) { + ShouldNotReachHere(); + return 0; +} + +int os::get_sock_name(int fd, struct sockaddr *him, int *len) { + ShouldNotReachHere(); + return 0; +} + +int os::get_sock_opt(int fd, int level, int optname, + char *optval, int* optlen) { + ShouldNotReachHere(); + return 0; +} + +int os::set_sock_opt(int fd, int level, int optname, + const char *optval, int optlen) { + ShouldNotReachHere(); + return 0; +} diff -r 01c0559441c8 -r 3c205c4f1cda src/os/windows/vm/os_windows.inline.hpp --- a/src/os/windows/vm/os_windows.inline.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os/windows/vm/os_windows.inline.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -35,15 +35,26 @@ inline const char* os::file_separator() { return "\\"; } inline const char* os::line_separator() { return "\r\n"; } inline const char* os::path_separator() { return ";"; } +inline const char* os::dll_file_extension() { return ".dll"; } inline const char* os::jlong_format_specifier() { return "%I64d"; } inline const char* os::julong_format_specifier() { return "%I64u"; } +inline const int os::default_file_open_flags() { return O_BINARY | O_NOINHERIT;} + // File names are case-insensitive on windows only inline int os::file_name_strcmp(const char* s, const char* t) { return _stricmp(s, t); } +inline void os::dll_unload(void *lib) { + ::FreeLibrary((HMODULE)lib); +} + +inline void* os::dll_lookup(void *lib, const char *name) { + return (void*)::GetProcAddress((HMODULE)lib, name); +} + // Used to improve time-sharing on some systems inline void os::loop_breaker(int attempts) {} @@ -83,4 +94,19 @@ inline bool os::numa_has_static_binding() { return true; } inline bool os::numa_has_group_homing() { return false; } +inline size_t os::read(int fd, void *buf, unsigned int nBytes) { + return ::read(fd, buf, nBytes); +} + +inline size_t os::restartable_read(int fd, void *buf, unsigned int nBytes) { + return ::read(fd, buf, nBytes); +} + +inline size_t os::write(int fd, const void *buf, unsigned int nBytes) { + return ::write(fd, buf, nBytes); +} + +inline int os::close(int fd) { + return ::close(fd); +} #endif // OS_WINDOWS_VM_OS_WINDOWS_INLINE_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp --- a/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -41,7 +41,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/linux_x86/vm/os_linux_x86.cpp --- a/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/linux_x86/vm/os_linux_x86.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -41,7 +41,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/linux_zero/vm/os_linux_zero.cpp --- a/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/linux_zero/vm/os_linux_zero.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -42,7 +42,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp --- a/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -41,7 +41,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" @@ -289,17 +288,17 @@ if (*flags == TRS_LWPID) { sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(), *lwp); - if ((lwpfd = open(lwpstatusfile, O_RDONLY)) < 0) { + if ((lwpfd = ::open(lwpstatusfile, O_RDONLY)) < 0) { perror("thr_mutator_status: open lwpstatus"); return (EINVAL); } if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) != sizeof (lwpstatus_t)) { perror("thr_mutator_status: read lwpstatus"); - (void) close(lwpfd); + (void) ::close(lwpfd); return (EINVAL); } - (void) close(lwpfd); + (void) ::close(lwpfd); } return (0); } diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp --- a/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/solaris_x86/vm/os_solaris_x86.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -41,7 +41,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/os_cpu/windows_x86/vm/os_windows_x86.cpp --- a/src/os_cpu/windows_x86/vm/os_windows_x86.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/os_cpu/windows_x86/vm/os_windows_x86.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -41,7 +41,6 @@ #include "runtime/arguments.hpp" #include "runtime/extendedPC.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/classfile/classLoader.cpp --- a/src/share/vm/classfile/classLoader.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/classfile/classLoader.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -48,7 +48,6 @@ #include "runtime/fprofiler.hpp" #include "runtime/handles.hpp" #include "runtime/handles.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/init.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" @@ -61,15 +60,12 @@ #include "utilities/hashtable.hpp" #include "utilities/hashtable.inline.hpp" #ifdef TARGET_OS_FAMILY_linux -# include "hpi_linux.hpp" # include "os_linux.inline.hpp" #endif #ifdef TARGET_OS_FAMILY_solaris -# include "hpi_solaris.hpp" # include "os_solaris.inline.hpp" #endif #ifdef TARGET_OS_FAMILY_windows -# include "hpi_windows.hpp" # include "os_windows.inline.hpp" #endif @@ -208,13 +204,13 @@ struct stat st; if (os::stat(path, &st) == 0) { // found file, open it - int file_handle = hpi::open(path, 0, 0); + int file_handle = os::open(path, 0, 0); if (file_handle != -1) { // read contents into resource array u1* buffer = NEW_RESOURCE_ARRAY(u1, st.st_size); size_t num_read = os::read(file_handle, (char*) buffer, st.st_size); // close file - hpi::close(file_handle); + os::close(file_handle); // construct ClassFileStream if (num_read == (size_t)st.st_size) { if (UsePerfData) { @@ -607,18 +603,18 @@ // Load zip library char path[JVM_MAXPATHLEN]; char ebuf[1024]; - hpi::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip"); - void* handle = hpi::dll_load(path, ebuf, sizeof ebuf); + os::dll_build_name(path, sizeof(path), Arguments::get_dll_dir(), "zip"); + void* handle = os::dll_load(path, ebuf, sizeof ebuf); if (handle == NULL) { vm_exit_during_initialization("Unable to load ZIP library", path); } // Lookup zip entry points - ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, hpi::dll_lookup(handle, "ZIP_Open")); - ZipClose = CAST_TO_FN_PTR(ZipClose_t, hpi::dll_lookup(handle, "ZIP_Close")); - FindEntry = CAST_TO_FN_PTR(FindEntry_t, hpi::dll_lookup(handle, "ZIP_FindEntry")); - ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, hpi::dll_lookup(handle, "ZIP_ReadEntry")); - ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, hpi::dll_lookup(handle, "ZIP_ReadMappedEntry")); - GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, hpi::dll_lookup(handle, "ZIP_GetNextEntry")); + ZipOpen = CAST_TO_FN_PTR(ZipOpen_t, os::dll_lookup(handle, "ZIP_Open")); + ZipClose = CAST_TO_FN_PTR(ZipClose_t, os::dll_lookup(handle, "ZIP_Close")); + FindEntry = CAST_TO_FN_PTR(FindEntry_t, os::dll_lookup(handle, "ZIP_FindEntry")); + ReadEntry = CAST_TO_FN_PTR(ReadEntry_t, os::dll_lookup(handle, "ZIP_ReadEntry")); + ReadMappedEntry = CAST_TO_FN_PTR(ReadMappedEntry_t, os::dll_lookup(handle, "ZIP_ReadMappedEntry")); + GetNextEntry = CAST_TO_FN_PTR(GetNextEntry_t, os::dll_lookup(handle, "ZIP_GetNextEntry")); // ZIP_Close is not exported on Windows in JDK5.0 so don't abort if ZIP_Close is NULL if (ZipOpen == NULL || FindEntry == NULL || ReadEntry == NULL || GetNextEntry == NULL) { @@ -627,7 +623,7 @@ // Lookup canonicalize entry in libjava.dll void *javalib_handle = os::native_java_library(); - CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, hpi::dll_lookup(javalib_handle, "Canonicalize")); + CanonicalizeEntry = CAST_TO_FN_PTR(canonicalize_fn_t, os::dll_lookup(javalib_handle, "Canonicalize")); // This lookup only works on 1.3. Do not check for non-null here } @@ -1076,7 +1072,7 @@ assert(orig != NULL && out != NULL && len > 0, "bad arguments"); if (CanonicalizeEntry != NULL) { JNIEnv* env = JavaThread::current()->jni_environment(); - if ((CanonicalizeEntry)(env, hpi::native_path(orig), out, len) < 0) { + if ((CanonicalizeEntry)(env, os::native_path(orig), out, len) < 0) { return false; } } else { diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/classfile/javaClasses.cpp --- a/src/share/vm/classfile/javaClasses.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/classfile/javaClasses.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -182,7 +182,7 @@ if (_to_java_string_fn == NULL) { void *lib_handle = os::native_java_library(); - _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, hpi::dll_lookup(lib_handle, "NewStringPlatform")); + _to_java_string_fn = CAST_TO_FN_PTR(to_java_string_fn_t, os::dll_lookup(lib_handle, "NewStringPlatform")); if (_to_java_string_fn == NULL) { fatal("NewStringPlatform missing"); } @@ -207,7 +207,7 @@ if (_to_platform_string_fn == NULL) { void *lib_handle = os::native_java_library(); - _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, hpi::dll_lookup(lib_handle, "GetStringPlatformChars")); + _to_platform_string_fn = CAST_TO_FN_PTR(to_platform_string_fn_t, os::dll_lookup(lib_handle, "GetStringPlatformChars")); if (_to_platform_string_fn == NULL) { fatal("GetStringPlatformChars missing"); } diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/classfile/verifier.cpp --- a/src/share/vm/classfile/verifier.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/classfile/verifier.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -38,7 +38,6 @@ #include "prims/jvm.h" #include "runtime/fieldDescriptor.hpp" #include "runtime/handles.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/javaCalls.hpp" #include "runtime/orderAccess.hpp" @@ -69,11 +68,11 @@ static void* verify_byte_codes_fn() { if (_verify_byte_codes_fn == NULL) { void *lib_handle = os::native_java_library(); - void *func = hpi::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); + void *func = os::dll_lookup(lib_handle, "VerifyClassCodesForMajorVersion"); OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); if (func == NULL) { OrderAccess::release_store(&_is_new_verify_byte_codes_fn, false); - func = hpi::dll_lookup(lib_handle, "VerifyClassCodes"); + func = os::dll_lookup(lib_handle, "VerifyClassCodes"); OrderAccess::release_store_ptr(&_verify_byte_codes_fn, func); } } diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/compiler/disassembler.cpp --- a/src/share/vm/compiler/disassembler.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/compiler/disassembler.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -30,7 +30,6 @@ #include "memory/cardTableModRefBS.hpp" #include "runtime/fprofiler.hpp" #include "runtime/handles.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/stubCodeGenerator.hpp" #include "runtime/stubRoutines.hpp" #ifdef TARGET_ARCH_x86 @@ -84,17 +83,17 @@ // Find the disassembler next to libjvm.so. strcpy(&buf[jvm_offset], hsdis_library_name); strcat(&buf[jvm_offset], os::dll_file_extension()); - _library = hpi::dll_load(buf, ebuf, sizeof ebuf); + _library = os::dll_load(buf, ebuf, sizeof ebuf); } if (_library == NULL) { // Try a free-floating lookup. strcpy(&buf[0], hsdis_library_name); strcat(&buf[0], os::dll_file_extension()); - _library = hpi::dll_load(buf, ebuf, sizeof ebuf); + _library = os::dll_load(buf, ebuf, sizeof ebuf); } if (_library != NULL) { _decode_instructions = CAST_TO_FN_PTR(Disassembler::decode_func, - hpi::dll_lookup(_library, decode_instructions_name)); + os::dll_lookup(_library, decode_instructions_name)); } _tried_to_load_library = true; if (_decode_instructions == NULL) { diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/memory/dump.cpp --- a/src/share/vm/memory/dump.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/memory/dump.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -1365,7 +1365,7 @@ ResourceMark rm; // Preload classes to be shared. - // Should use some hpi:: method rather than fopen() here. aB. + // Should use some os:: method rather than fopen() here. aB. // Construct the path to the class list (in jre/lib) // Walk up two directories from the location of the VM and // optionally tack on "lib" (depending on platform) @@ -1504,7 +1504,7 @@ } else { char errmsg[JVM_MAXPATHLEN]; - hpi::lasterror(errmsg, JVM_MAXPATHLEN); + os::lasterror(errmsg, JVM_MAXPATHLEN); tty->print_cr("Loading classlist failed: %s", errmsg); exit(1); } diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/memory/filemap.cpp --- a/src/share/vm/memory/filemap.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/memory/filemap.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -30,15 +30,6 @@ #include "runtime/java.hpp" #include "runtime/os.hpp" #include "utilities/defaultStream.hpp" -#ifdef TARGET_OS_FAMILY_linux -# include "hpi_linux.hpp" -#endif -#ifdef TARGET_OS_FAMILY_solaris -# include "hpi_solaris.hpp" -#endif -#ifdef TARGET_OS_FAMILY_windows -# include "hpi_windows.hpp" -#endif # include # include diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/opto/matcher.cpp --- a/src/share/vm/opto/matcher.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/opto/matcher.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -36,7 +36,6 @@ #include "opto/runtime.hpp" #include "opto/type.hpp" #include "runtime/atomic.hpp" -#include "runtime/hpi.hpp" #include "runtime/os.hpp" #ifdef TARGET_ARCH_MODEL_x86_32 # include "adfiles/ad_x86_32.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/precompiled.hpp --- a/src/share/vm/precompiled.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/precompiled.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -168,7 +168,6 @@ # include "oops/symbolOop.hpp" # include "oops/typeArrayKlass.hpp" # include "oops/typeArrayOop.hpp" -# include "prims/hpi_imported.h" # include "prims/jni.h" # include "prims/jvm.h" # include "prims/jvmtiExport.hpp" @@ -185,7 +184,6 @@ # include "runtime/globals_extension.hpp" # include "runtime/handles.hpp" # include "runtime/handles.inline.hpp" -# include "runtime/hpi.hpp" # include "runtime/icache.hpp" # include "runtime/init.hpp" # include "runtime/interfaceSupport.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/hpi_imported.h --- a/src/share/vm/prims/hpi_imported.h Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,319 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -/* - * HotSpot integration note: - * - * This is a consolidation of these two files: - * src/share/hpi/export/hpi.h 1.15 99/06/18 JDK1.3 beta build I - * src/share/hpi/export/dll.h 1.3 98/09/15 JDK1.3 beta build I - * from the classic VM. - * - * bool_t is a type in the classic VM, and we define it here, - * but in the future this should be a jboolean. - * - * The files are included verbatim expect for local includes removed from hpi.h. - */ - -#ifndef SHARE_VM_PRIMS_HPI_IMPORTED_H -#define SHARE_VM_PRIMS_HPI_IMPORTED_H - -#include "jni.h" - -#ifdef __cplusplus -extern "C" { -#endif - -/* A classic VMism that should become a jboolean. Fix in 1.2.1? */ -typedef enum { HPI_FALSE = 0, HPI_TRUE = 1 } bool_t; - -/* - * DLL.H: A common interface for helper DLLs loaded by the VM. - * Each library exports the main entry point "DLL_Initialize". Through - * that function the programmer can obtain a function pointer which has - * type "GetInterfaceFunc." Through the function pointer the programmer - * can obtain other interfaces supported in the DLL. - */ -typedef jint (JNICALL * GetInterfaceFunc) - (void **intfP, const char *name, jint ver); - -jint JNICALL DLL_Initialize(GetInterfaceFunc *, void *args); - - -/* - * Host Porting Interface. This defines the "porting layer" for - * POSIX.1 compliant operating systems. - */ - -/* - * memory allocations - */ -typedef struct { - /* - * Malloc must return a unique pointer if size == 0. - */ - void * (*Malloc)(size_t size); - void * (*Realloc)(void *ptr, size_t new_size); - /* - * Free must allow ptr == NULL to be a no-op. - */ - void (*Free)(void *ptr); - /* - * Calloc must return a unique pointer for if - * n_item == 0 || item_size == 0. - */ - void * (*Calloc)(size_t n_item, size_t item_size); - char * (*Strdup)(const char *str); - - void * (*MapMem)(size_t req_size, size_t *maped_size); - void * (*UnmapMem)(void *req_addr, size_t req_size, size_t *unmap_size); - /* - * CommitMem should round the ptr down to the nearest page and - * round the size up to the nearest page so that the committed - * region is at least as large as the requested region. - */ - void * (*CommitMem)(void *ptr, size_t size, size_t *actual); - /* - * sysDecommitMem should round the ptr up to the nearest page and - * round the size down to the nearest page so that the decommitted - * region is no greater than the requested region. - */ - void * (*DecommitMem)(void *ptr, size_t size, size_t *actual); - -#define HPI_PAGE_ALIGNMENT (64 * 1024) - - void * (*AllocBlock)(size_t size, void **headP); - void (*FreeBlock)(void *head); -} HPI_MemoryInterface; - -/* - * dynamic linking libraries - */ -typedef struct { - void (*BuildLibName)(char *buf, int buf_len, char *path, const char *name); - int (*BuildFunName)(char *name, int name_len, int arg_size, int en_idx); - - void * (*LoadLibrary)(const char *name, char *err_buf, int err_buflen); - void (*UnloadLibrary)(void *lib); - void * (*FindLibraryEntry)(void *lib, const char *name); -} HPI_LibraryInterface; - -typedef void (*signal_handler_t)(int sig, void *siginfo, void *context); - -#define HPI_SIG_DFL (signal_handler_t)0 -#define HPI_SIG_ERR (signal_handler_t)-1 -#define HPI_SIG_IGN (signal_handler_t)1 - -typedef struct { - char *name; /* name such as green/native threads. */ - int isMP; -} HPI_SysInfo; - -typedef struct { - HPI_SysInfo * (*GetSysInfo)(void); - long (*GetMilliTicks)(void); - jlong (*TimeMillis)(void); - - signal_handler_t (*Signal)(int sig, signal_handler_t handler); - void (*Raise)(int sig); - void (*SignalNotify)(int sig); - int (*SignalWait)(void); - - int (*Shutdown)(void); - - int (*SetLoggingLevel)(int level); - bool_t (*SetMonitoringOn)(bool_t on); - int (*GetLastErrorString)(char *buf, int len); -} HPI_SystemInterface; - -/* - * threads and monitors - */ -typedef struct sys_thread sys_thread_t; -typedef struct sys_mon sys_mon_t; - -#define HPI_OK 0 -#define HPI_ERR -1 -#define HPI_INTRPT -2 /* Operation was interrupted */ -#define HPI_TIMEOUT -3 /* A timer ran out */ -#define HPI_NOMEM -5 /* Ran out of memory */ -#define HPI_NORESOURCE -6 /* Ran out of some system resource */ - -/* There are three basic states: RUNNABLE, MONITOR_WAIT, and CONDVAR_WAIT. - * When the thread is suspended in any of these states, the - * HPI_THREAD_SUSPENDED bit will be set - */ -enum { - HPI_THREAD_RUNNABLE = 1, - HPI_THREAD_MONITOR_WAIT, - HPI_THREAD_CONDVAR_WAIT -}; - -#define HPI_MINIMUM_PRIORITY 1 -#define HPI_MAXIMUM_PRIORITY 10 -#define HPI_NORMAL_PRIORITY 5 - -#define HPI_THREAD_SUSPENDED 0x8000 -#define HPI_THREAD_INTERRUPTED 0x4000 - -typedef struct { - sys_thread_t *owner; - int entry_count; - sys_thread_t **monitor_waiters; - sys_thread_t **condvar_waiters; - int sz_monitor_waiters; - int sz_condvar_waiters; - int n_monitor_waiters; - int n_condvar_waiters; -} sys_mon_info; - -typedef struct { - int (*ThreadBootstrap)(sys_thread_t **tidP, - sys_mon_t **qlockP, - int nReservedBytes); - int (*ThreadCreate)(sys_thread_t **tidP, - long stk_size, - void (*func)(void *), - void *arg); - sys_thread_t * (*ThreadSelf)(void); - void (*ThreadYield)(void); - int (*ThreadSuspend)(sys_thread_t *tid); - int (*ThreadResume)(sys_thread_t *tid); - int (*ThreadSetPriority)(sys_thread_t *tid, int prio); - int (*ThreadGetPriority)(sys_thread_t *tid, int *prio); - void * (*ThreadStackPointer)(sys_thread_t *tid); - void * (*ThreadStackTop)(sys_thread_t *tid); - long * (*ThreadRegs)(sys_thread_t *tid, int *regs); - int (*ThreadSingle)(void); - void (*ThreadMulti)(void); - int (*ThreadEnumerateOver)(int (*func)(sys_thread_t *, void *), - void *arg); - int (*ThreadCheckStack)(void); - void (*ThreadPostException)(sys_thread_t *tid, void *arg); - void (*ThreadInterrupt)(sys_thread_t *tid); - int (*ThreadIsInterrupted)(sys_thread_t *tid, int clear); - int (*ThreadAlloc)(sys_thread_t **tidP); - int (*ThreadFree)(void); - jlong (*ThreadCPUTime)(void); - int (*ThreadGetStatus)(sys_thread_t *tid, sys_mon_t **monitor); - void * (*ThreadInterruptEvent)(void); - void * (*ThreadNativeID)(sys_thread_t *tid); - - /* These three functions are used by the CPU time profiler. - * sysThreadIsRunning determines whether the thread is running (not just - * runnable). It is only safe to call this function after calling - * sysThreadProfSuspend. - */ - bool_t (*ThreadIsRunning)(sys_thread_t *tid); - void (*ThreadProfSuspend)(sys_thread_t *tid); - void (*ThreadProfResume)(sys_thread_t *tid); - - int (*AdjustTimeSlice)(int ms); - - size_t (*MonitorSizeof)(void); - int (*MonitorInit)(sys_mon_t *mid); - int (*MonitorDestroy)(sys_mon_t *mid); - int (*MonitorEnter)(sys_thread_t *self, sys_mon_t *mid); - bool_t (*MonitorEntered)(sys_thread_t *self, sys_mon_t *mid); - int (*MonitorExit)(sys_thread_t *self, sys_mon_t *mid); - int (*MonitorNotify)(sys_thread_t *self, sys_mon_t *mid); - int (*MonitorNotifyAll)(sys_thread_t *self, sys_mon_t *mid); - int (*MonitorWait)(sys_thread_t *self, sys_mon_t *mid, jlong ms); - bool_t (*MonitorInUse)(sys_mon_t *mid); - sys_thread_t * (*MonitorOwner)(sys_mon_t *mid); - int (*MonitorGetInfo)(sys_mon_t *mid, sys_mon_info *info); - -} HPI_ThreadInterface; - -/* - * files - */ - -#define HPI_FILETYPE_REGULAR (0) -#define HPI_FILETYPE_DIRECTORY (1) -#define HPI_FILETYPE_OTHER (2) - -typedef struct { - char * (*NativePath)(char *path); - int (*FileType)(const char *path); - int (*Open)(const char *name, int openMode, int filePerm); - int (*Close)(int fd); - jlong (*Seek)(int fd, jlong offset, int whence); - int (*SetLength)(int fd, jlong length); - int (*Sync)(int fd); - int (*Available)(int fd, jlong *bytes); - size_t (*Read)(int fd, void *buf, unsigned int nBytes); - size_t (*Write)(int fd, const void *buf, unsigned int nBytes); - int (*FileSizeFD)(int fd, jlong *size); -} HPI_FileInterface; - -/* - * sockets - */ -struct sockaddr; -struct hostent; - -typedef struct { - int (*Close)(int fd); - long (*Available)(int fd, jint *pbytes); - int (*Connect)(int fd, struct sockaddr *him, int len); - int (*Accept)(int fd, struct sockaddr *him, int *len); - int (*SendTo)(int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen); - int (*RecvFrom)(int fd, char *buf, int nbytes, int flags, - struct sockaddr *from, int *fromlen); - int (*Listen)(int fd, long count); - int (*Recv)(int fd, char *buf, int nBytes, int flags); - int (*Send)(int fd, char *buf, int nBytes, int flags); - int (*Timeout)(int fd, long timeout); - struct hostent * (*GetHostByName)(char *hostname); - int (*Socket)(int domain, int type, int protocol); - int (*SocketShutdown)(int fd, int howto); - int (*Bind)(int fd, struct sockaddr *him, int len); - int (*GetSocketName)(int fd, struct sockaddr *him, int *len); - int (*GetHostName)(char *hostname, int namelen); - struct hostent * (*GetHostByAddr)(const char *hostname, int len, int type); - int (*SocketGetOption)(int fd, int level, int optname, char *optval, int *optlen); - int (*SocketSetOption)(int fd, int level, int optname, const char *optval, int optlen); - struct protoent * (*GetProtoByName)(char* name); -} HPI_SocketInterface; - -/* - * callbacks. - */ -typedef struct vm_calls { - int (*jio_fprintf)(FILE *fp, const char *fmt, ...); - void (*panic)(const char *fmt, ...); - void (*monitorRegister)(sys_mon_t *mid, char *info_str); - - void (*monitorContendedEnter)(sys_thread_t *self, sys_mon_t *mid); - void (*monitorContendedEntered)(sys_thread_t *self, sys_mon_t *mid); - void (*monitorContendedExit)(sys_thread_t *self, sys_mon_t *mid); -} vm_calls_t; - -#ifdef __cplusplus -} -#endif - -#endif // SHARE_VM_PRIMS_HPI_IMPORTED_H diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/jni.cpp --- a/src/share/vm/prims/jni.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/prims/jni.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -3258,7 +3258,6 @@ #define JAVASTACKSIZE (400 * 1024) /* Default size of a thread java stack */ -#define PROCSTACKSIZE 0 /* 0 means default size in HPI */ enum { VERIFY_NONE, VERIFY_REMOTE, VERIFY_ALL }; HS_DTRACE_PROBE_DECL1(hotspot_jni, GetDefaultJavaVMInitArgs__entry, void*); diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/jvm.cpp --- a/src/share/vm/prims/jvm.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/prims/jvm.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -43,7 +43,6 @@ #include "runtime/arguments.hpp" #include "runtime/dtraceJSDT.hpp" #include "runtime/handles.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/init.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" @@ -65,15 +64,12 @@ #include "utilities/top.hpp" #include "utilities/utf8.hpp" #ifdef TARGET_OS_FAMILY_linux -# include "hpi_linux.hpp" # include "jvm_linux.h" #endif #ifdef TARGET_OS_FAMILY_solaris -# include "hpi_solaris.hpp" # include "jvm_solaris.h" #endif #ifdef TARGET_OS_FAMILY_windows -# include "hpi_windows.hpp" # include "jvm_windows.h" #endif @@ -653,7 +649,7 @@ JVM_LEAF(jint, JVM_GetLastErrorString(char *buf, int len)) JVMWrapper("JVM_GetLastErrorString"); - return hpi::lasterror(buf, len); + return (jint)os::lasterror(buf, len); JVM_END @@ -661,7 +657,7 @@ JVM_LEAF(char*, JVM_NativePath(char* path)) JVMWrapper2("JVM_NativePath (%s)", path); - return hpi::native_path(path); + return os::native_path(path); JVM_END @@ -2487,7 +2483,7 @@ JVMWrapper2("JVM_Open (%s)", fname); //%note jvm_r6 - int result = hpi::open(fname, flags, mode); + int result = os::open(fname, flags, mode); if (result >= 0) { return result; } else { @@ -2504,7 +2500,7 @@ JVM_LEAF(jint, JVM_Close(jint fd)) JVMWrapper2("JVM_Close (0x%x)", fd); //%note jvm_r6 - return hpi::close(fd); + return os::close(fd); JVM_END @@ -2512,7 +2508,7 @@ JVMWrapper2("JVM_Read (0x%x)", fd); //%note jvm_r6 - return (jint)hpi::read(fd, buf, nbytes); + return (jint)os::restartable_read(fd, buf, nbytes); JVM_END @@ -2520,34 +2516,34 @@ JVMWrapper2("JVM_Write (0x%x)", fd); //%note jvm_r6 - return (jint)hpi::write(fd, buf, nbytes); + return (jint)os::write(fd, buf, nbytes); JVM_END JVM_LEAF(jint, JVM_Available(jint fd, jlong *pbytes)) JVMWrapper2("JVM_Available (0x%x)", fd); //%note jvm_r6 - return hpi::available(fd, pbytes); + return os::available(fd, pbytes); JVM_END JVM_LEAF(jlong, JVM_Lseek(jint fd, jlong offset, jint whence)) JVMWrapper4("JVM_Lseek (0x%x, %Ld, %d)", fd, offset, whence); //%note jvm_r6 - return hpi::lseek(fd, offset, whence); + return os::lseek(fd, offset, whence); JVM_END JVM_LEAF(jint, JVM_SetLength(jint fd, jlong length)) JVMWrapper3("JVM_SetLength (0x%x, %Ld)", fd, length); - return hpi::ftruncate(fd, length); + return os::ftruncate(fd, length); JVM_END JVM_LEAF(jint, JVM_Sync(jint fd)) JVMWrapper2("JVM_Sync (0x%x)", fd); //%note jvm_r6 - return hpi::fsync(fd); + return os::fsync(fd); JVM_END @@ -3457,145 +3453,124 @@ JVM_LEAF(jint, JVM_InitializeSocketLibrary()) JVMWrapper("JVM_InitializeSocketLibrary"); - return hpi::initialize_socket_library(); + return 0; JVM_END JVM_LEAF(jint, JVM_Socket(jint domain, jint type, jint protocol)) JVMWrapper("JVM_Socket"); - return hpi::socket(domain, type, protocol); + return os::socket(domain, type, protocol); JVM_END JVM_LEAF(jint, JVM_SocketClose(jint fd)) JVMWrapper2("JVM_SocketClose (0x%x)", fd); //%note jvm_r6 - return hpi::socket_close(fd); + return os::socket_close(fd); JVM_END JVM_LEAF(jint, JVM_SocketShutdown(jint fd, jint howto)) JVMWrapper2("JVM_SocketShutdown (0x%x)", fd); //%note jvm_r6 - return hpi::socket_shutdown(fd, howto); + return os::socket_shutdown(fd, howto); JVM_END JVM_LEAF(jint, JVM_Recv(jint fd, char *buf, jint nBytes, jint flags)) JVMWrapper2("JVM_Recv (0x%x)", fd); //%note jvm_r6 - return hpi::recv(fd, buf, nBytes, flags); + return os::recv(fd, buf, nBytes, flags); JVM_END JVM_LEAF(jint, JVM_Send(jint fd, char *buf, jint nBytes, jint flags)) JVMWrapper2("JVM_Send (0x%x)", fd); //%note jvm_r6 - return hpi::send(fd, buf, nBytes, flags); + return os::send(fd, buf, nBytes, flags); JVM_END JVM_LEAF(jint, JVM_Timeout(int fd, long timeout)) JVMWrapper2("JVM_Timeout (0x%x)", fd); //%note jvm_r6 - return hpi::timeout(fd, timeout); + return os::timeout(fd, timeout); JVM_END JVM_LEAF(jint, JVM_Listen(jint fd, jint count)) JVMWrapper2("JVM_Listen (0x%x)", fd); //%note jvm_r6 - return hpi::listen(fd, count); + return os::listen(fd, count); JVM_END JVM_LEAF(jint, JVM_Connect(jint fd, struct sockaddr *him, jint len)) JVMWrapper2("JVM_Connect (0x%x)", fd); //%note jvm_r6 - return hpi::connect(fd, him, len); + return os::connect(fd, him, len); JVM_END JVM_LEAF(jint, JVM_Bind(jint fd, struct sockaddr *him, jint len)) JVMWrapper2("JVM_Bind (0x%x)", fd); //%note jvm_r6 - return hpi::bind(fd, him, len); + return os::bind(fd, him, len); JVM_END JVM_LEAF(jint, JVM_Accept(jint fd, struct sockaddr *him, jint *len)) JVMWrapper2("JVM_Accept (0x%x)", fd); //%note jvm_r6 - return hpi::accept(fd, him, (int *)len); + return os::accept(fd, him, (int *)len); JVM_END JVM_LEAF(jint, JVM_RecvFrom(jint fd, char *buf, int nBytes, int flags, struct sockaddr *from, int *fromlen)) JVMWrapper2("JVM_RecvFrom (0x%x)", fd); //%note jvm_r6 - return hpi::recvfrom(fd, buf, nBytes, flags, from, fromlen); + return os::recvfrom(fd, buf, nBytes, flags, from, fromlen); JVM_END JVM_LEAF(jint, JVM_GetSockName(jint fd, struct sockaddr *him, int *len)) JVMWrapper2("JVM_GetSockName (0x%x)", fd); //%note jvm_r6 - return hpi::get_sock_name(fd, him, len); + return os::get_sock_name(fd, him, len); JVM_END JVM_LEAF(jint, JVM_SendTo(jint fd, char *buf, int len, int flags, struct sockaddr *to, int tolen)) JVMWrapper2("JVM_SendTo (0x%x)", fd); //%note jvm_r6 - return hpi::sendto(fd, buf, len, flags, to, tolen); + return os::sendto(fd, buf, len, flags, to, tolen); JVM_END JVM_LEAF(jint, JVM_SocketAvailable(jint fd, jint *pbytes)) JVMWrapper2("JVM_SocketAvailable (0x%x)", fd); //%note jvm_r6 - return hpi::socket_available(fd, pbytes); + return os::socket_available(fd, pbytes); JVM_END JVM_LEAF(jint, JVM_GetSockOpt(jint fd, int level, int optname, char *optval, int *optlen)) JVMWrapper2("JVM_GetSockOpt (0x%x)", fd); //%note jvm_r6 - return hpi::get_sock_opt(fd, level, optname, optval, optlen); + return os::get_sock_opt(fd, level, optname, optval, optlen); JVM_END JVM_LEAF(jint, JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen)) JVMWrapper2("JVM_GetSockOpt (0x%x)", fd); //%note jvm_r6 - return hpi::set_sock_opt(fd, level, optname, optval, optlen); + return os::set_sock_opt(fd, level, optname, optval, optlen); JVM_END JVM_LEAF(int, JVM_GetHostName(char* name, int namelen)) JVMWrapper("JVM_GetHostName"); - return hpi::get_host_name(name, namelen); -JVM_END - -#ifdef _WINDOWS - -JVM_LEAF(struct hostent*, JVM_GetHostByAddr(const char* name, int len, int type)) - JVMWrapper("JVM_GetHostByAddr"); - return hpi::get_host_by_addr(name, len, type); -JVM_END - - -JVM_LEAF(struct hostent*, JVM_GetHostByName(char* name)) - JVMWrapper("JVM_GetHostByName"); - return hpi::get_host_by_name(name); -JVM_END - - -JVM_LEAF(struct protoent*, JVM_GetProtoByName(char* name)) - JVMWrapper("JVM_GetProtoByName"); - return hpi::get_proto_by_name(name); -JVM_END - -#endif + return os::get_host_name(name, namelen); +JVM_END // Library support /////////////////////////////////////////////////////////////////////////// @@ -3606,7 +3581,7 @@ void *load_result; { ThreadToNativeFromVM ttnfvm(thread); - load_result = hpi::dll_load(name, ebuf, sizeof ebuf); + load_result = os::dll_load(name, ebuf, sizeof ebuf); } if (load_result == NULL) { char msg[1024]; @@ -3628,13 +3603,13 @@ JVM_LEAF(void, JVM_UnloadLibrary(void* handle)) JVMWrapper("JVM_UnloadLibrary"); - hpi::dll_unload(handle); + os::dll_unload(handle); JVM_END JVM_LEAF(void*, JVM_FindLibraryEntry(void* handle, const char* name)) JVMWrapper2("JVM_FindLibraryEntry (%s)", name); - return hpi::dll_lookup(handle, name); + return os::dll_lookup(handle, name); JVM_END // Floating point support //////////////////////////////////////////////////////////////////// diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/jvm.h --- a/src/share/vm/prims/jvm.h Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/prims/jvm.h Wed Dec 01 18:32:50 2010 -0500 @@ -1405,23 +1405,6 @@ JNIEXPORT jint JNICALL JVM_SetSockOpt(jint fd, int level, int optname, const char *optval, int optlen); -/* - * These routines are only reentrant on Windows - */ - -#ifdef _WINDOWS - -JNIEXPORT struct protoent * JNICALL -JVM_GetProtoByName(char* name); - -JNIEXPORT struct hostent* JNICALL -JVM_GetHostByAddr(const char* name, int len, int type); - -JNIEXPORT struct hostent* JNICALL -JVM_GetHostByName(char* name); - -#endif /* _WINDOWS */ - JNIEXPORT int JNICALL JVM_GetHostName(char* name, int namelen); diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/jvmtiExport.cpp --- a/src/share/vm/prims/jvmtiExport.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/prims/jvmtiExport.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -2298,16 +2298,16 @@ // load it from the standard dll directory. if (is_absolute_path) { - library = hpi::dll_load(agent, ebuf, sizeof ebuf); + library = os::dll_load(agent, ebuf, sizeof ebuf); } else { // Try to load the agent from the standard dll directory - hpi::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), agent); - library = hpi::dll_load(buffer, ebuf, sizeof ebuf); + os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), agent); + library = os::dll_load(buffer, ebuf, sizeof ebuf); if (library == NULL) { // not found - try local path char ns[1] = {0}; - hpi::dll_build_name(buffer, sizeof(buffer), ns, agent); - library = hpi::dll_load(buffer, ebuf, sizeof ebuf); + os::dll_build_name(buffer, sizeof(buffer), ns, agent); + library = os::dll_load(buffer, ebuf, sizeof ebuf); } } @@ -2320,13 +2320,13 @@ const char *on_attach_symbols[] = AGENT_ONATTACH_SYMBOLS; for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_attach_symbols); symbol_index++) { on_attach_entry = - CAST_TO_FN_PTR(OnAttachEntry_t, hpi::dll_lookup(library, on_attach_symbols[symbol_index])); + CAST_TO_FN_PTR(OnAttachEntry_t, os::dll_lookup(library, on_attach_symbols[symbol_index])); if (on_attach_entry != NULL) break; } if (on_attach_entry == NULL) { // Agent_OnAttach missing - unload library - hpi::dll_unload(library); + os::dll_unload(library); } else { // Invoke the Agent_OnAttach function JavaThread* THREAD = JavaThread::current(); diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/prims/nativeLookup.cpp --- a/src/share/vm/prims/nativeLookup.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/prims/nativeLookup.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -37,7 +37,6 @@ #include "prims/nativeLookup.hpp" #include "runtime/arguments.hpp" #include "runtime/handles.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/javaCalls.hpp" #include "runtime/sharedRuntime.hpp" #include "runtime/signature.hpp" @@ -154,7 +153,7 @@ if (loader.is_null()) { entry = lookup_special_native(jni_name); if (entry == NULL) { - entry = (address) hpi::dll_lookup(os::native_java_library(), jni_name); + entry = (address) os::dll_lookup(os::native_java_library(), jni_name); } if (entry != NULL) { in_base_library = true; @@ -181,7 +180,7 @@ // findNative didn't find it, if there are any agent libraries look in them AgentLibrary* agent; for (agent = Arguments::agents(); agent != NULL; agent = agent->next()) { - entry = (address) hpi::dll_lookup(agent->os_lib(), jni_name); + entry = (address) os::dll_lookup(agent->os_lib(), jni_name); if (entry != NULL) { return entry; } diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/globals.hpp --- a/src/share/vm/runtime/globals.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/runtime/globals.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -1280,9 +1280,6 @@ develop(bool, TraceStartupTime, false, \ "Trace setup time") \ \ - develop(bool, TraceHPI, false, \ - "Trace Host Porting Interface (HPI)") \ - \ product(ccstr, HPILibPath, NULL, \ "Specify alternate path to HPI library") \ \ diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/hpi.cpp --- a/src/share/vm/runtime/hpi.cpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,103 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#include "precompiled.hpp" -#include "prims/jvm.h" -#include "runtime/hpi.hpp" - -extern "C" { - static void unimplemented_panic(const char *fmt, ...) { - // mitigate testing damage from bug 6626677 - warning("hpi::unimplemented_panic called"); - } - - static void unimplemented_monitorRegister(sys_mon_t *mid, char *info_str) { - Unimplemented(); - } -} - -static vm_calls_t callbacks = { - jio_fprintf, - unimplemented_panic, - unimplemented_monitorRegister, - - NULL, // unused - NULL, // unused - NULL // unused -}; - -GetInterfaceFunc hpi::_get_interface = NULL; -HPI_FileInterface* hpi::_file = NULL; -HPI_SocketInterface* hpi::_socket = NULL; -HPI_LibraryInterface* hpi::_library = NULL; -HPI_SystemInterface* hpi::_system = NULL; - -jint hpi::initialize() -{ - initialize_get_interface(&callbacks); - if (_get_interface == NULL) - return JNI_ERR; - - jint result; - - result = (*_get_interface)((void **)&_file, "File", 1); - if (result != 0) { - if (TraceHPI) tty->print_cr("Can't find HPI_FileInterface"); - return JNI_ERR; - } - - - result = (*_get_interface)((void **)&_library, "Library", 1); - if (result != 0) { - if (TraceHPI) tty->print_cr("Can't find HPI_LibraryInterface"); - return JNI_ERR; - } - - result = (*_get_interface)((void **)&_system, "System", 1); - if (result != 0) { - if (TraceHPI) tty->print_cr("Can't find HPI_SystemInterface"); - return JNI_ERR; - } - - return JNI_OK; -} - -jint hpi::initialize_socket_library() -{ - if (_get_interface == NULL) { - if (TraceHPI) { - tty->print_cr("Fatal HPI error: reached initialize_socket_library with NULL _get_interface"); - } - return JNI_ERR; - } - - jint result; - result = (*_get_interface)((void **)&_socket, "Socket", 1); - if (result != 0) { - if (TraceHPI) tty->print_cr("Can't find HPI_SocketInterface"); - return JNI_ERR; - } - - return JNI_OK; -} diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/hpi.hpp --- a/src/share/vm/runtime/hpi.hpp Wed Dec 01 03:12:35 2010 -0800 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,244 +0,0 @@ -/* - * Copyright (c) 1998, 2010, Oracle and/or its affiliates. All rights reserved. - * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. - * - * This code is free software; you can redistribute it and/or modify it - * under the terms of the GNU General Public License version 2 only, as - * published by the Free Software Foundation. - * - * This code is distributed in the hope that it will be useful, but WITHOUT - * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or - * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License - * version 2 for more details (a copy is included in the LICENSE file that - * accompanied this code). - * - * You should have received a copy of the GNU General Public License version - * 2 along with this work; if not, write to the Free Software Foundation, - * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. - * - * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA - * or visit www.oracle.com if you need additional information or have any - * questions. - * - */ - -#ifndef SHARE_VM_RUNTIME_HPI_HPP -#define SHARE_VM_RUNTIME_HPI_HPP - -#include "prims/hpi_imported.h" -#include "runtime/os.hpp" -#include "utilities/globalDefinitions.hpp" -#include "utilities/top.hpp" - -// -// C++ wrapper to HPI. -// - -class hpi : AllStatic { - -private: - static GetInterfaceFunc _get_interface; - static HPI_FileInterface* _file; - static HPI_SocketInterface* _socket; - static HPI_LibraryInterface* _library; - static HPI_SystemInterface* _system; - -private: - static void initialize_get_interface(vm_calls_t *callbacks); - -public: - // Load and initialize everything except sockets. - static jint initialize(); - - // Socket library needs to be lazy intialized because eagerly - // loading Winsock is known to cause "connect to your ISP" - // dialog to show up. Or so goes the legend. - static jint initialize_socket_library(); - - // HPI_FileInterface - static inline char* native_path(char *path); - static inline int file_type(const char *path); - static inline int open(const char *name, int mode, int perm); - static inline int close(int fd); - static inline jlong lseek(int fd, jlong off, int whence); - static inline int ftruncate(int fd, jlong length); - static inline int fsync(int fd); - static inline int available(int fd, jlong *bytes); - static inline size_t read(int fd, void *buf, unsigned int nBytes); - static inline size_t write(int fd, const void *buf, unsigned int nBytes); - static inline int fsize(int fd, jlong *size); - - // HPI_SocketInterface - static inline int socket(int domain, int type, int protocol); - static inline int socket_close(int fd); - static inline int socket_shutdown(int fd, int howto); - static inline int recv(int fd, char *buf, int nBytes, int flags); - static inline int send(int fd, char *buf, int nBytes, int flags); - // Variant of send that doesn't support interruptible I/O - static inline int raw_send(int fd, char *buf, int nBytes, int flags); - static inline int timeout(int fd, long timeout); - static inline int listen(int fd, int count); - static inline int connect(int fd, struct sockaddr *him, int len); - static inline int bind(int fd, struct sockaddr *him, int len); - static inline int accept(int fd, struct sockaddr *him, int *len); - static inline int recvfrom(int fd, char *buf, int nbytes, int flags, - struct sockaddr *from, int *fromlen); - static inline int get_sock_name(int fd, struct sockaddr *him, int *len); - static inline int sendto(int fd, char *buf, int len, int flags, - struct sockaddr *to, int tolen); - static inline int socket_available(int fd, jint *pbytes); - - static inline int get_sock_opt(int fd, int level, int optname, - char *optval, int* optlen); - static inline int set_sock_opt(int fd, int level, int optname, - const char *optval, int optlen); - static inline int get_host_name(char* name, int namelen); - static inline struct hostent* get_host_by_addr(const char* name, int len, int type); - static inline struct hostent* get_host_by_name(char* name); - static inline struct protoent* get_proto_by_name(char* name); - - // HPI_LibraryInterface - static inline void dll_build_name(char *buf, int buf_len, const char* path, - const char *name); - static inline void* dll_load(const char *name, char *ebuf, int ebuflen); - static inline void dll_unload(void *lib); - static inline void* dll_lookup(void *lib, const char *name); - - // HPI_SystemInterface - static inline int lasterror(char *buf, int len); -}; - -// -// Macros that provide inline bodies for the functions. -// - -#define HPIDECL(name, names, intf, func, ret_type, ret_fmt, arg_type, arg_print, arg) \ - inline ret_type hpi::name arg_type { \ - if (TraceHPI) { \ - tty->print("hpi::" names "("); \ - tty->print arg_print ; \ - tty->print(") = "); \ - } \ - ret_type result = (*intf->func) arg ; \ - if (TraceHPI) { \ - tty->print_cr(ret_fmt, result); \ - } \ - return result; \ - } - -// Macro to facilitate moving HPI functionality into the vm. -// See bug 6348631. The only difference between this macro and -// HPIDECL is that we call a vm method rather than use the HPI -// transfer vector. Ultimately, we'll replace HPIDECL with -// VM_HPIDECL for all hpi methods. -#define VM_HPIDECL(name, names, func, ret_type, ret_fmt, arg_type,arg_print, arg) \ - inline ret_type hpi::name arg_type { \ - if (TraceHPI) { \ - tty->print("hpi::" names "("); \ - tty->print arg_print ; \ - tty->print(") = "); \ - } \ - ret_type result = func arg ; \ - if (TraceHPI) { \ - tty->print_cr(ret_fmt, result); \ - } \ - return result; \ - } - -#define VM_HPIDECL_VOID(name, names, func, arg_type, arg_print, arg) \ - inline void hpi::name arg_type { \ - if (TraceHPI) { \ - tty->print("hpi::" names "("); \ - tty->print arg_print; \ - tty->print(") = "); \ - } \ - func arg; \ - } - -#define HPIDECL_VOID(name, names, intf, func, arg_type, arg_print, arg) \ - inline void hpi::name arg_type { \ - if (TraceHPI) { \ - tty->print("hpi::" names "("); \ - tty->print arg_print ; \ - tty->print_cr(") = void"); \ - } \ - (*intf->func) arg ; \ - } - - -// The macro calls below realize into -// inline char * hpi::native_path(...) { inlined_body; } -// etc. - -// HPI_FileInterface - -HPIDECL(native_path, "native_path", _file, NativePath, char *, "%s", - (char *path), - ("path = %s", path), - (path)); - -HPIDECL(file_type, "file_type", _file, FileType, int, "%d", - (const char *path), - ("path = %s", path), - (path)); - -HPIDECL(open, "open", _file, Open, int, "%d", - (const char *name, int mode, int perm), - ("name = %s, mode = %d, perm = %d", name, mode, perm), - (name, mode, perm)); - -HPIDECL(lseek, "seek", _file, Seek, jlong, "(a jlong)", - (int fd, jlong off, int whence), - ("fd = %d, off = (a jlong), whence = %d", fd, /* off, */ whence), - (fd, off, whence)); - -HPIDECL(ftruncate, "ftruncate", _file, SetLength, int, "%d", - (int fd, jlong length), - ("fd = %d, length = (a jlong)", fd /*, length */), - (fd, length)); - -HPIDECL(fsync, "fsync", _file, Sync, int, "%d", - (int fd), - ("fd = %d", fd), - (fd)); - -HPIDECL(available, "available", _file, Available, int, "%d", - (int fd, jlong *bytes), - ("fd = %d, bytes = %p", fd, bytes), - (fd, bytes)); - -HPIDECL(fsize, "fsize", _file, FileSizeFD, int, "%d", - (int fd, jlong *size), - ("fd = %d, size = %p", fd, size), - (fd, size)); - -// HPI_LibraryInterface -VM_HPIDECL_VOID(dll_build_name, "dll_build_name", os::dll_build_name, - (char *buf, int buf_len, const char *path, const char *name), - ("buf = %p, buflen = %d, path = %s, name = %s", - buf, buf_len, path, name), - (buf, buf_len, path, name)); - -VM_HPIDECL(dll_load, "dll_load", os::dll_load, - void *, "(void *)%p", - (const char *name, char *ebuf, int ebuflen), - ("name = %s, ebuf = %p, ebuflen = %d", name, ebuf, ebuflen), - (name, ebuf, ebuflen)); - -HPIDECL_VOID(dll_unload, "dll_unload", _library, UnloadLibrary, - (void *lib), - ("lib = %p", lib), - (lib)); - -HPIDECL(dll_lookup, "dll_lookup", _library, FindLibraryEntry, void *, "%p", - (void *lib, const char *name), - ("lib = %p, name = %s", lib, name), - (lib, name)); - -// HPI_SystemInterface -HPIDECL(lasterror, "lasterror", _system, GetLastErrorString, int, "%d", - (char *buf, int len), - ("buf = %p, len = %d", buf, len), - (buf, len)); - -#endif // SHARE_VM_RUNTIME_HPI_HPP diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/os.cpp --- a/src/share/vm/runtime/os.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/runtime/os.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -38,7 +38,6 @@ #include "prims/privilegedStack.hpp" #include "runtime/arguments.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" #include "runtime/javaCalls.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/os.hpp --- a/src/share/vm/runtime/os.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/runtime/os.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -360,9 +360,6 @@ // thread id on Linux/64bit is 64bit, on Windows and Solaris, it's 32bit static intx current_thread_id(); static int current_process_id(); - // hpi::read for calls from non native state - // For performance, hpi::read is only callable from _thread_in_native - static size_t read(int fd, void *buf, unsigned int nBytes); static int sleep(Thread* thread, jlong ms, bool interruptable); static int naked_sleep(); static void infinite_sleep(); // never returns, use with CAUTION @@ -418,6 +415,22 @@ // Die immediately, no exit hook, no abort hook, no cleanup. static void die(); + // File i/o operations + static const int default_file_open_flags(); + static int open(const char *path, int oflag, int mode); + static int close(int fd); + static jlong lseek(int fd, jlong offset, int whence); + static char* native_path(char *path); + static int ftruncate(int fd, jlong length); + static int fsync(int fd); + static int available(int fd, jlong *bytes); + + //File i/o operations + + static size_t read(int fd, void *buf, unsigned int nBytes); + static size_t restartable_read(int fd, void *buf, unsigned int nBytes); + static size_t write(int fd, const void *buf, unsigned int nBytes); + // Reading directories. static DIR* opendir(const char* dirname); static int readdir_buf_size(const char *path); @@ -460,6 +473,9 @@ // lookup symbol in a shared library static void* dll_lookup(void* handle, const char* name); + // Unload library + static void dll_unload(void *lib); + // Print out system information; they are called by fatal error handler. // Output format may be different on different platforms. static void print_os_info(outputStream* st); @@ -474,6 +490,7 @@ static void print_date_and_time(outputStream* st); static void print_location(outputStream* st, intptr_t x, bool verbose = false); + static size_t lasterror(char *buf, size_t len); // The following two functions are used by fatal error handler to trace // native (C) frames. They are not part of frame.hpp/frame.cpp because @@ -501,7 +518,7 @@ // Returns native Java library, loads if necessary static void* native_java_library(); - // Fills in path to jvm.dll/libjvm.so (this info used to find hpi). + // Fills in path to jvm.dll/libjvm.so (used by the Disassembler) static void jvm_path(char *buf, jint buflen); // Returns true if we are running in a headless jre. @@ -547,6 +564,33 @@ static int num_frees; // # of calls to free #endif + // SocketInterface (ex HPI SocketInterface ) + static int socket(int domain, int type, int protocol); + static int socket_close(int fd); + static int socket_shutdown(int fd, int howto); + static int recv(int fd, char *buf, int nBytes, int flags); + static int send(int fd, char *buf, int nBytes, int flags); + static int raw_send(int fd, char *buf, int nBytes, int flags); + static int timeout(int fd, long timeout); + static int listen(int fd, int count); + static int connect(int fd, struct sockaddr *him, int len); + static int bind(int fd, struct sockaddr *him, int len); + static int accept(int fd, struct sockaddr *him, int *len); + static int recvfrom(int fd, char *buf, int nbytes, int flags, + struct sockaddr *from, int *fromlen); + static int get_sock_name(int fd, struct sockaddr *him, int *len); + static int sendto(int fd, char *buf, int len, int flags, + struct sockaddr *to, int tolen); + static int socket_available(int fd, jint *pbytes); + + static int get_sock_opt(int fd, int level, int optname, + char *optval, int* optlen); + static int set_sock_opt(int fd, int level, int optname, + const char *optval, int optlen); + static int get_host_name(char* name, int namelen); + + static struct hostent* get_host_by_name(char* name); + // Printing 64 bit integers static const char* jlong_format_specifier(); static const char* julong_format_specifier(); diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/osThread.hpp --- a/src/share/vm/runtime/osThread.hpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/runtime/osThread.hpp Wed Dec 01 18:32:50 2010 -0500 @@ -27,7 +27,6 @@ #include "runtime/frame.hpp" #include "runtime/handles.hpp" -#include "runtime/hpi.hpp" #include "runtime/javaFrameAnchor.hpp" #include "runtime/objectMonitor.hpp" #include "utilities/top.hpp" diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/runtime/thread.cpp --- a/src/share/vm/runtime/thread.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/runtime/thread.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -47,7 +47,6 @@ #include "runtime/deoptimization.hpp" #include "runtime/fprofiler.hpp" #include "runtime/frame.inline.hpp" -#include "runtime/hpi.hpp" #include "runtime/init.hpp" #include "runtime/interfaceSupport.hpp" #include "runtime/java.hpp" @@ -3386,7 +3385,7 @@ const char *msg = "Could not find agent library "; if (agent->is_absolute_path()) { - library = hpi::dll_load(name, ebuf, sizeof ebuf); + library = os::dll_load(name, ebuf, sizeof ebuf); if (library == NULL) { const char *sub_msg = " in absolute path, with error: "; size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; @@ -3398,8 +3397,8 @@ } } else { // Try to load the agent from the standard dll directory - hpi::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), name); - library = hpi::dll_load(buffer, ebuf, sizeof ebuf); + os::dll_build_name(buffer, sizeof(buffer), Arguments::get_dll_dir(), name); + library = os::dll_load(buffer, ebuf, sizeof ebuf); #ifdef KERNEL // Download instrument dll if (library == NULL && strcmp(name, "instrument") == 0) { @@ -3419,13 +3418,13 @@ } FREE_C_HEAP_ARRAY(char, cmd); // when this comes back the instrument.dll should be where it belongs. - library = hpi::dll_load(buffer, ebuf, sizeof ebuf); + library = os::dll_load(buffer, ebuf, sizeof ebuf); } #endif // KERNEL if (library == NULL) { // Try the local directory char ns[1] = {0}; - hpi::dll_build_name(buffer, sizeof(buffer), ns, name); - library = hpi::dll_load(buffer, ebuf, sizeof ebuf); + os::dll_build_name(buffer, sizeof(buffer), ns, name); + library = os::dll_load(buffer, ebuf, sizeof ebuf); if (library == NULL) { const char *sub_msg = " on the library path, with error: "; size_t len = strlen(msg) + strlen(name) + strlen(sub_msg) + strlen(ebuf) + 1; @@ -3442,7 +3441,7 @@ // Find the OnLoad function. for (size_t symbol_index = 0; symbol_index < num_symbol_entries; symbol_index++) { - on_load_entry = CAST_TO_FN_PTR(OnLoadEntry_t, hpi::dll_lookup(library, on_load_symbols[symbol_index])); + on_load_entry = CAST_TO_FN_PTR(OnLoadEntry_t, os::dll_lookup(library, on_load_symbols[symbol_index])); if (on_load_entry != NULL) break; } return on_load_entry; @@ -3524,7 +3523,7 @@ // Find the Agent_OnUnload function. for (uint symbol_index = 0; symbol_index < ARRAY_SIZE(on_unload_symbols); symbol_index++) { Agent_OnUnload_t unload_entry = CAST_TO_FN_PTR(Agent_OnUnload_t, - hpi::dll_lookup(agent->os_lib(), on_unload_symbols[symbol_index])); + os::dll_lookup(agent->os_lib(), on_unload_symbols[symbol_index])); // Invoke the Agent_OnUnload function if (unload_entry != NULL) { @@ -3693,7 +3692,6 @@ #ifndef PRODUCT // disable function tracing at JNI/JVM barriers - TraceHPI = false; TraceJNICalls = false; TraceJVMCalls = false; TraceRuntimeCalls = false; diff -r 01c0559441c8 -r 3c205c4f1cda src/share/vm/utilities/ostream.cpp --- a/src/share/vm/utilities/ostream.cpp Wed Dec 01 03:12:35 2010 -0800 +++ b/src/share/vm/utilities/ostream.cpp Wed Dec 01 18:32:50 2010 -0500 @@ -26,21 +26,17 @@ #include "compiler/compileLog.hpp" #include "oops/oop.inline.hpp" #include "runtime/arguments.hpp" -#include "runtime/hpi.hpp" #include "utilities/defaultStream.hpp" #include "utilities/ostream.hpp" #include "utilities/top.hpp" #include "utilities/xmlstream.hpp" #ifdef TARGET_OS_FAMILY_linux -# include "hpi_linux.hpp" # include "os_linux.inline.hpp" #endif #ifdef TARGET_OS_FAMILY_solaris -# include "hpi_solaris.hpp" # include "os_solaris.inline.hpp" #endif #ifdef TARGET_OS_FAMILY_windows -# include "hpi_windows.hpp" # include "os_windows.inline.hpp" #endif @@ -879,9 +875,7 @@ _socket = -1; - hpi::initialize_socket_library(); - - int result = hpi::socket(AF_INET, SOCK_STREAM, 0); + int result = os::socket(AF_INET, SOCK_STREAM, 0); if (result <= 0) { assert(false, "Socket could not be created!"); } else { @@ -890,12 +884,12 @@ } int networkStream::read(char *buf, size_t len) { - return hpi::recv(_socket, buf, (int)len, 0); + return os::recv(_socket, buf, (int)len, 0); } void networkStream::flush() { if (size() != 0) { - int result = hpi::raw_send(_socket, (char *)base(), (int)size(), 0); + int result = os::raw_send(_socket, (char *)base(), (int)size(), 0); assert(result != -1, "connection error"); assert(result == (int)size(), "didn't send enough data"); } @@ -909,7 +903,7 @@ void networkStream::close() { if (_socket != -1) { flush(); - hpi::socket_close(_socket); + os::socket_close(_socket); _socket = -1; } } @@ -922,11 +916,7 @@ server.sin_addr.s_addr = inet_addr(ip); if (server.sin_addr.s_addr == (uint32_t)-1) { -#ifdef _WINDOWS - struct hostent* host = hpi::get_host_by_name((char*)ip); -#else - struct hostent* host = gethostbyname(ip); -#endif + struct hostent* host = os::get_host_by_name((char*)ip); if (host != NULL) { memcpy(&server.sin_addr, host->h_addr_list[0], host->h_length); } else { @@ -935,7 +925,7 @@ } - int result = hpi::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in)); + int result = os::connect(_socket, (struct sockaddr*)&server, sizeof(struct sockaddr_in)); return (result >= 0); }