409 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); 410 if (unloaded_klass != NULL) { 411 if (require_local) return NULL; 412 return unloaded_klass; 413 } 414 415 Handle loader(THREAD, (oop)NULL); 416 Handle domain(THREAD, (oop)NULL); 417 if (accessing_klass != NULL) { 418 loader = Handle(THREAD, accessing_klass->loader()); 419 domain = Handle(THREAD, accessing_klass->protection_domain()); 420 } 421 422 // setup up the proper type to return on OOM 423 ciKlass* fail_type; 424 if (sym->byte_at(0) == '[') { 425 fail_type = _unloaded_ciobjarrayklass; 426 } else { 427 fail_type = _unloaded_ciinstance_klass; 428 } 429 KlassHandle found_klass; 430 { 431 ttyUnlocker ttyul; // release tty lock to avoid ordering problems 432 MutexLocker ml(Compile_lock); 433 Klass* kls; 434 if (!require_local) { 435 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, 436 KILL_COMPILE_ON_FATAL_(fail_type)); 437 } else { 438 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, 439 KILL_COMPILE_ON_FATAL_(fail_type)); 440 } 441 found_klass = KlassHandle(THREAD, kls); 442 } 443 444 // If we fail to find an array klass, look again for its element type. 445 // The element type may be available either locally or via constraints. 446 // In either case, if we can find the element type in the system dictionary, 447 // we must build an array type around it. The CI requires array klasses 448 // to be loaded if their element klasses are loaded, except when memory 449 // is exhausted. 450 if (sym->byte_at(0) == '[' && 451 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 452 // We have an unloaded array. 453 // Build it on the fly if the element class exists. 454 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, 455 sym->utf8_length()-1, 456 KILL_COMPILE_ON_FATAL_(fail_type)); 457 458 // Get element ciKlass recursively. 459 ciKlass* elem_klass = 460 get_klass_by_name_impl(accessing_klass, 461 cpool, 462 get_symbol(elem_sym), 463 require_local); 464 if (elem_klass != NULL && elem_klass->is_loaded()) { 465 // Now make an array for it 466 return ciObjArrayKlass::make_impl(elem_klass); 467 } 468 } 469 470 if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) { 471 // Look inside the constant pool for pre-resolved class entries. 472 for (int i = cpool->length() - 1; i >= 1; i--) { 473 if (cpool->tag_at(i).is_klass()) { 474 Klass* kls = cpool->resolved_klass_at(i); 475 if (kls->name() == sym) { 476 found_klass = KlassHandle(THREAD, kls); 477 break; 478 } 479 } 480 } 481 } 482 483 if (found_klass() != NULL) { 484 // Found it. Build a CI handle. 485 return get_klass(found_klass()); 486 } 487 488 if (require_local) return NULL; 489 490 // Not yet loaded into the VM, or not governed by loader constraints. 491 // Make a CI representative for it. 492 return get_unloaded_klass(accessing_klass, name); 493 } 494 495 // ------------------------------------------------------------------ 496 // ciEnv::get_klass_by_name 497 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, 498 ciSymbol* klass_name, 499 bool require_local) { 500 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, 501 constantPoolHandle(), 502 klass_name, 503 require_local);) 504 } 505 506 // ------------------------------------------------------------------ 507 // ciEnv::get_klass_by_index_impl 508 // 509 // Implementation of get_klass_by_index. 510 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, 511 int index, 512 bool& is_accessible, 513 ciInstanceKlass* accessor) { 514 EXCEPTION_CONTEXT; 515 KlassHandle klass; // = NULL; 516 Symbol* klass_name = NULL; 517 518 if (cpool->tag_at(index).is_symbol()) { 519 klass_name = cpool->symbol_at(index); 520 } else { 521 // Check if it's resolved if it's not a symbol constant pool entry. 522 klass = KlassHandle(THREAD, ConstantPool::klass_at_if_loaded(cpool, index)); 523 // Try to look it up by name. 524 if (klass.is_null()) { 525 klass_name = cpool->klass_name_at(index); 526 } 527 } 528 529 if (klass.is_null()) { 530 // Not found in constant pool. Use the name to do the lookup. 531 ciKlass* k = get_klass_by_name_impl(accessor, 532 cpool, 533 get_symbol(klass_name), 534 false); 535 // Calculate accessibility the hard way. 536 if (!k->is_loaded()) { 537 is_accessible = false; 538 } else if (k->loader() != accessor->loader() && 539 get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { 540 // Loaded only remotely. Not linked yet. 541 is_accessible = false; 542 } else { 543 // Linked locally, and we must also check public/private, etc. 544 is_accessible = check_klass_accessibility(accessor, k->get_Klass()); 545 } 546 return k; 547 } 548 549 // Check for prior unloaded klass. The SystemDictionary's answers 550 // can vary over time but the compiler needs consistency. 551 ciSymbol* name = get_symbol(klass()->name()); 552 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); 553 if (unloaded_klass != NULL) { 554 is_accessible = false; 555 return unloaded_klass; 556 } 557 558 // It is known to be accessible, since it was found in the constant pool. 559 is_accessible = true; 560 return get_klass(klass()); 561 } 562 563 // ------------------------------------------------------------------ 564 // ciEnv::get_klass_by_index 565 // 566 // Get a klass from the constant pool. 567 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool, 568 int index, 569 bool& is_accessible, 570 ciInstanceKlass* accessor) { 571 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) 572 } 573 574 // ------------------------------------------------------------------ 575 // ciEnv::get_constant_by_index_impl 576 // 577 // Implementation of get_constant_by_index(). 578 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool, 579 int pool_index, int cache_index, 580 ciInstanceKlass* accessor) { 694 // ciEnv::get_field_by_index 695 // 696 // Get a field by index from a klass's constant pool. 697 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, 698 int index) { 699 GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) 700 } 701 702 // ------------------------------------------------------------------ 703 // ciEnv::lookup_method 704 // 705 // Perform an appropriate method lookup based on accessor, holder, 706 // name, signature, and bytecode. 707 Method* ciEnv::lookup_method(InstanceKlass* accessor, 708 InstanceKlass* holder, 709 Symbol* name, 710 Symbol* sig, 711 Bytecodes::Code bc, 712 constantTag tag) { 713 EXCEPTION_CONTEXT; 714 KlassHandle h_accessor(THREAD, accessor); 715 KlassHandle h_holder(THREAD, holder); 716 LinkResolver::check_klass_accessability(h_accessor, h_holder, KILL_COMPILE_ON_FATAL_(NULL)); 717 methodHandle dest_method; 718 LinkInfo link_info(h_holder, name, sig, h_accessor, LinkInfo::needs_access_check, tag); 719 switch (bc) { 720 case Bytecodes::_invokestatic: 721 dest_method = 722 LinkResolver::resolve_static_call_or_null(link_info); 723 break; 724 case Bytecodes::_invokespecial: 725 dest_method = 726 LinkResolver::resolve_special_call_or_null(link_info); 727 break; 728 case Bytecodes::_invokeinterface: 729 dest_method = 730 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 731 break; 732 case Bytecodes::_invokevirtual: 733 dest_method = 734 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 735 break; 736 default: ShouldNotReachHere(); 737 } 738 | 409 ciKlass* unloaded_klass = check_get_unloaded_klass(accessing_klass, name); 410 if (unloaded_klass != NULL) { 411 if (require_local) return NULL; 412 return unloaded_klass; 413 } 414 415 Handle loader(THREAD, (oop)NULL); 416 Handle domain(THREAD, (oop)NULL); 417 if (accessing_klass != NULL) { 418 loader = Handle(THREAD, accessing_klass->loader()); 419 domain = Handle(THREAD, accessing_klass->protection_domain()); 420 } 421 422 // setup up the proper type to return on OOM 423 ciKlass* fail_type; 424 if (sym->byte_at(0) == '[') { 425 fail_type = _unloaded_ciobjarrayklass; 426 } else { 427 fail_type = _unloaded_ciinstance_klass; 428 } 429 Klass* found_klass; 430 { 431 ttyUnlocker ttyul; // release tty lock to avoid ordering problems 432 MutexLocker ml(Compile_lock); 433 Klass* kls; 434 if (!require_local) { 435 kls = SystemDictionary::find_constrained_instance_or_array_klass(sym, loader, 436 KILL_COMPILE_ON_FATAL_(fail_type)); 437 } else { 438 kls = SystemDictionary::find_instance_or_array_klass(sym, loader, domain, 439 KILL_COMPILE_ON_FATAL_(fail_type)); 440 } 441 found_klass = kls; 442 } 443 444 // If we fail to find an array klass, look again for its element type. 445 // The element type may be available either locally or via constraints. 446 // In either case, if we can find the element type in the system dictionary, 447 // we must build an array type around it. The CI requires array klasses 448 // to be loaded if their element klasses are loaded, except when memory 449 // is exhausted. 450 if (sym->byte_at(0) == '[' && 451 (sym->byte_at(1) == '[' || sym->byte_at(1) == 'L')) { 452 // We have an unloaded array. 453 // Build it on the fly if the element class exists. 454 TempNewSymbol elem_sym = SymbolTable::new_symbol(sym->as_utf8()+1, 455 sym->utf8_length()-1, 456 KILL_COMPILE_ON_FATAL_(fail_type)); 457 458 // Get element ciKlass recursively. 459 ciKlass* elem_klass = 460 get_klass_by_name_impl(accessing_klass, 461 cpool, 462 get_symbol(elem_sym), 463 require_local); 464 if (elem_klass != NULL && elem_klass->is_loaded()) { 465 // Now make an array for it 466 return ciObjArrayKlass::make_impl(elem_klass); 467 } 468 } 469 470 if (found_klass == NULL && !cpool.is_null() && cpool->has_preresolution()) { 471 // Look inside the constant pool for pre-resolved class entries. 472 for (int i = cpool->length() - 1; i >= 1; i--) { 473 if (cpool->tag_at(i).is_klass()) { 474 Klass* kls = cpool->resolved_klass_at(i); 475 if (kls->name() == sym) { 476 found_klass = kls; 477 break; 478 } 479 } 480 } 481 } 482 483 if (found_klass != NULL) { 484 // Found it. Build a CI handle. 485 return get_klass(found_klass); 486 } 487 488 if (require_local) return NULL; 489 490 // Not yet loaded into the VM, or not governed by loader constraints. 491 // Make a CI representative for it. 492 return get_unloaded_klass(accessing_klass, name); 493 } 494 495 // ------------------------------------------------------------------ 496 // ciEnv::get_klass_by_name 497 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass, 498 ciSymbol* klass_name, 499 bool require_local) { 500 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass, 501 constantPoolHandle(), 502 klass_name, 503 require_local);) 504 } 505 506 // ------------------------------------------------------------------ 507 // ciEnv::get_klass_by_index_impl 508 // 509 // Implementation of get_klass_by_index. 510 ciKlass* ciEnv::get_klass_by_index_impl(const constantPoolHandle& cpool, 511 int index, 512 bool& is_accessible, 513 ciInstanceKlass* accessor) { 514 EXCEPTION_CONTEXT; 515 Klass* klass = NULL; 516 Symbol* klass_name = NULL; 517 518 if (cpool->tag_at(index).is_symbol()) { 519 klass_name = cpool->symbol_at(index); 520 } else { 521 // Check if it's resolved if it's not a symbol constant pool entry. 522 klass = ConstantPool::klass_at_if_loaded(cpool, index); 523 // Try to look it up by name. 524 if (klass == NULL) { 525 klass_name = cpool->klass_name_at(index); 526 } 527 } 528 529 if (klass == NULL) { 530 // Not found in constant pool. Use the name to do the lookup. 531 ciKlass* k = get_klass_by_name_impl(accessor, 532 cpool, 533 get_symbol(klass_name), 534 false); 535 // Calculate accessibility the hard way. 536 if (!k->is_loaded()) { 537 is_accessible = false; 538 } else if (k->loader() != accessor->loader() && 539 get_klass_by_name_impl(accessor, cpool, k->name(), true) == NULL) { 540 // Loaded only remotely. Not linked yet. 541 is_accessible = false; 542 } else { 543 // Linked locally, and we must also check public/private, etc. 544 is_accessible = check_klass_accessibility(accessor, k->get_Klass()); 545 } 546 return k; 547 } 548 549 // Check for prior unloaded klass. The SystemDictionary's answers 550 // can vary over time but the compiler needs consistency. 551 ciSymbol* name = get_symbol(klass->name()); 552 ciKlass* unloaded_klass = check_get_unloaded_klass(accessor, name); 553 if (unloaded_klass != NULL) { 554 is_accessible = false; 555 return unloaded_klass; 556 } 557 558 // It is known to be accessible, since it was found in the constant pool. 559 is_accessible = true; 560 return get_klass(klass); 561 } 562 563 // ------------------------------------------------------------------ 564 // ciEnv::get_klass_by_index 565 // 566 // Get a klass from the constant pool. 567 ciKlass* ciEnv::get_klass_by_index(const constantPoolHandle& cpool, 568 int index, 569 bool& is_accessible, 570 ciInstanceKlass* accessor) { 571 GUARDED_VM_ENTRY(return get_klass_by_index_impl(cpool, index, is_accessible, accessor);) 572 } 573 574 // ------------------------------------------------------------------ 575 // ciEnv::get_constant_by_index_impl 576 // 577 // Implementation of get_constant_by_index(). 578 ciConstant ciEnv::get_constant_by_index_impl(const constantPoolHandle& cpool, 579 int pool_index, int cache_index, 580 ciInstanceKlass* accessor) { 694 // ciEnv::get_field_by_index 695 // 696 // Get a field by index from a klass's constant pool. 697 ciField* ciEnv::get_field_by_index(ciInstanceKlass* accessor, 698 int index) { 699 GUARDED_VM_ENTRY(return get_field_by_index_impl(accessor, index);) 700 } 701 702 // ------------------------------------------------------------------ 703 // ciEnv::lookup_method 704 // 705 // Perform an appropriate method lookup based on accessor, holder, 706 // name, signature, and bytecode. 707 Method* ciEnv::lookup_method(InstanceKlass* accessor, 708 InstanceKlass* holder, 709 Symbol* name, 710 Symbol* sig, 711 Bytecodes::Code bc, 712 constantTag tag) { 713 EXCEPTION_CONTEXT; 714 LinkResolver::check_klass_accessability(accessor, holder, KILL_COMPILE_ON_FATAL_(NULL)); 715 methodHandle dest_method; 716 LinkInfo link_info(holder, name, sig, accessor, LinkInfo::needs_access_check, tag); 717 switch (bc) { 718 case Bytecodes::_invokestatic: 719 dest_method = 720 LinkResolver::resolve_static_call_or_null(link_info); 721 break; 722 case Bytecodes::_invokespecial: 723 dest_method = 724 LinkResolver::resolve_special_call_or_null(link_info); 725 break; 726 case Bytecodes::_invokeinterface: 727 dest_method = 728 LinkResolver::linktime_resolve_interface_method_or_null(link_info); 729 break; 730 case Bytecodes::_invokevirtual: 731 dest_method = 732 LinkResolver::linktime_resolve_virtual_method_or_null(link_info); 733 break; 734 default: ShouldNotReachHere(); 735 } 736 |