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