14 *
15 * You should have received a copy of the GNU General Public License version
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 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "classfile/classLoaderData.inline.hpp"
30 #include "classfile/defaultMethods.hpp"
31 #include "classfile/javaClasses.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #include "classfile/verificationType.hpp"
35 #include "classfile/verifier.hpp"
36 #include "classfile/vmSymbols.hpp"
37 #include "memory/allocation.hpp"
38 #include "memory/gcLocker.hpp"
39 #include "memory/metadataFactory.hpp"
40 #include "memory/oopFactory.hpp"
41 #include "memory/referenceType.hpp"
42 #include "memory/universe.inline.hpp"
43 #include "oops/constantPool.hpp"
44 #include "oops/fieldStreams.hpp"
45 #include "oops/instanceKlass.hpp"
46 #include "oops/instanceMirrorKlass.hpp"
47 #include "oops/klass.inline.hpp"
48 #include "oops/klassVtable.hpp"
49 #include "oops/method.hpp"
50 #include "oops/symbol.hpp"
51 #include "prims/jvm.h"
52 #include "prims/jvmtiExport.hpp"
53 #include "prims/jvmtiThreadState.hpp"
54 #include "runtime/javaCalls.hpp"
55 #include "runtime/perfData.hpp"
56 #include "runtime/reflection.hpp"
57 #include "runtime/signature.hpp"
58 #include "runtime/timer.hpp"
59 #include "services/classLoadingService.hpp"
60 #include "services/threadService.hpp"
61 #include "utilities/array.hpp"
62 #include "utilities/globalDefinitions.hpp"
63
64 // We generally try to create the oops directly when parsing, rather than
65 // allocating temporary data structures and copying the bytes twice. A
66 // temporary area is only needed when parsing utf8 entries in the constant
67 // pool and when parsing line number tables.
68
69 // We add assert in debug mode when class format is not checked.
70
71 #define JAVA_CLASSFILE_MAGIC 0xCAFEBABE
72 #define JAVA_MIN_SUPPORTED_VERSION 45
73 #define JAVA_MAX_SUPPORTED_VERSION 52
74 #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
75
76 // Used for two backward compatibility reasons:
77 // - to check for new additions to the class file format in JDK1.5
78 // - to check for bug fixes in the format checker in JDK1.5
79 #define JAVA_1_5_VERSION 49
80
81 // Used for backward compatibility reasons:
82 // - to check for javac bug fixes that happened after 1.5
3769 unsigned char* end_ptr = cfs->buffer() + cfs->length();
3770
3771 JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain,
3772 &ptr, &end_ptr, &cached_class_file);
3773
3774 if (ptr != cfs->buffer()) {
3775 // JVMTI agent has modified class file data.
3776 // Set new class file stream using JVMTI agent modified
3777 // class file data.
3778 cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source());
3779 set_stream(cfs);
3780 }
3781 }
3782
3783 _host_klass = host_klass;
3784 _cp_patches = cp_patches;
3785
3786 instanceKlassHandle nullHandle;
3787
3788 // Figure out whether we can skip format checking (matching classic VM behavior)
3789 _need_verify = Verifier::should_verify_for(class_loader(), verify);
3790
3791 // Set the verify flag in stream
3792 cfs->set_verify(_need_verify);
3793
3794 // Save the class file name for easier error message printing.
3795 _class_name = (name != NULL) ? name : vmSymbols::unknown_class_name();
3796
3797 cfs->guarantee_more(8, CHECK_(nullHandle)); // magic, major, minor
3798 // Magic value
3799 u4 magic = cfs->get_u4_fast();
3800 guarantee_property(magic == JAVA_CLASSFILE_MAGIC,
3801 "Incompatible magic value %u in class file %s",
3802 magic, CHECK_(nullHandle));
3803
3804 // Version numbers
3805 u2 minor_version = cfs->get_u2_fast();
3806 u2 major_version = cfs->get_u2_fast();
3807
3808 // Check version numbers - we check this even with verifier off
3809 if (!is_supported_version(major_version, minor_version)) {
3810 if (name == NULL) {
3811 Exceptions::fthrow(
3812 THREAD_AND_LOCATION,
3813 vmSymbols::java_lang_UnsupportedClassVersionError(),
3814 "Unsupported class file version %u.%u, "
3815 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
3816 major_version,
3817 minor_version,
3818 JAVA_MAX_SUPPORTED_VERSION,
3819 JAVA_MAX_SUPPORTED_MINOR_VERSION);
3820 } else {
3821 ResourceMark rm(THREAD);
3822 Exceptions::fthrow(
3823 THREAD_AND_LOCATION,
3824 vmSymbols::java_lang_UnsupportedClassVersionError(),
3825 "%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), "
3826 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
3827 name->as_C_string(),
3895 { HandleMark hm(THREAD);
3896
3897 // Checks if name in class file matches requested name
3898 if (name != NULL && class_name != name) {
3899 ResourceMark rm(THREAD);
3900 Exceptions::fthrow(
3901 THREAD_AND_LOCATION,
3902 vmSymbols::java_lang_NoClassDefFoundError(),
3903 "%s (wrong name: %s)",
3904 name->as_C_string(),
3905 class_name->as_C_string()
3906 );
3907 return nullHandle;
3908 }
3909
3910 if (TraceClassLoadingPreorder) {
3911 tty->print("[Loading %s", (name != NULL) ? name->as_klass_external_name() : "NoName");
3912 if (cfs->source() != NULL) tty->print(" from %s", cfs->source());
3913 tty->print_cr("]");
3914 }
3915
3916 u2 super_class_index = cfs->get_u2_fast();
3917 instanceKlassHandle super_klass = parse_super_class(super_class_index,
3918 CHECK_NULL);
3919
3920 // Interfaces
3921 u2 itfs_len = cfs->get_u2_fast();
3922 Array<Klass*>* local_interfaces =
3923 parse_interfaces(itfs_len, protection_domain, _class_name,
3924 &has_default_methods, CHECK_(nullHandle));
3925
3926 u2 java_fields_count = 0;
3927 // Fields (offsets are filled in later)
3928 FieldAllocationCount fac;
3929 Array<u2>* fields = parse_fields(class_name,
3930 access_flags.is_interface(),
3931 &fac, &java_fields_count,
3932 CHECK_(nullHandle));
3933 // Methods
3934 bool has_final_method = false;
|
14 *
15 * You should have received a copy of the GNU General Public License version
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 #include "precompiled.hpp"
26 #include "classfile/classFileParser.hpp"
27 #include "classfile/classLoader.hpp"
28 #include "classfile/classLoaderData.hpp"
29 #include "classfile/classLoaderData.inline.hpp"
30 #include "classfile/defaultMethods.hpp"
31 #include "classfile/javaClasses.hpp"
32 #include "classfile/symbolTable.hpp"
33 #include "classfile/systemDictionary.hpp"
34 #if INCLUDE_CDS
35 #include "classfile/systemDictionaryShared.hpp"
36 #endif
37 #include "classfile/verificationType.hpp"
38 #include "classfile/verifier.hpp"
39 #include "classfile/vmSymbols.hpp"
40 #include "memory/allocation.hpp"
41 #include "memory/gcLocker.hpp"
42 #include "memory/metadataFactory.hpp"
43 #include "memory/oopFactory.hpp"
44 #include "memory/referenceType.hpp"
45 #include "memory/universe.inline.hpp"
46 #include "oops/constantPool.hpp"
47 #include "oops/fieldStreams.hpp"
48 #include "oops/instanceKlass.hpp"
49 #include "oops/instanceMirrorKlass.hpp"
50 #include "oops/klass.inline.hpp"
51 #include "oops/klassVtable.hpp"
52 #include "oops/method.hpp"
53 #include "oops/symbol.hpp"
54 #include "prims/jvm.h"
55 #include "prims/jvmtiExport.hpp"
56 #include "prims/jvmtiThreadState.hpp"
57 #include "runtime/javaCalls.hpp"
58 #include "runtime/perfData.hpp"
59 #include "runtime/reflection.hpp"
60 #include "runtime/signature.hpp"
61 #include "runtime/timer.hpp"
62 #include "services/classLoadingService.hpp"
63 #include "services/threadService.hpp"
64 #include "utilities/array.hpp"
65 #include "utilities/globalDefinitions.hpp"
66 #include "utilities/ostream.hpp"
67
68 // We generally try to create the oops directly when parsing, rather than
69 // allocating temporary data structures and copying the bytes twice. A
70 // temporary area is only needed when parsing utf8 entries in the constant
71 // pool and when parsing line number tables.
72
73 // We add assert in debug mode when class format is not checked.
74
75 #define JAVA_CLASSFILE_MAGIC 0xCAFEBABE
76 #define JAVA_MIN_SUPPORTED_VERSION 45
77 #define JAVA_MAX_SUPPORTED_VERSION 52
78 #define JAVA_MAX_SUPPORTED_MINOR_VERSION 0
79
80 // Used for two backward compatibility reasons:
81 // - to check for new additions to the class file format in JDK1.5
82 // - to check for bug fixes in the format checker in JDK1.5
83 #define JAVA_1_5_VERSION 49
84
85 // Used for backward compatibility reasons:
86 // - to check for javac bug fixes that happened after 1.5
3773 unsigned char* end_ptr = cfs->buffer() + cfs->length();
3774
3775 JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain,
3776 &ptr, &end_ptr, &cached_class_file);
3777
3778 if (ptr != cfs->buffer()) {
3779 // JVMTI agent has modified class file data.
3780 // Set new class file stream using JVMTI agent modified
3781 // class file data.
3782 cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source());
3783 set_stream(cfs);
3784 }
3785 }
3786
3787 _host_klass = host_klass;
3788 _cp_patches = cp_patches;
3789
3790 instanceKlassHandle nullHandle;
3791
3792 // Figure out whether we can skip format checking (matching classic VM behavior)
3793 if (DumpSharedSpaces) {
3794 // verify == true means it's a 'remote' class (i.e., non-boot class)
3795 // Verification decision is based on BytecodeVerificationRemote flag
3796 // for those classes.
3797 _need_verify = (verify) ? BytecodeVerificationRemote :
3798 BytecodeVerificationLocal;
3799 } else {
3800 _need_verify = Verifier::should_verify_for(class_loader(), verify);
3801 }
3802
3803 // Set the verify flag in stream
3804 cfs->set_verify(_need_verify);
3805
3806 // Save the class file name for easier error message printing.
3807 _class_name = (name != NULL) ? name : vmSymbols::unknown_class_name();
3808
3809 cfs->guarantee_more(8, CHECK_(nullHandle)); // magic, major, minor
3810 // Magic value
3811 u4 magic = cfs->get_u4_fast();
3812 guarantee_property(magic == JAVA_CLASSFILE_MAGIC,
3813 "Incompatible magic value %u in class file %s",
3814 magic, CHECK_(nullHandle));
3815
3816 // Version numbers
3817 u2 minor_version = cfs->get_u2_fast();
3818 u2 major_version = cfs->get_u2_fast();
3819
3820 if (DumpSharedSpaces && major_version < JAVA_1_5_VERSION) {
3821 ResourceMark rm;
3822 warning("Pre JDK 1.5 class not supported by CDS: %u.%u %s",
3823 major_version, minor_version, name->as_C_string());
3824 Exceptions::fthrow(
3825 THREAD_AND_LOCATION,
3826 vmSymbols::java_lang_UnsupportedClassVersionError(),
3827 "Unsupported major.minor version for dump time %u.%u",
3828 major_version,
3829 minor_version);
3830 }
3831
3832 // Check version numbers - we check this even with verifier off
3833 if (!is_supported_version(major_version, minor_version)) {
3834 if (name == NULL) {
3835 Exceptions::fthrow(
3836 THREAD_AND_LOCATION,
3837 vmSymbols::java_lang_UnsupportedClassVersionError(),
3838 "Unsupported class file version %u.%u, "
3839 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
3840 major_version,
3841 minor_version,
3842 JAVA_MAX_SUPPORTED_VERSION,
3843 JAVA_MAX_SUPPORTED_MINOR_VERSION);
3844 } else {
3845 ResourceMark rm(THREAD);
3846 Exceptions::fthrow(
3847 THREAD_AND_LOCATION,
3848 vmSymbols::java_lang_UnsupportedClassVersionError(),
3849 "%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), "
3850 "this version of the Java Runtime only recognizes class file versions up to %u.%u",
3851 name->as_C_string(),
3919 { HandleMark hm(THREAD);
3920
3921 // Checks if name in class file matches requested name
3922 if (name != NULL && class_name != name) {
3923 ResourceMark rm(THREAD);
3924 Exceptions::fthrow(
3925 THREAD_AND_LOCATION,
3926 vmSymbols::java_lang_NoClassDefFoundError(),
3927 "%s (wrong name: %s)",
3928 name->as_C_string(),
3929 class_name->as_C_string()
3930 );
3931 return nullHandle;
3932 }
3933
3934 if (TraceClassLoadingPreorder) {
3935 tty->print("[Loading %s", (name != NULL) ? name->as_klass_external_name() : "NoName");
3936 if (cfs->source() != NULL) tty->print(" from %s", cfs->source());
3937 tty->print_cr("]");
3938 }
3939 #if INCLUDE_CDS
3940 if (DumpLoadedClassList != NULL && cfs->source() != NULL && classlist_file->is_open()) {
3941 // Only dump the classes that can be stored into CDS archive
3942 if (SystemDictionaryShared::is_sharing_possible(loader_data)) {
3943 if (name != NULL) {
3944 ResourceMark rm(THREAD);
3945 classlist_file->print_cr("%s", name->as_C_string());
3946 classlist_file->flush();
3947 }
3948 }
3949 }
3950 #endif
3951
3952 u2 super_class_index = cfs->get_u2_fast();
3953 instanceKlassHandle super_klass = parse_super_class(super_class_index,
3954 CHECK_NULL);
3955
3956 // Interfaces
3957 u2 itfs_len = cfs->get_u2_fast();
3958 Array<Klass*>* local_interfaces =
3959 parse_interfaces(itfs_len, protection_domain, _class_name,
3960 &has_default_methods, CHECK_(nullHandle));
3961
3962 u2 java_fields_count = 0;
3963 // Fields (offsets are filled in later)
3964 FieldAllocationCount fac;
3965 Array<u2>* fields = parse_fields(class_name,
3966 access_flags.is_interface(),
3967 &fac, &java_fields_count,
3968 CHECK_(nullHandle));
3969 // Methods
3970 bool has_final_method = false;
|