456
457 if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
458 // Look inside the constant pool for pre-resolved class entries.
459 for (int i = cpool->length() - 1; i >= 1; i--) {
460 if (cpool->tag_at(i).is_klass()) {
461 klassOop kls = cpool->resolved_klass_at(i);
462 if (Klass::cast(kls)->name() == sym) {
463 found_klass = KlassHandle(THREAD, kls);
464 break;
465 }
466 }
467 }
468 }
469
470 if (found_klass() != NULL) {
471 // Found it. Build a CI handle.
472 return get_object(found_klass())->as_klass();
473 }
474
475 if (require_local) return NULL;
476 // Not yet loaded into the VM, or not governed by loader constraints.
477 // Make a CI representative for it.
478 return get_unloaded_klass(accessing_klass, name);
479 }
480
481 // ------------------------------------------------------------------
482 // ciEnv::get_klass_by_name
483 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
484 ciSymbol* klass_name,
485 bool require_local) {
486 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
487 constantPoolHandle(),
488 klass_name,
489 require_local);)
490 }
491
492 // ------------------------------------------------------------------
493 // ciEnv::get_klass_by_index_impl
494 //
495 // Implementation of get_klass_by_index.
496 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
497 int index,
498 bool& is_accessible,
499 ciInstanceKlass* accessor) {
500 EXCEPTION_CONTEXT;
501 KlassHandle klass (THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
502 Symbol* klass_name = NULL;
503 if (klass.is_null()) {
504 // The klass has not been inserted into the constant pool.
505 // Try to look it up by name.
506 {
507 // We have to lock the cpool to keep the oop from being resolved
508 // while we are accessing it.
509 ObjectLocker ol(cpool, THREAD);
510
511 constantTag tag = cpool->tag_at(index);
512 if (tag.is_klass()) {
513 // The klass has been inserted into the constant pool
514 // very recently.
515 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
516 } else if (tag.is_symbol()) {
517 klass_name = cpool->symbol_at(index);
518 } else {
519 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
520 klass_name = cpool->unresolved_klass_at(index);
521 }
768 }
769
770 if (holder_is_accessible) { // Our declared holder is loaded.
771 instanceKlass* lookup = declared_holder->get_instanceKlass();
772 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
773 if (m != NULL &&
774 (bc == Bytecodes::_invokestatic
775 ? instanceKlass::cast(m->method_holder())->is_not_initialized()
776 : !instanceKlass::cast(m->method_holder())->is_loaded())) {
777 m = NULL;
778 }
779 if (m != NULL) {
780 // We found the method.
781 return get_object(m)->as_method();
782 }
783 }
784
785 // Either the declared holder was not loaded, or the method could
786 // not be found. Create a dummy ciMethod to represent the failed
787 // lookup.
788
789 return get_unloaded_method(declared_holder,
790 get_symbol(name_sym),
791 get_symbol(sig_sym));
792 }
793
794
795 // ------------------------------------------------------------------
796 // ciEnv::get_fake_invokedynamic_method_impl
797 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
798 int index, Bytecodes::Code bc) {
799 // Compare the following logic with InterpreterRuntime::resolve_invokedynamic.
800 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
801
802 bool is_resolved = cpool->cache()->main_entry_at(index)->is_resolved(bc);
803 if (is_resolved && cpool->cache()->secondary_entry_at(index)->is_f1_null())
804 // FIXME: code generation could allow for null (unlinked) call site
805 is_resolved = false;
806
807 // Call site might not be resolved yet. We could create a real invoker method from the
808 // compiler, but it is simpler to stop the code path here with an unlinked method.
809 if (!is_resolved) {
810 ciInstanceKlass* mh_klass = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
811 ciSymbol* sig_sym = get_symbol(cpool->signature_ref_at(index));
812 return get_unloaded_method(mh_klass, ciSymbol::invokeExact_name(), sig_sym);
813 }
814
815 // Get the invoker methodOop from the constant pool.
816 oop f1_value = cpool->cache()->main_entry_at(index)->f1();
817 methodOop signature_invoker = (methodOop) f1_value;
818 assert(signature_invoker != NULL && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
819 "correct result from LinkResolver::resolve_invokedynamic");
820
821 return get_object(signature_invoker)->as_method();
822 }
823
824
825 // ------------------------------------------------------------------
826 // ciEnv::get_instance_klass_for_declared_method_holder
827 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) {
828 // For the case of <array>.clone(), the method holder can be a ciArrayKlass
829 // instead of a ciInstanceKlass. For that case simply pretend that the
830 // declared holder is Object.clone since that's where the call will bottom out.
831 // A more correct fix would trickle out through many interfaces in CI,
832 // requiring ciInstanceKlass* to become ciKlass* and many more places would
833 // require checks to make sure the expected type was found. Given that this
834 // only occurs for clone() the more extensive fix seems like overkill so
835 // instead we simply smear the array type into Object.
836 if (method_holder->is_instance_klass()) {
837 return method_holder->as_instance_klass();
838 } else if (method_holder->is_array_klass()) {
839 return current()->Object_klass();
840 } else {
841 ShouldNotReachHere();
842 }
843 return NULL;
844 }
845
846
847 // ------------------------------------------------------------------
848 // ciEnv::get_method_by_index
849 ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool,
850 int index, Bytecodes::Code bc,
851 ciInstanceKlass* accessor) {
852 if (bc == Bytecodes::_invokedynamic) {
853 GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc);)
854 } else {
855 GUARDED_VM_ENTRY(return get_method_by_index_impl(cpool, index, bc, accessor);)
856 }
857 }
858
859
860 // ------------------------------------------------------------------
861 // ciEnv::name_buffer
862 char *ciEnv::name_buffer(int req_len) {
863 if (_name_buffer_len < req_len) {
864 if (_name_buffer == NULL) {
865 _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len);
866 _name_buffer_len = req_len;
867 } else {
868 _name_buffer =
869 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
870 _name_buffer_len = req_len;
871 }
872 }
873 return _name_buffer;
874 }
875
|
456
457 if (found_klass() == NULL && !cpool.is_null() && cpool->has_preresolution()) {
458 // Look inside the constant pool for pre-resolved class entries.
459 for (int i = cpool->length() - 1; i >= 1; i--) {
460 if (cpool->tag_at(i).is_klass()) {
461 klassOop kls = cpool->resolved_klass_at(i);
462 if (Klass::cast(kls)->name() == sym) {
463 found_klass = KlassHandle(THREAD, kls);
464 break;
465 }
466 }
467 }
468 }
469
470 if (found_klass() != NULL) {
471 // Found it. Build a CI handle.
472 return get_object(found_klass())->as_klass();
473 }
474
475 if (require_local) return NULL;
476
477 // Not yet loaded into the VM, or not governed by loader constraints.
478 // Make a CI representative for it.
479 return get_unloaded_klass(accessing_klass, name);
480 }
481
482 // ------------------------------------------------------------------
483 // ciEnv::get_klass_by_name
484 ciKlass* ciEnv::get_klass_by_name(ciKlass* accessing_klass,
485 ciSymbol* klass_name,
486 bool require_local) {
487 GUARDED_VM_ENTRY(return get_klass_by_name_impl(accessing_klass,
488 constantPoolHandle(),
489 klass_name,
490 require_local);)
491 }
492
493 // ------------------------------------------------------------------
494 // ciEnv::get_klass_by_index_impl
495 //
496 // Implementation of get_klass_by_index.
497 ciKlass* ciEnv::get_klass_by_index_impl(constantPoolHandle cpool,
498 int index,
499 bool& is_accessible,
500 ciInstanceKlass* accessor) {
501 EXCEPTION_CONTEXT;
502 KlassHandle klass(THREAD, constantPoolOopDesc::klass_at_if_loaded(cpool, index));
503 Symbol* klass_name = NULL;
504 if (klass.is_null()) {
505 // The klass has not been inserted into the constant pool.
506 // Try to look it up by name.
507 {
508 // We have to lock the cpool to keep the oop from being resolved
509 // while we are accessing it.
510 ObjectLocker ol(cpool, THREAD);
511
512 constantTag tag = cpool->tag_at(index);
513 if (tag.is_klass()) {
514 // The klass has been inserted into the constant pool
515 // very recently.
516 klass = KlassHandle(THREAD, cpool->resolved_klass_at(index));
517 } else if (tag.is_symbol()) {
518 klass_name = cpool->symbol_at(index);
519 } else {
520 assert(cpool->tag_at(index).is_unresolved_klass(), "wrong tag");
521 klass_name = cpool->unresolved_klass_at(index);
522 }
769 }
770
771 if (holder_is_accessible) { // Our declared holder is loaded.
772 instanceKlass* lookup = declared_holder->get_instanceKlass();
773 methodOop m = lookup_method(accessor->get_instanceKlass(), lookup, name_sym, sig_sym, bc);
774 if (m != NULL &&
775 (bc == Bytecodes::_invokestatic
776 ? instanceKlass::cast(m->method_holder())->is_not_initialized()
777 : !instanceKlass::cast(m->method_holder())->is_loaded())) {
778 m = NULL;
779 }
780 if (m != NULL) {
781 // We found the method.
782 return get_object(m)->as_method();
783 }
784 }
785
786 // Either the declared holder was not loaded, or the method could
787 // not be found. Create a dummy ciMethod to represent the failed
788 // lookup.
789 ciSymbol* name = get_symbol(name_sym);
790 ciSymbol* signature = get_symbol(sig_sym);
791 return get_unloaded_method(declared_holder, name, signature, accessor);
792 }
793
794
795 // ------------------------------------------------------------------
796 // ciEnv::get_fake_invokedynamic_method_impl
797 ciMethod* ciEnv::get_fake_invokedynamic_method_impl(constantPoolHandle cpool,
798 int index, Bytecodes::Code bc,
799 ciInstanceKlass* accessor) {
800 // Compare the following logic with InterpreterRuntime::resolve_invokedynamic.
801 assert(bc == Bytecodes::_invokedynamic, "must be invokedynamic");
802
803 bool is_resolved = cpool->cache()->main_entry_at(index)->is_resolved(bc);
804 if (is_resolved && cpool->cache()->secondary_entry_at(index)->is_f1_null())
805 // FIXME: code generation could allow for null (unlinked) call site
806 is_resolved = false;
807
808 // Call site might not be resolved yet. We could create a real invoker method from the
809 // compiler, but it is simpler to stop the code path here with an unlinked method.
810 if (!is_resolved) {
811 ciInstanceKlass* holder = get_object(SystemDictionary::MethodHandle_klass())->as_instance_klass();
812 ciSymbol* name = ciSymbol::invokeExact_name();
813 ciSymbol* signature = get_symbol(cpool->signature_ref_at(index));
814 return get_unloaded_method(holder, name, signature, accessor);
815 }
816
817 // Get the invoker methodOop from the constant pool.
818 oop f1_value = cpool->cache()->main_entry_at(index)->f1();
819 methodOop signature_invoker = (methodOop) f1_value;
820 assert(signature_invoker != NULL && signature_invoker->is_method() && signature_invoker->is_method_handle_invoke(),
821 "correct result from LinkResolver::resolve_invokedynamic");
822
823 return get_object(signature_invoker)->as_method();
824 }
825
826
827 // ------------------------------------------------------------------
828 // ciEnv::get_instance_klass_for_declared_method_holder
829 ciInstanceKlass* ciEnv::get_instance_klass_for_declared_method_holder(ciKlass* method_holder) {
830 // For the case of <array>.clone(), the method holder can be a ciArrayKlass
831 // instead of a ciInstanceKlass. For that case simply pretend that the
832 // declared holder is Object.clone since that's where the call will bottom out.
833 // A more correct fix would trickle out through many interfaces in CI,
834 // requiring ciInstanceKlass* to become ciKlass* and many more places would
835 // require checks to make sure the expected type was found. Given that this
836 // only occurs for clone() the more extensive fix seems like overkill so
837 // instead we simply smear the array type into Object.
838 if (method_holder->is_instance_klass()) {
839 return method_holder->as_instance_klass();
840 } else if (method_holder->is_array_klass()) {
841 return current()->Object_klass();
842 } else {
843 ShouldNotReachHere();
844 }
845 return NULL;
846 }
847
848
849 // ------------------------------------------------------------------
850 // ciEnv::get_method_by_index
851 ciMethod* ciEnv::get_method_by_index(constantPoolHandle cpool,
852 int index, Bytecodes::Code bc,
853 ciInstanceKlass* accessor) {
854 if (bc == Bytecodes::_invokedynamic) {
855 GUARDED_VM_ENTRY(return get_fake_invokedynamic_method_impl(cpool, index, bc, accessor);)
856 } else {
857 GUARDED_VM_ENTRY(return get_method_by_index_impl( cpool, index, bc, accessor);)
858 }
859 }
860
861
862 // ------------------------------------------------------------------
863 // ciEnv::name_buffer
864 char *ciEnv::name_buffer(int req_len) {
865 if (_name_buffer_len < req_len) {
866 if (_name_buffer == NULL) {
867 _name_buffer = (char*)arena()->Amalloc(sizeof(char)*req_len);
868 _name_buffer_len = req_len;
869 } else {
870 _name_buffer =
871 (char*)arena()->Arealloc(_name_buffer, _name_buffer_len, req_len);
872 _name_buffer_len = req_len;
873 }
874 }
875 return _name_buffer;
876 }
877
|