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