Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os_cpu/linux_s390/os_linux_s390.cpp
40951 views
1
/*
2
* Copyright (c) 2016, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2016, 2019 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 "jvm.h"
30
#include "asm/assembler.inline.hpp"
31
#include "classfile/vmSymbols.hpp"
32
#include "code/icBuffer.hpp"
33
#include "code/nativeInst.hpp"
34
#include "code/vtableStubs.hpp"
35
#include "compiler/disassembler.hpp"
36
#include "interpreter/interpreter.hpp"
37
#include "memory/allocation.inline.hpp"
38
#include "nativeInst_s390.hpp"
39
#include "os_share_linux.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/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/thread.inline.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 NULL;
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 != NULL) {
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 = NULL;
132
if (ret_sp) { *ret_sp = (intptr_t *)NULL; }
133
if (ret_fp) { *ret_fp = (intptr_t *)NULL; }
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() != NULL && 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
return frame(fr->sender_sp(), fr->native_sender_pc());
175
}
176
}
177
}
178
179
frame os::current_frame() {
180
// Expected to return the stack pointer of this method.
181
// But if inlined, returns the stack pointer of our caller!
182
intptr_t* csp = (intptr_t*) *((intptr_t*) os::current_stack_pointer());
183
assert (csp != NULL, "sp should not be NULL");
184
// Pass a dummy pc. This way we don't have to load it from the
185
// stack, since we don't know in which slot we can find it.
186
frame topframe(csp, (address)0x8);
187
if (os::is_first_C_frame(&topframe)) {
188
// Stack is not walkable.
189
return frame();
190
} else {
191
frame senderFrame = os::get_sender_for_C_frame(&topframe);
192
assert(senderFrame.pc() != NULL, "Sender pc should not be NULL");
193
// Return sender of sender of current topframe which hopefully
194
// both have pc != NULL.
195
#ifdef _NMT_NOINLINE_ // Is set in slowdebug builds.
196
// Current_stack_pointer is not inlined, we must pop one more frame.
197
frame tmp = os::get_sender_for_C_frame(&topframe);
198
return os::get_sender_for_C_frame(&tmp);
199
#else
200
return os::get_sender_for_C_frame(&topframe);
201
#endif
202
}
203
}
204
205
bool PosixSignals::pd_hotspot_signal_handler(int sig, siginfo_t* info,
206
ucontext_t* uc, JavaThread* thread) {
207
208
// Decide if this trap can be handled by a stub.
209
address stub = NULL;
210
address pc = NULL; // Pc as retrieved from PSW. Usually points past failing instruction.
211
address trap_pc = NULL; // Pc of the instruction causing the trap.
212
213
//%note os_trap_1
214
if (info != NULL && uc != NULL && thread != NULL) {
215
pc = os::Posix::ucontext_get_pc(uc);
216
if (TraceTraps) {
217
tty->print_cr(" pc at " INTPTR_FORMAT, p2i(pc));
218
}
219
if ((unsigned long)(pc - (address)info->si_addr) <= (unsigned long)Assembler::instr_maxlen() ) {
220
trap_pc = (address)info->si_addr;
221
if (TraceTraps) {
222
tty->print_cr("trap_pc at " INTPTR_FORMAT, p2i(trap_pc));
223
}
224
}
225
226
// Handle ALL stack overflow variations here
227
if (sig == SIGSEGV) {
228
address addr = (address)info->si_addr; // Address causing SIGSEGV, usually mem ref target.
229
230
// Check if fault address is within thread stack.
231
if (thread->is_in_full_stack(addr)) {
232
// stack overflow
233
if (os::Posix::handle_stack_overflow(thread, addr, pc, uc, &stub)) {
234
return true; // continue
235
}
236
}
237
}
238
239
if (thread->thread_state() == _thread_in_Java) {
240
// Java thread running in Java code => find exception handler if any
241
// a fault inside compiled code, the interpreter, or a stub
242
243
// Handle signal from NativeJump::patch_verified_entry().
244
if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
245
if (TraceTraps) {
246
tty->print_cr("trap: zombie_not_entrant (SIGILL)");
247
}
248
stub = SharedRuntime::get_handle_wrong_method_stub();
249
}
250
251
else if (sig == SIGSEGV &&
252
SafepointMechanism::is_poll_address((address)info->si_addr)) {
253
if (TraceTraps) {
254
tty->print_cr("trap: safepoint_poll at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
255
}
256
stub = SharedRuntime::get_poll_stub(pc);
257
258
// Info->si_addr only points to the page base address, so we
259
// must extract the real si_addr from the instruction and the
260
// ucontext.
261
assert(((NativeInstruction*)pc)->is_safepoint_poll(), "must be safepoint poll");
262
const address real_si_addr = ((NativeInstruction*)pc)->get_poll_address(uc);
263
}
264
265
// SIGTRAP-based implicit null check in compiled code.
266
else if ((sig == SIGFPE) &&
267
TrapBasedNullChecks &&
268
(trap_pc != NULL) &&
269
Assembler::is_sigtrap_zero_check(trap_pc)) {
270
if (TraceTraps) {
271
tty->print_cr("trap: NULL_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
272
}
273
stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
274
}
275
276
else if (sig == SIGSEGV && ImplicitNullChecks &&
277
CodeCache::contains((void*) pc) &&
278
MacroAssembler::uses_implicit_null_check(info->si_addr)) {
279
if (TraceTraps) {
280
tty->print_cr("trap: null_check at " INTPTR_FORMAT " (SIGSEGV)", p2i(pc));
281
}
282
stub = SharedRuntime::continuation_for_implicit_exception(thread, pc, SharedRuntime::IMPLICIT_NULL);
283
}
284
285
#ifdef COMPILER2
286
// SIGTRAP-based implicit range check in compiled code.
287
else if (sig == SIGFPE && TrapBasedRangeChecks &&
288
(trap_pc != NULL) &&
289
Assembler::is_sigtrap_range_check(trap_pc)) {
290
if (TraceTraps) {
291
tty->print_cr("trap: RANGE_CHECK at " INTPTR_FORMAT " (SIGFPE)", p2i(trap_pc));
292
}
293
stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_NULL);
294
}
295
#endif
296
297
else if (sig == SIGFPE && info->si_code == FPE_INTDIV) {
298
stub = SharedRuntime::continuation_for_implicit_exception(thread, trap_pc, SharedRuntime::IMPLICIT_DIVIDE_BY_ZERO);
299
}
300
301
else if (sig == SIGBUS) {
302
// BugId 4454115: A read from a MappedByteBuffer can fault here if the
303
// underlying file has been truncated. Do not crash the VM in such a case.
304
CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
305
CompiledMethod* nm = (cb != NULL) ? cb->as_compiled_method_or_null() : NULL;
306
if (nm != NULL && nm->has_unsafe_access()) {
307
// We don't really need a stub here! Just set the pending exeption and
308
// continue at the next instruction after the faulting read. Returning
309
// garbage from this read is ok.
310
thread->set_pending_unsafe_access_error();
311
uc->uc_mcontext.psw.addr = ((unsigned long)pc) + Assembler::instr_len(pc);
312
return true;
313
}
314
}
315
}
316
317
else { // thread->thread_state() != _thread_in_Java
318
if ((sig == SIGILL) && VM_Version::is_determine_features_test_running()) {
319
// SIGILL must be caused by VM_Version::determine_features()
320
// when attempting to execute a non-existing instruction.
321
//*(int *) (pc-6)=0; // Patch instruction to 0 to indicate that it causes a SIGILL.
322
// Flushing of icache is not necessary.
323
stub = pc; // Continue with next instruction.
324
} else if ((sig == SIGFPE) && VM_Version::is_determine_features_test_running()) {
325
// SIGFPE is known to be caused by trying to execute a vector instruction
326
// when the vector facility is installed, but operating system support is missing.
327
VM_Version::reset_has_VectorFacility();
328
stub = pc; // Continue with next instruction.
329
} else if ((thread->thread_state() == _thread_in_vm ||
330
thread->thread_state() == _thread_in_native) &&
331
sig == SIGBUS && thread->doing_unsafe_access()) {
332
// We don't really need a stub here! Just set the pending exeption and
333
// continue at the next instruction after the faulting read. Returning
334
// garbage from this read is ok.
335
thread->set_pending_unsafe_access_error();
336
os::Posix::ucontext_set_pc(uc, pc + Assembler::instr_len(pc));
337
return true;
338
}
339
}
340
341
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
342
// and the heap gets shrunk before the field access.
343
if ((sig == SIGSEGV) || (sig == SIGBUS)) {
344
address addr = JNI_FastGetField::find_slowcase_pc(pc);
345
if (addr != (address)-1) {
346
stub = addr;
347
}
348
}
349
}
350
351
if (stub != NULL) {
352
// Save all thread context in case we need to restore it.
353
if (thread != NULL) thread->set_saved_exception_pc(pc);
354
os::Posix::ucontext_set_pc(uc, stub);
355
return true;
356
}
357
358
return false;
359
}
360
361
void os::Linux::init_thread_fpu_state(void) {
362
// Nothing to do on z/Architecture.
363
}
364
365
int os::Linux::get_fpu_control_word(void) {
366
// Nothing to do on z/Architecture.
367
return 0;
368
}
369
370
void os::Linux::set_fpu_control_word(int fpu_control) {
371
// Nothing to do on z/Architecture.
372
}
373
374
////////////////////////////////////////////////////////////////////////////////
375
// thread stack
376
377
// Minimum usable stack sizes required to get to user code. Space for
378
// HotSpot guard pages is added later.
379
size_t os::Posix::_compiler_thread_min_stack_allowed = (52 DEBUG_ONLY(+ 32)) * K;
380
size_t os::Posix::_java_thread_min_stack_allowed = (32 DEBUG_ONLY(+ 8)) * K;
381
size_t os::Posix::_vm_internal_thread_min_stack_allowed = 32 * K;
382
383
// Return default stack size for thr_type.
384
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
385
// Default stack size (compiler thread needs larger stack).
386
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1024 * K);
387
return s;
388
}
389
390
/////////////////////////////////////////////////////////////////////////////
391
// helper functions for fatal error handler
392
393
void os::print_context(outputStream *st, const void *context) {
394
if (context == NULL) return;
395
396
const ucontext_t* uc = (const ucontext_t*)context;
397
398
st->print_cr("Processor state:");
399
st->print_cr("----------------");
400
st->print_cr(" ip = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.addr);
401
st->print_cr(" proc mask = " INTPTR_FORMAT " ", uc->uc_mcontext.psw.mask);
402
st->print_cr(" fpc reg = 0x%8.8x " , uc->uc_mcontext.fpregs.fpc);
403
st->cr();
404
405
st->print_cr("General Purpose Registers:");
406
st->print_cr("--------------------------");
407
for( int i = 0; i < 16; i+=2 ) {
408
st->print(" r%-2d = " INTPTR_FORMAT " " , i, uc->uc_mcontext.gregs[i]);
409
st->print(" r%-2d = " INTPTR_FORMAT " |", i+1, uc->uc_mcontext.gregs[i+1]);
410
st->print(" r%-2d = %23.1ld " , i, uc->uc_mcontext.gregs[i]);
411
st->print(" r%-2d = %23.1ld " , i+1, uc->uc_mcontext.gregs[i+1]);
412
st->cr();
413
}
414
st->cr();
415
416
st->print_cr("Access Registers:");
417
st->print_cr("-----------------");
418
for( int i = 0; i < 16; i+=2 ) {
419
st->print(" ar%-2d = 0x%8.8x ", i, uc->uc_mcontext.aregs[i]);
420
st->print(" ar%-2d = 0x%8.8x ", i+1, uc->uc_mcontext.aregs[i+1]);
421
st->cr();
422
}
423
st->cr();
424
425
st->print_cr("Float Registers:");
426
st->print_cr("----------------");
427
for (int i = 0; i < 16; i += 2) {
428
st->print(" fr%-2d = " INTPTR_FORMAT " " , i, (int64_t)(uc->uc_mcontext.fpregs.fprs[i].d));
429
st->print(" fr%-2d = " INTPTR_FORMAT " |", i+1, (int64_t)(uc->uc_mcontext.fpregs.fprs[i+1].d));
430
st->print(" fr%-2d = %23.15e " , i, (uc->uc_mcontext.fpregs.fprs[i].d));
431
st->print(" fr%-2d = %23.15e " , i+1, (uc->uc_mcontext.fpregs.fprs[i+1].d));
432
st->cr();
433
}
434
st->cr();
435
st->cr();
436
437
intptr_t *sp = (intptr_t *)os::Linux::ucontext_get_sp(uc);
438
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", p2i(sp));
439
print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
440
st->cr();
441
442
// Note: it may be unsafe to inspect memory near pc. For example, pc may
443
// point to garbage if entry point in an nmethod is corrupted. Leave
444
// this at the end, and hope for the best.
445
address pc = os::Posix::ucontext_get_pc(uc);
446
print_instructions(st, pc, /*intrsize=*/4);
447
st->cr();
448
}
449
450
void os::print_register_info(outputStream *st, const void *context) {
451
if (context == NULL) return;
452
453
const ucontext_t *uc = (const ucontext_t*)context;
454
455
st->print_cr("Register to memory mapping:");
456
st->cr();
457
458
st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.psw.addr);
459
for (int i = 0; i < 16; i++) {
460
st->print("r%-2d=", i);
461
print_location(st, uc->uc_mcontext.gregs[i]);
462
}
463
st->cr();
464
}
465
466
#ifndef PRODUCT
467
void os::verify_stack_alignment() {
468
}
469
#endif
470
471
int os::extra_bang_size_in_bytes() {
472
// z/Architecture does not require the additional stack bang.
473
return 0;
474
}
475
476