< prev index next >

src/hotspot/share/oops/constantPool.cpp

Print this page




  32 #include "classfile/vmSymbols.hpp"
  33 #include "interpreter/bootstrapInfo.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/heapShared.hpp"
  37 #include "memory/metadataFactory.hpp"
  38 #include "memory/metaspaceClosure.hpp"
  39 #include "memory/metaspaceShared.hpp"
  40 #include "memory/oopFactory.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "oops/array.hpp"
  44 #include "oops/constantPool.inline.hpp"
  45 #include "oops/cpCache.inline.hpp"
  46 #include "oops/instanceKlass.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "runtime/atomic.hpp"
  52 #include "runtime/fieldType.hpp"
  53 #include "runtime/handles.inline.hpp"
  54 #include "runtime/init.hpp"
  55 #include "runtime/javaCalls.hpp"
  56 #include "runtime/signature.hpp"
  57 #include "runtime/thread.inline.hpp"
  58 #include "runtime/vframe.inline.hpp"
  59 #include "utilities/copy.hpp"
  60 
  61 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  62   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
  63   int size = ConstantPool::size(length);
  64   return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
  65 }
  66 
  67 #ifdef ASSERT
  68 
  69 // MetaspaceObj allocation invariant is calloc equivalent memory
  70 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
  71 static bool tag_array_is_zero_initialized(Array<u1>* tags) {
  72   assert(tags != NULL, "invariant");


 711 
 712 Symbol* ConstantPool::klass_name_at(int which) const {
 713   return symbol_at(klass_slot_at(which).name_index());
 714 }
 715 
 716 Symbol* ConstantPool::klass_ref_at_noresolve(int which) {
 717   jint ref_index = klass_ref_index_at(which);
 718   return klass_at_noresolve(ref_index);
 719 }
 720 
 721 Symbol* ConstantPool::uncached_klass_ref_at_noresolve(int which) {
 722   jint ref_index = uncached_klass_ref_index_at(which);
 723   return klass_at_noresolve(ref_index);
 724 }
 725 
 726 char* ConstantPool::string_at_noresolve(int which) {
 727   return unresolved_string_at(which)->as_C_string();
 728 }
 729 
 730 BasicType ConstantPool::basic_type_for_signature_at(int which) const {
 731   return FieldType::basic_type(symbol_at(which));
 732 }
 733 
 734 
 735 void ConstantPool::resolve_string_constants_impl(const constantPoolHandle& this_cp, TRAPS) {
 736   for (int index = 1; index < this_cp->length(); index++) { // Index 0 is unused
 737     if (this_cp->tag_at(index).is_string()) {
 738       this_cp->string_at(index, CHECK);
 739     }
 740   }
 741 }
 742 
 743 Symbol* ConstantPool::exception_message(const constantPoolHandle& this_cp, int which, constantTag tag, oop pending_exception) {
 744   // Dig out the detailed message to reuse if possible
 745   Symbol* message = java_lang_Throwable::detail_message(pending_exception);
 746   if (message != NULL) {
 747     return message;
 748   }
 749 
 750   // Return specific message for the tag
 751   switch (tag.value()) {


 823   }
 824 }
 825 
 826 constantTag ConstantPool::constant_tag_at(int which) {
 827   constantTag tag = tag_at(which);
 828   if (tag.is_dynamic_constant() ||
 829       tag.is_dynamic_constant_in_error()) {
 830     BasicType bt = basic_type_for_constant_at(which);
 831     // dynamic constant could return an array, treat as object
 832     return constantTag::ofBasicType(is_reference_type(bt) ? T_OBJECT : bt);
 833   }
 834   return tag;
 835 }
 836 
 837 BasicType ConstantPool::basic_type_for_constant_at(int which) {
 838   constantTag tag = tag_at(which);
 839   if (tag.is_dynamic_constant() ||
 840       tag.is_dynamic_constant_in_error()) {
 841     // have to look at the signature for this one
 842     Symbol* constant_type = uncached_signature_ref_at(which);
 843     return FieldType::basic_type(constant_type);
 844   }
 845   return tag.basic_type();
 846 }
 847 
 848 // Called to resolve constants in the constant pool and return an oop.
 849 // Some constant pool entries cache their resolved oop. This is also
 850 // called to create oops from constants to use in arguments for invokedynamic
 851 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 852                                            int index, int cache_index,
 853                                            bool* status_return, TRAPS) {
 854   oop result_oop = NULL;
 855   Handle throw_exception;
 856 
 857   if (cache_index == _possible_index_sentinel) {
 858     // It is possible that this constant is one which is cached in the objects.
 859     // We'll do a linear search.  This should be OK because this usage is rare.
 860     // FIXME: If bootstrap specifiers stress this code, consider putting in
 861     // a reverse index.  Binary search over a short array should do it.
 862     assert(index > 0, "valid index");
 863     cache_index = this_cp->cp_to_object_index(index);


 933 
 934       // The initial step in resolving an unresolved symbolic reference to a
 935       // dynamically-computed constant is to resolve the symbolic reference to a
 936       // method handle which will be the bootstrap method for the dynamically-computed
 937       // constant. If resolution of the java.lang.invoke.MethodHandle for the bootstrap
 938       // method fails, then a MethodHandleInError is stored at the corresponding
 939       // bootstrap method's CP index for the CONSTANT_MethodHandle_info. No need to
 940       // set a DynamicConstantInError here since any subsequent use of this
 941       // bootstrap method will encounter the resolution of MethodHandleInError.
 942       // Both the first, (resolution of the BSM and its static arguments), and the second tasks,
 943       // (invocation of the BSM), of JVMS Section 5.4.3.6 occur within invoke_bootstrap_method()
 944       // for the bootstrap_specifier created above.
 945       SystemDictionary::invoke_bootstrap_method(bootstrap_specifier, THREAD);
 946       Exceptions::wrap_dynamic_exception(THREAD);
 947       if (HAS_PENDING_EXCEPTION) {
 948         // Resolution failure of the dynamically-computed constant, save_and_throw_exception
 949         // will check for a LinkageError and store a DynamicConstantInError.
 950         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 951       }
 952       result_oop = bootstrap_specifier.resolved_value()();
 953       BasicType type = FieldType::basic_type(bootstrap_specifier.signature());
 954       if (!is_reference_type(type)) {
 955         // Make sure the primitive value is properly boxed.
 956         // This is a JDK responsibility.
 957         const char* fail = NULL;
 958         if (result_oop == NULL) {
 959           fail = "null result instead of box";
 960         } else if (!is_java_primitive(type)) {
 961           // FIXME: support value types via unboxing
 962           fail = "can only handle references and primitives";
 963         } else if (!java_lang_boxing_object::is_instance(result_oop, type)) {
 964           fail = "primitive is not properly boxed";
 965         }
 966         if (fail != NULL) {
 967           // Since this exception is not a LinkageError, throw exception
 968           // but do not save a DynamicInError resolution result.
 969           // See section 5.4.3 of the VM spec.
 970           THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), fail);
 971         }
 972       }
 973 




  32 #include "classfile/vmSymbols.hpp"
  33 #include "interpreter/bootstrapInfo.hpp"
  34 #include "interpreter/linkResolver.hpp"
  35 #include "memory/allocation.inline.hpp"
  36 #include "memory/heapShared.hpp"
  37 #include "memory/metadataFactory.hpp"
  38 #include "memory/metaspaceClosure.hpp"
  39 #include "memory/metaspaceShared.hpp"
  40 #include "memory/oopFactory.hpp"
  41 #include "memory/resourceArea.hpp"
  42 #include "memory/universe.hpp"
  43 #include "oops/array.hpp"
  44 #include "oops/constantPool.inline.hpp"
  45 #include "oops/cpCache.inline.hpp"
  46 #include "oops/instanceKlass.hpp"
  47 #include "oops/objArrayKlass.hpp"
  48 #include "oops/objArrayOop.inline.hpp"
  49 #include "oops/oop.inline.hpp"
  50 #include "oops/typeArrayOop.inline.hpp"
  51 #include "runtime/atomic.hpp"

  52 #include "runtime/handles.inline.hpp"
  53 #include "runtime/init.hpp"
  54 #include "runtime/javaCalls.hpp"
  55 #include "runtime/signature.hpp"
  56 #include "runtime/thread.inline.hpp"
  57 #include "runtime/vframe.inline.hpp"
  58 #include "utilities/copy.hpp"
  59 
  60 ConstantPool* ConstantPool::allocate(ClassLoaderData* loader_data, int length, TRAPS) {
  61   Array<u1>* tags = MetadataFactory::new_array<u1>(loader_data, length, 0, CHECK_NULL);
  62   int size = ConstantPool::size(length);
  63   return new (loader_data, size, MetaspaceObj::ConstantPoolType, THREAD) ConstantPool(tags);
  64 }
  65 
  66 #ifdef ASSERT
  67 
  68 // MetaspaceObj allocation invariant is calloc equivalent memory
  69 // simple verification of this here (JVM_CONSTANT_Invalid == 0 )
  70 static bool tag_array_is_zero_initialized(Array<u1>* tags) {
  71   assert(tags != NULL, "invariant");


 710 
 711 Symbol* ConstantPool::klass_name_at(int which) const {
 712   return symbol_at(klass_slot_at(which).name_index());
 713 }
 714 
 715 Symbol* ConstantPool::klass_ref_at_noresolve(int which) {
 716   jint ref_index = klass_ref_index_at(which);
 717   return klass_at_noresolve(ref_index);
 718 }
 719 
 720 Symbol* ConstantPool::uncached_klass_ref_at_noresolve(int which) {
 721   jint ref_index = uncached_klass_ref_index_at(which);
 722   return klass_at_noresolve(ref_index);
 723 }
 724 
 725 char* ConstantPool::string_at_noresolve(int which) {
 726   return unresolved_string_at(which)->as_C_string();
 727 }
 728 
 729 BasicType ConstantPool::basic_type_for_signature_at(int which) const {
 730   return Signature::basic_type(symbol_at(which));
 731 }
 732 
 733 
 734 void ConstantPool::resolve_string_constants_impl(const constantPoolHandle& this_cp, TRAPS) {
 735   for (int index = 1; index < this_cp->length(); index++) { // Index 0 is unused
 736     if (this_cp->tag_at(index).is_string()) {
 737       this_cp->string_at(index, CHECK);
 738     }
 739   }
 740 }
 741 
 742 Symbol* ConstantPool::exception_message(const constantPoolHandle& this_cp, int which, constantTag tag, oop pending_exception) {
 743   // Dig out the detailed message to reuse if possible
 744   Symbol* message = java_lang_Throwable::detail_message(pending_exception);
 745   if (message != NULL) {
 746     return message;
 747   }
 748 
 749   // Return specific message for the tag
 750   switch (tag.value()) {


 822   }
 823 }
 824 
 825 constantTag ConstantPool::constant_tag_at(int which) {
 826   constantTag tag = tag_at(which);
 827   if (tag.is_dynamic_constant() ||
 828       tag.is_dynamic_constant_in_error()) {
 829     BasicType bt = basic_type_for_constant_at(which);
 830     // dynamic constant could return an array, treat as object
 831     return constantTag::ofBasicType(is_reference_type(bt) ? T_OBJECT : bt);
 832   }
 833   return tag;
 834 }
 835 
 836 BasicType ConstantPool::basic_type_for_constant_at(int which) {
 837   constantTag tag = tag_at(which);
 838   if (tag.is_dynamic_constant() ||
 839       tag.is_dynamic_constant_in_error()) {
 840     // have to look at the signature for this one
 841     Symbol* constant_type = uncached_signature_ref_at(which);
 842     return Signature::basic_type(constant_type);
 843   }
 844   return tag.basic_type();
 845 }
 846 
 847 // Called to resolve constants in the constant pool and return an oop.
 848 // Some constant pool entries cache their resolved oop. This is also
 849 // called to create oops from constants to use in arguments for invokedynamic
 850 oop ConstantPool::resolve_constant_at_impl(const constantPoolHandle& this_cp,
 851                                            int index, int cache_index,
 852                                            bool* status_return, TRAPS) {
 853   oop result_oop = NULL;
 854   Handle throw_exception;
 855 
 856   if (cache_index == _possible_index_sentinel) {
 857     // It is possible that this constant is one which is cached in the objects.
 858     // We'll do a linear search.  This should be OK because this usage is rare.
 859     // FIXME: If bootstrap specifiers stress this code, consider putting in
 860     // a reverse index.  Binary search over a short array should do it.
 861     assert(index > 0, "valid index");
 862     cache_index = this_cp->cp_to_object_index(index);


 932 
 933       // The initial step in resolving an unresolved symbolic reference to a
 934       // dynamically-computed constant is to resolve the symbolic reference to a
 935       // method handle which will be the bootstrap method for the dynamically-computed
 936       // constant. If resolution of the java.lang.invoke.MethodHandle for the bootstrap
 937       // method fails, then a MethodHandleInError is stored at the corresponding
 938       // bootstrap method's CP index for the CONSTANT_MethodHandle_info. No need to
 939       // set a DynamicConstantInError here since any subsequent use of this
 940       // bootstrap method will encounter the resolution of MethodHandleInError.
 941       // Both the first, (resolution of the BSM and its static arguments), and the second tasks,
 942       // (invocation of the BSM), of JVMS Section 5.4.3.6 occur within invoke_bootstrap_method()
 943       // for the bootstrap_specifier created above.
 944       SystemDictionary::invoke_bootstrap_method(bootstrap_specifier, THREAD);
 945       Exceptions::wrap_dynamic_exception(THREAD);
 946       if (HAS_PENDING_EXCEPTION) {
 947         // Resolution failure of the dynamically-computed constant, save_and_throw_exception
 948         // will check for a LinkageError and store a DynamicConstantInError.
 949         save_and_throw_exception(this_cp, index, tag, CHECK_NULL);
 950       }
 951       result_oop = bootstrap_specifier.resolved_value()();
 952       BasicType type = Signature::basic_type(bootstrap_specifier.signature());
 953       if (!is_reference_type(type)) {
 954         // Make sure the primitive value is properly boxed.
 955         // This is a JDK responsibility.
 956         const char* fail = NULL;
 957         if (result_oop == NULL) {
 958           fail = "null result instead of box";
 959         } else if (!is_java_primitive(type)) {
 960           // FIXME: support value types via unboxing
 961           fail = "can only handle references and primitives";
 962         } else if (!java_lang_boxing_object::is_instance(result_oop, type)) {
 963           fail = "primitive is not properly boxed";
 964         }
 965         if (fail != NULL) {
 966           // Since this exception is not a LinkageError, throw exception
 967           // but do not save a DynamicInError resolution result.
 968           // See section 5.4.3 of the VM spec.
 969           THROW_MSG_NULL(vmSymbols::java_lang_InternalError(), fail);
 970         }
 971       }
 972 


< prev index next >