< prev index next >

src/hotspot/share/runtime/frame.cpp

Print this page




  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 "classfile/moduleEntry.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/vmreg.inline.hpp"
  29 #include "compiler/abstractCompiler.hpp"
  30 #include "compiler/disassembler.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "interpreter/oopMapCache.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/markOop.hpp"
  37 #include "oops/method.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "oops/oop.inline.hpp"

  40 #include "oops/verifyOopClosure.hpp"
  41 #include "prims/methodHandles.hpp"
  42 #include "runtime/frame.inline.hpp"
  43 #include "runtime/handles.inline.hpp"
  44 #include "runtime/javaCalls.hpp"
  45 #include "runtime/monitorChunk.hpp"
  46 #include "runtime/os.hpp"
  47 #include "runtime/sharedRuntime.hpp"
  48 #include "runtime/signature.hpp"
  49 #include "runtime/stubCodeGenerator.hpp"
  50 #include "runtime/stubRoutines.hpp"
  51 #include "runtime/thread.inline.hpp"
  52 #include "utilities/debug.hpp"
  53 #include "utilities/decoder.hpp"
  54 #include "utilities/formatBuffer.hpp"
  55 
  56 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
  57   _thread         = thread;
  58   _update_map     = update_map;
  59   clear();


 663 }
 664 
 665 
 666 /*
 667   The interpreter_frame_expression_stack_at method in the case of SPARC needs the
 668   max_stack value of the method in order to compute the expression stack address.
 669   It uses the Method* in order to get the max_stack value but during GC this
 670   Method* value saved on the frame is changed by reverse_and_push and hence cannot
 671   be used. So we save the max_stack value in the FrameClosure object and pass it
 672   down to the interpreter_frame_expression_stack_at method
 673 */
 674 class InterpreterFrameClosure : public OffsetClosure {
 675  private:
 676   frame* _fr;
 677   OopClosure* _f;
 678   int    _max_locals;
 679   int    _max_stack;
 680 
 681  public:
 682   InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
 683                           OopClosure* f) {
 684     _fr         = fr;
 685     _max_locals = max_locals;
 686     _max_stack  = max_stack;
 687     _f          = f;
 688   }
 689 
 690   void offset_do(int offset) {
 691     oop* addr;
 692     if (offset < _max_locals) {
 693       addr = (oop*) _fr->interpreter_frame_local_at(offset);
 694       assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
 695       _f->do_oop(addr);


 696     } else {
 697       addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
 698       // In case of exceptions, the expression stack is invalid and the esp will be reset to express
 699       // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
 700       bool in_stack;
 701       if (frame::interpreter_frame_expression_stack_direction() > 0) {
 702         in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
 703       } else {
 704         in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
 705       }
 706       if (in_stack) {
 707         _f->do_oop(addr);


 708       }
 709     }
 710   }
 711 
 712   int max_locals()  { return _max_locals; }
 713   frame* fr()       { return _fr; }
 714 };
 715 
 716 
 717 class InterpretedArgumentOopFinder: public SignatureInfo {
 718  private:
 719   OopClosure* _f;        // Closure to invoke
 720   int    _offset;        // TOS-relative offset, decremented with each argument
 721   bool   _has_receiver;  // true if the callee has a receiver
 722   frame* _fr;
 723 
 724   void set(int size, BasicType type) {
 725     _offset -= size;
 726     if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();
 727   }
 728 
 729   void oop_offset_do() {
 730     oop* addr;
 731     addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
 732     _f->do_oop(addr);
 733   }
 734 
 735  public:
 736   InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
 737     // compute size of arguments
 738     int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
 739     assert(!fr->is_interpreted_frame() ||
 740            args_size <= fr->interpreter_frame_expression_stack_size(),
 741             "args cannot be on stack anymore");
 742     // initialize InterpretedArgumentOopFinder
 743     _f         = f;
 744     _fr        = fr;
 745     _offset    = args_size;
 746   }


 759 //         +-----------+
 760 //   sp -> |  last arg |
 761 //         +-----------+
 762 //         :    :::    :
 763 //         +-----------+
 764 // (sp+n)->|  first arg|
 765 //         +-----------+
 766 
 767 
 768 
 769 // visits and GC's all the arguments in entry frame
 770 class EntryFrameOopFinder: public SignatureInfo {
 771  private:
 772   bool   _is_static;
 773   int    _offset;
 774   frame* _fr;
 775   OopClosure* _f;
 776 
 777   void set(int size, BasicType type) {
 778     assert (_offset >= 0, "illegal offset");
 779     if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);
 780     _offset -= size;
 781   }
 782 
 783   void oop_at_offset_do(int offset) {
 784     assert (offset >= 0, "illegal offset");
 785     oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
 786     _f->do_oop(addr);
 787   }
 788 
 789  public:
 790    EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
 791      _f = NULL; // will be set later
 792      _fr = frame;
 793      _is_static = is_static;
 794      _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
 795    }
 796 
 797   void arguments_do(OopClosure* f) {
 798     _f = f;
 799     if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver


 860       signature = call.signature();
 861       has_receiver = call.has_receiver();
 862       if (map->include_argument_oops() &&
 863           interpreter_frame_expression_stack_size() > 0) {
 864         ResourceMark rm(thread);  // is this right ???
 865         // we are at a call site & the expression stack is not empty
 866         // => process callee's arguments
 867         //
 868         // Note: The expression stack can be empty if an exception
 869         //       occurred during method resolution/execution. In all
 870         //       cases we empty the expression stack completely be-
 871         //       fore handling the exception (the exception handling
 872         //       code in the interpreter calls a blocking runtime
 873         //       routine which can cause this code to be executed).
 874         //       (was bug gri 7/27/98)
 875         oops_interpreted_arguments_do(signature, has_receiver, f);
 876       }
 877     }
 878   }
 879 
 880   InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
 881 
 882   // process locals & expression stack
 883   InterpreterOopMap mask;
 884   if (query_oop_map_cache) {
 885     m->mask_for(bci, &mask);
 886   } else {
 887     OopMapCache::compute_one_oop_map(m, bci, &mask);
 888   }
 889   mask.iterate_oop(&blk);
 890 }
 891 

















 892 
 893 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
 894   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
 895   finder.oops_do();
 896 }
 897 
 898 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
 899   assert(_cb != NULL, "sanity check");
 900   if (_cb->oop_maps() != NULL) {
 901     OopMapSet::oops_do(this, reg_map, f);
 902 
 903     // Preserve potential arguments for a callee. We handle this by dispatching
 904     // on the codeblob. For c2i, we do
 905     if (reg_map->include_argument_oops()) {
 906       _cb->preserve_callee_argument_oops(*this, reg_map, f);
 907     }
 908   }
 909   // In cases where perm gen is collected, GC will want to mark
 910   // oops referenced from nmethods active on thread stacks so as to
 911   // prevent them from being collected. However, this visit should be
 912   // restricted to certain phases of the collection only. The
 913   // closure decides how it wants nmethods to be traced.
 914   if (cf != NULL)
 915     cf->do_code_blob(_cb);
 916 }
 917 
 918 class CompiledArgumentOopFinder: public SignatureInfo {
 919  protected:
 920   OopClosure*     _f;
 921   int             _offset;        // the current offset, incremented with each argument
 922   bool            _has_receiver;  // true if the callee has a receiver
 923   bool            _has_appendix;  // true if the call has an appendix
 924   frame           _fr;
 925   RegisterMap*    _reg_map;
 926   int             _arg_size;
 927   VMRegPair*      _regs;        // VMReg list of arguments
 928 
 929   void set(int size, BasicType type) {
 930     if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();
 931     _offset += size;
 932   }
 933 
 934   virtual void handle_oop_offset() {
 935     // Extract low order register number from register array.
 936     // In LP64-land, the high-order bits are valid but unhelpful.

 937     VMReg reg = _regs[_offset].first();
 938     oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
 939     _f->do_oop(loc);
 940   }
 941 
 942  public:
 943   CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr,  const RegisterMap* reg_map)
 944     : SignatureInfo(signature) {
 945 
 946     // initialize CompiledArgumentOopFinder
 947     _f         = f;
 948     _offset    = 0;
 949     _has_receiver = has_receiver;
 950     _has_appendix = has_appendix;
 951     _fr        = fr;
 952     _reg_map   = (RegisterMap*)reg_map;
 953     _arg_size  = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);
 954 
 955     int arg_size;
 956     _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);
 957     assert(arg_size == _arg_size, "wrong arg size");
 958   }
 959 
 960   void oops_do() {
 961     if (_has_receiver) {
 962       handle_oop_offset();
 963       _offset++;
 964     }
 965     iterate_parameters();
 966     if (_has_appendix) {
 967       handle_oop_offset();
 968       _offset++;
 969     }
 970   }
 971 };
 972 
 973 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix,
 974                                        const RegisterMap* reg_map, OopClosure* f) {
 975   ResourceMark rm;
 976   CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
 977   finder.oops_do();




  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 "classfile/moduleEntry.hpp"
  27 #include "code/codeCache.hpp"
  28 #include "code/vmreg.inline.hpp"
  29 #include "compiler/abstractCompiler.hpp"
  30 #include "compiler/disassembler.hpp"
  31 #include "gc/shared/collectedHeap.inline.hpp"
  32 #include "interpreter/interpreter.hpp"
  33 #include "interpreter/oopMapCache.hpp"
  34 #include "memory/resourceArea.hpp"
  35 #include "memory/universe.hpp"
  36 #include "oops/markOop.hpp"
  37 #include "oops/method.hpp"
  38 #include "oops/methodData.hpp"
  39 #include "oops/oop.inline.hpp"
  40 #include "oops/valueKlass.hpp"
  41 #include "oops/verifyOopClosure.hpp"
  42 #include "prims/methodHandles.hpp"
  43 #include "runtime/frame.inline.hpp"
  44 #include "runtime/handles.inline.hpp"
  45 #include "runtime/javaCalls.hpp"
  46 #include "runtime/monitorChunk.hpp"
  47 #include "runtime/os.hpp"
  48 #include "runtime/sharedRuntime.hpp"
  49 #include "runtime/signature.hpp"
  50 #include "runtime/stubCodeGenerator.hpp"
  51 #include "runtime/stubRoutines.hpp"
  52 #include "runtime/thread.inline.hpp"
  53 #include "utilities/debug.hpp"
  54 #include "utilities/decoder.hpp"
  55 #include "utilities/formatBuffer.hpp"
  56 
  57 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
  58   _thread         = thread;
  59   _update_map     = update_map;
  60   clear();


 664 }
 665 
 666 
 667 /*
 668   The interpreter_frame_expression_stack_at method in the case of SPARC needs the
 669   max_stack value of the method in order to compute the expression stack address.
 670   It uses the Method* in order to get the max_stack value but during GC this
 671   Method* value saved on the frame is changed by reverse_and_push and hence cannot
 672   be used. So we save the max_stack value in the FrameClosure object and pass it
 673   down to the interpreter_frame_expression_stack_at method
 674 */
 675 class InterpreterFrameClosure : public OffsetClosure {
 676  private:
 677   frame* _fr;
 678   OopClosure* _f;
 679   int    _max_locals;
 680   int    _max_stack;
 681 
 682  public:
 683   InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
 684                           OopClosure* f, BufferedValueClosure* bvt_f) {
 685     _fr         = fr;
 686     _max_locals = max_locals;
 687     _max_stack  = max_stack;
 688     _f          = f;
 689   }
 690 
 691   void offset_do(int offset) {
 692     oop* addr;
 693     if (offset < _max_locals) {
 694       addr = (oop*) _fr->interpreter_frame_local_at(offset);
 695       assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
 696       if (_f != NULL) {
 697         _f->do_oop(addr);
 698       }
 699     } else {
 700       addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
 701       // In case of exceptions, the expression stack is invalid and the esp will be reset to express
 702       // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
 703       bool in_stack;
 704       if (frame::interpreter_frame_expression_stack_direction() > 0) {
 705         in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
 706       } else {
 707         in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
 708       }
 709       if (in_stack) {
 710         if (_f != NULL) {
 711           _f->do_oop(addr);
 712         }
 713       }
 714     }
 715   }
 716 
 717   int max_locals()  { return _max_locals; }
 718   frame* fr()       { return _fr; }
 719 };
 720 
 721 
 722 class InterpretedArgumentOopFinder: public SignatureInfo {
 723  private:
 724   OopClosure* _f;        // Closure to invoke
 725   int    _offset;        // TOS-relative offset, decremented with each argument
 726   bool   _has_receiver;  // true if the callee has a receiver
 727   frame* _fr;
 728 
 729   void set(int size, BasicType type) {
 730     _offset -= size;
 731     if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) oop_offset_do();
 732   }
 733 
 734   void oop_offset_do() {
 735     oop* addr;
 736     addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
 737     _f->do_oop(addr);
 738   }
 739 
 740  public:
 741   InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
 742     // compute size of arguments
 743     int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
 744     assert(!fr->is_interpreted_frame() ||
 745            args_size <= fr->interpreter_frame_expression_stack_size(),
 746             "args cannot be on stack anymore");
 747     // initialize InterpretedArgumentOopFinder
 748     _f         = f;
 749     _fr        = fr;
 750     _offset    = args_size;
 751   }


 764 //         +-----------+
 765 //   sp -> |  last arg |
 766 //         +-----------+
 767 //         :    :::    :
 768 //         +-----------+
 769 // (sp+n)->|  first arg|
 770 //         +-----------+
 771 
 772 
 773 
 774 // visits and GC's all the arguments in entry frame
 775 class EntryFrameOopFinder: public SignatureInfo {
 776  private:
 777   bool   _is_static;
 778   int    _offset;
 779   frame* _fr;
 780   OopClosure* _f;
 781 
 782   void set(int size, BasicType type) {
 783     assert (_offset >= 0, "illegal offset");
 784     if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) oop_at_offset_do(_offset);
 785     _offset -= size;
 786   }
 787 
 788   void oop_at_offset_do(int offset) {
 789     assert (offset >= 0, "illegal offset");
 790     oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
 791     _f->do_oop(addr);
 792   }
 793 
 794  public:
 795    EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
 796      _f = NULL; // will be set later
 797      _fr = frame;
 798      _is_static = is_static;
 799      _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
 800    }
 801 
 802   void arguments_do(OopClosure* f) {
 803     _f = f;
 804     if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver


 865       signature = call.signature();
 866       has_receiver = call.has_receiver();
 867       if (map->include_argument_oops() &&
 868           interpreter_frame_expression_stack_size() > 0) {
 869         ResourceMark rm(thread);  // is this right ???
 870         // we are at a call site & the expression stack is not empty
 871         // => process callee's arguments
 872         //
 873         // Note: The expression stack can be empty if an exception
 874         //       occurred during method resolution/execution. In all
 875         //       cases we empty the expression stack completely be-
 876         //       fore handling the exception (the exception handling
 877         //       code in the interpreter calls a blocking runtime
 878         //       routine which can cause this code to be executed).
 879         //       (was bug gri 7/27/98)
 880         oops_interpreted_arguments_do(signature, has_receiver, f);
 881       }
 882     }
 883   }
 884 
 885   InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f, NULL);
 886 
 887   // process locals & expression stack
 888   InterpreterOopMap mask;
 889   if (query_oop_map_cache) {
 890     m->mask_for(bci, &mask);
 891   } else {
 892     OopMapCache::compute_one_oop_map(m, bci, &mask);
 893   }
 894   mask.iterate_oop(&blk);
 895 }
 896 
 897 void frame::buffered_values_interpreted_do(BufferedValueClosure* f) {
 898   assert(is_interpreted_frame(), "Not an interpreted frame");
 899   Thread *thread = Thread::current();
 900   methodHandle m (thread, interpreter_frame_method());
 901   jint      bci = interpreter_frame_bci();
 902 
 903   assert(m->is_method(), "checking frame value");
 904   assert(!m->is_native() && bci >= 0 && bci < m->code_size(),
 905          "invalid bci value");
 906 
 907   InterpreterFrameClosure blk(this, m->max_locals(), m->max_stack(), NULL, f);
 908 
 909   // process locals & expression stack
 910   InterpreterOopMap mask;
 911   m->mask_for(bci, &mask);
 912   mask.iterate_oop(&blk);
 913 }
 914 
 915 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
 916   InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
 917   finder.oops_do();
 918 }
 919 
 920 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
 921   assert(_cb != NULL, "sanity check");
 922   if (_cb->oop_maps() != NULL) {
 923     OopMapSet::oops_do(this, reg_map, f);
 924 
 925     // Preserve potential arguments for a callee. We handle this by dispatching
 926     // on the codeblob. For c2i, we do
 927     if (reg_map->include_argument_oops()) {
 928       _cb->preserve_callee_argument_oops(*this, reg_map, f);
 929     }
 930   }
 931   // In cases where perm gen is collected, GC will want to mark
 932   // oops referenced from nmethods active on thread stacks so as to
 933   // prevent them from being collected. However, this visit should be
 934   // restricted to certain phases of the collection only. The
 935   // closure decides how it wants nmethods to be traced.
 936   if (cf != NULL)
 937     cf->do_code_blob(_cb);
 938 }
 939 
 940 class CompiledArgumentOopFinder: public SignatureInfo {
 941  protected:
 942   OopClosure*     _f;
 943   int             _offset;        // the current offset, incremented with each argument
 944   bool            _has_receiver;  // true if the callee has a receiver
 945   bool            _has_appendix;  // true if the call has an appendix
 946   frame           _fr;
 947   RegisterMap*    _reg_map;
 948   int             _arg_size;
 949   VMRegPair*      _regs;        // VMReg list of arguments
 950 
 951   void set(int size, BasicType type) {
 952     if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) handle_oop_offset();
 953     _offset += size;
 954   }
 955 
 956   virtual void handle_oop_offset() {
 957     // Extract low order register number from register array.
 958     // In LP64-land, the high-order bits are valid but unhelpful.
 959     assert(_offset < _arg_size, "out of bounds");
 960     VMReg reg = _regs[_offset].first();
 961     oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
 962     _f->do_oop(loc);
 963   }
 964 
 965  public:
 966   CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)
 967     : SignatureInfo(signature) {
 968 
 969     // initialize CompiledArgumentOopFinder
 970     _f         = f;
 971     _offset    = 0;
 972     _has_receiver = has_receiver;
 973     _has_appendix = has_appendix;
 974     _fr        = fr;
 975     _reg_map   = (RegisterMap*)reg_map;
 976     _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &_arg_size);




 977   }
 978 
 979   void oops_do() {
 980     if (_has_receiver) {
 981       handle_oop_offset();
 982       _offset++;
 983     }
 984     iterate_parameters();
 985     if (_has_appendix) {
 986       handle_oop_offset();
 987       _offset++;
 988     }
 989   }
 990 };
 991 
 992 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix,
 993                                        const RegisterMap* reg_map, OopClosure* f) {
 994   ResourceMark rm;
 995   CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
 996   finder.oops_do();


< prev index next >