Mercurial > hg > graal-compiler
comparison src/os/linux/vm/os_linux.cpp @ 1980:828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
Summary: move functions from hpi library to hotspot, communicate with licensees and open source community, check jdk for dependency, file CCC request
Reviewed-by: coleenp, acorn, dsamersoff
author | ikrylov |
---|---|
date | Wed, 01 Dec 2010 18:26:32 -0500 |
parents | f95d63e2154a |
children | 54f5dd2aa1d9 |
comparison
equal
deleted
inserted
replaced
1972:f95d63e2154a | 1980:828eafbd85cc |
---|---|
42 #include "prims/jvm.h" | 42 #include "prims/jvm.h" |
43 #include "prims/jvm_misc.hpp" | 43 #include "prims/jvm_misc.hpp" |
44 #include "runtime/arguments.hpp" | 44 #include "runtime/arguments.hpp" |
45 #include "runtime/extendedPC.hpp" | 45 #include "runtime/extendedPC.hpp" |
46 #include "runtime/globals.hpp" | 46 #include "runtime/globals.hpp" |
47 #include "runtime/hpi.hpp" | |
48 #include "runtime/interfaceSupport.hpp" | 47 #include "runtime/interfaceSupport.hpp" |
49 #include "runtime/java.hpp" | 48 #include "runtime/java.hpp" |
50 #include "runtime/javaCalls.hpp" | 49 #include "runtime/javaCalls.hpp" |
51 #include "runtime/mutexLocker.hpp" | 50 #include "runtime/mutexLocker.hpp" |
52 #include "runtime/objectMonitor.hpp" | 51 #include "runtime/objectMonitor.hpp" |
1563 } | 1562 } |
1564 | 1563 |
1565 // unused on linux for now. | 1564 // unused on linux for now. |
1566 void os::set_error_file(const char *logfile) {} | 1565 void os::set_error_file(const char *logfile) {} |
1567 | 1566 |
1567 | |
1568 // This method is a copy of JDK's sysGetLastErrorString | |
1569 // from src/solaris/hpi/src/system_md.c | |
1570 | |
1571 size_t os::lasterror(char *buf, size_t len) { | |
1572 | |
1573 if (errno == 0) return 0; | |
1574 | |
1575 const char *s = ::strerror(errno); | |
1576 size_t n = ::strlen(s); | |
1577 if (n >= len) { | |
1578 n = len - 1; | |
1579 } | |
1580 ::strncpy(buf, s, n); | |
1581 buf[n] = '\0'; | |
1582 return n; | |
1583 } | |
1584 | |
1568 intx os::current_thread_id() { return (intx)pthread_self(); } | 1585 intx os::current_thread_id() { return (intx)pthread_self(); } |
1569 int os::current_process_id() { | 1586 int os::current_process_id() { |
1570 | 1587 |
1571 // Under the old linux thread library, linux gives each thread | 1588 // Under the old linux thread library, linux gives each thread |
1572 // its own process id. Because of this each thread will return | 1589 // its own process id. Because of this each thread will return |
1927 pthread_mutex_unlock(&dl_mutex); | 1944 pthread_mutex_unlock(&dl_mutex); |
1928 return res; | 1945 return res; |
1929 } | 1946 } |
1930 | 1947 |
1931 | 1948 |
1932 bool _print_ascii_file(const char* filename, outputStream* st) { | 1949 static bool _print_ascii_file(const char* filename, outputStream* st) { |
1933 int fd = open(filename, O_RDONLY); | 1950 int fd = ::open(filename, O_RDONLY); |
1934 if (fd == -1) { | 1951 if (fd == -1) { |
1935 return false; | 1952 return false; |
1936 } | 1953 } |
1937 | 1954 |
1938 char buf[32]; | 1955 char buf[32]; |
1939 int bytes; | 1956 int bytes; |
1940 while ((bytes = read(fd, buf, sizeof(buf))) > 0) { | 1957 while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { |
1941 st->print_raw(buf, bytes); | 1958 st->print_raw(buf, bytes); |
1942 } | 1959 } |
1943 | 1960 |
1944 close(fd); | 1961 ::close(fd); |
1945 | 1962 |
1946 return true; | 1963 return true; |
1947 } | 1964 } |
1948 | 1965 |
1949 void os::print_dll_info(outputStream *st) { | 1966 void os::print_dll_info(outputStream *st) { |
2217 | 2234 |
2218 if (0 == access(buf, F_OK)) { | 2235 if (0 == access(buf, F_OK)) { |
2219 // Use current module name "libjvm[_g].so" instead of | 2236 // Use current module name "libjvm[_g].so" instead of |
2220 // "libjvm"debug_only("_g")".so" since for fastdebug version | 2237 // "libjvm"debug_only("_g")".so" since for fastdebug version |
2221 // we should have "libjvm.so" but debug_only("_g") adds "_g"! | 2238 // we should have "libjvm.so" but debug_only("_g") adds "_g"! |
2222 // It is used when we are choosing the HPI library's name | |
2223 // "libhpi[_g].so" in hpi::initialize_get_interface(). | |
2224 len = strlen(buf); | 2239 len = strlen(buf); |
2225 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); | 2240 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); |
2226 } else { | 2241 } else { |
2227 // Go back to path of .so | 2242 // Go back to path of .so |
2228 rp = realpath(dli_fname, buf); | 2243 rp = realpath(dli_fname, buf); |
2402 | 2417 |
2403 snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d", | 2418 snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d", |
2404 os::get_temp_directory(), os::current_process_id(), num); | 2419 os::get_temp_directory(), os::current_process_id(), num); |
2405 unlink(buf); | 2420 unlink(buf); |
2406 | 2421 |
2407 int fd = open(buf, O_CREAT | O_RDWR, S_IRWXU); | 2422 int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU); |
2408 | 2423 |
2409 if (fd != -1) { | 2424 if (fd != -1) { |
2410 off_t rv = lseek(fd, size-2, SEEK_SET); | 2425 off_t rv = ::lseek(fd, size-2, SEEK_SET); |
2411 if (rv != (off_t)-1) { | 2426 if (rv != (off_t)-1) { |
2412 if (write(fd, "", 1) == 1) { | 2427 if (::write(fd, "", 1) == 1) { |
2413 mmap(base, size, | 2428 mmap(base, size, |
2414 PROT_READ|PROT_WRITE|PROT_EXEC, | 2429 PROT_READ|PROT_WRITE|PROT_EXEC, |
2415 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0); | 2430 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0); |
2416 } | 2431 } |
2417 } | 2432 } |
2418 close(fd); | 2433 ::close(fd); |
2419 unlink(buf); | 2434 unlink(buf); |
2420 } | 2435 } |
2421 } | 2436 } |
2422 | 2437 |
2423 // NOTE: Linux kernel does not really reserve the pages for us. | 2438 // NOTE: Linux kernel does not really reserve the pages for us. |
4045 } | 4060 } |
4046 | 4061 |
4047 // Initialize lock used to serialize thread creation (see os::create_thread) | 4062 // Initialize lock used to serialize thread creation (see os::create_thread) |
4048 Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false)); | 4063 Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false)); |
4049 | 4064 |
4050 // Initialize HPI. | |
4051 jint hpi_result = hpi::initialize(); | |
4052 if (hpi_result != JNI_OK) { | |
4053 tty->print_cr("There was an error trying to initialize the HPI library."); | |
4054 return hpi_result; | |
4055 } | |
4056 | |
4057 // at-exit methods are called in the reverse order of their registration. | 4065 // at-exit methods are called in the reverse order of their registration. |
4058 // atexit functions are called on return from main or as a result of a | 4066 // atexit functions are called on return from main or as a result of a |
4059 // call to exit(3C). There can be only 32 of these functions registered | 4067 // call to exit(3C). There can be only 32 of these functions registered |
4060 // and atexit() does not set errno. | 4068 // and atexit() does not set errno. |
4061 | 4069 |
4249 char pathbuf[MAX_PATH]; | 4257 char pathbuf[MAX_PATH]; |
4250 if (strlen(path) > MAX_PATH - 1) { | 4258 if (strlen(path) > MAX_PATH - 1) { |
4251 errno = ENAMETOOLONG; | 4259 errno = ENAMETOOLONG; |
4252 return -1; | 4260 return -1; |
4253 } | 4261 } |
4254 hpi::native_path(strcpy(pathbuf, path)); | 4262 os::native_path(strcpy(pathbuf, path)); |
4255 return ::stat(pathbuf, sbuf); | 4263 return ::stat(pathbuf, sbuf); |
4256 } | 4264 } |
4257 | 4265 |
4258 bool os::check_heap(bool force) { | 4266 bool os::check_heap(bool force) { |
4259 return true; | 4267 return true; |
4281 } | 4289 } |
4282 closedir(dir); | 4290 closedir(dir); |
4283 return result; | 4291 return result; |
4284 } | 4292 } |
4285 | 4293 |
4294 // This code originates from JDK's sysOpen and open64_w | |
4295 // from src/solaris/hpi/src/system_md.c | |
4296 | |
4297 #ifndef O_DELETE | |
4298 #define O_DELETE 0x10000 | |
4299 #endif | |
4300 | |
4301 // Open a file. Unlink the file immediately after open returns | |
4302 // if the specified oflag has the O_DELETE flag set. | |
4303 // O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c | |
4304 | |
4305 int os::open(const char *path, int oflag, int mode) { | |
4306 | |
4307 if (strlen(path) > MAX_PATH - 1) { | |
4308 errno = ENAMETOOLONG; | |
4309 return -1; | |
4310 } | |
4311 int fd; | |
4312 int o_delete = (oflag & O_DELETE); | |
4313 oflag = oflag & ~O_DELETE; | |
4314 | |
4315 fd = ::open64(path, oflag, mode); | |
4316 if (fd == -1) return -1; | |
4317 | |
4318 //If the open succeeded, the file might still be a directory | |
4319 { | |
4320 struct stat64 buf64; | |
4321 int ret = ::fstat64(fd, &buf64); | |
4322 int st_mode = buf64.st_mode; | |
4323 | |
4324 if (ret != -1) { | |
4325 if ((st_mode & S_IFMT) == S_IFDIR) { | |
4326 errno = EISDIR; | |
4327 ::close(fd); | |
4328 return -1; | |
4329 } | |
4330 } else { | |
4331 ::close(fd); | |
4332 return -1; | |
4333 } | |
4334 } | |
4335 | |
4336 /* | |
4337 * All file descriptors that are opened in the JVM and not | |
4338 * specifically destined for a subprocess should have the | |
4339 * close-on-exec flag set. If we don't set it, then careless 3rd | |
4340 * party native code might fork and exec without closing all | |
4341 * appropriate file descriptors (e.g. as we do in closeDescriptors in | |
4342 * UNIXProcess.c), and this in turn might: | |
4343 * | |
4344 * - cause end-of-file to fail to be detected on some file | |
4345 * descriptors, resulting in mysterious hangs, or | |
4346 * | |
4347 * - might cause an fopen in the subprocess to fail on a system | |
4348 * suffering from bug 1085341. | |
4349 * | |
4350 * (Yes, the default setting of the close-on-exec flag is a Unix | |
4351 * design flaw) | |
4352 * | |
4353 * See: | |
4354 * 1085341: 32-bit stdio routines should support file descriptors >255 | |
4355 * 4843136: (process) pipe file descriptor from Runtime.exec not being closed | |
4356 * 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 | |
4357 */ | |
4358 #ifdef FD_CLOEXEC | |
4359 { | |
4360 int flags = ::fcntl(fd, F_GETFD); | |
4361 if (flags != -1) | |
4362 ::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); | |
4363 } | |
4364 #endif | |
4365 | |
4366 if (o_delete != 0) { | |
4367 ::unlink(path); | |
4368 } | |
4369 return fd; | |
4370 } | |
4371 | |
4372 | |
4286 // create binary file, rewriting existing file if required | 4373 // create binary file, rewriting existing file if required |
4287 int os::create_binary_file(const char* path, bool rewrite_existing) { | 4374 int os::create_binary_file(const char* path, bool rewrite_existing) { |
4288 int oflags = O_WRONLY | O_CREAT; | 4375 int oflags = O_WRONLY | O_CREAT; |
4289 if (!rewrite_existing) { | 4376 if (!rewrite_existing) { |
4290 oflags |= O_EXCL; | 4377 oflags |= O_EXCL; |
4298 } | 4385 } |
4299 | 4386 |
4300 // move file pointer to the specified offset | 4387 // move file pointer to the specified offset |
4301 jlong os::seek_to_file_offset(int fd, jlong offset) { | 4388 jlong os::seek_to_file_offset(int fd, jlong offset) { |
4302 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); | 4389 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); |
4390 } | |
4391 | |
4392 // This code originates from JDK's sysAvailable | |
4393 // from src/solaris/hpi/src/native_threads/src/sys_api_td.c | |
4394 | |
4395 int os::available(int fd, jlong *bytes) { | |
4396 jlong cur, end; | |
4397 int mode; | |
4398 struct stat64 buf64; | |
4399 | |
4400 if (::fstat64(fd, &buf64) >= 0) { | |
4401 mode = buf64.st_mode; | |
4402 if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { | |
4403 /* | |
4404 * XXX: is the following call interruptible? If so, this might | |
4405 * need to go through the INTERRUPT_IO() wrapper as for other | |
4406 * blocking, interruptible calls in this file. | |
4407 */ | |
4408 int n; | |
4409 if (::ioctl(fd, FIONREAD, &n) >= 0) { | |
4410 *bytes = n; | |
4411 return 1; | |
4412 } | |
4413 } | |
4414 } | |
4415 if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { | |
4416 return 0; | |
4417 } else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { | |
4418 return 0; | |
4419 } else if (::lseek64(fd, cur, SEEK_SET) == -1) { | |
4420 return 0; | |
4421 } | |
4422 *bytes = end - cur; | |
4423 return 1; | |
4303 } | 4424 } |
4304 | 4425 |
4305 // Map a block of memory. | 4426 // Map a block of memory. |
4306 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | 4427 char* os::map_memory(int fd, const char* file_name, size_t file_offset, |
4307 char *addr, size_t bytes, bool read_only, | 4428 char *addr, size_t bytes, bool read_only, |
4526 } | 4647 } |
4527 | 4648 |
4528 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); | 4649 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
4529 if (fd != -1) { | 4650 if (fd != -1) { |
4530 struct stat buf; | 4651 struct stat buf; |
4531 close(fd); | 4652 ::close(fd); |
4532 while (::stat(filename, &buf) == 0) { | 4653 while (::stat(filename, &buf) == 0) { |
4533 (void)::poll(NULL, 0, 100); | 4654 (void)::poll(NULL, 0, 100); |
4534 } | 4655 } |
4535 } else { | 4656 } else { |
4536 jio_fprintf(stderr, | 4657 jio_fprintf(stderr, |