Mercurial > hg > graal-compiler
comparison src/share/vm/c1/c1_Runtime1.cpp @ 2142:8012aa3ccede
4926272: methodOopDesc::method_from_bcp is unsafe
Reviewed-by: coleenp, jrose, kvn, dcubed
author | never |
---|---|
date | Thu, 13 Jan 2011 22:15:41 -0800 |
parents | ac637b7220d1 |
children | e4fee0bdaa85 |
comparison
equal
deleted
inserted
replaced
2130:34d64ad817f4 | 2142:8012aa3ccede |
---|---|
1 /* | 1 /* |
2 * Copyright (c) 1999, 2010, Oracle and/or its affiliates. All rights reserved. | 2 * Copyright (c) 1999, 2011, Oracle and/or its affiliates. All rights reserved. |
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. | 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 * | 4 * |
5 * This code is free software; you can redistribute it and/or modify it | 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 | 6 * under the terms of the GNU General Public License version 2 only, as |
7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
367 CompLevel level = (CompLevel)nm->comp_level(); | 367 CompLevel level = (CompLevel)nm->comp_level(); |
368 int bci = InvocationEntryBci; | 368 int bci = InvocationEntryBci; |
369 if (branch_bci != InvocationEntryBci) { | 369 if (branch_bci != InvocationEntryBci) { |
370 // Compute desination bci | 370 // Compute desination bci |
371 address pc = method()->code_base() + branch_bci; | 371 address pc = method()->code_base() + branch_bci; |
372 Bytecodes::Code branch = Bytecodes::code_at(pc, method()); | 372 Bytecodes::Code branch = Bytecodes::code_at(method(), pc); |
373 int offset = 0; | 373 int offset = 0; |
374 switch (branch) { | 374 switch (branch) { |
375 case Bytecodes::_if_icmplt: case Bytecodes::_iflt: | 375 case Bytecodes::_if_icmplt: case Bytecodes::_iflt: |
376 case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt: | 376 case Bytecodes::_if_icmpgt: case Bytecodes::_ifgt: |
377 case Bytecodes::_if_icmple: case Bytecodes::_ifle: | 377 case Bytecodes::_if_icmple: case Bytecodes::_ifle: |
657 } | 657 } |
658 JRT_END | 658 JRT_END |
659 | 659 |
660 | 660 |
661 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) { | 661 static klassOop resolve_field_return_klass(methodHandle caller, int bci, TRAPS) { |
662 Bytecode_field* field_access = Bytecode_field_at(caller, bci); | 662 Bytecode_field field_access(caller, bci); |
663 // This can be static or non-static field access | 663 // This can be static or non-static field access |
664 Bytecodes::Code code = field_access->code(); | 664 Bytecodes::Code code = field_access.code(); |
665 | 665 |
666 // We must load class, initialize class and resolvethe field | 666 // We must load class, initialize class and resolvethe field |
667 FieldAccessInfo result; // initialize class if needed | 667 FieldAccessInfo result; // initialize class if needed |
668 constantPoolHandle constants(THREAD, caller->constants()); | 668 constantPoolHandle constants(THREAD, caller->constants()); |
669 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK_NULL); | 669 LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK_NULL); |
670 return result.klass()(); | 670 return result.klass()(); |
671 } | 671 } |
672 | 672 |
673 | 673 |
674 // | 674 // |
765 | 765 |
766 int bci = vfst.bci(); | 766 int bci = vfst.bci(); |
767 | 767 |
768 Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc()); | 768 Events::log("patch_code @ " INTPTR_FORMAT , caller_frame.pc()); |
769 | 769 |
770 Bytecodes::Code code = Bytecode_at(caller_method->bcp_from(bci))->java_code(); | 770 Bytecodes::Code code = caller_method()->java_code_at(bci); |
771 | 771 |
772 #ifndef PRODUCT | 772 #ifndef PRODUCT |
773 // this is used by assertions in the access_field_patching_id | 773 // this is used by assertions in the access_field_patching_id |
774 BasicType patch_field_type = T_ILLEGAL; | 774 BasicType patch_field_type = T_ILLEGAL; |
775 #endif // PRODUCT | 775 #endif // PRODUCT |
777 int patch_field_offset = -1; | 777 int patch_field_offset = -1; |
778 KlassHandle init_klass(THREAD, klassOop(NULL)); // klass needed by access_field_patching code | 778 KlassHandle init_klass(THREAD, klassOop(NULL)); // klass needed by access_field_patching code |
779 Handle load_klass(THREAD, NULL); // oop needed by load_klass_patching code | 779 Handle load_klass(THREAD, NULL); // oop needed by load_klass_patching code |
780 if (stub_id == Runtime1::access_field_patching_id) { | 780 if (stub_id == Runtime1::access_field_patching_id) { |
781 | 781 |
782 Bytecode_field* field_access = Bytecode_field_at(caller_method, bci); | 782 Bytecode_field field_access(caller_method, bci); |
783 FieldAccessInfo result; // initialize class if needed | 783 FieldAccessInfo result; // initialize class if needed |
784 Bytecodes::Code code = field_access->code(); | 784 Bytecodes::Code code = field_access.code(); |
785 constantPoolHandle constants(THREAD, caller_method->constants()); | 785 constantPoolHandle constants(THREAD, caller_method->constants()); |
786 LinkResolver::resolve_field(result, constants, field_access->index(), Bytecodes::java_code(code), false, CHECK); | 786 LinkResolver::resolve_field(result, constants, field_access.index(), Bytecodes::java_code(code), false, CHECK); |
787 patch_field_offset = result.field_offset(); | 787 patch_field_offset = result.field_offset(); |
788 | 788 |
789 // If we're patching a field which is volatile then at compile it | 789 // If we're patching a field which is volatile then at compile it |
790 // must not have been know to be volatile, so the generated code | 790 // must not have been know to be volatile, so the generated code |
791 // isn't correct for a volatile reference. The nmethod has to be | 791 // isn't correct for a volatile reference. The nmethod has to be |
809 init_klass = KlassHandle(THREAD, klass); | 809 init_klass = KlassHandle(THREAD, klass); |
810 k = klass; | 810 k = klass; |
811 } | 811 } |
812 break; | 812 break; |
813 case Bytecodes::_new: | 813 case Bytecodes::_new: |
814 { Bytecode_new* bnew = Bytecode_new_at(caller_method->bcp_from(bci)); | 814 { Bytecode_new bnew(caller_method(), caller_method->bcp_from(bci)); |
815 k = caller_method->constants()->klass_at(bnew->index(), CHECK); | 815 k = caller_method->constants()->klass_at(bnew.index(), CHECK); |
816 } | 816 } |
817 break; | 817 break; |
818 case Bytecodes::_multianewarray: | 818 case Bytecodes::_multianewarray: |
819 { Bytecode_multianewarray* mna = Bytecode_multianewarray_at(caller_method->bcp_from(bci)); | 819 { Bytecode_multianewarray mna(caller_method(), caller_method->bcp_from(bci)); |
820 k = caller_method->constants()->klass_at(mna->index(), CHECK); | 820 k = caller_method->constants()->klass_at(mna.index(), CHECK); |
821 } | 821 } |
822 break; | 822 break; |
823 case Bytecodes::_instanceof: | 823 case Bytecodes::_instanceof: |
824 { Bytecode_instanceof* io = Bytecode_instanceof_at(caller_method->bcp_from(bci)); | 824 { Bytecode_instanceof io(caller_method(), caller_method->bcp_from(bci)); |
825 k = caller_method->constants()->klass_at(io->index(), CHECK); | 825 k = caller_method->constants()->klass_at(io.index(), CHECK); |
826 } | 826 } |
827 break; | 827 break; |
828 case Bytecodes::_checkcast: | 828 case Bytecodes::_checkcast: |
829 { Bytecode_checkcast* cc = Bytecode_checkcast_at(caller_method->bcp_from(bci)); | 829 { Bytecode_checkcast cc(caller_method(), caller_method->bcp_from(bci)); |
830 k = caller_method->constants()->klass_at(cc->index(), CHECK); | 830 k = caller_method->constants()->klass_at(cc.index(), CHECK); |
831 } | 831 } |
832 break; | 832 break; |
833 case Bytecodes::_anewarray: | 833 case Bytecodes::_anewarray: |
834 { Bytecode_anewarray* anew = Bytecode_anewarray_at(caller_method->bcp_from(bci)); | 834 { Bytecode_anewarray anew(caller_method(), caller_method->bcp_from(bci)); |
835 klassOop ek = caller_method->constants()->klass_at(anew->index(), CHECK); | 835 klassOop ek = caller_method->constants()->klass_at(anew.index(), CHECK); |
836 k = Klass::cast(ek)->array_klass(CHECK); | 836 k = Klass::cast(ek)->array_klass(CHECK); |
837 } | 837 } |
838 break; | 838 break; |
839 case Bytecodes::_ldc: | 839 case Bytecodes::_ldc: |
840 case Bytecodes::_ldc_w: | 840 case Bytecodes::_ldc_w: |
841 { | 841 { |
842 Bytecode_loadconstant* cc = Bytecode_loadconstant_at(caller_method, bci); | 842 Bytecode_loadconstant cc(caller_method, bci); |
843 k = cc->resolve_constant(CHECK); | 843 k = cc.resolve_constant(CHECK); |
844 assert(k != NULL && !k->is_klass(), "must be class mirror or other Java constant"); | 844 assert(k != NULL && !k->is_klass(), "must be class mirror or other Java constant"); |
845 } | 845 } |
846 break; | 846 break; |
847 default: Unimplemented(); | 847 default: Unimplemented(); |
848 } | 848 } |