< prev index next >

src/hotspot/cpu/x86/frame_x86.cpp

Print this page


   1 /*
   2  * Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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  *


 128       // which can be different from the sender unextended sp (the sp seen
 129       // by the sender) because of current frame local variables
 130       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
 131       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
 132       saved_fp = (intptr_t*) this->fp()[link_offset];
 133 
 134     } else {
 135       // must be some sort of compiled/runtime frame
 136       // fp does not have to be safe (although it could be check for c1?)
 137 
 138       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
 139       if (_cb->frame_size() <= 0) {
 140         return false;
 141       }
 142 
 143       sender_sp = _unextended_sp + _cb->frame_size();
 144       // Is sender_sp safe?
 145       if ((address)sender_sp >= thread->stack_base()) {
 146         return false;
 147       }
 148       sender_unextended_sp = sender_sp;
 149       // On Intel the return_address is always the word on the stack
 150       sender_pc = (address) *(sender_sp-1);
 151       // Note: frame::sender_sp_offset is only valid for compiled frame
 152       saved_fp = (intptr_t*) *(sender_sp - frame::sender_sp_offset);
 153     }
 154 




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


 438   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 439 
 440 #if COMPILER2_OR_JVMCI
 441   if (map->update_map()) {
 442     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
 443   }
 444 #endif // COMPILER2_OR_JVMCI
 445 
 446   return frame(sender_sp, unextended_sp, link(), sender_pc());
 447 }
 448 
 449 
 450 //------------------------------------------------------------------------------
 451 // frame::sender_for_compiled_frame
 452 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
 453   assert(map != NULL, "map must be set");
 454 
 455   // frame owned by optimizing compiler
 456   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
 457   intptr_t* sender_sp = unextended_sp() + _cb->frame_size();
 458   intptr_t* unextended_sp = sender_sp;
 459 
 460   // On Intel the return_address is always the word on the stack
 461   address sender_pc = (address) *(sender_sp-1);
 462 
 463   // This is the saved value of EBP which may or may not really be an FP.
 464   // It is only an FP if the sender is an interpreter frame (or C1?).
 465   intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
 466 



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

















 472     if (_cb->oop_maps() != NULL) {
 473       OopMapSet::update_register_map(this, map);
 474     }
 475 
 476     // Since the prolog does the save and restore of EBP there is no oopmap
 477     // for it so we must fill in its location as if there was an oopmap entry
 478     // since if our caller was compiled code there could be live jvm state in it.
 479     update_map_with_saved_link(map, saved_fp_addr);
 480   }
 481 
 482   assert(sender_sp != sp(), "must have changed");
 483   return frame(sender_sp, unextended_sp, *saved_fp_addr, sender_pc);
 484 }
 485 
 486 
 487 //------------------------------------------------------------------------------
 488 // frame::sender
 489 frame frame::sender(RegisterMap* map) const {
 490   // Default is we done have to follow them. The sender_for_xxx will
 491   // update it accordingly
 492   map->set_include_argument_oops(false);
 493 
 494   if (is_entry_frame())       return sender_for_entry_frame(map);
 495   if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
 496   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
 497 
 498   if (_cb != NULL) {
 499     return sender_for_compiled_frame(map);
 500   }
 501   // Must be native-compiled frame, i.e. the marshaling code for native
 502   // methods that exists in the core system.
 503   return frame(sender_sp(), link(), sender_pc());
 504 }
 505 
 506 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
 507   assert(is_interpreted_frame(), "Not an interpreted frame");
 508   // These are reasonable sanity checks
 509   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
 510     return false;


 569     // Prior to calling into the runtime to report the method_exit the possible
 570     // return value is pushed to the native stack. If the result is a jfloat/jdouble
 571     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
 572     tos_addr = (intptr_t*)sp();
 573     if (type == T_FLOAT || type == T_DOUBLE) {
 574     // QQQ seems like this code is equivalent on the two platforms
 575 #ifdef AMD64
 576       // This is times two because we do a push(ltos) after pushing XMM0
 577       // and that takes two interpreter stack slots.
 578       tos_addr += 2 * Interpreter::stackElementWords;
 579 #else
 580       tos_addr += 2;
 581 #endif // AMD64
 582     }
 583   } else {
 584     tos_addr = (intptr_t*)interpreter_frame_tos_address();
 585   }
 586 
 587   switch (type) {
 588     case T_OBJECT  :

 589     case T_ARRAY   : {
 590       oop obj;
 591       if (method->is_native()) {
 592         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
 593       } else {
 594         oop* obj_p = (oop*)tos_addr;
 595         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
 596       }
 597       assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
 598       *oop_result = obj;
 599       break;
 600     }
 601     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
 602     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
 603     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
 604     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
 605     case T_INT     : value_result->i = *(jint*)tos_addr; break;
 606     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
 607     case T_FLOAT   : {
 608 #ifdef AMD64


 669   if (_cb != NULL) {
 670     // use the frame size if valid
 671     int size = _cb->frame_size();
 672     if (size > 0) {
 673       return unextended_sp() + size;
 674     }
 675   }
 676   // else rely on fp()
 677   assert(! is_compiled_frame(), "unknown compiled frame size");
 678   return fp();
 679 }
 680 
 681 #ifndef PRODUCT
 682 // This is a generic constructor which is only used by pns() in debug.cpp.
 683 frame::frame(void* sp, void* fp, void* pc) {
 684   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
 685 }
 686 
 687 void frame::pd_ps() {}
 688 #endif



















 689 
 690 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
 691   // last frame set?
 692   if (last_Java_sp() == NULL) return;
 693   // already walkable?
 694   if (walkable()) return;
 695   vmassert(Thread::current() == (Thread*)thread, "not current thread");
 696   vmassert(last_Java_sp() != NULL, "not called from Java code?");
 697   vmassert(last_Java_pc() == NULL, "already walkable");
 698   capture_last_Java_pc();
 699   vmassert(walkable(), "something went wrong");
 700 }
 701 
 702 void JavaFrameAnchor::capture_last_Java_pc() {
 703   vmassert(_last_Java_sp != NULL, "no last frame set");
 704   vmassert(_last_Java_pc == NULL, "already walkable");
 705   _last_Java_pc = (address)_last_Java_sp[-1];
 706 }
   1 /*
   2  * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.
   8  *
   9  * This code is distributed in the hope that it will be useful, but WITHOUT
  10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  12  * version 2 for more details (a copy is included in the LICENSE file that
  13  * accompanied this code).
  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  *


 128       // which can be different from the sender unextended sp (the sp seen
 129       // by the sender) because of current frame local variables
 130       sender_sp = (intptr_t*) addr_at(sender_sp_offset);
 131       sender_unextended_sp = (intptr_t*) this->fp()[interpreter_frame_sender_sp_offset];
 132       saved_fp = (intptr_t*) this->fp()[link_offset];
 133 
 134     } else {
 135       // must be some sort of compiled/runtime frame
 136       // fp does not have to be safe (although it could be check for c1?)
 137 
 138       // check for a valid frame_size, otherwise we are unlikely to get a valid sender_pc
 139       if (_cb->frame_size() <= 0) {
 140         return false;
 141       }
 142 
 143       sender_sp = _unextended_sp + _cb->frame_size();
 144       // Is sender_sp safe?
 145       if ((address)sender_sp >= thread->stack_base()) {
 146         return false;
 147       }

 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       intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
 152       saved_fp = *saved_fp_addr;
 153 
 154       // Repair the sender sp if this is a method with scalarized value type args
 155       sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
 156       sender_unextended_sp = sender_sp;
 157     }
 158 
 159     // If the potential sender is the interpreter then we can do some more checking
 160     if (Interpreter::contains(sender_pc)) {
 161 
 162       // ebp is always saved in a recognizable place in any code we generate. However
 163       // only if the sender is interpreted/call_stub (c1 too?) are we certain that the saved ebp
 164       // is really a frame pointer.
 165 
 166       bool saved_fp_safe = ((address)saved_fp < thread->stack_base()) && (saved_fp > sender_sp);
 167 
 168       if (!saved_fp_safe) {
 169         return false;
 170       }
 171 
 172       // construct the potential sender
 173 
 174       frame sender(sender_sp, sender_unextended_sp, saved_fp, sender_pc);
 175 
 176       return sender.is_interpreted_frame_valid(thread);
 177 


 441   intptr_t* unextended_sp = interpreter_frame_sender_sp();
 442 
 443 #if COMPILER2_OR_JVMCI
 444   if (map->update_map()) {
 445     update_map_with_saved_link(map, (intptr_t**) addr_at(link_offset));
 446   }
 447 #endif // COMPILER2_OR_JVMCI
 448 
 449   return frame(sender_sp, unextended_sp, link(), sender_pc());
 450 }
 451 
 452 
 453 //------------------------------------------------------------------------------
 454 // frame::sender_for_compiled_frame
 455 frame frame::sender_for_compiled_frame(RegisterMap* map) const {
 456   assert(map != NULL, "map must be set");
 457 
 458   // frame owned by optimizing compiler
 459   assert(_cb->frame_size() >= 0, "must have non-zero frame size");
 460   intptr_t* sender_sp = unextended_sp() + _cb->frame_size();

 461 
 462   // On Intel the return_address is always the word on the stack
 463   address sender_pc = (address) *(sender_sp-1);
 464 
 465   // This is the saved value of EBP which may or may not really be an FP.
 466   // It is only an FP if the sender is an interpreter frame (or C1?).
 467   intptr_t** saved_fp_addr = (intptr_t**) (sender_sp - frame::sender_sp_offset);
 468 
 469   // Repair the sender sp if this is a method with scalarized value type args
 470   sender_sp = repair_sender_sp(sender_sp, saved_fp_addr);
 471 
 472   if (map->update_map()) {
 473     // Tell GC to use argument oopmaps for some runtime stubs that need it.
 474     // For C1, the runtime stub might not have oop maps, so set this flag
 475     // outside of update_register_map.
 476     bool caller_args = _cb->caller_must_gc_arguments(map->thread());
 477     if (!caller_args) {
 478       nmethod* nm = _cb->as_nmethod_or_null();
 479       if (nm != NULL && nm->is_compiled_by_c1() &&
 480           nm->method()->has_scalarized_args() &&
 481           pc() < nm->verified_value_entry_point()) {
 482         // The VEP and VVEP(RO) of C1-compiled methods call buffer_value_args_xxx
 483         // before doing any argument shuffling, so we need to scan the oops
 484         // as the caller passes them.
 485         NativeCall* call = nativeCall_before(pc());
 486         address dest = call->destination();
 487         if (dest == Runtime1::entry_for(Runtime1::buffer_value_args_no_receiver_id) ||
 488             dest == Runtime1::entry_for(Runtime1::buffer_value_args_id)) {
 489           caller_args = true;
 490         }
 491       }
 492     }
 493     map->set_include_argument_oops(caller_args);
 494     if (_cb->oop_maps() != NULL) {
 495       OopMapSet::update_register_map(this, map);
 496     }
 497 
 498     // Since the prolog does the save and restore of EBP there is no oopmap
 499     // for it so we must fill in its location as if there was an oopmap entry
 500     // since if our caller was compiled code there could be live jvm state in it.
 501     update_map_with_saved_link(map, saved_fp_addr);
 502   }
 503 
 504   assert(sender_sp != sp(), "must have changed");
 505   return frame(sender_sp, sender_sp, *saved_fp_addr, sender_pc);
 506 }
 507 
 508 
 509 //------------------------------------------------------------------------------
 510 // frame::sender
 511 frame frame::sender(RegisterMap* map) const {
 512   // Default is we don't have to follow them. The sender_for_xxx will
 513   // update it accordingly
 514   map->set_include_argument_oops(false);
 515 
 516   if (is_entry_frame())       return sender_for_entry_frame(map);
 517   if (is_interpreted_frame()) return sender_for_interpreter_frame(map);
 518   assert(_cb == CodeCache::find_blob(pc()),"Must be the same");
 519 
 520   if (_cb != NULL) {
 521     return sender_for_compiled_frame(map);
 522   }
 523   // Must be native-compiled frame, i.e. the marshaling code for native
 524   // methods that exists in the core system.
 525   return frame(sender_sp(), link(), sender_pc());
 526 }
 527 
 528 bool frame::is_interpreted_frame_valid(JavaThread* thread) const {
 529   assert(is_interpreted_frame(), "Not an interpreted frame");
 530   // These are reasonable sanity checks
 531   if (fp() == 0 || (intptr_t(fp()) & (wordSize-1)) != 0) {
 532     return false;


 591     // Prior to calling into the runtime to report the method_exit the possible
 592     // return value is pushed to the native stack. If the result is a jfloat/jdouble
 593     // then ST0 is saved before EAX/EDX. See the note in generate_native_result
 594     tos_addr = (intptr_t*)sp();
 595     if (type == T_FLOAT || type == T_DOUBLE) {
 596     // QQQ seems like this code is equivalent on the two platforms
 597 #ifdef AMD64
 598       // This is times two because we do a push(ltos) after pushing XMM0
 599       // and that takes two interpreter stack slots.
 600       tos_addr += 2 * Interpreter::stackElementWords;
 601 #else
 602       tos_addr += 2;
 603 #endif // AMD64
 604     }
 605   } else {
 606     tos_addr = (intptr_t*)interpreter_frame_tos_address();
 607   }
 608 
 609   switch (type) {
 610     case T_OBJECT  :
 611     case T_VALUETYPE:
 612     case T_ARRAY   : {
 613       oop obj;
 614       if (method->is_native()) {
 615         obj = cast_to_oop(at(interpreter_frame_oop_temp_offset));
 616       } else {
 617         oop* obj_p = (oop*)tos_addr;
 618         obj = (obj_p == NULL) ? (oop)NULL : *obj_p;
 619       }
 620       assert(obj == NULL || Universe::heap()->is_in(obj), "sanity check");
 621       *oop_result = obj;
 622       break;
 623     }
 624     case T_BOOLEAN : value_result->z = *(jboolean*)tos_addr; break;
 625     case T_BYTE    : value_result->b = *(jbyte*)tos_addr; break;
 626     case T_CHAR    : value_result->c = *(jchar*)tos_addr; break;
 627     case T_SHORT   : value_result->s = *(jshort*)tos_addr; break;
 628     case T_INT     : value_result->i = *(jint*)tos_addr; break;
 629     case T_LONG    : value_result->j = *(jlong*)tos_addr; break;
 630     case T_FLOAT   : {
 631 #ifdef AMD64


 692   if (_cb != NULL) {
 693     // use the frame size if valid
 694     int size = _cb->frame_size();
 695     if (size > 0) {
 696       return unextended_sp() + size;
 697     }
 698   }
 699   // else rely on fp()
 700   assert(! is_compiled_frame(), "unknown compiled frame size");
 701   return fp();
 702 }
 703 
 704 #ifndef PRODUCT
 705 // This is a generic constructor which is only used by pns() in debug.cpp.
 706 frame::frame(void* sp, void* fp, void* pc) {
 707   init((intptr_t*)sp, (intptr_t*)fp, (address)pc);
 708 }
 709 
 710 void frame::pd_ps() {}
 711 #endif
 712 
 713 // Check for a method with scalarized value type arguments that needs
 714 // a stack repair and return the repaired sender stack pointer.
 715 intptr_t* frame::repair_sender_sp(intptr_t* sender_sp, intptr_t** saved_fp_addr) const {
 716   CompiledMethod* cm = _cb->as_compiled_method_or_null();
 717   if (cm != NULL && cm->needs_stack_repair()) {
 718     // The stack increment resides just below the saved rbp on the stack
 719     // and does not account for the return address.
 720     intptr_t* real_frame_size_addr = (intptr_t*) (saved_fp_addr - 1);
 721     int real_frame_size = (*real_frame_size_addr) / wordSize;
 722     if (!cm->is_compiled_by_c1()) {
 723       // Add size of return address (C1 already includes the RA size)
 724       real_frame_size += 1;
 725     }
 726     assert(real_frame_size >= _cb->frame_size(), "invalid frame size");
 727     sender_sp = unextended_sp() + real_frame_size;
 728   }
 729   return sender_sp;
 730 }
 731 
 732 void JavaFrameAnchor::make_walkable(JavaThread* thread) {
 733   // last frame set?
 734   if (last_Java_sp() == NULL) return;
 735   // already walkable?
 736   if (walkable()) return;
 737   vmassert(Thread::current() == (Thread*)thread, "not current thread");
 738   vmassert(last_Java_sp() != NULL, "not called from Java code?");
 739   vmassert(last_Java_pc() == NULL, "already walkable");
 740   capture_last_Java_pc();
 741   vmassert(walkable(), "something went wrong");
 742 }
 743 
 744 void JavaFrameAnchor::capture_last_Java_pc() {
 745   vmassert(_last_Java_sp != NULL, "no last frame set");
 746   vmassert(_last_Java_pc == NULL, "already walkable");
 747   _last_Java_pc = (address)_last_Java_sp[-1];
 748 }
< prev index next >