< prev index next >

src/hotspot/cpu/aarch64/frame_aarch64.cpp

Print this page

133       // by the sender) because of current frame local variables
134       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
135       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
136       saved_fp = (intptr_t*) this->fp()[link_offset];
137       sender_pc = pauth_strip_verifiable((address) this->fp()[return_addr_offset], (address)saved_fp);
138 
139     } else {
140       // must be some sort of compiled/runtime frame
141       // fp does not have to be safe (although it could be check for c1?)
142 
143       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
144       if (_cb->frame_size() <= 0) {
145         return false;
146       }
147 
148       sender_sp = _unextended_sp + _cb->frame_size();
149       // Is sender_sp safe?
150       if (!thread->is_in_full_stack_checked((address)sender_sp)) {
151         return false;
152       }
153       sender_unextended_sp = sender_sp;
154       // Note: frame::sender_sp_offset is only valid for compiled frame
155       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);

156       sender_pc = pauth_strip_verifiable((address) *(sender_sp-1), (address)saved_fp);
157     }
158 




159 
160     // If the potential sender is the interpreter then we can do some more checking
161     if (Interpreter::contains(sender_pc)) {
162 
163       // fp is always saved in a recognizable place in any code we generate. However
164       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp
165       // is really a frame pointer.
166 
167       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
168         return false;
169       }
170 
171       // construct the potential sender
172 
173       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
174 
175       return sender.is_interpreted_frame_valid(thread);
176 
177     }
178 

467 }
468 
469 //------------------------------------------------------------------------------
470 // frame::sender_for_compiled_frame
471 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
472   // When the sp of a compiled frame is correct, we can get the correct sender sp
473   // by unextended sp + frame size.
474   // For the following two scenarios, the sp of a compiled frame is correct:
475   //  a) This compiled frame is built from the anchor.
476   //  b) This compiled frame is built from a callee frame, and the callee frame can
477   //    calculate its sp correctly.
478   //
479   // For b), if the callee frame is a native code frame (such as leaf call), the sp of
480   // the compiled frame cannot be calculated correctly. There is currently no suitable
481   // solution to solve this problem perfectly. But when PreserveFramePointer is enabled,
482   // we can get the correct sender sp by fp + 2 (that is sender_sp()).
483 
484   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
485   intptr_t* l_sender_sp = (!PreserveFramePointer || _sp_is_trusted) ? unextended_sp() + _cb->frame_size()
486                                                                     : sender_sp();
487   intptr_t* unextended_sp = l_sender_sp;
488 
489   // the return_address is always the word on the stack
490 
491   // For ROP protection, C1/C2 will have signed the sender_pc, but there is no requirement to authenticate it here.
492   address sender_pc = pauth_strip_verifiable((address) *(l_sender_sp-1), (address) *(l_sender_sp-2));
493 
494   intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);
495 
496   // assert (sender_sp() == l_sender_sp, "should be");
497   // assert (*saved_fp_addr == link(), "should be");
498 



















499   if (map->update_map()) {
500     // Tell GC to use argument oopmaps for some runtime stubs that need it.
501     // For C1, the runtime stub might not have oop maps, so set this flag
502     // outside of update_register_map.
503     map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));













504     if (_cb->oop_maps() != NULL) {
505       OopMapSet::update_register_map(this, map);
506     }
507 
508     // Since the prolog does the save and restore of FP there is no
509     // oopmap for it so we must fill in its location as if there was
510     // an oopmap entry since if our caller was compiled code there
511     // could be live jvm state in it.
512     update_map_with_saved_link(map, saved_fp_addr);
513   }
514 
515   return frame(l_sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
516 }
517 
518 //------------------------------------------------------------------------------
519 // frame::sender_raw
520 frame frame::sender_raw(RegisterMap* map) const {
521   // Default is we done have to follow them. The sender_for_xxx will
522   // update it accordingly
523    map->set_include_argument_oops(false);
524 
525   if (is_entry_frame())
526     return sender_for_entry_frame(map);
527   if (is_interpreted_frame())
528     return sender_for_interpreter_frame(map);
529   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
530 
531   // This test looks odd: why is it not is_compiled_frame() ?  That's
532   // because stubs also have OOP maps.
533   if (_cb != NULL) {
534     return sender_for_compiled_frame(map);
535   }

611   Method* method = interpreter_frame_method();
612   BasicType type = method->result_type();
613 
614   intptr_t* tos_addr;
615   if (method->is_native()) {
616     // TODO : ensure AARCH64 does the same as Intel here i.e. push v0 then r0
617     // Prior to calling into the runtime to report the method_exit the possible
618     // return value is pushed to the native stack. If the result is a jfloat/jdouble
619     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
620     tos_addr = (intptr_t*)sp();
621     if (type == T_FLOAT || type == T_DOUBLE) {
622       // This is times two because we do a push(ltos) after pushing XMM0
623       // and that takes two interpreter stack slots.
624       tos_addr += 2 * Interpreter::stackElementWords;
625     }
626   } else {
627     tos_addr = (intptr_t*)interpreter_frame_tos_address();
628   }
629 
630   switch (type) {

631     case T_OBJECT  :
632     case T_ARRAY   : {
633       oop obj;
634       if (method->is_native()) {
635         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
636       } else {
637         oop* obj_p = (oop*)tos_addr;
638         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
639       }
640       assert(Universe::is_in_heap_or_null(obj), "sanity check");
641       *oop_result = obj;
642       break;
643     }
644     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
645     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
646     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
647     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
648     case T_INT     : value_result->i = *(jint*)tos_addr; break;
649     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
650     case T_FLOAT   : {

819 }
820 
821 // support for printing out where we are in a Java method
822 // needs to be passed current fp and bcp register values
823 // prints method name, bc index and bytecode name
824 extern "C" void pm(uintptr_t fp, uintptr_t bcx) {
825   DESCRIBE_FP_OFFSET(interpreter_frame_method);
826   uintptr_t *p = (uintptr_t *)fp;
827   Method* m = (Method*)p[frame::interpreter_frame_method_offset];
828   printbc(m, bcx);
829 }
830 
831 #ifndef PRODUCT
832 // This is a generic constructor which is only used by pns() in debug.cpp.
833 frame::frame(void* sp, void* fp, void* pc) {
834   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
835 }
836 
837 #endif
838 
















839 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
840   // last frame set?
841   if (last_Java_sp() == NULL) return;
842   // already walkable?
843   if (walkable()) return;
844   vmassert(Thread::current() == (Thread*)thread, "not current thread");
845   vmassert(last_Java_sp() != NULL, "not called from Java code?");
846   vmassert(last_Java_pc() == NULL, "already walkable");
847   capture_last_Java_pc();
848   vmassert(walkable(), "something went wrong");
849 }
850 
851 void JavaFrameAnchor::capture_last_Java_pc() {
852   vmassert(_last_Java_sp != NULL, "no last frame set");
853   vmassert(_last_Java_pc == NULL, "already walkable");
854   _last_Java_pc = (address)_last_Java_sp[-1];
855 }

133       // by the sender) because of current frame local variables
134       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
135       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
136       saved_fp = (intptr_t*) this->fp()[link_offset];
137       sender_pc = pauth_strip_verifiable((address) this->fp()[return_addr_offset], (address)saved_fp);
138 
139     } else {
140       // must be some sort of compiled/runtime frame
141       // fp does not have to be safe (although it could be check for c1?)
142 
143       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
144       if (_cb->frame_size() <= 0) {
145         return false;
146       }
147 
148       sender_sp = _unextended_sp + _cb->frame_size();
149       // Is sender_sp safe?
150       if (!thread->is_in_full_stack_checked((address)sender_sp)) {
151         return false;
152       }

153       // Note: frame::sender_sp_offset is only valid for compiled frame
154       intptr_t **saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
155       saved_fp = *saved_fp_addr;
156       sender_pc = pauth_strip_verifiable((address) *(sender_sp-1), (address)saved_fp);

157 
158       // Repair the sender sp if this is a method with scalarized inline type args
159       sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
160       sender_unextended_sp = sender_sp;
161     }
162 
163     // If the potential sender is the interpreter then we can do some more checking
164     if (Interpreter::contains(sender_pc)) {
165 
166       // fp is always saved in a recognizable place in any code we generate. However
167       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved fp
168       // is really a frame pointer.
169 
170       if (!thread->is_in_stack_range_excl((address)saved_fp, (address)sender_sp)) {
171         return false;
172       }
173 
174       // construct the potential sender
175 
176       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
177 
178       return sender.is_interpreted_frame_valid(thread);
179 
180     }
181 

470 }
471 
472 //------------------------------------------------------------------------------
473 // frame::sender_for_compiled_frame
474 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
475   // When the sp of a compiled frame is correct, we can get the correct sender sp
476   // by unextended sp + frame size.
477   // For the following two scenarios, the sp of a compiled frame is correct:
478   //  a) This compiled frame is built from the anchor.
479   //  b) This compiled frame is built from a callee frame, and the callee frame can
480   //    calculate its sp correctly.
481   //
482   // For b), if the callee frame is a native code frame (such as leaf call), the sp of
483   // the compiled frame cannot be calculated correctly. There is currently no suitable
484   // solution to solve this problem perfectly. But when PreserveFramePointer is enabled,
485   // we can get the correct sender sp by fp + 2 (that is sender_sp()).
486 
487   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
488   intptr_t* l_sender_sp = (!PreserveFramePointer || _sp_is_trusted) ? unextended_sp() + _cb->frame_size()
489                                                                     : sender_sp();

490 
491 #ifdef ASSERT
492   address sender_pc_copy = pauth_strip_verifiable((address) *(l_sender_sp-1), (address) *(l_sender_sp-2));
493 #endif

494 
495   intptr_t** saved_fp_addr = (intptr_t**) (l_sender_sp - frame::sender_sp_offset);
496 
497   // assert (sender_sp() == l_sender_sp, "should be");
498   // assert (*saved_fp_addr == link(), "should be");
499 
500   // Repair the sender sp if the frame has been extended
501   l_sender_sp = repair_sender_sp(l_sender_sp, saved_fp_addr);
502 
503   // the return_address is always the word on the stack
504 
505   // For ROP protection, C1/C2 will have signed the sender_pc, but there is no requirement to authenticate it here.
506   // The return address is always the first word on the stack
507   address sender_pc = pauth_strip_verifiable((address) *(l_sender_sp-1), (address) *(l_sender_sp-2));
508 
509 #ifdef ASSERT
510   if (sender_pc != sender_pc_copy) {
511     // When extending the stack in the callee method entry to make room for unpacking of value
512     // type args, we keep a copy of the sender pc at the expected location in the callee frame.
513     // If the sender pc is patched due to deoptimization, the copy is not consistent anymore.
514     nmethod* nm = CodeCache::find_blob(sender_pc)->as_nmethod();
515     assert(sender_pc == nm->deopt_mh_handler_begin() || sender_pc == nm->deopt_handler_begin(), "unexpected sender pc");
516   }
517 #endif
518 
519   if (map->update_map()) {
520     // Tell GC to use argument oopmaps for some runtime stubs that need it.
521     // For C1, the runtime stub might not have oop maps, so set this flag
522     // outside of update_register_map.
523     bool caller_args = _cb->caller_must_gc_arguments(map->thread());
524 #ifdef COMPILER1
525     if (!caller_args) {
526       nmethod* nm = _cb->as_nmethod_or_null();
527       if (nm != NULL && nm->is_compiled_by_c1() && nm->method()->has_scalarized_args() &&
528           pc() < nm->verified_inline_entry_point()) {
529         // The VEP and VIEP(RO) of C1-compiled methods call buffer_inline_args_xxx
530         // before doing any argument shuffling, so we need to scan the oops
531         // as the caller passes them.
532         caller_args = true;
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 FP there is no
542     // oopmap for it so we must fill in its location as if there was
543     // an oopmap entry since if our caller was compiled code there
544     // could be live jvm state in it.
545     update_map_with_saved_link(map, saved_fp_addr);
546   }
547 
548   return frame(l_sender_sp, l_sender_sp, *saved_fp_addr, sender_pc);
549 }
550 
551 //------------------------------------------------------------------------------
552 // frame::sender_raw
553 frame frame::sender_raw(RegisterMap* map) const {
554   // Default is we done have to follow them. The sender_for_xxx will
555   // update it accordingly
556    map->set_include_argument_oops(false);
557 
558   if (is_entry_frame())
559     return sender_for_entry_frame(map);
560   if (is_interpreted_frame())
561     return sender_for_interpreter_frame(map);
562   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
563 
564   // This test looks odd: why is it not is_compiled_frame() ?  That's
565   // because stubs also have OOP maps.
566   if (_cb != NULL) {
567     return sender_for_compiled_frame(map);
568   }

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

853 }
854 
855 // support for printing out where we are in a Java method
856 // needs to be passed current fp and bcp register values
857 // prints method name, bc index and bytecode name
858 extern "C" void pm(uintptr_t fp, uintptr_t bcx) {
859   DESCRIBE_FP_OFFSET(interpreter_frame_method);
860   uintptr_t *p = (uintptr_t *)fp;
861   Method* m = (Method*)p[frame::interpreter_frame_method_offset];
862   printbc(m, bcx);
863 }
864 
865 #ifndef PRODUCT
866 // This is a generic constructor which is only used by pns() in debug.cpp.
867 frame::frame(void* sp, void* fp, void* pc) {
868   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
869 }
870 
871 #endif
872 
873 // Check for a method with scalarized inline type arguments that needs
874 // a stack repair and return the repaired sender stack pointer.
875 intptr_t* frame::repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const {
876   CompiledMethod* cm = _cb->as_compiled_method_or_null();
877   if (cm != NULL && cm->needs_stack_repair()) {
878     // The stack increment resides just below the saved FP on the stack and
879     // records the total frame size excluding the two words for saving FP and LR.
880     intptr_t* sp_inc_addr = (intptr_t*) (saved_fp_addr - 1);
881     assert(*sp_inc_addr % StackAlignmentInBytes == 0, "sp_inc not aligned");
882     int real_frame_size = (*sp_inc_addr / wordSize) + 2;
883     assert(real_frame_size >= _cb->frame_size() && real_frame_size <= 1000000, "invalid frame size");
884     sender_sp = unextended_sp() + real_frame_size;
885   }
886   return sender_sp;
887 }
888 
889 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
890   // last frame set?
891   if (last_Java_sp() == NULL) return;
892   // already walkable?
893   if (walkable()) return;
894   vmassert(Thread::current() == (Thread*)thread, "not current thread");
895   vmassert(last_Java_sp() != NULL, "not called from Java code?");
896   vmassert(last_Java_pc() == NULL, "already walkable");
897   capture_last_Java_pc();
898   vmassert(walkable(), "something went wrong");
899 }
900 
901 void JavaFrameAnchor::capture_last_Java_pc() {
902   vmassert(_last_Java_sp != NULL, "no last frame set");
903   vmassert(_last_Java_pc == NULL, "already walkable");
904   _last_Java_pc = (address)_last_Java_sp[-1];
905 }
< prev index next >