< prev index next >

hotspot/src/share/vm/classfile/classFileParser.cpp

Print this page




1029                              CHECK);
1030     }
1031   }
1032 }
1033 
1034 class AnnotationCollector : public ResourceObj{
1035 public:
1036   enum Location { _in_field, _in_method, _in_class };
1037   enum ID {
1038     _unknown = 0,
1039     _method_CallerSensitive,
1040     _method_ForceInline,
1041     _method_DontInline,
1042     _method_InjectedProfile,
1043     _method_LambdaForm_Compiled,
1044     _method_LambdaForm_Hidden,
1045     _method_HotSpotIntrinsicCandidate,
1046     _jdk_internal_vm_annotation_Contended,
1047     _field_Stable,
1048     _jdk_internal_vm_annotation_ReservedStackAccess,
1049     _jvm_internal_value_ValueCapableClass,
1050     _annotation_LIMIT
1051   };
1052   const Location _location;
1053   int _annotations_present;
1054   u2 _contended_group;
1055 
1056   AnnotationCollector(Location location)
1057     : _location(location), _annotations_present(0)
1058   {
1059     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1060   }
1061   // If this annotation name has an ID, report it (or _none).
1062   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1063   // Set the annotation name:
1064   void set_annotation(ID id) {
1065     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1066     _annotations_present |= nth_bit((int)id);
1067   }
1068 
1069   void remove_annotation(ID id) {
1070     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1071     _annotations_present &= ~nth_bit((int)id);
1072   }
1073 
1074   // Report if the annotation is present.
1075   bool has_any_annotations() const { return _annotations_present != 0; }
1076   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1077 
1078   void set_contended_group(u2 group) { _contended_group = group; }
1079   u2 contended_group() const { return _contended_group; }
1080 
1081   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1082 
1083   void set_stable(bool stable) { set_annotation(_field_Stable); }
1084   bool is_stable() const { return has_annotation(_field_Stable); }
1085 
1086   bool is_value_capable_class() const { return has_annotation(_jvm_internal_value_ValueCapableClass); }
1087 };
1088 
1089 // This class also doubles as a holder for metadata cleanup.
1090 class ClassFileParser::FieldAnnotationCollector : public AnnotationCollector {
1091 private:
1092   ClassLoaderData* _loader_data;
1093   AnnotationArray* _field_annotations;
1094   AnnotationArray* _field_type_annotations;
1095 public:
1096   FieldAnnotationCollector(ClassLoaderData* loader_data) :
1097     AnnotationCollector(_in_field),
1098     _loader_data(loader_data),
1099     _field_annotations(NULL),
1100     _field_type_annotations(NULL) {}
1101   ~FieldAnnotationCollector();
1102   void apply_to(FieldInfo* f);
1103   AnnotationArray* field_annotations()      { return _field_annotations; }
1104   AnnotationArray* field_type_annotations() { return _field_type_annotations; }
1105 
1106   void set_field_annotations(AnnotationArray* a)      { _field_annotations = a; }


2117     }
2118     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2119       if (_location != _in_field)   break;  // only allow for fields
2120       if (!privileged)              break;  // only allow in privileged code
2121       return _field_Stable;
2122     }
2123     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2124       if (_location != _in_field && _location != _in_class) {
2125         break;  // only allow for fields and classes
2126       }
2127       if (!EnableContended || (RestrictContended && !privileged)) {
2128         break;  // honor privileges
2129       }
2130       return _jdk_internal_vm_annotation_Contended;
2131     }
2132     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
2133       if (_location != _in_method)  break;  // only allow for methods
2134       if (RestrictReservedStack && !privileged) break; // honor privileges
2135       return _jdk_internal_vm_annotation_ReservedStackAccess;
2136     }
2137     case vmSymbols::VM_SYMBOL_ENUM_NAME(jvm_internal_value_ValueCapableClass_signature) : {
2138       if (_location != _in_class) {
2139         break;
2140       }
2141       return _jvm_internal_value_ValueCapableClass;
2142     }
2143     default: {
2144       break;
2145     }
2146   }
2147   return AnnotationCollector::_unknown;
2148 }
2149 
2150 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
2151   if (is_contended())
2152     f->set_contended_group(contended_group());
2153   if (is_stable())
2154     f->set_stable(true);
2155 }
2156 
2157 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2158   // If there's an error deallocate metadata for field annotations
2159   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2160   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2161 }




1029                              CHECK);
1030     }
1031   }
1032 }
1033 
1034 class AnnotationCollector : public ResourceObj{
1035 public:
1036   enum Location { _in_field, _in_method, _in_class };
1037   enum ID {
1038     _unknown = 0,
1039     _method_CallerSensitive,
1040     _method_ForceInline,
1041     _method_DontInline,
1042     _method_InjectedProfile,
1043     _method_LambdaForm_Compiled,
1044     _method_LambdaForm_Hidden,
1045     _method_HotSpotIntrinsicCandidate,
1046     _jdk_internal_vm_annotation_Contended,
1047     _field_Stable,
1048     _jdk_internal_vm_annotation_ReservedStackAccess,
1049     _jdk_incubator_mvt_ValueCapableClass,
1050     _annotation_LIMIT
1051   };
1052   const Location _location;
1053   int _annotations_present;
1054   u2 _contended_group;
1055 
1056   AnnotationCollector(Location location)
1057     : _location(location), _annotations_present(0)
1058   {
1059     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
1060   }
1061   // If this annotation name has an ID, report it (or _none).
1062   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
1063   // Set the annotation name:
1064   void set_annotation(ID id) {
1065     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1066     _annotations_present |= nth_bit((int)id);
1067   }
1068 
1069   void remove_annotation(ID id) {
1070     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
1071     _annotations_present &= ~nth_bit((int)id);
1072   }
1073 
1074   // Report if the annotation is present.
1075   bool has_any_annotations() const { return _annotations_present != 0; }
1076   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
1077 
1078   void set_contended_group(u2 group) { _contended_group = group; }
1079   u2 contended_group() const { return _contended_group; }
1080 
1081   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
1082 
1083   void set_stable(bool stable) { set_annotation(_field_Stable); }
1084   bool is_stable() const { return has_annotation(_field_Stable); }
1085 
1086   bool is_value_capable_class() const { return has_annotation(_jdk_incubator_mvt_ValueCapableClass); }
1087 };
1088 
1089 // This class also doubles as a holder for metadata cleanup.
1090 class ClassFileParser::FieldAnnotationCollector : public AnnotationCollector {
1091 private:
1092   ClassLoaderData* _loader_data;
1093   AnnotationArray* _field_annotations;
1094   AnnotationArray* _field_type_annotations;
1095 public:
1096   FieldAnnotationCollector(ClassLoaderData* loader_data) :
1097     AnnotationCollector(_in_field),
1098     _loader_data(loader_data),
1099     _field_annotations(NULL),
1100     _field_type_annotations(NULL) {}
1101   ~FieldAnnotationCollector();
1102   void apply_to(FieldInfo* f);
1103   AnnotationArray* field_annotations()      { return _field_annotations; }
1104   AnnotationArray* field_type_annotations() { return _field_type_annotations; }
1105 
1106   void set_field_annotations(AnnotationArray* a)      { _field_annotations = a; }


2117     }
2118     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): {
2119       if (_location != _in_field)   break;  // only allow for fields
2120       if (!privileged)              break;  // only allow in privileged code
2121       return _field_Stable;
2122     }
2123     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): {
2124       if (_location != _in_field && _location != _in_class) {
2125         break;  // only allow for fields and classes
2126       }
2127       if (!EnableContended || (RestrictContended && !privileged)) {
2128         break;  // honor privileges
2129       }
2130       return _jdk_internal_vm_annotation_Contended;
2131     }
2132     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): {
2133       if (_location != _in_method)  break;  // only allow for methods
2134       if (RestrictReservedStack && !privileged) break; // honor privileges
2135       return _jdk_internal_vm_annotation_ReservedStackAccess;
2136     }
2137     case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_incubator_mvt_ValueCapableClass_signature) : {
2138       if (_location != _in_class) {
2139         break;
2140       }
2141       return _jdk_incubator_mvt_ValueCapableClass;
2142     }
2143     default: {
2144       break;
2145     }
2146   }
2147   return AnnotationCollector::_unknown;
2148 }
2149 
2150 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) {
2151   if (is_contended())
2152     f->set_contended_group(contended_group());
2153   if (is_stable())
2154     f->set_stable(true);
2155 }
2156 
2157 ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() {
2158   // If there's an error deallocate metadata for field annotations
2159   MetadataFactory::free_array<u1>(_loader_data, _field_annotations);
2160   MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations);
2161 }


< prev index next >