Print this page
rev 6900 : 8048169: Change 8037816 breaks HS build on PPC64 and CPP-Interpreter platforms
Summary: Fix the matching of format string parameter types to the actual argument types for the PPC64 and CPP-Interpreter files in the same way as 8037816 already did it for all the other files
Reviewed-by: stefank, coleenp, dholmes
Split |
Split |
Close |
Expand all |
Collapse all |
--- old/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp
+++ new/hotspot/src/os_cpu/linux_ppc/vm/os_linux_ppc.cpp
1 1 /*
2 - * Copyright (c) 1997, 2013, Oracle and/or its affiliates. All rights reserved.
3 - * Copyright 2012, 2013 SAP AG. All rights reserved.
2 + * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 + * Copyright 2012, 2014 SAP AG. All rights reserved.
4 4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 5 *
6 6 * This code is free software; you can redistribute it and/or modify it
7 7 * under the terms of the GNU General Public License version 2 only, as
8 8 * published by the Free Software Foundation.
9 9 *
10 10 * This code is distributed in the hope that it will be useful, but WITHOUT
11 11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 13 * version 2 for more details (a copy is included in the LICENSE file hat
14 14 * accompanied this code).
15 15 *
16 16 * You should have received a copy of the GNU General Public License version
17 17 * 2 along with this work; if not, write to the Free Software Foundation,
18 18 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19 19 *
20 20 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21 21 * or visit www.oracle.com if you need additional information or have any
22 22 * questions.
23 23 *
24 24 */
25 25
26 26 // no precompiled headers
27 27 #include "assembler_ppc.inline.hpp"
28 28 #include "classfile/classLoader.hpp"
29 29 #include "classfile/systemDictionary.hpp"
30 30 #include "classfile/vmSymbols.hpp"
31 31 #include "code/icBuffer.hpp"
32 32 #include "code/vtableStubs.hpp"
33 33 #include "interpreter/interpreter.hpp"
34 34 #include "jvm_linux.h"
35 35 #include "memory/allocation.inline.hpp"
36 36 #include "mutex_linux.inline.hpp"
37 37 #include "nativeInst_ppc.hpp"
38 38 #include "os_share_linux.hpp"
39 39 #include "prims/jniFastGetField.hpp"
40 40 #include "prims/jvm.h"
41 41 #include "prims/jvm_misc.hpp"
42 42 #include "runtime/arguments.hpp"
43 43 #include "runtime/extendedPC.hpp"
44 44 #include "runtime/frame.inline.hpp"
45 45 #include "runtime/interfaceSupport.hpp"
46 46 #include "runtime/java.hpp"
47 47 #include "runtime/javaCalls.hpp"
48 48 #include "runtime/mutexLocker.hpp"
49 49 #include "runtime/osThread.hpp"
50 50 #include "runtime/sharedRuntime.hpp"
51 51 #include "runtime/stubRoutines.hpp"
52 52 #include "runtime/thread.inline.hpp"
53 53 #include "runtime/timer.hpp"
54 54 #include "utilities/events.hpp"
55 55 #include "utilities/vmError.hpp"
56 56
57 57 // put OS-includes here
58 58 # include <sys/types.h>
59 59 # include <sys/mman.h>
60 60 # include <pthread.h>
61 61 # include <signal.h>
62 62 # include <errno.h>
63 63 # include <dlfcn.h>
64 64 # include <stdlib.h>
65 65 # include <stdio.h>
66 66 # include <unistd.h>
67 67 # include <sys/resource.h>
68 68 # include <pthread.h>
69 69 # include <sys/stat.h>
70 70 # include <sys/time.h>
71 71 # include <sys/utsname.h>
72 72 # include <sys/socket.h>
73 73 # include <sys/wait.h>
74 74 # include <pwd.h>
75 75 # include <poll.h>
76 76 # include <ucontext.h>
77 77
78 78
79 79 address os::current_stack_pointer() {
80 80 intptr_t* csp;
81 81
82 82 // inline assembly `mr regno(csp), R1_SP':
83 83 __asm__ __volatile__ ("mr %0, 1":"=r"(csp):);
84 84
85 85 return (address) csp;
86 86 }
87 87
88 88 char* os::non_memory_address_word() {
89 89 // Must never look like an address returned by reserve_memory,
90 90 // even in its subfields (as defined by the CPU immediate fields,
91 91 // if the CPU splits constants across multiple instructions).
92 92
93 93 return (char*) -1;
94 94 }
95 95
96 96 void os::initialize_thread(Thread *thread) { }
97 97
98 98 // Frame information (pc, sp, fp) retrieved via ucontext
99 99 // always looks like a C-frame according to the frame
100 100 // conventions in frame_ppc64.hpp.
101 101 address os::Linux::ucontext_get_pc(ucontext_t * uc) {
102 102 // On powerpc64, ucontext_t is not selfcontained but contains
103 103 // a pointer to an optional substructure (mcontext_t.regs) containing the volatile
104 104 // registers - NIP, among others.
105 105 // This substructure may or may not be there depending where uc came from:
106 106 // - if uc was handed over as the argument to a sigaction handler, a pointer to the
107 107 // substructure was provided by the kernel when calling the signal handler, and
108 108 // regs->nip can be accessed.
109 109 // - if uc was filled by getcontext(), it is undefined - getcontext() does not fill
110 110 // it because the volatile registers are not needed to make setcontext() work.
111 111 // Hopefully it was zero'd out beforehand.
112 112 guarantee(uc->uc_mcontext.regs != NULL, "only use ucontext_get_pc in sigaction context");
113 113 return (address)uc->uc_mcontext.regs->nip;
114 114 }
115 115
116 116 intptr_t* os::Linux::ucontext_get_sp(ucontext_t * uc) {
117 117 return (intptr_t*)uc->uc_mcontext.regs->gpr[1/*REG_SP*/];
118 118 }
119 119
120 120 intptr_t* os::Linux::ucontext_get_fp(ucontext_t * uc) {
121 121 return NULL;
122 122 }
123 123
124 124 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
125 125 intptr_t** ret_sp, intptr_t** ret_fp) {
126 126
127 127 ExtendedPC epc;
128 128 ucontext_t* uc = (ucontext_t*)ucVoid;
129 129
130 130 if (uc != NULL) {
131 131 epc = ExtendedPC(os::Linux::ucontext_get_pc(uc));
132 132 if (ret_sp) *ret_sp = os::Linux::ucontext_get_sp(uc);
133 133 if (ret_fp) *ret_fp = os::Linux::ucontext_get_fp(uc);
134 134 } else {
135 135 // construct empty ExtendedPC for return value checking
136 136 epc = ExtendedPC(NULL);
137 137 if (ret_sp) *ret_sp = (intptr_t *)NULL;
138 138 if (ret_fp) *ret_fp = (intptr_t *)NULL;
139 139 }
140 140
141 141 return epc;
142 142 }
143 143
144 144 frame os::fetch_frame_from_context(void* ucVoid) {
145 145 intptr_t* sp;
146 146 intptr_t* fp;
147 147 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
148 148 return frame(sp, epc.pc());
149 149 }
150 150
151 151 frame os::get_sender_for_C_frame(frame* fr) {
152 152 if (*fr->sp() == 0) {
153 153 // fr is the last C frame
154 154 return frame(NULL, NULL);
155 155 }
156 156 return frame(fr->sender_sp(), fr->sender_pc());
157 157 }
158 158
159 159
160 160 frame os::current_frame() {
161 161 intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
162 162 // hack.
163 163 frame topframe(csp, (address)0x8);
164 164 // return sender of current topframe which hopefully has pc != NULL.
165 165 return os::get_sender_for_C_frame(&topframe);
166 166 }
167 167
168 168 // Utility functions
169 169
170 170 extern "C" JNIEXPORT int
171 171 JVM_handle_linux_signal(int sig,
172 172 siginfo_t* info,
173 173 void* ucVoid,
174 174 int abort_if_unrecognized) {
175 175 ucontext_t* uc = (ucontext_t*) ucVoid;
176 176
177 177 Thread* t = ThreadLocalStorage::get_thread_slow();
178 178
179 179 SignalHandlerMark shm(t);
180 180
181 181 // Note: it's not uncommon that JNI code uses signal/sigset to install
182 182 // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
183 183 // or have a SIGILL handler when detecting CPU type). When that happens,
184 184 // JVM_handle_linux_signal() might be invoked with junk info/ucVoid. To
185 185 // avoid unnecessary crash when libjsig is not preloaded, try handle signals
186 186 // that do not require siginfo/ucontext first.
187 187
188 188 if (sig == SIGPIPE) {
189 189 if (os::Linux::chained_handler(sig, info, ucVoid)) {
190 190 return true;
191 191 } else {
192 192 if (PrintMiscellaneous && (WizardMode || Verbose)) {
193 193 warning("Ignoring SIGPIPE - see bug 4229104");
194 194 }
195 195 return true;
196 196 }
197 197 }
198 198
199 199 JavaThread* thread = NULL;
200 200 VMThread* vmthread = NULL;
201 201 if (os::Linux::signal_handlers_are_installed) {
202 202 if (t != NULL) {
203 203 if(t->is_Java_thread()) {
204 204 thread = (JavaThread*)t;
205 205 } else if(t->is_VM_thread()) {
206 206 vmthread = (VMThread *)t;
207 207 }
208 208 }
209 209 }
210 210
211 211 // Moved SafeFetch32 handling outside thread!=NULL conditional block to make
212 212 // it work if no associated JavaThread object exists.
213 213 if (uc) {
214 214 address const pc = os::Linux::ucontext_get_pc(uc);
215 215 if (pc && StubRoutines::is_safefetch_fault(pc)) {
216 216 uc->uc_mcontext.regs->nip = (unsigned long)StubRoutines::continuation_for_safefetch_fault(pc);
217 217 return true;
218 218 }
219 219 }
220 220
221 221 // decide if this trap can be handled by a stub
222 222 address stub = NULL;
223 223 address pc = NULL;
224 224
225 225 //%note os_trap_1
226 226 if (info != NULL && uc != NULL && thread != NULL) {
227 227 pc = (address) os::Linux::ucontext_get_pc(uc);
228 228
229 229 // Handle ALL stack overflow variations here
230 230 if (sig == SIGSEGV) {
231 231 // Si_addr may not be valid due to a bug in the linux-ppc64 kernel (see
232 232 // comment below). Use get_stack_bang_address instead of si_addr.
233 233 address addr = ((NativeInstruction*)pc)->get_stack_bang_address(uc);
234 234
235 235 // Check if fault address is within thread stack.
236 236 if (addr < thread->stack_base() &&
237 237 addr >= thread->stack_base() - thread->stack_size()) {
238 238 // stack overflow
239 239 if (thread->in_stack_yellow_zone(addr)) {
240 240 thread->disable_stack_yellow_zone();
241 241 if (thread->thread_state() == _thread_in_Java) {
242 242 // Throw a stack overflow exception.
243 243 // Guard pages will be reenabled while unwinding the stack.
244 244 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
245 245 } else {
246 246 // Thread was in the vm or native code. Return and try to finish.
247 247 return 1;
248 248 }
249 249 } else if (thread->in_stack_red_zone(addr)) {
250 250 // Fatal red zone violation. Disable the guard pages and fall through
251 251 // to handle_unexpected_exception way down below.
252 252 thread->disable_stack_red_zone();
253 253 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
254 254
255 255 // This is a likely cause, but hard to verify. Let's just print
256 256 // it as a hint.
257 257 tty->print_raw_cr("Please check if any of your loaded .so files has "
258 258 "enabled executable stack (see man page execstack(8))");
259 259 } else {
260 260 // Accessing stack address below sp may cause SEGV if current
261 261 // thread has MAP_GROWSDOWN stack. This should only happen when
262 262 // current thread was created by user code with MAP_GROWSDOWN flag
263 263 // and then attached to VM. See notes in os_linux.cpp.
264 264 if (thread->osthread()->expanding_stack() == 0) {
265 265 thread->osthread()->set_expanding_stack();
266 266 if (os::Linux::manually_expand_stack(thread, addr)) {
267 267 thread->osthread()->clear_expanding_stack();
268 268 return 1;
269 269 }
270 270 thread->osthread()->clear_expanding_stack();
271 271 } else {
272 272 fatal("recursive segv. expanding stack.");
273 273 }
274 274 }
275 275 }
276 276 }
277 277
278 278 if (thread->thread_state() == _thread_in_Java) {
279 279 // Java thread running in Java code => find exception handler if any
280 280 // a fault inside compiled code, the interpreter, or a stub
281 281
282 282 // A VM-related SIGILL may only occur if we are not in the zero page.
283 283 // On AIX, we get a SIGILL if we jump to 0x0 or to somewhere else
284 284 // in the zero page, because it is filled with 0x0. We ignore
285 285 // explicit SIGILLs in the zero page.
286 286 if (sig == SIGILL && (pc < (address) 0x200)) {
287 287 if (TraceTraps) {
288 288 tty->print_raw_cr("SIGILL happened inside zero page.");
289 289 }
290 290 goto report_and_die;
291 291 }
292 292
293 293 // Handle signal from NativeJump::patch_verified_entry().
294 294 if (( TrapBasedNotEntrantChecks && sig == SIGTRAP && nativeInstruction_at(pc)->is_sigtrap_zombie_not_entrant()) ||
295 295 (!TrapBasedNotEntrantChecks && sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant())) {
296 296 if (TraceTraps) {
297 297 tty->print_cr("trap: zombie_not_entrant (%s)", (sig == SIGTRAP) ? "SIGTRAP" : "SIGILL");
298 298 }
299 299 stub = SharedRuntime::get_handle_wrong_method_stub();
↓ open down ↓ |
286 lines elided |
↑ open up ↑ |
300 300 }
301 301
302 302 else if (sig == SIGSEGV &&
303 303 // A linux-ppc64 kernel before 2.6.6 doesn't set si_addr on some segfaults
304 304 // in 64bit mode (cf. http://www.kernel.org/pub/linux/kernel/v2.6/ChangeLog-2.6.6),
305 305 // especially when we try to read from the safepoint polling page. So the check
306 306 // (address)info->si_addr == os::get_standard_polling_page()
307 307 // doesn't work for us. We use:
308 308 ((NativeInstruction*)pc)->is_safepoint_poll()) {
309 309 if (TraceTraps) {
310 - tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", pc);
310 + tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
311 311 }
312 312 stub = SharedRuntime::get_poll_stub(pc);
313 313 }
314 314
315 315 // SIGTRAP-based ic miss check in compiled code.
316 316 else if (sig == SIGTRAP && TrapBasedICMissChecks &&
317 317 nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
318 318 if (TraceTraps) {
319 - tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
319 + tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
320 320 }
321 321 stub = SharedRuntime::get_ic_miss_stub();
322 322 }
323 323
324 324 // SIGTRAP-based implicit null check in compiled code.
325 325 else if (sig == SIGTRAP && TrapBasedNullChecks &&
326 326 nativeInstruction_at(pc)->is_sigtrap_null_check()) {
327 327 if (TraceTraps) {
328 - tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
328 + tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
329 329 }
330 330 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
331 331 }
332 332
333 333 // SIGSEGV-based implicit null check in compiled code.
334 334 else if (sig == SIGSEGV && ImplicitNullChecks &&
335 335 CodeCache::contains((void*) pc) &&
336 336 !MacroAssembler::needs_explicit_null_check((intptr_t) info->si_addr)) {
337 337 if (TraceTraps) {
338 - tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", pc);
338 + tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
339 339 }
340 340 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
341 341 }
342 342
343 343 #ifdef COMPILER2
344 344 // SIGTRAP-based implicit range check in compiled code.
345 345 else if (sig == SIGTRAP && TrapBasedRangeChecks &&
346 346 nativeInstruction_at(pc)->is_sigtrap_range_check()) {
347 347 if (TraceTraps) {
348 - tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", pc);
348 + tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
349 349 }
350 350 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
351 351 }
352 352 #endif
353 353 else if (sig == SIGBUS) {
354 354 // BugId 4454115: A read from a MappedByteBuffer can fault here if the
355 355 // underlying file has been truncated. Do not crash the VM in such a case.
356 356 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
357 357 nmethod* nm = (cb != NULL && cb->is_nmethod()) ? (nmethod*)cb : NULL;
358 358 if (nm != NULL && nm->has_unsafe_access()) {
359 359 // We don't really need a stub here! Just set the pending exeption and
360 360 // continue at the next instruction after the faulting read. Returning
361 361 // garbage from this read is ok.
362 362 thread->set_pending_unsafe_access_error();
363 363 uc->uc_mcontext.regs->nip = ((unsigned long)pc) + 4;
364 364 return true;
365 365 }
366 366 }
367 367 }
368 368
369 369 else { // thread->thread_state() != _thread_in_Java
370 370 if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
371 371 // SIGILL must be caused by VM_Version::determine_features().
372 372 *(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,
373 373 // flushing of icache is not necessary.
374 374 stub = pc + 4; // continue with next instruction.
375 375 }
376 376 else if (thread->thread_state() == _thread_in_vm &&
377 377 sig == SIGBUS && thread->doing_unsafe_access()) {
378 378 // We don't really need a stub here! Just set the pending exeption and
379 379 // continue at the next instruction after the faulting read. Returning
380 380 // garbage from this read is ok.
381 381 thread->set_pending_unsafe_access_error();
382 382 uc->uc_mcontext.regs->nip = ((unsigned long)pc) + 4;
383 383 return true;
384 384 }
385 385 }
386 386
387 387 // Check to see if we caught the safepoint code in the
388 388 // process of write protecting the memory serialization page.
389 389 // It write enables the page immediately after protecting it
390 390 // so we can just return to retry the write.
391 391 if ((sig == SIGSEGV) &&
392 392 // Si_addr may not be valid due to a bug in the linux-ppc64 kernel (see comment above).
393 393 // Use is_memory_serialization instead of si_addr.
394 394 ((NativeInstruction*)pc)->is_memory_serialization(thread, ucVoid)) {
395 395 // Synchronization problem in the pseudo memory barrier code (bug id 6546278)
396 396 // Block current thread until the memory serialize page permission restored.
397 397 os::block_on_serialize_page_trap();
398 398 return true;
399 399 }
400 400 }
401 401
402 402 if (stub != NULL) {
403 403 // Save all thread context in case we need to restore it.
404 404 if (thread != NULL) thread->set_saved_exception_pc(pc);
405 405 uc->uc_mcontext.regs->nip = (unsigned long)stub;
406 406 return true;
407 407 }
408 408
409 409 // signal-chaining
410 410 if (os::Linux::chained_handler(sig, info, ucVoid)) {
411 411 return true;
412 412 }
413 413
414 414 if (!abort_if_unrecognized) {
415 415 // caller wants another chance, so give it to him
416 416 return false;
417 417 }
418 418
419 419 if (pc == NULL && uc != NULL) {
420 420 pc = os::Linux::ucontext_get_pc(uc);
421 421 }
422 422
423 423 report_and_die:
424 424 // unmask current signal
425 425 sigset_t newset;
426 426 sigemptyset(&newset);
427 427 sigaddset(&newset, sig);
428 428 sigprocmask(SIG_UNBLOCK, &newset, NULL);
429 429
430 430 VMError err(t, sig, pc, info, ucVoid);
431 431 err.report_and_die();
432 432
433 433 ShouldNotReachHere();
434 434 return false;
435 435 }
436 436
437 437 void os::Linux::init_thread_fpu_state(void) {
438 438 // Disable FP exceptions.
439 439 __asm__ __volatile__ ("mtfsfi 6,0");
440 440 }
441 441
442 442 int os::Linux::get_fpu_control_word(void) {
443 443 // x86 has problems with FPU precision after pthread_cond_timedwait().
444 444 // nothing to do on ppc64.
445 445 return 0;
446 446 }
447 447
448 448 void os::Linux::set_fpu_control_word(int fpu_control) {
449 449 // x86 has problems with FPU precision after pthread_cond_timedwait().
450 450 // nothing to do on ppc64.
451 451 }
452 452
453 453 ////////////////////////////////////////////////////////////////////////////////
454 454 // thread stack
455 455
456 456 size_t os::Linux::min_stack_allowed = 768*K;
457 457
458 458 bool os::Linux::supports_variable_stack_size() { return true; }
459 459
460 460 // return default stack size for thr_type
461 461 size_t os::Linux::default_stack_size(os::ThreadType thr_type) {
462 462 // default stack size (compiler thread needs larger stack)
463 463 // Notice that the setting for compiler threads here have no impact
464 464 // because of the strange 'fallback logic' in os::create_thread().
465 465 // Better set CompilerThreadStackSize in globals_<os_cpu>.hpp if you want to
466 466 // specify a different stack size for compiler threads!
467 467 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
468 468 return s;
469 469 }
470 470
471 471 size_t os::Linux::default_guard_size(os::ThreadType thr_type) {
472 472 return 2 * page_size();
473 473 }
474 474
475 475 // Java thread:
476 476 //
477 477 // Low memory addresses
478 478 // +------------------------+
479 479 // | |\ JavaThread created by VM does not have glibc
480 480 // | glibc guard page | - guard, attached Java thread usually has
481 481 // | |/ 1 page glibc guard.
482 482 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
483 483 // | |\
484 484 // | HotSpot Guard Pages | - red and yellow pages
485 485 // | |/
486 486 // +------------------------+ JavaThread::stack_yellow_zone_base()
487 487 // | |\
488 488 // | Normal Stack | -
489 489 // | |/
490 490 // P2 +------------------------+ Thread::stack_base()
491 491 //
492 492 // Non-Java thread:
493 493 //
494 494 // Low memory addresses
495 495 // +------------------------+
496 496 // | |\
497 497 // | glibc guard page | - usually 1 page
498 498 // | |/
499 499 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
500 500 // | |\
501 501 // | Normal Stack | -
502 502 // | |/
503 503 // P2 +------------------------+ Thread::stack_base()
504 504 //
505 505 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
506 506 // pthread_attr_getstack()
507 507
508 508 static void current_stack_region(address * bottom, size_t * size) {
509 509 if (os::Linux::is_initial_thread()) {
510 510 // initial thread needs special handling because pthread_getattr_np()
511 511 // may return bogus value.
512 512 *bottom = os::Linux::initial_thread_stack_bottom();
513 513 *size = os::Linux::initial_thread_stack_size();
514 514 } else {
515 515 pthread_attr_t attr;
516 516
517 517 int rslt = pthread_getattr_np(pthread_self(), &attr);
518 518
519 519 // JVM needs to know exact stack location, abort if it fails
520 520 if (rslt != 0) {
521 521 if (rslt == ENOMEM) {
522 522 vm_exit_out_of_memory(0, OOM_MMAP_ERROR, "pthread_getattr_np");
523 523 } else {
524 524 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
525 525 }
526 526 }
527 527
528 528 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
529 529 fatal("Can not locate current stack attributes!");
530 530 }
531 531
532 532 pthread_attr_destroy(&attr);
533 533
534 534 }
535 535 assert(os::current_stack_pointer() >= *bottom &&
536 536 os::current_stack_pointer() < *bottom + *size, "just checking");
537 537 }
538 538
539 539 address os::current_stack_base() {
540 540 address bottom;
541 541 size_t size;
542 542 current_stack_region(&bottom, &size);
543 543 return (bottom + size);
544 544 }
545 545
546 546 size_t os::current_stack_size() {
547 547 // stack size includes normal stack and HotSpot guard pages
548 548 address bottom;
549 549 size_t size;
550 550 current_stack_region(&bottom, &size);
551 551 return size;
552 552 }
553 553
554 554 /////////////////////////////////////////////////////////////////////////////
555 555 // helper functions for fatal error handler
556 556
557 557 void os::print_context(outputStream *st, void *context) {
558 558 if (context == NULL) return;
559 559
560 560 ucontext_t* uc = (ucontext_t*)context;
561 561
562 562 st->print_cr("Registers:");
563 563 st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->nip);
564 564 st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.regs->link);
↓ open down ↓ |
206 lines elided |
↑ open up ↑ |
565 565 st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.regs->ctr);
566 566 st->cr();
567 567 for (int i = 0; i < 32; i++) {
568 568 st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.regs->gpr[i]);
569 569 if (i % 3 == 2) st->cr();
570 570 }
571 571 st->cr();
572 572 st->cr();
573 573
574 574 intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
575 - st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
575 + st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
576 576 print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
577 577 st->cr();
578 578
579 579 // Note: it may be unsafe to inspect memory near pc. For example, pc may
580 580 // point to garbage if entry point in an nmethod is corrupted. Leave
581 581 // this at the end, and hope for the best.
582 582 address pc = os::Linux::ucontext_get_pc(uc);
583 - st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
583 + st->print_cr("Instructions: (pc=" PTR_FORMAT ")", p2i(pc));
584 584 print_hex_dump(st, pc - 64, pc + 64, /*instrsize=*/4);
585 585 st->cr();
586 586 }
587 587
588 588 void os::print_register_info(outputStream *st, void *context) {
589 589 if (context == NULL) return;
590 590
591 591 ucontext_t *uc = (ucontext_t*)context;
592 592
593 593 st->print_cr("Register to memory mapping:");
594 594 st->cr();
595 595
596 596 // this is only for the "general purpose" registers
597 597 for (int i = 0; i < 32; i++) {
598 598 st->print("r%-2d=", i);
599 599 print_location(st, uc->uc_mcontext.regs->gpr[i]);
600 600 }
601 601 st->cr();
602 602 }
603 603
604 604 extern "C" {
605 605 int SpinPause() {
606 606 return 0;
607 607 }
608 608 }
609 609
610 610 #ifndef PRODUCT
611 611 void os::verify_stack_alignment() {
612 612 assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
613 613 }
614 614 #endif
↓ open down ↓ |
21 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX