Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/s390/frame_s390.cpp
40930 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
#include "precompiled.hpp"
27
#include "compiler/oopMap.hpp"
28
#include "interpreter/interpreter.hpp"
29
#include "memory/resourceArea.hpp"
30
#include "memory/universe.hpp"
31
#include "oops/markWord.hpp"
32
#include "oops/oop.inline.hpp"
33
#include "runtime/frame.inline.hpp"
34
#include "runtime/handles.inline.hpp"
35
#include "runtime/javaCalls.hpp"
36
#include "runtime/monitorChunk.hpp"
37
#include "runtime/os.inline.hpp"
38
#include "runtime/signature.hpp"
39
#include "runtime/stubCodeGenerator.hpp"
40
#include "runtime/stubRoutines.hpp"
41
#include "vmreg_s390.inline.hpp"
42
#ifdef COMPILER1
43
#include "c1/c1_Runtime1.hpp"
44
#include "runtime/vframeArray.hpp"
45
#endif
46
47
// Major contributions by Aha, AS.
48
49
#ifdef ASSERT
50
void RegisterMap::check_location_valid() {
51
}
52
#endif // ASSERT
53
54
55
// Profiling/safepoint support
56
57
bool frame::safe_for_sender(JavaThread *thread) {
58
bool safe = false;
59
address sp = (address)_sp;
60
address fp = (address)_fp;
61
address unextended_sp = (address)_unextended_sp;
62
63
// consider stack guards when trying to determine "safe" stack pointers
64
// sp must be within the usable part of the stack (not in guards)
65
if (!thread->is_in_usable_stack(sp)) {
66
return false;
67
}
68
69
// Unextended sp must be within the stack
70
if (!thread->is_in_full_stack_checked(unextended_sp)) {
71
return false;
72
}
73
74
// An fp must be within the stack and above (but not equal) sp.
75
bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
76
// An interpreter fp must be within the stack and above (but not equal) sp.
77
// Moreover, it must be at least the size of the z_ijava_state structure.
78
bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);
79
80
// We know sp/unextended_sp are safe, only fp is questionable here
81
82
// If the current frame is known to the code cache then we can attempt to
83
// to construct the sender and do some validation of it. This goes a long way
84
// toward eliminating issues when we get in frame construction code
85
86
if (_cb != NULL ) {
87
// Entry frame checks
88
if (is_entry_frame()) {
89
// An entry frame must have a valid fp.
90
return fp_safe && is_entry_frame_valid(thread);
91
}
92
93
// Now check if the frame is complete and the test is
94
// reliable. Unfortunately we can only check frame completeness for
95
// runtime stubs. Other generic buffer blobs are more
96
// problematic so we just assume they are OK. Adapter blobs never have a
97
// complete frame and are never OK. nmethods should be OK on s390.
98
if (!_cb->is_frame_complete_at(_pc)) {
99
if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) {
100
return false;
101
}
102
}
103
104
// Could just be some random pointer within the codeBlob.
105
if (!_cb->code_contains(_pc)) {
106
return false;
107
}
108
109
if (is_interpreted_frame() && !fp_interp_safe) {
110
return false;
111
}
112
113
z_abi_160* sender_abi = (z_abi_160*) fp;
114
intptr_t* sender_sp = (intptr_t*) sender_abi->callers_sp;
115
address sender_pc = (address) sender_abi->return_pc;
116
117
// We must always be able to find a recognizable pc.
118
CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
119
if (sender_blob == NULL) {
120
return false;
121
}
122
123
// Could be a zombie method
124
if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
125
return false;
126
}
127
128
// It should be safe to construct the sender though it might not be valid.
129
130
frame sender(sender_sp, sender_pc);
131
132
// Do we have a valid fp?
133
address sender_fp = (address) sender.fp();
134
135
// sender_fp must be within the stack and above (but not
136
// equal) current frame's fp.
137
if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
138
return false;
139
}
140
141
// If the potential sender is the interpreter then we can do some more checking.
142
if (Interpreter::contains(sender_pc)) {
143
return sender.is_interpreted_frame_valid(thread);
144
}
145
146
// Could just be some random pointer within the codeBlob.
147
if (!sender.cb()->code_contains(sender_pc)) {
148
return false;
149
}
150
151
// We should never be able to see an adapter if the current frame is something from code cache.
152
if (sender_blob->is_adapter_blob()) {
153
return false;
154
}
155
156
if (sender.is_entry_frame()) {
157
return sender.is_entry_frame_valid(thread);
158
}
159
160
// Frame size is always greater than zero. If the sender frame size is zero or less,
161
// something is really weird and we better give up.
162
if (sender_blob->frame_size() <= 0) {
163
return false;
164
}
165
166
return true;
167
}
168
169
// Must be native-compiled frame. Since sender will try and use fp to find
170
// linkages it must be safe
171
172
if (!fp_safe) {
173
return false;
174
}
175
176
return true;
177
}
178
179
bool frame::is_interpreted_frame() const {
180
return Interpreter::contains(pc());
181
}
182
183
// sender_sp
184
185
intptr_t* frame::interpreter_frame_sender_sp() const {
186
return sender_sp();
187
}
188
189
frame frame::sender_for_entry_frame(RegisterMap *map) const {
190
assert(map != NULL, "map must be set");
191
// Java frame called from C. Skip all C frames and return top C
192
// frame of that chunk as the sender.
193
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
194
195
assert(!entry_frame_is_first(), "next Java sp must be non zero");
196
assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
197
198
map->clear();
199
200
assert(map->include_argument_oops(), "should be set by clear");
201
202
if (jfa->last_Java_pc() != NULL) {
203
frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());
204
return fr;
205
}
206
// Last_java_pc is not set if we come here from compiled code.
207
frame fr(jfa->last_Java_sp());
208
return fr;
209
}
210
211
frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
212
// Pass callers sender_sp as unextended_sp.
213
return frame(sender_sp(), sender_pc(), (intptr_t*)(ijava_state()->sender_sp));
214
}
215
216
frame frame::sender_for_compiled_frame(RegisterMap *map) const {
217
assert(map != NULL, "map must be set");
218
// Frame owned by compiler.
219
220
address pc = *compiled_sender_pc_addr(_cb);
221
frame caller(compiled_sender_sp(_cb), pc);
222
223
// Now adjust the map.
224
225
// Get the rest.
226
if (map->update_map()) {
227
// Tell GC to use argument oopmaps for some runtime stubs that need it.
228
map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
229
if (_cb->oop_maps() != NULL) {
230
OopMapSet::update_register_map(this, map);
231
}
232
}
233
234
return caller;
235
}
236
237
intptr_t* frame::compiled_sender_sp(CodeBlob* cb) const {
238
return sender_sp();
239
}
240
241
address* frame::compiled_sender_pc_addr(CodeBlob* cb) const {
242
return sender_pc_addr();
243
}
244
245
frame frame::sender(RegisterMap* map) const {
246
// Default is we don't have to follow them. The sender_for_xxx will
247
// update it accordingly.
248
map->set_include_argument_oops(false);
249
250
if (is_entry_frame()) {
251
return sender_for_entry_frame(map);
252
}
253
if (is_interpreted_frame()) {
254
return sender_for_interpreter_frame(map);
255
}
256
assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
257
if (_cb != NULL) {
258
return sender_for_compiled_frame(map);
259
}
260
// Must be native-compiled frame, i.e. the marshaling code for native
261
// methods that exists in the core system.
262
return frame(sender_sp(), sender_pc());
263
}
264
265
void frame::patch_pc(Thread* thread, address pc) {
266
assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
267
if (TracePcPatching) {
268
tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "] ",
269
p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));
270
}
271
own_abi()->return_pc = (uint64_t)pc;
272
address original_pc = CompiledMethod::get_deopt_original_pc(this);
273
if (original_pc != NULL) {
274
assert(original_pc == _pc, "expected original to be stored before patching");
275
_deopt_state = is_deoptimized;
276
// Leave _pc as is.
277
} else {
278
_deopt_state = not_deoptimized;
279
_pc = pc;
280
}
281
}
282
283
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
284
// Is there anything to do?
285
assert(is_interpreted_frame(), "Not an interpreted frame");
286
return true;
287
}
288
289
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
290
assert(is_interpreted_frame(), "interpreted frame expected");
291
Method* method = interpreter_frame_method();
292
BasicType type = method->result_type();
293
294
if (method->is_native()) {
295
address lresult = (address)&(ijava_state()->lresult);
296
address fresult = (address)&(ijava_state()->fresult);
297
298
switch (type) {
299
case T_OBJECT:
300
case T_ARRAY: {
301
*oop_result = cast_to_oop((void*) ijava_state()->oop_tmp);
302
break;
303
}
304
// We use std/stfd to store the values.
305
case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;
306
case T_INT : value_result->i = (jint) *(long*)lresult; break;
307
case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;
308
case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;
309
case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;
310
case T_LONG : value_result->j = (jlong) *(long*)lresult; break;
311
case T_FLOAT : value_result->f = (jfloat) *(float*)fresult; break;
312
case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;
313
case T_VOID : break; // Nothing to do.
314
default : ShouldNotReachHere();
315
}
316
} else {
317
intptr_t* tos_addr = interpreter_frame_tos_address();
318
switch (type) {
319
case T_OBJECT:
320
case T_ARRAY: {
321
oop obj = *(oop*)tos_addr;
322
assert(Universe::is_in_heap_or_null(obj), "sanity check");
323
*oop_result = obj;
324
break;
325
}
326
case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;
327
case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;
328
case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;
329
case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;
330
case T_INT : value_result->i = *(jint*)tos_addr; break;
331
case T_LONG : value_result->j = *(jlong*)tos_addr; break;
332
case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
333
case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
334
case T_VOID : break; // Nothing to do.
335
default : ShouldNotReachHere();
336
}
337
}
338
339
return type;
340
}
341
342
343
// Dump all frames starting a given C stack-pointer.
344
// Use max_frames to limit the number of traced frames.
345
void frame::back_trace(outputStream* st, intptr_t* start_sp, intptr_t* top_pc, unsigned long flags, int max_frames) {
346
347
static char buf[ 150 ];
348
349
bool print_outgoing_arguments = flags & 0x1;
350
bool print_istate_pointers = flags & 0x2;
351
int num = 0;
352
353
intptr_t* current_sp = (intptr_t*) start_sp;
354
int last_num_jargs = 0;
355
int frame_type = 0;
356
int last_frame_type = 0;
357
358
while (current_sp) {
359
intptr_t* current_fp = (intptr_t*) *current_sp;
360
address current_pc = (num == 0)
361
? (address) top_pc
362
: (address) *((intptr_t*)(((address) current_sp) + _z_abi(return_pc)));
363
364
if ((intptr_t*) current_fp != 0 && (intptr_t*) current_fp <= current_sp) {
365
st->print_cr("ERROR: corrupt stack");
366
return;
367
}
368
369
st->print("#%-3d ", num);
370
const char* type_name = " ";
371
const char* function_name = NULL;
372
373
// Detect current frame's frame_type, default to 'C frame'.
374
frame_type = 0;
375
376
CodeBlob* blob = NULL;
377
378
if (Interpreter::contains(current_pc)) {
379
frame_type = 1;
380
} else if (StubRoutines::contains(current_pc)) {
381
if (StubRoutines::returns_to_call_stub(current_pc)) {
382
frame_type = 2;
383
} else {
384
frame_type = 4;
385
type_name = "stu";
386
StubCodeDesc* desc = StubCodeDesc::desc_for (current_pc);
387
if (desc) {
388
function_name = desc->name();
389
} else {
390
function_name = "unknown stub";
391
}
392
}
393
} else if (CodeCache::contains(current_pc)) {
394
blob = CodeCache::find_blob_unsafe(current_pc);
395
if (blob) {
396
if (blob->is_nmethod()) {
397
frame_type = 3;
398
} else if (blob->is_deoptimization_stub()) {
399
frame_type = 4;
400
type_name = "deo";
401
function_name = "deoptimization blob";
402
} else if (blob->is_uncommon_trap_stub()) {
403
frame_type = 4;
404
type_name = "uct";
405
function_name = "uncommon trap blob";
406
} else if (blob->is_exception_stub()) {
407
frame_type = 4;
408
type_name = "exc";
409
function_name = "exception blob";
410
} else if (blob->is_safepoint_stub()) {
411
frame_type = 4;
412
type_name = "saf";
413
function_name = "safepoint blob";
414
} else if (blob->is_runtime_stub()) {
415
frame_type = 4;
416
type_name = "run";
417
function_name = ((RuntimeStub *)blob)->name();
418
} else if (blob->is_method_handles_adapter_blob()) {
419
frame_type = 4;
420
type_name = "mha";
421
function_name = "method handles adapter blob";
422
} else {
423
frame_type = 4;
424
type_name = "blo";
425
function_name = "unknown code blob";
426
}
427
} else {
428
frame_type = 4;
429
type_name = "blo";
430
function_name = "unknown code blob";
431
}
432
}
433
434
st->print("sp=" PTR_FORMAT " ", p2i(current_sp));
435
436
if (frame_type == 0) {
437
current_pc = (address) *((intptr_t*)(((address) current_sp) + _z_abi(gpr14)));
438
}
439
440
st->print("pc=" PTR_FORMAT " ", p2i(current_pc));
441
st->print(" ");
442
443
switch (frame_type) {
444
case 0: // C frame:
445
{
446
st->print(" ");
447
if (current_pc == 0) {
448
st->print("? ");
449
} else {
450
// name
451
int func_offset;
452
char demangled_name[256];
453
int demangled_name_len = 256;
454
if (os::dll_address_to_function_name(current_pc, demangled_name, demangled_name_len, &func_offset)) {
455
demangled_name[demangled_name_len-1] = '\0';
456
st->print(func_offset == -1 ? "%s " : "%s+0x%x", demangled_name, func_offset);
457
} else {
458
st->print("? ");
459
}
460
}
461
}
462
break;
463
464
case 1: // interpreter frame:
465
{
466
st->print(" i ");
467
468
if (last_frame_type != 1) last_num_jargs = 8;
469
470
// name
471
Method* method = *(Method**)((address)current_fp + _z_ijava_state_neg(method));
472
if (method) {
473
ResourceMark rm;
474
if (method->is_synchronized()) st->print("synchronized ");
475
if (method->is_static()) st->print("static ");
476
if (method->is_native()) st->print("native ");
477
method->name_and_sig_as_C_string(buf, sizeof(buf));
478
st->print("%s ", buf);
479
}
480
else
481
st->print("? ");
482
483
intptr_t* tos = (intptr_t*) *(intptr_t*)((address)current_fp + _z_ijava_state_neg(esp));
484
if (print_istate_pointers) {
485
st->cr();
486
st->print(" ");
487
st->print("ts=" PTR_FORMAT " ", p2i(tos));
488
}
489
490
// Dump some Java stack slots.
491
if (print_outgoing_arguments) {
492
if (method->is_native()) {
493
#ifdef ASSERT
494
intptr_t* cargs = (intptr_t*) (((address)current_sp) + _z_abi(carg_1));
495
for (int i = 0; i < last_num_jargs; i++) {
496
// Cargs is not prepushed.
497
st->cr();
498
st->print(" ");
499
st->print(PTR_FORMAT, *(cargs));
500
cargs++;
501
}
502
#endif /* ASSERT */
503
}
504
else {
505
if (tos) {
506
for (int i = 0; i < last_num_jargs; i++) {
507
// tos+0 is prepushed, ignore.
508
tos++;
509
if (tos >= (intptr_t *)((address)current_fp + _z_ijava_state_neg(monitors)))
510
break;
511
st->cr();
512
st->print(" ");
513
st->print(PTR_FORMAT " %+.3e %+.3le", *(tos), *(float*)(tos), *(double*)(tos));
514
}
515
}
516
}
517
last_num_jargs = method->size_of_parameters();
518
}
519
}
520
break;
521
522
case 2: // entry frame:
523
{
524
st->print("v2i ");
525
526
// name
527
st->print("call stub");
528
}
529
break;
530
531
case 3: // compiled frame:
532
{
533
st->print(" c ");
534
535
// name
536
Method* method = ((nmethod *)blob)->method();
537
if (method) {
538
ResourceMark rm;
539
method->name_and_sig_as_C_string(buf, sizeof(buf));
540
st->print("%s ", buf);
541
}
542
else
543
st->print("? ");
544
}
545
break;
546
547
case 4: // named frames
548
{
549
st->print("%s ", type_name);
550
551
// name
552
if (function_name)
553
st->print("%s", function_name);
554
}
555
break;
556
557
default:
558
break;
559
}
560
561
st->cr();
562
st->flush();
563
564
current_sp = current_fp;
565
last_frame_type = frame_type;
566
num++;
567
// Check for maximum # of frames, and stop when reached.
568
if (max_frames > 0 && --max_frames == 0)
569
break;
570
}
571
572
}
573
574
// Convenience function for calls from the debugger.
575
576
extern "C" void bt(intptr_t* start_sp,intptr_t* top_pc) {
577
frame::back_trace(tty,start_sp, top_pc, 0);
578
}
579
580
extern "C" void bt_full(intptr_t* start_sp,intptr_t* top_pc) {
581
frame::back_trace(tty,start_sp, top_pc, (unsigned long)(long)-1);
582
}
583
584
585
// Function for tracing a limited number of frames.
586
// Use this one if you only need to see the "top of stack" frames.
587
extern "C" void bt_max(intptr_t *start_sp, intptr_t *top_pc, int max_frames) {
588
frame::back_trace(tty, start_sp, top_pc, 0, max_frames);
589
}
590
591
#if !defined(PRODUCT)
592
593
#define DESCRIBE_ADDRESS(name) \
594
values.describe(frame_no, (intptr_t*)&ijava_state()->name, #name);
595
596
void frame::describe_pd(FrameValues& values, int frame_no) {
597
if (is_interpreted_frame()) {
598
// Describe z_ijava_state elements.
599
DESCRIBE_ADDRESS(method);
600
DESCRIBE_ADDRESS(locals);
601
DESCRIBE_ADDRESS(monitors);
602
DESCRIBE_ADDRESS(cpoolCache);
603
DESCRIBE_ADDRESS(bcp);
604
DESCRIBE_ADDRESS(mdx);
605
DESCRIBE_ADDRESS(esp);
606
DESCRIBE_ADDRESS(sender_sp);
607
DESCRIBE_ADDRESS(top_frame_sp);
608
DESCRIBE_ADDRESS(oop_tmp);
609
DESCRIBE_ADDRESS(lresult);
610
DESCRIBE_ADDRESS(fresult);
611
}
612
}
613
614
615
void frame::pd_ps() {}
616
#endif // !PRODUCT
617
618
intptr_t *frame::initial_deoptimization_info() {
619
// Used to reset the saved FP.
620
return fp();
621
}
622
623