Print this page
Split |
Close |
Expand all |
Collapse all |
--- old/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
+++ new/src/os_cpu/bsd_x86/vm/os_bsd_x86.cpp
1 1 /*
2 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved.
3 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 4 *
5 5 * This code is free software; you can redistribute it and/or modify it
6 6 * under the terms of the GNU General Public License version 2 only, as
7 7 * published by the Free Software Foundation.
8 8 *
9 9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 12 * version 2 for more details (a copy is included in the LICENSE file that
13 13 * accompanied this code).
14 14 *
15 15 * You should have received a copy of the GNU General Public License version
16 16 * 2 along with this work; if not, write to the Free Software Foundation,
17 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18 18 *
19 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20 20 * or visit www.oracle.com if you need additional information or have any
21 21 * questions.
22 22 *
23 23 */
24 24
25 25 // no precompiled headers
26 26 #include "assembler_x86.inline.hpp"
27 27 #include "classfile/classLoader.hpp"
28 28 #include "classfile/systemDictionary.hpp"
29 29 #include "classfile/vmSymbols.hpp"
30 30 #include "code/icBuffer.hpp"
31 31 #include "code/vtableStubs.hpp"
32 32 #include "interpreter/interpreter.hpp"
33 33 #include "jvm_bsd.h"
34 34 #include "memory/allocation.inline.hpp"
35 35 #include "mutex_bsd.inline.hpp"
36 36 #include "nativeInst_x86.hpp"
37 37 #include "os_share_bsd.hpp"
38 38 #include "prims/jniFastGetField.hpp"
39 39 #include "prims/jvm.h"
40 40 #include "prims/jvm_misc.hpp"
41 41 #include "runtime/arguments.hpp"
42 42 #include "runtime/extendedPC.hpp"
43 43 #include "runtime/frame.inline.hpp"
44 44 #include "runtime/interfaceSupport.hpp"
45 45 #include "runtime/java.hpp"
46 46 #include "runtime/javaCalls.hpp"
47 47 #include "runtime/mutexLocker.hpp"
48 48 #include "runtime/osThread.hpp"
49 49 #include "runtime/sharedRuntime.hpp"
50 50 #include "runtime/stubRoutines.hpp"
51 51 #include "runtime/timer.hpp"
52 52 #include "thread_bsd.inline.hpp"
53 53 #include "utilities/events.hpp"
54 54 #include "utilities/vmError.hpp"
55 55 #ifdef COMPILER1
56 56 #include "c1/c1_Runtime1.hpp"
57 57 #endif
58 58 #ifdef COMPILER2
59 59 #include "opto/runtime.hpp"
60 60 #endif
61 61
62 62 // put OS-includes here
63 63 # include <sys/types.h>
64 64 # include <sys/mman.h>
65 65 # include <pthread.h>
66 66 # include <signal.h>
67 67 # include <errno.h>
68 68 # include <dlfcn.h>
69 69 # include <stdlib.h>
70 70 # include <stdio.h>
71 71 # include <unistd.h>
72 72 # include <sys/resource.h>
73 73 # include <pthread.h>
74 74 # include <sys/stat.h>
75 75 # include <sys/time.h>
76 76 # include <sys/utsname.h>
77 77 # include <sys/socket.h>
78 78 # include <sys/wait.h>
79 79 # include <pwd.h>
80 80 # include <poll.h>
81 81 #ifndef __OpenBSD__
82 82 # include <ucontext.h>
83 83 #endif
84 84
85 85 #if defined(_ALLBSD_SOURCE) && !defined(__APPLE__) && !defined(__NetBSD__)
86 86 # include <pthread_np.h>
87 87 #endif
88 88
89 89 #ifdef AMD64
90 90 #define SPELL_REG_SP "rsp"
91 91 #define SPELL_REG_FP "rbp"
92 92 #else
93 93 #define SPELL_REG_SP "esp"
94 94 #define SPELL_REG_FP "ebp"
95 95 #endif // AMD64
96 96
97 97 #ifdef __FreeBSD__
98 98 # define context_trapno uc_mcontext.mc_trapno
99 99 # ifdef AMD64
100 100 # define context_pc uc_mcontext.mc_rip
101 101 # define context_sp uc_mcontext.mc_rsp
102 102 # define context_fp uc_mcontext.mc_rbp
103 103 # define context_rip uc_mcontext.mc_rip
104 104 # define context_rsp uc_mcontext.mc_rsp
105 105 # define context_rbp uc_mcontext.mc_rbp
106 106 # define context_rax uc_mcontext.mc_rax
107 107 # define context_rbx uc_mcontext.mc_rbx
108 108 # define context_rcx uc_mcontext.mc_rcx
109 109 # define context_rdx uc_mcontext.mc_rdx
110 110 # define context_rsi uc_mcontext.mc_rsi
111 111 # define context_rdi uc_mcontext.mc_rdi
112 112 # define context_r8 uc_mcontext.mc_r8
113 113 # define context_r9 uc_mcontext.mc_r9
114 114 # define context_r10 uc_mcontext.mc_r10
115 115 # define context_r11 uc_mcontext.mc_r11
116 116 # define context_r12 uc_mcontext.mc_r12
117 117 # define context_r13 uc_mcontext.mc_r13
118 118 # define context_r14 uc_mcontext.mc_r14
119 119 # define context_r15 uc_mcontext.mc_r15
120 120 # define context_flags uc_mcontext.mc_flags
121 121 # define context_err uc_mcontext.mc_err
122 122 # else
123 123 # define context_pc uc_mcontext.mc_eip
124 124 # define context_sp uc_mcontext.mc_esp
125 125 # define context_fp uc_mcontext.mc_ebp
126 126 # define context_eip uc_mcontext.mc_eip
127 127 # define context_esp uc_mcontext.mc_esp
128 128 # define context_eax uc_mcontext.mc_eax
129 129 # define context_ebx uc_mcontext.mc_ebx
130 130 # define context_ecx uc_mcontext.mc_ecx
131 131 # define context_edx uc_mcontext.mc_edx
132 132 # define context_ebp uc_mcontext.mc_ebp
133 133 # define context_esi uc_mcontext.mc_esi
134 134 # define context_edi uc_mcontext.mc_edi
135 135 # define context_eflags uc_mcontext.mc_eflags
136 136 # define context_trapno uc_mcontext.mc_trapno
137 137 # endif
138 138 #endif
139 139
140 140 #ifdef __APPLE__
141 141 # if __DARWIN_UNIX03 && (MAC_OS_X_VERSION_MAX_ALLOWED >= MAC_OS_X_VERSION_10_5)
142 142 // 10.5 UNIX03 member name prefixes
143 143 #define DU3_PREFIX(s, m) __ ## s.__ ## m
144 144 # else
145 145 #define DU3_PREFIX(s, m) s ## . ## m
146 146 # endif
147 147
148 148 # ifdef AMD64
149 149 # define context_pc context_rip
150 150 # define context_sp context_rsp
151 151 # define context_fp context_rbp
152 152 # define context_rip uc_mcontext->DU3_PREFIX(ss,rip)
153 153 # define context_rsp uc_mcontext->DU3_PREFIX(ss,rsp)
154 154 # define context_rax uc_mcontext->DU3_PREFIX(ss,rax)
155 155 # define context_rbx uc_mcontext->DU3_PREFIX(ss,rbx)
156 156 # define context_rcx uc_mcontext->DU3_PREFIX(ss,rcx)
157 157 # define context_rdx uc_mcontext->DU3_PREFIX(ss,rdx)
158 158 # define context_rbp uc_mcontext->DU3_PREFIX(ss,rbp)
159 159 # define context_rsi uc_mcontext->DU3_PREFIX(ss,rsi)
160 160 # define context_rdi uc_mcontext->DU3_PREFIX(ss,rdi)
161 161 # define context_r8 uc_mcontext->DU3_PREFIX(ss,r8)
162 162 # define context_r9 uc_mcontext->DU3_PREFIX(ss,r9)
163 163 # define context_r10 uc_mcontext->DU3_PREFIX(ss,r10)
164 164 # define context_r11 uc_mcontext->DU3_PREFIX(ss,r11)
165 165 # define context_r12 uc_mcontext->DU3_PREFIX(ss,r12)
166 166 # define context_r13 uc_mcontext->DU3_PREFIX(ss,r13)
167 167 # define context_r14 uc_mcontext->DU3_PREFIX(ss,r14)
168 168 # define context_r15 uc_mcontext->DU3_PREFIX(ss,r15)
169 169 # define context_flags uc_mcontext->DU3_PREFIX(ss,rflags)
170 170 # define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
171 171 # define context_err uc_mcontext->DU3_PREFIX(es,err)
172 172 # else
173 173 # define context_pc context_eip
174 174 # define context_sp context_esp
175 175 # define context_fp context_ebp
176 176 # define context_eip uc_mcontext->DU3_PREFIX(ss,eip)
177 177 # define context_esp uc_mcontext->DU3_PREFIX(ss,esp)
178 178 # define context_eax uc_mcontext->DU3_PREFIX(ss,eax)
179 179 # define context_ebx uc_mcontext->DU3_PREFIX(ss,ebx)
180 180 # define context_ecx uc_mcontext->DU3_PREFIX(ss,ecx)
181 181 # define context_edx uc_mcontext->DU3_PREFIX(ss,edx)
182 182 # define context_ebp uc_mcontext->DU3_PREFIX(ss,ebp)
183 183 # define context_esi uc_mcontext->DU3_PREFIX(ss,esi)
184 184 # define context_edi uc_mcontext->DU3_PREFIX(ss,edi)
185 185 # define context_eflags uc_mcontext->DU3_PREFIX(ss,eflags)
186 186 # define context_trapno uc_mcontext->DU3_PREFIX(es,trapno)
187 187 # endif
188 188 #endif
189 189
190 190 #ifdef __OpenBSD__
191 191 # define context_trapno sc_trapno
192 192 # ifdef AMD64
193 193 # define context_pc sc_rip
194 194 # define context_sp sc_rsp
195 195 # define context_fp sc_rbp
196 196 # define context_rip sc_rip
197 197 # define context_rsp sc_rsp
198 198 # define context_rbp sc_rbp
199 199 # define context_rax sc_rax
200 200 # define context_rbx sc_rbx
201 201 # define context_rcx sc_rcx
202 202 # define context_rdx sc_rdx
203 203 # define context_rsi sc_rsi
204 204 # define context_rdi sc_rdi
205 205 # define context_r8 sc_r8
206 206 # define context_r9 sc_r9
207 207 # define context_r10 sc_r10
208 208 # define context_r11 sc_r11
209 209 # define context_r12 sc_r12
210 210 # define context_r13 sc_r13
211 211 # define context_r14 sc_r14
212 212 # define context_r15 sc_r15
213 213 # define context_flags sc_rflags
214 214 # define context_err sc_err
215 215 # else
216 216 # define context_pc sc_eip
217 217 # define context_sp sc_esp
218 218 # define context_fp sc_ebp
219 219 # define context_eip sc_eip
220 220 # define context_esp sc_esp
221 221 # define context_eax sc_eax
222 222 # define context_ebx sc_ebx
223 223 # define context_ecx sc_ecx
224 224 # define context_edx sc_edx
225 225 # define context_ebp sc_ebp
226 226 # define context_esi sc_esi
227 227 # define context_edi sc_edi
228 228 # define context_eflags sc_eflags
229 229 # define context_trapno sc_trapno
230 230 # endif
231 231 #endif
232 232
233 233 #ifdef __NetBSD__
234 234 # define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
235 235 # ifdef AMD64
236 236 # define __register_t __greg_t
237 237 # define context_pc uc_mcontext.__gregs[_REG_RIP]
238 238 # define context_sp uc_mcontext.__gregs[_REG_URSP]
239 239 # define context_fp uc_mcontext.__gregs[_REG_RBP]
240 240 # define context_rip uc_mcontext.__gregs[_REG_RIP]
241 241 # define context_rsp uc_mcontext.__gregs[_REG_URSP]
242 242 # define context_rax uc_mcontext.__gregs[_REG_RAX]
243 243 # define context_rbx uc_mcontext.__gregs[_REG_RBX]
244 244 # define context_rcx uc_mcontext.__gregs[_REG_RCX]
245 245 # define context_rdx uc_mcontext.__gregs[_REG_RDX]
246 246 # define context_rbp uc_mcontext.__gregs[_REG_RBP]
247 247 # define context_rsi uc_mcontext.__gregs[_REG_RSI]
248 248 # define context_rdi uc_mcontext.__gregs[_REG_RDI]
249 249 # define context_r8 uc_mcontext.__gregs[_REG_R8]
250 250 # define context_r9 uc_mcontext.__gregs[_REG_R9]
251 251 # define context_r10 uc_mcontext.__gregs[_REG_R10]
252 252 # define context_r11 uc_mcontext.__gregs[_REG_R11]
253 253 # define context_r12 uc_mcontext.__gregs[_REG_R12]
254 254 # define context_r13 uc_mcontext.__gregs[_REG_R13]
255 255 # define context_r14 uc_mcontext.__gregs[_REG_R14]
256 256 # define context_r15 uc_mcontext.__gregs[_REG_R15]
257 257 # define context_flags uc_mcontext.__gregs[_REG_RFL]
258 258 # define context_err uc_mcontext.__gregs[_REG_ERR]
259 259 # else
260 260 # define context_pc uc_mcontext.__gregs[_REG_EIP]
261 261 # define context_sp uc_mcontext.__gregs[_REG_UESP]
262 262 # define context_fp uc_mcontext.__gregs[_REG_EBP]
263 263 # define context_eip uc_mcontext.__gregs[_REG_EIP]
264 264 # define context_esp uc_mcontext.__gregs[_REG_UESP]
265 265 # define context_eax uc_mcontext.__gregs[_REG_EAX]
266 266 # define context_ebx uc_mcontext.__gregs[_REG_EBX]
267 267 # define context_ecx uc_mcontext.__gregs[_REG_ECX]
268 268 # define context_edx uc_mcontext.__gregs[_REG_EDX]
269 269 # define context_ebp uc_mcontext.__gregs[_REG_EBP]
270 270 # define context_esi uc_mcontext.__gregs[_REG_ESI]
271 271 # define context_edi uc_mcontext.__gregs[_REG_EDI]
272 272 # define context_eflags uc_mcontext.__gregs[_REG_EFL]
273 273 # define context_trapno uc_mcontext.__gregs[_REG_TRAPNO]
274 274 # endif
275 275 #endif
276 276
277 277 address os::current_stack_pointer() {
278 278 #if defined(__clang__) || defined(__llvm__)
279 279 register void *esp;
280 280 __asm__("mov %%"SPELL_REG_SP", %0":"=r"(esp));
281 281 return (address) esp;
282 282 #elif defined(SPARC_WORKS)
283 283 register void *esp;
284 284 __asm__("mov %%"SPELL_REG_SP", %0":"=r"(esp));
285 285 return (address) ((char*)esp + sizeof(long)*2);
286 286 #else
287 287 register void *esp __asm__ (SPELL_REG_SP);
288 288 return (address) esp;
289 289 #endif
290 290 }
291 291
292 292 char* os::non_memory_address_word() {
293 293 // Must never look like an address returned by reserve_memory,
294 294 // even in its subfields (as defined by the CPU immediate fields,
295 295 // if the CPU splits constants across multiple instructions).
296 296
297 297 return (char*) -1;
298 298 }
299 299
300 300 void os::initialize_thread() {
301 301 // Nothing to do.
302 302 }
303 303
304 304 address os::Bsd::ucontext_get_pc(ucontext_t * uc) {
305 305 return (address)uc->context_pc;
306 306 }
307 307
308 308 intptr_t* os::Bsd::ucontext_get_sp(ucontext_t * uc) {
309 309 return (intptr_t*)uc->context_sp;
310 310 }
311 311
312 312 intptr_t* os::Bsd::ucontext_get_fp(ucontext_t * uc) {
313 313 return (intptr_t*)uc->context_fp;
314 314 }
315 315
316 316 // For Forte Analyzer AsyncGetCallTrace profiling support - thread
317 317 // is currently interrupted by SIGPROF.
318 318 // os::Solaris::fetch_frame_from_ucontext() tries to skip nested signal
319 319 // frames. Currently we don't do that on Bsd, so it's the same as
320 320 // os::fetch_frame_from_context().
321 321 ExtendedPC os::Bsd::fetch_frame_from_ucontext(Thread* thread,
322 322 ucontext_t* uc, intptr_t** ret_sp, intptr_t** ret_fp) {
323 323
324 324 assert(thread != NULL, "just checking");
325 325 assert(ret_sp != NULL, "just checking");
326 326 assert(ret_fp != NULL, "just checking");
327 327
328 328 return os::fetch_frame_from_context(uc, ret_sp, ret_fp);
329 329 }
330 330
331 331 ExtendedPC os::fetch_frame_from_context(void* ucVoid,
332 332 intptr_t** ret_sp, intptr_t** ret_fp) {
333 333
334 334 ExtendedPC epc;
335 335 ucontext_t* uc = (ucontext_t*)ucVoid;
336 336
337 337 if (uc != NULL) {
338 338 epc = ExtendedPC(os::Bsd::ucontext_get_pc(uc));
339 339 if (ret_sp) *ret_sp = os::Bsd::ucontext_get_sp(uc);
340 340 if (ret_fp) *ret_fp = os::Bsd::ucontext_get_fp(uc);
341 341 } else {
342 342 // construct empty ExtendedPC for return value checking
343 343 epc = ExtendedPC(NULL);
344 344 if (ret_sp) *ret_sp = (intptr_t *)NULL;
345 345 if (ret_fp) *ret_fp = (intptr_t *)NULL;
346 346 }
347 347
348 348 return epc;
349 349 }
350 350
351 351 frame os::fetch_frame_from_context(void* ucVoid) {
352 352 intptr_t* sp;
353 353 intptr_t* fp;
354 354 ExtendedPC epc = fetch_frame_from_context(ucVoid, &sp, &fp);
↓ open down ↓ |
354 lines elided |
↑ open up ↑ |
355 355 return frame(sp, fp, epc.pc());
356 356 }
357 357
358 358 // By default, gcc always save frame pointer (%ebp/%rbp) on stack. It may get
359 359 // turned off by -fomit-frame-pointer,
360 360 frame os::get_sender_for_C_frame(frame* fr) {
361 361 return frame(fr->sender_sp(), fr->link(), fr->sender_pc());
362 362 }
363 363
364 364 intptr_t* _get_previous_fp() {
365 -#if defined(SPARC_WORKS) || defined(__clang__)
365 +#if defined(SPARC_WORKS) || defined(__clang__) || defined(__llvm__)
366 366 register intptr_t **ebp;
367 367 __asm__("mov %%"SPELL_REG_FP", %0":"=r"(ebp));
368 368 #else
369 369 register intptr_t **ebp __asm__ (SPELL_REG_FP);
370 370 #endif
371 371 return (intptr_t*) *ebp; // we want what it points to.
372 372 }
373 373
374 374
375 375 frame os::current_frame() {
376 376 intptr_t* fp = _get_previous_fp();
377 377 frame myframe((intptr_t*)os::current_stack_pointer(),
378 378 (intptr_t*)fp,
379 379 CAST_FROM_FN_PTR(address, os::current_frame));
380 380 if (os::is_first_C_frame(&myframe)) {
381 381 // stack is not walkable
382 382 return frame(NULL, NULL, NULL);
383 383 } else {
384 384 return os::get_sender_for_C_frame(&myframe);
385 385 }
386 386 }
387 387
388 388 // Utility functions
389 389
390 390 // From IA32 System Programming Guide
391 391 enum {
392 392 trap_page_fault = 0xE
393 393 };
394 394
395 395 extern "C" void Fetch32PFI () ;
396 396 extern "C" void Fetch32Resume () ;
397 397 #ifdef AMD64
398 398 extern "C" void FetchNPFI () ;
399 399 extern "C" void FetchNResume () ;
400 400 #endif // AMD64
401 401
402 402 extern "C" JNIEXPORT int
403 403 JVM_handle_bsd_signal(int sig,
404 404 siginfo_t* info,
405 405 void* ucVoid,
406 406 int abort_if_unrecognized) {
407 407 ucontext_t* uc = (ucontext_t*) ucVoid;
408 408
409 409 Thread* t = ThreadLocalStorage::get_thread_slow();
410 410
411 411 SignalHandlerMark shm(t);
412 412
413 413 // Note: it's not uncommon that JNI code uses signal/sigset to install
414 414 // then restore certain signal handler (e.g. to temporarily block SIGPIPE,
415 415 // or have a SIGILL handler when detecting CPU type). When that happens,
416 416 // JVM_handle_bsd_signal() might be invoked with junk info/ucVoid. To
417 417 // avoid unnecessary crash when libjsig is not preloaded, try handle signals
418 418 // that do not require siginfo/ucontext first.
419 419
420 420 if (sig == SIGPIPE || sig == SIGXFSZ) {
421 421 // allow chained handler to go first
422 422 if (os::Bsd::chained_handler(sig, info, ucVoid)) {
423 423 return true;
424 424 } else {
425 425 if (PrintMiscellaneous && (WizardMode || Verbose)) {
426 426 char buf[64];
427 427 warning("Ignoring %s - see bugs 4229104 or 646499219",
428 428 os::exception_name(sig, buf, sizeof(buf)));
429 429 }
430 430 return true;
431 431 }
432 432 }
433 433
434 434 JavaThread* thread = NULL;
435 435 VMThread* vmthread = NULL;
436 436 if (os::Bsd::signal_handlers_are_installed) {
437 437 if (t != NULL ){
438 438 if(t->is_Java_thread()) {
439 439 thread = (JavaThread*)t;
440 440 }
441 441 else if(t->is_VM_thread()){
442 442 vmthread = (VMThread *)t;
443 443 }
444 444 }
445 445 }
446 446 /*
447 447 NOTE: does not seem to work on bsd.
448 448 if (info == NULL || info->si_code <= 0 || info->si_code == SI_NOINFO) {
449 449 // can't decode this kind of signal
450 450 info = NULL;
451 451 } else {
452 452 assert(sig == info->si_signo, "bad siginfo");
453 453 }
454 454 */
455 455 // decide if this trap can be handled by a stub
456 456 address stub = NULL;
457 457
458 458 address pc = NULL;
459 459
460 460 //%note os_trap_1
461 461 if (info != NULL && uc != NULL && thread != NULL) {
462 462 pc = (address) os::Bsd::ucontext_get_pc(uc);
463 463
464 464 if (pc == (address) Fetch32PFI) {
465 465 uc->context_pc = intptr_t(Fetch32Resume) ;
466 466 return 1 ;
467 467 }
468 468 #ifdef AMD64
469 469 if (pc == (address) FetchNPFI) {
470 470 uc->context_pc = intptr_t (FetchNResume) ;
471 471 return 1 ;
472 472 }
473 473 #endif // AMD64
474 474
475 475 // Handle ALL stack overflow variations here
476 476 if (sig == SIGSEGV || sig == SIGBUS) {
477 477 address addr = (address) info->si_addr;
478 478
479 479 // check if fault address is within thread stack
480 480 if (addr < thread->stack_base() &&
481 481 addr >= thread->stack_base() - thread->stack_size()) {
482 482 // stack overflow
483 483 if (thread->in_stack_yellow_zone(addr)) {
484 484 thread->disable_stack_yellow_zone();
485 485 if (thread->thread_state() == _thread_in_Java) {
486 486 // Throw a stack overflow exception. Guard pages will be reenabled
487 487 // while unwinding the stack.
488 488 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::STACK_OVERFLOW);
489 489 } else {
490 490 // Thread was in the vm or native code. Return and try to finish.
491 491 return 1;
492 492 }
493 493 } else if (thread->in_stack_red_zone(addr)) {
494 494 // Fatal red zone violation. Disable the guard pages and fall through
495 495 // to handle_unexpected_exception way down below.
496 496 thread->disable_stack_red_zone();
497 497 tty->print_raw_cr("An irrecoverable stack overflow has occurred.");
498 498 #ifndef _ALLBSD_SOURCE
499 499 } else {
500 500 // Accessing stack address below sp may cause SEGV if current
501 501 // thread has MAP_GROWSDOWN stack. This should only happen when
502 502 // current thread was created by user code with MAP_GROWSDOWN flag
503 503 // and then attached to VM. See notes in os_bsd.cpp.
504 504 if (thread->osthread()->expanding_stack() == 0) {
505 505 thread->osthread()->set_expanding_stack();
506 506 if (os::Bsd::manually_expand_stack(thread, addr)) {
507 507 thread->osthread()->clear_expanding_stack();
508 508 return 1;
509 509 }
510 510 thread->osthread()->clear_expanding_stack();
511 511 } else {
512 512 fatal("recursive segv. expanding stack.");
513 513 }
514 514 #endif
515 515 }
516 516 }
517 517 }
518 518
519 519 if (thread->thread_state() == _thread_in_Java) {
520 520 // Java thread running in Java code => find exception handler if any
521 521 // a fault inside compiled code, the interpreter, or a stub
522 522
523 523 if ((sig == SIGSEGV || sig == SIGBUS) && os::is_poll_address((address)info->si_addr)) {
524 524 stub = SharedRuntime::get_poll_stub(pc);
525 525 #if defined(__APPLE__) && !defined(AMD64)
526 526 // 32-bit Darwin reports a SIGBUS for nearly all memory access exceptions.
527 527 // Catching SIGBUS here prevents the implicit SIGBUS NULL check below from
528 528 // being called, so only do so if the implicit NULL check is not necessary.
529 529 } else if (sig == SIGBUS && MacroAssembler::needs_explicit_null_check((int)info->si_addr)) {
530 530 #else
531 531 } else if (sig == SIGBUS /* && info->si_code == BUS_OBJERR */) {
532 532 #endif
533 533 // BugId 4454115: A read from a MappedByteBuffer can fault
534 534 // here if the underlying file has been truncated.
535 535 // Do not crash the VM in such a case.
536 536 CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
537 537 nmethod* nm = cb->is_nmethod() ? (nmethod*)cb : NULL;
538 538 if (nm != NULL && nm->has_unsafe_access()) {
539 539 stub = StubRoutines::handler_for_unsafe_access();
540 540 }
541 541 }
542 542 else
543 543
544 544 #ifdef AMD64
545 545 if (sig == SIGFPE &&
546 546 (info->si_code == FPE_INTDIV || info->si_code == FPE_FLTDIV)) {
547 547 stub =
548 548 SharedRuntime::
549 549 continuation_for_implicit_exception(thread,
550 550 pc,
551 551 SharedRuntime::
552 552 IMPLICIT_DIVIDE_BY_ZERO);
553 553 #ifdef __APPLE__
554 554 } else if (sig == SIGFPE && info->si_code == FPE_NOOP) {
555 555 int op = pc[0];
556 556
557 557 // Skip REX
558 558 if ((pc[0] & 0xf0) == 0x40) {
559 559 op = pc[1];
560 560 } else {
561 561 op = pc[0];
562 562 }
563 563
564 564 // Check for IDIV
565 565 if (op == 0xF7) {
566 566 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime:: IMPLICIT_DIVIDE_BY_ZERO);
567 567 } else {
568 568 // TODO: handle more cases if we are using other x86 instructions
569 569 // that can generate SIGFPE signal.
570 570 tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
571 571 fatal("please update this code.");
572 572 }
573 573 #endif /* __APPLE__ */
574 574
575 575 #else
576 576 if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
577 577 // HACK: si_code does not work on bsd 2.2.12-20!!!
578 578 int op = pc[0];
579 579 if (op == 0xDB) {
580 580 // FIST
581 581 // TODO: The encoding of D2I in i486.ad can cause an exception
582 582 // prior to the fist instruction if there was an invalid operation
583 583 // pending. We want to dismiss that exception. From the win_32
584 584 // side it also seems that if it really was the fist causing
585 585 // the exception that we do the d2i by hand with different
586 586 // rounding. Seems kind of weird.
587 587 // NOTE: that we take the exception at the NEXT floating point instruction.
588 588 assert(pc[0] == 0xDB, "not a FIST opcode");
589 589 assert(pc[1] == 0x14, "not a FIST opcode");
590 590 assert(pc[2] == 0x24, "not a FIST opcode");
591 591 return true;
592 592 } else if (op == 0xF7) {
593 593 // IDIV
594 594 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
595 595 } else {
596 596 // TODO: handle more cases if we are using other x86 instructions
597 597 // that can generate SIGFPE signal on bsd.
598 598 tty->print_cr("unknown opcode 0x%X with SIGFPE.", op);
599 599 fatal("please update this code.");
600 600 }
601 601 #endif // AMD64
602 602 } else if ((sig == SIGSEGV || sig == SIGBUS) &&
603 603 !MacroAssembler::needs_explicit_null_check((intptr_t)info->si_addr)) {
604 604 // Determination of interpreter/vtable stub/compiled code null exception
605 605 stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
606 606 }
607 607 } else if (thread->thread_state() == _thread_in_vm &&
608 608 sig == SIGBUS && /* info->si_code == BUS_OBJERR && */
609 609 thread->doing_unsafe_access()) {
610 610 stub = StubRoutines::handler_for_unsafe_access();
611 611 }
612 612
613 613 // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
614 614 // and the heap gets shrunk before the field access.
615 615 if ((sig == SIGSEGV) || (sig == SIGBUS)) {
616 616 address addr = JNI_FastGetField::find_slowcase_pc(pc);
617 617 if (addr != (address)-1) {
618 618 stub = addr;
619 619 }
620 620 }
621 621
622 622 // Check to see if we caught the safepoint code in the
623 623 // process of write protecting the memory serialization page.
624 624 // It write enables the page immediately after protecting it
625 625 // so we can just return to retry the write.
626 626 if ((sig == SIGSEGV || sig == SIGBUS) &&
627 627 os::is_memory_serialize_page(thread, (address) info->si_addr)) {
628 628 // Block current thread until the memory serialize page permission restored.
629 629 os::block_on_serialize_page_trap();
630 630 return true;
631 631 }
632 632 }
633 633
634 634 #ifndef AMD64
635 635 // Execution protection violation
636 636 //
637 637 // This should be kept as the last step in the triage. We don't
638 638 // have a dedicated trap number for a no-execute fault, so be
639 639 // conservative and allow other handlers the first shot.
640 640 //
641 641 // Note: We don't test that info->si_code == SEGV_ACCERR here.
642 642 // this si_code is so generic that it is almost meaningless; and
643 643 // the si_code for this condition may change in the future.
644 644 // Furthermore, a false-positive should be harmless.
645 645 if (UnguardOnExecutionViolation > 0 &&
646 646 (sig == SIGSEGV || sig == SIGBUS) &&
647 647 uc->context_trapno == trap_page_fault) {
648 648 int page_size = os::vm_page_size();
649 649 address addr = (address) info->si_addr;
650 650 address pc = os::Bsd::ucontext_get_pc(uc);
651 651 // Make sure the pc and the faulting address are sane.
652 652 //
653 653 // If an instruction spans a page boundary, and the page containing
654 654 // the beginning of the instruction is executable but the following
655 655 // page is not, the pc and the faulting address might be slightly
656 656 // different - we still want to unguard the 2nd page in this case.
657 657 //
658 658 // 15 bytes seems to be a (very) safe value for max instruction size.
659 659 bool pc_is_near_addr =
660 660 (pointer_delta((void*) addr, (void*) pc, sizeof(char)) < 15);
661 661 bool instr_spans_page_boundary =
662 662 (align_size_down((intptr_t) pc ^ (intptr_t) addr,
663 663 (intptr_t) page_size) > 0);
664 664
665 665 if (pc == addr || (pc_is_near_addr && instr_spans_page_boundary)) {
666 666 static volatile address last_addr =
667 667 (address) os::non_memory_address_word();
668 668
669 669 // In conservative mode, don't unguard unless the address is in the VM
670 670 if (addr != last_addr &&
671 671 (UnguardOnExecutionViolation > 1 || os::address_is_in_vm(addr))) {
672 672
673 673 // Set memory to RWX and retry
674 674 address page_start =
675 675 (address) align_size_down((intptr_t) addr, (intptr_t) page_size);
676 676 bool res = os::protect_memory((char*) page_start, page_size,
677 677 os::MEM_PROT_RWX);
678 678
679 679 if (PrintMiscellaneous && Verbose) {
680 680 char buf[256];
681 681 jio_snprintf(buf, sizeof(buf), "Execution protection violation "
682 682 "at " INTPTR_FORMAT
683 683 ", unguarding " INTPTR_FORMAT ": %s, errno=%d", addr,
684 684 page_start, (res ? "success" : "failed"), errno);
685 685 tty->print_raw_cr(buf);
686 686 }
687 687 stub = pc;
688 688
689 689 // Set last_addr so if we fault again at the same address, we don't end
690 690 // up in an endless loop.
691 691 //
692 692 // There are two potential complications here. Two threads trapping at
693 693 // the same address at the same time could cause one of the threads to
694 694 // think it already unguarded, and abort the VM. Likely very rare.
695 695 //
696 696 // The other race involves two threads alternately trapping at
697 697 // different addresses and failing to unguard the page, resulting in
698 698 // an endless loop. This condition is probably even more unlikely than
699 699 // the first.
700 700 //
701 701 // Although both cases could be avoided by using locks or thread local
702 702 // last_addr, these solutions are unnecessary complication: this
703 703 // handler is a best-effort safety net, not a complete solution. It is
704 704 // disabled by default and should only be used as a workaround in case
705 705 // we missed any no-execute-unsafe VM code.
706 706
707 707 last_addr = addr;
708 708 }
709 709 }
710 710 }
711 711 #endif // !AMD64
712 712
713 713 if (stub != NULL) {
714 714 // save all thread context in case we need to restore it
715 715 if (thread != NULL) thread->set_saved_exception_pc(pc);
716 716
717 717 uc->context_pc = (intptr_t)stub;
718 718 return true;
719 719 }
720 720
721 721 // signal-chaining
722 722 if (os::Bsd::chained_handler(sig, info, ucVoid)) {
723 723 return true;
724 724 }
725 725
726 726 if (!abort_if_unrecognized) {
727 727 // caller wants another chance, so give it to him
728 728 return false;
729 729 }
730 730
731 731 if (pc == NULL && uc != NULL) {
732 732 pc = os::Bsd::ucontext_get_pc(uc);
733 733 }
734 734
735 735 // unmask current signal
736 736 sigset_t newset;
737 737 sigemptyset(&newset);
738 738 sigaddset(&newset, sig);
739 739 sigprocmask(SIG_UNBLOCK, &newset, NULL);
740 740
741 741 VMError err(t, sig, pc, info, ucVoid);
742 742 err.report_and_die();
743 743
744 744 ShouldNotReachHere();
745 745 }
746 746
747 747 #ifdef _ALLBSD_SOURCE
748 748 // From solaris_i486.s ported to bsd_i486.s
749 749 extern "C" void fixcw();
750 750 #endif
751 751
752 752 void os::Bsd::init_thread_fpu_state(void) {
753 753 #ifndef AMD64
754 754 # ifdef _ALLBSD_SOURCE
755 755 // Set fpu to 53 bit precision. This happens too early to use a stub.
756 756 fixcw();
757 757 # else
758 758 // set fpu to 53 bit precision
759 759 set_fpu_control_word(0x27f);
760 760 # endif
761 761 #endif // !AMD64
762 762 }
763 763
764 764 #ifndef _ALLBSD_SOURCE
765 765 int os::Bsd::get_fpu_control_word(void) {
766 766 #ifdef AMD64
767 767 return 0;
768 768 #else
769 769 int fpu_control;
770 770 _FPU_GETCW(fpu_control);
771 771 return fpu_control & 0xffff;
772 772 #endif // AMD64
773 773 }
774 774
775 775 void os::Bsd::set_fpu_control_word(int fpu_control) {
776 776 #ifndef AMD64
777 777 _FPU_SETCW(fpu_control);
778 778 #endif // !AMD64
779 779 }
780 780 #endif
781 781
782 782 // Check that the bsd kernel version is 2.4 or higher since earlier
783 783 // versions do not support SSE without patches.
784 784 bool os::supports_sse() {
785 785 #if defined(AMD64) || defined(_ALLBSD_SOURCE)
786 786 return true;
787 787 #else
788 788 struct utsname uts;
789 789 if( uname(&uts) != 0 ) return false; // uname fails?
790 790 char *minor_string;
791 791 int major = strtol(uts.release,&minor_string,10);
792 792 int minor = strtol(minor_string+1,NULL,10);
793 793 bool result = (major > 2 || (major==2 && minor >= 4));
794 794 #ifndef PRODUCT
795 795 if (PrintMiscellaneous && Verbose) {
796 796 tty->print("OS version is %d.%d, which %s support SSE/SSE2\n",
797 797 major,minor, result ? "DOES" : "does NOT");
798 798 }
799 799 #endif
800 800 return result;
801 801 #endif // AMD64
802 802 }
803 803
804 804 bool os::is_allocatable(size_t bytes) {
805 805 #ifdef AMD64
806 806 // unused on amd64?
807 807 return true;
808 808 #else
809 809
810 810 if (bytes < 2 * G) {
811 811 return true;
812 812 }
813 813
814 814 char* addr = reserve_memory(bytes, NULL);
815 815
816 816 if (addr != NULL) {
817 817 release_memory(addr, bytes);
818 818 }
819 819
820 820 return addr != NULL;
821 821 #endif // AMD64
822 822 }
823 823
824 824 ////////////////////////////////////////////////////////////////////////////////
825 825 // thread stack
826 826
827 827 #ifdef AMD64
828 828 size_t os::Bsd::min_stack_allowed = 64 * K;
829 829
830 830 // amd64: pthread on amd64 is always in floating stack mode
831 831 bool os::Bsd::supports_variable_stack_size() { return true; }
832 832 #else
833 833 size_t os::Bsd::min_stack_allowed = (48 DEBUG_ONLY(+4))*K;
834 834
835 835 #ifdef __GNUC__
836 836 #define GET_GS() ({int gs; __asm__ volatile("movw %%gs, %w0":"=q"(gs)); gs&0xffff;})
837 837 #endif
838 838
839 839 #ifdef _ALLBSD_SOURCE
840 840 bool os::Bsd::supports_variable_stack_size() { return true; }
841 841 #else
842 842 // Test if pthread library can support variable thread stack size. BsdThreads
843 843 // in fixed stack mode allocates 2M fixed slot for each thread. BsdThreads
844 844 // in floating stack mode and NPTL support variable stack size.
845 845 bool os::Bsd::supports_variable_stack_size() {
846 846 if (os::Bsd::is_NPTL()) {
847 847 // NPTL, yes
848 848 return true;
849 849
850 850 } else {
851 851 // Note: We can't control default stack size when creating a thread.
852 852 // If we use non-default stack size (pthread_attr_setstacksize), both
853 853 // floating stack and non-floating stack BsdThreads will return the
854 854 // same value. This makes it impossible to implement this function by
855 855 // detecting thread stack size directly.
856 856 //
857 857 // An alternative approach is to check %gs. Fixed-stack BsdThreads
858 858 // do not use %gs, so its value is 0. Floating-stack BsdThreads use
859 859 // %gs (either as LDT selector or GDT selector, depending on kernel)
860 860 // to access thread specific data.
861 861 //
862 862 // Note that %gs is a reserved glibc register since early 2001, so
863 863 // applications are not allowed to change its value (Ulrich Drepper from
864 864 // Redhat confirmed that all known offenders have been modified to use
865 865 // either %fs or TSD). In the worst case scenario, when VM is embedded in
866 866 // a native application that plays with %gs, we might see non-zero %gs
867 867 // even BsdThreads is running in fixed stack mode. As the result, we'll
868 868 // return true and skip _thread_safety_check(), so we may not be able to
869 869 // detect stack-heap collisions. But otherwise it's harmless.
870 870 //
871 871 #ifdef __GNUC__
872 872 return (GET_GS() != 0);
873 873 #else
874 874 return false;
875 875 #endif
876 876 }
877 877 }
878 878 #endif
879 879 #endif // AMD64
880 880
881 881 // return default stack size for thr_type
882 882 size_t os::Bsd::default_stack_size(os::ThreadType thr_type) {
883 883 // default stack size (compiler thread needs larger stack)
884 884 #ifdef AMD64
885 885 size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
886 886 #else
887 887 size_t s = (thr_type == os::compiler_thread ? 2 * M : 512 * K);
888 888 #endif // AMD64
889 889 return s;
890 890 }
891 891
892 892 size_t os::Bsd::default_guard_size(os::ThreadType thr_type) {
893 893 // Creating guard page is very expensive. Java thread has HotSpot
894 894 // guard page, only enable glibc guard page for non-Java threads.
895 895 return (thr_type == java_thread ? 0 : page_size());
896 896 }
897 897
898 898 // Java thread:
899 899 //
900 900 // Low memory addresses
901 901 // +------------------------+
902 902 // | |\ JavaThread created by VM does not have glibc
903 903 // | glibc guard page | - guard, attached Java thread usually has
904 904 // | |/ 1 page glibc guard.
905 905 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
906 906 // | |\
907 907 // | HotSpot Guard Pages | - red and yellow pages
908 908 // | |/
909 909 // +------------------------+ JavaThread::stack_yellow_zone_base()
910 910 // | |\
911 911 // | Normal Stack | -
912 912 // | |/
913 913 // P2 +------------------------+ Thread::stack_base()
914 914 //
915 915 // Non-Java thread:
916 916 //
917 917 // Low memory addresses
918 918 // +------------------------+
919 919 // | |\
920 920 // | glibc guard page | - usually 1 page
921 921 // | |/
922 922 // P1 +------------------------+ Thread::stack_base() - Thread::stack_size()
923 923 // | |\
924 924 // | Normal Stack | -
925 925 // | |/
926 926 // P2 +------------------------+ Thread::stack_base()
927 927 //
928 928 // ** P1 (aka bottom) and size ( P2 = P1 - size) are the address and stack size returned from
929 929 // pthread_attr_getstack()
930 930
931 931 static void current_stack_region(address * bottom, size_t * size) {
932 932 #ifdef __APPLE__
933 933 pthread_t self = pthread_self();
934 934 void *stacktop = pthread_get_stackaddr_np(self);
935 935 *size = pthread_get_stacksize_np(self);
936 936 *bottom = (address) stacktop - *size;
937 937 #elif defined(__OpenBSD__)
938 938 stack_t ss;
939 939 int rslt = pthread_stackseg_np(pthread_self(), &ss);
940 940
941 941 if (rslt != 0)
942 942 fatal(err_msg("pthread_stackseg_np failed with err = %d", rslt));
943 943
944 944 *bottom = (address)((char *)ss.ss_sp - ss.ss_size);
945 945 *size = ss.ss_size;
946 946 #elif defined(_ALLBSD_SOURCE)
947 947 pthread_attr_t attr;
948 948
949 949 int rslt = pthread_attr_init(&attr);
950 950
951 951 // JVM needs to know exact stack location, abort if it fails
952 952 if (rslt != 0)
953 953 fatal(err_msg("pthread_attr_init failed with err = %d", rslt));
954 954
955 955 rslt = pthread_attr_get_np(pthread_self(), &attr);
956 956
957 957 if (rslt != 0)
958 958 fatal(err_msg("pthread_attr_get_np failed with err = %d", rslt));
959 959
960 960 if (pthread_attr_getstackaddr(&attr, (void **)bottom) != 0 ||
961 961 pthread_attr_getstacksize(&attr, size) != 0) {
962 962 fatal("Can not locate current stack attributes!");
963 963 }
964 964
965 965 pthread_attr_destroy(&attr);
966 966 #else
967 967 if (os::Bsd::is_initial_thread()) {
968 968 // initial thread needs special handling because pthread_getattr_np()
969 969 // may return bogus value.
970 970 *bottom = os::Bsd::initial_thread_stack_bottom();
971 971 *size = os::Bsd::initial_thread_stack_size();
972 972 } else {
973 973 pthread_attr_t attr;
974 974
975 975 int rslt = pthread_getattr_np(pthread_self(), &attr);
976 976
977 977 // JVM needs to know exact stack location, abort if it fails
978 978 if (rslt != 0) {
979 979 if (rslt == ENOMEM) {
980 980 vm_exit_out_of_memory(0, "pthread_getattr_np");
981 981 } else {
982 982 fatal(err_msg("pthread_getattr_np failed with errno = %d", rslt));
983 983 }
984 984 }
985 985
986 986 if (pthread_attr_getstack(&attr, (void **)bottom, size) != 0) {
987 987 fatal("Can not locate current stack attributes!");
988 988 }
989 989
990 990 pthread_attr_destroy(&attr);
991 991
992 992 }
993 993 #endif
994 994 assert(os::current_stack_pointer() >= *bottom &&
995 995 os::current_stack_pointer() < *bottom + *size, "just checking");
996 996 }
997 997
998 998 address os::current_stack_base() {
999 999 address bottom;
1000 1000 size_t size;
1001 1001 current_stack_region(&bottom, &size);
1002 1002 return (bottom + size);
1003 1003 }
1004 1004
1005 1005 size_t os::current_stack_size() {
1006 1006 // stack size includes normal stack and HotSpot guard pages
1007 1007 address bottom;
1008 1008 size_t size;
1009 1009 current_stack_region(&bottom, &size);
1010 1010 return size;
1011 1011 }
1012 1012
1013 1013 /////////////////////////////////////////////////////////////////////////////
1014 1014 // helper functions for fatal error handler
1015 1015
1016 1016 void os::print_context(outputStream *st, void *context) {
1017 1017 if (context == NULL) return;
1018 1018
1019 1019 ucontext_t *uc = (ucontext_t*)context;
1020 1020 st->print_cr("Registers:");
1021 1021 #ifdef AMD64
1022 1022 st->print( "RAX=" INTPTR_FORMAT, uc->context_rax);
1023 1023 st->print(", RBX=" INTPTR_FORMAT, uc->context_rbx);
1024 1024 st->print(", RCX=" INTPTR_FORMAT, uc->context_rcx);
1025 1025 st->print(", RDX=" INTPTR_FORMAT, uc->context_rdx);
1026 1026 st->cr();
1027 1027 st->print( "RSP=" INTPTR_FORMAT, uc->context_rsp);
1028 1028 st->print(", RBP=" INTPTR_FORMAT, uc->context_rbp);
1029 1029 st->print(", RSI=" INTPTR_FORMAT, uc->context_rsi);
1030 1030 st->print(", RDI=" INTPTR_FORMAT, uc->context_rdi);
1031 1031 st->cr();
1032 1032 st->print( "R8 =" INTPTR_FORMAT, uc->context_r8);
1033 1033 st->print(", R9 =" INTPTR_FORMAT, uc->context_r9);
1034 1034 st->print(", R10=" INTPTR_FORMAT, uc->context_r10);
1035 1035 st->print(", R11=" INTPTR_FORMAT, uc->context_r11);
1036 1036 st->cr();
1037 1037 st->print( "R12=" INTPTR_FORMAT, uc->context_r12);
1038 1038 st->print(", R13=" INTPTR_FORMAT, uc->context_r13);
1039 1039 st->print(", R14=" INTPTR_FORMAT, uc->context_r14);
1040 1040 st->print(", R15=" INTPTR_FORMAT, uc->context_r15);
1041 1041 st->cr();
1042 1042 st->print( "RIP=" INTPTR_FORMAT, uc->context_rip);
1043 1043 st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_flags);
1044 1044 st->print(", ERR=" INTPTR_FORMAT, uc->context_err);
1045 1045 st->cr();
1046 1046 st->print(" TRAPNO=" INTPTR_FORMAT, uc->context_trapno);
1047 1047 #else
1048 1048 st->print( "EAX=" INTPTR_FORMAT, uc->context_eax);
1049 1049 st->print(", EBX=" INTPTR_FORMAT, uc->context_ebx);
1050 1050 st->print(", ECX=" INTPTR_FORMAT, uc->context_ecx);
1051 1051 st->print(", EDX=" INTPTR_FORMAT, uc->context_edx);
1052 1052 st->cr();
1053 1053 st->print( "ESP=" INTPTR_FORMAT, uc->context_esp);
1054 1054 st->print(", EBP=" INTPTR_FORMAT, uc->context_ebp);
1055 1055 st->print(", ESI=" INTPTR_FORMAT, uc->context_esi);
1056 1056 st->print(", EDI=" INTPTR_FORMAT, uc->context_edi);
1057 1057 st->cr();
1058 1058 st->print( "EIP=" INTPTR_FORMAT, uc->context_eip);
1059 1059 st->print(", EFLAGS=" INTPTR_FORMAT, uc->context_eflags);
1060 1060 #endif // AMD64
1061 1061 st->cr();
1062 1062 st->cr();
1063 1063
1064 1064 intptr_t *sp = (intptr_t *)os::Bsd::ucontext_get_sp(uc);
1065 1065 st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
1066 1066 print_hex_dump(st, (address)sp, (address)(sp + 8*sizeof(intptr_t)), sizeof(intptr_t));
1067 1067 st->cr();
1068 1068
1069 1069 // Note: it may be unsafe to inspect memory near pc. For example, pc may
1070 1070 // point to garbage if entry point in an nmethod is corrupted. Leave
1071 1071 // this at the end, and hope for the best.
1072 1072 address pc = os::Bsd::ucontext_get_pc(uc);
1073 1073 st->print_cr("Instructions: (pc=" PTR_FORMAT ")", pc);
1074 1074 print_hex_dump(st, pc - 32, pc + 32, sizeof(char));
1075 1075 }
1076 1076
1077 1077 void os::print_register_info(outputStream *st, void *context) {
1078 1078 if (context == NULL) return;
1079 1079
1080 1080 ucontext_t *uc = (ucontext_t*)context;
1081 1081
1082 1082 st->print_cr("Register to memory mapping:");
1083 1083 st->cr();
1084 1084
1085 1085 // this is horrendously verbose but the layout of the registers in the
1086 1086 // context does not match how we defined our abstract Register set, so
1087 1087 // we can't just iterate through the gregs area
1088 1088
1089 1089 // this is only for the "general purpose" registers
1090 1090
1091 1091 #ifdef AMD64
1092 1092 st->print("RAX="); print_location(st, uc->context_rax);
1093 1093 st->print("RBX="); print_location(st, uc->context_rbx);
1094 1094 st->print("RCX="); print_location(st, uc->context_rcx);
1095 1095 st->print("RDX="); print_location(st, uc->context_rdx);
1096 1096 st->print("RSP="); print_location(st, uc->context_rsp);
1097 1097 st->print("RBP="); print_location(st, uc->context_rbp);
1098 1098 st->print("RSI="); print_location(st, uc->context_rsi);
1099 1099 st->print("RDI="); print_location(st, uc->context_rdi);
1100 1100 st->print("R8 ="); print_location(st, uc->context_r8);
1101 1101 st->print("R9 ="); print_location(st, uc->context_r9);
1102 1102 st->print("R10="); print_location(st, uc->context_r10);
1103 1103 st->print("R11="); print_location(st, uc->context_r11);
1104 1104 st->print("R12="); print_location(st, uc->context_r12);
1105 1105 st->print("R13="); print_location(st, uc->context_r13);
1106 1106 st->print("R14="); print_location(st, uc->context_r14);
1107 1107 st->print("R15="); print_location(st, uc->context_r15);
1108 1108 #else
1109 1109 st->print("EAX="); print_location(st, uc->context_eax);
1110 1110 st->print("EBX="); print_location(st, uc->context_ebx);
1111 1111 st->print("ECX="); print_location(st, uc->context_ecx);
1112 1112 st->print("EDX="); print_location(st, uc->context_edx);
1113 1113 st->print("ESP="); print_location(st, uc->context_esp);
1114 1114 st->print("EBP="); print_location(st, uc->context_ebp);
1115 1115 st->print("ESI="); print_location(st, uc->context_esi);
1116 1116 st->print("EDI="); print_location(st, uc->context_edi);
1117 1117 #endif // AMD64
1118 1118
1119 1119 st->cr();
1120 1120 }
1121 1121
1122 1122 void os::setup_fpu() {
1123 1123 #ifndef AMD64
1124 1124 address fpu_cntrl = StubRoutines::addr_fpu_cntrl_wrd_std();
1125 1125 __asm__ volatile ( "fldcw (%0)" :
1126 1126 : "r" (fpu_cntrl) : "memory");
1127 1127 #endif // !AMD64
1128 1128 }
↓ open down ↓ |
753 lines elided |
↑ open up ↑ |
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX