1 /*
2 * Copyright (c) 2016, 2026, Oracle and/or its affiliates. All rights reserved.
3 * Copyright (c) 2016, 2023 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 "compiler/oopMap.hpp"
27 #include "interpreter/interpreter.hpp"
28 #include "memory/resourceArea.hpp"
29 #include "memory/universe.hpp"
30 #include "oops/markWord.hpp"
31 #include "oops/oop.inline.hpp"
32 #include "runtime/frame.inline.hpp"
33 #include "runtime/handles.inline.hpp"
34 #include "runtime/javaCalls.hpp"
35 #include "runtime/monitorChunk.hpp"
36 #include "runtime/os.inline.hpp"
37 #include "runtime/signature.hpp"
38 #include "runtime/stubCodeGenerator.hpp"
39 #include "runtime/stubRoutines.hpp"
40 #include "vmreg_s390.inline.hpp"
41 #ifdef COMPILER1
42 #include "c1/c1_Runtime1.hpp"
43 #include "runtime/vframeArray.hpp"
44 #endif
45
46 // Major contributions by Aha, AS.
47
48 #ifdef ASSERT
49 void RegisterMap::check_location_valid() {
50 }
51 #endif // ASSERT
52
53
54 // Profiling/safepoint support
55
56 bool frame::safe_for_sender(JavaThread *thread) {
57 if (is_heap_frame()) {
58 return true;
59 }
60
61 address sp = (address)_sp;
62 address fp = (address)_fp;
63 address unextended_sp = (address)_unextended_sp;
64
65 // consider stack guards when trying to determine "safe" stack pointers
66 // sp must be within the usable part of the stack (not in guards)
67 if (!thread->is_in_usable_stack(sp)) {
68 return false;
69 }
70
71 // Unextended sp must be within the stack
72 if (!thread->is_in_full_stack_checked(unextended_sp)) {
73 return false;
74 }
75
76 // An fp must be within the stack and above (but not equal) sp.
77 bool fp_safe = thread->is_in_stack_range_excl(fp, sp);
78 // An interpreter fp must be fp_safe.
79 // Moreover, it must be at a distance at least the size of the z_ijava_state structure.
80 bool fp_interp_safe = fp_safe && ((fp - sp) >= z_ijava_state_size);
81
82 // We know sp/unextended_sp are safe, only fp is questionable here
83
84 // If the current frame is known to the code cache then we can attempt to
85 // construct the sender and do some validation of it. This goes a long way
86 // toward eliminating issues when we get in frame construction code
87
88 if (_cb != nullptr ) {
89
90 // First check if the frame is complete and the test is reliable.
91 // Unfortunately we can only check frame completeness for runtime stubs.
92 // Other generic buffer blobs are more problematic so we just assume they are OK.
93 // Adapter blobs never have a complete frame and are never OK.
94 // nmethods should be OK on s390.
95 if (!_cb->is_frame_complete_at(_pc)) {
96 if (_cb->is_adapter_blob() || _cb->is_runtime_stub()) {
97 return false;
98 }
99 }
100
101 // Could just be some random pointer within the codeBlob.
102 if (!_cb->code_contains(_pc)) {
103 return false;
104 }
105
106 // Entry frame checks
107 if (is_entry_frame()) {
108 // An entry frame must have a valid fp.
109 return fp_safe && is_entry_frame_valid(thread);
110 }
111
112 if (is_interpreted_frame() && !fp_interp_safe) {
113 return false;
114 }
115
116 // At this point, there still is a chance that fp_safe is false.
117 // In particular, fp might be null. So let's check and
118 // bail out before we actually dereference from fp.
119 if (!fp_safe) {
120 return false;
121 }
122
123 z_common_abi* sender_abi = (z_common_abi*)fp;
124 intptr_t* sender_sp = (intptr_t*) fp;
125 address sender_pc = (address) sender_abi->return_pc;
126
127 if (Continuation::is_return_barrier_entry(sender_pc)) {
128 // If our sender_pc is the return barrier, then our "real" sender is the continuation entry
129 frame s = Continuation::continuation_bottom_sender(thread, *this, sender_sp);
130 sender_sp = s.sp();
131 sender_pc = s.pc();
132 }
133
134 // We must always be able to find a recognizable pc.
135 CodeBlob* sender_blob = CodeCache::find_blob(sender_pc);
136 if (sender_blob == nullptr) {
137 return false;
138 }
139
140 // It should be safe to construct the sender though it might not be valid.
141
142 frame sender(sender_sp, sender_pc);
143
144 // Do we have a valid fp?
145 address sender_fp = (address) sender.fp();
146
147 // sender_fp must be within the stack and above (but not
148 // equal) current frame's fp.
149 if (!thread->is_in_stack_range_excl(sender_fp, fp)) {
150 return false;
151 }
152
153 // If the potential sender is the interpreter then we can do some more checking.
154 if (Interpreter::contains(sender_pc)) {
155 return sender.is_interpreted_frame_valid(thread);
156 }
157
158 // Could just be some random pointer within the codeBlob.
159 if (!sender.cb()->code_contains(sender_pc)) {
160 return false;
161 }
162
163 // We should never be able to see an adapter if the current frame is something from code cache.
164 if (sender_blob->is_adapter_blob()) {
165 return false;
166 }
167
168 if (sender.is_entry_frame()) {
169 return sender.is_entry_frame_valid(thread);
170 }
171
172 // Frame size is always greater than zero. If the sender frame size is zero or less,
173 // something is really weird and we better give up.
174 if (sender_blob->frame_size() <= 0) {
175 return false;
176 }
177
178 return true;
179 }
180
181 // Must be native-compiled frame. Since sender will try and use fp to find
182 // linkages it must be safe
183
184 if (!fp_safe) {
185 return false;
186 }
187
188 return true;
189 }
190
191 bool frame::is_interpreted_frame() const {
192 return Interpreter::contains(pc());
193 }
194
195 // locals
196
197 void frame::interpreter_frame_set_locals(intptr_t* locs) {
198 assert(is_interpreted_frame(), "interpreted frame expected");
199 // set relativized locals
200 *addr_at(_z_ijava_idx(locals)) = (intptr_t) (locs - fp());
201 }
202
203 // sender_sp
204
205 intptr_t* frame::interpreter_frame_sender_sp() const {
206 assert(is_interpreted_frame(), "interpreted frame expected");
207 return (intptr_t*)at(_z_ijava_idx(sender_sp));
208 }
209
210 frame frame::sender_for_entry_frame(RegisterMap *map) const {
211 assert(map != nullptr, "map must be set");
212 // Java frame called from C. Skip all C frames and return top C
213 // frame of that chunk as the sender.
214 JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
215
216 assert(!entry_frame_is_first(), "next Java sp must be non zero");
217 assert(jfa->last_Java_sp() > _sp, "must be above this frame on stack");
218
219 map->clear();
220
221 assert(map->include_argument_oops(), "should be set by clear");
222
223 if (jfa->last_Java_pc() != nullptr) {
224 frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());
225 return fr;
226 }
227 // Last_java_pc is not set if we come here from compiled code.
228 frame fr(jfa->last_Java_sp());
229 return fr;
230 }
231
232 UpcallStub::FrameData* UpcallStub::frame_data_for_frame(const frame& frame) const {
233 assert(frame.is_upcall_stub_frame(), "wrong frame");
234 // need unextended_sp here, since normal sp is wrong for interpreter callees
235 return reinterpret_cast<UpcallStub::FrameData*>(
236 reinterpret_cast<address>(frame.unextended_sp()) + in_bytes(_frame_data_offset));
237 }
238
239 bool frame::upcall_stub_frame_is_first() const {
240 assert(is_upcall_stub_frame(), "must be optimized entry frame");
241 UpcallStub* blob = _cb->as_upcall_stub();
242 JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
243 return jfa->last_Java_sp() == nullptr;
244 }
245
246 frame frame::sender_for_upcall_stub_frame(RegisterMap* map) const {
247 assert(map != nullptr, "map must be set");
248 UpcallStub* blob = _cb->as_upcall_stub();
249 // Java frame called from C; skip all C frames and return top C
250 // frame of that chunk as the sender
251 JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
252 assert(!upcall_stub_frame_is_first(), "must have a frame anchor to go back to");
253 assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
254 map->clear();
255 assert(map->include_argument_oops(), "should be set by clear");
256 frame fr(jfa->last_Java_sp(), jfa->last_Java_pc());
257
258 return fr;
259
260 }
261
262 #if defined(ASSERT)
263 static address get_register_address_in_stub(const frame& stub_fr, VMReg reg) {
264 RegisterMap map(nullptr,
265 RegisterMap::UpdateMap::include,
266 RegisterMap::ProcessFrames::skip,
267 RegisterMap::WalkContinuation::skip);
268 stub_fr.oop_map()->update_register_map(&stub_fr, &map);
269 return map.location(reg, stub_fr.sp());
270 }
271 #endif
272
273 JavaThread** frame::saved_thread_address(const frame& f) {
274 CodeBlob* cb = f.cb();
275 assert(cb != nullptr && cb->is_runtime_stub(), "invalid frame");
276
277 JavaThread** thread_addr;
278 #ifdef COMPILER1
279 if (cb == Runtime1::blob_for(StubId::c1_monitorenter_id) ||
280 cb == Runtime1::blob_for(StubId::c1_monitorenter_nofpu_id)) {
281 thread_addr = (JavaThread**)(f.sp() + Runtime1::runtime_blob_current_thread_offset(f));
282 } else
283 #endif
284 {
285 // c2 only saves Z_fp in the stub frame so nothing to do.
286 thread_addr = nullptr;
287 }
288 assert(get_register_address_in_stub(f, SharedRuntime::thread_register()) == (address)thread_addr, "wrong thread address");
289 return thread_addr;
290 }
291
292 frame frame::sender_for_interpreter_frame(RegisterMap *map) const {
293 // This is the sp before any possible extension (adapter/locals).
294 intptr_t* unextended_sp = interpreter_frame_sender_sp();
295 address sender_pc = this->sender_pc();
296 if (Continuation::is_return_barrier_entry(sender_pc)) {
297 if (map->walk_cont()) { // about to walk into an h-stack
298 return Continuation::top_frame(*this, map);
299 } else {
300 return Continuation::continuation_bottom_sender(map->thread(), *this, sender_sp());
301 }
302 }
303
304 return frame(sender_sp(), sender_pc, unextended_sp);
305 }
306
307 void frame::patch_pc(Thread* thread, address pc) {
308 assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
309 address* pc_addr = (address*)&(own_abi()->return_pc);
310
311 if (TracePcPatching) {
312 tty->print_cr("patch_pc at address " PTR_FORMAT " [" PTR_FORMAT " -> " PTR_FORMAT "] ",
313 p2i(&((address*) _sp)[-1]), p2i(((address*) _sp)[-1]), p2i(pc));
314 }
315 assert(!Continuation::is_return_barrier_entry(*pc_addr), "return barrier");
316 assert(_pc == *pc_addr || pc == *pc_addr || nullptr == *pc_addr,
317 "must be (pc: " INTPTR_FORMAT " _pc: " INTPTR_FORMAT " pc_addr: " INTPTR_FORMAT
318 " *pc_addr: " INTPTR_FORMAT " sp: " INTPTR_FORMAT ")",
319 p2i(pc), p2i(_pc), p2i(pc_addr), p2i(*pc_addr), p2i(sp()));
320 DEBUG_ONLY(address old_pc = _pc;)
321 own_abi()->return_pc = (uint64_t)pc;
322 _pc = pc; // must be set before call to get_deopt_original_pc
323 address original_pc = get_deopt_original_pc();
324 if (original_pc != nullptr) {
325 // assert(original_pc == _pc, "expected original to be stored before patching");
326 _deopt_state = is_deoptimized;
327 _pc = original_pc;
328 } else {
329 _deopt_state = not_deoptimized;
330 }
331 assert(!is_compiled_frame() || !_cb->as_nmethod()->is_deopt_entry(_pc), "must be");
332
333 #ifdef ASSERT
334 {
335 frame f(sp(), unextended_sp(), fp(), pc, cb(), oop_map(), is_heap_frame());
336 assert(f.is_deoptimized_frame() == this->is_deoptimized_frame() && f.pc() == this->pc() && f.raw_pc() == this->raw_pc(),
337 "must be (f.is_deoptimized_frame(): %d this->is_deoptimized_frame(): %d "
338 "f.pc(): " INTPTR_FORMAT " this->pc(): " INTPTR_FORMAT " f.raw_pc(): " INTPTR_FORMAT " this->raw_pc(): " INTPTR_FORMAT ")",
339 f.is_deoptimized_frame(), this->is_deoptimized_frame(), p2i(f.pc()), p2i(this->pc()), p2i(f.raw_pc()), p2i(this->raw_pc()));
340 }
341 #endif
342 }
343
344 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
345 assert(is_interpreted_frame(), "Not an interpreted frame");
346 // These are reasonable sanity checks
347 if (fp() == nullptr || (intptr_t(fp()) & (wordSize-1)) != 0) {
348 return false;
349 }
350 if (sp() == nullptr || (intptr_t(sp()) & (wordSize-1)) != 0) {
351 return false;
352 }
353 int min_frame_slots = (z_common_abi_size + z_ijava_state_size) / sizeof(intptr_t);
354 if (fp() - min_frame_slots < sp()) {
355 return false;
356 }
357 // These are hacks to keep us out of trouble.
358 // The problem with these is that they mask other problems
359 if (fp() <= sp()) { // this attempts to deal with unsigned comparison above
360 return false;
361 }
362
363 // do some validation of frame elements
364
365 // first the method
366 // Need to use "unchecked" versions to avoid "z_istate_magic_number" assertion.
367 Method* m = (Method*)(ijava_state_unchecked()->method);
368
369 // validate the method we'd find in this potential sender
370 if (!Method::is_valid_method(m)) return false;
371
372 // stack frames shouldn't be much larger than max_stack elements
373 // this test requires the use of unextended_sp which is the sp as seen by
374 // the current frame, and not sp which is the "raw" pc which could point
375 // further because of local variables of the callee method inserted after
376 // method arguments
377 if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
378 return false;
379 }
380
381 // validate bci/bcx
382 address bcp = (address)(ijava_state_unchecked()->bcp);
383 if (m->validate_bci_from_bcp(bcp) < 0) {
384 return false;
385 }
386
387 // validate constantPoolCache*
388 ConstantPoolCache* cp = (ConstantPoolCache*)(ijava_state_unchecked()->cpoolCache);
389 if (MetaspaceObj::is_valid(cp) == false) return false;
390
391 // validate locals
392 address locals = (address)interpreter_frame_locals();
393 return thread->is_in_stack_range_incl(locals, (address)fp());
394 }
395
396 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
397 assert(is_interpreted_frame(), "interpreted frame expected");
398 Method* method = interpreter_frame_method();
399 BasicType type = method->result_type();
400
401 if (method->is_native()) {
402 address lresult = (address)&(ijava_state()->lresult);
403 address fresult = (address)&(ijava_state()->fresult);
404
405 switch (type) {
406 case T_OBJECT:
407 case T_ARRAY: {
408 *oop_result = cast_to_oop((void*) ijava_state()->oop_tmp);
409 break;
410 }
411 // We use std/stfd to store the values.
412 case T_BOOLEAN : value_result->z = (jboolean) *(unsigned long*)lresult; break;
413 case T_INT : value_result->i = (jint) *(long*)lresult; break;
414 case T_CHAR : value_result->c = (jchar) *(unsigned long*)lresult; break;
415 case T_SHORT : value_result->s = (jshort) *(long*)lresult; break;
416 case T_BYTE : value_result->z = (jbyte) *(long*)lresult; break;
417 case T_LONG : value_result->j = (jlong) *(long*)lresult; break;
418 case T_FLOAT : value_result->f = (jfloat) *(float*)fresult; break;
419 case T_DOUBLE : value_result->d = (jdouble) *(double*)fresult; break;
420 case T_VOID : break; // Nothing to do.
421 default : ShouldNotReachHere();
422 }
423 } else {
424 intptr_t* tos_addr = interpreter_frame_tos_address();
425 switch (type) {
426 case T_OBJECT:
427 case T_ARRAY: {
428 oop obj = *(oop*)tos_addr;
429 assert(Universe::is_in_heap_or_null(obj), "sanity check");
430 *oop_result = obj;
431 break;
432 }
433 case T_BOOLEAN : value_result->z = (jboolean) *(jint*)tos_addr; break;
434 case T_BYTE : value_result->b = (jbyte) *(jint*)tos_addr; break;
435 case T_CHAR : value_result->c = (jchar) *(jint*)tos_addr; break;
436 case T_SHORT : value_result->s = (jshort) *(jint*)tos_addr; break;
437 case T_INT : value_result->i = *(jint*)tos_addr; break;
438 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
439 case T_FLOAT : value_result->f = *(jfloat*)tos_addr; break;
440 case T_DOUBLE : value_result->d = *(jdouble*)tos_addr; break;
441 case T_VOID : break; // Nothing to do.
442 default : ShouldNotReachHere();
443 }
444 }
445
446 return type;
447 }
448
449
450 // Dump all frames starting a given C stack-pointer.
451 // Use max_frames to limit the number of traced frames.
452 void frame::back_trace(outputStream* st, intptr_t* start_sp, intptr_t* top_pc, unsigned long flags, int max_frames) {
453
454 static char buf[ 150 ];
455
456 bool print_outgoing_arguments = flags & 0x1;
457 bool print_istate_pointers = flags & 0x2;
458 int num = 0;
459
460 intptr_t* current_sp = (intptr_t*) start_sp;
461 int last_num_jargs = 0;
462 int frame_type = 0;
463 int last_frame_type = 0;
464
465 while (current_sp) {
466 intptr_t* current_fp = (intptr_t*) *current_sp;
467 address current_pc = (num == 0)
468 ? (address) top_pc
469 : (address) *((intptr_t*)(((address) current_sp) + _z_abi(return_pc)));
470
471 if ((intptr_t*) current_fp != nullptr && (intptr_t*) current_fp <= current_sp) {
472 st->print_cr("ERROR: corrupt stack");
473 return;
474 }
475
476 st->print("#%-3d ", num);
477 const char* type_name = " ";
478 const char* function_name = nullptr;
479
480 // Detect current frame's frame_type, default to 'C frame'.
481 frame_type = 0;
482
483 CodeBlob* blob = nullptr;
484
485 if (Interpreter::contains(current_pc)) {
486 frame_type = 1;
487 } else if (StubRoutines::contains(current_pc)) {
488 if (StubRoutines::returns_to_call_stub(current_pc)) {
489 frame_type = 2;
490 } else {
491 frame_type = 4;
492 type_name = "stu";
493 StubCodeDesc* desc = StubCodeDesc::desc_for (current_pc);
494 if (desc) {
495 function_name = desc->name();
496 } else {
497 function_name = "unknown stub";
498 }
499 }
500 } else if (CodeCache::contains(current_pc)) {
501 blob = CodeCache::find_blob(current_pc);
502 if (blob) {
503 if (blob->is_nmethod()) {
504 frame_type = 3;
505 } else if (blob->is_deoptimization_stub()) {
506 frame_type = 4;
507 type_name = "deo";
508 function_name = "deoptimization blob";
509 } else if (blob->is_uncommon_trap_stub()) {
510 frame_type = 4;
511 type_name = "uct";
512 function_name = "uncommon trap blob";
513 } else if (blob->is_exception_stub()) {
514 frame_type = 4;
515 type_name = "exc";
516 function_name = "exception blob";
517 } else if (blob->is_safepoint_stub()) {
518 frame_type = 4;
519 type_name = "saf";
520 function_name = "safepoint blob";
521 } else if (blob->is_runtime_stub()) {
522 frame_type = 4;
523 type_name = "run";
524 function_name = ((RuntimeStub *)blob)->name();
525 } else if (blob->is_method_handles_adapter_blob()) {
526 frame_type = 4;
527 type_name = "mha";
528 function_name = "method handles adapter blob";
529 } else {
530 frame_type = 4;
531 type_name = "blo";
532 function_name = "unknown code blob";
533 }
534 } else {
535 frame_type = 4;
536 type_name = "blo";
537 function_name = "unknown code blob";
538 }
539 }
540
541 st->print("sp=" PTR_FORMAT " ", p2i(current_sp));
542
543 if (frame_type == 0) {
544 current_pc = (address) *((intptr_t*)(((address) current_sp) + _z_abi(gpr14)));
545 }
546
547 st->print("pc=" PTR_FORMAT " ", p2i(current_pc));
548 st->print(" ");
549
550 switch (frame_type) {
551 case 0: // C frame:
552 {
553 st->print(" ");
554 if (current_pc == nullptr) {
555 st->print("? ");
556 } else {
557 // name
558 int func_offset;
559 char demangled_name[256];
560 int demangled_name_len = 256;
561 if (os::dll_address_to_function_name(current_pc, demangled_name, demangled_name_len, &func_offset)) {
562 demangled_name[demangled_name_len-1] = '\0';
563 st->print(func_offset == -1 ? "%s " : "%s+0x%x", demangled_name, func_offset);
564 } else {
565 st->print("? ");
566 }
567 }
568 }
569 break;
570
571 case 1: // interpreter frame:
572 {
573 st->print(" i ");
574
575 if (last_frame_type != 1) last_num_jargs = 8;
576
577 // name
578 Method* method = *(Method**)((address)current_fp + _z_ijava_state_neg(method));
579 if (method) {
580 ResourceMark rm;
581 if (method->is_synchronized()) st->print("synchronized ");
582 if (method->is_static()) st->print("static ");
583 if (method->is_native()) st->print("native ");
584 method->name_and_sig_as_C_string(buf, sizeof(buf));
585 st->print("%s ", buf);
586 }
587 else
588 st->print("? ");
589
590 intptr_t* tos = (intptr_t*) *(intptr_t*)((address)current_fp + _z_ijava_state_neg(esp));
591 if (print_istate_pointers) {
592 st->cr();
593 st->print(" ");
594 st->print("ts=" PTR_FORMAT " ", p2i(tos));
595 }
596
597 // Dump some Java stack slots.
598 if (print_outgoing_arguments) {
599 if (method->is_native()) {
600 #ifdef ASSERT
601 intptr_t* cargs = (intptr_t*) (((address)current_sp) + _z_abi(carg_1));
602 for (int i = 0; i < last_num_jargs; i++) {
603 // Cargs is not prepushed.
604 st->cr();
605 st->print(" ");
606 st->print(PTR_FORMAT, *(cargs));
607 cargs++;
608 }
609 #endif /* ASSERT */
610 }
611 else {
612 if (tos) {
613 for (int i = 0; i < last_num_jargs; i++) {
614 // tos+0 is prepushed, ignore.
615 tos++;
616 if (tos >= (intptr_t *)((address)current_fp + _z_ijava_state_neg(monitors)))
617 break;
618 st->cr();
619 st->print(" ");
620 st->print(PTR_FORMAT " %+.3e %+.3le", *(tos), *(float*)(tos), *(double*)(tos));
621 }
622 }
623 }
624 last_num_jargs = method->size_of_parameters();
625 }
626 }
627 break;
628
629 case 2: // entry frame:
630 {
631 st->print("v2i ");
632
633 // name
634 st->print("call stub");
635 }
636 break;
637
638 case 3: // compiled frame:
639 {
640 st->print(" c ");
641
642 // name
643 Method* method = ((nmethod *)blob)->method();
644 if (method) {
645 ResourceMark rm;
646 method->name_and_sig_as_C_string(buf, sizeof(buf));
647 st->print("%s ", buf);
648 }
649 else
650 st->print("? ");
651 }
652 break;
653
654 case 4: // named frames
655 {
656 st->print("%s ", type_name);
657
658 // name
659 if (function_name)
660 st->print("%s", function_name);
661 }
662 break;
663
664 default:
665 break;
666 }
667
668 st->cr();
669 st->flush();
670
671 current_sp = current_fp;
672 last_frame_type = frame_type;
673 num++;
674 // Check for maximum # of frames, and stop when reached.
675 if (max_frames > 0 && --max_frames == 0)
676 break;
677 }
678
679 }
680
681 // Convenience function for calls from the debugger.
682
683 extern "C" void bt(intptr_t* start_sp,intptr_t* top_pc) {
684 frame::back_trace(tty,start_sp, top_pc, 0);
685 }
686
687 extern "C" void bt_full(intptr_t* start_sp,intptr_t* top_pc) {
688 frame::back_trace(tty,start_sp, top_pc, (unsigned long)(long)-1);
689 }
690
691
692 // Function for tracing a limited number of frames.
693 // Use this one if you only need to see the "top of stack" frames.
694 extern "C" void bt_max(intptr_t *start_sp, intptr_t *top_pc, int max_frames) {
695 frame::back_trace(tty, start_sp, top_pc, 0, max_frames);
696 }
697
698 #if !defined(PRODUCT)
699 #define DESCRIBE_ADDRESS_MAGIC(name) \
700 values.describe(frame_no, (intptr_t*)&ijava_state()->name, #name "_number_debug");
701
702 #define DESCRIBE_ADDRESS(name) \
703 values.describe(frame_no, (intptr_t*)&ijava_state()->name, #name);
704
705 void frame::describe_pd(FrameValues& values, int frame_no) {
706 if (is_interpreted_frame()) {
707 // Describe z_ijava_state elements.
708 DESCRIBE_ADDRESS(method);
709 DESCRIBE_ADDRESS(mirror);
710 DESCRIBE_ADDRESS(locals);
711 DESCRIBE_ADDRESS(monitors);
712 DESCRIBE_ADDRESS(cpoolCache);
713 DESCRIBE_ADDRESS(bcp);
714 DESCRIBE_ADDRESS(esp);
715 DESCRIBE_ADDRESS(mdx);
716 DESCRIBE_ADDRESS(top_frame_sp);
717 DESCRIBE_ADDRESS(sender_sp);
718 DESCRIBE_ADDRESS(oop_tmp);
719 DESCRIBE_ADDRESS(lresult);
720 DESCRIBE_ADDRESS(fresult);
721 DESCRIBE_ADDRESS_MAGIC(magic);
722 }
723
724 if (is_java_frame() || Continuation::is_continuation_enterSpecial(*this)) {
725 intptr_t* ret_pc_loc = (intptr_t*)&own_abi()->return_pc;
726 address ret_pc = *(address*)ret_pc_loc;
727 values.describe(frame_no, ret_pc_loc,
728 Continuation::is_return_barrier_entry(ret_pc) ? "return address (return barrier)" : "return address");
729 }
730 }
731
732 #endif // !PRODUCT
733
734 intptr_t *frame::initial_deoptimization_info() {
735 // `this` is the caller of the deoptee. We want to trim it, if compiled, to
736 // unextended_sp. This is necessary if the deoptee frame is the bottom frame
737 // of a continuation on stack (more frames could be in a StackChunk) as it
738 // will pop its stack args. Otherwise the recursion in
739 // FreezeBase::recurse_freeze_java_frame() would not stop at the bottom frame.
740 return is_compiled_frame() ? unextended_sp() : sp();
741 }
742
743 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
744 return interpreter_frame_monitors();
745 }
746
747 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
748 return &interpreter_frame_tos_address()[offset];
749 }
750