Mercurial > hg > graal-compiler
comparison src/share/vm/classfile/classFileParser.hpp @ 6222:6d8f36bcef55
6711908: JVM needs direct access to some annotations
Summary: Add annotation extraction code to class file parser.
Reviewed-by: twisti, jrose, kvn
Contributed-by: michael.haupt@oracle.com
author | jrose |
---|---|
date | Thu, 12 Jul 2012 00:39:53 -0700 |
parents | 749b1464aa81 |
children | 9c9fb30d2b3b |
comparison
equal
deleted
inserted
replaced
6207:ae9241bbce4a | 6222:6d8f36bcef55 |
---|---|
29 #include "memory/resourceArea.hpp" | 29 #include "memory/resourceArea.hpp" |
30 #include "oops/oop.inline.hpp" | 30 #include "oops/oop.inline.hpp" |
31 #include "oops/typeArrayOop.hpp" | 31 #include "oops/typeArrayOop.hpp" |
32 #include "runtime/handles.inline.hpp" | 32 #include "runtime/handles.inline.hpp" |
33 #include "utilities/accessFlags.hpp" | 33 #include "utilities/accessFlags.hpp" |
34 | 34 #include "classfile/symbolTable.hpp" |
35 class TempNewSymbol; | 35 |
36 class FieldAllocationCount; | 36 class FieldAllocationCount; |
37 | 37 |
38 | 38 |
39 // Parser for for .class files | 39 // Parser for for .class files |
40 // | 40 // |
48 u2 _minor_version; | 48 u2 _minor_version; |
49 Symbol* _class_name; | 49 Symbol* _class_name; |
50 KlassHandle _host_klass; | 50 KlassHandle _host_klass; |
51 GrowableArray<Handle>* _cp_patches; // overrides for CP entries | 51 GrowableArray<Handle>* _cp_patches; // overrides for CP entries |
52 | 52 |
53 // precomputed flags | |
53 bool _has_finalizer; | 54 bool _has_finalizer; |
54 bool _has_empty_finalizer; | 55 bool _has_empty_finalizer; |
55 bool _has_vanilla_constructor; | 56 bool _has_vanilla_constructor; |
56 | 57 int _max_bootstrap_specifier_index; // detects BSS values |
57 int _max_bootstrap_specifier_index; | 58 |
59 // class attributes parsed before the instance klass is created: | |
60 bool _synthetic_flag; | |
61 Symbol* _sourcefile; | |
62 Symbol* _generic_signature; | |
63 TempNewSymbol _sde_symbol; | |
64 typeArrayHandle _inner_classes; | |
65 typeArrayHandle _annotations; | |
66 | |
67 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; } | |
68 void set_class_sourcefile(Symbol* x) { _sourcefile = x; } | |
69 void set_class_generic_signature(Symbol* x) { _generic_signature = x; } | |
70 void set_class_sde_symbol(Symbol* x) { _sde_symbol = x; } | |
71 void set_class_inner_classes(typeArrayHandle x) { _inner_classes = x; } | |
72 void set_class_annotations(typeArrayHandle x) { _annotations = x; } | |
73 void init_parsed_class_attributes() { | |
74 _synthetic_flag = false; | |
75 _sourcefile = NULL; | |
76 _generic_signature = NULL; | |
77 // initialize the other flags too: | |
78 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; | |
79 _max_bootstrap_specifier_index = -1; | |
80 } | |
81 void apply_parsed_class_attributes(instanceKlassHandle k); // update k | |
82 | |
83 class AnnotationCollector { | |
84 public: | |
85 enum Location { _in_field, _in_method, _in_class }; | |
86 enum ID { | |
87 _unknown = 0, | |
88 _method_ForceInline, | |
89 _annotation_LIMIT | |
90 }; | |
91 const Location _location; | |
92 int _annotations_present; | |
93 AnnotationCollector(Location location) | |
94 : _location(location), _annotations_present(0) | |
95 { | |
96 assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, ""); | |
97 } | |
98 // If this annotation name has an ID, report it (or _none). | |
99 ID annotation_index(Symbol* name); | |
100 // Set the annotation name: | |
101 void set_annotation(ID id) { | |
102 assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); | |
103 _annotations_present |= nth_bit((int)id); | |
104 } | |
105 // Report if the annotation is present. | |
106 bool has_any_annotations() { return _annotations_present != 0; } | |
107 bool has_annotation(ID id) { return (nth_bit((int)id) & _annotations_present) != 0; } | |
108 }; | |
109 class FieldAnnotationCollector: public AnnotationCollector { | |
110 public: | |
111 FieldAnnotationCollector() : AnnotationCollector(_in_field) { } | |
112 void apply_to(FieldInfo* f); | |
113 }; | |
114 class MethodAnnotationCollector: public AnnotationCollector { | |
115 public: | |
116 MethodAnnotationCollector() : AnnotationCollector(_in_method) { } | |
117 void apply_to(methodHandle m); | |
118 }; | |
119 class ClassAnnotationCollector: public AnnotationCollector { | |
120 public: | |
121 ClassAnnotationCollector() : AnnotationCollector(_in_class) { } | |
122 void apply_to(instanceKlassHandle k); | |
123 }; | |
58 | 124 |
59 enum { fixed_buffer_size = 128 }; | 125 enum { fixed_buffer_size = 128 }; |
60 u_char linenumbertable_buffer[fixed_buffer_size]; | 126 u_char linenumbertable_buffer[fixed_buffer_size]; |
61 | 127 |
62 ClassFileStream* _stream; // Actual input stream | 128 ClassFileStream* _stream; // Actual input stream |
85 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count, | 151 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count, |
86 bool is_static, u2 signature_index, | 152 bool is_static, u2 signature_index, |
87 u2* constantvalue_index_addr, | 153 u2* constantvalue_index_addr, |
88 bool* is_synthetic_addr, | 154 bool* is_synthetic_addr, |
89 u2* generic_signature_index_addr, | 155 u2* generic_signature_index_addr, |
90 typeArrayHandle* field_annotations, TRAPS); | 156 typeArrayHandle* field_annotations, |
157 FieldAnnotationCollector* parsed_annotations, | |
158 TRAPS); | |
91 typeArrayHandle parse_fields(Symbol* class_name, | 159 typeArrayHandle parse_fields(Symbol* class_name, |
92 constantPoolHandle cp, bool is_interface, | 160 constantPoolHandle cp, bool is_interface, |
93 FieldAllocationCount *fac, | 161 FieldAllocationCount *fac, |
94 objArrayHandle* fields_annotations, | 162 objArrayHandle* fields_annotations, |
95 u2* java_fields_count_ptr, TRAPS); | 163 u2* java_fields_count_ptr, TRAPS); |
126 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, | 194 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, |
127 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS); | 195 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS); |
128 typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS); | 196 typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS); |
129 | 197 |
130 // Classfile attribute parsing | 198 // Classfile attribute parsing |
131 void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | 199 void parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS); |
132 void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, | 200 void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, int length, TRAPS); |
133 instanceKlassHandle k, int length, TRAPS); | |
134 u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, | 201 u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, |
135 bool parsed_enclosingmethod_attribute, | 202 bool parsed_enclosingmethod_attribute, |
136 u2 enclosing_method_class_index, | 203 u2 enclosing_method_class_index, |
137 u2 enclosing_method_method_index, | 204 u2 enclosing_method_method_index, |
138 constantPoolHandle cp, | 205 constantPoolHandle cp, |
139 instanceKlassHandle k, TRAPS); | 206 TRAPS); |
140 void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | 207 void parse_classfile_attributes(constantPoolHandle cp, |
141 void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | 208 ClassAnnotationCollector* parsed_annotations, |
142 void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | 209 TRAPS); |
143 void parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k, u4 attribute_length, TRAPS); | 210 void parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS); |
211 void parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS); | |
212 void parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, u4 attribute_length, TRAPS); | |
144 | 213 |
145 // Annotations handling | 214 // Annotations handling |
146 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations, | 215 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations, |
147 int runtime_visible_annotations_length, | 216 int runtime_visible_annotations_length, |
148 u1* runtime_invisible_annotations, | 217 u1* runtime_invisible_annotations, |
149 int runtime_invisible_annotations_length, TRAPS); | 218 int runtime_invisible_annotations_length, TRAPS); |
219 int skip_annotation(u1* buffer, int limit, int index); | |
220 int skip_annotation_value(u1* buffer, int limit, int index); | |
221 void parse_annotations(u1* buffer, int limit, constantPoolHandle cp, | |
222 /* Results (currently, only one result is supported): */ | |
223 AnnotationCollector* result, | |
224 TRAPS); | |
150 | 225 |
151 // Final setup | 226 // Final setup |
152 unsigned int compute_oop_map_count(instanceKlassHandle super, | 227 unsigned int compute_oop_map_count(instanceKlassHandle super, |
153 unsigned int nonstatic_oop_count, | 228 unsigned int nonstatic_oop_count, |
154 int first_nonstatic_oop_offset); | 229 int first_nonstatic_oop_offset); |