< prev index next >

src/hotspot/share/classfile/classFileParser.hpp

Print this page




  28 #include "memory/referenceType.hpp"
  29 #include "oops/annotations.hpp"
  30 #include "oops/constantPool.hpp"
  31 #include "oops/instanceKlass.hpp"
  32 #include "oops/typeArrayOop.hpp"
  33 #include "utilities/accessFlags.hpp"
  34 
  35 class Annotations;
  36 template <typename T>
  37 class Array;
  38 class ClassFileStream;
  39 class ClassLoaderData;
  40 class CompressedLineNumberWriteStream;
  41 class ConstMethod;
  42 class FieldInfo;
  43 template <typename T>
  44 class GrowableArray;
  45 class InstanceKlass;
  46 class Symbol;
  47 class TempNewSymbol;


















































































  48 
  49 // Parser for for .class files
  50 //
  51 // The bytes describing the class file structure is read from a Stream object
  52 
  53 class ClassFileParser {



  54 
  55  class ClassAnnotationCollector;




  56  class FieldAllocationCount;
  57  class FieldAnnotationCollector;
  58  class FieldLayoutInfo;
  59  class OopMapBlocksBuilder;
  60 
  61  public:
  62   // The ClassFileParser has an associated "publicity" level
  63   // It is used to control which subsystems (if any)
  64   // will observe the parsing (logging, events, tracing).
  65   // Default level is "BROADCAST", which is equivalent to
  66   // a "public" parsing attempt.
  67   //
  68   // "INTERNAL" level should be entirely private to the
  69   // caller - this allows for internal reuse of ClassFileParser
  70   //
  71   enum Publicity {
  72     INTERNAL,
  73     BROADCAST
  74   };
  75 
  76   enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
  77 
  78  private:
  79   // Potentially unaligned pointer to various 16-bit entries in the class file


 108   Array<AnnotationArray*>* _fields_annotations;
 109   Array<AnnotationArray*>* _fields_type_annotations;
 110   InstanceKlass* _klass;  // InstanceKlass* once created.
 111   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
 112 
 113   ClassAnnotationCollector* _parsed_annotations;
 114   FieldAllocationCount* _fac;
 115   FieldLayoutInfo* _field_info;
 116   const intArray* _method_ordering;
 117   GrowableArray<Method*>* _all_mirandas;
 118 
 119   enum { fixed_buffer_size = 128 };
 120   u_char _linenumbertable_buffer[fixed_buffer_size];
 121 
 122   // Size of Java vtable (in words)
 123   int _vtable_size;
 124   int _itable_size;
 125 
 126   int _num_miranda_methods;
 127 




 128   ReferenceType _rt;
 129   Handle _protection_domain;
 130   AccessFlags _access_flags;
 131 
 132   // for tracing and notifications
 133   Publicity _pub_level;
 134 
 135   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
 136   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
 137   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
 138   // immediately when these are seen because a NCDFE must be thrown if the class's
 139   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
 140   // at yet.  So, the bad constant pool item is cached here.  A value of zero
 141   // means that no constant pool item 19 or 20 was found.
 142   short _bad_constant_seen;
 143 
 144   // class attributes parsed before the instance klass is created:
 145   bool _synthetic_flag;
 146   int _sde_length;
 147   const char* _sde_buffer;




  28 #include "memory/referenceType.hpp"
  29 #include "oops/annotations.hpp"
  30 #include "oops/constantPool.hpp"
  31 #include "oops/instanceKlass.hpp"
  32 #include "oops/typeArrayOop.hpp"
  33 #include "utilities/accessFlags.hpp"
  34 
  35 class Annotations;
  36 template <typename T>
  37 class Array;
  38 class ClassFileStream;
  39 class ClassLoaderData;
  40 class CompressedLineNumberWriteStream;
  41 class ConstMethod;
  42 class FieldInfo;
  43 template <typename T>
  44 class GrowableArray;
  45 class InstanceKlass;
  46 class Symbol;
  47 class TempNewSymbol;
  48 class FieldLayoutBuilder;
  49 
  50 
  51 class AnnotationCollector : public ResourceObj{
  52 public:
  53   enum Location { _in_field, _in_method, _in_class };
  54   enum ID {
  55     _unknown = 0,
  56     _method_CallerSensitive,
  57     _method_ForceInline,
  58     _method_DontInline,
  59     _method_InjectedProfile,
  60     _method_LambdaForm_Compiled,
  61     _method_Hidden,
  62     _method_HotSpotIntrinsicCandidate,
  63     _jdk_internal_vm_annotation_Contended,
  64     _field_Stable,
  65     _jdk_internal_vm_annotation_ReservedStackAccess,
  66     _annotation_LIMIT
  67   };
  68   const Location _location;
  69   int _annotations_present;
  70   u2 _contended_group;
  71 
  72   AnnotationCollector(Location location)
  73     : _location(location), _annotations_present(0)
  74   {
  75     assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, "");
  76   }
  77   // If this annotation name has an ID, report it (or _none).
  78   ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name);
  79   // Set the annotation name:
  80   void set_annotation(ID id) {
  81     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
  82     _annotations_present |= nth_bit((int)id);
  83   }
  84 
  85   void remove_annotation(ID id) {
  86     assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob");
  87     _annotations_present &= ~nth_bit((int)id);
  88   }
  89 
  90   // Report if the annotation is present.
  91   bool has_any_annotations() const { return _annotations_present != 0; }
  92   bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; }
  93 
  94   void set_contended_group(u2 group) { _contended_group = group; }
  95   u2 contended_group() const { return _contended_group; }
  96 
  97   bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); }
  98 
  99   void set_stable(bool stable) { set_annotation(_field_Stable); }
 100   bool is_stable() const { return has_annotation(_field_Stable); }
 101 };
 102 
 103 // Utility to collect and compact oop maps during layout
 104 class OopMapBlocksBuilder : public ResourceObj {
 105 public:
 106   OopMapBlock*  nonstatic_oop_maps;
 107   unsigned int  nonstatic_oop_map_count;
 108   unsigned int  max_nonstatic_oop_maps;
 109 
 110  public:
 111   OopMapBlocksBuilder(unsigned int  max_blocks, TRAPS);
 112   OopMapBlock* last_oop_map() const;
 113   void initialize_inherited_blocks(OopMapBlock* blocks, unsigned int nof_blocks);
 114   void add(int offset, int count);
 115   void copy(OopMapBlock* dst);
 116   void compact(TRAPS);
 117   void print_on(outputStream* st) const;
 118   void print_value_on(outputStream* st) const;
 119 };
 120 
 121 // Values needed for oopmap and InstanceKlass creation
 122 class FieldLayoutInfo : public ResourceObj {
 123  public:
 124   OopMapBlocksBuilder* oop_map_blocks;
 125   int           instance_size;
 126   int           nonstatic_field_size;
 127   int           static_field_size;
 128   bool          has_nonstatic_fields;
 129 };
 130 
 131 // Parser for for .class files
 132 //
 133 // The bytes describing the class file structure is read from a Stream object
 134 
 135 class ClassFileParser {
 136  friend class FieldLayoutBuilder;
 137  friend class FieldLayout;
 138 
 139 
 140  class ClassAnnotationCollector : public AnnotationCollector {
 141  public:
 142    ClassAnnotationCollector() : AnnotationCollector(_in_class) { }
 143    void apply_to(InstanceKlass* ik);
 144  };
 145  class FieldAllocationCount;
 146  class FieldAnnotationCollector;


 147 
 148  public:
 149   // The ClassFileParser has an associated "publicity" level
 150   // It is used to control which subsystems (if any)
 151   // will observe the parsing (logging, events, tracing).
 152   // Default level is "BROADCAST", which is equivalent to
 153   // a "public" parsing attempt.
 154   //
 155   // "INTERNAL" level should be entirely private to the
 156   // caller - this allows for internal reuse of ClassFileParser
 157   //
 158   enum Publicity {
 159     INTERNAL,
 160     BROADCAST
 161   };
 162 
 163   enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
 164 
 165  private:
 166   // Potentially unaligned pointer to various 16-bit entries in the class file


 195   Array<AnnotationArray*>* _fields_annotations;
 196   Array<AnnotationArray*>* _fields_type_annotations;
 197   InstanceKlass* _klass;  // InstanceKlass* once created.
 198   InstanceKlass* _klass_to_deallocate; // an InstanceKlass* to be destroyed
 199 
 200   ClassAnnotationCollector* _parsed_annotations;
 201   FieldAllocationCount* _fac;
 202   FieldLayoutInfo* _field_info;
 203   const intArray* _method_ordering;
 204   GrowableArray<Method*>* _all_mirandas;
 205 
 206   enum { fixed_buffer_size = 128 };
 207   u_char _linenumbertable_buffer[fixed_buffer_size];
 208 
 209   // Size of Java vtable (in words)
 210   int _vtable_size;
 211   int _itable_size;
 212 
 213   int _num_miranda_methods;
 214 
 215   int _alignment;
 216   int _first_field_offset;
 217   int _exact_size_in_bytes;
 218 
 219   ReferenceType _rt;
 220   Handle _protection_domain;
 221   AccessFlags _access_flags;
 222 
 223   // for tracing and notifications
 224   Publicity _pub_level;
 225 
 226   // Used to keep track of whether a constant pool item 19 or 20 is found.  These
 227   // correspond to CONSTANT_Module and CONSTANT_Package tags and are not allowed
 228   // in regular class files.  For class file version >= 53, a CFE cannot be thrown
 229   // immediately when these are seen because a NCDFE must be thrown if the class's
 230   // access_flags have ACC_MODULE set.  But, the access_flags haven't been looked
 231   // at yet.  So, the bad constant pool item is cached here.  A value of zero
 232   // means that no constant pool item 19 or 20 was found.
 233   short _bad_constant_seen;
 234 
 235   // class attributes parsed before the instance klass is created:
 236   bool _synthetic_flag;
 237   int _sde_length;
 238   const char* _sde_buffer;


< prev index next >