Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/os_cpu/aix_ppc/os_aix_ppc.cpp
40930 views
1
/*
2
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2012, 2021 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 "jvm.h"
28
#include "assembler_ppc.hpp"
29
#include "asm/assembler.inline.hpp"
30
#include "classfile/vmSymbols.hpp"
31
#include "code/codeCache.hpp"
32
#include "code/icBuffer.hpp"
33
#include "code/vtableStubs.hpp"
34
#include "interpreter/interpreter.hpp"
35
#include "memory/allocation.inline.hpp"
36
#include "nativeInst_ppc.hpp"
37
#include "os_share_aix.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/mutexLocker.hpp"
47
#include "runtime/osThread.hpp"
48
#include "runtime/safepointMechanism.hpp"
49
#include "runtime/sharedRuntime.hpp"
50
#include "runtime/stubRoutines.hpp"
51
#include "runtime/thread.inline.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 NULL;
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 != NULL) {
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 = NULL;
115
if (ret_sp) *ret_sp = (intptr_t *)NULL;
116
if (ret_fp) *ret_fp = (intptr_t *)NULL;
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);
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);
140
}
141
142
frame os::get_sender_for_C_frame(frame* fr) {
143
if (*fr->sp() == NULL) {
144
// fr is the last C frame
145
return frame(NULL, NULL);
146
}
147
return frame(fr->sender_sp(), fr->sender_pc());
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));
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 = NULL;
162
163
// retrieve program counter
164
address const pc = uc ? os::Posix::ucontext_get_pc(uc) : NULL;
165
166
// retrieve crash address
167
address const addr = info ? (const address) info->si_addr : NULL;
168
169
if (info == NULL || uc == NULL) {
170
return false; // Fatal error
171
}
172
173
// If we are a java thread...
174
if (thread != NULL) {
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 != NULL) {
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 Zombie methods,
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
// - zombie methods
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 = NULL;
225
int stop_type = -1;
226
// Handle signal from NativeJump::patch_verified_entry().
227
if (sig == SIGILL && nativeInstruction_at(pc)->is_sigill_zombie_not_entrant()) {
228
if (TraceTraps) {
229
tty->print_cr("trap: zombie_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)) != NULL) &&
239
cb->is_compiled()) {
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)) != NULL) &&
252
cb->is_compiled()) {
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)", 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)", 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)", 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)", 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 = NULL;
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
va_list va_dummy;
334
VMError::report_and_die(thread, uc, NULL, 0, msg, detail_msg, va_dummy);
335
va_end(va_dummy);
336
337
ShouldNotReachHere();
338
}
339
340
else if (sig == SIGBUS) {
341
// BugId 4454115: A read from a MappedByteBuffer can fault here if the
342
// underlying file has been truncated. Do not crash the VM in such a case.
343
CodeBlob* cb = CodeCache::find_blob_unsafe(pc);
344
CompiledMethod* nm = cb ? cb->as_compiled_method_or_null() : NULL;
345
bool is_unsafe_arraycopy = (thread->doing_unsafe_access() && UnsafeCopyMemory::contains_pc(pc));
346
if ((nm != NULL && nm->has_unsafe_access()) || is_unsafe_arraycopy) {
347
address next_pc = pc + 4;
348
if (is_unsafe_arraycopy) {
349
next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
350
}
351
next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
352
os::Posix::ucontext_set_pc(uc, next_pc);
353
return true;
354
}
355
}
356
}
357
358
else { // thread->thread_state() != _thread_in_Java
359
// Detect CPU features. This is only done at the very start of the VM. Later, the
360
// VM_Version::is_determine_features_test_running() flag should be false.
361
362
if (sig == SIGILL && VM_Version::is_determine_features_test_running()) {
363
// SIGILL must be caused by VM_Version::determine_features().
364
*(int *)pc = 0; // patch instruction to 0 to indicate that it causes a SIGILL,
365
// flushing of icache is not necessary.
366
stub = pc + 4; // continue with next instruction.
367
goto run_stub;
368
}
369
else if ((thread->thread_state() == _thread_in_vm ||
370
thread->thread_state() == _thread_in_native) &&
371
sig == SIGBUS && thread->doing_unsafe_access()) {
372
address next_pc = pc + 4;
373
if (UnsafeCopyMemory::contains_pc(pc)) {
374
next_pc = UnsafeCopyMemory::page_error_continue_pc(pc);
375
}
376
next_pc = SharedRuntime::handle_unsafe_access(thread, next_pc);
377
os::Posix::ucontext_set_pc(uc, next_pc);
378
return true;
379
}
380
}
381
382
// jni_fast_Get<Primitive>Field can trap at certain pc's if a GC kicks in
383
// and the heap gets shrunk before the field access.
384
if ((sig == SIGSEGV) || (sig == SIGBUS)) {
385
address addr = JNI_FastGetField::find_slowcase_pc(pc);
386
if (addr != (address)-1) {
387
stub = addr;
388
}
389
}
390
}
391
392
run_stub:
393
394
// One of the above code blocks ininitalized the stub, so we want to
395
// delegate control to that stub.
396
if (stub != NULL) {
397
// Save all thread context in case we need to restore it.
398
if (thread != NULL) thread->set_saved_exception_pc(pc);
399
os::Posix::ucontext_set_pc(uc, stub);
400
return true;
401
}
402
403
return false; // Fatal error
404
}
405
406
void os::Aix::init_thread_fpu_state(void) {
407
#if !defined(USE_XLC_BUILTINS)
408
// Disable FP exceptions.
409
__asm__ __volatile__ ("mtfsfi 6,0");
410
#else
411
__mtfsfi(6, 0);
412
#endif
413
}
414
415
////////////////////////////////////////////////////////////////////////////////
416
// thread stack
417
418
// Minimum usable stack sizes required to get to user code. Space for
419
// HotSpot guard pages is added later.
420
size_t os::Posix::_compiler_thread_min_stack_allowed = 192 * K;
421
size_t os::Posix::_java_thread_min_stack_allowed = 64 * K;
422
size_t os::Posix::_vm_internal_thread_min_stack_allowed = 64 * K;
423
424
// Return default stack size for thr_type.
425
size_t os::Posix::default_stack_size(os::ThreadType thr_type) {
426
// Default stack size (compiler thread needs larger stack).
427
size_t s = (thr_type == os::compiler_thread ? 4 * M : 1 * M);
428
return s;
429
}
430
431
/////////////////////////////////////////////////////////////////////////////
432
// helper functions for fatal error handler
433
434
void os::print_context(outputStream *st, const void *context) {
435
if (context == NULL) return;
436
437
const ucontext_t* uc = (const ucontext_t*)context;
438
439
st->print_cr("Registers:");
440
st->print("pc =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.iar);
441
st->print("lr =" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.lr);
442
st->print("ctr=" INTPTR_FORMAT " ", uc->uc_mcontext.jmp_context.ctr);
443
st->cr();
444
for (int i = 0; i < 32; i++) {
445
st->print("r%-2d=" INTPTR_FORMAT " ", i, uc->uc_mcontext.jmp_context.gpr[i]);
446
if (i % 3 == 2) st->cr();
447
}
448
st->cr();
449
st->cr();
450
451
intptr_t *sp = (intptr_t *)os::Aix::ucontext_get_sp(uc);
452
st->print_cr("Top of Stack: (sp=" PTR_FORMAT ")", sp);
453
print_hex_dump(st, (address)sp, (address)(sp + 128), sizeof(intptr_t));
454
st->cr();
455
456
// Note: it may be unsafe to inspect memory near pc. For example, pc may
457
// point to garbage if entry point in an nmethod is corrupted. Leave
458
// this at the end, and hope for the best.
459
address pc = os::Posix::ucontext_get_pc(uc);
460
print_instructions(st, pc, /*instrsize=*/4);
461
st->cr();
462
463
// Try to decode the instructions.
464
st->print_cr("Decoded instructions: (pc=" PTR_FORMAT ")", pc);
465
st->print("<TODO: PPC port - print_context>");
466
// TODO: PPC port Disassembler::decode(pc, 16, 16, st);
467
st->cr();
468
}
469
470
void os::print_register_info(outputStream *st, const void *context) {
471
if (context == NULL) return;
472
473
ucontext_t *uc = (ucontext_t*)context;
474
475
st->print_cr("Register to memory mapping:");
476
st->cr();
477
478
st->print("pc ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.iar);
479
st->print("lr ="); print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.lr);
480
st->print("sp ="); print_location(st, (intptr_t)os::Aix::ucontext_get_sp(uc));
481
for (int i = 0; i < 32; i++) {
482
st->print("r%-2d=", i);
483
print_location(st, (intptr_t)uc->uc_mcontext.jmp_context.gpr[i]);
484
}
485
486
st->cr();
487
}
488
489
extern "C" {
490
int SpinPause() {
491
return 0;
492
}
493
}
494
495
#ifndef PRODUCT
496
void os::verify_stack_alignment() {
497
assert(((intptr_t)os::current_stack_pointer() & (StackAlignmentInBytes-1)) == 0, "incorrect stack alignment");
498
}
499
#endif
500
501
int os::extra_bang_size_in_bytes() {
502
// PPC does not require the additional stack bang.
503
return 0;
504
}
505
506
bool os::platform_print_native_stack(outputStream* st, void* context, char *buf, int buf_size) {
507
AixNativeCallstack::print_callstack_for_context(st, (const ucontext_t*)context, true, buf, (size_t) buf_size);
508
return true;
509
}
510
511
// HAVE_FUNCTION_DESCRIPTORS
512
void* os::resolve_function_descriptor(void* p) {
513
return ((const FunctionDescriptor*)p)->entry();
514
}
515
516