classFileParser.hpp revision 1472
0N/A/*
1472N/A * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
0N/A * published by the Free Software Foundation.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
1472N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
1472N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
0N/A *
0N/A */
0N/A
0N/A// Parser for for .class files
0N/A//
0N/A// The bytes describing the class file structure is read from a Stream object
0N/A
0N/Aclass ClassFileParser VALUE_OBJ_CLASS_SPEC {
0N/A private:
0N/A bool _need_verify;
0N/A bool _relax_verify;
0N/A u2 _major_version;
0N/A u2 _minor_version;
0N/A symbolHandle _class_name;
710N/A KlassHandle _host_klass;
431N/A GrowableArray<Handle>* _cp_patches; // overrides for CP entries
0N/A
0N/A bool _has_finalizer;
0N/A bool _has_empty_finalizer;
0N/A bool _has_vanilla_constructor;
0N/A
0N/A enum { fixed_buffer_size = 128 };
0N/A u_char linenumbertable_buffer[fixed_buffer_size];
0N/A
0N/A ClassFileStream* _stream; // Actual input stream
0N/A
0N/A enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
0N/A
0N/A // Accessors
0N/A ClassFileStream* stream() { return _stream; }
0N/A void set_stream(ClassFileStream* st) { _stream = st; }
0N/A
0N/A // Constant pool parsing
0N/A void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
0N/A
0N/A constantPoolHandle parse_constant_pool(TRAPS);
0N/A
0N/A // Interface parsing
0N/A objArrayHandle parse_interfaces(constantPoolHandle cp,
0N/A int length,
0N/A Handle class_loader,
0N/A Handle protection_domain,
0N/A symbolHandle class_name,
0N/A TRAPS);
0N/A
0N/A // Field parsing
0N/A void parse_field_attributes(constantPoolHandle cp, u2 attributes_count,
0N/A bool is_static, u2 signature_index,
0N/A u2* constantvalue_index_addr,
0N/A bool* is_synthetic_addr,
0N/A u2* generic_signature_index_addr,
0N/A typeArrayHandle* field_annotations, TRAPS);
0N/A typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface,
0N/A struct FieldAllocationCount *fac,
0N/A objArrayHandle* fields_annotations, TRAPS);
0N/A
0N/A // Method parsing
0N/A methodHandle parse_method(constantPoolHandle cp, bool is_interface,
0N/A AccessFlags* promoted_flags,
0N/A typeArrayHandle* method_annotations,
0N/A typeArrayHandle* method_parameter_annotations,
0N/A typeArrayHandle* method_default_annotations,
0N/A TRAPS);
0N/A objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface,
0N/A AccessFlags* promoted_flags,
0N/A bool* has_final_method,
0N/A objArrayOop* methods_annotations_oop,
0N/A objArrayOop* methods_parameter_annotations_oop,
0N/A objArrayOop* methods_default_annotations_oop,
0N/A TRAPS);
0N/A typeArrayHandle sort_methods (objArrayHandle methods,
0N/A objArrayHandle methods_annotations,
0N/A objArrayHandle methods_parameter_annotations,
0N/A objArrayHandle methods_default_annotations,
0N/A TRAPS);
0N/A typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length,
0N/A constantPoolHandle cp, TRAPS);
0N/A void parse_linenumber_table(
0N/A u4 code_attribute_length, u4 code_length,
0N/A CompressedLineNumberWriteStream** write_stream, TRAPS);
0N/A u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
0N/A constantPoolHandle cp, u2* localvariable_table_length,
0N/A bool isLVTT, TRAPS);
0N/A u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
0N/A constantPoolHandle cp, TRAPS);
0N/A void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
0N/A u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS);
0N/A typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS);
0N/A
0N/A // Classfile attribute parsing
0N/A void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
0N/A void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
0N/A instanceKlassHandle k, int length, TRAPS);
0N/A u2 parse_classfile_inner_classes_attribute(constantPoolHandle cp,
0N/A instanceKlassHandle k, TRAPS);
0N/A void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
0N/A void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
0N/A void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
0N/A
0N/A // Annotations handling
0N/A typeArrayHandle assemble_annotations(u1* runtime_visible_annotations,
0N/A int runtime_visible_annotations_length,
0N/A u1* runtime_invisible_annotations,
0N/A int runtime_invisible_annotations_length, TRAPS);
0N/A
0N/A // Final setup
939N/A unsigned int compute_oop_map_count(instanceKlassHandle super,
939N/A unsigned int nonstatic_oop_count,
939N/A int first_nonstatic_oop_offset);
939N/A void fill_oop_maps(instanceKlassHandle k,
939N/A unsigned int nonstatic_oop_map_count,
939N/A int* nonstatic_oop_offsets,
939N/A unsigned int* nonstatic_oop_counts);
0N/A void set_precomputed_flags(instanceKlassHandle k);
0N/A objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
0N/A objArrayHandle local_ifs, TRAPS);
0N/A
0N/A // Special handling for certain classes.
0N/A // Add the "discovered" field to java.lang.ref.Reference if
0N/A // it does not exist.
0N/A void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
0N/A constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS);
0N/A // Adjust the field allocation counts for java.lang.Class to add
0N/A // fake fields.
0N/A void java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
0N/A FieldAllocationCount *fac_ptr, TRAPS);
0N/A // Adjust the next_nonstatic_oop_offset to place the fake fields
0N/A // before any Java fields.
0N/A void java_lang_Class_fix_post(int* next_nonstatic_oop_offset);
710N/A // Adjust the field allocation counts for java.dyn.MethodHandle to add
710N/A // a fake address (void*) field.
710N/A void java_dyn_MethodHandle_fix_pre(constantPoolHandle cp,
710N/A typeArrayHandle* fields_ptr,
710N/A FieldAllocationCount *fac_ptr, TRAPS);
0N/A
0N/A // Format checker methods
0N/A void classfile_parse_error(const char* msg, TRAPS);
0N/A void classfile_parse_error(const char* msg, int index, TRAPS);
0N/A void classfile_parse_error(const char* msg, const char *name, TRAPS);
0N/A void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
0N/A inline void guarantee_property(bool b, const char* msg, TRAPS) {
0N/A if (!b) { classfile_parse_error(msg, CHECK); }
0N/A }
0N/A
0N/A inline void assert_property(bool b, const char* msg, TRAPS) {
0N/A#ifdef ASSERT
0N/A if (!b) { fatal(msg); }
0N/A#endif
0N/A }
0N/A
0N/A inline void check_property(bool property, const char* msg, int index, TRAPS) {
0N/A if (_need_verify) {
0N/A guarantee_property(property, msg, index, CHECK);
0N/A } else {
0N/A assert_property(property, msg, CHECK);
0N/A }
0N/A }
0N/A
0N/A inline void check_property(bool property, const char* msg, TRAPS) {
0N/A if (_need_verify) {
0N/A guarantee_property(property, msg, CHECK);
0N/A } else {
0N/A assert_property(property, msg, CHECK);
0N/A }
0N/A }
0N/A
0N/A inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
0N/A if (!b) { classfile_parse_error(msg, index, CHECK); }
0N/A }
0N/A inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
0N/A if (!b) { classfile_parse_error(msg, name, CHECK); }
0N/A }
0N/A inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
0N/A if (!b) { classfile_parse_error(msg, index, name, CHECK); }
0N/A }
0N/A
0N/A bool is_supported_version(u2 major, u2 minor);
0N/A bool has_illegal_visibility(jint flags);
0N/A
0N/A void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
0N/A void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
0N/A void verify_legal_class_name(symbolHandle name, TRAPS);
0N/A void verify_legal_field_name(symbolHandle name, TRAPS);
0N/A void verify_legal_method_name(symbolHandle name, TRAPS);
0N/A void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
0N/A int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
0N/A void verify_legal_class_modifiers(jint flags, TRAPS);
0N/A void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
0N/A void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
0N/A bool verify_unqualified_name(char* name, unsigned int length, int type);
0N/A char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
0N/A char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
0N/A
710N/A bool is_anonymous() {
710N/A assert(AnonymousClasses || _host_klass.is_null(), "");
710N/A return _host_klass.not_null();
710N/A }
431N/A bool has_cp_patch_at(int index) {
431N/A assert(AnonymousClasses, "");
431N/A assert(index >= 0, "oob");
431N/A return (_cp_patches != NULL
431N/A && index < _cp_patches->length()
431N/A && _cp_patches->adr_at(index)->not_null());
431N/A }
431N/A Handle cp_patch_at(int index) {
431N/A assert(has_cp_patch_at(index), "oob");
431N/A return _cp_patches->at(index);
431N/A }
431N/A Handle clear_cp_patch_at(int index) {
431N/A Handle patch = cp_patch_at(index);
431N/A _cp_patches->at_put(index, Handle());
431N/A assert(!has_cp_patch_at(index), "");
431N/A return patch;
431N/A }
431N/A void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS);
431N/A
431N/A // Wrapper for constantTag.is_klass_[or_]reference.
431N/A // In older versions of the VM, klassOops cannot sneak into early phases of
431N/A // constant pool construction, but in later versions they can.
431N/A // %%% Let's phase out the old is_klass_reference.
431N/A bool is_klass_reference(constantPoolHandle cp, int index) {
431N/A return ((LinkWellKnownClasses || AnonymousClasses)
431N/A ? cp->tag_at(index).is_klass_or_reference()
431N/A : cp->tag_at(index).is_klass_reference());
431N/A }
431N/A
0N/A public:
0N/A // Constructor
0N/A ClassFileParser(ClassFileStream* st) { set_stream(st); }
0N/A
0N/A // Parse .class file and return new klassOop. The klassOop is not hooked up
0N/A // to the system dictionary or any other structures, so a .class file can
0N/A // be loaded several times if desired.
0N/A // The system dictionary hookup is done by the caller.
0N/A //
0N/A // "parsed_name" is updated by this method, and is the name found
0N/A // while parsing the stream.
0N/A instanceKlassHandle parseClassFile(symbolHandle name,
0N/A Handle class_loader,
0N/A Handle protection_domain,
0N/A symbolHandle& parsed_name,
973N/A bool verify,
431N/A TRAPS) {
710N/A KlassHandle no_host_klass;
973N/A return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
431N/A }
431N/A instanceKlassHandle parseClassFile(symbolHandle name,
431N/A Handle class_loader,
431N/A Handle protection_domain,
710N/A KlassHandle host_klass,
431N/A GrowableArray<Handle>* cp_patches,
431N/A symbolHandle& parsed_name,
973N/A bool verify,
0N/A TRAPS);
0N/A
0N/A // Verifier checks
0N/A static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
0N/A static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
0N/A static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
0N/A static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
0N/A};