author | coleenp |
Mon, 11 Mar 2013 14:00:09 -0400 | |
changeset 15932 | a27c3d066552 |
parent 15927 | f256c20146f4 |
child 16438 | 245d5c0a8dd8 |
child 16605 | ba13efd453bc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
2 |
* Copyright (c) 1999, 2013, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5532
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5532
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5532
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
24 |
||
7397 | 25 |
// no precompiled headers |
26 |
#include "classfile/classLoader.hpp" |
|
27 |
#include "classfile/systemDictionary.hpp" |
|
28 |
#include "classfile/vmSymbols.hpp" |
|
29 |
#include "code/icBuffer.hpp" |
|
30 |
#include "code/vtableStubs.hpp" |
|
31 |
#include "compiler/compileBroker.hpp" |
|
14626
0cf4eccf130f
8003240: x86: move MacroAssembler into separate file
twisti
parents:
14471
diff
changeset
|
32 |
#include "compiler/disassembler.hpp" |
7397 | 33 |
#include "interpreter/interpreter.hpp" |
34 |
#include "jvm_linux.h" |
|
35 |
#include "memory/allocation.inline.hpp" |
|
36 |
#include "memory/filemap.hpp" |
|
37 |
#include "mutex_linux.inline.hpp" |
|
38 |
#include "oops/oop.inline.hpp" |
|
39 |
#include "os_share_linux.hpp" |
|
40 |
#include "prims/jniFastGetField.hpp" |
|
41 |
#include "prims/jvm.h" |
|
42 |
#include "prims/jvm_misc.hpp" |
|
43 |
#include "runtime/arguments.hpp" |
|
44 |
#include "runtime/extendedPC.hpp" |
|
45 |
#include "runtime/globals.hpp" |
|
46 |
#include "runtime/interfaceSupport.hpp" |
|
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
47 |
#include "runtime/init.hpp" |
7397 | 48 |
#include "runtime/java.hpp" |
49 |
#include "runtime/javaCalls.hpp" |
|
50 |
#include "runtime/mutexLocker.hpp" |
|
51 |
#include "runtime/objectMonitor.hpp" |
|
52 |
#include "runtime/osThread.hpp" |
|
53 |
#include "runtime/perfMemory.hpp" |
|
54 |
#include "runtime/sharedRuntime.hpp" |
|
55 |
#include "runtime/statSampler.hpp" |
|
56 |
#include "runtime/stubRoutines.hpp" |
|
14583
d70ee55535f4
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
14471
diff
changeset
|
57 |
#include "runtime/thread.inline.hpp" |
7397 | 58 |
#include "runtime/threadCritical.hpp" |
59 |
#include "runtime/timer.hpp" |
|
60 |
#include "services/attachListener.hpp" |
|
15927
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
61 |
#include "services/memTracker.hpp" |
7397 | 62 |
#include "services/runtimeService.hpp" |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
63 |
#include "utilities/decoder.hpp" |
7397 | 64 |
#include "utilities/defaultStream.hpp" |
65 |
#include "utilities/events.hpp" |
|
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
66 |
#include "utilities/elfFile.hpp" |
7397 | 67 |
#include "utilities/growableArray.hpp" |
68 |
#include "utilities/vmError.hpp" |
|
1 | 69 |
|
70 |
// put OS-includes here |
|
71 |
# include <sys/types.h> |
|
72 |
# include <sys/mman.h> |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
73 |
# include <sys/stat.h> |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
74 |
# include <sys/select.h> |
1 | 75 |
# include <pthread.h> |
76 |
# include <signal.h> |
|
77 |
# include <errno.h> |
|
78 |
# include <dlfcn.h> |
|
79 |
# include <stdio.h> |
|
80 |
# include <unistd.h> |
|
81 |
# include <sys/resource.h> |
|
82 |
# include <pthread.h> |
|
83 |
# include <sys/stat.h> |
|
84 |
# include <sys/time.h> |
|
85 |
# include <sys/times.h> |
|
86 |
# include <sys/utsname.h> |
|
87 |
# include <sys/socket.h> |
|
88 |
# include <sys/wait.h> |
|
89 |
# include <pwd.h> |
|
90 |
# include <poll.h> |
|
91 |
# include <semaphore.h> |
|
92 |
# include <fcntl.h> |
|
93 |
# include <string.h> |
|
94 |
# include <syscall.h> |
|
95 |
# include <sys/sysinfo.h> |
|
96 |
# include <gnu/libc-version.h> |
|
97 |
# include <sys/ipc.h> |
|
98 |
# include <sys/shm.h> |
|
99 |
# include <link.h> |
|
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
100 |
# include <stdint.h> |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
101 |
# include <inttypes.h> |
7458
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
102 |
# include <sys/ioctl.h> |
1 | 103 |
|
104 |
#define MAX_PATH (2 * K) |
|
105 |
||
106 |
// for timer info max values which include all bits |
|
107 |
#define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) |
|
108 |
||
8119
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
109 |
#define LARGEPAGES_BIT (1 << 6) |
1 | 110 |
//////////////////////////////////////////////////////////////////////////////// |
111 |
// global variables |
|
112 |
julong os::Linux::_physical_memory = 0; |
|
113 |
||
114 |
address os::Linux::_initial_thread_stack_bottom = NULL; |
|
115 |
uintptr_t os::Linux::_initial_thread_stack_size = 0; |
|
116 |
||
117 |
int (*os::Linux::_clock_gettime)(clockid_t, struct timespec *) = NULL; |
|
118 |
int (*os::Linux::_pthread_getcpuclockid)(pthread_t, clockid_t *) = NULL; |
|
119 |
Mutex* os::Linux::_createThread_lock = NULL; |
|
120 |
pthread_t os::Linux::_main_thread; |
|
121 |
int os::Linux::_page_size = -1; |
|
122 |
bool os::Linux::_is_floating_stack = false; |
|
123 |
bool os::Linux::_is_NPTL = false; |
|
124 |
bool os::Linux::_supports_fast_thread_cpu_time = false; |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
125 |
const char * os::Linux::_glibc_version = NULL; |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
126 |
const char * os::Linux::_libpthread_version = NULL; |
1 | 127 |
|
128 |
static jlong initial_time_count=0; |
|
129 |
||
130 |
static int clock_tics_per_sec = 100; |
|
131 |
||
132 |
// For diagnostics to print a message once. see run_periodic_checks |
|
133 |
static sigset_t check_signal_done; |
|
134 |
static bool check_signals = true;; |
|
135 |
||
136 |
static pid_t _initial_pid = 0; |
|
137 |
||
138 |
/* Signal number used to suspend/resume a thread */ |
|
139 |
||
140 |
/* do not use any signal number less than SIGSEGV, see 4355769 */ |
|
141 |
static int SR_signum = SIGUSR2; |
|
142 |
sigset_t SR_sigset; |
|
143 |
||
950 | 144 |
/* Used to protect dlsym() calls */ |
145 |
static pthread_mutex_t dl_mutex; |
|
146 |
||
10025
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
147 |
#ifdef JAVASE_EMBEDDED |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
148 |
class MemNotifyThread: public Thread { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
149 |
friend class VMStructs; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
150 |
public: |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
151 |
virtual void run(); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
152 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
153 |
private: |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
154 |
static MemNotifyThread* _memnotify_thread; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
155 |
int _fd; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
156 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
157 |
public: |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
158 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
159 |
// Constructor |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
160 |
MemNotifyThread(int fd); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
161 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
162 |
// Tester |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
163 |
bool is_memnotify_thread() const { return true; } |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
164 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
165 |
// Printing |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
166 |
char* name() const { return (char*)"Linux MemNotify Thread"; } |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
167 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
168 |
// Returns the single instance of the MemNotifyThread |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
169 |
static MemNotifyThread* memnotify_thread() { return _memnotify_thread; } |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
170 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
171 |
// Create and start the single instance of MemNotifyThread |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
172 |
static void start(); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
173 |
}; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
174 |
#endif // JAVASE_EMBEDDED |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
175 |
|
1 | 176 |
// utility functions |
177 |
||
178 |
static int SR_initialize(); |
|
179 |
static int SR_finalize(); |
|
180 |
||
181 |
julong os::available_memory() { |
|
182 |
return Linux::available_memory(); |
|
183 |
} |
|
184 |
||
185 |
julong os::Linux::available_memory() { |
|
186 |
// values in struct sysinfo are "unsigned long" |
|
187 |
struct sysinfo si; |
|
188 |
sysinfo(&si); |
|
189 |
||
190 |
return (julong)si.freeram * si.mem_unit; |
|
191 |
} |
|
192 |
||
193 |
julong os::physical_memory() { |
|
194 |
return Linux::physical_memory(); |
|
195 |
} |
|
196 |
||
193
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
197 |
julong os::allocatable_physical_memory(julong size) { |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
198 |
#ifdef _LP64 |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
199 |
return size; |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
200 |
#else |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
201 |
julong result = MIN2(size, (julong)3800*M); |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
202 |
if (!is_allocatable(result)) { |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
203 |
// See comments under solaris for alignment considerations |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
204 |
julong reasonable_size = (julong)2*G - 2 * os::vm_page_size(); |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
205 |
result = MIN2(size, reasonable_size); |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
206 |
} |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
207 |
return result; |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
208 |
#endif // _LP64 |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
209 |
} |
171c404abf72
6629887: 64-bit windows should not restrict default heap size to 1400m
phh
parents:
1
diff
changeset
|
210 |
|
1 | 211 |
//////////////////////////////////////////////////////////////////////////////// |
212 |
// environment support |
|
213 |
||
214 |
bool os::getenv(const char* name, char* buf, int len) { |
|
215 |
const char* val = ::getenv(name); |
|
216 |
if (val != NULL && strlen(val) < (size_t)len) { |
|
217 |
strcpy(buf, val); |
|
218 |
return true; |
|
219 |
} |
|
220 |
if (len > 0) buf[0] = 0; // return a null string |
|
221 |
return false; |
|
222 |
} |
|
223 |
||
224 |
||
225 |
// Return true if user is running as root. |
|
226 |
||
227 |
bool os::have_special_privileges() { |
|
228 |
static bool init = false; |
|
229 |
static bool privileges = false; |
|
230 |
if (!init) { |
|
231 |
privileges = (getuid() != geteuid()) || (getgid() != getegid()); |
|
232 |
init = true; |
|
233 |
} |
|
234 |
return privileges; |
|
235 |
} |
|
236 |
||
237 |
||
238 |
#ifndef SYS_gettid |
|
239 |
// i386: 224, ia64: 1105, amd64: 186, sparc 143 |
|
240 |
#ifdef __ia64__ |
|
241 |
#define SYS_gettid 1105 |
|
242 |
#elif __i386__ |
|
243 |
#define SYS_gettid 224 |
|
244 |
#elif __amd64__ |
|
245 |
#define SYS_gettid 186 |
|
246 |
#elif __sparc__ |
|
247 |
#define SYS_gettid 143 |
|
248 |
#else |
|
249 |
#error define gettid for the arch |
|
250 |
#endif |
|
251 |
#endif |
|
252 |
||
253 |
// Cpu architecture string |
|
4013 | 254 |
#if defined(ZERO) |
255 |
static char cpu_arch[] = ZERO_LIBARCH; |
|
256 |
#elif defined(IA64) |
|
1 | 257 |
static char cpu_arch[] = "ia64"; |
258 |
#elif defined(IA32) |
|
259 |
static char cpu_arch[] = "i386"; |
|
260 |
#elif defined(AMD64) |
|
261 |
static char cpu_arch[] = "amd64"; |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
262 |
#elif defined(ARM) |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
263 |
static char cpu_arch[] = "arm"; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
264 |
#elif defined(PPC) |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
265 |
static char cpu_arch[] = "ppc"; |
1 | 266 |
#elif defined(SPARC) |
267 |
# ifdef _LP64 |
|
268 |
static char cpu_arch[] = "sparcv9"; |
|
269 |
# else |
|
270 |
static char cpu_arch[] = "sparc"; |
|
271 |
# endif |
|
272 |
#else |
|
273 |
#error Add appropriate cpu_arch setting |
|
274 |
#endif |
|
275 |
||
276 |
||
277 |
// pid_t gettid() |
|
278 |
// |
|
279 |
// Returns the kernel thread id of the currently running thread. Kernel |
|
280 |
// thread id is used to access /proc. |
|
281 |
// |
|
282 |
// (Note that getpid() on LinuxThreads returns kernel thread id too; but |
|
283 |
// on NPTL, it returns the same pid for all threads, as required by POSIX.) |
|
284 |
// |
|
285 |
pid_t os::Linux::gettid() { |
|
286 |
int rslt = syscall(SYS_gettid); |
|
287 |
if (rslt == -1) { |
|
288 |
// old kernel, no NPTL support |
|
289 |
return getpid(); |
|
290 |
} else { |
|
291 |
return (pid_t)rslt; |
|
292 |
} |
|
293 |
} |
|
294 |
||
295 |
// Most versions of linux have a bug where the number of processors are |
|
296 |
// determined by looking at the /proc file system. In a chroot environment, |
|
297 |
// the system call returns 1. This causes the VM to act as if it is |
|
298 |
// a single processor and elide locking (see is_MP() call). |
|
299 |
static bool unsafe_chroot_detected = false; |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
300 |
static const char *unstable_chroot_error = "/proc file system not found.\n" |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
301 |
"Java may be unstable running multithreaded in a chroot " |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
302 |
"environment on Linux when /proc filesystem is not mounted."; |
1 | 303 |
|
304 |
void os::Linux::initialize_system_info() { |
|
4493
9204129f065e
6843629: Make current hotspot build part of jdk5 control build
phh
parents:
4487
diff
changeset
|
305 |
set_processor_count(sysconf(_SC_NPROCESSORS_CONF)); |
9204129f065e
6843629: Make current hotspot build part of jdk5 control build
phh
parents:
4487
diff
changeset
|
306 |
if (processor_count() == 1) { |
1 | 307 |
pid_t pid = os::Linux::gettid(); |
308 |
char fname[32]; |
|
309 |
jio_snprintf(fname, sizeof(fname), "/proc/%d", pid); |
|
310 |
FILE *fp = fopen(fname, "r"); |
|
311 |
if (fp == NULL) { |
|
312 |
unsafe_chroot_detected = true; |
|
313 |
} else { |
|
314 |
fclose(fp); |
|
315 |
} |
|
316 |
} |
|
317 |
_physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE); |
|
4493
9204129f065e
6843629: Make current hotspot build part of jdk5 control build
phh
parents:
4487
diff
changeset
|
318 |
assert(processor_count() > 0, "linux error"); |
1 | 319 |
} |
320 |
||
321 |
void os::init_system_properties_values() { |
|
322 |
// char arch[12]; |
|
323 |
// sysinfo(SI_ARCHITECTURE, arch, sizeof(arch)); |
|
324 |
||
325 |
// The next steps are taken in the product version: |
|
326 |
// |
|
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
327 |
// Obtain the JAVA_HOME value from the location of libjvm.so. |
1 | 328 |
// This library should be located at: |
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
329 |
// <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm.so. |
1 | 330 |
// |
331 |
// If "/jre/lib/" appears at the right place in the path, then we |
|
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
332 |
// assume libjvm.so is installed in a JDK and we use this path. |
1 | 333 |
// |
334 |
// Otherwise exit with message: "Could not create the Java virtual machine." |
|
335 |
// |
|
336 |
// The following extra steps are taken in the debugging version: |
|
337 |
// |
|
338 |
// If "/jre/lib/" does NOT appear at the right place in the path |
|
339 |
// instead of exit check for $JAVA_HOME environment variable. |
|
340 |
// |
|
341 |
// If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>, |
|
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
342 |
// then we append a fake suffix "hotspot/libjvm.so" to this path so |
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
343 |
// it looks like libjvm.so is installed there |
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
344 |
// <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm.so. |
1 | 345 |
// |
346 |
// Otherwise exit. |
|
347 |
// |
|
348 |
// Important note: if the location of libjvm.so changes this |
|
349 |
// code needs to be changed accordingly. |
|
350 |
||
351 |
// The next few definitions allow the code to be verbatim: |
|
13195 | 352 |
#define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n), mtInternal) |
1 | 353 |
#define getenv(n) ::getenv(n) |
354 |
||
355 |
/* |
|
356 |
* See ld(1): |
|
357 |
* The linker uses the following search paths to locate required |
|
358 |
* shared libraries: |
|
359 |
* 1: ... |
|
360 |
* ... |
|
361 |
* 7: The default directories, normally /lib and /usr/lib. |
|
362 |
*/ |
|
1885
ae1dcaf4363f
6778662: fixes 64-bits libraries directory search paths on linux
kvn
parents:
1664
diff
changeset
|
363 |
#if defined(AMD64) || defined(_LP64) && (defined(SPARC) || defined(PPC) || defined(S390)) |
ae1dcaf4363f
6778662: fixes 64-bits libraries directory search paths on linux
kvn
parents:
1664
diff
changeset
|
364 |
#define DEFAULT_LIBPATH "/usr/lib64:/lib64:/lib:/usr/lib" |
ae1dcaf4363f
6778662: fixes 64-bits libraries directory search paths on linux
kvn
parents:
1664
diff
changeset
|
365 |
#else |
1 | 366 |
#define DEFAULT_LIBPATH "/lib:/usr/lib" |
1885
ae1dcaf4363f
6778662: fixes 64-bits libraries directory search paths on linux
kvn
parents:
1664
diff
changeset
|
367 |
#endif |
1 | 368 |
|
369 |
#define EXTENSIONS_DIR "/lib/ext" |
|
370 |
#define ENDORSED_DIR "/lib/endorsed" |
|
371 |
#define REG_DIR "/usr/java/packages" |
|
372 |
||
373 |
{ |
|
374 |
/* sysclasspath, java_home, dll_dir */ |
|
375 |
{ |
|
376 |
char *home_path; |
|
377 |
char *dll_path; |
|
378 |
char *pslash; |
|
379 |
char buf[MAXPATHLEN]; |
|
380 |
os::jvm_path(buf, sizeof(buf)); |
|
381 |
||
382 |
// Found the full path to libjvm.so. |
|
383 |
// Now cut the path to <java_home>/jre if we can. |
|
384 |
*(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ |
|
385 |
pslash = strrchr(buf, '/'); |
|
386 |
if (pslash != NULL) |
|
387 |
*pslash = '\0'; /* get rid of /{client|server|hotspot} */ |
|
388 |
dll_path = malloc(strlen(buf) + 1); |
|
389 |
if (dll_path == NULL) |
|
390 |
return; |
|
391 |
strcpy(dll_path, buf); |
|
392 |
Arguments::set_dll_dir(dll_path); |
|
393 |
||
394 |
if (pslash != NULL) { |
|
395 |
pslash = strrchr(buf, '/'); |
|
396 |
if (pslash != NULL) { |
|
397 |
*pslash = '\0'; /* get rid of /<arch> */ |
|
398 |
pslash = strrchr(buf, '/'); |
|
399 |
if (pslash != NULL) |
|
400 |
*pslash = '\0'; /* get rid of /lib */ |
|
401 |
} |
|
402 |
} |
|
403 |
||
404 |
home_path = malloc(strlen(buf) + 1); |
|
405 |
if (home_path == NULL) |
|
406 |
return; |
|
407 |
strcpy(home_path, buf); |
|
408 |
Arguments::set_java_home(home_path); |
|
409 |
||
410 |
if (!set_boot_path('/', ':')) |
|
411 |
return; |
|
412 |
} |
|
413 |
||
414 |
/* |
|
415 |
* Where to look for native libraries |
|
416 |
* |
|
417 |
* Note: Due to a legacy implementation, most of the library path |
|
418 |
* is set in the launcher. This was to accomodate linking restrictions |
|
419 |
* on legacy Linux implementations (which are no longer supported). |
|
420 |
* Eventually, all the library path setting will be done here. |
|
421 |
* |
|
422 |
* However, to prevent the proliferation of improperly built native |
|
423 |
* libraries, the new path component /usr/java/packages is added here. |
|
424 |
* Eventually, all the library path setting will be done here. |
|
425 |
*/ |
|
426 |
{ |
|
427 |
char *ld_library_path; |
|
428 |
||
429 |
/* |
|
430 |
* Construct the invariant part of ld_library_path. Note that the |
|
431 |
* space for the colon and the trailing null are provided by the |
|
432 |
* nulls included by the sizeof operator (so actually we allocate |
|
433 |
* a byte more than necessary). |
|
434 |
*/ |
|
435 |
ld_library_path = (char *) malloc(sizeof(REG_DIR) + sizeof("/lib/") + |
|
436 |
strlen(cpu_arch) + sizeof(DEFAULT_LIBPATH)); |
|
437 |
sprintf(ld_library_path, REG_DIR "/lib/%s:" DEFAULT_LIBPATH, cpu_arch); |
|
438 |
||
439 |
/* |
|
440 |
* Get the user setting of LD_LIBRARY_PATH, and prepended it. It |
|
441 |
* should always exist (until the legacy problem cited above is |
|
442 |
* addressed). |
|
443 |
*/ |
|
444 |
char *v = getenv("LD_LIBRARY_PATH"); |
|
445 |
if (v != NULL) { |
|
446 |
char *t = ld_library_path; |
|
447 |
/* That's +1 for the colon and +1 for the trailing '\0' */ |
|
448 |
ld_library_path = (char *) malloc(strlen(v) + 1 + strlen(t) + 1); |
|
449 |
sprintf(ld_library_path, "%s:%s", v, t); |
|
450 |
} |
|
451 |
Arguments::set_library_path(ld_library_path); |
|
452 |
} |
|
453 |
||
454 |
/* |
|
455 |
* Extensions directories. |
|
456 |
* |
|
457 |
* Note that the space for the colon and the trailing null are provided |
|
458 |
* by the nulls included by the sizeof operator (so actually one byte more |
|
459 |
* than necessary is allocated). |
|
460 |
*/ |
|
461 |
{ |
|
462 |
char *buf = malloc(strlen(Arguments::get_java_home()) + |
|
463 |
sizeof(EXTENSIONS_DIR) + sizeof(REG_DIR) + sizeof(EXTENSIONS_DIR)); |
|
464 |
sprintf(buf, "%s" EXTENSIONS_DIR ":" REG_DIR EXTENSIONS_DIR, |
|
465 |
Arguments::get_java_home()); |
|
466 |
Arguments::set_ext_dirs(buf); |
|
467 |
} |
|
468 |
||
469 |
/* Endorsed standards default directory. */ |
|
470 |
{ |
|
471 |
char * buf; |
|
472 |
buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR)); |
|
473 |
sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); |
|
474 |
Arguments::set_endorsed_dirs(buf); |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
#undef malloc |
|
479 |
#undef getenv |
|
480 |
#undef EXTENSIONS_DIR |
|
481 |
#undef ENDORSED_DIR |
|
482 |
||
483 |
// Done |
|
484 |
return; |
|
485 |
} |
|
486 |
||
487 |
//////////////////////////////////////////////////////////////////////////////// |
|
488 |
// breakpoint support |
|
489 |
||
490 |
void os::breakpoint() { |
|
491 |
BREAKPOINT; |
|
492 |
} |
|
493 |
||
494 |
extern "C" void breakpoint() { |
|
495 |
// use debugger to set breakpoint here |
|
496 |
} |
|
497 |
||
498 |
//////////////////////////////////////////////////////////////////////////////// |
|
499 |
// signal support |
|
500 |
||
501 |
debug_only(static bool signal_sets_initialized = false); |
|
502 |
static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs; |
|
503 |
||
504 |
bool os::Linux::is_sig_ignored(int sig) { |
|
505 |
struct sigaction oact; |
|
506 |
sigaction(sig, (struct sigaction*)NULL, &oact); |
|
507 |
void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) |
|
508 |
: CAST_FROM_FN_PTR(void*, oact.sa_handler); |
|
509 |
if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) |
|
510 |
return true; |
|
511 |
else |
|
512 |
return false; |
|
513 |
} |
|
514 |
||
515 |
void os::Linux::signal_sets_init() { |
|
516 |
// Should also have an assertion stating we are still single-threaded. |
|
517 |
assert(!signal_sets_initialized, "Already initialized"); |
|
518 |
// Fill in signals that are necessarily unblocked for all threads in |
|
519 |
// the VM. Currently, we unblock the following signals: |
|
520 |
// SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden |
|
521 |
// by -Xrs (=ReduceSignalUsage)); |
|
522 |
// BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all |
|
523 |
// other threads. The "ReduceSignalUsage" boolean tells us not to alter |
|
524 |
// the dispositions or masks wrt these signals. |
|
525 |
// Programs embedding the VM that want to use the above signals for their |
|
526 |
// own purposes must, at this time, use the "-Xrs" option to prevent |
|
527 |
// interference with shutdown hooks and BREAK_SIGNAL thread dumping. |
|
528 |
// (See bug 4345157, and other related bugs). |
|
529 |
// In reality, though, unblocking these signals is really a nop, since |
|
530 |
// these signals are not blocked by default. |
|
531 |
sigemptyset(&unblocked_sigs); |
|
532 |
sigemptyset(&allowdebug_blocked_sigs); |
|
533 |
sigaddset(&unblocked_sigs, SIGILL); |
|
534 |
sigaddset(&unblocked_sigs, SIGSEGV); |
|
535 |
sigaddset(&unblocked_sigs, SIGBUS); |
|
536 |
sigaddset(&unblocked_sigs, SIGFPE); |
|
537 |
sigaddset(&unblocked_sigs, SR_signum); |
|
538 |
||
539 |
if (!ReduceSignalUsage) { |
|
540 |
if (!os::Linux::is_sig_ignored(SHUTDOWN1_SIGNAL)) { |
|
541 |
sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL); |
|
542 |
sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL); |
|
543 |
} |
|
544 |
if (!os::Linux::is_sig_ignored(SHUTDOWN2_SIGNAL)) { |
|
545 |
sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL); |
|
546 |
sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL); |
|
547 |
} |
|
548 |
if (!os::Linux::is_sig_ignored(SHUTDOWN3_SIGNAL)) { |
|
549 |
sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL); |
|
550 |
sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL); |
|
551 |
} |
|
552 |
} |
|
553 |
// Fill in signals that are blocked by all but the VM thread. |
|
554 |
sigemptyset(&vm_sigs); |
|
555 |
if (!ReduceSignalUsage) |
|
556 |
sigaddset(&vm_sigs, BREAK_SIGNAL); |
|
557 |
debug_only(signal_sets_initialized = true); |
|
558 |
||
559 |
} |
|
560 |
||
561 |
// These are signals that are unblocked while a thread is running Java. |
|
562 |
// (For some reason, they get blocked by default.) |
|
563 |
sigset_t* os::Linux::unblocked_signals() { |
|
564 |
assert(signal_sets_initialized, "Not initialized"); |
|
565 |
return &unblocked_sigs; |
|
566 |
} |
|
567 |
||
568 |
// These are the signals that are blocked while a (non-VM) thread is |
|
569 |
// running Java. Only the VM thread handles these signals. |
|
570 |
sigset_t* os::Linux::vm_signals() { |
|
571 |
assert(signal_sets_initialized, "Not initialized"); |
|
572 |
return &vm_sigs; |
|
573 |
} |
|
574 |
||
575 |
// These are signals that are blocked during cond_wait to allow debugger in |
|
576 |
sigset_t* os::Linux::allowdebug_blocked_signals() { |
|
577 |
assert(signal_sets_initialized, "Not initialized"); |
|
578 |
return &allowdebug_blocked_sigs; |
|
579 |
} |
|
580 |
||
581 |
void os::Linux::hotspot_sigmask(Thread* thread) { |
|
582 |
||
583 |
//Save caller's signal mask before setting VM signal mask |
|
584 |
sigset_t caller_sigmask; |
|
585 |
pthread_sigmask(SIG_BLOCK, NULL, &caller_sigmask); |
|
586 |
||
587 |
OSThread* osthread = thread->osthread(); |
|
588 |
osthread->set_caller_sigmask(caller_sigmask); |
|
589 |
||
590 |
pthread_sigmask(SIG_UNBLOCK, os::Linux::unblocked_signals(), NULL); |
|
591 |
||
592 |
if (!ReduceSignalUsage) { |
|
593 |
if (thread->is_VM_thread()) { |
|
594 |
// Only the VM thread handles BREAK_SIGNAL ... |
|
595 |
pthread_sigmask(SIG_UNBLOCK, vm_signals(), NULL); |
|
596 |
} else { |
|
597 |
// ... all other threads block BREAK_SIGNAL |
|
598 |
pthread_sigmask(SIG_BLOCK, vm_signals(), NULL); |
|
599 |
} |
|
600 |
} |
|
601 |
} |
|
602 |
||
603 |
////////////////////////////////////////////////////////////////////////////// |
|
604 |
// detecting pthread library |
|
605 |
||
606 |
void os::Linux::libpthread_init() { |
|
607 |
// Save glibc and pthread version strings. Note that _CS_GNU_LIBC_VERSION |
|
608 |
// and _CS_GNU_LIBPTHREAD_VERSION are supported in glibc >= 2.3.2. Use a |
|
609 |
// generic name for earlier versions. |
|
610 |
// Define macros here so we can build HotSpot on old systems. |
|
611 |
# ifndef _CS_GNU_LIBC_VERSION |
|
612 |
# define _CS_GNU_LIBC_VERSION 2 |
|
613 |
# endif |
|
614 |
# ifndef _CS_GNU_LIBPTHREAD_VERSION |
|
615 |
# define _CS_GNU_LIBPTHREAD_VERSION 3 |
|
616 |
# endif |
|
617 |
||
618 |
size_t n = confstr(_CS_GNU_LIBC_VERSION, NULL, 0); |
|
619 |
if (n > 0) { |
|
13195 | 620 |
char *str = (char *)malloc(n, mtInternal); |
1 | 621 |
confstr(_CS_GNU_LIBC_VERSION, str, n); |
622 |
os::Linux::set_glibc_version(str); |
|
623 |
} else { |
|
624 |
// _CS_GNU_LIBC_VERSION is not supported, try gnu_get_libc_version() |
|
625 |
static char _gnu_libc_version[32]; |
|
626 |
jio_snprintf(_gnu_libc_version, sizeof(_gnu_libc_version), |
|
627 |
"glibc %s %s", gnu_get_libc_version(), gnu_get_libc_release()); |
|
628 |
os::Linux::set_glibc_version(_gnu_libc_version); |
|
629 |
} |
|
630 |
||
631 |
n = confstr(_CS_GNU_LIBPTHREAD_VERSION, NULL, 0); |
|
632 |
if (n > 0) { |
|
13195 | 633 |
char *str = (char *)malloc(n, mtInternal); |
1 | 634 |
confstr(_CS_GNU_LIBPTHREAD_VERSION, str, n); |
635 |
// Vanilla RH-9 (glibc 2.3.2) has a bug that confstr() always tells |
|
636 |
// us "NPTL-0.29" even we are running with LinuxThreads. Check if this |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
637 |
// is the case. LinuxThreads has a hard limit on max number of threads. |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
638 |
// So sysconf(_SC_THREAD_THREADS_MAX) will return a positive value. |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
639 |
// On the other hand, NPTL does not have such a limit, sysconf() |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
640 |
// will return -1 and errno is not changed. Check if it is really NPTL. |
1 | 641 |
if (strcmp(os::Linux::glibc_version(), "glibc 2.3.2") == 0 && |
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
642 |
strstr(str, "NPTL") && |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
643 |
sysconf(_SC_THREAD_THREADS_MAX) > 0) { |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
644 |
free(str); |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
645 |
os::Linux::set_libpthread_version("linuxthreads"); |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
646 |
} else { |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
647 |
os::Linux::set_libpthread_version(str); |
1 | 648 |
} |
649 |
} else { |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
650 |
// glibc before 2.3.2 only has LinuxThreads. |
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
651 |
os::Linux::set_libpthread_version("linuxthreads"); |
1 | 652 |
} |
653 |
||
654 |
if (strstr(libpthread_version(), "NPTL")) { |
|
655 |
os::Linux::set_is_NPTL(); |
|
656 |
} else { |
|
657 |
os::Linux::set_is_LinuxThreads(); |
|
658 |
} |
|
659 |
||
660 |
// LinuxThreads have two flavors: floating-stack mode, which allows variable |
|
661 |
// stack size; and fixed-stack mode. NPTL is always floating-stack. |
|
662 |
if (os::Linux::is_NPTL() || os::Linux::supports_variable_stack_size()) { |
|
663 |
os::Linux::set_is_floating_stack(); |
|
664 |
} |
|
665 |
} |
|
666 |
||
667 |
///////////////////////////////////////////////////////////////////////////// |
|
668 |
// thread stack |
|
669 |
||
670 |
// Force Linux kernel to expand current thread stack. If "bottom" is close |
|
671 |
// to the stack guard, caller should block all signals. |
|
672 |
// |
|
673 |
// MAP_GROWSDOWN: |
|
674 |
// A special mmap() flag that is used to implement thread stacks. It tells |
|
675 |
// kernel that the memory region should extend downwards when needed. This |
|
676 |
// allows early versions of LinuxThreads to only mmap the first few pages |
|
677 |
// when creating a new thread. Linux kernel will automatically expand thread |
|
678 |
// stack as needed (on page faults). |
|
679 |
// |
|
680 |
// However, because the memory region of a MAP_GROWSDOWN stack can grow on |
|
681 |
// demand, if a page fault happens outside an already mapped MAP_GROWSDOWN |
|
682 |
// region, it's hard to tell if the fault is due to a legitimate stack |
|
683 |
// access or because of reading/writing non-exist memory (e.g. buffer |
|
684 |
// overrun). As a rule, if the fault happens below current stack pointer, |
|
685 |
// Linux kernel does not expand stack, instead a SIGSEGV is sent to the |
|
686 |
// application (see Linux kernel fault.c). |
|
687 |
// |
|
688 |
// This Linux feature can cause SIGSEGV when VM bangs thread stack for |
|
689 |
// stack overflow detection. |
|
690 |
// |
|
691 |
// Newer version of LinuxThreads (since glibc-2.2, or, RH-7.x) and NPTL do |
|
692 |
// not use this flag. However, the stack of initial thread is not created |
|
693 |
// by pthread, it is still MAP_GROWSDOWN. Also it's possible (though |
|
694 |
// unlikely) that user code can create a thread with MAP_GROWSDOWN stack |
|
695 |
// and then attach the thread to JVM. |
|
696 |
// |
|
697 |
// To get around the problem and allow stack banging on Linux, we need to |
|
698 |
// manually expand thread stack after receiving the SIGSEGV. |
|
699 |
// |
|
700 |
// There are two ways to expand thread stack to address "bottom", we used |
|
701 |
// both of them in JVM before 1.5: |
|
702 |
// 1. adjust stack pointer first so that it is below "bottom", and then |
|
703 |
// touch "bottom" |
|
704 |
// 2. mmap() the page in question |
|
705 |
// |
|
706 |
// Now alternate signal stack is gone, it's harder to use 2. For instance, |
|
707 |
// if current sp is already near the lower end of page 101, and we need to |
|
708 |
// call mmap() to map page 100, it is possible that part of the mmap() frame |
|
709 |
// will be placed in page 100. When page 100 is mapped, it is zero-filled. |
|
710 |
// That will destroy the mmap() frame and cause VM to crash. |
|
711 |
// |
|
712 |
// The following code works by adjusting sp first, then accessing the "bottom" |
|
713 |
// page to force a page fault. Linux kernel will then automatically expand the |
|
714 |
// stack mapping. |
|
715 |
// |
|
716 |
// _expand_stack_to() assumes its frame size is less than page size, which |
|
717 |
// should always be true if the function is not inlined. |
|
718 |
||
719 |
#if __GNUC__ < 3 // gcc 2.x does not support noinline attribute |
|
720 |
#define NOINLINE |
|
721 |
#else |
|
722 |
#define NOINLINE __attribute__ ((noinline)) |
|
723 |
#endif |
|
724 |
||
725 |
static void _expand_stack_to(address bottom) NOINLINE; |
|
726 |
||
727 |
static void _expand_stack_to(address bottom) { |
|
728 |
address sp; |
|
729 |
size_t size; |
|
730 |
volatile char *p; |
|
731 |
||
732 |
// Adjust bottom to point to the largest address within the same page, it |
|
733 |
// gives us a one-page buffer if alloca() allocates slightly more memory. |
|
734 |
bottom = (address)align_size_down((uintptr_t)bottom, os::Linux::page_size()); |
|
735 |
bottom += os::Linux::page_size() - 1; |
|
736 |
||
737 |
// sp might be slightly above current stack pointer; if that's the case, we |
|
738 |
// will alloca() a little more space than necessary, which is OK. Don't use |
|
739 |
// os::current_stack_pointer(), as its result can be slightly below current |
|
740 |
// stack pointer, causing us to not alloca enough to reach "bottom". |
|
741 |
sp = (address)&sp; |
|
742 |
||
743 |
if (sp > bottom) { |
|
744 |
size = sp - bottom; |
|
745 |
p = (volatile char *)alloca(size); |
|
746 |
assert(p != NULL && p <= (volatile char *)bottom, "alloca problem?"); |
|
747 |
p[0] = '\0'; |
|
748 |
} |
|
749 |
} |
|
750 |
||
751 |
bool os::Linux::manually_expand_stack(JavaThread * t, address addr) { |
|
752 |
assert(t!=NULL, "just checking"); |
|
753 |
assert(t->osthread()->expanding_stack(), "expand should be set"); |
|
754 |
assert(t->stack_base() != NULL, "stack_base was not initialized"); |
|
755 |
||
756 |
if (addr < t->stack_base() && addr >= t->stack_yellow_zone_base()) { |
|
757 |
sigset_t mask_all, old_sigset; |
|
758 |
sigfillset(&mask_all); |
|
759 |
pthread_sigmask(SIG_SETMASK, &mask_all, &old_sigset); |
|
760 |
_expand_stack_to(addr); |
|
761 |
pthread_sigmask(SIG_SETMASK, &old_sigset, NULL); |
|
762 |
return true; |
|
763 |
} |
|
764 |
return false; |
|
765 |
} |
|
766 |
||
767 |
////////////////////////////////////////////////////////////////////////////// |
|
768 |
// create new thread |
|
769 |
||
770 |
static address highest_vm_reserved_address(); |
|
771 |
||
772 |
// check if it's safe to start a new thread |
|
773 |
static bool _thread_safety_check(Thread* thread) { |
|
774 |
if (os::Linux::is_LinuxThreads() && !os::Linux::is_floating_stack()) { |
|
775 |
// Fixed stack LinuxThreads (SuSE Linux/x86, and some versions of Redhat) |
|
776 |
// Heap is mmap'ed at lower end of memory space. Thread stacks are |
|
777 |
// allocated (MAP_FIXED) from high address space. Every thread stack |
|
778 |
// occupies a fixed size slot (usually 2Mbytes, but user can change |
|
779 |
// it to other values if they rebuild LinuxThreads). |
|
780 |
// |
|
781 |
// Problem with MAP_FIXED is that mmap() can still succeed even part of |
|
782 |
// the memory region has already been mmap'ed. That means if we have too |
|
783 |
// many threads and/or very large heap, eventually thread stack will |
|
784 |
// collide with heap. |
|
785 |
// |
|
786 |
// Here we try to prevent heap/stack collision by comparing current |
|
787 |
// stack bottom with the highest address that has been mmap'ed by JVM |
|
788 |
// plus a safety margin for memory maps created by native code. |
|
789 |
// |
|
790 |
// This feature can be disabled by setting ThreadSafetyMargin to 0 |
|
791 |
// |
|
792 |
if (ThreadSafetyMargin > 0) { |
|
793 |
address stack_bottom = os::current_stack_base() - os::current_stack_size(); |
|
794 |
||
795 |
// not safe if our stack extends below the safety margin |
|
796 |
return stack_bottom - ThreadSafetyMargin >= highest_vm_reserved_address(); |
|
797 |
} else { |
|
798 |
return true; |
|
799 |
} |
|
800 |
} else { |
|
801 |
// Floating stack LinuxThreads or NPTL: |
|
802 |
// Unlike fixed stack LinuxThreads, thread stacks are not MAP_FIXED. When |
|
803 |
// there's not enough space left, pthread_create() will fail. If we come |
|
804 |
// here, that means enough space has been reserved for stack. |
|
805 |
return true; |
|
806 |
} |
|
807 |
} |
|
808 |
||
809 |
// Thread start routine for all newly created threads |
|
810 |
static void *java_start(Thread *thread) { |
|
811 |
// Try to randomize the cache line index of hot stack frames. |
|
812 |
// This helps when threads of the same stack traces evict each other's |
|
813 |
// cache lines. The threads can be either from the same JVM instance, or |
|
814 |
// from different JVM instances. The benefit is especially true for |
|
815 |
// processors with hyperthreading technology. |
|
816 |
static int counter = 0; |
|
817 |
int pid = os::current_process_id(); |
|
818 |
alloca(((pid ^ counter++) & 7) * 128); |
|
819 |
||
820 |
ThreadLocalStorage::set_thread(thread); |
|
821 |
||
822 |
OSThread* osthread = thread->osthread(); |
|
823 |
Monitor* sync = osthread->startThread_lock(); |
|
824 |
||
825 |
// non floating stack LinuxThreads needs extra check, see above |
|
826 |
if (!_thread_safety_check(thread)) { |
|
827 |
// notify parent thread |
|
828 |
MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag); |
|
829 |
osthread->set_state(ZOMBIE); |
|
830 |
sync->notify_all(); |
|
831 |
return NULL; |
|
832 |
} |
|
833 |
||
834 |
// thread_id is kernel thread id (similar to Solaris LWP id) |
|
835 |
osthread->set_thread_id(os::Linux::gettid()); |
|
836 |
||
837 |
if (UseNUMA) { |
|
838 |
int lgrp_id = os::numa_get_group_id(); |
|
839 |
if (lgrp_id != -1) { |
|
840 |
thread->set_lgrp_id(lgrp_id); |
|
841 |
} |
|
842 |
} |
|
843 |
// initialize signal mask for this thread |
|
844 |
os::Linux::hotspot_sigmask(thread); |
|
845 |
||
846 |
// initialize floating point control register |
|
847 |
os::Linux::init_thread_fpu_state(); |
|
848 |
||
849 |
// handshaking with parent thread |
|
850 |
{ |
|
851 |
MutexLockerEx ml(sync, Mutex::_no_safepoint_check_flag); |
|
852 |
||
853 |
// notify parent thread |
|
854 |
osthread->set_state(INITIALIZED); |
|
855 |
sync->notify_all(); |
|
856 |
||
857 |
// wait until os::start_thread() |
|
858 |
while (osthread->get_state() == INITIALIZED) { |
|
859 |
sync->wait(Mutex::_no_safepoint_check_flag); |
|
860 |
} |
|
861 |
} |
|
862 |
||
863 |
// call one more level start routine |
|
864 |
thread->run(); |
|
865 |
||
866 |
return 0; |
|
867 |
} |
|
868 |
||
869 |
bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { |
|
870 |
assert(thread->osthread() == NULL, "caller responsible"); |
|
871 |
||
872 |
// Allocate the OSThread object |
|
873 |
OSThread* osthread = new OSThread(NULL, NULL); |
|
874 |
if (osthread == NULL) { |
|
875 |
return false; |
|
876 |
} |
|
877 |
||
878 |
// set the correct thread state |
|
879 |
osthread->set_thread_type(thr_type); |
|
880 |
||
881 |
// Initial state is ALLOCATED but not INITIALIZED |
|
882 |
osthread->set_state(ALLOCATED); |
|
883 |
||
884 |
thread->set_osthread(osthread); |
|
885 |
||
886 |
// init thread attributes |
|
887 |
pthread_attr_t attr; |
|
888 |
pthread_attr_init(&attr); |
|
889 |
pthread_attr_setdetachstate(&attr, PTHREAD_CREATE_DETACHED); |
|
890 |
||
891 |
// stack size |
|
892 |
if (os::Linux::supports_variable_stack_size()) { |
|
893 |
// calculate stack size if it's not specified by caller |
|
894 |
if (stack_size == 0) { |
|
895 |
stack_size = os::Linux::default_stack_size(thr_type); |
|
896 |
||
897 |
switch (thr_type) { |
|
898 |
case os::java_thread: |
|
6964
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
899 |
// Java threads use ThreadStackSize which default value can be |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
900 |
// changed with the flag -Xss |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
901 |
assert (JavaThread::stack_size_at_create() > 0, "this should be set"); |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
902 |
stack_size = JavaThread::stack_size_at_create(); |
1 | 903 |
break; |
904 |
case os::compiler_thread: |
|
905 |
if (CompilerThreadStackSize > 0) { |
|
906 |
stack_size = (size_t)(CompilerThreadStackSize * K); |
|
907 |
break; |
|
908 |
} // else fall through: |
|
909 |
// use VMThreadStackSize if CompilerThreadStackSize is not defined |
|
910 |
case os::vm_thread: |
|
911 |
case os::pgc_thread: |
|
912 |
case os::cgc_thread: |
|
913 |
case os::watcher_thread: |
|
914 |
if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K); |
|
915 |
break; |
|
916 |
} |
|
917 |
} |
|
918 |
||
919 |
stack_size = MAX2(stack_size, os::Linux::min_stack_allowed); |
|
920 |
pthread_attr_setstacksize(&attr, stack_size); |
|
921 |
} else { |
|
922 |
// let pthread_create() pick the default value. |
|
923 |
} |
|
924 |
||
925 |
// glibc guard page |
|
926 |
pthread_attr_setguardsize(&attr, os::Linux::default_guard_size(thr_type)); |
|
927 |
||
928 |
ThreadState state; |
|
929 |
||
930 |
{ |
|
931 |
// Serialize thread creation if we are running with fixed stack LinuxThreads |
|
932 |
bool lock = os::Linux::is_LinuxThreads() && !os::Linux::is_floating_stack(); |
|
933 |
if (lock) { |
|
934 |
os::Linux::createThread_lock()->lock_without_safepoint_check(); |
|
935 |
} |
|
936 |
||
937 |
pthread_t tid; |
|
938 |
int ret = pthread_create(&tid, &attr, (void* (*)(void*)) java_start, thread); |
|
939 |
||
940 |
pthread_attr_destroy(&attr); |
|
941 |
||
942 |
if (ret != 0) { |
|
943 |
if (PrintMiscellaneous && (Verbose || WizardMode)) { |
|
944 |
perror("pthread_create()"); |
|
945 |
} |
|
946 |
// Need to clean up stuff we've allocated so far |
|
947 |
thread->set_osthread(NULL); |
|
948 |
delete osthread; |
|
949 |
if (lock) os::Linux::createThread_lock()->unlock(); |
|
950 |
return false; |
|
951 |
} |
|
952 |
||
953 |
// Store pthread info into the OSThread |
|
954 |
osthread->set_pthread_id(tid); |
|
955 |
||
956 |
// Wait until child thread is either initialized or aborted |
|
957 |
{ |
|
958 |
Monitor* sync_with_child = osthread->startThread_lock(); |
|
959 |
MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag); |
|
960 |
while ((state = osthread->get_state()) == ALLOCATED) { |
|
961 |
sync_with_child->wait(Mutex::_no_safepoint_check_flag); |
|
962 |
} |
|
963 |
} |
|
964 |
||
965 |
if (lock) { |
|
966 |
os::Linux::createThread_lock()->unlock(); |
|
967 |
} |
|
968 |
} |
|
969 |
||
970 |
// Aborted due to thread limit being reached |
|
971 |
if (state == ZOMBIE) { |
|
972 |
thread->set_osthread(NULL); |
|
973 |
delete osthread; |
|
974 |
return false; |
|
975 |
} |
|
976 |
||
977 |
// The thread is returned suspended (in state INITIALIZED), |
|
978 |
// and is started higher up in the call chain |
|
979 |
assert(state == INITIALIZED, "race condition"); |
|
980 |
return true; |
|
981 |
} |
|
982 |
||
983 |
///////////////////////////////////////////////////////////////////////////// |
|
984 |
// attach existing thread |
|
985 |
||
986 |
// bootstrap the main thread |
|
987 |
bool os::create_main_thread(JavaThread* thread) { |
|
988 |
assert(os::Linux::_main_thread == pthread_self(), "should be called inside main thread"); |
|
989 |
return create_attached_thread(thread); |
|
990 |
} |
|
991 |
||
992 |
bool os::create_attached_thread(JavaThread* thread) { |
|
993 |
#ifdef ASSERT |
|
994 |
thread->verify_not_published(); |
|
995 |
#endif |
|
996 |
||
997 |
// Allocate the OSThread object |
|
998 |
OSThread* osthread = new OSThread(NULL, NULL); |
|
999 |
||
1000 |
if (osthread == NULL) { |
|
1001 |
return false; |
|
1002 |
} |
|
1003 |
||
1004 |
// Store pthread info into the OSThread |
|
1005 |
osthread->set_thread_id(os::Linux::gettid()); |
|
1006 |
osthread->set_pthread_id(::pthread_self()); |
|
1007 |
||
1008 |
// initialize floating point control register |
|
1009 |
os::Linux::init_thread_fpu_state(); |
|
1010 |
||
1011 |
// Initial thread state is RUNNABLE |
|
1012 |
osthread->set_state(RUNNABLE); |
|
1013 |
||
1014 |
thread->set_osthread(osthread); |
|
1015 |
||
1016 |
if (UseNUMA) { |
|
1017 |
int lgrp_id = os::numa_get_group_id(); |
|
1018 |
if (lgrp_id != -1) { |
|
1019 |
thread->set_lgrp_id(lgrp_id); |
|
1020 |
} |
|
1021 |
} |
|
1022 |
||
1023 |
if (os::Linux::is_initial_thread()) { |
|
1024 |
// If current thread is initial thread, its stack is mapped on demand, |
|
1025 |
// see notes about MAP_GROWSDOWN. Here we try to force kernel to map |
|
1026 |
// the entire stack region to avoid SEGV in stack banging. |
|
1027 |
// It is also useful to get around the heap-stack-gap problem on SuSE |
|
1028 |
// kernel (see 4821821 for details). We first expand stack to the top |
|
1029 |
// of yellow zone, then enable stack yellow zone (order is significant, |
|
1030 |
// enabling yellow zone first will crash JVM on SuSE Linux), so there |
|
1031 |
// is no gap between the last two virtual memory regions. |
|
1032 |
||
1033 |
JavaThread *jt = (JavaThread *)thread; |
|
1034 |
address addr = jt->stack_yellow_zone_base(); |
|
1035 |
assert(addr != NULL, "initialization problem?"); |
|
1036 |
assert(jt->stack_available(addr) > 0, "stack guard should not be enabled"); |
|
1037 |
||
1038 |
osthread->set_expanding_stack(); |
|
1039 |
os::Linux::manually_expand_stack(jt, addr); |
|
1040 |
osthread->clear_expanding_stack(); |
|
1041 |
} |
|
1042 |
||
1043 |
// initialize signal mask for this thread |
|
1044 |
// and save the caller's signal mask |
|
1045 |
os::Linux::hotspot_sigmask(thread); |
|
1046 |
||
1047 |
return true; |
|
1048 |
} |
|
1049 |
||
1050 |
void os::pd_start_thread(Thread* thread) { |
|
1051 |
OSThread * osthread = thread->osthread(); |
|
1052 |
assert(osthread->get_state() != INITIALIZED, "just checking"); |
|
1053 |
Monitor* sync_with_child = osthread->startThread_lock(); |
|
1054 |
MutexLockerEx ml(sync_with_child, Mutex::_no_safepoint_check_flag); |
|
1055 |
sync_with_child->notify(); |
|
1056 |
} |
|
1057 |
||
1058 |
// Free Linux resources related to the OSThread |
|
1059 |
void os::free_thread(OSThread* osthread) { |
|
1060 |
assert(osthread != NULL, "osthread not set"); |
|
1061 |
||
1062 |
if (Thread::current()->osthread() == osthread) { |
|
1063 |
// Restore caller's signal mask |
|
1064 |
sigset_t sigmask = osthread->caller_sigmask(); |
|
1065 |
pthread_sigmask(SIG_SETMASK, &sigmask, NULL); |
|
1066 |
} |
|
1067 |
||
1068 |
delete osthread; |
|
1069 |
} |
|
1070 |
||
1071 |
////////////////////////////////////////////////////////////////////////////// |
|
1072 |
// thread local storage |
|
1073 |
||
1074 |
int os::allocate_thread_local_storage() { |
|
1075 |
pthread_key_t key; |
|
1076 |
int rslt = pthread_key_create(&key, NULL); |
|
1077 |
assert(rslt == 0, "cannot allocate thread local storage"); |
|
1078 |
return (int)key; |
|
1079 |
} |
|
1080 |
||
1081 |
// Note: This is currently not used by VM, as we don't destroy TLS key |
|
1082 |
// on VM exit. |
|
1083 |
void os::free_thread_local_storage(int index) { |
|
1084 |
int rslt = pthread_key_delete((pthread_key_t)index); |
|
1085 |
assert(rslt == 0, "invalid index"); |
|
1086 |
} |
|
1087 |
||
1088 |
void os::thread_local_storage_at_put(int index, void* value) { |
|
1089 |
int rslt = pthread_setspecific((pthread_key_t)index, value); |
|
1090 |
assert(rslt == 0, "pthread_setspecific failed"); |
|
1091 |
} |
|
1092 |
||
1093 |
extern "C" Thread* get_thread() { |
|
1094 |
return ThreadLocalStorage::thread(); |
|
1095 |
} |
|
1096 |
||
1097 |
////////////////////////////////////////////////////////////////////////////// |
|
1098 |
// initial thread |
|
1099 |
||
1100 |
// Check if current thread is the initial thread, similar to Solaris thr_main. |
|
1101 |
bool os::Linux::is_initial_thread(void) { |
|
1102 |
char dummy; |
|
1103 |
// If called before init complete, thread stack bottom will be null. |
|
1104 |
// Can be called if fatal error occurs before initialization. |
|
1105 |
if (initial_thread_stack_bottom() == NULL) return false; |
|
1106 |
assert(initial_thread_stack_bottom() != NULL && |
|
1107 |
initial_thread_stack_size() != 0, |
|
1108 |
"os::init did not locate initial thread's stack region"); |
|
1109 |
if ((address)&dummy >= initial_thread_stack_bottom() && |
|
1110 |
(address)&dummy < initial_thread_stack_bottom() + initial_thread_stack_size()) |
|
1111 |
return true; |
|
1112 |
else return false; |
|
1113 |
} |
|
1114 |
||
1115 |
// Find the virtual memory area that contains addr |
|
1116 |
static bool find_vma(address addr, address* vma_low, address* vma_high) { |
|
1117 |
FILE *fp = fopen("/proc/self/maps", "r"); |
|
1118 |
if (fp) { |
|
1119 |
address low, high; |
|
1120 |
while (!feof(fp)) { |
|
1121 |
if (fscanf(fp, "%p-%p", &low, &high) == 2) { |
|
1122 |
if (low <= addr && addr < high) { |
|
1123 |
if (vma_low) *vma_low = low; |
|
1124 |
if (vma_high) *vma_high = high; |
|
1125 |
fclose (fp); |
|
1126 |
return true; |
|
1127 |
} |
|
1128 |
} |
|
1129 |
for (;;) { |
|
1130 |
int ch = fgetc(fp); |
|
1131 |
if (ch == EOF || ch == (int)'\n') break; |
|
1132 |
} |
|
1133 |
} |
|
1134 |
fclose(fp); |
|
1135 |
} |
|
1136 |
return false; |
|
1137 |
} |
|
1138 |
||
1139 |
// Locate initial thread stack. This special handling of initial thread stack |
|
1140 |
// is needed because pthread_getattr_np() on most (all?) Linux distros returns |
|
1141 |
// bogus value for initial thread. |
|
1142 |
void os::Linux::capture_initial_stack(size_t max_size) { |
|
1143 |
// stack size is the easy part, get it from RLIMIT_STACK |
|
1144 |
size_t stack_size; |
|
1145 |
struct rlimit rlim; |
|
1146 |
getrlimit(RLIMIT_STACK, &rlim); |
|
1147 |
stack_size = rlim.rlim_cur; |
|
1148 |
||
1149 |
// 6308388: a bug in ld.so will relocate its own .data section to the |
|
1150 |
// lower end of primordial stack; reduce ulimit -s value a little bit |
|
1151 |
// so we won't install guard page on ld.so's data section. |
|
1152 |
stack_size -= 2 * page_size(); |
|
1153 |
||
1154 |
// 4441425: avoid crash with "unlimited" stack size on SuSE 7.1 or Redhat |
|
1155 |
// 7.1, in both cases we will get 2G in return value. |
|
1156 |
// 4466587: glibc 2.2.x compiled w/o "--enable-kernel=2.4.0" (RH 7.0, |
|
1157 |
// SuSE 7.2, Debian) can not handle alternate signal stack correctly |
|
1158 |
// for initial thread if its stack size exceeds 6M. Cap it at 2M, |
|
1159 |
// in case other parts in glibc still assumes 2M max stack size. |
|
1160 |
// FIXME: alt signal stack is gone, maybe we can relax this constraint? |
|
1161 |
// Problem still exists RH7.2 (IA64 anyway) but 2MB is a little small |
|
15475 | 1162 |
if (stack_size > 2 * K * K IA64_ONLY(*2)) |
1163 |
stack_size = 2 * K * K IA64_ONLY(*2); |
|
1 | 1164 |
// Try to figure out where the stack base (top) is. This is harder. |
1165 |
// |
|
1166 |
// When an application is started, glibc saves the initial stack pointer in |
|
1167 |
// a global variable "__libc_stack_end", which is then used by system |
|
1168 |
// libraries. __libc_stack_end should be pretty close to stack top. The |
|
1169 |
// variable is available since the very early days. However, because it is |
|
1170 |
// a private interface, it could disappear in the future. |
|
1171 |
// |
|
1172 |
// Linux kernel saves start_stack information in /proc/<pid>/stat. Similar |
|
1173 |
// to __libc_stack_end, it is very close to stack top, but isn't the real |
|
1174 |
// stack top. Note that /proc may not exist if VM is running as a chroot |
|
1175 |
// program, so reading /proc/<pid>/stat could fail. Also the contents of |
|
1176 |
// /proc/<pid>/stat could change in the future (though unlikely). |
|
1177 |
// |
|
1178 |
// We try __libc_stack_end first. If that doesn't work, look for |
|
1179 |
// /proc/<pid>/stat. If neither of them works, we use current stack pointer |
|
1180 |
// as a hint, which should work well in most cases. |
|
1181 |
||
1182 |
uintptr_t stack_start; |
|
1183 |
||
1184 |
// try __libc_stack_end first |
|
1185 |
uintptr_t *p = (uintptr_t *)dlsym(RTLD_DEFAULT, "__libc_stack_end"); |
|
1186 |
if (p && *p) { |
|
1187 |
stack_start = *p; |
|
1188 |
} else { |
|
1189 |
// see if we can get the start_stack field from /proc/self/stat |
|
1190 |
FILE *fp; |
|
1191 |
int pid; |
|
1192 |
char state; |
|
1193 |
int ppid; |
|
1194 |
int pgrp; |
|
1195 |
int session; |
|
1196 |
int nr; |
|
1197 |
int tpgrp; |
|
1198 |
unsigned long flags; |
|
1199 |
unsigned long minflt; |
|
1200 |
unsigned long cminflt; |
|
1201 |
unsigned long majflt; |
|
1202 |
unsigned long cmajflt; |
|
1203 |
unsigned long utime; |
|
1204 |
unsigned long stime; |
|
1205 |
long cutime; |
|
1206 |
long cstime; |
|
1207 |
long prio; |
|
1208 |
long nice; |
|
1209 |
long junk; |
|
1210 |
long it_real; |
|
1211 |
uintptr_t start; |
|
1212 |
uintptr_t vsize; |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1213 |
intptr_t rss; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1214 |
uintptr_t rsslim; |
1 | 1215 |
uintptr_t scodes; |
1216 |
uintptr_t ecode; |
|
1217 |
int i; |
|
1218 |
||
1219 |
// Figure what the primordial thread stack base is. Code is inspired |
|
1220 |
// by email from Hans Boehm. /proc/self/stat begins with current pid, |
|
1221 |
// followed by command name surrounded by parentheses, state, etc. |
|
1222 |
char stat[2048]; |
|
1223 |
int statlen; |
|
1224 |
||
1225 |
fp = fopen("/proc/self/stat", "r"); |
|
1226 |
if (fp) { |
|
1227 |
statlen = fread(stat, 1, 2047, fp); |
|
1228 |
stat[statlen] = '\0'; |
|
1229 |
fclose(fp); |
|
1230 |
||
1231 |
// Skip pid and the command string. Note that we could be dealing with |
|
1232 |
// weird command names, e.g. user could decide to rename java launcher |
|
1233 |
// to "java 1.4.2 :)", then the stat file would look like |
|
1234 |
// 1234 (java 1.4.2 :)) R ... ... |
|
1235 |
// We don't really need to know the command string, just find the last |
|
1236 |
// occurrence of ")" and then start parsing from there. See bug 4726580. |
|
1237 |
char * s = strrchr(stat, ')'); |
|
1238 |
||
1239 |
i = 0; |
|
1240 |
if (s) { |
|
1241 |
// Skip blank chars |
|
1242 |
do s++; while (isspace(*s)); |
|
1243 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1244 |
#define _UFM UINTX_FORMAT |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1245 |
#define _DFM INTX_FORMAT |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1246 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1247 |
/* 1 1 1 1 1 1 1 1 1 1 2 2 2 2 2 2 2 2 2 */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1248 |
/* 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1249 |
i = sscanf(s, "%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu %ld %ld %ld %ld %ld %ld " _UFM _UFM _DFM _UFM _UFM _UFM _UFM, |
1 | 1250 |
&state, /* 3 %c */ |
1251 |
&ppid, /* 4 %d */ |
|
1252 |
&pgrp, /* 5 %d */ |
|
1253 |
&session, /* 6 %d */ |
|
1254 |
&nr, /* 7 %d */ |
|
1255 |
&tpgrp, /* 8 %d */ |
|
1256 |
&flags, /* 9 %lu */ |
|
1257 |
&minflt, /* 10 %lu */ |
|
1258 |
&cminflt, /* 11 %lu */ |
|
1259 |
&majflt, /* 12 %lu */ |
|
1260 |
&cmajflt, /* 13 %lu */ |
|
1261 |
&utime, /* 14 %lu */ |
|
1262 |
&stime, /* 15 %lu */ |
|
1263 |
&cutime, /* 16 %ld */ |
|
1264 |
&cstime, /* 17 %ld */ |
|
1265 |
&prio, /* 18 %ld */ |
|
1266 |
&nice, /* 19 %ld */ |
|
1267 |
&junk, /* 20 %ld */ |
|
1268 |
&it_real, /* 21 %ld */ |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1269 |
&start, /* 22 UINTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1270 |
&vsize, /* 23 UINTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1271 |
&rss, /* 24 INTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1272 |
&rsslim, /* 25 UINTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1273 |
&scodes, /* 26 UINTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1274 |
&ecode, /* 27 UINTX_FORMAT */ |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1275 |
&stack_start); /* 28 UINTX_FORMAT */ |
1 | 1276 |
} |
1277 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1278 |
#undef _UFM |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1279 |
#undef _DFM |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1280 |
|
1 | 1281 |
if (i != 28 - 2) { |
1282 |
assert(false, "Bad conversion from /proc/self/stat"); |
|
1283 |
// product mode - assume we are the initial thread, good luck in the |
|
1284 |
// embedded case. |
|
1285 |
warning("Can't detect initial thread stack location - bad conversion"); |
|
1286 |
stack_start = (uintptr_t) &rlim; |
|
1287 |
} |
|
1288 |
} else { |
|
1289 |
// For some reason we can't open /proc/self/stat (for example, running on |
|
1290 |
// FreeBSD with a Linux emulator, or inside chroot), this should work for |
|
1291 |
// most cases, so don't abort: |
|
1292 |
warning("Can't detect initial thread stack location - no /proc/self/stat"); |
|
1293 |
stack_start = (uintptr_t) &rlim; |
|
1294 |
} |
|
1295 |
} |
|
1296 |
||
1297 |
// Now we have a pointer (stack_start) very close to the stack top, the |
|
1298 |
// next thing to do is to figure out the exact location of stack top. We |
|
1299 |
// can find out the virtual memory area that contains stack_start by |
|
1300 |
// reading /proc/self/maps, it should be the last vma in /proc/self/maps, |
|
1301 |
// and its upper limit is the real stack top. (again, this would fail if |
|
1302 |
// running inside chroot, because /proc may not exist.) |
|
1303 |
||
1304 |
uintptr_t stack_top; |
|
1305 |
address low, high; |
|
1306 |
if (find_vma((address)stack_start, &low, &high)) { |
|
1307 |
// success, "high" is the true stack top. (ignore "low", because initial |
|
1308 |
// thread stack grows on demand, its real bottom is high - RLIMIT_STACK.) |
|
1309 |
stack_top = (uintptr_t)high; |
|
1310 |
} else { |
|
1311 |
// failed, likely because /proc/self/maps does not exist |
|
1312 |
warning("Can't detect initial thread stack location - find_vma failed"); |
|
1313 |
// best effort: stack_start is normally within a few pages below the real |
|
1314 |
// stack top, use it as stack top, and reduce stack size so we won't put |
|
1315 |
// guard page outside stack. |
|
1316 |
stack_top = stack_start; |
|
1317 |
stack_size -= 16 * page_size(); |
|
1318 |
} |
|
1319 |
||
1320 |
// stack_top could be partially down the page so align it |
|
1321 |
stack_top = align_size_up(stack_top, page_size()); |
|
1322 |
||
1323 |
if (max_size && stack_size > max_size) { |
|
1324 |
_initial_thread_stack_size = max_size; |
|
1325 |
} else { |
|
1326 |
_initial_thread_stack_size = stack_size; |
|
1327 |
} |
|
1328 |
||
1329 |
_initial_thread_stack_size = align_size_down(_initial_thread_stack_size, page_size()); |
|
1330 |
_initial_thread_stack_bottom = (address)stack_top - _initial_thread_stack_size; |
|
1331 |
} |
|
1332 |
||
1333 |
//////////////////////////////////////////////////////////////////////////////// |
|
1334 |
// time support |
|
1335 |
||
1336 |
// Time since start-up in seconds to a fine granularity. |
|
1337 |
// Used by VMSelfDestructTimer and the MemProfiler. |
|
1338 |
double os::elapsedTime() { |
|
1339 |
||
1340 |
return (double)(os::elapsed_counter()) * 0.000001; |
|
1341 |
} |
|
1342 |
||
1343 |
jlong os::elapsed_counter() { |
|
1344 |
timeval time; |
|
1345 |
int status = gettimeofday(&time, NULL); |
|
1346 |
return jlong(time.tv_sec) * 1000 * 1000 + jlong(time.tv_usec) - initial_time_count; |
|
1347 |
} |
|
1348 |
||
1349 |
jlong os::elapsed_frequency() { |
|
1350 |
return (1000 * 1000); |
|
1351 |
} |
|
1352 |
||
1374
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1353 |
// For now, we say that linux does not support vtime. I have no idea |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1354 |
// whether it can actually be made to (DLD, 9/13/05). |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1355 |
|
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1356 |
bool os::supports_vtime() { return false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1357 |
bool os::enable_vtime() { return false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1358 |
bool os::vtime_enabled() { return false; } |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1359 |
double os::elapsedVTime() { |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1360 |
// better than nothing, but not much |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1361 |
return elapsedTime(); |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1362 |
} |
4c24294029a9
6711316: Open source the Garbage-First garbage collector
ysr
parents:
388
diff
changeset
|
1363 |
|
234 | 1364 |
jlong os::javaTimeMillis() { |
1 | 1365 |
timeval time; |
1366 |
int status = gettimeofday(&time, NULL); |
|
1367 |
assert(status != -1, "linux error"); |
|
1368 |
return jlong(time.tv_sec) * 1000 + jlong(time.tv_usec / 1000); |
|
1369 |
} |
|
1370 |
||
1371 |
#ifndef CLOCK_MONOTONIC |
|
1372 |
#define CLOCK_MONOTONIC (1) |
|
1373 |
#endif |
|
1374 |
||
1375 |
void os::Linux::clock_init() { |
|
1376 |
// we do dlopen's in this particular order due to bug in linux |
|
1377 |
// dynamical loader (see 6348968) leading to crash on exit |
|
1378 |
void* handle = dlopen("librt.so.1", RTLD_LAZY); |
|
1379 |
if (handle == NULL) { |
|
1380 |
handle = dlopen("librt.so", RTLD_LAZY); |
|
1381 |
} |
|
1382 |
||
1383 |
if (handle) { |
|
1384 |
int (*clock_getres_func)(clockid_t, struct timespec*) = |
|
1385 |
(int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_getres"); |
|
1386 |
int (*clock_gettime_func)(clockid_t, struct timespec*) = |
|
1387 |
(int(*)(clockid_t, struct timespec*))dlsym(handle, "clock_gettime"); |
|
1388 |
if (clock_getres_func && clock_gettime_func) { |
|
1389 |
// See if monotonic clock is supported by the kernel. Note that some |
|
1390 |
// early implementations simply return kernel jiffies (updated every |
|
1391 |
// 1/100 or 1/1000 second). It would be bad to use such a low res clock |
|
1392 |
// for nano time (though the monotonic property is still nice to have). |
|
1393 |
// It's fixed in newer kernels, however clock_getres() still returns |
|
1394 |
// 1/HZ. We check if clock_getres() works, but will ignore its reported |
|
1395 |
// resolution for now. Hopefully as people move to new kernels, this |
|
1396 |
// won't be a problem. |
|
1397 |
struct timespec res; |
|
1398 |
struct timespec tp; |
|
1399 |
if (clock_getres_func (CLOCK_MONOTONIC, &res) == 0 && |
|
1400 |
clock_gettime_func(CLOCK_MONOTONIC, &tp) == 0) { |
|
1401 |
// yes, monotonic clock is supported |
|
1402 |
_clock_gettime = clock_gettime_func; |
|
1403 |
} else { |
|
1404 |
// close librt if there is no monotonic clock |
|
1405 |
dlclose(handle); |
|
1406 |
} |
|
1407 |
} |
|
1408 |
} |
|
1409 |
} |
|
1410 |
||
1411 |
#ifndef SYS_clock_getres |
|
1412 |
||
1413 |
#if defined(IA32) || defined(AMD64) |
|
1414 |
#define SYS_clock_getres IA32_ONLY(266) AMD64_ONLY(229) |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1415 |
#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
1 | 1416 |
#else |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1417 |
#warning "SYS_clock_getres not defined for this platform, disabling fast_thread_cpu_time" |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1418 |
#define sys_clock_getres(x,y) -1 |
1 | 1419 |
#endif |
1420 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1421 |
#else |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
1422 |
#define sys_clock_getres(x,y) ::syscall(SYS_clock_getres, x, y) |
1 | 1423 |
#endif |
1424 |
||
1425 |
void os::Linux::fast_thread_clock_init() { |
|
1426 |
if (!UseLinuxPosixThreadCPUClocks) { |
|
1427 |
return; |
|
1428 |
} |
|
1429 |
clockid_t clockid; |
|
1430 |
struct timespec tp; |
|
1431 |
int (*pthread_getcpuclockid_func)(pthread_t, clockid_t *) = |
|
1432 |
(int(*)(pthread_t, clockid_t *)) dlsym(RTLD_DEFAULT, "pthread_getcpuclockid"); |
|
1433 |
||
1434 |
// Switch to using fast clocks for thread cpu time if |
|
1435 |
// the sys_clock_getres() returns 0 error code. |
|
1436 |
// Note, that some kernels may support the current thread |
|
1437 |
// clock (CLOCK_THREAD_CPUTIME_ID) but not the clocks |
|
1438 |
// returned by the pthread_getcpuclockid(). |
|
1439 |
// If the fast Posix clocks are supported then the sys_clock_getres() |
|
1440 |
// must return at least tp.tv_sec == 0 which means a resolution |
|
1441 |
// better than 1 sec. This is extra check for reliability. |
|
1442 |
||
1443 |
if(pthread_getcpuclockid_func && |
|
1444 |
pthread_getcpuclockid_func(_main_thread, &clockid) == 0 && |
|
1445 |
sys_clock_getres(clockid, &tp) == 0 && tp.tv_sec == 0) { |
|
1446 |
||
1447 |
_supports_fast_thread_cpu_time = true; |
|
1448 |
_pthread_getcpuclockid = pthread_getcpuclockid_func; |
|
1449 |
} |
|
1450 |
} |
|
1451 |
||
1452 |
jlong os::javaTimeNanos() { |
|
1453 |
if (Linux::supports_monotonic_clock()) { |
|
1454 |
struct timespec tp; |
|
1455 |
int status = Linux::clock_gettime(CLOCK_MONOTONIC, &tp); |
|
1456 |
assert(status == 0, "gettime error"); |
|
1457 |
jlong result = jlong(tp.tv_sec) * (1000 * 1000 * 1000) + jlong(tp.tv_nsec); |
|
1458 |
return result; |
|
1459 |
} else { |
|
1460 |
timeval time; |
|
1461 |
int status = gettimeofday(&time, NULL); |
|
1462 |
assert(status != -1, "linux error"); |
|
1463 |
jlong usecs = jlong(time.tv_sec) * (1000 * 1000) + jlong(time.tv_usec); |
|
1464 |
return 1000 * usecs; |
|
1465 |
} |
|
1466 |
} |
|
1467 |
||
1468 |
void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { |
|
1469 |
if (Linux::supports_monotonic_clock()) { |
|
1470 |
info_ptr->max_value = ALL_64_BITS; |
|
1471 |
||
1472 |
// CLOCK_MONOTONIC - amount of time since some arbitrary point in the past |
|
1473 |
info_ptr->may_skip_backward = false; // not subject to resetting or drifting |
|
1474 |
info_ptr->may_skip_forward = false; // not subject to resetting or drifting |
|
1475 |
} else { |
|
1476 |
// gettimeofday - based on time in seconds since the Epoch thus does not wrap |
|
1477 |
info_ptr->max_value = ALL_64_BITS; |
|
1478 |
||
1479 |
// gettimeofday is a real time clock so it skips |
|
1480 |
info_ptr->may_skip_backward = true; |
|
1481 |
info_ptr->may_skip_forward = true; |
|
1482 |
} |
|
1483 |
||
1484 |
info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time |
|
1485 |
} |
|
1486 |
||
1487 |
// Return the real, user, and system times in seconds from an |
|
1488 |
// arbitrary fixed point in the past. |
|
1489 |
bool os::getTimesSecs(double* process_real_time, |
|
1490 |
double* process_user_time, |
|
1491 |
double* process_system_time) { |
|
1492 |
struct tms ticks; |
|
1493 |
clock_t real_ticks = times(&ticks); |
|
1494 |
||
1495 |
if (real_ticks == (clock_t) (-1)) { |
|
1496 |
return false; |
|
1497 |
} else { |
|
1498 |
double ticks_per_second = (double) clock_tics_per_sec; |
|
1499 |
*process_user_time = ((double) ticks.tms_utime) / ticks_per_second; |
|
1500 |
*process_system_time = ((double) ticks.tms_stime) / ticks_per_second; |
|
1501 |
*process_real_time = ((double) real_ticks) / ticks_per_second; |
|
1502 |
||
1503 |
return true; |
|
1504 |
} |
|
1505 |
} |
|
1506 |
||
1507 |
||
1508 |
char * os::local_time_string(char *buf, size_t buflen) { |
|
1509 |
struct tm t; |
|
1510 |
time_t long_time; |
|
1511 |
time(&long_time); |
|
1512 |
localtime_r(&long_time, &t); |
|
1513 |
jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", |
|
1514 |
t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, |
|
1515 |
t.tm_hour, t.tm_min, t.tm_sec); |
|
1516 |
return buf; |
|
1517 |
} |
|
1518 |
||
2012
041fbc6030dd
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
1892
diff
changeset
|
1519 |
struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { |
041fbc6030dd
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
1892
diff
changeset
|
1520 |
return localtime_r(clock, res); |
041fbc6030dd
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
1892
diff
changeset
|
1521 |
} |
041fbc6030dd
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
1892
diff
changeset
|
1522 |
|
1 | 1523 |
//////////////////////////////////////////////////////////////////////////////// |
1524 |
// runtime exit support |
|
1525 |
||
1526 |
// Note: os::shutdown() might be called very early during initialization, or |
|
1527 |
// called from signal handler. Before adding something to os::shutdown(), make |
|
1528 |
// sure it is async-safe and can handle partially initialized VM. |
|
1529 |
void os::shutdown() { |
|
1530 |
||
1531 |
// allow PerfMemory to attempt cleanup of any persistent resources |
|
1532 |
perfMemory_exit(); |
|
1533 |
||
1534 |
// needs to remove object in file system |
|
1535 |
AttachListener::abort(); |
|
1536 |
||
1537 |
// flush buffered output, finish log files |
|
1538 |
ostream_abort(); |
|
1539 |
||
1540 |
// Check for abort hook |
|
1541 |
abort_hook_t abort_hook = Arguments::abort_hook(); |
|
1542 |
if (abort_hook != NULL) { |
|
1543 |
abort_hook(); |
|
1544 |
} |
|
1545 |
||
1546 |
} |
|
1547 |
||
1548 |
// Note: os::abort() might be called very early during initialization, or |
|
1549 |
// called from signal handler. Before adding something to os::abort(), make |
|
1550 |
// sure it is async-safe and can handle partially initialized VM. |
|
1551 |
void os::abort(bool dump_core) { |
|
1552 |
os::shutdown(); |
|
1553 |
if (dump_core) { |
|
1554 |
#ifndef PRODUCT |
|
1555 |
fdStream out(defaultStream::output_fd()); |
|
1556 |
out.print_raw("Current thread is "); |
|
1557 |
char buf[16]; |
|
1558 |
jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id()); |
|
1559 |
out.print_raw_cr(buf); |
|
1560 |
out.print_raw_cr("Dumping core ..."); |
|
1561 |
#endif |
|
1562 |
::abort(); // dump core |
|
1563 |
} |
|
1564 |
||
1565 |
::exit(1); |
|
1566 |
} |
|
1567 |
||
1568 |
// Die immediately, no exit hook, no abort hook, no cleanup. |
|
1569 |
void os::die() { |
|
1570 |
// _exit() on LinuxThreads only kills current thread |
|
1571 |
::abort(); |
|
1572 |
} |
|
1573 |
||
1574 |
// unused on linux for now. |
|
1575 |
void os::set_error_file(const char *logfile) {} |
|
1576 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1577 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1578 |
// This method is a copy of JDK's sysGetLastErrorString |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1579 |
// from src/solaris/hpi/src/system_md.c |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1580 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1581 |
size_t os::lasterror(char *buf, size_t len) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1582 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1583 |
if (errno == 0) return 0; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1584 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1585 |
const char *s = ::strerror(errno); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1586 |
size_t n = ::strlen(s); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1587 |
if (n >= len) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1588 |
n = len - 1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1589 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1590 |
::strncpy(buf, s, n); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1591 |
buf[n] = '\0'; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1592 |
return n; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1593 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
1594 |
|
1 | 1595 |
intx os::current_thread_id() { return (intx)pthread_self(); } |
1596 |
int os::current_process_id() { |
|
1597 |
||
1598 |
// Under the old linux thread library, linux gives each thread |
|
1599 |
// its own process id. Because of this each thread will return |
|
1600 |
// a different pid if this method were to return the result |
|
1601 |
// of getpid(2). Linux provides no api that returns the pid |
|
1602 |
// of the launcher thread for the vm. This implementation |
|
1603 |
// returns a unique pid, the pid of the launcher thread |
|
1604 |
// that starts the vm 'process'. |
|
1605 |
||
1606 |
// Under the NPTL, getpid() returns the same pid as the |
|
1607 |
// launcher thread rather than a unique pid per thread. |
|
1608 |
// Use gettid() if you want the old pre NPTL behaviour. |
|
1609 |
||
1610 |
// if you are looking for the result of a call to getpid() that |
|
1611 |
// returns a unique pid for the calling thread, then look at the |
|
1612 |
// OSThread::thread_id() method in osThread_linux.hpp file |
|
1613 |
||
1614 |
return (int)(_initial_pid ? _initial_pid : getpid()); |
|
1615 |
} |
|
1616 |
||
1617 |
// DLL functions |
|
1618 |
||
1619 |
const char* os::dll_file_extension() { return ".so"; } |
|
1620 |
||
7901
ea3d83447861
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
7458
diff
changeset
|
1621 |
// This must be hard coded because it's the system's temporary |
ea3d83447861
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
7458
diff
changeset
|
1622 |
// directory not the java application's temp directory, ala java.io.tmpdir. |
ea3d83447861
7009828: Fix for 6938627 breaks visualvm monitoring when -Djava.io.tmpdir is defined
coleenp
parents:
7458
diff
changeset
|
1623 |
const char* os::get_temp_directory() { return "/tmp"; } |
1 | 1624 |
|
2358 | 1625 |
static bool file_exists(const char* filename) { |
1626 |
struct stat statbuf; |
|
1627 |
if (filename == NULL || strlen(filename) == 0) { |
|
1628 |
return false; |
|
1629 |
} |
|
1630 |
return os::stat(filename, &statbuf) == 0; |
|
1631 |
} |
|
1632 |
||
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1633 |
bool os::dll_build_name(char* buffer, size_t buflen, |
2358 | 1634 |
const char* pname, const char* fname) { |
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1635 |
bool retval = false; |
2358 | 1636 |
// Copied from libhpi |
950 | 1637 |
const size_t pnamelen = pname ? strlen(pname) : 0; |
1638 |
||
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1639 |
// Return error on buffer overflow. |
950 | 1640 |
if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { |
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1641 |
return retval; |
950 | 1642 |
} |
1643 |
||
1644 |
if (pnamelen == 0) { |
|
2358 | 1645 |
snprintf(buffer, buflen, "lib%s.so", fname); |
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1646 |
retval = true; |
2358 | 1647 |
} else if (strchr(pname, *os::path_separator()) != NULL) { |
1648 |
int n; |
|
1649 |
char** pelements = split_path(pname, &n); |
|
1650 |
for (int i = 0 ; i < n ; i++) { |
|
1651 |
// Really shouldn't be NULL, but check can't hurt |
|
1652 |
if (pelements[i] == NULL || strlen(pelements[i]) == 0) { |
|
1653 |
continue; // skip the empty path values |
|
1654 |
} |
|
1655 |
snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname); |
|
1656 |
if (file_exists(buffer)) { |
|
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1657 |
retval = true; |
2358 | 1658 |
break; |
1659 |
} |
|
1660 |
} |
|
1661 |
// release the storage |
|
1662 |
for (int i = 0 ; i < n ; i++) { |
|
1663 |
if (pelements[i] != NULL) { |
|
13195 | 1664 |
FREE_C_HEAP_ARRAY(char, pelements[i], mtInternal); |
2358 | 1665 |
} |
1666 |
} |
|
1667 |
if (pelements != NULL) { |
|
13195 | 1668 |
FREE_C_HEAP_ARRAY(char*, pelements, mtInternal); |
2358 | 1669 |
} |
950 | 1670 |
} else { |
2358 | 1671 |
snprintf(buffer, buflen, "%s/lib%s.so", pname, fname); |
14471
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1672 |
retval = true; |
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1673 |
} |
f3a6b82e25cf
8001185: parsing of sun.boot.library.path in os::dll_build_name somewhat broken
bpittore
parents:
13932
diff
changeset
|
1674 |
return retval; |
950 | 1675 |
} |
1676 |
||
1 | 1677 |
const char* os::get_current_directory(char *buf, int buflen) { |
1678 |
return getcwd(buf, buflen); |
|
1679 |
} |
|
1680 |
||
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
1681 |
// check if addr is inside libjvm.so |
1 | 1682 |
bool os::address_is_in_vm(address addr) { |
1683 |
static address libjvm_base_addr; |
|
1684 |
Dl_info dlinfo; |
|
1685 |
||
1686 |
if (libjvm_base_addr == NULL) { |
|
1687 |
dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo); |
|
1688 |
libjvm_base_addr = (address)dlinfo.dli_fbase; |
|
1689 |
assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm"); |
|
1690 |
} |
|
1691 |
||
1692 |
if (dladdr((void *)addr, &dlinfo)) { |
|
1693 |
if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true; |
|
1694 |
} |
|
1695 |
||
1696 |
return false; |
|
1697 |
} |
|
1698 |
||
1699 |
bool os::dll_address_to_function_name(address addr, char *buf, |
|
1700 |
int buflen, int *offset) { |
|
1701 |
Dl_info dlinfo; |
|
1702 |
||
1703 |
if (dladdr((void*)addr, &dlinfo) && dlinfo.dli_sname != NULL) { |
|
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1704 |
if (buf != NULL) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1705 |
if(!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1706 |
jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname); |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1707 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1708 |
} |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1709 |
if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr; |
1 | 1710 |
return true; |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1711 |
} else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) { |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1712 |
if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase), |
11483 | 1713 |
buf, buflen, offset, dlinfo.dli_fname)) { |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1714 |
return true; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1715 |
} |
1 | 1716 |
} |
7447
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1717 |
|
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1718 |
if (buf != NULL) buf[0] = '\0'; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1719 |
if (offset != NULL) *offset = -1; |
32c42d627f41
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
7397
diff
changeset
|
1720 |
return false; |
1 | 1721 |
} |
1722 |
||
1723 |
struct _address_to_library_name { |
|
1724 |
address addr; // input : memory address |
|
1725 |
size_t buflen; // size of fname |
|
1726 |
char* fname; // output: library name |
|
1727 |
address base; // library base addr |
|
1728 |
}; |
|
1729 |
||
1730 |
static int address_to_library_name_callback(struct dl_phdr_info *info, |
|
1731 |
size_t size, void *data) { |
|
1732 |
int i; |
|
1733 |
bool found = false; |
|
1734 |
address libbase = NULL; |
|
1735 |
struct _address_to_library_name * d = (struct _address_to_library_name *)data; |
|
1736 |
||
1737 |
// iterate through all loadable segments |
|
1738 |
for (i = 0; i < info->dlpi_phnum; i++) { |
|
1739 |
address segbase = (address)(info->dlpi_addr + info->dlpi_phdr[i].p_vaddr); |
|
1740 |
if (info->dlpi_phdr[i].p_type == PT_LOAD) { |
|
1741 |
// base address of a library is the lowest address of its loaded |
|
1742 |
// segments. |
|
1743 |
if (libbase == NULL || libbase > segbase) { |
|
1744 |
libbase = segbase; |
|
1745 |
} |
|
1746 |
// see if 'addr' is within current segment |
|
1747 |
if (segbase <= d->addr && |
|
1748 |
d->addr < segbase + info->dlpi_phdr[i].p_memsz) { |
|
1749 |
found = true; |
|
1750 |
} |
|
1751 |
} |
|
1752 |
} |
|
1753 |
||
1754 |
// dlpi_name is NULL or empty if the ELF file is executable, return 0 |
|
1755 |
// so dll_address_to_library_name() can fall through to use dladdr() which |
|
1756 |
// can figure out executable name from argv[0]. |
|
1757 |
if (found && info->dlpi_name && info->dlpi_name[0]) { |
|
1758 |
d->base = libbase; |
|
1759 |
if (d->fname) { |
|
1760 |
jio_snprintf(d->fname, d->buflen, "%s", info->dlpi_name); |
|
1761 |
} |
|
1762 |
return 1; |
|
1763 |
} |
|
1764 |
return 0; |
|
1765 |
} |
|
1766 |
||
1767 |
bool os::dll_address_to_library_name(address addr, char* buf, |
|
1768 |
int buflen, int* offset) { |
|
1769 |
Dl_info dlinfo; |
|
1770 |
struct _address_to_library_name data; |
|
1771 |
||
1772 |
// There is a bug in old glibc dladdr() implementation that it could resolve |
|
1773 |
// to wrong library name if the .so file has a base address != NULL. Here |
|
1774 |
// we iterate through the program headers of all loaded libraries to find |
|
1775 |
// out which library 'addr' really belongs to. This workaround can be |
|
1776 |
// removed once the minimum requirement for glibc is moved to 2.3.x. |
|
1777 |
data.addr = addr; |
|
1778 |
data.fname = buf; |
|
1779 |
data.buflen = buflen; |
|
1780 |
data.base = NULL; |
|
1781 |
int rslt = dl_iterate_phdr(address_to_library_name_callback, (void *)&data); |
|
1782 |
||
1783 |
if (rslt) { |
|
1784 |
// buf already contains library name |
|
1785 |
if (offset) *offset = addr - data.base; |
|
1786 |
return true; |
|
1787 |
} else if (dladdr((void*)addr, &dlinfo)){ |
|
1788 |
if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname); |
|
1789 |
if (offset) *offset = addr - (address)dlinfo.dli_fbase; |
|
1790 |
return true; |
|
1791 |
} else { |
|
1792 |
if (buf) buf[0] = '\0'; |
|
1793 |
if (offset) *offset = -1; |
|
1794 |
return false; |
|
1795 |
} |
|
1796 |
} |
|
1797 |
||
1798 |
// Loads .dll/.so and |
|
1799 |
// in case of error it checks if .dll/.so was built for the |
|
1800 |
// same architecture as Hotspot is running on |
|
1801 |
||
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1802 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1803 |
// Remember the stack's state. The Linux dynamic linker will change |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1804 |
// the stack to 'executable' at most once, so we must safepoint only once. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1805 |
bool os::Linux::_stack_is_executable = false; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1806 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1807 |
// VM operation that loads a library. This is necessary if stack protection |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1808 |
// of the Java stacks can be lost during loading the library. If we |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1809 |
// do not stop the Java threads, they can stack overflow before the stacks |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1810 |
// are protected again. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1811 |
class VM_LinuxDllLoad: public VM_Operation { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1812 |
private: |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1813 |
const char *_filename; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1814 |
void *_lib; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1815 |
public: |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1816 |
VM_LinuxDllLoad(const char *fn) : |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1817 |
_filename(fn), _lib(NULL) {} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1818 |
VMOp_Type type() const { return VMOp_LinuxDllLoad; } |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1819 |
void doit() { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1820 |
_lib = os::Linux::dll_load_inner(_filename); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1821 |
os::Linux::_stack_is_executable = true; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1822 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1823 |
void* loaded_library() { return _lib; } |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1824 |
}; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1825 |
|
1 | 1826 |
void * os::dll_load(const char *filename, char *ebuf, int ebuflen) |
1827 |
{ |
|
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1828 |
void * result = NULL; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1829 |
bool load_attempted = false; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1830 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1831 |
// Check whether the library to load might change execution rights |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1832 |
// of the stack. If they are changed, the protection of the stack |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1833 |
// guard pages will be lost. We need a safepoint to fix this. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1834 |
// |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1835 |
// See Linux man page execstack(8) for more info. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1836 |
if (os::uses_stack_guard_pages() && !os::Linux::_stack_is_executable) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1837 |
ElfFile ef(filename); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1838 |
if (!ef.specifies_noexecstack()) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1839 |
if (!is_init_completed()) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1840 |
os::Linux::_stack_is_executable = true; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1841 |
// This is OK - No Java threads have been created yet, and hence no |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1842 |
// stack guard pages to fix. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1843 |
// |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1844 |
// This should happen only when you are building JDK7 using a very |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1845 |
// old version of JDK6 (e.g., with JPRT) and running test_gamma. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1846 |
// |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1847 |
// Dynamic loader will make all stacks executable after |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1848 |
// this function returns, and will not do that again. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1849 |
assert(Threads::first() == NULL, "no Java threads should exist yet."); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1850 |
} else { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1851 |
warning("You have loaded library %s which might have disabled stack guard. " |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1852 |
"The VM will try to fix the stack guard now.\n" |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1853 |
"It's highly recommended that you fix the library with " |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1854 |
"'execstack -c <libfile>', or link it with '-z noexecstack'.", |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1855 |
filename); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1856 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1857 |
assert(Thread::current()->is_Java_thread(), "must be Java thread"); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1858 |
JavaThread *jt = JavaThread::current(); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1859 |
if (jt->thread_state() != _thread_in_native) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1860 |
// This happens when a compiler thread tries to load a hsdis-<arch>.so file |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1861 |
// that requires ExecStack. Cannot enter safe point. Let's give up. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1862 |
warning("Unable to fix stack guard. Giving up."); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1863 |
} else { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1864 |
if (!LoadExecStackDllInVMThread) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1865 |
// This is for the case where the DLL has an static |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1866 |
// constructor function that executes JNI code. We cannot |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1867 |
// load such DLLs in the VMThread. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1868 |
result = ::dlopen(filename, RTLD_LAZY); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1869 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1870 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1871 |
ThreadInVMfromNative tiv(jt); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1872 |
debug_only(VMNativeEntryWrapper vew;) |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1873 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1874 |
VM_LinuxDllLoad op(filename); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1875 |
VMThread::execute(&op); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1876 |
if (LoadExecStackDllInVMThread) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1877 |
result = op.loaded_library(); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1878 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1879 |
load_attempted = true; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1880 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1881 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1882 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1883 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1884 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1885 |
if (!load_attempted) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1886 |
result = ::dlopen(filename, RTLD_LAZY); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1887 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
1888 |
|
1 | 1889 |
if (result != NULL) { |
1890 |
// Successful loading |
|
1891 |
return result; |
|
1892 |
} |
|
1893 |
||
1894 |
Elf32_Ehdr elf_head; |
|
1895 |
||
1896 |
// Read system error message into ebuf |
|
1897 |
// It may or may not be overwritten below |
|
1898 |
::strncpy(ebuf, ::dlerror(), ebuflen-1); |
|
1899 |
ebuf[ebuflen-1]='\0'; |
|
1900 |
int diag_msg_max_length=ebuflen-strlen(ebuf); |
|
1901 |
char* diag_msg_buf=ebuf+strlen(ebuf); |
|
1902 |
||
1903 |
if (diag_msg_max_length==0) { |
|
1904 |
// No more space in ebuf for additional diagnostics message |
|
1905 |
return NULL; |
|
1906 |
} |
|
1907 |
||
1908 |
||
1909 |
int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK); |
|
1910 |
||
1911 |
if (file_descriptor < 0) { |
|
1912 |
// Can't open library, report dlerror() message |
|
1913 |
return NULL; |
|
1914 |
} |
|
1915 |
||
1916 |
bool failed_to_read_elf_head= |
|
1917 |
(sizeof(elf_head)!= |
|
1918 |
(::read(file_descriptor, &elf_head,sizeof(elf_head)))) ; |
|
1919 |
||
1920 |
::close(file_descriptor); |
|
1921 |
if (failed_to_read_elf_head) { |
|
1922 |
// file i/o error - report dlerror() msg |
|
1923 |
return NULL; |
|
1924 |
} |
|
1925 |
||
1926 |
typedef struct { |
|
1927 |
Elf32_Half code; // Actual value as defined in elf.h |
|
1928 |
Elf32_Half compat_class; // Compatibility of archs at VM's sense |
|
1929 |
char elf_class; // 32 or 64 bit |
|
1930 |
char endianess; // MSB or LSB |
|
1931 |
char* name; // String representation |
|
1932 |
} arch_t; |
|
1933 |
||
1934 |
#ifndef EM_486 |
|
1935 |
#define EM_486 6 /* Intel 80486 */ |
|
1936 |
#endif |
|
1937 |
||
1938 |
static const arch_t arch_array[]={ |
|
1939 |
{EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
|
1940 |
{EM_486, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, |
|
1941 |
{EM_IA_64, EM_IA_64, ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"}, |
|
1942 |
{EM_X86_64, EM_X86_64, ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"}, |
|
1943 |
{EM_SPARC, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"}, |
|
1944 |
{EM_SPARC32PLUS, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"}, |
|
1945 |
{EM_SPARCV9, EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"}, |
|
1946 |
{EM_PPC, EM_PPC, ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"}, |
|
4013 | 1947 |
{EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
1948 |
{EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM"}, |
|
1949 |
{EM_S390, EM_S390, ELFCLASSNONE, ELFDATA2MSB, (char*)"IBM System/390"}, |
|
1950 |
{EM_ALPHA, EM_ALPHA, ELFCLASS64, ELFDATA2LSB, (char*)"Alpha"}, |
|
1951 |
{EM_MIPS_RS3_LE, EM_MIPS_RS3_LE, ELFCLASS32, ELFDATA2LSB, (char*)"MIPSel"}, |
|
1952 |
{EM_MIPS, EM_MIPS, ELFCLASS32, ELFDATA2MSB, (char*)"MIPS"}, |
|
1953 |
{EM_PARISC, EM_PARISC, ELFCLASS32, ELFDATA2MSB, (char*)"PARISC"}, |
|
1954 |
{EM_68K, EM_68K, ELFCLASS32, ELFDATA2MSB, (char*)"M68k"} |
|
1 | 1955 |
}; |
1956 |
||
1957 |
#if (defined IA32) |
|
1958 |
static Elf32_Half running_arch_code=EM_386; |
|
1959 |
#elif (defined AMD64) |
|
1960 |
static Elf32_Half running_arch_code=EM_X86_64; |
|
1961 |
#elif (defined IA64) |
|
1962 |
static Elf32_Half running_arch_code=EM_IA_64; |
|
1963 |
#elif (defined __sparc) && (defined _LP64) |
|
1964 |
static Elf32_Half running_arch_code=EM_SPARCV9; |
|
1965 |
#elif (defined __sparc) && (!defined _LP64) |
|
1966 |
static Elf32_Half running_arch_code=EM_SPARC; |
|
1967 |
#elif (defined __powerpc64__) |
|
1968 |
static Elf32_Half running_arch_code=EM_PPC64; |
|
1969 |
#elif (defined __powerpc__) |
|
1970 |
static Elf32_Half running_arch_code=EM_PPC; |
|
4013 | 1971 |
#elif (defined ARM) |
1972 |
static Elf32_Half running_arch_code=EM_ARM; |
|
1973 |
#elif (defined S390) |
|
1974 |
static Elf32_Half running_arch_code=EM_S390; |
|
1975 |
#elif (defined ALPHA) |
|
1976 |
static Elf32_Half running_arch_code=EM_ALPHA; |
|
1977 |
#elif (defined MIPSEL) |
|
1978 |
static Elf32_Half running_arch_code=EM_MIPS_RS3_LE; |
|
1979 |
#elif (defined PARISC) |
|
1980 |
static Elf32_Half running_arch_code=EM_PARISC; |
|
1981 |
#elif (defined MIPS) |
|
1982 |
static Elf32_Half running_arch_code=EM_MIPS; |
|
1983 |
#elif (defined M68K) |
|
1984 |
static Elf32_Half running_arch_code=EM_68K; |
|
1 | 1985 |
#else |
1986 |
#error Method os::dll_load requires that one of following is defined:\ |
|
4013 | 1987 |
IA32, AMD64, IA64, __sparc, __powerpc__, ARM, S390, ALPHA, MIPS, MIPSEL, PARISC, M68K |
1 | 1988 |
#endif |
1989 |
||
1990 |
// Identify compatability class for VM's architecture and library's architecture |
|
1991 |
// Obtain string descriptions for architectures |
|
1992 |
||
1993 |
arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; |
|
1994 |
int running_arch_index=-1; |
|
1995 |
||
1996 |
for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) { |
|
1997 |
if (running_arch_code == arch_array[i].code) { |
|
1998 |
running_arch_index = i; |
|
1999 |
} |
|
2000 |
if (lib_arch.code == arch_array[i].code) { |
|
2001 |
lib_arch.compat_class = arch_array[i].compat_class; |
|
2002 |
lib_arch.name = arch_array[i].name; |
|
2003 |
} |
|
2004 |
} |
|
2005 |
||
2006 |
assert(running_arch_index != -1, |
|
2007 |
"Didn't find running architecture code (running_arch_code) in arch_array"); |
|
2008 |
if (running_arch_index == -1) { |
|
2009 |
// Even though running architecture detection failed |
|
2010 |
// we may still continue with reporting dlerror() message |
|
2011 |
return NULL; |
|
2012 |
} |
|
2013 |
||
2014 |
if (lib_arch.endianess != arch_array[running_arch_index].endianess) { |
|
2015 |
::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)"); |
|
2016 |
return NULL; |
|
2017 |
} |
|
2018 |
||
4013 | 2019 |
#ifndef S390 |
1 | 2020 |
if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) { |
2021 |
::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)"); |
|
2022 |
return NULL; |
|
2023 |
} |
|
4013 | 2024 |
#endif // !S390 |
1 | 2025 |
|
2026 |
if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) { |
|
2027 |
if ( lib_arch.name!=NULL ) { |
|
2028 |
::snprintf(diag_msg_buf, diag_msg_max_length-1, |
|
2029 |
" (Possible cause: can't load %s-bit .so on a %s-bit platform)", |
|
2030 |
lib_arch.name, arch_array[running_arch_index].name); |
|
2031 |
} else { |
|
2032 |
::snprintf(diag_msg_buf, diag_msg_max_length-1, |
|
2033 |
" (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)", |
|
2034 |
lib_arch.code, |
|
2035 |
arch_array[running_arch_index].name); |
|
2036 |
} |
|
2037 |
} |
|
2038 |
||
2039 |
return NULL; |
|
2040 |
} |
|
2041 |
||
15926
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2042 |
void * os::Linux::dll_load_inner(const char *filename) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2043 |
void * result = NULL; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2044 |
if (LoadExecStackDllInVMThread) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2045 |
result = ::dlopen(filename, RTLD_LAZY); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2046 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2047 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2048 |
// Since 7019808, libjvm.so is linked with -noexecstack. If the VM loads a |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2049 |
// library that requires an executable stack, or which does not have this |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2050 |
// stack attribute set, dlopen changes the stack attribute to executable. The |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2051 |
// read protection of the guard pages gets lost. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2052 |
// |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2053 |
// Need to check _stack_is_executable again as multiple VM_LinuxDllLoad |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2054 |
// may have been queued at the same time. |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2055 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2056 |
if (!_stack_is_executable) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2057 |
JavaThread *jt = Threads::first(); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2058 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2059 |
while (jt) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2060 |
if (!jt->stack_guard_zone_unused() && // Stack not yet fully initialized |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2061 |
jt->stack_yellow_zone_enabled()) { // No pending stack overflow exceptions |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2062 |
if (!os::guard_memory((char *) jt->stack_red_zone_base() - jt->stack_red_zone_size(), |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2063 |
jt->stack_yellow_zone_size() + jt->stack_red_zone_size())) { |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2064 |
warning("Attempt to reguard stack yellow zone failed."); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2065 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2066 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2067 |
jt = jt->next(); |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2068 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2069 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2070 |
|
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2071 |
return result; |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2072 |
} |
8e87d545195f
7107135: Stack guard pages are no more protected after loading a shared library with executable stack
iklam
parents:
15855
diff
changeset
|
2073 |
|
950 | 2074 |
/* |
2075 |
* glibc-2.0 libdl is not MT safe. If you are building with any glibc, |
|
2076 |
* chances are you might want to run the generated bits against glibc-2.0 |
|
2077 |
* libdl.so, so always use locking for any version of glibc. |
|
2078 |
*/ |
|
2079 |
void* os::dll_lookup(void* handle, const char* name) { |
|
2080 |
pthread_mutex_lock(&dl_mutex); |
|
2081 |
void* res = dlsym(handle, name); |
|
2082 |
pthread_mutex_unlock(&dl_mutex); |
|
2083 |
return res; |
|
2084 |
} |
|
1 | 2085 |
|
2086 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2087 |
static bool _print_ascii_file(const char* filename, outputStream* st) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2088 |
int fd = ::open(filename, O_RDONLY); |
1 | 2089 |
if (fd == -1) { |
2090 |
return false; |
|
2091 |
} |
|
2092 |
||
2093 |
char buf[32]; |
|
2094 |
int bytes; |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2095 |
while ((bytes = ::read(fd, buf, sizeof(buf))) > 0) { |
1 | 2096 |
st->print_raw(buf, bytes); |
2097 |
} |
|
2098 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2099 |
::close(fd); |
1 | 2100 |
|
2101 |
return true; |
|
2102 |
} |
|
2103 |
||
2104 |
void os::print_dll_info(outputStream *st) { |
|
2105 |
st->print_cr("Dynamic libraries:"); |
|
2106 |
||
2107 |
char fname[32]; |
|
2108 |
pid_t pid = os::Linux::gettid(); |
|
2109 |
||
2110 |
jio_snprintf(fname, sizeof(fname), "/proc/%d/maps", pid); |
|
2111 |
||
2112 |
if (!_print_ascii_file(fname, st)) { |
|
2113 |
st->print("Can not get library information for pid = %d\n", pid); |
|
2114 |
} |
|
2115 |
} |
|
2116 |
||
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2117 |
void os::print_os_info_brief(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2118 |
os::Linux::print_distro_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2119 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2120 |
os::Posix::print_uname_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2121 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2122 |
os::Linux::print_libversion_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2123 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2124 |
} |
1 | 2125 |
|
2126 |
void os::print_os_info(outputStream* st) { |
|
2127 |
st->print("OS:"); |
|
2128 |
||
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2129 |
os::Linux::print_distro_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2130 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2131 |
os::Posix::print_uname_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2132 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2133 |
// Print warning if unsafe chroot environment detected |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2134 |
if (unsafe_chroot_detected) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2135 |
st->print("WARNING!! "); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2136 |
st->print_cr(unstable_chroot_error); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2137 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2138 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2139 |
os::Linux::print_libversion_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2140 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2141 |
os::Posix::print_rlimit_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2142 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2143 |
os::Posix::print_load_average(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2144 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2145 |
os::Linux::print_full_memory_info(st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2146 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2147 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2148 |
// Try to identify popular distros. |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2149 |
// Most Linux distributions have /etc/XXX-release file, which contains |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2150 |
// the OS version string. Some have more than one /etc/XXX-release file |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2151 |
// (e.g. Mandrake has both /etc/mandrake-release and /etc/redhat-release.), |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2152 |
// so the order is important. |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2153 |
void os::Linux::print_distro_info(outputStream* st) { |
1 | 2154 |
if (!_print_ascii_file("/etc/mandrake-release", st) && |
2155 |
!_print_ascii_file("/etc/sun-release", st) && |
|
2156 |
!_print_ascii_file("/etc/redhat-release", st) && |
|
2157 |
!_print_ascii_file("/etc/SuSE-release", st) && |
|
2158 |
!_print_ascii_file("/etc/turbolinux-release", st) && |
|
2159 |
!_print_ascii_file("/etc/gentoo-release", st) && |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2160 |
!_print_ascii_file("/etc/debian_version", st) && |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2161 |
!_print_ascii_file("/etc/ltib-release", st) && |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2162 |
!_print_ascii_file("/etc/angstrom-version", st)) { |
1 | 2163 |
st->print("Linux"); |
2164 |
} |
|
2165 |
st->cr(); |
|
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2166 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2167 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2168 |
void os::Linux::print_libversion_info(outputStream* st) { |
1 | 2169 |
// libc, pthread |
2170 |
st->print("libc:"); |
|
2171 |
st->print(os::Linux::glibc_version()); st->print(" "); |
|
2172 |
st->print(os::Linux::libpthread_version()); st->print(" "); |
|
2173 |
if (os::Linux::is_LinuxThreads()) { |
|
2174 |
st->print("(%s stack)", os::Linux::is_floating_stack() ? "floating" : "fixed"); |
|
2175 |
} |
|
2176 |
st->cr(); |
|
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2177 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2178 |
|
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2179 |
void os::Linux::print_full_memory_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2180 |
st->print("\n/proc/meminfo:\n"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2181 |
_print_ascii_file("/proc/meminfo", st); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2182 |
st->cr(); |
10023
e99d9a03c0f5
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
9625
diff
changeset
|
2183 |
} |
e99d9a03c0f5
7061225: os::print_cpu_info() should support os-specific data
jcoomes
parents:
9625
diff
changeset
|
2184 |
|
1 | 2185 |
void os::print_memory_info(outputStream* st) { |
2186 |
||
2187 |
st->print("Memory:"); |
|
2188 |
st->print(" %dk page", os::vm_page_size()>>10); |
|
2189 |
||
2190 |
// values in struct sysinfo are "unsigned long" |
|
2191 |
struct sysinfo si; |
|
2192 |
sysinfo(&si); |
|
2193 |
||
2194 |
st->print(", physical " UINT64_FORMAT "k", |
|
2195 |
os::physical_memory() >> 10); |
|
2196 |
st->print("(" UINT64_FORMAT "k free)", |
|
2197 |
os::available_memory() >> 10); |
|
2198 |
st->print(", swap " UINT64_FORMAT "k", |
|
2199 |
((jlong)si.totalswap * si.mem_unit) >> 10); |
|
2200 |
st->print("(" UINT64_FORMAT "k free)", |
|
2201 |
((jlong)si.freeswap * si.mem_unit) >> 10); |
|
2202 |
st->cr(); |
|
2203 |
} |
|
2204 |
||
12735
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2205 |
void os::pd_print_cpu_info(outputStream* st) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2206 |
st->print("\n/proc/cpuinfo:\n"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2207 |
if (!_print_ascii_file("/proc/cpuinfo", st)) { |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2208 |
st->print(" <Not Available>"); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2209 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2210 |
st->cr(); |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2211 |
} |
3e2e491f4f69
7165755: OS Information much longer on linux than other platforms
nloodin
parents:
12116
diff
changeset
|
2212 |
|
1 | 2213 |
// Taken from /usr/include/bits/siginfo.h Supposed to be architecture specific |
2214 |
// but they're the same for all the linux arch that we support |
|
2215 |
// and they're the same for solaris but there's no common place to put this. |
|
2216 |
const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR", |
|
2217 |
"ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG", |
|
2218 |
"ILL_COPROC", "ILL_BADSTK" }; |
|
2219 |
||
2220 |
const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV", |
|
2221 |
"FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES", |
|
2222 |
"FPE_FLTINV", "FPE_FLTSUB", "FPE_FLTDEN" }; |
|
2223 |
||
2224 |
const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" }; |
|
2225 |
||
2226 |
const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" }; |
|
2227 |
||
2228 |
void os::print_siginfo(outputStream* st, void* siginfo) { |
|
2229 |
st->print("siginfo:"); |
|
2230 |
||
2231 |
const int buflen = 100; |
|
2232 |
char buf[buflen]; |
|
2233 |
siginfo_t *si = (siginfo_t*)siginfo; |
|
2234 |
st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen)); |
|
2235 |
if (si->si_errno != 0 && strerror_r(si->si_errno, buf, buflen) == 0) { |
|
2236 |
st->print("si_errno=%s", buf); |
|
2237 |
} else { |
|
2238 |
st->print("si_errno=%d", si->si_errno); |
|
2239 |
} |
|
2240 |
const int c = si->si_code; |
|
2241 |
assert(c > 0, "unexpected si_code"); |
|
2242 |
switch (si->si_signo) { |
|
2243 |
case SIGILL: |
|
2244 |
st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]); |
|
2245 |
st->print(", si_addr=" PTR_FORMAT, si->si_addr); |
|
2246 |
break; |
|
2247 |
case SIGFPE: |
|
2248 |
st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]); |
|
2249 |
st->print(", si_addr=" PTR_FORMAT, si->si_addr); |
|
2250 |
break; |
|
2251 |
case SIGSEGV: |
|
2252 |
st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]); |
|
2253 |
st->print(", si_addr=" PTR_FORMAT, si->si_addr); |
|
2254 |
break; |
|
2255 |
case SIGBUS: |
|
2256 |
st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]); |
|
2257 |
st->print(", si_addr=" PTR_FORMAT, si->si_addr); |
|
2258 |
break; |
|
2259 |
default: |
|
2260 |
st->print(", si_code=%d", si->si_code); |
|
2261 |
// no si_addr |
|
2262 |
} |
|
2263 |
||
2264 |
if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) && |
|
2265 |
UseSharedSpaces) { |
|
2266 |
FileMapInfo* mapinfo = FileMapInfo::current_info(); |
|
2267 |
if (mapinfo->is_in_shared_space(si->si_addr)) { |
|
2268 |
st->print("\n\nError accessing class data sharing archive." \ |
|
2269 |
" Mapped file inaccessible during execution, " \ |
|
2270 |
" possible disk/network problem."); |
|
2271 |
} |
|
2272 |
} |
|
2273 |
st->cr(); |
|
2274 |
} |
|
2275 |
||
2276 |
||
2277 |
static void print_signal_handler(outputStream* st, int sig, |
|
2278 |
char* buf, size_t buflen); |
|
2279 |
||
2280 |
void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) { |
|
2281 |
st->print_cr("Signal Handlers:"); |
|
2282 |
print_signal_handler(st, SIGSEGV, buf, buflen); |
|
2283 |
print_signal_handler(st, SIGBUS , buf, buflen); |
|
2284 |
print_signal_handler(st, SIGFPE , buf, buflen); |
|
2285 |
print_signal_handler(st, SIGPIPE, buf, buflen); |
|
2286 |
print_signal_handler(st, SIGXFSZ, buf, buflen); |
|
2287 |
print_signal_handler(st, SIGILL , buf, buflen); |
|
2288 |
print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen); |
|
2289 |
print_signal_handler(st, SR_signum, buf, buflen); |
|
2290 |
print_signal_handler(st, SHUTDOWN1_SIGNAL, buf, buflen); |
|
2291 |
print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen); |
|
2292 |
print_signal_handler(st, SHUTDOWN3_SIGNAL , buf, buflen); |
|
2293 |
print_signal_handler(st, BREAK_SIGNAL, buf, buflen); |
|
2294 |
} |
|
2295 |
||
2296 |
static char saved_jvm_path[MAXPATHLEN] = {0}; |
|
2297 |
||
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
2298 |
// Find the full path to the current module, libjvm.so |
5922 | 2299 |
void os::jvm_path(char *buf, jint buflen) { |
1 | 2300 |
// Error checking. |
5922 | 2301 |
if (buflen < MAXPATHLEN) { |
1 | 2302 |
assert(false, "must use a large-enough buffer"); |
2303 |
buf[0] = '\0'; |
|
2304 |
return; |
|
2305 |
} |
|
2306 |
// Lazy resolve the path to current module. |
|
2307 |
if (saved_jvm_path[0] != 0) { |
|
2308 |
strcpy(buf, saved_jvm_path); |
|
2309 |
return; |
|
2310 |
} |
|
2311 |
||
2312 |
char dli_fname[MAXPATHLEN]; |
|
2313 |
bool ret = dll_address_to_library_name( |
|
2314 |
CAST_FROM_FN_PTR(address, os::jvm_path), |
|
2315 |
dli_fname, sizeof(dli_fname), NULL); |
|
2316 |
assert(ret != 0, "cannot locate libjvm"); |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2317 |
char *rp = realpath(dli_fname, buf); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2318 |
if (rp == NULL) |
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1664
diff
changeset
|
2319 |
return; |
1 | 2320 |
|
8476
7e34c2d4cf9b
7022037: Pause when exiting if debugger is attached on windows
sla
parents:
8119
diff
changeset
|
2321 |
if (Arguments::created_by_gamma_launcher()) { |
1 | 2322 |
// Support for the gamma launcher. Typical value for buf is |
2323 |
// "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so". If "/jre/lib/" appears at |
|
2324 |
// the right place in the string, then assume we are installed in a JDK and |
|
2325 |
// we're done. Otherwise, check for a JAVA_HOME environment variable and fix |
|
2326 |
// up the path so it looks like libjvm.so is installed there (append a |
|
2327 |
// fake suffix hotspot/libjvm.so). |
|
2328 |
const char *p = buf + strlen(buf) - 1; |
|
2329 |
for (int count = 0; p > buf && count < 5; ++count) { |
|
2330 |
for (--p; p > buf && *p != '/'; --p) |
|
2331 |
/* empty */ ; |
|
2332 |
} |
|
2333 |
||
2334 |
if (strncmp(p, "/jre/lib/", 9) != 0) { |
|
2335 |
// Look for JAVA_HOME in the environment. |
|
2336 |
char* java_home_var = ::getenv("JAVA_HOME"); |
|
2337 |
if (java_home_var != NULL && java_home_var[0] != 0) { |
|
5922 | 2338 |
char* jrelib_p; |
2339 |
int len; |
|
2340 |
||
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
2341 |
// Check the current module name "libjvm.so". |
1 | 2342 |
p = strrchr(buf, '/'); |
2343 |
assert(strstr(p, "/libjvm") == p, "invalid library name"); |
|
2344 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2345 |
rp = realpath(java_home_var, buf); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2346 |
if (rp == NULL) |
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1664
diff
changeset
|
2347 |
return; |
5922 | 2348 |
|
2349 |
// determine if this is a legacy image or modules image |
|
2350 |
// modules image doesn't have "jre" subdirectory |
|
2351 |
len = strlen(buf); |
|
2352 |
jrelib_p = buf + len; |
|
2353 |
snprintf(jrelib_p, buflen-len, "/jre/lib/%s", cpu_arch); |
|
2354 |
if (0 != access(buf, F_OK)) { |
|
2355 |
snprintf(jrelib_p, buflen-len, "/lib/%s", cpu_arch); |
|
2356 |
} |
|
2357 |
||
1 | 2358 |
if (0 == access(buf, F_OK)) { |
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
2359 |
// Use current module name "libjvm.so" |
5922 | 2360 |
len = strlen(buf); |
15096
3db45569f8c0
8005044: remove crufty '_g' support from HS runtime code
dcubed
parents:
14633
diff
changeset
|
2361 |
snprintf(buf + len, buflen-len, "/hotspot/libjvm.so"); |
1 | 2362 |
} else { |
2363 |
// Go back to path of .so |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2364 |
rp = realpath(dli_fname, buf); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2365 |
if (rp == NULL) |
1889
24b003a6fe46
6781583: Hotspot build fails on linux 64 bit platform with gcc 4.3.2
xlu
parents:
1664
diff
changeset
|
2366 |
return; |
1 | 2367 |
} |
2368 |
} |
|
2369 |
} |
|
2370 |
} |
|
2371 |
||
2372 |
strcpy(saved_jvm_path, buf); |
|
2373 |
} |
|
2374 |
||
2375 |
void os::print_jni_name_prefix_on(outputStream* st, int args_size) { |
|
2376 |
// no prefix required, not even "_" |
|
2377 |
} |
|
2378 |
||
2379 |
void os::print_jni_name_suffix_on(outputStream* st, int args_size) { |
|
2380 |
// no suffix required |
|
2381 |
} |
|
2382 |
||
2383 |
//////////////////////////////////////////////////////////////////////////////// |
|
2384 |
// sun.misc.Signal support |
|
2385 |
||
2386 |
static volatile jint sigint_count = 0; |
|
2387 |
||
2388 |
static void |
|
2389 |
UserHandler(int sig, void *siginfo, void *context) { |
|
2390 |
// 4511530 - sem_post is serialized and handled by the manager thread. When |
|
2391 |
// the program is interrupted by Ctrl-C, SIGINT is sent to every thread. We |
|
2392 |
// don't want to flood the manager thread with sem_post requests. |
|
2393 |
if (sig == SIGINT && Atomic::add(1, &sigint_count) > 1) |
|
2394 |
return; |
|
2395 |
||
2396 |
// Ctrl-C is pressed during error reporting, likely because the error |
|
2397 |
// handler fails to abort. Let VM die immediately. |
|
2398 |
if (sig == SIGINT && is_error_reported()) { |
|
2399 |
os::die(); |
|
2400 |
} |
|
2401 |
||
2402 |
os::signal_notify(sig); |
|
2403 |
} |
|
2404 |
||
2405 |
void* os::user_handler() { |
|
2406 |
return CAST_FROM_FN_PTR(void*, UserHandler); |
|
2407 |
} |
|
2408 |
||
2409 |
extern "C" { |
|
2410 |
typedef void (*sa_handler_t)(int); |
|
2411 |
typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); |
|
2412 |
} |
|
2413 |
||
2414 |
void* os::signal(int signal_number, void* handler) { |
|
2415 |
struct sigaction sigAct, oldSigAct; |
|
2416 |
||
2417 |
sigfillset(&(sigAct.sa_mask)); |
|
2418 |
sigAct.sa_flags = SA_RESTART|SA_SIGINFO; |
|
2419 |
sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler); |
|
2420 |
||
2421 |
if (sigaction(signal_number, &sigAct, &oldSigAct)) { |
|
2422 |
// -1 means registration failed |
|
2423 |
return (void *)-1; |
|
2424 |
} |
|
2425 |
||
2426 |
return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler); |
|
2427 |
} |
|
2428 |
||
2429 |
void os::signal_raise(int signal_number) { |
|
2430 |
::raise(signal_number); |
|
2431 |
} |
|
2432 |
||
2433 |
/* |
|
2434 |
* The following code is moved from os.cpp for making this |
|
2435 |
* code platform specific, which it is by its very nature. |
|
2436 |
*/ |
|
2437 |
||
2438 |
// Will be modified when max signal is changed to be dynamic |
|
2439 |
int os::sigexitnum_pd() { |
|
2440 |
return NSIG; |
|
2441 |
} |
|
2442 |
||
2443 |
// a counter for each possible signal value |
|
2444 |
static volatile jint pending_signals[NSIG+1] = { 0 }; |
|
2445 |
||
2446 |
// Linux(POSIX) specific hand shaking semaphore. |
|
2447 |
static sem_t sig_sem; |
|
2448 |
||
2449 |
void os::signal_init_pd() { |
|
2450 |
// Initialize signal structures |
|
2451 |
::memset((void*)pending_signals, 0, sizeof(pending_signals)); |
|
2452 |
||
2453 |
// Initialize signal semaphore |
|
2454 |
::sem_init(&sig_sem, 0, 0); |
|
2455 |
} |
|
2456 |
||
2457 |
void os::signal_notify(int sig) { |
|
2458 |
Atomic::inc(&pending_signals[sig]); |
|
2459 |
::sem_post(&sig_sem); |
|
2460 |
} |
|
2461 |
||
2462 |
static int check_pending_signals(bool wait) { |
|
2463 |
Atomic::store(0, &sigint_count); |
|
2464 |
for (;;) { |
|
2465 |
for (int i = 0; i < NSIG + 1; i++) { |
|
2466 |
jint n = pending_signals[i]; |
|
2467 |
if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) { |
|
2468 |
return i; |
|
2469 |
} |
|
2470 |
} |
|
2471 |
if (!wait) { |
|
2472 |
return -1; |
|
2473 |
} |
|
2474 |
JavaThread *thread = JavaThread::current(); |
|
2475 |
ThreadBlockInVM tbivm(thread); |
|
2476 |
||
2477 |
bool threadIsSuspended; |
|
2478 |
do { |
|
2479 |
thread->set_suspend_equivalent(); |
|
2480 |
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() |
|
2481 |
::sem_wait(&sig_sem); |
|
2482 |
||
2483 |
// were we externally suspended while we were waiting? |
|
2484 |
threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); |
|
2485 |
if (threadIsSuspended) { |
|
2486 |
// |
|
2487 |
// The semaphore has been incremented, but while we were waiting |
|
2488 |
// another thread suspended us. We don't want to continue running |
|
2489 |
// while suspended because that would surprise the thread that |
|
2490 |
// suspended us. |
|
2491 |
// |
|
2492 |
::sem_post(&sig_sem); |
|
2493 |
||
2494 |
thread->java_suspend_self(); |
|
2495 |
} |
|
2496 |
} while (threadIsSuspended); |
|
2497 |
} |
|
2498 |
} |
|
2499 |
||
2500 |
int os::signal_lookup() { |
|
2501 |
return check_pending_signals(false); |
|
2502 |
} |
|
2503 |
||
2504 |
int os::signal_wait() { |
|
2505 |
return check_pending_signals(true); |
|
2506 |
} |
|
2507 |
||
2508 |
//////////////////////////////////////////////////////////////////////////////// |
|
2509 |
// Virtual Memory |
|
2510 |
||
2511 |
int os::vm_page_size() { |
|
2512 |
// Seems redundant as all get out |
|
2513 |
assert(os::Linux::page_size() != -1, "must call os::init"); |
|
2514 |
return os::Linux::page_size(); |
|
2515 |
} |
|
2516 |
||
2517 |
// Solaris allocates memory by pages. |
|
2518 |
int os::vm_allocation_granularity() { |
|
2519 |
assert(os::Linux::page_size() != -1, "must call os::init"); |
|
2520 |
return os::Linux::page_size(); |
|
2521 |
} |
|
2522 |
||
2523 |
// Rationale behind this function: |
|
2524 |
// current (Mon Apr 25 20:12:18 MSD 2005) oprofile drops samples without executable |
|
2525 |
// mapping for address (see lookup_dcookie() in the kernel module), thus we cannot get |
|
2526 |
// samples for JITted code. Here we create private executable mapping over the code cache |
|
2527 |
// and then we can use standard (well, almost, as mapping can change) way to provide |
|
2528 |
// info for the reporting script by storing timestamp and location of symbol |
|
2529 |
void linux_wrap_code(char* base, size_t size) { |
|
2530 |
static volatile jint cnt = 0; |
|
2531 |
||
2532 |
if (!UseOprofile) { |
|
2533 |
return; |
|
2534 |
} |
|
2535 |
||
5410
c4b979417733
6944822: Fix for 6938627 exposes problem with hard-coded buffer sizes
coleenp
parents:
5237
diff
changeset
|
2536 |
char buf[PATH_MAX+1]; |
1 | 2537 |
int num = Atomic::add(1, &cnt); |
2538 |
||
5237
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5090
diff
changeset
|
2539 |
snprintf(buf, sizeof(buf), "%s/hs-vm-%d-%d", |
aab592fd4f44
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
5090
diff
changeset
|
2540 |
os::get_temp_directory(), os::current_process_id(), num); |
1 | 2541 |
unlink(buf); |
2542 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2543 |
int fd = ::open(buf, O_CREAT | O_RDWR, S_IRWXU); |
1 | 2544 |
|
2545 |
if (fd != -1) { |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2546 |
off_t rv = ::lseek(fd, size-2, SEEK_SET); |
1 | 2547 |
if (rv != (off_t)-1) { |
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2548 |
if (::write(fd, "", 1) == 1) { |
1 | 2549 |
mmap(base, size, |
2550 |
PROT_READ|PROT_WRITE|PROT_EXEC, |
|
2551 |
MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, fd, 0); |
|
2552 |
} |
|
2553 |
} |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
2554 |
::close(fd); |
1 | 2555 |
unlink(buf); |
2556 |
} |
|
2557 |
} |
|
2558 |
||
2559 |
// NOTE: Linux kernel does not really reserve the pages for us. |
|
2560 |
// All it does is to check if there are enough free pages |
|
2561 |
// left at the time of mmap(). This could be a potential |
|
2562 |
// problem. |
|
13195 | 2563 |
bool os::pd_commit_memory(char* addr, size_t size, bool exec) { |
2268 | 2564 |
int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; |
2565 |
uintptr_t res = (uintptr_t) ::mmap(addr, size, prot, |
|
1 | 2566 |
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS, -1, 0); |
10494 | 2567 |
if (res != (uintptr_t) MAP_FAILED) { |
2568 |
if (UseNUMAInterleaving) { |
|
2569 |
numa_make_global(addr, size); |
|
2570 |
} |
|
2571 |
return true; |
|
2572 |
} |
|
2573 |
return false; |
|
1 | 2574 |
} |
2575 |
||
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2576 |
// Define MAP_HUGETLB here so we can build HotSpot on old systems. |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2577 |
#ifndef MAP_HUGETLB |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2578 |
#define MAP_HUGETLB 0x40000 |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2579 |
#endif |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2580 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2581 |
// Define MADV_HUGEPAGE here so we can build HotSpot on old systems. |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2582 |
#ifndef MADV_HUGEPAGE |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2583 |
#define MADV_HUGEPAGE 14 |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2584 |
#endif |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2585 |
|
13195 | 2586 |
bool os::pd_commit_memory(char* addr, size_t size, size_t alignment_hint, |
2268 | 2587 |
bool exec) { |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2588 |
if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2589 |
int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2590 |
uintptr_t res = |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2591 |
(uintptr_t) ::mmap(addr, size, prot, |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2592 |
MAP_PRIVATE|MAP_FIXED|MAP_ANONYMOUS|MAP_HUGETLB, |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2593 |
-1, 0); |
10494 | 2594 |
if (res != (uintptr_t) MAP_FAILED) { |
2595 |
if (UseNUMAInterleaving) { |
|
2596 |
numa_make_global(addr, size); |
|
2597 |
} |
|
2598 |
return true; |
|
2599 |
} |
|
10522
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2600 |
// Fall through and try to use small pages |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2601 |
} |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2602 |
|
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2603 |
if (commit_memory(addr, size, exec)) { |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2604 |
realign_memory(addr, size, alignment_hint); |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2605 |
return true; |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2606 |
} |
23830453e083
7087583: Hotspot fails to allocate heap with mmap(MAP_HUGETLB)
iveresov
parents:
10496
diff
changeset
|
2607 |
return false; |
1 | 2608 |
} |
2609 |
||
13195 | 2610 |
void os::pd_realign_memory(char *addr, size_t bytes, size_t alignment_hint) { |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2611 |
if (UseHugeTLBFS && alignment_hint > (size_t)vm_page_size()) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2612 |
// We don't check the return value: madvise(MADV_HUGEPAGE) may not |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2613 |
// be supported or the memory may already be backed by huge pages. |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2614 |
::madvise(addr, bytes, MADV_HUGEPAGE); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2615 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2616 |
} |
388 | 2617 |
|
13195 | 2618 |
void os::pd_free_memory(char *addr, size_t bytes, size_t alignment_hint) { |
12116
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2619 |
// This method works by doing an mmap over an existing mmaping and effectively discarding |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2620 |
// the existing pages. However it won't work for SHM-based large pages that cannot be |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2621 |
// uncommitted at all. We don't do anything in this case to avoid creating a segment with |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2622 |
// small pages on top of the SHM segment. This method always works for small pages, so we |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2623 |
// allow that in any case. |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2624 |
if (alignment_hint <= (size_t)os::vm_page_size() || !UseSHM) { |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2625 |
commit_memory(addr, bytes, alignment_hint, false); |
d81396ae8bf6
7151089: PS NUMA: NUMA allocator should not attempt to free pages when using SHM large pages
iveresov
parents:
11967
diff
changeset
|
2626 |
} |
388 | 2627 |
} |
2628 |
||
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2629 |
void os::numa_make_global(char *addr, size_t bytes) { |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2630 |
Linux::numa_interleave_memory(addr, bytes); |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2631 |
} |
388 | 2632 |
|
2633 |
void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { |
|
2634 |
Linux::numa_tonode_memory(addr, bytes, lgrp_hint); |
|
2635 |
} |
|
2636 |
||
2637 |
bool os::numa_topology_changed() { return false; } |
|
2638 |
||
2639 |
size_t os::numa_get_groups_num() { |
|
2640 |
int max_node = Linux::numa_max_node(); |
|
2641 |
return max_node > 0 ? max_node + 1 : 1; |
|
2642 |
} |
|
2643 |
||
2644 |
int os::numa_get_group_id() { |
|
2645 |
int cpu_id = Linux::sched_getcpu(); |
|
2646 |
if (cpu_id != -1) { |
|
2647 |
int lgrp_id = Linux::get_node_by_cpu(cpu_id); |
|
2648 |
if (lgrp_id != -1) { |
|
2649 |
return lgrp_id; |
|
2650 |
} |
|
1 | 2651 |
} |
2652 |
return 0; |
|
2653 |
} |
|
2654 |
||
388 | 2655 |
size_t os::numa_get_leaf_groups(int *ids, size_t size) { |
2656 |
for (size_t i = 0; i < size; i++) { |
|
2657 |
ids[i] = i; |
|
2658 |
} |
|
2659 |
return size; |
|
2660 |
} |
|
2661 |
||
1 | 2662 |
bool os::get_page_info(char *start, page_info* info) { |
2663 |
return false; |
|
2664 |
} |
|
2665 |
||
2666 |
char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { |
|
2667 |
return end; |
|
2668 |
} |
|
2669 |
||
10239
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2670 |
|
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2671 |
int os::Linux::sched_getcpu_syscall(void) { |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2672 |
unsigned int cpu; |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2673 |
int retval = -1; |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2674 |
|
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2675 |
#if defined(IA32) |
10496
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2676 |
# ifndef SYS_getcpu |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2677 |
# define SYS_getcpu 318 |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2678 |
# endif |
10239
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2679 |
retval = syscall(SYS_getcpu, &cpu, NULL, NULL); |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2680 |
#elif defined(AMD64) |
10496
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2681 |
// Unfortunately we have to bring all these macros here from vsyscall.h |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2682 |
// to be able to compile on old linuxes. |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2683 |
# define __NR_vgetcpu 2 |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2684 |
# define VSYSCALL_START (-10UL << 20) |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2685 |
# define VSYSCALL_SIZE 1024 |
b209db6147cf
7082645: Hotspot doesn't compile on old linuxes after 7060836
iveresov
parents:
10494
diff
changeset
|
2686 |
# define VSYSCALL_ADDR(vsyscall_nr) (VSYSCALL_START+VSYSCALL_SIZE*(vsyscall_nr)) |
10239
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2687 |
typedef long (*vgetcpu_t)(unsigned int *cpu, unsigned int *node, unsigned long *tcache); |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2688 |
vgetcpu_t vgetcpu = (vgetcpu_t)VSYSCALL_ADDR(__NR_vgetcpu); |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2689 |
retval = vgetcpu(&cpu, NULL, NULL); |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2690 |
#endif |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2691 |
|
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2692 |
return (retval == -1) ? retval : cpu; |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2693 |
} |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2694 |
|
8106 | 2695 |
// Something to do with the numa-aware allocator needs these symbols |
2696 |
extern "C" JNIEXPORT void numa_warn(int number, char *where, ...) { } |
|
2697 |
extern "C" JNIEXPORT void numa_error(char *where) { } |
|
2698 |
extern "C" JNIEXPORT int fork1() { return fork(); } |
|
388 | 2699 |
|
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2700 |
|
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2701 |
// If we are running with libnuma version > 2, then we should |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2702 |
// be trying to use symbols with versions 1.1 |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2703 |
// If we are running with earlier version, which did not have symbol versions, |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2704 |
// we should use the base version. |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2705 |
void* os::Linux::libnuma_dlsym(void* handle, const char *name) { |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2706 |
void *f = dlvsym(handle, name, "libnuma_1.1"); |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2707 |
if (f == NULL) { |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2708 |
f = dlsym(handle, name); |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2709 |
} |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2710 |
return f; |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2711 |
} |
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2712 |
|
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2713 |
bool os::Linux::libnuma_init() { |
388 | 2714 |
// sched_getcpu() should be in libc. |
2715 |
set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, |
|
2716 |
dlsym(RTLD_DEFAULT, "sched_getcpu"))); |
|
2717 |
||
10239
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2718 |
// If it's not, try a direct syscall. |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2719 |
if (sched_getcpu() == -1) |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2720 |
set_sched_getcpu(CAST_TO_FN_PTR(sched_getcpu_func_t, (void*)&sched_getcpu_syscall)); |
c7af330d33d9
7060836: RHEL 5.5 and 5.6 should support UseNUMA
iveresov
parents:
10238
diff
changeset
|
2721 |
|
388 | 2722 |
if (sched_getcpu() != -1) { // Does it work? |
975
ad7da100aa6a
6720130: NUMA allocator: The linux version should search for libnuma.so.1
iveresov
parents:
745
diff
changeset
|
2723 |
void *handle = dlopen("libnuma.so.1", RTLD_LAZY); |
388 | 2724 |
if (handle != NULL) { |
2725 |
set_numa_node_to_cpus(CAST_TO_FN_PTR(numa_node_to_cpus_func_t, |
|
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2726 |
libnuma_dlsym(handle, "numa_node_to_cpus"))); |
388 | 2727 |
set_numa_max_node(CAST_TO_FN_PTR(numa_max_node_func_t, |
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2728 |
libnuma_dlsym(handle, "numa_max_node"))); |
388 | 2729 |
set_numa_available(CAST_TO_FN_PTR(numa_available_func_t, |
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2730 |
libnuma_dlsym(handle, "numa_available"))); |
388 | 2731 |
set_numa_tonode_memory(CAST_TO_FN_PTR(numa_tonode_memory_func_t, |
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2732 |
libnuma_dlsym(handle, "numa_tonode_memory"))); |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2733 |
set_numa_interleave_memory(CAST_TO_FN_PTR(numa_interleave_memory_func_t, |
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2734 |
libnuma_dlsym(handle, "numa_interleave_memory"))); |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2735 |
|
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2736 |
|
388 | 2737 |
if (numa_available() != -1) { |
2753
1e9bbaae891b
6840196: NUMA allocator: crash in fastdebug during startup on Linux
iveresov
parents:
2751
diff
changeset
|
2738 |
set_numa_all_nodes((unsigned long*)libnuma_dlsym(handle, "numa_all_nodes")); |
388 | 2739 |
// Create a cpu -> node mapping |
13195 | 2740 |
_cpu_to_node = new (ResourceObj::C_HEAP, mtInternal) GrowableArray<int>(0, true); |
388 | 2741 |
rebuild_cpu_to_node_map(); |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2742 |
return true; |
388 | 2743 |
} |
2744 |
} |
|
2745 |
} |
|
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2746 |
return false; |
388 | 2747 |
} |
2748 |
||
2749 |
// rebuild_cpu_to_node_map() constructs a table mapping cpud id to node id. |
|
2750 |
// The table is later used in get_node_by_cpu(). |
|
2751 |
void os::Linux::rebuild_cpu_to_node_map() { |
|
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2752 |
const size_t NCPUS = 32768; // Since the buffer size computation is very obscure |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2753 |
// in libnuma (possible values are starting from 16, |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2754 |
// and continuing up with every other power of 2, but less |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2755 |
// than the maximum number of CPUs supported by kernel), and |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2756 |
// is a subject to change (in libnuma version 2 the requirements |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2757 |
// are more reasonable) we'll just hardcode the number they use |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2758 |
// in the library. |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2759 |
const size_t BitsPerCLong = sizeof(long) * CHAR_BIT; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2760 |
|
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2761 |
size_t cpu_num = os::active_processor_count(); |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2762 |
size_t cpu_map_size = NCPUS / BitsPerCLong; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2763 |
size_t cpu_map_valid_size = |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2764 |
MIN2((cpu_num + BitsPerCLong - 1) / BitsPerCLong, cpu_map_size); |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2765 |
|
388 | 2766 |
cpu_to_node()->clear(); |
2767 |
cpu_to_node()->at_grow(cpu_num - 1); |
|
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2768 |
size_t node_num = numa_get_groups_num(); |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2769 |
|
13195 | 2770 |
unsigned long *cpu_map = NEW_C_HEAP_ARRAY(unsigned long, cpu_map_size, mtInternal); |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2771 |
for (size_t i = 0; i < node_num; i++) { |
388 | 2772 |
if (numa_node_to_cpus(i, cpu_map, cpu_map_size * sizeof(unsigned long)) != -1) { |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2773 |
for (size_t j = 0; j < cpu_map_valid_size; j++) { |
388 | 2774 |
if (cpu_map[j] != 0) { |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2775 |
for (size_t k = 0; k < BitsPerCLong; k++) { |
388 | 2776 |
if (cpu_map[j] & (1UL << k)) { |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2777 |
cpu_to_node()->at_put(j * BitsPerCLong + k, i); |
388 | 2778 |
} |
2779 |
} |
|
2780 |
} |
|
2781 |
} |
|
2782 |
} |
|
2783 |
} |
|
13195 | 2784 |
FREE_C_HEAP_ARRAY(unsigned long, cpu_map, mtInternal); |
388 | 2785 |
} |
2786 |
||
2787 |
int os::Linux::get_node_by_cpu(int cpu_id) { |
|
2788 |
if (cpu_to_node() != NULL && cpu_id >= 0 && cpu_id < cpu_to_node()->length()) { |
|
2789 |
return cpu_to_node()->at(cpu_id); |
|
2790 |
} |
|
2791 |
return -1; |
|
2792 |
} |
|
2793 |
||
2794 |
GrowableArray<int>* os::Linux::_cpu_to_node; |
|
2795 |
os::Linux::sched_getcpu_func_t os::Linux::_sched_getcpu; |
|
2796 |
os::Linux::numa_node_to_cpus_func_t os::Linux::_numa_node_to_cpus; |
|
2797 |
os::Linux::numa_max_node_func_t os::Linux::_numa_max_node; |
|
2798 |
os::Linux::numa_available_func_t os::Linux::_numa_available; |
|
2799 |
os::Linux::numa_tonode_memory_func_t os::Linux::_numa_tonode_memory; |
|
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2800 |
os::Linux::numa_interleave_memory_func_t os::Linux::_numa_interleave_memory; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
2801 |
unsigned long* os::Linux::_numa_all_nodes; |
388 | 2802 |
|
13195 | 2803 |
bool os::pd_uncommit_memory(char* addr, size_t size) { |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2804 |
uintptr_t res = (uintptr_t) ::mmap(addr, size, PROT_NONE, |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2805 |
MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE|MAP_ANONYMOUS, -1, 0); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
2806 |
return res != (uintptr_t) MAP_FAILED; |
1 | 2807 |
} |
2808 |
||
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2809 |
// Linux uses a growable mapping for the stack, and if the mapping for |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2810 |
// the stack guard pages is not removed when we detach a thread the |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2811 |
// stack cannot grow beyond the pages where the stack guard was |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2812 |
// mapped. If at some point later in the process the stack expands to |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2813 |
// that point, the Linux kernel cannot expand the stack any further |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2814 |
// because the guard pages are in the way, and a segfault occurs. |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2815 |
// |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2816 |
// However, it's essential not to split the stack region by unmapping |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2817 |
// a region (leaving a hole) that's already part of the stack mapping, |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2818 |
// so if the stack mapping has already grown beyond the guard pages at |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2819 |
// the time we create them, we have to truncate the stack mapping. |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2820 |
// So, we need to know the extent of the stack mapping when |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2821 |
// create_stack_guard_pages() is called. |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2822 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2823 |
// Find the bounds of the stack mapping. Return true for success. |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2824 |
// |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2825 |
// We only need this for stacks that are growable: at the time of |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2826 |
// writing thread stacks don't use growable mappings (i.e. those |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2827 |
// creeated with MAP_GROWSDOWN), and aren't marked "[stack]", so this |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2828 |
// only applies to the main thread. |
9125
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2829 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2830 |
static |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2831 |
bool get_stack_bounds(uintptr_t *bottom, uintptr_t *top) { |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2832 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2833 |
char buf[128]; |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2834 |
int fd, sz; |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2835 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2836 |
if ((fd = ::open("/proc/self/maps", O_RDONLY)) < 0) { |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2837 |
return false; |
9125
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2838 |
} |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2839 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2840 |
const char kw[] = "[stack]"; |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2841 |
const int kwlen = sizeof(kw)-1; |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2842 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2843 |
// Address part of /proc/self/maps couldn't be more than 128 bytes |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2844 |
while ((sz = os::get_line_chars(fd, buf, sizeof(buf))) > 0) { |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2845 |
if (sz > kwlen && ::memcmp(buf+sz-kwlen, kw, kwlen) == 0) { |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2846 |
// Extract addresses |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2847 |
if (sscanf(buf, "%" SCNxPTR "-%" SCNxPTR, bottom, top) == 2) { |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2848 |
uintptr_t sp = (uintptr_t) __builtin_frame_address(0); |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2849 |
if (sp >= *bottom && sp <= *top) { |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2850 |
::close(fd); |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2851 |
return true; |
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2852 |
} |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2853 |
} |
9125
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2854 |
} |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2855 |
} |
9125
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2856 |
|
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2857 |
::close(fd); |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2858 |
return false; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2859 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2860 |
|
9125
3b9a527cd492
7017193: Small memory leak in get_stack_bounds os::create_stack_guard_pages
dsamersoff
parents:
8476
diff
changeset
|
2861 |
|
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2862 |
// If the (growable) stack mapping already extends beyond the point |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2863 |
// where we're going to put our guard pages, truncate the mapping at |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2864 |
// that point by munmap()ping it. This ensures that when we later |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2865 |
// munmap() the guard pages we don't leave a hole in the stack |
6420
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2866 |
// mapping. This only affects the main/initial thread, but guard |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2867 |
// against future OS changes |
13195 | 2868 |
bool os::pd_create_stack_guard_pages(char* addr, size_t size) { |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2869 |
uintptr_t stack_extent, stack_base; |
6420
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2870 |
bool chk_bounds = NOT_DEBUG(os::Linux::is_initial_thread()) DEBUG_ONLY(true); |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2871 |
if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) { |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2872 |
assert(os::Linux::is_initial_thread(), |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2873 |
"growable stack in non-initial thread"); |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2874 |
if (stack_extent < (uintptr_t)addr) |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2875 |
::munmap((void*)stack_extent, (uintptr_t)addr - stack_extent); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2876 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2877 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2878 |
return os::commit_memory(addr, size); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2879 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2880 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2881 |
// If this is a growable mapping, remove the guard pages entirely by |
6420
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2882 |
// munmap()ping them. If not, just call uncommit_memory(). This only |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2883 |
// affects the main/initial thread, but guard against future OS changes |
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2884 |
bool os::remove_stack_guard_pages(char* addr, size_t size) { |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2885 |
uintptr_t stack_extent, stack_base; |
6420
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2886 |
bool chk_bounds = NOT_DEBUG(os::Linux::is_initial_thread()) DEBUG_ONLY(true); |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2887 |
if (chk_bounds && get_stack_bounds(&stack_extent, &stack_base)) { |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2888 |
assert(os::Linux::is_initial_thread(), |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2889 |
"growable stack in non-initial thread"); |
a4205fed5b18
6978641: Fix for 6929067 introduces additional overhead in thread creation/termination paths
dholmes
parents:
6176
diff
changeset
|
2890 |
|
5085
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2891 |
return ::munmap(addr, size) == 0; |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2892 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2893 |
|
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2894 |
return os::uncommit_memory(addr, size); |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2895 |
} |
4f0c435f8c3c
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
4493
diff
changeset
|
2896 |
|
1 | 2897 |
static address _highest_vm_reserved_address = NULL; |
2898 |
||
2899 |
// If 'fixed' is true, anon_mmap() will attempt to reserve anonymous memory |
|
2900 |
// at 'requested_addr'. If there are existing memory mappings at the same |
|
2901 |
// location, however, they will be overwritten. If 'fixed' is false, |
|
2902 |
// 'requested_addr' is only treated as a hint, the return value may or |
|
2903 |
// may not start from the requested address. Unlike Linux mmap(), this |
|
2904 |
// function returns NULL to indicate failure. |
|
2905 |
static char* anon_mmap(char* requested_addr, size_t bytes, bool fixed) { |
|
2906 |
char * addr; |
|
2907 |
int flags; |
|
2908 |
||
2909 |
flags = MAP_PRIVATE | MAP_NORESERVE | MAP_ANONYMOUS; |
|
2910 |
if (fixed) { |
|
2911 |
assert((uintptr_t)requested_addr % os::Linux::page_size() == 0, "unaligned address"); |
|
2912 |
flags |= MAP_FIXED; |
|
2913 |
} |
|
2914 |
||
2268 | 2915 |
// Map uncommitted pages PROT_READ and PROT_WRITE, change access |
2916 |
// to PROT_EXEC if executable when we commit the page. |
|
2917 |
addr = (char*)::mmap(requested_addr, bytes, PROT_READ|PROT_WRITE, |
|
1 | 2918 |
flags, -1, 0); |
2919 |
||
2920 |
if (addr != MAP_FAILED) { |
|
2921 |
// anon_mmap() should only get called during VM initialization, |
|
2922 |
// don't need lock (actually we can skip locking even it can be called |
|
2923 |
// from multiple threads, because _highest_vm_reserved_address is just a |
|
2924 |
// hint about the upper limit of non-stack memory regions.) |
|
2925 |
if ((address)addr + bytes > _highest_vm_reserved_address) { |
|
2926 |
_highest_vm_reserved_address = (address)addr + bytes; |
|
2927 |
} |
|
2928 |
} |
|
2929 |
||
2930 |
return addr == MAP_FAILED ? NULL : addr; |
|
2931 |
} |
|
2932 |
||
2933 |
// Don't update _highest_vm_reserved_address, because there might be memory |
|
2934 |
// regions above addr + size. If so, releasing a memory region only creates |
|
2935 |
// a hole in the address space, it doesn't help prevent heap-stack collision. |
|
2936 |
// |
|
2937 |
static int anon_munmap(char * addr, size_t size) { |
|
2938 |
return ::munmap(addr, size) == 0; |
|
2939 |
} |
|
2940 |
||
13195 | 2941 |
char* os::pd_reserve_memory(size_t bytes, char* requested_addr, |
1 | 2942 |
size_t alignment_hint) { |
2943 |
return anon_mmap(requested_addr, bytes, (requested_addr != NULL)); |
|
2944 |
} |
|
2945 |
||
13195 | 2946 |
bool os::pd_release_memory(char* addr, size_t size) { |
1 | 2947 |
return anon_munmap(addr, size); |
2948 |
} |
|
2949 |
||
2950 |
static address highest_vm_reserved_address() { |
|
2951 |
return _highest_vm_reserved_address; |
|
2952 |
} |
|
2953 |
||
2954 |
static bool linux_mprotect(char* addr, size_t size, int prot) { |
|
2955 |
// Linux wants the mprotect address argument to be page aligned. |
|
2956 |
char* bottom = (char*)align_size_down((intptr_t)addr, os::Linux::page_size()); |
|
2957 |
||
2958 |
// According to SUSv3, mprotect() should only be used with mappings |
|
2959 |
// established by mmap(), and mmap() always maps whole pages. Unaligned |
|
2960 |
// 'addr' likely indicates problem in the VM (e.g. trying to change |
|
2961 |
// protection of malloc'ed or statically allocated memory). Check the |
|
2962 |
// caller if you hit this assert. |
|
2963 |
assert(addr == bottom, "sanity check"); |
|
2964 |
||
2965 |
size = align_size_up(pointer_delta(addr, bottom, 1) + size, os::Linux::page_size()); |
|
2966 |
return ::mprotect(bottom, size, prot) == 0; |
|
2967 |
} |
|
2968 |
||
823
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2969 |
// Set protections specified |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2970 |
bool os::protect_memory(char* addr, size_t bytes, ProtType prot, |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2971 |
bool is_committed) { |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2972 |
unsigned int p = 0; |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2973 |
switch (prot) { |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2974 |
case MEM_PROT_NONE: p = PROT_NONE; break; |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2975 |
case MEM_PROT_READ: p = PROT_READ; break; |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2976 |
case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break; |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2977 |
case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break; |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2978 |
default: |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2979 |
ShouldNotReachHere(); |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2980 |
} |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2981 |
// is_committed is unused. |
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
2982 |
return linux_mprotect(addr, bytes, p); |
1 | 2983 |
} |
2984 |
||
2985 |
bool os::guard_memory(char* addr, size_t size) { |
|
2986 |
return linux_mprotect(addr, size, PROT_NONE); |
|
2987 |
} |
|
2988 |
||
2989 |
bool os::unguard_memory(char* addr, size_t size) { |
|
1664
fc9ed50498fb
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
1615
diff
changeset
|
2990 |
return linux_mprotect(addr, size, PROT_READ|PROT_WRITE); |
1 | 2991 |
} |
2992 |
||
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2993 |
bool os::Linux::hugetlbfs_sanity_check(bool warn, size_t page_size) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2994 |
bool result = false; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2995 |
void *p = mmap (NULL, page_size, PROT_READ|PROT_WRITE, |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2996 |
MAP_ANONYMOUS|MAP_PRIVATE|MAP_HUGETLB, |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2997 |
-1, 0); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2998 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
2999 |
if (p != (void *) -1) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3000 |
// We don't know if this really is a huge page or not. |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3001 |
FILE *fp = fopen("/proc/self/maps", "r"); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3002 |
if (fp) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3003 |
while (!feof(fp)) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3004 |
char chars[257]; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3005 |
long x = 0; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3006 |
if (fgets(chars, sizeof(chars), fp)) { |
9625 | 3007 |
if (sscanf(chars, "%lx-%*x", &x) == 1 |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3008 |
&& x == (long)p) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3009 |
if (strstr (chars, "hugepage")) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3010 |
result = true; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3011 |
break; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3012 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3013 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3014 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3015 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3016 |
fclose(fp); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3017 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3018 |
munmap (p, page_size); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3019 |
if (result) |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3020 |
return true; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3021 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3022 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3023 |
if (warn) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3024 |
warning("HugeTLBFS is not supported by the operating system."); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3025 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3026 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3027 |
return result; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3028 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3029 |
|
8119
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3030 |
/* |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3031 |
* Set the coredump_filter bits to include largepages in core dump (bit 6) |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3032 |
* |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3033 |
* From the coredump_filter documentation: |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3034 |
* |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3035 |
* - (bit 0) anonymous private memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3036 |
* - (bit 1) anonymous shared memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3037 |
* - (bit 2) file-backed private memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3038 |
* - (bit 3) file-backed shared memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3039 |
* - (bit 4) ELF header pages in file-backed private memory areas (it is |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3040 |
* effective only if the bit 2 is cleared) |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3041 |
* - (bit 5) hugetlb private memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3042 |
* - (bit 6) hugetlb shared memory |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3043 |
*/ |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3044 |
static void set_coredump_filter(void) { |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3045 |
FILE *f; |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3046 |
long cdm; |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3047 |
|
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3048 |
if ((f = fopen("/proc/self/coredump_filter", "r+")) == NULL) { |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3049 |
return; |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3050 |
} |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3051 |
|
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3052 |
if (fscanf(f, "%lx", &cdm) != 1) { |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3053 |
fclose(f); |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3054 |
return; |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3055 |
} |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3056 |
|
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3057 |
rewind(f); |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3058 |
|
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3059 |
if ((cdm & LARGEPAGES_BIT) == 0) { |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3060 |
cdm |= LARGEPAGES_BIT; |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3061 |
fprintf(f, "%#lx", cdm); |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3062 |
} |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3063 |
|
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3064 |
fclose(f); |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3065 |
} |
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3066 |
|
1 | 3067 |
// Large page support |
3068 |
||
3069 |
static size_t _large_page_size = 0; |
|
3070 |
||
9419
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3071 |
void os::large_page_init() { |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3072 |
if (!UseLargePages) { |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3073 |
UseHugeTLBFS = false; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3074 |
UseSHM = false; |
9419
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3075 |
return; |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3076 |
} |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3077 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3078 |
if (FLAG_IS_DEFAULT(UseHugeTLBFS) && FLAG_IS_DEFAULT(UseSHM)) { |
9419
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3079 |
// If UseLargePages is specified on the command line try both methods, |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3080 |
// if it's default, then try only HugeTLBFS. |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3081 |
if (FLAG_IS_DEFAULT(UseLargePages)) { |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3082 |
UseHugeTLBFS = true; |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3083 |
} else { |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3084 |
UseHugeTLBFS = UseSHM = true; |
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
3085 |
} |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3086 |
} |
1 | 3087 |
|
3088 |
if (LargePageSizeInBytes) { |
|
3089 |
_large_page_size = LargePageSizeInBytes; |
|
3090 |
} else { |
|
3091 |
// large_page_size on Linux is used to round up heap size. x86 uses either |
|
3092 |
// 2M or 4M page, depending on whether PAE (Physical Address Extensions) |
|
3093 |
// mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. IA64 can use |
|
3094 |
// page as large as 256M. |
|
3095 |
// |
|
3096 |
// Here we try to figure out page size by parsing /proc/meminfo and looking |
|
3097 |
// for a line with the following format: |
|
3098 |
// Hugepagesize: 2048 kB |
|
3099 |
// |
|
3100 |
// If we can't determine the value (e.g. /proc is not mounted, or the text |
|
3101 |
// format has been changed), we'll use the largest page size supported by |
|
3102 |
// the processor. |
|
3103 |
||
4013 | 3104 |
#ifndef ZERO |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
3105 |
_large_page_size = IA32_ONLY(4 * M) AMD64_ONLY(2 * M) IA64_ONLY(256 * M) SPARC_ONLY(4 * M) |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
3106 |
ARM_ONLY(2 * M) PPC_ONLY(4 * M); |
4013 | 3107 |
#endif // ZERO |
1 | 3108 |
|
3109 |
FILE *fp = fopen("/proc/meminfo", "r"); |
|
3110 |
if (fp) { |
|
3111 |
while (!feof(fp)) { |
|
3112 |
int x = 0; |
|
3113 |
char buf[16]; |
|
3114 |
if (fscanf(fp, "Hugepagesize: %d", &x) == 1) { |
|
3115 |
if (x && fgets(buf, sizeof(buf), fp) && strcmp(buf, " kB\n") == 0) { |
|
3116 |
_large_page_size = x * K; |
|
3117 |
break; |
|
3118 |
} |
|
3119 |
} else { |
|
3120 |
// skip to next line |
|
3121 |
for (;;) { |
|
3122 |
int ch = fgetc(fp); |
|
3123 |
if (ch == EOF || ch == (int)'\n') break; |
|
3124 |
} |
|
3125 |
} |
|
3126 |
} |
|
3127 |
fclose(fp); |
|
3128 |
} |
|
3129 |
} |
|
3130 |
||
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3131 |
// print a warning if any large page related flag is specified on command line |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3132 |
bool warn_on_failure = !FLAG_IS_DEFAULT(UseHugeTLBFS); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3133 |
|
1 | 3134 |
const size_t default_page_size = (size_t)Linux::page_size(); |
3135 |
if (_large_page_size > default_page_size) { |
|
3136 |
_page_sizes[0] = _large_page_size; |
|
3137 |
_page_sizes[1] = default_page_size; |
|
3138 |
_page_sizes[2] = 0; |
|
3139 |
} |
|
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3140 |
UseHugeTLBFS = UseHugeTLBFS && |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3141 |
Linux::hugetlbfs_sanity_check(warn_on_failure, _large_page_size); |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3142 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3143 |
if (UseHugeTLBFS) |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3144 |
UseSHM = false; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3145 |
|
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3146 |
UseLargePages = UseHugeTLBFS || UseSHM; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3147 |
|
8119
81eef1b06988
7014918: Improve core/minidump handling in Hotspot
ctornqvi
parents:
8108
diff
changeset
|
3148 |
set_coredump_filter(); |
1 | 3149 |
} |
3150 |
||
3151 |
#ifndef SHM_HUGETLB |
|
3152 |
#define SHM_HUGETLB 04000 |
|
3153 |
#endif |
|
3154 |
||
2268 | 3155 |
char* os::reserve_memory_special(size_t bytes, char* req_addr, bool exec) { |
3156 |
// "exec" is passed in but not used. Creating the shared image for |
|
3157 |
// the code cache doesn't have an SHM_X executable permission to check. |
|
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3158 |
assert(UseLargePages && UseSHM, "only for SHM large pages"); |
1 | 3159 |
|
3160 |
key_t key = IPC_PRIVATE; |
|
3161 |
char *addr; |
|
3162 |
||
3163 |
bool warn_on_failure = UseLargePages && |
|
3164 |
(!FLAG_IS_DEFAULT(UseLargePages) || |
|
3165 |
!FLAG_IS_DEFAULT(LargePageSizeInBytes) |
|
3166 |
); |
|
3167 |
char msg[128]; |
|
3168 |
||
3169 |
// Create a large shared memory region to attach to based on size. |
|
3170 |
// Currently, size is the total size of the heap |
|
3171 |
int shmid = shmget(key, bytes, SHM_HUGETLB|IPC_CREAT|SHM_R|SHM_W); |
|
3172 |
if (shmid == -1) { |
|
3173 |
// Possible reasons for shmget failure: |
|
3174 |
// 1. shmmax is too small for Java heap. |
|
3175 |
// > check shmmax value: cat /proc/sys/kernel/shmmax |
|
3176 |
// > increase shmmax value: echo "0xffffffff" > /proc/sys/kernel/shmmax |
|
3177 |
// 2. not enough large page memory. |
|
3178 |
// > check available large pages: cat /proc/meminfo |
|
3179 |
// > increase amount of large pages: |
|
3180 |
// echo new_value > /proc/sys/vm/nr_hugepages |
|
3181 |
// Note 1: different Linux may use different name for this property, |
|
3182 |
// e.g. on Redhat AS-3 it is "hugetlb_pool". |
|
3183 |
// Note 2: it's possible there's enough physical memory available but |
|
3184 |
// they are so fragmented after a long run that they can't |
|
3185 |
// coalesce into large pages. Try to reserve large pages when |
|
3186 |
// the system is still "fresh". |
|
3187 |
if (warn_on_failure) { |
|
3188 |
jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno); |
|
3189 |
warning(msg); |
|
3190 |
} |
|
3191 |
return NULL; |
|
3192 |
} |
|
3193 |
||
3194 |
// attach to the region |
|
5532
34c4ef11dbed
6951686: Using large pages on Linux prevents zero based compressed oops
kvn
parents:
5413
diff
changeset
|
3195 |
addr = (char*)shmat(shmid, req_addr, 0); |
1 | 3196 |
int err = errno; |
3197 |
||
3198 |
// Remove shmid. If shmat() is successful, the actual shared memory segment |
|
3199 |
// will be deleted when it's detached by shmdt() or when the process |
|
3200 |
// terminates. If shmat() is not successful this will remove the shared |
|
3201 |
// segment immediately. |
|
3202 |
shmctl(shmid, IPC_RMID, NULL); |
|
3203 |
||
3204 |
if ((intptr_t)addr == -1) { |
|
3205 |
if (warn_on_failure) { |
|
3206 |
jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err); |
|
3207 |
warning(msg); |
|
3208 |
} |
|
3209 |
return NULL; |
|
3210 |
} |
|
3211 |
||
10494 | 3212 |
if ((addr != NULL) && UseNUMAInterleaving) { |
3213 |
numa_make_global(addr, bytes); |
|
3214 |
} |
|
3215 |
||
15927
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3216 |
// The memory is committed |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3217 |
address pc = CALLER_PC; |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3218 |
MemTracker::record_virtual_memory_reserve((address)addr, bytes, pc); |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3219 |
MemTracker::record_virtual_memory_commit((address)addr, bytes, pc); |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3220 |
|
1 | 3221 |
return addr; |
3222 |
} |
|
3223 |
||
3224 |
bool os::release_memory_special(char* base, size_t bytes) { |
|
3225 |
// detaching the SHM segment will also delete it, see reserve_memory_special() |
|
3226 |
int rslt = shmdt(base); |
|
15927
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3227 |
if (rslt == 0) { |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3228 |
MemTracker::record_virtual_memory_uncommit((address)base, bytes); |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3229 |
MemTracker::record_virtual_memory_release((address)base, bytes); |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3230 |
return true; |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3231 |
} else { |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3232 |
return false; |
f256c20146f4
8008257: NMT: assert(new_rec->is_allocation_record()) failed when running with shared memory option
zgu
parents:
15926
diff
changeset
|
3233 |
} |
1 | 3234 |
} |
3235 |
||
3236 |
size_t os::large_page_size() { |
|
3237 |
return _large_page_size; |
|
3238 |
} |
|
3239 |
||
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3240 |
// HugeTLBFS allows application to commit large page memory on demand; |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3241 |
// with SysV SHM the entire memory region must be allocated as shared |
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3242 |
// memory. |
1 | 3243 |
bool os::can_commit_large_page_memory() { |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3244 |
return UseHugeTLBFS; |
1 | 3245 |
} |
3246 |
||
252
050143a0dbfb
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
235
diff
changeset
|
3247 |
bool os::can_execute_large_page_memory() { |
9335
7bdd2a3ab3d8
7034464: Support transparent large pages on Linux
iveresov
parents:
8476
diff
changeset
|
3248 |
return UseHugeTLBFS; |
252
050143a0dbfb
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
235
diff
changeset
|
3249 |
} |
050143a0dbfb
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
235
diff
changeset
|
3250 |
|
1 | 3251 |
// Reserve memory at an arbitrary address, only if that area is |
3252 |
// available (and not reserved for something else). |
|
3253 |
||
13195 | 3254 |
char* os::pd_attempt_reserve_memory_at(size_t bytes, char* requested_addr) { |
1 | 3255 |
const int max_tries = 10; |
3256 |
char* base[max_tries]; |
|
3257 |
size_t size[max_tries]; |
|
3258 |
const size_t gap = 0x000000; |
|
3259 |
||
3260 |
// Assert only that the size is a multiple of the page size, since |
|
3261 |
// that's all that mmap requires, and since that's all we really know |
|
3262 |
// about at this low abstraction level. If we need higher alignment, |
|
3263 |
// we can either pass an alignment to this method or verify alignment |
|
3264 |
// in one of the methods further up the call chain. See bug 5044738. |
|
3265 |
assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block"); |
|
3266 |
||
3267 |
// Repeatedly allocate blocks until the block is allocated at the |
|
3268 |
// right spot. Give up after max_tries. Note that reserve_memory() will |
|
3269 |
// automatically update _highest_vm_reserved_address if the call is |
|
3270 |
// successful. The variable tracks the highest memory address every reserved |
|
3271 |
// by JVM. It is used to detect heap-stack collision if running with |
|
3272 |
// fixed-stack LinuxThreads. Because here we may attempt to reserve more |
|
3273 |
// space than needed, it could confuse the collision detecting code. To |
|
3274 |
// solve the problem, save current _highest_vm_reserved_address and |
|
3275 |
// calculate the correct value before return. |
|
3276 |
address old_highest = _highest_vm_reserved_address; |
|
3277 |
||
3278 |
// Linux mmap allows caller to pass an address as hint; give it a try first, |
|
3279 |
// if kernel honors the hint then we can return immediately. |
|
3280 |
char * addr = anon_mmap(requested_addr, bytes, false); |
|
3281 |
if (addr == requested_addr) { |
|
3282 |
return requested_addr; |
|
3283 |
} |
|
3284 |
||
3285 |
if (addr != NULL) { |
|
3286 |
// mmap() is successful but it fails to reserve at the requested address |
|
3287 |
anon_munmap(addr, bytes); |
|
3288 |
} |
|
3289 |
||
3290 |
int i; |
|
3291 |
for (i = 0; i < max_tries; ++i) { |
|
3292 |
base[i] = reserve_memory(bytes); |
|
3293 |
||
3294 |
if (base[i] != NULL) { |
|
3295 |
// Is this the block we wanted? |
|
3296 |
if (base[i] == requested_addr) { |
|
3297 |
size[i] = bytes; |
|
3298 |
break; |
|
3299 |
} |
|
3300 |
||
3301 |
// Does this overlap the block we wanted? Give back the overlapped |
|
3302 |
// parts and try again. |
|
3303 |
||
3304 |
size_t top_overlap = requested_addr + (bytes + gap) - base[i]; |
|
3305 |
if (top_overlap >= 0 && top_overlap < bytes) { |
|
3306 |
unmap_memory(base[i], top_overlap); |
|
3307 |
base[i] += top_overlap; |
|
3308 |
size[i] = bytes - top_overlap; |
|
3309 |
} else { |
|
3310 |
size_t bottom_overlap = base[i] + bytes - requested_addr; |
|
3311 |
if (bottom_overlap >= 0 && bottom_overlap < bytes) { |
|
3312 |
unmap_memory(requested_addr, bottom_overlap); |
|
3313 |
size[i] = bytes - bottom_overlap; |
|
3314 |
} else { |
|
3315 |
size[i] = bytes; |
|
3316 |
} |
|
3317 |
} |
|
3318 |
} |
|
3319 |
} |
|
3320 |
||
3321 |
// Give back the unused reserved pieces. |
|
3322 |
||
3323 |
for (int j = 0; j < i; ++j) { |
|
3324 |
if (base[j] != NULL) { |
|
3325 |
unmap_memory(base[j], size[j]); |
|
3326 |
} |
|
3327 |
} |
|
3328 |
||
3329 |
if (i < max_tries) { |
|
3330 |
_highest_vm_reserved_address = MAX2(old_highest, (address)requested_addr + bytes); |
|
3331 |
return requested_addr; |
|
3332 |
} else { |
|
3333 |
_highest_vm_reserved_address = old_highest; |
|
3334 |
return NULL; |
|
3335 |
} |
|
3336 |
} |
|
3337 |
||
3338 |
size_t os::read(int fd, void *buf, unsigned int nBytes) { |
|
3339 |
return ::read(fd, buf, nBytes); |
|
3340 |
} |
|
3341 |
||
3342 |
// TODO-FIXME: reconcile Solaris' os::sleep with the linux variation. |
|
3343 |
// Solaris uses poll(), linux uses park(). |
|
3344 |
// Poll() is likely a better choice, assuming that Thread.interrupt() |
|
3345 |
// generates a SIGUSRx signal. Note that SIGUSR1 can interfere with |
|
3346 |
// SIGSEGV, see 4355769. |
|
3347 |
||
3348 |
int os::sleep(Thread* thread, jlong millis, bool interruptible) { |
|
3349 |
assert(thread == Thread::current(), "thread consistency check"); |
|
3350 |
||
3351 |
ParkEvent * const slp = thread->_SleepEvent ; |
|
3352 |
slp->reset() ; |
|
3353 |
OrderAccess::fence() ; |
|
3354 |
||
3355 |
if (interruptible) { |
|
3356 |
jlong prevtime = javaTimeNanos(); |
|
3357 |
||
3358 |
for (;;) { |
|
3359 |
if (os::is_interrupted(thread, true)) { |
|
3360 |
return OS_INTRPT; |
|
3361 |
} |
|
3362 |
||
3363 |
jlong newtime = javaTimeNanos(); |
|
3364 |
||
3365 |
if (newtime - prevtime < 0) { |
|
3366 |
// time moving backwards, should only happen if no monotonic clock |
|
3367 |
// not a guarantee() because JVM should not abort on kernel/glibc bugs |
|
3368 |
assert(!Linux::supports_monotonic_clock(), "time moving backwards"); |
|
3369 |
} else { |
|
11251
e29da6b5622b
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
11161
diff
changeset
|
3370 |
millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC; |
1 | 3371 |
} |
3372 |
||
3373 |
if(millis <= 0) { |
|
3374 |
return OS_OK; |
|
3375 |
} |
|
3376 |
||
3377 |
prevtime = newtime; |
|
3378 |
||
3379 |
{ |
|
3380 |
assert(thread->is_Java_thread(), "sanity check"); |
|
3381 |
JavaThread *jt = (JavaThread *) thread; |
|
3382 |
ThreadBlockInVM tbivm(jt); |
|
3383 |
OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */); |
|
3384 |
||
3385 |
jt->set_suspend_equivalent(); |
|
3386 |
// cleared by handle_special_suspend_equivalent_condition() or |
|
3387 |
// java_suspend_self() via check_and_wait_while_suspended() |
|
3388 |
||
3389 |
slp->park(millis); |
|
3390 |
||
3391 |
// were we externally suspended while we were waiting? |
|
3392 |
jt->check_and_wait_while_suspended(); |
|
3393 |
} |
|
3394 |
} |
|
3395 |
} else { |
|
3396 |
OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); |
|
3397 |
jlong prevtime = javaTimeNanos(); |
|
3398 |
||
3399 |
for (;;) { |
|
3400 |
// It'd be nice to avoid the back-to-back javaTimeNanos() calls on |
|
3401 |
// the 1st iteration ... |
|
3402 |
jlong newtime = javaTimeNanos(); |
|
3403 |
||
3404 |
if (newtime - prevtime < 0) { |
|
3405 |
// time moving backwards, should only happen if no monotonic clock |
|
3406 |
// not a guarantee() because JVM should not abort on kernel/glibc bugs |
|
3407 |
assert(!Linux::supports_monotonic_clock(), "time moving backwards"); |
|
3408 |
} else { |
|
11251
e29da6b5622b
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
11161
diff
changeset
|
3409 |
millis -= (newtime - prevtime) / NANOSECS_PER_MILLISEC; |
1 | 3410 |
} |
3411 |
||
3412 |
if(millis <= 0) break ; |
|
3413 |
||
3414 |
prevtime = newtime; |
|
3415 |
slp->park(millis); |
|
3416 |
} |
|
3417 |
return OS_OK ; |
|
3418 |
} |
|
3419 |
} |
|
3420 |
||
3421 |
int os::naked_sleep() { |
|
3422 |
// %% make the sleep time an integer flag. for now use 1 millisec. |
|
3423 |
return os::sleep(Thread::current(), 1, false); |
|
3424 |
} |
|
3425 |
||
3426 |
// Sleep forever; naked call to OS-specific sleep; use with CAUTION |
|
3427 |
void os::infinite_sleep() { |
|
3428 |
while (true) { // sleep forever ... |
|
3429 |
::sleep(100); // ... 100 seconds at a time |
|
3430 |
} |
|
3431 |
} |
|
3432 |
||
3433 |
// Used to convert frequent JVM_Yield() to nops |
|
3434 |
bool os::dont_yield() { |
|
3435 |
return DontYieldALot; |
|
3436 |
} |
|
3437 |
||
3438 |
void os::yield() { |
|
3439 |
sched_yield(); |
|
3440 |
} |
|
3441 |
||
3442 |
os::YieldResult os::NakedYield() { sched_yield(); return os::YIELD_UNKNOWN ;} |
|
3443 |
||
3444 |
void os::yield_all(int attempts) { |
|
3445 |
// Yields to all threads, including threads with lower priorities |
|
3446 |
// Threads on Linux are all with same priority. The Solaris style |
|
3447 |
// os::yield_all() with nanosleep(1ms) is not necessary. |
|
3448 |
sched_yield(); |
|
3449 |
} |
|
3450 |
||
3451 |
// Called from the tight loops to possibly influence time-sharing heuristics |
|
3452 |
void os::loop_breaker(int attempts) { |
|
3453 |
os::yield_all(attempts); |
|
3454 |
} |
|
3455 |
||
3456 |
//////////////////////////////////////////////////////////////////////////////// |
|
3457 |
// thread priority support |
|
3458 |
||
3459 |
// Note: Normal Linux applications are run with SCHED_OTHER policy. SCHED_OTHER |
|
3460 |
// only supports dynamic priority, static priority must be zero. For real-time |
|
3461 |
// applications, Linux supports SCHED_RR which allows static priority (1-99). |
|
3462 |
// However, for large multi-threaded applications, SCHED_RR is not only slower |
|
3463 |
// than SCHED_OTHER, but also very unstable (my volano tests hang hard 4 out |
|
3464 |
// of 5 runs - Sep 2005). |
|
3465 |
// |
|
3466 |
// The following code actually changes the niceness of kernel-thread/LWP. It |
|
3467 |
// has an assumption that setpriority() only modifies one kernel-thread/LWP, |
|
3468 |
// not the entire user process, and user level threads are 1:1 mapped to kernel |
|
3469 |
// threads. It has always been the case, but could change in the future. For |
|
3470 |
// this reason, the code should not be used as default (ThreadPriorityPolicy=0). |
|
3471 |
// It is only used when ThreadPriorityPolicy=1 and requires root privilege. |
|
3472 |
||
11601
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3473 |
int os::java_to_os_priority[CriticalPriority + 1] = { |
1 | 3474 |
19, // 0 Entry should never be used |
3475 |
||
3476 |
4, // 1 MinPriority |
|
3477 |
3, // 2 |
|
3478 |
2, // 3 |
|
3479 |
||
3480 |
1, // 4 |
|
3481 |
0, // 5 NormPriority |
|
3482 |
-1, // 6 |
|
3483 |
||
3484 |
-2, // 7 |
|
3485 |
-3, // 8 |
|
3486 |
-4, // 9 NearMaxPriority |
|
3487 |
||
11601
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3488 |
-5, // 10 MaxPriority |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3489 |
|
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3490 |
-5 // 11 CriticalPriority |
1 | 3491 |
}; |
3492 |
||
3493 |
static int prio_init() { |
|
3494 |
if (ThreadPriorityPolicy == 1) { |
|
3495 |
// Only root can raise thread priority. Don't allow ThreadPriorityPolicy=1 |
|
3496 |
// if effective uid is not root. Perhaps, a more elegant way of doing |
|
3497 |
// this is to test CAP_SYS_NICE capability, but that will require libcap.so |
|
3498 |
if (geteuid() != 0) { |
|
3499 |
if (!FLAG_IS_DEFAULT(ThreadPriorityPolicy)) { |
|
3500 |
warning("-XX:ThreadPriorityPolicy requires root privilege on Linux"); |
|
3501 |
} |
|
3502 |
ThreadPriorityPolicy = 0; |
|
3503 |
} |
|
3504 |
} |
|
11601
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3505 |
if (UseCriticalJavaThreadPriority) { |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3506 |
os::java_to_os_priority[MaxPriority] = os::java_to_os_priority[CriticalPriority]; |
f359304c1856
7082553: Interpret Thread.setPriority(Thread.MAX_PRIORITY) to mean FX60 on Solaris 10 and 11
phh
parents:
11483
diff
changeset
|
3507 |
} |
1 | 3508 |
return 0; |
3509 |
} |
|
3510 |
||
3511 |
OSReturn os::set_native_priority(Thread* thread, int newpri) { |
|
3512 |
if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) return OS_OK; |
|
3513 |
||
3514 |
int ret = setpriority(PRIO_PROCESS, thread->osthread()->thread_id(), newpri); |
|
3515 |
return (ret == 0) ? OS_OK : OS_ERR; |
|
3516 |
} |
|
3517 |
||
3518 |
OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) { |
|
3519 |
if ( !UseThreadPriorities || ThreadPriorityPolicy == 0 ) { |
|
3520 |
*priority_ptr = java_to_os_priority[NormPriority]; |
|
3521 |
return OS_OK; |
|
3522 |
} |
|
3523 |
||
3524 |
errno = 0; |
|
3525 |
*priority_ptr = getpriority(PRIO_PROCESS, thread->osthread()->thread_id()); |
|
3526 |
return (*priority_ptr != -1 || errno == 0 ? OS_OK : OS_ERR); |
|
3527 |
} |
|
3528 |
||
3529 |
// Hint to the underlying OS that a task switch would not be good. |
|
3530 |
// Void return because it's a hint and can fail. |
|
3531 |
void os::hint_no_preempt() {} |
|
3532 |
||
3533 |
//////////////////////////////////////////////////////////////////////////////// |
|
3534 |
// suspend/resume support |
|
3535 |
||
3536 |
// the low-level signal-based suspend/resume support is a remnant from the |
|
3537 |
// old VM-suspension that used to be for java-suspension, safepoints etc, |
|
3538 |
// within hotspot. Now there is a single use-case for this: |
|
3539 |
// - calling get_thread_pc() on the VMThread by the flat-profiler task |
|
3540 |
// that runs in the watcher thread. |
|
3541 |
// The remaining code is greatly simplified from the more general suspension |
|
3542 |
// code that used to be used. |
|
3543 |
// |
|
3544 |
// The protocol is quite simple: |
|
3545 |
// - suspend: |
|
3546 |
// - sends a signal to the target thread |
|
3547 |
// - polls the suspend state of the osthread using a yield loop |
|
3548 |
// - target thread signal handler (SR_handler) sets suspend state |
|
3549 |
// and blocks in sigsuspend until continued |
|
3550 |
// - resume: |
|
3551 |
// - sets target osthread state to continue |
|
3552 |
// - sends signal to end the sigsuspend loop in the SR_handler |
|
3553 |
// |
|
3554 |
// Note that the SR_lock plays no role in this suspend/resume protocol. |
|
3555 |
// |
|
3556 |
||
3557 |
static void resume_clear_context(OSThread *osthread) { |
|
3558 |
osthread->set_ucontext(NULL); |
|
3559 |
osthread->set_siginfo(NULL); |
|
3560 |
||
3561 |
// notify the suspend action is completed, we have now resumed |
|
3562 |
osthread->sr.clear_suspended(); |
|
3563 |
} |
|
3564 |
||
3565 |
static void suspend_save_context(OSThread *osthread, siginfo_t* siginfo, ucontext_t* context) { |
|
3566 |
osthread->set_ucontext(context); |
|
3567 |
osthread->set_siginfo(siginfo); |
|
3568 |
} |
|
3569 |
||
3570 |
// |
|
3571 |
// Handler function invoked when a thread's execution is suspended or |
|
3572 |
// resumed. We have to be careful that only async-safe functions are |
|
3573 |
// called here (Note: most pthread functions are not async safe and |
|
3574 |
// should be avoided.) |
|
3575 |
// |
|
3576 |
// Note: sigwait() is a more natural fit than sigsuspend() from an |
|
3577 |
// interface point of view, but sigwait() prevents the signal hander |
|
3578 |
// from being run. libpthread would get very confused by not having |
|
3579 |
// its signal handlers run and prevents sigwait()'s use with the |
|
3580 |
// mutex granting granting signal. |
|
3581 |
// |
|
3582 |
// Currently only ever called on the VMThread |
|
3583 |
// |
|
3584 |
static void SR_handler(int sig, siginfo_t* siginfo, ucontext_t* context) { |
|
3585 |
// Save and restore errno to avoid confusing native code with EINTR |
|
3586 |
// after sigsuspend. |
|
3587 |
int old_errno = errno; |
|
3588 |
||
3589 |
Thread* thread = Thread::current(); |
|
3590 |
OSThread* osthread = thread->osthread(); |
|
3591 |
assert(thread->is_VM_thread(), "Must be VMThread"); |
|
3592 |
// read current suspend action |
|
3593 |
int action = osthread->sr.suspend_action(); |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3594 |
if (action == os::Linux::SuspendResume::SR_SUSPEND) { |
1 | 3595 |
suspend_save_context(osthread, siginfo, context); |
3596 |
||
3597 |
// Notify the suspend action is about to be completed. do_suspend() |
|
3598 |
// waits until SR_SUSPENDED is set and then returns. We will wait |
|
3599 |
// here for a resume signal and that completes the suspend-other |
|
3600 |
// action. do_suspend/do_resume is always called as a pair from |
|
3601 |
// the same thread - so there are no races |
|
3602 |
||
3603 |
// notify the caller |
|
3604 |
osthread->sr.set_suspended(); |
|
3605 |
||
3606 |
sigset_t suspend_set; // signals for sigsuspend() |
|
3607 |
||
3608 |
// get current set of blocked signals and unblock resume signal |
|
3609 |
pthread_sigmask(SIG_BLOCK, NULL, &suspend_set); |
|
3610 |
sigdelset(&suspend_set, SR_signum); |
|
3611 |
||
3612 |
// wait here until we are resumed |
|
3613 |
do { |
|
3614 |
sigsuspend(&suspend_set); |
|
3615 |
// ignore all returns until we get a resume signal |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3616 |
} while (osthread->sr.suspend_action() != os::Linux::SuspendResume::SR_CONTINUE); |
1 | 3617 |
|
3618 |
resume_clear_context(osthread); |
|
3619 |
||
3620 |
} else { |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3621 |
assert(action == os::Linux::SuspendResume::SR_CONTINUE, "unexpected sr action"); |
1 | 3622 |
// nothing special to do - just leave the handler |
3623 |
} |
|
3624 |
||
3625 |
errno = old_errno; |
|
3626 |
} |
|
3627 |
||
3628 |
||
3629 |
static int SR_initialize() { |
|
3630 |
struct sigaction act; |
|
3631 |
char *s; |
|
3632 |
/* Get signal number to use for suspend/resume */ |
|
3633 |
if ((s = ::getenv("_JAVA_SR_SIGNUM")) != 0) { |
|
3634 |
int sig = ::strtol(s, 0, 10); |
|
3635 |
if (sig > 0 || sig < _NSIG) { |
|
3636 |
SR_signum = sig; |
|
3637 |
} |
|
3638 |
} |
|
3639 |
||
3640 |
assert(SR_signum > SIGSEGV && SR_signum > SIGBUS, |
|
3641 |
"SR_signum must be greater than max(SIGSEGV, SIGBUS), see 4355769"); |
|
3642 |
||
3643 |
sigemptyset(&SR_sigset); |
|
3644 |
sigaddset(&SR_sigset, SR_signum); |
|
3645 |
||
3646 |
/* Set up signal handler for suspend/resume */ |
|
3647 |
act.sa_flags = SA_RESTART|SA_SIGINFO; |
|
3648 |
act.sa_handler = (void (*)(int)) SR_handler; |
|
3649 |
||
3650 |
// SR_signum is blocked by default. |
|
3651 |
// 4528190 - We also need to block pthread restart signal (32 on all |
|
3652 |
// supported Linux platforms). Note that LinuxThreads need to block |
|
3653 |
// this signal for all threads to work properly. So we don't have |
|
3654 |
// to use hard-coded signal number when setting up the mask. |
|
3655 |
pthread_sigmask(SIG_BLOCK, NULL, &act.sa_mask); |
|
3656 |
||
3657 |
if (sigaction(SR_signum, &act, 0) == -1) { |
|
3658 |
return -1; |
|
3659 |
} |
|
3660 |
||
3661 |
// Save signal flag |
|
3662 |
os::Linux::set_our_sigflags(SR_signum, act.sa_flags); |
|
3663 |
return 0; |
|
3664 |
} |
|
3665 |
||
3666 |
static int SR_finalize() { |
|
3667 |
return 0; |
|
3668 |
} |
|
3669 |
||
3670 |
||
3671 |
// returns true on success and false on error - really an error is fatal |
|
3672 |
// but this seems the normal response to library errors |
|
3673 |
static bool do_suspend(OSThread* osthread) { |
|
3674 |
// mark as suspended and send signal |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3675 |
osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_SUSPEND); |
1 | 3676 |
int status = pthread_kill(osthread->pthread_id(), SR_signum); |
3677 |
assert_status(status == 0, status, "pthread_kill"); |
|
3678 |
||
3679 |
// check status and wait until notified of suspension |
|
3680 |
if (status == 0) { |
|
3681 |
for (int i = 0; !osthread->sr.is_suspended(); i++) { |
|
3682 |
os::yield_all(i); |
|
3683 |
} |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3684 |
osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); |
1 | 3685 |
return true; |
3686 |
} |
|
3687 |
else { |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3688 |
osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); |
1 | 3689 |
return false; |
3690 |
} |
|
3691 |
} |
|
3692 |
||
3693 |
static void do_resume(OSThread* osthread) { |
|
3694 |
assert(osthread->sr.is_suspended(), "thread should be suspended"); |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3695 |
osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_CONTINUE); |
1 | 3696 |
|
3697 |
int status = pthread_kill(osthread->pthread_id(), SR_signum); |
|
3698 |
assert_status(status == 0, status, "pthread_kill"); |
|
3699 |
// check status and wait unit notified of resumption |
|
3700 |
if (status == 0) { |
|
3701 |
for (int i = 0; osthread->sr.is_suspended(); i++) { |
|
3702 |
os::yield_all(i); |
|
3703 |
} |
|
3704 |
} |
|
15855
2ac9ebea17f3
8008959: Fix non-PCH build on Linux, Windows and MacOS X
simonis
parents:
15794
diff
changeset
|
3705 |
osthread->sr.set_suspend_action(os::Linux::SuspendResume::SR_NONE); |
1 | 3706 |
} |
3707 |
||
3708 |
//////////////////////////////////////////////////////////////////////////////// |
|
3709 |
// interrupt support |
|
3710 |
||
3711 |
void os::interrupt(Thread* thread) { |
|
3712 |
assert(Thread::current() == thread || Threads_lock->owned_by_self(), |
|
3713 |
"possibility of dangling Thread pointer"); |
|
3714 |
||
3715 |
OSThread* osthread = thread->osthread(); |
|
3716 |
||
3717 |
if (!osthread->interrupted()) { |
|
3718 |
osthread->set_interrupted(true); |
|
3719 |
// More than one thread can get here with the same value of osthread, |
|
3720 |
// resulting in multiple notifications. We do, however, want the store |
|
3721 |
// to interrupted() to be visible to other threads before we execute unpark(). |
|
3722 |
OrderAccess::fence(); |
|
3723 |
ParkEvent * const slp = thread->_SleepEvent ; |
|
3724 |
if (slp != NULL) slp->unpark() ; |
|
3725 |
} |
|
3726 |
||
3727 |
// For JSR166. Unpark even if interrupt status already was set |
|
3728 |
if (thread->is_Java_thread()) |
|
3729 |
((JavaThread*)thread)->parker()->unpark(); |
|
3730 |
||
3731 |
ParkEvent * ev = thread->_ParkEvent ; |
|
3732 |
if (ev != NULL) ev->unpark() ; |
|
3733 |
||
3734 |
} |
|
3735 |
||
3736 |
bool os::is_interrupted(Thread* thread, bool clear_interrupted) { |
|
3737 |
assert(Thread::current() == thread || Threads_lock->owned_by_self(), |
|
3738 |
"possibility of dangling Thread pointer"); |
|
3739 |
||
3740 |
OSThread* osthread = thread->osthread(); |
|
3741 |
||
3742 |
bool interrupted = osthread->interrupted(); |
|
3743 |
||
3744 |
if (interrupted && clear_interrupted) { |
|
3745 |
osthread->set_interrupted(false); |
|
3746 |
// consider thread->_SleepEvent->reset() ... optional optimization |
|
3747 |
} |
|
3748 |
||
3749 |
return interrupted; |
|
3750 |
} |
|
3751 |
||
3752 |
/////////////////////////////////////////////////////////////////////////////////// |
|
3753 |
// signal handling (except suspend/resume) |
|
3754 |
||
3755 |
// This routine may be used by user applications as a "hook" to catch signals. |
|
3756 |
// The user-defined signal handler must pass unrecognized signals to this |
|
3757 |
// routine, and if it returns true (non-zero), then the signal handler must |
|
3758 |
// return immediately. If the flag "abort_if_unrecognized" is true, then this |
|
3759 |
// routine will never retun false (zero), but instead will execute a VM panic |
|
3760 |
// routine kill the process. |
|
3761 |
// |
|
3762 |
// If this routine returns false, it is OK to call it again. This allows |
|
3763 |
// the user-defined signal handler to perform checks either before or after |
|
3764 |
// the VM performs its own checks. Naturally, the user code would be making |
|
3765 |
// a serious error if it tried to handle an exception (such as a null check |
|
3766 |
// or breakpoint) that the VM was generating for its own correct operation. |
|
3767 |
// |
|
3768 |
// This routine may recognize any of the following kinds of signals: |
|
3769 |
// SIGBUS, SIGSEGV, SIGILL, SIGFPE, SIGQUIT, SIGPIPE, SIGXFSZ, SIGUSR1. |
|
3770 |
// It should be consulted by handlers for any of those signals. |
|
3771 |
// |
|
3772 |
// The caller of this routine must pass in the three arguments supplied |
|
3773 |
// to the function referred to in the "sa_sigaction" (not the "sa_handler") |
|
3774 |
// field of the structure passed to sigaction(). This routine assumes that |
|
3775 |
// the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. |
|
3776 |
// |
|
3777 |
// Note that the VM will print warnings if it detects conflicting signal |
|
3778 |
// handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". |
|
3779 |
// |
|
8106 | 3780 |
extern "C" JNIEXPORT int |
1 | 3781 |
JVM_handle_linux_signal(int signo, siginfo_t* siginfo, |
3782 |
void* ucontext, int abort_if_unrecognized); |
|
3783 |
||
3784 |
void signalHandler(int sig, siginfo_t* info, void* uc) { |
|
3785 |
assert(info != NULL && uc != NULL, "it must be old kernel"); |
|
15743
f708934a12e7
6749267: Signal handler should save/restore errno
hseigel
parents:
15475
diff
changeset
|
3786 |
int orig_errno = errno; // Preserve errno value over signal handler. |
1 | 3787 |
JVM_handle_linux_signal(sig, info, uc, true); |
15743
f708934a12e7
6749267: Signal handler should save/restore errno
hseigel
parents:
15475
diff
changeset
|
3788 |
errno = orig_errno; |
1 | 3789 |
} |
3790 |
||
3791 |
||
3792 |
// This boolean allows users to forward their own non-matching signals |
|
3793 |
// to JVM_handle_linux_signal, harmlessly. |
|
3794 |
bool os::Linux::signal_handlers_are_installed = false; |
|
3795 |
||
3796 |
// For signal-chaining |
|
3797 |
struct sigaction os::Linux::sigact[MAXSIGNUM]; |
|
3798 |
unsigned int os::Linux::sigs = 0; |
|
3799 |
bool os::Linux::libjsig_is_loaded = false; |
|
3800 |
typedef struct sigaction *(*get_signal_t)(int); |
|
3801 |
get_signal_t os::Linux::get_signal_action = NULL; |
|
3802 |
||
3803 |
struct sigaction* os::Linux::get_chained_signal_action(int sig) { |
|
3804 |
struct sigaction *actp = NULL; |
|
3805 |
||
3806 |
if (libjsig_is_loaded) { |
|
3807 |
// Retrieve the old signal handler from libjsig |
|
3808 |
actp = (*get_signal_action)(sig); |
|
3809 |
} |
|
3810 |
if (actp == NULL) { |
|
3811 |
// Retrieve the preinstalled signal handler from jvm |
|
3812 |
actp = get_preinstalled_handler(sig); |
|
3813 |
} |
|
3814 |
||
3815 |
return actp; |
|
3816 |
} |
|
3817 |
||
3818 |
static bool call_chained_handler(struct sigaction *actp, int sig, |
|
3819 |
siginfo_t *siginfo, void *context) { |
|
3820 |
// Call the old signal handler |
|
3821 |
if (actp->sa_handler == SIG_DFL) { |
|
3822 |
// It's more reasonable to let jvm treat it as an unexpected exception |
|
3823 |
// instead of taking the default action. |
|
3824 |
return false; |
|
3825 |
} else if (actp->sa_handler != SIG_IGN) { |
|
3826 |
if ((actp->sa_flags & SA_NODEFER) == 0) { |
|
3827 |
// automaticlly block the signal |
|
3828 |
sigaddset(&(actp->sa_mask), sig); |
|
3829 |
} |
|
3830 |
||
3831 |
sa_handler_t hand; |
|
3832 |
sa_sigaction_t sa; |
|
3833 |
bool siginfo_flag_set = (actp->sa_flags & SA_SIGINFO) != 0; |
|
3834 |
// retrieve the chained handler |
|
3835 |
if (siginfo_flag_set) { |
|
3836 |
sa = actp->sa_sigaction; |
|
3837 |
} else { |
|
3838 |
hand = actp->sa_handler; |
|
3839 |
} |
|
3840 |
||
3841 |
if ((actp->sa_flags & SA_RESETHAND) != 0) { |
|
3842 |
actp->sa_handler = SIG_DFL; |
|
3843 |
} |
|
3844 |
||
3845 |
// try to honor the signal mask |
|
3846 |
sigset_t oset; |
|
3847 |
pthread_sigmask(SIG_SETMASK, &(actp->sa_mask), &oset); |
|
3848 |
||
3849 |
// call into the chained handler |
|
3850 |
if (siginfo_flag_set) { |
|
3851 |
(*sa)(sig, siginfo, context); |
|
3852 |
} else { |
|
3853 |
(*hand)(sig); |
|
3854 |
} |
|
3855 |
||
3856 |
// restore the signal mask |
|
3857 |
pthread_sigmask(SIG_SETMASK, &oset, 0); |
|
3858 |
} |
|
3859 |
// Tell jvm's signal handler the signal is taken care of. |
|
3860 |
return true; |
|
3861 |
} |
|
3862 |
||
3863 |
bool os::Linux::chained_handler(int sig, siginfo_t* siginfo, void* context) { |
|
3864 |
bool chained = false; |
|
3865 |
// signal-chaining |
|
3866 |
if (UseSignalChaining) { |
|
3867 |
struct sigaction *actp = get_chained_signal_action(sig); |
|
3868 |
if (actp != NULL) { |
|
3869 |
chained = call_chained_handler(actp, sig, siginfo, context); |
|
3870 |
} |
|
3871 |
} |
|
3872 |
return chained; |
|
3873 |
} |
|
3874 |
||
3875 |
struct sigaction* os::Linux::get_preinstalled_handler(int sig) { |
|
3876 |
if ((( (unsigned int)1 << sig ) & sigs) != 0) { |
|
3877 |
return &sigact[sig]; |
|
3878 |
} |
|
3879 |
return NULL; |
|
3880 |
} |
|
3881 |
||
3882 |
void os::Linux::save_preinstalled_handler(int sig, struct sigaction& oldAct) { |
|
3883 |
assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range"); |
|
3884 |
sigact[sig] = oldAct; |
|
3885 |
sigs |= (unsigned int)1 << sig; |
|
3886 |
} |
|
3887 |
||
3888 |
// for diagnostic |
|
3889 |
int os::Linux::sigflags[MAXSIGNUM]; |
|
3890 |
||
3891 |
int os::Linux::get_our_sigflags(int sig) { |
|
3892 |
assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range"); |
|
3893 |
return sigflags[sig]; |
|
3894 |
} |
|
3895 |
||
3896 |
void os::Linux::set_our_sigflags(int sig, int flags) { |
|
3897 |
assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range"); |
|
3898 |
sigflags[sig] = flags; |
|
3899 |
} |
|
3900 |
||
3901 |
void os::Linux::set_signal_handler(int sig, bool set_installed) { |
|
3902 |
// Check for overwrite. |
|
3903 |
struct sigaction oldAct; |
|
3904 |
sigaction(sig, (struct sigaction*)NULL, &oldAct); |
|
3905 |
||
3906 |
void* oldhand = oldAct.sa_sigaction |
|
3907 |
? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) |
|
3908 |
: CAST_FROM_FN_PTR(void*, oldAct.sa_handler); |
|
3909 |
if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) && |
|
3910 |
oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) && |
|
3911 |
oldhand != CAST_FROM_FN_PTR(void*, (sa_sigaction_t)signalHandler)) { |
|
3912 |
if (AllowUserSignalHandlers || !set_installed) { |
|
3913 |
// Do not overwrite; user takes responsibility to forward to us. |
|
3914 |
return; |
|
3915 |
} else if (UseSignalChaining) { |
|
3916 |
// save the old handler in jvm |
|
3917 |
save_preinstalled_handler(sig, oldAct); |
|
3918 |
// libjsig also interposes the sigaction() call below and saves the |
|
3919 |
// old sigaction on it own. |
|
3920 |
} else { |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
5237
diff
changeset
|
3921 |
fatal(err_msg("Encountered unexpected pre-existing sigaction handler " |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
5237
diff
changeset
|
3922 |
"%#lx for signal %d.", (long)oldhand, sig)); |
1 | 3923 |
} |
3924 |
} |
|
3925 |
||
3926 |
struct sigaction sigAct; |
|
3927 |
sigfillset(&(sigAct.sa_mask)); |
|
3928 |
sigAct.sa_handler = SIG_DFL; |
|
3929 |
if (!set_installed) { |
|
3930 |
sigAct.sa_flags = SA_SIGINFO|SA_RESTART; |
|
3931 |
} else { |
|
3932 |
sigAct.sa_sigaction = signalHandler; |
|
3933 |
sigAct.sa_flags = SA_SIGINFO|SA_RESTART; |
|
3934 |
} |
|
3935 |
// Save flags, which are set by ours |
|
3936 |
assert(sig > 0 && sig < MAXSIGNUM, "vm signal out of expected range"); |
|
3937 |
sigflags[sig] = sigAct.sa_flags; |
|
3938 |
||
3939 |
int ret = sigaction(sig, &sigAct, &oldAct); |
|
3940 |
assert(ret == 0, "check"); |
|
3941 |
||
3942 |
void* oldhand2 = oldAct.sa_sigaction |
|
3943 |
? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) |
|
3944 |
: CAST_FROM_FN_PTR(void*, oldAct.sa_handler); |
|
3945 |
assert(oldhand2 == oldhand, "no concurrent signal handler installation"); |
|
3946 |
} |
|
3947 |
||
3948 |
// install signal handlers for signals that HotSpot needs to |
|
3949 |
// handle in order to support Java-level exception handling. |
|
3950 |
||
3951 |
void os::Linux::install_signal_handlers() { |
|
3952 |
if (!signal_handlers_are_installed) { |
|
3953 |
signal_handlers_are_installed = true; |
|
3954 |
||
3955 |
// signal-chaining |
|
3956 |
typedef void (*signal_setting_t)(); |
|
3957 |
signal_setting_t begin_signal_setting = NULL; |
|
3958 |
signal_setting_t end_signal_setting = NULL; |
|
3959 |
begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t, |
|
3960 |
dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting")); |
|
3961 |
if (begin_signal_setting != NULL) { |
|
3962 |
end_signal_setting = CAST_TO_FN_PTR(signal_setting_t, |
|
3963 |
dlsym(RTLD_DEFAULT, "JVM_end_signal_setting")); |
|
3964 |
get_signal_action = CAST_TO_FN_PTR(get_signal_t, |
|
3965 |
dlsym(RTLD_DEFAULT, "JVM_get_signal_action")); |
|
3966 |
libjsig_is_loaded = true; |
|
3967 |
assert(UseSignalChaining, "should enable signal-chaining"); |
|
3968 |
} |
|
3969 |
if (libjsig_is_loaded) { |
|
3970 |
// Tell libjsig jvm is setting signal handlers |
|
3971 |
(*begin_signal_setting)(); |
|
3972 |
} |
|
3973 |
||
3974 |
set_signal_handler(SIGSEGV, true); |
|
3975 |
set_signal_handler(SIGPIPE, true); |
|
3976 |
set_signal_handler(SIGBUS, true); |
|
3977 |
set_signal_handler(SIGILL, true); |
|
3978 |
set_signal_handler(SIGFPE, true); |
|
3979 |
set_signal_handler(SIGXFSZ, true); |
|
3980 |
||
3981 |
if (libjsig_is_loaded) { |
|
3982 |
// Tell libjsig jvm finishes setting signal handlers |
|
3983 |
(*end_signal_setting)(); |
|
3984 |
} |
|
3985 |
||
3986 |
// We don't activate signal checker if libjsig is in place, we trust ourselves |
|
10561
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3987 |
// and if UserSignalHandler is installed all bets are off. |
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3988 |
// Log that signal checking is off only if -verbose:jni is specified. |
1 | 3989 |
if (CheckJNICalls) { |
3990 |
if (libjsig_is_loaded) { |
|
10561
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3991 |
if (PrintJNIResolving) { |
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3992 |
tty->print_cr("Info: libjsig is activated, all active signal checking is disabled"); |
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3993 |
} |
1 | 3994 |
check_signals = false; |
3995 |
} |
|
3996 |
if (AllowUserSignalHandlers) { |
|
10561
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3997 |
if (PrintJNIResolving) { |
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3998 |
tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled"); |
bf51fe78a9ad
7051189: Need to suppress info message if -xcheck:jni used with libjsig.so
kevinw
parents:
10522
diff
changeset
|
3999 |
} |
1 | 4000 |
check_signals = false; |
4001 |
} |
|
4002 |
} |
|
4003 |
} |
|
4004 |
} |
|
4005 |
||
4006 |
// This is the fastest way to get thread cpu time on Linux. |
|
4007 |
// Returns cpu time (user+sys) for any thread, not only for current. |
|
4008 |
// POSIX compliant clocks are implemented in the kernels 2.6.16+. |
|
4009 |
// It might work on 2.6.10+ with a special kernel/glibc patch. |
|
4010 |
// For reference, please, see IEEE Std 1003.1-2004: |
|
4011 |
// http://www.unix.org/single_unix_specification |
|
4012 |
||
4013 |
jlong os::Linux::fast_thread_cpu_time(clockid_t clockid) { |
|
4014 |
struct timespec tp; |
|
4015 |
int rc = os::Linux::clock_gettime(clockid, &tp); |
|
4016 |
assert(rc == 0, "clock_gettime is expected to return 0 code"); |
|
4017 |
||
11251
e29da6b5622b
7117303: VM uses non-monotonic time source and complains that it is non-monotonic
johnc
parents:
11161
diff
changeset
|
4018 |
return (tp.tv_sec * NANOSECS_PER_SEC) + tp.tv_nsec; |
1 | 4019 |
} |
4020 |
||
4021 |
///// |
|
4022 |
// glibc on Linux platform uses non-documented flag |
|
4023 |
// to indicate, that some special sort of signal |
|
4024 |
// trampoline is used. |
|
4025 |
// We will never set this flag, and we should |
|
4026 |
// ignore this flag in our diagnostic |
|
4027 |
#ifdef SIGNIFICANT_SIGNAL_MASK |
|
4028 |
#undef SIGNIFICANT_SIGNAL_MASK |
|
4029 |
#endif |
|
4030 |
#define SIGNIFICANT_SIGNAL_MASK (~0x04000000) |
|
4031 |
||
4032 |
static const char* get_signal_handler_name(address handler, |
|
4033 |
char* buf, int buflen) { |
|
4034 |
int offset; |
|
4035 |
bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset); |
|
4036 |
if (found) { |
|
4037 |
// skip directory names |
|
4038 |
const char *p1, *p2; |
|
4039 |
p1 = buf; |
|
4040 |
size_t len = strlen(os::file_separator()); |
|
4041 |
while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; |
|
4042 |
jio_snprintf(buf, buflen, "%s+0x%x", p1, offset); |
|
4043 |
} else { |
|
4044 |
jio_snprintf(buf, buflen, PTR_FORMAT, handler); |
|
4045 |
} |
|
4046 |
return buf; |
|
4047 |
} |
|
4048 |
||
4049 |
static void print_signal_handler(outputStream* st, int sig, |
|
4050 |
char* buf, size_t buflen) { |
|
4051 |
struct sigaction sa; |
|
4052 |
||
4053 |
sigaction(sig, NULL, &sa); |
|
4054 |
||
4055 |
// See comment for SIGNIFICANT_SIGNAL_MASK define |
|
4056 |
sa.sa_flags &= SIGNIFICANT_SIGNAL_MASK; |
|
4057 |
||
4058 |
st->print("%s: ", os::exception_name(sig, buf, buflen)); |
|
4059 |
||
4060 |
address handler = (sa.sa_flags & SA_SIGINFO) |
|
4061 |
? CAST_FROM_FN_PTR(address, sa.sa_sigaction) |
|
4062 |
: CAST_FROM_FN_PTR(address, sa.sa_handler); |
|
4063 |
||
4064 |
if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) { |
|
4065 |
st->print("SIG_DFL"); |
|
4066 |
} else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) { |
|
4067 |
st->print("SIG_IGN"); |
|
4068 |
} else { |
|
4069 |
st->print("[%s]", get_signal_handler_name(handler, buf, buflen)); |
|
4070 |
} |
|
4071 |
||
4072 |
st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask); |
|
4073 |
||
4074 |
address rh = VMError::get_resetted_sighandler(sig); |
|
4075 |
// May be, handler was resetted by VMError? |
|
4076 |
if(rh != NULL) { |
|
4077 |
handler = rh; |
|
4078 |
sa.sa_flags = VMError::get_resetted_sigflags(sig) & SIGNIFICANT_SIGNAL_MASK; |
|
4079 |
} |
|
4080 |
||
4081 |
st->print(", sa_flags=" PTR32_FORMAT, sa.sa_flags); |
|
4082 |
||
4083 |
// Check: is it our handler? |
|
4084 |
if(handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler) || |
|
4085 |
handler == CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler)) { |
|
4086 |
// It is our signal handler |
|
4087 |
// check for flags, reset system-used one! |
|
4088 |
if((int)sa.sa_flags != os::Linux::get_our_sigflags(sig)) { |
|
4089 |
st->print( |
|
4090 |
", flags was changed from " PTR32_FORMAT ", consider using jsig library", |
|
4091 |
os::Linux::get_our_sigflags(sig)); |
|
4092 |
} |
|
4093 |
} |
|
4094 |
st->cr(); |
|
4095 |
} |
|
4096 |
||
4097 |
||
4098 |
#define DO_SIGNAL_CHECK(sig) \ |
|
4099 |
if (!sigismember(&check_signal_done, sig)) \ |
|
4100 |
os::Linux::check_signal_handler(sig) |
|
4101 |
||
4102 |
// This method is a periodic task to check for misbehaving JNI applications |
|
4103 |
// under CheckJNI, we can add any periodic checks here |
|
4104 |
||
4105 |
void os::run_periodic_checks() { |
|
4106 |
||
4107 |
if (check_signals == false) return; |
|
4108 |
||
4109 |
// SEGV and BUS if overridden could potentially prevent |
|
4110 |
// generation of hs*.log in the event of a crash, debugging |
|
4111 |
// such a case can be very challenging, so we absolutely |
|
4112 |
// check the following for a good measure: |
|
4113 |
DO_SIGNAL_CHECK(SIGSEGV); |
|
4114 |
DO_SIGNAL_CHECK(SIGILL); |
|
4115 |
DO_SIGNAL_CHECK(SIGFPE); |
|
4116 |
DO_SIGNAL_CHECK(SIGBUS); |
|
4117 |
DO_SIGNAL_CHECK(SIGPIPE); |
|
4118 |
DO_SIGNAL_CHECK(SIGXFSZ); |
|
4119 |
||
4120 |
||
4121 |
// ReduceSignalUsage allows the user to override these handlers |
|
4122 |
// see comments at the very top and jvm_solaris.h |
|
4123 |
if (!ReduceSignalUsage) { |
|
4124 |
DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL); |
|
4125 |
DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL); |
|
4126 |
DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL); |
|
4127 |
DO_SIGNAL_CHECK(BREAK_SIGNAL); |
|
4128 |
} |
|
4129 |
||
4130 |
DO_SIGNAL_CHECK(SR_signum); |
|
4131 |
DO_SIGNAL_CHECK(INTERRUPT_SIGNAL); |
|
4132 |
} |
|
4133 |
||
4134 |
typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *); |
|
4135 |
||
4136 |
static os_sigaction_t os_sigaction = NULL; |
|
4137 |
||
4138 |
void os::Linux::check_signal_handler(int sig) { |
|
4139 |
char buf[O_BUFLEN]; |
|
4140 |
address jvmHandler = NULL; |
|
4141 |
||
4142 |
||
4143 |
struct sigaction act; |
|
4144 |
if (os_sigaction == NULL) { |
|
4145 |
// only trust the default sigaction, in case it has been interposed |
|
4146 |
os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction"); |
|
4147 |
if (os_sigaction == NULL) return; |
|
4148 |
} |
|
4149 |
||
4150 |
os_sigaction(sig, (struct sigaction*)NULL, &act); |
|
4151 |
||
4152 |
||
4153 |
act.sa_flags &= SIGNIFICANT_SIGNAL_MASK; |
|
4154 |
||
4155 |
address thisHandler = (act.sa_flags & SA_SIGINFO) |
|
4156 |
? CAST_FROM_FN_PTR(address, act.sa_sigaction) |
|
4157 |
: CAST_FROM_FN_PTR(address, act.sa_handler) ; |
|
4158 |
||
4159 |
||
4160 |
switch(sig) { |
|
4161 |
case SIGSEGV: |
|
4162 |
case SIGBUS: |
|
4163 |
case SIGFPE: |
|
4164 |
case SIGPIPE: |
|
4165 |
case SIGILL: |
|
4166 |
case SIGXFSZ: |
|
4167 |
jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)signalHandler); |
|
4168 |
break; |
|
4169 |
||
4170 |
case SHUTDOWN1_SIGNAL: |
|
4171 |
case SHUTDOWN2_SIGNAL: |
|
4172 |
case SHUTDOWN3_SIGNAL: |
|
4173 |
case BREAK_SIGNAL: |
|
4174 |
jvmHandler = (address)user_handler(); |
|
4175 |
break; |
|
4176 |
||
4177 |
case INTERRUPT_SIGNAL: |
|
4178 |
jvmHandler = CAST_FROM_FN_PTR(address, SIG_DFL); |
|
4179 |
break; |
|
4180 |
||
4181 |
default: |
|
4182 |
if (sig == SR_signum) { |
|
4183 |
jvmHandler = CAST_FROM_FN_PTR(address, (sa_sigaction_t)SR_handler); |
|
4184 |
} else { |
|
4185 |
return; |
|
4186 |
} |
|
4187 |
break; |
|
4188 |
} |
|
4189 |
||
4190 |
if (thisHandler != jvmHandler) { |
|
4191 |
tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN)); |
|
4192 |
tty->print("expected:%s", get_signal_handler_name(jvmHandler, buf, O_BUFLEN)); |
|
4193 |
tty->print_cr(" found:%s", get_signal_handler_name(thisHandler, buf, O_BUFLEN)); |
|
4194 |
// No need to check this sig any longer |
|
4195 |
sigaddset(&check_signal_done, sig); |
|
4196 |
} else if(os::Linux::get_our_sigflags(sig) != 0 && (int)act.sa_flags != os::Linux::get_our_sigflags(sig)) { |
|
4197 |
tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN)); |
|
4198 |
tty->print("expected:" PTR32_FORMAT, os::Linux::get_our_sigflags(sig)); |
|
4199 |
tty->print_cr(" found:" PTR32_FORMAT, act.sa_flags); |
|
4200 |
// No need to check this sig any longer |
|
4201 |
sigaddset(&check_signal_done, sig); |
|
4202 |
} |
|
4203 |
||
4204 |
// Dump all the signal |
|
4205 |
if (sigismember(&check_signal_done, sig)) { |
|
4206 |
print_signal_handlers(tty, buf, O_BUFLEN); |
|
4207 |
} |
|
4208 |
} |
|
4209 |
||
4210 |
extern void report_error(char* file_name, int line_no, char* title, char* format, ...); |
|
4211 |
||
4212 |
extern bool signal_name(int signo, char* buf, size_t len); |
|
4213 |
||
4214 |
const char* os::exception_name(int exception_code, char* buf, size_t size) { |
|
4215 |
if (0 < exception_code && exception_code <= SIGRTMAX) { |
|
4216 |
// signal |
|
4217 |
if (!signal_name(exception_code, buf, size)) { |
|
4218 |
jio_snprintf(buf, size, "SIG%d", exception_code); |
|
4219 |
} |
|
4220 |
return buf; |
|
4221 |
} else { |
|
4222 |
return NULL; |
|
4223 |
} |
|
4224 |
} |
|
4225 |
||
4226 |
// this is called _before_ the most of global arguments have been parsed |
|
4227 |
void os::init(void) { |
|
4228 |
char dummy; /* used to get a guess on initial stack address */ |
|
4229 |
// first_hrtime = gethrtime(); |
|
4230 |
||
4231 |
// With LinuxThreads the JavaMain thread pid (primordial thread) |
|
4232 |
// is different than the pid of the java launcher thread. |
|
4233 |
// So, on Linux, the launcher thread pid is passed to the VM |
|
4234 |
// via the sun.java.launcher.pid property. |
|
4235 |
// Use this property instead of getpid() if it was correctly passed. |
|
4236 |
// See bug 6351349. |
|
4237 |
pid_t java_launcher_pid = (pid_t) Arguments::sun_java_launcher_pid(); |
|
4238 |
||
4239 |
_initial_pid = (java_launcher_pid > 0) ? java_launcher_pid : getpid(); |
|
4240 |
||
4241 |
clock_tics_per_sec = sysconf(_SC_CLK_TCK); |
|
4242 |
||
4243 |
init_random(1234567); |
|
4244 |
||
4245 |
ThreadCritical::initialize(); |
|
4246 |
||
4247 |
Linux::set_page_size(sysconf(_SC_PAGESIZE)); |
|
4248 |
if (Linux::page_size() == -1) { |
|
5403
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
5237
diff
changeset
|
4249 |
fatal(err_msg("os_linux.cpp: os::init: sysconf failed (%s)", |
6b0dd9c75dde
6888954: argument formatting for assert() and friends
jcoomes
parents:
5237
diff
changeset
|
4250 |
strerror(errno))); |
1 | 4251 |
} |
4252 |
init_page_sizes((size_t) Linux::page_size()); |
|
4253 |
||
4254 |
Linux::initialize_system_info(); |
|
4255 |
||
4256 |
// main_thread points to the aboriginal thread |
|
4257 |
Linux::_main_thread = pthread_self(); |
|
4258 |
||
4259 |
Linux::clock_init(); |
|
4260 |
initial_time_count = os::elapsed_counter(); |
|
950 | 4261 |
pthread_mutex_init(&dl_mutex, NULL); |
1 | 4262 |
} |
4263 |
||
4264 |
// To install functions for atexit system call |
|
4265 |
extern "C" { |
|
4266 |
static void perfMemory_exit_helper() { |
|
4267 |
perfMemory_exit(); |
|
4268 |
} |
|
4269 |
} |
|
4270 |
||
4271 |
// this is called _after_ the global arguments have been parsed |
|
4272 |
jint os::init_2(void) |
|
4273 |
{ |
|
4274 |
Linux::fast_thread_clock_init(); |
|
4275 |
||
4276 |
// Allocate a single page and mark it as readable for safepoint polling |
|
4277 |
address polling_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
|
4278 |
guarantee( polling_page != MAP_FAILED, "os::init_2: failed to allocate polling page" ); |
|
4279 |
||
4280 |
os::set_polling_page( polling_page ); |
|
4281 |
||
4282 |
#ifndef PRODUCT |
|
4283 |
if(Verbose && PrintMiscellaneous) |
|
4284 |
tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); |
|
4285 |
#endif |
|
4286 |
||
4287 |
if (!UseMembar) { |
|
4288 |
address mem_serialize_page = (address) ::mmap(NULL, Linux::page_size(), PROT_READ | PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0); |
|
4289 |
guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page"); |
|
4290 |
os::set_memory_serialize_page( mem_serialize_page ); |
|
4291 |
||
4292 |
#ifndef PRODUCT |
|
4293 |
if(Verbose && PrintMiscellaneous) |
|
4294 |
tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); |
|
4295 |
#endif |
|
4296 |
} |
|
4297 |
||
9419
f0360dfe734d
7040485: Use transparent huge page on linux by default
iveresov
parents:
9341
diff
changeset
|
4298 |
os::large_page_init(); |
1 | 4299 |
|
4300 |
// initialize suspend/resume support - must do this before signal_sets_init() |
|
4301 |
if (SR_initialize() != 0) { |
|
4302 |
perror("SR_initialize failed"); |
|
4303 |
return JNI_ERR; |
|
4304 |
} |
|
4305 |
||
4306 |
Linux::signal_sets_init(); |
|
4307 |
Linux::install_signal_handlers(); |
|
4308 |
||
6964
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4309 |
// Check minimum allowable stack size for thread creation and to initialize |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4310 |
// the java system classes, including StackOverflowError - depends on page |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4311 |
// size. Add a page for compiler2 recursion in main thread. |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4312 |
// Add in 2*BytesPerWord times page size to account for VM stack during |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4313 |
// class initialization depending on 32 or 64 bit VM. |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4314 |
os::Linux::min_stack_allowed = MAX2(os::Linux::min_stack_allowed, |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4315 |
(size_t)(StackYellowPages+StackRedPages+StackShadowPages+ |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4316 |
2*BytesPerWord COMPILER2_PRESENT(+1)) * Linux::page_size()); |
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4317 |
|
1 | 4318 |
size_t threadStackSizeInBytes = ThreadStackSize * K; |
4319 |
if (threadStackSizeInBytes != 0 && |
|
6964
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4320 |
threadStackSizeInBytes < os::Linux::min_stack_allowed) { |
1 | 4321 |
tty->print_cr("\nThe stack size specified is too small, " |
4322 |
"Specify at least %dk", |
|
6964
6e45ffa3bccf
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
6962
diff
changeset
|
4323 |
os::Linux::min_stack_allowed/ K); |
1 | 4324 |
return JNI_ERR; |
4325 |
} |
|
4326 |
||
4327 |
// Make the stack size a multiple of the page size so that |
|
4328 |
// the yellow/red zones can be guarded. |
|
4329 |
JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, |
|
4330 |
vm_page_size())); |
|
4331 |
||
4332 |
Linux::capture_initial_stack(JavaThread::stack_size_at_create()); |
|
4333 |
||
4334 |
Linux::libpthread_init(); |
|
4335 |
if (PrintMiscellaneous && (Verbose || WizardMode)) { |
|
4336 |
tty->print_cr("[HotSpot is running with %s, %s(%s)]\n", |
|
4337 |
Linux::glibc_version(), Linux::libpthread_version(), |
|
4338 |
Linux::is_floating_stack() ? "floating stack" : "fixed stack"); |
|
4339 |
} |
|
4340 |
||
388 | 4341 |
if (UseNUMA) { |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4342 |
if (!Linux::libnuma_init()) { |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4343 |
UseNUMA = false; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4344 |
} else { |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4345 |
if ((Linux::numa_max_node() < 1)) { |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4346 |
// There's only one node(they start from 0), disable NUMA. |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4347 |
UseNUMA = false; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4348 |
} |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4349 |
} |
9341
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4350 |
// With SHM large pages we cannot uncommit a page, so there's not way |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4351 |
// we can make the adaptive lgrp chunk resizing work. If the user specified |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4352 |
// both UseNUMA and UseLargePages (or UseSHM) on the command line - warn and |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4353 |
// disable adaptive resizing. |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4354 |
if (UseNUMA && UseLargePages && UseSHM) { |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4355 |
if (!FLAG_IS_DEFAULT(UseNUMA)) { |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4356 |
if (FLAG_IS_DEFAULT(UseLargePages) && FLAG_IS_DEFAULT(UseSHM)) { |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4357 |
UseLargePages = false; |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4358 |
} else { |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4359 |
warning("UseNUMA is not fully compatible with SHM large pages, disabling adaptive resizing"); |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4360 |
UseAdaptiveSizePolicy = false; |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4361 |
UseAdaptiveNUMAChunkSizing = false; |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4362 |
} |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4363 |
} else { |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4364 |
UseNUMA = false; |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4365 |
} |
347fa5cdbd39
7037939: NUMA: Disable adaptive resizing if SHM large pages are used
iveresov
parents:
9339
diff
changeset
|
4366 |
} |
1615
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4367 |
if (!UseNUMA && ForceNUMA) { |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4368 |
UseNUMA = true; |
b46d9f19bde2
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
1388
diff
changeset
|
4369 |
} |
388 | 4370 |
} |
4371 |
||
1 | 4372 |
if (MaxFDLimit) { |
4373 |
// set the number of file descriptors to max. print out error |
|
4374 |
// if getrlimit/setrlimit fails but continue regardless. |
|
4375 |
struct rlimit nbr_files; |
|
4376 |
int status = getrlimit(RLIMIT_NOFILE, &nbr_files); |
|
4377 |
if (status != 0) { |
|
4378 |
if (PrintMiscellaneous && (Verbose || WizardMode)) |
|
4379 |
perror("os::init_2 getrlimit failed"); |
|
4380 |
} else { |
|
4381 |
nbr_files.rlim_cur = nbr_files.rlim_max; |
|
4382 |
status = setrlimit(RLIMIT_NOFILE, &nbr_files); |
|
4383 |
if (status != 0) { |
|
4384 |
if (PrintMiscellaneous && (Verbose || WizardMode)) |
|
4385 |
perror("os::init_2 setrlimit failed"); |
|
4386 |
} |
|
4387 |
} |
|
4388 |
} |
|
4389 |
||
4390 |
// Initialize lock used to serialize thread creation (see os::create_thread) |
|
4391 |
Linux::set_createThread_lock(new Mutex(Mutex::leaf, "createThread_lock", false)); |
|
4392 |
||
4393 |
// at-exit methods are called in the reverse order of their registration. |
|
4394 |
// atexit functions are called on return from main or as a result of a |
|
4395 |
// call to exit(3C). There can be only 32 of these functions registered |
|
4396 |
// and atexit() does not set errno. |
|
4397 |
||
4398 |
if (PerfAllowAtExitRegistration) { |
|
4399 |
// only register atexit functions if PerfAllowAtExitRegistration is set. |
|
4400 |
// atexit functions can be delayed until process exit time, which |
|
4401 |
// can be problematic for embedded VM situations. Embedded VMs should |
|
4402 |
// call DestroyJavaVM() to assure that VM resources are released. |
|
4403 |
||
4404 |
// note: perfMemory_exit_helper atexit function may be removed in |
|
4405 |
// the future if the appropriate cleanup code can be added to the |
|
4406 |
// VM_Exit VMOperation's doit method. |
|
4407 |
if (atexit(perfMemory_exit_helper) != 0) { |
|
4408 |
warning("os::init2 atexit(perfMemory_exit_helper) failed"); |
|
4409 |
} |
|
4410 |
} |
|
4411 |
||
4412 |
// initialize thread priority policy |
|
4413 |
prio_init(); |
|
4414 |
||
4415 |
return JNI_OK; |
|
4416 |
} |
|
4417 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4418 |
// this is called at the end of vm_initialization |
10025
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4419 |
void os::init_3(void) |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4420 |
{ |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4421 |
#ifdef JAVASE_EMBEDDED |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4422 |
// Start the MemNotifyThread |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4423 |
if (LowMemoryProtection) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4424 |
MemNotifyThread::start(); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4425 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4426 |
return; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4427 |
#endif |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
4428 |
} |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4429 |
|
1 | 4430 |
// Mark the polling page as unreadable |
4431 |
void os::make_polling_page_unreadable(void) { |
|
4432 |
if( !guard_memory((char*)_polling_page, Linux::page_size()) ) |
|
4433 |
fatal("Could not disable polling page"); |
|
4434 |
}; |
|
4435 |
||
4436 |
// Mark the polling page as readable |
|
4437 |
void os::make_polling_page_readable(void) { |
|
823
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
4438 |
if( !linux_mprotect((char *)_polling_page, Linux::page_size(), PROT_READ)) { |
1 | 4439 |
fatal("Could not enable polling page"); |
823
9a5271881bc0
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
781
diff
changeset
|
4440 |
} |
1 | 4441 |
}; |
4442 |
||
4443 |
int os::active_processor_count() { |
|
4444 |
// Linux doesn't yet have a (official) notion of processor sets, |
|
4445 |
// so just return the number of online processors. |
|
4446 |
int online_cpus = ::sysconf(_SC_NPROCESSORS_ONLN); |
|
4447 |
assert(online_cpus > 0 && online_cpus <= processor_count(), "sanity check"); |
|
4448 |
return online_cpus; |
|
4449 |
} |
|
4450 |
||
10739 | 4451 |
void os::set_native_thread_name(const char *name) { |
4452 |
// Not yet implemented. |
|
4453 |
return; |
|
4454 |
} |
|
4455 |
||
1 | 4456 |
bool os::distribute_processes(uint length, uint* distribution) { |
4457 |
// Not yet implemented. |
|
4458 |
return false; |
|
4459 |
} |
|
4460 |
||
4461 |
bool os::bind_to_processor(uint processor_id) { |
|
4462 |
// Not yet implemented. |
|
4463 |
return false; |
|
4464 |
} |
|
4465 |
||
4466 |
/// |
|
4467 |
||
4468 |
// Suspends the target using the signal mechanism and then grabs the PC before |
|
4469 |
// resuming the target. Used by the flat-profiler only |
|
4470 |
ExtendedPC os::get_thread_pc(Thread* thread) { |
|
4471 |
// Make sure that it is called by the watcher for the VMThread |
|
4472 |
assert(Thread::current()->is_Watcher_thread(), "Must be watcher"); |
|
4473 |
assert(thread->is_VM_thread(), "Can only be called for VMThread"); |
|
4474 |
||
4475 |
ExtendedPC epc; |
|
4476 |
||
4477 |
OSThread* osthread = thread->osthread(); |
|
4478 |
if (do_suspend(osthread)) { |
|
4479 |
if (osthread->ucontext() != NULL) { |
|
4480 |
epc = os::Linux::ucontext_get_pc(osthread->ucontext()); |
|
4481 |
} else { |
|
4482 |
// NULL context is unexpected, double-check this is the VMThread |
|
4483 |
guarantee(thread->is_VM_thread(), "can only be called for VMThread"); |
|
4484 |
} |
|
4485 |
do_resume(osthread); |
|
4486 |
} |
|
4487 |
// failure means pthread_kill failed for some reason - arguably this is |
|
4488 |
// a fatal problem, but such problems are ignored elsewhere |
|
4489 |
||
4490 |
return epc; |
|
4491 |
} |
|
4492 |
||
4493 |
int os::Linux::safe_cond_timedwait(pthread_cond_t *_cond, pthread_mutex_t *_mutex, const struct timespec *_abstime) |
|
4494 |
{ |
|
4495 |
if (is_NPTL()) { |
|
4496 |
return pthread_cond_timedwait(_cond, _mutex, _abstime); |
|
4497 |
} else { |
|
4498 |
// 6292965: LinuxThreads pthread_cond_timedwait() resets FPU control |
|
4499 |
// word back to default 64bit precision if condvar is signaled. Java |
|
4500 |
// wants 53bit precision. Save and restore current value. |
|
4501 |
int fpu = get_fpu_control_word(); |
|
4502 |
int status = pthread_cond_timedwait(_cond, _mutex, _abstime); |
|
4503 |
set_fpu_control_word(fpu); |
|
4504 |
return status; |
|
4505 |
} |
|
4506 |
} |
|
4507 |
||
4508 |
//////////////////////////////////////////////////////////////////////////////// |
|
4509 |
// debug support |
|
4510 |
||
4511 |
static address same_page(address x, address y) { |
|
4512 |
int page_bits = -os::vm_page_size(); |
|
4513 |
if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits)) |
|
4514 |
return x; |
|
4515 |
else if (x > y) |
|
4516 |
return (address)(intptr_t(y) | ~page_bits) + 1; |
|
4517 |
else |
|
4518 |
return (address)(intptr_t(y) & page_bits); |
|
4519 |
} |
|
4520 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4521 |
bool os::find(address addr, outputStream* st) { |
1 | 4522 |
Dl_info dlinfo; |
4523 |
memset(&dlinfo, 0, sizeof(dlinfo)); |
|
4524 |
if (dladdr(addr, &dlinfo)) { |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4525 |
st->print(PTR_FORMAT ": ", addr); |
1 | 4526 |
if (dlinfo.dli_sname != NULL) { |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4527 |
st->print("%s+%#x", dlinfo.dli_sname, |
1 | 4528 |
addr - (intptr_t)dlinfo.dli_saddr); |
4529 |
} else if (dlinfo.dli_fname) { |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4530 |
st->print("<offset %#x>", addr - (intptr_t)dlinfo.dli_fbase); |
1 | 4531 |
} else { |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4532 |
st->print("<absolute address>"); |
1 | 4533 |
} |
4534 |
if (dlinfo.dli_fname) { |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4535 |
st->print(" in %s", dlinfo.dli_fname); |
1 | 4536 |
} |
4537 |
if (dlinfo.dli_fbase) { |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4538 |
st->print(" at " PTR_FORMAT, dlinfo.dli_fbase); |
1 | 4539 |
} |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4540 |
st->cr(); |
1 | 4541 |
|
4542 |
if (Verbose) { |
|
4543 |
// decode some bytes around the PC |
|
4544 |
address begin = same_page(addr-40, addr); |
|
4545 |
address end = same_page(addr+40, addr); |
|
4546 |
address lowest = (address) dlinfo.dli_sname; |
|
4547 |
if (!lowest) lowest = (address) dlinfo.dli_fbase; |
|
4548 |
if (begin < lowest) begin = lowest; |
|
4549 |
Dl_info dlinfo2; |
|
4550 |
if (dladdr(end, &dlinfo2) && dlinfo2.dli_saddr != dlinfo.dli_saddr |
|
4551 |
&& end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) |
|
4552 |
end = (address) dlinfo2.dli_saddr; |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4553 |
Disassembler::decode(begin, end, st); |
1 | 4554 |
} |
4555 |
return true; |
|
4556 |
} |
|
4557 |
return false; |
|
4558 |
} |
|
4559 |
||
4560 |
//////////////////////////////////////////////////////////////////////////////// |
|
4561 |
// misc |
|
4562 |
||
4563 |
// This does not do anything on Linux. This is basically a hook for being |
|
4564 |
// able to use structured exception handling (thread-local exception filters) |
|
4565 |
// on, e.g., Win32. |
|
4566 |
void |
|
4567 |
os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, |
|
4568 |
JavaCallArguments* args, Thread* thread) { |
|
4569 |
f(value, method, args, thread); |
|
4570 |
} |
|
4571 |
||
4572 |
void os::print_statistics() { |
|
4573 |
} |
|
4574 |
||
4575 |
int os::message_box(const char* title, const char* message) { |
|
4576 |
int i; |
|
4577 |
fdStream err(defaultStream::error_fd()); |
|
4578 |
for (i = 0; i < 78; i++) err.print_raw("="); |
|
4579 |
err.cr(); |
|
4580 |
err.print_raw_cr(title); |
|
4581 |
for (i = 0; i < 78; i++) err.print_raw("-"); |
|
4582 |
err.cr(); |
|
4583 |
err.print_raw_cr(message); |
|
4584 |
for (i = 0; i < 78; i++) err.print_raw("="); |
|
4585 |
err.cr(); |
|
4586 |
||
4587 |
char buf[16]; |
|
4588 |
// Prevent process from exiting upon "read error" without consuming all CPU |
|
4589 |
while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); } |
|
4590 |
||
4591 |
return buf[0] == 'y' || buf[0] == 'Y'; |
|
4592 |
} |
|
4593 |
||
4594 |
int os::stat(const char *path, struct stat *sbuf) { |
|
4595 |
char pathbuf[MAX_PATH]; |
|
4596 |
if (strlen(path) > MAX_PATH - 1) { |
|
4597 |
errno = ENAMETOOLONG; |
|
4598 |
return -1; |
|
4599 |
} |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4600 |
os::native_path(strcpy(pathbuf, path)); |
1 | 4601 |
return ::stat(pathbuf, sbuf); |
4602 |
} |
|
4603 |
||
4604 |
bool os::check_heap(bool force) { |
|
4605 |
return true; |
|
4606 |
} |
|
4607 |
||
4608 |
int local_vsnprintf(char* buf, size_t count, const char* format, va_list args) { |
|
4609 |
return ::vsnprintf(buf, count, format, args); |
|
4610 |
} |
|
4611 |
||
4612 |
// Is a (classpath) directory empty? |
|
4613 |
bool os::dir_is_empty(const char* path) { |
|
4614 |
DIR *dir = NULL; |
|
4615 |
struct dirent *ptr; |
|
4616 |
||
4617 |
dir = opendir(path); |
|
4618 |
if (dir == NULL) return true; |
|
4619 |
||
4620 |
/* Scan the directory */ |
|
4621 |
bool result = true; |
|
4622 |
char buf[sizeof(struct dirent) + MAX_PATH]; |
|
4623 |
while (result && (ptr = ::readdir(dir)) != NULL) { |
|
4624 |
if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { |
|
4625 |
result = false; |
|
4626 |
} |
|
4627 |
} |
|
4628 |
closedir(dir); |
|
4629 |
return result; |
|
4630 |
} |
|
4631 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4632 |
// This code originates from JDK's sysOpen and open64_w |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4633 |
// from src/solaris/hpi/src/system_md.c |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4634 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4635 |
#ifndef O_DELETE |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4636 |
#define O_DELETE 0x10000 |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4637 |
#endif |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4638 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4639 |
// Open a file. Unlink the file immediately after open returns |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4640 |
// if the specified oflag has the O_DELETE flag set. |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4641 |
// O_DELETE is used only in j2se/src/share/native/java/util/zip/ZipFile.c |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4642 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4643 |
int os::open(const char *path, int oflag, int mode) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4644 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4645 |
if (strlen(path) > MAX_PATH - 1) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4646 |
errno = ENAMETOOLONG; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4647 |
return -1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4648 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4649 |
int fd; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4650 |
int o_delete = (oflag & O_DELETE); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4651 |
oflag = oflag & ~O_DELETE; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4652 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4653 |
fd = ::open64(path, oflag, mode); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4654 |
if (fd == -1) return -1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4655 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4656 |
//If the open succeeded, the file might still be a directory |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4657 |
{ |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4658 |
struct stat64 buf64; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4659 |
int ret = ::fstat64(fd, &buf64); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4660 |
int st_mode = buf64.st_mode; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4661 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4662 |
if (ret != -1) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4663 |
if ((st_mode & S_IFMT) == S_IFDIR) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4664 |
errno = EISDIR; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4665 |
::close(fd); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4666 |
return -1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4667 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4668 |
} else { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4669 |
::close(fd); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4670 |
return -1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4671 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4672 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4673 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4674 |
/* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4675 |
* All file descriptors that are opened in the JVM and not |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4676 |
* specifically destined for a subprocess should have the |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4677 |
* close-on-exec flag set. If we don't set it, then careless 3rd |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4678 |
* party native code might fork and exec without closing all |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4679 |
* appropriate file descriptors (e.g. as we do in closeDescriptors in |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4680 |
* UNIXProcess.c), and this in turn might: |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4681 |
* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4682 |
* - cause end-of-file to fail to be detected on some file |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4683 |
* descriptors, resulting in mysterious hangs, or |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4684 |
* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4685 |
* - might cause an fopen in the subprocess to fail on a system |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4686 |
* suffering from bug 1085341. |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4687 |
* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4688 |
* (Yes, the default setting of the close-on-exec flag is a Unix |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4689 |
* design flaw) |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4690 |
* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4691 |
* See: |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4692 |
* 1085341: 32-bit stdio routines should support file descriptors >255 |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4693 |
* 4843136: (process) pipe file descriptor from Runtime.exec not being closed |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4694 |
* 6339493: (process) Runtime.exec does not close all file descriptors on Solaris 9 |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4695 |
*/ |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4696 |
#ifdef FD_CLOEXEC |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4697 |
{ |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4698 |
int flags = ::fcntl(fd, F_GETFD); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4699 |
if (flags != -1) |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4700 |
::fcntl(fd, F_SETFD, flags | FD_CLOEXEC); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4701 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4702 |
#endif |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4703 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4704 |
if (o_delete != 0) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4705 |
::unlink(path); |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4706 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4707 |
return fd; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4708 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4709 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4710 |
|
1 | 4711 |
// create binary file, rewriting existing file if required |
4712 |
int os::create_binary_file(const char* path, bool rewrite_existing) { |
|
4713 |
int oflags = O_WRONLY | O_CREAT; |
|
4714 |
if (!rewrite_existing) { |
|
4715 |
oflags |= O_EXCL; |
|
4716 |
} |
|
4717 |
return ::open64(path, oflags, S_IREAD | S_IWRITE); |
|
4718 |
} |
|
4719 |
||
4720 |
// return current position of file pointer |
|
4721 |
jlong os::current_file_offset(int fd) { |
|
4722 |
return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR); |
|
4723 |
} |
|
4724 |
||
4725 |
// move file pointer to the specified offset |
|
4726 |
jlong os::seek_to_file_offset(int fd, jlong offset) { |
|
4727 |
return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); |
|
4728 |
} |
|
4729 |
||
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4730 |
// This code originates from JDK's sysAvailable |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4731 |
// from src/solaris/hpi/src/native_threads/src/sys_api_td.c |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4732 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4733 |
int os::available(int fd, jlong *bytes) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4734 |
jlong cur, end; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4735 |
int mode; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4736 |
struct stat64 buf64; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4737 |
|
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4738 |
if (::fstat64(fd, &buf64) >= 0) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4739 |
mode = buf64.st_mode; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4740 |
if (S_ISCHR(mode) || S_ISFIFO(mode) || S_ISSOCK(mode)) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4741 |
/* |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4742 |
* XXX: is the following call interruptible? If so, this might |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4743 |
* need to go through the INTERRUPT_IO() wrapper as for other |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4744 |
* blocking, interruptible calls in this file. |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4745 |
*/ |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4746 |
int n; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4747 |
if (::ioctl(fd, FIONREAD, &n) >= 0) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4748 |
*bytes = n; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4749 |
return 1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4750 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4751 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4752 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4753 |
if ((cur = ::lseek64(fd, 0L, SEEK_CUR)) == -1) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4754 |
return 0; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4755 |
} else if ((end = ::lseek64(fd, 0L, SEEK_END)) == -1) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4756 |
return 0; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4757 |
} else if (::lseek64(fd, cur, SEEK_SET) == -1) { |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4758 |
return 0; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4759 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4760 |
*bytes = end - cur; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4761 |
return 1; |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4762 |
} |
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4763 |
|
7458
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4764 |
int os::socket_available(int fd, jint *pbytes) { |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4765 |
// Linux doc says EINTR not returned, unlike Solaris |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4766 |
int ret = ::ioctl(fd, FIONREAD, pbytes); |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4767 |
|
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4768 |
//%% note ioctl can return 0 when successful, JVM_SocketAvailable |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4769 |
// is expected to return 0 on failure and 1 on success to the jdk. |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4770 |
return (ret < 0) ? 0 : 1; |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4771 |
} |
3f956542f1fd
7003707: need to remove (some) system include files from the HotSpot header files
dholmes
parents:
7448
diff
changeset
|
4772 |
|
1 | 4773 |
// Map a block of memory. |
13195 | 4774 |
char* os::pd_map_memory(int fd, const char* file_name, size_t file_offset, |
1 | 4775 |
char *addr, size_t bytes, bool read_only, |
4776 |
bool allow_exec) { |
|
4777 |
int prot; |
|
11967 | 4778 |
int flags = MAP_PRIVATE; |
1 | 4779 |
|
4780 |
if (read_only) { |
|
4781 |
prot = PROT_READ; |
|
4782 |
} else { |
|
4783 |
prot = PROT_READ | PROT_WRITE; |
|
4784 |
} |
|
4785 |
||
4786 |
if (allow_exec) { |
|
4787 |
prot |= PROT_EXEC; |
|
4788 |
} |
|
4789 |
||
4790 |
if (addr != NULL) { |
|
4791 |
flags |= MAP_FIXED; |
|
4792 |
} |
|
4793 |
||
4794 |
char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags, |
|
4795 |
fd, file_offset); |
|
4796 |
if (mapped_address == MAP_FAILED) { |
|
4797 |
return NULL; |
|
4798 |
} |
|
4799 |
return mapped_address; |
|
4800 |
} |
|
4801 |
||
4802 |
||
4803 |
// Remap a block of memory. |
|
13195 | 4804 |
char* os::pd_remap_memory(int fd, const char* file_name, size_t file_offset, |
1 | 4805 |
char *addr, size_t bytes, bool read_only, |
4806 |
bool allow_exec) { |
|
4807 |
// same as map_memory() on this OS |
|
4808 |
return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only, |
|
4809 |
allow_exec); |
|
4810 |
} |
|
4811 |
||
4812 |
||
4813 |
// Unmap a block of memory. |
|
13195 | 4814 |
bool os::pd_unmap_memory(char* addr, size_t bytes) { |
1 | 4815 |
return munmap(addr, bytes) == 0; |
4816 |
} |
|
4817 |
||
4818 |
static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time); |
|
4819 |
||
4820 |
static clockid_t thread_cpu_clockid(Thread* thread) { |
|
4821 |
pthread_t tid = thread->osthread()->pthread_id(); |
|
4822 |
clockid_t clockid; |
|
4823 |
||
4824 |
// Get thread clockid |
|
4825 |
int rc = os::Linux::pthread_getcpuclockid(tid, &clockid); |
|
4826 |
assert(rc == 0, "pthread_getcpuclockid is expected to return 0 code"); |
|
4827 |
return clockid; |
|
4828 |
} |
|
4829 |
||
4830 |
// current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool) |
|
4831 |
// are used by JVM M&M and JVMTI to get user+sys or user CPU time |
|
4832 |
// of a thread. |
|
4833 |
// |
|
4834 |
// current_thread_cpu_time() and thread_cpu_time(Thread*) returns |
|
4835 |
// the fast estimate available on the platform. |
|
4836 |
||
4837 |
jlong os::current_thread_cpu_time() { |
|
4838 |
if (os::Linux::supports_fast_thread_cpu_time()) { |
|
4839 |
return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID); |
|
4840 |
} else { |
|
4841 |
// return user + sys since the cost is the same |
|
4842 |
return slow_thread_cpu_time(Thread::current(), true /* user + sys */); |
|
4843 |
} |
|
4844 |
} |
|
4845 |
||
4846 |
jlong os::thread_cpu_time(Thread* thread) { |
|
4847 |
// consistent with what current_thread_cpu_time() returns |
|
4848 |
if (os::Linux::supports_fast_thread_cpu_time()) { |
|
4849 |
return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread)); |
|
4850 |
} else { |
|
4851 |
return slow_thread_cpu_time(thread, true /* user + sys */); |
|
4852 |
} |
|
4853 |
} |
|
4854 |
||
4855 |
jlong os::current_thread_cpu_time(bool user_sys_cpu_time) { |
|
4856 |
if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) { |
|
4857 |
return os::Linux::fast_thread_cpu_time(CLOCK_THREAD_CPUTIME_ID); |
|
4858 |
} else { |
|
4859 |
return slow_thread_cpu_time(Thread::current(), user_sys_cpu_time); |
|
4860 |
} |
|
4861 |
} |
|
4862 |
||
4863 |
jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { |
|
4864 |
if (user_sys_cpu_time && os::Linux::supports_fast_thread_cpu_time()) { |
|
4865 |
return os::Linux::fast_thread_cpu_time(thread_cpu_clockid(thread)); |
|
4866 |
} else { |
|
4867 |
return slow_thread_cpu_time(thread, user_sys_cpu_time); |
|
4868 |
} |
|
4869 |
} |
|
4870 |
||
4871 |
// |
|
4872 |
// -1 on error. |
|
4873 |
// |
|
4874 |
||
4875 |
static jlong slow_thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { |
|
4876 |
static bool proc_task_unchecked = true; |
|
4877 |
static const char *proc_stat_path = "/proc/%d/stat"; |
|
4878 |
pid_t tid = thread->osthread()->thread_id(); |
|
4879 |
char *s; |
|
4880 |
char stat[2048]; |
|
4881 |
int statlen; |
|
4882 |
char proc_name[64]; |
|
4883 |
int count; |
|
4884 |
long sys_time, user_time; |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4885 |
char cdummy; |
1 | 4886 |
int idummy; |
4887 |
long ldummy; |
|
4888 |
FILE *fp; |
|
4889 |
||
4890 |
// The /proc/<tid>/stat aggregates per-process usage on |
|
4891 |
// new Linux kernels 2.6+ where NPTL is supported. |
|
4892 |
// The /proc/self/task/<tid>/stat still has the per-thread usage. |
|
4893 |
// See bug 6328462. |
|
15794
af92b7196818
8004495: [parfait] False positive Buffer overflow in hotspot/src/os/linux/vm/os_linux.cpp
hseigel
parents:
15743
diff
changeset
|
4894 |
// There possibly can be cases where there is no directory |
af92b7196818
8004495: [parfait] False positive Buffer overflow in hotspot/src/os/linux/vm/os_linux.cpp
hseigel
parents:
15743
diff
changeset
|
4895 |
// /proc/self/task, so we check its availability. |
1 | 4896 |
if (proc_task_unchecked && os::Linux::is_NPTL()) { |
4897 |
// This is executed only once |
|
4898 |
proc_task_unchecked = false; |
|
4899 |
fp = fopen("/proc/self/task", "r"); |
|
4900 |
if (fp != NULL) { |
|
4901 |
proc_stat_path = "/proc/self/task/%d/stat"; |
|
4902 |
fclose(fp); |
|
4903 |
} |
|
4904 |
} |
|
4905 |
||
4906 |
sprintf(proc_name, proc_stat_path, tid); |
|
4907 |
fp = fopen(proc_name, "r"); |
|
4908 |
if ( fp == NULL ) return -1; |
|
4909 |
statlen = fread(stat, 1, 2047, fp); |
|
4910 |
stat[statlen] = '\0'; |
|
4911 |
fclose(fp); |
|
4912 |
||
4913 |
// Skip pid and the command string. Note that we could be dealing with |
|
4914 |
// weird command names, e.g. user could decide to rename java launcher |
|
4915 |
// to "java 1.4.2 :)", then the stat file would look like |
|
4916 |
// 1234 (java 1.4.2 :)) R ... ... |
|
4917 |
// We don't really need to know the command string, just find the last |
|
4918 |
// occurrence of ")" and then start parsing from there. See bug 4726580. |
|
4919 |
s = strrchr(stat, ')'); |
|
4920 |
if (s == NULL ) return -1; |
|
4921 |
||
4922 |
// Skip blank chars |
|
4923 |
do s++; while (isspace(*s)); |
|
4924 |
||
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4925 |
count = sscanf(s,"%c %d %d %d %d %d %lu %lu %lu %lu %lu %lu %lu", |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4926 |
&cdummy, &idummy, &idummy, &idummy, &idummy, &idummy, |
1 | 4927 |
&ldummy, &ldummy, &ldummy, &ldummy, &ldummy, |
4928 |
&user_time, &sys_time); |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
4929 |
if ( count != 13 ) return -1; |
1 | 4930 |
if (user_sys_cpu_time) { |
4931 |
return ((jlong)sys_time + (jlong)user_time) * (1000000000 / clock_tics_per_sec); |
|
4932 |
} else { |
|
4933 |
return (jlong)user_time * (1000000000 / clock_tics_per_sec); |
|
4934 |
} |
|
4935 |
} |
|
4936 |
||
4937 |
void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { |
|
4938 |
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits |
|
4939 |
info_ptr->may_skip_backward = false; // elapsed time not wall time |
|
4940 |
info_ptr->may_skip_forward = false; // elapsed time not wall time |
|
4941 |
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned |
|
4942 |
} |
|
4943 |
||
4944 |
void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { |
|
4945 |
info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits |
|
4946 |
info_ptr->may_skip_backward = false; // elapsed time not wall time |
|
4947 |
info_ptr->may_skip_forward = false; // elapsed time not wall time |
|
4948 |
info_ptr->kind = JVMTI_TIMER_TOTAL_CPU; // user+system time is returned |
|
4949 |
} |
|
4950 |
||
4951 |
bool os::is_thread_cpu_time_supported() { |
|
4952 |
return true; |
|
4953 |
} |
|
4954 |
||
4955 |
// System loadavg support. Returns -1 if load average cannot be obtained. |
|
4956 |
// Linux doesn't yet have a (official) notion of processor sets, |
|
4957 |
// so just return the system wide load average. |
|
4958 |
int os::loadavg(double loadavg[], int nelem) { |
|
4959 |
return ::getloadavg(loadavg, nelem); |
|
4960 |
} |
|
4961 |
||
4962 |
void os::pause() { |
|
4963 |
char filename[MAX_PATH]; |
|
4964 |
if (PauseAtStartupFile && PauseAtStartupFile[0]) { |
|
4965 |
jio_snprintf(filename, MAX_PATH, PauseAtStartupFile); |
|
4966 |
} else { |
|
4967 |
jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id()); |
|
4968 |
} |
|
4969 |
||
4970 |
int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); |
|
4971 |
if (fd != -1) { |
|
4972 |
struct stat buf; |
|
7405
e6fc8d3926f8
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
7397
diff
changeset
|
4973 |
::close(fd); |
1 | 4974 |
while (::stat(filename, &buf) == 0) { |
4975 |
(void)::poll(NULL, 0, 100); |
|
4976 |
} |
|
4977 |
} else { |
|
4978 |
jio_fprintf(stderr, |
|
4979 |
"Could not open pause file '%s', continuing immediately.\n", filename); |
|
4980 |
} |
|
4981 |
} |
|
4982 |
||
4983 |
||
4984 |
// Refer to the comments in os_solaris.cpp park-unpark. |
|
4985 |
// |
|
4986 |
// Beware -- Some versions of NPTL embody a flaw where pthread_cond_timedwait() can |
|
4987 |
// hang indefinitely. For instance NPTL 0.60 on 2.4.21-4ELsmp is vulnerable. |
|
4988 |
// For specifics regarding the bug see GLIBC BUGID 261237 : |
|
4989 |
// http://www.mail-archive.com/debian-glibc@lists.debian.org/msg10837.html. |
|
4990 |
// Briefly, pthread_cond_timedwait() calls with an expiry time that's not in the future |
|
4991 |
// will either hang or corrupt the condvar, resulting in subsequent hangs if the condvar |
|
4992 |
// is used. (The simple C test-case provided in the GLIBC bug report manifests the |
|
4993 |
// hang). The JVM is vulernable via sleep(), Object.wait(timo), LockSupport.parkNanos() |
|
4994 |
// and monitorenter when we're using 1-0 locking. All those operations may result in |
|
4995 |
// calls to pthread_cond_timedwait(). Using LD_ASSUME_KERNEL to use an older version |
|
4996 |
// of libpthread avoids the problem, but isn't practical. |
|
4997 |
// |
|
4998 |
// Possible remedies: |
|
4999 |
// |
|
5000 |
// 1. Establish a minimum relative wait time. 50 to 100 msecs seems to work. |
|
5001 |
// This is palliative and probabilistic, however. If the thread is preempted |
|
5002 |
// between the call to compute_abstime() and pthread_cond_timedwait(), more |
|
5003 |
// than the minimum period may have passed, and the abstime may be stale (in the |
|
5004 |
// past) resultin in a hang. Using this technique reduces the odds of a hang |
|
5005 |
// but the JVM is still vulnerable, particularly on heavily loaded systems. |
|
5006 |
// |
|
5007 |
// 2. Modify park-unpark to use per-thread (per ParkEvent) pipe-pairs instead |
|
5008 |
// of the usual flag-condvar-mutex idiom. The write side of the pipe is set |
|
5009 |
// NDELAY. unpark() reduces to write(), park() reduces to read() and park(timo) |
|
5010 |
// reduces to poll()+read(). This works well, but consumes 2 FDs per extant |
|
5011 |
// thread. |
|
5012 |
// |
|
5013 |
// 3. Embargo pthread_cond_timedwait() and implement a native "chron" thread |
|
5014 |
// that manages timeouts. We'd emulate pthread_cond_timedwait() by enqueuing |
|
5015 |
// a timeout request to the chron thread and then blocking via pthread_cond_wait(). |
|
5016 |
// This also works well. In fact it avoids kernel-level scalability impediments |
|
5017 |
// on certain platforms that don't handle lots of active pthread_cond_timedwait() |
|
5018 |
// timers in a graceful fashion. |
|
5019 |
// |
|
5020 |
// 4. When the abstime value is in the past it appears that control returns |
|
5021 |
// correctly from pthread_cond_timedwait(), but the condvar is left corrupt. |
|
5022 |
// Subsequent timedwait/wait calls may hang indefinitely. Given that, we |
|
5023 |
// can avoid the problem by reinitializing the condvar -- by cond_destroy() |
|
5024 |
// followed by cond_init() -- after all calls to pthread_cond_timedwait(). |
|
5025 |
// It may be possible to avoid reinitialization by checking the return |
|
5026 |
// value from pthread_cond_timedwait(). In addition to reinitializing the |
|
5027 |
// condvar we must establish the invariant that cond_signal() is only called |
|
5028 |
// within critical sections protected by the adjunct mutex. This prevents |
|
5029 |
// cond_signal() from "seeing" a condvar that's in the midst of being |
|
5030 |
// reinitialized or that is corrupt. Sadly, this invariant obviates the |
|
5031 |
// desirable signal-after-unlock optimization that avoids futile context switching. |
|
5032 |
// |
|
5033 |
// I'm also concerned that some versions of NTPL might allocate an auxilliary |
|
5034 |
// structure when a condvar is used or initialized. cond_destroy() would |
|
5035 |
// release the helper structure. Our reinitialize-after-timedwait fix |
|
5036 |
// put excessive stress on malloc/free and locks protecting the c-heap. |
|
5037 |
// |
|
5038 |
// We currently use (4). See the WorkAroundNTPLTimedWaitHang flag. |
|
5039 |
// It may be possible to refine (4) by checking the kernel and NTPL verisons |
|
5040 |
// and only enabling the work-around for vulnerable environments. |
|
5041 |
||
5042 |
// utility to compute the abstime argument to timedwait: |
|
5043 |
// millis is the relative timeout time |
|
5044 |
// abstime will be the absolute timeout time |
|
5045 |
// TODO: replace compute_abstime() with unpackTime() |
|
5046 |
||
5047 |
static struct timespec* compute_abstime(timespec* abstime, jlong millis) { |
|
5048 |
if (millis < 0) millis = 0; |
|
5049 |
struct timeval now; |
|
5050 |
int status = gettimeofday(&now, NULL); |
|
5051 |
assert(status == 0, "gettimeofday"); |
|
5052 |
jlong seconds = millis / 1000; |
|
5053 |
millis %= 1000; |
|
5054 |
if (seconds > 50000000) { // see man cond_timedwait(3T) |
|
5055 |
seconds = 50000000; |
|
5056 |
} |
|
5057 |
abstime->tv_sec = now.tv_sec + seconds; |
|
5058 |
long usec = now.tv_usec + millis * 1000; |
|
5059 |
if (usec >= 1000000) { |
|
5060 |
abstime->tv_sec += 1; |
|
5061 |
usec -= 1000000; |
|
5062 |
} |
|
5063 |
abstime->tv_nsec = usec * 1000; |
|
5064 |
return abstime; |
|
5065 |
} |
|
5066 |
||
5067 |
||
5068 |
// Test-and-clear _Event, always leaves _Event set to 0, returns immediately. |
|
5069 |
// Conceptually TryPark() should be equivalent to park(0). |
|
5070 |
||
5071 |
int os::PlatformEvent::TryPark() { |
|
5072 |
for (;;) { |
|
5073 |
const int v = _Event ; |
|
5074 |
guarantee ((v == 0) || (v == 1), "invariant") ; |
|
5075 |
if (Atomic::cmpxchg (0, &_Event, v) == v) return v ; |
|
5076 |
} |
|
5077 |
} |
|
5078 |
||
5079 |
void os::PlatformEvent::park() { // AKA "down()" |
|
5080 |
// Invariant: Only the thread associated with the Event/PlatformEvent |
|
5081 |
// may call park(). |
|
5082 |
// TODO: assert that _Assoc != NULL or _Assoc == Self |
|
5083 |
int v ; |
|
5084 |
for (;;) { |
|
5085 |
v = _Event ; |
|
5086 |
if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; |
|
5087 |
} |
|
5088 |
guarantee (v >= 0, "invariant") ; |
|
5089 |
if (v == 0) { |
|
5090 |
// Do this the hard way by blocking ... |
|
5091 |
int status = pthread_mutex_lock(_mutex); |
|
5092 |
assert_status(status == 0, status, "mutex_lock"); |
|
5093 |
guarantee (_nParked == 0, "invariant") ; |
|
5094 |
++ _nParked ; |
|
5095 |
while (_Event < 0) { |
|
5096 |
status = pthread_cond_wait(_cond, _mutex); |
|
5097 |
// for some reason, under 2.7 lwp_cond_wait() may return ETIME ... |
|
5098 |
// Treat this the same as if the wait was interrupted |
|
5099 |
if (status == ETIME) { status = EINTR; } |
|
5100 |
assert_status(status == 0 || status == EINTR, status, "cond_wait"); |
|
5101 |
} |
|
5102 |
-- _nParked ; |
|
5103 |
||
5104 |
_Event = 0 ; |
|
5105 |
status = pthread_mutex_unlock(_mutex); |
|
5106 |
assert_status(status == 0, status, "mutex_unlock"); |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5107 |
// Paranoia to ensure our locked and lock-free paths interact |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5108 |
// correctly with each other. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5109 |
OrderAccess::fence(); |
1 | 5110 |
} |
5111 |
guarantee (_Event >= 0, "invariant") ; |
|
5112 |
} |
|
5113 |
||
5114 |
int os::PlatformEvent::park(jlong millis) { |
|
5115 |
guarantee (_nParked == 0, "invariant") ; |
|
5116 |
||
5117 |
int v ; |
|
5118 |
for (;;) { |
|
5119 |
v = _Event ; |
|
5120 |
if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; |
|
5121 |
} |
|
5122 |
guarantee (v >= 0, "invariant") ; |
|
5123 |
if (v != 0) return OS_OK ; |
|
5124 |
||
5125 |
// We do this the hard way, by blocking the thread. |
|
5126 |
// Consider enforcing a minimum timeout value. |
|
5127 |
struct timespec abst; |
|
5128 |
compute_abstime(&abst, millis); |
|
5129 |
||
5130 |
int ret = OS_TIMEOUT; |
|
5131 |
int status = pthread_mutex_lock(_mutex); |
|
5132 |
assert_status(status == 0, status, "mutex_lock"); |
|
5133 |
guarantee (_nParked == 0, "invariant") ; |
|
5134 |
++_nParked ; |
|
5135 |
||
5136 |
// Object.wait(timo) will return because of |
|
5137 |
// (a) notification |
|
5138 |
// (b) timeout |
|
5139 |
// (c) thread.interrupt |
|
5140 |
// |
|
5141 |
// Thread.interrupt and object.notify{All} both call Event::set. |
|
5142 |
// That is, we treat thread.interrupt as a special case of notification. |
|
5143 |
// The underlying Solaris implementation, cond_timedwait, admits |
|
5144 |
// spurious/premature wakeups, but the JLS/JVM spec prevents the |
|
5145 |
// JVM from making those visible to Java code. As such, we must |
|
5146 |
// filter out spurious wakeups. We assume all ETIME returns are valid. |
|
5147 |
// |
|
5148 |
// TODO: properly differentiate simultaneous notify+interrupt. |
|
5149 |
// In that case, we should propagate the notify to another waiter. |
|
5150 |
||
5151 |
while (_Event < 0) { |
|
5152 |
status = os::Linux::safe_cond_timedwait(_cond, _mutex, &abst); |
|
5153 |
if (status != 0 && WorkAroundNPTLTimedWaitHang) { |
|
5154 |
pthread_cond_destroy (_cond); |
|
5155 |
pthread_cond_init (_cond, NULL) ; |
|
5156 |
} |
|
5157 |
assert_status(status == 0 || status == EINTR || |
|
5158 |
status == ETIME || status == ETIMEDOUT, |
|
5159 |
status, "cond_timedwait"); |
|
5160 |
if (!FilterSpuriousWakeups) break ; // previous semantics |
|
5161 |
if (status == ETIME || status == ETIMEDOUT) break ; |
|
5162 |
// We consume and ignore EINTR and spurious wakeups. |
|
5163 |
} |
|
5164 |
--_nParked ; |
|
5165 |
if (_Event >= 0) { |
|
5166 |
ret = OS_OK; |
|
5167 |
} |
|
5168 |
_Event = 0 ; |
|
5169 |
status = pthread_mutex_unlock(_mutex); |
|
5170 |
assert_status(status == 0, status, "mutex_unlock"); |
|
5171 |
assert (_nParked == 0, "invariant") ; |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5172 |
// Paranoia to ensure our locked and lock-free paths interact |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5173 |
// correctly with each other. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5174 |
OrderAccess::fence(); |
1 | 5175 |
return ret; |
5176 |
} |
|
5177 |
||
5178 |
void os::PlatformEvent::unpark() { |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5179 |
// Transitions for _Event: |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5180 |
// 0 :=> 1 |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5181 |
// 1 :=> 1 |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5182 |
// -1 :=> either 0 or 1; must signal target thread |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5183 |
// That is, we can safely transition _Event from -1 to either |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5184 |
// 0 or 1. Forcing 1 is slightly more efficient for back-to-back |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5185 |
// unpark() calls. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5186 |
// See also: "Semaphores in Plan 9" by Mullender & Cox |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5187 |
// |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5188 |
// Note: Forcing a transition from "-1" to "1" on an unpark() means |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5189 |
// that it will take two back-to-back park() calls for the owning |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5190 |
// thread to block. This has the benefit of forcing a spurious return |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5191 |
// from the first park() call after an unpark() call which will help |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5192 |
// shake out uses of park() and unpark() without condition variables. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5193 |
|
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5194 |
if (Atomic::xchg(1, &_Event) >= 0) return; |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5195 |
|
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5196 |
// Wait for the thread associated with the event to vacate |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5197 |
int status = pthread_mutex_lock(_mutex); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5198 |
assert_status(status == 0, status, "mutex_lock"); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5199 |
int AnyWaiters = _nParked; |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5200 |
assert(AnyWaiters == 0 || AnyWaiters == 1, "invariant"); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5201 |
if (AnyWaiters != 0 && WorkAroundNPTLTimedWaitHang) { |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5202 |
AnyWaiters = 0; |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5203 |
pthread_cond_signal(_cond); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5204 |
} |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5205 |
status = pthread_mutex_unlock(_mutex); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5206 |
assert_status(status == 0, status, "mutex_unlock"); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5207 |
if (AnyWaiters != 0) { |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5208 |
status = pthread_cond_signal(_cond); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5209 |
assert_status(status == 0, status, "cond_signal"); |
1 | 5210 |
} |
5211 |
||
5212 |
// Note that we signal() _after dropping the lock for "immortal" Events. |
|
5213 |
// This is safe and avoids a common class of futile wakeups. In rare |
|
5214 |
// circumstances this can cause a thread to return prematurely from |
|
5215 |
// cond_{timed}wait() but the spurious wakeup is benign and the victim will |
|
5216 |
// simply re-test the condition and re-park itself. |
|
5217 |
} |
|
5218 |
||
5219 |
||
5220 |
// JSR166 |
|
5221 |
// ------------------------------------------------------- |
|
5222 |
||
5223 |
/* |
|
5224 |
* The solaris and linux implementations of park/unpark are fairly |
|
5225 |
* conservative for now, but can be improved. They currently use a |
|
5226 |
* mutex/condvar pair, plus a a count. |
|
5227 |
* Park decrements count if > 0, else does a condvar wait. Unpark |
|
5228 |
* sets count to 1 and signals condvar. Only one thread ever waits |
|
5229 |
* on the condvar. Contention seen when trying to park implies that someone |
|
5230 |
* is unparking you, so don't wait. And spurious returns are fine, so there |
|
5231 |
* is no need to track notifications. |
|
5232 |
*/ |
|
5233 |
||
5234 |
#define MAX_SECS 100000000 |
|
5235 |
/* |
|
5236 |
* This code is common to linux and solaris and will be moved to a |
|
5237 |
* common place in dolphin. |
|
5238 |
* |
|
5239 |
* The passed in time value is either a relative time in nanoseconds |
|
5240 |
* or an absolute time in milliseconds. Either way it has to be unpacked |
|
5241 |
* into suitable seconds and nanoseconds components and stored in the |
|
5242 |
* given timespec structure. |
|
5243 |
* Given time is a 64-bit value and the time_t used in the timespec is only |
|
5244 |
* a signed-32-bit value (except on 64-bit Linux) we have to watch for |
|
5245 |
* overflow if times way in the future are given. Further on Solaris versions |
|
5246 |
* prior to 10 there is a restriction (see cond_timedwait) that the specified |
|
5247 |
* number of seconds, in abstime, is less than current_time + 100,000,000. |
|
5248 |
* As it will be 28 years before "now + 100000000" will overflow we can |
|
5249 |
* ignore overflow and just impose a hard-limit on seconds using the value |
|
5250 |
* of "now + 100,000,000". This places a limit on the timeout of about 3.17 |
|
5251 |
* years from "now". |
|
5252 |
*/ |
|
5253 |
||
5254 |
static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { |
|
5255 |
assert (time > 0, "convertTime"); |
|
5256 |
||
5257 |
struct timeval now; |
|
5258 |
int status = gettimeofday(&now, NULL); |
|
5259 |
assert(status == 0, "gettimeofday"); |
|
5260 |
||
5261 |
time_t max_secs = now.tv_sec + MAX_SECS; |
|
5262 |
||
5263 |
if (isAbsolute) { |
|
5264 |
jlong secs = time / 1000; |
|
5265 |
if (secs > max_secs) { |
|
5266 |
absTime->tv_sec = max_secs; |
|
5267 |
} |
|
5268 |
else { |
|
5269 |
absTime->tv_sec = secs; |
|
5270 |
} |
|
5271 |
absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; |
|
5272 |
} |
|
5273 |
else { |
|
5274 |
jlong secs = time / NANOSECS_PER_SEC; |
|
5275 |
if (secs >= MAX_SECS) { |
|
5276 |
absTime->tv_sec = max_secs; |
|
5277 |
absTime->tv_nsec = 0; |
|
5278 |
} |
|
5279 |
else { |
|
5280 |
absTime->tv_sec = now.tv_sec + secs; |
|
5281 |
absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; |
|
5282 |
if (absTime->tv_nsec >= NANOSECS_PER_SEC) { |
|
5283 |
absTime->tv_nsec -= NANOSECS_PER_SEC; |
|
5284 |
++absTime->tv_sec; // note: this must be <= max_secs |
|
5285 |
} |
|
5286 |
} |
|
5287 |
} |
|
5288 |
assert(absTime->tv_sec >= 0, "tv_sec < 0"); |
|
5289 |
assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs"); |
|
5290 |
assert(absTime->tv_nsec >= 0, "tv_nsec < 0"); |
|
5291 |
assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec"); |
|
5292 |
} |
|
5293 |
||
5294 |
void Parker::park(bool isAbsolute, jlong time) { |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5295 |
// Ideally we'd do something useful while spinning, such |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5296 |
// as calling unpackTime(). |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5297 |
|
1 | 5298 |
// Optional fast-path check: |
5299 |
// Return immediately if a permit is available. |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5300 |
// We depend on Atomic::xchg() having full barrier semantics |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5301 |
// since we are doing a lock-free update to _counter. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5302 |
if (Atomic::xchg(0, &_counter) > 0) return; |
1 | 5303 |
|
5304 |
Thread* thread = Thread::current(); |
|
5305 |
assert(thread->is_Java_thread(), "Must be JavaThread"); |
|
5306 |
JavaThread *jt = (JavaThread *)thread; |
|
5307 |
||
5308 |
// Optional optimization -- avoid state transitions if there's an interrupt pending. |
|
5309 |
// Check interrupt before trying to wait |
|
5310 |
if (Thread::is_interrupted(thread, false)) { |
|
5311 |
return; |
|
5312 |
} |
|
5313 |
||
5314 |
// Next, demultiplex/decode time arguments |
|
5315 |
timespec absTime; |
|
6962
d49132ce025b
6763959: java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
acorn
parents:
6420
diff
changeset
|
5316 |
if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all |
1 | 5317 |
return; |
5318 |
} |
|
5319 |
if (time > 0) { |
|
5320 |
unpackTime(&absTime, isAbsolute, time); |
|
5321 |
} |
|
5322 |
||
5323 |
||
5324 |
// Enter safepoint region |
|
5325 |
// Beware of deadlocks such as 6317397. |
|
5326 |
// The per-thread Parker:: mutex is a classic leaf-lock. |
|
5327 |
// In particular a thread must never block on the Threads_lock while |
|
5328 |
// holding the Parker:: mutex. If safepoints are pending both the |
|
5329 |
// the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock. |
|
5330 |
ThreadBlockInVM tbivm(jt); |
|
5331 |
||
5332 |
// Don't wait if cannot get lock since interference arises from |
|
5333 |
// unblocking. Also. check interrupt before trying wait |
|
5334 |
if (Thread::is_interrupted(thread, false) || pthread_mutex_trylock(_mutex) != 0) { |
|
5335 |
return; |
|
5336 |
} |
|
5337 |
||
5338 |
int status ; |
|
5339 |
if (_counter > 0) { // no wait needed |
|
5340 |
_counter = 0; |
|
5341 |
status = pthread_mutex_unlock(_mutex); |
|
5342 |
assert (status == 0, "invariant") ; |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5343 |
// Paranoia to ensure our locked and lock-free paths interact |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5344 |
// correctly with each other and Java-level accesses. |
4487
de1359156181
6822370: ReentrantReadWriteLock: threads hung when there are no threads holding onto the lock (Netra x4450)
dholmes
parents:
4013
diff
changeset
|
5345 |
OrderAccess::fence(); |
1 | 5346 |
return; |
5347 |
} |
|
5348 |
||
5349 |
#ifdef ASSERT |
|
5350 |
// Don't catch signals while blocked; let the running threads have the signals. |
|
5351 |
// (This allows a debugger to break into the running thread.) |
|
5352 |
sigset_t oldsigs; |
|
5353 |
sigset_t* allowdebug_blocked = os::Linux::allowdebug_blocked_signals(); |
|
5354 |
pthread_sigmask(SIG_BLOCK, allowdebug_blocked, &oldsigs); |
|
5355 |
#endif |
|
5356 |
||
5357 |
OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); |
|
5358 |
jt->set_suspend_equivalent(); |
|
5359 |
// cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() |
|
5360 |
||
5361 |
if (time == 0) { |
|
5362 |
status = pthread_cond_wait (_cond, _mutex) ; |
|
5363 |
} else { |
|
5364 |
status = os::Linux::safe_cond_timedwait (_cond, _mutex, &absTime) ; |
|
5365 |
if (status != 0 && WorkAroundNPTLTimedWaitHang) { |
|
5366 |
pthread_cond_destroy (_cond) ; |
|
5367 |
pthread_cond_init (_cond, NULL); |
|
5368 |
} |
|
5369 |
} |
|
5370 |
assert_status(status == 0 || status == EINTR || |
|
5371 |
status == ETIME || status == ETIMEDOUT, |
|
5372 |
status, "cond_timedwait"); |
|
5373 |
||
5374 |
#ifdef ASSERT |
|
5375 |
pthread_sigmask(SIG_SETMASK, &oldsigs, NULL); |
|
5376 |
#endif |
|
5377 |
||
5378 |
_counter = 0 ; |
|
5379 |
status = pthread_mutex_unlock(_mutex) ; |
|
5380 |
assert_status(status == 0, status, "invariant") ; |
|
15234
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5381 |
// Paranoia to ensure our locked and lock-free paths interact |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5382 |
// correctly with each other and Java-level accesses. |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5383 |
OrderAccess::fence(); |
ff1f01be5fbd
8004902: correctness fixes motivated by contended locking work (6607129)
dcubed
parents:
15096
diff
changeset
|
5384 |
|
1 | 5385 |
// If externally suspended while waiting, re-suspend |
5386 |
if (jt->handle_special_suspend_equivalent_condition()) { |
|
5387 |
jt->java_suspend_self(); |
|
5388 |
} |
|
5389 |
} |
|
5390 |
||
5391 |
void Parker::unpark() { |
|
5392 |
int s, status ; |
|
5393 |
status = pthread_mutex_lock(_mutex); |
|
5394 |
assert (status == 0, "invariant") ; |
|
5395 |
s = _counter; |
|
5396 |
_counter = 1; |
|
5397 |
if (s < 1) { |
|
5398 |
if (WorkAroundNPTLTimedWaitHang) { |
|
5399 |
status = pthread_cond_signal (_cond) ; |
|
5400 |
assert (status == 0, "invariant") ; |
|
5401 |
status = pthread_mutex_unlock(_mutex); |
|
5402 |
assert (status == 0, "invariant") ; |
|
5403 |
} else { |
|
5404 |
status = pthread_mutex_unlock(_mutex); |
|
5405 |
assert (status == 0, "invariant") ; |
|
5406 |
status = pthread_cond_signal (_cond) ; |
|
5407 |
assert (status == 0, "invariant") ; |
|
5408 |
} |
|
5409 |
} else { |
|
5410 |
pthread_mutex_unlock(_mutex); |
|
5411 |
assert (status == 0, "invariant") ; |
|
5412 |
} |
|
5413 |
} |
|
5414 |
||
5415 |
||
5416 |
extern char** environ; |
|
5417 |
||
5418 |
#ifndef __NR_fork |
|
5419 |
#define __NR_fork IA32_ONLY(2) IA64_ONLY(not defined) AMD64_ONLY(57) |
|
5420 |
#endif |
|
5421 |
||
5422 |
#ifndef __NR_execve |
|
5423 |
#define __NR_execve IA32_ONLY(11) IA64_ONLY(1033) AMD64_ONLY(59) |
|
5424 |
#endif |
|
5425 |
||
5426 |
// Run the specified command in a separate process. Return its exit value, |
|
5427 |
// or -1 on failure (e.g. can't fork a new process). |
|
5428 |
// Unlike system(), this function can be called from signal handler. It |
|
5429 |
// doesn't block SIGINT et al. |
|
5430 |
int os::fork_and_exec(char* cmd) { |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
5431 |
const char * argv[4] = {"sh", "-c", cmd, NULL}; |
1 | 5432 |
|
5433 |
// fork() in LinuxThreads/NPTL is not async-safe. It needs to run |
|
5434 |
// pthread_atfork handlers and reset pthread library. All we need is a |
|
5435 |
// separate process to execve. Make a direct syscall to fork process. |
|
5436 |
// On IA64 there's no fork syscall, we have to use fork() and hope for |
|
5437 |
// the best... |
|
5438 |
pid_t pid = NOT_IA64(syscall(__NR_fork);) |
|
5439 |
IA64_ONLY(fork();) |
|
5440 |
||
5441 |
if (pid < 0) { |
|
5442 |
// fork failed |
|
5443 |
return -1; |
|
5444 |
||
5445 |
} else if (pid == 0) { |
|
5446 |
// child process |
|
5447 |
||
5448 |
// execve() in LinuxThreads will call pthread_kill_other_threads_np() |
|
5449 |
// first to kill every thread on the thread list. Because this list is |
|
5450 |
// not reset by fork() (see notes above), execve() will instead kill |
|
5451 |
// every thread in the parent process. We know this is the only thread |
|
5452 |
// in the new process, so make a system call directly. |
|
5453 |
// IA64 should use normal execve() from glibc to match the glibc fork() |
|
5454 |
// above. |
|
5455 |
NOT_IA64(syscall(__NR_execve, "/bin/sh", argv, environ);) |
|
745
47129a5cacd3
6681796: hotspot build failure on gcc 4.2.x (ubuntu 8.04) w/ openjdk 6
xlu
parents:
388
diff
changeset
|
5456 |
IA64_ONLY(execve("/bin/sh", (char* const*)argv, environ);) |
1 | 5457 |
|
5458 |
// execve failed |
|
5459 |
_exit(-1); |
|
5460 |
||
5461 |
} else { |
|
5462 |
// copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't |
|
5463 |
// care about the actual exit code, for now. |
|
5464 |
||
5465 |
int status; |
|
5466 |
||
5467 |
// Wait for the child process to exit. This returns immediately if |
|
5468 |
// the child has already exited. */ |
|
5469 |
while (waitpid(pid, &status, 0) < 0) { |
|
5470 |
switch (errno) { |
|
5471 |
case ECHILD: return 0; |
|
5472 |
case EINTR: break; |
|
5473 |
default: return -1; |
|
5474 |
} |
|
5475 |
} |
|
5476 |
||
5477 |
if (WIFEXITED(status)) { |
|
5478 |
// The child exited normally; get its exit code. |
|
5479 |
return WEXITSTATUS(status); |
|
5480 |
} else if (WIFSIGNALED(status)) { |
|
5481 |
// The child exited because of a signal |
|
5482 |
// The best value to return is 0x80 + signal number, |
|
5483 |
// because that is what all Unix shells do, and because |
|
5484 |
// it allows callers to distinguish between process exit and |
|
5485 |
// process death by signal. |
|
5486 |
return 0x80 + WTERMSIG(status); |
|
5487 |
} else { |
|
5488 |
// Unknown exit code; pass it through |
|
5489 |
return status; |
|
5490 |
} |
|
5491 |
} |
|
5492 |
} |
|
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5493 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5494 |
// is_headless_jre() |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5495 |
// |
11161
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5496 |
// Test for the existence of xawt/libmawt.so or libawt_xawt.so |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5497 |
// in order to report if we are running in a headless jre |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5498 |
// |
11161
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5499 |
// Since JDK8 xawt/libmawt.so was moved into the same directory |
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5500 |
// as libawt.so, and renamed libawt_xawt.so |
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5501 |
// |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5502 |
bool os::is_headless_jre() { |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5503 |
struct stat statbuf; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5504 |
char buf[MAXPATHLEN]; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5505 |
char libmawtpath[MAXPATHLEN]; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5506 |
const char *xawtstr = "/xawt/libmawt.so"; |
11161
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5507 |
const char *new_xawtstr = "/libawt_xawt.so"; |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5508 |
char *p; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5509 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5510 |
// Get path to libjvm.so |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5511 |
os::jvm_path(buf, sizeof(buf)); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5512 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5513 |
// Get rid of libjvm.so |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5514 |
p = strrchr(buf, '/'); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5515 |
if (p == NULL) return false; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5516 |
else *p = '\0'; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5517 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5518 |
// Get rid of client or server |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5519 |
p = strrchr(buf, '/'); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5520 |
if (p == NULL) return false; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5521 |
else *p = '\0'; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5522 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5523 |
// check xawt/libmawt.so |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5524 |
strcpy(libmawtpath, buf); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5525 |
strcat(libmawtpath, xawtstr); |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5526 |
if (::stat(libmawtpath, &statbuf) == 0) return false; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5527 |
|
11161
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5528 |
// check libawt_xawt.so |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5529 |
strcpy(libmawtpath, buf); |
11161
ec855b5a23c2
7110017: is_headless_jre should be updated to reflect the new location of awt toolkit libraries
dholmes
parents:
10739
diff
changeset
|
5530 |
strcat(libmawtpath, new_xawtstr); |
6176
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5531 |
if (::stat(libmawtpath, &statbuf) == 0) return false; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5532 |
|
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5533 |
return true; |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5534 |
} |
4d9030fe341f
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
5922
diff
changeset
|
5535 |
|
13198
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5536 |
// Get the default path to the core file |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5537 |
// Returns the length of the string |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5538 |
int os::get_core_path(char* buffer, size_t bufferSize) { |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5539 |
const char* p = get_current_directory(buffer, bufferSize); |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5540 |
|
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5541 |
if (p == NULL) { |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5542 |
assert(p != NULL, "failed to get current directory"); |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5543 |
return 0; |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5544 |
} |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5545 |
|
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5546 |
return strlen(buffer); |
271c557a7623
7129724: MAC: Core file location is wrong in crash report
mikael
parents:
13195
diff
changeset
|
5547 |
} |
10025
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5548 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5549 |
#ifdef JAVASE_EMBEDDED |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5550 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5551 |
// A thread to watch the '/dev/mem_notify' device, which will tell us when the OS is running low on memory. |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5552 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5553 |
MemNotifyThread* MemNotifyThread::_memnotify_thread = NULL; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5554 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5555 |
// ctor |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5556 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5557 |
MemNotifyThread::MemNotifyThread(int fd): Thread() { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5558 |
assert(memnotify_thread() == NULL, "we can only allocate one MemNotifyThread"); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5559 |
_fd = fd; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5560 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5561 |
if (os::create_thread(this, os::os_thread)) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5562 |
_memnotify_thread = this; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5563 |
os::set_priority(this, NearMaxPriority); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5564 |
os::start_thread(this); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5565 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5566 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5567 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5568 |
// Where all the work gets done |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5569 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5570 |
void MemNotifyThread::run() { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5571 |
assert(this == memnotify_thread(), "expected the singleton MemNotifyThread"); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5572 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5573 |
// Set up the select arguments |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5574 |
fd_set rfds; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5575 |
if (_fd != -1) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5576 |
FD_ZERO(&rfds); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5577 |
FD_SET(_fd, &rfds); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5578 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5579 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5580 |
// Now wait for the mem_notify device to wake up |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5581 |
while (1) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5582 |
// Wait for the mem_notify device to signal us.. |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5583 |
int rc = select(_fd+1, _fd != -1 ? &rfds : NULL, NULL, NULL, NULL); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5584 |
if (rc == -1) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5585 |
perror("select!\n"); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5586 |
break; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5587 |
} else if (rc) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5588 |
//ssize_t free_before = os::available_memory(); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5589 |
//tty->print ("Notified: Free: %dK \n",os::available_memory()/1024); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5590 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5591 |
// The kernel is telling us there is not much memory left... |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5592 |
// try to do something about that |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5593 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5594 |
// If we are not already in a GC, try one. |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5595 |
if (!Universe::heap()->is_gc_active()) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5596 |
Universe::heap()->collect(GCCause::_allocation_failure); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5597 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5598 |
//ssize_t free_after = os::available_memory(); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5599 |
//tty->print ("Post-Notify: Free: %dK\n",free_after/1024); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5600 |
//tty->print ("GC freed: %dK\n", (free_after - free_before)/1024); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5601 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5602 |
// We might want to do something like the following if we find the GC's are not helping... |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5603 |
// Universe::heap()->size_policy()->set_gc_time_limit_exceeded(true); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5604 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5605 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5606 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5607 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5608 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5609 |
// See if the /dev/mem_notify device exists, and if so, start a thread to monitor it. |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5610 |
// |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5611 |
void MemNotifyThread::start() { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5612 |
int fd; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5613 |
fd = open ("/dev/mem_notify", O_RDONLY, 0); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5614 |
if (fd < 0) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5615 |
return; |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5616 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5617 |
|
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5618 |
if (memnotify_thread() == NULL) { |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5619 |
new MemNotifyThread(fd); |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5620 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5621 |
} |
57fe03f10cf2
7061212: use o/s low memory notification in embedded builds
jcoomes
parents:
10023
diff
changeset
|
5622 |
#endif // JAVASE_EMBEDDED |