1 /*
2 * Copyright (c) 1999, 2018, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
2124 }
2125
2126 ::close(fd);
2127
2128 return true;
2129 }
2130
2131 void os::print_dll_info(outputStream *st) {
2132 st->print_cr("Dynamic libraries:");
2133
2134 char fname[32];
2135 pid_t pid = os::Linux::gettid();
2136
2137 jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
2138
2139 if (!_print_ascii_file(fname, st)) {
2140 st->print("Can not get library information for pid = %d\n", pid);
2141 }
2142 }
2143
2144 void os::print_os_info_brief(outputStream* st) {
2145 os::Linux::print_distro_info(st);
2146
2147 os::Posix::print_uname_info(st);
2148
2149 os::Linux::print_libversion_info(st);
2150
2151 }
2152
2153 void os::print_os_info(outputStream* st) {
2154 st->print("OS:");
2155
2156 os::Linux::print_distro_info(st);
2157
2158 os::Posix::print_uname_info(st);
2159
2160 // Print warning if unsafe chroot environment detected
2161 if (unsafe_chroot_detected) {
2162 st->print("WARNING!! ");
2163 st->print_cr("%s", unstable_chroot_error);
4008
4009 for (int j = 0; j < i; ++j) {
4010 if (base[j] != NULL) {
4011 unmap_memory(base[j], size[j]);
4012 }
4013 }
4014
4015 if (i < max_tries) {
4016 _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
4017 return requested_addr;
4018 } else {
4019 _highest_vm_reserved_address = old_highest;
4020 return NULL;
4021 }
4022 }
4023
4024 size_t os::read(int fd, void *buf, unsigned int nBytes) {
4025 return ::read(fd, buf, nBytes);
4026 }
4027
4028 // TODO-FIXME: reconcile Solaris' os::sleep with the linux variation.
4029 // Solaris uses poll(), linux uses park().
4030 // Poll() is likely a better choice, assuming that Thread.interrupt()
4031 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
4032 // SIGSEGV, see 4355769.
4033
4034 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
4035 assert(thread == Thread::current(), "thread consistency check");
4036
4037 ParkEvent * const slp = thread->_SleepEvent ;
4038 slp->reset() ;
4039 OrderAccess::fence() ;
4040
4041 if (interruptible) {
4042 jlong prevtime = javaTimeNanos();
4043
4044 for (;;) {
4045 if (os::is_interrupted(thread, true)) {
4046 return OS_INTRPT;
4047 }
|
1 /*
2 * Copyright (c) 1999, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
14 *
15 * You should have received a copy of the GNU General Public License version
16 * 2 along with this work; if not, write to the Free Software Foundation,
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 *
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 * or visit www.oracle.com if you need additional information or have any
21 * questions.
22 *
2124 }
2125
2126 ::close(fd);
2127
2128 return true;
2129 }
2130
2131 void os::print_dll_info(outputStream *st) {
2132 st->print_cr("Dynamic libraries:");
2133
2134 char fname[32];
2135 pid_t pid = os::Linux::gettid();
2136
2137 jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid);
2138
2139 if (!_print_ascii_file(fname, st)) {
2140 st->print("Can not get library information for pid = %d\n", pid);
2141 }
2142 }
2143
2144 int os::get_loaded_modules_info(os::LoadedModulesCallbackFunc callback, void *param) {
2145 FILE *procmapsFile = NULL;
2146
2147 // Open the procfs maps file for the current process
2148 if ((procmapsFile = fopen("/proc/self/maps", "r")) != NULL) {
2149 // Allocate PATH_MAX for file name plus a reasonable size for other fields.
2150 char line[PATH_MAX + 100];
2151
2152 // Read line by line from 'file'
2153 while (fgets(line, sizeof(line), procmapsFile) != NULL) {
2154 u8 base, top, offset, inode;
2155 char permissions[5];
2156 char device[6];
2157 char name[PATH_MAX + 1];
2158
2159 // Parse fields from line
2160 sscanf(line, UINT64_FORMAT_X "-" UINT64_FORMAT_X " %4s " UINT64_FORMAT_X " %5s " INT64_FORMAT " %s",
2161 &base, &top, permissions, &offset, device, &inode, name);
2162
2163 // Filter by device id '00:00' so that we only get file system mapped files.
2164 if (strcmp(device, "00:00") != 0) {
2165
2166 // Call callback with the fields of interest
2167 if(callback(name, (address)base, (address)top, param)) {
2168 // Oops abort, callback aborted
2169 fclose(procmapsFile);
2170 return 1;
2171 }
2172 }
2173 }
2174 fclose(procmapsFile);
2175 }
2176 return 0;
2177 }
2178
2179 void os::print_os_info_brief(outputStream* st) {
2180 os::Linux::print_distro_info(st);
2181
2182 os::Posix::print_uname_info(st);
2183
2184 os::Linux::print_libversion_info(st);
2185
2186 }
2187
2188 void os::print_os_info(outputStream* st) {
2189 st->print("OS:");
2190
2191 os::Linux::print_distro_info(st);
2192
2193 os::Posix::print_uname_info(st);
2194
2195 // Print warning if unsafe chroot environment detected
2196 if (unsafe_chroot_detected) {
2197 st->print("WARNING!! ");
2198 st->print_cr("%s", unstable_chroot_error);
4043
4044 for (int j = 0; j < i; ++j) {
4045 if (base[j] != NULL) {
4046 unmap_memory(base[j], size[j]);
4047 }
4048 }
4049
4050 if (i < max_tries) {
4051 _highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes);
4052 return requested_addr;
4053 } else {
4054 _highest_vm_reserved_address = old_highest;
4055 return NULL;
4056 }
4057 }
4058
4059 size_t os::read(int fd, void *buf, unsigned int nBytes) {
4060 return ::read(fd, buf, nBytes);
4061 }
4062
4063 size_t os::read_at(int fd, void *buf, unsigned int nBytes, jlong offset) {
4064 return ::pread(fd, buf, nBytes, offset);
4065 }
4066
4067 // TODO-FIXME: reconcile Solaris' os::sleep with the linux variation.
4068 // Solaris uses poll(), linux uses park().
4069 // Poll() is likely a better choice, assuming that Thread.interrupt()
4070 // generates a SIGUSRx signal. Note that SIGUSR1 can interfere with
4071 // SIGSEGV, see 4355769.
4072
4073 int os::sleep(Thread* thread, jlong millis, bool interruptible) {
4074 assert(thread == Thread::current(), "thread consistency check");
4075
4076 ParkEvent * const slp = thread->_SleepEvent ;
4077 slp->reset() ;
4078 OrderAccess::fence() ;
4079
4080 if (interruptible) {
4081 jlong prevtime = javaTimeNanos();
4082
4083 for (;;) {
4084 if (os::is_interrupted(thread, true)) {
4085 return OS_INTRPT;
4086 }
|