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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/vmreg.inline.hpp"
28 #include "compiler/abstractCompiler.hpp"
29 #include "compiler/disassembler.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/oopMapCache.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/markOop.hpp"
36 #include "oops/method.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "oops/verifyOopClosure.hpp"
40 #include "prims/methodHandles.hpp"
41 #include "runtime/frame.inline.hpp"
42 #include "runtime/handles.inline.hpp"
43 #include "runtime/javaCalls.hpp"
44 #include "runtime/monitorChunk.hpp"
45 #include "runtime/os.hpp"
46 #include "runtime/sharedRuntime.hpp"
47 #include "runtime/signature.hpp"
48 #include "runtime/stubCodeGenerator.hpp"
49 #include "runtime/stubRoutines.hpp"
50 #include "runtime/thread.inline.hpp"
51 #include "utilities/debug.hpp"
52 #include "utilities/decoder.hpp"
53 #include "utilities/formatBuffer.hpp"
54
55 RegisterMap::RegisterMap(JavaThread *thread, bool update_map) {
56 _thread = thread;
57 _update_map = update_map;
58 clear();
715 }
716
717
718 /*
719 The interpreter_frame_expression_stack_at method in the case of SPARC needs the
720 max_stack value of the method in order to compute the expression stack address.
721 It uses the Method* in order to get the max_stack value but during GC this
722 Method* value saved on the frame is changed by reverse_and_push and hence cannot
723 be used. So we save the max_stack value in the FrameClosure object and pass it
724 down to the interpreter_frame_expression_stack_at method
725 */
726 class InterpreterFrameClosure : public OffsetClosure {
727 private:
728 frame* _fr;
729 OopClosure* _f;
730 int _max_locals;
731 int _max_stack;
732
733 public:
734 InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
735 OopClosure* f) {
736 _fr = fr;
737 _max_locals = max_locals;
738 _max_stack = max_stack;
739 _f = f;
740 }
741
742 void offset_do(int offset) {
743 oop* addr;
744 if (offset < _max_locals) {
745 addr = (oop*) _fr->interpreter_frame_local_at(offset);
746 assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
747 _f->do_oop(addr);
748 } else {
749 addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
750 // In case of exceptions, the expression stack is invalid and the esp will be reset to express
751 // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
752 bool in_stack;
753 if (frame::interpreter_frame_expression_stack_direction() > 0) {
754 in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
755 } else {
756 in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
757 }
758 if (in_stack) {
759 _f->do_oop(addr);
760 }
761 }
762 }
763
764 int max_locals() { return _max_locals; }
765 frame* fr() { return _fr; }
766 };
767
768
769 class InterpretedArgumentOopFinder: public SignatureInfo {
770 private:
771 OopClosure* _f; // Closure to invoke
772 int _offset; // TOS-relative offset, decremented with each argument
773 bool _has_receiver; // true if the callee has a receiver
774 frame* _fr;
775
776 void set(int size, BasicType type) {
777 _offset -= size;
778 if (type == T_OBJECT || type == T_ARRAY) oop_offset_do();
779 }
780
781 void oop_offset_do() {
782 oop* addr;
783 addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
784 _f->do_oop(addr);
785 }
786
787 public:
788 InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
789 // compute size of arguments
790 int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
791 assert(!fr->is_interpreted_frame() ||
792 args_size <= fr->interpreter_frame_expression_stack_size(),
793 "args cannot be on stack anymore");
794 // initialize InterpretedArgumentOopFinder
795 _f = f;
796 _fr = fr;
797 _offset = args_size;
798 }
811 // +-----------+
812 // sp -> | last arg |
813 // +-----------+
814 // : ::: :
815 // +-----------+
816 // (sp+n)->| first arg|
817 // +-----------+
818
819
820
821 // visits and GC's all the arguments in entry frame
822 class EntryFrameOopFinder: public SignatureInfo {
823 private:
824 bool _is_static;
825 int _offset;
826 frame* _fr;
827 OopClosure* _f;
828
829 void set(int size, BasicType type) {
830 assert (_offset >= 0, "illegal offset");
831 if (type == T_OBJECT || type == T_ARRAY) oop_at_offset_do(_offset);
832 _offset -= size;
833 }
834
835 void oop_at_offset_do(int offset) {
836 assert (offset >= 0, "illegal offset");
837 oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
838 _f->do_oop(addr);
839 }
840
841 public:
842 EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
843 _f = NULL; // will be set later
844 _fr = frame;
845 _is_static = is_static;
846 _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
847 }
848
849 void arguments_do(OopClosure* f) {
850 _f = f;
851 if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver
912 signature = call.signature();
913 has_receiver = call.has_receiver();
914 if (map->include_argument_oops() &&
915 interpreter_frame_expression_stack_size() > 0) {
916 ResourceMark rm(thread); // is this right ???
917 // we are at a call site & the expression stack is not empty
918 // => process callee's arguments
919 //
920 // Note: The expression stack can be empty if an exception
921 // occurred during method resolution/execution. In all
922 // cases we empty the expression stack completely be-
923 // fore handling the exception (the exception handling
924 // code in the interpreter calls a blocking runtime
925 // routine which can cause this code to be executed).
926 // (was bug gri 7/27/98)
927 oops_interpreted_arguments_do(signature, has_receiver, f);
928 }
929 }
930 }
931
932 InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f);
933
934 // process locals & expression stack
935 InterpreterOopMap mask;
936 if (query_oop_map_cache) {
937 m->mask_for(bci, &mask);
938 } else {
939 OopMapCache::compute_one_oop_map(m, bci, &mask);
940 }
941 mask.iterate_oop(&blk);
942 }
943
944
945 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
946 InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
947 finder.oops_do();
948 }
949
950 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
951 assert(_cb != NULL, "sanity check");
952 if (_cb->oop_maps() != NULL) {
953 OopMapSet::oops_do(this, reg_map, f);
954
955 // Preserve potential arguments for a callee. We handle this by dispatching
956 // on the codeblob. For c2i, we do
957 if (reg_map->include_argument_oops()) {
958 _cb->preserve_callee_argument_oops(*this, reg_map, f);
959 }
960 }
961 // In cases where perm gen is collected, GC will want to mark
962 // oops referenced from nmethods active on thread stacks so as to
963 // prevent them from being collected. However, this visit should be
964 // restricted to certain phases of the collection only. The
965 // closure decides how it wants nmethods to be traced.
966 if (cf != NULL)
967 cf->do_code_blob(_cb);
968 }
969
970 class CompiledArgumentOopFinder: public SignatureInfo {
971 protected:
972 OopClosure* _f;
973 int _offset; // the current offset, incremented with each argument
974 bool _has_receiver; // true if the callee has a receiver
975 bool _has_appendix; // true if the call has an appendix
976 frame _fr;
977 RegisterMap* _reg_map;
978 int _arg_size;
979 VMRegPair* _regs; // VMReg list of arguments
980
981 void set(int size, BasicType type) {
982 if (type == T_OBJECT || type == T_ARRAY) handle_oop_offset();
983 _offset += size;
984 }
985
986 virtual void handle_oop_offset() {
987 // Extract low order register number from register array.
988 // In LP64-land, the high-order bits are valid but unhelpful.
989 VMReg reg = _regs[_offset].first();
990 oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
991 _f->do_oop(loc);
992 }
993
994 public:
995 CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)
996 : SignatureInfo(signature) {
997
998 // initialize CompiledArgumentOopFinder
999 _f = f;
1000 _offset = 0;
1001 _has_receiver = has_receiver;
1002 _has_appendix = has_appendix;
1003 _fr = fr;
1004 _reg_map = (RegisterMap*)reg_map;
1005 _arg_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0) + (has_appendix ? 1 : 0);
1006
1007 int arg_size;
1008 _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &arg_size);
1009 assert(arg_size == _arg_size, "wrong arg size");
1010 }
1011
1012 void oops_do() {
1013 if (_has_receiver) {
1014 handle_oop_offset();
1015 _offset++;
1016 }
1017 iterate_parameters();
1018 if (_has_appendix) {
1019 handle_oop_offset();
1020 _offset++;
1021 }
1022 }
1023 };
1024
1025 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix,
1026 const RegisterMap* reg_map, OopClosure* f) {
1027 ResourceMark rm;
1028 CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
1029 finder.oops_do();
|
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 *
23 */
24
25 #include "precompiled.hpp"
26 #include "code/codeCache.hpp"
27 #include "code/vmreg.inline.hpp"
28 #include "compiler/abstractCompiler.hpp"
29 #include "compiler/disassembler.hpp"
30 #include "gc/shared/collectedHeap.inline.hpp"
31 #include "interpreter/interpreter.hpp"
32 #include "interpreter/oopMapCache.hpp"
33 #include "memory/resourceArea.hpp"
34 #include "memory/universe.hpp"
35 #include "oops/markOop.hpp"
36 #include "oops/method.hpp"
37 #include "oops/methodData.hpp"
38 #include "oops/oop.inline.hpp"
39 #include "oops/valueKlass.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();
716 }
717
718
719 /*
720 The interpreter_frame_expression_stack_at method in the case of SPARC needs the
721 max_stack value of the method in order to compute the expression stack address.
722 It uses the Method* in order to get the max_stack value but during GC this
723 Method* value saved on the frame is changed by reverse_and_push and hence cannot
724 be used. So we save the max_stack value in the FrameClosure object and pass it
725 down to the interpreter_frame_expression_stack_at method
726 */
727 class InterpreterFrameClosure : public OffsetClosure {
728 private:
729 frame* _fr;
730 OopClosure* _f;
731 int _max_locals;
732 int _max_stack;
733
734 public:
735 InterpreterFrameClosure(frame* fr, int max_locals, int max_stack,
736 OopClosure* f, BufferedValueClosure* bvt_f) {
737 _fr = fr;
738 _max_locals = max_locals;
739 _max_stack = max_stack;
740 _f = f;
741 }
742
743 void offset_do(int offset) {
744 oop* addr;
745 if (offset < _max_locals) {
746 addr = (oop*) _fr->interpreter_frame_local_at(offset);
747 assert((intptr_t*)addr >= _fr->sp(), "must be inside the frame");
748 if (_f != NULL) {
749 _f->do_oop(addr);
750 }
751 } else {
752 addr = (oop*) _fr->interpreter_frame_expression_stack_at((offset - _max_locals));
753 // In case of exceptions, the expression stack is invalid and the esp will be reset to express
754 // this condition. Therefore, we call f only if addr is 'inside' the stack (i.e., addr >= esp for Intel).
755 bool in_stack;
756 if (frame::interpreter_frame_expression_stack_direction() > 0) {
757 in_stack = (intptr_t*)addr <= _fr->interpreter_frame_tos_address();
758 } else {
759 in_stack = (intptr_t*)addr >= _fr->interpreter_frame_tos_address();
760 }
761 if (in_stack) {
762 if (_f != NULL) {
763 _f->do_oop(addr);
764 }
765 }
766 }
767 }
768
769 int max_locals() { return _max_locals; }
770 frame* fr() { return _fr; }
771 };
772
773
774 class InterpretedArgumentOopFinder: public SignatureInfo {
775 private:
776 OopClosure* _f; // Closure to invoke
777 int _offset; // TOS-relative offset, decremented with each argument
778 bool _has_receiver; // true if the callee has a receiver
779 frame* _fr;
780
781 void set(int size, BasicType type) {
782 _offset -= size;
783 if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) oop_offset_do();
784 }
785
786 void oop_offset_do() {
787 oop* addr;
788 addr = (oop*)_fr->interpreter_frame_tos_at(_offset);
789 _f->do_oop(addr);
790 }
791
792 public:
793 InterpretedArgumentOopFinder(Symbol* signature, bool has_receiver, frame* fr, OopClosure* f) : SignatureInfo(signature), _has_receiver(has_receiver) {
794 // compute size of arguments
795 int args_size = ArgumentSizeComputer(signature).size() + (has_receiver ? 1 : 0);
796 assert(!fr->is_interpreted_frame() ||
797 args_size <= fr->interpreter_frame_expression_stack_size(),
798 "args cannot be on stack anymore");
799 // initialize InterpretedArgumentOopFinder
800 _f = f;
801 _fr = fr;
802 _offset = args_size;
803 }
816 // +-----------+
817 // sp -> | last arg |
818 // +-----------+
819 // : ::: :
820 // +-----------+
821 // (sp+n)->| first arg|
822 // +-----------+
823
824
825
826 // visits and GC's all the arguments in entry frame
827 class EntryFrameOopFinder: public SignatureInfo {
828 private:
829 bool _is_static;
830 int _offset;
831 frame* _fr;
832 OopClosure* _f;
833
834 void set(int size, BasicType type) {
835 assert (_offset >= 0, "illegal offset");
836 if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) oop_at_offset_do(_offset);
837 _offset -= size;
838 }
839
840 void oop_at_offset_do(int offset) {
841 assert (offset >= 0, "illegal offset");
842 oop* addr = (oop*) _fr->entry_frame_argument_at(offset);
843 _f->do_oop(addr);
844 }
845
846 public:
847 EntryFrameOopFinder(frame* frame, Symbol* signature, bool is_static) : SignatureInfo(signature) {
848 _f = NULL; // will be set later
849 _fr = frame;
850 _is_static = is_static;
851 _offset = ArgumentSizeComputer(signature).size() - 1; // last parameter is at index 0
852 }
853
854 void arguments_do(OopClosure* f) {
855 _f = f;
856 if (!_is_static) oop_at_offset_do(_offset+1); // do the receiver
917 signature = call.signature();
918 has_receiver = call.has_receiver();
919 if (map->include_argument_oops() &&
920 interpreter_frame_expression_stack_size() > 0) {
921 ResourceMark rm(thread); // is this right ???
922 // we are at a call site & the expression stack is not empty
923 // => process callee's arguments
924 //
925 // Note: The expression stack can be empty if an exception
926 // occurred during method resolution/execution. In all
927 // cases we empty the expression stack completely be-
928 // fore handling the exception (the exception handling
929 // code in the interpreter calls a blocking runtime
930 // routine which can cause this code to be executed).
931 // (was bug gri 7/27/98)
932 oops_interpreted_arguments_do(signature, has_receiver, f);
933 }
934 }
935 }
936
937 InterpreterFrameClosure blk(this, max_locals, m->max_stack(), f, NULL);
938
939 // process locals & expression stack
940 InterpreterOopMap mask;
941 if (query_oop_map_cache) {
942 m->mask_for(bci, &mask);
943 } else {
944 OopMapCache::compute_one_oop_map(m, bci, &mask);
945 }
946 mask.iterate_oop(&blk);
947 }
948
949 void frame::buffered_values_interpreted_do(BufferedValueClosure* f) {
950 assert(is_interpreted_frame(), "Not an interpreted frame");
951 Thread *thread = Thread::current();
952 methodHandle m (thread, interpreter_frame_method());
953 jint bci = interpreter_frame_bci();
954
955 assert(m->is_method(), "checking frame value");
956 assert(!m->is_native() && bci >= 0 && bci < m->code_size(),
957 "invalid bci value");
958
959 InterpreterFrameClosure blk(this, m->max_locals(), m->max_stack(), NULL, f);
960
961 // process locals & expression stack
962 InterpreterOopMap mask;
963 m->mask_for(bci, &mask);
964 mask.iterate_oop(&blk);
965 }
966
967 void frame::oops_interpreted_arguments_do(Symbol* signature, bool has_receiver, OopClosure* f) {
968 InterpretedArgumentOopFinder finder(signature, has_receiver, this, f);
969 finder.oops_do();
970 }
971
972 void frame::oops_code_blob_do(OopClosure* f, CodeBlobClosure* cf, const RegisterMap* reg_map) {
973 assert(_cb != NULL, "sanity check");
974 if (_cb->oop_maps() != NULL) {
975 OopMapSet::oops_do(this, reg_map, f);
976
977 // Preserve potential arguments for a callee. We handle this by dispatching
978 // on the codeblob. For c2i, we do
979 if (reg_map->include_argument_oops()) {
980 _cb->preserve_callee_argument_oops(*this, reg_map, f);
981 }
982 }
983 // In cases where perm gen is collected, GC will want to mark
984 // oops referenced from nmethods active on thread stacks so as to
985 // prevent them from being collected. However, this visit should be
986 // restricted to certain phases of the collection only. The
987 // closure decides how it wants nmethods to be traced.
988 if (cf != NULL)
989 cf->do_code_blob(_cb);
990 }
991
992 class CompiledArgumentOopFinder: public SignatureInfo {
993 protected:
994 OopClosure* _f;
995 int _offset; // the current offset, incremented with each argument
996 bool _has_receiver; // true if the callee has a receiver
997 bool _has_appendix; // true if the call has an appendix
998 frame _fr;
999 RegisterMap* _reg_map;
1000 int _arg_size;
1001 VMRegPair* _regs; // VMReg list of arguments
1002
1003 void set(int size, BasicType type) {
1004 if (type == T_OBJECT || type == T_ARRAY || type == T_VALUETYPE) handle_oop_offset();
1005 _offset += size;
1006 }
1007
1008 virtual void handle_oop_offset() {
1009 // Extract low order register number from register array.
1010 // In LP64-land, the high-order bits are valid but unhelpful.
1011 assert(_offset < _arg_size, "out of bounds");
1012 VMReg reg = _regs[_offset].first();
1013 oop *loc = _fr.oopmapreg_to_location(reg, _reg_map);
1014 _f->do_oop(loc);
1015 }
1016
1017 public:
1018 CompiledArgumentOopFinder(Symbol* signature, bool has_receiver, bool has_appendix, OopClosure* f, frame fr, const RegisterMap* reg_map)
1019 : SignatureInfo(signature) {
1020
1021 // initialize CompiledArgumentOopFinder
1022 _f = f;
1023 _offset = 0;
1024 _has_receiver = has_receiver;
1025 _has_appendix = has_appendix;
1026 _fr = fr;
1027 _reg_map = (RegisterMap*)reg_map;
1028 _regs = SharedRuntime::find_callee_arguments(signature, has_receiver, has_appendix, &_arg_size);
1029 }
1030
1031 void oops_do() {
1032 if (_has_receiver) {
1033 handle_oop_offset();
1034 _offset++;
1035 }
1036 iterate_parameters();
1037 if (_has_appendix) {
1038 handle_oop_offset();
1039 _offset++;
1040 }
1041 }
1042 };
1043
1044 void frame::oops_compiled_arguments_do(Symbol* signature, bool has_receiver, bool has_appendix,
1045 const RegisterMap* reg_map, OopClosure* f) {
1046 ResourceMark rm;
1047 CompiledArgumentOopFinder finder(signature, has_receiver, has_appendix, f, *this, reg_map);
1048 finder.oops_do();
|