< prev index next >

src/hotspot/cpu/x86/frame_x86.cpp

Print this page

122       // which can be different from the sender unextended sp (the sp seen
123       // by the sender) because of current frame local variables
124       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
125       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
126       saved_fp = (intptr_t*) this->fp()[link_offset];
127 
128     } else {
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 

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()) {

603     // Prior to calling into the runtime to report the method_exit the possible
604     // return value is pushed to the native stack. If the result is a jfloat/jdouble
605     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
606     tos_addr = (intptr_t*)sp();
607     if (type == T_FLOAT || type == T_DOUBLE) {
608     // QQQ seems like this code is equivalent on the two platforms
609 #ifdef AMD64
610       // This is times two because we do a push(ltos) after pushing XMM0
611       // and that takes two interpreter stack slots.
612       tos_addr += 2 * Interpreter::stackElementWords;
613 #else
614       tos_addr += 2;
615 #endif // AMD64
616     }
617   } else {
618     tos_addr = (intptr_t*)interpreter_frame_tos_address();
619   }
620 
621   switch (type) {
622     case T_OBJECT  :

623     case T_ARRAY   : {
624       oop obj;
625       if (method->is_native()) {
626         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
627       } else {
628         oop* obj_p = (oop*)tos_addr;
629         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
630       }
631       assert(Universe::is_in_heap_or_null(obj), "sanity check");
632       *oop_result = obj;
633       break;
634     }
635     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
636     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
637     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
638     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
639     case T_INT     : value_result->i = *(jint*)tos_addr; break;
640     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
641     case T_FLOAT   : {
642 #ifdef AMD64

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 
735 void JavaFrameAnchor::capture_last_Java_pc() {
736   vmassert(_last_Java_sp != NULL, "no last frame set");
737   vmassert(_last_Java_pc == NULL, "already walkable");
738   _last_Java_pc = (address)_last_Java_sp[-1];
739 }

122       // which can be different from the sender unextended sp (the sp seen
123       // by the sender) because of current frame local variables
124       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
125       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
126       saved_fp = (intptr_t*) this->fp()[link_offset];
127 
128     } else {
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       // On Intel the return_address is always the word on the stack
143       sender_pc = (address) *(sender_sp-1);
144       // Note: frame::sender_sp_offset is only valid for compiled frame
145       intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
146       saved_fp = *saved_fp_addr;
147 
148       // Repair the sender sp if this is a method with scalarized inline type args
149       sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
150       sender_unextended_sp = sender_sp;
151     }
152 
153     // If the potential sender is the interpreter then we can do some more checking
154     if (Interpreter::contains(sender_pc)) {
155 
156       // ebp is always saved in a recognizable place in any code we generate. However
157       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
158       // is really a frame pointer.
159 
160       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
161         return false;
162       }
163 
164       // construct the potential sender
165 
166       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
167 
168       return sender.is_interpreted_frame_valid(thread);
169 
170     }
171 

468   intptr_t* unextended_sp = interpreter_frame_sender_sp();
469 
470 #if COMPILER2_OR_JVMCI
471   if (map->update_map()) {
472     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
473   }
474 #endif // COMPILER2_OR_JVMCI
475 
476   return frame(sender_sp, unextended_sp, link(), sender_pc());
477 }
478 
479 
480 //------------------------------------------------------------------------------
481 // frame::sender_for_compiled_frame
482 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
483   assert(map != NULL, "map must be set");
484 
485   // frame owned by optimizing compiler
486   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
487   intptr_t* sender_sp = unextended_sp() + _cb->frame_size();

488 
489 #ifdef ASSERT
490   address sender_pc_copy = (address) *(sender_sp-1);
491 #endif
492 
493   // This is the saved value of EBP which may or may not really be an FP.
494   // It is only an FP if the sender is an interpreter frame (or C1?).
495   intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
496 
497   // Repair the sender sp if the frame has been extended
498   sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
499 
500   // On Intel the return_address is always the word on the stack
501   address sender_pc = (address) *(sender_sp-1);
502 
503 #ifdef ASSERT
504   if (sender_pc != sender_pc_copy) {
505     // When extending the stack in the callee method entry to make room for unpacking of value
506     // type args, we keep a copy of the sender pc at the expected location in the callee frame.
507     // If the sender pc is patched due to deoptimization, the copy is not consistent anymore.
508     nmethod* nm = CodeCache::find_blob(sender_pc)->as_nmethod();
509     assert(sender_pc == nm->deopt_mh_handler_begin() || sender_pc == nm->deopt_handler_begin(), "unexpected sender pc");
510   }
511 #endif
512 
513   if (map->update_map()) {
514     // Tell GC to use argument oopmaps for some runtime stubs that need it.
515     // For C1, the runtime stub might not have oop maps, so set this flag
516     // outside of update_register_map.
517     bool caller_args = _cb->caller_must_gc_arguments(map->thread());
518 #ifdef COMPILER1
519     if (!caller_args) {
520       nmethod* nm = _cb->as_nmethod_or_null();
521       if (nm != NULL && nm->is_compiled_by_c1() && nm->method()->has_scalarized_args() &&
522           pc() < nm->verified_inline_entry_point()) {
523         // The VEP and VIEP(RO) of C1-compiled methods call buffer_inline_args_xxx
524         // before doing any argument shuffling, so we need to scan the oops
525         // as the caller passes them.
526         caller_args = true;
527 #ifdef ASSERT
528         NativeCall* call = nativeCall_before(pc());
529         address dest = call->destination();
530         assert(dest == Runtime1::entry_for(Runtime1::buffer_inline_args_no_receiver_id) ||
531                dest == Runtime1::entry_for(Runtime1::buffer_inline_args_id), "unexpected safepoint in entry point");
532 #endif
533       }
534     }
535 #endif
536     map->set_include_argument_oops(caller_args);
537     if (_cb->oop_maps() != NULL) {
538       OopMapSet::update_register_map(this, map);
539     }
540 
541     // Since the prolog does the save and restore of EBP there is no oopmap
542     // for it so we must fill in its location as if there was an oopmap entry
543     // since if our caller was compiled code there could be live jvm state in it.
544     update_map_with_saved_link(map, saved_fp_addr);
545   }
546 
547   assert(sender_sp != sp(), "must have changed");
548   return frame(sender_sp, sender_sp, *saved_fp_addr, sender_pc);
549 }
550 
551 
552 //------------------------------------------------------------------------------
553 // frame::sender_raw
554 frame frame::sender_raw(RegisterMap* map) const {
555   // Default is we don't have to follow them. The sender_for_xxx will
556   // update it accordingly
557   map->set_include_argument_oops(false);
558 
559   if (is_entry_frame())        return sender_for_entry_frame(map);
560   if (is_optimized_entry_frame()) return sender_for_optimized_entry_frame(map);
561   if (is_interpreted_frame())  return sender_for_interpreter_frame(map);
562   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
563 
564   if (_cb != NULL) {
565     return sender_for_compiled_frame(map);
566   }
567   // Must be native-compiled frame, i.e. the marshaling code for native
568   // methods that exists in the core system.
569   return frame(sender_sp(), link(), sender_pc());
570 }
571 
572 frame frame::sender(RegisterMap* map) const {
573   frame result = sender_raw(map);
574 
575   if (map->process_frames()) {

641     // Prior to calling into the runtime to report the method_exit the possible
642     // return value is pushed to the native stack. If the result is a jfloat/jdouble
643     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
644     tos_addr = (intptr_t*)sp();
645     if (type == T_FLOAT || type == T_DOUBLE) {
646     // QQQ seems like this code is equivalent on the two platforms
647 #ifdef AMD64
648       // This is times two because we do a push(ltos) after pushing XMM0
649       // and that takes two interpreter stack slots.
650       tos_addr += 2 * Interpreter::stackElementWords;
651 #else
652       tos_addr += 2;
653 #endif // AMD64
654     }
655   } else {
656     tos_addr = (intptr_t*)interpreter_frame_tos_address();
657   }
658 
659   switch (type) {
660     case T_OBJECT  :
661     case T_INLINE_TYPE:
662     case T_ARRAY   : {
663       oop obj;
664       if (method->is_native()) {
665         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
666       } else {
667         oop* obj_p = (oop*)tos_addr;
668         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
669       }
670       assert(Universe::is_in_heap_or_null(obj), "sanity check");
671       *oop_result = obj;
672       break;
673     }
674     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
675     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
676     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
677     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
678     case T_INT     : value_result->i = *(jint*)tos_addr; break;
679     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
680     case T_FLOAT   : {
681 #ifdef AMD64

742   if (_cb != NULL) {
743     // use the frame size if valid
744     int size = _cb->frame_size();
745     if (size > 0) {
746       return unextended_sp() + size;
747     }
748   }
749   // else rely on fp()
750   assert(! is_compiled_frame(), "unknown compiled frame size");
751   return fp();
752 }
753 
754 #ifndef PRODUCT
755 // This is a generic constructor which is only used by pns() in debug.cpp.
756 frame::frame(void* sp, void* fp, void* pc) {
757   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
758 }
759 
760 #endif
761 
762 // Check for a method with scalarized inline type arguments that needs
763 // a stack repair and return the repaired sender stack pointer.
764 intptr_t* frame::repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const {
765   CompiledMethod* cm = _cb->as_compiled_method_or_null();
766   if (cm != NULL && cm->needs_stack_repair()) {
767     // The stack increment resides just below the saved rbp on the stack
768     // and does not account for the return address.
769     intptr_t* real_frame_size_addr = (intptr_t*) (saved_fp_addr - 1);
770     int real_frame_size = ((*real_frame_size_addr) + wordSize) / wordSize;
771     assert(real_frame_size >= _cb->frame_size() && real_frame_size <= 1000000, "invalid frame size");
772     sender_sp = unextended_sp() + real_frame_size;
773   }
774   return sender_sp;
775 }
776 
777 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
778   // last frame set?
779   if (last_Java_sp() == NULL) return;
780   // already walkable?
781   if (walkable()) return;
782   vmassert(Thread::current() == (Thread*)thread, "not current thread");
783   vmassert(last_Java_sp() != NULL, "not called from Java code?");
784   vmassert(last_Java_pc() == NULL, "already walkable");
785   capture_last_Java_pc();
786   vmassert(walkable(), "something went wrong");
787 }
788 
789 void JavaFrameAnchor::capture_last_Java_pc() {
790   vmassert(_last_Java_sp != NULL, "no last frame set");
791   vmassert(_last_Java_pc == NULL, "already walkable");
792   _last_Java_pc = (address)_last_Java_sp[-1];
793 }
< prev index next >