1133 // Perform the field lookup. 1134 Klass* canonical_holder = 1135 InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc); 1136 if (canonical_holder == NULL) { 1137 return; 1138 } 1139 1140 assert(canonical_holder == field_desc.field_holder(), "just checking"); 1141 } 1142 1143 // ------------------------------------------------------------------ 1144 // Get a field by index from a klass's constant pool. 1145 void JVMCIRuntime::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) { 1146 ResourceMark rm; 1147 return get_field_by_index_impl(accessor, fd, index); 1148 } 1149 1150 // ------------------------------------------------------------------ 1151 // Perform an appropriate method lookup based on accessor, holder, 1152 // name, signature, and bytecode. 1153 methodHandle JVMCIRuntime::lookup_method(InstanceKlass* accessor, 1154 Klass* holder, 1155 Symbol* name, 1156 Symbol* sig, 1157 Bytecodes::Code bc, 1158 constantTag tag) { 1159 // Accessibility checks are performed in JVMCIEnv::get_method_by_index_impl(). 1160 assert(check_klass_accessibility(accessor, holder), "holder not accessible"); 1161 1162 methodHandle dest_method; 1163 LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag); 1164 switch (bc) { 1165 case Bytecodes::_invokestatic: 1166 dest_method = 1167 LinkResolver::resolve_static_call_or_null(link_info); 1168 break; 1169 case Bytecodes::_invokespecial: 1170 dest_method = 1171 LinkResolver::resolve_special_call_or_null(link_info); 1172 break; 1173 case Bytecodes::_invokeinterface: 1174 dest_method = 1175 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 1176 break; 1177 case Bytecodes::_invokevirtual: 1178 dest_method = 1179 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 1180 break; 1181 default: ShouldNotReachHere(); 1182 } 1183 1184 return dest_method; 1185 } 1186 1187 1188 // ------------------------------------------------------------------ 1189 methodHandle JVMCIRuntime::get_method_by_index_impl(const constantPoolHandle& cpool, 1190 int index, Bytecodes::Code bc, 1191 InstanceKlass* accessor) { 1192 if (bc == Bytecodes::_invokedynamic) { 1193 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 1194 bool is_resolved = !cpce->is_f1_null(); 1195 if (is_resolved) { 1196 // Get the invoker Method* from the constant pool. 1197 // (The appendix argument, if any, will be noted in the method's signature.) 1198 Method* adapter = cpce->f1_as_method(); 1199 return methodHandle(adapter); 1200 } 1201 1202 return NULL; 1203 } 1204 1205 int holder_index = cpool->klass_ref_index_at(index); 1206 bool holder_is_accessible; 1207 Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 1208 1209 // Get the method's name and signature. 1210 Symbol* name_sym = cpool->name_ref_at(index); 1211 Symbol* sig_sym = cpool->signature_ref_at(index); 1212 1213 if (cpool->has_preresolution() 1214 || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) && 1215 MethodHandles::is_signature_polymorphic_name(holder, name_sym))) { 1216 // Short-circuit lookups for JSR 292-related call sites. 1217 // That is, do not rely only on name-based lookups, because they may fail 1218 // if the names are not resolvable in the boot class loader (7056328). 1219 switch (bc) { 1220 case Bytecodes::_invokevirtual: 1221 case Bytecodes::_invokeinterface: 1222 case Bytecodes::_invokespecial: 1223 case Bytecodes::_invokestatic: 1224 { 1225 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 1226 if (m != NULL) { 1227 return m; 1228 } 1229 } 1230 break; 1231 default: 1232 break; 1233 } 1234 } 1235 1236 if (holder_is_accessible) { // Our declared holder is loaded. 1237 constantTag tag = cpool->tag_ref_at(index); 1238 methodHandle m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag); 1239 if (!m.is_null()) { 1240 // We found the method. 1241 return m; 1242 } 1243 } 1244 1245 // Either the declared holder was not loaded, or the method could 1246 // not be found. 1247 1248 return NULL; 1249 } 1250 1251 // ------------------------------------------------------------------ 1252 InstanceKlass* JVMCIRuntime::get_instance_klass_for_declared_method_holder(Klass* method_holder) { 1253 // For the case of <array>.clone(), the method holder can be an ArrayKlass* 1254 // instead of an InstanceKlass*. For that case simply pretend that the 1255 // declared holder is Object.clone since that's where the call will bottom out. 1256 if (method_holder->is_instance_klass()) { 1257 return InstanceKlass::cast(method_holder); 1258 } else if (method_holder->is_array_klass()) { 1259 return SystemDictionary::Object_klass(); 1260 } else { 1261 ShouldNotReachHere(); 1262 } 1263 return NULL; 1264 } 1265 1266 1267 // ------------------------------------------------------------------ 1268 methodHandle JVMCIRuntime::get_method_by_index(const constantPoolHandle& cpool, 1269 int index, Bytecodes::Code bc, 1270 InstanceKlass* accessor) { 1271 ResourceMark rm; 1272 return get_method_by_index_impl(cpool, index, bc, accessor); 1273 } 1274 1275 // ------------------------------------------------------------------ 1276 // Check for changes to the system dictionary during compilation 1277 // class loads, evolution, breakpoints 1278 JVMCI::CodeInstallResult JVMCIRuntime::validate_compile_task_dependencies(Dependencies* dependencies, JVMCICompileState* compile_state, char** failure_detail) { 1279 // If JVMTI capabilities were enabled during compile, the compilation is invalidated. 1280 if (compile_state != NULL && compile_state->jvmti_state_changed()) { 1281 *failure_detail = (char*) "Jvmti state change during compilation invalidated dependencies"; 1282 return JVMCI::dependencies_failed; 1283 } 1284 1285 CompileTask* task = compile_state == NULL ? NULL : compile_state->task(); 1286 Dependencies::DepType result = dependencies->validate_dependencies(task, failure_detail); 1287 if (result == Dependencies::end_marker) { 1288 return JVMCI::ok; | 1133 // Perform the field lookup. 1134 Klass* canonical_holder = 1135 InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc); 1136 if (canonical_holder == NULL) { 1137 return; 1138 } 1139 1140 assert(canonical_holder == field_desc.field_holder(), "just checking"); 1141 } 1142 1143 // ------------------------------------------------------------------ 1144 // Get a field by index from a klass's constant pool. 1145 void JVMCIRuntime::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) { 1146 ResourceMark rm; 1147 return get_field_by_index_impl(accessor, fd, index); 1148 } 1149 1150 // ------------------------------------------------------------------ 1151 // Perform an appropriate method lookup based on accessor, holder, 1152 // name, signature, and bytecode. 1153 Method* JVMCIRuntime::lookup_method(InstanceKlass* accessor, 1154 Klass* holder, 1155 Symbol* name, 1156 Symbol* sig, 1157 Bytecodes::Code bc, 1158 constantTag tag) { 1159 // Accessibility checks are performed in JVMCIEnv::get_method_by_index_impl(). 1160 assert(check_klass_accessibility(accessor, holder), "holder not accessible"); 1161 1162 Method* dest_method; 1163 LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag); 1164 switch (bc) { 1165 case Bytecodes::_invokestatic: 1166 dest_method = 1167 LinkResolver::resolve_static_call_or_null(link_info); 1168 break; 1169 case Bytecodes::_invokespecial: 1170 dest_method = 1171 LinkResolver::resolve_special_call_or_null(link_info); 1172 break; 1173 case Bytecodes::_invokeinterface: 1174 dest_method = 1175 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 1176 break; 1177 case Bytecodes::_invokevirtual: 1178 dest_method = 1179 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 1180 break; 1181 default: ShouldNotReachHere(); 1182 } 1183 1184 return dest_method; 1185 } 1186 1187 1188 // ------------------------------------------------------------------ 1189 Method* JVMCIRuntime::get_method_by_index_impl(const constantPoolHandle& cpool, 1190 int index, Bytecodes::Code bc, 1191 InstanceKlass* accessor) { 1192 if (bc == Bytecodes::_invokedynamic) { 1193 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 1194 bool is_resolved = !cpce->is_f1_null(); 1195 if (is_resolved) { 1196 // Get the invoker Method* from the constant pool. 1197 // (The appendix argument, if any, will be noted in the method's signature.) 1198 Method* adapter = cpce->f1_as_method(); 1199 return adapter; 1200 } 1201 1202 return NULL; 1203 } 1204 1205 int holder_index = cpool->klass_ref_index_at(index); 1206 bool holder_is_accessible; 1207 Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 1208 1209 // Get the method's name and signature. 1210 Symbol* name_sym = cpool->name_ref_at(index); 1211 Symbol* sig_sym = cpool->signature_ref_at(index); 1212 1213 if (cpool->has_preresolution() 1214 || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) && 1215 MethodHandles::is_signature_polymorphic_name(holder, name_sym))) { 1216 // Short-circuit lookups for JSR 292-related call sites. 1217 // That is, do not rely only on name-based lookups, because they may fail 1218 // if the names are not resolvable in the boot class loader (7056328). 1219 switch (bc) { 1220 case Bytecodes::_invokevirtual: 1221 case Bytecodes::_invokeinterface: 1222 case Bytecodes::_invokespecial: 1223 case Bytecodes::_invokestatic: 1224 { 1225 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 1226 if (m != NULL) { 1227 return m; 1228 } 1229 } 1230 break; 1231 default: 1232 break; 1233 } 1234 } 1235 1236 if (holder_is_accessible) { // Our declared holder is loaded. 1237 constantTag tag = cpool->tag_ref_at(index); 1238 Method* m = lookup_method(accessor, holder, name_sym, sig_sym, bc, tag); 1239 if (m != NULL) { 1240 // We found the method. 1241 return m; 1242 } 1243 } 1244 1245 // Either the declared holder was not loaded, or the method could 1246 // not be found. 1247 1248 return NULL; 1249 } 1250 1251 // ------------------------------------------------------------------ 1252 InstanceKlass* JVMCIRuntime::get_instance_klass_for_declared_method_holder(Klass* method_holder) { 1253 // For the case of <array>.clone(), the method holder can be an ArrayKlass* 1254 // instead of an InstanceKlass*. For that case simply pretend that the 1255 // declared holder is Object.clone since that's where the call will bottom out. 1256 if (method_holder->is_instance_klass()) { 1257 return InstanceKlass::cast(method_holder); 1258 } else if (method_holder->is_array_klass()) { 1259 return SystemDictionary::Object_klass(); 1260 } else { 1261 ShouldNotReachHere(); 1262 } 1263 return NULL; 1264 } 1265 1266 1267 // ------------------------------------------------------------------ 1268 Method* JVMCIRuntime::get_method_by_index(const constantPoolHandle& cpool, 1269 int index, Bytecodes::Code bc, 1270 InstanceKlass* accessor) { 1271 ResourceMark rm; 1272 return get_method_by_index_impl(cpool, index, bc, accessor); 1273 } 1274 1275 // ------------------------------------------------------------------ 1276 // Check for changes to the system dictionary during compilation 1277 // class loads, evolution, breakpoints 1278 JVMCI::CodeInstallResult JVMCIRuntime::validate_compile_task_dependencies(Dependencies* dependencies, JVMCICompileState* compile_state, char** failure_detail) { 1279 // If JVMTI capabilities were enabled during compile, the compilation is invalidated. 1280 if (compile_state != NULL && compile_state->jvmti_state_changed()) { 1281 *failure_detail = (char*) "Jvmti state change during compilation invalidated dependencies"; 1282 return JVMCI::dependencies_failed; 1283 } 1284 1285 CompileTask* task = compile_state == NULL ? NULL : compile_state->task(); 1286 Dependencies::DepType result = dependencies->validate_dependencies(task, failure_detail); 1287 if (result == Dependencies::end_marker) { 1288 return JVMCI::ok; |