classFileParser.hpp revision 1879
4ed92248676a091e0d73db61773d9059b36d0861stoddard * Copyright (c) 1997, 2010, Oracle and/or its affiliates. All rights reserved.
4ed92248676a091e0d73db61773d9059b36d0861stoddard * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4ed92248676a091e0d73db61773d9059b36d0861stoddard * This code is free software; you can redistribute it and/or modify it
4ed92248676a091e0d73db61773d9059b36d0861stoddard * under the terms of the GNU General Public License version 2 only, as
4ed92248676a091e0d73db61773d9059b36d0861stoddard * published by the Free Software Foundation.
4ed92248676a091e0d73db61773d9059b36d0861stoddard * This code is distributed in the hope that it will be useful, but WITHOUT
4ed92248676a091e0d73db61773d9059b36d0861stoddard * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
b4b458e66e24979631466a69c4bae3090a7e50fewrowe * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
4ed92248676a091e0d73db61773d9059b36d0861stoddard * version 2 for more details (a copy is included in the LICENSE file that
fa29e798c69385995c601ddfe75cbd5cf29244efwrowe * accompanied this code).
fa29e798c69385995c601ddfe75cbd5cf29244efwrowe * You should have received a copy of the GNU General Public License version
071646a05417cc437fcffec9512588f75bd39a03wrowe * 2 along with this work; if not, write to the Free Software Foundation,
fa29e798c69385995c601ddfe75cbd5cf29244efwrowe * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
fa29e798c69385995c601ddfe75cbd5cf29244efwrowe * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
9d134be9b7d1d6f0f9e910346a8075dac77b3d69ianh * or visit www.oracle.com if you need additional information or have any
fa29e798c69385995c601ddfe75cbd5cf29244efwrowe * questions.
0ea0379ff6438182ac3c9d8f108deb3c82210319wrowe// Parser for for .class files
c71d15c4b41b9d89e90e936d49b4e5a6db19244ewrowe// The bytes describing the class file structure is read from a Stream object
6166dacd3c3d034394c1f8c131919ea7452835a7wrowe GrowableArray<Handle>* _cp_patches; // overrides for CP entries
743aeb835754aadabaec38c00742899668eb9dd1wrowe enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names
a78b700fa90213df137e4178a9bd9c81aadd39d3wrowe // Accessors
b56ce33e3fe5670a4562de222c60ade06fe1bce0wrowe void set_stream(ClassFileStream* st) { _stream = st; }
945f023c83c2d18bf5145a5b9af48fc3216fbef6wrowe // Constant pool parsing
549b1f3d6860ae792e6a8c8d3a483140bdb857a5wrowe void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS);
945f023c83c2d18bf5145a5b9af48fc3216fbef6wrowe static int start_operand_group(GrowableArray<int>* &operands, int op_count, TRAPS);
a8f3504993ae9a401b6fc87c7a00b716b112e3d0wrowe static void store_operand_array(GrowableArray<int>* operands, constantPoolHandle cp, TRAPS);
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe // Interface parsing
b4b458e66e24979631466a69c4bae3090a7e50fewrowe objArrayHandle parse_interfaces(constantPoolHandle cp,
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe // Field parsing
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe void parse_field_attributes(constantPoolHandle cp, u2 attributes_count,
fa3f183306fa2ec98249f2afec904d403643a015wrowe typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface,
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe // Method parsing
549b1f3d6860ae792e6a8c8d3a483140bdb857a5wrowe methodHandle parse_method(constantPoolHandle cp, bool is_interface,
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface,
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length,
f397bb616fba8b3a5a9b3c57a5c89ad0e254b673mturk CompressedLineNumberWriteStream** write_stream, TRAPS);
9d134be9b7d1d6f0f9e910346a8075dac77b3d69ianh u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length,
6b441c81aae632befd971e634b4a36780c71d18ewrowe constantPoolHandle cp, u2* localvariable_table_length,
6b441c81aae632befd971e634b4a36780c71d18ewrowe u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length,
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index,
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS);
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS);
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe // Classfile attribute parsing
6b441c81aae632befd971e634b4a36780c71d18ewrowe void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
6b441c81aae632befd971e634b4a36780c71d18ewrowe void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp,
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe u2 parse_classfile_inner_classes_attribute(constantPoolHandle cp,
ea0acbc141b3ca2ef21666bd23bfea9af9a758aawrowe void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
9cef38b3a87190d0c4dcd5b389573418af9de73cwrowe void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS);
4ed92248676a091e0d73db61773d9059b36d0861stoddard // Annotations handling
50feafa397d01128b8cf94ad1602d3d78e1a4169wrowe typeArrayHandle assemble_annotations(u1* runtime_visible_annotations,
ea0acbc141b3ca2ef21666bd23bfea9af9a758aawrowe // Final setup
ea0acbc141b3ca2ef21666bd23bfea9af9a758aawrowe unsigned int compute_oop_map_count(instanceKlassHandle super,
98086904a5df1d6127b49bf06af39f23ff844889wrowe unsigned int* nonstatic_oop_counts);
b4b458e66e24979631466a69c4bae3090a7e50fewrowe objArrayHandle compute_transitive_interfaces(instanceKlassHandle super,
b4b458e66e24979631466a69c4bae3090a7e50fewrowe // Special handling for certain classes.
4ed92248676a091e0d73db61773d9059b36d0861stoddard // Add the "discovered" field to java.lang.ref.Reference if
549b1f3d6860ae792e6a8c8d3a483140bdb857a5wrowe // it does not exist.
4ed92248676a091e0d73db61773d9059b36d0861stoddard void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr,
4ed92248676a091e0d73db61773d9059b36d0861stoddard constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS);
549b1f3d6860ae792e6a8c8d3a483140bdb857a5wrowe // Adjust the field allocation counts for java.lang.Class to add
4ed92248676a091e0d73db61773d9059b36d0861stoddard // fake fields.
4ed92248676a091e0d73db61773d9059b36d0861stoddard void java_lang_Class_fix_pre(objArrayHandle* methods_ptr,
4ed92248676a091e0d73db61773d9059b36d0861stoddard // Adjust the next_nonstatic_oop_offset to place the fake fields
4ed92248676a091e0d73db61773d9059b36d0861stoddard // before any Java fields.
549b1f3d6860ae792e6a8c8d3a483140bdb857a5wrowe void java_lang_Class_fix_post(int* next_nonstatic_oop_offset);
4ed92248676a091e0d73db61773d9059b36d0861stoddard // Adjust the field allocation counts for java.dyn.MethodHandle to add
945f023c83c2d18bf5145a5b9af48fc3216fbef6wrowe // a fake address (void*) field.
90f3e85cc3332e202aa198786798709fc55505d9wrowe void java_dyn_MethodHandle_fix_pre(constantPoolHandle cp,
14d27a22a8fdb25e6e82d8af853a63bd4c6bd894wrowe // Format checker methods
b4b458e66e24979631466a69c4bae3090a7e50fewrowe void classfile_parse_error(const char* msg, int index, TRAPS);
50feafa397d01128b8cf94ad1602d3d78e1a4169wrowe void classfile_parse_error(const char* msg, const char *name, TRAPS);
4ed92248676a091e0d73db61773d9059b36d0861stoddard void classfile_parse_error(const char* msg, int index, const char *name, TRAPS);
4ed92248676a091e0d73db61773d9059b36d0861stoddard inline void guarantee_property(bool b, const char* msg, TRAPS) {
4ed92248676a091e0d73db61773d9059b36d0861stoddard inline void assert_property(bool b, const char* msg, TRAPS) {
0ea0379ff6438182ac3c9d8f108deb3c82210319wrowe inline void check_property(bool property, const char* msg, int index, TRAPS) {
d7f2b79379c5a3b849bf3d5dacf7180805ecba1fwrowe inline void check_property(bool property, const char* msg, TRAPS) {
1e83c8de3aa48b316b28057d53995272baf1260cwrowe inline void guarantee_property(bool b, const char* msg, int index, TRAPS) {
1e83c8de3aa48b316b28057d53995272baf1260cwrowe inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) {
1e83c8de3aa48b316b28057d53995272baf1260cwrowe inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) {
1e83c8de3aa48b316b28057d53995272baf1260cwrowe if (!b) { classfile_parse_error(msg, index, name, CHECK); }
4ed92248676a091e0d73db61773d9059b36d0861stoddard const char* type, symbolHandle name, symbolHandle sig, TRAPS);
6a5b8f7bd9abe819babda806a7245a31cd0dd2fbwrowe void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS);
6a5b8f7bd9abe819babda806a7245a31cd0dd2fbwrowe void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS);
9106bbba512da6e81bb4feb268bbd17435354d79wrowe void verify_legal_class_name(symbolHandle name, TRAPS);
9106bbba512da6e81bb4feb268bbd17435354d79wrowe void verify_legal_field_name(symbolHandle name, TRAPS);
9106bbba512da6e81bb4feb268bbd17435354d79wrowe void verify_legal_method_name(symbolHandle name, TRAPS);
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS);
f71283367c234bf49ddc8ba7b23d3d3829db0d8dmturk int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS);
1a1462ebfd091853d54071a693fc7ad4c5573f8awrowe void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS);
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS);
bc21ce13cec2409c8fdb7122154636b2df97715ajerenkrantz bool verify_unqualified_name(char* name, unsigned int length, int type);
34e753c9dba1e821f54f0d4179f8774f854123eecolm char* skip_over_field_name(char* name, bool slash_ok, unsigned int length);
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS);
14d5b1a7866541c4eb974f2d213d2aea59743c95wrowe assert(AnonymousClasses || _host_klass.is_null(), "");
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS);
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe // Wrapper for constantTag.is_klass_[or_]reference.
0f488df653e7e8cf4ee0006a3138f9474ca1d375wrowe // In older versions of the VM, klassOops cannot sneak into early phases of
538b2b76902ad0b42b4fb2c8ace94bf74d8100cewrowe // constant pool construction, but in later versions they can.
538b2b76902ad0b42b4fb2c8ace94bf74d8100cewrowe // %%% Let's phase out the old is_klass_reference.
538b2b76902ad0b42b4fb2c8ace94bf74d8100cewrowe bool is_klass_reference(constantPoolHandle cp, int index) {
60f8e9cbbfc2d757c71db17a35acb8566eebc0dawrowe // Constructor
255d4d329b2d41e4ac0c3ade5cfe528a078ef682wrowe ClassFileParser(ClassFileStream* st) { set_stream(st); }
1e83c8de3aa48b316b28057d53995272baf1260cwrowe // Parse .class file and return new klassOop. The klassOop is not hooked up
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe // to the system dictionary or any other structures, so a .class file can
1e83c8de3aa48b316b28057d53995272baf1260cwrowe // be loaded several times if desired.
1e83c8de3aa48b316b28057d53995272baf1260cwrowe // The system dictionary hookup is done by the caller.
1e83c8de3aa48b316b28057d53995272baf1260cwrowe // "parsed_name" is updated by this method, and is the name found
1e83c8de3aa48b316b28057d53995272baf1260cwrowe // while parsing the stream.
5a51653135041ee35b24fa67453bff4e9f8e3591wrowe return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
995f5596d461cdd916f9ae5b7b4dcd27efbc3c2fwrowe // Verifier checks
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
0b64c3e5c7379284f90efc7193f16b373df39fe1wrowe static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
1e83c8de3aa48b316b28057d53995272baf1260cwrowe static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
1e83c8de3aa48b316b28057d53995272baf1260cwrowe static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
3ea7933c5a74b8d8d54ec2689190a865a0689420wrowe#endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP