Mercurial > hg > truffle
annotate src/os_cpu/solaris_sparc/vm/os_solaris_sparc.cpp @ 10519:3891371b2a3b
Method renaming
author | Christos Kotselidis <christos.kotselidis@oracle.com> |
---|---|
date | Mon, 24 Jun 2013 14:52:44 +0200 |
parents | f2110083203d |
children | 980532a806a5 5e3b6f79d280 |
rev | line source |
---|---|
0 | 1 /* |
10405 | 2 * Copyright (c) 1999, 2013, 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:
844
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
844
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:
844
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 // no precompiled headers |
7204
f0c2369fda5a
8003250: SPARC: move MacroAssembler into separate file
twisti
parents:
6842
diff
changeset
|
26 #include "asm/macroAssembler.hpp" |
1972 | 27 #include "classfile/classLoader.hpp" |
28 #include "classfile/systemDictionary.hpp" | |
29 #include "classfile/vmSymbols.hpp" | |
30 #include "code/icBuffer.hpp" | |
31 #include "code/vtableStubs.hpp" | |
32 #include "interpreter/interpreter.hpp" | |
33 #include "jvm_solaris.h" | |
34 #include "memory/allocation.inline.hpp" | |
35 #include "mutex_solaris.inline.hpp" | |
36 #include "nativeInst_sparc.hpp" | |
37 #include "os_share_solaris.hpp" | |
38 #include "prims/jniFastGetField.hpp" | |
39 #include "prims/jvm.h" | |
40 #include "prims/jvm_misc.hpp" | |
41 #include "runtime/arguments.hpp" | |
42 #include "runtime/extendedPC.hpp" | |
43 #include "runtime/frame.inline.hpp" | |
44 #include "runtime/interfaceSupport.hpp" | |
45 #include "runtime/java.hpp" | |
46 #include "runtime/javaCalls.hpp" | |
47 #include "runtime/mutexLocker.hpp" | |
48 #include "runtime/osThread.hpp" | |
49 #include "runtime/sharedRuntime.hpp" | |
50 #include "runtime/stubRoutines.hpp" | |
7180
f34d701e952e
8003935: Simplify the needed includes for using Thread::current()
stefank
parents:
6842
diff
changeset
|
51 #include "runtime/thread.inline.hpp" |
1972 | 52 #include "runtime/timer.hpp" |
53 #include "utilities/events.hpp" | |
54 #include "utilities/vmError.hpp" | |
0 | 55 |
56 # include <signal.h> // needed first to avoid name collision for "std" with SC 5.0 | |
57 | |
58 // put OS-includes here | |
59 # include <sys/types.h> | |
60 # include <sys/mman.h> | |
61 # include <pthread.h> | |
62 # include <errno.h> | |
63 # include <dlfcn.h> | |
64 # include <stdio.h> | |
65 # include <unistd.h> | |
66 # include <sys/resource.h> | |
67 # include <thread.h> | |
68 # include <sys/stat.h> | |
69 # include <sys/time.h> | |
70 # include <sys/filio.h> | |
71 # include <sys/utsname.h> | |
72 # include <sys/systeminfo.h> | |
73 # include <sys/socket.h> | |
74 # include <sys/lwp.h> | |
75 # include <pwd.h> | |
76 # include <poll.h> | |
77 # include <sys/lwp.h> | |
78 | |
79 # define _STRUCTURED_PROC 1 // this gets us the new structured proc interfaces of 5.6 & later | |
80 # include <sys/procfs.h> // see comment in <sys/procfs.h> | |
81 | |
82 #define MAX_PATH (2 * K) | |
83 | |
84 // Minimum stack size for the VM. It's easier to document a constant | |
85 // but it's different for x86 and sparc because the page sizes are different. | |
86 #ifdef _LP64 | |
87 size_t os::Solaris::min_stack_allowed = 128*K; | |
88 #else | |
89 size_t os::Solaris::min_stack_allowed = 96*K; | |
90 #endif | |
91 | |
92 int os::Solaris::max_register_window_saves_before_flushing() { | |
93 // We should detect this at run time. For now, filling | |
94 // in with a constant. | |
95 return 8; | |
96 } | |
97 | |
98 static void handle_unflushed_register_windows(gwindows_t *win) { | |
99 int restore_count = win->wbcnt; | |
100 int i; | |
101 | |
102 for(i=0; i<restore_count; i++) { | |
103 address sp = ((address)win->spbuf[i]) + STACK_BIAS; | |
104 address reg_win = (address)&win->wbuf[i]; | |
105 memcpy(sp,reg_win,sizeof(struct rwindow)); | |
106 } | |
107 } | |
108 | |
109 char* os::non_memory_address_word() { | |
110 // Must never look like an address returned by reserve_memory, | |
111 // even in its subfields (as defined by the CPU immediate fields, | |
112 // if the CPU splits constants across multiple instructions). | |
113 // On SPARC, 0 != %hi(any real address), because there is no | |
114 // allocation in the first 1Kb of the virtual address space. | |
115 return (char*) 0; | |
116 } | |
117 | |
118 // Validate a ucontext retrieved from walking a uc_link of a ucontext. | |
119 // There are issues with libthread giving out uc_links for different threads | |
120 // on the same uc_link chain and bad or circular links. | |
121 // | |
122 bool os::Solaris::valid_ucontext(Thread* thread, ucontext_t* valid, ucontext_t* suspect) { | |
123 if (valid >= suspect || | |
124 valid->uc_stack.ss_flags != suspect->uc_stack.ss_flags || | |
125 valid->uc_stack.ss_sp != suspect->uc_stack.ss_sp || | |
126 valid->uc_stack.ss_size != suspect->uc_stack.ss_size) { | |
127 DEBUG_ONLY(tty->print_cr("valid_ucontext: failed test 1");) | |
128 return false; | |
129 } | |
130 | |
131 if (thread->is_Java_thread()) { | |
132 if (!valid_stack_address(thread, (address)suspect)) { | |
133 DEBUG_ONLY(tty->print_cr("valid_ucontext: uc_link not in thread stack");) | |
134 return false; | |
135 } | |
136 address _sp = (address)((intptr_t)suspect->uc_mcontext.gregs[REG_SP] + STACK_BIAS); | |
137 if (!valid_stack_address(thread, _sp) || | |
138 !frame::is_valid_stack_pointer(((JavaThread*)thread)->base_of_stack_pointer(), (intptr_t*)_sp)) { | |
139 DEBUG_ONLY(tty->print_cr("valid_ucontext: stackpointer not in thread stack");) | |
140 return false; | |
141 } | |
142 } | |
143 return true; | |
144 } | |
145 | |
146 // We will only follow one level of uc_link since there are libthread | |
147 // issues with ucontext linking and it is better to be safe and just | |
148 // let caller retry later. | |
149 ucontext_t* os::Solaris::get_valid_uc_in_signal_handler(Thread *thread, | |
150 ucontext_t *uc) { | |
151 | |
152 ucontext_t *retuc = NULL; | |
153 | |
154 // Sometimes the topmost register windows are not properly flushed. | |
155 // i.e., if the kernel would have needed to take a page fault | |
156 if (uc != NULL && uc->uc_mcontext.gwins != NULL) { | |
157 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); | |
158 } | |
159 | |
160 if (uc != NULL) { | |
161 if (uc->uc_link == NULL) { | |
162 // cannot validate without uc_link so accept current ucontext | |
163 retuc = uc; | |
164 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { | |
165 // first ucontext is valid so try the next one | |
166 uc = uc->uc_link; | |
167 if (uc->uc_link == NULL) { | |
168 // cannot validate without uc_link so accept current ucontext | |
169 retuc = uc; | |
170 } else if (os::Solaris::valid_ucontext(thread, uc, uc->uc_link)) { | |
171 // the ucontext one level down is also valid so return it | |
172 retuc = uc; | |
173 } | |
174 } | |
175 } | |
176 return retuc; | |
177 } | |
178 | |
179 // Assumes ucontext is valid | |
180 ExtendedPC os::Solaris::ucontext_get_ExtendedPC(ucontext_t *uc) { | |
181 address pc = (address)uc->uc_mcontext.gregs[REG_PC]; | |
182 // set npc to zero to avoid using it for safepoint, good for profiling only | |
183 return ExtendedPC(pc); | |
184 } | |
185 | |
186 // Assumes ucontext is valid | |
187 intptr_t* os::Solaris::ucontext_get_sp(ucontext_t *uc) { | |
188 return (intptr_t*)((intptr_t)uc->uc_mcontext.gregs[REG_SP] + STACK_BIAS); | |
189 } | |
190 | |
191 // Solaris X86 only | |
192 intptr_t* os::Solaris::ucontext_get_fp(ucontext_t *uc) { | |
193 ShouldNotReachHere(); | |
194 return NULL; | |
195 } | |
196 | |
10405 | 197 address os::Solaris::ucontext_get_pc(ucontext_t *uc) { |
198 return (address) uc->uc_mcontext.gregs[REG_PC]; | |
199 } | |
200 | |
201 | |
0 | 202 // For Forte Analyzer AsyncGetCallTrace profiling support - thread |
203 // is currently interrupted by SIGPROF. | |
204 // | |
205 // ret_fp parameter is only used by Solaris X86. | |
206 // | |
207 // The difference between this and os::fetch_frame_from_context() is that | |
208 // here we try to skip nested signal frames. | |
209 ExtendedPC os::Solaris::fetch_frame_from_ucontext(Thread* thread, | |
210 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) { | |
211 | |
212 assert(thread != NULL, "just checking"); | |
213 assert(ret_sp != NULL, "just checking"); | |
214 assert(ret_fp == NULL, "just checking"); | |
215 | |
216 ucontext_t *luc = os::Solaris::get_valid_uc_in_signal_handler(thread, uc); | |
217 | |
218 return os::fetch_frame_from_context(luc, ret_sp, ret_fp); | |
219 } | |
220 | |
221 | |
222 // ret_fp parameter is only used by Solaris X86. | |
223 ExtendedPC os::fetch_frame_from_context(void* ucVoid, | |
224 intptr_t** ret_sp, intptr_t** ret_fp) { | |
225 | |
226 ExtendedPC epc; | |
227 ucontext_t *uc = (ucontext_t*)ucVoid; | |
228 | |
229 if (uc != NULL) { | |
230 epc = os::Solaris::ucontext_get_ExtendedPC(uc); | |
231 if (ret_sp) *ret_sp = os::Solaris::ucontext_get_sp(uc); | |
232 } else { | |
233 // construct empty ExtendedPC for return value checking | |
234 epc = ExtendedPC(NULL); | |
235 if (ret_sp) *ret_sp = (intptr_t *)NULL; | |
236 } | |
237 | |
238 return epc; | |
239 } | |
240 | |
241 frame os::fetch_frame_from_context(void* ucVoid) { | |
242 intptr_t* sp; | |
243 intptr_t* fp; | |
244 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); | |
245 return frame(sp, frame::unpatchable, epc.pc()); | |
246 } | |
247 | |
248 frame os::get_sender_for_C_frame(frame* fr) { | |
249 return frame(fr->sender_sp(), frame::unpatchable, fr->sender_pc()); | |
250 } | |
251 | |
5903
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
252 // Returns an estimate of the current stack pointer. Result must be guaranteed to |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
253 // point into the calling threads stack, and be no lower than the current stack |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
254 // pointer. |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
255 address os::current_stack_pointer() { |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
256 volatile int dummy; |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
257 address sp = (address)&dummy + 8; // %%%% need to confirm if this is right |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
258 return sp; |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
259 } |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
260 |
0 | 261 frame os::current_frame() { |
262 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); | |
263 frame myframe(sp, frame::unpatchable, | |
264 CAST_FROM_FN_PTR(address, os::current_frame)); | |
265 if (os::is_first_C_frame(&myframe)) { | |
266 // stack is not walkable | |
267 return frame(NULL, NULL, NULL); | |
268 } else { | |
269 return os::get_sender_for_C_frame(&myframe); | |
270 } | |
271 } | |
272 | |
273 static int threadgetstate(thread_t tid, int *flags, lwpid_t *lwp, stack_t *ss, gregset_t rs, lwpstatus_t *lwpstatus) { | |
274 char lwpstatusfile[PROCFILE_LENGTH]; | |
275 int lwpfd, err; | |
276 | |
277 if (err = os::Solaris::thr_getstate(tid, flags, lwp, ss, rs)) | |
278 return (err); | |
279 if (*flags == TRS_LWPID) { | |
280 sprintf(lwpstatusfile, "/proc/%d/lwp/%d/lwpstatus", getpid(), | |
281 *lwp); | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
282 if ((lwpfd = ::open(lwpstatusfile, O_RDONLY)) < 0) { |
0 | 283 perror("thr_mutator_status: open lwpstatus"); |
284 return (EINVAL); | |
285 } | |
286 if (pread(lwpfd, lwpstatus, sizeof (lwpstatus_t), (off_t)0) != | |
287 sizeof (lwpstatus_t)) { | |
288 perror("thr_mutator_status: read lwpstatus"); | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
289 (void) ::close(lwpfd); |
0 | 290 return (EINVAL); |
291 } | |
1980
828eafbd85cc
6348631: remove the use of the HPI library from Hotspot
ikrylov
parents:
1972
diff
changeset
|
292 (void) ::close(lwpfd); |
0 | 293 } |
294 return (0); | |
295 } | |
296 | |
297 | |
298 bool os::is_allocatable(size_t bytes) { | |
299 #ifdef _LP64 | |
300 return true; | |
301 #else | |
302 return (bytes <= (size_t)3835*M); | |
303 #endif | |
304 } | |
305 | |
306 extern "C" void Fetch32PFI () ; | |
307 extern "C" void Fetch32Resume () ; | |
308 extern "C" void FetchNPFI () ; | |
309 extern "C" void FetchNResume () ; | |
310 | |
2191 | 311 extern "C" JNIEXPORT int |
312 JVM_handle_solaris_signal(int sig, siginfo_t* info, void* ucVoid, | |
313 int abort_if_unrecognized) { | |
0 | 314 ucontext_t* uc = (ucontext_t*) ucVoid; |
315 | |
316 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
317 | |
318 SignalHandlerMark shm(t); | |
319 | |
320 if(sig == SIGPIPE || sig == SIGXFSZ) { | |
321 if (os::Solaris::chained_handler(sig, info, ucVoid)) { | |
322 return true; | |
323 } else { | |
324 if (PrintMiscellaneous && (WizardMode || Verbose)) { | |
325 char buf[64]; | |
326 warning("Ignoring %s - see 4229104 or 6499219", | |
327 os::exception_name(sig, buf, sizeof(buf))); | |
328 | |
329 } | |
330 return true; | |
331 } | |
332 } | |
333 | |
334 JavaThread* thread = NULL; | |
335 VMThread* vmthread = NULL; | |
336 if (os::Solaris::signal_handlers_are_installed) { | |
337 if (t != NULL ){ | |
338 if(t->is_Java_thread()) { | |
339 thread = (JavaThread*)t; | |
340 } | |
341 else if(t->is_VM_thread()){ | |
342 vmthread = (VMThread *)t; | |
343 } | |
344 } | |
345 } | |
346 | |
347 guarantee(sig != os::Solaris::SIGinterrupt(), "Can not chain VM interrupt signal, try -XX:+UseAltSigs"); | |
348 | |
349 if (sig == os::Solaris::SIGasync()) { | |
10405 | 350 if (thread || vmthread) { |
351 OSThread::SR_handler(t, uc); | |
0 | 352 return true; |
353 } else if (os::Solaris::chained_handler(sig, info, ucVoid)) { | |
354 return true; | |
355 } else { | |
356 // If os::Solaris::SIGasync not chained, and this is a non-vm and | |
357 // non-java thread | |
358 return true; | |
359 } | |
360 } | |
361 | |
362 if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) { | |
363 // can't decode this kind of signal | |
364 info = NULL; | |
365 } else { | |
366 assert(sig == info->si_signo, "bad siginfo"); | |
367 } | |
368 | |
369 // decide if this trap can be handled by a stub | |
370 address stub = NULL; | |
371 | |
372 address pc = NULL; | |
373 address npc = NULL; | |
374 | |
375 //%note os_trap_1 | |
376 if (info != NULL && uc != NULL && thread != NULL) { | |
377 // factor me: getPCfromContext | |
378 pc = (address) uc->uc_mcontext.gregs[REG_PC]; | |
379 npc = (address) uc->uc_mcontext.gregs[REG_nPC]; | |
380 | |
381 // SafeFetch() support | |
382 // Implemented with either a fixed set of addresses such | |
383 // as Fetch32*, or with Thread._OnTrap. | |
384 if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(Fetch32PFI)) { | |
385 uc->uc_mcontext.gregs [REG_PC] = intptr_t(Fetch32Resume) ; | |
386 uc->uc_mcontext.gregs [REG_nPC] = intptr_t(Fetch32Resume) + 4 ; | |
387 return true ; | |
388 } | |
389 if (uc->uc_mcontext.gregs[REG_PC] == intptr_t(FetchNPFI)) { | |
390 uc->uc_mcontext.gregs [REG_PC] = intptr_t(FetchNResume) ; | |
391 uc->uc_mcontext.gregs [REG_nPC] = intptr_t(FetchNResume) + 4 ; | |
392 return true ; | |
393 } | |
394 | |
395 // Handle ALL stack overflow variations here | |
396 if (sig == SIGSEGV && info->si_code == SEGV_ACCERR) { | |
397 address addr = (address) info->si_addr; | |
398 if (thread->in_stack_yellow_zone(addr)) { | |
399 thread->disable_stack_yellow_zone(); | |
400 // Sometimes the register windows are not properly flushed. | |
401 if(uc->uc_mcontext.gwins != NULL) { | |
402 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); | |
403 } | |
404 if (thread->thread_state() == _thread_in_Java) { | |
405 // Throw a stack overflow exception. Guard pages will be reenabled | |
406 // while unwinding the stack. | |
407 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW); | |
408 } else { | |
409 // Thread was in the vm or native code. Return and try to finish. | |
410 return true; | |
411 } | |
412 } else if (thread->in_stack_red_zone(addr)) { | |
413 // Fatal red zone violation. Disable the guard pages and fall through | |
414 // to handle_unexpected_exception way down below. | |
415 thread->disable_stack_red_zone(); | |
416 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); | |
417 // Sometimes the register windows are not properly flushed. | |
418 if(uc->uc_mcontext.gwins != NULL) { | |
419 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); | |
420 } | |
421 } | |
422 } | |
423 | |
424 | |
425 if (thread->thread_state() == _thread_in_vm) { | |
426 if (sig == SIGBUS && info->si_code == BUS_OBJERR && thread->doing_unsafe_access()) { | |
427 stub = StubRoutines::handler_for_unsafe_access(); | |
428 } | |
429 } | |
430 | |
431 else if (thread->thread_state() == _thread_in_Java) { | |
432 // Java thread running in Java code => find exception handler if any | |
433 // a fault inside compiled code, the interpreter, or a stub | |
434 | |
435 // Support Safepoint Polling | |
436 if ( sig == SIGSEGV && (address)info->si_addr == os::get_polling_page() ) { | |
437 stub = SharedRuntime::get_poll_stub(pc); | |
438 } | |
439 | |
440 // Not needed on x86 solaris because verify_oops doesn't generate | |
441 // SEGV/BUS like sparc does. | |
442 if ( (sig == SIGSEGV || sig == SIGBUS) | |
443 && pc >= MacroAssembler::_verify_oop_implicit_branch[0] | |
444 && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { | |
445 stub = MacroAssembler::_verify_oop_implicit_branch[2]; | |
446 warning("fixed up memory fault in +VerifyOops at address " INTPTR_FORMAT, info->si_addr); | |
447 } | |
448 | |
449 // This is not factored because on x86 solaris the patching for | |
450 // zombies does not generate a SEGV. | |
451 else if (sig == SIGSEGV && nativeInstruction_at(pc)->is_zombie()) { | |
452 // zombie method (ld [%g0],%o7 instruction) | |
453 stub = SharedRuntime::get_handle_wrong_method_stub(); | |
454 | |
455 // At the stub it needs to look like a call from the caller of this | |
456 // method (not a call from the segv site). | |
457 pc = (address)uc->uc_mcontext.gregs[REG_O7]; | |
458 } | |
459 else if (sig == SIGBUS && info->si_code == BUS_OBJERR) { | |
460 // BugId 4454115: A read from a MappedByteBuffer can fault | |
461 // here if the underlying file has been truncated. | |
462 // Do not crash the VM in such a case. | |
463 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); | |
464 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; | |
465 if (nm != NULL && nm->has_unsafe_access()) { | |
466 stub = StubRoutines::handler_for_unsafe_access(); | |
467 } | |
468 } | |
469 | |
470 else if (sig == SIGFPE && info->si_code == FPE_INTDIV) { | |
471 // integer divide by zero | |
472 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); | |
473 } | |
474 else if (sig == SIGFPE && info->si_code == FPE_FLTDIV) { | |
475 // floating-point divide by zero | |
476 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); | |
477 } | |
478 #ifdef COMPILER2 | |
479 else if (sig == SIGILL && nativeInstruction_at(pc)->is_ic_miss_trap()) { | |
480 #ifdef ASSERT | |
481 #ifdef TIERED | |
482 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); | |
483 assert(cb->is_compiled_by_c2(), "Wrong compiler"); | |
484 #endif // TIERED | |
485 #endif // ASSERT | |
486 // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. | |
487 stub = SharedRuntime::get_ic_miss_stub(); | |
488 // At the stub it needs to look like a call from the caller of this | |
489 // method (not a call from the segv site). | |
490 pc = (address)uc->uc_mcontext.gregs[REG_O7]; | |
491 } | |
492 #endif // COMPILER2 | |
493 | |
494 else if (sig == SIGSEGV && info->si_code > 0 && !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) { | |
495 // Determination of interpreter/vtable stub/compiled code null exception | |
496 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL); | |
497 } | |
498 } | |
499 | |
500 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in | |
501 // and the heap gets shrunk before the field access. | |
502 if ((sig == SIGSEGV) || (sig == SIGBUS)) { | |
503 address addr = JNI_FastGetField::find_slowcase_pc(pc); | |
504 if (addr != (address)-1) { | |
505 stub = addr; | |
506 } | |
507 } | |
508 | |
509 // Check to see if we caught the safepoint code in the | |
510 // process of write protecting the memory serialization page. | |
511 // It write enables the page immediately after protecting it | |
512 // so just return. | |
513 if ((sig == SIGSEGV) && | |
514 os::is_memory_serialize_page(thread, (address)info->si_addr)) { | |
515 // Block current thread until the memory serialize page permission restored. | |
516 os::block_on_serialize_page_trap(); | |
517 return true; | |
518 } | |
519 } | |
520 | |
521 if (stub != NULL) { | |
522 // save all thread context in case we need to restore it | |
523 | |
524 thread->set_saved_exception_pc(pc); | |
525 thread->set_saved_exception_npc(npc); | |
526 | |
527 // simulate a branch to the stub (a "call" in the safepoint stub case) | |
528 // factor me: setPC | |
529 uc->uc_mcontext.gregs[REG_PC ] = (greg_t)stub; | |
530 uc->uc_mcontext.gregs[REG_nPC] = (greg_t)(stub + 4); | |
531 | |
532 #ifndef PRODUCT | |
533 if (TraceJumps) thread->record_jump(stub, NULL, __FILE__, __LINE__); | |
534 #endif /* PRODUCT */ | |
535 | |
536 return true; | |
537 } | |
538 | |
539 // signal-chaining | |
540 if (os::Solaris::chained_handler(sig, info, ucVoid)) { | |
541 return true; | |
542 } | |
543 | |
544 if (!abort_if_unrecognized) { | |
545 // caller wants another chance, so give it to him | |
546 return false; | |
547 } | |
548 | |
549 if (!os::Solaris::libjsig_is_loaded) { | |
550 struct sigaction oldAct; | |
551 sigaction(sig, (struct sigaction *)0, &oldAct); | |
552 if (oldAct.sa_sigaction != signalHandler) { | |
553 void* sighand = oldAct.sa_sigaction ? CAST_FROM_FN_PTR(void*, oldAct.sa_sigaction) | |
554 : CAST_FROM_FN_PTR(void*, oldAct.sa_handler); | |
605 | 555 warning("Unexpected Signal %d occurred under user-defined signal handler " INTPTR_FORMAT, sig, (intptr_t)sighand); |
0 | 556 } |
557 } | |
558 | |
559 if (pc == NULL && uc != NULL) { | |
560 pc = (address) uc->uc_mcontext.gregs[REG_PC]; | |
561 } | |
562 | |
1907 | 563 // Sometimes the register windows are not properly flushed. |
564 if(uc->uc_mcontext.gwins != NULL) { | |
565 ::handle_unflushed_register_windows(uc->uc_mcontext.gwins); | |
566 } | |
567 | |
0 | 568 // unmask current signal |
569 sigset_t newset; | |
570 sigemptyset(&newset); | |
571 sigaddset(&newset, sig); | |
572 sigprocmask(SIG_UNBLOCK, &newset, NULL); | |
573 | |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
574 // Determine which sort of error to throw. Out of swap may signal |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
575 // on the thread stack, which could get a mapping error when touched. |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
576 address addr = (address) info->si_addr; |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
577 if (sig == SIGBUS && info->si_code == BUS_OBJERR && info->si_errno == ENOMEM) { |
10161
746b070f5022
8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
ccheung
parents:
7206
diff
changeset
|
578 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "Out of swap space to map in thread stack."); |
2095
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
579 } |
36c186bcc085
6302804: Hotspot VM dies ungraceful death when C heap is exhausted in various places.
coleenp
parents:
1980
diff
changeset
|
580 |
0 | 581 VMError err(t, sig, pc, info, ucVoid); |
582 err.report_and_die(); | |
583 | |
584 ShouldNotReachHere(); | |
585 } | |
586 | |
587 void os::print_context(outputStream *st, void *context) { | |
588 if (context == NULL) return; | |
589 | |
590 ucontext_t *uc = (ucontext_t*)context; | |
591 st->print_cr("Registers:"); | |
592 | |
1907 | 593 st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT |
594 " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, | |
595 uc->uc_mcontext.gregs[REG_G1], | |
596 uc->uc_mcontext.gregs[REG_G2], | |
597 uc->uc_mcontext.gregs[REG_G3], | |
598 uc->uc_mcontext.gregs[REG_G4]); | |
599 st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT | |
600 " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, | |
601 uc->uc_mcontext.gregs[REG_G5], | |
602 uc->uc_mcontext.gregs[REG_G6], | |
603 uc->uc_mcontext.gregs[REG_G7], | |
604 uc->uc_mcontext.gregs[REG_Y]); | |
0 | 605 st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT |
606 " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, | |
607 uc->uc_mcontext.gregs[REG_O0], | |
608 uc->uc_mcontext.gregs[REG_O1], | |
609 uc->uc_mcontext.gregs[REG_O2], | |
610 uc->uc_mcontext.gregs[REG_O3]); | |
611 st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT | |
612 " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, | |
613 uc->uc_mcontext.gregs[REG_O4], | |
614 uc->uc_mcontext.gregs[REG_O5], | |
615 uc->uc_mcontext.gregs[REG_O6], | |
616 uc->uc_mcontext.gregs[REG_O7]); | |
617 | |
1907 | 618 |
619 intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc); | |
620 st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT | |
621 " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, | |
622 sp[L0->sp_offset_in_saved_window()], | |
623 sp[L1->sp_offset_in_saved_window()], | |
624 sp[L2->sp_offset_in_saved_window()], | |
625 sp[L3->sp_offset_in_saved_window()]); | |
626 st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT | |
627 " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, | |
628 sp[L4->sp_offset_in_saved_window()], | |
629 sp[L5->sp_offset_in_saved_window()], | |
630 sp[L6->sp_offset_in_saved_window()], | |
631 sp[L7->sp_offset_in_saved_window()]); | |
632 st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT | |
633 " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, | |
634 sp[I0->sp_offset_in_saved_window()], | |
635 sp[I1->sp_offset_in_saved_window()], | |
636 sp[I2->sp_offset_in_saved_window()], | |
637 sp[I3->sp_offset_in_saved_window()]); | |
638 st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT | |
639 " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, | |
640 sp[I4->sp_offset_in_saved_window()], | |
641 sp[I5->sp_offset_in_saved_window()], | |
642 sp[I6->sp_offset_in_saved_window()], | |
643 sp[I7->sp_offset_in_saved_window()]); | |
0 | 644 |
645 st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, | |
646 uc->uc_mcontext.gregs[REG_PC], | |
647 uc->uc_mcontext.gregs[REG_nPC]); | |
1681
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
648 st->cr(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
649 st->cr(); |
126ea7725993
6953477: Increase portability and flexibility of building Hotspot
bobv
parents:
1552
diff
changeset
|
650 |
0 | 651 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); |
652 print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); | |
653 st->cr(); | |
654 | |
655 // Note: it may be unsafe to inspect memory near pc. For example, pc may | |
656 // point to garbage if entry point in an nmethod is corrupted. Leave | |
657 // this at the end, and hope for the best. | |
658 ExtendedPC epc = os::Solaris::ucontext_get_ExtendedPC(uc); | |
659 address pc = epc.pc(); | |
660 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); | |
1907 | 661 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); |
662 } | |
663 | |
664 void os::print_register_info(outputStream *st, void *context) { | |
665 if (context == NULL) return; | |
666 | |
667 ucontext_t *uc = (ucontext_t*)context; | |
668 intptr_t *sp = (intptr_t *)os::Solaris::ucontext_get_sp(uc); | |
669 | |
670 st->print_cr("Register to memory mapping:"); | |
671 st->cr(); | |
672 | |
673 // this is only for the "general purpose" registers | |
674 st->print("G1="); print_location(st, uc->uc_mcontext.gregs[REG_G1]); | |
675 st->print("G2="); print_location(st, uc->uc_mcontext.gregs[REG_G2]); | |
676 st->print("G3="); print_location(st, uc->uc_mcontext.gregs[REG_G3]); | |
677 st->print("G4="); print_location(st, uc->uc_mcontext.gregs[REG_G4]); | |
678 st->print("G5="); print_location(st, uc->uc_mcontext.gregs[REG_G5]); | |
679 st->print("G6="); print_location(st, uc->uc_mcontext.gregs[REG_G6]); | |
680 st->print("G7="); print_location(st, uc->uc_mcontext.gregs[REG_G7]); | |
681 st->cr(); | |
682 | |
683 st->print("O0="); print_location(st, uc->uc_mcontext.gregs[REG_O0]); | |
684 st->print("O1="); print_location(st, uc->uc_mcontext.gregs[REG_O1]); | |
685 st->print("O2="); print_location(st, uc->uc_mcontext.gregs[REG_O2]); | |
686 st->print("O3="); print_location(st, uc->uc_mcontext.gregs[REG_O3]); | |
687 st->print("O4="); print_location(st, uc->uc_mcontext.gregs[REG_O4]); | |
688 st->print("O5="); print_location(st, uc->uc_mcontext.gregs[REG_O5]); | |
689 st->print("O6="); print_location(st, uc->uc_mcontext.gregs[REG_O6]); | |
690 st->print("O7="); print_location(st, uc->uc_mcontext.gregs[REG_O7]); | |
691 st->cr(); | |
692 | |
693 st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); | |
694 st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); | |
695 st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); | |
696 st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); | |
697 st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); | |
698 st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); | |
699 st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); | |
700 st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); | |
701 st->cr(); | |
702 | |
703 st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); | |
704 st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); | |
705 st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); | |
706 st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); | |
707 st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); | |
708 st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); | |
709 st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); | |
710 st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); | |
711 st->cr(); | |
0 | 712 } |
713 | |
714 void os::Solaris::init_thread_fpu_state(void) { | |
715 // Nothing needed on Sparc. | |
716 } | |
717 | |
718 #if !defined(COMPILER2) && !defined(_LP64) | |
719 | |
720 // These routines are the initial value of atomic_xchg_entry(), | |
721 // atomic_cmpxchg_entry(), atomic_add_entry() and fence_entry() | |
722 // until initialization is complete. | |
723 // TODO - remove when the VM drops support for V8. | |
724 | |
725 typedef jint xchg_func_t (jint, volatile jint*); | |
726 typedef jint cmpxchg_func_t (jint, volatile jint*, jint); | |
727 typedef jlong cmpxchg_long_func_t(jlong, volatile jlong*, jlong); | |
728 typedef jint add_func_t (jint, volatile jint*); | |
729 | |
730 jint os::atomic_xchg_bootstrap(jint exchange_value, volatile jint* dest) { | |
731 // try to use the stub: | |
732 xchg_func_t* func = CAST_TO_FN_PTR(xchg_func_t*, StubRoutines::atomic_xchg_entry()); | |
733 | |
734 if (func != NULL) { | |
735 os::atomic_xchg_func = func; | |
736 return (*func)(exchange_value, dest); | |
737 } | |
738 assert(Threads::number_of_threads() == 0, "for bootstrap only"); | |
739 | |
740 jint old_value = *dest; | |
741 *dest = exchange_value; | |
742 return old_value; | |
743 } | |
744 | |
745 jint os::atomic_cmpxchg_bootstrap(jint exchange_value, volatile jint* dest, jint compare_value) { | |
746 // try to use the stub: | |
747 cmpxchg_func_t* func = CAST_TO_FN_PTR(cmpxchg_func_t*, StubRoutines::atomic_cmpxchg_entry()); | |
748 | |
749 if (func != NULL) { | |
750 os::atomic_cmpxchg_func = func; | |
751 return (*func)(exchange_value, dest, compare_value); | |
752 } | |
753 assert(Threads::number_of_threads() == 0, "for bootstrap only"); | |
754 | |
755 jint old_value = *dest; | |
756 if (old_value == compare_value) | |
757 *dest = exchange_value; | |
758 return old_value; | |
759 } | |
760 | |
761 jlong os::atomic_cmpxchg_long_bootstrap(jlong exchange_value, volatile jlong* dest, jlong compare_value) { | |
762 // try to use the stub: | |
763 cmpxchg_long_func_t* func = CAST_TO_FN_PTR(cmpxchg_long_func_t*, StubRoutines::atomic_cmpxchg_long_entry()); | |
764 | |
765 if (func != NULL) { | |
766 os::atomic_cmpxchg_long_func = func; | |
767 return (*func)(exchange_value, dest, compare_value); | |
768 } | |
769 assert(Threads::number_of_threads() == 0, "for bootstrap only"); | |
770 | |
771 jlong old_value = *dest; | |
772 if (old_value == compare_value) | |
773 *dest = exchange_value; | |
774 return old_value; | |
775 } | |
776 | |
777 jint os::atomic_add_bootstrap(jint add_value, volatile jint* dest) { | |
778 // try to use the stub: | |
779 add_func_t* func = CAST_TO_FN_PTR(add_func_t*, StubRoutines::atomic_add_entry()); | |
780 | |
781 if (func != NULL) { | |
782 os::atomic_add_func = func; | |
783 return (*func)(add_value, dest); | |
784 } | |
785 assert(Threads::number_of_threads() == 0, "for bootstrap only"); | |
786 | |
787 return (*dest) += add_value; | |
788 } | |
789 | |
790 xchg_func_t* os::atomic_xchg_func = os::atomic_xchg_bootstrap; | |
791 cmpxchg_func_t* os::atomic_cmpxchg_func = os::atomic_cmpxchg_bootstrap; | |
792 cmpxchg_long_func_t* os::atomic_cmpxchg_long_func = os::atomic_cmpxchg_long_bootstrap; | |
793 add_func_t* os::atomic_add_func = os::atomic_add_bootstrap; | |
794 | |
795 #endif // !_LP64 && !COMPILER2 | |
796 | |
797 #if defined(__sparc) && defined(COMPILER2) && defined(_GNU_SOURCE) | |
798 // See file build/solaris/makefiles/$compiler.make | |
799 // For compiler1 the architecture is v8 and frps isn't present in v8 | |
800 extern "C" void _mark_fpu_nosave() { | |
801 __asm__ __volatile__ ("wr %%g0, 0, %%fprs \n\t" : : :); | |
802 } | |
803 #endif //defined(__sparc) && defined(COMPILER2) | |
5903
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
804 |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
805 #ifndef PRODUCT |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
806 void os::verify_stack_alignment() { |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
807 } |
da4be62fb889
7147740: add assertions to check stack alignment on VM entry from generated code (x64)
roland
parents:
2426
diff
changeset
|
808 #endif |