Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/src/hotspot/cpu/aarch64/frame_aarch64.cpp
40930 views
1
/*
2
* Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved.
3
* Copyright (c) 2014, 2020, Red Hat Inc. 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/method.hpp"
33
#include "oops/oop.inline.hpp"
34
#include "prims/methodHandles.hpp"
35
#include "runtime/frame.inline.hpp"
36
#include "runtime/handles.inline.hpp"
37
#include "runtime/javaCalls.hpp"
38
#include "runtime/monitorChunk.hpp"
39
#include "runtime/os.inline.hpp"
40
#include "runtime/signature.hpp"
41
#include "runtime/stackWatermarkSet.hpp"
42
#include "runtime/stubCodeGenerator.hpp"
43
#include "runtime/stubRoutines.hpp"
44
#include "vmreg_aarch64.inline.hpp"
45
#ifdef COMPILER1
46
#include "c1/c1_Runtime1.hpp"
47
#include "runtime/vframeArray.hpp"
48
#endif
49
50
#ifdef ASSERT
51
void RegisterMap::check_location_valid() {
52
}
53
#endif
54
55
56
// Profiling/safepoint support
57
58
bool frame::safe_for_sender(JavaThread *thread) {
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
// When we are running interpreted code the machine stack pointer, SP, is
70
// set low enough so that the Java expression stack can grow and shrink
71
// without ever exceeding the machine stack bounds. So, ESP >= SP.
72
73
// When we call out of an interpreted method, SP is incremented so that
74
// the space between SP and ESP is removed. The SP saved in the callee's
75
// frame is the SP *before* this increment. So, when we walk a stack of
76
// interpreter frames the sender's SP saved in a frame might be less than
77
// the SP at the point of call.
78
79
// So unextended sp must be within the stack but we need not to check
80
// that unextended sp >= sp
81
if (!thread->is_in_full_stack_checked(unextended_sp)) {
82
return false;
83
}
84
85
// an fp must be within the stack and above (but not equal) sp
86
// second evaluation on fp+ is added to handle situation where fp is -1
87
bool fp_safe = thread->is_in_stack_range_excl(fp, sp) &&
88
thread->is_in_full_stack_checked(fp + (return_addr_offset * sizeof(void*)));
89
90
// We know sp/unextended_sp are safe only fp is questionable here
91
92
// If the current frame is known to the code cache then we can attempt to
93
// to construct the sender and do some validation of it. This goes a long way
94
// toward eliminating issues when we get in frame construction code
95
96
if (_cb != NULL ) {
97
98
// First check if frame is complete and tester is reliable
99
// Unfortunately we can only check frame complete for runtime stubs and nmethod
100
// other generic buffer blobs are more problematic so we just assume they are
101
// ok. adapter blobs never have a frame complete and are never ok.
102
103
if (!_cb->is_frame_complete_at(_pc)) {
104
if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
105
return false;
106
}
107
}
108
109
// Could just be some random pointer within the codeBlob
110
if (!_cb->code_contains(_pc)) {
111
return false;
112
}
113
114
// Entry frame checks
115
if (is_entry_frame()) {
116
// an entry frame must have a valid fp.
117
return fp_safe && is_entry_frame_valid(thread);
118
}
119
120
intptr_t* sender_sp = NULL;
121
intptr_t* sender_unextended_sp = NULL;
122
address sender_pc = NULL;
123
intptr_t* saved_fp = NULL;
124
125
if (is_interpreted_frame()) {
126
// fp must be safe
127
if (!fp_safe) {
128
return false;
129
}
130
131
sender_pc = (address) this->fp()[return_addr_offset];
132
// for interpreted frames, the value below is the sender "raw" sp,
133
// which can be different from the sender unextended sp (the sp seen
134
// by the sender) because of current frame local variables
135
sender_sp = (intptr_t*) addr_at(sender_sp_offset);
136
sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
137
saved_fp = (intptr_t*) this->fp()[link_offset];
138
139
} else {
140
// must be some sort of compiled/runtime frame
141
// fp does not have to be safe (although it could be check for c1?)
142
143
// check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
144
if (_cb->frame_size() <= 0) {
145
return false;
146
}
147
148
sender_sp = _unextended_sp + _cb->frame_size();
149
// Is sender_sp safe?
150
if (!thread->is_in_full_stack_checked((address)sender_sp)) {
151
return false;
152
}
153
sender_unextended_sp = sender_sp;
154
sender_pc = (address) *(sender_sp-1);
155
// Note: frame::sender_sp_offset is only valid for compiled frame
156
saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
157
}
158
159
160
// If the potential sender is the interpreter then we can do some more checking
161
if (Interpreter::contains(sender_pc)) {
162
163
// fp is always saved in a recognizable place in any code we generate. However
164
// only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp
165
// is really a frame pointer.
166
167
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
168
return false;
169
}
170
171
// construct the potential sender
172
173
frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
174
175
return sender.is_interpreted_frame_valid(thread);
176
177
}
178
179
// We must always be able to find a recognizable pc
180
CodeBlob* sender_blob = CodeCache::find_blob_unsafe(sender_pc);
181
if (sender_pc == NULL || sender_blob == NULL) {
182
return false;
183
}
184
185
// Could be a zombie method
186
if (sender_blob->is_zombie() || sender_blob->is_unloaded()) {
187
return false;
188
}
189
190
// Could just be some random pointer within the codeBlob
191
if (!sender_blob->code_contains(sender_pc)) {
192
return false;
193
}
194
195
// We should never be able to see an adapter if the current frame is something from code cache
196
if (sender_blob->is_adapter_blob()) {
197
return false;
198
}
199
200
// Could be the call_stub
201
if (StubRoutines::returns_to_call_stub(sender_pc)) {
202
if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
203
return false;
204
}
205
206
// construct the potential sender
207
208
frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
209
210
// Validate the JavaCallWrapper an entry frame must have
211
address jcw = (address)sender.entry_frame_call_wrapper();
212
213
return thread->is_in_stack_range_excl(jcw, (address)sender.fp());
214
}
215
216
CompiledMethod* nm = sender_blob->as_compiled_method_or_null();
217
if (nm != NULL) {
218
if (nm->is_deopt_mh_entry(sender_pc) || nm->is_deopt_entry(sender_pc) ||
219
nm->method()->is_method_handle_intrinsic()) {
220
return false;
221
}
222
}
223
224
// If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
225
// because the return address counts against the callee's frame.
226
227
if (sender_blob->frame_size() <= 0) {
228
assert(!sender_blob->is_compiled(), "should count return address at least");
229
return false;
230
}
231
232
// We should never be able to see anything here except an nmethod. If something in the
233
// code cache (current frame) is called by an entity within the code cache that entity
234
// should not be anything but the call stub (already covered), the interpreter (already covered)
235
// or an nmethod.
236
237
if (!sender_blob->is_compiled()) {
238
return false;
239
}
240
241
// Could put some more validation for the potential non-interpreted sender
242
// frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
243
244
// One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
245
246
// We've validated the potential sender that would be created
247
return true;
248
}
249
250
// Must be native-compiled frame. Since sender will try and use fp to find
251
// linkages it must be safe
252
253
if (!fp_safe) {
254
return false;
255
}
256
257
// Will the pc we fetch be non-zero (which we'll find at the oldest frame)
258
259
if ( (address) this->fp()[return_addr_offset] == NULL) return false;
260
261
262
// could try and do some more potential verification of native frame if we could think of some...
263
264
return true;
265
266
}
267
268
void frame::patch_pc(Thread* thread, address pc) {
269
assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
270
address* pc_addr = &(((address*) sp())[-1]);
271
if (TracePcPatching) {
272
tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
273
p2i(pc_addr), p2i(*pc_addr), p2i(pc));
274
}
275
// Either the return address is the original one or we are going to
276
// patch in the same address that's already there.
277
assert(_pc == *pc_addr || pc == *pc_addr, "must be");
278
*pc_addr = pc;
279
address original_pc = CompiledMethod::get_deopt_original_pc(this);
280
if (original_pc != NULL) {
281
assert(original_pc == _pc, "expected original PC to be stored before patching");
282
_deopt_state = is_deoptimized;
283
// leave _pc as is
284
} else {
285
_deopt_state = not_deoptimized;
286
_pc = pc;
287
}
288
}
289
290
bool frame::is_interpreted_frame() const {
291
return Interpreter::contains(pc());
292
}
293
294
int frame::frame_size(RegisterMap* map) const {
295
frame sender = this->sender(map);
296
return sender.sp() - sp();
297
}
298
299
intptr_t* frame::entry_frame_argument_at(int offset) const {
300
// convert offset to index to deal with tsi
301
int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
302
// Entry frame's arguments are always in relation to unextended_sp()
303
return &unextended_sp()[index];
304
}
305
306
// sender_sp
307
intptr_t* frame::interpreter_frame_sender_sp() const {
308
assert(is_interpreted_frame(), "interpreted frame expected");
309
return (intptr_t*) at(interpreter_frame_sender_sp_offset);
310
}
311
312
void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
313
assert(is_interpreted_frame(), "interpreted frame expected");
314
ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
315
}
316
317
318
// monitor elements
319
320
BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
321
return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
322
}
323
324
BasicObjectLock* frame::interpreter_frame_monitor_end() const {
325
BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
326
// make sure the pointer points inside the frame
327
assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
328
assert((intptr_t*) result < fp(), "monitor end should be strictly below the frame pointer");
329
return result;
330
}
331
332
void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
333
*((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
334
}
335
336
// Used by template based interpreter deoptimization
337
void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
338
*((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
339
}
340
341
frame frame::sender_for_entry_frame(RegisterMap* map) const {
342
assert(map != NULL, "map must be set");
343
// Java frame called from C; skip all C frames and return top C
344
// frame of that chunk as the sender
345
JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
346
assert(!entry_frame_is_first(), "next Java fp must be non zero");
347
assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
348
// Since we are walking the stack now this nested anchor is obviously walkable
349
// even if it wasn't when it was stacked.
350
if (!jfa->walkable()) {
351
// Capture _last_Java_pc (if needed) and mark anchor walkable.
352
jfa->capture_last_Java_pc();
353
}
354
map->clear();
355
assert(map->include_argument_oops(), "should be set by clear");
356
vmassert(jfa->last_Java_pc() != NULL, "not walkable");
357
frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
358
359
return fr;
360
}
361
362
JavaFrameAnchor* OptimizedEntryBlob::jfa_for_frame(const frame& frame) const {
363
ShouldNotCallThis();
364
return nullptr;
365
}
366
367
frame frame::sender_for_optimized_entry_frame(RegisterMap* map) const {
368
ShouldNotCallThis();
369
return {};
370
}
371
372
//------------------------------------------------------------------------------
373
// frame::verify_deopt_original_pc
374
//
375
// Verifies the calculated original PC of a deoptimization PC for the
376
// given unextended SP.
377
#ifdef ASSERT
378
void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {
379
frame fr;
380
381
// This is ugly but it's better than to change {get,set}_original_pc
382
// to take an SP value as argument. And it's only a debugging
383
// method anyway.
384
fr._unextended_sp = unextended_sp;
385
386
address original_pc = nm->get_original_pc(&fr);
387
assert(nm->insts_contains_inclusive(original_pc),
388
"original PC must be in the main code section of the the compiled method (or must be immediately following it)");
389
}
390
#endif
391
392
//------------------------------------------------------------------------------
393
// frame::adjust_unextended_sp
394
void frame::adjust_unextended_sp() {
395
// On aarch64, sites calling method handle intrinsics and lambda forms are treated
396
// as any other call site. Therefore, no special action is needed when we are
397
// returning to any of these call sites.
398
399
if (_cb != NULL) {
400
CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();
401
if (sender_cm != NULL) {
402
// If the sender PC is a deoptimization point, get the original PC.
403
if (sender_cm->is_deopt_entry(_pc) ||
404
sender_cm->is_deopt_mh_entry(_pc)) {
405
DEBUG_ONLY(verify_deopt_original_pc(sender_cm, _unextended_sp));
406
}
407
}
408
}
409
}
410
411
//------------------------------------------------------------------------------
412
// frame::update_map_with_saved_link
413
void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {
414
// The interpreter and compiler(s) always save fp in a known
415
// location on entry. We must record where that location is
416
// so that if fp was live on callout from c2 we can find
417
// the saved copy no matter what it called.
418
419
// Since the interpreter always saves fp if we record where it is then
420
// we don't have to always save fp on entry and exit to c2 compiled
421
// code, on entry will be enough.
422
map->set_location(rfp->as_VMReg(), (address) link_addr);
423
// this is weird "H" ought to be at a higher address however the
424
// oopMaps seems to have the "H" regs at the same address and the
425
// vanilla register.
426
// XXXX make this go away
427
if (true) {
428
map->set_location(rfp->as_VMReg()->next(), (address) link_addr);
429
}
430
}
431
432
433
//------------------------------------------------------------------------------
434
// frame::sender_for_interpreter_frame
435
frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
436
// SP is the raw SP from the sender after adapter or interpreter
437
// extension.
438
intptr_t* sender_sp = this->sender_sp();
439
440
// This is the sp before any possible extension (adapter/locals).
441
intptr_t* unextended_sp = interpreter_frame_sender_sp();
442
443
#if COMPILER2_OR_JVMCI
444
if (map->update_map()) {
445
update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
446
}
447
#endif // COMPILER2_OR_JVMCI
448
449
return frame(sender_sp, unextended_sp, link(), sender_pc());
450
}
451
452
453
//------------------------------------------------------------------------------
454
// frame::sender_for_compiled_frame
455
frame frame::sender_for_compiled_frame(RegisterMap* map) const {
456
// we cannot rely upon the last fp having been saved to the thread
457
// in C2 code but it will have been pushed onto the stack. so we
458
// have to find it relative to the unextended sp
459
460
assert(_cb->frame_size() >= 0, "must have non-zero frame size");
461
intptr_t* l_sender_sp = unextended_sp() + _cb->frame_size();
462
intptr_t* unextended_sp = l_sender_sp;
463
464
// the return_address is always the word on the stack
465
address sender_pc = (address) *(l_sender_sp-1);
466
467
intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);
468
469
// assert (sender_sp() == l_sender_sp, "should be");
470
// assert (*saved_fp_addr == link(), "should be");
471
472
if (map->update_map()) {
473
// Tell GC to use argument oopmaps for some runtime stubs that need it.
474
// For C1, the runtime stub might not have oop maps, so set this flag
475
// outside of update_register_map.
476
map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
477
if (_cb->oop_maps() != NULL) {
478
OopMapSet::update_register_map(this, map);
479
}
480
481
// Since the prolog does the save and restore of FP there is no
482
// oopmap for it so we must fill in its location as if there was
483
// an oopmap entry since if our caller was compiled code there
484
// could be live jvm state in it.
485
update_map_with_saved_link(map, saved_fp_addr);
486
}
487
488
return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
489
}
490
491
//------------------------------------------------------------------------------
492
// frame::sender_raw
493
frame frame::sender_raw(RegisterMap* map) const {
494
// Default is we done have to follow them. The sender_for_xxx will
495
// update it accordingly
496
map->set_include_argument_oops(false);
497
498
if (is_entry_frame())
499
return sender_for_entry_frame(map);
500
if (is_interpreted_frame())
501
return sender_for_interpreter_frame(map);
502
assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
503
504
// This test looks odd: why is it not is_compiled_frame() ? That's
505
// because stubs also have OOP maps.
506
if (_cb != NULL) {
507
return sender_for_compiled_frame(map);
508
}
509
510
// Must be native-compiled frame, i.e. the marshaling code for native
511
// methods that exists in the core system.
512
return frame(sender_sp(), link(), sender_pc());
513
}
514
515
frame frame::sender(RegisterMap* map) const {
516
frame result = sender_raw(map);
517
518
if (map->process_frames()) {
519
StackWatermarkSet::on_iteration(map->thread(), result);
520
}
521
522
return result;
523
}
524
525
bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
526
assert(is_interpreted_frame(), "Not an interpreted frame");
527
// These are reasonable sanity checks
528
if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
529
return false;
530
}
531
if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
532
return false;
533
}
534
if (fp() + interpreter_frame_initial_sp_offset < sp()) {
535
return false;
536
}
537
// These are hacks to keep us out of trouble.
538
// The problem with these is that they mask other problems
539
if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
540
return false;
541
}
542
543
// do some validation of frame elements
544
545
// first the method
546
547
Method* m = *interpreter_frame_method_addr();
548
549
// validate the method we'd find in this potential sender
550
if (!Method::is_valid_method(m)) return false;
551
552
// stack frames shouldn't be much larger than max_stack elements
553
// this test requires the use of unextended_sp which is the sp as seen by
554
// the current frame, and not sp which is the "raw" pc which could point
555
// further because of local variables of the callee method inserted after
556
// method arguments
557
if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
558
return false;
559
}
560
561
// validate bci/bcx
562
563
address bcp = interpreter_frame_bcp();
564
if (m->validate_bci_from_bcp(bcp) < 0) {
565
return false;
566
}
567
568
// validate constantPoolCache*
569
ConstantPoolCache* cp = *interpreter_frame_cache_addr();
570
if (MetaspaceObj::is_valid(cp) == false) return false;
571
572
// validate locals
573
574
address locals = (address) *interpreter_frame_locals_addr();
575
return thread->is_in_stack_range_incl(locals, (address)fp());
576
}
577
578
BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
579
assert(is_interpreted_frame(), "interpreted frame expected");
580
Method* method = interpreter_frame_method();
581
BasicType type = method->result_type();
582
583
intptr_t* tos_addr;
584
if (method->is_native()) {
585
// TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0
586
// Prior to calling into the runtime to report the method_exit the possible
587
// return value is pushed to the native stack. If the result is a jfloat/jdouble
588
// then ST0 is saved before EAX/EDX. See the note in generate_native_result
589
tos_addr = (intptr_t*)sp();
590
if (type == T_FLOAT || type == T_DOUBLE) {
591
// This is times two because we do a push(ltos) after pushing XMM0
592
// and that takes two interpreter stack slots.
593
tos_addr += 2 * Interpreter::stackElementWords;
594
}
595
} else {
596
tos_addr = (intptr_t*)interpreter_frame_tos_address();
597
}
598
599
switch (type) {
600
case T_OBJECT :
601
case T_ARRAY : {
602
oop obj;
603
if (method->is_native()) {
604
obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
605
} else {
606
oop* obj_p = (oop*)tos_addr;
607
obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
608
}
609
assert(Universe::is_in_heap_or_null(obj), "sanity check");
610
*oop_result = obj;
611
break;
612
}
613
case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
614
case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
615
case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
616
case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
617
case T_INT : value_result->i = *(jint*)tos_addr; break;
618
case T_LONG : value_result->j = *(jlong*)tos_addr; break;
619
case T_FLOAT : {
620
value_result->f = *(jfloat*)tos_addr;
621
break;
622
}
623
case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
624
case T_VOID : /* Nothing to do */ break;
625
default : ShouldNotReachHere();
626
}
627
628
return type;
629
}
630
631
632
intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
633
int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
634
return &interpreter_frame_tos_address()[index];
635
}
636
637
#ifndef PRODUCT
638
639
#define DESCRIBE_FP_OFFSET(name) \
640
values.describe(frame_no, fp() + frame::name##_offset, #name)
641
642
void frame::describe_pd(FrameValues& values, int frame_no) {
643
if (is_interpreted_frame()) {
644
DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
645
DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
646
DESCRIBE_FP_OFFSET(interpreter_frame_method);
647
DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
648
DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
649
DESCRIBE_FP_OFFSET(interpreter_frame_cache);
650
DESCRIBE_FP_OFFSET(interpreter_frame_locals);
651
DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
652
DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
653
}
654
}
655
#endif
656
657
intptr_t *frame::initial_deoptimization_info() {
658
// Not used on aarch64, but we must return something.
659
return NULL;
660
}
661
662
intptr_t* frame::real_fp() const {
663
if (_cb != NULL) {
664
// use the frame size if valid
665
int size = _cb->frame_size();
666
if (size > 0) {
667
return unextended_sp() + size;
668
}
669
}
670
// else rely on fp()
671
assert(! is_compiled_frame(), "unknown compiled frame size");
672
return fp();
673
}
674
675
#undef DESCRIBE_FP_OFFSET
676
677
#define DESCRIBE_FP_OFFSET(name) \
678
{ \
679
uintptr_t *p = (uintptr_t *)fp; \
680
printf(INTPTR_FORMAT " " INTPTR_FORMAT " %s\n", \
681
(uintptr_t)(p + frame::name##_offset), \
682
p[frame::name##_offset], #name); \
683
}
684
685
static THREAD_LOCAL uintptr_t nextfp;
686
static THREAD_LOCAL uintptr_t nextpc;
687
static THREAD_LOCAL uintptr_t nextsp;
688
static THREAD_LOCAL RegisterMap *reg_map;
689
690
static void printbc(Method *m, intptr_t bcx) {
691
const char *name;
692
char buf[16];
693
if (m->validate_bci_from_bcp((address)bcx) < 0
694
|| !m->contains((address)bcx)) {
695
name = "???";
696
snprintf(buf, sizeof buf, "(bad)");
697
} else {
698
int bci = m->bci_from((address)bcx);
699
snprintf(buf, sizeof buf, "%d", bci);
700
name = Bytecodes::name(m->code_at(bci));
701
}
702
ResourceMark rm;
703
printf("%s : %s ==> %s\n", m->name_and_sig_as_C_string(), buf, name);
704
}
705
706
void internal_pf(uintptr_t sp, uintptr_t fp, uintptr_t pc, uintptr_t bcx) {
707
if (! fp)
708
return;
709
710
DESCRIBE_FP_OFFSET(return_addr);
711
DESCRIBE_FP_OFFSET(link);
712
DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
713
DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
714
DESCRIBE_FP_OFFSET(interpreter_frame_method);
715
DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
716
DESCRIBE_FP_OFFSET(interpreter_frame_cache);
717
DESCRIBE_FP_OFFSET(interpreter_frame_locals);
718
DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
719
DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
720
uintptr_t *p = (uintptr_t *)fp;
721
722
// We want to see all frames, native and Java. For compiled and
723
// interpreted frames we have special information that allows us to
724
// unwind them; for everything else we assume that the native frame
725
// pointer chain is intact.
726
frame this_frame((intptr_t*)sp, (intptr_t*)fp, (address)pc);
727
if (this_frame.is_compiled_frame() ||
728
this_frame.is_interpreted_frame()) {
729
frame sender = this_frame.sender(reg_map);
730
nextfp = (uintptr_t)sender.fp();
731
nextpc = (uintptr_t)sender.pc();
732
nextsp = (uintptr_t)sender.unextended_sp();
733
} else {
734
nextfp = p[frame::link_offset];
735
nextpc = p[frame::return_addr_offset];
736
nextsp = (uintptr_t)&p[frame::sender_sp_offset];
737
}
738
739
if (bcx == -1ULL)
740
bcx = p[frame::interpreter_frame_bcp_offset];
741
742
if (Interpreter::contains((address)pc)) {
743
Method* m = (Method*)p[frame::interpreter_frame_method_offset];
744
if(m && m->is_method()) {
745
printbc(m, bcx);
746
} else
747
printf("not a Method\n");
748
} else {
749
CodeBlob *cb = CodeCache::find_blob((address)pc);
750
if (cb != NULL) {
751
if (cb->is_nmethod()) {
752
ResourceMark rm;
753
nmethod* nm = (nmethod*)cb;
754
printf("nmethod %s\n", nm->method()->name_and_sig_as_C_string());
755
} else if (cb->name()) {
756
printf("CodeBlob %s\n", cb->name());
757
}
758
}
759
}
760
}
761
762
extern "C" void npf() {
763
CodeBlob *cb = CodeCache::find_blob((address)nextpc);
764
// C2 does not always chain the frame pointers when it can, instead
765
// preferring to use fixed offsets from SP, so a simple leave() does
766
// not work. Instead, it adds the frame size to SP then pops FP and
767
// LR. We have to do the same thing to get a good call chain.
768
if (cb && cb->frame_size())
769
nextfp = nextsp + wordSize * (cb->frame_size() - 2);
770
internal_pf (nextsp, nextfp, nextpc, -1);
771
}
772
773
extern "C" void pf(uintptr_t sp, uintptr_t fp, uintptr_t pc,
774
uintptr_t bcx, uintptr_t thread) {
775
if (!reg_map) {
776
reg_map = NEW_C_HEAP_OBJ(RegisterMap, mtInternal);
777
::new (reg_map) RegisterMap((JavaThread*)thread, false);
778
} else {
779
*reg_map = RegisterMap((JavaThread*)thread, false);
780
}
781
782
{
783
CodeBlob *cb = CodeCache::find_blob((address)pc);
784
if (cb && cb->frame_size())
785
fp = sp + wordSize * (cb->frame_size() - 2);
786
}
787
internal_pf(sp, fp, pc, bcx);
788
}
789
790
// support for printing out where we are in a Java method
791
// needs to be passed current fp and bcp register values
792
// prints method name, bc index and bytecode name
793
extern "C" void pm(uintptr_t fp, uintptr_t bcx) {
794
DESCRIBE_FP_OFFSET(interpreter_frame_method);
795
uintptr_t *p = (uintptr_t *)fp;
796
Method* m = (Method*)p[frame::interpreter_frame_method_offset];
797
printbc(m, bcx);
798
}
799
800
#ifndef PRODUCT
801
// This is a generic constructor which is only used by pns() in debug.cpp.
802
frame::frame(void* sp, void* fp, void* pc) {
803
init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
804
}
805
806
void frame::pd_ps() {}
807
#endif
808
809
void JavaFrameAnchor::make_walkable(JavaThread* thread) {
810
// last frame set?
811
if (last_Java_sp() == NULL) return;
812
// already walkable?
813
if (walkable()) return;
814
vmassert(Thread::current() == (Thread*)thread, "not current thread");
815
vmassert(last_Java_sp() != NULL, "not called from Java code?");
816
vmassert(last_Java_pc() == NULL, "already walkable");
817
capture_last_Java_pc();
818
vmassert(walkable(), "something went wrong");
819
}
820
821
void JavaFrameAnchor::capture_last_Java_pc() {
822
vmassert(_last_Java_sp != NULL, "no last frame set");
823
vmassert(_last_Java_pc == NULL, "already walkable");
824
_last_Java_pc = (address)_last_Java_sp[-1];
825
}
826
827