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