48 #include "utilities/dtrace.hpp" 49 #include "jvmci/jvmciRuntime.hpp" 50 #include "jvmci/jvmciJavaClasses.hpp" 51 52 JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter): 53 _task(task), 54 _system_dictionary_modification_counter(system_dictionary_modification_counter), 55 _failure_reason(NULL), 56 _retryable(true) 57 { 58 // Get Jvmti capabilities under lock to get consistent values. 59 MutexLocker mu(JvmtiThreadState_lock); 60 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); 61 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); 62 _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); 63 } 64 65 // ------------------------------------------------------------------ 66 // Note: the logic of this method should mirror the logic of 67 // constantPoolOopDesc::verify_constant_pool_resolve. 68 bool JVMCIEnv::check_klass_accessibility(KlassHandle accessing_klass, KlassHandle resolved_klass) { 69 if (accessing_klass->is_objArray_klass()) { 70 accessing_klass = ObjArrayKlass::cast(accessing_klass())->bottom_klass(); 71 } 72 if (!accessing_klass->is_instance_klass()) { 73 return true; 74 } 75 76 if (resolved_klass->is_objArray_klass()) { 77 // Find the element klass, if this is an array. 78 resolved_klass = ObjArrayKlass::cast(resolved_klass())->bottom_klass(); 79 } 80 if (resolved_klass->is_instance_klass()) { 81 Reflection::VerifyClassAccessResults result = 82 Reflection::verify_class_access(accessing_klass(), InstanceKlass::cast(resolved_klass()), true); 83 return result == Reflection::ACCESS_OK; 84 } 85 return true; 86 } 87 88 // ------------------------------------------------------------------ 89 KlassHandle JVMCIEnv::get_klass_by_name_impl(KlassHandle& accessing_klass, 90 const constantPoolHandle& cpool, 91 Symbol* sym, 92 bool require_local) { 93 JVMCI_EXCEPTION_CONTEXT; 94 95 // Now we need to check the SystemDictionary 96 if (sym->byte_at(0) == 'L' && 97 sym->byte_at(sym->utf8_length()-1) == ';') { 98 // This is a name from a signature. Strip off the trimmings. 99 // Call recursive to keep scope of strippedsym. 100 TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, 101 sym->utf8_length()-2, 102 CHECK_(KlassHandle())); 103 return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local); 104 } 105 106 Handle loader(THREAD, (oop)NULL); 107 Handle domain(THREAD, (oop)NULL); 108 if (!accessing_klass.is_null()) { 109 loader = Handle(THREAD, accessing_klass->class_loader()); 110 domain = Handle(THREAD, accessing_klass->protection_domain()); 111 } 112 113 KlassHandle found_klass; 114 { 115 ttyUnlocker ttyul; // release tty lock to avoid ordering problems 116 MutexLocker ml(Compile_lock); 117 Klass* kls; 118 if (!require_local) { 119 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_(KlassHandle())); 120 } else { 121 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_(KlassHandle())); 122 } 123 found_klass = KlassHandle(THREAD, kls); 124 } 125 126 // If we fail to find an array klass, look again for its element type. 127 // The element type may be available either locally or via constraints. 128 // In either case, if we can find the element type in the system dictionary, 129 // we must build an array type around it. The CI requires array klasses 130 // to be loaded if their element klasses are loaded, except when memory 131 // is exhausted. 132 if (sym->byte_at(0) == '[' && 133 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 134 // We have an unloaded array. 135 // Build it on the fly if the element class exists. 136 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, 137 sym->utf8_length()-1, 138 CHECK_(KlassHandle())); 139 140 // Get element Klass recursively. 141 KlassHandle elem_klass = 142 get_klass_by_name_impl(accessing_klass, 143 cpool, 144 elem_sym, 145 require_local); 146 if (!elem_klass.is_null()) { 147 // Now make an array for it 148 return elem_klass->array_klass(CHECK_(KlassHandle())); 149 } 150 } 151 152 if (found_klass.is_null() && !cpool.is_null() && cpool->has_preresolution()) { 153 // Look inside the constant pool for pre-resolved class entries. 154 for (int i = cpool->length() - 1; i >= 1; i--) { 155 if (cpool->tag_at(i).is_klass()) { 156 Klass* kls = cpool->resolved_klass_at(i); 157 if (kls->name() == sym) { 158 return kls; 159 } 160 } 161 } 162 } 163 164 return found_klass(); 165 } 166 167 // ------------------------------------------------------------------ 168 KlassHandle JVMCIEnv::get_klass_by_name(KlassHandle accessing_klass, 169 Symbol* klass_name, 170 bool require_local) { 171 ResourceMark rm; 172 constantPoolHandle cpool; 173 return get_klass_by_name_impl(accessing_klass, 174 cpool, 175 klass_name, 176 require_local); 177 } 178 179 // ------------------------------------------------------------------ 180 // Implementation of get_klass_by_index. 181 KlassHandle JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, 182 int index, 183 bool& is_accessible, 184 KlassHandle accessor) { 185 JVMCI_EXCEPTION_CONTEXT; 186 KlassHandle klass (THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); 187 Symbol* klass_name = NULL; 188 if (klass.is_null()) { 189 klass_name = cpool->klass_name_at(index); 190 } 191 192 if (klass.is_null()) { 193 // Not found in constant pool. Use the name to do the lookup. 194 KlassHandle k = get_klass_by_name_impl(accessor, 195 cpool, 196 klass_name, 197 false); 198 // Calculate accessibility the hard way. 199 if (k.is_null()) { 200 is_accessible = false; 201 } else if (k->class_loader() != accessor->class_loader() && 202 get_klass_by_name_impl(accessor, cpool, k->name(), true).is_null()) { 203 // Loaded only remotely. Not linked yet. 204 is_accessible = false; 205 } else { 206 // Linked locally, and we must also check public/private, etc. 207 is_accessible = check_klass_accessibility(accessor, k); 208 } 209 if (!is_accessible) { 210 return KlassHandle(); 211 } 212 return k; 213 } 214 215 // It is known to be accessible, since it was found in the constant pool. 216 is_accessible = true; 217 return klass; 218 } 219 220 // ------------------------------------------------------------------ 221 // Get a klass from the constant pool. 222 KlassHandle JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool, 223 int index, 224 bool& is_accessible, 225 KlassHandle accessor) { 226 ResourceMark rm; 227 KlassHandle result = get_klass_by_index_impl(cpool, index, is_accessible, accessor); 228 return result; 229 } 230 231 // ------------------------------------------------------------------ 232 // Implementation of get_field_by_index. 233 // 234 // Implementation note: the results of field lookups are cached 235 // in the accessor klass. 236 void JVMCIEnv::get_field_by_index_impl(instanceKlassHandle klass, fieldDescriptor& field_desc, 237 int index) { 238 JVMCI_EXCEPTION_CONTEXT; 239 240 assert(klass->is_linked(), "must be linked before using its constant-pool"); 241 242 constantPoolHandle cpool(thread, klass->constants()); 243 244 // Get the field's name, signature, and type. 245 Symbol* name = cpool->name_ref_at(index); 246 247 int nt_index = cpool->name_and_type_ref_index_at(index); 248 int sig_index = cpool->signature_ref_index_at(nt_index); 249 Symbol* signature = cpool->symbol_at(sig_index); 250 251 // Get the field's declared holder. 252 int holder_index = cpool->klass_ref_index_at(index); 253 bool holder_is_accessible; 254 KlassHandle declared_holder = get_klass_by_index(cpool, holder_index, 255 holder_is_accessible, 256 klass); 257 258 // The declared holder of this field may not have been loaded. 259 // Bail out with partial field information. 260 if (!holder_is_accessible) { 261 return; 262 } 263 264 265 // Perform the field lookup. 266 Klass* canonical_holder = 267 InstanceKlass::cast(declared_holder())->find_field(name, signature, &field_desc); 268 if (canonical_holder == NULL) { 269 return; 270 } 271 272 assert(canonical_holder == field_desc.field_holder(), "just checking"); 273 } 274 275 // ------------------------------------------------------------------ 276 // Get a field by index from a klass's constant pool. 277 void JVMCIEnv::get_field_by_index(instanceKlassHandle accessor, fieldDescriptor& fd, int index) { 278 ResourceMark rm; 279 return get_field_by_index_impl(accessor, fd, index); 280 } 281 282 // ------------------------------------------------------------------ 283 // Perform an appropriate method lookup based on accessor, holder, 284 // name, signature, and bytecode. 285 methodHandle JVMCIEnv::lookup_method(instanceKlassHandle h_accessor, 286 instanceKlassHandle h_holder, 287 Symbol* name, 288 Symbol* sig, 289 Bytecodes::Code bc, 290 constantTag tag) { 291 JVMCI_EXCEPTION_CONTEXT; 292 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 293 methodHandle dest_method; 294 LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag); 295 switch (bc) { 296 case Bytecodes::_invokestatic: 297 dest_method = 298 LinkResolver::resolve_static_call_or_null(link_info); 299 break; 300 case Bytecodes::_invokespecial: 301 dest_method = 302 LinkResolver::resolve_special_call_or_null(link_info); 303 break; 304 case Bytecodes::_invokeinterface: 305 dest_method = 306 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 307 break; 308 case Bytecodes::_invokevirtual: 309 dest_method = 310 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 311 break; 312 default: ShouldNotReachHere(); 313 } 314 315 return dest_method; 316 } 317 318 319 // ------------------------------------------------------------------ 320 methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool, 321 int index, Bytecodes::Code bc, 322 instanceKlassHandle accessor) { 323 if (bc == Bytecodes::_invokedynamic) { 324 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 325 bool is_resolved = !cpce->is_f1_null(); 326 if (is_resolved) { 327 // Get the invoker Method* from the constant pool. 328 // (The appendix argument, if any, will be noted in the method's signature.) 329 Method* adapter = cpce->f1_as_method(); 330 return methodHandle(adapter); 331 } 332 333 return NULL; 334 } 335 336 int holder_index = cpool->klass_ref_index_at(index); 337 bool holder_is_accessible; 338 KlassHandle holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 339 340 // Get the method's name and signature. 341 Symbol* name_sym = cpool->name_ref_at(index); 342 Symbol* sig_sym = cpool->signature_ref_at(index); 343 344 if (cpool->has_preresolution() 345 || ((holder() == SystemDictionary::MethodHandle_klass() || holder() == SystemDictionary::VarHandle_klass()) && 346 MethodHandles::is_signature_polymorphic_name(holder(), name_sym))) { 347 // Short-circuit lookups for JSR 292-related call sites. 348 // That is, do not rely only on name-based lookups, because they may fail 349 // if the names are not resolvable in the boot class loader (7056328). 350 switch (bc) { 351 case Bytecodes::_invokevirtual: 352 case Bytecodes::_invokeinterface: 353 case Bytecodes::_invokespecial: 354 case Bytecodes::_invokestatic: 355 { 356 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 357 if (m != NULL) { 358 return m; 359 } 360 } 361 break; 362 } 363 } 364 365 if (holder_is_accessible) { // Our declared holder is loaded. 366 instanceKlassHandle lookup = get_instance_klass_for_declared_method_holder(holder); 367 constantTag tag = cpool->tag_ref_at(index); 368 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag); 369 if (!m.is_null() && 370 (bc == Bytecodes::_invokestatic 371 ? InstanceKlass::cast(m->method_holder())->is_not_initialized() 372 : !InstanceKlass::cast(m->method_holder())->is_loaded())) { 373 m = NULL; 374 } 375 if (!m.is_null()) { 376 // We found the method. 377 return m; 378 } 379 } 380 381 // Either the declared holder was not loaded, or the method could 382 // not be found. 383 384 return NULL; 385 } 386 387 // ------------------------------------------------------------------ 388 instanceKlassHandle JVMCIEnv::get_instance_klass_for_declared_method_holder(KlassHandle method_holder) { 389 // For the case of <array>.clone(), the method holder can be an ArrayKlass* 390 // instead of an InstanceKlass*. For that case simply pretend that the 391 // declared holder is Object.clone since that's where the call will bottom out. 392 if (method_holder->is_instance_klass()) { 393 return instanceKlassHandle(method_holder()); 394 } else if (method_holder->is_array_klass()) { 395 return instanceKlassHandle(SystemDictionary::Object_klass()); 396 } else { 397 ShouldNotReachHere(); 398 } 399 return NULL; 400 } 401 402 403 // ------------------------------------------------------------------ 404 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool, 405 int index, Bytecodes::Code bc, 406 instanceKlassHandle accessor) { 407 ResourceMark rm; 408 return get_method_by_index_impl(cpool, index, bc, accessor); 409 } 410 411 // ------------------------------------------------------------------ 412 // Check for changes to the system dictionary during compilation 413 // class loads, evolution, breakpoints 414 JVMCIEnv::CodeInstallResult JVMCIEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code, 415 JVMCIEnv* env, char** failure_detail) { 416 // If JVMTI capabilities were enabled during compile, the compilation is invalidated. 417 if (env != NULL) { 418 if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) { 419 *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation"; 420 return JVMCIEnv::dependencies_failed; 421 } 422 } 423 424 // Dependencies must be checked when the system dictionary changes 425 // or if we don't know whether it has changed (i.e., env == NULL). 426 // In debug mode, always check dependencies. | 48 #include "utilities/dtrace.hpp" 49 #include "jvmci/jvmciRuntime.hpp" 50 #include "jvmci/jvmciJavaClasses.hpp" 51 52 JVMCIEnv::JVMCIEnv(CompileTask* task, int system_dictionary_modification_counter): 53 _task(task), 54 _system_dictionary_modification_counter(system_dictionary_modification_counter), 55 _failure_reason(NULL), 56 _retryable(true) 57 { 58 // Get Jvmti capabilities under lock to get consistent values. 59 MutexLocker mu(JvmtiThreadState_lock); 60 _jvmti_can_hotswap_or_post_breakpoint = JvmtiExport::can_hotswap_or_post_breakpoint(); 61 _jvmti_can_access_local_variables = JvmtiExport::can_access_local_variables(); 62 _jvmti_can_post_on_exceptions = JvmtiExport::can_post_on_exceptions(); 63 } 64 65 // ------------------------------------------------------------------ 66 // Note: the logic of this method should mirror the logic of 67 // constantPoolOopDesc::verify_constant_pool_resolve. 68 bool JVMCIEnv::check_klass_accessibility(Klass* accessing_klass, Klass* resolved_klass) { 69 if (accessing_klass->is_objArray_klass()) { 70 accessing_klass = ObjArrayKlass::cast(accessing_klass)->bottom_klass(); 71 } 72 if (!accessing_klass->is_instance_klass()) { 73 return true; 74 } 75 76 if (resolved_klass->is_objArray_klass()) { 77 // Find the element klass, if this is an array. 78 resolved_klass = ObjArrayKlass::cast(resolved_klass)->bottom_klass(); 79 } 80 if (resolved_klass->is_instance_klass()) { 81 Reflection::VerifyClassAccessResults result = 82 Reflection::verify_class_access(accessing_klass, InstanceKlass::cast(resolved_klass), true); 83 return result == Reflection::ACCESS_OK; 84 } 85 return true; 86 } 87 88 // ------------------------------------------------------------------ 89 Klass* JVMCIEnv::get_klass_by_name_impl(Klass* accessing_klass, 90 const constantPoolHandle& cpool, 91 Symbol* sym, 92 bool require_local) { 93 JVMCI_EXCEPTION_CONTEXT; 94 95 // Now we need to check the SystemDictionary 96 if (sym->byte_at(0) == 'L' && 97 sym->byte_at(sym->utf8_length()-1) == ';') { 98 // This is a name from a signature. Strip off the trimmings. 99 // Call recursive to keep scope of strippedsym. 100 TempNewSymbol strippedsym = SymbolTable::new_symbol(sym->as_utf8()+1, 101 sym->utf8_length()-2, 102 CHECK_NULL); 103 return get_klass_by_name_impl(accessing_klass, cpool, strippedsym, require_local); 104 } 105 106 Handle loader(THREAD, (oop)NULL); 107 Handle domain(THREAD, (oop)NULL); 108 if (accessing_klass != NULL) { 109 loader = Handle(THREAD, accessing_klass->class_loader()); 110 domain = Handle(THREAD, accessing_klass->protection_domain()); 111 } 112 113 Klass* found_klass = NULL; 114 { 115 ttyUnlocker ttyul; // release tty lock to avoid ordering problems 116 MutexLocker ml(Compile_lock); 117 if (!require_local) { 118 found_klass = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, CHECK_NULL); 119 } else { 120 found_klass = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, CHECK_NULL); 121 } 122 } 123 124 // If we fail to find an array klass, look again for its element type. 125 // The element type may be available either locally or via constraints. 126 // In either case, if we can find the element type in the system dictionary, 127 // we must build an array type around it. The CI requires array klasses 128 // to be loaded if their element klasses are loaded, except when memory 129 // is exhausted. 130 if (sym->byte_at(0) == '[' && 131 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 132 // We have an unloaded array. 133 // Build it on the fly if the element class exists. 134 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, 135 sym->utf8_length()-1, 136 CHECK_NULL); 137 138 // Get element Klass recursively. 139 Klass* elem_klass = 140 get_klass_by_name_impl(accessing_klass, 141 cpool, 142 elem_sym, 143 require_local); 144 if (elem_klass != NULL) { 145 // Now make an array for it 146 return elem_klass->array_klass(CHECK_NULL); 147 } 148 } 149 150 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) { 151 // Look inside the constant pool for pre-resolved class entries. 152 for (int i = cpool->length() - 1; i >= 1; i--) { 153 if (cpool->tag_at(i).is_klass()) { 154 Klass* kls = cpool->resolved_klass_at(i); 155 if (kls->name() == sym) { 156 return kls; 157 } 158 } 159 } 160 } 161 162 return found_klass; 163 } 164 165 // ------------------------------------------------------------------ 166 Klass* JVMCIEnv::get_klass_by_name(Klass* accessing_klass, 167 Symbol* klass_name, 168 bool require_local) { 169 ResourceMark rm; 170 constantPoolHandle cpool; 171 return get_klass_by_name_impl(accessing_klass, 172 cpool, 173 klass_name, 174 require_local); 175 } 176 177 // ------------------------------------------------------------------ 178 // Implementation of get_klass_by_index. 179 Klass* JVMCIEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, 180 int index, 181 bool& is_accessible, 182 Klass* accessor) { 183 JVMCI_EXCEPTION_CONTEXT; 184 Klass* klass = ConstantPool::klass_at_if_loaded(cpool, index); 185 Symbol* klass_name = NULL; 186 if (klass == NULL) { 187 klass_name = cpool->klass_name_at(index); 188 } 189 190 if (klass == NULL) { 191 // Not found in constant pool. Use the name to do the lookup. 192 Klass* k = get_klass_by_name_impl(accessor, 193 cpool, 194 klass_name, 195 false); 196 // Calculate accessibility the hard way. 197 if (k == NULL) { 198 is_accessible = false; 199 } else if (k->class_loader() != accessor->class_loader() && 200 get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { 201 // Loaded only remotely. Not linked yet. 202 is_accessible = false; 203 } else { 204 // Linked locally, and we must also check public/private, etc. 205 is_accessible = check_klass_accessibility(accessor, k); 206 } 207 if (!is_accessible) { 208 return NULL; 209 } 210 return k; 211 } 212 213 // It is known to be accessible, since it was found in the constant pool. 214 is_accessible = true; 215 return klass; 216 } 217 218 // ------------------------------------------------------------------ 219 // Get a klass from the constant pool. 220 Klass* JVMCIEnv::get_klass_by_index(const constantPoolHandle& cpool, 221 int index, 222 bool& is_accessible, 223 Klass* accessor) { 224 ResourceMark rm; 225 return get_klass_by_index_impl(cpool, index, is_accessible, accessor); 226 } 227 228 // ------------------------------------------------------------------ 229 // Implementation of get_field_by_index. 230 // 231 // Implementation note: the results of field lookups are cached 232 // in the accessor klass. 233 void JVMCIEnv::get_field_by_index_impl(InstanceKlass* klass, fieldDescriptor& field_desc, 234 int index) { 235 JVMCI_EXCEPTION_CONTEXT; 236 237 assert(klass->is_linked(), "must be linked before using its constant-pool"); 238 239 constantPoolHandle cpool(thread, klass->constants()); 240 241 // Get the field's name, signature, and type. 242 Symbol* name = cpool->name_ref_at(index); 243 244 int nt_index = cpool->name_and_type_ref_index_at(index); 245 int sig_index = cpool->signature_ref_index_at(nt_index); 246 Symbol* signature = cpool->symbol_at(sig_index); 247 248 // Get the field's declared holder. 249 int holder_index = cpool->klass_ref_index_at(index); 250 bool holder_is_accessible; 251 Klass* declared_holder = get_klass_by_index(cpool, holder_index, 252 holder_is_accessible, 253 klass); 254 255 // The declared holder of this field may not have been loaded. 256 // Bail out with partial field information. 257 if (!holder_is_accessible) { 258 return; 259 } 260 261 262 // Perform the field lookup. 263 Klass* canonical_holder = 264 InstanceKlass::cast(declared_holder)->find_field(name, signature, &field_desc); 265 if (canonical_holder == NULL) { 266 return; 267 } 268 269 assert(canonical_holder == field_desc.field_holder(), "just checking"); 270 } 271 272 // ------------------------------------------------------------------ 273 // Get a field by index from a klass's constant pool. 274 void JVMCIEnv::get_field_by_index(InstanceKlass* accessor, fieldDescriptor& fd, int index) { 275 ResourceMark rm; 276 return get_field_by_index_impl(accessor, fd, index); 277 } 278 279 // ------------------------------------------------------------------ 280 // Perform an appropriate method lookup based on accessor, holder, 281 // name, signature, and bytecode. 282 methodHandle JVMCIEnv::lookup_method(InstanceKlass* h_accessor, 283 InstanceKlass* h_holder, 284 Symbol* name, 285 Symbol* sig, 286 Bytecodes::Code bc, 287 constantTag tag) { 288 JVMCI_EXCEPTION_CONTEXT; 289 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 290 methodHandle dest_method; 291 LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag); 292 switch (bc) { 293 case Bytecodes::_invokestatic: 294 dest_method = 295 LinkResolver::resolve_static_call_or_null(link_info); 296 break; 297 case Bytecodes::_invokespecial: 298 dest_method = 299 LinkResolver::resolve_special_call_or_null(link_info); 300 break; 301 case Bytecodes::_invokeinterface: 302 dest_method = 303 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 304 break; 305 case Bytecodes::_invokevirtual: 306 dest_method = 307 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 308 break; 309 default: ShouldNotReachHere(); 310 } 311 312 return dest_method; 313 } 314 315 316 // ------------------------------------------------------------------ 317 methodHandle JVMCIEnv::get_method_by_index_impl(const constantPoolHandle& cpool, 318 int index, Bytecodes::Code bc, 319 InstanceKlass* accessor) { 320 if (bc == Bytecodes::_invokedynamic) { 321 ConstantPoolCacheEntry* cpce = cpool->invokedynamic_cp_cache_entry_at(index); 322 bool is_resolved = !cpce->is_f1_null(); 323 if (is_resolved) { 324 // Get the invoker Method* from the constant pool. 325 // (The appendix argument, if any, will be noted in the method's signature.) 326 Method* adapter = cpce->f1_as_method(); 327 return methodHandle(adapter); 328 } 329 330 return NULL; 331 } 332 333 int holder_index = cpool->klass_ref_index_at(index); 334 bool holder_is_accessible; 335 Klass* holder = get_klass_by_index_impl(cpool, holder_index, holder_is_accessible, accessor); 336 337 // Get the method's name and signature. 338 Symbol* name_sym = cpool->name_ref_at(index); 339 Symbol* sig_sym = cpool->signature_ref_at(index); 340 341 if (cpool->has_preresolution() 342 || ((holder == SystemDictionary::MethodHandle_klass() || holder == SystemDictionary::VarHandle_klass()) && 343 MethodHandles::is_signature_polymorphic_name(holder, name_sym))) { 344 // Short-circuit lookups for JSR 292-related call sites. 345 // That is, do not rely only on name-based lookups, because they may fail 346 // if the names are not resolvable in the boot class loader (7056328). 347 switch (bc) { 348 case Bytecodes::_invokevirtual: 349 case Bytecodes::_invokeinterface: 350 case Bytecodes::_invokespecial: 351 case Bytecodes::_invokestatic: 352 { 353 Method* m = ConstantPool::method_at_if_loaded(cpool, index); 354 if (m != NULL) { 355 return m; 356 } 357 } 358 break; 359 } 360 } 361 362 if (holder_is_accessible) { // Our declared holder is loaded. 363 InstanceKlass* lookup = get_instance_klass_for_declared_method_holder(holder); 364 constantTag tag = cpool->tag_ref_at(index); 365 methodHandle m = lookup_method(accessor, lookup, name_sym, sig_sym, bc, tag); 366 if (!m.is_null() && 367 (bc == Bytecodes::_invokestatic 368 ? InstanceKlass::cast(m->method_holder())->is_not_initialized() 369 : !InstanceKlass::cast(m->method_holder())->is_loaded())) { 370 m = NULL; 371 } 372 if (!m.is_null()) { 373 // We found the method. 374 return m; 375 } 376 } 377 378 // Either the declared holder was not loaded, or the method could 379 // not be found. 380 381 return NULL; 382 } 383 384 // ------------------------------------------------------------------ 385 InstanceKlass* JVMCIEnv::get_instance_klass_for_declared_method_holder(Klass* method_holder) { 386 // For the case of <array>.clone(), the method holder can be an ArrayKlass* 387 // instead of an InstanceKlass*. For that case simply pretend that the 388 // declared holder is Object.clone since that's where the call will bottom out. 389 if (method_holder->is_instance_klass()) { 390 return InstanceKlass::cast(method_holder); 391 } else if (method_holder->is_array_klass()) { 392 return SystemDictionary::Object_klass(); 393 } else { 394 ShouldNotReachHere(); 395 } 396 return NULL; 397 } 398 399 400 // ------------------------------------------------------------------ 401 methodHandle JVMCIEnv::get_method_by_index(const constantPoolHandle& cpool, 402 int index, Bytecodes::Code bc, 403 InstanceKlass* accessor) { 404 ResourceMark rm; 405 return get_method_by_index_impl(cpool, index, bc, accessor); 406 } 407 408 // ------------------------------------------------------------------ 409 // Check for changes to the system dictionary during compilation 410 // class loads, evolution, breakpoints 411 JVMCIEnv::CodeInstallResult JVMCIEnv::check_for_system_dictionary_modification(Dependencies* dependencies, Handle compiled_code, 412 JVMCIEnv* env, char** failure_detail) { 413 // If JVMTI capabilities were enabled during compile, the compilation is invalidated. 414 if (env != NULL) { 415 if (!env->_jvmti_can_hotswap_or_post_breakpoint && JvmtiExport::can_hotswap_or_post_breakpoint()) { 416 *failure_detail = (char*) "Hotswapping or breakpointing was enabled during compilation"; 417 return JVMCIEnv::dependencies_failed; 418 } 419 } 420 421 // Dependencies must be checked when the system dictionary changes 422 // or if we don't know whether it has changed (i.e., env == NULL). 423 // In debug mode, always check dependencies. |