1 /*
2 * Copyright (c) 1997, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
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 *
30 #include "oops/oop.inline.hpp"
31 #include "oops/typeArrayOop.hpp"
32 #include "runtime/handles.inline.hpp"
33 #include "utilities/accessFlags.hpp"
34 #include "classfile/symbolTable.hpp"
35
36 class FieldAllocationCount;
37 class FieldLayoutInfo;
38
39
40 // Parser for for .class files
41 //
42 // The bytes describing the class file structure is read from a Stream object
43
44 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
45 private:
46 bool _need_verify;
47 bool _relax_verify;
48 u2 _major_version;
49 u2 _minor_version;
50 Symbol* _class_name;
51 ClassLoaderData* _loader_data;
52 KlassHandle _host_klass;
53 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
54
55 // precomputed flags
56 bool _has_finalizer;
57 bool _has_empty_finalizer;
58 bool _has_vanilla_constructor;
59 int _max_bootstrap_specifier_index; // detects BSS values
60
61 // class attributes parsed before the instance klass is created:
62 bool _synthetic_flag;
63 int _sde_length;
64 char* _sde_buffer;
65 u2 _sourcefile_index;
66 u2 _generic_signature_index;
67
68 // Metadata created before the instance klass is created. Must be deallocated
69 // if not transferred to the InstanceKlass upon successful class loading
73 Array<u2>* _fields;
74 Array<Method*>* _methods;
75 Array<u2>* _inner_classes;
76 Array<Klass*>* _local_interfaces;
77 Array<Klass*>* _transitive_interfaces;
78 Annotations* _combined_annotations;
79 AnnotationArray* _annotations;
80 AnnotationArray* _type_annotations;
81 Array<AnnotationArray*>* _fields_annotations;
82 Array<AnnotationArray*>* _fields_type_annotations;
83 InstanceKlass* _klass; // InstanceKlass once created.
84
85 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
86 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
87 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
88 void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; }
89
90 void create_combined_annotations(TRAPS);
91
92 void init_parsed_class_attributes(ClassLoaderData* loader_data) {
93 _loader_data = loader_data;
94 _synthetic_flag = false;
95 _sourcefile_index = 0;
96 _generic_signature_index = 0;
97 _sde_buffer = NULL;
98 _sde_length = 0;
99 // initialize the other flags too:
100 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
101 _max_bootstrap_specifier_index = -1;
102 clear_class_metadata();
103 _klass = NULL;
104 }
105 void apply_parsed_class_attributes(instanceKlassHandle k); // update k
106 void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS);
107 void clear_class_metadata() {
108 // metadata created before the instance klass is created. Must be
109 // deallocated if classfile parsing returns an error.
110 _cp = NULL;
111 _fields = NULL;
112 _methods = NULL;
469 // "parsed_name" is updated by this method, and is the name found
470 // while parsing the stream.
471 instanceKlassHandle parseClassFile(Symbol* name,
472 ClassLoaderData* loader_data,
473 Handle protection_domain,
474 TempNewSymbol& parsed_name,
475 bool verify,
476 TRAPS) {
477 KlassHandle no_host_klass;
478 return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
479 }
480 instanceKlassHandle parseClassFile(Symbol* name,
481 ClassLoaderData* loader_data,
482 Handle protection_domain,
483 KlassHandle host_klass,
484 GrowableArray<Handle>* cp_patches,
485 TempNewSymbol& parsed_name,
486 bool verify,
487 TRAPS);
488
489 // Verifier checks
490 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
491 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
492 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
493 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
494 };
495
496 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
|
1 /*
2 * Copyright (c) 1997, 2019, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation.
8 *
9 * This code is distributed in the hope that it will be useful, but WITHOUT
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 * version 2 for more details (a copy is included in the LICENSE file that
13 * accompanied this code).
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 *
30 #include "oops/oop.inline.hpp"
31 #include "oops/typeArrayOop.hpp"
32 #include "runtime/handles.inline.hpp"
33 #include "utilities/accessFlags.hpp"
34 #include "classfile/symbolTable.hpp"
35
36 class FieldAllocationCount;
37 class FieldLayoutInfo;
38
39
40 // Parser for for .class files
41 //
42 // The bytes describing the class file structure is read from a Stream object
43
44 class ClassFileParser VALUE_OBJ_CLASS_SPEC {
45 private:
46 bool _need_verify;
47 bool _relax_verify;
48 u2 _major_version;
49 u2 _minor_version;
50 u2 _this_class_index;
51 Symbol* _class_name;
52 ClassLoaderData* _loader_data;
53 KlassHandle _host_klass;
54 GrowableArray<Handle>* _cp_patches; // overrides for CP entries
55
56 // precomputed flags
57 bool _has_finalizer;
58 bool _has_empty_finalizer;
59 bool _has_vanilla_constructor;
60 int _max_bootstrap_specifier_index; // detects BSS values
61
62 // class attributes parsed before the instance klass is created:
63 bool _synthetic_flag;
64 int _sde_length;
65 char* _sde_buffer;
66 u2 _sourcefile_index;
67 u2 _generic_signature_index;
68
69 // Metadata created before the instance klass is created. Must be deallocated
70 // if not transferred to the InstanceKlass upon successful class loading
74 Array<u2>* _fields;
75 Array<Method*>* _methods;
76 Array<u2>* _inner_classes;
77 Array<Klass*>* _local_interfaces;
78 Array<Klass*>* _transitive_interfaces;
79 Annotations* _combined_annotations;
80 AnnotationArray* _annotations;
81 AnnotationArray* _type_annotations;
82 Array<AnnotationArray*>* _fields_annotations;
83 Array<AnnotationArray*>* _fields_type_annotations;
84 InstanceKlass* _klass; // InstanceKlass once created.
85
86 void set_class_synthetic_flag(bool x) { _synthetic_flag = x; }
87 void set_class_sourcefile_index(u2 x) { _sourcefile_index = x; }
88 void set_class_generic_signature_index(u2 x) { _generic_signature_index = x; }
89 void set_class_sde_buffer(char* x, int len) { _sde_buffer = x; _sde_length = len; }
90
91 void create_combined_annotations(TRAPS);
92
93 void init_parsed_class_attributes(ClassLoaderData* loader_data) {
94 _this_class_index = 0;
95 _loader_data = loader_data;
96 _synthetic_flag = false;
97 _sourcefile_index = 0;
98 _generic_signature_index = 0;
99 _sde_buffer = NULL;
100 _sde_length = 0;
101 // initialize the other flags too:
102 _has_finalizer = _has_empty_finalizer = _has_vanilla_constructor = false;
103 _max_bootstrap_specifier_index = -1;
104 clear_class_metadata();
105 _klass = NULL;
106 }
107 void apply_parsed_class_attributes(instanceKlassHandle k); // update k
108 void apply_parsed_class_metadata(instanceKlassHandle k, int fields_count, TRAPS);
109 void clear_class_metadata() {
110 // metadata created before the instance klass is created. Must be
111 // deallocated if classfile parsing returns an error.
112 _cp = NULL;
113 _fields = NULL;
114 _methods = NULL;
471 // "parsed_name" is updated by this method, and is the name found
472 // while parsing the stream.
473 instanceKlassHandle parseClassFile(Symbol* name,
474 ClassLoaderData* loader_data,
475 Handle protection_domain,
476 TempNewSymbol& parsed_name,
477 bool verify,
478 TRAPS) {
479 KlassHandle no_host_klass;
480 return parseClassFile(name, loader_data, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD);
481 }
482 instanceKlassHandle parseClassFile(Symbol* name,
483 ClassLoaderData* loader_data,
484 Handle protection_domain,
485 KlassHandle host_klass,
486 GrowableArray<Handle>* cp_patches,
487 TempNewSymbol& parsed_name,
488 bool verify,
489 TRAPS);
490
491 u2 this_class_index() const { return _this_class_index; }
492 const ClassFileStream* clone_stream() const;
493 void set_klass_to_deallocate(InstanceKlass* klass);
494
495 // Verifier checks
496 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS);
497 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS);
498 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS);
499 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS);
500 };
501
502 #endif // SHARE_VM_CLASSFILE_CLASSFILEPARSER_HPP
|