Mercurial > hg > graal-compiler
annotate src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp @ 1961:deef066c3622
Merge
author | johnc |
---|---|
date | Tue, 16 Nov 2010 16:12:28 -0800 |
parents | 1e9a9d2e6509 |
children | f95d63e2154a |
rev | line source |
---|---|
133 | 1 /* |
1907 | 2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. |
133 | 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. |
133 | 22 * |
23 */ | |
24 | |
25 // do not include precompiled header file | |
26 | |
27 #include "incls/_os_linux_sparc.cpp.incl" | |
28 | |
29 // Linux/Sparc has rather obscure naming of registers in sigcontext | |
30 // different between 32 and 64 bits | |
31 #ifdef _LP64 | |
32 #define SIG_PC(x) ((x)->sigc_regs.tpc) | |
33 #define SIG_NPC(x) ((x)->sigc_regs.tnpc) | |
34 #define SIG_REGS(x) ((x)->sigc_regs) | |
35 #else | |
36 #define SIG_PC(x) ((x)->si_regs.pc) | |
37 #define SIG_NPC(x) ((x)->si_regs.npc) | |
38 #define SIG_REGS(x) ((x)->si_regs) | |
39 #endif | |
40 | |
41 // those are to reference registers in sigcontext | |
42 enum { | |
43 CON_G0 = 0, | |
44 CON_G1, | |
45 CON_G2, | |
46 CON_G3, | |
47 CON_G4, | |
48 CON_G5, | |
49 CON_G6, | |
50 CON_G7, | |
51 CON_O0, | |
52 CON_O1, | |
53 CON_O2, | |
54 CON_O3, | |
55 CON_O4, | |
56 CON_O5, | |
57 CON_O6, | |
58 CON_O7, | |
59 }; | |
60 | |
61 static inline void set_cont_address(sigcontext* ctx, address addr) { | |
62 SIG_PC(ctx) = (intptr_t)addr; | |
63 SIG_NPC(ctx) = (intptr_t)(addr+4); | |
64 } | |
65 | |
66 // For Forte Analyzer AsyncGetCallTrace profiling support - thread is | |
67 // currently interrupted by SIGPROF. | |
68 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested | |
69 // signal frames. Currently we don't do that on Linux, so it's the | |
70 // same as os::fetch_frame_from_context(). | |
71 ExtendedPC os::Linux::fetch_frame_from_ucontext(Thread* thread, | |
72 ucontext_t* uc, | |
73 intptr_t** ret_sp, | |
74 intptr_t** ret_fp) { | |
75 assert(thread != NULL, "just checking"); | |
76 assert(ret_sp != NULL, "just checking"); | |
77 assert(ret_fp != NULL, "just checking"); | |
78 | |
79 return os::fetch_frame_from_context(uc, ret_sp, ret_fp); | |
80 } | |
81 | |
82 ExtendedPC os::fetch_frame_from_context(void* ucVoid, | |
83 intptr_t** ret_sp, | |
84 intptr_t** ret_fp) { | |
85 ucontext_t* uc = (ucontext_t*) ucVoid; | |
86 ExtendedPC epc; | |
87 | |
88 if (uc != NULL) { | |
89 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc)); | |
90 if (ret_sp) { | |
91 *ret_sp = os::Linux::ucontext_get_sp(uc); | |
92 } | |
93 if (ret_fp) { | |
94 *ret_fp = os::Linux::ucontext_get_fp(uc); | |
95 } | |
96 } else { | |
97 // construct empty ExtendedPC for return value checking | |
98 epc = ExtendedPC(NULL); | |
99 if (ret_sp) { | |
100 *ret_sp = (intptr_t*) NULL; | |
101 } | |
102 if (ret_fp) { | |
103 *ret_fp = (intptr_t*) NULL; | |
104 } | |
105 } | |
106 | |
107 return epc; | |
108 } | |
109 | |
110 frame os::fetch_frame_from_context(void* ucVoid) { | |
111 intptr_t* sp; | |
112 intptr_t* fp; | |
113 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp); | |
114 return frame(sp, fp, epc.pc()); | |
115 } | |
116 | |
117 frame os::get_sender_for_C_frame(frame* fr) { | |
118 return frame(fr->sender_sp(), fr->link(), fr->sender_pc()); | |
119 } | |
120 | |
121 frame os::current_frame() { | |
122 fprintf(stderr, "current_frame()"); | |
123 | |
124 intptr_t* sp = StubRoutines::Sparc::flush_callers_register_windows_func()(); | |
125 frame myframe(sp, frame::unpatchable, | |
126 CAST_FROM_FN_PTR(address, os::current_frame)); | |
127 if (os::is_first_C_frame(&myframe)) { | |
128 // stack is not walkable | |
129 return frame(NULL, frame::unpatchable, NULL); | |
130 } else { | |
131 return os::get_sender_for_C_frame(&myframe); | |
132 } | |
133 } | |
134 | |
135 address os::current_stack_pointer() { | |
136 register void *sp __asm__ ("sp"); | |
137 return (address)sp; | |
138 } | |
139 | |
140 static void current_stack_region(address* bottom, size_t* size) { | |
141 if (os::Linux::is_initial_thread()) { | |
142 // initial thread needs special handling because pthread_getattr_np() | |
143 // may return bogus value. | |
144 *bottom = os::Linux::initial_thread_stack_bottom(); | |
145 *size = os::Linux::initial_thread_stack_size(); | |
146 } else { | |
147 pthread_attr_t attr; | |
148 | |
149 int rslt = pthread_getattr_np(pthread_self(), &attr); | |
150 | |
151 // JVM needs to know exact stack location, abort if it fails | |
152 if (rslt != 0) { | |
153 if (rslt == ENOMEM) { | |
154 vm_exit_out_of_memory(0, "pthread_getattr_np"); | |
155 } else { | |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
196
diff
changeset
|
156 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt)); |
133 | 157 } |
158 } | |
159 | |
160 if (pthread_attr_getstack(&attr, (void**)bottom, size) != 0) { | |
161 fatal("Can not locate current stack attributes!"); | |
162 } | |
163 | |
164 pthread_attr_destroy(&attr); | |
165 } | |
166 assert(os::current_stack_pointer() >= *bottom && | |
167 os::current_stack_pointer() < *bottom + *size, "just checking"); | |
168 } | |
169 | |
170 address os::current_stack_base() { | |
171 address bottom; | |
172 size_t size; | |
173 current_stack_region(&bottom, &size); | |
174 return bottom + size; | |
175 } | |
176 | |
177 size_t os::current_stack_size() { | |
178 // stack size includes normal stack and HotSpot guard pages | |
179 address bottom; | |
180 size_t size; | |
181 current_stack_region(&bottom, &size); | |
182 return size; | |
183 } | |
184 | |
185 char* os::non_memory_address_word() { | |
186 // Must never look like an address returned by reserve_memory, | |
187 // even in its subfields (as defined by the CPU immediate fields, | |
188 // if the CPU splits constants across multiple instructions). | |
189 // On SPARC, 0 != %hi(any real address), because there is no | |
190 // allocation in the first 1Kb of the virtual address space. | |
191 return (char*) 0; | |
192 } | |
193 | |
194 void os::initialize_thread() {} | |
195 | |
196 void os::print_context(outputStream *st, void *context) { | |
197 if (context == NULL) return; | |
198 | |
199 ucontext_t* uc = (ucontext_t*)context; | |
200 sigcontext* sc = (sigcontext*)context; | |
201 st->print_cr("Registers:"); | |
202 | |
1907 | 203 st->print_cr(" G1=" INTPTR_FORMAT " G2=" INTPTR_FORMAT |
204 " G3=" INTPTR_FORMAT " G4=" INTPTR_FORMAT, | |
205 SIG_REGS(sc).u_regs[CON_G1], | |
206 SIG_REGS(sc).u_regs[CON_G2], | |
207 SIG_REGS(sc).u_regs[CON_G3], | |
208 SIG_REGS(sc).u_regs[CON_G4]); | |
209 st->print_cr(" G5=" INTPTR_FORMAT " G6=" INTPTR_FORMAT | |
210 " G7=" INTPTR_FORMAT " Y=" INTPTR_FORMAT, | |
211 SIG_REGS(sc).u_regs[CON_G5], | |
212 SIG_REGS(sc).u_regs[CON_G6], | |
213 SIG_REGS(sc).u_regs[CON_G7], | |
214 SIG_REGS(sc).y); | |
133 | 215 st->print_cr(" O0=" INTPTR_FORMAT " O1=" INTPTR_FORMAT |
216 " O2=" INTPTR_FORMAT " O3=" INTPTR_FORMAT, | |
217 SIG_REGS(sc).u_regs[CON_O0], | |
218 SIG_REGS(sc).u_regs[CON_O1], | |
219 SIG_REGS(sc).u_regs[CON_O2], | |
220 SIG_REGS(sc).u_regs[CON_O3]); | |
221 st->print_cr(" O4=" INTPTR_FORMAT " O5=" INTPTR_FORMAT | |
222 " O6=" INTPTR_FORMAT " O7=" INTPTR_FORMAT, | |
223 SIG_REGS(sc).u_regs[CON_O4], | |
224 SIG_REGS(sc).u_regs[CON_O5], | |
225 SIG_REGS(sc).u_regs[CON_O6], | |
226 SIG_REGS(sc).u_regs[CON_O7]); | |
227 | |
1907 | 228 |
229 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); | |
230 st->print_cr(" L0=" INTPTR_FORMAT " L1=" INTPTR_FORMAT | |
231 " L2=" INTPTR_FORMAT " L3=" INTPTR_FORMAT, | |
232 sp[L0->sp_offset_in_saved_window()], | |
233 sp[L1->sp_offset_in_saved_window()], | |
234 sp[L2->sp_offset_in_saved_window()], | |
235 sp[L3->sp_offset_in_saved_window()]); | |
236 st->print_cr(" L4=" INTPTR_FORMAT " L5=" INTPTR_FORMAT | |
237 " L6=" INTPTR_FORMAT " L7=" INTPTR_FORMAT, | |
238 sp[L4->sp_offset_in_saved_window()], | |
239 sp[L5->sp_offset_in_saved_window()], | |
240 sp[L6->sp_offset_in_saved_window()], | |
241 sp[L7->sp_offset_in_saved_window()]); | |
242 st->print_cr(" I0=" INTPTR_FORMAT " I1=" INTPTR_FORMAT | |
243 " I2=" INTPTR_FORMAT " I3=" INTPTR_FORMAT, | |
244 sp[I0->sp_offset_in_saved_window()], | |
245 sp[I1->sp_offset_in_saved_window()], | |
246 sp[I2->sp_offset_in_saved_window()], | |
247 sp[I3->sp_offset_in_saved_window()]); | |
248 st->print_cr(" I4=" INTPTR_FORMAT " I5=" INTPTR_FORMAT | |
249 " I6=" INTPTR_FORMAT " I7=" INTPTR_FORMAT, | |
250 sp[I4->sp_offset_in_saved_window()], | |
251 sp[I5->sp_offset_in_saved_window()], | |
252 sp[I6->sp_offset_in_saved_window()], | |
253 sp[I7->sp_offset_in_saved_window()]); | |
133 | 254 |
255 st->print_cr(" PC=" INTPTR_FORMAT " nPC=" INTPTR_FORMAT, | |
256 SIG_PC(sc), | |
257 SIG_NPC(sc)); | |
258 st->cr(); | |
259 st->cr(); | |
260 | |
261 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp); | |
262 print_hex_dump(st, (address)sp, (address)(sp + 32), sizeof(intptr_t)); | |
263 st->cr(); | |
264 | |
265 // Note: it may be unsafe to inspect memory near pc. For example, pc may | |
266 // point to garbage if entry point in an nmethod is corrupted. Leave | |
267 // this at the end, and hope for the best. | |
268 address pc = os::Linux::ucontext_get_pc(uc); | |
269 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc); | |
1907 | 270 print_hex_dump(st, pc - 32, pc + 32, sizeof(char)); |
271 } | |
272 | |
273 | |
274 void os::print_register_info(outputStream *st, void *context) { | |
275 if (context == NULL) return; | |
276 | |
277 ucontext_t *uc = (ucontext_t*)context; | |
278 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc); | |
279 | |
280 st->print_cr("Register to memory mapping:"); | |
281 st->cr(); | |
282 | |
283 // this is only for the "general purpose" registers | |
284 st->print("G1="); print_location(st, SIG_REGS(sc).u_regs[CON__G1]); | |
285 st->print("G2="); print_location(st, SIG_REGS(sc).u_regs[CON__G2]); | |
286 st->print("G3="); print_location(st, SIG_REGS(sc).u_regs[CON__G3]); | |
287 st->print("G4="); print_location(st, SIG_REGS(sc).u_regs[CON__G4]); | |
288 st->print("G5="); print_location(st, SIG_REGS(sc).u_regs[CON__G5]); | |
289 st->print("G6="); print_location(st, SIG_REGS(sc).u_regs[CON__G6]); | |
290 st->print("G7="); print_location(st, SIG_REGS(sc).u_regs[CON__G7]); | |
291 st->cr(); | |
292 | |
293 st->print("O0="); print_location(st, SIG_REGS(sc).u_regs[CON__O0]); | |
294 st->print("O1="); print_location(st, SIG_REGS(sc).u_regs[CON__O1]); | |
295 st->print("O2="); print_location(st, SIG_REGS(sc).u_regs[CON__O2]); | |
296 st->print("O3="); print_location(st, SIG_REGS(sc).u_regs[CON__O3]); | |
297 st->print("O4="); print_location(st, SIG_REGS(sc).u_regs[CON__O4]); | |
298 st->print("O5="); print_location(st, SIG_REGS(sc).u_regs[CON__O5]); | |
299 st->print("O6="); print_location(st, SIG_REGS(sc).u_regs[CON__O6]); | |
300 st->print("O7="); print_location(st, SIG_REGS(sc).u_regs[CON__O7]); | |
301 st->cr(); | |
302 | |
303 st->print("L0="); print_location(st, sp[L0->sp_offset_in_saved_window()]); | |
304 st->print("L1="); print_location(st, sp[L1->sp_offset_in_saved_window()]); | |
305 st->print("L2="); print_location(st, sp[L2->sp_offset_in_saved_window()]); | |
306 st->print("L3="); print_location(st, sp[L3->sp_offset_in_saved_window()]); | |
307 st->print("L4="); print_location(st, sp[L4->sp_offset_in_saved_window()]); | |
308 st->print("L5="); print_location(st, sp[L5->sp_offset_in_saved_window()]); | |
309 st->print("L6="); print_location(st, sp[L6->sp_offset_in_saved_window()]); | |
310 st->print("L7="); print_location(st, sp[L7->sp_offset_in_saved_window()]); | |
311 st->cr(); | |
312 | |
313 st->print("I0="); print_location(st, sp[I0->sp_offset_in_saved_window()]); | |
314 st->print("I1="); print_location(st, sp[I1->sp_offset_in_saved_window()]); | |
315 st->print("I2="); print_location(st, sp[I2->sp_offset_in_saved_window()]); | |
316 st->print("I3="); print_location(st, sp[I3->sp_offset_in_saved_window()]); | |
317 st->print("I4="); print_location(st, sp[I4->sp_offset_in_saved_window()]); | |
318 st->print("I5="); print_location(st, sp[I5->sp_offset_in_saved_window()]); | |
319 st->print("I6="); print_location(st, sp[I6->sp_offset_in_saved_window()]); | |
320 st->print("I7="); print_location(st, sp[I7->sp_offset_in_saved_window()]); | |
321 st->cr(); | |
133 | 322 } |
323 | |
324 | |
325 address os::Linux::ucontext_get_pc(ucontext_t* uc) { | |
326 return (address) SIG_PC((sigcontext*)uc); | |
327 } | |
328 | |
329 intptr_t* os::Linux::ucontext_get_sp(ucontext_t *uc) { | |
330 return (intptr_t*) | |
331 ((intptr_t)SIG_REGS((sigcontext*)uc).u_regs[CON_O6] + STACK_BIAS); | |
332 } | |
333 | |
334 // not used on Sparc | |
335 intptr_t* os::Linux::ucontext_get_fp(ucontext_t *uc) { | |
336 ShouldNotReachHere(); | |
337 return NULL; | |
338 } | |
339 | |
340 // Utility functions | |
341 | |
342 extern "C" void Fetch32PFI(); | |
343 extern "C" void Fetch32Resume(); | |
344 extern "C" void FetchNPFI(); | |
345 extern "C" void FetchNResume(); | |
346 | |
347 inline static bool checkPrefetch(sigcontext* uc, address pc) { | |
348 if (pc == (address) Fetch32PFI) { | |
349 set_cont_address(uc, address(Fetch32Resume)); | |
350 return true; | |
351 } | |
352 if (pc == (address) FetchNPFI) { | |
353 set_cont_address(uc, address(FetchNResume)); | |
354 return true; | |
355 } | |
356 return false; | |
357 } | |
358 | |
359 inline static bool checkOverflow(sigcontext* uc, | |
360 address pc, | |
361 address addr, | |
362 JavaThread* thread, | |
363 address* stub) { | |
364 // check if fault address is within thread stack | |
365 if (addr < thread->stack_base() && | |
366 addr >= thread->stack_base() - thread->stack_size()) { | |
367 // stack overflow | |
368 if (thread->in_stack_yellow_zone(addr)) { | |
369 thread->disable_stack_yellow_zone(); | |
370 if (thread->thread_state() == _thread_in_Java) { | |
371 // Throw a stack overflow exception. Guard pages will be reenabled | |
372 // while unwinding the stack. | |
373 *stub = | |
374 SharedRuntime::continuation_for_implicit_exception(thread, | |
375 pc, | |
376 SharedRuntime::STACK_OVERFLOW); | |
377 } else { | |
378 // Thread was in the vm or native code. Return and try to finish. | |
379 return true; | |
380 } | |
381 } else if (thread->in_stack_red_zone(addr)) { | |
382 // Fatal red zone violation. Disable the guard pages and fall through | |
383 // to handle_unexpected_exception way down below. | |
384 thread->disable_stack_red_zone(); | |
385 tty->print_raw_cr("An irrecoverable stack overflow has occurred."); | |
386 } else { | |
387 // Accessing stack address below sp may cause SEGV if current | |
388 // thread has MAP_GROWSDOWN stack. This should only happen when | |
389 // current thread was created by user code with MAP_GROWSDOWN flag | |
390 // and then attached to VM. See notes in os_linux.cpp. | |
391 if (thread->osthread()->expanding_stack() == 0) { | |
392 thread->osthread()->set_expanding_stack(); | |
393 if (os::Linux::manually_expand_stack(thread, addr)) { | |
394 thread->osthread()->clear_expanding_stack(); | |
395 return true; | |
396 } | |
397 thread->osthread()->clear_expanding_stack(); | |
398 } else { | |
399 fatal("recursive segv. expanding stack."); | |
400 } | |
401 } | |
402 } | |
403 return false; | |
404 } | |
405 | |
406 inline static bool checkPollingPage(address pc, address fault, address* stub) { | |
407 if (fault == os::get_polling_page()) { | |
408 *stub = SharedRuntime::get_poll_stub(pc); | |
409 return true; | |
410 } | |
411 return false; | |
412 } | |
413 | |
414 inline static bool checkByteBuffer(address pc, address* stub) { | |
415 // BugId 4454115: A read from a MappedByteBuffer can fault | |
416 // here if the underlying file has been truncated. | |
417 // Do not crash the VM in such a case. | |
418 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); | |
419 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL; | |
420 if (nm != NULL && nm->has_unsafe_access()) { | |
421 *stub = StubRoutines::handler_for_unsafe_access(); | |
422 return true; | |
423 } | |
424 return false; | |
425 } | |
426 | |
427 inline static bool checkVerifyOops(address pc, address fault, address* stub) { | |
428 if (pc >= MacroAssembler::_verify_oop_implicit_branch[0] | |
429 && pc < MacroAssembler::_verify_oop_implicit_branch[1] ) { | |
430 *stub = MacroAssembler::_verify_oop_implicit_branch[2]; | |
431 warning("fixed up memory fault in +VerifyOops at address " | |
432 INTPTR_FORMAT, fault); | |
433 return true; | |
434 } | |
435 return false; | |
436 } | |
437 | |
438 inline static bool checkFPFault(address pc, int code, | |
439 JavaThread* thread, address* stub) { | |
440 if (code == FPE_INTDIV || code == FPE_FLTDIV) { | |
441 *stub = | |
442 SharedRuntime:: | |
443 continuation_for_implicit_exception(thread, | |
444 pc, | |
445 SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO); | |
446 return true; | |
447 } | |
448 return false; | |
449 } | |
450 | |
451 inline static bool checkNullPointer(address pc, intptr_t fault, | |
452 JavaThread* thread, address* stub) { | |
453 if (!MacroAssembler::needs_explicit_null_check(fault)) { | |
454 // Determination of interpreter/vtable stub/compiled code null | |
455 // exception | |
456 *stub = | |
457 SharedRuntime:: | |
458 continuation_for_implicit_exception(thread, pc, | |
459 SharedRuntime::IMPLICIT_NULL); | |
460 return true; | |
461 } | |
462 return false; | |
463 } | |
464 | |
465 inline static bool checkFastJNIAccess(address pc, address* stub) { | |
466 address addr = JNI_FastGetField::find_slowcase_pc(pc); | |
467 if (addr != (address)-1) { | |
468 *stub = addr; | |
469 return true; | |
470 } | |
471 return false; | |
472 } | |
473 | |
474 inline static bool checkSerializePage(JavaThread* thread, address addr) { | |
475 return os::is_memory_serialize_page(thread, addr); | |
476 } | |
477 | |
478 inline static bool checkZombie(sigcontext* uc, address* pc, address* stub) { | |
479 if (nativeInstruction_at(*pc)->is_zombie()) { | |
480 // zombie method (ld [%g0],%o7 instruction) | |
481 *stub = SharedRuntime::get_handle_wrong_method_stub(); | |
482 | |
483 // At the stub it needs to look like a call from the caller of this | |
484 // method (not a call from the segv site). | |
485 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; | |
486 return true; | |
487 } | |
488 return false; | |
489 } | |
490 | |
491 inline static bool checkICMiss(sigcontext* uc, address* pc, address* stub) { | |
492 #ifdef COMPILER2 | |
493 if (nativeInstruction_at(*pc)->is_ic_miss_trap()) { | |
494 #ifdef ASSERT | |
495 #ifdef TIERED | |
496 CodeBlob* cb = CodeCache::find_blob_unsafe(pc); | |
497 assert(cb->is_compiled_by_c2(), "Wrong compiler"); | |
498 #endif // TIERED | |
499 #endif // ASSERT | |
500 // Inline cache missed and user trap "Tne G0+ST_RESERVED_FOR_USER_0+2" taken. | |
501 *stub = SharedRuntime::get_ic_miss_stub(); | |
502 // At the stub it needs to look like a call from the caller of this | |
503 // method (not a call from the segv site). | |
504 *pc = (address)SIG_REGS(uc).u_regs[CON_O7]; | |
505 return true; | |
506 } | |
507 #endif // COMPILER2 | |
508 return false; | |
509 } | |
510 | |
511 extern "C" int | |
512 JVM_handle_linux_signal(int sig, | |
513 siginfo_t* info, | |
514 void* ucVoid, | |
515 int abort_if_unrecognized) { | |
516 // in fact this isn't ucontext_t* at all, but struct sigcontext* | |
517 // but Linux porting layer uses ucontext_t, so to minimize code change | |
518 // we cast as needed | |
519 ucontext_t* ucFake = (ucontext_t*) ucVoid; | |
520 sigcontext* uc = (sigcontext*)ucVoid; | |
521 | |
522 Thread* t = ThreadLocalStorage::get_thread_slow(); | |
523 | |
524 SignalHandlerMark shm(t); | |
525 | |
526 // Note: it's not uncommon that JNI code uses signal/sigset to install | |
527 // then restore certain signal handler (e.g. to temporarily block SIGPIPE, | |
528 // or have a SIGILL handler when detecting CPU type). When that happens, | |
529 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To | |
530 // avoid unnecessary crash when libjsig is not preloaded, try handle signals | |
531 // that do not require siginfo/ucontext first. | |
532 | |
533 if (sig == SIGPIPE || sig == SIGXFSZ) { | |
534 // allow chained handler to go first | |
535 if (os::Linux::chained_handler(sig, info, ucVoid)) { | |
536 return true; | |
537 } else { | |
538 if (PrintMiscellaneous && (WizardMode || Verbose)) { | |
539 char buf[64]; | |
540 warning("Ignoring %s - see bugs 4229104 or 646499219", | |
541 os::exception_name(sig, buf, sizeof(buf))); | |
542 } | |
543 return true; | |
544 } | |
545 } | |
546 | |
547 JavaThread* thread = NULL; | |
548 VMThread* vmthread = NULL; | |
549 if (os::Linux::signal_handlers_are_installed) { | |
550 if (t != NULL ){ | |
551 if(t->is_Java_thread()) { | |
552 thread = (JavaThread*)t; | |
553 } | |
554 else if(t->is_VM_thread()){ | |
555 vmthread = (VMThread *)t; | |
556 } | |
557 } | |
558 } | |
559 | |
560 // decide if this trap can be handled by a stub | |
561 address stub = NULL; | |
562 address pc = NULL; | |
563 address npc = NULL; | |
564 | |
565 //%note os_trap_1 | |
566 if (info != NULL && uc != NULL && thread != NULL) { | |
567 pc = address(SIG_PC(uc)); | |
568 npc = address(SIG_NPC(uc)); | |
569 | |
570 // Check to see if we caught the safepoint code in the | |
571 // process of write protecting the memory serialization page. | |
572 // It write enables the page immediately after protecting it | |
573 // so we can just return to retry the write. | |
574 if ((sig == SIGSEGV) && checkSerializePage(thread, (address)info->si_addr)) { | |
575 // Block current thread until the memory serialize page permission restored. | |
576 os::block_on_serialize_page_trap(); | |
577 return 1; | |
578 } | |
579 | |
580 if (checkPrefetch(uc, pc)) { | |
581 return 1; | |
582 } | |
583 | |
584 // Handle ALL stack overflow variations here | |
585 if (sig == SIGSEGV) { | |
586 if (checkOverflow(uc, pc, (address)info->si_addr, thread, &stub)) { | |
587 return 1; | |
588 } | |
589 } | |
590 | |
591 if (sig == SIGBUS && | |
592 thread->thread_state() == _thread_in_vm && | |
593 thread->doing_unsafe_access()) { | |
594 stub = StubRoutines::handler_for_unsafe_access(); | |
595 } | |
596 | |
597 if (thread->thread_state() == _thread_in_Java) { | |
598 do { | |
599 // Java thread running in Java code => find exception handler if any | |
600 // a fault inside compiled code, the interpreter, or a stub | |
601 | |
602 if ((sig == SIGSEGV) && checkPollingPage(pc, (address)info->si_addr, &stub)) { | |
603 break; | |
604 } | |
605 | |
606 if ((sig == SIGBUS) && checkByteBuffer(pc, &stub)) { | |
607 break; | |
608 } | |
609 | |
610 if ((sig == SIGSEGV || sig == SIGBUS) && | |
611 checkVerifyOops(pc, (address)info->si_addr, &stub)) { | |
612 break; | |
613 } | |
614 | |
615 if ((sig == SIGSEGV) && checkZombie(uc, &pc, &stub)) { | |
616 break; | |
617 } | |
618 | |
619 if ((sig == SIGILL) && checkICMiss(uc, &pc, &stub)) { | |
620 break; | |
621 } | |
622 | |
623 if ((sig == SIGFPE) && checkFPFault(pc, info->si_code, thread, &stub)) { | |
624 break; | |
625 } | |
626 | |
627 if ((sig == SIGSEGV) && | |
628 checkNullPointer(pc, (intptr_t)info->si_addr, thread, &stub)) { | |
629 break; | |
630 } | |
631 } while (0); | |
632 | |
633 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in | |
634 // and the heap gets shrunk before the field access. | |
635 if ((sig == SIGSEGV) || (sig == SIGBUS)) { | |
636 checkFastJNIAccess(pc, &stub); | |
637 } | |
638 } | |
639 | |
640 if (stub != NULL) { | |
641 // save all thread context in case we need to restore it | |
642 thread->set_saved_exception_pc(pc); | |
643 thread->set_saved_exception_npc(npc); | |
644 set_cont_address(uc, stub); | |
645 return true; | |
646 } | |
647 } | |
648 | |
649 // signal-chaining | |
650 if (os::Linux::chained_handler(sig, info, ucVoid)) { | |
651 return true; | |
652 } | |
653 | |
654 if (!abort_if_unrecognized) { | |
655 // caller wants another chance, so give it to him | |
656 return false; | |
657 } | |
658 | |
659 if (pc == NULL && uc != NULL) { | |
660 pc = os::Linux::ucontext_get_pc((ucontext_t*)uc); | |
661 } | |
662 | |
663 // unmask current signal | |
664 sigset_t newset; | |
665 sigemptyset(&newset); | |
666 sigaddset(&newset, sig); | |
667 sigprocmask(SIG_UNBLOCK, &newset, NULL); | |
668 | |
669 VMError err(t, sig, pc, info, ucVoid); | |
670 err.report_and_die(); | |
671 | |
672 ShouldNotReachHere(); | |
673 } | |
674 | |
675 void os::Linux::init_thread_fpu_state(void) { | |
676 // Nothing to do | |
677 } | |
678 | |
679 int os::Linux::get_fpu_control_word() { | |
680 return 0; | |
681 } | |
682 | |
683 void os::Linux::set_fpu_control_word(int fpu) { | |
684 // nothing | |
685 } | |
686 | |
687 bool os::is_allocatable(size_t bytes) { | |
688 #ifdef _LP64 | |
689 return true; | |
690 #else | |
691 if (bytes < 2 * G) { | |
692 return true; | |
693 } | |
694 | |
695 char* addr = reserve_memory(bytes, NULL); | |
696 | |
697 if (addr != NULL) { | |
698 release_memory(addr, bytes); | |
699 } | |
700 | |
701 return addr != NULL; | |
702 #endif // _LP64 | |
703 } | |
704 | |
705 /////////////////////////////////////////////////////////////////////////////// | |
706 // thread stack | |
707 | |
708 size_t os::Linux::min_stack_allowed = 128 * K; | |
709 | |
710 // pthread on Ubuntu is always in floating stack mode | |
711 bool os::Linux::supports_variable_stack_size() { return true; } | |
712 | |
713 // return default stack size for thr_type | |
714 size_t os::Linux::default_stack_size(os::ThreadType thr_type) { | |
715 // default stack size (compiler thread needs larger stack) | |
716 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M); | |
717 return s; | |
718 } | |
719 | |
720 size_t os::Linux::default_guard_size(os::ThreadType thr_type) { | |
721 // Creating guard page is very expensive. Java thread has HotSpot | |
722 // guard page, only enable glibc guard page for non-Java threads. | |
723 return (thr_type == java_thread ? 0 : page_size()); | |
724 } |