950 Method* vt_m = ik->method_at_vtable(vtable_index()); 951 return vt_m != this; 952 } 953 } 954 955 956 // give advice about whether this Method* should be cached or not 957 bool Method::should_not_be_cached() const { 958 if (is_old()) { 959 // This method has been redefined. It is either EMCP or obsolete 960 // and we don't want to cache it because that would pin the method 961 // down and prevent it from being collectible if and when it 962 // finishes executing. 963 return true; 964 } 965 966 // caching this method should be just fine 967 return false; 968 } 969 970 // Constant pool structure for invoke methods: 971 enum { 972 _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. 973 _imcp_invoke_signature, // utf8: (variable Symbol*) 974 _imcp_limit 975 }; 976 977 // Test if this method is an MH adapter frame generated by Java code. 978 // Cf. java/lang/invoke/InvokerBytecodeGenerator 979 bool Method::is_compiled_lambda_form() const { 980 return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; 981 } 982 983 // Test if this method is an internal MH primitive method. 984 bool Method::is_method_handle_intrinsic() const { 985 vmIntrinsics::ID iid = intrinsic_id(); 986 return (MethodHandles::is_signature_polymorphic(iid) && 987 MethodHandles::is_signature_polymorphic_intrinsic(iid)); 988 } 989 1161 localvariable_len * sizeof(LocalVariableTableElement)); 1162 } 1163 // Copy stackmap table 1164 if (m->has_stackmap_table()) { 1165 int code_attribute_length = m->stackmap_data()->length(); 1166 Array<u1>* stackmap_data = 1167 MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); 1168 memcpy((void*)stackmap_data->adr_at(0), 1169 (void*)m->stackmap_data()->adr_at(0), code_attribute_length); 1170 newm->set_stackmap_data(stackmap_data); 1171 } 1172 1173 return newm; 1174 } 1175 1176 vmSymbols::SID Method::klass_id_for_intrinsics(Klass* holder) { 1177 // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics 1178 // because we are not loading from core libraries 1179 // exception: the AES intrinsics come from lib/ext/sunjce_provider.jar 1180 // which does not use the class default class loader so we check for its loader here 1181 if ((InstanceKlass::cast(holder)->class_loader() != NULL) && 1182 InstanceKlass::cast(holder)->class_loader()->klass()->name() != vmSymbols::sun_misc_Launcher_ExtClassLoader()) { 1183 return vmSymbols::NO_SID; // regardless of name, no intrinsics here 1184 } 1185 1186 // see if the klass name is well-known: 1187 Symbol* klass_name = InstanceKlass::cast(holder)->name(); 1188 return vmSymbols::find_sid(klass_name); 1189 } 1190 1191 void Method::init_intrinsic_id() { 1192 assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); 1193 const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte)); 1194 assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size"); 1195 assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), ""); 1196 1197 // the klass name is well-known: 1198 vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); 1199 assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); 1200 1201 // ditto for method and signature: 1202 vmSymbols::SID name_id = vmSymbols::find_sid(name()); 1203 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) 1204 && name_id == vmSymbols::NO_SID) 1205 return; 1206 vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); 1207 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) | 950 Method* vt_m = ik->method_at_vtable(vtable_index()); 951 return vt_m != this; 952 } 953 } 954 955 956 // give advice about whether this Method* should be cached or not 957 bool Method::should_not_be_cached() const { 958 if (is_old()) { 959 // This method has been redefined. It is either EMCP or obsolete 960 // and we don't want to cache it because that would pin the method 961 // down and prevent it from being collectible if and when it 962 // finishes executing. 963 return true; 964 } 965 966 // caching this method should be just fine 967 return false; 968 } 969 970 971 /** 972 * Returns true if this is one of the specially treated methods for 973 * security related stack walks (like Reflection.getCallerClass). 974 */ 975 bool Method::is_ignored_by_security_stack_walk() const { 976 const bool use_new_reflection = JDK_Version::is_gte_jdk14x_version() && UseNewReflection; 977 978 assert(intrinsic_id() != vmIntrinsics::_invoke || Universe::reflect_invoke_cache()->is_same_method((Method*)this), "sanity"); 979 if (intrinsic_id() == vmIntrinsics::_invoke) { 980 // This is Method.invoke() -- ignore it 981 return true; 982 } 983 if (use_new_reflection && 984 method_holder()->is_subclass_of(SystemDictionary::reflect_MethodAccessorImpl_klass())) { 985 // This is an auxilary frame -- ignore it 986 return true; 987 } 988 if (is_method_handle_intrinsic() || is_compiled_lambda_form()) { 989 // This is an internal adapter frame for method handles -- ignore it 990 return true; 991 } 992 return false; 993 } 994 995 996 // Constant pool structure for invoke methods: 997 enum { 998 _imcp_invoke_name = 1, // utf8: 'invokeExact', etc. 999 _imcp_invoke_signature, // utf8: (variable Symbol*) 1000 _imcp_limit 1001 }; 1002 1003 // Test if this method is an MH adapter frame generated by Java code. 1004 // Cf. java/lang/invoke/InvokerBytecodeGenerator 1005 bool Method::is_compiled_lambda_form() const { 1006 return intrinsic_id() == vmIntrinsics::_compiledLambdaForm; 1007 } 1008 1009 // Test if this method is an internal MH primitive method. 1010 bool Method::is_method_handle_intrinsic() const { 1011 vmIntrinsics::ID iid = intrinsic_id(); 1012 return (MethodHandles::is_signature_polymorphic(iid) && 1013 MethodHandles::is_signature_polymorphic_intrinsic(iid)); 1014 } 1015 1187 localvariable_len * sizeof(LocalVariableTableElement)); 1188 } 1189 // Copy stackmap table 1190 if (m->has_stackmap_table()) { 1191 int code_attribute_length = m->stackmap_data()->length(); 1192 Array<u1>* stackmap_data = 1193 MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); 1194 memcpy((void*)stackmap_data->adr_at(0), 1195 (void*)m->stackmap_data()->adr_at(0), code_attribute_length); 1196 newm->set_stackmap_data(stackmap_data); 1197 } 1198 1199 return newm; 1200 } 1201 1202 vmSymbols::SID Method::klass_id_for_intrinsics(Klass* holder) { 1203 // if loader is not the default loader (i.e., != NULL), we can't know the intrinsics 1204 // because we are not loading from core libraries 1205 // exception: the AES intrinsics come from lib/ext/sunjce_provider.jar 1206 // which does not use the class default class loader so we check for its loader here 1207 InstanceKlass* ik = InstanceKlass::cast(holder); 1208 if ((ik->class_loader() != NULL) && !SystemDictionary::is_ext_class_loader(ik->class_loader())) { 1209 return vmSymbols::NO_SID; // regardless of name, no intrinsics here 1210 } 1211 1212 // see if the klass name is well-known: 1213 Symbol* klass_name = ik->name(); 1214 return vmSymbols::find_sid(klass_name); 1215 } 1216 1217 void Method::init_intrinsic_id() { 1218 assert(_intrinsic_id == vmIntrinsics::_none, "do this just once"); 1219 const uintptr_t max_id_uint = right_n_bits((int)(sizeof(_intrinsic_id) * BitsPerByte)); 1220 assert((uintptr_t)vmIntrinsics::ID_LIMIT <= max_id_uint, "else fix size"); 1221 assert(intrinsic_id_size_in_bytes() == sizeof(_intrinsic_id), ""); 1222 1223 // the klass name is well-known: 1224 vmSymbols::SID klass_id = klass_id_for_intrinsics(method_holder()); 1225 assert(klass_id != vmSymbols::NO_SID, "caller responsibility"); 1226 1227 // ditto for method and signature: 1228 vmSymbols::SID name_id = vmSymbols::find_sid(name()); 1229 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) 1230 && name_id == vmSymbols::NO_SID) 1231 return; 1232 vmSymbols::SID sig_id = vmSymbols::find_sid(signature()); 1233 if (klass_id != vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_MethodHandle) |