jdk

Форк
0
/
os_aix_ppc.cpp 
526 строк · 18.9 Кб
1
/*
2
 * Copyright (c) 1997, 2024, Oracle and/or its affiliates. All rights reserved.
3
 * Copyright (c) 2012, 2024 SAP SE. All rights reserved.
4
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5
 *
6
 * This code is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU General Public License version 2 only, as
8
 * published by the Free Software Foundation.
9
 *
10
 * This code is distributed in the hope that it will be useful, but WITHOUT
11
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
13
 * version 2 for more details (a copy is included in the LICENSE file that
14
 * accompanied this code).
15
 *
16
 * You should have received a copy of the GNU General Public License version
17
 * 2 along with this work; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
19
 *
20
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
21
 * or visit www.oracle.com if you need additional information or have any
22
 * questions.
23
 *
24
 */
25

26
// no precompiled headers
27
#include "assembler_ppc.hpp"
28
#include "asm/assembler.inline.hpp"
29
#include "classfile/vmSymbols.hpp"
30
#include "code/codeCache.hpp"
31
#include "code/vtableStubs.hpp"
32
#include "interpreter/interpreter.hpp"
33
#include "jvm.h"
34
#include "memory/allocation.inline.hpp"
35
#include "nativeInst_ppc.hpp"
36
#include "os_aix.hpp"
37
#include "os_posix.hpp"
38
#include "prims/jniFastGetField.hpp"
39
#include "prims/jvm_misc.hpp"
40
#include "porting_aix.hpp"
41
#include "runtime/arguments.hpp"
42
#include "runtime/frame.inline.hpp"
43
#include "runtime/interfaceSupport.inline.hpp"
44
#include "runtime/java.hpp"
45
#include "runtime/javaCalls.hpp"
46
#include "runtime/javaThread.hpp"
47
#include "runtime/mutexLocker.hpp"
48
#include "runtime/osThread.hpp"
49
#include "runtime/safepointMechanism.hpp"
50
#include "runtime/sharedRuntime.hpp"
51
#include "runtime/stubRoutines.hpp"
52
#include "runtime/timer.hpp"
53
#include "signals_posix.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
// put OS-includes here
64
# include <ucontext.h>
65

66
address os::current_stack_pointer() {
67
  return (address)__builtin_frame_address(0);
68
}
69

70
char* os::non_memory_address_word() {
71
  // Must never look like an address returned by reserve_memory,
72
  // even in its subfields (as defined by the CPU immediate fields,
73
  // if the CPU splits constants across multiple instructions).
74

75
  return (char*) -1;
76
}
77

78
// Frame information (pc, sp, fp) retrieved via ucontext
79
// always looks like a C-frame according to the frame
80
// conventions in frame_ppc.hpp.
81

82
address os::Posix::ucontext_get_pc(const ucontext_t * uc) {
83
  return (address)uc->uc_mcontext.jmp_context.iar;
84
}
85

86
intptr_t* os::Aix::ucontext_get_sp(const ucontext_t * uc) {
87
  // gpr1 holds the stack pointer on aix
88
  return (intptr_t*)uc->uc_mcontext.jmp_context.gpr[1/*REG_SP*/];
89
}
90

91
intptr_t* os::Aix::ucontext_get_fp(const ucontext_t * uc) {
92
  return nullptr;
93
}
94

95
void os::Posix::ucontext_set_pc(ucontext_t* uc, address new_pc) {
96
  uc->uc_mcontext.jmp_context.iar = (uint64_t) new_pc;
97
}
98

99
static address ucontext_get_lr(const ucontext_t * uc) {
100
  return (address)uc->uc_mcontext.jmp_context.lr;
101
}
102

103
address os::fetch_frame_from_context(const void* ucVoid,
104
                                     intptr_t** ret_sp, intptr_t** ret_fp) {
105

106
  address epc;
107
  const ucontext_t* uc = (const ucontext_t*)ucVoid;
108

109
  if (uc != nullptr) {
110
    epc = os::Posix::ucontext_get_pc(uc);
111
    if (ret_sp) *ret_sp = os::Aix::ucontext_get_sp(uc);
112
    if (ret_fp) *ret_fp = os::Aix::ucontext_get_fp(uc);
113
  } else {
114
    epc = nullptr;
115
    if (ret_sp) *ret_sp = (intptr_t *)nullptr;
116
    if (ret_fp) *ret_fp = (intptr_t *)nullptr;
117
  }
118

119
  return epc;
120
}
121

122
frame os::fetch_frame_from_context(const void* ucVoid) {
123
  intptr_t* sp;
124
  intptr_t* fp;
125
  address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
126
  // Avoid crash during crash if pc broken.
127
  if (epc) {
128
    frame fr(sp, epc, frame::kind::unknown);
129
    return fr;
130
  }
131
  frame fr(sp);
132
  return fr;
133
}
134

135
frame os::fetch_compiled_frame_from_context(const void* ucVoid) {
136
  const ucontext_t* uc = (const ucontext_t*)ucVoid;
137
  intptr_t* sp = os::Aix::ucontext_get_sp(uc);
138
  address lr = ucontext_get_lr(uc);
139
  return frame(sp, lr, frame::kind::unknown);
140
}
141

142
frame os::get_sender_for_C_frame(frame* fr) {
143
  if (*fr->sp() == (intptr_t) nullptr) {
144
    // fr is the last C frame
145
    return frame();
146
  }
147
  return frame(fr->sender_sp(), fr->sender_pc(), frame::kind::unknown);
148
}
149

150

151
frame os::current_frame() {
152
  intptr_t* csp = *(intptr_t**) __builtin_frame_address(0);
153
  frame topframe(csp, CAST_FROM_FN_PTR(address, os::current_frame), frame::kind::unknown);
154
  return os::get_sender_for_C_frame(&topframe);
155
}
156

157
bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
158
                                             ucontext_t* uc, JavaThread* thread) {
159

160
  // Decide if this trap can be handled by a stub.
161
  address stub = nullptr;
162

163
  // retrieve program counter
164
  address const pc = uc ? os::Posix::ucontext_get_pc(uc) : nullptr;
165

166
  // retrieve crash address
167
  address const addr = info ? (const address) info->si_addr : nullptr;
168

169
  if (info == nullptr || uc == nullptr) {
170
    return false; // Fatal error
171
  }
172

173
  // If we are a java thread...
174
  if (thread != nullptr) {
175

176
    // Handle ALL stack overflow variations here
177
    if (sig == SIGSEGV && thread->is_in_full_stack(addr)) {
178
      // stack overflow
179
      if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {
180
        return true; // continue
181
      } else if (stub != nullptr) {
182
        goto run_stub;
183
      } else {
184
        return false; // Fatal error
185
      }
186
    } // end handle SIGSEGV inside stack boundaries
187

188
    if (thread->thread_state() == _thread_in_Java) {
189
      // Java thread running in Java code
190

191
      // The following signals are used for communicating VM events:
192
      //
193
      // SIGILL: the compiler generates illegal opcodes
194
      //   at places where it wishes to interrupt the VM:
195
      //   Safepoints, Unreachable Code, Entry points of not entrant nmethods,
196
      //    This results in a SIGILL with (*pc) == inserted illegal instruction.
197
      //
198
      //   (so, SIGILLs with a pc inside the zero page are real errors)
199
      //
200
      // SIGTRAP:
201
      //   The ppc trap instruction raises a SIGTRAP and is very efficient if it
202
      //   does not trap. It is used for conditional branches that are expected
203
      //   to be never taken. These are:
204
      //     - not entrant nmethods
205
      //     - IC (inline cache) misses.
206
      //     - null checks leading to UncommonTraps.
207
      //     - range checks leading to Uncommon Traps.
208
      //   On Aix, these are especially null checks, as the ImplicitNullCheck
209
      //   optimization works only in rare cases, as the page at address 0 is only
210
      //   write protected.      //
211
      //   Note: !UseSIGTRAP is used to prevent SIGTRAPS altogether, to facilitate debugging.
212
      //
213
      // SIGSEGV:
214
      //   used for safe point polling:
215
      //     To notify all threads that they have to reach a safe point, safe point polling is used:
216
      //     All threads poll a certain mapped memory page. Normally, this page has read access.
217
      //     If the VM wants to inform the threads about impending safe points, it puts this
218
      //     page to read only ("poisens" the page), and the threads then reach a safe point.
219
      //   used for null checks:
220
      //     If the compiler finds a store it uses it for a null check. Unfortunately this
221
      //     happens rarely.  In heap based and disjoint base compressd oop modes also loads
222
      //     are used for null checks.
223

224
      CodeBlob *cb = nullptr;
225
      int stop_type = -1;
226
      // Handle signal from NativeJump::patch_verified_entry().
227
      if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_not_entrant()) {
228
        if (TraceTraps) {
229
          tty->print_cr("trap: not_entrant");
230
        }
231
        stub = SharedRuntime::get_handle_wrong_method_stub();
232
        goto run_stub;
233
      }
234

235
      else if ((sig == (USE_POLL_BIT_ONLY ? SIGTRAP : SIGSEGV)) &&
236
               ((NativeInstruction*)pc)->is_safepoint_poll() &&
237
               CodeCache::contains((void*) pc) &&
238
               ((cb = CodeCache::find_blob(pc)) != nullptr) &&
239
               cb->is_nmethod()) {
240
        if (TraceTraps) {
241
          tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (%s)", p2i(pc),
242
                        USE_POLL_BIT_ONLY ? "SIGTRAP" : "SIGSEGV");
243
        }
244
        stub = SharedRuntime::get_poll_stub(pc);
245
        goto run_stub;
246
      }
247

248
      else if (UseSIGTRAP && sig == SIGTRAP &&
249
               ((NativeInstruction*)pc)->is_safepoint_poll_return() &&
250
               CodeCache::contains((void*) pc) &&
251
               ((cb = CodeCache::find_blob(pc)) != nullptr) &&
252
               cb->is_nmethod()) {
253
        if (TraceTraps) {
254
          tty->print_cr("trap: safepoint_poll at return at " INTPTR_FORMAT " (nmethod)", p2i(pc));
255
        }
256
        stub = SharedRuntime::polling_page_return_handler_blob()->entry_point();
257
        goto run_stub;
258
      }
259

260
      // SIGTRAP-based ic miss check in compiled code.
261
      else if (sig == SIGTRAP && TrapBasedICMissChecks &&
262
               nativeInstruction_at(pc)->is_sigtrap_ic_miss_check()) {
263
        if (TraceTraps) {
264
          tty->print_cr("trap: ic_miss_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
265
        }
266
        stub = SharedRuntime::get_ic_miss_stub();
267
        goto run_stub;
268
      }
269

270
      // SIGTRAP-based implicit null check in compiled code.
271
      else if (sig == SIGTRAP && TrapBasedNullChecks &&
272
               nativeInstruction_at(pc)->is_sigtrap_null_check()) {
273
        if (TraceTraps) {
274
          tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
275
        }
276
        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
277
        goto run_stub;
278
      }
279

280
      // SIGSEGV-based implicit null check in compiled code.
281
      else if (sig == SIGSEGV && ImplicitNullChecks &&
282
               CodeCache::contains((void*) pc) &&
283
               MacroAssembler::uses_implicit_null_check(info->si_addr)) {
284
        if (TraceTraps) {
285
          tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
286
        }
287
        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
288
      }
289

290
#ifdef COMPILER2
291
      // SIGTRAP-based implicit range check in compiled code.
292
      else if (sig == SIGTRAP && TrapBasedRangeChecks &&
293
               nativeInstruction_at(pc)->is_sigtrap_range_check()) {
294
        if (TraceTraps) {
295
          tty->print_cr("trap: range_check at " INTPTR_FORMAT " (SIGTRAP)", p2i(pc));
296
        }
297
        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
298
        goto run_stub;
299
      }
300
#endif
301

302
      else if (sig == SIGFPE /* && info->si_code == FPE_INTDIV */) {
303
        if (TraceTraps) {
304
          tty->print_raw_cr("Fix SIGFPE handler, trying divide by zero handler.");
305
        }
306
        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
307
        goto run_stub;
308
      }
309

310
      // stop on request
311
      else if (sig == SIGTRAP && (stop_type = nativeInstruction_at(pc)->get_stop_type()) != -1) {
312
        bool msg_present = (stop_type & MacroAssembler::stop_msg_present);
313
        stop_type = (stop_type &~ MacroAssembler::stop_msg_present);
314

315
        const char *msg = nullptr;
316
        switch (stop_type) {
317
          case MacroAssembler::stop_stop              : msg = "stop"; break;
318
          case MacroAssembler::stop_untested          : msg = "untested"; break;
319
          case MacroAssembler::stop_unimplemented     : msg = "unimplemented"; break;
320
          case MacroAssembler::stop_shouldnotreachhere: msg = "shouldnotreachhere"; break;
321
          default: msg = "unknown"; break;
322
        }
323

324
        const char **detail_msg_ptr = (const char**)(pc + 4);
325
        const char *detail_msg = msg_present ? *detail_msg_ptr : "no details provided";
326

327
        if (TraceTraps) {
328
          tty->print_cr("trap: %s: %s (SIGTRAP, stop type %d)", msg, detail_msg, stop_type);
329
        }
330

331
        // End life with a fatal error, message and detail message and the context.
332
        // Note: no need to do any post-processing here (e.g. signal chaining)
333
        VMError::report_and_die(thread, uc, nullptr, 0, msg, "%s", detail_msg);
334

335
        ShouldNotReachHere();
336
      }
337

338
      else if (sig == SIGBUS) {
339
        // BugId 4454115: A read from a MappedByteBuffer can fault here if the
340
        // underlying file has been truncated. Do not crash the VM in such a case.
341
        CodeBlob* cb = CodeCache::find_blob(pc);
342
        nmethod* nm = cb ? cb->as_nmethod_or_null() : nullptr;
343
        bool is_unsafe_memory_access = (thread->doing_unsafe_access() && UnsafeMemoryAccess::contains_pc(pc));
344
        if ((nm != nullptr && nm->has_unsafe_access()) || is_unsafe_memory_access) {
345
          address next_pc = pc + 4;
346
          if (is_unsafe_memory_access) {
347
            next_pc = UnsafeMemoryAccess::page_error_continue_pc(pc);
348
          }
349
          next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
350
          os::Posix::ucontext_set_pc(uc, next_pc);
351
          return true;
352
        }
353
      }
354
    }
355

356
    else { // thread->thread_state() != _thread_in_Java
357
      // Detect CPU features. This is only done at the very start of the VM. Later, the
358
      // VM_Version::is_determine_features_test_running() flag should be false.
359

360
      if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
361
        // SIGILL must be caused by VM_Version::determine_features().
362
        *(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,
363
                        // flushing of icache is not necessary.
364
        stub = pc + 4;  // continue with next instruction.
365
        goto run_stub;
366
      }
367
      else if ((thread->thread_state() == _thread_in_vm ||
368
                thread->thread_state() == _thread_in_native) &&
369
               sig == SIGBUS && thread->doing_unsafe_access()) {
370
        address next_pc = pc + 4;
371
        if (UnsafeMemoryAccess::contains_pc(pc)) {
372
          next_pc = UnsafeMemoryAccess::page_error_continue_pc(pc);
373
        }
374
        next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
375
        os::Posix::ucontext_set_pc(uc, next_pc);
376
        return true;
377
      }
378
    }
379

380
    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
381
    // and the heap gets shrunk before the field access.
382
    if ((sig == SIGSEGV) || (sig == SIGBUS)) {
383
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
384
      if (addr != (address)-1) {
385
        stub = addr;
386
      }
387
    }
388
  }
389

390
run_stub:
391

392
  // One of the above code blocks ininitalized the stub, so we want to
393
  // delegate control to that stub.
394
  if (stub != nullptr) {
395
    // Save all thread context in case we need to restore it.
396
    if (thread != nullptr) thread->set_saved_exception_pc(pc);
397
    os::Posix::ucontext_set_pc(uc, stub);
398
    return true;
399
  }
400

401
  return false; // Fatal error
402
}
403

404
void os::Aix::init_thread_fpu_state(void) {
405
#if !defined(USE_XLC_BUILTINS)
406
  // Disable FP exceptions.
407
  __asm__ __volatile__ ("mtfsfi 6,0");
408
#else
409
  __mtfsfi(6, 0);
410
#endif
411
}
412

413
////////////////////////////////////////////////////////////////////////////////
414
// thread stack
415

416
// Minimum usable stack sizes required to get to user code. Space for
417
// HotSpot guard pages is added later.
418
size_t os::_compiler_thread_min_stack_allowed = 192 * K;
419
size_t os::_java_thread_min_stack_allowed = 64 * K;
420
size_t os::_vm_internal_thread_min_stack_allowed = 64 * K;
421

422
// Return default stack size for thr_type.
423
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
424
  // Default stack size (compiler thread needs larger stack).
425
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
426
  return s;
427
}
428

429
/////////////////////////////////////////////////////////////////////////////
430
// helper functions for fatal error handler
431

432
void os::print_context(outputStream *st, const void *context) {
433
  if (context == nullptr) return;
434

435
  const ucontext_t* uc = (const ucontext_t*)context;
436

437
  st->print_cr("Registers:");
438
  st->print("pc =" INTPTR_FORMAT "  ", (unsigned long)uc->uc_mcontext.jmp_context.iar);
439
  st->print("lr =" INTPTR_FORMAT "  ", (unsigned long)uc->uc_mcontext.jmp_context.lr);
440
  st->print("ctr=" INTPTR_FORMAT "  ", (unsigned long)uc->uc_mcontext.jmp_context.ctr);
441
  st->cr();
442
  for (int i = 0; i < 32; i++) {
443
    st->print("r%-2d=" INTPTR_FORMAT "  ", i, (unsigned long)uc->uc_mcontext.jmp_context.gpr[i]);
444
    if (i % 3 == 2) st->cr();
445
  }
446
  st->cr();
447
  st->cr();
448
}
449

450
void os::print_tos_pc(outputStream *st, const void *context) {
451
  if (context == nullptr) return;
452

453
  const ucontext_t* uc = (const ucontext_t*)context;
454

455
  address sp = (address)os::Aix::ucontext_get_sp(uc);
456
  print_tos(st, sp);
457
  st->cr();
458

459
  // Note: it may be unsafe to inspect memory near pc. For example, pc may
460
  // point to garbage if entry point in an nmethod is corrupted. Leave
461
  // this at the end, and hope for the best.
462
  address pc = os::Posix::ucontext_get_pc(uc);
463
  print_instructions(st, pc);
464
  st->cr();
465

466
  // Try to decode the instructions.
467
  st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", p2i(pc));
468
  st->print("<TODO: PPC port - print_context>");
469
  // TODO: PPC port Disassembler::decode(pc, 16, 16, st);
470
  st->cr();
471
}
472

473
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
474
  const int register_count = 32 /* r0-r32 */ + 3 /* pc, lr, sp */;
475
  int n = continuation;
476
  assert(n >= 0 && n <= register_count, "Invalid continuation value");
477
  if (context == nullptr || n == register_count) {
478
    return;
479
  }
480

481
  const ucontext_t *uc = (const ucontext_t*)context;
482
  while (n < register_count) {
483
    // Update continuation with next index before printing location
484
    continuation = n + 1;
485
    if (n == register_count - 1) {
486
      st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.iar);
487
    } else if (n == register_count - 2) {
488
      st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.lr);
489
    } else if (n == register_count - 3) {
490
      st->print("sp ="); print_location(st, (intptr_t)os::Aix::ucontext_get_sp(uc));
491
    } else {
492
      st->print("r%-2d=", n);
493
      print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.gpr[n]);
494
    }
495
    ++n;
496
  }
497
}
498

499
extern "C" {
500
  int SpinPause() {
501
    return 0;
502
  }
503
}
504

505
#ifndef PRODUCT
506
void os::verify_stack_alignment() {
507
  assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
508
}
509
#endif
510

511
int os::extra_bang_size_in_bytes() {
512
  // PPC does not require the additional stack bang.
513
  return 0;
514
}
515

516
bool os::Aix::platform_print_native_stack(outputStream* st, const void* context, char *buf, int buf_size, address& lastpc) {
517
  AixNativeCallstack::print_callstack_for_context(st, (const ucontext_t*)context, true, buf, (size_t) buf_size);
518
  return true;
519
}
520

521
// HAVE_FUNCTION_DESCRIPTORS
522
void* os::Aix::resolve_function_descriptor(void* p) {
523
  return ((const FunctionDescriptor*)p)->entry();
524
}
525

526
void os::setup_fpu() {}
527

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.