jdk

Форк
0
/
os_linux_s390.cpp 
494 строки · 17.6 Кб
1
/*
2
 * Copyright (c) 2016, 2024, Oracle and/or its affiliates. All rights reserved.
3
 * Copyright (c) 2016, 2023 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
// This file is organized as os_linux_x86.cpp.
27

28
// no precompiled headers
29
#include "asm/assembler.inline.hpp"
30
#include "classfile/vmSymbols.hpp"
31
#include "code/nativeInst.hpp"
32
#include "code/vtableStubs.hpp"
33
#include "compiler/disassembler.hpp"
34
#include "interpreter/interpreter.hpp"
35
#include "jvm.h"
36
#include "memory/allocation.inline.hpp"
37
#include "nativeInst_s390.hpp"
38
#include "os_linux.hpp"
39
#include "os_posix.hpp"
40
#include "prims/jniFastGetField.hpp"
41
#include "prims/jvm_misc.hpp"
42
#include "runtime/arguments.hpp"
43
#include "runtime/frame.inline.hpp"
44
#include "runtime/interfaceSupport.inline.hpp"
45
#include "runtime/java.hpp"
46
#include "runtime/javaCalls.hpp"
47
#include "runtime/javaThread.hpp"
48
#include "runtime/mutexLocker.hpp"
49
#include "runtime/osThread.hpp"
50
#include "runtime/safepointMechanism.hpp"
51
#include "runtime/sharedRuntime.hpp"
52
#include "runtime/stubRoutines.hpp"
53
#include "runtime/timer.hpp"
54
#include "signals_posix.hpp"
55
#include "utilities/events.hpp"
56
#include "utilities/debug.hpp"
57
#include "utilities/vmError.hpp"
58

59
// put OS-includes here
60
# include <sys/types.h>
61
# include <sys/mman.h>
62
# include <pthread.h>
63
# include <signal.h>
64
# include <errno.h>
65
# include <dlfcn.h>
66
# include <stdlib.h>
67
# include <stdio.h>
68
# include <unistd.h>
69
# include <sys/resource.h>
70
# include <pthread.h>
71
# include <sys/stat.h>
72
# include <sys/time.h>
73
# include <sys/utsname.h>
74
# include <sys/socket.h>
75
# include <sys/wait.h>
76
# include <pwd.h>
77
# include <poll.h>
78
# include <ucontext.h>
79

80
address os::current_stack_pointer() {
81
  intptr_t* csp;
82

83
  // Inline assembly for `z_lgr regno(csp), Z_SP' (Z_SP = Z_R15):
84
  __asm__ __volatile__ ("lgr %0, 15":"=r"(csp):);
85

86
  assert(((uint64_t)csp & (frame::alignment_in_bytes-1)) == 0, "SP must be aligned");
87
  return (address) csp;
88
}
89

90
char* os::non_memory_address_word() {
91
  // Must never look like an address returned by reserve_memory,
92
  // even in its subfields (as defined by the CPU immediate fields,
93
  // if the CPU splits constants across multiple instructions).
94
  return (char*) -1;
95
}
96

97
// Frame information (pc, sp, fp) retrieved via ucontext
98
// always looks like a C-frame according to the frame
99
// conventions in frame_s390.hpp.
100
address os::Posix::ucontext_get_pc(const ucontext_t * uc) {
101
  return (address)uc->uc_mcontext.psw.addr;
102
}
103

104
void os::Posix::ucontext_set_pc(ucontext_t * uc, address pc) {
105
  uc->uc_mcontext.psw.addr = (unsigned long)pc;
106
}
107

108
static address ucontext_get_lr(const ucontext_t * uc) {
109
  return (address)uc->uc_mcontext.gregs[14/*LINK*/];
110
}
111

112
intptr_t* os::Linux::ucontext_get_sp(const ucontext_t * uc) {
113
  return (intptr_t*)uc->uc_mcontext.gregs[15/*REG_SP*/];
114
}
115

116
intptr_t* os::Linux::ucontext_get_fp(const ucontext_t * uc) {
117
  return nullptr;
118
}
119

120
address os::fetch_frame_from_context(const void* ucVoid,
121
                    intptr_t** ret_sp, intptr_t** ret_fp) {
122

123
  address epc;
124
  const ucontext_t* uc = (const ucontext_t*)ucVoid;
125

126
  if (uc != nullptr) {
127
    epc = os::Posix::ucontext_get_pc(uc);
128
    if (ret_sp) { *ret_sp = os::Linux::ucontext_get_sp(uc); }
129
    if (ret_fp) { *ret_fp = os::Linux::ucontext_get_fp(uc); }
130
  } else {
131
    epc = nullptr;
132
    if (ret_sp) { *ret_sp = (intptr_t *)nullptr; }
133
    if (ret_fp) { *ret_fp = (intptr_t *)nullptr; }
134
  }
135

136
  return epc;
137
}
138

139
frame os::fetch_frame_from_context(const void* ucVoid) {
140
  intptr_t* sp;
141
  intptr_t* fp;
142
  address epc = fetch_frame_from_context(ucVoid, &sp, &fp);
143
  return frame(sp, epc);
144
}
145

146
frame os::fetch_compiled_frame_from_context(const void* ucVoid) {
147
  const ucontext_t* uc = (const ucontext_t*)ucVoid;
148
  intptr_t* sp = os::Linux::ucontext_get_sp(uc);
149
  address lr = ucontext_get_lr(uc);
150
  return frame(sp, lr);
151
}
152

153
frame os::get_sender_for_C_frame(frame* fr) {
154
  if (*fr->sp() == 0) {
155
    // fr is the last C frame.
156
    return frame();
157
  }
158

159
  // If its not one of our frames, the return pc is saved at gpr14
160
  // stack slot. The call_stub stores the return_pc to the stack slot
161
  // of gpr10.
162
  if ((Interpreter::code() != nullptr && Interpreter::contains(fr->pc())) ||
163
      (CodeCache::contains(fr->pc()) && !StubRoutines::contains(fr->pc()))) {
164
    return frame(fr->sender_sp(), fr->sender_pc());
165
  } else {
166
    if (StubRoutines::contains(fr->pc())) {
167
      StubCodeDesc* desc = StubCodeDesc::desc_for(fr->pc());
168
      if (desc && !strcmp(desc->name(),"call_stub")) {
169
        return frame(fr->sender_sp(), fr->callstub_sender_pc());
170
      } else {
171
        return frame(fr->sender_sp(), fr->sender_pc());
172
      }
173
    } else {
174
      intptr_t* sender_sp = fr->sender_sp();
175
      address   sender_fp = (address)*sender_sp;
176
      ptrdiff_t entry_len = sender_fp - (address)sender_sp;
177
      if (entry_len < frame::z_abi_160_size) {
178
        return frame(sender_sp, fr->sender_pc());
179
      } else {
180
        return frame(sender_sp, fr->native_sender_pc());
181
      }
182
    }
183
  }
184
}
185

186
frame os::current_frame() {
187
  // Expected to return the stack pointer of this method.
188
  // But if inlined, returns the stack pointer of our caller!
189
  intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
190
  assert (csp != nullptr, "sp should not be null");
191
  // Pass a dummy pc. This way we don't have to load it from the
192
  // stack, since we don't know in which slot we can find it.
193
  frame topframe(csp, (address)0x8);
194
  if (os::is_first_C_frame(&topframe)) {
195
    // Stack is not walkable.
196
    return frame();
197
  } else {
198
    frame senderFrame = os::get_sender_for_C_frame(&topframe);
199
    assert(senderFrame.pc() != nullptr, "Sender pc should not be null");
200
    // Return sender of sender of current topframe which hopefully
201
    // both have pc != nullptr.
202
#ifdef _NMT_NOINLINE_   // Is set in slowdebug builds.
203
    // Current_stack_pointer is not inlined, we must pop one more frame.
204
    frame tmp = os::get_sender_for_C_frame(&topframe);
205
    return os::get_sender_for_C_frame(&tmp);
206
#else
207
    return os::get_sender_for_C_frame(&topframe);
208
#endif
209
  }
210
}
211

212
bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
213
                                             ucontext_t* uc, JavaThread* thread) {
214

215
  // Decide if this trap can be handled by a stub.
216
  address stub    = nullptr;
217
  address pc      = nullptr;  // Pc as retrieved from PSW. Usually points past failing instruction.
218
  address trap_pc = nullptr;  // Pc of the instruction causing the trap.
219

220
  //%note os_trap_1
221
  if (info != nullptr && uc != nullptr && thread != nullptr) {
222
    pc = os::Posix::ucontext_get_pc(uc);
223
    if (TraceTraps) {
224
      tty->print_cr("     pc at " INTPTR_FORMAT, p2i(pc));
225
    }
226
    if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
227
      trap_pc = (address)info->si_addr;
228
      if (TraceTraps) {
229
        tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
230
      }
231
    }
232

233
    // Handle ALL stack overflow variations here
234
    if (sig == SIGSEGV) {
235
      address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
236

237
      // Check if fault address is within thread stack.
238
      if (thread->is_in_full_stack(addr)) {
239
        // stack overflow
240
        if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {
241
          return true; // continue
242
        }
243
      }
244
    }
245

246
    if (thread->thread_state() == _thread_in_Java) {
247
      // Java thread running in Java code => find exception handler if any
248
      // a fault inside compiled code, the interpreter, or a stub
249

250
      // Handle signal from NativeJump::patch_verified_entry().
251
      if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_not_entrant()) {
252
        if (TraceTraps) {
253
          tty->print_cr("trap: not_entrant (SIGILL)");
254
        }
255
        stub = SharedRuntime::get_handle_wrong_method_stub();
256
      }
257

258
      else if (sig == SIGSEGV &&
259
               SafepointMechanism::is_poll_address((address)info->si_addr)) {
260
        if (TraceTraps) {
261
          tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
262
        }
263
        stub = SharedRuntime::get_poll_stub(pc);
264

265
        // Info->si_addr only points to the page base address, so we
266
        // must extract the real si_addr from the instruction and the
267
        // ucontext.
268
        assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");
269
        const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);
270
      }
271

272
      // SIGTRAP-based implicit null check in compiled code.
273
      else if ((sig == SIGFPE) &&
274
               TrapBasedNullChecks &&
275
               (trap_pc != nullptr) &&
276
               Assembler::is_sigtrap_zero_check(trap_pc)) {
277
        if (TraceTraps) {
278
          tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
279
        }
280
        stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
281
      }
282

283
      else if (sig == SIGSEGV && ImplicitNullChecks &&
284
               CodeCache::contains((void*) pc) &&
285
               MacroAssembler::uses_implicit_null_check(info->si_addr)) {
286
        if (TraceTraps) {
287
          tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
288
        }
289
        stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
290
      }
291

292
#ifdef COMPILER2
293
      // SIGTRAP-based implicit range check in compiled code.
294
      else if (sig == SIGFPE && TrapBasedRangeChecks &&
295
               (trap_pc != nullptr) &&
296
               Assembler::is_sigtrap_range_check(trap_pc)) {
297
        if (TraceTraps) {
298
          tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
299
        }
300
        stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
301
      }
302
#endif
303

304
      else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
305
        stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
306
      }
307

308
      else if (sig == SIGBUS) {
309
        // BugId 4454115: A read from a MappedByteBuffer can fault here if the
310
        // underlying file has been truncated. Do not crash the VM in such a case.
311
        CodeBlob* cb = CodeCache::find_blob(pc);
312
        nmethod* nm = (cb != nullptr) ? cb->as_nmethod_or_null() : nullptr;
313
        if (nm != nullptr && nm->has_unsafe_access()) {
314
          // We don't really need a stub here! Just set the pending exception and
315
          // continue at the next instruction after the faulting read. Returning
316
          // garbage from this read is ok.
317
          thread->set_pending_unsafe_access_error();
318
          uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);
319
          return true;
320
        }
321
      }
322
    }
323

324
    else { // thread->thread_state() != _thread_in_Java
325
      if ((sig == SIGILL) && VM_Version::is_determine_features_test_running()) {
326
        // SIGILL must be caused by VM_Version::determine_features()
327
        // when attempting to execute a non-existing instruction.
328
        //*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.
329
                             // Flushing of icache is not necessary.
330
        stub = pc; // Continue with next instruction.
331
      } else if ((sig == SIGFPE) && VM_Version::is_determine_features_test_running()) {
332
        // SIGFPE is known to be caused by trying to execute a vector instruction
333
        // when the vector facility is installed, but operating system support is missing.
334
        VM_Version::reset_has_VectorFacility();
335
        stub = pc; // Continue with next instruction.
336
      } else if ((thread->thread_state() == _thread_in_vm ||
337
                  thread->thread_state() == _thread_in_native) &&
338
                 sig == SIGBUS && thread->doing_unsafe_access()) {
339
        // We don't really need a stub here! Just set the pending exception and
340
        // continue at the next instruction after the faulting read. Returning
341
        // garbage from this read is ok.
342
        thread->set_pending_unsafe_access_error();
343
        os::Posix::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));
344
        return true;
345
      }
346
    }
347

348
    // jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
349
    // and the heap gets shrunk before the field access.
350
    if ((sig == SIGSEGV) || (sig == SIGBUS)) {
351
      address addr = JNI_FastGetField::find_slowcase_pc(pc);
352
      if (addr != (address)-1) {
353
        stub = addr;
354
      }
355
    }
356
  }
357

358
  if (stub != nullptr) {
359
    // Save all thread context in case we need to restore it.
360
    if (thread != nullptr) thread->set_saved_exception_pc(pc);
361
    os::Posix::ucontext_set_pc(uc, stub);
362
    return true;
363
  }
364

365
  return false;
366
}
367

368
void os::Linux::init_thread_fpu_state(void) {
369
  // Nothing to do on z/Architecture.
370
}
371

372
int os::Linux::get_fpu_control_word(void) {
373
  // Nothing to do on z/Architecture.
374
  return 0;
375
}
376

377
void os::Linux::set_fpu_control_word(int fpu_control) {
378
  // Nothing to do on z/Architecture.
379
}
380

381
////////////////////////////////////////////////////////////////////////////////
382
// thread stack
383

384
// Minimum usable stack sizes required to get to user code. Space for
385
// HotSpot guard pages is added later.
386
size_t os::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;
387
size_t os::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;
388
size_t os::_vm_internal_thread_min_stack_allowed = 32 * K;
389

390
// Return default stack size for thr_type.
391
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
392
  // Default stack size (compiler thread needs larger stack).
393
  size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
394
  return s;
395
}
396

397
/////////////////////////////////////////////////////////////////////////////
398
// helper functions for fatal error handler
399

400
void os::print_context(outputStream *st, const void *context) {
401
  if (context == nullptr) return;
402

403
  const ucontext_t* uc = (const ucontext_t*)context;
404

405
  st->print_cr("Processor state:");
406
  st->print_cr("----------------");
407
  st->print_cr("        ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);
408
  st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);
409
  st->print_cr("   fpc reg = 0x%8.8x "          , uc->uc_mcontext.fpregs.fpc);
410
  st->cr();
411

412
  st->print_cr("General Purpose Registers:");
413
  st->print_cr("--------------------------");
414
  for( int i = 0; i < 16; i+=2 ) {
415
    st->print("  r%-2d = " INTPTR_FORMAT "  " ,  i,   uc->uc_mcontext.gregs[i]);
416
    st->print("  r%-2d = " INTPTR_FORMAT "  |",  i+1, uc->uc_mcontext.gregs[i+1]);
417
    st->print("  r%-2d = %23.1ld  "           ,  i,   uc->uc_mcontext.gregs[i]);
418
    st->print("  r%-2d = %23.1ld  "           ,  i+1, uc->uc_mcontext.gregs[i+1]);
419
    st->cr();
420
  }
421
  st->cr();
422

423
  st->print_cr("Access Registers:");
424
  st->print_cr("-----------------");
425
  for( int i = 0; i < 16; i+=2 ) {
426
    st->print("  ar%-2d = 0x%8.8x  ", i,   uc->uc_mcontext.aregs[i]);
427
    st->print("  ar%-2d = 0x%8.8x  ", i+1, uc->uc_mcontext.aregs[i+1]);
428
    st->cr();
429
  }
430
  st->cr();
431

432
  st->print_cr("Float Registers:");
433
  st->print_cr("----------------");
434
  for (int i = 0; i < 16; i += 2) {
435
    st->print("  fr%-2d = " INTPTR_FORMAT "  " , i,   (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));
436
    st->print("  fr%-2d = " INTPTR_FORMAT "  |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));
437
    st->print("  fr%-2d = %23.15e  "           , i,   (uc->uc_mcontext.fpregs.fprs[i].d));
438
    st->print("  fr%-2d = %23.15e  "           , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));
439
    st->cr();
440
  }
441
  st->cr();
442
  st->cr();
443
}
444

445
void os::print_tos_pc(outputStream *st, const void *context) {
446
  if (context == nullptr) return;
447

448
  const ucontext_t* uc = (const ucontext_t*)context;
449

450
  address sp = (address)os::Linux::ucontext_get_sp(uc);
451
  print_tos(st, sp);
452
  st->cr();
453

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

462
void os::print_register_info(outputStream *st, const void *context, int& continuation) {
463
  const int register_count = 16 /* r0-r15 */ + 1 /* pc */;
464
  int n = continuation;
465
  assert(n >= 0 && n <= register_count, "Invalid continuation value");
466
  if (context == nullptr || n == register_count) {
467
    return;
468
  }
469

470
  const ucontext_t *uc = (const ucontext_t*)context;
471
  while (n < register_count) {
472
    // Update continuation with next index before printing location
473
    continuation = n + 1;
474
    if (n == register_count - 1) {
475
      st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.psw.addr);
476
    } else {
477
      st->print("r%-2d=", n);
478
      print_location(st, uc->uc_mcontext.gregs[n]);
479
    }
480
    ++n;
481
  }
482
}
483

484
#ifndef PRODUCT
485
void os::verify_stack_alignment() {
486
}
487
#endif
488

489
int os::extra_bang_size_in_bytes() {
490
  // z/Architecture does not require the additional stack bang.
491
  return 0;
492
}
493

494
void os::setup_fpu() {}
495

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

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

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

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