< prev index next >

src/hotspot/cpu/x86/frame_x86.cpp

Print this page

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 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/method.hpp"
 32 #include "oops/oop.inline.hpp"
 33 #include "prims/methodHandles.hpp"

 34 #include "runtime/frame.inline.hpp"
 35 #include "runtime/handles.inline.hpp"
 36 #include "runtime/javaCalls.hpp"
 37 #include "runtime/monitorChunk.hpp"
 38 #include "runtime/signature.hpp"
 39 #include "runtime/stackWatermarkSet.hpp"
 40 #include "runtime/stubCodeGenerator.hpp"
 41 #include "runtime/stubRoutines.hpp"
 42 #include "vmreg_x86.inline.hpp"
 43 #include "utilities/formatBuffer.hpp"
 44 #ifdef COMPILER1
 45 #include "c1/c1_Runtime1.hpp"
 46 #include "runtime/vframeArray.hpp"
 47 #endif
 48 
 49 #ifdef ASSERT
 50 void RegisterMap::check_location_valid() {
 51 }
 52 #endif
 53 

129       // must be some sort of compiled/runtime frame
130       // fp does not have to be safe (although it could be check for c1?)
131 
132       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
133       if (_cb->frame_size() <= 0) {
134         return false;
135       }
136 
137       sender_sp = _unextended_sp + _cb->frame_size();
138       // Is sender_sp safe?
139       if (!thread->is_in_full_stack_checked((address)sender_sp)) {
140         return false;
141       }
142       sender_unextended_sp = sender_sp;
143       // On Intel the return_address is always the word on the stack
144       sender_pc = (address) *(sender_sp-1);
145       // Note: frame::sender_sp_offset is only valid for compiled frame
146       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
147     }
148 



149 
150     // If the potential sender is the interpreter then we can do some more checking
151     if (Interpreter::contains(sender_pc)) {
152 
153       // ebp is always saved in a recognizable place in any code we generate. However
154       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
155       // is really a frame pointer.
156 
157       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
158         return false;
159       }
160 
161       // construct the potential sender
162 
163       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
164 
165       return sender.is_interpreted_frame_valid(thread);
166 
167     }
168 

244 
245   if (!fp_safe) {
246     return false;
247   }
248 
249   // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
250 
251   if ( (address) this->fp()[return_addr_offset] == NULL) return false;
252 
253 
254   // could try and do some more potential verification of native frame if we could think of some...
255 
256   return true;
257 
258 }
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   if (TracePcPatching) {
265     tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
266                   p2i(pc_addr), p2i(*pc_addr), p2i(pc));
267   }
268   // Either the return address is the original one or we are going to
269   // patch in the same address that's already there.
270   assert(_pc == *pc_addr || pc == *pc_addr, "must be");




271   *pc_addr = pc;

272   address original_pc = CompiledMethod::get_deopt_original_pc(this);
273   if (original_pc != NULL) {
274     assert(original_pc == _pc, "expected original PC to be stored before patching");
275     _deopt_state = is_deoptimized;
276     // leave _pc as is
277   } else {
278     _deopt_state = not_deoptimized;
279     _pc = pc;
280   }
281 }
282 
283 bool frame::is_interpreted_frame() const  {
284   return Interpreter::contains(pc());
285 }
286 
287 int frame::frame_size(RegisterMap* map) const {
288   frame sender = this->sender(map);
289   return sender.sp() - sp();


290 }
291 
292 intptr_t* frame::entry_frame_argument_at(int offset) const {
293   // convert offset to index to deal with tsi
294   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
295   // Entry frame's arguments are always in relation to unextended_sp()
296   return &unextended_sp()[index];
297 }
298 
299 // sender_sp
300 
301 intptr_t* frame::interpreter_frame_sender_sp() const {
302   assert(is_interpreted_frame(), "interpreted frame expected");
303   return (intptr_t*) at(interpreter_frame_sender_sp_offset);
304 }
305 
306 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
307   assert(is_interpreted_frame(), "interpreted frame expected");
308   ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
309 }
310 
311 
312 // monitor elements
313 
314 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
315   return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
316 }
317 




318 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
319   BasicObjectLock* result = (BasicObjectLock*) *addr_at(interpreter_frame_monitor_block_top_offset);
320   // make sure the pointer points inside the frame
321   assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
322   assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer");
323   return result;
324 }
325 
326 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
327   *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
328 }
329 
330 // Used by template based interpreter deoptimization
331 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
332     *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
333 }
334 
335 frame frame::sender_for_entry_frame(RegisterMap* map) const {
336   assert(map != NULL, "map must be set");
337   // Java frame called from C; skip all C frames and return top C
338   // frame of that chunk as the sender
339   JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
340   assert(!entry_frame_is_first(), "next Java fp must be non zero");
341   assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
342   // Since we are walking the stack now this nested anchor is obviously walkable

388 
389   return fr;
390 }
391 
392 //------------------------------------------------------------------------------
393 // frame::verify_deopt_original_pc
394 //
395 // Verifies the calculated original PC of a deoptimization PC for the
396 // given unextended SP.
397 #ifdef ASSERT
398 void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {
399   frame fr;
400 
401   // This is ugly but it's better than to change {get,set}_original_pc
402   // to take an SP value as argument.  And it's only a debugging
403   // method anyway.
404   fr._unextended_sp = unextended_sp;
405 
406   address original_pc = nm->get_original_pc(&fr);
407   assert(nm->insts_contains_inclusive(original_pc),
408          "original PC must be in the main code section of the the compiled method (or must be immediately following it)");
409 }
410 #endif
411 
412 //------------------------------------------------------------------------------
413 // frame::adjust_unextended_sp
414 #ifdef ASSERT
415 void frame::adjust_unextended_sp() {
416   // On x86, sites calling method handle intrinsics and lambda forms are treated
417   // as any other call site. Therefore, no special action is needed when we are
418   // returning to any of these call sites.
419 
420   if (_cb != NULL) {
421     CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();
422     if (sender_cm != NULL) {
423       // If the sender PC is a deoptimization point, get the original PC.
424       if (sender_cm->is_deopt_entry(_pc) ||
425           sender_cm->is_deopt_mh_entry(_pc)) {
426         verify_deopt_original_pc(sender_cm, _unextended_sp);
427       }
428     }
429   }
430 }
431 #endif
432 
433 //------------------------------------------------------------------------------
434 // frame::update_map_with_saved_link
435 void frame::update_map_with_saved_link(RegisterMap* map, intptr_t** link_addr) {
436   // The interpreter and compiler(s) always save EBP/RBP in a known
437   // location on entry. We must record where that location is
438   // so this if EBP/RBP was live on callout from c2 we can find
439   // the saved copy no matter what it called.
440 
441   // Since the interpreter always saves EBP/RBP if we record where it is then
442   // we don't have to always save EBP/RBP on entry and exit to c2 compiled
443   // code, on entry will be enough.
444   map->set_location(rbp->as_VMReg(), (address) link_addr);
445 #ifdef AMD64
446   // this is weird "H" ought to be at a higher address however the
447   // oopMaps seems to have the "H" regs at the same address and the
448   // vanilla register.
449   // XXXX make this go away
450   if (true) {
451     map->set_location(rbp->as_VMReg()->next(), (address) link_addr);
452   }
453 #endif // AMD64
454 }
455 
456 
457 //------------------------------------------------------------------------------
458 // frame::sender_for_interpreter_frame
459 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
460   // SP is the raw SP from the sender after adapter or interpreter
461   // extension.
462   intptr_t* sender_sp = this->sender_sp();
463 
464   // This is the sp before any possible extension (adapter/locals).
465   intptr_t* unextended_sp = interpreter_frame_sender_sp();

466 
467 #if COMPILER2_OR_JVMCI
468   if (map->update_map()) {
469     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
470   }
471 #endif // COMPILER2_OR_JVMCI
472 
473   return frame(sender_sp, unextended_sp, link(), sender_pc());
474 }
475 
476 
477 //------------------------------------------------------------------------------
478 // frame::sender_for_compiled_frame
479 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
480   assert(map != NULL, "map must be set");
481 
482   // frame owned by optimizing compiler
483   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
484   intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
485   intptr_t* unextended_sp = sender_sp;
486 
487   // On Intel the return_address is always the word on the stack
488   address sender_pc = (address) *(sender_sp-1);
489 
490   // This is the saved value of EBP which may or may not really be an FP.
491   // It is only an FP if the sender is an interpreter frame (or C1?).
492   intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
493 
494   if (map->update_map()) {
495     // Tell GC to use argument oopmaps for some runtime stubs that need it.
496     // For C1, the runtime stub might not have oop maps, so set this flag
497     // outside of update_register_map.
498     map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
499     if (_cb->oop_maps() != NULL) {
500       OopMapSet::update_register_map(this, map);
501     }
502 
503     // Since the prolog does the save and restore of EBP there is no oopmap
504     // for it so we must fill in its location as if there was an oopmap entry
505     // since if our caller was compiled code there could be live jvm state in it.
506     update_map_with_saved_link(map, saved_fp_addr);
507   }
508 
509   assert(sender_sp != sp(), "must have changed");
510   return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
511 }
512 
513 
514 //------------------------------------------------------------------------------
515 // frame::sender_raw
516 frame frame::sender_raw(RegisterMap* map) const {
517   // Default is we done have to follow them. The sender_for_xxx will
518   // update it accordingly
519   map->set_include_argument_oops(false);
520 
521   if (is_entry_frame())        return sender_for_entry_frame(map);
522   if (is_optimized_entry_frame()) return sender_for_optimized_entry_frame(map);
523   if (is_interpreted_frame())  return sender_for_interpreter_frame(map);
524   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
525 
526   if (_cb != NULL) {
527     return sender_for_compiled_frame(map);
528   }
529   // Must be native-compiled frame, i.e. the marshaling code for native
530   // methods that exists in the core system.
531   return frame(sender_sp(), link(), sender_pc());
532 }
533 
534 frame frame::sender(RegisterMap* map) const {
535   frame result = sender_raw(map);
536 
537   if (map->process_frames()) {
538     StackWatermarkSet::on_iteration(map->thread(), result);
539   }
540 
541   return result;
542 }
543 
544 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
545   assert(is_interpreted_frame(), "Not an interpreted frame");
546   // These are reasonable sanity checks
547   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
548     return false;
549   }
550   if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
551     return false;
552   }
553   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
554     return false;
555   }
556   // These are hacks to keep us out of trouble.
557   // The problem with these is that they mask other problems

642 #ifdef AMD64
643         value_result->f = *(jfloat*)tos_addr;
644 #else
645       if (method->is_native()) {
646         jdouble d = *(jdouble*)tos_addr;  // Result was in ST0 so need to convert to jfloat
647         value_result->f = (jfloat)d;
648       } else {
649         value_result->f = *(jfloat*)tos_addr;
650       }
651 #endif // AMD64
652       break;
653     }
654     case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
655     case T_VOID    : /* Nothing to do */ break;
656     default        : ShouldNotReachHere();
657   }
658 
659   return type;
660 }
661 


662 

663 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
664   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
665   return &interpreter_frame_tos_address()[index];
666 }
667 
668 #ifndef PRODUCT
669 
670 #define DESCRIBE_FP_OFFSET(name) \
671   values.describe(frame_no, fp() + frame::name##_offset, #name)
672 
673 void frame::describe_pd(FrameValues& values, int frame_no) {
674   if (is_interpreted_frame()) {
675     DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
676     DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
677     DESCRIBE_FP_OFFSET(interpreter_frame_method);
678     DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
679     DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
680     DESCRIBE_FP_OFFSET(interpreter_frame_cache);
681     DESCRIBE_FP_OFFSET(interpreter_frame_locals);
682     DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
683     DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
684 #ifdef AMD64
685   } else if (is_entry_frame()) {
686     // This could be more descriptive if we use the enum in
687     // stubGenerator to map to real names but it's most important to
688     // claim these frame slots so the error checking works.
689     for (int i = 0; i < entry_frame_after_call_words; i++) {
690       values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i));
691     }
692 #endif // AMD64
693   }












694 }
695 #endif // !PRODUCT
696 
697 intptr_t *frame::initial_deoptimization_info() {
698   // used to reset the saved FP
699   return fp();
700 }
701 
702 intptr_t* frame::real_fp() const {
703   if (_cb != NULL) {
704     // use the frame size if valid
705     int size = _cb->frame_size();
706     if (size > 0) {
707       return unextended_sp() + size;
708     }
709   }
710   // else rely on fp()
711   assert(! is_compiled_frame(), "unknown compiled frame size");
712   return fp();
713 }
714 
715 #ifndef PRODUCT
716 // This is a generic constructor which is only used by pns() in debug.cpp.
717 frame::frame(void* sp, void* fp, void* pc) {
718   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
719 }
720 
721 #endif
722 
723 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
724   // last frame set?
725   if (last_Java_sp() == NULL) return;
726   // already walkable?
727   if (walkable()) return;
728   vmassert(Thread::current() == (Thread*)thread, "not current thread");
729   vmassert(last_Java_sp() != NULL, "not called from Java code?");
730   vmassert(last_Java_pc() == NULL, "already walkable");
731   capture_last_Java_pc();
732   vmassert(walkable(), "something went wrong");
733 }
734 

 14  *
 15  * You should have received a copy of the GNU General Public License version
 16  * 2 along with this work; if not, write to the Free Software Foundation,
 17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
 18  *
 19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
 20  * or visit www.oracle.com if you need additional information or have any
 21  * questions.
 22  *
 23  */
 24 
 25 #include "precompiled.hpp"
 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/method.hpp"
 32 #include "oops/oop.inline.hpp"
 33 #include "prims/methodHandles.hpp"
 34 #include "runtime/continuation.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/signature.hpp"
 40 #include "runtime/stackWatermarkSet.hpp"
 41 #include "runtime/stubCodeGenerator.hpp"
 42 #include "runtime/stubRoutines.hpp"
 43 #include "vmreg_x86.inline.hpp"
 44 #include "utilities/formatBuffer.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 

130       // must be some sort of compiled/runtime frame
131       // fp does not have to be safe (although it could be check for c1?)
132 
133       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
134       if (_cb->frame_size() <= 0) {
135         return false;
136       }
137 
138       sender_sp = _unextended_sp + _cb->frame_size();
139       // Is sender_sp safe?
140       if (!thread->is_in_full_stack_checked((address)sender_sp)) {
141         return false;
142       }
143       sender_unextended_sp = sender_sp;
144       // On Intel the return_address is always the word on the stack
145       sender_pc = (address) *(sender_sp-1);
146       // Note: frame::sender_sp_offset is only valid for compiled frame
147       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
148     }
149 
150     if (Continuation::is_return_barrier_entry(sender_pc)) {	
151       Continuation::fix_continuation_bottom_sender(thread, *this, &sender_pc, &sender_sp);	
152     }
153 
154     // If the potential sender is the interpreter then we can do some more checking
155     if (Interpreter::contains(sender_pc)) {
156 
157       // ebp is always saved in a recognizable place in any code we generate. However
158       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
159       // is really a frame pointer.
160 
161       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
162         return false;
163       }
164 
165       // construct the potential sender
166 
167       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
168 
169       return sender.is_interpreted_frame_valid(thread);
170 
171     }
172 

248 
249   if (!fp_safe) {
250     return false;
251   }
252 
253   // Will the pc we fetch be non-zero (which we'll find at the oldest frame)
254 
255   if ( (address) this->fp()[return_addr_offset] == NULL) return false;
256 
257 
258   // could try and do some more potential verification of native frame if we could think of some...
259 
260   return true;
261 
262 }
263 
264 
265 void frame::patch_pc(Thread* thread, address pc) {
266   assert(_cb == CodeCache::find_blob(pc), "unexpected pc");
267   address* pc_addr = &(((address*) sp())[-1]);
268 
269   if (TracePcPatching) {
270     tty->print_cr("patch_pc at address " INTPTR_FORMAT " [" INTPTR_FORMAT " -> " INTPTR_FORMAT "]",
271                   p2i(pc_addr), p2i(*pc_addr), p2i(pc));
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 
276   assert(!Continuation::is_return_barrier_entry(*pc_addr), "return barrier");
277 
278   assert(_pc == *pc_addr || pc == *pc_addr || *pc_addr == 0, "must be (pc: " INTPTR_FORMAT " _pc: " INTPTR_FORMAT " pc_addr: " INTPTR_FORMAT " *pc_addr: " INTPTR_FORMAT  " sp: " INTPTR_FORMAT ")", p2i(pc), p2i(_pc), p2i(pc_addr), p2i(*pc_addr), p2i(sp()));
279   DEBUG_ONLY(address old_pc = _pc;)
280   *pc_addr = pc;
281   _pc = pc; // must be set before call to get_deopt_original_pc
282   address original_pc = CompiledMethod::get_deopt_original_pc(this);
283   if (original_pc != NULL) {
284     assert(original_pc == old_pc, "expected original PC to be stored before patching");
285     _deopt_state = is_deoptimized;
286     _pc = original_pc;
287   } else {
288     _deopt_state = not_deoptimized;

289   }
290   assert (!is_compiled_frame() || !_cb->as_compiled_method()->is_deopt_entry(_pc), "must be");
291 
292 #ifdef ASSERT
293   {
294     frame f(this->sp(), this->unextended_sp(), this->fp(), pc);
295     assert(f.is_deoptimized_frame() == this->is_deoptimized_frame() && f.pc() == this->pc() && f.raw_pc() == this->raw_pc(), 
296       "must be (f.is_deoptimized_frame(): %d this->is_deoptimized_frame(): %d "
297       "f.pc(): " INTPTR_FORMAT " this->pc(): " INTPTR_FORMAT " f.raw_pc(): " INTPTR_FORMAT " this->raw_pc(): " INTPTR_FORMAT ")", 
298       f.is_deoptimized_frame(), this->is_deoptimized_frame(), p2i(f.pc()), p2i(this->pc()), p2i(f.raw_pc()), p2i(this->raw_pc()));
299   }
300 #endif
301 }
302 
303 intptr_t* frame::entry_frame_argument_at(int offset) const {
304   // convert offset to index to deal with tsi
305   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
306   // Entry frame's arguments are always in relation to unextended_sp()
307   return &unextended_sp()[index];
308 }
309 
310 // sender_sp
311 
312 intptr_t* frame::interpreter_frame_sender_sp() const {
313   assert(is_interpreted_frame(), "interpreted frame expected");
314   return (intptr_t*) at(interpreter_frame_sender_sp_offset);
315 }
316 
317 void frame::set_interpreter_frame_sender_sp(intptr_t* sender_sp) {
318   assert(is_interpreted_frame(), "interpreted frame expected");
319   ptr_at_put(interpreter_frame_sender_sp_offset, (intptr_t) sender_sp);
320 }
321 
322 
323 // monitor elements
324 
325 BasicObjectLock* frame::interpreter_frame_monitor_begin() const {
326   return (BasicObjectLock*) addr_at(interpreter_frame_monitor_block_bottom_offset);
327 }
328 
329 template BasicObjectLock* frame::interpreter_frame_monitor_end<true>() const;
330 template BasicObjectLock* frame::interpreter_frame_monitor_end<false>() const;
331 
332 template <bool relative>
333 BasicObjectLock* frame::interpreter_frame_monitor_end() const {
334   BasicObjectLock* result = (BasicObjectLock*) at<relative>(interpreter_frame_monitor_block_top_offset);
335   // make sure the pointer points inside the frame
336   assert(sp() <= (intptr_t*) result, "monitor end should be above the stack pointer");
337   assert((intptr_t*) result < fp(),  "monitor end should be strictly below the frame pointer: result: " INTPTR_FORMAT " fp: " INTPTR_FORMAT, p2i(result), p2i(fp()));
338   return result;
339 }
340 
341 void frame::interpreter_frame_set_monitor_end(BasicObjectLock* value) {
342   *((BasicObjectLock**)addr_at(interpreter_frame_monitor_block_top_offset)) = value;
343 }
344 
345 // Used by template based interpreter deoptimization
346 void frame::interpreter_frame_set_last_sp(intptr_t* sp) {
347     *((intptr_t**)addr_at(interpreter_frame_last_sp_offset)) = sp;
348 }
349 
350 frame frame::sender_for_entry_frame(RegisterMap* map) const {
351   assert(map != NULL, "map must be set");
352   // Java frame called from C; skip all C frames and return top C
353   // frame of that chunk as the sender
354   JavaFrameAnchor* jfa = entry_frame_call_wrapper()->anchor();
355   assert(!entry_frame_is_first(), "next Java fp must be non zero");
356   assert(jfa->last_Java_sp() > sp(), "must be above this frame on stack");
357   // Since we are walking the stack now this nested anchor is obviously walkable

403 
404   return fr;
405 }
406 
407 //------------------------------------------------------------------------------
408 // frame::verify_deopt_original_pc
409 //
410 // Verifies the calculated original PC of a deoptimization PC for the
411 // given unextended SP.
412 #ifdef ASSERT
413 void frame::verify_deopt_original_pc(CompiledMethod* nm, intptr_t* unextended_sp) {
414   frame fr;
415 
416   // This is ugly but it's better than to change {get,set}_original_pc
417   // to take an SP value as argument.  And it's only a debugging
418   // method anyway.
419   fr._unextended_sp = unextended_sp;
420 
421   address original_pc = nm->get_original_pc(&fr);
422   assert(nm->insts_contains_inclusive(original_pc),
423          "original PC must be in the main code section of the the compiled method (or must be immediately following it) original_pc: " INTPTR_FORMAT " unextended_sp: " INTPTR_FORMAT " name: %s", p2i(original_pc), p2i(unextended_sp), nm->name());
424 }
425 #endif
426 
427 //------------------------------------------------------------------------------
428 // frame::adjust_unextended_sp
429 #ifdef ASSERT
430 void frame::adjust_unextended_sp() {
431   // On x86, sites calling method handle intrinsics and lambda forms are treated
432   // as any other call site. Therefore, no special action is needed when we are
433   // returning to any of these call sites.
434 
435   if (_cb != NULL) {
436     CompiledMethod* sender_cm = _cb->as_compiled_method_or_null();
437     if (sender_cm != NULL) {
438       // If the sender PC is a deoptimization point, get the original PC.
439       if (sender_cm->is_deopt_entry(_pc) ||
440           sender_cm->is_deopt_mh_entry(_pc)) {
441         verify_deopt_original_pc(sender_cm, _unextended_sp);
442       }
443     }
444   }
445 }
446 #endif
447 
























448 //------------------------------------------------------------------------------
449 // frame::sender_for_interpreter_frame
450 frame frame::sender_for_interpreter_frame(RegisterMap* map) const {
451   // SP is the raw SP from the sender after adapter or interpreter
452   // extension.
453   intptr_t* sender_sp = this->sender_sp();
454 
455   // This is the sp before any possible extension (adapter/locals).
456   intptr_t* unextended_sp = interpreter_frame_sender_sp();
457   intptr_t* sender_fp = link();
458 
459 #if COMPILER2_OR_JVMCI
460   if (map->update_map()) {
461     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
462   }
463 #endif // COMPILER2_OR_JVMCI
464 
465   address sender_pc = this->sender_pc();















466 
467   if (Continuation::is_return_barrier_entry(sender_pc)) {
468     if (map->walk_cont()) { // about to walk into an h-stack	
469       return Continuation::top_frame(*this, map);	
470     } else {
471       Continuation::fix_continuation_bottom_sender(map->thread(), *this, &sender_pc, &unextended_sp);






472     }





473   }
474 
475   return frame(sender_sp, unextended_sp, sender_fp, sender_pc);

476 }
477 
478 
479 //------------------------------------------------------------------------------
480 // frame::sender

















481 
482 frame frame::sender(RegisterMap* map) const {
483   frame result = sender_raw(map);
484 
485   if (map->process_frames() && !map->in_cont()) {
486     StackWatermarkSet::on_iteration(map->thread(), result);
487   }
488 
489   return result;
490 }
491 
492 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
493   assert(is_interpreted_frame(), "Not an interpreted frame");
494   // These are reasonable sanity checks
495   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
496     return false;
497   }
498   if (sp() == 0 || (intptr_t(sp()) & (wordSize-1)) != 0) {
499     return false;
500   }
501   if (fp() + interpreter_frame_initial_sp_offset < sp()) {
502     return false;
503   }
504   // These are hacks to keep us out of trouble.
505   // The problem with these is that they mask other problems

590 #ifdef AMD64
591         value_result->f = *(jfloat*)tos_addr;
592 #else
593       if (method->is_native()) {
594         jdouble d = *(jdouble*)tos_addr;  // Result was in ST0 so need to convert to jfloat
595         value_result->f = (jfloat)d;
596       } else {
597         value_result->f = *(jfloat*)tos_addr;
598       }
599 #endif // AMD64
600       break;
601     }
602     case T_DOUBLE  : value_result->d = *(jdouble*)tos_addr; break;
603     case T_VOID    : /* Nothing to do */ break;
604     default        : ShouldNotReachHere();
605   }
606 
607   return type;
608 }
609 
610 template intptr_t* frame::interpreter_frame_tos_at<false>(jint offset) const;
611 template intptr_t* frame::interpreter_frame_tos_at<true >(jint offset) const;
612 
613 template <bool relative>
614 intptr_t* frame::interpreter_frame_tos_at(jint offset) const {
615   int index = (Interpreter::expr_offset_in_bytes(offset)/wordSize);
616   return &interpreter_frame_tos_address<relative>()[index];
617 }
618 
619 #ifndef PRODUCT
620 
621 #define DESCRIBE_FP_OFFSET(name) \
622   values.describe(frame_no, fp() + frame::name##_offset, #name, 1)
623 
624 void frame::describe_pd(FrameValues& values, int frame_no) {
625   if (is_interpreted_frame()) {
626     DESCRIBE_FP_OFFSET(interpreter_frame_sender_sp);
627     DESCRIBE_FP_OFFSET(interpreter_frame_last_sp);
628     DESCRIBE_FP_OFFSET(interpreter_frame_method);
629     DESCRIBE_FP_OFFSET(interpreter_frame_mirror);
630     DESCRIBE_FP_OFFSET(interpreter_frame_mdp);
631     DESCRIBE_FP_OFFSET(interpreter_frame_cache);
632     DESCRIBE_FP_OFFSET(interpreter_frame_locals);
633     DESCRIBE_FP_OFFSET(interpreter_frame_bcp);
634     DESCRIBE_FP_OFFSET(interpreter_frame_initial_sp);
635 #ifdef AMD64
636   } else if (is_entry_frame()) {
637     // This could be more descriptive if we use the enum in
638     // stubGenerator to map to real names but it's most important to
639     // claim these frame slots so the error checking works.
640     for (int i = 0; i < entry_frame_after_call_words; i++) {
641       values.describe(frame_no, fp() - i, err_msg("call_stub word fp - %d", i));
642     }
643 #endif // AMD64
644   }
645 
646   if (is_java_frame()) {
647     address ret_pc = *(address*)(real_fp() - return_addr_offset);
648     values.describe(frame_no, real_fp() - return_addr_offset, Continuation::is_return_barrier_entry(ret_pc) ? "return address (return barrier)" : "return address");
649     values.describe(-1, real_fp() - sender_sp_offset, "saved fp", 2);
650   }
651 }
652 
653 void frame::describe_top_pd(FrameValues& values) {
654   address ret_pc_callee = *(address*)(sp() - return_addr_offset);
655   values.describe(-1, sp() - return_addr_offset, Continuation::is_return_barrier_entry(ret_pc_callee) ? "return address (return barrier)" : "return address");
656   values.describe(-1, sp() - sender_sp_offset, "saved fp", 2);
657 }
658 #endif // !PRODUCT
659 
660 intptr_t *frame::initial_deoptimization_info() {
661   // used to reset the saved FP
662   return fp();
663 }
664 













665 #ifndef PRODUCT
666 // This is a generic constructor which is only used by pns() in debug.cpp.
667 frame::frame(void* sp, void* fp, void* pc) {
668   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
669 }
670 
671 #endif
672 
673 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
674   // last frame set?
675   if (last_Java_sp() == NULL) return;
676   // already walkable?
677   if (walkable()) return;
678   vmassert(Thread::current() == (Thread*)thread, "not current thread");
679   vmassert(last_Java_sp() != NULL, "not called from Java code?");
680   vmassert(last_Java_pc() == NULL, "already walkable");
681   capture_last_Java_pc();
682   vmassert(walkable(), "something went wrong");
683 }
684 
< prev index next >