Fri, 06 Mar 2015 16:47:46 +0100
8074561: Wrong volatile qualifier for field ClassLoaderDataGraphKlassIteratorAtomic::_next_klass
Reviewed-by: mgerdin, stefank
duke@435 | 1 | /* |
drchase@6680 | 2 | * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved. |
duke@435 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
duke@435 | 4 | * |
duke@435 | 5 | * This code is free software; you can redistribute it and/or modify it |
duke@435 | 6 | * under the terms of the GNU General Public License version 2 only, as |
duke@435 | 7 | * published by the Free Software Foundation. |
duke@435 | 8 | * |
duke@435 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
duke@435 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
duke@435 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
duke@435 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
duke@435 | 13 | * accompanied this code). |
duke@435 | 14 | * |
duke@435 | 15 | * You should have received a copy of the GNU General Public License version |
duke@435 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
duke@435 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
duke@435 | 18 | * |
trims@1907 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
trims@1907 | 20 | * or visit www.oracle.com if you need additional information or have any |
trims@1907 | 21 | * questions. |
duke@435 | 22 | * |
duke@435 | 23 | */ |
duke@435 | 24 | |
stefank@2314 | 25 | #ifndef SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP |
stefank@2314 | 26 | #define SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP |
stefank@2314 | 27 | |
stefank@2314 | 28 | #include "classfile/classFileStream.hpp" |
stefank@2314 | 29 | #include "memory/resourceArea.hpp" |
stefank@2314 | 30 | #include "oops/oop.inline.hpp" |
stefank@2314 | 31 | #include "oops/typeArrayOop.hpp" |
stefank@2314 | 32 | #include "runtime/handles.inline.hpp" |
stefank@2314 | 33 | #include "utilities/accessFlags.hpp" |
jrose@3926 | 34 | #include "classfile/symbolTable.hpp" |
stefank@2314 | 35 | |
never@3137 | 36 | class FieldAllocationCount; |
coleenp@4719 | 37 | class FieldLayoutInfo; |
never@3137 | 38 | |
never@3137 | 39 | |
duke@435 | 40 | // Parser for for .class files |
duke@435 | 41 | // |
duke@435 | 42 | // The bytes describing the class file structure is read from a Stream object |
duke@435 | 43 | |
duke@435 | 44 | class ClassFileParser VALUE_OBJ_CLASS_SPEC { |
duke@435 | 45 | private: |
duke@435 | 46 | bool _need_verify; |
duke@435 | 47 | bool _relax_verify; |
duke@435 | 48 | u2 _major_version; |
duke@435 | 49 | u2 _minor_version; |
coleenp@2497 | 50 | Symbol* _class_name; |
coleenp@4719 | 51 | ClassLoaderData* _loader_data; |
jrose@1145 | 52 | KlassHandle _host_klass; |
jrose@866 | 53 | GrowableArray<Handle>* _cp_patches; // overrides for CP entries |
duke@435 | 54 | |
jrose@3926 | 55 | // precomputed flags |
duke@435 | 56 | bool _has_finalizer; |
duke@435 | 57 | bool _has_empty_finalizer; |
duke@435 | 58 | bool _has_vanilla_constructor; |
jrose@3926 | 59 | int _max_bootstrap_specifier_index; // detects BSS values |
duke@435 | 60 | |
jrose@3926 | 61 | // class attributes parsed before the instance klass is created: |
jrose@3926 | 62 | bool _synthetic_flag; |
coleenp@4719 | 63 | int _sde_length; |
coleenp@4719 | 64 | char* _sde_buffer; |
jiangli@5535 | 65 | u2 _sourcefile_index; |
jiangli@5535 | 66 | u2 _generic_signature_index; |
coleenp@4719 | 67 | |
coleenp@4719 | 68 | // Metadata created before the instance klass is created. Must be deallocated |
coleenp@4719 | 69 | // if not transferred to the InstanceKlass upon successful class loading |
coleenp@4719 | 70 | // in which case these pointers have been set to NULL. |
coleenp@4719 | 71 | instanceKlassHandle _super_klass; |
coleenp@4719 | 72 | ConstantPool* _cp; |
coleenp@4719 | 73 | Array<u2>* _fields; |
coleenp@4719 | 74 | Array<Method*>* _methods; |
coleenp@4719 | 75 | Array<u2>* _inner_classes; |
coleenp@4719 | 76 | Array<Klass*>* _local_interfaces; |
coleenp@4719 | 77 | Array<Klass*>* _transitive_interfaces; |
stefank@7417 | 78 | Annotations* _combined_annotations; |
coleenp@4037 | 79 | AnnotationArray* _annotations; |
stefank@4393 | 80 | AnnotationArray* _type_annotations; |
coleenp@4719 | 81 | Array<AnnotationArray*>* _fields_annotations; |
coleenp@4719 | 82 | Array<AnnotationArray*>* _fields_type_annotations; |
coleenp@4719 | 83 | InstanceKlass* _klass; // InstanceKlass once created. |
jrose@3926 | 84 | |
jiangli@5535 | 85 | void set_class_synthetic_flag(bool x) { _synthetic_flag = x; } |
jiangli@5535 | 86 | void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; } |
jiangli@5535 | 87 | void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; } |
jiangli@5535 | 88 | void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; } |
coleenp@4719 | 89 | |
stefank@7417 | 90 | void create_combined_annotations(TRAPS); |
stefank@7417 | 91 | |
coleenp@4719 | 92 | void init_parsed_class_attributes(ClassLoaderData* loader_data) { |
coleenp@4719 | 93 | _loader_data = loader_data; |
jrose@3926 | 94 | _synthetic_flag = false; |
jiangli@5535 | 95 | _sourcefile_index = 0; |
jiangli@5535 | 96 | _generic_signature_index = 0; |
kvn@3930 | 97 | _sde_buffer = NULL; |
kvn@3930 | 98 | _sde_length = 0; |
jrose@3926 | 99 | // initialize the other flags too: |
jrose@3926 | 100 | _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false; |
jrose@3926 | 101 | _max_bootstrap_specifier_index = -1; |
coleenp@4719 | 102 | clear_class_metadata(); |
coleenp@4719 | 103 | _klass = NULL; |
jrose@3926 | 104 | } |
jrose@3926 | 105 | void apply_parsed_class_attributes(instanceKlassHandle k); // update k |
coleenp@4719 | 106 | void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS); |
coleenp@4719 | 107 | void clear_class_metadata() { |
coleenp@4719 | 108 | // metadata created before the instance klass is created. Must be |
coleenp@4719 | 109 | // deallocated if classfile parsing returns an error. |
coleenp@4719 | 110 | _cp = NULL; |
coleenp@4719 | 111 | _fields = NULL; |
coleenp@4719 | 112 | _methods = NULL; |
coleenp@4719 | 113 | _inner_classes = NULL; |
coleenp@4719 | 114 | _local_interfaces = NULL; |
coleenp@4719 | 115 | _transitive_interfaces = NULL; |
stefank@7417 | 116 | _combined_annotations = NULL; |
coleenp@4719 | 117 | _annotations = _type_annotations = NULL; |
coleenp@4719 | 118 | _fields_annotations = _fields_type_annotations = NULL; |
coleenp@4719 | 119 | } |
jrose@3926 | 120 | |
jrose@3926 | 121 | class AnnotationCollector { |
jrose@3926 | 122 | public: |
jrose@3926 | 123 | enum Location { _in_field, _in_method, _in_class }; |
jrose@3926 | 124 | enum ID { |
jrose@3926 | 125 | _unknown = 0, |
twisti@4866 | 126 | _method_CallerSensitive, |
jrose@3926 | 127 | _method_ForceInline, |
twisti@3969 | 128 | _method_DontInline, |
twisti@3969 | 129 | _method_LambdaForm_Compiled, |
twisti@3969 | 130 | _method_LambdaForm_Hidden, |
jwilhelm@4430 | 131 | _sun_misc_Contended, |
vlivanov@5658 | 132 | _field_Stable, |
jrose@3926 | 133 | _annotation_LIMIT |
jrose@3926 | 134 | }; |
jrose@3926 | 135 | const Location _location; |
jrose@3926 | 136 | int _annotations_present; |
jwilhelm@4430 | 137 | u2 _contended_group; |
jwilhelm@4430 | 138 | |
jrose@3926 | 139 | AnnotationCollector(Location location) |
jrose@3926 | 140 | : _location(location), _annotations_present(0) |
jrose@3926 | 141 | { |
jrose@3926 | 142 | assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, ""); |
jrose@3926 | 143 | } |
jrose@3926 | 144 | // If this annotation name has an ID, report it (or _none). |
jwilhelm@4430 | 145 | ID annotation_index(ClassLoaderData* loader_data, Symbol* name); |
jrose@3926 | 146 | // Set the annotation name: |
jrose@3926 | 147 | void set_annotation(ID id) { |
jrose@3926 | 148 | assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); |
jrose@3926 | 149 | _annotations_present |= nth_bit((int)id); |
jrose@3926 | 150 | } |
vlivanov@5658 | 151 | |
vlivanov@5658 | 152 | void remove_annotation(ID id) { |
vlivanov@5658 | 153 | assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); |
vlivanov@5658 | 154 | _annotations_present &= ~nth_bit((int)id); |
vlivanov@5658 | 155 | } |
vlivanov@5658 | 156 | |
jrose@3926 | 157 | // Report if the annotation is present. |
vlivanov@5658 | 158 | bool has_any_annotations() const { return _annotations_present != 0; } |
vlivanov@5658 | 159 | bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; } |
jwilhelm@4430 | 160 | |
jwilhelm@4430 | 161 | void set_contended_group(u2 group) { _contended_group = group; } |
vlivanov@5658 | 162 | u2 contended_group() const { return _contended_group; } |
jwilhelm@4430 | 163 | |
vlivanov@5658 | 164 | bool is_contended() const { return has_annotation(_sun_misc_Contended); } |
vlivanov@5658 | 165 | |
vlivanov@5658 | 166 | void set_stable(bool stable) { set_annotation(_field_Stable); } |
vlivanov@5658 | 167 | bool is_stable() const { return has_annotation(_field_Stable); } |
jrose@3926 | 168 | }; |
coleenp@4719 | 169 | |
coleenp@4719 | 170 | // This class also doubles as a holder for metadata cleanup. |
jrose@3926 | 171 | class FieldAnnotationCollector: public AnnotationCollector { |
coleenp@4719 | 172 | ClassLoaderData* _loader_data; |
coleenp@4719 | 173 | AnnotationArray* _field_annotations; |
coleenp@4719 | 174 | AnnotationArray* _field_type_annotations; |
jrose@3926 | 175 | public: |
coleenp@4719 | 176 | FieldAnnotationCollector(ClassLoaderData* loader_data) : |
coleenp@4719 | 177 | AnnotationCollector(_in_field), |
coleenp@4719 | 178 | _loader_data(loader_data), |
coleenp@4719 | 179 | _field_annotations(NULL), |
coleenp@4719 | 180 | _field_type_annotations(NULL) {} |
jrose@3926 | 181 | void apply_to(FieldInfo* f); |
coleenp@4719 | 182 | ~FieldAnnotationCollector(); |
coleenp@4719 | 183 | AnnotationArray* field_annotations() { return _field_annotations; } |
coleenp@4719 | 184 | AnnotationArray* field_type_annotations() { return _field_type_annotations; } |
coleenp@4719 | 185 | |
coleenp@4719 | 186 | void set_field_annotations(AnnotationArray* a) { _field_annotations = a; } |
coleenp@4719 | 187 | void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; } |
jrose@3926 | 188 | }; |
coleenp@4719 | 189 | |
jrose@3926 | 190 | class MethodAnnotationCollector: public AnnotationCollector { |
jrose@3926 | 191 | public: |
jrose@3926 | 192 | MethodAnnotationCollector() : AnnotationCollector(_in_method) { } |
jrose@3926 | 193 | void apply_to(methodHandle m); |
jrose@3926 | 194 | }; |
jrose@3926 | 195 | class ClassAnnotationCollector: public AnnotationCollector { |
jrose@3926 | 196 | public: |
jrose@3926 | 197 | ClassAnnotationCollector() : AnnotationCollector(_in_class) { } |
jrose@3926 | 198 | void apply_to(instanceKlassHandle k); |
jrose@3926 | 199 | }; |
jrose@2353 | 200 | |
duke@435 | 201 | enum { fixed_buffer_size = 128 }; |
duke@435 | 202 | u_char linenumbertable_buffer[fixed_buffer_size]; |
duke@435 | 203 | |
duke@435 | 204 | ClassFileStream* _stream; // Actual input stream |
duke@435 | 205 | |
duke@435 | 206 | enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names |
duke@435 | 207 | |
duke@435 | 208 | // Accessors |
duke@435 | 209 | ClassFileStream* stream() { return _stream; } |
duke@435 | 210 | void set_stream(ClassFileStream* st) { _stream = st; } |
duke@435 | 211 | |
duke@435 | 212 | // Constant pool parsing |
coleenp@4719 | 213 | void parse_constant_pool_entries(int length, TRAPS); |
duke@435 | 214 | |
coleenp@4719 | 215 | constantPoolHandle parse_constant_pool(TRAPS); |
duke@435 | 216 | |
duke@435 | 217 | // Interface parsing |
coleenp@4719 | 218 | Array<Klass*>* parse_interfaces(int length, |
duke@435 | 219 | Handle protection_domain, |
coleenp@2497 | 220 | Symbol* class_name, |
kamg@4245 | 221 | bool* has_default_methods, |
duke@435 | 222 | TRAPS); |
coleenp@4037 | 223 | void record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS); |
duke@435 | 224 | |
coleenp@4719 | 225 | instanceKlassHandle parse_super_class(int super_class_index, TRAPS); |
duke@435 | 226 | // Field parsing |
coleenp@4719 | 227 | void parse_field_attributes(u2 attributes_count, |
duke@435 | 228 | bool is_static, u2 signature_index, |
duke@435 | 229 | u2* constantvalue_index_addr, |
duke@435 | 230 | bool* is_synthetic_addr, |
duke@435 | 231 | u2* generic_signature_index_addr, |
jrose@3926 | 232 | FieldAnnotationCollector* parsed_annotations, |
jrose@3926 | 233 | TRAPS); |
coleenp@4719 | 234 | Array<u2>* parse_fields(Symbol* class_name, |
coleenp@4719 | 235 | bool is_interface, |
coleenp@4142 | 236 | FieldAllocationCount *fac, |
coleenp@4142 | 237 | u2* java_fields_count_ptr, TRAPS); |
duke@435 | 238 | |
jwilhelm@4430 | 239 | void print_field_layout(Symbol* name, |
jwilhelm@4430 | 240 | Array<u2>* fields, |
jwilhelm@4430 | 241 | constantPoolHandle cp, |
jwilhelm@4430 | 242 | int instance_size, |
jwilhelm@4430 | 243 | int instance_fields_start, |
jwilhelm@4430 | 244 | int instance_fields_end, |
jwilhelm@4430 | 245 | int static_fields_end); |
jwilhelm@4430 | 246 | |
duke@435 | 247 | // Method parsing |
coleenp@4719 | 248 | methodHandle parse_method(bool is_interface, |
duke@435 | 249 | AccessFlags* promoted_flags, |
duke@435 | 250 | TRAPS); |
coleenp@4719 | 251 | Array<Method*>* parse_methods(bool is_interface, |
duke@435 | 252 | AccessFlags* promoted_flags, |
duke@435 | 253 | bool* has_final_method, |
acorn@7290 | 254 | bool* declares_default_methods, |
duke@435 | 255 | TRAPS); |
coleenp@4719 | 256 | intArray* sort_methods(Array<Method*>* methods); |
coleenp@4719 | 257 | |
coleenp@4719 | 258 | u2* parse_exception_table(u4 code_length, u4 exception_table_length, |
coleenp@4719 | 259 | TRAPS); |
duke@435 | 260 | void parse_linenumber_table( |
duke@435 | 261 | u4 code_attribute_length, u4 code_length, |
duke@435 | 262 | CompressedLineNumberWriteStream** write_stream, TRAPS); |
duke@435 | 263 | u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length, |
coleenp@4719 | 264 | u2* localvariable_table_length, |
duke@435 | 265 | bool isLVTT, TRAPS); |
duke@435 | 266 | u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length, |
coleenp@4719 | 267 | TRAPS); |
duke@435 | 268 | void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, |
coleenp@4719 | 269 | u1* u1_array, u2* u2_array, TRAPS); |
coleenp@4719 | 270 | u1* parse_stackmap_table(u4 code_attribute_length, TRAPS); |
duke@435 | 271 | |
duke@435 | 272 | // Classfile attribute parsing |
acorn@6765 | 273 | u2 parse_generic_signature_attribute(TRAPS); |
coleenp@4719 | 274 | void parse_classfile_sourcefile_attribute(TRAPS); |
coleenp@4719 | 275 | void parse_classfile_source_debug_extension_attribute(int length, TRAPS); |
coleenp@4719 | 276 | u2 parse_classfile_inner_classes_attribute(u1* inner_classes_attribute_start, |
jiangli@3670 | 277 | bool parsed_enclosingmethod_attribute, |
jiangli@3670 | 278 | u2 enclosing_method_class_index, |
jiangli@3670 | 279 | u2 enclosing_method_method_index, |
jrose@3926 | 280 | TRAPS); |
coleenp@4719 | 281 | void parse_classfile_attributes(ClassAnnotationCollector* parsed_annotations, |
jrose@3926 | 282 | TRAPS); |
coleenp@4719 | 283 | void parse_classfile_synthetic_attribute(TRAPS); |
coleenp@4719 | 284 | void parse_classfile_signature_attribute(TRAPS); |
coleenp@4719 | 285 | void parse_classfile_bootstrap_methods_attribute(u4 attribute_length, TRAPS); |
duke@435 | 286 | |
duke@435 | 287 | // Annotations handling |
coleenp@4719 | 288 | AnnotationArray* assemble_annotations(u1* runtime_visible_annotations, |
coleenp@4142 | 289 | int runtime_visible_annotations_length, |
coleenp@4142 | 290 | u1* runtime_invisible_annotations, |
coleenp@4142 | 291 | int runtime_invisible_annotations_length, TRAPS); |
jrose@3926 | 292 | int skip_annotation(u1* buffer, int limit, int index); |
jrose@3926 | 293 | int skip_annotation_value(u1* buffer, int limit, int index); |
coleenp@4719 | 294 | void parse_annotations(u1* buffer, int limit, |
jrose@3926 | 295 | /* Results (currently, only one result is supported): */ |
jrose@3926 | 296 | AnnotationCollector* result, |
jrose@3926 | 297 | TRAPS); |
duke@435 | 298 | |
duke@435 | 299 | // Final setup |
jcoomes@1374 | 300 | unsigned int compute_oop_map_count(instanceKlassHandle super, |
jcoomes@1374 | 301 | unsigned int nonstatic_oop_count, |
jcoomes@1374 | 302 | int first_nonstatic_oop_offset); |
jcoomes@1374 | 303 | void fill_oop_maps(instanceKlassHandle k, |
jcoomes@1374 | 304 | unsigned int nonstatic_oop_map_count, |
jcoomes@1374 | 305 | int* nonstatic_oop_offsets, |
jcoomes@1374 | 306 | unsigned int* nonstatic_oop_counts); |
duke@435 | 307 | void set_precomputed_flags(instanceKlassHandle k); |
coleenp@4719 | 308 | Array<Klass*>* compute_transitive_interfaces(instanceKlassHandle super, |
coleenp@4142 | 309 | Array<Klass*>* local_ifs, TRAPS); |
duke@435 | 310 | |
duke@435 | 311 | // Format checker methods |
duke@435 | 312 | void classfile_parse_error(const char* msg, TRAPS); |
duke@435 | 313 | void classfile_parse_error(const char* msg, int index, TRAPS); |
duke@435 | 314 | void classfile_parse_error(const char* msg, const char *name, TRAPS); |
duke@435 | 315 | void classfile_parse_error(const char* msg, int index, const char *name, TRAPS); |
duke@435 | 316 | inline void guarantee_property(bool b, const char* msg, TRAPS) { |
duke@435 | 317 | if (!b) { classfile_parse_error(msg, CHECK); } |
duke@435 | 318 | } |
duke@435 | 319 | |
drchase@6680 | 320 | PRAGMA_DIAG_PUSH |
drchase@6680 | 321 | PRAGMA_FORMAT_NONLITERAL_IGNORED |
drchase@6680 | 322 | inline void assert_property(bool b, const char* msg, TRAPS) { |
duke@435 | 323 | #ifdef ASSERT |
hseigel@4979 | 324 | if (!b) { |
hseigel@4979 | 325 | ResourceMark rm(THREAD); |
hseigel@4979 | 326 | fatal(err_msg(msg, _class_name->as_C_string())); |
hseigel@4979 | 327 | } |
hseigel@4979 | 328 | #endif |
hseigel@4979 | 329 | } |
hseigel@4979 | 330 | |
hseigel@4979 | 331 | inline void assert_property(bool b, const char* msg, int index, TRAPS) { |
hseigel@4979 | 332 | #ifdef ASSERT |
hseigel@4979 | 333 | if (!b) { |
hseigel@4979 | 334 | ResourceMark rm(THREAD); |
hseigel@4979 | 335 | fatal(err_msg(msg, index, _class_name->as_C_string())); |
hseigel@4979 | 336 | } |
duke@435 | 337 | #endif |
duke@435 | 338 | } |
drchase@6680 | 339 | PRAGMA_DIAG_POP |
duke@435 | 340 | |
duke@435 | 341 | inline void check_property(bool property, const char* msg, int index, TRAPS) { |
duke@435 | 342 | if (_need_verify) { |
duke@435 | 343 | guarantee_property(property, msg, index, CHECK); |
duke@435 | 344 | } else { |
hseigel@4979 | 345 | assert_property(property, msg, index, CHECK); |
duke@435 | 346 | } |
duke@435 | 347 | } |
duke@435 | 348 | |
duke@435 | 349 | inline void check_property(bool property, const char* msg, TRAPS) { |
duke@435 | 350 | if (_need_verify) { |
duke@435 | 351 | guarantee_property(property, msg, CHECK); |
duke@435 | 352 | } else { |
duke@435 | 353 | assert_property(property, msg, CHECK); |
duke@435 | 354 | } |
duke@435 | 355 | } |
duke@435 | 356 | |
duke@435 | 357 | inline void guarantee_property(bool b, const char* msg, int index, TRAPS) { |
duke@435 | 358 | if (!b) { classfile_parse_error(msg, index, CHECK); } |
duke@435 | 359 | } |
duke@435 | 360 | inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) { |
duke@435 | 361 | if (!b) { classfile_parse_error(msg, name, CHECK); } |
duke@435 | 362 | } |
duke@435 | 363 | inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) { |
duke@435 | 364 | if (!b) { classfile_parse_error(msg, index, name, CHECK); } |
duke@435 | 365 | } |
duke@435 | 366 | |
kamg@1941 | 367 | void throwIllegalSignature( |
coleenp@2497 | 368 | const char* type, Symbol* name, Symbol* sig, TRAPS); |
kamg@1941 | 369 | |
duke@435 | 370 | bool is_supported_version(u2 major, u2 minor); |
duke@435 | 371 | bool has_illegal_visibility(jint flags); |
duke@435 | 372 | |
coleenp@4719 | 373 | void verify_constantvalue(int constantvalue_index, int signature_index, TRAPS); |
duke@435 | 374 | void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS); |
coleenp@2497 | 375 | void verify_legal_class_name(Symbol* name, TRAPS); |
coleenp@2497 | 376 | void verify_legal_field_name(Symbol* name, TRAPS); |
coleenp@2497 | 377 | void verify_legal_method_name(Symbol* name, TRAPS); |
coleenp@2497 | 378 | void verify_legal_field_signature(Symbol* fieldname, Symbol* signature, TRAPS); |
coleenp@2497 | 379 | int verify_legal_method_signature(Symbol* methodname, Symbol* signature, TRAPS); |
duke@435 | 380 | void verify_legal_class_modifiers(jint flags, TRAPS); |
duke@435 | 381 | void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS); |
coleenp@2497 | 382 | void verify_legal_method_modifiers(jint flags, bool is_interface, Symbol* name, TRAPS); |
duke@435 | 383 | bool verify_unqualified_name(char* name, unsigned int length, int type); |
duke@435 | 384 | char* skip_over_field_name(char* name, bool slash_ok, unsigned int length); |
duke@435 | 385 | char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS); |
duke@435 | 386 | |
jrose@1145 | 387 | bool is_anonymous() { |
twisti@2698 | 388 | assert(EnableInvokeDynamic || _host_klass.is_null(), ""); |
jrose@1145 | 389 | return _host_klass.not_null(); |
jrose@1145 | 390 | } |
jrose@866 | 391 | bool has_cp_patch_at(int index) { |
twisti@2698 | 392 | assert(EnableInvokeDynamic, ""); |
jrose@866 | 393 | assert(index >= 0, "oob"); |
jrose@866 | 394 | return (_cp_patches != NULL |
jrose@866 | 395 | && index < _cp_patches->length() |
jrose@866 | 396 | && _cp_patches->adr_at(index)->not_null()); |
jrose@866 | 397 | } |
jrose@866 | 398 | Handle cp_patch_at(int index) { |
jrose@866 | 399 | assert(has_cp_patch_at(index), "oob"); |
jrose@866 | 400 | return _cp_patches->at(index); |
jrose@866 | 401 | } |
jrose@866 | 402 | Handle clear_cp_patch_at(int index) { |
jrose@866 | 403 | Handle patch = cp_patch_at(index); |
jrose@866 | 404 | _cp_patches->at_put(index, Handle()); |
jrose@866 | 405 | assert(!has_cp_patch_at(index), ""); |
jrose@866 | 406 | return patch; |
jrose@866 | 407 | } |
jrose@866 | 408 | void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS); |
jrose@866 | 409 | |
jrose@866 | 410 | // Wrapper for constantTag.is_klass_[or_]reference. |
coleenp@4037 | 411 | // In older versions of the VM, Klass*s cannot sneak into early phases of |
jrose@866 | 412 | // constant pool construction, but in later versions they can. |
jrose@866 | 413 | // %%% Let's phase out the old is_klass_reference. |
coleenp@4719 | 414 | bool valid_klass_reference_at(int index) { |
coleenp@4719 | 415 | return _cp->is_within_bounds(index) && |
coleenp@4719 | 416 | (EnableInvokeDynamic |
coleenp@4719 | 417 | ? _cp->tag_at(index).is_klass_or_reference() |
coleenp@4719 | 418 | : _cp->tag_at(index).is_klass_reference()); |
coleenp@4719 | 419 | } |
coleenp@4719 | 420 | |
coleenp@4719 | 421 | // Checks that the cpool index is in range and is a utf8 |
coleenp@4719 | 422 | bool valid_symbol_at(int cpool_index) { |
coleenp@4719 | 423 | return (_cp->is_within_bounds(cpool_index) && |
coleenp@4719 | 424 | _cp->tag_at(cpool_index).is_utf8()); |
jrose@866 | 425 | } |
jrose@866 | 426 | |
coleenp@4572 | 427 | void copy_localvariable_table(ConstMethod* cm, int lvt_cnt, |
coleenp@4572 | 428 | u2* localvariable_table_length, |
coleenp@4572 | 429 | u2** localvariable_table_start, |
coleenp@4572 | 430 | int lvtt_cnt, |
coleenp@4572 | 431 | u2* localvariable_type_table_length, |
coleenp@4572 | 432 | u2** localvariable_type_table_start, |
coleenp@4572 | 433 | TRAPS); |
coleenp@4572 | 434 | |
coleenp@4719 | 435 | void copy_method_annotations(ConstMethod* cm, |
coleenp@4572 | 436 | u1* runtime_visible_annotations, |
coleenp@4572 | 437 | int runtime_visible_annotations_length, |
coleenp@4572 | 438 | u1* runtime_invisible_annotations, |
coleenp@4572 | 439 | int runtime_invisible_annotations_length, |
coleenp@4572 | 440 | u1* runtime_visible_parameter_annotations, |
coleenp@4572 | 441 | int runtime_visible_parameter_annotations_length, |
coleenp@4572 | 442 | u1* runtime_invisible_parameter_annotations, |
coleenp@4572 | 443 | int runtime_invisible_parameter_annotations_length, |
coleenp@4572 | 444 | u1* runtime_visible_type_annotations, |
coleenp@4572 | 445 | int runtime_visible_type_annotations_length, |
coleenp@4572 | 446 | u1* runtime_invisible_type_annotations, |
coleenp@4572 | 447 | int runtime_invisible_type_annotations_length, |
coleenp@4572 | 448 | u1* annotation_default, |
coleenp@4572 | 449 | int annotation_default_length, |
coleenp@4572 | 450 | TRAPS); |
coleenp@4572 | 451 | |
coleenp@4719 | 452 | // lays out fields in class and returns the total oopmap count |
coleenp@4719 | 453 | void layout_fields(Handle class_loader, FieldAllocationCount* fac, |
coleenp@4719 | 454 | ClassAnnotationCollector* parsed_annotations, |
coleenp@4719 | 455 | FieldLayoutInfo* info, TRAPS); |
coleenp@4719 | 456 | |
duke@435 | 457 | public: |
duke@435 | 458 | // Constructor |
duke@435 | 459 | ClassFileParser(ClassFileStream* st) { set_stream(st); } |
coleenp@4719 | 460 | ~ClassFileParser(); |
duke@435 | 461 | |
coleenp@4037 | 462 | // Parse .class file and return new Klass*. The Klass* is not hooked up |
duke@435 | 463 | // to the system dictionary or any other structures, so a .class file can |
duke@435 | 464 | // be loaded several times if desired. |
duke@435 | 465 | // The system dictionary hookup is done by the caller. |
duke@435 | 466 | // |
duke@435 | 467 | // "parsed_name" is updated by this method, and is the name found |
duke@435 | 468 | // while parsing the stream. |
coleenp@2497 | 469 | instanceKlassHandle parseClassFile(Symbol* name, |
coleenp@4304 | 470 | ClassLoaderData* loader_data, |
duke@435 | 471 | Handle protection_domain, |
coleenp@2497 | 472 | TempNewSymbol& parsed_name, |
acorn@1408 | 473 | bool verify, |
jrose@866 | 474 | TRAPS) { |
jrose@1145 | 475 | KlassHandle no_host_klass; |
coleenp@4304 | 476 | return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD); |
jrose@866 | 477 | } |
coleenp@2497 | 478 | instanceKlassHandle parseClassFile(Symbol* name, |
coleenp@4304 | 479 | ClassLoaderData* loader_data, |
jrose@866 | 480 | Handle protection_domain, |
jrose@1145 | 481 | KlassHandle host_klass, |
jrose@866 | 482 | GrowableArray<Handle>* cp_patches, |
coleenp@2497 | 483 | TempNewSymbol& parsed_name, |
acorn@1408 | 484 | bool verify, |
duke@435 | 485 | TRAPS); |
duke@435 | 486 | |
duke@435 | 487 | // Verifier checks |
duke@435 | 488 | static void check_super_class_access(instanceKlassHandle this_klass, TRAPS); |
duke@435 | 489 | static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS); |
duke@435 | 490 | static void check_final_method_override(instanceKlassHandle this_klass, TRAPS); |
duke@435 | 491 | static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS); |
duke@435 | 492 | }; |
stefank@2314 | 493 | |
stefank@2314 | 494 | #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP |