951 set_method_data(NULL); |
951 set_method_data(NULL); |
952 clear_method_counters(); |
952 clear_method_counters(); |
953 } |
953 } |
954 #endif |
954 #endif |
955 |
955 |
|
956 /**************************************************************************** |
|
957 // The following illustrates how the entries work for CDS shared Methods: |
|
958 // |
|
959 // Our goal is to delay writing into a shared Method until it's compiled. |
|
960 // Hence, we want to determine the initial values for _i2i_entry, |
|
961 // _from_interpreted_entry and _from_compiled_entry during CDS dump time. |
|
962 // |
|
963 // In this example, both Methods A and B have the _i2i_entry of "zero_locals". |
|
964 // They also have similar signatures so that they will share the same |
|
965 // AdapterHandlerEntry. |
|
966 // |
|
967 // _adapter_trampoline points to a fixed location in the RW section of |
|
968 // the CDS archive. This location initially contains a NULL pointer. When the |
|
969 // first of method A or B is linked, an AdapterHandlerEntry is allocated |
|
970 // dynamically, and its c2i/i2c entries are generated. |
|
971 // |
|
972 // _i2i_entry and _from_interpreted_entry initially points to the same |
|
973 // (fixed) location in the CODE section of the CDS archive. This contains |
|
974 // an unconditional branch to the actual entry for "zero_locals", which is |
|
975 // generated at run time and may be on an arbitrary address. Thus, the |
|
976 // unconditional branch is also generated at run time to jump to the correct |
|
977 // address. |
|
978 // |
|
979 // Similarly, _from_compiled_entry points to a fixed address in the CODE |
|
980 // section. This address has enough space for an unconditional branch |
|
981 // instruction, and is initially zero-filled. After the AdapterHandlerEntry is |
|
982 // initialized, and the address for the actual c2i_entry is known, we emit a |
|
983 // branch instruction here to branch to the actual c2i_entry. |
|
984 // |
|
985 // The effect of the extra branch on the i2i and c2i entries is negligible. |
|
986 // |
|
987 // The reason for putting _adapter_trampoline in RO is many shared Methods |
|
988 // share the same AdapterHandlerEntry, so we can save space in the RW section |
|
989 // by having the extra indirection. |
|
990 |
|
991 |
|
992 [Method A: RW] |
|
993 _constMethod ----> [ConstMethod: RO] |
|
994 _adapter_trampoline -----------+ |
|
995 | |
|
996 _i2i_entry (same value as method B) | |
|
997 _from_interpreted_entry (same value as method B) | |
|
998 _from_compiled_entry (same value as method B) | |
|
999 | |
|
1000 | |
|
1001 [Method B: RW] +--------+ |
|
1002 _constMethod ----> [ConstMethod: RO] | |
|
1003 _adapter_trampoline --+--->(AdapterHandlerEntry* ptr: RW)-+ |
|
1004 | |
|
1005 +-------------------------------+ |
|
1006 | |
|
1007 +----> [AdapterHandlerEntry] (allocated at run time) |
|
1008 _fingerprint |
|
1009 _c2i_entry ---------------------------------+->[c2i entry..] |
|
1010 _i2i_entry -------------+ _i2c_entry ---------------+-> [i2c entry..] | |
|
1011 _from_interpreted_entry | _c2i_unverified_entry | | |
|
1012 | | | | |
|
1013 | | (_cds_entry_table: CODE) | | |
|
1014 | +->[0]: jmp _entry_table[0] --> (i2i_entry_for "zero_locals") | | |
|
1015 | | (allocated at run time) | | |
|
1016 | | ... [asm code ...] | | |
|
1017 +-[not compiled]-+ [n]: jmp _entry_table[n] | | |
|
1018 | | | |
|
1019 | | | |
|
1020 +-[compiled]-------------------------------------------------------------------+ | |
|
1021 | |
|
1022 _from_compiled_entry------------> (_c2i_entry_trampoline: CODE) | |
|
1023 [jmp c2i_entry] ------------------------------------------------------+ |
|
1024 |
|
1025 ***/ |
|
1026 |
956 // Called when the method_holder is getting linked. Setup entrypoints so the method |
1027 // Called when the method_holder is getting linked. Setup entrypoints so the method |
957 // is ready to be called from interpreter, compiler, and vtables. |
1028 // is ready to be called from interpreter, compiler, and vtables. |
958 void Method::link_method(const methodHandle& h_method, TRAPS) { |
1029 void Method::link_method(const methodHandle& h_method, TRAPS) { |
959 // If the code cache is full, we may reenter this function for the |
1030 // If the code cache is full, we may reenter this function for the |
960 // leftover methods that weren't linked. |
1031 // leftover methods that weren't linked. |
961 if (is_shared()) { |
1032 if (is_shared()) { |
962 if (adapter() != NULL) return; |
1033 address entry = Interpreter::entry_for_cds_method(h_method); |
963 } else { |
1034 assert(entry != NULL && entry == _i2i_entry, |
964 if (_i2i_entry != NULL) return; |
1035 "should be correctly set during dump time"); |
965 |
1036 if (adapter() != NULL) { |
966 assert(adapter() == NULL, "init'd to NULL" ); |
1037 return; |
|
1038 } |
|
1039 assert(entry == _from_interpreted_entry, |
|
1040 "should be correctly set during dump time"); |
|
1041 } else if (_i2i_entry != NULL) { |
|
1042 return; |
967 } |
1043 } |
968 assert( _code == NULL, "nothing compiled yet" ); |
1044 assert( _code == NULL, "nothing compiled yet" ); |
969 |
1045 |
970 // Setup interpreter entrypoint |
1046 // Setup interpreter entrypoint |
971 assert(this == h_method(), "wrong h_method()" ); |
1047 assert(this == h_method(), "wrong h_method()" ); |
972 address entry; |
1048 |
973 |
1049 if (!is_shared()) { |
974 if (this->is_shared()) { |
1050 assert(adapter() == NULL, "init'd to NULL"); |
975 entry = Interpreter::entry_for_cds_method(h_method); |
1051 address entry = Interpreter::entry_for_method(h_method); |
976 } else { |
1052 assert(entry != NULL, "interpreter entry must be non-null"); |
977 entry = Interpreter::entry_for_method(h_method); |
|
978 } |
|
979 assert(entry != NULL, "interpreter entry must be non-null"); |
|
980 if (is_shared()) { |
|
981 assert(entry == _i2i_entry && entry == _from_interpreted_entry, |
|
982 "should be correctly set during dump time"); |
|
983 } else { |
|
984 // Sets both _i2i_entry and _from_interpreted_entry |
1053 // Sets both _i2i_entry and _from_interpreted_entry |
985 set_interpreter_entry(entry); |
1054 set_interpreter_entry(entry); |
986 } |
1055 } |
987 |
1056 |
988 // Don't overwrite already registered native entries. |
1057 // Don't overwrite already registered native entries. |
1022 } |
1091 } |
1023 } |
1092 } |
1024 |
1093 |
1025 if (mh->is_shared()) { |
1094 if (mh->is_shared()) { |
1026 assert(mh->adapter() == adapter, "must be"); |
1095 assert(mh->adapter() == adapter, "must be"); |
1027 assert(mh->_from_compiled_entry != NULL, "must be"); // FIXME, the instructions also not NULL |
1096 assert(mh->_from_compiled_entry != NULL, "must be"); |
1028 } else { |
1097 } else { |
1029 mh->set_adapter_entry(adapter); |
1098 mh->set_adapter_entry(adapter); |
1030 mh->_from_compiled_entry = adapter->get_c2i_entry(); |
1099 mh->_from_compiled_entry = adapter->get_c2i_entry(); |
1031 } |
1100 } |
1032 return adapter->get_c2i_entry(); |
1101 return adapter->get_c2i_entry(); |
1033 } |
1102 } |
1034 |
1103 |
1035 void Method::restore_unshareable_info(TRAPS) { |
1104 void Method::restore_unshareable_info(TRAPS) { |
1036 // Since restore_unshareable_info can be called more than once for a method, don't |
1105 // Since restore_unshareable_info can be called more than once for a method, don't |
1037 // redo any work. If this field is restored, there is nothing to do. |
1106 // redo any work. |
1038 if (_from_compiled_entry == NULL) { |
1107 if (adapter() == NULL) { |
1039 // restore method's vtable by calling a virtual function |
1108 // Restore Method's C++ vtable by calling a virtual function |
1040 restore_vtable(); |
1109 restore_vtable(); |
1041 |
1110 |
1042 methodHandle mh(THREAD, this); |
1111 methodHandle mh(THREAD, this); |
1043 link_method(mh, CHECK); |
1112 link_method(mh, CHECK); |
1044 } |
1113 } |