16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 25 #ifndef SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP 26 #define SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP 27 28 #include "classfile/classFileStream.hpp" 29 #include "memory/resourceArea.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "oops/typeArrayOop.hpp" 32 #include "runtime/handles.inline.hpp" 33 #include "utilities/accessFlags.hpp" 34 35 class TempNewSymbol; 36 // Parser for for .class files 37 // 38 // The bytes describing the class file structure is read from a Stream object 39 40 class ClassFileParser VALUE_OBJ_CLASS_SPEC { 41 private: 42 bool _need_verify; 43 bool _relax_verify; 44 u2 _major_version; 45 u2 _minor_version; 46 Symbol* _class_name; 47 KlassHandle _host_klass; 48 GrowableArray<Handle>* _cp_patches; // overrides for CP entries 49 50 bool _has_finalizer; 51 bool _has_empty_finalizer; 52 bool _has_vanilla_constructor; 53 54 int _max_bootstrap_specifier_index; 55 67 // Constant pool parsing 68 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS); 69 70 constantPoolHandle parse_constant_pool(TRAPS); 71 72 // Interface parsing 73 objArrayHandle parse_interfaces(constantPoolHandle cp, 74 int length, 75 Handle class_loader, 76 Handle protection_domain, 77 Symbol* class_name, 78 TRAPS); 79 80 // Field parsing 81 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count, 82 bool is_static, u2 signature_index, 83 u2* constantvalue_index_addr, 84 bool* is_synthetic_addr, 85 u2* generic_signature_index_addr, 86 typeArrayHandle* field_annotations, TRAPS); 87 typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface, 88 struct FieldAllocationCount *fac, 89 objArrayHandle* fields_annotations, TRAPS); 90 91 // Method parsing 92 methodHandle parse_method(constantPoolHandle cp, bool is_interface, 93 AccessFlags* promoted_flags, 94 typeArrayHandle* method_annotations, 95 typeArrayHandle* method_parameter_annotations, 96 typeArrayHandle* method_default_annotations, 97 TRAPS); 98 objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface, 99 AccessFlags* promoted_flags, 100 bool* has_final_method, 101 objArrayOop* methods_annotations_oop, 102 objArrayOop* methods_parameter_annotations_oop, 103 objArrayOop* methods_default_annotations_oop, 104 TRAPS); 105 typeArrayHandle sort_methods (objArrayHandle methods, 106 objArrayHandle methods_annotations, 107 objArrayHandle methods_parameter_annotations, 108 objArrayHandle methods_default_annotations, 109 TRAPS); 133 void parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k, u4 attribute_length, TRAPS); 134 135 // Annotations handling 136 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations, 137 int runtime_visible_annotations_length, 138 u1* runtime_invisible_annotations, 139 int runtime_invisible_annotations_length, TRAPS); 140 141 // Final setup 142 unsigned int compute_oop_map_count(instanceKlassHandle super, 143 unsigned int nonstatic_oop_count, 144 int first_nonstatic_oop_offset); 145 void fill_oop_maps(instanceKlassHandle k, 146 unsigned int nonstatic_oop_map_count, 147 int* nonstatic_oop_offsets, 148 unsigned int* nonstatic_oop_counts); 149 void set_precomputed_flags(instanceKlassHandle k); 150 objArrayHandle compute_transitive_interfaces(instanceKlassHandle super, 151 objArrayHandle local_ifs, TRAPS); 152 153 // Special handling for certain classes. 154 // Add the "discovered" field to java.lang.ref.Reference if 155 // it does not exist. 156 void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr, 157 constantPoolHandle cp, 158 FieldAllocationCount *fac_ptr, TRAPS); 159 // Adjust the field allocation counts for java.lang.Class to add 160 // fake fields. 161 void java_lang_Class_fix_pre(int* nonstatic_field_size, 162 FieldAllocationCount *fac_ptr); 163 // Adjust the next_nonstatic_oop_offset to place the fake fields 164 // before any Java fields. 165 void java_lang_Class_fix_post(int* next_nonstatic_oop_offset); 166 // Adjust the field allocation counts for java.lang.invoke.MethodHandle to add 167 // a fake address (void*) field. 168 void java_lang_invoke_MethodHandle_fix_pre(constantPoolHandle cp, 169 typeArrayHandle fields, 170 FieldAllocationCount *fac_ptr, TRAPS); 171 172 // Format checker methods 173 void classfile_parse_error(const char* msg, TRAPS); 174 void classfile_parse_error(const char* msg, int index, TRAPS); 175 void classfile_parse_error(const char* msg, const char *name, TRAPS); 176 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS); 177 inline void guarantee_property(bool b, const char* msg, TRAPS) { 178 if (!b) { classfile_parse_error(msg, CHECK); } 179 } 180 181 inline void assert_property(bool b, const char* msg, TRAPS) { 182 #ifdef ASSERT 183 if (!b) { fatal(msg); } 184 #endif 185 } 186 187 inline void check_property(bool property, const char* msg, int index, TRAPS) { 188 if (_need_verify) { 189 guarantee_property(property, msg, index, CHECK); 190 } else { 191 assert_property(property, msg, CHECK); | 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 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 25 #ifndef SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP 26 #define SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP 27 28 #include "classfile/classFileStream.hpp" 29 #include "memory/resourceArea.hpp" 30 #include "oops/oop.inline.hpp" 31 #include "oops/typeArrayOop.hpp" 32 #include "runtime/handles.inline.hpp" 33 #include "utilities/accessFlags.hpp" 34 35 class TempNewSymbol; 36 class FieldAllocationCount; 37 38 39 // Parser for for .class files 40 // 41 // The bytes describing the class file structure is read from a Stream object 42 43 class ClassFileParser VALUE_OBJ_CLASS_SPEC { 44 private: 45 bool _need_verify; 46 bool _relax_verify; 47 u2 _major_version; 48 u2 _minor_version; 49 Symbol* _class_name; 50 KlassHandle _host_klass; 51 GrowableArray<Handle>* _cp_patches; // overrides for CP entries 52 53 bool _has_finalizer; 54 bool _has_empty_finalizer; 55 bool _has_vanilla_constructor; 56 57 int _max_bootstrap_specifier_index; 58 70 // Constant pool parsing 71 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS); 72 73 constantPoolHandle parse_constant_pool(TRAPS); 74 75 // Interface parsing 76 objArrayHandle parse_interfaces(constantPoolHandle cp, 77 int length, 78 Handle class_loader, 79 Handle protection_domain, 80 Symbol* class_name, 81 TRAPS); 82 83 // Field parsing 84 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count, 85 bool is_static, u2 signature_index, 86 u2* constantvalue_index_addr, 87 bool* is_synthetic_addr, 88 u2* generic_signature_index_addr, 89 typeArrayHandle* field_annotations, TRAPS); 90 typeArrayHandle parse_fields(Symbol* class_name, 91 constantPoolHandle cp, bool is_interface, 92 FieldAllocationCount *fac, 93 objArrayHandle* fields_annotations, 94 int* java_fields_count_ptr, TRAPS); 95 96 // Method parsing 97 methodHandle parse_method(constantPoolHandle cp, bool is_interface, 98 AccessFlags* promoted_flags, 99 typeArrayHandle* method_annotations, 100 typeArrayHandle* method_parameter_annotations, 101 typeArrayHandle* method_default_annotations, 102 TRAPS); 103 objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface, 104 AccessFlags* promoted_flags, 105 bool* has_final_method, 106 objArrayOop* methods_annotations_oop, 107 objArrayOop* methods_parameter_annotations_oop, 108 objArrayOop* methods_default_annotations_oop, 109 TRAPS); 110 typeArrayHandle sort_methods (objArrayHandle methods, 111 objArrayHandle methods_annotations, 112 objArrayHandle methods_parameter_annotations, 113 objArrayHandle methods_default_annotations, 114 TRAPS); 138 void parse_classfile_bootstrap_methods_attribute(constantPoolHandle cp, instanceKlassHandle k, u4 attribute_length, TRAPS); 139 140 // Annotations handling 141 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations, 142 int runtime_visible_annotations_length, 143 u1* runtime_invisible_annotations, 144 int runtime_invisible_annotations_length, TRAPS); 145 146 // Final setup 147 unsigned int compute_oop_map_count(instanceKlassHandle super, 148 unsigned int nonstatic_oop_count, 149 int first_nonstatic_oop_offset); 150 void fill_oop_maps(instanceKlassHandle k, 151 unsigned int nonstatic_oop_map_count, 152 int* nonstatic_oop_offsets, 153 unsigned int* nonstatic_oop_counts); 154 void set_precomputed_flags(instanceKlassHandle k); 155 objArrayHandle compute_transitive_interfaces(instanceKlassHandle super, 156 objArrayHandle local_ifs, TRAPS); 157 158 // Format checker methods 159 void classfile_parse_error(const char* msg, TRAPS); 160 void classfile_parse_error(const char* msg, int index, TRAPS); 161 void classfile_parse_error(const char* msg, const char *name, TRAPS); 162 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS); 163 inline void guarantee_property(bool b, const char* msg, TRAPS) { 164 if (!b) { classfile_parse_error(msg, CHECK); } 165 } 166 167 inline void assert_property(bool b, const char* msg, TRAPS) { 168 #ifdef ASSERT 169 if (!b) { fatal(msg); } 170 #endif 171 } 172 173 inline void check_property(bool property, const char* msg, int index, TRAPS) { 174 if (_need_verify) { 175 guarantee_property(property, msg, index, CHECK); 176 } else { 177 assert_property(property, msg, CHECK); |