Mercurial > hg > graal-compiler
annotate src/share/vm/classfile/classFileParser.hpp @ 1662:e0ba4e04c839
6969574: invokedynamic call sites deoptimize instead of executing
Reviewed-by: kvn
author | jrose |
---|---|
date | Fri, 16 Jul 2010 18:14:19 -0700 |
parents | 3a9de63b2209 |
children | d2e35ffae982 |
rev | line source |
---|---|
0 | 1 /* |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
974
diff
changeset
|
2 * Copyright (c) 1997, 2009, Oracle and/or its affiliates. All rights reserved. |
0 | 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 * | |
1552
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
974
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
974
diff
changeset
|
20 * or visit www.oracle.com if you need additional information or have any |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
974
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
25 // Parser for for .class files | |
26 // | |
27 // The bytes describing the class file structure is read from a Stream object | |
28 | |
29 class ClassFileParser VALUE_OBJ_CLASS_SPEC { | |
30 private: | |
31 bool _need_verify; | |
32 bool _relax_verify; | |
33 u2 _major_version; | |
34 u2 _minor_version; | |
35 symbolHandle _class_name; | |
710 | 36 KlassHandle _host_klass; |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
37 GrowableArray<Handle>* _cp_patches; // overrides for CP entries |
0 | 38 |
39 bool _has_finalizer; | |
40 bool _has_empty_finalizer; | |
41 bool _has_vanilla_constructor; | |
42 | |
43 enum { fixed_buffer_size = 128 }; | |
44 u_char linenumbertable_buffer[fixed_buffer_size]; | |
45 | |
46 ClassFileStream* _stream; // Actual input stream | |
47 | |
48 enum { LegalClass, LegalField, LegalMethod }; // used to verify unqualified names | |
49 | |
50 // Accessors | |
51 ClassFileStream* stream() { return _stream; } | |
52 void set_stream(ClassFileStream* st) { _stream = st; } | |
53 | |
54 // Constant pool parsing | |
55 void parse_constant_pool_entries(constantPoolHandle cp, int length, TRAPS); | |
56 | |
57 constantPoolHandle parse_constant_pool(TRAPS); | |
58 | |
59 // Interface parsing | |
60 objArrayHandle parse_interfaces(constantPoolHandle cp, | |
61 int length, | |
62 Handle class_loader, | |
63 Handle protection_domain, | |
64 symbolHandle class_name, | |
65 TRAPS); | |
66 | |
67 // Field parsing | |
68 void parse_field_attributes(constantPoolHandle cp, u2 attributes_count, | |
69 bool is_static, u2 signature_index, | |
70 u2* constantvalue_index_addr, | |
71 bool* is_synthetic_addr, | |
72 u2* generic_signature_index_addr, | |
73 typeArrayHandle* field_annotations, TRAPS); | |
74 typeArrayHandle parse_fields(constantPoolHandle cp, bool is_interface, | |
75 struct FieldAllocationCount *fac, | |
76 objArrayHandle* fields_annotations, TRAPS); | |
77 | |
78 // Method parsing | |
79 methodHandle parse_method(constantPoolHandle cp, bool is_interface, | |
80 AccessFlags* promoted_flags, | |
81 typeArrayHandle* method_annotations, | |
82 typeArrayHandle* method_parameter_annotations, | |
83 typeArrayHandle* method_default_annotations, | |
84 TRAPS); | |
85 objArrayHandle parse_methods (constantPoolHandle cp, bool is_interface, | |
86 AccessFlags* promoted_flags, | |
87 bool* has_final_method, | |
88 objArrayOop* methods_annotations_oop, | |
89 objArrayOop* methods_parameter_annotations_oop, | |
90 objArrayOop* methods_default_annotations_oop, | |
91 TRAPS); | |
92 typeArrayHandle sort_methods (objArrayHandle methods, | |
93 objArrayHandle methods_annotations, | |
94 objArrayHandle methods_parameter_annotations, | |
95 objArrayHandle methods_default_annotations, | |
96 TRAPS); | |
97 typeArrayHandle parse_exception_table(u4 code_length, u4 exception_table_length, | |
98 constantPoolHandle cp, TRAPS); | |
99 void parse_linenumber_table( | |
100 u4 code_attribute_length, u4 code_length, | |
101 CompressedLineNumberWriteStream** write_stream, TRAPS); | |
102 u2* parse_localvariable_table(u4 code_length, u2 max_locals, u4 code_attribute_length, | |
103 constantPoolHandle cp, u2* localvariable_table_length, | |
104 bool isLVTT, TRAPS); | |
105 u2* parse_checked_exceptions(u2* checked_exceptions_length, u4 method_attribute_length, | |
106 constantPoolHandle cp, TRAPS); | |
107 void parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, | |
108 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS); | |
109 typeArrayOop parse_stackmap_table(u4 code_attribute_length, TRAPS); | |
110 | |
111 // Classfile attribute parsing | |
112 void parse_classfile_sourcefile_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | |
113 void parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, | |
114 instanceKlassHandle k, int length, TRAPS); | |
115 u2 parse_classfile_inner_classes_attribute(constantPoolHandle cp, | |
116 instanceKlassHandle k, TRAPS); | |
117 void parse_classfile_attributes(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | |
118 void parse_classfile_synthetic_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | |
119 void parse_classfile_signature_attribute(constantPoolHandle cp, instanceKlassHandle k, TRAPS); | |
120 | |
121 // Annotations handling | |
122 typeArrayHandle assemble_annotations(u1* runtime_visible_annotations, | |
123 int runtime_visible_annotations_length, | |
124 u1* runtime_invisible_annotations, | |
125 int runtime_invisible_annotations_length, TRAPS); | |
126 | |
127 // Final setup | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
128 unsigned int compute_oop_map_count(instanceKlassHandle super, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
129 unsigned int nonstatic_oop_count, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
130 int first_nonstatic_oop_offset); |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
131 void fill_oop_maps(instanceKlassHandle k, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
132 unsigned int nonstatic_oop_map_count, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
133 int* nonstatic_oop_offsets, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
134 unsigned int* nonstatic_oop_counts); |
0 | 135 void set_precomputed_flags(instanceKlassHandle k); |
136 objArrayHandle compute_transitive_interfaces(instanceKlassHandle super, | |
137 objArrayHandle local_ifs, TRAPS); | |
138 | |
139 // Special handling for certain classes. | |
140 // Add the "discovered" field to java.lang.ref.Reference if | |
141 // it does not exist. | |
142 void java_lang_ref_Reference_fix_pre(typeArrayHandle* fields_ptr, | |
143 constantPoolHandle cp, FieldAllocationCount *fac_ptr, TRAPS); | |
144 // Adjust the field allocation counts for java.lang.Class to add | |
145 // fake fields. | |
146 void java_lang_Class_fix_pre(objArrayHandle* methods_ptr, | |
147 FieldAllocationCount *fac_ptr, TRAPS); | |
148 // Adjust the next_nonstatic_oop_offset to place the fake fields | |
149 // before any Java fields. | |
150 void java_lang_Class_fix_post(int* next_nonstatic_oop_offset); | |
710 | 151 // Adjust the field allocation counts for java.dyn.MethodHandle to add |
152 // a fake address (void*) field. | |
153 void java_dyn_MethodHandle_fix_pre(constantPoolHandle cp, | |
154 typeArrayHandle* fields_ptr, | |
155 FieldAllocationCount *fac_ptr, TRAPS); | |
0 | 156 |
157 // Format checker methods | |
158 void classfile_parse_error(const char* msg, TRAPS); | |
159 void classfile_parse_error(const char* msg, int index, TRAPS); | |
160 void classfile_parse_error(const char* msg, const char *name, TRAPS); | |
161 void classfile_parse_error(const char* msg, int index, const char *name, TRAPS); | |
162 inline void guarantee_property(bool b, const char* msg, TRAPS) { | |
163 if (!b) { classfile_parse_error(msg, CHECK); } | |
164 } | |
165 | |
166 inline void assert_property(bool b, const char* msg, TRAPS) { | |
167 #ifdef ASSERT | |
168 if (!b) { fatal(msg); } | |
169 #endif | |
170 } | |
171 | |
172 inline void check_property(bool property, const char* msg, int index, TRAPS) { | |
173 if (_need_verify) { | |
174 guarantee_property(property, msg, index, CHECK); | |
175 } else { | |
176 assert_property(property, msg, CHECK); | |
177 } | |
178 } | |
179 | |
180 inline void check_property(bool property, const char* msg, TRAPS) { | |
181 if (_need_verify) { | |
182 guarantee_property(property, msg, CHECK); | |
183 } else { | |
184 assert_property(property, msg, CHECK); | |
185 } | |
186 } | |
187 | |
188 inline void guarantee_property(bool b, const char* msg, int index, TRAPS) { | |
189 if (!b) { classfile_parse_error(msg, index, CHECK); } | |
190 } | |
191 inline void guarantee_property(bool b, const char* msg, const char *name, TRAPS) { | |
192 if (!b) { classfile_parse_error(msg, name, CHECK); } | |
193 } | |
194 inline void guarantee_property(bool b, const char* msg, int index, const char *name, TRAPS) { | |
195 if (!b) { classfile_parse_error(msg, index, name, CHECK); } | |
196 } | |
197 | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
974
diff
changeset
|
198 void throwIllegalSignature( |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
974
diff
changeset
|
199 const char* type, symbolHandle name, symbolHandle sig, TRAPS); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
974
diff
changeset
|
200 |
0 | 201 bool is_supported_version(u2 major, u2 minor); |
202 bool has_illegal_visibility(jint flags); | |
203 | |
204 void verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS); | |
205 void verify_legal_utf8(const unsigned char* buffer, int length, TRAPS); | |
206 void verify_legal_class_name(symbolHandle name, TRAPS); | |
207 void verify_legal_field_name(symbolHandle name, TRAPS); | |
208 void verify_legal_method_name(symbolHandle name, TRAPS); | |
209 void verify_legal_field_signature(symbolHandle fieldname, symbolHandle signature, TRAPS); | |
210 int verify_legal_method_signature(symbolHandle methodname, symbolHandle signature, TRAPS); | |
211 void verify_legal_class_modifiers(jint flags, TRAPS); | |
212 void verify_legal_field_modifiers(jint flags, bool is_interface, TRAPS); | |
213 void verify_legal_method_modifiers(jint flags, bool is_interface, symbolHandle name, TRAPS); | |
214 bool verify_unqualified_name(char* name, unsigned int length, int type); | |
215 char* skip_over_field_name(char* name, bool slash_ok, unsigned int length); | |
216 char* skip_over_field_signature(char* signature, bool void_ok, unsigned int length, TRAPS); | |
217 | |
710 | 218 bool is_anonymous() { |
219 assert(AnonymousClasses || _host_klass.is_null(), ""); | |
220 return _host_klass.not_null(); | |
221 } | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
222 bool has_cp_patch_at(int index) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
223 assert(AnonymousClasses, ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
224 assert(index >= 0, "oob"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
225 return (_cp_patches != NULL |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
226 && index < _cp_patches->length() |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
227 && _cp_patches->adr_at(index)->not_null()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
228 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
229 Handle cp_patch_at(int index) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
230 assert(has_cp_patch_at(index), "oob"); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
231 return _cp_patches->at(index); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
232 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
233 Handle clear_cp_patch_at(int index) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
234 Handle patch = cp_patch_at(index); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
235 _cp_patches->at_put(index, Handle()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
236 assert(!has_cp_patch_at(index), ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
237 return patch; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
238 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
239 void patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
240 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
241 // Wrapper for constantTag.is_klass_[or_]reference. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
242 // In older versions of the VM, klassOops cannot sneak into early phases of |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
243 // constant pool construction, but in later versions they can. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
244 // %%% Let's phase out the old is_klass_reference. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
245 bool is_klass_reference(constantPoolHandle cp, int index) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
246 return ((LinkWellKnownClasses || AnonymousClasses) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
247 ? cp->tag_at(index).is_klass_or_reference() |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
248 : cp->tag_at(index).is_klass_reference()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
249 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
250 |
0 | 251 public: |
252 // Constructor | |
253 ClassFileParser(ClassFileStream* st) { set_stream(st); } | |
254 | |
255 // Parse .class file and return new klassOop. The klassOop is not hooked up | |
256 // to the system dictionary or any other structures, so a .class file can | |
257 // be loaded several times if desired. | |
258 // The system dictionary hookup is done by the caller. | |
259 // | |
260 // "parsed_name" is updated by this method, and is the name found | |
261 // while parsing the stream. | |
262 instanceKlassHandle parseClassFile(symbolHandle name, | |
263 Handle class_loader, | |
264 Handle protection_domain, | |
265 symbolHandle& parsed_name, | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
266 bool verify, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
267 TRAPS) { |
710 | 268 KlassHandle no_host_klass; |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
269 return parseClassFile(name, class_loader, protection_domain, no_host_klass, NULL, parsed_name, verify, THREAD); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
270 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
271 instanceKlassHandle parseClassFile(symbolHandle name, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
272 Handle class_loader, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
273 Handle protection_domain, |
710 | 274 KlassHandle host_klass, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
275 GrowableArray<Handle>* cp_patches, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
0
diff
changeset
|
276 symbolHandle& parsed_name, |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
875
diff
changeset
|
277 bool verify, |
0 | 278 TRAPS); |
279 | |
280 // Verifier checks | |
281 static void check_super_class_access(instanceKlassHandle this_klass, TRAPS); | |
282 static void check_super_interface_access(instanceKlassHandle this_klass, TRAPS); | |
283 static void check_final_method_override(instanceKlassHandle this_klass, TRAPS); | |
284 static void check_illegal_static_method(instanceKlassHandle this_klass, TRAPS); | |
285 }; |