< prev index next >

src/hotspot/share/oops/resolvedMethodEntry.cpp

Print this page

  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  *
 23  */
 24 
 25 #include "precompiled.hpp"

 26 #include "oops/method.hpp"
 27 #include "oops/resolvedMethodEntry.hpp"
 28 
 29 bool ResolvedMethodEntry::check_no_old_or_obsolete_entry() {
 30   // return false if m refers to a non-deleted old or obsolete method
 31   if (_method != nullptr) {
 32     assert(_method->is_valid() && _method->is_method(), "m is a valid method");
 33     return !_method->is_old() && !_method->is_obsolete(); // old is always set for old and obsolete
 34   } else {
 35     return true;
 36   }
 37 }
 38 
 39 void ResolvedMethodEntry::reset_entry() {
 40   if (has_resolved_references_index()) {
 41     u2 saved_resolved_references_index = _entry_specific._resolved_references_index;
 42     u2 saved_cpool_index = _cpool_index;
 43     memset(this, 0, sizeof(*this));
 44     set_resolved_references_index(saved_resolved_references_index);
 45     _cpool_index = saved_cpool_index;
 46   } else {
 47     u2 saved_cpool_index = _cpool_index;
 48     memset(this, 0, sizeof(*this));
 49     _cpool_index = saved_cpool_index;
 50   }
 51 }
 52 
 53 void ResolvedMethodEntry::remove_unshareable_info() {
 54   reset_entry();
 55 }
 56 





















































































 57 void ResolvedMethodEntry::print_on(outputStream* st) const {
 58   st->print_cr("Method Entry:");
 59 
 60   if (method() != nullptr) {
 61     st->print_cr(" - Method: " INTPTR_FORMAT " %s", p2i(method()), method()->external_name());
 62   } else {
 63     st->print_cr("- Method: null");
 64   }
 65   // Some fields are mutually exclusive and are only used by certain invoke codes
 66   if (bytecode1() == Bytecodes::_invokeinterface && interface_klass() != nullptr) {
 67     st->print_cr(" - Klass: " INTPTR_FORMAT " %s", p2i(interface_klass()), interface_klass()->external_name());
 68   } else {
 69     st->print_cr("- Klass: null");
 70   }
 71   if (bytecode1() == Bytecodes::_invokehandle) {
 72     st->print_cr(" - Resolved References Index: %d", resolved_references_index());
 73   } else {
 74     st->print_cr(" - Resolved References Index: none");
 75   }
 76   if (bytecode2() == Bytecodes::_invokevirtual) {

  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  *
 23  */
 24 
 25 #include "precompiled.hpp"
 26 #include "cds/archiveBuilder.hpp"
 27 #include "oops/method.hpp"
 28 #include "oops/resolvedMethodEntry.hpp"
 29 
 30 bool ResolvedMethodEntry::check_no_old_or_obsolete_entry() {
 31   // return false if m refers to a non-deleted old or obsolete method
 32   if (_method != nullptr) {
 33     assert(_method->is_valid() && _method->is_method(), "m is a valid method");
 34     return !_method->is_old() && !_method->is_obsolete(); // old is always set for old and obsolete
 35   } else {
 36     return true;
 37   }
 38 }
 39 
 40 void ResolvedMethodEntry::reset_entry() {
 41   if (has_resolved_references_index()) {
 42     u2 saved_resolved_references_index = _entry_specific._resolved_references_index;
 43     u2 saved_cpool_index = _cpool_index;
 44     memset(this, 0, sizeof(*this));
 45     set_resolved_references_index(saved_resolved_references_index);
 46     _cpool_index = saved_cpool_index;
 47   } else {
 48     u2 saved_cpool_index = _cpool_index;
 49     memset(this, 0, sizeof(*this));
 50     _cpool_index = saved_cpool_index;
 51   }
 52 }
 53 
 54 void ResolvedMethodEntry::remove_unshareable_info() {
 55   reset_entry();
 56 }
 57 
 58 #if INCLUDE_CDS
 59 void ResolvedMethodEntry::mark_and_relocate(ConstantPool* src_cp) {
 60   ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_method);
 61   if (bytecode1() == Bytecodes::_invokeinterface) {
 62     ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_entry_specific._interface_klass);
 63   }
 64 #if 0
 65   // OLD CODE ... some of it may need to be salvaged.
 66   Bytecodes::Code invoke_code = bytecode_1();
 67   if (invoke_code != (Bytecodes::Code)0) {
 68     Metadata* f1 = f1_ord();
 69     if (f1 != nullptr) {
 70       ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_f1);
 71       switch (invoke_code) {
 72       case Bytecodes::_invokeinterface:
 73         assert(0, "not implemented");
 74         //assert(f1->is_klass(), "");
 75         //ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_f2); // f2 is interface method
 76         return false;
 77       case Bytecodes::_invokestatic:
 78         // For safety, we support invokestatic only for invoking methods in MethodHandle.
 79         // FIXME -- further restrict it to linkToStatic(), etc?
 80         assert(bytecode_2() == (Bytecodes::Code)0, "must be");
 81         assert(f1->is_method(), "");
 82         assert(f1_as_method()->method_holder()->name()->equals("java/lang/invoke/MethodHandle") ||
 83                f1_as_method()->method_holder()->name()->equals("java/lang/invoke/MethodHandleNatives"), "sanity");
 84         return true;
 85       case Bytecodes::_invokespecial:
 86         assert(f1->is_method(), "must be");
 87         // Also need to work on bytecode_2() below.
 88         break;
 89       case Bytecodes::_invokehandle:
 90         assert(bytecode_2() == (Bytecodes::Code)0, "must be");
 91         assert(f1->is_method(), "");
 92         return true;
 93       default:
 94         ShouldNotReachHere();
 95         break;
 96       }
 97     }
 98   }
 99 
100   // TODO test case: can invokespecial and invokevirtual share the same CP?
101   invoke_code = bytecode_2();
102   if (invoke_code != (Bytecodes::Code)0) {
103     assert(invoke_code == Bytecodes::_invokevirtual, "must be");
104     if (is_vfinal()) {
105       // f2 is vfinal method
106       ArchiveBuilder::current()->mark_and_relocate_to_buffered_addr(&_f2); // f2 is final method
107     } else {
108       // f2 is vtable index, no need to mark
109       if (DynamicDumpSharedSpaces) {
110         // InstanceKlass::methods() is has been resorted, so we need to
111         // update the vtable_index.
112         int holder_index = src_cp->uncached_klass_ref_index_at(constant_pool_index());
113         Klass* src_klass = src_cp->resolved_klass_at(holder_index);
114         Method* src_m = src_klass->method_at_vtable(f2_as_index());
115         if (!ArchiveBuilder::current()->is_in_mapped_static_archive(src_m->method_holder()) &&
116             !ArchiveBuilder::current()->is_in_mapped_static_archive(src_m)) {
117           Klass* buffered_klass = ArchiveBuilder::current()->get_buffered_addr(src_klass);
118           Method* buffered_m = ArchiveBuilder::current()->get_buffered_addr(src_m);
119           int vtable_index;
120           if (src_m->method_holder()->is_interface()) { // default or miranda method
121             assert(src_m->vtable_index() < 0, "must be");
122             assert(buffered_klass->is_instance_klass(), "must be");
123             vtable_index = InstanceKlass::cast(buffered_klass)->vtable_index_of_interface_method(buffered_m);
124             assert(vtable_index >= 0, "must be");
125           } else {
126             vtable_index = buffered_m->vtable_index();
127             assert(vtable_index >= 0, "must be");
128           }
129           if (_f2 != vtable_index) {
130             log_trace(cds, resolve)("vtable_index changed %d => %d", (int)_f2, vtable_index);
131             _f2 = vtable_index;
132           }
133         }
134       }
135     }
136   }
137 
138 #endif
139 }
140 #endif
141 
142 
143 void ResolvedMethodEntry::print_on(outputStream* st) const {
144   st->print_cr("Method Entry:");
145 
146   if (method() != nullptr) {
147     st->print_cr(" - Method: " INTPTR_FORMAT " %s", p2i(method()), method()->external_name());
148   } else {
149     st->print_cr("- Method: null");
150   }
151   // Some fields are mutually exclusive and are only used by certain invoke codes
152   if (bytecode1() == Bytecodes::_invokeinterface && interface_klass() != nullptr) {
153     st->print_cr(" - Klass: " INTPTR_FORMAT " %s", p2i(interface_klass()), interface_klass()->external_name());
154   } else {
155     st->print_cr("- Klass: null");
156   }
157   if (bytecode1() == Bytecodes::_invokehandle) {
158     st->print_cr(" - Resolved References Index: %d", resolved_references_index());
159   } else {
160     st->print_cr(" - Resolved References Index: none");
161   }
162   if (bytecode2() == Bytecodes::_invokevirtual) {
< prev index next >