127 // which can be different from the sender unextended sp (the sp seen
128 // by the sender) because of current frame local variables
129 sender_sp = (intptr_t*) addr_at(sender_sp_offset);
130 sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
131 saved_fp = (intptr_t*) this->fp()[link_offset];
132
133 } else {
134 // must be some sort of compiled/runtime frame
135 // fp does not have to be safe (although it could be check for c1?)
136
137 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
138 if (_cb->frame_size() <= 0) {
139 return false;
140 }
141
142 sender_sp = _unextended_sp + _cb->frame_size();
143 // Is sender_sp safe?
144 if ((address)sender_sp >= thread->stack_base()) {
145 return false;
146 }
147 sender_unextended_sp = sender_sp;
148 // On Intel the return_address is always the word on the stack
149 sender_pc = (address) *(sender_sp-1);
150 // Note: frame::sender_sp_offset is only valid for compiled frame
151 saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
152 }
153
154
155 // If the potential sender is the interpreter then we can do some more checking
156 if (Interpreter::contains(sender_pc)) {
157
158 // ebp is always saved in a recognizable place in any code we generate. However
159 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
160 // is really a frame pointer.
161
162 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
163
164 if (!saved_fp_safe) {
165 return false;
166 }
167
168 // construct the potential sender
169
170 frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
171
172 return sender.is_interpreted_frame_valid(thread);
173
437 intptr_t* unextended_sp = interpreter_frame_sender_sp();
438
439 #if COMPILER2_OR_JVMCI
440 if (map->update_map()) {
441 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
442 }
443 #endif // COMPILER2_OR_JVMCI
444
445 return frame(sender_sp, unextended_sp, link(), sender_pc());
446 }
447
448
449 //------------------------------------------------------------------------------
450 // frame::sender_for_compiled_frame
451 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
452 assert(map != NULL, "map must be set");
453
454 // frame owned by optimizing compiler
455 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
456 intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
457 intptr_t* unextended_sp = sender_sp;
458
459 // On Intel the return_address is always the word on the stack
460 address sender_pc = (address) *(sender_sp-1);
461
462 // This is the saved value of EBP which may or may not really be an FP.
463 // It is only an FP if the sender is an interpreter frame (or C1?).
464 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
465
466 if (map->update_map()) {
467 // Tell GC to use argument oopmaps for some runtime stubs that need it.
468 // For C1, the runtime stub might not have oop maps, so set this flag
469 // outside of update_register_map.
470 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
471 if (_cb->oop_maps() != NULL) {
472 OopMapSet::update_register_map(this, map);
473 }
474
475 // Since the prolog does the save and restore of EBP there is no oopmap
476 // for it so we must fill in its location as if there was an oopmap entry
477 // since if our caller was compiled code there could be live jvm state in it.
478 update_map_with_saved_link(map, saved_fp_addr);
479 }
480
481 assert(sender_sp != sp(), "must have changed");
482 return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
483 }
484
485
486 //------------------------------------------------------------------------------
487 // frame::sender
488 frame frame::sender(RegisterMap* map) const {
489 // Default is we done have to follow them. The sender_for_xxx will
490 // update it accordingly
491 map->set_include_argument_oops(false);
492
493 if (is_entry_frame()) return sender_for_entry_frame(map);
494 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
495 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
496
497 if (_cb != NULL) {
498 return sender_for_compiled_frame(map);
499 }
500 // Must be native-compiled frame, i.e. the marshaling code for native
501 // methods that exists in the core system.
502 return frame(sender_sp(), link(), sender_pc());
568 // Prior to calling into the runtime to report the method_exit the possible
569 // return value is pushed to the native stack. If the result is a jfloat/jdouble
570 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
571 tos_addr = (intptr_t*)sp();
572 if (type == T_FLOAT || type == T_DOUBLE) {
573 // QQQ seems like this code is equivalent on the two platforms
574 #ifdef AMD64
575 // This is times two because we do a push(ltos) after pushing XMM0
576 // and that takes two interpreter stack slots.
577 tos_addr += 2 * Interpreter::stackElementWords;
578 #else
579 tos_addr += 2;
580 #endif // AMD64
581 }
582 } else {
583 tos_addr = (intptr_t*)interpreter_frame_tos_address();
584 }
585
586 switch (type) {
587 case T_OBJECT :
588 case T_ARRAY : {
589 oop obj;
590 if (method->is_native()) {
591 obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
592 } else {
593 oop* obj_p = (oop*)tos_addr;
594 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
595 }
596 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
597 *oop_result = obj;
598 break;
599 }
600 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
601 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
602 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
603 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
604 case T_INT : value_result->i = *(jint*)tos_addr; break;
605 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
606 case T_FLOAT : {
607 #ifdef AMD64
668 if (_cb != NULL) {
669 // use the frame size if valid
670 int size = _cb->frame_size();
671 if (size > 0) {
672 return unextended_sp() + size;
673 }
674 }
675 // else rely on fp()
676 assert(! is_compiled_frame(), "unknown compiled frame size");
677 return fp();
678 }
679
680 #ifndef PRODUCT
681 // This is a generic constructor which is only used by pns() in debug.cpp.
682 frame::frame(void* sp, void* fp, void* pc) {
683 init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
684 }
685
686 void frame::pd_ps() {}
687 #endif
688
689 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
690 // last frame set?
691 if (last_Java_sp() == NULL) return;
692 // already walkable?
693 if (walkable()) return;
694 vmassert(Thread::current() == (Thread*)thread, "not current thread");
695 vmassert(last_Java_sp() != NULL, "not called from Java code?");
696 vmassert(last_Java_pc() == NULL, "already walkable");
697 capture_last_Java_pc();
698 vmassert(walkable(), "something went wrong");
699 }
700
701 void JavaFrameAnchor::capture_last_Java_pc() {
702 vmassert(_last_Java_sp != NULL, "no last frame set");
703 vmassert(_last_Java_pc == NULL, "already walkable");
704 _last_Java_pc = (address)_last_Java_sp[-1];
705 }
|
127 // which can be different from the sender unextended sp (the sp seen
128 // by the sender) because of current frame local variables
129 sender_sp = (intptr_t*) addr_at(sender_sp_offset);
130 sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
131 saved_fp = (intptr_t*) this->fp()[link_offset];
132
133 } else {
134 // must be some sort of compiled/runtime frame
135 // fp does not have to be safe (although it could be check for c1?)
136
137 // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
138 if (_cb->frame_size() <= 0) {
139 return false;
140 }
141
142 sender_sp = _unextended_sp + _cb->frame_size();
143 // Is sender_sp safe?
144 if ((address)sender_sp >= thread->stack_base()) {
145 return false;
146 }
147 // On Intel the return_address is always the word on the stack
148 sender_pc = (address) *(sender_sp-1);
149 // Note: frame::sender_sp_offset is only valid for compiled frame
150 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
151 saved_fp = *saved_fp_addr;
152
153 // Repair the sender sp if this is a method with scalarized value type args
154 sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
155 sender_unextended_sp = sender_sp;
156 }
157
158 // If the potential sender is the interpreter then we can do some more checking
159 if (Interpreter::contains(sender_pc)) {
160
161 // ebp is always saved in a recognizable place in any code we generate. However
162 // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
163 // is really a frame pointer.
164
165 bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
166
167 if (!saved_fp_safe) {
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
440 intptr_t* unextended_sp = interpreter_frame_sender_sp();
441
442 #if COMPILER2_OR_JVMCI
443 if (map->update_map()) {
444 update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
445 }
446 #endif // COMPILER2_OR_JVMCI
447
448 return frame(sender_sp, unextended_sp, link(), sender_pc());
449 }
450
451
452 //------------------------------------------------------------------------------
453 // frame::sender_for_compiled_frame
454 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
455 assert(map != NULL, "map must be set");
456
457 // frame owned by optimizing compiler
458 assert(_cb->frame_size() >= 0, "must have non-zero frame size");
459 intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
460
461 // On Intel the return_address is always the word on the stack
462 address sender_pc = (address) *(sender_sp-1);
463
464 // This is the saved value of EBP which may or may not really be an FP.
465 // It is only an FP if the sender is an interpreter frame (or C1?).
466 intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
467
468 // Repair the sender sp if this is a method with scalarized value type args
469 sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
470
471 if (map->update_map()) {
472 // Tell GC to use argument oopmaps for some runtime stubs that need it.
473 // For C1, the runtime stub might not have oop maps, so set this flag
474 // outside of update_register_map.
475 map->set_include_argument_oops(_cb->caller_must_gc_arguments(map->thread()));
476 if (_cb->oop_maps() != NULL) {
477 OopMapSet::update_register_map(this, map);
478 }
479
480 // Since the prolog does the save and restore of EBP there is no oopmap
481 // for it so we must fill in its location as if there was an oopmap entry
482 // since if our caller was compiled code there could be live jvm state in it.
483 update_map_with_saved_link(map, saved_fp_addr);
484 }
485
486 assert(sender_sp != sp(), "must have changed");
487 return frame(sender_sp, sender_sp, *saved_fp_addr, sender_pc);
488 }
489
490
491 //------------------------------------------------------------------------------
492 // frame::sender
493 frame frame::sender(RegisterMap* map) const {
494 // Default is we done have to follow them. The sender_for_xxx will
495 // update it accordingly
496 map->set_include_argument_oops(false);
497
498 if (is_entry_frame()) return sender_for_entry_frame(map);
499 if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
500 assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
501
502 if (_cb != NULL) {
503 return sender_for_compiled_frame(map);
504 }
505 // Must be native-compiled frame, i.e. the marshaling code for native
506 // methods that exists in the core system.
507 return frame(sender_sp(), link(), sender_pc());
573 // Prior to calling into the runtime to report the method_exit the possible
574 // return value is pushed to the native stack. If the result is a jfloat/jdouble
575 // then ST0 is saved before EAX/EDX. See the note in generate_native_result
576 tos_addr = (intptr_t*)sp();
577 if (type == T_FLOAT || type == T_DOUBLE) {
578 // QQQ seems like this code is equivalent on the two platforms
579 #ifdef AMD64
580 // This is times two because we do a push(ltos) after pushing XMM0
581 // and that takes two interpreter stack slots.
582 tos_addr += 2 * Interpreter::stackElementWords;
583 #else
584 tos_addr += 2;
585 #endif // AMD64
586 }
587 } else {
588 tos_addr = (intptr_t*)interpreter_frame_tos_address();
589 }
590
591 switch (type) {
592 case T_OBJECT :
593 case T_VALUETYPE:
594 case T_ARRAY : {
595 oop obj;
596 if (method->is_native()) {
597 obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
598 } else {
599 oop* obj_p = (oop*)tos_addr;
600 obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
601 }
602 assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
603 *oop_result = obj;
604 break;
605 }
606 case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
607 case T_BYTE : value_result->b = *(jbyte*)tos_addr; break;
608 case T_CHAR : value_result->c = *(jchar*)tos_addr; break;
609 case T_SHORT : value_result->s = *(jshort*)tos_addr; break;
610 case T_INT : value_result->i = *(jint*)tos_addr; break;
611 case T_LONG : value_result->j = *(jlong*)tos_addr; break;
612 case T_FLOAT : {
613 #ifdef AMD64
674 if (_cb != NULL) {
675 // use the frame size if valid
676 int size = _cb->frame_size();
677 if (size > 0) {
678 return unextended_sp() + size;
679 }
680 }
681 // else rely on fp()
682 assert(! is_compiled_frame(), "unknown compiled frame size");
683 return fp();
684 }
685
686 #ifndef PRODUCT
687 // This is a generic constructor which is only used by pns() in debug.cpp.
688 frame::frame(void* sp, void* fp, void* pc) {
689 init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
690 }
691
692 void frame::pd_ps() {}
693 #endif
694
695 // Check for a method with scalarized value type arguments that needs
696 // a stack repair and return the repaired sender stack pointer.
697 intptr_t* frame::repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const {
698 CompiledMethod* cm = _cb->as_compiled_method_or_null();
699 if (cm != NULL && cm->method()->needs_stack_repair()) {
700 // The stack increment resides just below the saved rbp on the stack
701 // and does not account for the return address.
702 intptr_t* sp_inc_addr = (intptr_t*) (saved_fp_addr - 1);
703 int sp_inc = (*sp_inc_addr) / wordSize;
704 int real_frame_size = sp_inc + 1; // Add size of return address
705 assert(real_frame_size >= _cb->frame_size(), "invalid frame size");
706 sender_sp = unextended_sp() + real_frame_size;
707 }
708 return sender_sp;
709 }
710
711 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
712 // last frame set?
713 if (last_Java_sp() == NULL) return;
714 // already walkable?
715 if (walkable()) return;
716 vmassert(Thread::current() == (Thread*)thread, "not current thread");
717 vmassert(last_Java_sp() != NULL, "not called from Java code?");
718 vmassert(last_Java_pc() == NULL, "already walkable");
719 capture_last_Java_pc();
720 vmassert(walkable(), "something went wrong");
721 }
722
723 void JavaFrameAnchor::capture_last_Java_pc() {
724 vmassert(_last_Java_sp != NULL, "no last frame set");
725 vmassert(_last_Java_pc == NULL, "already walkable");
726 _last_Java_pc = (address)_last_Java_sp[-1];
727 }
|