src/os_cpu/linux_sparc/vm/os_linux_sparc.cpp

Tue, 30 Apr 2013 11:56:52 -0700

author
ccheung
date
Tue, 30 Apr 2013 11:56:52 -0700
changeset 4993
746b070f5022
parent 4710
9058789475af
child 5400
980532a806a5
child 5424
5e3b6f79d280
permissions
-rw-r--r--

8011661: Insufficient memory message says "malloc" when sometimes it should say "mmap"
Reviewed-by: coleenp, zgu, hseigel

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

mercurial