Mercurial > hg > truffle
annotate src/os/solaris/vm/os_solaris.cpp @ 2022:2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
Summary: Implemented in-process C native stack frame decoding when symbols are available.
Reviewed-by: coleenp, never
author | zgu |
---|---|
date | Sat, 11 Dec 2010 13:20:56 -0500 |
parents | f95d63e2154a |
children | 54f5dd2aa1d9 |
rev | line source |
---|---|
0 | 1 /* |
1865
1c352af0135d
6763959: java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
acorn
parents:
1681
diff
changeset
|
2 * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1490
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 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" | |
32 #include "interpreter/interpreter.hpp" | |
33 #include "jvm_solaris.h" | |
34 #include "memory/allocation.inline.hpp" | |
35 #include "memory/filemap.hpp" | |
36 #include "mutex_solaris.inline.hpp" | |
37 #include "oops/oop.inline.hpp" | |
38 #include "os_share_solaris.hpp" | |
39 #include "prims/jniFastGetField.hpp" | |
40 #include "prims/jvm.h" | |
41 #include "prims/jvm_misc.hpp" | |
42 #include "runtime/arguments.hpp" | |
43 #include "runtime/extendedPC.hpp" | |
44 #include "runtime/globals.hpp" | |
45 #include "runtime/hpi.hpp" | |
46 #include "runtime/interfaceSupport.hpp" | |
47 #include "runtime/java.hpp" | |
48 #include "runtime/javaCalls.hpp" | |
49 #include "runtime/mutexLocker.hpp" | |
50 #include "runtime/objectMonitor.hpp" | |
51 #include "runtime/osThread.hpp" | |
52 #include "runtime/perfMemory.hpp" | |
53 #include "runtime/sharedRuntime.hpp" | |
54 #include "runtime/statSampler.hpp" | |
55 #include "runtime/stubRoutines.hpp" | |
56 #include "runtime/threadCritical.hpp" | |
57 #include "runtime/timer.hpp" | |
58 #include "services/attachListener.hpp" | |
59 #include "services/runtimeService.hpp" | |
60 #include "thread_solaris.inline.hpp" | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
61 #include "utilities/decoder.hpp" |
1972 | 62 #include "utilities/defaultStream.hpp" |
63 #include "utilities/events.hpp" | |
64 #include "utilities/growableArray.hpp" | |
65 #include "utilities/vmError.hpp" | |
66 #ifdef TARGET_ARCH_x86 | |
67 # include "assembler_x86.inline.hpp" | |
68 # include "nativeInst_x86.hpp" | |
69 #endif | |
70 #ifdef TARGET_ARCH_sparc | |
71 # include "assembler_sparc.inline.hpp" | |
72 # include "nativeInst_sparc.hpp" | |
73 #endif | |
74 #ifdef COMPILER1 | |
75 #include "c1/c1_Runtime1.hpp" | |
76 #endif | |
77 #ifdef COMPILER2 | |
78 #include "opto/runtime.hpp" | |
79 #endif | |
0 | 80 |
81 // put OS-includes here | |
82 # include <dlfcn.h> | |
83 # include <errno.h> | |
84 # include <link.h> | |
85 # include <poll.h> | |
86 # include <pthread.h> | |
87 # include <pwd.h> | |
88 # include <schedctl.h> | |
89 # include <setjmp.h> | |
90 # include <signal.h> | |
91 # include <stdio.h> | |
92 # include <alloca.h> | |
93 # include <sys/filio.h> | |
94 # include <sys/ipc.h> | |
95 # include <sys/lwp.h> | |
96 # include <sys/machelf.h> // for elf Sym structure used by dladdr1 | |
97 # include <sys/mman.h> | |
98 # include <sys/processor.h> | |
99 # include <sys/procset.h> | |
100 # include <sys/pset.h> | |
101 # include <sys/resource.h> | |
102 # include <sys/shm.h> | |
103 # include <sys/socket.h> | |
104 # include <sys/stat.h> | |
105 # include <sys/systeminfo.h> | |
106 # include <sys/time.h> | |
107 # include <sys/times.h> | |
108 # include <sys/types.h> | |
109 # include <sys/wait.h> | |
110 # include <sys/utsname.h> | |
111 # include <thread.h> | |
112 # include <unistd.h> | |
113 # include <sys/priocntl.h> | |
114 # include <sys/rtpriocntl.h> | |
115 # include <sys/tspriocntl.h> | |
116 # include <sys/iapriocntl.h> | |
117 # include <sys/loadavg.h> | |
118 # include <string.h> | |
119 | |
120 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later | |
121 # include <sys/procfs.h> // see comment in <sys/procfs.h> | |
122 | |
123 #define MAX_PATH (2 * K) | |
124 | |
125 // for timer info max values which include all bits | |
126 #define ALL_64_BITS CONST64(0xFFFFFFFFFFFFFFFF) | |
127 | |
128 #ifdef _GNU_SOURCE | |
129 // See bug #6514594 | |
130 extern "C" int madvise(caddr_t, size_t, int); | |
131 extern "C" int memcntl(caddr_t addr, size_t len, int cmd, caddr_t arg, | |
132 int attr, int mask); | |
133 #endif //_GNU_SOURCE | |
134 | |
135 /* | |
136 MPSS Changes Start. | |
137 The JVM binary needs to be built and run on pre-Solaris 9 | |
138 systems, but the constants needed by MPSS are only in Solaris 9 | |
139 header files. They are textually replicated here to allow | |
140 building on earlier systems. Once building on Solaris 8 is | |
141 no longer a requirement, these #defines can be replaced by ordinary | |
142 system .h inclusion. | |
143 | |
144 In earlier versions of the JDK and Solaris, we used ISM for large pages. | |
145 But ISM requires shared memory to achieve this and thus has many caveats. | |
146 MPSS is a fully transparent and is a cleaner way to get large pages. | |
147 Although we still require keeping ISM for backward compatiblitiy as well as | |
148 giving the opportunity to use large pages on older systems it is | |
149 recommended that MPSS be used for Solaris 9 and above. | |
150 | |
151 */ | |
152 | |
153 #ifndef MC_HAT_ADVISE | |
154 | |
155 struct memcntl_mha { | |
156 uint_t mha_cmd; /* command(s) */ | |
157 uint_t mha_flags; | |
158 size_t mha_pagesize; | |
159 }; | |
160 #define MC_HAT_ADVISE 7 /* advise hat map size */ | |
161 #define MHA_MAPSIZE_VA 0x1 /* set preferred page size */ | |
162 #define MAP_ALIGN 0x200 /* addr specifies alignment */ | |
163 | |
164 #endif | |
165 // MPSS Changes End. | |
166 | |
167 | |
168 // Here are some liblgrp types from sys/lgrp_user.h to be able to | |
169 // compile on older systems without this header file. | |
170 | |
171 #ifndef MADV_ACCESS_LWP | |
172 # define MADV_ACCESS_LWP 7 /* next LWP to access heavily */ | |
173 #endif | |
174 #ifndef MADV_ACCESS_MANY | |
175 # define MADV_ACCESS_MANY 8 /* many processes to access heavily */ | |
176 #endif | |
177 | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
178 #ifndef LGRP_RSRC_CPU |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
179 # define LGRP_RSRC_CPU 0 /* CPU resources */ |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
180 #endif |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
181 #ifndef LGRP_RSRC_MEM |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
182 # define LGRP_RSRC_MEM 1 /* memory resources */ |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
183 #endif |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
184 |
0 | 185 // Some more macros from sys/mman.h that are not present in Solaris 8. |
186 | |
187 #ifndef MAX_MEMINFO_CNT | |
188 /* | |
189 * info_req request type definitions for meminfo | |
190 * request types starting with MEMINFO_V are used for Virtual addresses | |
191 * and should not be mixed with MEMINFO_PLGRP which is targeted for Physical | |
192 * addresses | |
193 */ | |
194 # define MEMINFO_SHIFT 16 | |
195 # define MEMINFO_MASK (0xFF << MEMINFO_SHIFT) | |
196 # define MEMINFO_VPHYSICAL (0x01 << MEMINFO_SHIFT) /* get physical addr */ | |
197 # define MEMINFO_VLGRP (0x02 << MEMINFO_SHIFT) /* get lgroup */ | |
198 # define MEMINFO_VPAGESIZE (0x03 << MEMINFO_SHIFT) /* size of phys page */ | |
199 # define MEMINFO_VREPLCNT (0x04 << MEMINFO_SHIFT) /* no. of replica */ | |
200 # define MEMINFO_VREPL (0x05 << MEMINFO_SHIFT) /* physical replica */ | |
201 # define MEMINFO_VREPL_LGRP (0x06 << MEMINFO_SHIFT) /* lgrp of replica */ | |
202 # define MEMINFO_PLGRP (0x07 << MEMINFO_SHIFT) /* lgroup for paddr */ | |
203 | |
204 /* maximum number of addresses meminfo() can process at a time */ | |
205 # define MAX_MEMINFO_CNT 256 | |
206 | |
207 /* maximum number of request types */ | |
208 # define MAX_MEMINFO_REQ 31 | |
209 #endif | |
210 | |
211 // see thr_setprio(3T) for the basis of these numbers | |
212 #define MinimumPriority 0 | |
213 #define NormalPriority 64 | |
214 #define MaximumPriority 127 | |
215 | |
216 // Values for ThreadPriorityPolicy == 1 | |
217 int prio_policy1[MaxPriority+1] = { -99999, 0, 16, 32, 48, 64, | |
218 80, 96, 112, 124, 127 }; | |
219 | |
220 // System parameters used internally | |
221 static clock_t clock_tics_per_sec = 100; | |
222 | |
223 // For diagnostics to print a message once. see run_periodic_checks | |
224 static bool check_addr0_done = false; | |
225 static sigset_t check_signal_done; | |
226 static bool check_signals = true; | |
227 | |
228 address os::Solaris::handler_start; // start pc of thr_sighndlrinfo | |
229 address os::Solaris::handler_end; // end pc of thr_sighndlrinfo | |
230 | |
231 address os::Solaris::_main_stack_base = NULL; // 4352906 workaround | |
232 | |
233 | |
234 // "default" initializers for missing libc APIs | |
235 extern "C" { | |
236 static int lwp_mutex_init(mutex_t *mx, int scope, void *arg) { memset(mx, 0, sizeof(mutex_t)); return 0; } | |
237 static int lwp_mutex_destroy(mutex_t *mx) { return 0; } | |
238 | |
239 static int lwp_cond_init(cond_t *cv, int scope, void *arg){ memset(cv, 0, sizeof(cond_t)); return 0; } | |
240 static int lwp_cond_destroy(cond_t *cv) { return 0; } | |
241 } | |
242 | |
243 // "default" initializers for pthread-based synchronization | |
244 extern "C" { | |
245 static int pthread_mutex_default_init(mutex_t *mx, int scope, void *arg) { memset(mx, 0, sizeof(mutex_t)); return 0; } | |
246 static int pthread_cond_default_init(cond_t *cv, int scope, void *arg){ memset(cv, 0, sizeof(cond_t)); return 0; } | |
247 } | |
248 | |
249 // Thread Local Storage | |
250 // This is common to all Solaris platforms so it is defined here, | |
251 // in this common file. | |
252 // The declarations are in the os_cpu threadLS*.hpp files. | |
253 // | |
254 // Static member initialization for TLS | |
255 Thread* ThreadLocalStorage::_get_thread_cache[ThreadLocalStorage::_pd_cache_size] = {NULL}; | |
256 | |
257 #ifndef PRODUCT | |
258 #define _PCT(n,d) ((100.0*(double)(n))/(double)(d)) | |
259 | |
260 int ThreadLocalStorage::_tcacheHit = 0; | |
261 int ThreadLocalStorage::_tcacheMiss = 0; | |
262 | |
263 void ThreadLocalStorage::print_statistics() { | |
264 int total = _tcacheMiss+_tcacheHit; | |
265 tty->print_cr("Thread cache hits %d misses %d total %d percent %f\n", | |
266 _tcacheHit, _tcacheMiss, total, _PCT(_tcacheHit, total)); | |
267 } | |
268 #undef _PCT | |
269 #endif // PRODUCT | |
270 | |
271 Thread* ThreadLocalStorage::get_thread_via_cache_slowly(uintptr_t raw_id, | |
272 int index) { | |
273 Thread *thread = get_thread_slow(); | |
274 if (thread != NULL) { | |
275 address sp = os::current_stack_pointer(); | |
276 guarantee(thread->_stack_base == NULL || | |
277 (sp <= thread->_stack_base && | |
278 sp >= thread->_stack_base - thread->_stack_size) || | |
279 is_error_reported(), | |
280 "sp must be inside of selected thread stack"); | |
281 | |
282 thread->_self_raw_id = raw_id; // mark for quick retrieval | |
283 _get_thread_cache[ index ] = thread; | |
284 } | |
285 return thread; | |
286 } | |
287 | |
288 | |
289 static const double all_zero[ sizeof(Thread) / sizeof(double) + 1 ] = {0}; | |
290 #define NO_CACHED_THREAD ((Thread*)all_zero) | |
291 | |
292 void ThreadLocalStorage::pd_set_thread(Thread* thread) { | |
293 | |
294 // Store the new value before updating the cache to prevent a race | |
295 // between get_thread_via_cache_slowly() and this store operation. | |
296 os::thread_local_storage_at_put(ThreadLocalStorage::thread_index(), thread); | |
297 | |
298 // Update thread cache with new thread if setting on thread create, | |
299 // or NO_CACHED_THREAD (zeroed) thread if resetting thread on exit. | |
300 uintptr_t raw = pd_raw_thread_id(); | |
301 int ix = pd_cache_index(raw); | |
302 _get_thread_cache[ix] = thread == NULL ? NO_CACHED_THREAD : thread; | |
303 } | |
304 | |
305 void ThreadLocalStorage::pd_init() { | |
306 for (int i = 0; i < _pd_cache_size; i++) { | |
307 _get_thread_cache[i] = NO_CACHED_THREAD; | |
308 } | |
309 } | |
310 | |
311 // Invalidate all the caches (happens to be the same as pd_init). | |
312 void ThreadLocalStorage::pd_invalidate_all() { pd_init(); } | |
313 | |
314 #undef NO_CACHED_THREAD | |
315 | |
316 // END Thread Local Storage | |
317 | |
318 static inline size_t adjust_stack_size(address base, size_t size) { | |
319 if ((ssize_t)size < 0) { | |
320 // 4759953: Compensate for ridiculous stack size. | |
321 size = max_intx; | |
322 } | |
323 if (size > (size_t)base) { | |
324 // 4812466: Make sure size doesn't allow the stack to wrap the address space. | |
325 size = (size_t)base; | |
326 } | |
327 return size; | |
328 } | |
329 | |
330 static inline stack_t get_stack_info() { | |
331 stack_t st; | |
332 int retval = thr_stksegment(&st); | |
333 st.ss_size = adjust_stack_size((address)st.ss_sp, st.ss_size); | |
334 assert(retval == 0, "incorrect return value from thr_stksegment"); | |
335 assert((address)&st < (address)st.ss_sp, "Invalid stack base returned"); | |
336 assert((address)&st > (address)st.ss_sp-st.ss_size, "Invalid stack size returned"); | |
337 return st; | |
338 } | |
339 | |
340 address os::current_stack_base() { | |
341 int r = thr_main() ; | |
342 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; | |
343 bool is_primordial_thread = r; | |
344 | |
345 // Workaround 4352906, avoid calls to thr_stksegment by | |
346 // thr_main after the first one (it looks like we trash | |
347 // some data, causing the value for ss_sp to be incorrect). | |
348 if (!is_primordial_thread || os::Solaris::_main_stack_base == NULL) { | |
349 stack_t st = get_stack_info(); | |
350 if (is_primordial_thread) { | |
351 // cache initial value of stack base | |
352 os::Solaris::_main_stack_base = (address)st.ss_sp; | |
353 } | |
354 return (address)st.ss_sp; | |
355 } else { | |
356 guarantee(os::Solaris::_main_stack_base != NULL, "Attempt to use null cached stack base"); | |
357 return os::Solaris::_main_stack_base; | |
358 } | |
359 } | |
360 | |
361 size_t os::current_stack_size() { | |
362 size_t size; | |
363 | |
364 int r = thr_main() ; | |
365 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; | |
366 if(!r) { | |
367 size = get_stack_info().ss_size; | |
368 } else { | |
369 struct rlimit limits; | |
370 getrlimit(RLIMIT_STACK, &limits); | |
371 size = adjust_stack_size(os::Solaris::_main_stack_base, (size_t)limits.rlim_cur); | |
372 } | |
373 // base may not be page aligned | |
374 address base = current_stack_base(); | |
375 address bottom = (address)align_size_up((intptr_t)(base - size), os::vm_page_size());; | |
376 return (size_t)(base - bottom); | |
377 } | |
378 | |
548
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
499
diff
changeset
|
379 struct tm* os::localtime_pd(const time_t* clock, struct tm* res) { |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
499
diff
changeset
|
380 return localtime_r(clock, res); |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
499
diff
changeset
|
381 } |
773234c55e8c
6800586: -XX:+PrintGCDateStamps is using mt-unsafe localtime function
ysr
parents:
499
diff
changeset
|
382 |
0 | 383 // interruptible infrastructure |
384 | |
385 // setup_interruptible saves the thread state before going into an | |
386 // interruptible system call. | |
387 // The saved state is used to restore the thread to | |
388 // its former state whether or not an interrupt is received. | |
389 // Used by classloader os::read | |
390 // hpi calls skip this layer and stay in _thread_in_native | |
391 | |
392 void os::Solaris::setup_interruptible(JavaThread* thread) { | |
393 | |
394 JavaThreadState thread_state = thread->thread_state(); | |
395 | |
396 assert(thread_state != _thread_blocked, "Coming from the wrong thread"); | |
397 assert(thread_state != _thread_in_native, "Native threads skip setup_interruptible"); | |
398 OSThread* osthread = thread->osthread(); | |
399 osthread->set_saved_interrupt_thread_state(thread_state); | |
400 thread->frame_anchor()->make_walkable(thread); | |
401 ThreadStateTransition::transition(thread, thread_state, _thread_blocked); | |
402 } | |
403 | |
404 // Version of setup_interruptible() for threads that are already in | |
405 // _thread_blocked. Used by os_sleep(). | |
406 void os::Solaris::setup_interruptible_already_blocked(JavaThread* thread) { | |
407 thread->frame_anchor()->make_walkable(thread); | |
408 } | |
409 | |
410 JavaThread* os::Solaris::setup_interruptible() { | |
411 JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread(); | |
412 setup_interruptible(thread); | |
413 return thread; | |
414 } | |
415 | |
416 void os::Solaris::try_enable_extended_io() { | |
417 typedef int (*enable_extended_FILE_stdio_t)(int, int); | |
418 | |
419 if (!UseExtendedFileIO) { | |
420 return; | |
421 } | |
422 | |
423 enable_extended_FILE_stdio_t enabler = | |
424 (enable_extended_FILE_stdio_t) dlsym(RTLD_DEFAULT, | |
425 "enable_extended_FILE_stdio"); | |
426 if (enabler) { | |
427 enabler(-1, -1); | |
428 } | |
429 } | |
430 | |
431 | |
432 #ifdef ASSERT | |
433 | |
434 JavaThread* os::Solaris::setup_interruptible_native() { | |
435 JavaThread* thread = (JavaThread*)ThreadLocalStorage::thread(); | |
436 JavaThreadState thread_state = thread->thread_state(); | |
437 assert(thread_state == _thread_in_native, "Assumed thread_in_native"); | |
438 return thread; | |
439 } | |
440 | |
441 void os::Solaris::cleanup_interruptible_native(JavaThread* thread) { | |
442 JavaThreadState thread_state = thread->thread_state(); | |
443 assert(thread_state == _thread_in_native, "Assumed thread_in_native"); | |
444 } | |
445 #endif | |
446 | |
447 // cleanup_interruptible reverses the effects of setup_interruptible | |
448 // setup_interruptible_already_blocked() does not need any cleanup. | |
449 | |
450 void os::Solaris::cleanup_interruptible(JavaThread* thread) { | |
451 OSThread* osthread = thread->osthread(); | |
452 | |
453 ThreadStateTransition::transition(thread, _thread_blocked, osthread->saved_interrupt_thread_state()); | |
454 } | |
455 | |
456 // I/O interruption related counters called in _INTERRUPTIBLE | |
457 | |
458 void os::Solaris::bump_interrupted_before_count() { | |
459 RuntimeService::record_interrupted_before_count(); | |
460 } | |
461 | |
462 void os::Solaris::bump_interrupted_during_count() { | |
463 RuntimeService::record_interrupted_during_count(); | |
464 } | |
465 | |
466 static int _processors_online = 0; | |
467 | |
468 jint os::Solaris::_os_thread_limit = 0; | |
469 volatile jint os::Solaris::_os_thread_count = 0; | |
470 | |
471 julong os::available_memory() { | |
472 return Solaris::available_memory(); | |
473 } | |
474 | |
475 julong os::Solaris::available_memory() { | |
476 return (julong)sysconf(_SC_AVPHYS_PAGES) * os::vm_page_size(); | |
477 } | |
478 | |
479 julong os::Solaris::_physical_memory = 0; | |
480 | |
481 julong os::physical_memory() { | |
482 return Solaris::physical_memory(); | |
483 } | |
484 | |
485 julong os::allocatable_physical_memory(julong size) { | |
486 #ifdef _LP64 | |
487 return size; | |
488 #else | |
489 julong result = MIN2(size, (julong)3835*M); | |
490 if (!is_allocatable(result)) { | |
491 // Memory allocations will be aligned but the alignment | |
492 // is not known at this point. Alignments will | |
493 // be at most to LargePageSizeInBytes. Protect | |
494 // allocations from alignments up to illegal | |
495 // values. If at this point 2G is illegal. | |
496 julong reasonable_size = (julong)2*G - 2 * LargePageSizeInBytes; | |
497 result = MIN2(size, reasonable_size); | |
498 } | |
499 return result; | |
500 #endif | |
501 } | |
502 | |
503 static hrtime_t first_hrtime = 0; | |
504 static const hrtime_t hrtime_hz = 1000*1000*1000; | |
505 const int LOCK_BUSY = 1; | |
506 const int LOCK_FREE = 0; | |
507 const int LOCK_INVALID = -1; | |
508 static volatile hrtime_t max_hrtime = 0; | |
509 static volatile int max_hrtime_lock = LOCK_FREE; // Update counter with LSB as lock-in-progress | |
510 | |
511 | |
512 void os::Solaris::initialize_system_info() { | |
1123
167c2986d91b
6843629: Make current hotspot build part of jdk5 control build
phh
parents:
1117
diff
changeset
|
513 set_processor_count(sysconf(_SC_NPROCESSORS_CONF)); |
0 | 514 _processors_online = sysconf (_SC_NPROCESSORS_ONLN); |
515 _physical_memory = (julong)sysconf(_SC_PHYS_PAGES) * (julong)sysconf(_SC_PAGESIZE); | |
516 } | |
517 | |
518 int os::active_processor_count() { | |
519 int online_cpus = sysconf(_SC_NPROCESSORS_ONLN); | |
520 pid_t pid = getpid(); | |
521 psetid_t pset = PS_NONE; | |
387
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
522 // Are we running in a processor set or is there any processor set around? |
0 | 523 if (pset_bind(PS_QUERY, P_PID, pid, &pset) == 0) { |
387
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
524 uint_t pset_cpus; |
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
525 // Query the number of cpus available to us. |
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
526 if (pset_info(pset, NULL, &pset_cpus, NULL) == 0) { |
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
527 assert(pset_cpus > 0 && pset_cpus <= online_cpus, "sanity check"); |
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
528 _processors_online = pset_cpus; |
fad66fdcb7fc
6673124: Runtime.availableProcessors / os::active_processor_count wrong if unused processor sets exist
xlu
parents:
356
diff
changeset
|
529 return pset_cpus; |
0 | 530 } |
531 } | |
532 // Otherwise return number of online cpus | |
533 return online_cpus; | |
534 } | |
535 | |
536 static bool find_processors_in_pset(psetid_t pset, | |
537 processorid_t** id_array, | |
538 uint_t* id_length) { | |
539 bool result = false; | |
540 // Find the number of processors in the processor set. | |
541 if (pset_info(pset, NULL, id_length, NULL) == 0) { | |
542 // Make up an array to hold their ids. | |
543 *id_array = NEW_C_HEAP_ARRAY(processorid_t, *id_length); | |
544 // Fill in the array with their processor ids. | |
545 if (pset_info(pset, NULL, id_length, *id_array) == 0) { | |
546 result = true; | |
547 } | |
548 } | |
549 return result; | |
550 } | |
551 | |
552 // Callers of find_processors_online() must tolerate imprecise results -- | |
553 // the system configuration can change asynchronously because of DR | |
554 // or explicit psradm operations. | |
555 // | |
556 // We also need to take care that the loop (below) terminates as the | |
557 // number of processors online can change between the _SC_NPROCESSORS_ONLN | |
558 // request and the loop that builds the list of processor ids. Unfortunately | |
559 // there's no reliable way to determine the maximum valid processor id, | |
560 // so we use a manifest constant, MAX_PROCESSOR_ID, instead. See p_online | |
561 // man pages, which claim the processor id set is "sparse, but | |
562 // not too sparse". MAX_PROCESSOR_ID is used to ensure that we eventually | |
563 // exit the loop. | |
564 // | |
565 // In the future we'll be able to use sysconf(_SC_CPUID_MAX), but that's | |
566 // not available on S8.0. | |
567 | |
568 static bool find_processors_online(processorid_t** id_array, | |
569 uint* id_length) { | |
570 const processorid_t MAX_PROCESSOR_ID = 100000 ; | |
571 // Find the number of processors online. | |
572 *id_length = sysconf(_SC_NPROCESSORS_ONLN); | |
573 // Make up an array to hold their ids. | |
574 *id_array = NEW_C_HEAP_ARRAY(processorid_t, *id_length); | |
575 // Processors need not be numbered consecutively. | |
576 long found = 0; | |
577 processorid_t next = 0; | |
578 while (found < *id_length && next < MAX_PROCESSOR_ID) { | |
579 processor_info_t info; | |
580 if (processor_info(next, &info) == 0) { | |
581 // NB, PI_NOINTR processors are effectively online ... | |
582 if (info.pi_state == P_ONLINE || info.pi_state == P_NOINTR) { | |
583 (*id_array)[found] = next; | |
584 found += 1; | |
585 } | |
586 } | |
587 next += 1; | |
588 } | |
589 if (found < *id_length) { | |
590 // The loop above didn't identify the expected number of processors. | |
591 // We could always retry the operation, calling sysconf(_SC_NPROCESSORS_ONLN) | |
592 // and re-running the loop, above, but there's no guarantee of progress | |
593 // if the system configuration is in flux. Instead, we just return what | |
594 // we've got. Note that in the worst case find_processors_online() could | |
595 // return an empty set. (As a fall-back in the case of the empty set we | |
596 // could just return the ID of the current processor). | |
597 *id_length = found ; | |
598 } | |
599 | |
600 return true; | |
601 } | |
602 | |
603 static bool assign_distribution(processorid_t* id_array, | |
604 uint id_length, | |
605 uint* distribution, | |
606 uint distribution_length) { | |
607 // We assume we can assign processorid_t's to uint's. | |
608 assert(sizeof(processorid_t) == sizeof(uint), | |
609 "can't convert processorid_t to uint"); | |
610 // Quick check to see if we won't succeed. | |
611 if (id_length < distribution_length) { | |
612 return false; | |
613 } | |
614 // Assign processor ids to the distribution. | |
615 // Try to shuffle processors to distribute work across boards, | |
616 // assuming 4 processors per board. | |
617 const uint processors_per_board = ProcessDistributionStride; | |
618 // Find the maximum processor id. | |
619 processorid_t max_id = 0; | |
620 for (uint m = 0; m < id_length; m += 1) { | |
621 max_id = MAX2(max_id, id_array[m]); | |
622 } | |
623 // The next id, to limit loops. | |
624 const processorid_t limit_id = max_id + 1; | |
625 // Make up markers for available processors. | |
626 bool* available_id = NEW_C_HEAP_ARRAY(bool, limit_id); | |
627 for (uint c = 0; c < limit_id; c += 1) { | |
628 available_id[c] = false; | |
629 } | |
630 for (uint a = 0; a < id_length; a += 1) { | |
631 available_id[id_array[a]] = true; | |
632 } | |
633 // Step by "boards", then by "slot", copying to "assigned". | |
634 // NEEDS_CLEANUP: The assignment of processors should be stateful, | |
635 // remembering which processors have been assigned by | |
636 // previous calls, etc., so as to distribute several | |
637 // independent calls of this method. What we'd like is | |
638 // It would be nice to have an API that let us ask | |
639 // how many processes are bound to a processor, | |
640 // but we don't have that, either. | |
641 // In the short term, "board" is static so that | |
642 // subsequent distributions don't all start at board 0. | |
643 static uint board = 0; | |
644 uint assigned = 0; | |
645 // Until we've found enough processors .... | |
646 while (assigned < distribution_length) { | |
647 // ... find the next available processor in the board. | |
648 for (uint slot = 0; slot < processors_per_board; slot += 1) { | |
649 uint try_id = board * processors_per_board + slot; | |
650 if ((try_id < limit_id) && (available_id[try_id] == true)) { | |
651 distribution[assigned] = try_id; | |
652 available_id[try_id] = false; | |
653 assigned += 1; | |
654 break; | |
655 } | |
656 } | |
657 board += 1; | |
658 if (board * processors_per_board + 0 >= limit_id) { | |
659 board = 0; | |
660 } | |
661 } | |
662 if (available_id != NULL) { | |
663 FREE_C_HEAP_ARRAY(bool, available_id); | |
664 } | |
665 return true; | |
666 } | |
667 | |
668 bool os::distribute_processes(uint length, uint* distribution) { | |
669 bool result = false; | |
670 // Find the processor id's of all the available CPUs. | |
671 processorid_t* id_array = NULL; | |
672 uint id_length = 0; | |
673 // There are some races between querying information and using it, | |
674 // since processor sets can change dynamically. | |
675 psetid_t pset = PS_NONE; | |
676 // Are we running in a processor set? | |
677 if ((pset_bind(PS_QUERY, P_PID, P_MYID, &pset) == 0) && pset != PS_NONE) { | |
678 result = find_processors_in_pset(pset, &id_array, &id_length); | |
679 } else { | |
680 result = find_processors_online(&id_array, &id_length); | |
681 } | |
682 if (result == true) { | |
683 if (id_length >= length) { | |
684 result = assign_distribution(id_array, id_length, distribution, length); | |
685 } else { | |
686 result = false; | |
687 } | |
688 } | |
689 if (id_array != NULL) { | |
690 FREE_C_HEAP_ARRAY(processorid_t, id_array); | |
691 } | |
692 return result; | |
693 } | |
694 | |
695 bool os::bind_to_processor(uint processor_id) { | |
696 // We assume that a processorid_t can be stored in a uint. | |
697 assert(sizeof(uint) == sizeof(processorid_t), | |
698 "can't convert uint to processorid_t"); | |
699 int bind_result = | |
700 processor_bind(P_LWPID, // bind LWP. | |
701 P_MYID, // bind current LWP. | |
702 (processorid_t) processor_id, // id. | |
703 NULL); // don't return old binding. | |
704 return (bind_result == 0); | |
705 } | |
706 | |
707 bool os::getenv(const char* name, char* buffer, int len) { | |
708 char* val = ::getenv( name ); | |
709 if ( val == NULL | |
710 || strlen(val) + 1 > len ) { | |
711 if (len > 0) buffer[0] = 0; // return a null string | |
712 return false; | |
713 } | |
714 strcpy( buffer, val ); | |
715 return true; | |
716 } | |
717 | |
718 | |
719 // Return true if user is running as root. | |
720 | |
721 bool os::have_special_privileges() { | |
722 static bool init = false; | |
723 static bool privileges = false; | |
724 if (!init) { | |
725 privileges = (getuid() != geteuid()) || (getgid() != getegid()); | |
726 init = true; | |
727 } | |
728 return privileges; | |
729 } | |
730 | |
731 | |
732 void os::init_system_properties_values() { | |
733 char arch[12]; | |
734 sysinfo(SI_ARCHITECTURE, arch, sizeof(arch)); | |
735 | |
736 // The next steps are taken in the product version: | |
737 // | |
738 // Obtain the JAVA_HOME value from the location of libjvm[_g].so. | |
739 // This library should be located at: | |
740 // <JAVA_HOME>/jre/lib/<arch>/{client|server}/libjvm[_g].so. | |
741 // | |
742 // If "/jre/lib/" appears at the right place in the path, then we | |
743 // assume libjvm[_g].so is installed in a JDK and we use this path. | |
744 // | |
745 // Otherwise exit with message: "Could not create the Java virtual machine." | |
746 // | |
747 // The following extra steps are taken in the debugging version: | |
748 // | |
749 // If "/jre/lib/" does NOT appear at the right place in the path | |
750 // instead of exit check for $JAVA_HOME environment variable. | |
751 // | |
752 // If it is defined and we are able to locate $JAVA_HOME/jre/lib/<arch>, | |
753 // then we append a fake suffix "hotspot/libjvm[_g].so" to this path so | |
754 // it looks like libjvm[_g].so is installed there | |
755 // <JAVA_HOME>/jre/lib/<arch>/hotspot/libjvm[_g].so. | |
756 // | |
757 // Otherwise exit. | |
758 // | |
759 // Important note: if the location of libjvm.so changes this | |
760 // code needs to be changed accordingly. | |
761 | |
762 // The next few definitions allow the code to be verbatim: | |
763 #define malloc(n) (char*)NEW_C_HEAP_ARRAY(char, (n)) | |
764 #define free(p) FREE_C_HEAP_ARRAY(char, p) | |
765 #define getenv(n) ::getenv(n) | |
766 | |
767 #define EXTENSIONS_DIR "/lib/ext" | |
768 #define ENDORSED_DIR "/lib/endorsed" | |
769 #define COMMON_DIR "/usr/jdk/packages" | |
770 | |
771 { | |
772 /* sysclasspath, java_home, dll_dir */ | |
773 { | |
774 char *home_path; | |
775 char *dll_path; | |
776 char *pslash; | |
777 char buf[MAXPATHLEN]; | |
778 os::jvm_path(buf, sizeof(buf)); | |
779 | |
780 // Found the full path to libjvm.so. | |
781 // Now cut the path to <java_home>/jre if we can. | |
782 *(strrchr(buf, '/')) = '\0'; /* get rid of /libjvm.so */ | |
783 pslash = strrchr(buf, '/'); | |
784 if (pslash != NULL) | |
785 *pslash = '\0'; /* get rid of /{client|server|hotspot} */ | |
786 dll_path = malloc(strlen(buf) + 1); | |
787 if (dll_path == NULL) | |
788 return; | |
789 strcpy(dll_path, buf); | |
790 Arguments::set_dll_dir(dll_path); | |
791 | |
792 if (pslash != NULL) { | |
793 pslash = strrchr(buf, '/'); | |
794 if (pslash != NULL) { | |
795 *pslash = '\0'; /* get rid of /<arch> */ | |
796 pslash = strrchr(buf, '/'); | |
797 if (pslash != NULL) | |
798 *pslash = '\0'; /* get rid of /lib */ | |
799 } | |
800 } | |
801 | |
802 home_path = malloc(strlen(buf) + 1); | |
803 if (home_path == NULL) | |
804 return; | |
805 strcpy(home_path, buf); | |
806 Arguments::set_java_home(home_path); | |
807 | |
808 if (!set_boot_path('/', ':')) | |
809 return; | |
810 } | |
811 | |
812 /* | |
813 * Where to look for native libraries | |
814 */ | |
815 { | |
816 // Use dlinfo() to determine the correct java.library.path. | |
817 // | |
818 // If we're launched by the Java launcher, and the user | |
819 // does not set java.library.path explicitly on the commandline, | |
820 // the Java launcher sets LD_LIBRARY_PATH for us and unsets | |
821 // LD_LIBRARY_PATH_32 and LD_LIBRARY_PATH_64. In this case | |
822 // dlinfo returns LD_LIBRARY_PATH + crle settings (including | |
823 // /usr/lib), which is exactly what we want. | |
824 // | |
825 // If the user does set java.library.path, it completely | |
826 // overwrites this setting, and always has. | |
827 // | |
828 // If we're not launched by the Java launcher, we may | |
829 // get here with any/all of the LD_LIBRARY_PATH[_32|64] | |
830 // settings. Again, dlinfo does exactly what we want. | |
831 | |
832 Dl_serinfo _info, *info = &_info; | |
833 Dl_serpath *path; | |
834 char* library_path; | |
835 char *common_path; | |
836 int i; | |
837 | |
838 // determine search path count and required buffer size | |
839 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFOSIZE, (void *)info) == -1) { | |
840 vm_exit_during_initialization("dlinfo SERINFOSIZE request", dlerror()); | |
841 } | |
842 | |
843 // allocate new buffer and initialize | |
844 info = (Dl_serinfo*)malloc(_info.dls_size); | |
845 if (info == NULL) { | |
846 vm_exit_out_of_memory(_info.dls_size, | |
847 "init_system_properties_values info"); | |
848 } | |
849 info->dls_size = _info.dls_size; | |
850 info->dls_cnt = _info.dls_cnt; | |
851 | |
852 // obtain search path information | |
853 if (dlinfo(RTLD_SELF, RTLD_DI_SERINFO, (void *)info) == -1) { | |
854 free(info); | |
855 vm_exit_during_initialization("dlinfo SERINFO request", dlerror()); | |
856 } | |
857 | |
858 path = &info->dls_serpath[0]; | |
859 | |
860 // Note: Due to a legacy implementation, most of the library path | |
861 // is set in the launcher. This was to accomodate linking restrictions | |
862 // on legacy Solaris implementations (which are no longer supported). | |
863 // Eventually, all the library path setting will be done here. | |
864 // | |
865 // However, to prevent the proliferation of improperly built native | |
866 // libraries, the new path component /usr/jdk/packages is added here. | |
867 | |
868 // Determine the actual CPU architecture. | |
869 char cpu_arch[12]; | |
870 sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch)); | |
871 #ifdef _LP64 | |
872 // If we are a 64-bit vm, perform the following translations: | |
873 // sparc -> sparcv9 | |
874 // i386 -> amd64 | |
875 if (strcmp(cpu_arch, "sparc") == 0) | |
876 strcat(cpu_arch, "v9"); | |
877 else if (strcmp(cpu_arch, "i386") == 0) | |
878 strcpy(cpu_arch, "amd64"); | |
879 #endif | |
880 | |
881 // Construct the invariant part of ld_library_path. Note that the | |
882 // space for the colon and the trailing null are provided by the | |
883 // nulls included by the sizeof operator. | |
884 size_t bufsize = sizeof(COMMON_DIR) + sizeof("/lib/") + strlen(cpu_arch); | |
885 common_path = malloc(bufsize); | |
886 if (common_path == NULL) { | |
887 free(info); | |
888 vm_exit_out_of_memory(bufsize, | |
889 "init_system_properties_values common_path"); | |
890 } | |
891 sprintf(common_path, COMMON_DIR "/lib/%s", cpu_arch); | |
892 | |
893 // struct size is more than sufficient for the path components obtained | |
894 // through the dlinfo() call, so only add additional space for the path | |
895 // components explicitly added here. | |
896 bufsize = info->dls_size + strlen(common_path); | |
897 library_path = malloc(bufsize); | |
898 if (library_path == NULL) { | |
899 free(info); | |
900 free(common_path); | |
901 vm_exit_out_of_memory(bufsize, | |
902 "init_system_properties_values library_path"); | |
903 } | |
904 library_path[0] = '\0'; | |
905 | |
906 // Construct the desired Java library path from the linker's library | |
907 // search path. | |
908 // | |
909 // For compatibility, it is optimal that we insert the additional path | |
910 // components specific to the Java VM after those components specified | |
911 // in LD_LIBRARY_PATH (if any) but before those added by the ld.so | |
912 // infrastructure. | |
913 if (info->dls_cnt == 0) { // Not sure this can happen, but allow for it | |
914 strcpy(library_path, common_path); | |
915 } else { | |
916 int inserted = 0; | |
917 for (i = 0; i < info->dls_cnt; i++, path++) { | |
918 uint_t flags = path->dls_flags & LA_SER_MASK; | |
919 if (((flags & LA_SER_LIBPATH) == 0) && !inserted) { | |
920 strcat(library_path, common_path); | |
921 strcat(library_path, os::path_separator()); | |
922 inserted = 1; | |
923 } | |
924 strcat(library_path, path->dls_name); | |
925 strcat(library_path, os::path_separator()); | |
926 } | |
927 // eliminate trailing path separator | |
928 library_path[strlen(library_path)-1] = '\0'; | |
929 } | |
930 | |
931 // happens before argument parsing - can't use a trace flag | |
932 // tty->print_raw("init_system_properties_values: native lib path: "); | |
933 // tty->print_raw_cr(library_path); | |
934 | |
935 // callee copies into its own buffer | |
936 Arguments::set_library_path(library_path); | |
937 | |
938 free(common_path); | |
939 free(library_path); | |
940 free(info); | |
941 } | |
942 | |
943 /* | |
944 * Extensions directories. | |
945 * | |
946 * Note that the space for the colon and the trailing null are provided | |
947 * by the nulls included by the sizeof operator (so actually one byte more | |
948 * than necessary is allocated). | |
949 */ | |
950 { | |
951 char *buf = (char *) malloc(strlen(Arguments::get_java_home()) + | |
952 sizeof(EXTENSIONS_DIR) + sizeof(COMMON_DIR) + | |
953 sizeof(EXTENSIONS_DIR)); | |
954 sprintf(buf, "%s" EXTENSIONS_DIR ":" COMMON_DIR EXTENSIONS_DIR, | |
955 Arguments::get_java_home()); | |
956 Arguments::set_ext_dirs(buf); | |
957 } | |
958 | |
959 /* Endorsed standards default directory. */ | |
960 { | |
961 char * buf = malloc(strlen(Arguments::get_java_home()) + sizeof(ENDORSED_DIR)); | |
962 sprintf(buf, "%s" ENDORSED_DIR, Arguments::get_java_home()); | |
963 Arguments::set_endorsed_dirs(buf); | |
964 } | |
965 } | |
966 | |
967 #undef malloc | |
968 #undef free | |
969 #undef getenv | |
970 #undef EXTENSIONS_DIR | |
971 #undef ENDORSED_DIR | |
972 #undef COMMON_DIR | |
973 | |
974 } | |
975 | |
976 void os::breakpoint() { | |
977 BREAKPOINT; | |
978 } | |
979 | |
980 bool os::obsolete_option(const JavaVMOption *option) | |
981 { | |
982 if (!strncmp(option->optionString, "-Xt", 3)) { | |
983 return true; | |
984 } else if (!strncmp(option->optionString, "-Xtm", 4)) { | |
985 return true; | |
986 } else if (!strncmp(option->optionString, "-Xverifyheap", 12)) { | |
987 return true; | |
988 } else if (!strncmp(option->optionString, "-Xmaxjitcodesize", 16)) { | |
989 return true; | |
990 } | |
991 return false; | |
992 } | |
993 | |
994 bool os::Solaris::valid_stack_address(Thread* thread, address sp) { | |
995 address stackStart = (address)thread->stack_base(); | |
996 address stackEnd = (address)(stackStart - (address)thread->stack_size()); | |
997 if (sp < stackStart && sp >= stackEnd ) return true; | |
998 return false; | |
999 } | |
1000 | |
1001 extern "C" void breakpoint() { | |
1002 // use debugger to set breakpoint here | |
1003 } | |
1004 | |
1005 // Returns an estimate of the current stack pointer. Result must be guaranteed to | |
1006 // point into the calling threads stack, and be no lower than the current stack | |
1007 // pointer. | |
1008 address os::current_stack_pointer() { | |
1009 volatile int dummy; | |
1010 address sp = (address)&dummy + 8; // %%%% need to confirm if this is right | |
1011 return sp; | |
1012 } | |
1013 | |
1014 static thread_t main_thread; | |
1015 | |
1016 // Thread start routine for all new Java threads | |
1017 extern "C" void* java_start(void* thread_addr) { | |
1018 // Try to randomize the cache line index of hot stack frames. | |
1019 // This helps when threads of the same stack traces evict each other's | |
1020 // cache lines. The threads can be either from the same JVM instance, or | |
1021 // from different JVM instances. The benefit is especially true for | |
1022 // processors with hyperthreading technology. | |
1023 static int counter = 0; | |
1024 int pid = os::current_process_id(); | |
1025 alloca(((pid ^ counter++) & 7) * 128); | |
1026 | |
1027 int prio; | |
1028 Thread* thread = (Thread*)thread_addr; | |
1029 OSThread* osthr = thread->osthread(); | |
1030 | |
1031 osthr->set_lwp_id( _lwp_self() ); // Store lwp in case we are bound | |
1032 thread->_schedctl = (void *) schedctl_init () ; | |
1033 | |
1034 if (UseNUMA) { | |
1035 int lgrp_id = os::numa_get_group_id(); | |
1036 if (lgrp_id != -1) { | |
1037 thread->set_lgrp_id(lgrp_id); | |
1038 } | |
1039 } | |
1040 | |
1041 // If the creator called set priority before we started, | |
1042 // we need to call set priority now that we have an lwp. | |
1043 // Get the priority from libthread and set the priority | |
1044 // for the new Solaris lwp. | |
1045 if ( osthr->thread_id() != -1 ) { | |
1046 if ( UseThreadPriorities ) { | |
1047 thr_getprio(osthr->thread_id(), &prio); | |
1048 if (ThreadPriorityVerbose) { | |
1049 tty->print_cr("Starting Thread " INTPTR_FORMAT ", LWP is " INTPTR_FORMAT ", setting priority: %d\n", | |
1050 osthr->thread_id(), osthr->lwp_id(), prio ); | |
1051 } | |
1052 os::set_native_priority(thread, prio); | |
1053 } | |
1054 } else if (ThreadPriorityVerbose) { | |
1055 warning("Can't set priority in _start routine, thread id hasn't been set\n"); | |
1056 } | |
1057 | |
1058 assert(osthr->get_state() == RUNNABLE, "invalid os thread state"); | |
1059 | |
1060 // initialize signal mask for this thread | |
1061 os::Solaris::hotspot_sigmask(thread); | |
1062 | |
1063 thread->run(); | |
1064 | |
1065 // One less thread is executing | |
1066 // When the VMThread gets here, the main thread may have already exited | |
1067 // which frees the CodeHeap containing the Atomic::dec code | |
1068 if (thread != VMThread::vm_thread() && VMThread::vm_thread() != NULL) { | |
1069 Atomic::dec(&os::Solaris::_os_thread_count); | |
1070 } | |
1071 | |
1072 if (UseDetachedThreads) { | |
1073 thr_exit(NULL); | |
1074 ShouldNotReachHere(); | |
1075 } | |
1076 return NULL; | |
1077 } | |
1078 | |
1079 static OSThread* create_os_thread(Thread* thread, thread_t thread_id) { | |
1080 // Allocate the OSThread object | |
1081 OSThread* osthread = new OSThread(NULL, NULL); | |
1082 if (osthread == NULL) return NULL; | |
1083 | |
1084 // Store info on the Solaris thread into the OSThread | |
1085 osthread->set_thread_id(thread_id); | |
1086 osthread->set_lwp_id(_lwp_self()); | |
1087 thread->_schedctl = (void *) schedctl_init () ; | |
1088 | |
1089 if (UseNUMA) { | |
1090 int lgrp_id = os::numa_get_group_id(); | |
1091 if (lgrp_id != -1) { | |
1092 thread->set_lgrp_id(lgrp_id); | |
1093 } | |
1094 } | |
1095 | |
1096 if ( ThreadPriorityVerbose ) { | |
1097 tty->print_cr("In create_os_thread, Thread " INTPTR_FORMAT ", LWP is " INTPTR_FORMAT "\n", | |
1098 osthread->thread_id(), osthread->lwp_id() ); | |
1099 } | |
1100 | |
1101 // Initial thread state is INITIALIZED, not SUSPENDED | |
1102 osthread->set_state(INITIALIZED); | |
1103 | |
1104 return osthread; | |
1105 } | |
1106 | |
1107 void os::Solaris::hotspot_sigmask(Thread* thread) { | |
1108 | |
1109 //Save caller's signal mask | |
1110 sigset_t sigmask; | |
1111 thr_sigsetmask(SIG_SETMASK, NULL, &sigmask); | |
1112 OSThread *osthread = thread->osthread(); | |
1113 osthread->set_caller_sigmask(sigmask); | |
1114 | |
1115 thr_sigsetmask(SIG_UNBLOCK, os::Solaris::unblocked_signals(), NULL); | |
1116 if (!ReduceSignalUsage) { | |
1117 if (thread->is_VM_thread()) { | |
1118 // Only the VM thread handles BREAK_SIGNAL ... | |
1119 thr_sigsetmask(SIG_UNBLOCK, vm_signals(), NULL); | |
1120 } else { | |
1121 // ... all other threads block BREAK_SIGNAL | |
1122 assert(!sigismember(vm_signals(), SIGINT), "SIGINT should not be blocked"); | |
1123 thr_sigsetmask(SIG_BLOCK, vm_signals(), NULL); | |
1124 } | |
1125 } | |
1126 } | |
1127 | |
1128 bool os::create_attached_thread(JavaThread* thread) { | |
1129 #ifdef ASSERT | |
1130 thread->verify_not_published(); | |
1131 #endif | |
1132 OSThread* osthread = create_os_thread(thread, thr_self()); | |
1133 if (osthread == NULL) { | |
1134 return false; | |
1135 } | |
1136 | |
1137 // Initial thread state is RUNNABLE | |
1138 osthread->set_state(RUNNABLE); | |
1139 thread->set_osthread(osthread); | |
1140 | |
1141 // initialize signal mask for this thread | |
1142 // and save the caller's signal mask | |
1143 os::Solaris::hotspot_sigmask(thread); | |
1144 | |
1145 return true; | |
1146 } | |
1147 | |
1148 bool os::create_main_thread(JavaThread* thread) { | |
1149 #ifdef ASSERT | |
1150 thread->verify_not_published(); | |
1151 #endif | |
1152 if (_starting_thread == NULL) { | |
1153 _starting_thread = create_os_thread(thread, main_thread); | |
1154 if (_starting_thread == NULL) { | |
1155 return false; | |
1156 } | |
1157 } | |
1158 | |
1159 // The primodial thread is runnable from the start | |
1160 _starting_thread->set_state(RUNNABLE); | |
1161 | |
1162 thread->set_osthread(_starting_thread); | |
1163 | |
1164 // initialize signal mask for this thread | |
1165 // and save the caller's signal mask | |
1166 os::Solaris::hotspot_sigmask(thread); | |
1167 | |
1168 return true; | |
1169 } | |
1170 | |
1171 // _T2_libthread is true if we believe we are running with the newer | |
1172 // SunSoft lwp/libthread.so (2.8 patch, 2.9 default) | |
1173 bool os::Solaris::_T2_libthread = false; | |
1174 | |
1175 bool os::create_thread(Thread* thread, ThreadType thr_type, size_t stack_size) { | |
1176 // Allocate the OSThread object | |
1177 OSThread* osthread = new OSThread(NULL, NULL); | |
1178 if (osthread == NULL) { | |
1179 return false; | |
1180 } | |
1181 | |
1182 if ( ThreadPriorityVerbose ) { | |
1183 char *thrtyp; | |
1184 switch ( thr_type ) { | |
1185 case vm_thread: | |
1186 thrtyp = (char *)"vm"; | |
1187 break; | |
1188 case cgc_thread: | |
1189 thrtyp = (char *)"cgc"; | |
1190 break; | |
1191 case pgc_thread: | |
1192 thrtyp = (char *)"pgc"; | |
1193 break; | |
1194 case java_thread: | |
1195 thrtyp = (char *)"java"; | |
1196 break; | |
1197 case compiler_thread: | |
1198 thrtyp = (char *)"compiler"; | |
1199 break; | |
1200 case watcher_thread: | |
1201 thrtyp = (char *)"watcher"; | |
1202 break; | |
1203 default: | |
1204 thrtyp = (char *)"unknown"; | |
1205 break; | |
1206 } | |
1207 tty->print_cr("In create_thread, creating a %s thread\n", thrtyp); | |
1208 } | |
1209 | |
1210 // Calculate stack size if it's not specified by caller. | |
1211 if (stack_size == 0) { | |
1212 // The default stack size 1M (2M for LP64). | |
1213 stack_size = (BytesPerWord >> 2) * K * K; | |
1214 | |
1215 switch (thr_type) { | |
1216 case os::java_thread: | |
1217 // Java threads use ThreadStackSize which default value can be changed with the flag -Xss | |
1218 if (JavaThread::stack_size_at_create() > 0) stack_size = JavaThread::stack_size_at_create(); | |
1219 break; | |
1220 case os::compiler_thread: | |
1221 if (CompilerThreadStackSize > 0) { | |
1222 stack_size = (size_t)(CompilerThreadStackSize * K); | |
1223 break; | |
1224 } // else fall through: | |
1225 // use VMThreadStackSize if CompilerThreadStackSize is not defined | |
1226 case os::vm_thread: | |
1227 case os::pgc_thread: | |
1228 case os::cgc_thread: | |
1229 case os::watcher_thread: | |
1230 if (VMThreadStackSize > 0) stack_size = (size_t)(VMThreadStackSize * K); | |
1231 break; | |
1232 } | |
1233 } | |
1234 stack_size = MAX2(stack_size, os::Solaris::min_stack_allowed); | |
1235 | |
1236 // Initial state is ALLOCATED but not INITIALIZED | |
1237 osthread->set_state(ALLOCATED); | |
1238 | |
1239 if (os::Solaris::_os_thread_count > os::Solaris::_os_thread_limit) { | |
1240 // We got lots of threads. Check if we still have some address space left. | |
1241 // Need to be at least 5Mb of unreserved address space. We do check by | |
1242 // trying to reserve some. | |
1243 const size_t VirtualMemoryBangSize = 20*K*K; | |
1244 char* mem = os::reserve_memory(VirtualMemoryBangSize); | |
1245 if (mem == NULL) { | |
1246 delete osthread; | |
1247 return false; | |
1248 } else { | |
1249 // Release the memory again | |
1250 os::release_memory(mem, VirtualMemoryBangSize); | |
1251 } | |
1252 } | |
1253 | |
1254 // Setup osthread because the child thread may need it. | |
1255 thread->set_osthread(osthread); | |
1256 | |
1257 // Create the Solaris thread | |
1258 // explicit THR_BOUND for T2_libthread case in case | |
1259 // that assumption is not accurate, but our alternate signal stack | |
1260 // handling is based on it which must have bound threads | |
1261 thread_t tid = 0; | |
1262 long flags = (UseDetachedThreads ? THR_DETACHED : 0) | THR_SUSPENDED | |
1263 | ((UseBoundThreads || os::Solaris::T2_libthread() || | |
1264 (thr_type == vm_thread) || | |
1265 (thr_type == cgc_thread) || | |
1266 (thr_type == pgc_thread) || | |
1267 (thr_type == compiler_thread && BackgroundCompilation)) ? | |
1268 THR_BOUND : 0); | |
1269 int status; | |
1270 | |
1271 // 4376845 -- libthread/kernel don't provide enough LWPs to utilize all CPUs. | |
1272 // | |
1273 // On multiprocessors systems, libthread sometimes under-provisions our | |
1274 // process with LWPs. On a 30-way systems, for instance, we could have | |
1275 // 50 user-level threads in ready state and only 2 or 3 LWPs assigned | |
1276 // to our process. This can result in under utilization of PEs. | |
1277 // I suspect the problem is related to libthread's LWP | |
1278 // pool management and to the kernel's SIGBLOCKING "last LWP parked" | |
1279 // upcall policy. | |
1280 // | |
1281 // The following code is palliative -- it attempts to ensure that our | |
1282 // process has sufficient LWPs to take advantage of multiple PEs. | |
1283 // Proper long-term cures include using user-level threads bound to LWPs | |
1284 // (THR_BOUND) or using LWP-based synchronization. Note that there is a | |
1285 // slight timing window with respect to sampling _os_thread_count, but | |
1286 // the race is benign. Also, we should periodically recompute | |
1287 // _processors_online as the min of SC_NPROCESSORS_ONLN and the | |
1288 // the number of PEs in our partition. You might be tempted to use | |
1289 // THR_NEW_LWP here, but I'd recommend against it as that could | |
1290 // result in undesirable growth of the libthread's LWP pool. | |
1291 // The fix below isn't sufficient; for instance, it doesn't take into count | |
1292 // LWPs parked on IO. It does, however, help certain CPU-bound benchmarks. | |
1293 // | |
1294 // Some pathologies this scheme doesn't handle: | |
1295 // * Threads can block, releasing the LWPs. The LWPs can age out. | |
1296 // When a large number of threads become ready again there aren't | |
1297 // enough LWPs available to service them. This can occur when the | |
1298 // number of ready threads oscillates. | |
1299 // * LWPs/Threads park on IO, thus taking the LWP out of circulation. | |
1300 // | |
1301 // Finally, we should call thr_setconcurrency() periodically to refresh | |
1302 // the LWP pool and thwart the LWP age-out mechanism. | |
1303 // The "+3" term provides a little slop -- we want to slightly overprovision. | |
1304 | |
1305 if (AdjustConcurrency && os::Solaris::_os_thread_count < (_processors_online+3)) { | |
1306 if (!(flags & THR_BOUND)) { | |
1307 thr_setconcurrency (os::Solaris::_os_thread_count); // avoid starvation | |
1308 } | |
1309 } | |
1310 // Although this doesn't hurt, we should warn of undefined behavior | |
1311 // when using unbound T1 threads with schedctl(). This should never | |
1312 // happen, as the compiler and VM threads are always created bound | |
1313 DEBUG_ONLY( | |
1314 if ((VMThreadHintNoPreempt || CompilerThreadHintNoPreempt) && | |
1315 (!os::Solaris::T2_libthread() && (!(flags & THR_BOUND))) && | |
1316 ((thr_type == vm_thread) || (thr_type == cgc_thread) || | |
1317 (thr_type == pgc_thread) || (thr_type == compiler_thread && BackgroundCompilation))) { | |
1318 warning("schedctl behavior undefined when Compiler/VM/GC Threads are Unbound"); | |
1319 } | |
1320 ); | |
1321 | |
1322 | |
1323 // Mark that we don't have an lwp or thread id yet. | |
1324 // In case we attempt to set the priority before the thread starts. | |
1325 osthread->set_lwp_id(-1); | |
1326 osthread->set_thread_id(-1); | |
1327 | |
1328 status = thr_create(NULL, stack_size, java_start, thread, flags, &tid); | |
1329 if (status != 0) { | |
1330 if (PrintMiscellaneous && (Verbose || WizardMode)) { | |
1331 perror("os::create_thread"); | |
1332 } | |
1333 thread->set_osthread(NULL); | |
1334 // Need to clean up stuff we've allocated so far | |
1335 delete osthread; | |
1336 return false; | |
1337 } | |
1338 | |
1339 Atomic::inc(&os::Solaris::_os_thread_count); | |
1340 | |
1341 // Store info on the Solaris thread into the OSThread | |
1342 osthread->set_thread_id(tid); | |
1343 | |
1344 // Remember that we created this thread so we can set priority on it | |
1345 osthread->set_vm_created(); | |
1346 | |
1347 // Set the default thread priority otherwise use NormalPriority | |
1348 | |
1349 if ( UseThreadPriorities ) { | |
1350 thr_setprio(tid, (DefaultThreadPriority == -1) ? | |
1351 java_to_os_priority[NormPriority] : | |
1352 DefaultThreadPriority); | |
1353 } | |
1354 | |
1355 // Initial thread state is INITIALIZED, not SUSPENDED | |
1356 osthread->set_state(INITIALIZED); | |
1357 | |
1358 // The thread is returned suspended (in state INITIALIZED), and is started higher up in the call chain | |
1359 return true; | |
1360 } | |
1361 | |
1362 /* defined for >= Solaris 10. This allows builds on earlier versions | |
1363 * of Solaris to take advantage of the newly reserved Solaris JVM signals | |
1364 * With SIGJVM1, SIGJVM2, INTERRUPT_SIGNAL is SIGJVM1, ASYNC_SIGNAL is SIGJVM2 | |
1365 * and -XX:+UseAltSigs does nothing since these should have no conflict | |
1366 */ | |
1367 #if !defined(SIGJVM1) | |
1368 #define SIGJVM1 39 | |
1369 #define SIGJVM2 40 | |
1370 #endif | |
1371 | |
1372 debug_only(static bool signal_sets_initialized = false); | |
1373 static sigset_t unblocked_sigs, vm_sigs, allowdebug_blocked_sigs; | |
1374 int os::Solaris::_SIGinterrupt = INTERRUPT_SIGNAL; | |
1375 int os::Solaris::_SIGasync = ASYNC_SIGNAL; | |
1376 | |
1377 bool os::Solaris::is_sig_ignored(int sig) { | |
1378 struct sigaction oact; | |
1379 sigaction(sig, (struct sigaction*)NULL, &oact); | |
1380 void* ohlr = oact.sa_sigaction ? CAST_FROM_FN_PTR(void*, oact.sa_sigaction) | |
1381 : CAST_FROM_FN_PTR(void*, oact.sa_handler); | |
1382 if (ohlr == CAST_FROM_FN_PTR(void*, SIG_IGN)) | |
1383 return true; | |
1384 else | |
1385 return false; | |
1386 } | |
1387 | |
1388 // Note: SIGRTMIN is a macro that calls sysconf() so it will | |
1389 // dynamically detect SIGRTMIN value for the system at runtime, not buildtime | |
1390 static bool isJVM1available() { | |
1391 return SIGJVM1 < SIGRTMIN; | |
1392 } | |
1393 | |
1394 void os::Solaris::signal_sets_init() { | |
1395 // Should also have an assertion stating we are still single-threaded. | |
1396 assert(!signal_sets_initialized, "Already initialized"); | |
1397 // Fill in signals that are necessarily unblocked for all threads in | |
1398 // the VM. Currently, we unblock the following signals: | |
1399 // SHUTDOWN{1,2,3}_SIGNAL: for shutdown hooks support (unless over-ridden | |
1400 // by -Xrs (=ReduceSignalUsage)); | |
1401 // BREAK_SIGNAL which is unblocked only by the VM thread and blocked by all | |
1402 // other threads. The "ReduceSignalUsage" boolean tells us not to alter | |
1403 // the dispositions or masks wrt these signals. | |
1404 // Programs embedding the VM that want to use the above signals for their | |
1405 // own purposes must, at this time, use the "-Xrs" option to prevent | |
1406 // interference with shutdown hooks and BREAK_SIGNAL thread dumping. | |
1407 // (See bug 4345157, and other related bugs). | |
1408 // In reality, though, unblocking these signals is really a nop, since | |
1409 // these signals are not blocked by default. | |
1410 sigemptyset(&unblocked_sigs); | |
1411 sigemptyset(&allowdebug_blocked_sigs); | |
1412 sigaddset(&unblocked_sigs, SIGILL); | |
1413 sigaddset(&unblocked_sigs, SIGSEGV); | |
1414 sigaddset(&unblocked_sigs, SIGBUS); | |
1415 sigaddset(&unblocked_sigs, SIGFPE); | |
1416 | |
1417 if (isJVM1available) { | |
1418 os::Solaris::set_SIGinterrupt(SIGJVM1); | |
1419 os::Solaris::set_SIGasync(SIGJVM2); | |
1420 } else if (UseAltSigs) { | |
1421 os::Solaris::set_SIGinterrupt(ALT_INTERRUPT_SIGNAL); | |
1422 os::Solaris::set_SIGasync(ALT_ASYNC_SIGNAL); | |
1423 } else { | |
1424 os::Solaris::set_SIGinterrupt(INTERRUPT_SIGNAL); | |
1425 os::Solaris::set_SIGasync(ASYNC_SIGNAL); | |
1426 } | |
1427 | |
1428 sigaddset(&unblocked_sigs, os::Solaris::SIGinterrupt()); | |
1429 sigaddset(&unblocked_sigs, os::Solaris::SIGasync()); | |
1430 | |
1431 if (!ReduceSignalUsage) { | |
1432 if (!os::Solaris::is_sig_ignored(SHUTDOWN1_SIGNAL)) { | |
1433 sigaddset(&unblocked_sigs, SHUTDOWN1_SIGNAL); | |
1434 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN1_SIGNAL); | |
1435 } | |
1436 if (!os::Solaris::is_sig_ignored(SHUTDOWN2_SIGNAL)) { | |
1437 sigaddset(&unblocked_sigs, SHUTDOWN2_SIGNAL); | |
1438 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN2_SIGNAL); | |
1439 } | |
1440 if (!os::Solaris::is_sig_ignored(SHUTDOWN3_SIGNAL)) { | |
1441 sigaddset(&unblocked_sigs, SHUTDOWN3_SIGNAL); | |
1442 sigaddset(&allowdebug_blocked_sigs, SHUTDOWN3_SIGNAL); | |
1443 } | |
1444 } | |
1445 // Fill in signals that are blocked by all but the VM thread. | |
1446 sigemptyset(&vm_sigs); | |
1447 if (!ReduceSignalUsage) | |
1448 sigaddset(&vm_sigs, BREAK_SIGNAL); | |
1449 debug_only(signal_sets_initialized = true); | |
1450 | |
1451 // For diagnostics only used in run_periodic_checks | |
1452 sigemptyset(&check_signal_done); | |
1453 } | |
1454 | |
1455 // These are signals that are unblocked while a thread is running Java. | |
1456 // (For some reason, they get blocked by default.) | |
1457 sigset_t* os::Solaris::unblocked_signals() { | |
1458 assert(signal_sets_initialized, "Not initialized"); | |
1459 return &unblocked_sigs; | |
1460 } | |
1461 | |
1462 // These are the signals that are blocked while a (non-VM) thread is | |
1463 // running Java. Only the VM thread handles these signals. | |
1464 sigset_t* os::Solaris::vm_signals() { | |
1465 assert(signal_sets_initialized, "Not initialized"); | |
1466 return &vm_sigs; | |
1467 } | |
1468 | |
1469 // These are signals that are blocked during cond_wait to allow debugger in | |
1470 sigset_t* os::Solaris::allowdebug_blocked_signals() { | |
1471 assert(signal_sets_initialized, "Not initialized"); | |
1472 return &allowdebug_blocked_sigs; | |
1473 } | |
1474 | |
1475 // First crack at OS-specific initialization, from inside the new thread. | |
1476 void os::initialize_thread() { | |
1477 int r = thr_main() ; | |
1478 guarantee (r == 0 || r == 1, "CR6501650 or CR6493689") ; | |
1479 if (r) { | |
1480 JavaThread* jt = (JavaThread *)Thread::current(); | |
1481 assert(jt != NULL,"Sanity check"); | |
1482 size_t stack_size; | |
1483 address base = jt->stack_base(); | |
1484 if (Arguments::created_by_java_launcher()) { | |
1485 // Use 2MB to allow for Solaris 7 64 bit mode. | |
1486 stack_size = JavaThread::stack_size_at_create() == 0 | |
1487 ? 2048*K : JavaThread::stack_size_at_create(); | |
1488 | |
1489 // There are rare cases when we may have already used more than | |
1490 // the basic stack size allotment before this method is invoked. | |
1491 // Attempt to allow for a normally sized java_stack. | |
1492 size_t current_stack_offset = (size_t)(base - (address)&stack_size); | |
1493 stack_size += ReservedSpace::page_align_size_down(current_stack_offset); | |
1494 } else { | |
1495 // 6269555: If we were not created by a Java launcher, i.e. if we are | |
1496 // running embedded in a native application, treat the primordial thread | |
1497 // as much like a native attached thread as possible. This means using | |
1498 // the current stack size from thr_stksegment(), unless it is too large | |
1499 // to reliably setup guard pages. A reasonable max size is 8MB. | |
1500 size_t current_size = current_stack_size(); | |
1501 // This should never happen, but just in case.... | |
1502 if (current_size == 0) current_size = 2 * K * K; | |
1503 stack_size = current_size > (8 * K * K) ? (8 * K * K) : current_size; | |
1504 } | |
1505 address bottom = (address)align_size_up((intptr_t)(base - stack_size), os::vm_page_size());; | |
1506 stack_size = (size_t)(base - bottom); | |
1507 | |
1508 assert(stack_size > 0, "Stack size calculation problem"); | |
1509 | |
1510 if (stack_size > jt->stack_size()) { | |
1511 NOT_PRODUCT( | |
1512 struct rlimit limits; | |
1513 getrlimit(RLIMIT_STACK, &limits); | |
1514 size_t size = adjust_stack_size(base, (size_t)limits.rlim_cur); | |
1515 assert(size >= jt->stack_size(), "Stack size problem in main thread"); | |
1516 ) | |
1517 tty->print_cr( | |
1518 "Stack size of %d Kb exceeds current limit of %d Kb.\n" | |
1519 "(Stack sizes are rounded up to a multiple of the system page size.)\n" | |
1520 "See limit(1) to increase the stack size limit.", | |
1521 stack_size / K, jt->stack_size() / K); | |
1522 vm_exit(1); | |
1523 } | |
1524 assert(jt->stack_size() >= stack_size, | |
1525 "Attempt to map more stack than was allocated"); | |
1526 jt->set_stack_size(stack_size); | |
1527 } | |
1528 | |
1529 // 5/22/01: Right now alternate signal stacks do not handle | |
1530 // throwing stack overflow exceptions, see bug 4463178 | |
1531 // Until a fix is found for this, T2 will NOT imply alternate signal | |
1532 // stacks. | |
1533 // If using T2 libthread threads, install an alternate signal stack. | |
1534 // Because alternate stacks associate with LWPs on Solaris, | |
1535 // see sigaltstack(2), if using UNBOUND threads, or if UseBoundThreads | |
1536 // we prefer to explicitly stack bang. | |
1537 // If not using T2 libthread, but using UseBoundThreads any threads | |
1538 // (primordial thread, jni_attachCurrentThread) we do not create, | |
1539 // probably are not bound, therefore they can not have an alternate | |
1540 // signal stack. Since our stack banging code is generated and | |
1541 // is shared across threads, all threads must be bound to allow | |
1542 // using alternate signal stacks. The alternative is to interpose | |
1543 // on _lwp_create to associate an alt sig stack with each LWP, | |
1544 // and this could be a problem when the JVM is embedded. | |
1545 // We would prefer to use alternate signal stacks with T2 | |
1546 // Since there is currently no accurate way to detect T2 | |
1547 // we do not. Assuming T2 when running T1 causes sig 11s or assertions | |
1548 // on installing alternate signal stacks | |
1549 | |
1550 | |
1551 // 05/09/03: removed alternate signal stack support for Solaris | |
1552 // The alternate signal stack mechanism is no longer needed to | |
1553 // handle stack overflow. This is now handled by allocating | |
1554 // guard pages (red zone) and stackbanging. | |
1555 // Initially the alternate signal stack mechanism was removed because | |
1556 // it did not work with T1 llibthread. Alternate | |
1557 // signal stacks MUST have all threads bound to lwps. Applications | |
1558 // can create their own threads and attach them without their being | |
1559 // bound under T1. This is frequently the case for the primordial thread. | |
1560 // If we were ever to reenable this mechanism we would need to | |
1561 // use the dynamic check for T2 libthread. | |
1562 | |
1563 os::Solaris::init_thread_fpu_state(); | |
1564 } | |
1565 | |
1566 | |
1567 | |
1568 // Free Solaris resources related to the OSThread | |
1569 void os::free_thread(OSThread* osthread) { | |
1570 assert(osthread != NULL, "os::free_thread but osthread not set"); | |
1571 | |
1572 | |
1573 // We are told to free resources of the argument thread, | |
1574 // but we can only really operate on the current thread. | |
1575 // The main thread must take the VMThread down synchronously | |
1576 // before the main thread exits and frees up CodeHeap | |
1577 guarantee((Thread::current()->osthread() == osthread | |
1578 || (osthread == VMThread::vm_thread()->osthread())), "os::free_thread but not current thread"); | |
1579 if (Thread::current()->osthread() == osthread) { | |
1580 // Restore caller's signal mask | |
1581 sigset_t sigmask = osthread->caller_sigmask(); | |
1582 thr_sigsetmask(SIG_SETMASK, &sigmask, NULL); | |
1583 } | |
1584 delete osthread; | |
1585 } | |
1586 | |
1587 void os::pd_start_thread(Thread* thread) { | |
1588 int status = thr_continue(thread->osthread()->thread_id()); | |
1589 assert_status(status == 0, status, "thr_continue failed"); | |
1590 } | |
1591 | |
1592 | |
1593 intx os::current_thread_id() { | |
1594 return (intx)thr_self(); | |
1595 } | |
1596 | |
1597 static pid_t _initial_pid = 0; | |
1598 | |
1599 int os::current_process_id() { | |
1600 return (int)(_initial_pid ? _initial_pid : getpid()); | |
1601 } | |
1602 | |
1603 int os::allocate_thread_local_storage() { | |
1604 // %%% in Win32 this allocates a memory segment pointed to by a | |
1605 // register. Dan Stein can implement a similar feature in | |
1606 // Solaris. Alternatively, the VM can do the same thing | |
1607 // explicitly: malloc some storage and keep the pointer in a | |
1608 // register (which is part of the thread's context) (or keep it | |
1609 // in TLS). | |
1610 // %%% In current versions of Solaris, thr_self and TSD can | |
1611 // be accessed via short sequences of displaced indirections. | |
1612 // The value of thr_self is available as %g7(36). | |
1613 // The value of thr_getspecific(k) is stored in %g7(12)(4)(k*4-4), | |
1614 // assuming that the current thread already has a value bound to k. | |
1615 // It may be worth experimenting with such access patterns, | |
1616 // and later having the parameters formally exported from a Solaris | |
1617 // interface. I think, however, that it will be faster to | |
1618 // maintain the invariant that %g2 always contains the | |
1619 // JavaThread in Java code, and have stubs simply | |
1620 // treat %g2 as a caller-save register, preserving it in a %lN. | |
1621 thread_key_t tk; | |
1622 if (thr_keycreate( &tk, NULL ) ) | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
1623 fatal(err_msg("os::allocate_thread_local_storage: thr_keycreate failed " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
1624 "(%s)", strerror(errno))); |
0 | 1625 return int(tk); |
1626 } | |
1627 | |
1628 void os::free_thread_local_storage(int index) { | |
1629 // %%% don't think we need anything here | |
1630 // if ( pthread_key_delete((pthread_key_t) tk) ) | |
1631 // fatal("os::free_thread_local_storage: pthread_key_delete failed"); | |
1632 } | |
1633 | |
1634 #define SMALLINT 32 // libthread allocate for tsd_common is a version specific | |
1635 // small number - point is NO swap space available | |
1636 void os::thread_local_storage_at_put(int index, void* value) { | |
1637 // %%% this is used only in threadLocalStorage.cpp | |
1638 if (thr_setspecific((thread_key_t)index, value)) { | |
1639 if (errno == ENOMEM) { | |
1640 vm_exit_out_of_memory(SMALLINT, "thr_setspecific: out of swap space"); | |
1641 } else { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
1642 fatal(err_msg("os::thread_local_storage_at_put: thr_setspecific failed " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
1643 "(%s)", strerror(errno))); |
0 | 1644 } |
1645 } else { | |
1646 ThreadLocalStorage::set_thread_in_slot ((Thread *) value) ; | |
1647 } | |
1648 } | |
1649 | |
1650 // This function could be called before TLS is initialized, for example, when | |
1651 // VM receives an async signal or when VM causes a fatal error during | |
1652 // initialization. Return NULL if thr_getspecific() fails. | |
1653 void* os::thread_local_storage_at(int index) { | |
1654 // %%% this is used only in threadLocalStorage.cpp | |
1655 void* r = NULL; | |
1656 return thr_getspecific((thread_key_t)index, &r) != 0 ? NULL : r; | |
1657 } | |
1658 | |
1659 | |
1660 const int NANOSECS_PER_MILLISECS = 1000000; | |
1661 // gethrtime can move backwards if read from one cpu and then a different cpu | |
1662 // getTimeNanos is guaranteed to not move backward on Solaris | |
1663 // local spinloop created as faster for a CAS on an int than | |
1664 // a CAS on a 64bit jlong. Also Atomic::cmpxchg for jlong is not | |
1665 // supported on sparc v8 or pre supports_cx8 intel boxes. | |
1666 // oldgetTimeNanos for systems which do not support CAS on 64bit jlong | |
1667 // i.e. sparc v8 and pre supports_cx8 (i486) intel boxes | |
1668 inline hrtime_t oldgetTimeNanos() { | |
1669 int gotlock = LOCK_INVALID; | |
1670 hrtime_t newtime = gethrtime(); | |
1671 | |
1672 for (;;) { | |
1673 // grab lock for max_hrtime | |
1674 int curlock = max_hrtime_lock; | |
1675 if (curlock & LOCK_BUSY) continue; | |
1676 if (gotlock = Atomic::cmpxchg(LOCK_BUSY, &max_hrtime_lock, LOCK_FREE) != LOCK_FREE) continue; | |
1677 if (newtime > max_hrtime) { | |
1678 max_hrtime = newtime; | |
1679 } else { | |
1680 newtime = max_hrtime; | |
1681 } | |
1682 // release lock | |
1683 max_hrtime_lock = LOCK_FREE; | |
1684 return newtime; | |
1685 } | |
1686 } | |
1687 // gethrtime can move backwards if read from one cpu and then a different cpu | |
1688 // getTimeNanos is guaranteed to not move backward on Solaris | |
1689 inline hrtime_t getTimeNanos() { | |
1690 if (VM_Version::supports_cx8()) { | |
499 | 1691 const hrtime_t now = gethrtime(); |
894
665be97e8704
6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
691
diff
changeset
|
1692 // Use atomic long load since 32-bit x86 uses 2 registers to keep long. |
665be97e8704
6863420: os::javaTimeNanos() go backward on Solaris x86
kvn
parents:
691
diff
changeset
|
1693 const hrtime_t prev = Atomic::load((volatile jlong*)&max_hrtime); |
499 | 1694 if (now <= prev) return prev; // same or retrograde time; |
1695 const hrtime_t obsv = Atomic::cmpxchg(now, (volatile jlong*)&max_hrtime, prev); | |
1696 assert(obsv >= prev, "invariant"); // Monotonicity | |
1697 // If the CAS succeeded then we're done and return "now". | |
1698 // If the CAS failed and the observed value "obs" is >= now then | |
1699 // we should return "obs". If the CAS failed and now > obs > prv then | |
1700 // some other thread raced this thread and installed a new value, in which case | |
1701 // we could either (a) retry the entire operation, (b) retry trying to install now | |
1702 // or (c) just return obs. We use (c). No loop is required although in some cases | |
1703 // we might discard a higher "now" value in deference to a slightly lower but freshly | |
1704 // installed obs value. That's entirely benign -- it admits no new orderings compared | |
1705 // to (a) or (b) -- and greatly reduces coherence traffic. | |
1706 // We might also condition (c) on the magnitude of the delta between obs and now. | |
1707 // Avoiding excessive CAS operations to hot RW locations is critical. | |
1708 // See http://blogs.sun.com/dave/entry/cas_and_cache_trivia_invalidate | |
1709 return (prev == obsv) ? now : obsv ; | |
0 | 1710 } else { |
1711 return oldgetTimeNanos(); | |
1712 } | |
1713 } | |
1714 | |
1715 // Time since start-up in seconds to a fine granularity. | |
1716 // Used by VMSelfDestructTimer and the MemProfiler. | |
1717 double os::elapsedTime() { | |
1718 return (double)(getTimeNanos() - first_hrtime) / (double)hrtime_hz; | |
1719 } | |
1720 | |
1721 jlong os::elapsed_counter() { | |
1722 return (jlong)(getTimeNanos() - first_hrtime); | |
1723 } | |
1724 | |
1725 jlong os::elapsed_frequency() { | |
1726 return hrtime_hz; | |
1727 } | |
1728 | |
1729 // Return the real, user, and system times in seconds from an | |
1730 // arbitrary fixed point in the past. | |
1731 bool os::getTimesSecs(double* process_real_time, | |
1732 double* process_user_time, | |
1733 double* process_system_time) { | |
1734 struct tms ticks; | |
1735 clock_t real_ticks = times(&ticks); | |
1736 | |
1737 if (real_ticks == (clock_t) (-1)) { | |
1738 return false; | |
1739 } else { | |
1740 double ticks_per_second = (double) clock_tics_per_sec; | |
1741 *process_user_time = ((double) ticks.tms_utime) / ticks_per_second; | |
1742 *process_system_time = ((double) ticks.tms_stime) / ticks_per_second; | |
1743 // For consistency return the real time from getTimeNanos() | |
1744 // converted to seconds. | |
1745 *process_real_time = ((double) getTimeNanos()) / ((double) NANOUNITS); | |
1746 | |
1747 return true; | |
1748 } | |
1749 } | |
1750 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1751 bool os::supports_vtime() { return true; } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1752 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1753 bool os::enable_vtime() { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1754 int fd = open("/proc/self/ctl", O_WRONLY); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1755 if (fd == -1) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1756 return false; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1757 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1758 long cmd[] = { PCSET, PR_MSACCT }; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1759 int res = write(fd, cmd, sizeof(long) * 2); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1760 close(fd); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1761 if (res != sizeof(long) * 2) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1762 return false; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1763 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1764 return true; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1765 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1766 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1767 bool os::vtime_enabled() { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1768 int fd = open("/proc/self/status", O_RDONLY); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1769 if (fd == -1) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1770 return false; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1771 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1772 pstatus_t status; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1773 int res = read(fd, (void*) &status, sizeof(pstatus_t)); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1774 close(fd); |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1775 if (res != sizeof(pstatus_t)) |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1776 return false; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1777 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1778 return status.pr_flags & PR_MSACCT; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1779 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1780 |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1781 double os::elapsedVTime() { |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1782 return (double)gethrvtime() / (double)hrtime_hz; |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1783 } |
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
1784 |
0 | 1785 // Used internally for comparisons only |
1786 // getTimeMillis guaranteed to not move backwards on Solaris | |
1787 jlong getTimeMillis() { | |
1788 jlong nanotime = getTimeNanos(); | |
1789 return (jlong)(nanotime / NANOSECS_PER_MILLISECS); | |
1790 } | |
1791 | |
61 | 1792 // Must return millis since Jan 1 1970 for JVM_CurrentTimeMillis |
1793 jlong os::javaTimeMillis() { | |
0 | 1794 timeval t; |
1795 if (gettimeofday( &t, NULL) == -1) | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
1796 fatal(err_msg("os::javaTimeMillis: gettimeofday (%s)", strerror(errno))); |
0 | 1797 return jlong(t.tv_sec) * 1000 + jlong(t.tv_usec) / 1000; |
1798 } | |
1799 | |
1800 jlong os::javaTimeNanos() { | |
1801 return (jlong)getTimeNanos(); | |
1802 } | |
1803 | |
1804 void os::javaTimeNanos_info(jvmtiTimerInfo *info_ptr) { | |
1805 info_ptr->max_value = ALL_64_BITS; // gethrtime() uses all 64 bits | |
1806 info_ptr->may_skip_backward = false; // not subject to resetting or drifting | |
1807 info_ptr->may_skip_forward = false; // not subject to resetting or drifting | |
1808 info_ptr->kind = JVMTI_TIMER_ELAPSED; // elapsed not CPU time | |
1809 } | |
1810 | |
1811 char * os::local_time_string(char *buf, size_t buflen) { | |
1812 struct tm t; | |
1813 time_t long_time; | |
1814 time(&long_time); | |
1815 localtime_r(&long_time, &t); | |
1816 jio_snprintf(buf, buflen, "%d-%02d-%02d %02d:%02d:%02d", | |
1817 t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, | |
1818 t.tm_hour, t.tm_min, t.tm_sec); | |
1819 return buf; | |
1820 } | |
1821 | |
1822 // Note: os::shutdown() might be called very early during initialization, or | |
1823 // called from signal handler. Before adding something to os::shutdown(), make | |
1824 // sure it is async-safe and can handle partially initialized VM. | |
1825 void os::shutdown() { | |
1826 | |
1827 // allow PerfMemory to attempt cleanup of any persistent resources | |
1828 perfMemory_exit(); | |
1829 | |
1830 // needs to remove object in file system | |
1831 AttachListener::abort(); | |
1832 | |
1833 // flush buffered output, finish log files | |
1834 ostream_abort(); | |
1835 | |
1836 // Check for abort hook | |
1837 abort_hook_t abort_hook = Arguments::abort_hook(); | |
1838 if (abort_hook != NULL) { | |
1839 abort_hook(); | |
1840 } | |
1841 } | |
1842 | |
1843 // Note: os::abort() might be called very early during initialization, or | |
1844 // called from signal handler. Before adding something to os::abort(), make | |
1845 // sure it is async-safe and can handle partially initialized VM. | |
1846 void os::abort(bool dump_core) { | |
1847 os::shutdown(); | |
1848 if (dump_core) { | |
1849 #ifndef PRODUCT | |
1850 fdStream out(defaultStream::output_fd()); | |
1851 out.print_raw("Current thread is "); | |
1852 char buf[16]; | |
1853 jio_snprintf(buf, sizeof(buf), UINTX_FORMAT, os::current_thread_id()); | |
1854 out.print_raw_cr(buf); | |
1855 out.print_raw_cr("Dumping core ..."); | |
1856 #endif | |
1857 ::abort(); // dump core (for debugging) | |
1858 } | |
1859 | |
1860 ::exit(1); | |
1861 } | |
1862 | |
1863 // Die immediately, no exit hook, no abort hook, no cleanup. | |
1864 void os::die() { | |
1865 _exit(-1); | |
1866 } | |
1867 | |
1868 // unused | |
1869 void os::set_error_file(const char *logfile) {} | |
1870 | |
1871 // DLL functions | |
1872 | |
1873 const char* os::dll_file_extension() { return ".so"; } | |
1874 | |
1353
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1875 const char* os::get_temp_directory() { |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1876 const char *prop = Arguments::get_property("java.io.tmpdir"); |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1877 return prop == NULL ? "/tmp" : prop; |
a2ea687fdc7c
6938627: Make temporary directory use property java.io.tmpdir when specified
coleenp
parents:
1320
diff
changeset
|
1878 } |
0 | 1879 |
691 | 1880 static bool file_exists(const char* filename) { |
1881 struct stat statbuf; | |
1882 if (filename == NULL || strlen(filename) == 0) { | |
1883 return false; | |
1884 } | |
1885 return os::stat(filename, &statbuf) == 0; | |
1886 } | |
1887 | |
1888 void os::dll_build_name(char* buffer, size_t buflen, | |
1889 const char* pname, const char* fname) { | |
1890 // Copied from libhpi | |
242 | 1891 const size_t pnamelen = pname ? strlen(pname) : 0; |
1892 | |
691 | 1893 // Quietly truncate on buffer overflow. Should be an error. |
242 | 1894 if (pnamelen + strlen(fname) + 10 > (size_t) buflen) { |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1895 *buffer = '\0'; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
1896 return; |
242 | 1897 } |
1898 | |
1899 if (pnamelen == 0) { | |
691 | 1900 snprintf(buffer, buflen, "lib%s.so", fname); |
1901 } else if (strchr(pname, *os::path_separator()) != NULL) { | |
1902 int n; | |
1903 char** pelements = split_path(pname, &n); | |
1904 for (int i = 0 ; i < n ; i++) { | |
1905 // really shouldn't be NULL but what the heck, check can't hurt | |
1906 if (pelements[i] == NULL || strlen(pelements[i]) == 0) { | |
1907 continue; // skip the empty path values | |
1908 } | |
1909 snprintf(buffer, buflen, "%s/lib%s.so", pelements[i], fname); | |
1910 if (file_exists(buffer)) { | |
1911 break; | |
1912 } | |
1913 } | |
1914 // release the storage | |
1915 for (int i = 0 ; i < n ; i++) { | |
1916 if (pelements[i] != NULL) { | |
1917 FREE_C_HEAP_ARRAY(char, pelements[i]); | |
1918 } | |
1919 } | |
1920 if (pelements != NULL) { | |
1921 FREE_C_HEAP_ARRAY(char*, pelements); | |
1922 } | |
242 | 1923 } else { |
691 | 1924 snprintf(buffer, buflen, "%s/lib%s.so", pname, fname); |
242 | 1925 } |
1926 } | |
1927 | |
0 | 1928 const char* os::get_current_directory(char *buf, int buflen) { |
1929 return getcwd(buf, buflen); | |
1930 } | |
1931 | |
1932 // check if addr is inside libjvm[_g].so | |
1933 bool os::address_is_in_vm(address addr) { | |
1934 static address libjvm_base_addr; | |
1935 Dl_info dlinfo; | |
1936 | |
1937 if (libjvm_base_addr == NULL) { | |
1938 dladdr(CAST_FROM_FN_PTR(void *, os::address_is_in_vm), &dlinfo); | |
1939 libjvm_base_addr = (address)dlinfo.dli_fbase; | |
1940 assert(libjvm_base_addr !=NULL, "Cannot obtain base address for libjvm"); | |
1941 } | |
1942 | |
1943 if (dladdr((void *)addr, &dlinfo)) { | |
1944 if (libjvm_base_addr == (address)dlinfo.dli_fbase) return true; | |
1945 } | |
1946 | |
1947 return false; | |
1948 } | |
1949 | |
1950 typedef int (*dladdr1_func_type) (void *, Dl_info *, void **, int); | |
1951 static dladdr1_func_type dladdr1_func = NULL; | |
1952 | |
1953 bool os::dll_address_to_function_name(address addr, char *buf, | |
1954 int buflen, int * offset) { | |
1955 Dl_info dlinfo; | |
1956 | |
1957 // dladdr1_func was initialized in os::init() | |
1958 if (dladdr1_func){ | |
1959 // yes, we have dladdr1 | |
1960 | |
1961 // Support for dladdr1 is checked at runtime; it may be | |
1962 // available even if the vm is built on a machine that does | |
1963 // not have dladdr1 support. Make sure there is a value for | |
1964 // RTLD_DL_SYMENT. | |
1965 #ifndef RTLD_DL_SYMENT | |
1966 #define RTLD_DL_SYMENT 1 | |
1967 #endif | |
1968 Sym * info; | |
1969 if (dladdr1_func((void *)addr, &dlinfo, (void **)&info, | |
1970 RTLD_DL_SYMENT)) { | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1971 if ((char *)dlinfo.dli_saddr + info->st_size > (char *)addr) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1972 if (buf != NULL) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1973 if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1974 jio_snprintf(buf, buflen, "%s", dlinfo.dli_sname); |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1975 } |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1976 if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1977 return true; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1978 } |
0 | 1979 } |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1980 if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1981 if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase), |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1982 dlinfo.dli_fname, buf, buflen, offset) == Decoder::no_error) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1983 return true; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1984 } |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1985 } |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1986 if (buf != NULL) buf[0] = '\0'; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1987 if (offset != NULL) *offset = -1; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1988 return false; |
0 | 1989 } else { |
1990 // no, only dladdr is available | |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1991 if (dladdr((void *)addr, &dlinfo)) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1992 if (buf != NULL) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1993 if (!Decoder::demangle(dlinfo.dli_sname, buf, buflen)) |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1994 jio_snprintf(buf, buflen, dlinfo.dli_sname); |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1995 } |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1996 if (offset != NULL) *offset = addr - (address)dlinfo.dli_saddr; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1997 return true; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1998 } else if (dlinfo.dli_fname != NULL && dlinfo.dli_fbase != 0) { |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
1999 if (Decoder::decode((address)(addr - (address)dlinfo.dli_fbase), |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
2000 dlinfo.dli_fname, buf, buflen, offset) == Decoder::no_error) { |
0 | 2001 return true; |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
2002 } |
0 | 2003 } |
2022
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
2004 if (buf != NULL) buf[0] = '\0'; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
2005 if (offset != NULL) *offset = -1; |
2d4762ec74af
7003748: Decode C stack frames when symbols are presented (PhoneHome project)
zgu
parents:
1972
diff
changeset
|
2006 return false; |
0 | 2007 } |
2008 } | |
2009 | |
2010 bool os::dll_address_to_library_name(address addr, char* buf, | |
2011 int buflen, int* offset) { | |
2012 Dl_info dlinfo; | |
2013 | |
2014 if (dladdr((void*)addr, &dlinfo)){ | |
2015 if (buf) jio_snprintf(buf, buflen, "%s", dlinfo.dli_fname); | |
2016 if (offset) *offset = addr - (address)dlinfo.dli_fbase; | |
2017 return true; | |
2018 } else { | |
2019 if (buf) buf[0] = '\0'; | |
2020 if (offset) *offset = -1; | |
2021 return false; | |
2022 } | |
2023 } | |
2024 | |
2025 // Prints the names and full paths of all opened dynamic libraries | |
2026 // for current process | |
2027 void os::print_dll_info(outputStream * st) { | |
2028 Dl_info dli; | |
2029 void *handle; | |
2030 Link_map *map; | |
2031 Link_map *p; | |
2032 | |
2033 st->print_cr("Dynamic libraries:"); st->flush(); | |
2034 | |
2035 if (!dladdr(CAST_FROM_FN_PTR(void *, os::print_dll_info), &dli)) { | |
2036 st->print_cr("Error: Cannot print dynamic libraries."); | |
2037 return; | |
2038 } | |
2039 handle = dlopen(dli.dli_fname, RTLD_LAZY); | |
2040 if (handle == NULL) { | |
2041 st->print_cr("Error: Cannot print dynamic libraries."); | |
2042 return; | |
2043 } | |
2044 dlinfo(handle, RTLD_DI_LINKMAP, &map); | |
2045 if (map == NULL) { | |
2046 st->print_cr("Error: Cannot print dynamic libraries."); | |
2047 return; | |
2048 } | |
2049 | |
2050 while (map->l_prev != NULL) | |
2051 map = map->l_prev; | |
2052 | |
2053 while (map != NULL) { | |
2054 st->print_cr(PTR_FORMAT " \t%s", map->l_addr, map->l_name); | |
2055 map = map->l_next; | |
2056 } | |
2057 | |
2058 dlclose(handle); | |
2059 } | |
2060 | |
2061 // Loads .dll/.so and | |
2062 // in case of error it checks if .dll/.so was built for the | |
2063 // same architecture as Hotspot is running on | |
2064 | |
2065 void * os::dll_load(const char *filename, char *ebuf, int ebuflen) | |
2066 { | |
2067 void * result= ::dlopen(filename, RTLD_LAZY); | |
2068 if (result != NULL) { | |
2069 // Successful loading | |
2070 return result; | |
2071 } | |
2072 | |
2073 Elf32_Ehdr elf_head; | |
2074 | |
2075 // Read system error message into ebuf | |
2076 // It may or may not be overwritten below | |
2077 ::strncpy(ebuf, ::dlerror(), ebuflen-1); | |
2078 ebuf[ebuflen-1]='\0'; | |
2079 int diag_msg_max_length=ebuflen-strlen(ebuf); | |
2080 char* diag_msg_buf=ebuf+strlen(ebuf); | |
2081 | |
2082 if (diag_msg_max_length==0) { | |
2083 // No more space in ebuf for additional diagnostics message | |
2084 return NULL; | |
2085 } | |
2086 | |
2087 | |
2088 int file_descriptor= ::open(filename, O_RDONLY | O_NONBLOCK); | |
2089 | |
2090 if (file_descriptor < 0) { | |
2091 // Can't open library, report dlerror() message | |
2092 return NULL; | |
2093 } | |
2094 | |
2095 bool failed_to_read_elf_head= | |
2096 (sizeof(elf_head)!= | |
2097 (::read(file_descriptor, &elf_head,sizeof(elf_head)))) ; | |
2098 | |
2099 ::close(file_descriptor); | |
2100 if (failed_to_read_elf_head) { | |
2101 // file i/o error - report dlerror() msg | |
2102 return NULL; | |
2103 } | |
2104 | |
2105 typedef struct { | |
2106 Elf32_Half code; // Actual value as defined in elf.h | |
2107 Elf32_Half compat_class; // Compatibility of archs at VM's sense | |
2108 char elf_class; // 32 or 64 bit | |
2109 char endianess; // MSB or LSB | |
2110 char* name; // String representation | |
2111 } arch_t; | |
2112 | |
2113 static const arch_t arch_array[]={ | |
2114 {EM_386, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, | |
2115 {EM_486, EM_386, ELFCLASS32, ELFDATA2LSB, (char*)"IA 32"}, | |
2116 {EM_IA_64, EM_IA_64, ELFCLASS64, ELFDATA2LSB, (char*)"IA 64"}, | |
2117 {EM_X86_64, EM_X86_64, ELFCLASS64, ELFDATA2LSB, (char*)"AMD 64"}, | |
2118 {EM_SPARC, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"}, | |
2119 {EM_SPARC32PLUS, EM_SPARC, ELFCLASS32, ELFDATA2MSB, (char*)"Sparc 32"}, | |
2120 {EM_SPARCV9, EM_SPARCV9, ELFCLASS64, ELFDATA2MSB, (char*)"Sparc v9 64"}, | |
2121 {EM_PPC, EM_PPC, ELFCLASS32, ELFDATA2MSB, (char*)"Power PC 32"}, | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
2122 {EM_PPC64, EM_PPC64, ELFCLASS64, ELFDATA2MSB, (char*)"Power PC 64"}, |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
2123 {EM_ARM, EM_ARM, ELFCLASS32, ELFDATA2LSB, (char*)"ARM 32"} |
0 | 2124 }; |
2125 | |
2126 #if (defined IA32) | |
2127 static Elf32_Half running_arch_code=EM_386; | |
2128 #elif (defined AMD64) | |
2129 static Elf32_Half running_arch_code=EM_X86_64; | |
2130 #elif (defined IA64) | |
2131 static Elf32_Half running_arch_code=EM_IA_64; | |
2132 #elif (defined __sparc) && (defined _LP64) | |
2133 static Elf32_Half running_arch_code=EM_SPARCV9; | |
2134 #elif (defined __sparc) && (!defined _LP64) | |
2135 static Elf32_Half running_arch_code=EM_SPARC; | |
2136 #elif (defined __powerpc64__) | |
2137 static Elf32_Half running_arch_code=EM_PPC64; | |
2138 #elif (defined __powerpc__) | |
2139 static Elf32_Half running_arch_code=EM_PPC; | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
2140 #elif (defined ARM) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
2141 static Elf32_Half running_arch_code=EM_ARM; |
0 | 2142 #else |
2143 #error Method os::dll_load requires that one of following is defined:\ | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
2144 IA32, AMD64, IA64, __sparc, __powerpc__, ARM, ARM |
0 | 2145 #endif |
2146 | |
2147 // Identify compatability class for VM's architecture and library's architecture | |
2148 // Obtain string descriptions for architectures | |
2149 | |
2150 arch_t lib_arch={elf_head.e_machine,0,elf_head.e_ident[EI_CLASS], elf_head.e_ident[EI_DATA], NULL}; | |
2151 int running_arch_index=-1; | |
2152 | |
2153 for (unsigned int i=0 ; i < ARRAY_SIZE(arch_array) ; i++ ) { | |
2154 if (running_arch_code == arch_array[i].code) { | |
2155 running_arch_index = i; | |
2156 } | |
2157 if (lib_arch.code == arch_array[i].code) { | |
2158 lib_arch.compat_class = arch_array[i].compat_class; | |
2159 lib_arch.name = arch_array[i].name; | |
2160 } | |
2161 } | |
2162 | |
2163 assert(running_arch_index != -1, | |
2164 "Didn't find running architecture code (running_arch_code) in arch_array"); | |
2165 if (running_arch_index == -1) { | |
2166 // Even though running architecture detection failed | |
2167 // we may still continue with reporting dlerror() message | |
2168 return NULL; | |
2169 } | |
2170 | |
2171 if (lib_arch.endianess != arch_array[running_arch_index].endianess) { | |
2172 ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: endianness mismatch)"); | |
2173 return NULL; | |
2174 } | |
2175 | |
2176 if (lib_arch.elf_class != arch_array[running_arch_index].elf_class) { | |
2177 ::snprintf(diag_msg_buf, diag_msg_max_length-1," (Possible cause: architecture word width mismatch)"); | |
2178 return NULL; | |
2179 } | |
2180 | |
2181 if (lib_arch.compat_class != arch_array[running_arch_index].compat_class) { | |
2182 if ( lib_arch.name!=NULL ) { | |
2183 ::snprintf(diag_msg_buf, diag_msg_max_length-1, | |
2184 " (Possible cause: can't load %s-bit .so on a %s-bit platform)", | |
2185 lib_arch.name, arch_array[running_arch_index].name); | |
2186 } else { | |
2187 ::snprintf(diag_msg_buf, diag_msg_max_length-1, | |
2188 " (Possible cause: can't load this .so (machine code=0x%x) on a %s-bit platform)", | |
2189 lib_arch.code, | |
2190 arch_array[running_arch_index].name); | |
2191 } | |
2192 } | |
2193 | |
2194 return NULL; | |
2195 } | |
2196 | |
242 | 2197 void* os::dll_lookup(void* handle, const char* name) { |
2198 return dlsym(handle, name); | |
2199 } | |
0 | 2200 |
2201 | |
2202 bool _print_ascii_file(const char* filename, outputStream* st) { | |
2203 int fd = open(filename, O_RDONLY); | |
2204 if (fd == -1) { | |
2205 return false; | |
2206 } | |
2207 | |
2208 char buf[32]; | |
2209 int bytes; | |
2210 while ((bytes = read(fd, buf, sizeof(buf))) > 0) { | |
2211 st->print_raw(buf, bytes); | |
2212 } | |
2213 | |
2214 close(fd); | |
2215 | |
2216 return true; | |
2217 } | |
2218 | |
2219 void os::print_os_info(outputStream* st) { | |
2220 st->print("OS:"); | |
2221 | |
2222 if (!_print_ascii_file("/etc/release", st)) { | |
2223 st->print("Solaris"); | |
2224 } | |
2225 st->cr(); | |
2226 | |
2227 // kernel | |
2228 st->print("uname:"); | |
2229 struct utsname name; | |
2230 uname(&name); | |
2231 st->print(name.sysname); st->print(" "); | |
2232 st->print(name.release); st->print(" "); | |
2233 st->print(name.version); st->print(" "); | |
2234 st->print(name.machine); | |
2235 | |
2236 // libthread | |
2237 if (os::Solaris::T2_libthread()) st->print(" (T2 libthread)"); | |
2238 else st->print(" (T1 libthread)"); | |
2239 st->cr(); | |
2240 | |
2241 // rlimit | |
2242 st->print("rlimit:"); | |
2243 struct rlimit rlim; | |
2244 | |
2245 st->print(" STACK "); | |
2246 getrlimit(RLIMIT_STACK, &rlim); | |
2247 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); | |
2248 else st->print("%uk", rlim.rlim_cur >> 10); | |
2249 | |
2250 st->print(", CORE "); | |
2251 getrlimit(RLIMIT_CORE, &rlim); | |
2252 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); | |
2253 else st->print("%uk", rlim.rlim_cur >> 10); | |
2254 | |
2255 st->print(", NOFILE "); | |
2256 getrlimit(RLIMIT_NOFILE, &rlim); | |
2257 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); | |
2258 else st->print("%d", rlim.rlim_cur); | |
2259 | |
2260 st->print(", AS "); | |
2261 getrlimit(RLIMIT_AS, &rlim); | |
2262 if (rlim.rlim_cur == RLIM_INFINITY) st->print("infinity"); | |
2263 else st->print("%uk", rlim.rlim_cur >> 10); | |
2264 st->cr(); | |
2265 | |
2266 // load average | |
2267 st->print("load average:"); | |
2268 double loadavg[3]; | |
2269 os::loadavg(loadavg, 3); | |
2270 st->print("%0.02f %0.02f %0.02f", loadavg[0], loadavg[1], loadavg[2]); | |
2271 st->cr(); | |
2272 } | |
2273 | |
2274 | |
2275 static bool check_addr0(outputStream* st) { | |
2276 jboolean status = false; | |
2277 int fd = open("/proc/self/map",O_RDONLY); | |
2278 if (fd >= 0) { | |
2279 prmap_t p; | |
2280 while(read(fd, &p, sizeof(p)) > 0) { | |
2281 if (p.pr_vaddr == 0x0) { | |
2282 st->print("Warning: Address: 0x%x, Size: %dK, ",p.pr_vaddr, p.pr_size/1024, p.pr_mapname); | |
2283 st->print("Mapped file: %s, ", p.pr_mapname[0] == '\0' ? "None" : p.pr_mapname); | |
2284 st->print("Access:"); | |
2285 st->print("%s",(p.pr_mflags & MA_READ) ? "r" : "-"); | |
2286 st->print("%s",(p.pr_mflags & MA_WRITE) ? "w" : "-"); | |
2287 st->print("%s",(p.pr_mflags & MA_EXEC) ? "x" : "-"); | |
2288 st->cr(); | |
2289 status = true; | |
2290 } | |
2291 close(fd); | |
2292 } | |
2293 } | |
2294 return status; | |
2295 } | |
2296 | |
2297 void os::print_memory_info(outputStream* st) { | |
2298 st->print("Memory:"); | |
2299 st->print(" %dk page", os::vm_page_size()>>10); | |
2300 st->print(", physical " UINT64_FORMAT "k", os::physical_memory()>>10); | |
2301 st->print("(" UINT64_FORMAT "k free)", os::available_memory() >> 10); | |
2302 st->cr(); | |
2303 (void) check_addr0(st); | |
2304 } | |
2305 | |
2306 // Taken from /usr/include/sys/machsig.h Supposed to be architecture specific | |
2307 // but they're the same for all the solaris architectures that we support. | |
2308 const char *ill_names[] = { "ILL0", "ILL_ILLOPC", "ILL_ILLOPN", "ILL_ILLADR", | |
2309 "ILL_ILLTRP", "ILL_PRVOPC", "ILL_PRVREG", | |
2310 "ILL_COPROC", "ILL_BADSTK" }; | |
2311 | |
2312 const char *fpe_names[] = { "FPE0", "FPE_INTDIV", "FPE_INTOVF", "FPE_FLTDIV", | |
2313 "FPE_FLTOVF", "FPE_FLTUND", "FPE_FLTRES", | |
2314 "FPE_FLTINV", "FPE_FLTSUB" }; | |
2315 | |
2316 const char *segv_names[] = { "SEGV0", "SEGV_MAPERR", "SEGV_ACCERR" }; | |
2317 | |
2318 const char *bus_names[] = { "BUS0", "BUS_ADRALN", "BUS_ADRERR", "BUS_OBJERR" }; | |
2319 | |
2320 void os::print_siginfo(outputStream* st, void* siginfo) { | |
2321 st->print("siginfo:"); | |
2322 | |
2323 const int buflen = 100; | |
2324 char buf[buflen]; | |
2325 siginfo_t *si = (siginfo_t*)siginfo; | |
2326 st->print("si_signo=%s: ", os::exception_name(si->si_signo, buf, buflen)); | |
2327 char *err = strerror(si->si_errno); | |
2328 if (si->si_errno != 0 && err != NULL) { | |
2329 st->print("si_errno=%s", err); | |
2330 } else { | |
2331 st->print("si_errno=%d", si->si_errno); | |
2332 } | |
2333 const int c = si->si_code; | |
2334 assert(c > 0, "unexpected si_code"); | |
2335 switch (si->si_signo) { | |
2336 case SIGILL: | |
2337 st->print(", si_code=%d (%s)", c, c > 8 ? "" : ill_names[c]); | |
2338 st->print(", si_addr=" PTR_FORMAT, si->si_addr); | |
2339 break; | |
2340 case SIGFPE: | |
2341 st->print(", si_code=%d (%s)", c, c > 9 ? "" : fpe_names[c]); | |
2342 st->print(", si_addr=" PTR_FORMAT, si->si_addr); | |
2343 break; | |
2344 case SIGSEGV: | |
2345 st->print(", si_code=%d (%s)", c, c > 2 ? "" : segv_names[c]); | |
2346 st->print(", si_addr=" PTR_FORMAT, si->si_addr); | |
2347 break; | |
2348 case SIGBUS: | |
2349 st->print(", si_code=%d (%s)", c, c > 3 ? "" : bus_names[c]); | |
2350 st->print(", si_addr=" PTR_FORMAT, si->si_addr); | |
2351 break; | |
2352 default: | |
2353 st->print(", si_code=%d", si->si_code); | |
2354 // no si_addr | |
2355 } | |
2356 | |
2357 if ((si->si_signo == SIGBUS || si->si_signo == SIGSEGV) && | |
2358 UseSharedSpaces) { | |
2359 FileMapInfo* mapinfo = FileMapInfo::current_info(); | |
2360 if (mapinfo->is_in_shared_space(si->si_addr)) { | |
2361 st->print("\n\nError accessing class data sharing archive." \ | |
2362 " Mapped file inaccessible during execution, " \ | |
2363 " possible disk/network problem."); | |
2364 } | |
2365 } | |
2366 st->cr(); | |
2367 } | |
2368 | |
2369 // Moved from whole group, because we need them here for diagnostic | |
2370 // prints. | |
2371 #define OLDMAXSIGNUM 32 | |
2372 static int Maxsignum = 0; | |
2373 static int *ourSigFlags = NULL; | |
2374 | |
2375 extern "C" void sigINTRHandler(int, siginfo_t*, void*); | |
2376 | |
2377 int os::Solaris::get_our_sigflags(int sig) { | |
2378 assert(ourSigFlags!=NULL, "signal data structure not initialized"); | |
2379 assert(sig > 0 && sig < Maxsignum, "vm signal out of expected range"); | |
2380 return ourSigFlags[sig]; | |
2381 } | |
2382 | |
2383 void os::Solaris::set_our_sigflags(int sig, int flags) { | |
2384 assert(ourSigFlags!=NULL, "signal data structure not initialized"); | |
2385 assert(sig > 0 && sig < Maxsignum, "vm signal out of expected range"); | |
2386 ourSigFlags[sig] = flags; | |
2387 } | |
2388 | |
2389 | |
2390 static const char* get_signal_handler_name(address handler, | |
2391 char* buf, int buflen) { | |
2392 int offset; | |
2393 bool found = os::dll_address_to_library_name(handler, buf, buflen, &offset); | |
2394 if (found) { | |
2395 // skip directory names | |
2396 const char *p1, *p2; | |
2397 p1 = buf; | |
2398 size_t len = strlen(os::file_separator()); | |
2399 while ((p2 = strstr(p1, os::file_separator())) != NULL) p1 = p2 + len; | |
2400 jio_snprintf(buf, buflen, "%s+0x%x", p1, offset); | |
2401 } else { | |
2402 jio_snprintf(buf, buflen, PTR_FORMAT, handler); | |
2403 } | |
2404 return buf; | |
2405 } | |
2406 | |
2407 static void print_signal_handler(outputStream* st, int sig, | |
2408 char* buf, size_t buflen) { | |
2409 struct sigaction sa; | |
2410 | |
2411 sigaction(sig, NULL, &sa); | |
2412 | |
2413 st->print("%s: ", os::exception_name(sig, buf, buflen)); | |
2414 | |
2415 address handler = (sa.sa_flags & SA_SIGINFO) | |
2416 ? CAST_FROM_FN_PTR(address, sa.sa_sigaction) | |
2417 : CAST_FROM_FN_PTR(address, sa.sa_handler); | |
2418 | |
2419 if (handler == CAST_FROM_FN_PTR(address, SIG_DFL)) { | |
2420 st->print("SIG_DFL"); | |
2421 } else if (handler == CAST_FROM_FN_PTR(address, SIG_IGN)) { | |
2422 st->print("SIG_IGN"); | |
2423 } else { | |
2424 st->print("[%s]", get_signal_handler_name(handler, buf, buflen)); | |
2425 } | |
2426 | |
2427 st->print(", sa_mask[0]=" PTR32_FORMAT, *(uint32_t*)&sa.sa_mask); | |
2428 | |
2429 address rh = VMError::get_resetted_sighandler(sig); | |
2430 // May be, handler was resetted by VMError? | |
2431 if(rh != NULL) { | |
2432 handler = rh; | |
2433 sa.sa_flags = VMError::get_resetted_sigflags(sig); | |
2434 } | |
2435 | |
2436 st->print(", sa_flags=" PTR32_FORMAT, sa.sa_flags); | |
2437 | |
2438 // Check: is it our handler? | |
2439 if(handler == CAST_FROM_FN_PTR(address, signalHandler) || | |
2440 handler == CAST_FROM_FN_PTR(address, sigINTRHandler)) { | |
2441 // It is our signal handler | |
2442 // check for flags | |
2443 if(sa.sa_flags != os::Solaris::get_our_sigflags(sig)) { | |
2444 st->print( | |
2445 ", flags was changed from " PTR32_FORMAT ", consider using jsig library", | |
2446 os::Solaris::get_our_sigflags(sig)); | |
2447 } | |
2448 } | |
2449 st->cr(); | |
2450 } | |
2451 | |
2452 void os::print_signal_handlers(outputStream* st, char* buf, size_t buflen) { | |
2453 st->print_cr("Signal Handlers:"); | |
2454 print_signal_handler(st, SIGSEGV, buf, buflen); | |
2455 print_signal_handler(st, SIGBUS , buf, buflen); | |
2456 print_signal_handler(st, SIGFPE , buf, buflen); | |
2457 print_signal_handler(st, SIGPIPE, buf, buflen); | |
2458 print_signal_handler(st, SIGXFSZ, buf, buflen); | |
2459 print_signal_handler(st, SIGILL , buf, buflen); | |
2460 print_signal_handler(st, INTERRUPT_SIGNAL, buf, buflen); | |
2461 print_signal_handler(st, ASYNC_SIGNAL, buf, buflen); | |
2462 print_signal_handler(st, BREAK_SIGNAL, buf, buflen); | |
2463 print_signal_handler(st, SHUTDOWN1_SIGNAL , buf, buflen); | |
2464 print_signal_handler(st, SHUTDOWN2_SIGNAL , buf, buflen); | |
2465 print_signal_handler(st, SHUTDOWN3_SIGNAL, buf, buflen); | |
2466 print_signal_handler(st, os::Solaris::SIGinterrupt(), buf, buflen); | |
2467 print_signal_handler(st, os::Solaris::SIGasync(), buf, buflen); | |
2468 } | |
2469 | |
2470 static char saved_jvm_path[MAXPATHLEN] = { 0 }; | |
2471 | |
2472 // Find the full path to the current module, libjvm.so or libjvm_g.so | |
2473 void os::jvm_path(char *buf, jint buflen) { | |
2474 // Error checking. | |
2475 if (buflen < MAXPATHLEN) { | |
2476 assert(false, "must use a large-enough buffer"); | |
2477 buf[0] = '\0'; | |
2478 return; | |
2479 } | |
2480 // Lazy resolve the path to current module. | |
2481 if (saved_jvm_path[0] != 0) { | |
2482 strcpy(buf, saved_jvm_path); | |
2483 return; | |
2484 } | |
2485 | |
2486 Dl_info dlinfo; | |
2487 int ret = dladdr(CAST_FROM_FN_PTR(void *, os::jvm_path), &dlinfo); | |
2488 assert(ret != 0, "cannot locate libjvm"); | |
2489 realpath((char *)dlinfo.dli_fname, buf); | |
2490 | |
2491 if (strcmp(Arguments::sun_java_launcher(), "gamma") == 0) { | |
2492 // Support for the gamma launcher. Typical value for buf is | |
2493 // "<JAVA_HOME>/jre/lib/<arch>/<vmtype>/libjvm.so". If "/jre/lib/" appears at | |
2494 // the right place in the string, then assume we are installed in a JDK and | |
2495 // we're done. Otherwise, check for a JAVA_HOME environment variable and fix | |
2496 // up the path so it looks like libjvm.so is installed there (append a | |
2497 // fake suffix hotspot/libjvm.so). | |
2498 const char *p = buf + strlen(buf) - 1; | |
2499 for (int count = 0; p > buf && count < 5; ++count) { | |
2500 for (--p; p > buf && *p != '/'; --p) | |
2501 /* empty */ ; | |
2502 } | |
2503 | |
2504 if (strncmp(p, "/jre/lib/", 9) != 0) { | |
2505 // Look for JAVA_HOME in the environment. | |
2506 char* java_home_var = ::getenv("JAVA_HOME"); | |
2507 if (java_home_var != NULL && java_home_var[0] != 0) { | |
2508 char cpu_arch[12]; | |
1642 | 2509 char* jrelib_p; |
2510 int len; | |
0 | 2511 sysinfo(SI_ARCHITECTURE, cpu_arch, sizeof(cpu_arch)); |
2512 #ifdef _LP64 | |
2513 // If we are on sparc running a 64-bit vm, look in jre/lib/sparcv9. | |
2514 if (strcmp(cpu_arch, "sparc") == 0) { | |
2515 strcat(cpu_arch, "v9"); | |
2516 } else if (strcmp(cpu_arch, "i386") == 0) { | |
2517 strcpy(cpu_arch, "amd64"); | |
2518 } | |
2519 #endif | |
2520 // Check the current module name "libjvm.so" or "libjvm_g.so". | |
2521 p = strrchr(buf, '/'); | |
2522 assert(strstr(p, "/libjvm") == p, "invalid library name"); | |
2523 p = strstr(p, "_g") ? "_g" : ""; | |
2524 | |
2525 realpath(java_home_var, buf); | |
1642 | 2526 // determine if this is a legacy image or modules image |
2527 // modules image doesn't have "jre" subdirectory | |
2528 len = strlen(buf); | |
2529 jrelib_p = buf + len; | |
2530 snprintf(jrelib_p, buflen-len, "/jre/lib/%s", cpu_arch); | |
2531 if (0 != access(buf, F_OK)) { | |
2532 snprintf(jrelib_p, buflen-len, "/lib/%s", cpu_arch); | |
2533 } | |
2534 | |
0 | 2535 if (0 == access(buf, F_OK)) { |
2536 // Use current module name "libjvm[_g].so" instead of | |
2537 // "libjvm"debug_only("_g")".so" since for fastdebug version | |
2538 // we should have "libjvm.so" but debug_only("_g") adds "_g"! | |
2539 // It is used when we are choosing the HPI library's name | |
2540 // "libhpi[_g].so" in hpi::initialize_get_interface(). | |
1642 | 2541 len = strlen(buf); |
2542 snprintf(buf + len, buflen-len, "/hotspot/libjvm%s.so", p); | |
0 | 2543 } else { |
2544 // Go back to path of .so | |
2545 realpath((char *)dlinfo.dli_fname, buf); | |
2546 } | |
2547 } | |
2548 } | |
2549 } | |
2550 | |
2551 strcpy(saved_jvm_path, buf); | |
2552 } | |
2553 | |
2554 | |
2555 void os::print_jni_name_prefix_on(outputStream* st, int args_size) { | |
2556 // no prefix required, not even "_" | |
2557 } | |
2558 | |
2559 | |
2560 void os::print_jni_name_suffix_on(outputStream* st, int args_size) { | |
2561 // no suffix required | |
2562 } | |
2563 | |
2564 | |
2565 // sun.misc.Signal | |
2566 | |
2567 extern "C" { | |
2568 static void UserHandler(int sig, void *siginfo, void *context) { | |
2569 // Ctrl-C is pressed during error reporting, likely because the error | |
2570 // handler fails to abort. Let VM die immediately. | |
2571 if (sig == SIGINT && is_error_reported()) { | |
2572 os::die(); | |
2573 } | |
2574 | |
2575 os::signal_notify(sig); | |
2576 // We do not need to reinstate the signal handler each time... | |
2577 } | |
2578 } | |
2579 | |
2580 void* os::user_handler() { | |
2581 return CAST_FROM_FN_PTR(void*, UserHandler); | |
2582 } | |
2583 | |
2584 extern "C" { | |
2585 typedef void (*sa_handler_t)(int); | |
2586 typedef void (*sa_sigaction_t)(int, siginfo_t *, void *); | |
2587 } | |
2588 | |
2589 void* os::signal(int signal_number, void* handler) { | |
2590 struct sigaction sigAct, oldSigAct; | |
2591 sigfillset(&(sigAct.sa_mask)); | |
2592 sigAct.sa_flags = SA_RESTART & ~SA_RESETHAND; | |
2593 sigAct.sa_handler = CAST_TO_FN_PTR(sa_handler_t, handler); | |
2594 | |
2595 if (sigaction(signal_number, &sigAct, &oldSigAct)) | |
2596 // -1 means registration failed | |
2597 return (void *)-1; | |
2598 | |
2599 return CAST_FROM_FN_PTR(void*, oldSigAct.sa_handler); | |
2600 } | |
2601 | |
2602 void os::signal_raise(int signal_number) { | |
2603 raise(signal_number); | |
2604 } | |
2605 | |
2606 /* | |
2607 * The following code is moved from os.cpp for making this | |
2608 * code platform specific, which it is by its very nature. | |
2609 */ | |
2610 | |
2611 // a counter for each possible signal value | |
2612 static int Sigexit = 0; | |
2613 static int Maxlibjsigsigs; | |
2614 static jint *pending_signals = NULL; | |
2615 static int *preinstalled_sigs = NULL; | |
2616 static struct sigaction *chainedsigactions = NULL; | |
2617 static sema_t sig_sem; | |
2618 typedef int (*version_getting_t)(); | |
2619 version_getting_t os::Solaris::get_libjsig_version = NULL; | |
2620 static int libjsigversion = NULL; | |
2621 | |
2622 int os::sigexitnum_pd() { | |
2623 assert(Sigexit > 0, "signal memory not yet initialized"); | |
2624 return Sigexit; | |
2625 } | |
2626 | |
2627 void os::Solaris::init_signal_mem() { | |
2628 // Initialize signal structures | |
2629 Maxsignum = SIGRTMAX; | |
2630 Sigexit = Maxsignum+1; | |
2631 assert(Maxsignum >0, "Unable to obtain max signal number"); | |
2632 | |
2633 Maxlibjsigsigs = Maxsignum; | |
2634 | |
2635 // pending_signals has one int per signal | |
2636 // The additional signal is for SIGEXIT - exit signal to signal_thread | |
2637 pending_signals = (jint *)os::malloc(sizeof(jint) * (Sigexit+1)); | |
2638 memset(pending_signals, 0, (sizeof(jint) * (Sigexit+1))); | |
2639 | |
2640 if (UseSignalChaining) { | |
2641 chainedsigactions = (struct sigaction *)malloc(sizeof(struct sigaction) | |
2642 * (Maxsignum + 1)); | |
2643 memset(chainedsigactions, 0, (sizeof(struct sigaction) * (Maxsignum + 1))); | |
2644 preinstalled_sigs = (int *)os::malloc(sizeof(int) * (Maxsignum + 1)); | |
2645 memset(preinstalled_sigs, 0, (sizeof(int) * (Maxsignum + 1))); | |
2646 } | |
2647 ourSigFlags = (int*)malloc(sizeof(int) * (Maxsignum + 1 )); | |
2648 memset(ourSigFlags, 0, sizeof(int) * (Maxsignum + 1)); | |
2649 } | |
2650 | |
2651 void os::signal_init_pd() { | |
2652 int ret; | |
2653 | |
2654 ret = ::sema_init(&sig_sem, 0, NULL, NULL); | |
2655 assert(ret == 0, "sema_init() failed"); | |
2656 } | |
2657 | |
2658 void os::signal_notify(int signal_number) { | |
2659 int ret; | |
2660 | |
2661 Atomic::inc(&pending_signals[signal_number]); | |
2662 ret = ::sema_post(&sig_sem); | |
2663 assert(ret == 0, "sema_post() failed"); | |
2664 } | |
2665 | |
2666 static int check_pending_signals(bool wait_for_signal) { | |
2667 int ret; | |
2668 while (true) { | |
2669 for (int i = 0; i < Sigexit + 1; i++) { | |
2670 jint n = pending_signals[i]; | |
2671 if (n > 0 && n == Atomic::cmpxchg(n - 1, &pending_signals[i], n)) { | |
2672 return i; | |
2673 } | |
2674 } | |
2675 if (!wait_for_signal) { | |
2676 return -1; | |
2677 } | |
2678 JavaThread *thread = JavaThread::current(); | |
2679 ThreadBlockInVM tbivm(thread); | |
2680 | |
2681 bool threadIsSuspended; | |
2682 do { | |
2683 thread->set_suspend_equivalent(); | |
2684 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() | |
2685 while((ret = ::sema_wait(&sig_sem)) == EINTR) | |
2686 ; | |
2687 assert(ret == 0, "sema_wait() failed"); | |
2688 | |
2689 // were we externally suspended while we were waiting? | |
2690 threadIsSuspended = thread->handle_special_suspend_equivalent_condition(); | |
2691 if (threadIsSuspended) { | |
2692 // | |
2693 // The semaphore has been incremented, but while we were waiting | |
2694 // another thread suspended us. We don't want to continue running | |
2695 // while suspended because that would surprise the thread that | |
2696 // suspended us. | |
2697 // | |
2698 ret = ::sema_post(&sig_sem); | |
2699 assert(ret == 0, "sema_post() failed"); | |
2700 | |
2701 thread->java_suspend_self(); | |
2702 } | |
2703 } while (threadIsSuspended); | |
2704 } | |
2705 } | |
2706 | |
2707 int os::signal_lookup() { | |
2708 return check_pending_signals(false); | |
2709 } | |
2710 | |
2711 int os::signal_wait() { | |
2712 return check_pending_signals(true); | |
2713 } | |
2714 | |
2715 //////////////////////////////////////////////////////////////////////////////// | |
2716 // Virtual Memory | |
2717 | |
2718 static int page_size = -1; | |
2719 | |
2720 // The mmap MAP_ALIGN flag is supported on Solaris 9 and later. init_2() will | |
2721 // clear this var if support is not available. | |
2722 static bool has_map_align = true; | |
2723 | |
2724 int os::vm_page_size() { | |
2725 assert(page_size != -1, "must call os::init"); | |
2726 return page_size; | |
2727 } | |
2728 | |
2729 // Solaris allocates memory by pages. | |
2730 int os::vm_allocation_granularity() { | |
2731 assert(page_size != -1, "must call os::init"); | |
2732 return page_size; | |
2733 } | |
2734 | |
656 | 2735 bool os::commit_memory(char* addr, size_t bytes, bool exec) { |
2736 int prot = exec ? PROT_READ|PROT_WRITE|PROT_EXEC : PROT_READ|PROT_WRITE; | |
0 | 2737 size_t size = bytes; |
2738 return | |
656 | 2739 NULL != Solaris::mmap_chunk(addr, size, MAP_PRIVATE|MAP_FIXED, prot); |
2740 } | |
2741 | |
2742 bool os::commit_memory(char* addr, size_t bytes, size_t alignment_hint, | |
2743 bool exec) { | |
2744 if (commit_memory(addr, bytes, exec)) { | |
0 | 2745 if (UseMPSS && alignment_hint > (size_t)vm_page_size()) { |
2746 // If the large page size has been set and the VM | |
2747 // is using large pages, use the large page size | |
2748 // if it is smaller than the alignment hint. This is | |
2749 // a case where the VM wants to use a larger alignment size | |
2750 // for its own reasons but still want to use large pages | |
2751 // (which is what matters to setting the mpss range. | |
2752 size_t page_size = 0; | |
2753 if (large_page_size() < alignment_hint) { | |
2754 assert(UseLargePages, "Expected to be here for large page use only"); | |
2755 page_size = large_page_size(); | |
2756 } else { | |
2757 // If the alignment hint is less than the large page | |
2758 // size, the VM wants a particular alignment (thus the hint) | |
2759 // for internal reasons. Try to set the mpss range using | |
2760 // the alignment_hint. | |
2761 page_size = alignment_hint; | |
2762 } | |
2763 // Since this is a hint, ignore any failures. | |
2764 (void)Solaris::set_mpss_range(addr, bytes, page_size); | |
2765 } | |
2766 return true; | |
2767 } | |
2768 return false; | |
2769 } | |
2770 | |
2771 // Uncommit the pages in a specified region. | |
2772 void os::free_memory(char* addr, size_t bytes) { | |
2773 if (madvise(addr, bytes, MADV_FREE) < 0) { | |
2774 debug_only(warning("MADV_FREE failed.")); | |
2775 return; | |
2776 } | |
2777 } | |
2778 | |
1320
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2779 bool os::create_stack_guard_pages(char* addr, size_t size) { |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2780 return os::commit_memory(addr, size); |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2781 } |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2782 |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2783 bool os::remove_stack_guard_pages(char* addr, size_t size) { |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2784 return os::uncommit_memory(addr, size); |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2785 } |
3b3d12e645e7
6929067: Stack guard pages should be removed when thread is detached
coleenp
parents:
1123
diff
changeset
|
2786 |
0 | 2787 // Change the page size in a given range. |
2788 void os::realign_memory(char *addr, size_t bytes, size_t alignment_hint) { | |
2789 assert((intptr_t)addr % alignment_hint == 0, "Address should be aligned."); | |
2790 assert((intptr_t)(addr + bytes) % alignment_hint == 0, "End should be aligned."); | |
2791 Solaris::set_mpss_range(addr, bytes, alignment_hint); | |
2792 } | |
2793 | |
2794 // Tell the OS to make the range local to the first-touching LWP | |
141 | 2795 void os::numa_make_local(char *addr, size_t bytes, int lgrp_hint) { |
0 | 2796 assert((intptr_t)addr % os::vm_page_size() == 0, "Address should be page-aligned."); |
2797 if (madvise(addr, bytes, MADV_ACCESS_LWP) < 0) { | |
2798 debug_only(warning("MADV_ACCESS_LWP failed.")); | |
2799 } | |
2800 } | |
2801 | |
2802 // Tell the OS that this range would be accessed from different LWPs. | |
2803 void os::numa_make_global(char *addr, size_t bytes) { | |
2804 assert((intptr_t)addr % os::vm_page_size() == 0, "Address should be page-aligned."); | |
2805 if (madvise(addr, bytes, MADV_ACCESS_MANY) < 0) { | |
2806 debug_only(warning("MADV_ACCESS_MANY failed.")); | |
2807 } | |
2808 } | |
2809 | |
2810 // Get the number of the locality groups. | |
2811 size_t os::numa_get_groups_num() { | |
2812 size_t n = Solaris::lgrp_nlgrps(Solaris::lgrp_cookie()); | |
2813 return n != -1 ? n : 1; | |
2814 } | |
2815 | |
2816 // Get a list of leaf locality groups. A leaf lgroup is group that | |
2817 // doesn't have any children. Typical leaf group is a CPU or a CPU/memory | |
2818 // board. An LWP is assigned to one of these groups upon creation. | |
2819 size_t os::numa_get_leaf_groups(int *ids, size_t size) { | |
2820 if ((ids[0] = Solaris::lgrp_root(Solaris::lgrp_cookie())) == -1) { | |
2821 ids[0] = 0; | |
2822 return 1; | |
2823 } | |
2824 int result_size = 0, top = 1, bottom = 0, cur = 0; | |
2825 for (int k = 0; k < size; k++) { | |
2826 int r = Solaris::lgrp_children(Solaris::lgrp_cookie(), ids[cur], | |
2827 (Solaris::lgrp_id_t*)&ids[top], size - top); | |
2828 if (r == -1) { | |
2829 ids[0] = 0; | |
2830 return 1; | |
2831 } | |
2832 if (!r) { | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2833 // That's a leaf node. |
0 | 2834 assert (bottom <= cur, "Sanity check"); |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2835 // Check if the node has memory |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2836 if (Solaris::lgrp_resources(Solaris::lgrp_cookie(), ids[cur], |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2837 NULL, 0, LGRP_RSRC_MEM) > 0) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2838 ids[bottom++] = ids[cur]; |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2839 } |
0 | 2840 } |
2841 top += r; | |
2842 cur++; | |
2843 } | |
268
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2844 if (bottom == 0) { |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2845 // Handle a situation, when the OS reports no memory available. |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2846 // Assume UMA architecture. |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2847 ids[0] = 0; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2848 return 1; |
d6340ab4105b
6723228: NUMA allocator: assert(lgrp_id != -1, "No lgrp_id set")
iveresov
parents:
267
diff
changeset
|
2849 } |
0 | 2850 return bottom; |
2851 } | |
2852 | |
342
37f87013dfd8
6711316: Open source the Garbage-First garbage collector
ysr
parents:
144
diff
changeset
|
2853 // Detect the topology change. Typically happens during CPU plugging-unplugging. |
0 | 2854 bool os::numa_topology_changed() { |
2855 int is_stale = Solaris::lgrp_cookie_stale(Solaris::lgrp_cookie()); | |
2856 if (is_stale != -1 && is_stale) { | |
2857 Solaris::lgrp_fini(Solaris::lgrp_cookie()); | |
2858 Solaris::lgrp_cookie_t c = Solaris::lgrp_init(Solaris::LGRP_VIEW_CALLER); | |
2859 assert(c != 0, "Failure to initialize LGRP API"); | |
2860 Solaris::set_lgrp_cookie(c); | |
2861 return true; | |
2862 } | |
2863 return false; | |
2864 } | |
2865 | |
2866 // Get the group id of the current LWP. | |
2867 int os::numa_get_group_id() { | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2868 int lgrp_id = Solaris::lgrp_home(P_LWPID, P_MYID); |
0 | 2869 if (lgrp_id == -1) { |
2870 return 0; | |
2871 } | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2872 const int size = os::numa_get_groups_num(); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2873 int *ids = (int*)alloca(size * sizeof(int)); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2874 |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2875 // Get the ids of all lgroups with memory; r is the count. |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2876 int r = Solaris::lgrp_resources(Solaris::lgrp_cookie(), lgrp_id, |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2877 (Solaris::lgrp_id_t*)ids, size, LGRP_RSRC_MEM); |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2878 if (r <= 0) { |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2879 return 0; |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2880 } |
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
2881 return ids[os::random() % r]; |
0 | 2882 } |
2883 | |
2884 // Request information about the page. | |
2885 bool os::get_page_info(char *start, page_info* info) { | |
2886 const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE }; | |
2887 uint64_t addr = (uintptr_t)start; | |
2888 uint64_t outdata[2]; | |
2889 uint_t validity = 0; | |
2890 | |
2891 if (os::Solaris::meminfo(&addr, 1, info_types, 2, outdata, &validity) < 0) { | |
2892 return false; | |
2893 } | |
2894 | |
2895 info->size = 0; | |
2896 info->lgrp_id = -1; | |
2897 | |
2898 if ((validity & 1) != 0) { | |
2899 if ((validity & 2) != 0) { | |
2900 info->lgrp_id = outdata[0]; | |
2901 } | |
2902 if ((validity & 4) != 0) { | |
2903 info->size = outdata[1]; | |
2904 } | |
2905 return true; | |
2906 } | |
2907 return false; | |
2908 } | |
2909 | |
2910 // Scan the pages from start to end until a page different than | |
2911 // the one described in the info parameter is encountered. | |
2912 char *os::scan_pages(char *start, char* end, page_info* page_expected, page_info* page_found) { | |
2913 const uint_t info_types[] = { MEMINFO_VLGRP, MEMINFO_VPAGESIZE }; | |
2914 const size_t types = sizeof(info_types) / sizeof(info_types[0]); | |
2915 uint64_t addrs[MAX_MEMINFO_CNT], outdata[types * MAX_MEMINFO_CNT]; | |
2916 uint_t validity[MAX_MEMINFO_CNT]; | |
2917 | |
2918 size_t page_size = MAX2((size_t)os::vm_page_size(), page_expected->size); | |
2919 uint64_t p = (uint64_t)start; | |
2920 while (p < (uint64_t)end) { | |
2921 addrs[0] = p; | |
2922 size_t addrs_count = 1; | |
2923 while (addrs_count < MAX_MEMINFO_CNT && addrs[addrs_count - 1] < (uint64_t)end) { | |
2924 addrs[addrs_count] = addrs[addrs_count - 1] + page_size; | |
2925 addrs_count++; | |
2926 } | |
2927 | |
2928 if (os::Solaris::meminfo(addrs, addrs_count, info_types, types, outdata, validity) < 0) { | |
2929 return NULL; | |
2930 } | |
2931 | |
2932 size_t i = 0; | |
2933 for (; i < addrs_count; i++) { | |
2934 if ((validity[i] & 1) != 0) { | |
2935 if ((validity[i] & 4) != 0) { | |
2936 if (outdata[types * i + 1] != page_expected->size) { | |
2937 break; | |
2938 } | |
2939 } else | |
2940 if (page_expected->size != 0) { | |
2941 break; | |
2942 } | |
2943 | |
2944 if ((validity[i] & 2) != 0 && page_expected->lgrp_id > 0) { | |
2945 if (outdata[types * i] != page_expected->lgrp_id) { | |
2946 break; | |
2947 } | |
2948 } | |
2949 } else { | |
2950 return NULL; | |
2951 } | |
2952 } | |
2953 | |
2954 if (i != addrs_count) { | |
2955 if ((validity[i] & 2) != 0) { | |
2956 page_found->lgrp_id = outdata[types * i]; | |
2957 } else { | |
2958 page_found->lgrp_id = -1; | |
2959 } | |
2960 if ((validity[i] & 4) != 0) { | |
2961 page_found->size = outdata[types * i + 1]; | |
2962 } else { | |
2963 page_found->size = 0; | |
2964 } | |
2965 return (char*)addrs[i]; | |
2966 } | |
2967 | |
2968 p = addrs[addrs_count - 1] + page_size; | |
2969 } | |
2970 return end; | |
2971 } | |
2972 | |
2973 bool os::uncommit_memory(char* addr, size_t bytes) { | |
2974 size_t size = bytes; | |
2975 // Map uncommitted pages PROT_NONE so we fail early if we touch an | |
2976 // uncommitted page. Otherwise, the read/write might succeed if we | |
2977 // have enough swap space to back the physical page. | |
2978 return | |
2979 NULL != Solaris::mmap_chunk(addr, size, | |
2980 MAP_PRIVATE|MAP_FIXED|MAP_NORESERVE, | |
2981 PROT_NONE); | |
2982 } | |
2983 | |
2984 char* os::Solaris::mmap_chunk(char *addr, size_t size, int flags, int prot) { | |
2985 char *b = (char *)mmap(addr, size, prot, flags, os::Solaris::_dev_zero_fd, 0); | |
2986 | |
2987 if (b == MAP_FAILED) { | |
2988 return NULL; | |
2989 } | |
2990 return b; | |
2991 } | |
2992 | |
60
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2993 char* os::Solaris::anon_mmap(char* requested_addr, size_t bytes, size_t alignment_hint, bool fixed) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2994 char* addr = requested_addr; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2995 int flags = MAP_PRIVATE | MAP_NORESERVE; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2996 |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2997 assert(!(fixed && (alignment_hint > 0)), "alignment hint meaningless with fixed mmap"); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2998 |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
2999 if (fixed) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3000 flags |= MAP_FIXED; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3001 } else if (has_map_align && (alignment_hint > (size_t) vm_page_size())) { |
0 | 3002 flags |= MAP_ALIGN; |
3003 addr = (char*) alignment_hint; | |
3004 } | |
3005 | |
3006 // Map uncommitted pages PROT_NONE so we fail early if we touch an | |
3007 // uncommitted page. Otherwise, the read/write might succeed if we | |
3008 // have enough swap space to back the physical page. | |
60
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3009 return mmap_chunk(addr, bytes, flags, PROT_NONE); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3010 } |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3011 |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3012 char* os::reserve_memory(size_t bytes, char* requested_addr, size_t alignment_hint) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3013 char* addr = Solaris::anon_mmap(requested_addr, bytes, alignment_hint, (requested_addr != NULL)); |
0 | 3014 |
3015 guarantee(requested_addr == NULL || requested_addr == addr, | |
3016 "OS failed to return requested mmap address."); | |
3017 return addr; | |
3018 } | |
3019 | |
3020 // Reserve memory at an arbitrary address, only if that area is | |
3021 // available (and not reserved for something else). | |
3022 | |
3023 char* os::attempt_reserve_memory_at(size_t bytes, char* requested_addr) { | |
3024 const int max_tries = 10; | |
3025 char* base[max_tries]; | |
3026 size_t size[max_tries]; | |
3027 | |
3028 // Solaris adds a gap between mmap'ed regions. The size of the gap | |
3029 // is dependent on the requested size and the MMU. Our initial gap | |
3030 // value here is just a guess and will be corrected later. | |
3031 bool had_top_overlap = false; | |
3032 bool have_adjusted_gap = false; | |
3033 size_t gap = 0x400000; | |
3034 | |
3035 // Assert only that the size is a multiple of the page size, since | |
3036 // that's all that mmap requires, and since that's all we really know | |
3037 // about at this low abstraction level. If we need higher alignment, | |
3038 // we can either pass an alignment to this method or verify alignment | |
3039 // in one of the methods further up the call chain. See bug 5044738. | |
3040 assert(bytes % os::vm_page_size() == 0, "reserving unexpected size block"); | |
3041 | |
60
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3042 // Since snv_84, Solaris attempts to honor the address hint - see 5003415. |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3043 // Give it a try, if the kernel honors the hint we can return immediately. |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3044 char* addr = Solaris::anon_mmap(requested_addr, bytes, 0, false); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3045 volatile int err = errno; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3046 if (addr == requested_addr) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3047 return addr; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3048 } else if (addr != NULL) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3049 unmap_memory(addr, bytes); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3050 } |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3051 |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3052 if (PrintMiscellaneous && Verbose) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3053 char buf[256]; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3054 buf[0] = '\0'; |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3055 if (addr == NULL) { |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3056 jio_snprintf(buf, sizeof(buf), ": %s", strerror(err)); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3057 } |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3058 warning("attempt_reserve_memory_at: couldn't reserve %d bytes at " |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3059 PTR_FORMAT ": reserve_memory_helper returned " PTR_FORMAT |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3060 "%s", bytes, requested_addr, addr, buf); |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3061 } |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3062 |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3063 // Address hint method didn't work. Fall back to the old method. |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3064 // In theory, once SNV becomes our oldest supported platform, this |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3065 // code will no longer be needed. |
8d84e28e68ba
6204603: Modify hotspot to use new Solaris mmap semantics for class data archive file
sbohne
parents:
0
diff
changeset
|
3066 // |
0 | 3067 // Repeatedly allocate blocks until the block is allocated at the |
3068 // right spot. Give up after max_tries. | |
3069 int i; | |
3070 for (i = 0; i < max_tries; ++i) { | |
3071 base[i] = reserve_memory(bytes); | |
3072 | |
3073 if (base[i] != NULL) { | |
3074 // Is this the block we wanted? | |
3075 if (base[i] == requested_addr) { | |
3076 size[i] = bytes; | |
3077 break; | |
3078 } | |
3079 | |
3080 // check that the gap value is right | |
3081 if (had_top_overlap && !have_adjusted_gap) { | |
3082 size_t actual_gap = base[i-1] - base[i] - bytes; | |
3083 if (gap != actual_gap) { | |
3084 // adjust the gap value and retry the last 2 allocations | |
3085 assert(i > 0, "gap adjustment code problem"); | |
3086 have_adjusted_gap = true; // adjust the gap only once, just in case | |
3087 gap = actual_gap; | |
3088 if (PrintMiscellaneous && Verbose) { | |
3089 warning("attempt_reserve_memory_at: adjusted gap to 0x%lx", gap); | |
3090 } | |
3091 unmap_memory(base[i], bytes); | |
3092 unmap_memory(base[i-1], size[i-1]); | |
3093 i-=2; | |
3094 continue; | |
3095 } | |
3096 } | |
3097 | |
3098 // Does this overlap the block we wanted? Give back the overlapped | |
3099 // parts and try again. | |
3100 // | |
3101 // There is still a bug in this code: if top_overlap == bytes, | |
3102 // the overlap is offset from requested region by the value of gap. | |
3103 // In this case giving back the overlapped part will not work, | |
3104 // because we'll give back the entire block at base[i] and | |
3105 // therefore the subsequent allocation will not generate a new gap. | |
3106 // This could be fixed with a new algorithm that used larger | |
3107 // or variable size chunks to find the requested region - | |
3108 // but such a change would introduce additional complications. | |
3109 // It's rare enough that the planets align for this bug, | |
3110 // so we'll just wait for a fix for 6204603/5003415 which | |
3111 // will provide a mmap flag to allow us to avoid this business. | |
3112 | |
3113 size_t top_overlap = requested_addr + (bytes + gap) - base[i]; | |
3114 if (top_overlap >= 0 && top_overlap < bytes) { | |
3115 had_top_overlap = true; | |
3116 unmap_memory(base[i], top_overlap); | |
3117 base[i] += top_overlap; | |
3118 size[i] = bytes - top_overlap; | |
3119 } else { | |
3120 size_t bottom_overlap = base[i] + bytes - requested_addr; | |
3121 if (bottom_overlap >= 0 && bottom_overlap < bytes) { | |
3122 if (PrintMiscellaneous && Verbose && bottom_overlap == 0) { | |
3123 warning("attempt_reserve_memory_at: possible alignment bug"); | |
3124 } | |
3125 unmap_memory(requested_addr, bottom_overlap); | |
3126 size[i] = bytes - bottom_overlap; | |
3127 } else { | |
3128 size[i] = bytes; | |
3129 } | |
3130 } | |
3131 } | |
3132 } | |
3133 | |
3134 // Give back the unused reserved pieces. | |
3135 | |
3136 for (int j = 0; j < i; ++j) { | |
3137 if (base[j] != NULL) { | |
3138 unmap_memory(base[j], size[j]); | |
3139 } | |
3140 } | |
3141 | |
3142 return (i < max_tries) ? requested_addr : NULL; | |
3143 } | |
3144 | |
3145 bool os::release_memory(char* addr, size_t bytes) { | |
3146 size_t size = bytes; | |
3147 return munmap(addr, size) == 0; | |
3148 } | |
3149 | |
3150 static bool solaris_mprotect(char* addr, size_t bytes, int prot) { | |
3151 assert(addr == (char*)align_size_down((uintptr_t)addr, os::vm_page_size()), | |
3152 "addr must be page aligned"); | |
3153 int retVal = mprotect(addr, bytes, prot); | |
3154 return retVal == 0; | |
3155 } | |
3156 | |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3157 // Protect memory (Used to pass readonly pages through |
0 | 3158 // JNI GetArray<type>Elements with empty arrays.) |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
462
diff
changeset
|
3159 // Also, used for serialization page and for compressed oops null pointer |
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
462
diff
changeset
|
3160 // checking. |
237
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3161 bool os::protect_memory(char* addr, size_t bytes, ProtType prot, |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3162 bool is_committed) { |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3163 unsigned int p = 0; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3164 switch (prot) { |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3165 case MEM_PROT_NONE: p = PROT_NONE; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3166 case MEM_PROT_READ: p = PROT_READ; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3167 case MEM_PROT_RW: p = PROT_READ|PROT_WRITE; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3168 case MEM_PROT_RWX: p = PROT_READ|PROT_WRITE|PROT_EXEC; break; |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3169 default: |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3170 ShouldNotReachHere(); |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3171 } |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3172 // is_committed is unused. |
1fdb98a17101
6716785: implicit null checks not triggering with CompressedOops
coleenp
parents:
196
diff
changeset
|
3173 return solaris_mprotect(addr, bytes, p); |
0 | 3174 } |
3175 | |
3176 // guard_memory and unguard_memory only happens within stack guard pages. | |
3177 // Since ISM pertains only to the heap, guard and unguard memory should not | |
3178 /// happen with an ISM region. | |
3179 bool os::guard_memory(char* addr, size_t bytes) { | |
3180 return solaris_mprotect(addr, bytes, PROT_NONE); | |
3181 } | |
3182 | |
3183 bool os::unguard_memory(char* addr, size_t bytes) { | |
477
24fda36852ce
6727377: VM stack guard pages on Windows should PAGE_READWRITE not PAGE_EXECUTE_READWRITE
coleenp
parents:
462
diff
changeset
|
3184 return solaris_mprotect(addr, bytes, PROT_READ|PROT_WRITE); |
0 | 3185 } |
3186 | |
3187 // Large page support | |
3188 | |
3189 // UseLargePages is the master flag to enable/disable large page memory. | |
3190 // UseMPSS and UseISM are supported for compatibility reasons. Their combined | |
3191 // effects can be described in the following table: | |
3192 // | |
3193 // UseLargePages UseMPSS UseISM | |
3194 // false * * => UseLargePages is the master switch, turning | |
3195 // it off will turn off both UseMPSS and | |
3196 // UseISM. VM will not use large page memory | |
3197 // regardless the settings of UseMPSS/UseISM. | |
3198 // true false false => Unless future Solaris provides other | |
3199 // mechanism to use large page memory, this | |
3200 // combination is equivalent to -UseLargePages, | |
3201 // VM will not use large page memory | |
3202 // true true false => JVM will use MPSS for large page memory. | |
3203 // This is the default behavior. | |
3204 // true false true => JVM will use ISM for large page memory. | |
3205 // true true true => JVM will use ISM if it is available. | |
3206 // Otherwise, JVM will fall back to MPSS. | |
3207 // Becaues ISM is now available on all | |
3208 // supported Solaris versions, this combination | |
3209 // is equivalent to +UseISM -UseMPSS. | |
3210 | |
3211 typedef int (*getpagesizes_func_type) (size_t[], int); | |
3212 static size_t _large_page_size = 0; | |
3213 | |
3214 bool os::Solaris::ism_sanity_check(bool warn, size_t * page_size) { | |
3215 // x86 uses either 2M or 4M page, depending on whether PAE (Physical Address | |
3216 // Extensions) mode is enabled. AMD64/EM64T uses 2M page in 64bit mode. Sparc | |
3217 // can support multiple page sizes. | |
3218 | |
3219 // Don't bother to probe page size because getpagesizes() comes with MPSS. | |
3220 // ISM is only recommended on old Solaris where there is no MPSS support. | |
3221 // Simply choose a conservative value as default. | |
3222 *page_size = LargePageSizeInBytes ? LargePageSizeInBytes : | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
3223 SPARC_ONLY(4 * M) IA32_ONLY(4 * M) AMD64_ONLY(2 * M) |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
3224 ARM_ONLY(2 * M); |
0 | 3225 |
3226 // ISM is available on all supported Solaris versions | |
3227 return true; | |
3228 } | |
3229 | |
3230 // Insertion sort for small arrays (descending order). | |
3231 static void insertion_sort_descending(size_t* array, int len) { | |
3232 for (int i = 0; i < len; i++) { | |
3233 size_t val = array[i]; | |
3234 for (size_t key = i; key > 0 && array[key - 1] < val; --key) { | |
3235 size_t tmp = array[key]; | |
3236 array[key] = array[key - 1]; | |
3237 array[key - 1] = tmp; | |
3238 } | |
3239 } | |
3240 } | |
3241 | |
3242 bool os::Solaris::mpss_sanity_check(bool warn, size_t * page_size) { | |
3243 getpagesizes_func_type getpagesizes_func = | |
3244 CAST_TO_FN_PTR(getpagesizes_func_type, dlsym(RTLD_DEFAULT, "getpagesizes")); | |
3245 if (getpagesizes_func == NULL) { | |
3246 if (warn) { | |
3247 warning("MPSS is not supported by the operating system."); | |
3248 } | |
3249 return false; | |
3250 } | |
3251 | |
3252 const unsigned int usable_count = VM_Version::page_size_count(); | |
3253 if (usable_count == 1) { | |
3254 return false; | |
3255 } | |
3256 | |
3257 // Fill the array of page sizes. | |
3258 int n = getpagesizes_func(_page_sizes, page_sizes_max); | |
3259 assert(n > 0, "Solaris bug?"); | |
3260 if (n == page_sizes_max) { | |
3261 // Add a sentinel value (necessary only if the array was completely filled | |
3262 // since it is static (zeroed at initialization)). | |
3263 _page_sizes[--n] = 0; | |
3264 DEBUG_ONLY(warning("increase the size of the os::_page_sizes array.");) | |
3265 } | |
3266 assert(_page_sizes[n] == 0, "missing sentinel"); | |
3267 | |
3268 if (n == 1) return false; // Only one page size available. | |
3269 | |
3270 // Skip sizes larger than 4M (or LargePageSizeInBytes if it was set) and | |
3271 // select up to usable_count elements. First sort the array, find the first | |
3272 // acceptable value, then copy the usable sizes to the top of the array and | |
3273 // trim the rest. Make sure to include the default page size :-). | |
3274 // | |
3275 // A better policy could get rid of the 4M limit by taking the sizes of the | |
3276 // important VM memory regions (java heap and possibly the code cache) into | |
3277 // account. | |
3278 insertion_sort_descending(_page_sizes, n); | |
3279 const size_t size_limit = | |
3280 FLAG_IS_DEFAULT(LargePageSizeInBytes) ? 4 * M : LargePageSizeInBytes; | |
3281 int beg; | |
3282 for (beg = 0; beg < n && _page_sizes[beg] > size_limit; ++beg) /* empty */ ; | |
3283 const int end = MIN2((int)usable_count, n) - 1; | |
3284 for (int cur = 0; cur < end; ++cur, ++beg) { | |
3285 _page_sizes[cur] = _page_sizes[beg]; | |
3286 } | |
3287 _page_sizes[end] = vm_page_size(); | |
3288 _page_sizes[end + 1] = 0; | |
3289 | |
3290 if (_page_sizes[end] > _page_sizes[end - 1]) { | |
3291 // Default page size is not the smallest; sort again. | |
3292 insertion_sort_descending(_page_sizes, end + 1); | |
3293 } | |
3294 *page_size = _page_sizes[0]; | |
3295 | |
3296 return true; | |
3297 } | |
3298 | |
3299 bool os::large_page_init() { | |
3300 if (!UseLargePages) { | |
3301 UseISM = false; | |
3302 UseMPSS = false; | |
3303 return false; | |
3304 } | |
3305 | |
3306 // print a warning if any large page related flag is specified on command line | |
3307 bool warn_on_failure = !FLAG_IS_DEFAULT(UseLargePages) || | |
3308 !FLAG_IS_DEFAULT(UseISM) || | |
3309 !FLAG_IS_DEFAULT(UseMPSS) || | |
3310 !FLAG_IS_DEFAULT(LargePageSizeInBytes); | |
3311 UseISM = UseISM && | |
3312 Solaris::ism_sanity_check(warn_on_failure, &_large_page_size); | |
3313 if (UseISM) { | |
3314 // ISM disables MPSS to be compatible with old JDK behavior | |
3315 UseMPSS = false; | |
79
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3316 _page_sizes[0] = _large_page_size; |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3317 _page_sizes[1] = vm_page_size(); |
0 | 3318 } |
3319 | |
3320 UseMPSS = UseMPSS && | |
3321 Solaris::mpss_sanity_check(warn_on_failure, &_large_page_size); | |
3322 | |
3323 UseLargePages = UseISM || UseMPSS; | |
3324 return UseLargePages; | |
3325 } | |
3326 | |
3327 bool os::Solaris::set_mpss_range(caddr_t start, size_t bytes, size_t align) { | |
3328 // Signal to OS that we want large pages for addresses | |
3329 // from addr, addr + bytes | |
3330 struct memcntl_mha mpss_struct; | |
3331 mpss_struct.mha_cmd = MHA_MAPSIZE_VA; | |
3332 mpss_struct.mha_pagesize = align; | |
3333 mpss_struct.mha_flags = 0; | |
3334 if (memcntl(start, bytes, MC_HAT_ADVISE, | |
3335 (caddr_t) &mpss_struct, 0, 0) < 0) { | |
3336 debug_only(warning("Attempt to use MPSS failed.")); | |
3337 return false; | |
3338 } | |
3339 return true; | |
3340 } | |
3341 | |
656 | 3342 char* os::reserve_memory_special(size_t bytes, char* addr, bool exec) { |
3343 // "exec" is passed in but not used. Creating the shared image for | |
3344 // the code cache doesn't have an SHM_X executable permission to check. | |
0 | 3345 assert(UseLargePages && UseISM, "only for ISM large pages"); |
3346 | |
3347 size_t size = bytes; | |
3348 char* retAddr = NULL; | |
3349 int shmid; | |
3350 key_t ismKey; | |
3351 | |
3352 bool warn_on_failure = UseISM && | |
3353 (!FLAG_IS_DEFAULT(UseLargePages) || | |
3354 !FLAG_IS_DEFAULT(UseISM) || | |
3355 !FLAG_IS_DEFAULT(LargePageSizeInBytes) | |
3356 ); | |
3357 char msg[128]; | |
3358 | |
3359 ismKey = IPC_PRIVATE; | |
3360 | |
3361 // Create a large shared memory region to attach to based on size. | |
3362 // Currently, size is the total size of the heap | |
3363 shmid = shmget(ismKey, size, SHM_R | SHM_W | IPC_CREAT); | |
3364 if (shmid == -1){ | |
3365 if (warn_on_failure) { | |
3366 jio_snprintf(msg, sizeof(msg), "Failed to reserve shared memory (errno = %d).", errno); | |
3367 warning(msg); | |
3368 } | |
3369 return NULL; | |
3370 } | |
3371 | |
3372 // Attach to the region | |
3373 retAddr = (char *) shmat(shmid, 0, SHM_SHARE_MMU | SHM_R | SHM_W); | |
3374 int err = errno; | |
3375 | |
3376 // Remove shmid. If shmat() is successful, the actual shared memory segment | |
3377 // will be deleted when it's detached by shmdt() or when the process | |
3378 // terminates. If shmat() is not successful this will remove the shared | |
3379 // segment immediately. | |
3380 shmctl(shmid, IPC_RMID, NULL); | |
3381 | |
3382 if (retAddr == (char *) -1) { | |
3383 if (warn_on_failure) { | |
3384 jio_snprintf(msg, sizeof(msg), "Failed to attach shared memory (errno = %d).", err); | |
3385 warning(msg); | |
3386 } | |
3387 return NULL; | |
3388 } | |
3389 | |
3390 return retAddr; | |
3391 } | |
3392 | |
3393 bool os::release_memory_special(char* base, size_t bytes) { | |
3394 // detaching the SHM segment will also delete it, see reserve_memory_special() | |
3395 int rslt = shmdt(base); | |
3396 return rslt == 0; | |
3397 } | |
3398 | |
3399 size_t os::large_page_size() { | |
3400 return _large_page_size; | |
3401 } | |
3402 | |
3403 // MPSS allows application to commit large page memory on demand; with ISM | |
3404 // the entire memory region must be allocated as shared memory. | |
3405 bool os::can_commit_large_page_memory() { | |
3406 return UseISM ? false : true; | |
3407 } | |
3408 | |
79
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3409 bool os::can_execute_large_page_memory() { |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3410 return UseISM ? false : true; |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3411 } |
82db0859acbe
6642862: Code cache allocation fails with large pages after 6588638
jcoomes
parents:
61
diff
changeset
|
3412 |
0 | 3413 static int os_sleep(jlong millis, bool interruptible) { |
3414 const jlong limit = INT_MAX; | |
3415 jlong prevtime; | |
3416 int res; | |
3417 | |
3418 while (millis > limit) { | |
3419 if ((res = os_sleep(limit, interruptible)) != OS_OK) | |
3420 return res; | |
3421 millis -= limit; | |
3422 } | |
3423 | |
3424 // Restart interrupted polls with new parameters until the proper delay | |
3425 // has been completed. | |
3426 | |
3427 prevtime = getTimeMillis(); | |
3428 | |
3429 while (millis > 0) { | |
3430 jlong newtime; | |
3431 | |
3432 if (!interruptible) { | |
3433 // Following assert fails for os::yield_all: | |
3434 // assert(!thread->is_Java_thread(), "must not be java thread"); | |
3435 res = poll(NULL, 0, millis); | |
3436 } else { | |
3437 JavaThread *jt = JavaThread::current(); | |
3438 | |
3439 INTERRUPTIBLE_NORESTART_VM_ALWAYS(poll(NULL, 0, millis), res, jt, | |
3440 os::Solaris::clear_interrupted); | |
3441 } | |
3442 | |
3443 // INTERRUPTIBLE_NORESTART_VM_ALWAYS returns res == OS_INTRPT for | |
3444 // thread.Interrupt. | |
3445 | |
1967 | 3446 // See c/r 6751923. Poll can return 0 before time |
3447 // has elapsed if time is set via clock_settime (as NTP does). | |
3448 // res == 0 if poll timed out (see man poll RETURN VALUES) | |
3449 // using the logic below checks that we really did | |
3450 // sleep at least "millis" if not we'll sleep again. | |
3451 if( ( res == 0 ) || ((res == OS_ERR) && (errno == EINTR))) { | |
0 | 3452 newtime = getTimeMillis(); |
3453 assert(newtime >= prevtime, "time moving backwards"); | |
3454 /* Doing prevtime and newtime in microseconds doesn't help precision, | |
3455 and trying to round up to avoid lost milliseconds can result in a | |
3456 too-short delay. */ | |
3457 millis -= newtime - prevtime; | |
3458 if(millis <= 0) | |
3459 return OS_OK; | |
3460 prevtime = newtime; | |
3461 } else | |
3462 return res; | |
3463 } | |
3464 | |
3465 return OS_OK; | |
3466 } | |
3467 | |
3468 // Read calls from inside the vm need to perform state transitions | |
3469 size_t os::read(int fd, void *buf, unsigned int nBytes) { | |
3470 INTERRUPTIBLE_RETURN_INT_VM(::read(fd, buf, nBytes), os::Solaris::clear_interrupted); | |
3471 } | |
3472 | |
3473 int os::sleep(Thread* thread, jlong millis, bool interruptible) { | |
3474 assert(thread == Thread::current(), "thread consistency check"); | |
3475 | |
3476 // TODO-FIXME: this should be removed. | |
3477 // On Solaris machines (especially 2.5.1) we found that sometimes the VM gets into a live lock | |
3478 // situation with a JavaThread being starved out of a lwp. The kernel doesn't seem to generate | |
3479 // a SIGWAITING signal which would enable the threads library to create a new lwp for the starving | |
3480 // thread. We suspect that because the Watcher thread keeps waking up at periodic intervals the kernel | |
3481 // is fooled into believing that the system is making progress. In the code below we block the | |
3482 // the watcher thread while safepoint is in progress so that it would not appear as though the | |
3483 // system is making progress. | |
3484 if (!Solaris::T2_libthread() && | |
3485 thread->is_Watcher_thread() && SafepointSynchronize::is_synchronizing() && !Arguments::has_profile()) { | |
3486 // We now try to acquire the threads lock. Since this lock is held by the VM thread during | |
3487 // the entire safepoint, the watcher thread will line up here during the safepoint. | |
3488 Threads_lock->lock_without_safepoint_check(); | |
3489 Threads_lock->unlock(); | |
3490 } | |
3491 | |
3492 if (thread->is_Java_thread()) { | |
3493 // This is a JavaThread so we honor the _thread_blocked protocol | |
3494 // even for sleeps of 0 milliseconds. This was originally done | |
3495 // as a workaround for bug 4338139. However, now we also do it | |
3496 // to honor the suspend-equivalent protocol. | |
3497 | |
3498 JavaThread *jt = (JavaThread *) thread; | |
3499 ThreadBlockInVM tbivm(jt); | |
3500 | |
3501 jt->set_suspend_equivalent(); | |
3502 // cleared by handle_special_suspend_equivalent_condition() or | |
3503 // java_suspend_self() via check_and_wait_while_suspended() | |
3504 | |
3505 int ret_code; | |
3506 if (millis <= 0) { | |
3507 thr_yield(); | |
3508 ret_code = 0; | |
3509 } else { | |
3510 // The original sleep() implementation did not create an | |
3511 // OSThreadWaitState helper for sleeps of 0 milliseconds. | |
3512 // I'm preserving that decision for now. | |
3513 OSThreadWaitState osts(jt->osthread(), false /* not Object.wait() */); | |
3514 | |
3515 ret_code = os_sleep(millis, interruptible); | |
3516 } | |
3517 | |
3518 // were we externally suspended while we were waiting? | |
3519 jt->check_and_wait_while_suspended(); | |
3520 | |
3521 return ret_code; | |
3522 } | |
3523 | |
3524 // non-JavaThread from this point on: | |
3525 | |
3526 if (millis <= 0) { | |
3527 thr_yield(); | |
3528 return 0; | |
3529 } | |
3530 | |
3531 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); | |
3532 | |
3533 return os_sleep(millis, interruptible); | |
3534 } | |
3535 | |
3536 int os::naked_sleep() { | |
3537 // %% make the sleep time an integer flag. for now use 1 millisec. | |
3538 return os_sleep(1, false); | |
3539 } | |
3540 | |
3541 // Sleep forever; naked call to OS-specific sleep; use with CAUTION | |
3542 void os::infinite_sleep() { | |
3543 while (true) { // sleep forever ... | |
3544 ::sleep(100); // ... 100 seconds at a time | |
3545 } | |
3546 } | |
3547 | |
3548 // Used to convert frequent JVM_Yield() to nops | |
3549 bool os::dont_yield() { | |
3550 if (DontYieldALot) { | |
3551 static hrtime_t last_time = 0; | |
3552 hrtime_t diff = getTimeNanos() - last_time; | |
3553 | |
3554 if (diff < DontYieldALotInterval * 1000000) | |
3555 return true; | |
3556 | |
3557 last_time += diff; | |
3558 | |
3559 return false; | |
3560 } | |
3561 else { | |
3562 return false; | |
3563 } | |
3564 } | |
3565 | |
3566 // Caveat: Solaris os::yield() causes a thread-state transition whereas | |
3567 // the linux and win32 implementations do not. This should be checked. | |
3568 | |
3569 void os::yield() { | |
3570 // Yields to all threads with same or greater priority | |
3571 os::sleep(Thread::current(), 0, false); | |
3572 } | |
3573 | |
3574 // Note that yield semantics are defined by the scheduling class to which | |
3575 // the thread currently belongs. Typically, yield will _not yield to | |
3576 // other equal or higher priority threads that reside on the dispatch queues | |
3577 // of other CPUs. | |
3578 | |
3579 os::YieldResult os::NakedYield() { thr_yield(); return os::YIELD_UNKNOWN; } | |
3580 | |
3581 | |
3582 // On Solaris we found that yield_all doesn't always yield to all other threads. | |
3583 // There have been cases where there is a thread ready to execute but it doesn't | |
3584 // get an lwp as the VM thread continues to spin with sleeps of 1 millisecond. | |
3585 // The 1 millisecond wait doesn't seem long enough for the kernel to issue a | |
3586 // SIGWAITING signal which will cause a new lwp to be created. So we count the | |
3587 // number of times yield_all is called in the one loop and increase the sleep | |
3588 // time after 8 attempts. If this fails too we increase the concurrency level | |
3589 // so that the starving thread would get an lwp | |
3590 | |
3591 void os::yield_all(int attempts) { | |
3592 // Yields to all threads, including threads with lower priorities | |
3593 if (attempts == 0) { | |
3594 os::sleep(Thread::current(), 1, false); | |
3595 } else { | |
3596 int iterations = attempts % 30; | |
3597 if (iterations == 0 && !os::Solaris::T2_libthread()) { | |
3598 // thr_setconcurrency and _getconcurrency make sense only under T1. | |
3599 int noofLWPS = thr_getconcurrency(); | |
3600 if (noofLWPS < (Threads::number_of_threads() + 2)) { | |
3601 thr_setconcurrency(thr_getconcurrency() + 1); | |
3602 } | |
3603 } else if (iterations < 25) { | |
3604 os::sleep(Thread::current(), 1, false); | |
3605 } else { | |
3606 os::sleep(Thread::current(), 10, false); | |
3607 } | |
3608 } | |
3609 } | |
3610 | |
3611 // Called from the tight loops to possibly influence time-sharing heuristics | |
3612 void os::loop_breaker(int attempts) { | |
3613 os::yield_all(attempts); | |
3614 } | |
3615 | |
3616 | |
3617 // Interface for setting lwp priorities. If we are using T2 libthread, | |
3618 // which forces the use of BoundThreads or we manually set UseBoundThreads, | |
3619 // all of our threads will be assigned to real lwp's. Using the thr_setprio | |
3620 // function is meaningless in this mode so we must adjust the real lwp's priority | |
3621 // The routines below implement the getting and setting of lwp priorities. | |
3622 // | |
3623 // Note: There are three priority scales used on Solaris. Java priotities | |
3624 // which range from 1 to 10, libthread "thr_setprio" scale which range | |
3625 // from 0 to 127, and the current scheduling class of the process we | |
3626 // are running in. This is typically from -60 to +60. | |
3627 // The setting of the lwp priorities in done after a call to thr_setprio | |
3628 // so Java priorities are mapped to libthread priorities and we map from | |
3629 // the latter to lwp priorities. We don't keep priorities stored in | |
3630 // Java priorities since some of our worker threads want to set priorities | |
3631 // higher than all Java threads. | |
3632 // | |
3633 // For related information: | |
3634 // (1) man -s 2 priocntl | |
3635 // (2) man -s 4 priocntl | |
3636 // (3) man dispadmin | |
3637 // = librt.so | |
3638 // = libthread/common/rtsched.c - thrp_setlwpprio(). | |
3639 // = ps -cL <pid> ... to validate priority. | |
3640 // = sched_get_priority_min and _max | |
3641 // pthread_create | |
3642 // sched_setparam | |
3643 // pthread_setschedparam | |
3644 // | |
3645 // Assumptions: | |
3646 // + We assume that all threads in the process belong to the same | |
3647 // scheduling class. IE. an homogenous process. | |
3648 // + Must be root or in IA group to change change "interactive" attribute. | |
3649 // Priocntl() will fail silently. The only indication of failure is when | |
3650 // we read-back the value and notice that it hasn't changed. | |
3651 // + Interactive threads enter the runq at the head, non-interactive at the tail. | |
3652 // + For RT, change timeslice as well. Invariant: | |
3653 // constant "priority integral" | |
3654 // Konst == TimeSlice * (60-Priority) | |
3655 // Given a priority, compute appropriate timeslice. | |
3656 // + Higher numerical values have higher priority. | |
3657 | |
3658 // sched class attributes | |
3659 typedef struct { | |
3660 int schedPolicy; // classID | |
3661 int maxPrio; | |
3662 int minPrio; | |
3663 } SchedInfo; | |
3664 | |
3665 | |
3666 static SchedInfo tsLimits, iaLimits, rtLimits; | |
3667 | |
3668 #ifdef ASSERT | |
3669 static int ReadBackValidate = 1; | |
3670 #endif | |
3671 static int myClass = 0; | |
3672 static int myMin = 0; | |
3673 static int myMax = 0; | |
3674 static int myCur = 0; | |
3675 static bool priocntl_enable = false; | |
3676 | |
3677 | |
3678 // Call the version of priocntl suitable for all supported versions | |
3679 // of Solaris. We need to call through this wrapper so that we can | |
3680 // build on Solaris 9 and run on Solaris 8, 9 and 10. | |
3681 // | |
3682 // This code should be removed if we ever stop supporting Solaris 8 | |
3683 // and earlier releases. | |
3684 | |
3685 static long priocntl_stub(int pcver, idtype_t idtype, id_t id, int cmd, caddr_t arg); | |
3686 typedef long (*priocntl_type)(int pcver, idtype_t idtype, id_t id, int cmd, caddr_t arg); | |
3687 static priocntl_type priocntl_ptr = priocntl_stub; | |
3688 | |
3689 // Stub to set the value of the real pointer, and then call the real | |
3690 // function. | |
3691 | |
3692 static long priocntl_stub(int pcver, idtype_t idtype, id_t id, int cmd, caddr_t arg) { | |
3693 // Try Solaris 8- name only. | |
3694 priocntl_type tmp = (priocntl_type)dlsym(RTLD_DEFAULT, "__priocntl"); | |
3695 guarantee(tmp != NULL, "priocntl function not found."); | |
3696 priocntl_ptr = tmp; | |
3697 return (*priocntl_ptr)(PC_VERSION, idtype, id, cmd, arg); | |
3698 } | |
3699 | |
3700 | |
3701 // lwp_priocntl_init | |
3702 // | |
3703 // Try to determine the priority scale for our process. | |
3704 // | |
3705 // Return errno or 0 if OK. | |
3706 // | |
3707 static | |
3708 int lwp_priocntl_init () | |
3709 { | |
3710 int rslt; | |
3711 pcinfo_t ClassInfo; | |
3712 pcparms_t ParmInfo; | |
3713 int i; | |
3714 | |
3715 if (!UseThreadPriorities) return 0; | |
3716 | |
3717 // We are using Bound threads, we need to determine our priority ranges | |
3718 if (os::Solaris::T2_libthread() || UseBoundThreads) { | |
3719 // If ThreadPriorityPolicy is 1, switch tables | |
3720 if (ThreadPriorityPolicy == 1) { | |
3721 for (i = 0 ; i < MaxPriority+1; i++) | |
3722 os::java_to_os_priority[i] = prio_policy1[i]; | |
3723 } | |
3724 } | |
3725 // Not using Bound Threads, set to ThreadPolicy 1 | |
3726 else { | |
3727 for ( i = 0 ; i < MaxPriority+1; i++ ) { | |
3728 os::java_to_os_priority[i] = prio_policy1[i]; | |
3729 } | |
3730 return 0; | |
3731 } | |
3732 | |
3733 | |
3734 // Get IDs for a set of well-known scheduling classes. | |
3735 // TODO-FIXME: GETCLINFO returns the current # of classes in the | |
3736 // the system. We should have a loop that iterates over the | |
3737 // classID values, which are known to be "small" integers. | |
3738 | |
3739 strcpy(ClassInfo.pc_clname, "TS"); | |
3740 ClassInfo.pc_cid = -1; | |
3741 rslt = (*priocntl_ptr)(PC_VERSION, P_ALL, 0, PC_GETCID, (caddr_t)&ClassInfo); | |
3742 if (rslt < 0) return errno; | |
3743 assert(ClassInfo.pc_cid != -1, "cid for TS class is -1"); | |
3744 tsLimits.schedPolicy = ClassInfo.pc_cid; | |
3745 tsLimits.maxPrio = ((tsinfo_t*)ClassInfo.pc_clinfo)->ts_maxupri; | |
3746 tsLimits.minPrio = -tsLimits.maxPrio; | |
3747 | |
3748 strcpy(ClassInfo.pc_clname, "IA"); | |
3749 ClassInfo.pc_cid = -1; | |
3750 rslt = (*priocntl_ptr)(PC_VERSION, P_ALL, 0, PC_GETCID, (caddr_t)&ClassInfo); | |
3751 if (rslt < 0) return errno; | |
3752 assert(ClassInfo.pc_cid != -1, "cid for IA class is -1"); | |
3753 iaLimits.schedPolicy = ClassInfo.pc_cid; | |
3754 iaLimits.maxPrio = ((iainfo_t*)ClassInfo.pc_clinfo)->ia_maxupri; | |
3755 iaLimits.minPrio = -iaLimits.maxPrio; | |
3756 | |
3757 strcpy(ClassInfo.pc_clname, "RT"); | |
3758 ClassInfo.pc_cid = -1; | |
3759 rslt = (*priocntl_ptr)(PC_VERSION, P_ALL, 0, PC_GETCID, (caddr_t)&ClassInfo); | |
3760 if (rslt < 0) return errno; | |
3761 assert(ClassInfo.pc_cid != -1, "cid for RT class is -1"); | |
3762 rtLimits.schedPolicy = ClassInfo.pc_cid; | |
3763 rtLimits.maxPrio = ((rtinfo_t*)ClassInfo.pc_clinfo)->rt_maxpri; | |
3764 rtLimits.minPrio = 0; | |
3765 | |
3766 | |
3767 // Query our "current" scheduling class. | |
3768 // This will normally be IA,TS or, rarely, RT. | |
3769 memset (&ParmInfo, 0, sizeof(ParmInfo)); | |
3770 ParmInfo.pc_cid = PC_CLNULL; | |
3771 rslt = (*priocntl_ptr) (PC_VERSION, P_PID, P_MYID, PC_GETPARMS, (caddr_t)&ParmInfo ); | |
3772 if ( rslt < 0 ) return errno; | |
3773 myClass = ParmInfo.pc_cid; | |
3774 | |
3775 // We now know our scheduling classId, get specific information | |
3776 // the class. | |
3777 ClassInfo.pc_cid = myClass; | |
3778 ClassInfo.pc_clname[0] = 0; | |
3779 rslt = (*priocntl_ptr) (PC_VERSION, (idtype)0, 0, PC_GETCLINFO, (caddr_t)&ClassInfo ); | |
3780 if ( rslt < 0 ) return errno; | |
3781 | |
3782 if (ThreadPriorityVerbose) | |
3783 tty->print_cr ("lwp_priocntl_init: Class=%d(%s)...", myClass, ClassInfo.pc_clname); | |
3784 | |
3785 memset(&ParmInfo, 0, sizeof(pcparms_t)); | |
3786 ParmInfo.pc_cid = PC_CLNULL; | |
3787 rslt = (*priocntl_ptr)(PC_VERSION, P_PID, P_MYID, PC_GETPARMS, (caddr_t)&ParmInfo); | |
3788 if (rslt < 0) return errno; | |
3789 | |
3790 if (ParmInfo.pc_cid == rtLimits.schedPolicy) { | |
3791 myMin = rtLimits.minPrio; | |
3792 myMax = rtLimits.maxPrio; | |
3793 } else if (ParmInfo.pc_cid == iaLimits.schedPolicy) { | |
3794 iaparms_t *iaInfo = (iaparms_t*)ParmInfo.pc_clparms; | |
3795 myMin = iaLimits.minPrio; | |
3796 myMax = iaLimits.maxPrio; | |
3797 myMax = MIN2(myMax, (int)iaInfo->ia_uprilim); // clamp - restrict | |
3798 } else if (ParmInfo.pc_cid == tsLimits.schedPolicy) { | |
3799 tsparms_t *tsInfo = (tsparms_t*)ParmInfo.pc_clparms; | |
3800 myMin = tsLimits.minPrio; | |
3801 myMax = tsLimits.maxPrio; | |
3802 myMax = MIN2(myMax, (int)tsInfo->ts_uprilim); // clamp - restrict | |
3803 } else { | |
3804 // No clue - punt | |
3805 if (ThreadPriorityVerbose) | |
3806 tty->print_cr ("Unknown scheduling class: %s ... \n", ClassInfo.pc_clname); | |
3807 return EINVAL; // no clue, punt | |
3808 } | |
3809 | |
3810 if (ThreadPriorityVerbose) | |
3811 tty->print_cr ("Thread priority Range: [%d..%d]\n", myMin, myMax); | |
3812 | |
3813 priocntl_enable = true; // Enable changing priorities | |
3814 return 0; | |
3815 } | |
3816 | |
3817 #define IAPRI(x) ((iaparms_t *)((x).pc_clparms)) | |
3818 #define RTPRI(x) ((rtparms_t *)((x).pc_clparms)) | |
3819 #define TSPRI(x) ((tsparms_t *)((x).pc_clparms)) | |
3820 | |
3821 | |
3822 // scale_to_lwp_priority | |
3823 // | |
3824 // Convert from the libthread "thr_setprio" scale to our current | |
3825 // lwp scheduling class scale. | |
3826 // | |
3827 static | |
3828 int scale_to_lwp_priority (int rMin, int rMax, int x) | |
3829 { | |
3830 int v; | |
3831 | |
3832 if (x == 127) return rMax; // avoid round-down | |
3833 v = (((x*(rMax-rMin)))/128)+rMin; | |
3834 return v; | |
3835 } | |
3836 | |
3837 | |
3838 // set_lwp_priority | |
3839 // | |
3840 // Set the priority of the lwp. This call should only be made | |
3841 // when using bound threads (T2 threads are bound by default). | |
3842 // | |
3843 int set_lwp_priority (int ThreadID, int lwpid, int newPrio ) | |
3844 { | |
3845 int rslt; | |
3846 int Actual, Expected, prv; | |
3847 pcparms_t ParmInfo; // for GET-SET | |
3848 #ifdef ASSERT | |
3849 pcparms_t ReadBack; // for readback | |
3850 #endif | |
3851 | |
3852 // Set priority via PC_GETPARMS, update, PC_SETPARMS | |
3853 // Query current values. | |
3854 // TODO: accelerate this by eliminating the PC_GETPARMS call. | |
3855 // Cache "pcparms_t" in global ParmCache. | |
3856 // TODO: elide set-to-same-value | |
3857 | |
3858 // If something went wrong on init, don't change priorities. | |
3859 if ( !priocntl_enable ) { | |
3860 if (ThreadPriorityVerbose) | |
3861 tty->print_cr("Trying to set priority but init failed, ignoring"); | |
3862 return EINVAL; | |
3863 } | |
3864 | |
3865 | |
3866 // If lwp hasn't started yet, just return | |
3867 // the _start routine will call us again. | |
3868 if ( lwpid <= 0 ) { | |
3869 if (ThreadPriorityVerbose) { | |
3870 tty->print_cr ("deferring the set_lwp_priority of thread " INTPTR_FORMAT " to %d, lwpid not set", | |
3871 ThreadID, newPrio); | |
3872 } | |
3873 return 0; | |
3874 } | |
3875 | |
3876 if (ThreadPriorityVerbose) { | |
3877 tty->print_cr ("set_lwp_priority(" INTPTR_FORMAT "@" INTPTR_FORMAT " %d) ", | |
3878 ThreadID, lwpid, newPrio); | |
3879 } | |
3880 | |
3881 memset(&ParmInfo, 0, sizeof(pcparms_t)); | |
3882 ParmInfo.pc_cid = PC_CLNULL; | |
3883 rslt = (*priocntl_ptr)(PC_VERSION, P_LWPID, lwpid, PC_GETPARMS, (caddr_t)&ParmInfo); | |
3884 if (rslt < 0) return errno; | |
3885 | |
3886 if (ParmInfo.pc_cid == rtLimits.schedPolicy) { | |
3887 rtparms_t *rtInfo = (rtparms_t*)ParmInfo.pc_clparms; | |
3888 rtInfo->rt_pri = scale_to_lwp_priority (rtLimits.minPrio, rtLimits.maxPrio, newPrio); | |
3889 rtInfo->rt_tqsecs = RT_NOCHANGE; | |
3890 rtInfo->rt_tqnsecs = RT_NOCHANGE; | |
3891 if (ThreadPriorityVerbose) { | |
3892 tty->print_cr("RT: %d->%d\n", newPrio, rtInfo->rt_pri); | |
3893 } | |
3894 } else if (ParmInfo.pc_cid == iaLimits.schedPolicy) { | |
3895 iaparms_t *iaInfo = (iaparms_t*)ParmInfo.pc_clparms; | |
3896 int maxClamped = MIN2(iaLimits.maxPrio, (int)iaInfo->ia_uprilim); | |
3897 iaInfo->ia_upri = scale_to_lwp_priority(iaLimits.minPrio, maxClamped, newPrio); | |
3898 iaInfo->ia_uprilim = IA_NOCHANGE; | |
3899 iaInfo->ia_mode = IA_NOCHANGE; | |
3900 if (ThreadPriorityVerbose) { | |
3901 tty->print_cr ("IA: [%d...%d] %d->%d\n", | |
3902 iaLimits.minPrio, maxClamped, newPrio, iaInfo->ia_upri); | |
3903 } | |
3904 } else if (ParmInfo.pc_cid == tsLimits.schedPolicy) { | |
3905 tsparms_t *tsInfo = (tsparms_t*)ParmInfo.pc_clparms; | |
3906 int maxClamped = MIN2(tsLimits.maxPrio, (int)tsInfo->ts_uprilim); | |
3907 prv = tsInfo->ts_upri; | |
3908 tsInfo->ts_upri = scale_to_lwp_priority(tsLimits.minPrio, maxClamped, newPrio); | |
3909 tsInfo->ts_uprilim = IA_NOCHANGE; | |
3910 if (ThreadPriorityVerbose) { | |
3911 tty->print_cr ("TS: %d [%d...%d] %d->%d\n", | |
3912 prv, tsLimits.minPrio, maxClamped, newPrio, tsInfo->ts_upri); | |
3913 } | |
3914 if (prv == tsInfo->ts_upri) return 0; | |
3915 } else { | |
3916 if ( ThreadPriorityVerbose ) { | |
3917 tty->print_cr ("Unknown scheduling class\n"); | |
3918 } | |
3919 return EINVAL; // no clue, punt | |
3920 } | |
3921 | |
3922 rslt = (*priocntl_ptr)(PC_VERSION, P_LWPID, lwpid, PC_SETPARMS, (caddr_t)&ParmInfo); | |
3923 if (ThreadPriorityVerbose && rslt) { | |
3924 tty->print_cr ("PC_SETPARMS ->%d %d\n", rslt, errno); | |
3925 } | |
3926 if (rslt < 0) return errno; | |
3927 | |
3928 #ifdef ASSERT | |
3929 // Sanity check: read back what we just attempted to set. | |
3930 // In theory it could have changed in the interim ... | |
3931 // | |
3932 // The priocntl system call is tricky. | |
3933 // Sometimes it'll validate the priority value argument and | |
3934 // return EINVAL if unhappy. At other times it fails silently. | |
3935 // Readbacks are prudent. | |
3936 | |
3937 if (!ReadBackValidate) return 0; | |
3938 | |
3939 memset(&ReadBack, 0, sizeof(pcparms_t)); | |
3940 ReadBack.pc_cid = PC_CLNULL; | |
3941 rslt = (*priocntl_ptr)(PC_VERSION, P_LWPID, lwpid, PC_GETPARMS, (caddr_t)&ReadBack); | |
3942 assert(rslt >= 0, "priocntl failed"); | |
3943 Actual = Expected = 0xBAD; | |
3944 assert(ParmInfo.pc_cid == ReadBack.pc_cid, "cid's don't match"); | |
3945 if (ParmInfo.pc_cid == rtLimits.schedPolicy) { | |
3946 Actual = RTPRI(ReadBack)->rt_pri; | |
3947 Expected = RTPRI(ParmInfo)->rt_pri; | |
3948 } else if (ParmInfo.pc_cid == iaLimits.schedPolicy) { | |
3949 Actual = IAPRI(ReadBack)->ia_upri; | |
3950 Expected = IAPRI(ParmInfo)->ia_upri; | |
3951 } else if (ParmInfo.pc_cid == tsLimits.schedPolicy) { | |
3952 Actual = TSPRI(ReadBack)->ts_upri; | |
3953 Expected = TSPRI(ParmInfo)->ts_upri; | |
3954 } else { | |
3955 if ( ThreadPriorityVerbose ) { | |
3956 tty->print_cr("set_lwp_priority: unexpected class in readback: %d\n", ParmInfo.pc_cid); | |
3957 } | |
3958 } | |
3959 | |
3960 if (Actual != Expected) { | |
3961 if ( ThreadPriorityVerbose ) { | |
3962 tty->print_cr ("set_lwp_priority(%d %d) Class=%d: actual=%d vs expected=%d\n", | |
3963 lwpid, newPrio, ReadBack.pc_cid, Actual, Expected); | |
3964 } | |
3965 } | |
3966 #endif | |
3967 | |
3968 return 0; | |
3969 } | |
3970 | |
3971 | |
3972 | |
3973 // Solaris only gives access to 128 real priorities at a time, | |
3974 // so we expand Java's ten to fill this range. This would be better | |
3975 // if we dynamically adjusted relative priorities. | |
3976 // | |
3977 // The ThreadPriorityPolicy option allows us to select 2 different | |
3978 // priority scales. | |
3979 // | |
3980 // ThreadPriorityPolicy=0 | |
3981 // Since the Solaris' default priority is MaximumPriority, we do not | |
3982 // set a priority lower than Max unless a priority lower than | |
3983 // NormPriority is requested. | |
3984 // | |
3985 // ThreadPriorityPolicy=1 | |
3986 // This mode causes the priority table to get filled with | |
3987 // linear values. NormPriority get's mapped to 50% of the | |
3988 // Maximum priority an so on. This will cause VM threads | |
3989 // to get unfair treatment against other Solaris processes | |
3990 // which do not explicitly alter their thread priorities. | |
3991 // | |
3992 | |
3993 | |
3994 int os::java_to_os_priority[MaxPriority + 1] = { | |
3995 -99999, // 0 Entry should never be used | |
3996 | |
3997 0, // 1 MinPriority | |
3998 32, // 2 | |
3999 64, // 3 | |
4000 | |
4001 96, // 4 | |
4002 127, // 5 NormPriority | |
4003 127, // 6 | |
4004 | |
4005 127, // 7 | |
4006 127, // 8 | |
4007 127, // 9 NearMaxPriority | |
4008 | |
4009 127 // 10 MaxPriority | |
4010 }; | |
4011 | |
4012 | |
4013 OSReturn os::set_native_priority(Thread* thread, int newpri) { | |
4014 assert(newpri >= MinimumPriority && newpri <= MaximumPriority, "bad priority mapping"); | |
4015 if ( !UseThreadPriorities ) return OS_OK; | |
4016 int status = thr_setprio(thread->osthread()->thread_id(), newpri); | |
4017 if ( os::Solaris::T2_libthread() || (UseBoundThreads && thread->osthread()->is_vm_created()) ) | |
4018 status |= (set_lwp_priority (thread->osthread()->thread_id(), | |
4019 thread->osthread()->lwp_id(), newpri )); | |
4020 return (status == 0) ? OS_OK : OS_ERR; | |
4021 } | |
4022 | |
4023 | |
4024 OSReturn os::get_native_priority(const Thread* const thread, int *priority_ptr) { | |
4025 int p; | |
4026 if ( !UseThreadPriorities ) { | |
4027 *priority_ptr = NormalPriority; | |
4028 return OS_OK; | |
4029 } | |
4030 int status = thr_getprio(thread->osthread()->thread_id(), &p); | |
4031 if (status != 0) { | |
4032 return OS_ERR; | |
4033 } | |
4034 *priority_ptr = p; | |
4035 return OS_OK; | |
4036 } | |
4037 | |
4038 | |
4039 // Hint to the underlying OS that a task switch would not be good. | |
4040 // Void return because it's a hint and can fail. | |
4041 void os::hint_no_preempt() { | |
4042 schedctl_start(schedctl_init()); | |
4043 } | |
4044 | |
4045 void os::interrupt(Thread* thread) { | |
4046 assert(Thread::current() == thread || Threads_lock->owned_by_self(), "possibility of dangling Thread pointer"); | |
4047 | |
4048 OSThread* osthread = thread->osthread(); | |
4049 | |
4050 int isInterrupted = osthread->interrupted(); | |
4051 if (!isInterrupted) { | |
4052 osthread->set_interrupted(true); | |
4053 OrderAccess::fence(); | |
4054 // os::sleep() is implemented with either poll (NULL,0,timeout) or | |
4055 // by parking on _SleepEvent. If the former, thr_kill will unwedge | |
4056 // the sleeper by SIGINTR, otherwise the unpark() will wake the sleeper. | |
4057 ParkEvent * const slp = thread->_SleepEvent ; | |
4058 if (slp != NULL) slp->unpark() ; | |
4059 } | |
4060 | |
4061 // For JSR166: unpark after setting status but before thr_kill -dl | |
4062 if (thread->is_Java_thread()) { | |
4063 ((JavaThread*)thread)->parker()->unpark(); | |
4064 } | |
4065 | |
4066 // Handle interruptible wait() ... | |
4067 ParkEvent * const ev = thread->_ParkEvent ; | |
4068 if (ev != NULL) ev->unpark() ; | |
4069 | |
4070 // When events are used everywhere for os::sleep, then this thr_kill | |
4071 // will only be needed if UseVMInterruptibleIO is true. | |
4072 | |
4073 if (!isInterrupted) { | |
4074 int status = thr_kill(osthread->thread_id(), os::Solaris::SIGinterrupt()); | |
4075 assert_status(status == 0, status, "thr_kill"); | |
4076 | |
4077 // Bump thread interruption counter | |
4078 RuntimeService::record_thread_interrupt_signaled_count(); | |
4079 } | |
4080 } | |
4081 | |
4082 | |
4083 bool os::is_interrupted(Thread* thread, bool clear_interrupted) { | |
4084 assert(Thread::current() == thread || Threads_lock->owned_by_self(), "possibility of dangling Thread pointer"); | |
4085 | |
4086 OSThread* osthread = thread->osthread(); | |
4087 | |
4088 bool res = osthread->interrupted(); | |
4089 | |
4090 // NOTE that since there is no "lock" around these two operations, | |
4091 // there is the possibility that the interrupted flag will be | |
4092 // "false" but that the interrupt event will be set. This is | |
4093 // intentional. The effect of this is that Object.wait() will appear | |
4094 // to have a spurious wakeup, which is not harmful, and the | |
4095 // possibility is so rare that it is not worth the added complexity | |
4096 // to add yet another lock. It has also been recommended not to put | |
4097 // the interrupted flag into the os::Solaris::Event structure, | |
4098 // because it hides the issue. | |
4099 if (res && clear_interrupted) { | |
4100 osthread->set_interrupted(false); | |
4101 } | |
4102 return res; | |
4103 } | |
4104 | |
4105 | |
4106 void os::print_statistics() { | |
4107 } | |
4108 | |
4109 int os::message_box(const char* title, const char* message) { | |
4110 int i; | |
4111 fdStream err(defaultStream::error_fd()); | |
4112 for (i = 0; i < 78; i++) err.print_raw("="); | |
4113 err.cr(); | |
4114 err.print_raw_cr(title); | |
4115 for (i = 0; i < 78; i++) err.print_raw("-"); | |
4116 err.cr(); | |
4117 err.print_raw_cr(message); | |
4118 for (i = 0; i < 78; i++) err.print_raw("="); | |
4119 err.cr(); | |
4120 | |
4121 char buf[16]; | |
4122 // Prevent process from exiting upon "read error" without consuming all CPU | |
4123 while (::read(0, buf, sizeof(buf)) <= 0) { ::sleep(100); } | |
4124 | |
4125 return buf[0] == 'y' || buf[0] == 'Y'; | |
4126 } | |
4127 | |
4128 // A lightweight implementation that does not suspend the target thread and | |
4129 // thus returns only a hint. Used for profiling only! | |
4130 ExtendedPC os::get_thread_pc(Thread* thread) { | |
4131 // Make sure that it is called by the watcher and the Threads lock is owned. | |
4132 assert(Thread::current()->is_Watcher_thread(), "Must be watcher and own Threads_lock"); | |
4133 // For now, is only used to profile the VM Thread | |
4134 assert(thread->is_VM_thread(), "Can only be called for VMThread"); | |
4135 ExtendedPC epc; | |
4136 | |
4137 GetThreadPC_Callback cb(ProfileVM_lock); | |
4138 OSThread *osthread = thread->osthread(); | |
4139 const int time_to_wait = 400; // 400ms wait for initial response | |
4140 int status = cb.interrupt(thread, time_to_wait); | |
4141 | |
4142 if (cb.is_done() ) { | |
4143 epc = cb.addr(); | |
4144 } else { | |
4145 DEBUG_ONLY(tty->print_cr("Failed to get pc for thread: %d got %d status", | |
4146 osthread->thread_id(), status);); | |
4147 // epc is already NULL | |
4148 } | |
4149 return epc; | |
4150 } | |
4151 | |
4152 | |
4153 // This does not do anything on Solaris. This is basically a hook for being | |
4154 // able to use structured exception handling (thread-local exception filters) on, e.g., Win32. | |
4155 void os::os_exception_wrapper(java_call_t f, JavaValue* value, methodHandle* method, JavaCallArguments* args, Thread* thread) { | |
4156 f(value, method, args, thread); | |
4157 } | |
4158 | |
4159 // This routine may be used by user applications as a "hook" to catch signals. | |
4160 // The user-defined signal handler must pass unrecognized signals to this | |
4161 // routine, and if it returns true (non-zero), then the signal handler must | |
4162 // return immediately. If the flag "abort_if_unrecognized" is true, then this | |
4163 // routine will never retun false (zero), but instead will execute a VM panic | |
4164 // routine kill the process. | |
4165 // | |
4166 // If this routine returns false, it is OK to call it again. This allows | |
4167 // the user-defined signal handler to perform checks either before or after | |
4168 // the VM performs its own checks. Naturally, the user code would be making | |
4169 // a serious error if it tried to handle an exception (such as a null check | |
4170 // or breakpoint) that the VM was generating for its own correct operation. | |
4171 // | |
4172 // This routine may recognize any of the following kinds of signals: | |
4173 // SIGBUS, SIGSEGV, SIGILL, SIGFPE, BREAK_SIGNAL, SIGPIPE, SIGXFSZ, | |
4174 // os::Solaris::SIGasync | |
4175 // It should be consulted by handlers for any of those signals. | |
4176 // It explicitly does not recognize os::Solaris::SIGinterrupt | |
4177 // | |
4178 // The caller of this routine must pass in the three arguments supplied | |
4179 // to the function referred to in the "sa_sigaction" (not the "sa_handler") | |
4180 // field of the structure passed to sigaction(). This routine assumes that | |
4181 // the sa_flags field passed to sigaction() includes SA_SIGINFO and SA_RESTART. | |
4182 // | |
4183 // Note that the VM will print warnings if it detects conflicting signal | |
4184 // handlers, unless invoked with the option "-XX:+AllowUserSignalHandlers". | |
4185 // | |
4186 extern "C" int JVM_handle_solaris_signal(int signo, siginfo_t* siginfo, void* ucontext, int abort_if_unrecognized); | |
4187 | |
4188 | |
4189 void signalHandler(int sig, siginfo_t* info, void* ucVoid) { | |
4190 JVM_handle_solaris_signal(sig, info, ucVoid, true); | |
4191 } | |
4192 | |
4193 /* Do not delete - if guarantee is ever removed, a signal handler (even empty) | |
4194 is needed to provoke threads blocked on IO to return an EINTR | |
4195 Note: this explicitly does NOT call JVM_handle_solaris_signal and | |
4196 does NOT participate in signal chaining due to requirement for | |
4197 NOT setting SA_RESTART to make EINTR work. */ | |
4198 extern "C" void sigINTRHandler(int sig, siginfo_t* info, void* ucVoid) { | |
4199 if (UseSignalChaining) { | |
4200 struct sigaction *actp = os::Solaris::get_chained_signal_action(sig); | |
4201 if (actp && actp->sa_handler) { | |
4202 vm_exit_during_initialization("Signal chaining detected for VM interrupt signal, try -XX:+UseAltSigs"); | |
4203 } | |
4204 } | |
4205 } | |
4206 | |
4207 // This boolean allows users to forward their own non-matching signals | |
4208 // to JVM_handle_solaris_signal, harmlessly. | |
4209 bool os::Solaris::signal_handlers_are_installed = false; | |
4210 | |
4211 // For signal-chaining | |
4212 bool os::Solaris::libjsig_is_loaded = false; | |
4213 typedef struct sigaction *(*get_signal_t)(int); | |
4214 get_signal_t os::Solaris::get_signal_action = NULL; | |
4215 | |
4216 struct sigaction* os::Solaris::get_chained_signal_action(int sig) { | |
4217 struct sigaction *actp = NULL; | |
4218 | |
4219 if ((libjsig_is_loaded) && (sig <= Maxlibjsigsigs)) { | |
4220 // Retrieve the old signal handler from libjsig | |
4221 actp = (*get_signal_action)(sig); | |
4222 } | |
4223 if (actp == NULL) { | |
4224 // Retrieve the preinstalled signal handler from jvm | |
4225 actp = get_preinstalled_handler(sig); | |
4226 } | |
4227 | |
4228 return actp; | |
4229 } | |
4230 | |
4231 static bool call_chained_handler(struct sigaction *actp, int sig, | |
4232 siginfo_t *siginfo, void *context) { | |
4233 // Call the old signal handler | |
4234 if (actp->sa_handler == SIG_DFL) { | |
4235 // It's more reasonable to let jvm treat it as an unexpected exception | |
4236 // instead of taking the default action. | |
4237 return false; | |
4238 } else if (actp->sa_handler != SIG_IGN) { | |
4239 if ((actp->sa_flags & SA_NODEFER) == 0) { | |
4240 // automaticlly block the signal | |
4241 sigaddset(&(actp->sa_mask), sig); | |
4242 } | |
4243 | |
4244 sa_handler_t hand; | |
4245 sa_sigaction_t sa; | |
4246 bool siginfo_flag_set = (actp->sa_flags & SA_SIGINFO) != 0; | |
4247 // retrieve the chained handler | |
4248 if (siginfo_flag_set) { | |
4249 sa = actp->sa_sigaction; | |
4250 } else { | |
4251 hand = actp->sa_handler; | |
4252 } | |
4253 | |
4254 if ((actp->sa_flags & SA_RESETHAND) != 0) { | |
4255 actp->sa_handler = SIG_DFL; | |
4256 } | |
4257 | |
4258 // try to honor the signal mask | |
4259 sigset_t oset; | |
4260 thr_sigsetmask(SIG_SETMASK, &(actp->sa_mask), &oset); | |
4261 | |
4262 // call into the chained handler | |
4263 if (siginfo_flag_set) { | |
4264 (*sa)(sig, siginfo, context); | |
4265 } else { | |
4266 (*hand)(sig); | |
4267 } | |
4268 | |
4269 // restore the signal mask | |
4270 thr_sigsetmask(SIG_SETMASK, &oset, 0); | |
4271 } | |
4272 // Tell jvm's signal handler the signal is taken care of. | |
4273 return true; | |
4274 } | |
4275 | |
4276 bool os::Solaris::chained_handler(int sig, siginfo_t* siginfo, void* context) { | |
4277 bool chained = false; | |
4278 // signal-chaining | |
4279 if (UseSignalChaining) { | |
4280 struct sigaction *actp = get_chained_signal_action(sig); | |
4281 if (actp != NULL) { | |
4282 chained = call_chained_handler(actp, sig, siginfo, context); | |
4283 } | |
4284 } | |
4285 return chained; | |
4286 } | |
4287 | |
4288 struct sigaction* os::Solaris::get_preinstalled_handler(int sig) { | |
4289 assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); | |
4290 if (preinstalled_sigs[sig] != 0) { | |
4291 return &chainedsigactions[sig]; | |
4292 } | |
4293 return NULL; | |
4294 } | |
4295 | |
4296 void os::Solaris::save_preinstalled_handler(int sig, struct sigaction& oldAct) { | |
4297 | |
4298 assert(sig > 0 && sig <= Maxsignum, "vm signal out of expected range"); | |
4299 assert((chainedsigactions != (struct sigaction *)NULL) && (preinstalled_sigs != (int *)NULL) , "signals not yet initialized"); | |
4300 chainedsigactions[sig] = oldAct; | |
4301 preinstalled_sigs[sig] = 1; | |
4302 } | |
4303 | |
4304 void os::Solaris::set_signal_handler(int sig, bool set_installed, bool oktochain) { | |
4305 // Check for overwrite. | |
4306 struct sigaction oldAct; | |
4307 sigaction(sig, (struct sigaction*)NULL, &oldAct); | |
4308 void* oldhand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) | |
4309 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); | |
4310 if (oldhand != CAST_FROM_FN_PTR(void*, SIG_DFL) && | |
4311 oldhand != CAST_FROM_FN_PTR(void*, SIG_IGN) && | |
4312 oldhand != CAST_FROM_FN_PTR(void*, signalHandler)) { | |
4313 if (AllowUserSignalHandlers || !set_installed) { | |
4314 // Do not overwrite; user takes responsibility to forward to us. | |
4315 return; | |
4316 } else if (UseSignalChaining) { | |
4317 if (oktochain) { | |
4318 // save the old handler in jvm | |
4319 save_preinstalled_handler(sig, oldAct); | |
4320 } else { | |
4321 vm_exit_during_initialization("Signal chaining not allowed for VM interrupt signal, try -XX:+UseAltSigs."); | |
4322 } | |
4323 // libjsig also interposes the sigaction() call below and saves the | |
4324 // old sigaction on it own. | |
4325 } else { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4326 fatal(err_msg("Encountered unexpected pre-existing sigaction handler " |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4327 "%#lx for signal %d.", (long)oldhand, sig)); |
0 | 4328 } |
4329 } | |
4330 | |
4331 struct sigaction sigAct; | |
4332 sigfillset(&(sigAct.sa_mask)); | |
4333 sigAct.sa_handler = SIG_DFL; | |
4334 | |
4335 sigAct.sa_sigaction = signalHandler; | |
4336 // Handle SIGSEGV on alternate signal stack if | |
4337 // not using stack banging | |
4338 if (!UseStackBanging && sig == SIGSEGV) { | |
4339 sigAct.sa_flags = SA_SIGINFO | SA_RESTART | SA_ONSTACK; | |
4340 // Interruptible i/o requires SA_RESTART cleared so EINTR | |
4341 // is returned instead of restarting system calls | |
4342 } else if (sig == os::Solaris::SIGinterrupt()) { | |
4343 sigemptyset(&sigAct.sa_mask); | |
4344 sigAct.sa_handler = NULL; | |
4345 sigAct.sa_flags = SA_SIGINFO; | |
4346 sigAct.sa_sigaction = sigINTRHandler; | |
4347 } else { | |
4348 sigAct.sa_flags = SA_SIGINFO | SA_RESTART; | |
4349 } | |
4350 os::Solaris::set_our_sigflags(sig, sigAct.sa_flags); | |
4351 | |
4352 sigaction(sig, &sigAct, &oldAct); | |
4353 | |
4354 void* oldhand2 = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) | |
4355 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); | |
4356 assert(oldhand2 == oldhand, "no concurrent signal handler installation"); | |
4357 } | |
4358 | |
4359 | |
4360 #define DO_SIGNAL_CHECK(sig) \ | |
4361 if (!sigismember(&check_signal_done, sig)) \ | |
4362 os::Solaris::check_signal_handler(sig) | |
4363 | |
4364 // This method is a periodic task to check for misbehaving JNI applications | |
4365 // under CheckJNI, we can add any periodic checks here | |
4366 | |
4367 void os::run_periodic_checks() { | |
4368 // A big source of grief is hijacking virt. addr 0x0 on Solaris, | |
4369 // thereby preventing a NULL checks. | |
4370 if(!check_addr0_done) check_addr0_done = check_addr0(tty); | |
4371 | |
4372 if (check_signals == false) return; | |
4373 | |
4374 // SEGV and BUS if overridden could potentially prevent | |
4375 // generation of hs*.log in the event of a crash, debugging | |
4376 // such a case can be very challenging, so we absolutely | |
4377 // check for the following for a good measure: | |
4378 DO_SIGNAL_CHECK(SIGSEGV); | |
4379 DO_SIGNAL_CHECK(SIGILL); | |
4380 DO_SIGNAL_CHECK(SIGFPE); | |
4381 DO_SIGNAL_CHECK(SIGBUS); | |
4382 DO_SIGNAL_CHECK(SIGPIPE); | |
4383 DO_SIGNAL_CHECK(SIGXFSZ); | |
4384 | |
4385 // ReduceSignalUsage allows the user to override these handlers | |
4386 // see comments at the very top and jvm_solaris.h | |
4387 if (!ReduceSignalUsage) { | |
4388 DO_SIGNAL_CHECK(SHUTDOWN1_SIGNAL); | |
4389 DO_SIGNAL_CHECK(SHUTDOWN2_SIGNAL); | |
4390 DO_SIGNAL_CHECK(SHUTDOWN3_SIGNAL); | |
4391 DO_SIGNAL_CHECK(BREAK_SIGNAL); | |
4392 } | |
4393 | |
4394 // See comments above for using JVM1/JVM2 and UseAltSigs | |
4395 DO_SIGNAL_CHECK(os::Solaris::SIGinterrupt()); | |
4396 DO_SIGNAL_CHECK(os::Solaris::SIGasync()); | |
4397 | |
4398 } | |
4399 | |
4400 typedef int (*os_sigaction_t)(int, const struct sigaction *, struct sigaction *); | |
4401 | |
4402 static os_sigaction_t os_sigaction = NULL; | |
4403 | |
4404 void os::Solaris::check_signal_handler(int sig) { | |
4405 char buf[O_BUFLEN]; | |
4406 address jvmHandler = NULL; | |
4407 | |
4408 struct sigaction act; | |
4409 if (os_sigaction == NULL) { | |
4410 // only trust the default sigaction, in case it has been interposed | |
4411 os_sigaction = (os_sigaction_t)dlsym(RTLD_DEFAULT, "sigaction"); | |
4412 if (os_sigaction == NULL) return; | |
4413 } | |
4414 | |
4415 os_sigaction(sig, (struct sigaction*)NULL, &act); | |
4416 | |
4417 address thisHandler = (act.sa_flags & SA_SIGINFO) | |
4418 ? CAST_FROM_FN_PTR(address, act.sa_sigaction) | |
4419 : CAST_FROM_FN_PTR(address, act.sa_handler) ; | |
4420 | |
4421 | |
4422 switch(sig) { | |
4423 case SIGSEGV: | |
4424 case SIGBUS: | |
4425 case SIGFPE: | |
4426 case SIGPIPE: | |
4427 case SIGXFSZ: | |
4428 case SIGILL: | |
4429 jvmHandler = CAST_FROM_FN_PTR(address, signalHandler); | |
4430 break; | |
4431 | |
4432 case SHUTDOWN1_SIGNAL: | |
4433 case SHUTDOWN2_SIGNAL: | |
4434 case SHUTDOWN3_SIGNAL: | |
4435 case BREAK_SIGNAL: | |
4436 jvmHandler = (address)user_handler(); | |
4437 break; | |
4438 | |
4439 default: | |
4440 int intrsig = os::Solaris::SIGinterrupt(); | |
4441 int asynsig = os::Solaris::SIGasync(); | |
4442 | |
4443 if (sig == intrsig) { | |
4444 jvmHandler = CAST_FROM_FN_PTR(address, sigINTRHandler); | |
4445 } else if (sig == asynsig) { | |
4446 jvmHandler = CAST_FROM_FN_PTR(address, signalHandler); | |
4447 } else { | |
4448 return; | |
4449 } | |
4450 break; | |
4451 } | |
4452 | |
4453 | |
4454 if (thisHandler != jvmHandler) { | |
4455 tty->print("Warning: %s handler ", exception_name(sig, buf, O_BUFLEN)); | |
4456 tty->print("expected:%s", get_signal_handler_name(jvmHandler, buf, O_BUFLEN)); | |
4457 tty->print_cr(" found:%s", get_signal_handler_name(thisHandler, buf, O_BUFLEN)); | |
4458 // No need to check this sig any longer | |
4459 sigaddset(&check_signal_done, sig); | |
4460 } else if(os::Solaris::get_our_sigflags(sig) != 0 && act.sa_flags != os::Solaris::get_our_sigflags(sig)) { | |
4461 tty->print("Warning: %s handler flags ", exception_name(sig, buf, O_BUFLEN)); | |
4462 tty->print("expected:" PTR32_FORMAT, os::Solaris::get_our_sigflags(sig)); | |
4463 tty->print_cr(" found:" PTR32_FORMAT, act.sa_flags); | |
4464 // No need to check this sig any longer | |
4465 sigaddset(&check_signal_done, sig); | |
4466 } | |
4467 | |
4468 // Print all the signal handler state | |
4469 if (sigismember(&check_signal_done, sig)) { | |
4470 print_signal_handlers(tty, buf, O_BUFLEN); | |
4471 } | |
4472 | |
4473 } | |
4474 | |
4475 void os::Solaris::install_signal_handlers() { | |
4476 bool libjsigdone = false; | |
4477 signal_handlers_are_installed = true; | |
4478 | |
4479 // signal-chaining | |
4480 typedef void (*signal_setting_t)(); | |
4481 signal_setting_t begin_signal_setting = NULL; | |
4482 signal_setting_t end_signal_setting = NULL; | |
4483 begin_signal_setting = CAST_TO_FN_PTR(signal_setting_t, | |
4484 dlsym(RTLD_DEFAULT, "JVM_begin_signal_setting")); | |
4485 if (begin_signal_setting != NULL) { | |
4486 end_signal_setting = CAST_TO_FN_PTR(signal_setting_t, | |
4487 dlsym(RTLD_DEFAULT, "JVM_end_signal_setting")); | |
4488 get_signal_action = CAST_TO_FN_PTR(get_signal_t, | |
4489 dlsym(RTLD_DEFAULT, "JVM_get_signal_action")); | |
4490 get_libjsig_version = CAST_TO_FN_PTR(version_getting_t, | |
4491 dlsym(RTLD_DEFAULT, "JVM_get_libjsig_version")); | |
4492 libjsig_is_loaded = true; | |
4493 if (os::Solaris::get_libjsig_version != NULL) { | |
4494 libjsigversion = (*os::Solaris::get_libjsig_version)(); | |
4495 } | |
4496 assert(UseSignalChaining, "should enable signal-chaining"); | |
4497 } | |
4498 if (libjsig_is_loaded) { | |
4499 // Tell libjsig jvm is setting signal handlers | |
4500 (*begin_signal_setting)(); | |
4501 } | |
4502 | |
4503 set_signal_handler(SIGSEGV, true, true); | |
4504 set_signal_handler(SIGPIPE, true, true); | |
4505 set_signal_handler(SIGXFSZ, true, true); | |
4506 set_signal_handler(SIGBUS, true, true); | |
4507 set_signal_handler(SIGILL, true, true); | |
4508 set_signal_handler(SIGFPE, true, true); | |
4509 | |
4510 | |
4511 if (os::Solaris::SIGinterrupt() > OLDMAXSIGNUM || os::Solaris::SIGasync() > OLDMAXSIGNUM) { | |
4512 | |
4513 // Pre-1.4.1 Libjsig limited to signal chaining signals <= 32 so | |
4514 // can not register overridable signals which might be > 32 | |
4515 if (libjsig_is_loaded && libjsigversion <= JSIG_VERSION_1_4_1) { | |
4516 // Tell libjsig jvm has finished setting signal handlers | |
4517 (*end_signal_setting)(); | |
4518 libjsigdone = true; | |
4519 } | |
4520 } | |
4521 | |
4522 // Never ok to chain our SIGinterrupt | |
4523 set_signal_handler(os::Solaris::SIGinterrupt(), true, false); | |
4524 set_signal_handler(os::Solaris::SIGasync(), true, true); | |
4525 | |
4526 if (libjsig_is_loaded && !libjsigdone) { | |
4527 // Tell libjsig jvm finishes setting signal handlers | |
4528 (*end_signal_setting)(); | |
4529 } | |
4530 | |
4531 // We don't activate signal checker if libjsig is in place, we trust ourselves | |
4532 // and if UserSignalHandler is installed all bets are off | |
4533 if (CheckJNICalls) { | |
4534 if (libjsig_is_loaded) { | |
4535 tty->print_cr("Info: libjsig is activated, all active signal checking is disabled"); | |
4536 check_signals = false; | |
4537 } | |
4538 if (AllowUserSignalHandlers) { | |
4539 tty->print_cr("Info: AllowUserSignalHandlers is activated, all active signal checking is disabled"); | |
4540 check_signals = false; | |
4541 } | |
4542 } | |
4543 } | |
4544 | |
4545 | |
4546 void report_error(const char* file_name, int line_no, const char* title, const char* format, ...); | |
4547 | |
4548 const char * signames[] = { | |
4549 "SIG0", | |
4550 "SIGHUP", "SIGINT", "SIGQUIT", "SIGILL", "SIGTRAP", | |
4551 "SIGABRT", "SIGEMT", "SIGFPE", "SIGKILL", "SIGBUS", | |
4552 "SIGSEGV", "SIGSYS", "SIGPIPE", "SIGALRM", "SIGTERM", | |
4553 "SIGUSR1", "SIGUSR2", "SIGCLD", "SIGPWR", "SIGWINCH", | |
4554 "SIGURG", "SIGPOLL", "SIGSTOP", "SIGTSTP", "SIGCONT", | |
4555 "SIGTTIN", "SIGTTOU", "SIGVTALRM", "SIGPROF", "SIGXCPU", | |
4556 "SIGXFSZ", "SIGWAITING", "SIGLWP", "SIGFREEZE", "SIGTHAW", | |
4557 "SIGCANCEL", "SIGLOST" | |
4558 }; | |
4559 | |
4560 const char* os::exception_name(int exception_code, char* buf, size_t size) { | |
4561 if (0 < exception_code && exception_code <= SIGRTMAX) { | |
4562 // signal | |
4563 if (exception_code < sizeof(signames)/sizeof(const char*)) { | |
4564 jio_snprintf(buf, size, "%s", signames[exception_code]); | |
4565 } else { | |
4566 jio_snprintf(buf, size, "SIG%d", exception_code); | |
4567 } | |
4568 return buf; | |
4569 } else { | |
4570 return NULL; | |
4571 } | |
4572 } | |
4573 | |
4574 // (Static) wrappers for the new libthread API | |
4575 int_fnP_thread_t_iP_uP_stack_tP_gregset_t os::Solaris::_thr_getstate; | |
4576 int_fnP_thread_t_i_gregset_t os::Solaris::_thr_setstate; | |
4577 int_fnP_thread_t_i os::Solaris::_thr_setmutator; | |
4578 int_fnP_thread_t os::Solaris::_thr_suspend_mutator; | |
4579 int_fnP_thread_t os::Solaris::_thr_continue_mutator; | |
4580 | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4581 // (Static) wrapper for getisax(2) call. |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4582 os::Solaris::getisax_func_t os::Solaris::_getisax = 0; |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4583 |
0 | 4584 // (Static) wrappers for the liblgrp API |
4585 os::Solaris::lgrp_home_func_t os::Solaris::_lgrp_home; | |
4586 os::Solaris::lgrp_init_func_t os::Solaris::_lgrp_init; | |
4587 os::Solaris::lgrp_fini_func_t os::Solaris::_lgrp_fini; | |
4588 os::Solaris::lgrp_root_func_t os::Solaris::_lgrp_root; | |
4589 os::Solaris::lgrp_children_func_t os::Solaris::_lgrp_children; | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
4590 os::Solaris::lgrp_resources_func_t os::Solaris::_lgrp_resources; |
0 | 4591 os::Solaris::lgrp_nlgrps_func_t os::Solaris::_lgrp_nlgrps; |
4592 os::Solaris::lgrp_cookie_stale_func_t os::Solaris::_lgrp_cookie_stale; | |
4593 os::Solaris::lgrp_cookie_t os::Solaris::_lgrp_cookie = 0; | |
4594 | |
4595 // (Static) wrapper for meminfo() call. | |
4596 os::Solaris::meminfo_func_t os::Solaris::_meminfo = 0; | |
4597 | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4598 static address resolve_symbol_lazy(const char* name) { |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4599 address addr = (address) dlsym(RTLD_DEFAULT, name); |
0 | 4600 if(addr == NULL) { |
4601 // RTLD_DEFAULT was not defined on some early versions of 2.5.1 | |
4602 addr = (address) dlsym(RTLD_NEXT, name); | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4603 } |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4604 return addr; |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4605 } |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4606 |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4607 static address resolve_symbol(const char* name) { |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4608 address addr = resolve_symbol_lazy(name); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4609 if(addr == NULL) { |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4610 fatal(dlerror()); |
0 | 4611 } |
4612 return addr; | |
4613 } | |
4614 | |
4615 | |
4616 | |
4617 // isT2_libthread() | |
4618 // | |
4619 // Routine to determine if we are currently using the new T2 libthread. | |
4620 // | |
4621 // We determine if we are using T2 by reading /proc/self/lstatus and | |
4622 // looking for a thread with the ASLWP bit set. If we find this status | |
4623 // bit set, we must assume that we are NOT using T2. The T2 team | |
4624 // has approved this algorithm. | |
4625 // | |
4626 // We need to determine if we are running with the new T2 libthread | |
4627 // since setting native thread priorities is handled differently | |
4628 // when using this library. All threads created using T2 are bound | |
4629 // threads. Calling thr_setprio is meaningless in this case. | |
4630 // | |
4631 bool isT2_libthread() { | |
4632 static prheader_t * lwpArray = NULL; | |
4633 static int lwpSize = 0; | |
4634 static int lwpFile = -1; | |
4635 lwpstatus_t * that; | |
4636 char lwpName [128]; | |
4637 bool isT2 = false; | |
4638 | |
4639 #define ADR(x) ((uintptr_t)(x)) | |
4640 #define LWPINDEX(ary,ix) ((lwpstatus_t *)(((ary)->pr_entsize * (ix)) + (ADR((ary) + 1)))) | |
4641 | |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4642 lwpFile = open("/proc/self/lstatus", O_RDONLY, 0); |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4643 if (lwpFile < 0) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4644 if (ThreadPriorityVerbose) warning ("Couldn't open /proc/self/lstatus\n"); |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4645 return false; |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4646 } |
0 | 4647 lwpSize = 16*1024; |
4648 for (;;) { | |
4649 lseek (lwpFile, 0, SEEK_SET); | |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4650 lwpArray = (prheader_t *)NEW_C_HEAP_ARRAY(char, lwpSize); |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4651 if (read(lwpFile, lwpArray, lwpSize) < 0) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4652 if (ThreadPriorityVerbose) warning("Error reading /proc/self/lstatus\n"); |
0 | 4653 break; |
4654 } | |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4655 if ((lwpArray->pr_nent * lwpArray->pr_entsize) <= lwpSize) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4656 // We got a good snapshot - now iterate over the list. |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4657 int aslwpcount = 0; |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4658 for (int i = 0; i < lwpArray->pr_nent; i++ ) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4659 that = LWPINDEX(lwpArray,i); |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4660 if (that->pr_flags & PR_ASLWP) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4661 aslwpcount++; |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4662 } |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4663 } |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4664 if (aslwpcount == 0) isT2 = true; |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4665 break; |
0 | 4666 } |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4667 lwpSize = lwpArray->pr_nent * lwpArray->pr_entsize; |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4668 FREE_C_HEAP_ARRAY(char, lwpArray); // retry. |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4669 } |
0 | 4670 |
4671 FREE_C_HEAP_ARRAY(char, lwpArray); | |
4672 close (lwpFile); | |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4673 if (ThreadPriorityVerbose) { |
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4674 if (isT2) tty->print_cr("We are running with a T2 libthread\n"); |
0 | 4675 else tty->print_cr("We are not running with a T2 libthread\n"); |
4676 } | |
89
b97de546208e
6671882: memory access after free in solaris/vm/os_solaris.cpp
xlu
parents:
79
diff
changeset
|
4677 return isT2; |
0 | 4678 } |
4679 | |
4680 | |
4681 void os::Solaris::libthread_init() { | |
4682 address func = (address)dlsym(RTLD_DEFAULT, "_thr_suspend_allmutators"); | |
4683 | |
4684 // Determine if we are running with the new T2 libthread | |
4685 os::Solaris::set_T2_libthread(isT2_libthread()); | |
4686 | |
4687 lwp_priocntl_init(); | |
4688 | |
4689 // RTLD_DEFAULT was not defined on some early versions of 5.5.1 | |
4690 if(func == NULL) { | |
4691 func = (address) dlsym(RTLD_NEXT, "_thr_suspend_allmutators"); | |
4692 // Guarantee that this VM is running on an new enough OS (5.6 or | |
4693 // later) that it will have a new enough libthread.so. | |
4694 guarantee(func != NULL, "libthread.so is too old."); | |
4695 } | |
4696 | |
4697 // Initialize the new libthread getstate API wrappers | |
4698 func = resolve_symbol("thr_getstate"); | |
4699 os::Solaris::set_thr_getstate(CAST_TO_FN_PTR(int_fnP_thread_t_iP_uP_stack_tP_gregset_t, func)); | |
4700 | |
4701 func = resolve_symbol("thr_setstate"); | |
4702 os::Solaris::set_thr_setstate(CAST_TO_FN_PTR(int_fnP_thread_t_i_gregset_t, func)); | |
4703 | |
4704 func = resolve_symbol("thr_setmutator"); | |
4705 os::Solaris::set_thr_setmutator(CAST_TO_FN_PTR(int_fnP_thread_t_i, func)); | |
4706 | |
4707 func = resolve_symbol("thr_suspend_mutator"); | |
4708 os::Solaris::set_thr_suspend_mutator(CAST_TO_FN_PTR(int_fnP_thread_t, func)); | |
4709 | |
4710 func = resolve_symbol("thr_continue_mutator"); | |
4711 os::Solaris::set_thr_continue_mutator(CAST_TO_FN_PTR(int_fnP_thread_t, func)); | |
4712 | |
4713 int size; | |
4714 void (*handler_info_func)(address *, int *); | |
4715 handler_info_func = CAST_TO_FN_PTR(void (*)(address *, int *), resolve_symbol("thr_sighndlrinfo")); | |
4716 handler_info_func(&handler_start, &size); | |
4717 handler_end = handler_start + size; | |
4718 } | |
4719 | |
4720 | |
4721 int_fnP_mutex_tP os::Solaris::_mutex_lock; | |
4722 int_fnP_mutex_tP os::Solaris::_mutex_trylock; | |
4723 int_fnP_mutex_tP os::Solaris::_mutex_unlock; | |
4724 int_fnP_mutex_tP_i_vP os::Solaris::_mutex_init; | |
4725 int_fnP_mutex_tP os::Solaris::_mutex_destroy; | |
4726 int os::Solaris::_mutex_scope = USYNC_THREAD; | |
4727 | |
4728 int_fnP_cond_tP_mutex_tP_timestruc_tP os::Solaris::_cond_timedwait; | |
4729 int_fnP_cond_tP_mutex_tP os::Solaris::_cond_wait; | |
4730 int_fnP_cond_tP os::Solaris::_cond_signal; | |
4731 int_fnP_cond_tP os::Solaris::_cond_broadcast; | |
4732 int_fnP_cond_tP_i_vP os::Solaris::_cond_init; | |
4733 int_fnP_cond_tP os::Solaris::_cond_destroy; | |
4734 int os::Solaris::_cond_scope = USYNC_THREAD; | |
4735 | |
4736 void os::Solaris::synchronization_init() { | |
4737 if(UseLWPSynchronization) { | |
4738 os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("_lwp_mutex_lock"))); | |
4739 os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("_lwp_mutex_trylock"))); | |
4740 os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("_lwp_mutex_unlock"))); | |
4741 os::Solaris::set_mutex_init(lwp_mutex_init); | |
4742 os::Solaris::set_mutex_destroy(lwp_mutex_destroy); | |
4743 os::Solaris::set_mutex_scope(USYNC_THREAD); | |
4744 | |
4745 os::Solaris::set_cond_timedwait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP_timestruc_tP, resolve_symbol("_lwp_cond_timedwait"))); | |
4746 os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("_lwp_cond_wait"))); | |
4747 os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_signal"))); | |
4748 os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("_lwp_cond_broadcast"))); | |
4749 os::Solaris::set_cond_init(lwp_cond_init); | |
4750 os::Solaris::set_cond_destroy(lwp_cond_destroy); | |
4751 os::Solaris::set_cond_scope(USYNC_THREAD); | |
4752 } | |
4753 else { | |
4754 os::Solaris::set_mutex_scope(USYNC_THREAD); | |
4755 os::Solaris::set_cond_scope(USYNC_THREAD); | |
4756 | |
4757 if(UsePthreads) { | |
4758 os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_lock"))); | |
4759 os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_trylock"))); | |
4760 os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_unlock"))); | |
4761 os::Solaris::set_mutex_init(pthread_mutex_default_init); | |
4762 os::Solaris::set_mutex_destroy(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("pthread_mutex_destroy"))); | |
4763 | |
4764 os::Solaris::set_cond_timedwait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP_timestruc_tP, resolve_symbol("pthread_cond_timedwait"))); | |
4765 os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("pthread_cond_wait"))); | |
4766 os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_signal"))); | |
4767 os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_broadcast"))); | |
4768 os::Solaris::set_cond_init(pthread_cond_default_init); | |
4769 os::Solaris::set_cond_destroy(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("pthread_cond_destroy"))); | |
4770 } | |
4771 else { | |
4772 os::Solaris::set_mutex_lock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_lock"))); | |
4773 os::Solaris::set_mutex_trylock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_trylock"))); | |
4774 os::Solaris::set_mutex_unlock(CAST_TO_FN_PTR(int_fnP_mutex_tP, resolve_symbol("mutex_unlock"))); | |
4775 os::Solaris::set_mutex_init(::mutex_init); | |
4776 os::Solaris::set_mutex_destroy(::mutex_destroy); | |
4777 | |
4778 os::Solaris::set_cond_timedwait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP_timestruc_tP, resolve_symbol("cond_timedwait"))); | |
4779 os::Solaris::set_cond_wait(CAST_TO_FN_PTR(int_fnP_cond_tP_mutex_tP, resolve_symbol("cond_wait"))); | |
4780 os::Solaris::set_cond_signal(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("cond_signal"))); | |
4781 os::Solaris::set_cond_broadcast(CAST_TO_FN_PTR(int_fnP_cond_tP, resolve_symbol("cond_broadcast"))); | |
4782 os::Solaris::set_cond_init(::cond_init); | |
4783 os::Solaris::set_cond_destroy(::cond_destroy); | |
4784 } | |
4785 } | |
4786 } | |
4787 | |
462
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4788 bool os::Solaris::liblgrp_init() { |
267
9d6a3a6891f8
6720130: NUMA allocator: The linux version should search for libnuma.so.1
iveresov
parents:
144
diff
changeset
|
4789 void *handle = dlopen("liblgrp.so.1", RTLD_LAZY); |
0 | 4790 if (handle != NULL) { |
4791 os::Solaris::set_lgrp_home(CAST_TO_FN_PTR(lgrp_home_func_t, dlsym(handle, "lgrp_home"))); | |
4792 os::Solaris::set_lgrp_init(CAST_TO_FN_PTR(lgrp_init_func_t, dlsym(handle, "lgrp_init"))); | |
4793 os::Solaris::set_lgrp_fini(CAST_TO_FN_PTR(lgrp_fini_func_t, dlsym(handle, "lgrp_fini"))); | |
4794 os::Solaris::set_lgrp_root(CAST_TO_FN_PTR(lgrp_root_func_t, dlsym(handle, "lgrp_root"))); | |
4795 os::Solaris::set_lgrp_children(CAST_TO_FN_PTR(lgrp_children_func_t, dlsym(handle, "lgrp_children"))); | |
144
e3729351c946
6697534: Premature GC and invalid lgrp selection with NUMA-aware allocator.
iveresov
parents:
141
diff
changeset
|
4796 os::Solaris::set_lgrp_resources(CAST_TO_FN_PTR(lgrp_resources_func_t, dlsym(handle, "lgrp_resources"))); |
0 | 4797 os::Solaris::set_lgrp_nlgrps(CAST_TO_FN_PTR(lgrp_nlgrps_func_t, dlsym(handle, "lgrp_nlgrps"))); |
4798 os::Solaris::set_lgrp_cookie_stale(CAST_TO_FN_PTR(lgrp_cookie_stale_func_t, | |
4799 dlsym(handle, "lgrp_cookie_stale"))); | |
4800 | |
4801 lgrp_cookie_t c = lgrp_init(LGRP_VIEW_CALLER); | |
4802 set_lgrp_cookie(c); | |
462
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4803 return true; |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4804 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4805 return false; |
0 | 4806 } |
4807 | |
4808 void os::Solaris::misc_sym_init() { | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4809 address func; |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4810 |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4811 // getisax |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4812 func = resolve_symbol_lazy("getisax"); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4813 if (func != NULL) { |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4814 os::Solaris::_getisax = CAST_TO_FN_PTR(getisax_func_t, func); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4815 } |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4816 |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4817 // meminfo |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4818 func = resolve_symbol_lazy("meminfo"); |
0 | 4819 if (func != NULL) { |
4820 os::Solaris::set_meminfo(CAST_TO_FN_PTR(meminfo_func_t, func)); | |
4821 } | |
4822 } | |
4823 | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4824 uint_t os::Solaris::getisax(uint32_t* array, uint_t n) { |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4825 assert(_getisax != NULL, "_getisax not set"); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4826 return _getisax(array, n); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4827 } |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4828 |
0 | 4829 // Symbol doesn't exist in Solaris 8 pset.h |
4830 #ifndef PS_MYID | |
4831 #define PS_MYID -3 | |
4832 #endif | |
4833 | |
4834 // int pset_getloadavg(psetid_t pset, double loadavg[], int nelem); | |
4835 typedef long (*pset_getloadavg_type)(psetid_t pset, double loadavg[], int nelem); | |
4836 static pset_getloadavg_type pset_getloadavg_ptr = NULL; | |
4837 | |
4838 void init_pset_getloadavg_ptr(void) { | |
4839 pset_getloadavg_ptr = | |
4840 (pset_getloadavg_type)dlsym(RTLD_DEFAULT, "pset_getloadavg"); | |
4841 if (PrintMiscellaneous && Verbose && pset_getloadavg_ptr == NULL) { | |
4842 warning("pset_getloadavg function not found"); | |
4843 } | |
4844 } | |
4845 | |
4846 int os::Solaris::_dev_zero_fd = -1; | |
4847 | |
4848 // this is called _before_ the global arguments have been parsed | |
4849 void os::init(void) { | |
4850 _initial_pid = getpid(); | |
4851 | |
4852 max_hrtime = first_hrtime = gethrtime(); | |
4853 | |
4854 init_random(1234567); | |
4855 | |
4856 page_size = sysconf(_SC_PAGESIZE); | |
4857 if (page_size == -1) | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4858 fatal(err_msg("os_solaris.cpp: os::init: sysconf failed (%s)", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4859 strerror(errno))); |
0 | 4860 init_page_sizes((size_t) page_size); |
4861 | |
4862 Solaris::initialize_system_info(); | |
4863 | |
641
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4864 // Initialize misc. symbols as soon as possible, so we can use them |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4865 // if we need them. |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4866 Solaris::misc_sym_init(); |
6af0a709d52b
6812587: Use auxv to determine SPARC hardware features on Solaris
twisti
parents:
548
diff
changeset
|
4867 |
0 | 4868 int fd = open("/dev/zero", O_RDWR); |
4869 if (fd < 0) { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1353
diff
changeset
|
4870 fatal(err_msg("os::init: cannot open /dev/zero (%s)", strerror(errno))); |
0 | 4871 } else { |
4872 Solaris::set_dev_zero_fd(fd); | |
4873 | |
4874 // Close on exec, child won't inherit. | |
4875 fcntl(fd, F_SETFD, FD_CLOEXEC); | |
4876 } | |
4877 | |
4878 clock_tics_per_sec = CLK_TCK; | |
4879 | |
4880 // check if dladdr1() exists; dladdr1 can provide more information than | |
4881 // dladdr for os::dll_address_to_function_name. It comes with SunOS 5.9 | |
4882 // and is available on linker patches for 5.7 and 5.8. | |
4883 // libdl.so must have been loaded, this call is just an entry lookup | |
4884 void * hdl = dlopen("libdl.so", RTLD_NOW); | |
4885 if (hdl) | |
4886 dladdr1_func = CAST_TO_FN_PTR(dladdr1_func_type, dlsym(hdl, "dladdr1")); | |
4887 | |
4888 // (Solaris only) this switches to calls that actually do locking. | |
4889 ThreadCritical::initialize(); | |
4890 | |
4891 main_thread = thr_self(); | |
4892 | |
4893 // Constant minimum stack size allowed. It must be at least | |
4894 // the minimum of what the OS supports (thr_min_stack()), and | |
4895 // enough to allow the thread to get to user bytecode execution. | |
4896 Solaris::min_stack_allowed = MAX2(thr_min_stack(), Solaris::min_stack_allowed); | |
4897 // If the pagesize of the VM is greater than 8K determine the appropriate | |
4898 // number of initial guard pages. The user can change this with the | |
4899 // command line arguments, if needed. | |
4900 if (vm_page_size() > 8*K) { | |
4901 StackYellowPages = 1; | |
4902 StackRedPages = 1; | |
4903 StackShadowPages = round_to((StackShadowPages*8*K), vm_page_size()) / vm_page_size(); | |
4904 } | |
4905 } | |
4906 | |
4907 // To install functions for atexit system call | |
4908 extern "C" { | |
4909 static void perfMemory_exit_helper() { | |
4910 perfMemory_exit(); | |
4911 } | |
4912 } | |
4913 | |
4914 // this is called _after_ the global arguments have been parsed | |
4915 jint os::init_2(void) { | |
4916 // try to enable extended file IO ASAP, see 6431278 | |
4917 os::Solaris::try_enable_extended_io(); | |
4918 | |
4919 // Allocate a single page and mark it as readable for safepoint polling. Also | |
4920 // use this first mmap call to check support for MAP_ALIGN. | |
4921 address polling_page = (address)Solaris::mmap_chunk((char*)page_size, | |
4922 page_size, | |
4923 MAP_PRIVATE | MAP_ALIGN, | |
4924 PROT_READ); | |
4925 if (polling_page == NULL) { | |
4926 has_map_align = false; | |
4927 polling_page = (address)Solaris::mmap_chunk(NULL, page_size, MAP_PRIVATE, | |
4928 PROT_READ); | |
4929 } | |
4930 | |
4931 os::set_polling_page(polling_page); | |
4932 | |
4933 #ifndef PRODUCT | |
4934 if( Verbose && PrintMiscellaneous ) | |
4935 tty->print("[SafePoint Polling address: " INTPTR_FORMAT "]\n", (intptr_t)polling_page); | |
4936 #endif | |
4937 | |
4938 if (!UseMembar) { | |
4939 address mem_serialize_page = (address)Solaris::mmap_chunk( NULL, page_size, MAP_PRIVATE, PROT_READ | PROT_WRITE ); | |
4940 guarantee( mem_serialize_page != NULL, "mmap Failed for memory serialize page"); | |
4941 os::set_memory_serialize_page( mem_serialize_page ); | |
4942 | |
4943 #ifndef PRODUCT | |
4944 if(Verbose && PrintMiscellaneous) | |
4945 tty->print("[Memory Serialize Page address: " INTPTR_FORMAT "]\n", (intptr_t)mem_serialize_page); | |
4946 #endif | |
4947 } | |
4948 | |
4949 FLAG_SET_DEFAULT(UseLargePages, os::large_page_init()); | |
4950 | |
4951 // Check minimum allowable stack size for thread creation and to initialize | |
4952 // the java system classes, including StackOverflowError - depends on page | |
4953 // size. Add a page for compiler2 recursion in main thread. | |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4954 // Add in 2*BytesPerWord times page size to account for VM stack during |
0 | 4955 // class initialization depending on 32 or 64 bit VM. |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4956 os::Solaris::min_stack_allowed = MAX2(os::Solaris::min_stack_allowed, |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4957 (size_t)(StackYellowPages+StackRedPages+StackShadowPages+ |
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4958 2*BytesPerWord COMPILER2_PRESENT(+1)) * page_size); |
0 | 4959 |
4960 size_t threadStackSizeInBytes = ThreadStackSize * K; | |
4961 if (threadStackSizeInBytes != 0 && | |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4962 threadStackSizeInBytes < os::Solaris::min_stack_allowed) { |
0 | 4963 tty->print_cr("\nThe stack size specified is too small, Specify at least %dk", |
1867
b6aedd1acdc0
6983240: guarantee((Solaris::min_stack_allowed >= (StackYellowPages+StackRedPages...) wrong
coleenp
parents:
1865
diff
changeset
|
4964 os::Solaris::min_stack_allowed/K); |
0 | 4965 return JNI_ERR; |
4966 } | |
4967 | |
4968 // For 64kbps there will be a 64kb page size, which makes | |
4969 // the usable default stack size quite a bit less. Increase the | |
4970 // stack for 64kb (or any > than 8kb) pages, this increases | |
4971 // virtual memory fragmentation (since we're not creating the | |
4972 // stack on a power of 2 boundary. The real fix for this | |
4973 // should be to fix the guard page mechanism. | |
4974 | |
4975 if (vm_page_size() > 8*K) { | |
4976 threadStackSizeInBytes = (threadStackSizeInBytes != 0) | |
4977 ? threadStackSizeInBytes + | |
4978 ((StackYellowPages + StackRedPages) * vm_page_size()) | |
4979 : 0; | |
4980 ThreadStackSize = threadStackSizeInBytes/K; | |
4981 } | |
4982 | |
4983 // Make the stack size a multiple of the page size so that | |
4984 // the yellow/red zones can be guarded. | |
4985 JavaThread::set_stack_size_at_create(round_to(threadStackSizeInBytes, | |
4986 vm_page_size())); | |
4987 | |
4988 Solaris::libthread_init(); | |
462
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4989 |
0 | 4990 if (UseNUMA) { |
462
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4991 if (!Solaris::liblgrp_init()) { |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4992 UseNUMA = false; |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4993 } else { |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4994 size_t lgrp_limit = os::numa_get_groups_num(); |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4995 int *lgrp_ids = NEW_C_HEAP_ARRAY(int, lgrp_limit); |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4996 size_t lgrp_num = os::numa_get_leaf_groups(lgrp_ids, lgrp_limit); |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4997 FREE_C_HEAP_ARRAY(int, lgrp_ids); |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4998 if (lgrp_num < 2) { |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
4999 // There's only one locality group, disable NUMA. |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5000 UseNUMA = false; |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5001 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5002 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5003 if (!UseNUMA && ForceNUMA) { |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5004 UseNUMA = true; |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5005 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5006 } |
85f1b9537f70
6779436: NUMA allocator: libnuma expects certain size of the buffer in numa_node_to_cpus()
iveresov
parents:
439
diff
changeset
|
5007 |
0 | 5008 Solaris::signal_sets_init(); |
5009 Solaris::init_signal_mem(); | |
5010 Solaris::install_signal_handlers(); | |
5011 | |
5012 if (libjsigversion < JSIG_VERSION_1_4_1) { | |
5013 Maxlibjsigsigs = OLDMAXSIGNUM; | |
5014 } | |
5015 | |
5016 // initialize synchronization primitives to use either thread or | |
5017 // lwp synchronization (controlled by UseLWPSynchronization) | |
5018 Solaris::synchronization_init(); | |
5019 | |
5020 if (MaxFDLimit) { | |
5021 // set the number of file descriptors to max. print out error | |
5022 // if getrlimit/setrlimit fails but continue regardless. | |
5023 struct rlimit nbr_files; | |
5024 int status = getrlimit(RLIMIT_NOFILE, &nbr_files); | |
5025 if (status != 0) { | |
5026 if (PrintMiscellaneous && (Verbose || WizardMode)) | |
5027 perror("os::init_2 getrlimit failed"); | |
5028 } else { | |
5029 nbr_files.rlim_cur = nbr_files.rlim_max; | |
5030 status = setrlimit(RLIMIT_NOFILE, &nbr_files); | |
5031 if (status != 0) { | |
5032 if (PrintMiscellaneous && (Verbose || WizardMode)) | |
5033 perror("os::init_2 setrlimit failed"); | |
5034 } | |
5035 } | |
5036 } | |
5037 | |
5038 // Initialize HPI. | |
5039 jint hpi_result = hpi::initialize(); | |
5040 if (hpi_result != JNI_OK) { | |
5041 tty->print_cr("There was an error trying to initialize the HPI library."); | |
5042 return hpi_result; | |
5043 } | |
5044 | |
5045 // Calculate theoretical max. size of Threads to guard gainst | |
5046 // artifical out-of-memory situations, where all available address- | |
5047 // space has been reserved by thread stacks. Default stack size is 1Mb. | |
5048 size_t pre_thread_stack_size = (JavaThread::stack_size_at_create()) ? | |
5049 JavaThread::stack_size_at_create() : (1*K*K); | |
5050 assert(pre_thread_stack_size != 0, "Must have a stack"); | |
5051 // Solaris has a maximum of 4Gb of user programs. Calculate the thread limit when | |
5052 // we should start doing Virtual Memory banging. Currently when the threads will | |
5053 // have used all but 200Mb of space. | |
5054 size_t max_address_space = ((unsigned int)4 * K * K * K) - (200 * K * K); | |
5055 Solaris::_os_thread_limit = max_address_space / pre_thread_stack_size; | |
5056 | |
5057 // at-exit methods are called in the reverse order of their registration. | |
5058 // In Solaris 7 and earlier, atexit functions are called on return from | |
5059 // main or as a result of a call to exit(3C). There can be only 32 of | |
5060 // these functions registered and atexit() does not set errno. In Solaris | |
5061 // 8 and later, there is no limit to the number of functions registered | |
5062 // and atexit() sets errno. In addition, in Solaris 8 and later, atexit | |
5063 // functions are called upon dlclose(3DL) in addition to return from main | |
5064 // and exit(3C). | |
5065 | |
5066 if (PerfAllowAtExitRegistration) { | |
5067 // only register atexit functions if PerfAllowAtExitRegistration is set. | |
5068 // atexit functions can be delayed until process exit time, which | |
5069 // can be problematic for embedded VM situations. Embedded VMs should | |
5070 // call DestroyJavaVM() to assure that VM resources are released. | |
5071 | |
5072 // note: perfMemory_exit_helper atexit function may be removed in | |
5073 // the future if the appropriate cleanup code can be added to the | |
5074 // VM_Exit VMOperation's doit method. | |
5075 if (atexit(perfMemory_exit_helper) != 0) { | |
5076 warning("os::init2 atexit(perfMemory_exit_helper) failed"); | |
5077 } | |
5078 } | |
5079 | |
5080 // Init pset_loadavg function pointer | |
5081 init_pset_getloadavg_ptr(); | |
5082 | |
5083 return JNI_OK; | |
5084 } | |
5085 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5086 void os::init_3(void) { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5087 return; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5088 } |
0 | 5089 |
5090 // Mark the polling page as unreadable | |
5091 void os::make_polling_page_unreadable(void) { | |
5092 if( mprotect((char *)_polling_page, page_size, PROT_NONE) != 0 ) | |
5093 fatal("Could not disable polling page"); | |
5094 }; | |
5095 | |
5096 // Mark the polling page as readable | |
5097 void os::make_polling_page_readable(void) { | |
5098 if( mprotect((char *)_polling_page, page_size, PROT_READ) != 0 ) | |
5099 fatal("Could not enable polling page"); | |
5100 }; | |
5101 | |
5102 // OS interface. | |
5103 | |
5104 int os::stat(const char *path, struct stat *sbuf) { | |
5105 char pathbuf[MAX_PATH]; | |
5106 if (strlen(path) > MAX_PATH - 1) { | |
5107 errno = ENAMETOOLONG; | |
5108 return -1; | |
5109 } | |
5110 hpi::native_path(strcpy(pathbuf, path)); | |
5111 return ::stat(pathbuf, sbuf); | |
5112 } | |
5113 | |
5114 | |
5115 bool os::check_heap(bool force) { return true; } | |
5116 | |
5117 typedef int (*vsnprintf_t)(char* buf, size_t count, const char* fmt, va_list argptr); | |
5118 static vsnprintf_t sol_vsnprintf = NULL; | |
5119 | |
5120 int local_vsnprintf(char* buf, size_t count, const char* fmt, va_list argptr) { | |
5121 if (!sol_vsnprintf) { | |
5122 //search for the named symbol in the objects that were loaded after libjvm | |
5123 void* where = RTLD_NEXT; | |
5124 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) | |
5125 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); | |
5126 if (!sol_vsnprintf){ | |
5127 //search for the named symbol in the objects that were loaded before libjvm | |
5128 where = RTLD_DEFAULT; | |
5129 if ((sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "__vsnprintf"))) == NULL) | |
5130 sol_vsnprintf = CAST_TO_FN_PTR(vsnprintf_t, dlsym(where, "vsnprintf")); | |
5131 assert(sol_vsnprintf != NULL, "vsnprintf not found"); | |
5132 } | |
5133 } | |
5134 return (*sol_vsnprintf)(buf, count, fmt, argptr); | |
5135 } | |
5136 | |
5137 | |
5138 // Is a (classpath) directory empty? | |
5139 bool os::dir_is_empty(const char* path) { | |
5140 DIR *dir = NULL; | |
5141 struct dirent *ptr; | |
5142 | |
5143 dir = opendir(path); | |
5144 if (dir == NULL) return true; | |
5145 | |
5146 /* Scan the directory */ | |
5147 bool result = true; | |
5148 char buf[sizeof(struct dirent) + MAX_PATH]; | |
5149 struct dirent *dbuf = (struct dirent *) buf; | |
5150 while (result && (ptr = readdir(dir, dbuf)) != NULL) { | |
5151 if (strcmp(ptr->d_name, ".") != 0 && strcmp(ptr->d_name, "..") != 0) { | |
5152 result = false; | |
5153 } | |
5154 } | |
5155 closedir(dir); | |
5156 return result; | |
5157 } | |
5158 | |
5159 // create binary file, rewriting existing file if required | |
5160 int os::create_binary_file(const char* path, bool rewrite_existing) { | |
5161 int oflags = O_WRONLY | O_CREAT; | |
5162 if (!rewrite_existing) { | |
5163 oflags |= O_EXCL; | |
5164 } | |
5165 return ::open64(path, oflags, S_IREAD | S_IWRITE); | |
5166 } | |
5167 | |
5168 // return current position of file pointer | |
5169 jlong os::current_file_offset(int fd) { | |
5170 return (jlong)::lseek64(fd, (off64_t)0, SEEK_CUR); | |
5171 } | |
5172 | |
5173 // move file pointer to the specified offset | |
5174 jlong os::seek_to_file_offset(int fd, jlong offset) { | |
5175 return (jlong)::lseek64(fd, (off64_t)offset, SEEK_SET); | |
5176 } | |
5177 | |
5178 // Map a block of memory. | |
5179 char* os::map_memory(int fd, const char* file_name, size_t file_offset, | |
5180 char *addr, size_t bytes, bool read_only, | |
5181 bool allow_exec) { | |
5182 int prot; | |
5183 int flags; | |
5184 | |
5185 if (read_only) { | |
5186 prot = PROT_READ; | |
5187 flags = MAP_SHARED; | |
5188 } else { | |
5189 prot = PROT_READ | PROT_WRITE; | |
5190 flags = MAP_PRIVATE; | |
5191 } | |
5192 | |
5193 if (allow_exec) { | |
5194 prot |= PROT_EXEC; | |
5195 } | |
5196 | |
5197 if (addr != NULL) { | |
5198 flags |= MAP_FIXED; | |
5199 } | |
5200 | |
5201 char* mapped_address = (char*)mmap(addr, (size_t)bytes, prot, flags, | |
5202 fd, file_offset); | |
5203 if (mapped_address == MAP_FAILED) { | |
5204 return NULL; | |
5205 } | |
5206 return mapped_address; | |
5207 } | |
5208 | |
5209 | |
5210 // Remap a block of memory. | |
5211 char* os::remap_memory(int fd, const char* file_name, size_t file_offset, | |
5212 char *addr, size_t bytes, bool read_only, | |
5213 bool allow_exec) { | |
5214 // same as map_memory() on this OS | |
5215 return os::map_memory(fd, file_name, file_offset, addr, bytes, read_only, | |
5216 allow_exec); | |
5217 } | |
5218 | |
5219 | |
5220 // Unmap a block of memory. | |
5221 bool os::unmap_memory(char* addr, size_t bytes) { | |
5222 return munmap(addr, bytes) == 0; | |
5223 } | |
5224 | |
5225 void os::pause() { | |
5226 char filename[MAX_PATH]; | |
5227 if (PauseAtStartupFile && PauseAtStartupFile[0]) { | |
5228 jio_snprintf(filename, MAX_PATH, PauseAtStartupFile); | |
5229 } else { | |
5230 jio_snprintf(filename, MAX_PATH, "./vm.paused.%d", current_process_id()); | |
5231 } | |
5232 | |
5233 int fd = ::open(filename, O_WRONLY | O_CREAT | O_TRUNC, 0666); | |
5234 if (fd != -1) { | |
5235 struct stat buf; | |
5236 close(fd); | |
5237 while (::stat(filename, &buf) == 0) { | |
5238 (void)::poll(NULL, 0, 100); | |
5239 } | |
5240 } else { | |
5241 jio_fprintf(stderr, | |
5242 "Could not open pause file '%s', continuing immediately.\n", filename); | |
5243 } | |
5244 } | |
5245 | |
5246 #ifndef PRODUCT | |
5247 #ifdef INTERPOSE_ON_SYSTEM_SYNCH_FUNCTIONS | |
5248 // Turn this on if you need to trace synch operations. | |
5249 // Set RECORD_SYNCH_LIMIT to a large-enough value, | |
5250 // and call record_synch_enable and record_synch_disable | |
5251 // around the computation of interest. | |
5252 | |
5253 void record_synch(char* name, bool returning); // defined below | |
5254 | |
5255 class RecordSynch { | |
5256 char* _name; | |
5257 public: | |
5258 RecordSynch(char* name) :_name(name) | |
5259 { record_synch(_name, false); } | |
5260 ~RecordSynch() { record_synch(_name, true); } | |
5261 }; | |
5262 | |
5263 #define CHECK_SYNCH_OP(ret, name, params, args, inner) \ | |
5264 extern "C" ret name params { \ | |
5265 typedef ret name##_t params; \ | |
5266 static name##_t* implem = NULL; \ | |
5267 static int callcount = 0; \ | |
5268 if (implem == NULL) { \ | |
5269 implem = (name##_t*) dlsym(RTLD_NEXT, #name); \ | |
5270 if (implem == NULL) fatal(dlerror()); \ | |
5271 } \ | |
5272 ++callcount; \ | |
5273 RecordSynch _rs(#name); \ | |
5274 inner; \ | |
5275 return implem args; \ | |
5276 } | |
5277 // in dbx, examine callcounts this way: | |
5278 // for n in $(eval whereis callcount | awk '{print $2}'); do print $n; done | |
5279 | |
5280 #define CHECK_POINTER_OK(p) \ | |
5281 (Universe::perm_gen() == NULL || !Universe::is_reserved_heap((oop)(p))) | |
5282 #define CHECK_MU \ | |
5283 if (!CHECK_POINTER_OK(mu)) fatal("Mutex must be in C heap only."); | |
5284 #define CHECK_CV \ | |
5285 if (!CHECK_POINTER_OK(cv)) fatal("Condvar must be in C heap only."); | |
5286 #define CHECK_P(p) \ | |
5287 if (!CHECK_POINTER_OK(p)) fatal(false, "Pointer must be in C heap only."); | |
5288 | |
5289 #define CHECK_MUTEX(mutex_op) \ | |
5290 CHECK_SYNCH_OP(int, mutex_op, (mutex_t *mu), (mu), CHECK_MU); | |
5291 | |
5292 CHECK_MUTEX( mutex_lock) | |
5293 CHECK_MUTEX( _mutex_lock) | |
5294 CHECK_MUTEX( mutex_unlock) | |
5295 CHECK_MUTEX(_mutex_unlock) | |
5296 CHECK_MUTEX( mutex_trylock) | |
5297 CHECK_MUTEX(_mutex_trylock) | |
5298 | |
5299 #define CHECK_COND(cond_op) \ | |
5300 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu), (cv, mu), CHECK_MU;CHECK_CV); | |
5301 | |
5302 CHECK_COND( cond_wait); | |
5303 CHECK_COND(_cond_wait); | |
5304 CHECK_COND(_cond_wait_cancel); | |
5305 | |
5306 #define CHECK_COND2(cond_op) \ | |
5307 CHECK_SYNCH_OP(int, cond_op, (cond_t *cv, mutex_t *mu, timestruc_t* ts), (cv, mu, ts), CHECK_MU;CHECK_CV); | |
5308 | |
5309 CHECK_COND2( cond_timedwait); | |
5310 CHECK_COND2(_cond_timedwait); | |
5311 CHECK_COND2(_cond_timedwait_cancel); | |
5312 | |
5313 // do the _lwp_* versions too | |
5314 #define mutex_t lwp_mutex_t | |
5315 #define cond_t lwp_cond_t | |
5316 CHECK_MUTEX( _lwp_mutex_lock) | |
5317 CHECK_MUTEX( _lwp_mutex_unlock) | |
5318 CHECK_MUTEX( _lwp_mutex_trylock) | |
5319 CHECK_MUTEX( __lwp_mutex_lock) | |
5320 CHECK_MUTEX( __lwp_mutex_unlock) | |
5321 CHECK_MUTEX( __lwp_mutex_trylock) | |
5322 CHECK_MUTEX(___lwp_mutex_lock) | |
5323 CHECK_MUTEX(___lwp_mutex_unlock) | |
5324 | |
5325 CHECK_COND( _lwp_cond_wait); | |
5326 CHECK_COND( __lwp_cond_wait); | |
5327 CHECK_COND(___lwp_cond_wait); | |
5328 | |
5329 CHECK_COND2( _lwp_cond_timedwait); | |
5330 CHECK_COND2( __lwp_cond_timedwait); | |
5331 #undef mutex_t | |
5332 #undef cond_t | |
5333 | |
5334 CHECK_SYNCH_OP(int, _lwp_suspend2, (int lwp, int *n), (lwp, n), 0); | |
5335 CHECK_SYNCH_OP(int,__lwp_suspend2, (int lwp, int *n), (lwp, n), 0); | |
5336 CHECK_SYNCH_OP(int, _lwp_kill, (int lwp, int n), (lwp, n), 0); | |
5337 CHECK_SYNCH_OP(int,__lwp_kill, (int lwp, int n), (lwp, n), 0); | |
5338 CHECK_SYNCH_OP(int, _lwp_sema_wait, (lwp_sema_t* p), (p), CHECK_P(p)); | |
5339 CHECK_SYNCH_OP(int,__lwp_sema_wait, (lwp_sema_t* p), (p), CHECK_P(p)); | |
5340 CHECK_SYNCH_OP(int, _lwp_cond_broadcast, (lwp_cond_t* cv), (cv), CHECK_CV); | |
5341 CHECK_SYNCH_OP(int,__lwp_cond_broadcast, (lwp_cond_t* cv), (cv), CHECK_CV); | |
5342 | |
5343 | |
5344 // recording machinery: | |
5345 | |
5346 enum { RECORD_SYNCH_LIMIT = 200 }; | |
5347 char* record_synch_name[RECORD_SYNCH_LIMIT]; | |
5348 void* record_synch_arg0ptr[RECORD_SYNCH_LIMIT]; | |
5349 bool record_synch_returning[RECORD_SYNCH_LIMIT]; | |
5350 thread_t record_synch_thread[RECORD_SYNCH_LIMIT]; | |
5351 int record_synch_count = 0; | |
5352 bool record_synch_enabled = false; | |
5353 | |
5354 // in dbx, examine recorded data this way: | |
5355 // for n in name arg0ptr returning thread; do print record_synch_$n[0..record_synch_count-1]; done | |
5356 | |
5357 void record_synch(char* name, bool returning) { | |
5358 if (record_synch_enabled) { | |
5359 if (record_synch_count < RECORD_SYNCH_LIMIT) { | |
5360 record_synch_name[record_synch_count] = name; | |
5361 record_synch_returning[record_synch_count] = returning; | |
5362 record_synch_thread[record_synch_count] = thr_self(); | |
5363 record_synch_arg0ptr[record_synch_count] = &name; | |
5364 record_synch_count++; | |
5365 } | |
5366 // put more checking code here: | |
5367 // ... | |
5368 } | |
5369 } | |
5370 | |
5371 void record_synch_enable() { | |
5372 // start collecting trace data, if not already doing so | |
5373 if (!record_synch_enabled) record_synch_count = 0; | |
5374 record_synch_enabled = true; | |
5375 } | |
5376 | |
5377 void record_synch_disable() { | |
5378 // stop collecting trace data | |
5379 record_synch_enabled = false; | |
5380 } | |
5381 | |
5382 #endif // INTERPOSE_ON_SYSTEM_SYNCH_FUNCTIONS | |
5383 #endif // PRODUCT | |
5384 | |
5385 const intptr_t thr_time_off = (intptr_t)(&((prusage_t *)(NULL))->pr_utime); | |
5386 const intptr_t thr_time_size = (intptr_t)(&((prusage_t *)(NULL))->pr_ttime) - | |
5387 (intptr_t)(&((prusage_t *)(NULL))->pr_utime); | |
5388 | |
5389 | |
5390 // JVMTI & JVM monitoring and management support | |
5391 // The thread_cpu_time() and current_thread_cpu_time() are only | |
5392 // supported if is_thread_cpu_time_supported() returns true. | |
5393 // They are not supported on Solaris T1. | |
5394 | |
5395 // current_thread_cpu_time(bool) and thread_cpu_time(Thread*, bool) | |
5396 // are used by JVM M&M and JVMTI to get user+sys or user CPU time | |
5397 // of a thread. | |
5398 // | |
5399 // current_thread_cpu_time() and thread_cpu_time(Thread *) | |
5400 // returns the fast estimate available on the platform. | |
5401 | |
5402 // hrtime_t gethrvtime() return value includes | |
5403 // user time but does not include system time | |
5404 jlong os::current_thread_cpu_time() { | |
5405 return (jlong) gethrvtime(); | |
5406 } | |
5407 | |
5408 jlong os::thread_cpu_time(Thread *thread) { | |
5409 // return user level CPU time only to be consistent with | |
5410 // what current_thread_cpu_time returns. | |
5411 // thread_cpu_time_info() must be changed if this changes | |
5412 return os::thread_cpu_time(thread, false /* user time only */); | |
5413 } | |
5414 | |
5415 jlong os::current_thread_cpu_time(bool user_sys_cpu_time) { | |
5416 if (user_sys_cpu_time) { | |
5417 return os::thread_cpu_time(Thread::current(), user_sys_cpu_time); | |
5418 } else { | |
5419 return os::current_thread_cpu_time(); | |
5420 } | |
5421 } | |
5422 | |
5423 jlong os::thread_cpu_time(Thread *thread, bool user_sys_cpu_time) { | |
5424 char proc_name[64]; | |
5425 int count; | |
5426 prusage_t prusage; | |
5427 jlong lwp_time; | |
5428 int fd; | |
5429 | |
5430 sprintf(proc_name, "/proc/%d/lwp/%d/lwpusage", | |
5431 getpid(), | |
5432 thread->osthread()->lwp_id()); | |
5433 fd = open(proc_name, O_RDONLY); | |
5434 if ( fd == -1 ) return -1; | |
5435 | |
5436 do { | |
5437 count = pread(fd, | |
5438 (void *)&prusage.pr_utime, | |
5439 thr_time_size, | |
5440 thr_time_off); | |
5441 } while (count < 0 && errno == EINTR); | |
5442 close(fd); | |
5443 if ( count < 0 ) return -1; | |
5444 | |
5445 if (user_sys_cpu_time) { | |
5446 // user + system CPU time | |
5447 lwp_time = (((jlong)prusage.pr_stime.tv_sec + | |
5448 (jlong)prusage.pr_utime.tv_sec) * (jlong)1000000000) + | |
5449 (jlong)prusage.pr_stime.tv_nsec + | |
5450 (jlong)prusage.pr_utime.tv_nsec; | |
5451 } else { | |
5452 // user level CPU time only | |
5453 lwp_time = ((jlong)prusage.pr_utime.tv_sec * (jlong)1000000000) + | |
5454 (jlong)prusage.pr_utime.tv_nsec; | |
5455 } | |
5456 | |
5457 return(lwp_time); | |
5458 } | |
5459 | |
5460 void os::current_thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { | |
5461 info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits | |
5462 info_ptr->may_skip_backward = false; // elapsed time not wall time | |
5463 info_ptr->may_skip_forward = false; // elapsed time not wall time | |
5464 info_ptr->kind = JVMTI_TIMER_USER_CPU; // only user time is returned | |
5465 } | |
5466 | |
5467 void os::thread_cpu_time_info(jvmtiTimerInfo *info_ptr) { | |
5468 info_ptr->max_value = ALL_64_BITS; // will not wrap in less than 64 bits | |
5469 info_ptr->may_skip_backward = false; // elapsed time not wall time | |
5470 info_ptr->may_skip_forward = false; // elapsed time not wall time | |
5471 info_ptr->kind = JVMTI_TIMER_USER_CPU; // only user time is returned | |
5472 } | |
5473 | |
5474 bool os::is_thread_cpu_time_supported() { | |
5475 if ( os::Solaris::T2_libthread() || UseBoundThreads ) { | |
5476 return true; | |
5477 } else { | |
5478 return false; | |
5479 } | |
5480 } | |
5481 | |
5482 // System loadavg support. Returns -1 if load average cannot be obtained. | |
5483 // Return the load average for our processor set if the primitive exists | |
5484 // (Solaris 9 and later). Otherwise just return system wide loadavg. | |
5485 int os::loadavg(double loadavg[], int nelem) { | |
5486 if (pset_getloadavg_ptr != NULL) { | |
5487 return (*pset_getloadavg_ptr)(PS_MYID, loadavg, nelem); | |
5488 } else { | |
5489 return ::getloadavg(loadavg, nelem); | |
5490 } | |
5491 } | |
5492 | |
5493 //--------------------------------------------------------------------------------- | |
5494 | |
5495 static address same_page(address x, address y) { | |
5496 intptr_t page_bits = -os::vm_page_size(); | |
5497 if ((intptr_t(x) & page_bits) == (intptr_t(y) & page_bits)) | |
5498 return x; | |
5499 else if (x > y) | |
5500 return (address)(intptr_t(y) | ~page_bits) + 1; | |
5501 else | |
5502 return (address)(intptr_t(y) & page_bits); | |
5503 } | |
5504 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5505 bool os::find(address addr, outputStream* st) { |
0 | 5506 Dl_info dlinfo; |
5507 memset(&dlinfo, 0, sizeof(dlinfo)); | |
5508 if (dladdr(addr, &dlinfo)) { | |
5509 #ifdef _LP64 | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5510 st->print("0x%016lx: ", addr); |
0 | 5511 #else |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5512 st->print("0x%08x: ", addr); |
0 | 5513 #endif |
5514 if (dlinfo.dli_sname != NULL) | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5515 st->print("%s+%#lx", dlinfo.dli_sname, addr-(intptr_t)dlinfo.dli_saddr); |
0 | 5516 else if (dlinfo.dli_fname) |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5517 st->print("<offset %#lx>", addr-(intptr_t)dlinfo.dli_fbase); |
0 | 5518 else |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5519 st->print("<absolute address>"); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5520 if (dlinfo.dli_fname) st->print(" in %s", dlinfo.dli_fname); |
0 | 5521 #ifdef _LP64 |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5522 if (dlinfo.dli_fbase) st->print(" at 0x%016lx", dlinfo.dli_fbase); |
0 | 5523 #else |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5524 if (dlinfo.dli_fbase) st->print(" at 0x%08x", dlinfo.dli_fbase); |
0 | 5525 #endif |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5526 st->cr(); |
0 | 5527 |
5528 if (Verbose) { | |
5529 // decode some bytes around the PC | |
5530 address begin = same_page(addr-40, addr); | |
5531 address end = same_page(addr+40, addr); | |
5532 address lowest = (address) dlinfo.dli_sname; | |
5533 if (!lowest) lowest = (address) dlinfo.dli_fbase; | |
5534 if (begin < lowest) begin = lowest; | |
5535 Dl_info dlinfo2; | |
5536 if (dladdr(end, &dlinfo2) && dlinfo2.dli_saddr != dlinfo.dli_saddr | |
5537 && end > dlinfo2.dli_saddr && dlinfo2.dli_saddr > begin) | |
5538 end = (address) dlinfo2.dli_saddr; | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
5539 Disassembler::decode(begin, end, st); |
0 | 5540 } |
5541 return true; | |
5542 } | |
5543 return false; | |
5544 } | |
5545 | |
5546 // Following function has been added to support HotSparc's libjvm.so running | |
5547 // under Solaris production JDK 1.2.2 / 1.3.0. These came from | |
5548 // src/solaris/hpi/native_threads in the EVM codebase. | |
5549 // | |
5550 // NOTE: This is no longer needed in the 1.3.1 and 1.4 production release | |
5551 // libraries and should thus be removed. We will leave it behind for a while | |
5552 // until we no longer want to able to run on top of 1.3.0 Solaris production | |
5553 // JDK. See 4341971. | |
5554 | |
5555 #define STACK_SLACK 0x800 | |
5556 | |
5557 extern "C" { | |
5558 intptr_t sysThreadAvailableStackWithSlack() { | |
5559 stack_t st; | |
5560 intptr_t retval, stack_top; | |
5561 retval = thr_stksegment(&st); | |
5562 assert(retval == 0, "incorrect return value from thr_stksegment"); | |
5563 assert((address)&st < (address)st.ss_sp, "Invalid stack base returned"); | |
5564 assert((address)&st > (address)st.ss_sp-st.ss_size, "Invalid stack size returned"); | |
5565 stack_top=(intptr_t)st.ss_sp-st.ss_size; | |
5566 return ((intptr_t)&stack_top - stack_top - STACK_SLACK); | |
5567 } | |
5568 } | |
5569 | |
5570 // Just to get the Kernel build to link on solaris for testing. | |
5571 | |
5572 extern "C" { | |
5573 class ASGCT_CallTrace; | |
5574 void AsyncGetCallTrace(ASGCT_CallTrace *trace, jint depth, void* ucontext) | |
5575 KERNEL_RETURN; | |
5576 } | |
5577 | |
5578 | |
5579 // ObjectMonitor park-unpark infrastructure ... | |
5580 // | |
5581 // We implement Solaris and Linux PlatformEvents with the | |
5582 // obvious condvar-mutex-flag triple. | |
5583 // Another alternative that works quite well is pipes: | |
5584 // Each PlatformEvent consists of a pipe-pair. | |
5585 // The thread associated with the PlatformEvent | |
5586 // calls park(), which reads from the input end of the pipe. | |
5587 // Unpark() writes into the other end of the pipe. | |
5588 // The write-side of the pipe must be set NDELAY. | |
5589 // Unfortunately pipes consume a large # of handles. | |
5590 // Native solaris lwp_park() and lwp_unpark() work nicely, too. | |
5591 // Using pipes for the 1st few threads might be workable, however. | |
5592 // | |
5593 // park() is permitted to return spuriously. | |
5594 // Callers of park() should wrap the call to park() in | |
5595 // an appropriate loop. A litmus test for the correct | |
5596 // usage of park is the following: if park() were modified | |
5597 // to immediately return 0 your code should still work, | |
5598 // albeit degenerating to a spin loop. | |
5599 // | |
5600 // An interesting optimization for park() is to use a trylock() | |
5601 // to attempt to acquire the mutex. If the trylock() fails | |
5602 // then we know that a concurrent unpark() operation is in-progress. | |
5603 // in that case the park() code could simply set _count to 0 | |
5604 // and return immediately. The subsequent park() operation *might* | |
5605 // return immediately. That's harmless as the caller of park() is | |
5606 // expected to loop. By using trylock() we will have avoided a | |
5607 // avoided a context switch caused by contention on the per-thread mutex. | |
5608 // | |
5609 // TODO-FIXME: | |
5610 // 1. Reconcile Doug's JSR166 j.u.c park-unpark with the | |
5611 // objectmonitor implementation. | |
5612 // 2. Collapse the JSR166 parker event, and the | |
5613 // objectmonitor ParkEvent into a single "Event" construct. | |
5614 // 3. In park() and unpark() add: | |
5615 // assert (Thread::current() == AssociatedWith). | |
5616 // 4. add spurious wakeup injection on a -XX:EarlyParkReturn=N switch. | |
5617 // 1-out-of-N park() operations will return immediately. | |
5618 // | |
5619 // _Event transitions in park() | |
5620 // -1 => -1 : illegal | |
5621 // 1 => 0 : pass - return immediately | |
5622 // 0 => -1 : block | |
5623 // | |
5624 // _Event serves as a restricted-range semaphore. | |
5625 // | |
5626 // Another possible encoding of _Event would be with | |
5627 // explicit "PARKED" == 01b and "SIGNALED" == 10b bits. | |
5628 // | |
5629 // TODO-FIXME: add DTRACE probes for: | |
5630 // 1. Tx parks | |
5631 // 2. Ty unparks Tx | |
5632 // 3. Tx resumes from park | |
5633 | |
5634 | |
5635 // value determined through experimentation | |
5636 #define ROUNDINGFIX 11 | |
5637 | |
5638 // utility to compute the abstime argument to timedwait. | |
5639 // TODO-FIXME: switch from compute_abstime() to unpackTime(). | |
5640 | |
5641 static timestruc_t* compute_abstime(timestruc_t* abstime, jlong millis) { | |
5642 // millis is the relative timeout time | |
5643 // abstime will be the absolute timeout time | |
5644 if (millis < 0) millis = 0; | |
5645 struct timeval now; | |
5646 int status = gettimeofday(&now, NULL); | |
5647 assert(status == 0, "gettimeofday"); | |
5648 jlong seconds = millis / 1000; | |
5649 jlong max_wait_period; | |
5650 | |
5651 if (UseLWPSynchronization) { | |
5652 // forward port of fix for 4275818 (not sleeping long enough) | |
5653 // There was a bug in Solaris 6, 7 and pre-patch 5 of 8 where | |
5654 // _lwp_cond_timedwait() used a round_down algorithm rather | |
5655 // than a round_up. For millis less than our roundfactor | |
5656 // it rounded down to 0 which doesn't meet the spec. | |
5657 // For millis > roundfactor we may return a bit sooner, but | |
5658 // since we can not accurately identify the patch level and | |
5659 // this has already been fixed in Solaris 9 and 8 we will | |
5660 // leave it alone rather than always rounding down. | |
5661 | |
5662 if (millis > 0 && millis < ROUNDINGFIX) millis = ROUNDINGFIX; | |
5663 // It appears that when we go directly through Solaris _lwp_cond_timedwait() | |
5664 // the acceptable max time threshold is smaller than for libthread on 2.5.1 and 2.6 | |
5665 max_wait_period = 21000000; | |
5666 } else { | |
5667 max_wait_period = 50000000; | |
5668 } | |
5669 millis %= 1000; | |
5670 if (seconds > max_wait_period) { // see man cond_timedwait(3T) | |
5671 seconds = max_wait_period; | |
5672 } | |
5673 abstime->tv_sec = now.tv_sec + seconds; | |
5674 long usec = now.tv_usec + millis * 1000; | |
5675 if (usec >= 1000000) { | |
5676 abstime->tv_sec += 1; | |
5677 usec -= 1000000; | |
5678 } | |
5679 abstime->tv_nsec = usec * 1000; | |
5680 return abstime; | |
5681 } | |
5682 | |
5683 // Test-and-clear _Event, always leaves _Event set to 0, returns immediately. | |
5684 // Conceptually TryPark() should be equivalent to park(0). | |
5685 | |
5686 int os::PlatformEvent::TryPark() { | |
5687 for (;;) { | |
5688 const int v = _Event ; | |
5689 guarantee ((v == 0) || (v == 1), "invariant") ; | |
5690 if (Atomic::cmpxchg (0, &_Event, v) == v) return v ; | |
5691 } | |
5692 } | |
5693 | |
5694 void os::PlatformEvent::park() { // AKA: down() | |
5695 // Invariant: Only the thread associated with the Event/PlatformEvent | |
5696 // may call park(). | |
5697 int v ; | |
5698 for (;;) { | |
5699 v = _Event ; | |
5700 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; | |
5701 } | |
5702 guarantee (v >= 0, "invariant") ; | |
5703 if (v == 0) { | |
5704 // Do this the hard way by blocking ... | |
5705 // See http://monaco.sfbay/detail.jsf?cr=5094058. | |
5706 // TODO-FIXME: for Solaris SPARC set fprs.FEF=0 prior to parking. | |
5707 // Only for SPARC >= V8PlusA | |
5708 #if defined(__sparc) && defined(COMPILER2) | |
5709 if (ClearFPUAtPark) { _mark_fpu_nosave() ; } | |
5710 #endif | |
5711 int status = os::Solaris::mutex_lock(_mutex); | |
5712 assert_status(status == 0, status, "mutex_lock"); | |
5713 guarantee (_nParked == 0, "invariant") ; | |
5714 ++ _nParked ; | |
5715 while (_Event < 0) { | |
5716 // for some reason, under 2.7 lwp_cond_wait() may return ETIME ... | |
5717 // Treat this the same as if the wait was interrupted | |
5718 // With usr/lib/lwp going to kernel, always handle ETIME | |
5719 status = os::Solaris::cond_wait(_cond, _mutex); | |
5720 if (status == ETIME) status = EINTR ; | |
5721 assert_status(status == 0 || status == EINTR, status, "cond_wait"); | |
5722 } | |
5723 -- _nParked ; | |
5724 _Event = 0 ; | |
5725 status = os::Solaris::mutex_unlock(_mutex); | |
5726 assert_status(status == 0, status, "mutex_unlock"); | |
5727 } | |
5728 } | |
5729 | |
5730 int os::PlatformEvent::park(jlong millis) { | |
5731 guarantee (_nParked == 0, "invariant") ; | |
5732 int v ; | |
5733 for (;;) { | |
5734 v = _Event ; | |
5735 if (Atomic::cmpxchg (v-1, &_Event, v) == v) break ; | |
5736 } | |
5737 guarantee (v >= 0, "invariant") ; | |
5738 if (v != 0) return OS_OK ; | |
5739 | |
5740 int ret = OS_TIMEOUT; | |
5741 timestruc_t abst; | |
5742 compute_abstime (&abst, millis); | |
5743 | |
5744 // See http://monaco.sfbay/detail.jsf?cr=5094058. | |
5745 // For Solaris SPARC set fprs.FEF=0 prior to parking. | |
5746 // Only for SPARC >= V8PlusA | |
5747 #if defined(__sparc) && defined(COMPILER2) | |
5748 if (ClearFPUAtPark) { _mark_fpu_nosave() ; } | |
5749 #endif | |
5750 int status = os::Solaris::mutex_lock(_mutex); | |
5751 assert_status(status == 0, status, "mutex_lock"); | |
5752 guarantee (_nParked == 0, "invariant") ; | |
5753 ++ _nParked ; | |
5754 while (_Event < 0) { | |
5755 int status = os::Solaris::cond_timedwait(_cond, _mutex, &abst); | |
5756 assert_status(status == 0 || status == EINTR || | |
5757 status == ETIME || status == ETIMEDOUT, | |
5758 status, "cond_timedwait"); | |
5759 if (!FilterSpuriousWakeups) break ; // previous semantics | |
5760 if (status == ETIME || status == ETIMEDOUT) break ; | |
5761 // We consume and ignore EINTR and spurious wakeups. | |
5762 } | |
5763 -- _nParked ; | |
5764 if (_Event >= 0) ret = OS_OK ; | |
5765 _Event = 0 ; | |
5766 status = os::Solaris::mutex_unlock(_mutex); | |
5767 assert_status(status == 0, status, "mutex_unlock"); | |
5768 return ret; | |
5769 } | |
5770 | |
5771 void os::PlatformEvent::unpark() { | |
5772 int v, AnyWaiters; | |
5773 | |
5774 // Increment _Event. | |
5775 // Another acceptable implementation would be to simply swap 1 | |
5776 // into _Event: | |
5777 // if (Swap (&_Event, 1) < 0) { | |
5778 // mutex_lock (_mutex) ; AnyWaiters = nParked; mutex_unlock (_mutex) ; | |
5779 // if (AnyWaiters) cond_signal (_cond) ; | |
5780 // } | |
5781 | |
5782 for (;;) { | |
5783 v = _Event ; | |
5784 if (v > 0) { | |
5785 // The LD of _Event could have reordered or be satisfied | |
5786 // by a read-aside from this processor's write buffer. | |
5787 // To avoid problems execute a barrier and then | |
5788 // ratify the value. A degenerate CAS() would also work. | |
5789 // Viz., CAS (v+0, &_Event, v) == v). | |
5790 OrderAccess::fence() ; | |
5791 if (_Event == v) return ; | |
5792 continue ; | |
5793 } | |
5794 if (Atomic::cmpxchg (v+1, &_Event, v) == v) break ; | |
5795 } | |
5796 | |
5797 // If the thread associated with the event was parked, wake it. | |
5798 if (v < 0) { | |
5799 int status ; | |
5800 // Wait for the thread assoc with the PlatformEvent to vacate. | |
5801 status = os::Solaris::mutex_lock(_mutex); | |
5802 assert_status(status == 0, status, "mutex_lock"); | |
5803 AnyWaiters = _nParked ; | |
5804 status = os::Solaris::mutex_unlock(_mutex); | |
5805 assert_status(status == 0, status, "mutex_unlock"); | |
5806 guarantee (AnyWaiters == 0 || AnyWaiters == 1, "invariant") ; | |
5807 if (AnyWaiters != 0) { | |
5808 // We intentional signal *after* dropping the lock | |
5809 // to avoid a common class of futile wakeups. | |
5810 status = os::Solaris::cond_signal(_cond); | |
5811 assert_status(status == 0, status, "cond_signal"); | |
5812 } | |
5813 } | |
5814 } | |
5815 | |
5816 // JSR166 | |
5817 // ------------------------------------------------------- | |
5818 | |
5819 /* | |
5820 * The solaris and linux implementations of park/unpark are fairly | |
5821 * conservative for now, but can be improved. They currently use a | |
5822 * mutex/condvar pair, plus _counter. | |
5823 * Park decrements _counter if > 0, else does a condvar wait. Unpark | |
5824 * sets count to 1 and signals condvar. Only one thread ever waits | |
5825 * on the condvar. Contention seen when trying to park implies that someone | |
5826 * is unparking you, so don't wait. And spurious returns are fine, so there | |
5827 * is no need to track notifications. | |
5828 */ | |
5829 | |
5830 #define NANOSECS_PER_SEC 1000000000 | |
5831 #define NANOSECS_PER_MILLISEC 1000000 | |
5832 #define MAX_SECS 100000000 | |
5833 | |
5834 /* | |
5835 * This code is common to linux and solaris and will be moved to a | |
5836 * common place in dolphin. | |
5837 * | |
5838 * The passed in time value is either a relative time in nanoseconds | |
5839 * or an absolute time in milliseconds. Either way it has to be unpacked | |
5840 * into suitable seconds and nanoseconds components and stored in the | |
5841 * given timespec structure. | |
5842 * Given time is a 64-bit value and the time_t used in the timespec is only | |
5843 * a signed-32-bit value (except on 64-bit Linux) we have to watch for | |
5844 * overflow if times way in the future are given. Further on Solaris versions | |
5845 * prior to 10 there is a restriction (see cond_timedwait) that the specified | |
5846 * number of seconds, in abstime, is less than current_time + 100,000,000. | |
5847 * As it will be 28 years before "now + 100000000" will overflow we can | |
5848 * ignore overflow and just impose a hard-limit on seconds using the value | |
5849 * of "now + 100,000,000". This places a limit on the timeout of about 3.17 | |
5850 * years from "now". | |
5851 */ | |
5852 static void unpackTime(timespec* absTime, bool isAbsolute, jlong time) { | |
5853 assert (time > 0, "convertTime"); | |
5854 | |
5855 struct timeval now; | |
5856 int status = gettimeofday(&now, NULL); | |
5857 assert(status == 0, "gettimeofday"); | |
5858 | |
5859 time_t max_secs = now.tv_sec + MAX_SECS; | |
5860 | |
5861 if (isAbsolute) { | |
5862 jlong secs = time / 1000; | |
5863 if (secs > max_secs) { | |
5864 absTime->tv_sec = max_secs; | |
5865 } | |
5866 else { | |
5867 absTime->tv_sec = secs; | |
5868 } | |
5869 absTime->tv_nsec = (time % 1000) * NANOSECS_PER_MILLISEC; | |
5870 } | |
5871 else { | |
5872 jlong secs = time / NANOSECS_PER_SEC; | |
5873 if (secs >= MAX_SECS) { | |
5874 absTime->tv_sec = max_secs; | |
5875 absTime->tv_nsec = 0; | |
5876 } | |
5877 else { | |
5878 absTime->tv_sec = now.tv_sec + secs; | |
5879 absTime->tv_nsec = (time % NANOSECS_PER_SEC) + now.tv_usec*1000; | |
5880 if (absTime->tv_nsec >= NANOSECS_PER_SEC) { | |
5881 absTime->tv_nsec -= NANOSECS_PER_SEC; | |
5882 ++absTime->tv_sec; // note: this must be <= max_secs | |
5883 } | |
5884 } | |
5885 } | |
5886 assert(absTime->tv_sec >= 0, "tv_sec < 0"); | |
5887 assert(absTime->tv_sec <= max_secs, "tv_sec > max_secs"); | |
5888 assert(absTime->tv_nsec >= 0, "tv_nsec < 0"); | |
5889 assert(absTime->tv_nsec < NANOSECS_PER_SEC, "tv_nsec >= nanos_per_sec"); | |
5890 } | |
5891 | |
5892 void Parker::park(bool isAbsolute, jlong time) { | |
5893 | |
5894 // Optional fast-path check: | |
5895 // Return immediately if a permit is available. | |
5896 if (_counter > 0) { | |
5897 _counter = 0 ; | |
1117
95e9083cf4a7
6822370: ReentrantReadWriteLock: threads hung when there are no threads holding onto the lock (Netra x4450)
dholmes
parents:
894
diff
changeset
|
5898 OrderAccess::fence(); |
0 | 5899 return ; |
5900 } | |
5901 | |
5902 // Optional fast-exit: Check interrupt before trying to wait | |
5903 Thread* thread = Thread::current(); | |
5904 assert(thread->is_Java_thread(), "Must be JavaThread"); | |
5905 JavaThread *jt = (JavaThread *)thread; | |
5906 if (Thread::is_interrupted(thread, false)) { | |
5907 return; | |
5908 } | |
5909 | |
5910 // First, demultiplex/decode time arguments | |
5911 timespec absTime; | |
1865
1c352af0135d
6763959: java.util.concurrent.locks.LockSupport.parkUntil(0) blocks forever
acorn
parents:
1681
diff
changeset
|
5912 if (time < 0 || (isAbsolute && time == 0) ) { // don't wait at all |
0 | 5913 return; |
5914 } | |
5915 if (time > 0) { | |
5916 // Warning: this code might be exposed to the old Solaris time | |
5917 // round-down bugs. Grep "roundingFix" for details. | |
5918 unpackTime(&absTime, isAbsolute, time); | |
5919 } | |
5920 | |
5921 // Enter safepoint region | |
5922 // Beware of deadlocks such as 6317397. | |
5923 // The per-thread Parker:: _mutex is a classic leaf-lock. | |
5924 // In particular a thread must never block on the Threads_lock while | |
5925 // holding the Parker:: mutex. If safepoints are pending both the | |
5926 // the ThreadBlockInVM() CTOR and DTOR may grab Threads_lock. | |
5927 ThreadBlockInVM tbivm(jt); | |
5928 | |
5929 // Don't wait if cannot get lock since interference arises from | |
5930 // unblocking. Also. check interrupt before trying wait | |
5931 if (Thread::is_interrupted(thread, false) || | |
5932 os::Solaris::mutex_trylock(_mutex) != 0) { | |
5933 return; | |
5934 } | |
5935 | |
5936 int status ; | |
5937 | |
5938 if (_counter > 0) { // no wait needed | |
5939 _counter = 0; | |
5940 status = os::Solaris::mutex_unlock(_mutex); | |
5941 assert (status == 0, "invariant") ; | |
1117
95e9083cf4a7
6822370: ReentrantReadWriteLock: threads hung when there are no threads holding onto the lock (Netra x4450)
dholmes
parents:
894
diff
changeset
|
5942 OrderAccess::fence(); |
0 | 5943 return; |
5944 } | |
5945 | |
5946 #ifdef ASSERT | |
5947 // Don't catch signals while blocked; let the running threads have the signals. | |
5948 // (This allows a debugger to break into the running thread.) | |
5949 sigset_t oldsigs; | |
5950 sigset_t* allowdebug_blocked = os::Solaris::allowdebug_blocked_signals(); | |
5951 thr_sigsetmask(SIG_BLOCK, allowdebug_blocked, &oldsigs); | |
5952 #endif | |
5953 | |
5954 OSThreadWaitState osts(thread->osthread(), false /* not Object.wait() */); | |
5955 jt->set_suspend_equivalent(); | |
5956 // cleared by handle_special_suspend_equivalent_condition() or java_suspend_self() | |
5957 | |
5958 // Do this the hard way by blocking ... | |
5959 // See http://monaco.sfbay/detail.jsf?cr=5094058. | |
5960 // TODO-FIXME: for Solaris SPARC set fprs.FEF=0 prior to parking. | |
5961 // Only for SPARC >= V8PlusA | |
5962 #if defined(__sparc) && defined(COMPILER2) | |
5963 if (ClearFPUAtPark) { _mark_fpu_nosave() ; } | |
5964 #endif | |
5965 | |
5966 if (time == 0) { | |
5967 status = os::Solaris::cond_wait (_cond, _mutex) ; | |
5968 } else { | |
5969 status = os::Solaris::cond_timedwait (_cond, _mutex, &absTime); | |
5970 } | |
5971 // Note that an untimed cond_wait() can sometimes return ETIME on older | |
5972 // versions of the Solaris. | |
5973 assert_status(status == 0 || status == EINTR || | |
5974 status == ETIME || status == ETIMEDOUT, | |
5975 status, "cond_timedwait"); | |
5976 | |
5977 #ifdef ASSERT | |
5978 thr_sigsetmask(SIG_SETMASK, &oldsigs, NULL); | |
5979 #endif | |
5980 _counter = 0 ; | |
5981 status = os::Solaris::mutex_unlock(_mutex); | |
5982 assert_status(status == 0, status, "mutex_unlock") ; | |
5983 | |
5984 // If externally suspended while waiting, re-suspend | |
5985 if (jt->handle_special_suspend_equivalent_condition()) { | |
5986 jt->java_suspend_self(); | |
5987 } | |
1117
95e9083cf4a7
6822370: ReentrantReadWriteLock: threads hung when there are no threads holding onto the lock (Netra x4450)
dholmes
parents:
894
diff
changeset
|
5988 OrderAccess::fence(); |
0 | 5989 } |
5990 | |
5991 void Parker::unpark() { | |
5992 int s, status ; | |
5993 status = os::Solaris::mutex_lock (_mutex) ; | |
5994 assert (status == 0, "invariant") ; | |
5995 s = _counter; | |
5996 _counter = 1; | |
5997 status = os::Solaris::mutex_unlock (_mutex) ; | |
5998 assert (status == 0, "invariant") ; | |
5999 | |
6000 if (s < 1) { | |
6001 status = os::Solaris::cond_signal (_cond) ; | |
6002 assert (status == 0, "invariant") ; | |
6003 } | |
6004 } | |
6005 | |
6006 extern char** environ; | |
6007 | |
6008 // Run the specified command in a separate process. Return its exit value, | |
6009 // or -1 on failure (e.g. can't fork a new process). | |
6010 // Unlike system(), this function can be called from signal handler. It | |
6011 // doesn't block SIGINT et al. | |
6012 int os::fork_and_exec(char* cmd) { | |
6013 char * argv[4]; | |
6014 argv[0] = (char *)"sh"; | |
6015 argv[1] = (char *)"-c"; | |
6016 argv[2] = cmd; | |
6017 argv[3] = NULL; | |
6018 | |
6019 // fork is async-safe, fork1 is not so can't use in signal handler | |
6020 pid_t pid; | |
6021 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
6022 if (t != NULL && t->is_inside_signal_handler()) { | |
6023 pid = fork(); | |
6024 } else { | |
6025 pid = fork1(); | |
6026 } | |
6027 | |
6028 if (pid < 0) { | |
6029 // fork failed | |
6030 warning("fork failed: %s", strerror(errno)); | |
6031 return -1; | |
6032 | |
6033 } else if (pid == 0) { | |
6034 // child process | |
6035 | |
6036 // try to be consistent with system(), which uses "/usr/bin/sh" on Solaris | |
6037 execve("/usr/bin/sh", argv, environ); | |
6038 | |
6039 // execve failed | |
6040 _exit(-1); | |
6041 | |
6042 } else { | |
6043 // copied from J2SE ..._waitForProcessExit() in UNIXProcess_md.c; we don't | |
6044 // care about the actual exit code, for now. | |
6045 | |
6046 int status; | |
6047 | |
6048 // Wait for the child process to exit. This returns immediately if | |
6049 // the child has already exited. */ | |
6050 while (waitpid(pid, &status, 0) < 0) { | |
6051 switch (errno) { | |
6052 case ECHILD: return 0; | |
6053 case EINTR: break; | |
6054 default: return -1; | |
6055 } | |
6056 } | |
6057 | |
6058 if (WIFEXITED(status)) { | |
6059 // The child exited normally; get its exit code. | |
6060 return WEXITSTATUS(status); | |
6061 } else if (WIFSIGNALED(status)) { | |
6062 // The child exited because of a signal | |
6063 // The best value to return is 0x80 + signal number, | |
6064 // because that is what all Unix shells do, and because | |
6065 // it allows callers to distinguish between process exit and | |
6066 // process death by signal. | |
6067 return 0x80 + WTERMSIG(status); | |
6068 } else { | |
6069 // Unknown exit code; pass it through | |
6070 return status; | |
6071 } | |
6072 } | |
6073 } | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6074 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6075 // is_headless_jre() |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6076 // |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6077 // Test for the existence of libmawt in motif21 or xawt directories |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6078 // in order to report if we are running in a headless jre |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6079 // |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6080 bool os::is_headless_jre() { |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6081 struct stat statbuf; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6082 char buf[MAXPATHLEN]; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6083 char libmawtpath[MAXPATHLEN]; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6084 const char *xawtstr = "/xawt/libmawt.so"; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6085 const char *motifstr = "/motif21/libmawt.so"; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6086 char *p; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6087 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6088 // Get path to libjvm.so |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6089 os::jvm_path(buf, sizeof(buf)); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6090 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6091 // Get rid of libjvm.so |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6092 p = strrchr(buf, '/'); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6093 if (p == NULL) return false; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6094 else *p = '\0'; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6095 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6096 // Get rid of client or server |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6097 p = strrchr(buf, '/'); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6098 if (p == NULL) return false; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6099 else *p = '\0'; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6100 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6101 // check xawt/libmawt.so |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6102 strcpy(libmawtpath, buf); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6103 strcat(libmawtpath, xawtstr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6104 if (::stat(libmawtpath, &statbuf) == 0) return false; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6105 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6106 // check motif21/libmawt.so |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6107 strcpy(libmawtpath, buf); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6108 strcat(libmawtpath, motifstr); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6109 if (::stat(libmawtpath, &statbuf) == 0) return false; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6110 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6111 return true; |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6112 } |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6113 |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1642
diff
changeset
|
6114 |