src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp

Tue, 08 Aug 2017 15:57:29 +0800

author
aoqi
date
Tue, 08 Aug 2017 15:57:29 +0800
changeset 6876
710a3c8b516e
parent 6683
7f77d17d0f13
parent 0
f90c822e73f8
child 7535
7ae4e26cb1e0
permissions
-rw-r--r--

merge

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

mercurial