1 /*
  2  * Copyright (c) 1997, 2025, Oracle and/or its affiliates. All rights reserved.
  3  * Copyright (c) 2014, 2020, Red Hat Inc. All rights reserved.
  4  * Copyright (c) 2020, 2023, Huawei Technologies Co., Ltd. All rights reserved.
  5  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
  6  *
  7  * This code is free software; you can redistribute it and/or modify it
  8  * under the terms of the GNU General Public License version 2 only, as
  9  * published by the Free Software Foundation.
 10  *
 11  * This code is distributed in the hope that it will be useful, but WITHOUT
 12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
 14  * version 2 for more details (a copy is included in the LICENSE file that
 15  * accompanied this code).
 16  *
 17  * You should have received a copy of the GNU General Public License version
 18  * 2 along with this work; if not, write to the Free Software Foundation,
 19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 20  *
 21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 22  * or visit www.oracle.com if you need additional information or have any
 23  * questions.
 24  *
 25  */
 26 
 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_riscv.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   addr_sp = (address)_sp;
 60   address   addr_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(addr_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 
 82   if (!thread->is_in_full_stack_checked(unextended_sp)) {
 83     return false;
 84   }
 85 
 86   // an fp must be within the stack and above (but not equal) sp
 87   // second evaluation on fp+ is added to handle situation where fp is -1
 88   bool fp_safe = thread->is_in_stack_range_excl(addr_fp, addr_sp) &&
 89                  thread->is_in_full_stack_checked(addr_fp + (return_addr_offset * sizeof(void*)));
 90 
 91   // We know sp/unextended_sp are safe only fp is questionable here
 92 
 93   // If the current frame is known to the code cache then we can attempt to
 94   // to construct the sender and do some validation of it. This goes a long way
 95   // toward eliminating issues when we get in frame construction code
 96 
 97   if (_cb != nullptr) {
 98 
 99     // First check if frame is complete and tester is reliable
100     // Unfortunately we can only check frame complete for runtime stubs and nmethod
101     // other generic buffer blobs are more problematic so we just assume they are
102     // ok. adapter blobs never have a frame complete and are never ok.
103 
104     if (!_cb->is_frame_complete_at(_pc)) {
105       if (_cb->is_nmethod() || _cb->is_adapter_blob() || _cb->is_runtime_stub()) {
106         return false;
107       }
108     }
109 
110     // Could just be some random pointer within the codeBlob
111     if (!_cb->code_contains(_pc)) {
112       return false;
113     }
114 
115     // Entry frame checks
116     if (is_entry_frame()) {
117       // an entry frame must have a valid fp.
118       return fp_safe && is_entry_frame_valid(thread);
119     }
120 
121     intptr_t* sender_sp = nullptr;
122     intptr_t* sender_unextended_sp = nullptr;
123     address   sender_pc = nullptr;
124     intptr_t* saved_fp =  nullptr;
125 
126     if (is_interpreted_frame()) {
127       // fp must be safe
128       if (!fp_safe) {
129         return false;
130       }
131 
132       sender_pc = (address)this->fp()[return_addr_offset];
133       // for interpreted frames, the value below is the sender "raw" sp,
134       // which can be different from the sender unextended sp (the sp seen
135       // by the sender) because of current frame local variables
136       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
137       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
138       saved_fp = (intptr_t*) this->fp()[link_offset];
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 
154       sender_unextended_sp = sender_sp;
155       sender_pc = (address) *(sender_sp - 1);
156       saved_fp = (intptr_t*) *(sender_sp - 2);
157     }
158 
159     if (Continuation::is_return_barrier_entry(sender_pc)) {
160       // sender_pc might be invalid so check that the frame
161       // actually belongs to a Continuation.
162       if (!Continuation::is_frame_in_continuation(thread, *this)) {
163         return false;
164       }
165       // If our sender_pc is the return barrier, then our "real" sender is the continuation entry
166       frame s = Continuation::continuation_bottom_sender(thread, *this, sender_sp);
167       sender_sp = s.sp();
168       sender_pc = s.pc();
169     }
170 
171     // If the potential sender is the interpreter then we can do some more checking
172     if (Interpreter::contains(sender_pc)) {
173 
174       // fp is always saved in a recognizable place in any code we generate. However
175       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp
176       // is really a frame pointer.
177       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
178         return false;
179       }
180 
181       // construct the potential sender
182       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
183 
184       return sender.is_interpreted_frame_valid(thread);
185     }
186 
187     // We must always be able to find a recognizable pc
188     CodeBlob* sender_blob = CodeCache::find_blob(sender_pc);
189     if (sender_pc == nullptr || sender_blob == nullptr) {
190       return false;
191     }
192 
193     // Could just be some random pointer within the codeBlob
194     if (!sender_blob->code_contains(sender_pc)) {
195       return false;
196     }
197 
198     // We should never be able to see an adapter if the current frame is something from code cache
199     if (sender_blob->is_adapter_blob()) {
200       return false;
201     }
202 
203     // Could be the call_stub
204     if (StubRoutines::returns_to_call_stub(sender_pc)) {
205       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
206         return false;
207       }
208 
209       // construct the potential sender
210       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
211 
212       // Validate the JavaCallWrapper an entry frame must have
213       address jcw = (address)sender.entry_frame_call_wrapper();
214 
215       return thread->is_in_stack_range_excl(jcw, (address)sender.fp());
216     }
217 
218     nmethod* nm = sender_blob->as_nmethod_or_null();
219     if (nm != nullptr) {
220       if (nm->is_deopt_entry(sender_pc) || nm->method()->is_method_handle_intrinsic()) {
221         return false;
222       }
223     }
224 
225     // If the frame size is 0 something (or less) is bad because every nmethod has a non-zero frame size
226     // because the return address counts against the callee's frame.
227     if (sender_blob->frame_size() <= 0) {
228       assert(!sender_blob->is_nmethod(), "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     if (!sender_blob->is_nmethod()) {
237         return false;
238     }
239 
240     // Could put some more validation for the potential non-interpreted sender
241     // frame we'd create by calling sender if I could think of any. Wait for next crash in forte...
242 
243     // One idea is seeing if the sender_pc we have is one that we'd expect to call to current cb
244 
245     // We've validated the potential sender that would be created
246     return true;
247   }
248 
249   // Must be native-compiled frame. Since sender will try and use fp to find
250   // linkages it must be safe
251   if (!fp_safe) {
252     return false;
253   }
254 
255   // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
256   if ((address)this->fp()[return_addr_offset] == nullptr) { return false; }
257 
258   return true;
259 }
260 
261 void frame::patch_pc(Thread* thread, address pc) {
262   assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
263   address* pc_addr = &(((address*) sp())[-1]);
264   address pc_old = *pc_addr;
265 
266   if (TracePcPatching) {
267     tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
268                   p2i(pc_addr), p2i(pc_old), p2i(pc));
269   }
270 
271   assert(!Continuation::is_return_barrier_entry(pc_old), "return barrier");
272 
273   // Either the return address is the original one or we are going to
274   // patch in the same address that's already there.
275   assert(_pc == pc_old || pc == pc_old || pc_old == nullptr, "must be");
276   DEBUG_ONLY(address old_pc = _pc;)
277   *pc_addr = pc;
278   _pc = pc; // must be set before call to get_deopt_original_pc
279   address original_pc = get_deopt_original_pc();
280   if (original_pc != nullptr) {
281     assert(original_pc == old_pc, "expected original PC to be stored before patching");
282     _deopt_state = is_deoptimized;
283     _pc = original_pc;
284   } else {
285     _deopt_state = not_deoptimized;
286   }
287 }
288 
289 intptr_t* frame::entry_frame_argument_at(int offset) const {
290   // convert offset to index to deal with tsi
291   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
292   // Entry frame's arguments are always in relation to unextended_sp()
293   return &unextended_sp()[index];
294 }
295 
296 // locals
297 
298 void frame::interpreter_frame_set_locals(intptr_t* locs)  {
299   assert(is_interpreted_frame(), "interpreted frame expected");
300   // set relativized locals
301   ptr_at_put(interpreter_frame_locals_offset, (intptr_t) (locs - fp()));
302 }
303 
304 // sender_sp
305 
306 intptr_t* frame::interpreter_frame_sender_sp() const {
307   assert(is_interpreted_frame(), "interpreted frame expected");
308   return (intptr_t*) at(interpreter_frame_sender_sp_offset);
309 }
310 
311 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
312   assert(is_interpreted_frame(), "interpreted frame expected");
313   ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
314 }
315 
316 
317 // monitor elements
318 
319 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
320   return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
321 }
322 
323 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
324   BasicObjectLock* result = (BasicObjectLock*) at_relative(interpreter_frame_monitor_block_top_offset);
325   // make sure the pointer points inside the frame
326   assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
327   assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer");
328   return result;
329 }
330 
331 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
332   assert(is_interpreted_frame(), "interpreted frame expected");
333   // set relativized monitor_block_top
334   ptr_at_put(interpreter_frame_monitor_block_top_offset, (intptr_t*)value - fp());
335   assert(at_absolute(interpreter_frame_monitor_block_top_offset) <= interpreter_frame_monitor_block_top_offset, "");
336 }
337 
338 // Used by template based interpreter deoptimization
339 void frame::interpreter_frame_set_last_sp(intptr_t* last_sp) {
340   assert(is_interpreted_frame(), "interpreted frame expected");
341   // set relativized last_sp
342   ptr_at_put(interpreter_frame_last_sp_offset, last_sp != nullptr ? (last_sp - fp()) : 0);
343 }
344 
345 void frame::interpreter_frame_set_extended_sp(intptr_t* sp) {
346   assert(is_interpreted_frame(), "interpreted frame expected");
347   // set relativized extended_sp
348   ptr_at_put(interpreter_frame_extended_sp_offset, (sp - fp()));
349 }
350 
351 frame frame::sender_for_entry_frame(RegisterMap* map) const {
352   assert(map != nullptr, "map must be set");
353   // Java frame called from C; skip all C frames and return top C
354   // frame of that chunk as the sender
355   JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
356   assert(!entry_frame_is_first(), "next Java fp must be non zero");
357   assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
358   // Since we are walking the stack now this nested anchor is obviously walkable
359   // even if it wasn't when it was stacked.
360   jfa->make_walkable();
361   map->clear();
362   assert(map->include_argument_oops(), "should be set by clear");
363   frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
364   return fr;
365 }
366 
367 UpcallStub::FrameData* UpcallStub::frame_data_for_frame(const frame& frame) const {
368   assert(frame.is_upcall_stub_frame(), "wrong frame");
369   // need unextended_sp here, since normal sp is wrong for interpreter callees
370   return reinterpret_cast<UpcallStub::FrameData*>(
371           reinterpret_cast<address>(frame.unextended_sp()) + in_bytes(_frame_data_offset));
372 }
373 
374 bool frame::upcall_stub_frame_is_first() const {
375   assert(is_upcall_stub_frame(), "must be optimzed entry frame");
376   UpcallStub* blob = _cb->as_upcall_stub();
377   JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
378   return jfa->last_Java_sp() == nullptr;
379 }
380 
381 frame frame::sender_for_upcall_stub_frame(RegisterMap* map) const {
382   assert(map != nullptr, "map must be set");
383   UpcallStub* blob = _cb->as_upcall_stub();
384   // Java frame called from C; skip all C frames and return top C
385   // frame of that chunk as the sender
386   JavaFrameAnchor* jfa = blob->jfa_for_frame(*this);
387   assert(!upcall_stub_frame_is_first(), "must have a frame anchor to go back to");
388   assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
389   // Since we are walking the stack now this nested anchor is obviously walkable
390   // even if it wasn't when it was stacked.
391   jfa->make_walkable();
392   map->clear();
393   assert(map->include_argument_oops(), "should be set by clear");
394   frame fr(jfa->last_Java_sp(), jfa->last_Java_fp(), jfa->last_Java_pc());
395 
396   return fr;
397 }
398 
399 #if defined(ASSERT)
400 static address get_register_address_in_stub(const frame& stub_fr, VMReg reg) {
401   RegisterMap map(nullptr,
402                   RegisterMap::UpdateMap::include,
403                   RegisterMap::ProcessFrames::skip,
404                   RegisterMap::WalkContinuation::skip);
405   stub_fr.oop_map()->update_register_map(&stub_fr, &map);
406   return map.location(reg, stub_fr.sp());
407 }
408 #endif
409 
410 JavaThread** frame::saved_thread_address(const frame& f) {
411   CodeBlob* cb = f.cb();
412   assert(cb != nullptr && cb->is_runtime_stub(), "invalid frame");
413 
414   JavaThread** thread_addr;
415 #ifdef COMPILER1
416   if (cb == Runtime1::blob_for(StubId::c1_monitorenter_id) ||
417       cb == Runtime1::blob_for(StubId::c1_monitorenter_nofpu_id)) {
418     thread_addr = (JavaThread**)(f.sp() + Runtime1::runtime_blob_current_thread_offset(f));
419   } else
420 #endif
421   {
422     // c2 only saves rbp in the stub frame so nothing to do.
423     thread_addr = nullptr;
424   }
425   assert(get_register_address_in_stub(f, SharedRuntime::thread_register()) == (address)thread_addr, "wrong thread address");
426   return thread_addr;
427 }
428 
429 //------------------------------------------------------------------------------
430 // frame::sender_for_interpreter_frame
431 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
432   // SP is the raw SP from the sender after adapter or interpreter
433   // extension.
434   intptr_t* sender_sp = this->sender_sp();
435 
436   // This is the sp before any possible extension (adapter/locals).
437   intptr_t* unextended_sp = interpreter_frame_sender_sp();
438 
439 #ifdef COMPILER2
440   assert(map != nullptr, "map must be set");
441   if (map->update_map()) {
442     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
443   }
444 #endif // COMPILER2
445 
446   if (Continuation::is_return_barrier_entry(sender_pc())) {
447     if (map->walk_cont()) { // about to walk into an h-stack
448       return Continuation::top_frame(*this, map);
449     } else {
450       return Continuation::continuation_bottom_sender(map->thread(), *this, sender_sp);
451     }
452   }
453 
454   return frame(sender_sp, unextended_sp, link(), sender_pc());
455 }
456 
457 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
458   assert(is_interpreted_frame(), "Not an interpreted frame");
459   // These are reasonable sanity checks
460   if (fp() == nullptr || (intptr_t(fp()) & (wordSize-1)) != 0) {
461     return false;
462   }
463   if (sp() == nullptr || (intptr_t(sp()) & (wordSize-1)) != 0) {
464     return false;
465   }
466   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
467     return false;
468   }
469   // These are hacks to keep us out of trouble.
470   // The problem with these is that they mask other problems
471   if (fp() <= sp()) {        // this attempts to deal with unsigned comparison above
472     return false;
473   }
474 
475   // do some validation of frame elements
476 
477   // first the method
478   Method* m = safe_interpreter_frame_method();
479   // validate the method we'd find in this potential sender
480   if (!Method::is_valid_method(m)) {
481     return false;
482   }
483 
484   // stack frames shouldn't be much larger than max_stack elements
485   // this test requires the use of unextended_sp which is the sp as seen by
486   // the current frame, and not sp which is the "raw" pc which could point
487   // further because of local variables of the callee method inserted after
488   // method arguments
489   if (fp() - unextended_sp() > 1024 + m->max_stack()*Interpreter::stackElementSize) {
490     return false;
491   }
492 
493   // validate bci/bcx
494   address bcp = interpreter_frame_bcp();
495   if (m->validate_bci_from_bcp(bcp) < 0) {
496     return false;
497   }
498 
499   // validate constantPoolCache*
500   ConstantPoolCache* cp = *interpreter_frame_cache_addr();
501   if (MetaspaceObj::is_valid(cp) == false) {
502     return false;
503   }
504 
505   // validate locals
506   if (m->max_locals() > 0) {
507     address locals = (address)interpreter_frame_locals();
508     if (!thread->is_in_stack_range_incl(locals, (address)fp())) {
509       return false;
510     }
511   }
512 
513   // We'd have to be pretty unlucky to be mislead at this point
514   return true;
515 }
516 
517 BasicType frame::interpreter_frame_result(oop* oop_result, jvalue* value_result) {
518   assert(is_interpreted_frame(), "interpreted frame expected");
519   Method* method = interpreter_frame_method();
520   BasicType type = method->result_type();
521 
522   intptr_t* tos_addr = nullptr;
523   if (method->is_native()) {
524     tos_addr = (intptr_t*)sp();
525     if (type == T_FLOAT || type == T_DOUBLE) {
526       // This is because we do a push(ltos) after push(dtos) in generate_native_entry.
527       tos_addr += 2 * Interpreter::stackElementWords;
528     }
529   } else {
530     tos_addr = (intptr_t*)interpreter_frame_tos_address();
531   }
532 
533   switch (type) {
534     case T_OBJECT  :
535     case T_ARRAY   : {
536       oop obj;
537       if (method->is_native()) {
538         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
539       } else {
540         oop* obj_p = (oop*)tos_addr;
541         obj = (obj_p == nullptr) ? (oop)nullptr : *obj_p;
542       }
543       assert(Universe::is_in_heap_or_null(obj), "sanity check");
544       *oop_result = obj;
545       break;
546     }
547     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
548     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
549     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
550     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
551     case T_INT     : value_result->i = *(jint*)tos_addr; break;
552     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
553     case T_FLOAT   : {
554         value_result->f = *(jfloat*)tos_addr;
555       break;
556     }
557     case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
558     case T_VOID    : /* Nothing to do */ break;
559     default        : ShouldNotReachHere();
560   }
561 
562   return type;
563 }
564 
565 
566 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
567   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
568   return &interpreter_frame_tos_address()[index];
569 }
570 
571 #ifndef PRODUCT
572 
573 #define DESCRIBE_FP_OFFSET(name) \
574   values.describe(frame_no, fp() + frame::name##_offset, #name)
575 
576 void frame::describe_pd(FrameValues& values, int frame_no) {
577   if (is_interpreted_frame()) {
578     DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
579     DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
580     DESCRIBE_FP_OFFSET(interpreter_frame_method);
581     DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
582     DESCRIBE_FP_OFFSET(interpreter_frame_extended_sp);
583     DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
584     DESCRIBE_FP_OFFSET(interpreter_frame_cache);
585     DESCRIBE_FP_OFFSET(interpreter_frame_locals);
586     DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
587     DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
588   }
589 
590   if (is_java_frame() || Continuation::is_continuation_enterSpecial(*this)) {
591     intptr_t* ret_pc_loc;
592     intptr_t* fp_loc;
593     if (is_interpreted_frame()) {
594       ret_pc_loc = fp() + return_addr_offset;
595       fp_loc = fp();
596     } else {
597       ret_pc_loc = real_fp() - 1;
598       fp_loc = real_fp() - 2;
599     }
600     address ret_pc = *(address*)ret_pc_loc;
601     values.describe(frame_no, ret_pc_loc,
602       Continuation::is_return_barrier_entry(ret_pc) ? "return address (return barrier)" : "return address");
603     values.describe(-1, fp_loc, "saved fp", 0); // "unowned" as value belongs to sender
604   }
605 }
606 #endif
607 
608 intptr_t *frame::initial_deoptimization_info() {
609   // Not used on riscv, but we must return something.
610   return nullptr;
611 }
612 
613 #undef DESCRIBE_FP_OFFSET
614 
615 #ifndef PRODUCT
616 // This is a generic constructor which is only used by pns() in debug.cpp.
617 frame::frame(void* ptr_sp, void* ptr_fp, void* pc) : _on_heap(false) {
618   init((intptr_t*)ptr_sp, (intptr_t*)ptr_fp, (address)pc);
619 }
620 
621 #endif
622 
623 void JavaFrameAnchor::make_walkable() {
624   // last frame set?
625   if (last_Java_sp() == nullptr) { return; }
626   // already walkable?
627   if (walkable()) { return; }
628   vmassert(last_Java_sp() != nullptr, "not called from Java code?");
629   _last_Java_pc = (address)_last_Java_sp[-1];
630   vmassert(walkable(), "something went wrong");
631 }