< prev index next >

src/hotspot/share/classfile/classFileParser.cpp

Print this page

  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "jvm.h"
  26 #include "aot/aotLoader.hpp"
  27 #include "classfile/classFileParser.hpp"
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/classLoaderData.inline.hpp"
  31 #include "classfile/defaultMethods.hpp"
  32 #include "classfile/dictionary.hpp"
  33 #include "classfile/fieldLayoutBuilder.hpp"
  34 #include "classfile/javaClasses.inline.hpp"
  35 #include "classfile/moduleEntry.hpp"
  36 #include "classfile/packageEntry.hpp"
  37 #include "classfile/symbolTable.hpp"
  38 #include "classfile/systemDictionary.hpp"



  39 #include "classfile/verificationType.hpp"
  40 #include "classfile/verifier.hpp"
  41 #include "classfile/vmSymbols.hpp"
  42 #include "logging/log.hpp"
  43 #include "logging/logStream.hpp"
  44 #include "memory/allocation.hpp"
  45 #include "memory/metadataFactory.hpp"
  46 #include "memory/oopFactory.hpp"
  47 #include "memory/resourceArea.hpp"
  48 #include "memory/universe.hpp"
  49 #include "oops/annotations.hpp"
  50 #include "oops/constantPool.inline.hpp"
  51 #include "oops/fieldStreams.inline.hpp"
  52 #include "oops/instanceKlass.hpp"
  53 #include "oops/instanceMirrorKlass.hpp"
  54 #include "oops/klass.inline.hpp"
  55 #include "oops/klassVtable.hpp"
  56 #include "oops/metadata.hpp"
  57 #include "oops/method.inline.hpp"
  58 #include "oops/oop.inline.hpp"

1062                              constantvalue_index,
1063                              CHECK);
1064     }
1065   }
1066 }
1067 
1068 class AnnotationCollector : public ResourceObj{
1069 public:
1070   enum Location { _in_field, _in_method, _in_class };
1071   enum ID {
1072     _unknown = 0,
1073     _method_CallerSensitive,
1074     _method_ForceInline,
1075     _method_DontInline,
1076     _method_InjectedProfile,
1077     _method_LambdaForm_Compiled,
1078     _method_Hidden,
1079     _method_HotSpotIntrinsicCandidate,
1080     _jdk_internal_vm_annotation_Contended,
1081     _field_Stable,

1082     _jdk_internal_vm_annotation_ReservedStackAccess,
1083     _annotation_LIMIT
1084   };
1085   const Location _location;
1086   int _annotations_present;
1087   u2 _contended_group;
1088 
1089   AnnotationCollector(Location location)
1090     : _location(location), _annotations_present(0)
1091   {
1092     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1093   }
1094   // If this annotation name has an ID, report it (or _none).
1095   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1096   // Set the annotation name:
1097   void set_annotation(ID id) {
1098     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1099     _annotations_present |= nth_bit((int)id);
1100   }
1101 
1102   void remove_annotation(ID id) {
1103     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1104     _annotations_present &= ~nth_bit((int)id);
1105   }
1106 
1107   // Report if the annotation is present.
1108   bool has_any_annotations() const { return _annotations_present != 0; }
1109   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1110 
1111   void set_contended_group(u2 group) { _contended_group = group; }
1112   u2 contended_group() const { return _contended_group; }
1113 
1114   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1115 
1116   void set_stable(bool stable) { set_annotation(_field_Stable); }
1117   bool is_stable() const { return has_annotation(_field_Stable); }





1118 };
1119 
1120 // This class also doubles as a holder for metadata cleanup.
1121 class ClassFileParser::FieldAnnotationCollector : public AnnotationCollector {
1122 private:
1123   ClassLoaderData* _loader_data;
1124   AnnotationArray* _field_annotations;
1125   AnnotationArray* _field_type_annotations;
1126 public:
1127   FieldAnnotationCollector(ClassLoaderData* loader_data) :
1128     AnnotationCollector(_in_field),
1129     _loader_data(loader_data),
1130     _field_annotations(NULL),
1131     _field_type_annotations(NULL) {}
1132   ~FieldAnnotationCollector();
1133   void apply_to(FieldInfo* f);
1134   AnnotationArray* field_annotations()      { return _field_annotations; }
1135   AnnotationArray* field_type_annotations() { return _field_type_annotations; }
1136 
1137   void set_field_annotations(AnnotationArray* a)      { _field_annotations = a; }

1670       }
1671       if (generic_signature_index != 0) {
1672         access_flags.set_field_has_generic_signature();
1673         fa[generic_signature_slot] = generic_signature_index;
1674         generic_signature_slot ++;
1675         num_generic_signature ++;
1676       }
1677     }
1678 
1679     FieldInfo* const field = FieldInfo::from_field_array(fa, n);
1680     field->initialize(access_flags.as_short(),
1681                       name_index,
1682                       signature_index,
1683                       constantvalue_index);
1684     const BasicType type = cp->basic_type_for_signature_at(signature_index);
1685 
1686     // Remember how many oops we encountered and compute allocation type
1687     const FieldAllocationType atype = fac->update(is_static, type);
1688     field->set_allocation_type(atype);
1689 







1690     // After field is initialized with type, we can augment it with aux info
1691     if (parsed_annotations.has_any_annotations()) {
1692       parsed_annotations.apply_to(field);
1693       if (field->is_contended()) {
1694         _has_contended_fields = true;
1695       }
1696     }
1697   }
1698 
1699   int index = length;
1700   if (num_injected != 0) {
1701     for (int n = 0; n < num_injected; n++) {
1702       // Check for duplicates
1703       if (injected[n].may_be_java) {
1704         const Symbol* const name      = injected[n].name();
1705         const Symbol* const signature = injected[n].signature();
1706         bool duplicate = false;
1707         for (int i = 0; i < length; i++) {
1708           const FieldInfo* const f = FieldInfo::from_field_array(fa, i);
1709           if (name      == cp->symbol_at(f->name_index()) &&

2103     }
2104     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2105       if (_location != _in_field)   break;  // only allow for fields
2106       if (!privileged)              break;  // only allow in privileged code
2107       return _field_Stable;
2108     }
2109     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2110       if (_location != _in_field && _location != _in_class) {
2111         break;  // only allow for fields and classes
2112       }
2113       if (!EnableContended || (RestrictContended && !privileged)) {
2114         break;  // honor privileges
2115       }
2116       return _jdk_internal_vm_annotation_Contended;
2117     }
2118     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
2119       if (_location != _in_method)  break;  // only allow for methods
2120       if (RestrictReservedStack && !privileged) break; // honor privileges
2121       return _jdk_internal_vm_annotation_ReservedStackAccess;
2122     }








2123     default: {
2124       break;
2125     }
2126   }
2127   return AnnotationCollector::_unknown;
2128 }
2129 
2130 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
2131   if (is_contended())
2132     f->set_contended_group(contended_group());
2133   if (is_stable())
2134     f->set_stable(true);





2135 }
2136 
2137 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2138   // If there's an error deallocate metadata for field annotations
2139   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2140   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2141 }
2142 
2143 void MethodAnnotationCollector::apply_to(const methodHandle& m) {
2144   if (has_annotation(_method_CallerSensitive))
2145     m->set_caller_sensitive(true);
2146   if (has_annotation(_method_ForceInline))
2147     m->set_force_inline(true);
2148   if (has_annotation(_method_DontInline))
2149     m->set_dont_inline(true);
2150   if (has_annotation(_method_InjectedProfile))
2151     m->set_has_injected_profile(true);
2152   if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none)
2153     m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm);
2154   if (has_annotation(_method_Hidden))

5791 
5792   // Generate any default methods - default methods are public interface methods
5793   // that have a default implementation.  This is new with Java 8.
5794   if (_has_nonstatic_concrete_methods) {
5795     DefaultMethods::generate_default_methods(ik,
5796                                              _all_mirandas,
5797                                              CHECK);
5798   }
5799 
5800   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5801   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5802       !module_entry->has_default_read_edges()) {
5803     if (!module_entry->set_has_default_read_edges()) {
5804       // We won a potential race
5805       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5806     }
5807   }
5808 
5809   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5810 

















5811   if (!is_internal()) {
5812     if (log_is_enabled(Info, class, load)) {
5813       ResourceMark rm;
5814       const char* module_name = (module_entry->name() == NULL) ? UNNAMED_MODULE : module_entry->name()->as_C_string();
5815       ik->print_class_load_logging(_loader_data, module_name, _stream);
5816     }
5817 
5818     if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION &&
5819         ik->major_version() == JVM_CLASSFILE_MAJOR_VERSION &&
5820         log_is_enabled(Info, class, preview)) {
5821       ResourceMark rm;
5822       log_info(class, preview)("Loading class %s that depends on preview features (class file version %d.65535)",
5823                                ik->external_name(), JVM_CLASSFILE_MAJOR_VERSION);
5824     }
5825 
5826     if (log_is_enabled(Debug, class, resolve))  {
5827       ResourceMark rm;
5828       // print out the superclass.
5829       const char * from = ik->external_name();
5830       if (ik->java_super() != NULL) {

  19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  20  * or visit www.oracle.com if you need additional information or have any
  21  * questions.
  22  *
  23  */
  24 #include "precompiled.hpp"
  25 #include "jvm.h"
  26 #include "aot/aotLoader.hpp"
  27 #include "classfile/classFileParser.hpp"
  28 #include "classfile/classFileStream.hpp"
  29 #include "classfile/classLoader.hpp"
  30 #include "classfile/classLoaderData.inline.hpp"
  31 #include "classfile/defaultMethods.hpp"
  32 #include "classfile/dictionary.hpp"
  33 #include "classfile/fieldLayoutBuilder.hpp"
  34 #include "classfile/javaClasses.inline.hpp"
  35 #include "classfile/moduleEntry.hpp"
  36 #include "classfile/packageEntry.hpp"
  37 #include "classfile/symbolTable.hpp"
  38 #include "classfile/systemDictionary.hpp"
  39 #if INCLUDE_TSAN
  40 #include "classfile/tsanIgnoreList.hpp"
  41 #endif // INCLUDE_TSAN
  42 #include "classfile/verificationType.hpp"
  43 #include "classfile/verifier.hpp"
  44 #include "classfile/vmSymbols.hpp"
  45 #include "logging/log.hpp"
  46 #include "logging/logStream.hpp"
  47 #include "memory/allocation.hpp"
  48 #include "memory/metadataFactory.hpp"
  49 #include "memory/oopFactory.hpp"
  50 #include "memory/resourceArea.hpp"
  51 #include "memory/universe.hpp"
  52 #include "oops/annotations.hpp"
  53 #include "oops/constantPool.inline.hpp"
  54 #include "oops/fieldStreams.inline.hpp"
  55 #include "oops/instanceKlass.hpp"
  56 #include "oops/instanceMirrorKlass.hpp"
  57 #include "oops/klass.inline.hpp"
  58 #include "oops/klassVtable.hpp"
  59 #include "oops/metadata.hpp"
  60 #include "oops/method.inline.hpp"
  61 #include "oops/oop.inline.hpp"

1065                              constantvalue_index,
1066                              CHECK);
1067     }
1068   }
1069 }
1070 
1071 class AnnotationCollector : public ResourceObj{
1072 public:
1073   enum Location { _in_field, _in_method, _in_class };
1074   enum ID {
1075     _unknown = 0,
1076     _method_CallerSensitive,
1077     _method_ForceInline,
1078     _method_DontInline,
1079     _method_InjectedProfile,
1080     _method_LambdaForm_Compiled,
1081     _method_Hidden,
1082     _method_HotSpotIntrinsicCandidate,
1083     _jdk_internal_vm_annotation_Contended,
1084     _field_Stable,
1085     _field_TsanIgnore,
1086     _jdk_internal_vm_annotation_ReservedStackAccess,
1087     _annotation_LIMIT
1088   };
1089   const Location _location;
1090   int _annotations_present;
1091   u2 _contended_group;
1092 
1093   AnnotationCollector(Location location)
1094     : _location(location), _annotations_present(0)
1095   {
1096     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1097   }
1098   // If this annotation name has an ID, report it (or _none).
1099   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1100   // Set the annotation name:
1101   void set_annotation(ID id) {
1102     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1103     _annotations_present |= nth_bit((int)id);
1104   }
1105 
1106   void remove_annotation(ID id) {
1107     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1108     _annotations_present &= ~nth_bit((int)id);
1109   }
1110 
1111   // Report if the annotation is present.
1112   bool has_any_annotations() const { return _annotations_present != 0; }
1113   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1114 
1115   void set_contended_group(u2 group) { _contended_group = group; }
1116   u2 contended_group() const { return _contended_group; }
1117 
1118   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1119 
1120   void set_stable(bool stable) { set_annotation(_field_Stable); }
1121   bool is_stable() const { return has_annotation(_field_Stable); }
1122 
1123 #if INCLUDE_TSAN
1124   void set_tsan_ignore(bool tsan_ignore) { set_annotation(_field_TsanIgnore); }
1125   bool is_tsan_ignore() const { return has_annotation(_field_TsanIgnore); }
1126 #endif  // INCLUDE_TSAN
1127 };
1128 
1129 // This class also doubles as a holder for metadata cleanup.
1130 class ClassFileParser::FieldAnnotationCollector : public AnnotationCollector {
1131 private:
1132   ClassLoaderData* _loader_data;
1133   AnnotationArray* _field_annotations;
1134   AnnotationArray* _field_type_annotations;
1135 public:
1136   FieldAnnotationCollector(ClassLoaderData* loader_data) :
1137     AnnotationCollector(_in_field),
1138     _loader_data(loader_data),
1139     _field_annotations(NULL),
1140     _field_type_annotations(NULL) {}
1141   ~FieldAnnotationCollector();
1142   void apply_to(FieldInfo* f);
1143   AnnotationArray* field_annotations()      { return _field_annotations; }
1144   AnnotationArray* field_type_annotations() { return _field_type_annotations; }
1145 
1146   void set_field_annotations(AnnotationArray* a)      { _field_annotations = a; }

1679       }
1680       if (generic_signature_index != 0) {
1681         access_flags.set_field_has_generic_signature();
1682         fa[generic_signature_slot] = generic_signature_index;
1683         generic_signature_slot ++;
1684         num_generic_signature ++;
1685       }
1686     }
1687 
1688     FieldInfo* const field = FieldInfo::from_field_array(fa, n);
1689     field->initialize(access_flags.as_short(),
1690                       name_index,
1691                       signature_index,
1692                       constantvalue_index);
1693     const BasicType type = cp->basic_type_for_signature_at(signature_index);
1694 
1695     // Remember how many oops we encountered and compute allocation type
1696     const FieldAllocationType atype = fac->update(is_static, type);
1697     field->set_allocation_type(atype);
1698 
1699     TSAN_RUNTIME_ONLY(
1700       if (ThreadSanitizerIgnoreFile != NULL &&
1701           TsanIgnoreList::match(_class_name, name, type)) {
1702         parsed_annotations.set_tsan_ignore(true);
1703       }
1704     );
1705 
1706     // After field is initialized with type, we can augment it with aux info
1707     if (parsed_annotations.has_any_annotations()) {
1708       parsed_annotations.apply_to(field);
1709       if (field->is_contended()) {
1710         _has_contended_fields = true;
1711       }
1712     }
1713   }
1714 
1715   int index = length;
1716   if (num_injected != 0) {
1717     for (int n = 0; n < num_injected; n++) {
1718       // Check for duplicates
1719       if (injected[n].may_be_java) {
1720         const Symbol* const name      = injected[n].name();
1721         const Symbol* const signature = injected[n].signature();
1722         bool duplicate = false;
1723         for (int i = 0; i < length; i++) {
1724           const FieldInfo* const f = FieldInfo::from_field_array(fa, i);
1725           if (name      == cp->symbol_at(f->name_index()) &&

2119     }
2120     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2121       if (_location != _in_field)   break;  // only allow for fields
2122       if (!privileged)              break;  // only allow in privileged code
2123       return _field_Stable;
2124     }
2125     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2126       if (_location != _in_field && _location != _in_class) {
2127         break;  // only allow for fields and classes
2128       }
2129       if (!EnableContended || (RestrictContended && !privileged)) {
2130         break;  // honor privileges
2131       }
2132       return _jdk_internal_vm_annotation_Contended;
2133     }
2134     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
2135       if (_location != _in_method)  break;  // only allow for methods
2136       if (RestrictReservedStack && !privileged) break; // honor privileges
2137       return _jdk_internal_vm_annotation_ReservedStackAccess;
2138     }
2139 #if INCLUDE_TSAN
2140     case vmSymbols::VM_SYMBOL_ENUM_NAME(java_util_concurrent_annotation_LazyInit): {
2141       if (_location != _in_field) {
2142         break;  // only allow for fields
2143       }
2144       return _field_TsanIgnore;
2145     }
2146 #endif  // INCLUDE_TSAN
2147     default: {
2148       break;
2149     }
2150   }
2151   return AnnotationCollector::_unknown;
2152 }
2153 
2154 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
2155   if (is_contended())
2156     f->set_contended_group(contended_group());
2157   if (is_stable())
2158     f->set_stable(true);
2159   TSAN_RUNTIME_ONLY(
2160     if (is_tsan_ignore())
2161       f->set_tsan_ignore(true);
2162   );
2163 
2164 }
2165 
2166 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2167   // If there's an error deallocate metadata for field annotations
2168   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2169   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2170 }
2171 
2172 void MethodAnnotationCollector::apply_to(const methodHandle& m) {
2173   if (has_annotation(_method_CallerSensitive))
2174     m->set_caller_sensitive(true);
2175   if (has_annotation(_method_ForceInline))
2176     m->set_force_inline(true);
2177   if (has_annotation(_method_DontInline))
2178     m->set_dont_inline(true);
2179   if (has_annotation(_method_InjectedProfile))
2180     m->set_has_injected_profile(true);
2181   if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none)
2182     m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm);
2183   if (has_annotation(_method_Hidden))

5820 
5821   // Generate any default methods - default methods are public interface methods
5822   // that have a default implementation.  This is new with Java 8.
5823   if (_has_nonstatic_concrete_methods) {
5824     DefaultMethods::generate_default_methods(ik,
5825                                              _all_mirandas,
5826                                              CHECK);
5827   }
5828 
5829   // Add read edges to the unnamed modules of the bootstrap and app class loaders.
5830   if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() &&
5831       !module_entry->has_default_read_edges()) {
5832     if (!module_entry->set_has_default_read_edges()) {
5833       // We won a potential race
5834       JvmtiExport::add_default_read_edges(module_handle, THREAD);
5835     }
5836   }
5837 
5838   ClassLoadingService::notify_class_loaded(ik, false /* not shared class */);
5839 
5840 #if INCLUDE_TSAN
5841   if (ThreadSanitizer && !ik->is_interface()) {
5842     ik->ensure_space_for_methodids(0);
5843     int num_methods = ik->methods()->length();
5844     for (int index = 0; index < num_methods; index++) {
5845       // Make sure each method has a jmethodID.
5846       // This allows us to avoid allocating jmethodIDs during program execution.
5847       jmethodID id = ik->methods()->at(index)->jmethod_id();
5848 #ifdef ASSERT
5849       u8 id_u8 = reinterpret_cast<u8>(id);
5850       assert((id_u8 & right_n_bits(3)) == 0, "jmethodID is not aligned");
5851       assert((id_u8 & left_n_bits(17)) == 0, "jmethodID is not aligned");
5852 #endif
5853     }
5854   }
5855 #endif // INCLUDE_TSAN
5856 
5857   if (!is_internal()) {
5858     if (log_is_enabled(Info, class, load)) {
5859       ResourceMark rm;
5860       const char* module_name = (module_entry->name() == NULL) ? UNNAMED_MODULE : module_entry->name()->as_C_string();
5861       ik->print_class_load_logging(_loader_data, module_name, _stream);
5862     }
5863 
5864     if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION &&
5865         ik->major_version() == JVM_CLASSFILE_MAJOR_VERSION &&
5866         log_is_enabled(Info, class, preview)) {
5867       ResourceMark rm;
5868       log_info(class, preview)("Loading class %s that depends on preview features (class file version %d.65535)",
5869                                ik->external_name(), JVM_CLASSFILE_MAJOR_VERSION);
5870     }
5871 
5872     if (log_is_enabled(Debug, class, resolve))  {
5873       ResourceMark rm;
5874       // print out the superclass.
5875       const char * from = ik->external_name();
5876       if (ik->java_super() != NULL) {
< prev index next >