Mercurial > hg > truffle
annotate src/share/vm/classfile/classFileParser.cpp @ 8071:bbc7936779f9
8006398: Add regression tests for deprectated GCs
Reviewed-by: ehelin, jwilhelm, jmasa
author | brutisso |
---|---|
date | Thu, 14 Feb 2013 09:11:43 +0100 |
parents | 927a311d00f9 |
children | 96480359523a |
rev | line source |
---|---|
0 | 1 /* |
7579
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
2 * Copyright (c) 1997, 2013, 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:
1513
diff
changeset
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
c18cbe5936b8
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
1513
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:
1513
diff
changeset
|
21 * questions. |
0 | 22 * |
23 */ | |
24 | |
1972 | 25 #include "precompiled.hpp" |
26 #include "classfile/classFileParser.hpp" | |
27 #include "classfile/classLoader.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
28 #include "classfile/classLoaderData.hpp" |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
29 #include "classfile/classLoaderData.inline.hpp" |
6934 | 30 #include "classfile/defaultMethods.hpp" |
31 #include "classfile/genericSignatures.hpp" | |
1972 | 32 #include "classfile/javaClasses.hpp" |
33 #include "classfile/symbolTable.hpp" | |
34 #include "classfile/systemDictionary.hpp" | |
35 #include "classfile/verificationType.hpp" | |
36 #include "classfile/verifier.hpp" | |
37 #include "classfile/vmSymbols.hpp" | |
38 #include "memory/allocation.hpp" | |
39 #include "memory/gcLocker.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
40 #include "memory/metadataFactory.hpp" |
1972 | 41 #include "memory/oopFactory.hpp" |
42 #include "memory/universe.inline.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
43 #include "oops/constantPool.hpp" |
3938 | 44 #include "oops/fieldStreams.hpp" |
1972 | 45 #include "oops/instanceKlass.hpp" |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
46 #include "oops/instanceMirrorKlass.hpp" |
1972 | 47 #include "oops/klass.inline.hpp" |
48 #include "oops/klassVtable.hpp" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
49 #include "oops/method.hpp" |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
50 #include "oops/symbol.hpp" |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
51 #include "prims/jvm.h" |
1972 | 52 #include "prims/jvmtiExport.hpp" |
4731
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
53 #include "prims/jvmtiThreadState.hpp" |
1972 | 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" | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
61 #include "utilities/array.hpp" |
7588
f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
7579
diff
changeset
|
62 #include "utilities/globalDefinitions.hpp" |
0 | 63 |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
64 // We generally try to create the oops directly when parsing, rather than |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
65 // allocating temporary data structures and copying the bytes twice. A |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
66 // temporary area is only needed when parsing utf8 entries in the constant |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
67 // pool and when parsing line number tables. |
0 | 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 | |
6868 | 73 #define JAVA_MAX_SUPPORTED_VERSION 52 |
0 | 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 | |
176
6b648fefb395
6705523: Fix for 6695506 will violate spec when used in JDK6
kamg
parents:
136
diff
changeset
|
83 // - also used as the max version when running in jdk6 |
0 | 84 #define JAVA_6_VERSION 50 |
85 | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
86 // Used for backward compatibility reasons: |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
87 // - to check NameAndType_info signatures more aggressively |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
88 #define JAVA_7_VERSION 51 |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
89 |
6934 | 90 // Extension method support. |
91 #define JAVA_8_VERSION 52 | |
92 | |
0 | 93 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
94 void ClassFileParser::parse_constant_pool_entries(ClassLoaderData* loader_data, constantPoolHandle cp, int length, TRAPS) { |
0 | 95 // Use a local copy of ClassFileStream. It helps the C++ compiler to optimize |
96 // this function (_current can be allocated in a register, with scalar | |
97 // replacement of aggregates). The _current pointer is copied back to | |
98 // stream() when this function returns. DON'T call another method within | |
99 // this method that uses stream(). | |
100 ClassFileStream* cfs0 = stream(); | |
101 ClassFileStream cfs1 = *cfs0; | |
102 ClassFileStream* cfs = &cfs1; | |
103 #ifdef ASSERT | |
1685 | 104 assert(cfs->allocated_on_stack(),"should be local"); |
0 | 105 u1* old_current = cfs0->current(); |
106 #endif | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
107 Handle class_loader(THREAD, loader_data->class_loader()); |
0 | 108 |
109 // Used for batching symbol allocations. | |
110 const char* names[SymbolTable::symbol_alloc_batch_size]; | |
111 int lengths[SymbolTable::symbol_alloc_batch_size]; | |
112 int indices[SymbolTable::symbol_alloc_batch_size]; | |
113 unsigned int hashValues[SymbolTable::symbol_alloc_batch_size]; | |
114 int names_count = 0; | |
115 | |
116 // parsing Index 0 is unused | |
117 for (int index = 1; index < length; index++) { | |
118 // Each of the following case guarantees one more byte in the stream | |
119 // for the following tag or the access_flags following constant pool, | |
120 // so we don't need bounds-check for reading tag. | |
121 u1 tag = cfs->get_u1_fast(); | |
122 switch (tag) { | |
123 case JVM_CONSTANT_Class : | |
124 { | |
125 cfs->guarantee_more(3, CHECK); // name_index, tag/access_flags | |
126 u2 name_index = cfs->get_u2_fast(); | |
127 cp->klass_index_at_put(index, name_index); | |
128 } | |
129 break; | |
130 case JVM_CONSTANT_Fieldref : | |
131 { | |
132 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags | |
133 u2 class_index = cfs->get_u2_fast(); | |
134 u2 name_and_type_index = cfs->get_u2_fast(); | |
135 cp->field_at_put(index, class_index, name_and_type_index); | |
136 } | |
137 break; | |
138 case JVM_CONSTANT_Methodref : | |
139 { | |
140 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags | |
141 u2 class_index = cfs->get_u2_fast(); | |
142 u2 name_and_type_index = cfs->get_u2_fast(); | |
143 cp->method_at_put(index, class_index, name_and_type_index); | |
144 } | |
145 break; | |
146 case JVM_CONSTANT_InterfaceMethodref : | |
147 { | |
148 cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags | |
149 u2 class_index = cfs->get_u2_fast(); | |
150 u2 name_and_type_index = cfs->get_u2_fast(); | |
151 cp->interface_method_at_put(index, class_index, name_and_type_index); | |
152 } | |
153 break; | |
154 case JVM_CONSTANT_String : | |
155 { | |
156 cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags | |
157 u2 string_index = cfs->get_u2_fast(); | |
158 cp->string_index_at_put(index, string_index); | |
159 } | |
160 break; | |
1602 | 161 case JVM_CONSTANT_MethodHandle : |
162 case JVM_CONSTANT_MethodType : | |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
163 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
1602 | 164 classfile_parse_error( |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
165 "Class file version does not support constant tag %u in class file %s", |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
166 tag, CHECK); |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
167 } |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
168 if (!EnableInvokeDynamic) { |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
169 classfile_parse_error( |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
170 "This JVM does not support constant tag %u in class file %s", |
1602 | 171 tag, CHECK); |
172 } | |
173 if (tag == JVM_CONSTANT_MethodHandle) { | |
174 cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags | |
175 u1 ref_kind = cfs->get_u1_fast(); | |
176 u2 method_index = cfs->get_u2_fast(); | |
177 cp->method_handle_index_at_put(index, ref_kind, method_index); | |
178 } else if (tag == JVM_CONSTANT_MethodType) { | |
179 cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags | |
180 u2 signature_index = cfs->get_u2_fast(); | |
181 cp->method_type_index_at_put(index, signature_index); | |
182 } else { | |
183 ShouldNotReachHere(); | |
184 } | |
185 break; | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
186 case JVM_CONSTANT_InvokeDynamic : |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
187 { |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
188 if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
189 classfile_parse_error( |
2356
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
190 "Class file version does not support constant tag %u in class file %s", |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
191 tag, CHECK); |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
192 } |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
193 if (!EnableInvokeDynamic) { |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
194 classfile_parse_error( |
72dee110246f
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
2334
diff
changeset
|
195 "This JVM does not support constant tag %u in class file %s", |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
196 tag, CHECK); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
197 } |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
198 cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
199 u2 bootstrap_specifier_index = cfs->get_u2_fast(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
200 u2 name_and_type_index = cfs->get_u2_fast(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
201 if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
202 _max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
203 cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
204 } |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
205 break; |
0 | 206 case JVM_CONSTANT_Integer : |
207 { | |
208 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags | |
209 u4 bytes = cfs->get_u4_fast(); | |
210 cp->int_at_put(index, (jint) bytes); | |
211 } | |
212 break; | |
213 case JVM_CONSTANT_Float : | |
214 { | |
215 cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags | |
216 u4 bytes = cfs->get_u4_fast(); | |
217 cp->float_at_put(index, *(jfloat*)&bytes); | |
218 } | |
219 break; | |
220 case JVM_CONSTANT_Long : | |
221 // A mangled type might cause you to overrun allocated memory | |
222 guarantee_property(index+1 < length, | |
223 "Invalid constant pool entry %u in class file %s", | |
224 index, CHECK); | |
225 { | |
226 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags | |
227 u8 bytes = cfs->get_u8_fast(); | |
228 cp->long_at_put(index, bytes); | |
229 } | |
230 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 | |
231 break; | |
232 case JVM_CONSTANT_Double : | |
233 // A mangled type might cause you to overrun allocated memory | |
234 guarantee_property(index+1 < length, | |
235 "Invalid constant pool entry %u in class file %s", | |
236 index, CHECK); | |
237 { | |
238 cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags | |
239 u8 bytes = cfs->get_u8_fast(); | |
240 cp->double_at_put(index, *(jdouble*)&bytes); | |
241 } | |
242 index++; // Skip entry following eigth-byte constant, see JVM book p. 98 | |
243 break; | |
244 case JVM_CONSTANT_NameAndType : | |
245 { | |
246 cfs->guarantee_more(5, CHECK); // name_index, signature_index, tag/access_flags | |
247 u2 name_index = cfs->get_u2_fast(); | |
248 u2 signature_index = cfs->get_u2_fast(); | |
249 cp->name_and_type_at_put(index, name_index, signature_index); | |
250 } | |
251 break; | |
252 case JVM_CONSTANT_Utf8 : | |
253 { | |
254 cfs->guarantee_more(2, CHECK); // utf8_length | |
255 u2 utf8_length = cfs->get_u2_fast(); | |
256 u1* utf8_buffer = cfs->get_u1_buffer(); | |
257 assert(utf8_buffer != NULL, "null utf8 buffer"); | |
258 // Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward. | |
259 cfs->guarantee_more(utf8_length+1, CHECK); // utf8 string, tag/access_flags | |
260 cfs->skip_u1_fast(utf8_length); | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
261 |
0 | 262 // Before storing the symbol, make sure it's legal |
263 if (_need_verify) { | |
264 verify_legal_utf8((unsigned char*)utf8_buffer, utf8_length, CHECK); | |
265 } | |
266 | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
267 if (EnableInvokeDynamic && has_cp_patch_at(index)) { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
268 Handle patch = clear_cp_patch_at(index); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
269 guarantee_property(java_lang_String::is_instance(patch()), |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
270 "Illegal utf8 patch at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
271 index, CHECK); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
272 char* str = java_lang_String::as_utf8_string(patch()); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
273 // (could use java_lang_String::as_symbol instead, but might as well batch them) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
274 utf8_buffer = (u1*) str; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
275 utf8_length = (int) strlen(str); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
276 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
277 |
0 | 278 unsigned int hash; |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
279 Symbol* result = SymbolTable::lookup_only((char*)utf8_buffer, utf8_length, hash); |
0 | 280 if (result == NULL) { |
281 names[names_count] = (char*)utf8_buffer; | |
282 lengths[names_count] = utf8_length; | |
283 indices[names_count] = index; | |
284 hashValues[names_count++] = hash; | |
285 if (names_count == SymbolTable::symbol_alloc_batch_size) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
286 SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); |
0 | 287 names_count = 0; |
288 } | |
289 } else { | |
290 cp->symbol_at_put(index, result); | |
291 } | |
292 } | |
293 break; | |
294 default: | |
295 classfile_parse_error( | |
296 "Unknown constant tag %u in class file %s", tag, CHECK); | |
297 break; | |
298 } | |
299 } | |
300 | |
301 // Allocate the remaining symbols | |
302 if (names_count > 0) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
303 SymbolTable::new_symbols(loader_data, cp, names_count, names, lengths, indices, hashValues, CHECK); |
0 | 304 } |
305 | |
306 // Copy _current pointer of local copy back to stream(). | |
307 #ifdef ASSERT | |
308 assert(cfs0->current() == old_current, "non-exclusive use of stream()"); | |
309 #endif | |
310 cfs0->set_current(cfs1.current()); | |
311 } | |
312 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
313 // This class unreferences constant pool symbols if an error has occurred |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
314 // while parsing the class before it is assigned into the class. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
315 // If it gets an error after that it is unloaded and the constant pool will |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
316 // be cleaned up then. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
317 class ConstantPoolCleaner : public StackObj { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
318 constantPoolHandle _cphandle; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
319 bool _in_error; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
320 public: |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
321 ConstantPoolCleaner(constantPoolHandle cp) : _cphandle(cp), _in_error(true) {} |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
322 ~ConstantPoolCleaner() { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
323 if (_in_error && _cphandle.not_null()) { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
324 _cphandle->unreference_symbols(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
325 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
326 } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
327 void set_in_error(bool clean) { _in_error = clean; } |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
328 }; |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
329 |
0 | 330 bool inline valid_cp_range(int index, int length) { return (index > 0 && index < length); } |
331 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
332 inline Symbol* check_symbol_at(constantPoolHandle cp, int index) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
333 if (valid_cp_range(index, cp->length()) && cp->tag_at(index).is_utf8()) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
334 return cp->symbol_at(index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
335 else |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
336 return NULL; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
337 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
338 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
339 constantPoolHandle ClassFileParser::parse_constant_pool(ClassLoaderData* loader_data, TRAPS) { |
0 | 340 ClassFileStream* cfs = stream(); |
341 constantPoolHandle nullHandle; | |
342 | |
343 cfs->guarantee_more(3, CHECK_(nullHandle)); // length, first cp tag | |
344 u2 length = cfs->get_u2_fast(); | |
345 guarantee_property( | |
346 length >= 1, "Illegal constant pool size %u in class file %s", | |
347 length, CHECK_(nullHandle)); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
348 ConstantPool* constant_pool = |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
349 ConstantPool::allocate(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
350 length, |
518
0af8b0718fc9
6692899: CMS: many vm.parallel_class_loading tests fail with assert "missing Printezis mark"
jmasa
parents:
474
diff
changeset
|
351 CHECK_(nullHandle)); |
0 | 352 constantPoolHandle cp (THREAD, constant_pool); |
353 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
354 ConstantPoolCleaner cp_in_error(cp); // set constant pool to be cleaned up. |
0 | 355 |
356 // parsing constant pool entries | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
357 parse_constant_pool_entries(loader_data, cp, length, CHECK_(nullHandle)); |
0 | 358 |
359 int index = 1; // declared outside of loops for portability | |
360 | |
361 // first verification pass - validate cross references and fixup class and string constants | |
362 for (index = 1; index < length; index++) { // Index 0 is unused | |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
363 jbyte tag = cp->tag_at(index).value(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
364 switch (tag) { |
0 | 365 case JVM_CONSTANT_Class : |
366 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present | |
367 break; | |
368 case JVM_CONSTANT_Fieldref : | |
369 // fall through | |
370 case JVM_CONSTANT_Methodref : | |
371 // fall through | |
372 case JVM_CONSTANT_InterfaceMethodref : { | |
373 if (!_need_verify) break; | |
374 int klass_ref_index = cp->klass_ref_index_at(index); | |
375 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index); | |
376 check_property(valid_cp_range(klass_ref_index, length) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
377 is_klass_reference(cp, klass_ref_index), |
0 | 378 "Invalid constant pool index %u in class file %s", |
379 klass_ref_index, | |
380 CHECK_(nullHandle)); | |
381 check_property(valid_cp_range(name_and_type_ref_index, length) && | |
382 cp->tag_at(name_and_type_ref_index).is_name_and_type(), | |
383 "Invalid constant pool index %u in class file %s", | |
384 name_and_type_ref_index, | |
385 CHECK_(nullHandle)); | |
386 break; | |
387 } | |
388 case JVM_CONSTANT_String : | |
389 ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present | |
390 break; | |
391 case JVM_CONSTANT_Integer : | |
392 break; | |
393 case JVM_CONSTANT_Float : | |
394 break; | |
395 case JVM_CONSTANT_Long : | |
396 case JVM_CONSTANT_Double : | |
397 index++; | |
398 check_property( | |
399 (index < length && cp->tag_at(index).is_invalid()), | |
400 "Improper constant pool long/double index %u in class file %s", | |
401 index, CHECK_(nullHandle)); | |
402 break; | |
403 case JVM_CONSTANT_NameAndType : { | |
404 if (!_need_verify) break; | |
405 int name_ref_index = cp->name_ref_index_at(index); | |
406 int signature_ref_index = cp->signature_ref_index_at(index); | |
407 check_property( | |
408 valid_cp_range(name_ref_index, length) && | |
409 cp->tag_at(name_ref_index).is_utf8(), | |
410 "Invalid constant pool index %u in class file %s", | |
411 name_ref_index, CHECK_(nullHandle)); | |
412 check_property( | |
413 valid_cp_range(signature_ref_index, length) && | |
414 cp->tag_at(signature_ref_index).is_utf8(), | |
415 "Invalid constant pool index %u in class file %s", | |
416 signature_ref_index, CHECK_(nullHandle)); | |
417 break; | |
418 } | |
419 case JVM_CONSTANT_Utf8 : | |
420 break; | |
421 case JVM_CONSTANT_UnresolvedClass : // fall-through | |
422 case JVM_CONSTANT_UnresolvedClassInError: | |
423 ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present | |
424 break; | |
425 case JVM_CONSTANT_ClassIndex : | |
426 { | |
427 int class_index = cp->klass_index_at(index); | |
428 check_property( | |
429 valid_cp_range(class_index, length) && | |
430 cp->tag_at(class_index).is_utf8(), | |
431 "Invalid constant pool index %u in class file %s", | |
432 class_index, CHECK_(nullHandle)); | |
433 cp->unresolved_klass_at_put(index, cp->symbol_at(class_index)); | |
434 } | |
435 break; | |
436 case JVM_CONSTANT_StringIndex : | |
437 { | |
438 int string_index = cp->string_index_at(index); | |
439 check_property( | |
440 valid_cp_range(string_index, length) && | |
441 cp->tag_at(string_index).is_utf8(), | |
442 "Invalid constant pool index %u in class file %s", | |
443 string_index, CHECK_(nullHandle)); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
444 Symbol* sym = cp->symbol_at(string_index); |
0 | 445 cp->unresolved_string_at_put(index, sym); |
446 } | |
447 break; | |
1602 | 448 case JVM_CONSTANT_MethodHandle : |
449 { | |
450 int ref_index = cp->method_handle_index_at(index); | |
451 check_property( | |
452 valid_cp_range(ref_index, length) && | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
453 EnableInvokeDynamic, |
1602 | 454 "Invalid constant pool index %u in class file %s", |
455 ref_index, CHECK_(nullHandle)); | |
456 constantTag tag = cp->tag_at(ref_index); | |
457 int ref_kind = cp->method_handle_ref_kind_at(index); | |
458 switch (ref_kind) { | |
459 case JVM_REF_getField: | |
460 case JVM_REF_getStatic: | |
461 case JVM_REF_putField: | |
462 case JVM_REF_putStatic: | |
463 check_property( | |
464 tag.is_field(), | |
465 "Invalid constant pool index %u in class file %s (not a field)", | |
466 ref_index, CHECK_(nullHandle)); | |
467 break; | |
468 case JVM_REF_invokeVirtual: | |
469 case JVM_REF_invokeStatic: | |
470 case JVM_REF_invokeSpecial: | |
471 case JVM_REF_newInvokeSpecial: | |
472 check_property( | |
473 tag.is_method(), | |
474 "Invalid constant pool index %u in class file %s (not a method)", | |
475 ref_index, CHECK_(nullHandle)); | |
476 break; | |
477 case JVM_REF_invokeInterface: | |
478 check_property( | |
479 tag.is_interface_method(), | |
480 "Invalid constant pool index %u in class file %s (not an interface method)", | |
481 ref_index, CHECK_(nullHandle)); | |
482 break; | |
483 default: | |
484 classfile_parse_error( | |
485 "Bad method handle kind at constant pool index %u in class file %s", | |
486 index, CHECK_(nullHandle)); | |
487 } | |
488 // Keep the ref_index unchanged. It will be indirected at link-time. | |
489 } | |
490 break; | |
491 case JVM_CONSTANT_MethodType : | |
492 { | |
493 int ref_index = cp->method_type_index_at(index); | |
494 check_property( | |
495 valid_cp_range(ref_index, length) && | |
496 cp->tag_at(ref_index).is_utf8() && | |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
497 EnableInvokeDynamic, |
1602 | 498 "Invalid constant pool index %u in class file %s", |
499 ref_index, CHECK_(nullHandle)); | |
500 } | |
501 break; | |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
502 case JVM_CONSTANT_InvokeDynamic : |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
503 { |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
504 int name_and_type_ref_index = cp->invoke_dynamic_name_and_type_ref_index_at(index); |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
505 check_property(valid_cp_range(name_and_type_ref_index, length) && |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
506 cp->tag_at(name_and_type_ref_index).is_name_and_type(), |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
507 "Invalid constant pool index %u in class file %s", |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
508 name_and_type_ref_index, |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
509 CHECK_(nullHandle)); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
510 // bootstrap specifier index must be checked later, when BootstrapMethods attr is available |
1660
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
511 break; |
083fde3b838e
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
1608
diff
changeset
|
512 } |
0 | 513 default: |
1490
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1366
diff
changeset
|
514 fatal(err_msg("bad constant pool tag value %u", |
f03d0a26bf83
6888954: argument formatting for assert() and friends
jcoomes
parents:
1366
diff
changeset
|
515 cp->tag_at(index).value())); |
0 | 516 ShouldNotReachHere(); |
517 break; | |
518 } // end of switch | |
519 } // end of for | |
520 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
521 if (_cp_patches != NULL) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
522 // need to treat this_class specially... |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
523 assert(EnableInvokeDynamic, ""); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
524 int this_class_index; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
525 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
526 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
527 u1* mark = cfs->current(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
528 u2 flags = cfs->get_u2_fast(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
529 this_class_index = cfs->get_u2_fast(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
530 cfs->set_current(mark); // revert to mark |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
531 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
532 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
533 for (index = 1; index < length; index++) { // Index 0 is unused |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
534 if (has_cp_patch_at(index)) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
535 guarantee_property(index != this_class_index, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
536 "Illegal constant pool patch to self at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
537 index, CHECK_(nullHandle)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
538 patch_constant_pool(cp, index, cp_patch_at(index), CHECK_(nullHandle)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
539 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
540 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
541 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
542 |
0 | 543 if (!_need_verify) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
544 cp_in_error.set_in_error(false); |
0 | 545 return cp; |
546 } | |
547 | |
548 // second verification pass - checks the strings are of the right format. | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
549 // but not yet to the other entries |
0 | 550 for (index = 1; index < length; index++) { |
551 jbyte tag = cp->tag_at(index).value(); | |
552 switch (tag) { | |
553 case JVM_CONSTANT_UnresolvedClass: { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
554 Symbol* class_name = cp->unresolved_klass_at(index); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
555 // check the name, even if _cp_patches will overwrite it |
0 | 556 verify_legal_class_name(class_name, CHECK_(nullHandle)); |
557 break; | |
558 } | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
559 case JVM_CONSTANT_NameAndType: { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
560 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
561 int sig_index = cp->signature_ref_index_at(index); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
562 int name_index = cp->name_ref_index_at(index); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
563 Symbol* name = cp->symbol_at(name_index); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
564 Symbol* sig = cp->symbol_at(sig_index); |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
565 if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
566 verify_legal_method_signature(name, sig, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
567 } else { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
568 verify_legal_field_signature(name, sig, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
569 } |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
570 } |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
571 break; |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
572 } |
2461
758ba0bf7bcc
7012087: JSR 292 Misleading exception message for a non-bound MH for a virtual method
jrose
parents:
2460
diff
changeset
|
573 case JVM_CONSTANT_InvokeDynamic: |
0 | 574 case JVM_CONSTANT_Fieldref: |
575 case JVM_CONSTANT_Methodref: | |
576 case JVM_CONSTANT_InterfaceMethodref: { | |
577 int name_and_type_ref_index = cp->name_and_type_ref_index_at(index); | |
578 // already verified to be utf8 | |
579 int name_ref_index = cp->name_ref_index_at(name_and_type_ref_index); | |
580 // already verified to be utf8 | |
581 int signature_ref_index = cp->signature_ref_index_at(name_and_type_ref_index); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
582 Symbol* name = cp->symbol_at(name_ref_index); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
583 Symbol* signature = cp->symbol_at(signature_ref_index); |
0 | 584 if (tag == JVM_CONSTANT_Fieldref) { |
585 verify_legal_field_name(name, CHECK_(nullHandle)); | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
586 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
587 // Signature is verified above, when iterating NameAndType_info. |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
588 // Need only to be sure it's the right type. |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
589 if (signature->byte_at(0) == JVM_SIGNATURE_FUNC) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
590 throwIllegalSignature( |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
591 "Field", name, signature, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
592 } |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
593 } else { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
594 verify_legal_field_signature(name, signature, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
595 } |
0 | 596 } else { |
597 verify_legal_method_name(name, CHECK_(nullHandle)); | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
598 if (_need_verify && _major_version >= JAVA_7_VERSION) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
599 // Signature is verified above, when iterating NameAndType_info. |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
600 // Need only to be sure it's the right type. |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
601 if (signature->byte_at(0) != JVM_SIGNATURE_FUNC) { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
602 throwIllegalSignature( |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
603 "Method", name, signature, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
604 } |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
605 } else { |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
606 verify_legal_method_signature(name, signature, CHECK_(nullHandle)); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
607 } |
0 | 608 if (tag == JVM_CONSTANT_Methodref) { |
609 // 4509014: If a class method name begins with '<', it must be "<init>". | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
610 assert(name != NULL, "method name in constant pool is null"); |
0 | 611 unsigned int name_len = name->utf8_length(); |
612 assert(name_len > 0, "bad method name"); // already verified as legal name | |
613 if (name->byte_at(0) == '<') { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
614 if (name != vmSymbols::object_initializer_name()) { |
0 | 615 classfile_parse_error( |
616 "Bad method name at constant pool index %u in class file %s", | |
617 name_ref_index, CHECK_(nullHandle)); | |
618 } | |
619 } | |
620 } | |
621 } | |
622 break; | |
623 } | |
1602 | 624 case JVM_CONSTANT_MethodHandle: { |
625 int ref_index = cp->method_handle_index_at(index); | |
626 int ref_kind = cp->method_handle_ref_kind_at(index); | |
627 switch (ref_kind) { | |
628 case JVM_REF_invokeVirtual: | |
629 case JVM_REF_invokeStatic: | |
630 case JVM_REF_invokeSpecial: | |
631 case JVM_REF_newInvokeSpecial: | |
632 { | |
633 int name_and_type_ref_index = cp->name_and_type_ref_index_at(ref_index); | |
634 int name_ref_index = cp->name_ref_index_at(name_and_type_ref_index); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
635 Symbol* name = cp->symbol_at(name_ref_index); |
1602 | 636 if (ref_kind == JVM_REF_newInvokeSpecial) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
637 if (name != vmSymbols::object_initializer_name()) { |
1602 | 638 classfile_parse_error( |
639 "Bad constructor name at constant pool index %u in class file %s", | |
640 name_ref_index, CHECK_(nullHandle)); | |
641 } | |
642 } else { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
643 if (name == vmSymbols::object_initializer_name()) { |
1602 | 644 classfile_parse_error( |
645 "Bad method name at constant pool index %u in class file %s", | |
646 name_ref_index, CHECK_(nullHandle)); | |
647 } | |
648 } | |
649 } | |
650 break; | |
651 // Other ref_kinds are already fully checked in previous pass. | |
652 } | |
653 break; | |
654 } | |
655 case JVM_CONSTANT_MethodType: { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
656 Symbol* no_name = vmSymbols::type_name(); // place holder |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
657 Symbol* signature = cp->method_type_signature_at(index); |
1602 | 658 verify_legal_method_signature(no_name, signature, CHECK_(nullHandle)); |
659 break; | |
660 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
661 case JVM_CONSTANT_Utf8: { |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
662 assert(cp->symbol_at(index)->refcount() != 0, "count corrupted"); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
663 } |
0 | 664 } // end of switch |
665 } // end of for | |
666 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
667 cp_in_error.set_in_error(false); |
0 | 668 return cp; |
669 } | |
670 | |
671 | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
672 void ClassFileParser::patch_constant_pool(constantPoolHandle cp, int index, Handle patch, TRAPS) { |
2416
38fea01eb669
6817525: turn on method handle functionality by default for JSR 292
twisti
parents:
2376
diff
changeset
|
673 assert(EnableInvokeDynamic, ""); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
674 BasicType patch_type = T_VOID; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
675 |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
676 switch (cp->tag_at(index).value()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
677 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
678 case JVM_CONSTANT_UnresolvedClass : |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
679 // Patching a class means pre-resolving it. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
680 // The name in the constant pool is ignored. |
1602 | 681 if (java_lang_Class::is_instance(patch())) { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
682 guarantee_property(!java_lang_Class::is_primitive(patch()), |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
683 "Illegal class patch at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
684 index, CHECK); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
685 cp->klass_at_put(index, java_lang_Class::as_Klass(patch())); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
686 } else { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
687 guarantee_property(java_lang_String::is_instance(patch()), |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
688 "Illegal class patch at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
689 index, CHECK); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
690 Symbol* name = java_lang_String::as_symbol(patch(), CHECK); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
691 cp->unresolved_klass_at_put(index, name); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
692 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
693 break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
694 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
695 case JVM_CONSTANT_String : |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
696 // skip this patch and don't clear it. Needs the oop array for resolved |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
697 // references to be created first. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
698 return; |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
699 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
700 case JVM_CONSTANT_Integer : patch_type = T_INT; goto patch_prim; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
701 case JVM_CONSTANT_Float : patch_type = T_FLOAT; goto patch_prim; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
702 case JVM_CONSTANT_Long : patch_type = T_LONG; goto patch_prim; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
703 case JVM_CONSTANT_Double : patch_type = T_DOUBLE; goto patch_prim; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
704 patch_prim: |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
705 { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
706 jvalue value; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
707 BasicType value_type = java_lang_boxing_object::get_value(patch(), &value); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
708 guarantee_property(value_type == patch_type, |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
709 "Illegal primitive patch at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
710 index, CHECK); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
711 switch (value_type) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
712 case T_INT: cp->int_at_put(index, value.i); break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
713 case T_FLOAT: cp->float_at_put(index, value.f); break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
714 case T_LONG: cp->long_at_put(index, value.j); break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
715 case T_DOUBLE: cp->double_at_put(index, value.d); break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
716 default: assert(false, ""); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
717 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
718 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
719 break; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
720 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
721 default: |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
722 // %%% TODO: put method handles into CONSTANT_InterfaceMethodref, etc. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
723 guarantee_property(!has_cp_patch_at(index), |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
724 "Illegal unexpected patch at %d in class file %s", |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
725 index, CHECK); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
726 return; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
727 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
728 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
729 // On fall-through, mark the patch as used. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
730 clear_cp_patch_at(index); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
731 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
732 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
733 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
734 |
0 | 735 class NameSigHash: public ResourceObj { |
736 public: | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
737 Symbol* _name; // name |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
738 Symbol* _sig; // signature |
0 | 739 NameSigHash* _next; // Next entry in hash table |
740 }; | |
741 | |
742 | |
743 #define HASH_ROW_SIZE 256 | |
744 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
745 unsigned int hash(Symbol* name, Symbol* sig) { |
0 | 746 unsigned int raw_hash = 0; |
747 raw_hash += ((unsigned int)(uintptr_t)name) >> (LogHeapWordSize + 2); | |
748 raw_hash += ((unsigned int)(uintptr_t)sig) >> LogHeapWordSize; | |
749 | |
750 return (raw_hash + (unsigned int)(uintptr_t)name) % HASH_ROW_SIZE; | |
751 } | |
752 | |
753 | |
754 void initialize_hashtable(NameSigHash** table) { | |
755 memset((void*)table, 0, sizeof(NameSigHash*) * HASH_ROW_SIZE); | |
756 } | |
757 | |
758 // Return false if the name/sig combination is found in table. | |
759 // Return true if no duplicate is found. And name/sig is added as a new entry in table. | |
760 // The old format checker uses heap sort to find duplicates. | |
761 // NOTE: caller should guarantee that GC doesn't happen during the life cycle | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
762 // of table since we don't expect Symbol*'s to move. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
763 bool put_after_lookup(Symbol* name, Symbol* sig, NameSigHash** table) { |
0 | 764 assert(name != NULL, "name in constant pool is NULL"); |
765 | |
766 // First lookup for duplicates | |
767 int index = hash(name, sig); | |
768 NameSigHash* entry = table[index]; | |
769 while (entry != NULL) { | |
770 if (entry->_name == name && entry->_sig == sig) { | |
771 return false; | |
772 } | |
773 entry = entry->_next; | |
774 } | |
775 | |
776 // No duplicate is found, allocate a new entry and fill it. | |
777 entry = new NameSigHash(); | |
778 entry->_name = name; | |
779 entry->_sig = sig; | |
780 | |
781 // Insert into hash table | |
782 entry->_next = table[index]; | |
783 table[index] = entry; | |
784 | |
785 return true; | |
786 } | |
787 | |
788 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
789 Array<Klass*>* ClassFileParser::parse_interfaces(constantPoolHandle cp, |
0 | 790 int length, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
791 ClassLoaderData* loader_data, |
0 | 792 Handle protection_domain, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
793 Symbol* class_name, |
6934 | 794 bool* has_default_methods, |
0 | 795 TRAPS) { |
796 ClassFileStream* cfs = stream(); | |
797 assert(length > 0, "only called for length>0"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
798 // FIXME: Leak at later OOM. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
799 Array<Klass*>* interfaces = MetadataFactory::new_array<Klass*>(loader_data, length, NULL, CHECK_NULL); |
0 | 800 |
801 int index; | |
802 for (index = 0; index < length; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
803 u2 interface_index = cfs->get_u2(CHECK_NULL); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
804 KlassHandle interf; |
0 | 805 check_property( |
806 valid_cp_range(interface_index, cp->length()) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
807 is_klass_reference(cp, interface_index), |
0 | 808 "Interface name has bad constant pool index %u in class file %s", |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
809 interface_index, CHECK_NULL); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
810 if (cp->tag_at(interface_index).is_klass()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
811 interf = KlassHandle(THREAD, cp->resolved_klass_at(interface_index)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
812 } else { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
813 Symbol* unresolved_klass = cp->klass_name_at(interface_index); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
814 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
815 // Don't need to check legal name because it's checked when parsing constant pool. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
816 // But need to make sure it's not an array type. |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
817 guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
818 "Bad interface name in class file %s", CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
819 Handle class_loader(THREAD, loader_data->class_loader()); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
820 |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
821 // Call resolve_super so classcircularity is checked |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
822 Klass* k = SystemDictionary::resolve_super_or_fail(class_name, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
823 unresolved_klass, class_loader, protection_domain, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
824 false, CHECK_NULL); |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
825 interf = KlassHandle(THREAD, k); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
826 } |
0 | 827 |
6983 | 828 if (!interf()->is_interface()) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
829 THROW_MSG_(vmSymbols::java_lang_IncompatibleClassChangeError(), "Implementing class", NULL); |
0 | 830 } |
6934 | 831 if (InstanceKlass::cast(interf())->has_default_methods()) { |
832 *has_default_methods = true; | |
833 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
834 interfaces->at_put(index, interf()); |
0 | 835 } |
836 | |
837 if (!_need_verify || length <= 1) { | |
838 return interfaces; | |
839 } | |
840 | |
841 // Check if there's any duplicates in interfaces | |
842 ResourceMark rm(THREAD); | |
843 NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD( | |
844 THREAD, NameSigHash*, HASH_ROW_SIZE); | |
845 initialize_hashtable(interface_names); | |
846 bool dup = false; | |
847 { | |
848 debug_only(No_Safepoint_Verifier nsv;) | |
849 for (index = 0; index < length; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
850 Klass* k = interfaces->at(index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
851 Symbol* name = InstanceKlass::cast(k)->name(); |
0 | 852 // If no duplicates, add (name, NULL) in hashtable interface_names. |
853 if (!put_after_lookup(name, NULL, interface_names)) { | |
854 dup = true; | |
855 break; | |
856 } | |
857 } | |
858 } | |
859 if (dup) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
860 classfile_parse_error("Duplicate interface name in class file %s", CHECK_NULL); |
0 | 861 } |
862 | |
863 return interfaces; | |
864 } | |
865 | |
866 | |
867 void ClassFileParser::verify_constantvalue(int constantvalue_index, int signature_index, constantPoolHandle cp, TRAPS) { | |
868 // Make sure the constant pool entry is of a type appropriate to this field | |
869 guarantee_property( | |
870 (constantvalue_index > 0 && | |
871 constantvalue_index < cp->length()), | |
872 "Bad initial value index %u in ConstantValue attribute in class file %s", | |
873 constantvalue_index, CHECK); | |
874 constantTag value_type = cp->tag_at(constantvalue_index); | |
875 switch ( cp->basic_type_for_signature_at(signature_index) ) { | |
876 case T_LONG: | |
877 guarantee_property(value_type.is_long(), "Inconsistent constant value type in class file %s", CHECK); | |
878 break; | |
879 case T_FLOAT: | |
880 guarantee_property(value_type.is_float(), "Inconsistent constant value type in class file %s", CHECK); | |
881 break; | |
882 case T_DOUBLE: | |
883 guarantee_property(value_type.is_double(), "Inconsistent constant value type in class file %s", CHECK); | |
884 break; | |
885 case T_BYTE: case T_CHAR: case T_SHORT: case T_BOOLEAN: case T_INT: | |
886 guarantee_property(value_type.is_int(), "Inconsistent constant value type in class file %s", CHECK); | |
887 break; | |
888 case T_OBJECT: | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1108
diff
changeset
|
889 guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
890 && value_type.is_string()), |
0 | 891 "Bad string initial value in class file %s", CHECK); |
892 break; | |
893 default: | |
894 classfile_parse_error( | |
895 "Unable to set initial value %u in class file %s", | |
896 constantvalue_index, CHECK); | |
897 } | |
898 } | |
899 | |
900 | |
901 // Parse attributes for a field. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
902 void ClassFileParser::parse_field_attributes(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
903 constantPoolHandle cp, |
0 | 904 u2 attributes_count, |
905 bool is_static, u2 signature_index, | |
906 u2* constantvalue_index_addr, | |
907 bool* is_synthetic_addr, | |
908 u2* generic_signature_index_addr, | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
909 AnnotationArray** field_annotations, |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
910 AnnotationArray** field_type_annotations, |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
911 ClassFileParser::FieldAnnotationCollector* parsed_annotations, |
0 | 912 TRAPS) { |
913 ClassFileStream* cfs = stream(); | |
914 assert(attributes_count > 0, "length should be greater than 0"); | |
915 u2 constantvalue_index = 0; | |
916 u2 generic_signature_index = 0; | |
917 bool is_synthetic = false; | |
918 u1* runtime_visible_annotations = NULL; | |
919 int runtime_visible_annotations_length = 0; | |
920 u1* runtime_invisible_annotations = NULL; | |
921 int runtime_invisible_annotations_length = 0; | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
922 u1* runtime_visible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
923 int runtime_visible_type_annotations_length = 0; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
924 u1* runtime_invisible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
925 int runtime_invisible_type_annotations_length = 0; |
0 | 926 while (attributes_count--) { |
927 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length | |
928 u2 attribute_name_index = cfs->get_u2_fast(); | |
929 u4 attribute_length = cfs->get_u4_fast(); | |
930 check_property(valid_cp_range(attribute_name_index, cp->length()) && | |
931 cp->tag_at(attribute_name_index).is_utf8(), | |
932 "Invalid field attribute index %u in class file %s", | |
933 attribute_name_index, | |
934 CHECK); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
935 Symbol* attribute_name = cp->symbol_at(attribute_name_index); |
0 | 936 if (is_static && attribute_name == vmSymbols::tag_constant_value()) { |
937 // ignore if non-static | |
938 if (constantvalue_index != 0) { | |
939 classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK); | |
940 } | |
941 check_property( | |
942 attribute_length == 2, | |
943 "Invalid ConstantValue field attribute length %u in class file %s", | |
944 attribute_length, CHECK); | |
945 constantvalue_index = cfs->get_u2(CHECK); | |
946 if (_need_verify) { | |
947 verify_constantvalue(constantvalue_index, signature_index, cp, CHECK); | |
948 } | |
949 } else if (attribute_name == vmSymbols::tag_synthetic()) { | |
950 if (attribute_length != 0) { | |
951 classfile_parse_error( | |
952 "Invalid Synthetic field attribute length %u in class file %s", | |
953 attribute_length, CHECK); | |
954 } | |
955 is_synthetic = true; | |
956 } else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120 | |
957 if (attribute_length != 0) { | |
958 classfile_parse_error( | |
959 "Invalid Deprecated field attribute length %u in class file %s", | |
960 attribute_length, CHECK); | |
961 } | |
962 } else if (_major_version >= JAVA_1_5_VERSION) { | |
963 if (attribute_name == vmSymbols::tag_signature()) { | |
964 if (attribute_length != 2) { | |
965 classfile_parse_error( | |
966 "Wrong size %u for field's Signature attribute in class file %s", | |
967 attribute_length, CHECK); | |
968 } | |
969 generic_signature_index = cfs->get_u2(CHECK); | |
970 } else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) { | |
971 runtime_visible_annotations_length = attribute_length; | |
972 runtime_visible_annotations = cfs->get_u1_buffer(); | |
973 assert(runtime_visible_annotations != NULL, "null visible annotations"); | |
7587 | 974 parse_annotations(loader_data, |
975 runtime_visible_annotations, | |
976 runtime_visible_annotations_length, | |
977 cp, | |
978 parsed_annotations, | |
979 CHECK); | |
0 | 980 cfs->skip_u1(runtime_visible_annotations_length, CHECK); |
981 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { | |
982 runtime_invisible_annotations_length = attribute_length; | |
983 runtime_invisible_annotations = cfs->get_u1_buffer(); | |
984 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); | |
985 cfs->skip_u1(runtime_invisible_annotations_length, CHECK); | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
986 } else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
987 runtime_visible_type_annotations_length = attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
988 runtime_visible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
989 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
990 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
991 } else if (PreserveAllAnnotations && attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
992 runtime_invisible_type_annotations_length = attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
993 runtime_invisible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
994 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
995 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); |
0 | 996 } else { |
997 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes | |
998 } | |
999 } else { | |
1000 cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes | |
1001 } | |
1002 } | |
1003 | |
1004 *constantvalue_index_addr = constantvalue_index; | |
1005 *is_synthetic_addr = is_synthetic; | |
1006 *generic_signature_index_addr = generic_signature_index; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1007 *field_annotations = assemble_annotations(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1008 runtime_visible_annotations, |
0 | 1009 runtime_visible_annotations_length, |
1010 runtime_invisible_annotations, | |
1011 runtime_invisible_annotations_length, | |
1012 CHECK); | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1013 *field_type_annotations = assemble_annotations(loader_data, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1014 runtime_visible_type_annotations, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1015 runtime_visible_type_annotations_length, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1016 runtime_invisible_type_annotations, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1017 runtime_invisible_type_annotations_length, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1018 CHECK); |
0 | 1019 return; |
1020 } | |
1021 | |
1022 | |
1023 // Field allocation types. Used for computing field offsets. | |
1024 | |
1025 enum FieldAllocationType { | |
1026 STATIC_OOP, // Oops | |
1027 STATIC_BYTE, // Boolean, Byte, char | |
1028 STATIC_SHORT, // shorts | |
1029 STATIC_WORD, // ints | |
3938 | 1030 STATIC_DOUBLE, // aligned long or double |
0 | 1031 NONSTATIC_OOP, |
1032 NONSTATIC_BYTE, | |
1033 NONSTATIC_SHORT, | |
1034 NONSTATIC_WORD, | |
1035 NONSTATIC_DOUBLE, | |
3938 | 1036 MAX_FIELD_ALLOCATION_TYPE, |
1037 BAD_ALLOCATION_TYPE = -1 | |
0 | 1038 }; |
1039 | |
3938 | 1040 static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = { |
1041 BAD_ALLOCATION_TYPE, // 0 | |
1042 BAD_ALLOCATION_TYPE, // 1 | |
1043 BAD_ALLOCATION_TYPE, // 2 | |
1044 BAD_ALLOCATION_TYPE, // 3 | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1045 NONSTATIC_BYTE , // T_BOOLEAN = 4, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1046 NONSTATIC_SHORT, // T_CHAR = 5, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1047 NONSTATIC_WORD, // T_FLOAT = 6, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1048 NONSTATIC_DOUBLE, // T_DOUBLE = 7, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1049 NONSTATIC_BYTE, // T_BYTE = 8, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1050 NONSTATIC_SHORT, // T_SHORT = 9, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1051 NONSTATIC_WORD, // T_INT = 10, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1052 NONSTATIC_DOUBLE, // T_LONG = 11, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1053 NONSTATIC_OOP, // T_OBJECT = 12, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1054 NONSTATIC_OOP, // T_ARRAY = 13, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1055 BAD_ALLOCATION_TYPE, // T_VOID = 14, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1056 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1057 BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1058 BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1059 BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1060 BAD_ALLOCATION_TYPE, // T_CONFLICT = 19, |
3938 | 1061 BAD_ALLOCATION_TYPE, // 0 |
1062 BAD_ALLOCATION_TYPE, // 1 | |
1063 BAD_ALLOCATION_TYPE, // 2 | |
1064 BAD_ALLOCATION_TYPE, // 3 | |
6848
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1065 STATIC_BYTE , // T_BOOLEAN = 4, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1066 STATIC_SHORT, // T_CHAR = 5, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1067 STATIC_WORD, // T_FLOAT = 6, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1068 STATIC_DOUBLE, // T_DOUBLE = 7, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1069 STATIC_BYTE, // T_BYTE = 8, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1070 STATIC_SHORT, // T_SHORT = 9, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1071 STATIC_WORD, // T_INT = 10, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1072 STATIC_DOUBLE, // T_LONG = 11, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1073 STATIC_OOP, // T_OBJECT = 12, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1074 STATIC_OOP, // T_ARRAY = 13, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1075 BAD_ALLOCATION_TYPE, // T_VOID = 14, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1076 BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1077 BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1078 BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1079 BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18, |
8e47bac5643a
7054512: Compress class pointers after perm gen removal
roland
parents:
6735
diff
changeset
|
1080 BAD_ALLOCATION_TYPE, // T_CONFLICT = 19, |
0 | 1081 }; |
1082 | |
3938 | 1083 static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) { |
1084 assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values"); | |
1085 FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)]; | |
1086 assert(result != BAD_ALLOCATION_TYPE, "bad type"); | |
1087 return result; | |
1088 } | |
1089 | |
1090 class FieldAllocationCount: public ResourceObj { | |
1091 public: | |
4744
cd5d8cafcc84
7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
jiangli
parents:
3938
diff
changeset
|
1092 u2 count[MAX_FIELD_ALLOCATION_TYPE]; |
3938 | 1093 |
1094 FieldAllocationCount() { | |
1095 for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) { | |
1096 count[i] = 0; | |
1097 } | |
1098 } | |
1099 | |
1100 FieldAllocationType update(bool is_static, BasicType type) { | |
1101 FieldAllocationType atype = basic_type_to_atype(is_static, type); | |
4744
cd5d8cafcc84
7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
jiangli
parents:
3938
diff
changeset
|
1102 // Make sure there is no overflow with injected fields. |
cd5d8cafcc84
7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
jiangli
parents:
3938
diff
changeset
|
1103 assert(count[atype] < 0xFFFF, "More than 65535 fields"); |
3938 | 1104 count[atype]++; |
1105 return atype; | |
1106 } | |
1107 }; | |
1108 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1109 Array<u2>* ClassFileParser::parse_fields(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1110 Symbol* class_name, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
1111 constantPoolHandle cp, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
1112 bool is_interface, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
1113 FieldAllocationCount *fac, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1114 Array<AnnotationArray*>** fields_annotations, |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1115 Array<AnnotationArray*>** fields_type_annotations, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
1116 u2* java_fields_count_ptr, TRAPS) { |
0 | 1117 ClassFileStream* cfs = stream(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1118 cfs->guarantee_more(2, CHECK_NULL); // length |
0 | 1119 u2 length = cfs->get_u2_fast(); |
3938 | 1120 *java_fields_count_ptr = length; |
1121 | |
1122 int num_injected = 0; | |
1123 InjectedField* injected = JavaClasses::get_injected(class_name, &num_injected); | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1124 int total_fields = length + num_injected; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1125 |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1126 // The field array starts with tuples of shorts |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1127 // [access, name index, sig index, initial value index, byte offset]. |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1128 // A generic signature slot only exists for field with generic |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1129 // signature attribute. And the access flag is set with |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1130 // JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE for that field. The generic |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1131 // signature slots are at the end of the field array and after all |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1132 // other fields data. |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1133 // |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1134 // f1: [access, name index, sig index, initial value index, low_offset, high_offset] |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1135 // f2: [access, name index, sig index, initial value index, low_offset, high_offset] |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1136 // ... |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1137 // fn: [access, name index, sig index, initial value index, low_offset, high_offset] |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1138 // [generic signature index] |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1139 // [generic signature index] |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1140 // ... |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1141 // |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1142 // Allocate a temporary resource array for field data. For each field, |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1143 // a slot is reserved in the temporary array for the generic signature |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1144 // index. After parsing all fields, the data are copied to a permanent |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1145 // array and any unused slots will be discarded. |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1146 ResourceMark rm(THREAD); |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1147 u2* fa = NEW_RESOURCE_ARRAY_IN_THREAD( |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1148 THREAD, u2, total_fields * (FieldInfo::field_slots + 1)); |
0 | 1149 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1150 AnnotationArray* field_annotations = NULL; |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1151 AnnotationArray* field_type_annotations = NULL; |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1152 // The generic signature slots start after all other fields' data. |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1153 int generic_signature_slot = total_fields * FieldInfo::field_slots; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1154 int num_generic_signature = 0; |
0 | 1155 for (int n = 0; n < length; n++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1156 cfs->guarantee_more(8, CHECK_NULL); // access_flags, name_index, descriptor_index, attributes_count |
0 | 1157 |
1158 AccessFlags access_flags; | |
1159 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1160 verify_legal_field_modifiers(flags, is_interface, CHECK_NULL); |
0 | 1161 access_flags.set_flags(flags); |
1162 | |
1163 u2 name_index = cfs->get_u2_fast(); | |
1164 int cp_size = cp->length(); | |
1165 check_property( | |
1166 valid_cp_range(name_index, cp_size) && cp->tag_at(name_index).is_utf8(), | |
1167 "Invalid constant pool index %u for field name in class file %s", | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1168 name_index, CHECK_NULL); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1169 Symbol* name = cp->symbol_at(name_index); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1170 verify_legal_field_name(name, CHECK_NULL); |
0 | 1171 |
1172 u2 signature_index = cfs->get_u2_fast(); | |
1173 check_property( | |
1174 valid_cp_range(signature_index, cp_size) && | |
1175 cp->tag_at(signature_index).is_utf8(), | |
1176 "Invalid constant pool index %u for field signature in class file %s", | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1177 signature_index, CHECK_NULL); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1178 Symbol* sig = cp->symbol_at(signature_index); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1179 verify_legal_field_signature(name, sig, CHECK_NULL); |
0 | 1180 |
1181 u2 constantvalue_index = 0; | |
1182 bool is_synthetic = false; | |
1183 u2 generic_signature_index = 0; | |
1184 bool is_static = access_flags.is_static(); | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1185 FieldAnnotationCollector parsed_annotations; |
0 | 1186 |
1187 u2 attributes_count = cfs->get_u2_fast(); | |
1188 if (attributes_count > 0) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1189 parse_field_attributes(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1190 cp, attributes_count, is_static, signature_index, |
0 | 1191 &constantvalue_index, &is_synthetic, |
1192 &generic_signature_index, &field_annotations, | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1193 &field_type_annotations, &parsed_annotations, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1194 CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1195 if (field_annotations != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1196 if (*fields_annotations == NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1197 *fields_annotations = MetadataFactory::new_array<AnnotationArray*>( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1198 loader_data, length, NULL, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1199 CHECK_NULL); |
0 | 1200 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1201 (*fields_annotations)->at_put(n, field_annotations); |
0 | 1202 } |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1203 if (field_type_annotations != NULL) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1204 if (*fields_type_annotations == NULL) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1205 *fields_type_annotations = MetadataFactory::new_array<AnnotationArray*>( |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1206 loader_data, length, NULL, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1207 CHECK_NULL); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1208 } |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1209 (*fields_type_annotations)->at_put(n, field_type_annotations); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
1210 } |
0 | 1211 if (is_synthetic) { |
1212 access_flags.set_is_synthetic(); | |
1213 } | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1214 if (generic_signature_index != 0) { |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1215 access_flags.set_field_has_generic_signature(); |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1216 fa[generic_signature_slot] = generic_signature_index; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1217 generic_signature_slot ++; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1218 num_generic_signature ++; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1219 } |
0 | 1220 } |
1221 | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1222 FieldInfo* field = FieldInfo::from_field_array(fa, n); |
3938 | 1223 field->initialize(access_flags.as_short(), |
1224 name_index, | |
1225 signature_index, | |
7587 | 1226 constantvalue_index); |
3938 | 1227 BasicType type = cp->basic_type_for_signature_at(signature_index); |
0 | 1228 |
1229 // Remember how many oops we encountered and compute allocation type | |
3938 | 1230 FieldAllocationType atype = fac->update(is_static, type); |
7587 | 1231 field->set_allocation_type(atype); |
1232 | |
1233 // After field is initialized with type, we can augment it with aux info | |
1234 if (parsed_annotations.has_any_annotations()) | |
1235 parsed_annotations.apply_to(field); | |
3938 | 1236 } |
1237 | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1238 int index = length; |
3938 | 1239 if (num_injected != 0) { |
1240 for (int n = 0; n < num_injected; n++) { | |
1241 // Check for duplicates | |
1242 if (injected[n].may_be_java) { | |
1243 Symbol* name = injected[n].name(); | |
1244 Symbol* signature = injected[n].signature(); | |
1245 bool duplicate = false; | |
1246 for (int i = 0; i < length; i++) { | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1247 FieldInfo* f = FieldInfo::from_field_array(fa, i); |
3938 | 1248 if (name == cp->symbol_at(f->name_index()) && |
1249 signature == cp->symbol_at(f->signature_index())) { | |
1250 // Symbol is desclared in Java so skip this one | |
1251 duplicate = true; | |
1252 break; | |
1253 } | |
1254 } | |
1255 if (duplicate) { | |
1256 // These will be removed from the field array at the end | |
1257 continue; | |
1258 } | |
1259 } | |
1260 | |
1261 // Injected field | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1262 FieldInfo* field = FieldInfo::from_field_array(fa, index); |
3938 | 1263 field->initialize(JVM_ACC_FIELD_INTERNAL, |
1264 injected[n].name_index, | |
1265 injected[n].signature_index, | |
1266 0); | |
1267 | |
1268 BasicType type = FieldType::basic_type(injected[n].signature()); | |
1269 | |
1270 // Remember how many oops we encountered and compute allocation type | |
1271 FieldAllocationType atype = fac->update(false, type); | |
7587 | 1272 field->set_allocation_type(atype); |
3938 | 1273 index++; |
1274 } | |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1275 } |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1276 |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1277 // Now copy the fields' data from the temporary resource array. |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1278 // Sometimes injected fields already exist in the Java source so |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1279 // the fields array could be too long. In that case the |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1280 // fields array is trimed. Also unused slots that were reserved |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1281 // for generic signature indexes are discarded. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1282 Array<u2>* fields = MetadataFactory::new_array<u2>( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1283 loader_data, index * FieldInfo::field_slots + num_generic_signature, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1284 CHECK_NULL); |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1285 { |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1286 int i = 0; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1287 for (; i < index * FieldInfo::field_slots; i++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1288 fields->at_put(i, fa[i]); |
3938 | 1289 } |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1290 for (int j = total_fields * FieldInfo::field_slots; |
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1291 j < generic_signature_slot; j++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1292 fields->at_put(i++, fa[j]); |
6100
71afdabfd05b
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
6038
diff
changeset
|
1293 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1294 assert(i == fields->length(), ""); |
0 | 1295 } |
1296 | |
1297 if (_need_verify && length > 1) { | |
1298 // Check duplicated fields | |
1299 ResourceMark rm(THREAD); | |
1300 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( | |
1301 THREAD, NameSigHash*, HASH_ROW_SIZE); | |
1302 initialize_hashtable(names_and_sigs); | |
1303 bool dup = false; | |
1304 { | |
1305 debug_only(No_Safepoint_Verifier nsv;) | |
3938 | 1306 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { |
1307 Symbol* name = fs.name(); | |
1308 Symbol* sig = fs.signature(); | |
0 | 1309 // If no duplicates, add name/signature in hashtable names_and_sigs. |
1310 if (!put_after_lookup(name, sig, names_and_sigs)) { | |
1311 dup = true; | |
1312 break; | |
1313 } | |
1314 } | |
1315 } | |
1316 if (dup) { | |
1317 classfile_parse_error("Duplicate field name&signature in class file %s", | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1318 CHECK_NULL); |
0 | 1319 } |
1320 } | |
1321 | |
1322 return fields; | |
1323 } | |
1324 | |
1325 | |
1326 static void copy_u2_with_conversion(u2* dest, u2* src, int length) { | |
1327 while (length-- > 0) { | |
1328 *dest++ = Bytes::get_Java_u2((u1*) (src++)); | |
1329 } | |
1330 } | |
1331 | |
1332 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1333 u2* ClassFileParser::parse_exception_table(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1334 u4 code_length, |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1335 u4 exception_table_length, |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1336 constantPoolHandle cp, |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1337 TRAPS) { |
0 | 1338 ClassFileStream* cfs = stream(); |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1339 |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1340 u2* exception_table_start = cfs->get_u2_buffer(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1341 assert(exception_table_start != NULL, "null exception table"); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1342 cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc, end_pc, handler_pc, catch_type_index |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1343 // Will check legal target after parsing code array in verifier. |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1344 if (_need_verify) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1345 for (unsigned int i = 0; i < exception_table_length; i++) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1346 u2 start_pc = cfs->get_u2_fast(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1347 u2 end_pc = cfs->get_u2_fast(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1348 u2 handler_pc = cfs->get_u2_fast(); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1349 u2 catch_type_index = cfs->get_u2_fast(); |
0 | 1350 guarantee_property((start_pc < end_pc) && (end_pc <= code_length), |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1351 "Illegal exception table range in class file %s", |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1352 CHECK_NULL); |
0 | 1353 guarantee_property(handler_pc < code_length, |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1354 "Illegal exception table handler in class file %s", |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1355 CHECK_NULL); |
0 | 1356 if (catch_type_index != 0) { |
1357 guarantee_property(valid_cp_range(catch_type_index, cp->length()) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1358 is_klass_reference(cp, catch_type_index), |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1359 "Catch type in exception table has bad constant type in class file %s", CHECK_NULL); |
0 | 1360 } |
1361 } | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1362 } else { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1363 cfs->skip_u2_fast(exception_table_length * 4); |
0 | 1364 } |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
1365 return exception_table_start; |
0 | 1366 } |
1367 | |
1368 void ClassFileParser::parse_linenumber_table( | |
1369 u4 code_attribute_length, u4 code_length, | |
1370 CompressedLineNumberWriteStream** write_stream, TRAPS) { | |
1371 ClassFileStream* cfs = stream(); | |
1372 unsigned int num_entries = cfs->get_u2(CHECK); | |
1373 | |
1374 // Each entry is a u2 start_pc, and a u2 line_number | |
1375 unsigned int length_in_bytes = num_entries * (sizeof(u2) + sizeof(u2)); | |
1376 | |
1377 // Verify line number attribute and table length | |
1378 check_property( | |
1379 code_attribute_length == sizeof(u2) + length_in_bytes, | |
1380 "LineNumberTable attribute has wrong length in class file %s", CHECK); | |
1381 | |
1382 cfs->guarantee_more(length_in_bytes, CHECK); | |
1383 | |
1384 if ((*write_stream) == NULL) { | |
1385 if (length_in_bytes > fixed_buffer_size) { | |
1386 (*write_stream) = new CompressedLineNumberWriteStream(length_in_bytes); | |
1387 } else { | |
1388 (*write_stream) = new CompressedLineNumberWriteStream( | |
1389 linenumbertable_buffer, fixed_buffer_size); | |
1390 } | |
1391 } | |
1392 | |
1393 while (num_entries-- > 0) { | |
1394 u2 bci = cfs->get_u2_fast(); // start_pc | |
1395 u2 line = cfs->get_u2_fast(); // line_number | |
1396 guarantee_property(bci < code_length, | |
1397 "Invalid pc in LineNumberTable in class file %s", CHECK); | |
1398 (*write_stream)->write_pair(bci, line); | |
1399 } | |
1400 } | |
1401 | |
1402 | |
1403 // Class file LocalVariableTable elements. | |
1404 class Classfile_LVT_Element VALUE_OBJ_CLASS_SPEC { | |
1405 public: | |
1406 u2 start_bci; | |
1407 u2 length; | |
1408 u2 name_cp_index; | |
1409 u2 descriptor_cp_index; | |
1410 u2 slot; | |
1411 }; | |
1412 | |
1413 | |
6197 | 1414 class LVT_Hash: public CHeapObj<mtClass> { |
0 | 1415 public: |
1416 LocalVariableTableElement *_elem; // element | |
1417 LVT_Hash* _next; // Next entry in hash table | |
1418 }; | |
1419 | |
1420 unsigned int hash(LocalVariableTableElement *elem) { | |
1421 unsigned int raw_hash = elem->start_bci; | |
1422 | |
1423 raw_hash = elem->length + raw_hash * 37; | |
1424 raw_hash = elem->name_cp_index + raw_hash * 37; | |
1425 raw_hash = elem->slot + raw_hash * 37; | |
1426 | |
1427 return raw_hash % HASH_ROW_SIZE; | |
1428 } | |
1429 | |
1430 void initialize_hashtable(LVT_Hash** table) { | |
1431 for (int i = 0; i < HASH_ROW_SIZE; i++) { | |
1432 table[i] = NULL; | |
1433 } | |
1434 } | |
1435 | |
1436 void clear_hashtable(LVT_Hash** table) { | |
1437 for (int i = 0; i < HASH_ROW_SIZE; i++) { | |
1438 LVT_Hash* current = table[i]; | |
1439 LVT_Hash* next; | |
1440 while (current != NULL) { | |
1441 next = current->_next; | |
1442 current->_next = NULL; | |
1443 delete(current); | |
1444 current = next; | |
1445 } | |
1446 table[i] = NULL; | |
1447 } | |
1448 } | |
1449 | |
1450 LVT_Hash* LVT_lookup(LocalVariableTableElement *elem, int index, LVT_Hash** table) { | |
1451 LVT_Hash* entry = table[index]; | |
1452 | |
1453 /* | |
1454 * 3-tuple start_bci/length/slot has to be unique key, | |
1455 * so the following comparison seems to be redundant: | |
1456 * && elem->name_cp_index == entry->_elem->name_cp_index | |
1457 */ | |
1458 while (entry != NULL) { | |
1459 if (elem->start_bci == entry->_elem->start_bci | |
1460 && elem->length == entry->_elem->length | |
1461 && elem->name_cp_index == entry->_elem->name_cp_index | |
1462 && elem->slot == entry->_elem->slot | |
1463 ) { | |
1464 return entry; | |
1465 } | |
1466 entry = entry->_next; | |
1467 } | |
1468 return NULL; | |
1469 } | |
1470 | |
1471 // Return false if the local variable is found in table. | |
1472 // Return true if no duplicate is found. | |
1473 // And local variable is added as a new entry in table. | |
1474 bool LVT_put_after_lookup(LocalVariableTableElement *elem, LVT_Hash** table) { | |
1475 // First lookup for duplicates | |
1476 int index = hash(elem); | |
1477 LVT_Hash* entry = LVT_lookup(elem, index, table); | |
1478 | |
1479 if (entry != NULL) { | |
1480 return false; | |
1481 } | |
1482 // No duplicate is found, allocate a new entry and fill it. | |
1483 if ((entry = new LVT_Hash()) == NULL) { | |
1484 return false; | |
1485 } | |
1486 entry->_elem = elem; | |
1487 | |
1488 // Insert into hash table | |
1489 entry->_next = table[index]; | |
1490 table[index] = entry; | |
1491 | |
1492 return true; | |
1493 } | |
1494 | |
1495 void copy_lvt_element(Classfile_LVT_Element *src, LocalVariableTableElement *lvt) { | |
1496 lvt->start_bci = Bytes::get_Java_u2((u1*) &src->start_bci); | |
1497 lvt->length = Bytes::get_Java_u2((u1*) &src->length); | |
1498 lvt->name_cp_index = Bytes::get_Java_u2((u1*) &src->name_cp_index); | |
1499 lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index); | |
1500 lvt->signature_cp_index = 0; | |
1501 lvt->slot = Bytes::get_Java_u2((u1*) &src->slot); | |
1502 } | |
1503 | |
1504 // Function is used to parse both attributes: | |
1505 // LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT) | |
1506 u2* ClassFileParser::parse_localvariable_table(u4 code_length, | |
1507 u2 max_locals, | |
1508 u4 code_attribute_length, | |
1509 constantPoolHandle cp, | |
1510 u2* localvariable_table_length, | |
1511 bool isLVTT, | |
1512 TRAPS) { | |
1513 ClassFileStream* cfs = stream(); | |
1514 const char * tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable"; | |
1515 *localvariable_table_length = cfs->get_u2(CHECK_NULL); | |
1516 unsigned int size = (*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2); | |
1517 // Verify local variable table attribute has right length | |
1518 if (_need_verify) { | |
1519 guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)), | |
1520 "%s has wrong length in class file %s", tbl_name, CHECK_NULL); | |
1521 } | |
1522 u2* localvariable_table_start = cfs->get_u2_buffer(); | |
1523 assert(localvariable_table_start != NULL, "null local variable table"); | |
1524 if (!_need_verify) { | |
1525 cfs->skip_u2_fast(size); | |
1526 } else { | |
1527 cfs->guarantee_more(size * 2, CHECK_NULL); | |
1528 for(int i = 0; i < (*localvariable_table_length); i++) { | |
1529 u2 start_pc = cfs->get_u2_fast(); | |
1530 u2 length = cfs->get_u2_fast(); | |
1531 u2 name_index = cfs->get_u2_fast(); | |
1532 u2 descriptor_index = cfs->get_u2_fast(); | |
1533 u2 index = cfs->get_u2_fast(); | |
1534 // Assign to a u4 to avoid overflow | |
1535 u4 end_pc = (u4)start_pc + (u4)length; | |
1536 | |
1537 if (start_pc >= code_length) { | |
1538 classfile_parse_error( | |
1539 "Invalid start_pc %u in %s in class file %s", | |
1540 start_pc, tbl_name, CHECK_NULL); | |
1541 } | |
1542 if (end_pc > code_length) { | |
1543 classfile_parse_error( | |
1544 "Invalid length %u in %s in class file %s", | |
1545 length, tbl_name, CHECK_NULL); | |
1546 } | |
1547 int cp_size = cp->length(); | |
1548 guarantee_property( | |
1549 valid_cp_range(name_index, cp_size) && | |
1550 cp->tag_at(name_index).is_utf8(), | |
1551 "Name index %u in %s has bad constant type in class file %s", | |
1552 name_index, tbl_name, CHECK_NULL); | |
1553 guarantee_property( | |
1554 valid_cp_range(descriptor_index, cp_size) && | |
1555 cp->tag_at(descriptor_index).is_utf8(), | |
1556 "Signature index %u in %s has bad constant type in class file %s", | |
1557 descriptor_index, tbl_name, CHECK_NULL); | |
1558 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1559 Symbol* name = cp->symbol_at(name_index); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1560 Symbol* sig = cp->symbol_at(descriptor_index); |
0 | 1561 verify_legal_field_name(name, CHECK_NULL); |
1562 u2 extra_slot = 0; | |
1563 if (!isLVTT) { | |
1564 verify_legal_field_signature(name, sig, CHECK_NULL); | |
1565 | |
1566 // 4894874: check special cases for double and long local variables | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1567 if (sig == vmSymbols::type_signature(T_DOUBLE) || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1568 sig == vmSymbols::type_signature(T_LONG)) { |
0 | 1569 extra_slot = 1; |
1570 } | |
1571 } | |
1572 guarantee_property((index + extra_slot) < max_locals, | |
1573 "Invalid index %u in %s in class file %s", | |
1574 index, tbl_name, CHECK_NULL); | |
1575 } | |
1576 } | |
1577 return localvariable_table_start; | |
1578 } | |
1579 | |
1580 | |
1581 void ClassFileParser::parse_type_array(u2 array_length, u4 code_length, u4* u1_index, u4* u2_index, | |
1582 u1* u1_array, u2* u2_array, constantPoolHandle cp, TRAPS) { | |
1583 ClassFileStream* cfs = stream(); | |
1584 u2 index = 0; // index in the array with long/double occupying two slots | |
1585 u4 i1 = *u1_index; | |
1586 u4 i2 = *u2_index + 1; | |
1587 for(int i = 0; i < array_length; i++) { | |
1588 u1 tag = u1_array[i1++] = cfs->get_u1(CHECK); | |
1589 index++; | |
1590 if (tag == ITEM_Long || tag == ITEM_Double) { | |
1591 index++; | |
1592 } else if (tag == ITEM_Object) { | |
1593 u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK); | |
1594 guarantee_property(valid_cp_range(class_index, cp->length()) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1595 is_klass_reference(cp, class_index), |
0 | 1596 "Bad class index %u in StackMap in class file %s", |
1597 class_index, CHECK); | |
1598 } else if (tag == ITEM_Uninitialized) { | |
1599 u2 offset = u2_array[i2++] = cfs->get_u2(CHECK); | |
1600 guarantee_property( | |
1601 offset < code_length, | |
1602 "Bad uninitialized type offset %u in StackMap in class file %s", | |
1603 offset, CHECK); | |
1604 } else { | |
1605 guarantee_property( | |
1606 tag <= (u1)ITEM_Uninitialized, | |
1607 "Unknown variable type %u in StackMap in class file %s", | |
1608 tag, CHECK); | |
1609 } | |
1610 } | |
1611 u2_array[*u2_index] = index; | |
1612 *u1_index = i1; | |
1613 *u2_index = i2; | |
1614 } | |
1615 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1616 Array<u1>* ClassFileParser::parse_stackmap_table( |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1617 ClassLoaderData* loader_data, |
0 | 1618 u4 code_attribute_length, TRAPS) { |
1619 if (code_attribute_length == 0) | |
1620 return NULL; | |
1621 | |
1622 ClassFileStream* cfs = stream(); | |
1623 u1* stackmap_table_start = cfs->get_u1_buffer(); | |
1624 assert(stackmap_table_start != NULL, "null stackmap table"); | |
1625 | |
1626 // check code_attribute_length first | |
1627 stream()->skip_u1(code_attribute_length, CHECK_NULL); | |
1628 | |
1629 if (!_need_verify && !DumpSharedSpaces) { | |
1630 return NULL; | |
1631 } | |
1632 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1633 Array<u1>* stackmap_data = |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1634 MetadataFactory::new_array<u1>(loader_data, code_attribute_length, 0, CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1635 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
1636 memcpy((void*)stackmap_data->adr_at(0), |
0 | 1637 (void*)stackmap_table_start, code_attribute_length); |
1638 return stackmap_data; | |
1639 } | |
1640 | |
1641 u2* ClassFileParser::parse_checked_exceptions(u2* checked_exceptions_length, | |
1642 u4 method_attribute_length, | |
1643 constantPoolHandle cp, TRAPS) { | |
1644 ClassFileStream* cfs = stream(); | |
1645 cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length | |
1646 *checked_exceptions_length = cfs->get_u2_fast(); | |
1647 unsigned int size = (*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2); | |
1648 u2* checked_exceptions_start = cfs->get_u2_buffer(); | |
1649 assert(checked_exceptions_start != NULL, "null checked exceptions"); | |
1650 if (!_need_verify) { | |
1651 cfs->skip_u2_fast(size); | |
1652 } else { | |
1653 // Verify each value in the checked exception table | |
1654 u2 checked_exception; | |
1655 u2 len = *checked_exceptions_length; | |
1656 cfs->guarantee_more(2 * len, CHECK_NULL); | |
1657 for (int i = 0; i < len; i++) { | |
1658 checked_exception = cfs->get_u2_fast(); | |
1659 check_property( | |
1660 valid_cp_range(checked_exception, cp->length()) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
1661 is_klass_reference(cp, checked_exception), |
0 | 1662 "Exception name has bad type at constant pool %u in class file %s", |
1663 checked_exception, CHECK_NULL); | |
1664 } | |
1665 } | |
1666 // check exceptions attribute length | |
1667 if (_need_verify) { | |
1668 guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) + | |
1669 sizeof(u2) * size), | |
1670 "Exceptions attribute has wrong length in class file %s", CHECK_NULL); | |
1671 } | |
1672 return checked_exceptions_start; | |
1673 } | |
1674 | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1675 void ClassFileParser::throwIllegalSignature( |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
1676 const char* type, Symbol* name, Symbol* sig, TRAPS) { |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1677 ResourceMark rm(THREAD); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1678 Exceptions::fthrow(THREAD_AND_LOCATION, |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1679 vmSymbols::java_lang_ClassFormatError(), |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1680 "%s \"%s\" in class %s has illegal signature \"%s\"", type, |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1681 name->as_C_string(), _class_name->as_C_string(), sig->as_C_string()); |
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
1682 } |
0 | 1683 |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1684 // Skip an annotation. Return >=limit if there is any problem. |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1685 int ClassFileParser::skip_annotation(u1* buffer, int limit, int index) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1686 // annotation := atype:u2 do(nmem:u2) {member:u2 value} |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1687 // value := switch (tag:u1) { ... } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1688 index += 2; // skip atype |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1689 if ((index += 2) >= limit) return limit; // read nmem |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1690 int nmem = Bytes::get_Java_u2(buffer+index-2); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1691 while (--nmem >= 0 && index < limit) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1692 index += 2; // skip member |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1693 index = skip_annotation_value(buffer, limit, index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1694 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1695 return index; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1696 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1697 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1698 // Skip an annotation value. Return >=limit if there is any problem. |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1699 int ClassFileParser::skip_annotation_value(u1* buffer, int limit, int index) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1700 // value := switch (tag:u1) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1701 // case B, C, I, S, Z, D, F, J, c: con:u2; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1702 // case e: e_class:u2 e_name:u2; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1703 // case s: s_con:u2; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1704 // case [: do(nval:u2) {value}; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1705 // case @: annotation; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1706 // case s: s_con:u2; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1707 // } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1708 if ((index += 1) >= limit) return limit; // read tag |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1709 u1 tag = buffer[index-1]; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1710 switch (tag) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1711 case 'B': case 'C': case 'I': case 'S': case 'Z': |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1712 case 'D': case 'F': case 'J': case 'c': case 's': |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1713 index += 2; // skip con or s_con |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1714 break; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1715 case 'e': |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1716 index += 4; // skip e_class, e_name |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1717 break; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1718 case '[': |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1719 { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1720 if ((index += 2) >= limit) return limit; // read nval |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1721 int nval = Bytes::get_Java_u2(buffer+index-2); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1722 while (--nval >= 0 && index < limit) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1723 index = skip_annotation_value(buffer, limit, index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1724 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1725 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1726 break; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1727 case '@': |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1728 index = skip_annotation(buffer, limit, index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1729 break; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1730 default: |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1731 assert(false, "annotation tag"); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1732 return limit; // bad tag byte |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1733 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1734 return index; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1735 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1736 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1737 // Sift through annotations, looking for those significant to the VM: |
7587 | 1738 void ClassFileParser::parse_annotations(ClassLoaderData* loader_data, |
1739 u1* buffer, int limit, | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1740 constantPoolHandle cp, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1741 ClassFileParser::AnnotationCollector* coll, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1742 TRAPS) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1743 // annotations := do(nann:u2) {annotation} |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1744 int index = 0; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1745 if ((index += 2) >= limit) return; // read nann |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1746 int nann = Bytes::get_Java_u2(buffer+index-2); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1747 enum { // initial annotation layout |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1748 atype_off = 0, // utf8 such as 'Ljava/lang/annotation/Retention;' |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1749 count_off = 2, // u2 such as 1 (one value) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1750 member_off = 4, // utf8 such as 'value' |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1751 tag_off = 6, // u1 such as 'c' (type) or 'e' (enum) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1752 e_tag_val = 'e', |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1753 e_type_off = 7, // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;' |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1754 e_con_off = 9, // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME' |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1755 e_size = 11, // end of 'e' annotation |
7587 | 1756 c_tag_val = 'c', // payload is type |
1757 c_con_off = 7, // utf8 payload, such as 'I' | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1758 c_size = 9, // end of 'c' annotation |
7587 | 1759 s_tag_val = 's', // payload is String |
1760 s_con_off = 7, // utf8 payload, such as 'Ljava/lang/String;' | |
1761 s_size = 9, | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1762 min_size = 6 // smallest possible size (zero members) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1763 }; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1764 while ((--nann) >= 0 && (index-2 + min_size <= limit)) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1765 int index0 = index; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1766 index = skip_annotation(buffer, limit, index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1767 u1* abase = buffer + index0; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1768 int atype = Bytes::get_Java_u2(abase + atype_off); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1769 int count = Bytes::get_Java_u2(abase + count_off); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1770 Symbol* aname = check_symbol_at(cp, atype); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1771 if (aname == NULL) break; // invalid annotation name |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1772 Symbol* member = NULL; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1773 if (count >= 1) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1774 int member_index = Bytes::get_Java_u2(abase + member_off); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1775 member = check_symbol_at(cp, member_index); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1776 if (member == NULL) break; // invalid member name |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1777 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1778 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1779 // Here is where parsing particular annotations will take place. |
7587 | 1780 AnnotationCollector::ID id = coll->annotation_index(loader_data, aname); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1781 if (id == AnnotationCollector::_unknown) continue; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1782 coll->set_annotation(id); |
7587 | 1783 |
1784 if (id == AnnotationCollector::_sun_misc_Contended) { | |
1785 if (count == 1 | |
1786 && s_size == (index - index0) // match size | |
1787 && s_tag_val == *(abase + tag_off) | |
1788 && member == vmSymbols::value_name()) { | |
1789 u2 group_index = Bytes::get_Java_u2(abase + s_con_off); | |
1790 coll->set_contended_group(group_index); | |
1791 } else { | |
1792 coll->set_contended_group(0); // default contended group | |
1793 } | |
1794 coll->set_contended(true); | |
1795 } else { | |
1796 coll->set_contended(false); | |
1797 } | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1798 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1799 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1800 |
7587 | 1801 ClassFileParser::AnnotationCollector::ID |
1802 ClassFileParser::AnnotationCollector::annotation_index(ClassLoaderData* loader_data, | |
1803 Symbol* name) { | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1804 vmSymbols::SID sid = vmSymbols::find_sid(name); |
7639
22ead76da3f4
8006758: LinkResolver assertion (caused by @Contended changes)
kmo
parents:
7615
diff
changeset
|
1805 // Privileged code can use all annotations. Other code silently drops some. |
22ead76da3f4
8006758: LinkResolver assertion (caused by @Contended changes)
kmo
parents:
7615
diff
changeset
|
1806 bool privileged = loader_data->is_the_null_class_loader_data() || |
22ead76da3f4
8006758: LinkResolver assertion (caused by @Contended changes)
kmo
parents:
7615
diff
changeset
|
1807 loader_data->is_anonymous(); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1808 switch (sid) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1809 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_ForceInline_signature): |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1810 if (_location != _in_method) break; // only allow for methods |
7587 | 1811 if (!privileged) break; // only allow in privileged code |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1812 return _method_ForceInline; |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1813 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_DontInline_signature): |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1814 if (_location != _in_method) break; // only allow for methods |
7587 | 1815 if (!privileged) break; // only allow in privileged code |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1816 return _method_DontInline; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1817 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1818 if (_location != _in_method) break; // only allow for methods |
7587 | 1819 if (!privileged) break; // only allow in privileged code |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1820 return _method_LambdaForm_Compiled; |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1821 case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature): |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1822 if (_location != _in_method) break; // only allow for methods |
7587 | 1823 if (!privileged) break; // only allow in privileged code |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1824 return _method_LambdaForm_Hidden; |
7587 | 1825 case vmSymbols::VM_SYMBOL_ENUM_NAME(sun_misc_Contended_signature): |
1826 if (_location != _in_field && _location != _in_class) break; // only allow for fields and classes | |
1827 if (!EnableContended || (RestrictContended && !privileged)) break; // honor privileges | |
1828 return _sun_misc_Contended; | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1829 default: break; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1830 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1831 return AnnotationCollector::_unknown; |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1832 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1833 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1834 void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) { |
7587 | 1835 if (is_contended()) |
1836 f->set_contended_group(contended_group()); | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1837 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1838 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1839 void ClassFileParser::MethodAnnotationCollector::apply_to(methodHandle m) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1840 if (has_annotation(_method_ForceInline)) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1841 m->set_force_inline(true); |
6266
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1842 if (has_annotation(_method_DontInline)) |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1843 m->set_dont_inline(true); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1844 if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none) |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1845 m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm); |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1846 if (has_annotation(_method_LambdaForm_Hidden)) |
1d7922586cf6
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
6227
diff
changeset
|
1847 m->set_hidden(true); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1848 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1849 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1850 void ClassFileParser::ClassAnnotationCollector::apply_to(instanceKlassHandle k) { |
7587 | 1851 k->set_is_contended(is_contended()); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1852 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1853 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
1854 |
0 | 1855 #define MAX_ARGS_SIZE 255 |
1856 #define MAX_CODE_SIZE 65535 | |
1857 #define INITIAL_MAX_LVT_NUMBER 256 | |
1858 | |
8031 | 1859 /* Copy class file LVT's/LVTT's into the HotSpot internal LVT. |
1860 * | |
1861 * Rules for LVT's and LVTT's are: | |
1862 * - There can be any number of LVT's and LVTT's. | |
1863 * - If there are n LVT's, it is the same as if there was just | |
1864 * one LVT containing all the entries from the n LVT's. | |
1865 * - There may be no more than one LVT entry per local variable. | |
1866 * Two LVT entries are 'equal' if these fields are the same: | |
1867 * start_pc, length, name, slot | |
1868 * - There may be no more than one LVTT entry per each LVT entry. | |
1869 * Each LVTT entry has to match some LVT entry. | |
1870 * - HotSpot internal LVT keeps natural ordering of class file LVT entries. | |
1871 */ | |
1872 void ClassFileParser::copy_localvariable_table(ConstMethod* cm, | |
1873 int lvt_cnt, | |
1874 u2* localvariable_table_length, | |
1875 u2** localvariable_table_start, | |
1876 int lvtt_cnt, | |
1877 u2* localvariable_type_table_length, | |
1878 u2** localvariable_type_table_start, | |
1879 TRAPS) { | |
1880 | |
1881 LVT_Hash** lvt_Hash = NEW_RESOURCE_ARRAY(LVT_Hash*, HASH_ROW_SIZE); | |
1882 initialize_hashtable(lvt_Hash); | |
1883 | |
1884 // To fill LocalVariableTable in | |
1885 Classfile_LVT_Element* cf_lvt; | |
1886 LocalVariableTableElement* lvt = cm->localvariable_table_start(); | |
1887 | |
1888 for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) { | |
1889 cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no]; | |
1890 for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) { | |
1891 copy_lvt_element(&cf_lvt[idx], lvt); | |
1892 // If no duplicates, add LVT elem in hashtable lvt_Hash. | |
1893 if (LVT_put_after_lookup(lvt, lvt_Hash) == false | |
1894 && _need_verify | |
1895 && _major_version >= JAVA_1_5_VERSION) { | |
1896 clear_hashtable(lvt_Hash); | |
1897 ConstantPool* cp = cm->constants(); | |
1898 classfile_parse_error("Duplicated LocalVariableTable attribute " | |
1899 "entry for '%s' in class file %s", | |
1900 cp->symbol_at(lvt->name_cp_index)->as_utf8(), | |
1901 CHECK); | |
1902 } | |
1903 } | |
1904 } | |
1905 | |
1906 // To merge LocalVariableTable and LocalVariableTypeTable | |
1907 Classfile_LVT_Element* cf_lvtt; | |
1908 LocalVariableTableElement lvtt_elem; | |
1909 | |
1910 for (int tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) { | |
1911 cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no]; | |
1912 for (int idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) { | |
1913 copy_lvt_element(&cf_lvtt[idx], &lvtt_elem); | |
1914 int index = hash(&lvtt_elem); | |
1915 LVT_Hash* entry = LVT_lookup(&lvtt_elem, index, lvt_Hash); | |
1916 if (entry == NULL) { | |
1917 if (_need_verify) { | |
1918 clear_hashtable(lvt_Hash); | |
1919 ConstantPool* cp = cm->constants(); | |
1920 classfile_parse_error("LVTT entry for '%s' in class file %s " | |
1921 "does not match any LVT entry", | |
1922 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
1923 CHECK); | |
1924 } | |
1925 } else if (entry->_elem->signature_cp_index != 0 && _need_verify) { | |
1926 clear_hashtable(lvt_Hash); | |
1927 ConstantPool* cp = cm->constants(); | |
1928 classfile_parse_error("Duplicated LocalVariableTypeTable attribute " | |
1929 "entry for '%s' in class file %s", | |
1930 cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), | |
1931 CHECK); | |
1932 } else { | |
1933 // to add generic signatures into LocalVariableTable | |
1934 entry->_elem->signature_cp_index = lvtt_elem.descriptor_cp_index; | |
1935 } | |
1936 } | |
1937 } | |
1938 clear_hashtable(lvt_Hash); | |
1939 } | |
1940 | |
1941 | |
1942 void ClassFileParser::copy_method_annotations(ClassLoaderData* loader_data, | |
1943 ConstMethod* cm, | |
1944 u1* runtime_visible_annotations, | |
1945 int runtime_visible_annotations_length, | |
1946 u1* runtime_invisible_annotations, | |
1947 int runtime_invisible_annotations_length, | |
1948 u1* runtime_visible_parameter_annotations, | |
1949 int runtime_visible_parameter_annotations_length, | |
1950 u1* runtime_invisible_parameter_annotations, | |
1951 int runtime_invisible_parameter_annotations_length, | |
1952 u1* runtime_visible_type_annotations, | |
1953 int runtime_visible_type_annotations_length, | |
1954 u1* runtime_invisible_type_annotations, | |
1955 int runtime_invisible_type_annotations_length, | |
1956 u1* annotation_default, | |
1957 int annotation_default_length, | |
1958 TRAPS) { | |
1959 | |
1960 AnnotationArray* a; | |
1961 | |
1962 if (runtime_visible_annotations_length + | |
1963 runtime_invisible_annotations_length > 0) { | |
1964 a = assemble_annotations(loader_data, | |
1965 runtime_visible_annotations, | |
1966 runtime_visible_annotations_length, | |
1967 runtime_invisible_annotations, | |
1968 runtime_invisible_annotations_length, | |
1969 CHECK); | |
1970 cm->set_method_annotations(a); | |
1971 } | |
1972 | |
1973 if (runtime_visible_parameter_annotations_length + | |
1974 runtime_invisible_parameter_annotations_length > 0) { | |
1975 a = assemble_annotations(loader_data, | |
1976 runtime_visible_parameter_annotations, | |
1977 runtime_visible_parameter_annotations_length, | |
1978 runtime_invisible_parameter_annotations, | |
1979 runtime_invisible_parameter_annotations_length, | |
1980 CHECK); | |
1981 cm->set_parameter_annotations(a); | |
1982 } | |
1983 | |
1984 if (annotation_default_length > 0) { | |
1985 a = assemble_annotations(loader_data, | |
1986 annotation_default, | |
1987 annotation_default_length, | |
1988 NULL, | |
1989 0, | |
1990 CHECK); | |
1991 cm->set_default_annotations(a); | |
1992 } | |
1993 | |
1994 if (runtime_visible_type_annotations_length + | |
1995 runtime_invisible_type_annotations_length > 0) { | |
1996 a = assemble_annotations(loader_data, | |
1997 runtime_visible_type_annotations, | |
1998 runtime_visible_type_annotations_length, | |
1999 runtime_invisible_type_annotations, | |
2000 runtime_invisible_type_annotations_length, | |
2001 CHECK); | |
2002 cm->set_type_annotations(a); | |
2003 } | |
2004 } | |
2005 | |
2006 | |
0 | 2007 // Note: the parse_method below is big and clunky because all parsing of the code and exceptions |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2008 // attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2009 // Method* to save footprint, so we only know the size of the resulting Method* when the |
0 | 2010 // entire method attribute is parsed. |
2011 // | |
2012 // The promoted_flags parameter is used to pass relevant access_flags | |
2013 // from the method back up to the containing klass. These flag values | |
2014 // are added to klass's access_flags. | |
2015 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2016 methodHandle ClassFileParser::parse_method(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2017 constantPoolHandle cp, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2018 bool is_interface, |
0 | 2019 AccessFlags *promoted_flags, |
2020 TRAPS) { | |
2021 ClassFileStream* cfs = stream(); | |
2022 methodHandle nullHandle; | |
2023 ResourceMark rm(THREAD); | |
2024 // Parse fixed parts | |
2025 cfs->guarantee_more(8, CHECK_(nullHandle)); // access_flags, name_index, descriptor_index, attributes_count | |
2026 | |
2027 int flags = cfs->get_u2_fast(); | |
2028 u2 name_index = cfs->get_u2_fast(); | |
2029 int cp_size = cp->length(); | |
2030 check_property( | |
2031 valid_cp_range(name_index, cp_size) && | |
2032 cp->tag_at(name_index).is_utf8(), | |
2033 "Illegal constant pool index %u for method name in class file %s", | |
2034 name_index, CHECK_(nullHandle)); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2035 Symbol* name = cp->symbol_at(name_index); |
0 | 2036 verify_legal_method_name(name, CHECK_(nullHandle)); |
2037 | |
2038 u2 signature_index = cfs->get_u2_fast(); | |
2039 guarantee_property( | |
2040 valid_cp_range(signature_index, cp_size) && | |
2041 cp->tag_at(signature_index).is_utf8(), | |
2042 "Illegal constant pool index %u for method signature in class file %s", | |
2043 signature_index, CHECK_(nullHandle)); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2044 Symbol* signature = cp->symbol_at(signature_index); |
0 | 2045 |
2046 AccessFlags access_flags; | |
2047 if (name == vmSymbols::class_initializer_name()) { | |
2334
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2048 // We ignore the other access flags for a valid class initializer. |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2049 // (JVM Spec 2nd ed., chapter 4.6) |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2050 if (_major_version < 51) { // backward compatibility |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2051 flags = JVM_ACC_STATIC; |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2052 } else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) { |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2053 flags &= JVM_ACC_STATIC | JVM_ACC_STRICT; |
dbad0519a1c4
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
2226
diff
changeset
|
2054 } |
0 | 2055 } else { |
2056 verify_legal_method_modifiers(flags, is_interface, name, CHECK_(nullHandle)); | |
2057 } | |
2058 | |
2059 int args_size = -1; // only used when _need_verify is true | |
2060 if (_need_verify) { | |
2061 args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) + | |
2062 verify_legal_method_signature(name, signature, CHECK_(nullHandle)); | |
2063 if (args_size > MAX_ARGS_SIZE) { | |
2064 classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_(nullHandle)); | |
2065 } | |
2066 } | |
2067 | |
2068 access_flags.set_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS); | |
2069 | |
2070 // Default values for code and exceptions attribute elements | |
2071 u2 max_stack = 0; | |
2072 u2 max_locals = 0; | |
2073 u4 code_length = 0; | |
2074 u1* code_start = 0; | |
2075 u2 exception_table_length = 0; | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2076 u2* exception_table_start = NULL; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2077 Array<int>* exception_handlers = Universe::the_empty_int_array(); |
0 | 2078 u2 checked_exceptions_length = 0; |
2079 u2* checked_exceptions_start = NULL; | |
2080 CompressedLineNumberWriteStream* linenumber_table = NULL; | |
2081 int linenumber_table_length = 0; | |
2082 int total_lvt_length = 0; | |
2083 u2 lvt_cnt = 0; | |
2084 u2 lvtt_cnt = 0; | |
2085 bool lvt_allocated = false; | |
2086 u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER; | |
2087 u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER; | |
2088 u2* localvariable_table_length; | |
2089 u2** localvariable_table_start; | |
2090 u2* localvariable_type_table_length; | |
2091 u2** localvariable_type_table_start; | |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2092 u2 method_parameters_length = 0; |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2093 u1* method_parameters_data = NULL; |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2094 bool method_parameters_seen = false; |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2095 bool method_parameters_four_byte_flags; |
0 | 2096 bool parsed_code_attribute = false; |
2097 bool parsed_checked_exceptions_attribute = false; | |
2098 bool parsed_stackmap_attribute = false; | |
2099 // stackmap attribute - JDK1.5 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2100 Array<u1>* stackmap_data = NULL; |
0 | 2101 u2 generic_signature_index = 0; |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2102 MethodAnnotationCollector parsed_annotations; |
0 | 2103 u1* runtime_visible_annotations = NULL; |
2104 int runtime_visible_annotations_length = 0; | |
2105 u1* runtime_invisible_annotations = NULL; | |
2106 int runtime_invisible_annotations_length = 0; | |
2107 u1* runtime_visible_parameter_annotations = NULL; | |
2108 int runtime_visible_parameter_annotations_length = 0; | |
2109 u1* runtime_invisible_parameter_annotations = NULL; | |
2110 int runtime_invisible_parameter_annotations_length = 0; | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2111 u1* runtime_visible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2112 int runtime_visible_type_annotations_length = 0; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2113 u1* runtime_invisible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2114 int runtime_invisible_type_annotations_length = 0; |
0 | 2115 u1* annotation_default = NULL; |
2116 int annotation_default_length = 0; | |
2117 | |
2118 // Parse code and exceptions attribute | |
2119 u2 method_attributes_count = cfs->get_u2_fast(); | |
2120 while (method_attributes_count--) { | |
2121 cfs->guarantee_more(6, CHECK_(nullHandle)); // method_attribute_name_index, method_attribute_length | |
2122 u2 method_attribute_name_index = cfs->get_u2_fast(); | |
2123 u4 method_attribute_length = cfs->get_u4_fast(); | |
2124 check_property( | |
2125 valid_cp_range(method_attribute_name_index, cp_size) && | |
2126 cp->tag_at(method_attribute_name_index).is_utf8(), | |
2127 "Invalid method attribute name index %u in class file %s", | |
2128 method_attribute_name_index, CHECK_(nullHandle)); | |
2129 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2130 Symbol* method_attribute_name = cp->symbol_at(method_attribute_name_index); |
0 | 2131 if (method_attribute_name == vmSymbols::tag_code()) { |
2132 // Parse Code attribute | |
2133 if (_need_verify) { | |
6934 | 2134 guarantee_property( |
2135 !access_flags.is_native() && !access_flags.is_abstract(), | |
0 | 2136 "Code attribute in native or abstract methods in class file %s", |
2137 CHECK_(nullHandle)); | |
2138 } | |
2139 if (parsed_code_attribute) { | |
2140 classfile_parse_error("Multiple Code attributes in class file %s", CHECK_(nullHandle)); | |
2141 } | |
2142 parsed_code_attribute = true; | |
2143 | |
2144 // Stack size, locals size, and code size | |
2145 if (_major_version == 45 && _minor_version <= 2) { | |
2146 cfs->guarantee_more(4, CHECK_(nullHandle)); | |
2147 max_stack = cfs->get_u1_fast(); | |
2148 max_locals = cfs->get_u1_fast(); | |
2149 code_length = cfs->get_u2_fast(); | |
2150 } else { | |
2151 cfs->guarantee_more(8, CHECK_(nullHandle)); | |
2152 max_stack = cfs->get_u2_fast(); | |
2153 max_locals = cfs->get_u2_fast(); | |
2154 code_length = cfs->get_u4_fast(); | |
2155 } | |
2156 if (_need_verify) { | |
2157 guarantee_property(args_size <= max_locals, | |
2158 "Arguments can't fit into locals in class file %s", CHECK_(nullHandle)); | |
2159 guarantee_property(code_length > 0 && code_length <= MAX_CODE_SIZE, | |
2160 "Invalid method Code length %u in class file %s", | |
2161 code_length, CHECK_(nullHandle)); | |
2162 } | |
2163 // Code pointer | |
2164 code_start = cfs->get_u1_buffer(); | |
2165 assert(code_start != NULL, "null code start"); | |
2166 cfs->guarantee_more(code_length, CHECK_(nullHandle)); | |
2167 cfs->skip_u1_fast(code_length); | |
2168 | |
2169 // Exception handler table | |
2170 cfs->guarantee_more(2, CHECK_(nullHandle)); // exception_table_length | |
2171 exception_table_length = cfs->get_u2_fast(); | |
2172 if (exception_table_length > 0) { | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2173 exception_table_start = |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2174 parse_exception_table(loader_data, code_length, exception_table_length, cp, CHECK_(nullHandle)); |
0 | 2175 } |
2176 | |
2177 // Parse additional attributes in code attribute | |
2178 cfs->guarantee_more(2, CHECK_(nullHandle)); // code_attributes_count | |
2179 u2 code_attributes_count = cfs->get_u2_fast(); | |
92
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2180 |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2181 unsigned int calculated_attribute_length = 0; |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2182 |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2183 if (_major_version > 45 || (_major_version == 45 && _minor_version > 2)) { |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2184 calculated_attribute_length = |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2185 sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length); |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2186 } else { |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2187 // max_stack, locals and length are smaller in pre-version 45.2 classes |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2188 calculated_attribute_length = sizeof(u1) + sizeof(u1) + sizeof(u2); |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2189 } |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2190 calculated_attribute_length += |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2191 code_length + |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2192 sizeof(exception_table_length) + |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2193 sizeof(code_attributes_count) + |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2194 exception_table_length * |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2195 ( sizeof(u2) + // start_pc |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2196 sizeof(u2) + // end_pc |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2197 sizeof(u2) + // handler_pc |
ebec5b9731e2
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
0
diff
changeset
|
2198 sizeof(u2) ); // catch_type_index |
0 | 2199 |
2200 while (code_attributes_count--) { | |
2201 cfs->guarantee_more(6, CHECK_(nullHandle)); // code_attribute_name_index, code_attribute_length | |
2202 u2 code_attribute_name_index = cfs->get_u2_fast(); | |
2203 u4 code_attribute_length = cfs->get_u4_fast(); | |
2204 calculated_attribute_length += code_attribute_length + | |
2205 sizeof(code_attribute_name_index) + | |
2206 sizeof(code_attribute_length); | |
2207 check_property(valid_cp_range(code_attribute_name_index, cp_size) && | |
2208 cp->tag_at(code_attribute_name_index).is_utf8(), | |
2209 "Invalid code attribute name index %u in class file %s", | |
2210 code_attribute_name_index, | |
2211 CHECK_(nullHandle)); | |
2212 if (LoadLineNumberTables && | |
2213 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { | |
2214 // Parse and compress line number table | |
2215 parse_linenumber_table(code_attribute_length, code_length, | |
2216 &linenumber_table, CHECK_(nullHandle)); | |
2217 | |
2218 } else if (LoadLocalVariableTables && | |
2219 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { | |
2220 // Parse local variable table | |
2221 if (!lvt_allocated) { | |
2222 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2223 THREAD, u2, INITIAL_MAX_LVT_NUMBER); | |
2224 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2225 THREAD, u2*, INITIAL_MAX_LVT_NUMBER); | |
2226 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2227 THREAD, u2, INITIAL_MAX_LVT_NUMBER); | |
2228 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2229 THREAD, u2*, INITIAL_MAX_LVT_NUMBER); | |
2230 lvt_allocated = true; | |
2231 } | |
2232 if (lvt_cnt == max_lvt_cnt) { | |
2233 max_lvt_cnt <<= 1; | |
2234 REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt); | |
2235 REALLOC_RESOURCE_ARRAY(u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt); | |
2236 } | |
2237 localvariable_table_start[lvt_cnt] = | |
2238 parse_localvariable_table(code_length, | |
2239 max_locals, | |
2240 code_attribute_length, | |
2241 cp, | |
2242 &localvariable_table_length[lvt_cnt], | |
2243 false, // is not LVTT | |
2244 CHECK_(nullHandle)); | |
2245 total_lvt_length += localvariable_table_length[lvt_cnt]; | |
2246 lvt_cnt++; | |
2247 } else if (LoadLocalVariableTypeTables && | |
2248 _major_version >= JAVA_1_5_VERSION && | |
2249 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { | |
2250 if (!lvt_allocated) { | |
2251 localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2252 THREAD, u2, INITIAL_MAX_LVT_NUMBER); | |
2253 localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2254 THREAD, u2*, INITIAL_MAX_LVT_NUMBER); | |
2255 localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2256 THREAD, u2, INITIAL_MAX_LVT_NUMBER); | |
2257 localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2258 THREAD, u2*, INITIAL_MAX_LVT_NUMBER); | |
2259 lvt_allocated = true; | |
2260 } | |
2261 // Parse local variable type table | |
2262 if (lvtt_cnt == max_lvtt_cnt) { | |
2263 max_lvtt_cnt <<= 1; | |
2264 REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt); | |
2265 REALLOC_RESOURCE_ARRAY(u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt); | |
2266 } | |
2267 localvariable_type_table_start[lvtt_cnt] = | |
2268 parse_localvariable_table(code_length, | |
2269 max_locals, | |
2270 code_attribute_length, | |
2271 cp, | |
2272 &localvariable_type_table_length[lvtt_cnt], | |
2273 true, // is LVTT | |
2274 CHECK_(nullHandle)); | |
2275 lvtt_cnt++; | |
2276 } else if (UseSplitVerifier && | |
2277 _major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION && | |
2278 cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { | |
2279 // Stack map is only needed by the new verifier in JDK1.5. | |
2280 if (parsed_stackmap_attribute) { | |
2281 classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_(nullHandle)); | |
2282 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2283 stackmap_data = parse_stackmap_table(loader_data, code_attribute_length, CHECK_(nullHandle)); |
0 | 2284 parsed_stackmap_attribute = true; |
2285 } else { | |
2286 // Skip unknown attributes | |
2287 cfs->skip_u1(code_attribute_length, CHECK_(nullHandle)); | |
2288 } | |
2289 } | |
2290 // check method attribute length | |
2291 if (_need_verify) { | |
2292 guarantee_property(method_attribute_length == calculated_attribute_length, | |
2293 "Code segment has wrong length in class file %s", CHECK_(nullHandle)); | |
2294 } | |
2295 } else if (method_attribute_name == vmSymbols::tag_exceptions()) { | |
2296 // Parse Exceptions attribute | |
2297 if (parsed_checked_exceptions_attribute) { | |
2298 classfile_parse_error("Multiple Exceptions attributes in class file %s", CHECK_(nullHandle)); | |
2299 } | |
2300 parsed_checked_exceptions_attribute = true; | |
2301 checked_exceptions_start = | |
2302 parse_checked_exceptions(&checked_exceptions_length, | |
2303 method_attribute_length, | |
2304 cp, CHECK_(nullHandle)); | |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2305 } else if (method_attribute_name == vmSymbols::tag_method_parameters()) { |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2306 // reject multiple method parameters |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2307 if (method_parameters_seen) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2308 classfile_parse_error("Multiple MethodParameters attributes in class file %s", CHECK_(nullHandle)); |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2309 } |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2310 method_parameters_seen = true; |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2311 method_parameters_length = cfs->get_u1_fast(); |
7588
f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
7579
diff
changeset
|
2312 // Track the actual size (note: this is written for clarity; a |
f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
7579
diff
changeset
|
2313 // decent compiler will CSE and constant-fold this into a single |
f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
7579
diff
changeset
|
2314 // expression) |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2315 // Use the attribute length to figure out the size of flags |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2316 if (method_attribute_length == (method_parameters_length * 6u) + 1u) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2317 method_parameters_four_byte_flags = true; |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2318 } else if (method_attribute_length == (method_parameters_length * 4u) + 1u) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2319 method_parameters_four_byte_flags = false; |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2320 } else { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2321 classfile_parse_error( |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2322 "Invalid MethodParameters method attribute length %u in class file", |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2323 method_attribute_length, CHECK_(nullHandle)); |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2324 } |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2325 method_parameters_data = cfs->get_u1_buffer(); |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2326 cfs->skip_u2_fast(method_parameters_length); |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2327 if (method_parameters_four_byte_flags) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2328 cfs->skip_u4_fast(method_parameters_length); |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2329 } else { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2330 cfs->skip_u2_fast(method_parameters_length); |
7588
f9eb431c3efe
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
7579
diff
changeset
|
2331 } |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2332 // ignore this attribute if it cannot be reflected |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2333 if (!SystemDictionary::Parameter_klass_loaded()) |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2334 method_parameters_length = 0; |
0 | 2335 } else if (method_attribute_name == vmSymbols::tag_synthetic()) { |
2336 if (method_attribute_length != 0) { | |
2337 classfile_parse_error( | |
2338 "Invalid Synthetic method attribute length %u in class file %s", | |
2339 method_attribute_length, CHECK_(nullHandle)); | |
2340 } | |
2341 // Should we check that there hasn't already been a synthetic attribute? | |
2342 access_flags.set_is_synthetic(); | |
2343 } else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120 | |
2344 if (method_attribute_length != 0) { | |
2345 classfile_parse_error( | |
2346 "Invalid Deprecated method attribute length %u in class file %s", | |
2347 method_attribute_length, CHECK_(nullHandle)); | |
2348 } | |
2349 } else if (_major_version >= JAVA_1_5_VERSION) { | |
2350 if (method_attribute_name == vmSymbols::tag_signature()) { | |
2351 if (method_attribute_length != 2) { | |
2352 classfile_parse_error( | |
2353 "Invalid Signature attribute length %u in class file %s", | |
2354 method_attribute_length, CHECK_(nullHandle)); | |
2355 } | |
2356 cfs->guarantee_more(2, CHECK_(nullHandle)); // generic_signature_index | |
2357 generic_signature_index = cfs->get_u2_fast(); | |
2358 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) { | |
2359 runtime_visible_annotations_length = method_attribute_length; | |
2360 runtime_visible_annotations = cfs->get_u1_buffer(); | |
2361 assert(runtime_visible_annotations != NULL, "null visible annotations"); | |
7587 | 2362 parse_annotations(loader_data, |
2363 runtime_visible_annotations, | |
6934 | 2364 runtime_visible_annotations_length, cp, &parsed_annotations, |
2365 CHECK_(nullHandle)); | |
0 | 2366 cfs->skip_u1(runtime_visible_annotations_length, CHECK_(nullHandle)); |
2367 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { | |
2368 runtime_invisible_annotations_length = method_attribute_length; | |
2369 runtime_invisible_annotations = cfs->get_u1_buffer(); | |
2370 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); | |
2371 cfs->skip_u1(runtime_invisible_annotations_length, CHECK_(nullHandle)); | |
2372 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) { | |
2373 runtime_visible_parameter_annotations_length = method_attribute_length; | |
2374 runtime_visible_parameter_annotations = cfs->get_u1_buffer(); | |
2375 assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations"); | |
2376 cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_(nullHandle)); | |
2377 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) { | |
2378 runtime_invisible_parameter_annotations_length = method_attribute_length; | |
2379 runtime_invisible_parameter_annotations = cfs->get_u1_buffer(); | |
2380 assert(runtime_invisible_parameter_annotations != NULL, "null invisible parameter annotations"); | |
2381 cfs->skip_u1(runtime_invisible_parameter_annotations_length, CHECK_(nullHandle)); | |
2382 } else if (method_attribute_name == vmSymbols::tag_annotation_default()) { | |
2383 annotation_default_length = method_attribute_length; | |
2384 annotation_default = cfs->get_u1_buffer(); | |
2385 assert(annotation_default != NULL, "null annotation default"); | |
2386 cfs->skip_u1(annotation_default_length, CHECK_(nullHandle)); | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2387 } else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2388 runtime_visible_type_annotations_length = method_attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2389 runtime_visible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2390 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2391 // No need for the VM to parse Type annotations |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2392 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_(nullHandle)); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2393 } else if (PreserveAllAnnotations && method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2394 runtime_invisible_type_annotations_length = method_attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2395 runtime_invisible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2396 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2397 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK_(nullHandle)); |
0 | 2398 } else { |
2399 // Skip unknown attributes | |
2400 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); | |
2401 } | |
2402 } else { | |
2403 // Skip unknown attributes | |
2404 cfs->skip_u1(method_attribute_length, CHECK_(nullHandle)); | |
2405 } | |
2406 } | |
2407 | |
2408 if (linenumber_table != NULL) { | |
2409 linenumber_table->write_terminator(); | |
2410 linenumber_table_length = linenumber_table->position(); | |
2411 } | |
2412 | |
2413 // Make sure there's at least one Code attribute in non-native/non-abstract method | |
2414 if (_need_verify) { | |
2415 guarantee_property(access_flags.is_native() || access_flags.is_abstract() || parsed_code_attribute, | |
2416 "Absent Code attribute in method that is not native or abstract in class file %s", CHECK_(nullHandle)); | |
2417 } | |
2418 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2419 // All sizing information for a Method* is finally available, now create it |
8031 | 2420 InlineTableSizes sizes( |
2421 total_lvt_length, | |
2422 linenumber_table_length, | |
2423 exception_table_length, | |
2424 checked_exceptions_length, | |
2425 method_parameters_length, | |
2426 generic_signature_index, | |
2427 runtime_visible_annotations_length + | |
2428 runtime_invisible_annotations_length, | |
2429 runtime_visible_parameter_annotations_length + | |
2430 runtime_invisible_parameter_annotations_length, | |
2431 runtime_visible_type_annotations_length + | |
2432 runtime_invisible_type_annotations_length, | |
2433 annotation_default_length, | |
2434 0); | |
2435 | |
6934 | 2436 Method* m = Method::allocate( |
8031 | 2437 loader_data, code_length, access_flags, &sizes, |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2438 ConstMethod::NORMAL, CHECK_(nullHandle)); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2439 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2440 ClassLoadingService::add_class_method_size(m->size()*HeapWordSize); |
0 | 2441 |
2442 // Fill in information from fixed part (access_flags already set) | |
2443 m->set_constants(cp()); | |
2444 m->set_name_index(name_index); | |
2445 m->set_signature_index(signature_index); | |
2446 #ifdef CC_INTERP | |
2447 // hmm is there a gc issue here?? | |
2448 ResultTypeFinder rtf(cp->symbol_at(signature_index)); | |
2449 m->set_result_index(rtf.type()); | |
2450 #endif | |
2451 | |
2452 if (args_size >= 0) { | |
2453 m->set_size_of_parameters(args_size); | |
2454 } else { | |
2455 m->compute_size_of_parameters(THREAD); | |
2456 } | |
2457 #ifdef ASSERT | |
2458 if (args_size >= 0) { | |
2459 m->compute_size_of_parameters(THREAD); | |
2460 assert(args_size == m->size_of_parameters(), ""); | |
2461 } | |
2462 #endif | |
2463 | |
2464 // Fill in code attribute information | |
2465 m->set_max_stack(max_stack); | |
2466 m->set_max_locals(max_locals); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2467 m->constMethod()->set_stackmap_data(stackmap_data); |
0 | 2468 |
2469 // Copy byte codes | |
1138
dd57230ba8fe
6893268: additional dynamic language related optimizations in C2
twisti
parents:
1108
diff
changeset
|
2470 m->set_code(code_start); |
0 | 2471 |
2472 // Copy line number table | |
2473 if (linenumber_table != NULL) { | |
2474 memcpy(m->compressed_linenumber_table(), | |
2475 linenumber_table->buffer(), linenumber_table_length); | |
2476 } | |
2477 | |
6213
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2478 // Copy exception table |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2479 if (exception_table_length > 0) { |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2480 int size = |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2481 exception_table_length * sizeof(ExceptionTableElement) / sizeof(u2); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2482 copy_u2_with_conversion((u2*) m->exception_table_start(), |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2483 exception_table_start, size); |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2484 } |
8150fa46d2ed
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
6100
diff
changeset
|
2485 |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2486 // Copy method parameters |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2487 if (method_parameters_length > 0) { |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2488 MethodParametersElement* elem = m->constMethod()->method_parameters_start(); |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2489 for (int i = 0; i < method_parameters_length; i++) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2490 elem[i].name_cp_index = Bytes::get_Java_u2(method_parameters_data); |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2491 method_parameters_data += 2; |
7983
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2492 if (method_parameters_four_byte_flags) { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2493 elem[i].flags = Bytes::get_Java_u4(method_parameters_data); |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2494 method_parameters_data += 4; |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2495 } else { |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2496 elem[i].flags = Bytes::get_Java_u2(method_parameters_data); |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2497 method_parameters_data += 2; |
24a91505f9d5
8006949: Update hotspot for MethodParameters format change
emc
parents:
7639
diff
changeset
|
2498 } |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2499 } |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2500 } |
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
2501 |
0 | 2502 // Copy checked exceptions |
2503 if (checked_exceptions_length > 0) { | |
2504 int size = checked_exceptions_length * sizeof(CheckedExceptionElement) / sizeof(u2); | |
2505 copy_u2_with_conversion((u2*) m->checked_exceptions_start(), checked_exceptions_start, size); | |
2506 } | |
2507 | |
8031 | 2508 // Copy class file LVT's/LVTT's into the HotSpot internal LVT. |
0 | 2509 if (total_lvt_length > 0) { |
2510 promoted_flags->set_has_localvariable_table(); | |
8031 | 2511 copy_localvariable_table(m->constMethod(), lvt_cnt, |
2512 localvariable_table_length, | |
2513 localvariable_table_start, | |
2514 lvtt_cnt, | |
2515 localvariable_type_table_length, | |
2516 localvariable_type_table_start, CHECK_NULL); | |
0 | 2517 } |
2518 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2519 if (parsed_annotations.has_any_annotations()) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2520 parsed_annotations.apply_to(m); |
8031 | 2521 |
2522 // Copy annotations | |
2523 copy_method_annotations(loader_data, m->constMethod(), | |
2524 runtime_visible_annotations, | |
2525 runtime_visible_annotations_length, | |
2526 runtime_invisible_annotations, | |
2527 runtime_invisible_annotations_length, | |
2528 runtime_visible_parameter_annotations, | |
2529 runtime_visible_parameter_annotations_length, | |
2530 runtime_invisible_parameter_annotations, | |
2531 runtime_invisible_parameter_annotations_length, | |
2532 runtime_visible_type_annotations, | |
2533 runtime_visible_type_annotations_length, | |
2534 runtime_invisible_type_annotations, | |
2535 runtime_invisible_type_annotations_length, | |
2536 annotation_default, | |
2537 annotation_default_length, | |
2538 CHECK_NULL); | |
0 | 2539 |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2540 if (name == vmSymbols::finalize_method_name() && |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2541 signature == vmSymbols::void_method_signature()) { |
0 | 2542 if (m->is_empty_method()) { |
2543 _has_empty_finalizer = true; | |
2544 } else { | |
2545 _has_finalizer = true; | |
2546 } | |
2547 } | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2548 if (name == vmSymbols::object_initializer_name() && |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2549 signature == vmSymbols::void_method_signature() && |
0 | 2550 m->is_vanilla_constructor()) { |
2551 _has_vanilla_constructor = true; | |
2552 } | |
2553 | |
8031 | 2554 NOT_PRODUCT(m->verify()); |
0 | 2555 return m; |
2556 } | |
2557 | |
2558 | |
2559 // The promoted_flags parameter is used to pass relevant access_flags | |
2560 // from the methods back up to the containing klass. These flag values | |
2561 // are added to klass's access_flags. | |
2562 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2563 Array<Method*>* ClassFileParser::parse_methods(ClassLoaderData* loader_data, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
2564 constantPoolHandle cp, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
2565 bool is_interface, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
2566 AccessFlags* promoted_flags, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
2567 bool* has_final_method, |
6934 | 2568 bool* has_default_methods, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
2569 TRAPS) { |
0 | 2570 ClassFileStream* cfs = stream(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2571 cfs->guarantee_more(2, CHECK_NULL); // length |
0 | 2572 u2 length = cfs->get_u2_fast(); |
2573 if (length == 0) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2574 return Universe::the_empty_method_array(); |
0 | 2575 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2576 // FIXME: Handle leaks at later failures. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2577 Array<Method*>* methods = MetadataFactory::new_array<Method*>(loader_data, length, NULL, CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2578 |
0 | 2579 HandleMark hm(THREAD); |
2580 for (int index = 0; index < length; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2581 methodHandle method = parse_method(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2582 cp, is_interface, |
0 | 2583 promoted_flags, |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2584 CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2585 |
0 | 2586 if (method->is_final()) { |
2587 *has_final_method = true; | |
2588 } | |
6934 | 2589 if (is_interface && !method->is_abstract() && !method->is_static()) { |
2590 // default method | |
2591 *has_default_methods = true; | |
2592 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2593 methods->at_put(index, method()); |
0 | 2594 } |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2595 |
0 | 2596 if (_need_verify && length > 1) { |
2597 // Check duplicated methods | |
2598 ResourceMark rm(THREAD); | |
2599 NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( | |
2600 THREAD, NameSigHash*, HASH_ROW_SIZE); | |
2601 initialize_hashtable(names_and_sigs); | |
2602 bool dup = false; | |
2603 { | |
2604 debug_only(No_Safepoint_Verifier nsv;) | |
2605 for (int i = 0; i < length; i++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2606 Method* m = methods->at(i); |
0 | 2607 // If no duplicates, add name/signature in hashtable names_and_sigs. |
2608 if (!put_after_lookup(m->name(), m->signature(), names_and_sigs)) { | |
2609 dup = true; | |
2610 break; | |
2611 } | |
2612 } | |
2613 } | |
2614 if (dup) { | |
2615 classfile_parse_error("Duplicate method name&signature in class file %s", | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2616 CHECK_NULL); |
0 | 2617 } |
2618 } | |
2619 return methods; | |
2620 } | |
2621 } | |
2622 | |
2623 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2624 Array<int>* ClassFileParser::sort_methods(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2625 Array<Method*>* methods, |
8031 | 2626 TRAPS) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2627 int length = methods->length(); |
3245
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2628 // If JVMTI original method ordering or sharing is enabled we have to |
0 | 2629 // remember the original class file ordering. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2630 // We temporarily use the vtable_index field in the Method* to store the |
0 | 2631 // class file index, so we can read in after calling qsort. |
3245
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2632 // Put the method ordering in the shared archive. |
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2633 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
0 | 2634 for (int index = 0; index < length; index++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2635 Method* m = methods->at(index); |
0 | 2636 assert(!m->valid_vtable_index(), "vtable index should not be set"); |
2637 m->set_vtable_index(index); | |
2638 } | |
2639 } | |
2640 // Sort method array by ascending method name (for faster lookups & vtable construction) | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2641 // Note that the ordering is not alphabetical, see Symbol::fast_compare |
8031 | 2642 Method::sort_methods(methods); |
0 | 2643 |
3245
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2644 // If JVMTI original method ordering or sharing is enabled construct int |
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2645 // array remembering the original ordering |
8ce625481709
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
2461
diff
changeset
|
2646 if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2647 Array<int>* method_ordering = MetadataFactory::new_array<int>(loader_data, length, CHECK_NULL); |
0 | 2648 for (int index = 0; index < length; index++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2649 Method* m = methods->at(index); |
0 | 2650 int old_index = m->vtable_index(); |
2651 assert(old_index >= 0 && old_index < length, "invalid method index"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2652 method_ordering->at_put(index, old_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2653 m->set_vtable_index(Method::invalid_vtable_index); |
0 | 2654 } |
2655 return method_ordering; | |
2656 } else { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2657 return Universe::the_empty_int_array(); |
0 | 2658 } |
2659 } | |
2660 | |
2661 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2662 void ClassFileParser::parse_classfile_sourcefile_attribute(constantPoolHandle cp, TRAPS) { |
0 | 2663 ClassFileStream* cfs = stream(); |
2664 cfs->guarantee_more(2, CHECK); // sourcefile_index | |
2665 u2 sourcefile_index = cfs->get_u2_fast(); | |
2666 check_property( | |
2667 valid_cp_range(sourcefile_index, cp->length()) && | |
2668 cp->tag_at(sourcefile_index).is_utf8(), | |
2669 "Invalid SourceFile attribute at constant pool index %u in class file %s", | |
2670 sourcefile_index, CHECK); | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2671 set_class_sourcefile(cp->symbol_at(sourcefile_index)); |
0 | 2672 } |
2673 | |
2674 | |
2675 | |
2676 void ClassFileParser::parse_classfile_source_debug_extension_attribute(constantPoolHandle cp, | |
2677 int length, TRAPS) { | |
2678 ClassFileStream* cfs = stream(); | |
2679 u1* sde_buffer = cfs->get_u1_buffer(); | |
2680 assert(sde_buffer != NULL, "null sde buffer"); | |
2681 | |
2682 // Don't bother storing it if there is no way to retrieve it | |
2683 if (JvmtiExport::can_get_source_debug_extension()) { | |
6226 | 2684 assert((length+1) > length, "Overflow checking"); |
2685 u1* sde = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, u1, length+1); | |
2686 for (int i = 0; i < length; i++) { | |
2687 sde[i] = sde_buffer[i]; | |
2688 } | |
2689 sde[length] = '\0'; | |
2690 set_class_sde_buffer((char*)sde, length); | |
0 | 2691 } |
2692 // Got utf8 string, set stream position forward | |
2693 cfs->skip_u1(length, CHECK); | |
2694 } | |
2695 | |
2696 | |
2697 // Inner classes can be static, private or protected (classic VM does this) | |
2698 #define RECOGNIZED_INNER_CLASS_MODIFIERS (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_PRIVATE | JVM_ACC_PROTECTED | JVM_ACC_STATIC) | |
2699 | |
2700 // Return number of classes in the inner classes attribute table | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2701 u2 ClassFileParser::parse_classfile_inner_classes_attribute(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2702 u1* inner_classes_attribute_start, |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2703 bool parsed_enclosingmethod_attribute, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2704 u2 enclosing_method_class_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2705 u2 enclosing_method_method_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2706 constantPoolHandle cp, |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2707 TRAPS) { |
0 | 2708 ClassFileStream* cfs = stream(); |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2709 u1* current_mark = cfs->current(); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2710 u2 length = 0; |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2711 if (inner_classes_attribute_start != NULL) { |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2712 cfs->set_current(inner_classes_attribute_start); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2713 cfs->guarantee_more(2, CHECK_0); // length |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2714 length = cfs->get_u2_fast(); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2715 } |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2716 |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2717 // 4-tuples of shorts of inner classes data and 2 shorts of enclosing |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2718 // method data: |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2719 // [inner_class_info_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2720 // outer_class_info_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2721 // inner_name_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2722 // inner_class_access_flags, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2723 // ... |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2724 // enclosing_method_class_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2725 // enclosing_method_method_index] |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2726 int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2727 // FIXME: Will leak on exceptions. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2728 Array<u2>* inner_classes = MetadataFactory::new_array<u2>(loader_data, size, CHECK_0); |
0 | 2729 int index = 0; |
2730 int cp_size = cp->length(); | |
2731 cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 | |
2732 for (int n = 0; n < length; n++) { | |
2733 // Inner class index | |
2734 u2 inner_class_info_index = cfs->get_u2_fast(); | |
2735 check_property( | |
2736 inner_class_info_index == 0 || | |
2737 (valid_cp_range(inner_class_info_index, cp_size) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
2738 is_klass_reference(cp, inner_class_info_index)), |
0 | 2739 "inner_class_info_index %u has bad constant type in class file %s", |
2740 inner_class_info_index, CHECK_0); | |
2741 // Outer class index | |
2742 u2 outer_class_info_index = cfs->get_u2_fast(); | |
2743 check_property( | |
2744 outer_class_info_index == 0 || | |
2745 (valid_cp_range(outer_class_info_index, cp_size) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
2746 is_klass_reference(cp, outer_class_info_index)), |
0 | 2747 "outer_class_info_index %u has bad constant type in class file %s", |
2748 outer_class_info_index, CHECK_0); | |
2749 // Inner class name | |
2750 u2 inner_name_index = cfs->get_u2_fast(); | |
2751 check_property( | |
2752 inner_name_index == 0 || (valid_cp_range(inner_name_index, cp_size) && | |
2753 cp->tag_at(inner_name_index).is_utf8()), | |
2754 "inner_name_index %u has bad constant type in class file %s", | |
2755 inner_name_index, CHECK_0); | |
2756 if (_need_verify) { | |
2757 guarantee_property(inner_class_info_index != outer_class_info_index, | |
2758 "Class is both outer and inner class in class file %s", CHECK_0); | |
2759 } | |
2760 // Access flags | |
2761 AccessFlags inner_access_flags; | |
2762 jint flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS; | |
2763 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) { | |
2764 // Set abstract bit for old class files for backward compatibility | |
2765 flags |= JVM_ACC_ABSTRACT; | |
2766 } | |
2767 verify_legal_class_modifiers(flags, CHECK_0); | |
2768 inner_access_flags.set_flags(flags); | |
2769 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2770 inner_classes->at_put(index++, inner_class_info_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2771 inner_classes->at_put(index++, outer_class_info_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2772 inner_classes->at_put(index++, inner_name_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2773 inner_classes->at_put(index++, inner_access_flags.as_short()); |
0 | 2774 } |
2775 | |
2776 // 4347400: make sure there's no duplicate entry in the classes array | |
2777 if (_need_verify && _major_version >= JAVA_1_5_VERSION) { | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2778 for(int i = 0; i < length * 4; i += 4) { |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2779 for(int j = i + 4; j < length * 4; j += 4) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2780 guarantee_property((inner_classes->at(i) != inner_classes->at(j) || |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2781 inner_classes->at(i+1) != inner_classes->at(j+1) || |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2782 inner_classes->at(i+2) != inner_classes->at(j+2) || |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2783 inner_classes->at(i+3) != inner_classes->at(j+3)), |
0 | 2784 "Duplicate entry in InnerClasses in class file %s", |
2785 CHECK_0); | |
2786 } | |
2787 } | |
2788 } | |
2789 | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2790 // Set EnclosingMethod class and method indexes. |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2791 if (parsed_enclosingmethod_attribute) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2792 inner_classes->at_put(index++, enclosing_method_class_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2793 inner_classes->at_put(index++, enclosing_method_method_index); |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2794 } |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2795 assert(index == size, "wrong size"); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2796 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2797 // Update InstanceKlass with inner class info. |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2798 set_class_inner_classes(inner_classes); |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2799 |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2800 // Restore buffer's current position. |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2801 cfs->set_current(current_mark); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2802 |
0 | 2803 return length; |
2804 } | |
2805 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2806 void ClassFileParser::parse_classfile_synthetic_attribute(constantPoolHandle cp, TRAPS) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2807 set_class_synthetic_flag(true); |
0 | 2808 } |
2809 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2810 void ClassFileParser::parse_classfile_signature_attribute(constantPoolHandle cp, TRAPS) { |
0 | 2811 ClassFileStream* cfs = stream(); |
2812 u2 signature_index = cfs->get_u2(CHECK); | |
2813 check_property( | |
2814 valid_cp_range(signature_index, cp->length()) && | |
2815 cp->tag_at(signature_index).is_utf8(), | |
2816 "Invalid constant pool index %u in Signature attribute in class file %s", | |
2817 signature_index, CHECK); | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2818 set_class_generic_signature(cp->symbol_at(signature_index)); |
0 | 2819 } |
2820 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2821 void ClassFileParser::parse_classfile_bootstrap_methods_attribute(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2822 constantPoolHandle cp, |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2823 u4 attribute_byte_length, TRAPS) { |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2824 ClassFileStream* cfs = stream(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2825 u1* current_start = cfs->current(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2826 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2827 cfs->guarantee_more(2, CHECK); // length |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2828 int attribute_array_length = cfs->get_u2_fast(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2829 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2830 guarantee_property(_max_bootstrap_specifier_index < attribute_array_length, |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2831 "Short length on BootstrapMethods in class file %s", |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2832 CHECK); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2833 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2834 // The attribute contains a counted array of counted tuples of shorts, |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2835 // represending bootstrap specifiers: |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2836 // length*{bootstrap_method_index, argument_count*{argument_index}} |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2837 int operand_count = (attribute_byte_length - sizeof(u2)) / sizeof(u2); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2838 // operand_count = number of shorts in attr, except for leading length |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2839 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2840 // The attribute is copied into a short[] array. |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2841 // The array begins with a series of short[2] pairs, one for each tuple. |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2842 int index_size = (attribute_array_length * 2); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2843 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2844 Array<u2>* operands = MetadataFactory::new_array<u2>(loader_data, index_size + operand_count, CHECK); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2845 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2846 int operand_fill_index = index_size; |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2847 int cp_size = cp->length(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2848 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2849 for (int n = 0; n < attribute_array_length; n++) { |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2850 // Store a 32-bit offset into the header of the operand array. |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2851 ConstantPool::operand_offset_at_put(operands, n, operand_fill_index); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2852 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2853 // Read a bootstrap specifier. |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2854 cfs->guarantee_more(sizeof(u2) * 2, CHECK); // bsm, argc |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2855 u2 bootstrap_method_index = cfs->get_u2_fast(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2856 u2 argument_count = cfs->get_u2_fast(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2857 check_property( |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2858 valid_cp_range(bootstrap_method_index, cp_size) && |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2859 cp->tag_at(bootstrap_method_index).is_method_handle(), |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2860 "bootstrap_method_index %u has bad constant type in class file %s", |
2085 | 2861 bootstrap_method_index, |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2862 CHECK); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2863 operands->at_put(operand_fill_index++, bootstrap_method_index); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2864 operands->at_put(operand_fill_index++, argument_count); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2865 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2866 cfs->guarantee_more(sizeof(u2) * argument_count, CHECK); // argv[argc] |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2867 for (int j = 0; j < argument_count; j++) { |
2085 | 2868 u2 argument_index = cfs->get_u2_fast(); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2869 check_property( |
2085 | 2870 valid_cp_range(argument_index, cp_size) && |
2871 cp->tag_at(argument_index).is_loadable_constant(), | |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2872 "argument_index %u has bad constant type in class file %s", |
2085 | 2873 argument_index, |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2874 CHECK); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2875 operands->at_put(operand_fill_index++, argument_index); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2876 } |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2877 } |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2878 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2879 assert(operand_fill_index == operands->length(), "exact fill"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2880 assert(ConstantPool::operand_array_length(operands) == attribute_array_length, "correct decode"); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2881 |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2882 u1* current_end = cfs->current(); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2883 guarantee_property(current_end == current_start + attribute_byte_length, |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2884 "Bad length on BootstrapMethods in class file %s", |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2885 CHECK); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2886 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2887 cp->set_operands(operands); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2888 } |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2889 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2890 void ClassFileParser::parse_classfile_attributes(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2891 constantPoolHandle cp, |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2892 ClassFileParser::ClassAnnotationCollector* parsed_annotations, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2893 TRAPS) { |
0 | 2894 ClassFileStream* cfs = stream(); |
2895 // Set inner classes attribute to default sentinel | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
2896 set_class_inner_classes(Universe::the_empty_short_array()); |
0 | 2897 cfs->guarantee_more(2, CHECK); // attributes_count |
2898 u2 attributes_count = cfs->get_u2_fast(); | |
2899 bool parsed_sourcefile_attribute = false; | |
2900 bool parsed_innerclasses_attribute = false; | |
2901 bool parsed_enclosingmethod_attribute = false; | |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
2902 bool parsed_bootstrap_methods_attribute = false; |
0 | 2903 u1* runtime_visible_annotations = NULL; |
2904 int runtime_visible_annotations_length = 0; | |
2905 u1* runtime_invisible_annotations = NULL; | |
2906 int runtime_invisible_annotations_length = 0; | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2907 u1* runtime_visible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2908 int runtime_visible_type_annotations_length = 0; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2909 u1* runtime_invisible_type_annotations = NULL; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
2910 int runtime_invisible_type_annotations_length = 0; |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2911 u1* inner_classes_attribute_start = NULL; |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2912 u4 inner_classes_attribute_length = 0; |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2913 u2 enclosing_method_class_index = 0; |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2914 u2 enclosing_method_method_index = 0; |
0 | 2915 // Iterate over attributes |
2916 while (attributes_count--) { | |
2917 cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length | |
2918 u2 attribute_name_index = cfs->get_u2_fast(); | |
2919 u4 attribute_length = cfs->get_u4_fast(); | |
2920 check_property( | |
2921 valid_cp_range(attribute_name_index, cp->length()) && | |
2922 cp->tag_at(attribute_name_index).is_utf8(), | |
2923 "Attribute name has bad constant pool index %u in class file %s", | |
2924 attribute_name_index, CHECK); | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
2925 Symbol* tag = cp->symbol_at(attribute_name_index); |
0 | 2926 if (tag == vmSymbols::tag_source_file()) { |
2927 // Check for SourceFile tag | |
2928 if (_need_verify) { | |
2929 guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK); | |
2930 } | |
2931 if (parsed_sourcefile_attribute) { | |
2932 classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK); | |
2933 } else { | |
2934 parsed_sourcefile_attribute = true; | |
2935 } | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2936 parse_classfile_sourcefile_attribute(cp, CHECK); |
0 | 2937 } else if (tag == vmSymbols::tag_source_debug_extension()) { |
2938 // Check for SourceDebugExtension tag | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2939 parse_classfile_source_debug_extension_attribute(cp, (int)attribute_length, CHECK); |
0 | 2940 } else if (tag == vmSymbols::tag_inner_classes()) { |
2941 // Check for InnerClasses tag | |
2942 if (parsed_innerclasses_attribute) { | |
2943 classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK); | |
2944 } else { | |
2945 parsed_innerclasses_attribute = true; | |
2946 } | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2947 inner_classes_attribute_start = cfs->get_u1_buffer(); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2948 inner_classes_attribute_length = attribute_length; |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2949 cfs->skip_u1(inner_classes_attribute_length, CHECK); |
0 | 2950 } else if (tag == vmSymbols::tag_synthetic()) { |
2951 // Check for Synthetic tag | |
2952 // Shouldn't we check that the synthetic flags wasn't already set? - not required in spec | |
2953 if (attribute_length != 0) { | |
2954 classfile_parse_error( | |
2955 "Invalid Synthetic classfile attribute length %u in class file %s", | |
2956 attribute_length, CHECK); | |
2957 } | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2958 parse_classfile_synthetic_attribute(cp, CHECK); |
0 | 2959 } else if (tag == vmSymbols::tag_deprecated()) { |
2960 // Check for Deprecatd tag - 4276120 | |
2961 if (attribute_length != 0) { | |
2962 classfile_parse_error( | |
2963 "Invalid Deprecated classfile attribute length %u in class file %s", | |
2964 attribute_length, CHECK); | |
2965 } | |
2966 } else if (_major_version >= JAVA_1_5_VERSION) { | |
2967 if (tag == vmSymbols::tag_signature()) { | |
2968 if (attribute_length != 2) { | |
2969 classfile_parse_error( | |
2970 "Wrong Signature attribute length %u in class file %s", | |
2971 attribute_length, CHECK); | |
2972 } | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2973 parse_classfile_signature_attribute(cp, CHECK); |
0 | 2974 } else if (tag == vmSymbols::tag_runtime_visible_annotations()) { |
2975 runtime_visible_annotations_length = attribute_length; | |
2976 runtime_visible_annotations = cfs->get_u1_buffer(); | |
2977 assert(runtime_visible_annotations != NULL, "null visible annotations"); | |
7587 | 2978 parse_annotations(loader_data, |
2979 runtime_visible_annotations, | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2980 runtime_visible_annotations_length, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2981 cp, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2982 parsed_annotations, |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
2983 CHECK); |
0 | 2984 cfs->skip_u1(runtime_visible_annotations_length, CHECK); |
2985 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_annotations()) { | |
2986 runtime_invisible_annotations_length = attribute_length; | |
2987 runtime_invisible_annotations = cfs->get_u1_buffer(); | |
2988 assert(runtime_invisible_annotations != NULL, "null invisible annotations"); | |
2989 cfs->skip_u1(runtime_invisible_annotations_length, CHECK); | |
2990 } else if (tag == vmSymbols::tag_enclosing_method()) { | |
2991 if (parsed_enclosingmethod_attribute) { | |
2992 classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK); | |
2993 } else { | |
2994 parsed_enclosingmethod_attribute = true; | |
2995 } | |
2996 cfs->guarantee_more(4, CHECK); // class_index, method_index | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2997 enclosing_method_class_index = cfs->get_u2_fast(); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2998 enclosing_method_method_index = cfs->get_u2_fast(); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
2999 if (enclosing_method_class_index == 0) { |
0 | 3000 classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK); |
3001 } | |
3002 // Validate the constant pool indices and types | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3003 if (!cp->is_within_bounds(enclosing_method_class_index) || |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3004 !is_klass_reference(cp, enclosing_method_class_index)) { |
0 | 3005 classfile_parse_error("Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); |
3006 } | |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3007 if (enclosing_method_method_index != 0 && |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3008 (!cp->is_within_bounds(enclosing_method_method_index) || |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3009 !cp->tag_at(enclosing_method_method_index).is_name_and_type())) { |
0 | 3010 classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK); |
3011 } | |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3012 } else if (tag == vmSymbols::tag_bootstrap_methods() && |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3013 _major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3014 if (parsed_bootstrap_methods_attribute) |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3015 classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3016 parsed_bootstrap_methods_attribute = true; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3017 parse_classfile_bootstrap_methods_attribute(loader_data, cp, attribute_length, CHECK); |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3018 } else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3019 runtime_visible_type_annotations_length = attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3020 runtime_visible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3021 assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3022 // No need for the VM to parse Type annotations |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3023 cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3024 } else if (PreserveAllAnnotations && tag == vmSymbols::tag_runtime_invisible_type_annotations()) { |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3025 runtime_invisible_type_annotations_length = attribute_length; |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3026 runtime_invisible_type_annotations = cfs->get_u1_buffer(); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3027 assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3028 cfs->skip_u1(runtime_invisible_type_annotations_length, CHECK); |
0 | 3029 } else { |
3030 // Unknown attribute | |
3031 cfs->skip_u1(attribute_length, CHECK); | |
3032 } | |
3033 } else { | |
3034 // Unknown attribute | |
3035 cfs->skip_u1(attribute_length, CHECK); | |
3036 } | |
3037 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3038 AnnotationArray* annotations = assemble_annotations(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3039 runtime_visible_annotations, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3040 runtime_visible_annotations_length, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3041 runtime_invisible_annotations, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3042 runtime_invisible_annotations_length, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3043 CHECK); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3044 set_class_annotations(annotations); |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3045 AnnotationArray* type_annotations = assemble_annotations(loader_data, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3046 runtime_visible_type_annotations, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3047 runtime_visible_type_annotations_length, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3048 runtime_invisible_type_annotations, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3049 runtime_invisible_type_annotations_length, |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3050 CHECK); |
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3051 set_class_type_annotations(type_annotations); |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3052 |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3053 if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3054 u2 num_of_classes = parse_classfile_inner_classes_attribute( |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3055 loader_data, |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3056 inner_classes_attribute_start, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3057 parsed_innerclasses_attribute, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3058 enclosing_method_class_index, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3059 enclosing_method_method_index, |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3060 cp, CHECK); |
5967
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3061 if (parsed_innerclasses_attribute &&_need_verify && _major_version >= JAVA_1_5_VERSION) { |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3062 guarantee_property( |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3063 inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes, |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3064 "Wrong InnerClasses attribute length in class file %s", CHECK); |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3065 } |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3066 } |
f7c4174b33ba
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
4755
diff
changeset
|
3067 |
2011
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3068 if (_max_bootstrap_specifier_index >= 0) { |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3069 guarantee_property(parsed_bootstrap_methods_attribute, |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3070 "Missing BootstrapMethods attribute in class file %s", CHECK); |
dad31fc330cd
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
1972
diff
changeset
|
3071 } |
0 | 3072 } |
3073 | |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3074 void ClassFileParser::apply_parsed_class_attributes(instanceKlassHandle k) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3075 if (_synthetic_flag) |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3076 k->set_is_synthetic(); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3077 if (_sourcefile != NULL) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3078 _sourcefile->increment_refcount(); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3079 k->set_source_file_name(_sourcefile); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3080 } |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3081 if (_generic_signature != NULL) { |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3082 _generic_signature->increment_refcount(); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3083 k->set_generic_signature(_generic_signature); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3084 } |
6226 | 3085 if (_sde_buffer != NULL) { |
3086 k->set_source_debug_extension(_sde_buffer, _sde_length); | |
3087 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3088 k->set_inner_classes(_inner_classes); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3089 } |
0 | 3090 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3091 AnnotationArray* ClassFileParser::assemble_annotations(ClassLoaderData* loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3092 u1* runtime_visible_annotations, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3093 int runtime_visible_annotations_length, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3094 u1* runtime_invisible_annotations, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3095 int runtime_invisible_annotations_length, TRAPS) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3096 AnnotationArray* annotations = NULL; |
0 | 3097 if (runtime_visible_annotations != NULL || |
3098 runtime_invisible_annotations != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3099 annotations = MetadataFactory::new_array<u1>(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3100 runtime_visible_annotations_length + |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3101 runtime_invisible_annotations_length, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3102 CHECK_(annotations)); |
0 | 3103 if (runtime_visible_annotations != NULL) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3104 for (int i = 0; i < runtime_visible_annotations_length; i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3105 annotations->at_put(i, runtime_visible_annotations[i]); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3106 } |
0 | 3107 } |
3108 if (runtime_invisible_annotations != NULL) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3109 for (int i = 0; i < runtime_invisible_annotations_length; i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3110 int append = runtime_visible_annotations_length+i; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3111 annotations->at_put(append, runtime_invisible_annotations[i]); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3112 } |
0 | 3113 } |
3114 } | |
3115 return annotations; | |
3116 } | |
3117 | |
3118 | |
6934 | 3119 #ifndef PRODUCT |
3120 static void parseAndPrintGenericSignatures( | |
3121 instanceKlassHandle this_klass, TRAPS) { | |
3122 assert(ParseAllGenericSignatures == true, "Shouldn't call otherwise"); | |
3123 ResourceMark rm; | |
3124 | |
3125 if (this_klass->generic_signature() != NULL) { | |
3126 using namespace generic; | |
3127 ClassDescriptor* spec = ClassDescriptor::parse_generic_signature(this_klass(), CHECK); | |
3128 | |
3129 tty->print_cr("Parsing %s", this_klass->generic_signature()->as_C_string()); | |
3130 spec->print_on(tty); | |
3131 | |
3132 for (int i = 0; i < this_klass->methods()->length(); ++i) { | |
3133 Method* m = this_klass->methods()->at(i); | |
3134 MethodDescriptor* method_spec = MethodDescriptor::parse_generic_signature(m, spec); | |
3135 Symbol* sig = m->generic_signature(); | |
3136 if (sig == NULL) { | |
3137 sig = m->signature(); | |
3138 } | |
3139 tty->print_cr("Parsing %s", sig->as_C_string()); | |
3140 method_spec->print_on(tty); | |
3141 } | |
3142 } | |
3143 } | |
3144 #endif // ndef PRODUCT | |
3145 | |
3146 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3147 instanceKlassHandle ClassFileParser::parseClassFile(Symbol* name, |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
3148 ClassLoaderData* loader_data, |
0 | 3149 Handle protection_domain, |
710 | 3150 KlassHandle host_klass, |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3151 GrowableArray<Handle>* cp_patches, |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3152 TempNewSymbol& parsed_name, |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
879
diff
changeset
|
3153 bool verify, |
0 | 3154 TRAPS) { |
7462
ade95d680b42
8004728: Add hotspot support for parameter reflection
coleenp
parents:
7457
diff
changeset
|
3155 |
4731
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3156 // When a retransformable agent is attached, JVMTI caches the |
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3157 // class bytes that existed before the first retransformation. |
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3158 // If RedefineClasses() was used before the retransformable |
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3159 // agent attached, then the cached class bytes may not be the |
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3160 // original class bytes. |
0 | 3161 unsigned char *cached_class_file_bytes = NULL; |
3162 jint cached_class_file_length; | |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
3163 Handle class_loader(THREAD, loader_data->class_loader()); |
6934 | 3164 bool has_default_methods = false; |
3165 ResourceMark rm(THREAD); | |
0 | 3166 |
3167 ClassFileStream* cfs = stream(); | |
3168 // Timing | |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3169 assert(THREAD->is_Java_thread(), "must be a JavaThread"); |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3170 JavaThread* jt = (JavaThread*) THREAD; |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3171 |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3172 PerfClassTraceTime ctimer(ClassLoader::perf_class_parse_time(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3173 ClassLoader::perf_class_parse_selftime(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3174 NULL, |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3175 jt->get_thread_stat()->perf_recursion_counts_addr(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3176 jt->get_thread_stat()->perf_timers_addr(), |
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3177 PerfClassTraceTime::PARSE_CLASS); |
0 | 3178 |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3179 init_parsed_class_attributes(); |
0 | 3180 |
3181 if (JvmtiExport::should_post_class_file_load_hook()) { | |
4751
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3182 // Get the cached class file bytes (if any) from the class that |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3183 // is being redefined or retransformed. We use jvmti_thread_state() |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3184 // instead of JvmtiThreadState::state_for(jt) so we don't allocate |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3185 // a JvmtiThreadState any earlier than necessary. This will help |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3186 // avoid the bug described by 7126851. |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3187 JvmtiThreadState *state = jt->jvmti_thread_state(); |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3188 if (state != NULL) { |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3189 KlassHandle *h_class_being_redefined = |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3190 state->get_class_being_redefined(); |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3191 if (h_class_being_redefined != NULL) { |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3192 instanceKlassHandle ikh_class_being_redefined = |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3193 instanceKlassHandle(THREAD, (*h_class_being_redefined)()); |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3194 cached_class_file_bytes = |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3195 ikh_class_being_redefined->get_cached_class_file_bytes(); |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3196 cached_class_file_length = |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3197 ikh_class_being_redefined->get_cached_class_file_len(); |
5b58979183f9
7127032: fix for 7122253 adds a JvmtiThreadState earlier than necessary
dcubed
parents:
4731
diff
changeset
|
3198 } |
4731
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3199 } |
4ceaf61479fc
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
3938
diff
changeset
|
3200 |
0 | 3201 unsigned char* ptr = cfs->buffer(); |
3202 unsigned char* end_ptr = cfs->buffer() + cfs->length(); | |
3203 | |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
3204 JvmtiExport::post_class_file_load_hook(name, class_loader(), protection_domain, |
0 | 3205 &ptr, &end_ptr, |
3206 &cached_class_file_bytes, | |
3207 &cached_class_file_length); | |
3208 | |
3209 if (ptr != cfs->buffer()) { | |
3210 // JVMTI agent has modified class file data. | |
3211 // Set new class file stream using JVMTI agent modified | |
3212 // class file data. | |
3213 cfs = new ClassFileStream(ptr, end_ptr - ptr, cfs->source()); | |
3214 set_stream(cfs); | |
3215 } | |
3216 } | |
3217 | |
710 | 3218 _host_klass = host_klass; |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3219 _cp_patches = cp_patches; |
0 | 3220 |
3221 instanceKlassHandle nullHandle; | |
3222 | |
3223 // Figure out whether we can skip format checking (matching classic VM behavior) | |
973
ad6585fd4087
6830542: Performance: JVM_DefineClass already verified.
acorn
parents:
879
diff
changeset
|
3224 _need_verify = Verifier::should_verify_for(class_loader(), verify); |
0 | 3225 |
3226 // Set the verify flag in stream | |
3227 cfs->set_verify(_need_verify); | |
3228 | |
3229 // Save the class file name for easier error message printing. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3230 _class_name = (name != NULL) ? name : vmSymbols::unknown_class_name(); |
0 | 3231 |
3232 cfs->guarantee_more(8, CHECK_(nullHandle)); // magic, major, minor | |
3233 // Magic value | |
3234 u4 magic = cfs->get_u4_fast(); | |
3235 guarantee_property(magic == JAVA_CLASSFILE_MAGIC, | |
3236 "Incompatible magic value %u in class file %s", | |
3237 magic, CHECK_(nullHandle)); | |
3238 | |
3239 // Version numbers | |
3240 u2 minor_version = cfs->get_u2_fast(); | |
3241 u2 major_version = cfs->get_u2_fast(); | |
3242 | |
3243 // Check version numbers - we check this even with verifier off | |
3244 if (!is_supported_version(major_version, minor_version)) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3245 if (name == NULL) { |
0 | 3246 Exceptions::fthrow( |
3247 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3248 vmSymbols::java_lang_UnsupportedClassVersionError(), |
0 | 3249 "Unsupported major.minor version %u.%u", |
3250 major_version, | |
3251 minor_version); | |
3252 } else { | |
3253 ResourceMark rm(THREAD); | |
3254 Exceptions::fthrow( | |
3255 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3256 vmSymbols::java_lang_UnsupportedClassVersionError(), |
0 | 3257 "%s : Unsupported major.minor version %u.%u", |
3258 name->as_C_string(), | |
3259 major_version, | |
3260 minor_version); | |
3261 } | |
3262 return nullHandle; | |
3263 } | |
3264 | |
3265 _major_version = major_version; | |
3266 _minor_version = minor_version; | |
3267 | |
3268 | |
3269 // Check if verification needs to be relaxed for this class file | |
3270 // Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376) | |
3271 _relax_verify = Verifier::relax_verify_for(class_loader()); | |
3272 | |
3273 // Constant pool | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3274 constantPoolHandle cp = parse_constant_pool(loader_data, CHECK_(nullHandle)); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3275 ConstantPoolCleaner error_handler(cp); // set constant pool to be cleaned up. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3276 |
0 | 3277 int cp_size = cp->length(); |
3278 | |
3279 cfs->guarantee_more(8, CHECK_(nullHandle)); // flags, this_class, super_class, infs_len | |
3280 | |
3281 // Access flags | |
3282 AccessFlags access_flags; | |
3283 jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS; | |
3284 | |
3285 if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) { | |
3286 // Set abstract bit for old class files for backward compatibility | |
3287 flags |= JVM_ACC_ABSTRACT; | |
3288 } | |
3289 verify_legal_class_modifiers(flags, CHECK_(nullHandle)); | |
3290 access_flags.set_flags(flags); | |
3291 | |
3292 // This class and superclass | |
3293 instanceKlassHandle super_klass; | |
3294 u2 this_class_index = cfs->get_u2_fast(); | |
3295 check_property( | |
3296 valid_cp_range(this_class_index, cp_size) && | |
3297 cp->tag_at(this_class_index).is_unresolved_klass(), | |
3298 "Invalid this class index %u in constant pool in class file %s", | |
3299 this_class_index, CHECK_(nullHandle)); | |
3300 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3301 Symbol* class_name = cp->unresolved_klass_at(this_class_index); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3302 assert(class_name != NULL, "class_name can't be null"); |
0 | 3303 |
3304 // It's important to set parsed_name *before* resolving the super class. | |
3305 // (it's used for cleanup by the caller if parsing fails) | |
3306 parsed_name = class_name; | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3307 // parsed_name is returned and can be used if there's an error, so add to |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3308 // its reference count. Caller will decrement the refcount. |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3309 parsed_name->increment_refcount(); |
0 | 3310 |
3311 // Update _class_name which could be null previously to be class_name | |
3312 _class_name = class_name; | |
3313 | |
3314 // Don't need to check whether this class name is legal or not. | |
3315 // It has been checked when constant pool is parsed. | |
3316 // However, make sure it is not an array type. | |
3317 if (_need_verify) { | |
3318 guarantee_property(class_name->byte_at(0) != JVM_SIGNATURE_ARRAY, | |
3319 "Bad class name in class file %s", | |
3320 CHECK_(nullHandle)); | |
3321 } | |
3322 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3323 Klass* preserve_this_klass; // for storing result across HandleMark |
0 | 3324 |
3325 // release all handles when parsing is done | |
3326 { HandleMark hm(THREAD); | |
3327 | |
3328 // Checks if name in class file matches requested name | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3329 if (name != NULL && class_name != name) { |
0 | 3330 ResourceMark rm(THREAD); |
3331 Exceptions::fthrow( | |
3332 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3333 vmSymbols::java_lang_NoClassDefFoundError(), |
0 | 3334 "%s (wrong name: %s)", |
3335 name->as_C_string(), | |
3336 class_name->as_C_string() | |
3337 ); | |
3338 return nullHandle; | |
3339 } | |
3340 | |
3341 if (TraceClassLoadingPreorder) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3342 tty->print("[Loading %s", name->as_klass_external_name()); |
0 | 3343 if (cfs->source() != NULL) tty->print(" from %s", cfs->source()); |
3344 tty->print_cr("]"); | |
3345 } | |
3346 | |
3347 u2 super_class_index = cfs->get_u2_fast(); | |
3348 if (super_class_index == 0) { | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3349 check_property(class_name == vmSymbols::java_lang_Object(), |
0 | 3350 "Invalid superclass index %u in class file %s", |
3351 super_class_index, | |
3352 CHECK_(nullHandle)); | |
3353 } else { | |
3354 check_property(valid_cp_range(super_class_index, cp_size) && | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3355 is_klass_reference(cp, super_class_index), |
0 | 3356 "Invalid superclass index %u in class file %s", |
3357 super_class_index, | |
3358 CHECK_(nullHandle)); | |
3359 // The class name should be legal because it is checked when parsing constant pool. | |
3360 // However, make sure it is not an array type. | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3361 bool is_array = false; |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3362 if (cp->tag_at(super_class_index).is_klass()) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3363 super_klass = instanceKlassHandle(THREAD, cp->resolved_klass_at(super_class_index)); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3364 if (_need_verify) |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3365 is_array = super_klass->oop_is_array(); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3366 } else if (_need_verify) { |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3367 is_array = (cp->unresolved_klass_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3368 } |
0 | 3369 if (_need_verify) { |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3370 guarantee_property(!is_array, |
0 | 3371 "Bad superclass name in class file %s", CHECK_(nullHandle)); |
3372 } | |
3373 } | |
3374 | |
3375 // Interfaces | |
3376 u2 itfs_len = cfs->get_u2_fast(); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3377 Array<Klass*>* local_interfaces; |
0 | 3378 if (itfs_len == 0) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3379 local_interfaces = Universe::the_empty_klass_array(); |
0 | 3380 } else { |
6934 | 3381 local_interfaces = parse_interfaces( |
3382 cp, itfs_len, loader_data, protection_domain, _class_name, | |
3383 &has_default_methods, CHECK_(nullHandle)); | |
0 | 3384 } |
3385 | |
4744
cd5d8cafcc84
7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
jiangli
parents:
3938
diff
changeset
|
3386 u2 java_fields_count = 0; |
0 | 3387 // Fields (offsets are filled in later) |
3938 | 3388 FieldAllocationCount fac; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3389 Array<AnnotationArray*>* fields_annotations = NULL; |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3390 Array<AnnotationArray*>* fields_type_annotations = NULL; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3391 Array<u2>* fields = parse_fields(loader_data, class_name, cp, access_flags.is_interface(), &fac, &fields_annotations, |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
3392 &fields_type_annotations, |
3938 | 3393 &java_fields_count, |
3394 CHECK_(nullHandle)); | |
0 | 3395 // Methods |
3396 bool has_final_method = false; | |
3397 AccessFlags promoted_flags; | |
3398 promoted_flags.set_flags(0); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3399 Array<Method*>* methods = parse_methods(loader_data, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3400 cp, access_flags.is_interface(), |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3401 &promoted_flags, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3402 &has_final_method, |
6934 | 3403 &has_default_methods, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3404 CHECK_(nullHandle)); |
0 | 3405 |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3406 // Additional attributes |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3407 ClassAnnotationCollector parsed_annotations; |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3408 parse_classfile_attributes(loader_data, cp, &parsed_annotations, CHECK_(nullHandle)); |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3409 |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3410 // Make sure this is the end of class file stream |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3411 guarantee_property(cfs->at_eos(), "Extra bytes at the end of class file %s", CHECK_(nullHandle)); |
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
3412 |
0 | 3413 // We check super class after class file is parsed and format is checked |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3414 if (super_class_index > 0 && super_klass.is_null()) { |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3415 Symbol* sk = cp->klass_name_at(super_class_index); |
0 | 3416 if (access_flags.is_interface()) { |
3417 // Before attempting to resolve the superclass, check for class format | |
3418 // errors not checked yet. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3419 guarantee_property(sk == vmSymbols::java_lang_Object(), |
0 | 3420 "Interfaces must have java.lang.Object as superclass in class file %s", |
3421 CHECK_(nullHandle)); | |
3422 } | |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3423 Klass* k = SystemDictionary::resolve_super_or_fail(class_name, sk, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3424 class_loader, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3425 protection_domain, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3426 true, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3427 CHECK_(nullHandle)); |
875
6a93908f268f
6857194: Add hotspot perf counters to aid class loading performance measurement
mchung
parents:
710
diff
changeset
|
3428 |
0 | 3429 KlassHandle kh (THREAD, k); |
3430 super_klass = instanceKlassHandle(THREAD, kh()); | |
431
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3431 } |
a45484ea312d
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
196
diff
changeset
|
3432 if (super_klass.not_null()) { |
6934 | 3433 |
3434 if (super_klass->has_default_methods()) { | |
3435 has_default_methods = true; | |
3436 } | |
3437 | |
0 | 3438 if (super_klass->is_interface()) { |
3439 ResourceMark rm(THREAD); | |
3440 Exceptions::fthrow( | |
3441 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3442 vmSymbols::java_lang_IncompatibleClassChangeError(), |
0 | 3443 "class %s has interface %s as super class", |
3444 class_name->as_klass_external_name(), | |
3445 super_klass->external_name() | |
3446 ); | |
3447 return nullHandle; | |
3448 } | |
3449 // Make sure super class is not final | |
3450 if (super_klass->is_final()) { | |
3451 THROW_MSG_(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class", nullHandle); | |
3452 } | |
3453 } | |
3454 | |
3455 // Compute the transitive list of all unique interfaces implemented by this class | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3456 Array<Klass*>* transitive_interfaces = compute_transitive_interfaces(loader_data, super_klass, local_interfaces, CHECK_(nullHandle)); |
0 | 3457 |
3458 // sort methods | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3459 Array<int>* method_ordering = sort_methods(loader_data, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
3460 methods, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
3461 CHECK_(nullHandle)); |
0 | 3462 |
3463 // promote flags from parse_methods() to the klass' flags | |
3464 access_flags.add_promoted_flags(promoted_flags.as_int()); | |
3465 | |
3466 // Size of Java vtable (in words) | |
3467 int vtable_size = 0; | |
3468 int itable_size = 0; | |
3469 int num_miranda_methods = 0; | |
3470 | |
6934 | 3471 GrowableArray<Method*> all_mirandas(20); |
3472 | |
3473 klassVtable::compute_vtable_size_and_num_mirandas( | |
3474 &vtable_size, &num_miranda_methods, &all_mirandas, super_klass(), methods, | |
3475 access_flags, class_loader, class_name, local_interfaces, | |
652
4aaa9f5e02a8
4766230: Hotspot vtable inconsistencies cause core dumps. 6579515. 6582242.
acorn
parents:
579
diff
changeset
|
3476 CHECK_(nullHandle)); |
0 | 3477 |
3478 // Size of Java itable (in words) | |
3479 itable_size = access_flags.is_interface() ? 0 : klassItable::compute_itable_size(transitive_interfaces); | |
3480 | |
7587 | 3481 // get the padding width from the option |
3482 // TODO: Ask VM about specific CPU we are running on | |
3483 int pad_size = ContendedPaddingWidth; | |
3484 | |
0 | 3485 // Field size and offset computation |
3486 int nonstatic_field_size = super_klass() == NULL ? 0 : super_klass->nonstatic_field_size(); | |
3487 #ifndef PRODUCT | |
3488 int orig_nonstatic_field_size = 0; | |
3489 #endif | |
3490 int next_static_oop_offset; | |
3491 int next_static_double_offset; | |
3492 int next_static_word_offset; | |
3493 int next_static_short_offset; | |
3494 int next_static_byte_offset; | |
7587 | 3495 int next_static_padded_offset; |
0 | 3496 int next_nonstatic_oop_offset; |
3497 int next_nonstatic_double_offset; | |
3498 int next_nonstatic_word_offset; | |
3499 int next_nonstatic_short_offset; | |
3500 int next_nonstatic_byte_offset; | |
3501 int next_nonstatic_type_offset; | |
3502 int first_nonstatic_oop_offset; | |
3503 int first_nonstatic_field_offset; | |
3504 int next_nonstatic_field_offset; | |
7587 | 3505 int next_nonstatic_padded_offset; |
3506 | |
3507 // Count the contended fields by type. | |
3508 int static_contended_count = 0; | |
3509 int nonstatic_contended_count = 0; | |
3510 FieldAllocationCount fac_contended; | |
3511 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
3512 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); | |
3513 if (fs.is_contended()) { | |
3514 fac_contended.count[atype]++; | |
3515 if (fs.access_flags().is_static()) { | |
3516 static_contended_count++; | |
3517 } else { | |
3518 nonstatic_contended_count++; | |
3519 } | |
3520 } | |
3521 } | |
3522 int contended_count = static_contended_count + nonstatic_contended_count; | |
3523 | |
0 | 3524 |
3525 // Calculate the starting byte offsets | |
6735
aed758eda82a
7195833: NPG: Rename instanceClassLoaderKlass, instanceRefKlass and instanceMirrorKlass
coleenp
parents:
6725
diff
changeset
|
3526 next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); |
7587 | 3527 |
3528 // class is contended, pad before all the fields | |
3529 if (parsed_annotations.is_contended()) { | |
3530 next_static_oop_offset += pad_size; | |
3531 } | |
3532 | |
0 | 3533 next_static_double_offset = next_static_oop_offset + |
7587 | 3534 ((fac.count[STATIC_OOP] - fac_contended.count[STATIC_OOP]) * heapOopSize); |
3938 | 3535 if ( fac.count[STATIC_DOUBLE] && |
0 | 3536 (Universe::field_type_should_be_aligned(T_DOUBLE) || |
3537 Universe::field_type_should_be_aligned(T_LONG)) ) { | |
3538 next_static_double_offset = align_size_up(next_static_double_offset, BytesPerLong); | |
3539 } | |
3540 | |
3541 next_static_word_offset = next_static_double_offset + | |
7587 | 3542 ((fac.count[STATIC_DOUBLE] - fac_contended.count[STATIC_DOUBLE]) * BytesPerLong); |
0 | 3543 next_static_short_offset = next_static_word_offset + |
7587 | 3544 ((fac.count[STATIC_WORD] - fac_contended.count[STATIC_WORD]) * BytesPerInt); |
0 | 3545 next_static_byte_offset = next_static_short_offset + |
7587 | 3546 ((fac.count[STATIC_SHORT] - fac_contended.count[STATIC_SHORT]) * BytesPerShort); |
3547 next_static_padded_offset = next_static_byte_offset + | |
3548 ((fac.count[STATIC_BYTE] - fac_contended.count[STATIC_BYTE]) * 1); | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
3549 |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3550 first_nonstatic_field_offset = instanceOopDesc::base_offset_in_bytes() + |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3551 nonstatic_field_size * heapOopSize; |
7587 | 3552 |
3553 // class is contended, pad before all the fields | |
3554 if (parsed_annotations.is_contended()) { | |
3555 first_nonstatic_field_offset += pad_size; | |
3556 } | |
3557 | |
0 | 3558 next_nonstatic_field_offset = first_nonstatic_field_offset; |
3559 | |
7587 | 3560 unsigned int nonstatic_double_count = fac.count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; |
3561 unsigned int nonstatic_word_count = fac.count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; | |
3562 unsigned int nonstatic_short_count = fac.count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; | |
3563 unsigned int nonstatic_byte_count = fac.count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; | |
3564 unsigned int nonstatic_oop_count = fac.count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; | |
0 | 3565 |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3566 bool super_has_nonstatic_fields = |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3567 (super_klass() != NULL && super_klass->has_nonstatic_fields()); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3568 bool has_nonstatic_fields = super_has_nonstatic_fields || |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3569 ((nonstatic_double_count + nonstatic_word_count + |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3570 nonstatic_short_count + nonstatic_byte_count + |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3571 nonstatic_oop_count) != 0); |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3572 |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3573 |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3574 // Prepare list of oops for oop map generation. |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3575 int* nonstatic_oop_offsets; |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3576 unsigned int* nonstatic_oop_counts; |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3577 unsigned int nonstatic_oop_map_count = 0; |
0 | 3578 |
3579 nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3580 THREAD, int, nonstatic_oop_count + 1); |
938 | 3581 nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3582 THREAD, unsigned int, nonstatic_oop_count + 1); |
0 | 3583 |
3938 | 3584 first_nonstatic_oop_offset = 0; // will be set for first oop field |
0 | 3585 |
3586 #ifndef PRODUCT | |
3587 if( PrintCompactFieldsSavings ) { | |
3588 next_nonstatic_double_offset = next_nonstatic_field_offset + | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3589 (nonstatic_oop_count * heapOopSize); |
0 | 3590 if ( nonstatic_double_count > 0 ) { |
3591 next_nonstatic_double_offset = align_size_up(next_nonstatic_double_offset, BytesPerLong); | |
3592 } | |
3593 next_nonstatic_word_offset = next_nonstatic_double_offset + | |
3594 (nonstatic_double_count * BytesPerLong); | |
3595 next_nonstatic_short_offset = next_nonstatic_word_offset + | |
3596 (nonstatic_word_count * BytesPerInt); | |
3597 next_nonstatic_byte_offset = next_nonstatic_short_offset + | |
3598 (nonstatic_short_count * BytesPerShort); | |
3599 next_nonstatic_type_offset = align_size_up((next_nonstatic_byte_offset + | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3600 nonstatic_byte_count ), heapOopSize ); |
0 | 3601 orig_nonstatic_field_size = nonstatic_field_size + |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3602 ((next_nonstatic_type_offset - first_nonstatic_field_offset)/heapOopSize); |
0 | 3603 } |
3604 #endif | |
3605 bool compact_fields = CompactFields; | |
3606 int allocation_style = FieldsAllocationStyle; | |
1366
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3607 if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3608 assert(false, "0 <= FieldsAllocationStyle <= 2"); |
0 | 3609 allocation_style = 1; // Optimistic |
3610 } | |
3611 | |
3612 // The next classes have predefined hard-coded fields offsets | |
3613 // (see in JavaClasses::compute_hard_coded_offsets()). | |
3614 // Use default fields allocation order for them. | |
3615 if( (allocation_style != 0 || compact_fields ) && class_loader.is_null() && | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3616 (class_name == vmSymbols::java_lang_AssertionStatusDirectives() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3617 class_name == vmSymbols::java_lang_Class() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3618 class_name == vmSymbols::java_lang_ClassLoader() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3619 class_name == vmSymbols::java_lang_ref_Reference() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3620 class_name == vmSymbols::java_lang_ref_SoftReference() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3621 class_name == vmSymbols::java_lang_StackTraceElement() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3622 class_name == vmSymbols::java_lang_String() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3623 class_name == vmSymbols::java_lang_Throwable() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3624 class_name == vmSymbols::java_lang_Boolean() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3625 class_name == vmSymbols::java_lang_Character() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3626 class_name == vmSymbols::java_lang_Float() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3627 class_name == vmSymbols::java_lang_Double() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3628 class_name == vmSymbols::java_lang_Byte() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3629 class_name == vmSymbols::java_lang_Short() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3630 class_name == vmSymbols::java_lang_Integer() || |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
3631 class_name == vmSymbols::java_lang_Long())) { |
0 | 3632 allocation_style = 0; // Allocate oops first |
3633 compact_fields = false; // Don't compact fields | |
3634 } | |
3635 | |
3636 if( allocation_style == 0 ) { | |
7587 | 3637 // Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields |
0 | 3638 next_nonstatic_oop_offset = next_nonstatic_field_offset; |
3639 next_nonstatic_double_offset = next_nonstatic_oop_offset + | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3640 (nonstatic_oop_count * heapOopSize); |
0 | 3641 } else if( allocation_style == 1 ) { |
7587 | 3642 // Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields |
0 | 3643 next_nonstatic_double_offset = next_nonstatic_field_offset; |
1366
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3644 } else if( allocation_style == 2 ) { |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3645 // Fields allocation: oops fields in super and sub classes are together. |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3646 if( nonstatic_field_size > 0 && super_klass() != NULL && |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3647 super_klass->nonstatic_oop_map_size() > 0 ) { |
3786
498c6cf70f7e
7058036: FieldsAllocationStyle=2 does not work in 32-bit VM
kvn
parents:
3245
diff
changeset
|
3648 int map_count = super_klass->nonstatic_oop_map_count(); |
1366
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3649 OopMapBlock* first_map = super_klass->start_of_nonstatic_oop_maps(); |
3786
498c6cf70f7e
7058036: FieldsAllocationStyle=2 does not work in 32-bit VM
kvn
parents:
3245
diff
changeset
|
3650 OopMapBlock* last_map = first_map + map_count - 1; |
1366
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3651 int next_offset = last_map->offset() + (last_map->count() * heapOopSize); |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3652 if (next_offset == next_nonstatic_field_offset) { |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3653 allocation_style = 0; // allocate oops first |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3654 next_nonstatic_oop_offset = next_nonstatic_field_offset; |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3655 next_nonstatic_double_offset = next_nonstatic_oop_offset + |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3656 (nonstatic_oop_count * heapOopSize); |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3657 } |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3658 } |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3659 if( allocation_style == 2 ) { |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3660 allocation_style = 1; // allocate oops last |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3661 next_nonstatic_double_offset = next_nonstatic_field_offset; |
b9d85fcdf743
6940733: allocate non static oop fields in super and sub classes together
kvn
parents:
1144
diff
changeset
|
3662 } |
0 | 3663 } else { |
3664 ShouldNotReachHere(); | |
3665 } | |
3666 | |
3667 int nonstatic_oop_space_count = 0; | |
3668 int nonstatic_word_space_count = 0; | |
3669 int nonstatic_short_space_count = 0; | |
3670 int nonstatic_byte_space_count = 0; | |
3671 int nonstatic_oop_space_offset; | |
3672 int nonstatic_word_space_offset; | |
3673 int nonstatic_short_space_offset; | |
3674 int nonstatic_byte_space_offset; | |
3675 | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3676 if( nonstatic_double_count > 0 ) { |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3677 int offset = next_nonstatic_double_offset; |
0 | 3678 next_nonstatic_double_offset = align_size_up(offset, BytesPerLong); |
3679 if( compact_fields && offset != next_nonstatic_double_offset ) { | |
3680 // Allocate available fields into the gap before double field. | |
3681 int length = next_nonstatic_double_offset - offset; | |
3682 assert(length == BytesPerInt, ""); | |
3683 nonstatic_word_space_offset = offset; | |
3684 if( nonstatic_word_count > 0 ) { | |
3685 nonstatic_word_count -= 1; | |
3686 nonstatic_word_space_count = 1; // Only one will fit | |
3687 length -= BytesPerInt; | |
3688 offset += BytesPerInt; | |
3689 } | |
3690 nonstatic_short_space_offset = offset; | |
3691 while( length >= BytesPerShort && nonstatic_short_count > 0 ) { | |
3692 nonstatic_short_count -= 1; | |
3693 nonstatic_short_space_count += 1; | |
3694 length -= BytesPerShort; | |
3695 offset += BytesPerShort; | |
3696 } | |
3697 nonstatic_byte_space_offset = offset; | |
3698 while( length > 0 && nonstatic_byte_count > 0 ) { | |
3699 nonstatic_byte_count -= 1; | |
3700 nonstatic_byte_space_count += 1; | |
3701 length -= 1; | |
3702 } | |
3703 // Allocate oop field in the gap if there are no other fields for that. | |
3704 nonstatic_oop_space_offset = offset; | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
3705 if( length >= heapOopSize && nonstatic_oop_count > 0 && |
0 | 3706 allocation_style != 0 ) { // when oop fields not first |
3707 nonstatic_oop_count -= 1; | |
3708 nonstatic_oop_space_count = 1; // Only one will fit | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3709 length -= heapOopSize; |
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3710 offset += heapOopSize; |
0 | 3711 } |
3712 } | |
3713 } | |
3714 | |
3715 next_nonstatic_word_offset = next_nonstatic_double_offset + | |
3716 (nonstatic_double_count * BytesPerLong); | |
3717 next_nonstatic_short_offset = next_nonstatic_word_offset + | |
3718 (nonstatic_word_count * BytesPerInt); | |
3719 next_nonstatic_byte_offset = next_nonstatic_short_offset + | |
3720 (nonstatic_short_count * BytesPerShort); | |
7587 | 3721 next_nonstatic_padded_offset = next_nonstatic_byte_offset + |
3722 nonstatic_byte_count; | |
3723 | |
3724 // let oops jump before padding with this allocation style | |
3725 if( allocation_style == 1 ) { | |
3726 next_nonstatic_oop_offset = next_nonstatic_padded_offset; | |
0 | 3727 if( nonstatic_oop_count > 0 ) { |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3728 next_nonstatic_oop_offset = align_size_up(next_nonstatic_oop_offset, heapOopSize); |
0 | 3729 } |
7587 | 3730 next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); |
0 | 3731 } |
3732 | |
3733 // Iterate over fields again and compute correct offsets. | |
3734 // The field allocation type was temporarily stored in the offset slot. | |
3735 // oop fields are located before non-oop fields (static and non-static). | |
3938 | 3736 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { |
7587 | 3737 |
3738 // skip already laid out fields | |
3739 if (fs.is_offset_set()) continue; | |
3740 | |
3741 // contended fields are handled below | |
3742 if (fs.is_contended()) continue; | |
3743 | |
0 | 3744 int real_offset; |
7587 | 3745 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); |
3746 | |
3747 // pack the rest of the fields | |
0 | 3748 switch (atype) { |
3749 case STATIC_OOP: | |
3750 real_offset = next_static_oop_offset; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3751 next_static_oop_offset += heapOopSize; |
0 | 3752 break; |
3753 case STATIC_BYTE: | |
3754 real_offset = next_static_byte_offset; | |
3755 next_static_byte_offset += 1; | |
3756 break; | |
3757 case STATIC_SHORT: | |
3758 real_offset = next_static_short_offset; | |
3759 next_static_short_offset += BytesPerShort; | |
3760 break; | |
3761 case STATIC_WORD: | |
3762 real_offset = next_static_word_offset; | |
3763 next_static_word_offset += BytesPerInt; | |
3764 break; | |
3765 case STATIC_DOUBLE: | |
3766 real_offset = next_static_double_offset; | |
3767 next_static_double_offset += BytesPerLong; | |
3768 break; | |
3769 case NONSTATIC_OOP: | |
3770 if( nonstatic_oop_space_count > 0 ) { | |
3771 real_offset = nonstatic_oop_space_offset; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3772 nonstatic_oop_space_offset += heapOopSize; |
0 | 3773 nonstatic_oop_space_count -= 1; |
3774 } else { | |
3775 real_offset = next_nonstatic_oop_offset; | |
113
ba764ed4b6f2
6420645: Create a vm that uses compressed oops for up to 32gb heapsizes
coleenp
parents:
92
diff
changeset
|
3776 next_nonstatic_oop_offset += heapOopSize; |
0 | 3777 } |
3778 // Update oop maps | |
3779 if( nonstatic_oop_map_count > 0 && | |
3780 nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3781 real_offset - |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3782 int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3783 heapOopSize ) { |
0 | 3784 // Extend current oop map |
938 | 3785 nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; |
0 | 3786 } else { |
3787 // Create new oop map | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
3788 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; |
938 | 3789 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; |
0 | 3790 nonstatic_oop_map_count += 1; |
3791 if( first_nonstatic_oop_offset == 0 ) { // Undefined | |
3792 first_nonstatic_oop_offset = real_offset; | |
3793 } | |
3794 } | |
3795 break; | |
3796 case NONSTATIC_BYTE: | |
3797 if( nonstatic_byte_space_count > 0 ) { | |
3798 real_offset = nonstatic_byte_space_offset; | |
3799 nonstatic_byte_space_offset += 1; | |
3800 nonstatic_byte_space_count -= 1; | |
3801 } else { | |
3802 real_offset = next_nonstatic_byte_offset; | |
3803 next_nonstatic_byte_offset += 1; | |
3804 } | |
3805 break; | |
3806 case NONSTATIC_SHORT: | |
3807 if( nonstatic_short_space_count > 0 ) { | |
3808 real_offset = nonstatic_short_space_offset; | |
3809 nonstatic_short_space_offset += BytesPerShort; | |
3810 nonstatic_short_space_count -= 1; | |
3811 } else { | |
3812 real_offset = next_nonstatic_short_offset; | |
3813 next_nonstatic_short_offset += BytesPerShort; | |
3814 } | |
3815 break; | |
3816 case NONSTATIC_WORD: | |
3817 if( nonstatic_word_space_count > 0 ) { | |
3818 real_offset = nonstatic_word_space_offset; | |
3819 nonstatic_word_space_offset += BytesPerInt; | |
3820 nonstatic_word_space_count -= 1; | |
3821 } else { | |
3822 real_offset = next_nonstatic_word_offset; | |
3823 next_nonstatic_word_offset += BytesPerInt; | |
3824 } | |
3825 break; | |
3826 case NONSTATIC_DOUBLE: | |
3827 real_offset = next_nonstatic_double_offset; | |
3828 next_nonstatic_double_offset += BytesPerLong; | |
3829 break; | |
3830 default: | |
3831 ShouldNotReachHere(); | |
3832 } | |
3938 | 3833 fs.set_offset(real_offset); |
0 | 3834 } |
3835 | |
7587 | 3836 |
3837 // Handle the contended cases. | |
3838 // | |
3839 // Each contended field should not intersect the cache line with another contended field. | |
3840 // In the absence of alignment information, we end up with pessimistically separating | |
3841 // the fields with full-width padding. | |
3842 // | |
3843 // Additionally, this should not break alignment for the fields, so we round the alignment up | |
3844 // for each field. | |
3845 if (contended_count > 0) { | |
3846 | |
3847 // if there is at least one contended field, we need to have pre-padding for them | |
3848 if (nonstatic_contended_count > 0) { | |
3849 next_nonstatic_padded_offset += pad_size; | |
3850 } | |
3851 | |
3852 // collect all contended groups | |
3853 BitMap bm(cp->size()); | |
3854 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
3855 // skip already laid out fields | |
3856 if (fs.is_offset_set()) continue; | |
3857 | |
3858 if (fs.is_contended()) { | |
3859 bm.set_bit(fs.contended_group()); | |
3860 } | |
3861 } | |
3862 | |
3863 int current_group = -1; | |
3864 while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { | |
3865 | |
3866 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
3867 | |
3868 // skip already laid out fields | |
3869 if (fs.is_offset_set()) continue; | |
3870 | |
3871 // skip non-contended fields and fields from different group | |
3872 if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; | |
3873 | |
3874 // handle statics below | |
3875 if (fs.access_flags().is_static()) continue; | |
3876 | |
3877 int real_offset; | |
3878 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); | |
3879 | |
3880 switch (atype) { | |
3881 case NONSTATIC_BYTE: | |
3882 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, 1); | |
3883 real_offset = next_nonstatic_padded_offset; | |
3884 next_nonstatic_padded_offset += 1; | |
3885 break; | |
3886 | |
3887 case NONSTATIC_SHORT: | |
3888 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerShort); | |
3889 real_offset = next_nonstatic_padded_offset; | |
3890 next_nonstatic_padded_offset += BytesPerShort; | |
3891 break; | |
3892 | |
3893 case NONSTATIC_WORD: | |
3894 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerInt); | |
3895 real_offset = next_nonstatic_padded_offset; | |
3896 next_nonstatic_padded_offset += BytesPerInt; | |
3897 break; | |
3898 | |
3899 case NONSTATIC_DOUBLE: | |
3900 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, BytesPerLong); | |
3901 real_offset = next_nonstatic_padded_offset; | |
3902 next_nonstatic_padded_offset += BytesPerLong; | |
3903 break; | |
3904 | |
3905 case NONSTATIC_OOP: | |
3906 next_nonstatic_padded_offset = align_size_up(next_nonstatic_padded_offset, heapOopSize); | |
3907 real_offset = next_nonstatic_padded_offset; | |
3908 next_nonstatic_padded_offset += heapOopSize; | |
3909 | |
3910 // Create new oop map | |
3911 nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; | |
3912 nonstatic_oop_counts [nonstatic_oop_map_count] = 1; | |
3913 nonstatic_oop_map_count += 1; | |
3914 if( first_nonstatic_oop_offset == 0 ) { // Undefined | |
3915 first_nonstatic_oop_offset = real_offset; | |
3916 } | |
3917 break; | |
3918 | |
3919 default: | |
3920 ShouldNotReachHere(); | |
3921 } | |
3922 | |
3923 if (fs.contended_group() == 0) { | |
3924 // Contended group defines the equivalence class over the fields: | |
3925 // the fields within the same contended group are not inter-padded. | |
3926 // The only exception is default group, which does not incur the | |
3927 // equivalence, and so requires intra-padding. | |
3928 next_nonstatic_padded_offset += pad_size; | |
3929 } | |
3930 | |
3931 fs.set_offset(real_offset); | |
3932 } // for | |
3933 | |
3934 // Start laying out the next group. | |
3935 // Note that this will effectively pad the last group in the back; | |
3936 // this is expected to alleviate memory contention effects for | |
3937 // subclass fields and/or adjacent object. | |
3938 // If this was the default group, the padding is already in place. | |
3939 if (current_group != 0) { | |
3940 next_nonstatic_padded_offset += pad_size; | |
3941 } | |
3942 } | |
3943 | |
3944 // handle static fields | |
3945 | |
3946 // if there is at least one contended field, we need to have pre-padding for them | |
3947 if (static_contended_count > 0) { | |
3948 next_static_padded_offset += pad_size; | |
3949 } | |
3950 | |
3951 current_group = -1; | |
3952 while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { | |
3953 | |
3954 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
3955 | |
3956 // skip already laid out fields | |
3957 if (fs.is_offset_set()) continue; | |
3958 | |
3959 // skip non-contended fields and fields from different group | |
3960 if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; | |
3961 | |
3962 // non-statics already handled above | |
3963 if (!fs.access_flags().is_static()) continue; | |
3964 | |
3965 int real_offset; | |
3966 FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); | |
3967 | |
3968 switch (atype) { | |
3969 | |
3970 case STATIC_BYTE: | |
3971 next_static_padded_offset = align_size_up(next_static_padded_offset, 1); | |
3972 real_offset = next_static_padded_offset; | |
3973 next_static_padded_offset += 1; | |
3974 break; | |
3975 | |
3976 case STATIC_SHORT: | |
3977 next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerShort); | |
3978 real_offset = next_static_padded_offset; | |
3979 next_static_padded_offset += BytesPerShort; | |
3980 break; | |
3981 | |
3982 case STATIC_WORD: | |
3983 next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerInt); | |
3984 real_offset = next_static_padded_offset; | |
3985 next_static_padded_offset += BytesPerInt; | |
3986 break; | |
3987 | |
3988 case STATIC_DOUBLE: | |
3989 next_static_padded_offset = align_size_up(next_static_padded_offset, BytesPerLong); | |
3990 real_offset = next_static_padded_offset; | |
3991 next_static_padded_offset += BytesPerLong; | |
3992 break; | |
3993 | |
3994 case STATIC_OOP: | |
3995 next_static_padded_offset = align_size_up(next_static_padded_offset, heapOopSize); | |
3996 real_offset = next_static_padded_offset; | |
3997 next_static_padded_offset += heapOopSize; | |
3998 break; | |
3999 | |
4000 default: | |
4001 ShouldNotReachHere(); | |
4002 } | |
4003 | |
4004 if (fs.contended_group() == 0) { | |
4005 // Contended group defines the equivalence class over the fields: | |
4006 // the fields within the same contended group are not inter-padded. | |
4007 // The only exception is default group, which does not incur the | |
4008 // equivalence, and so requires intra-padding. | |
4009 next_static_padded_offset += pad_size; | |
4010 } | |
4011 | |
4012 fs.set_offset(real_offset); | |
4013 } // for | |
4014 | |
4015 // Start laying out the next group. | |
4016 // Note that this will effectively pad the last group in the back; | |
4017 // this is expected to alleviate memory contention effects for | |
4018 // subclass fields and/or adjacent object. | |
4019 // If this was the default group, the padding is already in place. | |
4020 if (current_group != 0) { | |
4021 next_static_padded_offset += pad_size; | |
4022 } | |
4023 | |
4024 } | |
4025 | |
4026 } // handle contended | |
4027 | |
0 | 4028 // Size of instances |
4029 int instance_size; | |
4030 | |
7587 | 4031 int notaligned_offset = next_nonstatic_padded_offset; |
4032 | |
4033 // Entire class is contended, pad in the back. | |
4034 // This helps to alleviate memory contention effects for subclass fields | |
4035 // and/or adjacent object. | |
4036 if (parsed_annotations.is_contended()) { | |
4037 notaligned_offset += pad_size; | |
4038 next_static_padded_offset += pad_size; | |
4039 } | |
4040 | |
4041 int next_static_type_offset = align_size_up(next_static_padded_offset, wordSize); | |
4042 int static_field_size = (next_static_type_offset - | |
4043 InstanceMirrorKlass::offset_of_static_fields()) / wordSize; | |
4044 | |
4045 next_nonstatic_type_offset = align_size_up(notaligned_offset, heapOopSize ); | |
4046 nonstatic_field_size = nonstatic_field_size + ((next_nonstatic_type_offset | |
4047 - first_nonstatic_field_offset)/heapOopSize); | |
4048 | |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4049 next_nonstatic_type_offset = align_size_up(notaligned_offset, wordSize ); |
0 | 4050 instance_size = align_object_size(next_nonstatic_type_offset / wordSize); |
4051 | |
7587 | 4052 assert(instance_size == align_object_size(align_size_up( |
4053 (instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize + ((parsed_annotations.is_contended()) ? pad_size : 0)), | |
4054 wordSize) / wordSize), "consistent layout helper value"); | |
0 | 4055 |
938 | 4056 // Number of non-static oop map blocks allocated at end of klass. |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4057 const unsigned int total_oop_map_count = |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4058 compute_oop_map_count(super_klass, nonstatic_oop_map_count, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4059 first_nonstatic_oop_offset); |
0 | 4060 // Compute reference type |
4061 ReferenceType rt; | |
4062 if (super_klass() == NULL) { | |
4063 rt = REF_NONE; | |
4064 } else { | |
4065 rt = super_klass->reference_type(); | |
4066 } | |
4067 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4068 // We can now create the basic Klass* for this klass |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4069 int total_oop_map_size2 = |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4070 InstanceKlass::nonstatic_oop_map_size(total_oop_map_count); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4071 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4072 Klass* ik = InstanceKlass::allocate_instance_klass(loader_data, |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4073 vtable_size, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4074 itable_size, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4075 static_field_size, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4076 total_oop_map_size2, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4077 rt, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4078 access_flags, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4079 name, |
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4080 super_klass(), |
8031 | 4081 !host_klass.is_null(), |
6831
d8ce2825b193
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
6735
diff
changeset
|
4082 CHECK_(nullHandle)); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4083 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4084 // Add all classes to our internal class loader list here, |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4085 // including classes in the bootstrap (NULL) class loader. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4086 loader_data->add_class(ik); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4087 |
0 | 4088 instanceKlassHandle this_klass (THREAD, ik); |
4089 | |
938 | 4090 assert(this_klass->static_field_size() == static_field_size, "sanity"); |
4091 assert(this_klass->nonstatic_oop_map_count() == total_oop_map_count, | |
4092 "sanity"); | |
0 | 4093 |
4094 // Fill in information already parsed | |
975 | 4095 this_klass->set_should_verify_class(verify); |
0 | 4096 jint lh = Klass::instance_layout_helper(instance_size, false); |
4097 this_klass->set_layout_helper(lh); | |
4098 assert(this_klass->oop_is_instance(), "layout is correct"); | |
4099 assert(this_klass->size_helper() == instance_size, "correct size_helper"); | |
4100 // Not yet: supers are done below to support the new subtype-checking fields | |
4101 //this_klass->set_super(super_klass()); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4102 this_klass->set_class_loader_data(loader_data); |
0 | 4103 this_klass->set_nonstatic_field_size(nonstatic_field_size); |
975 | 4104 this_klass->set_has_nonstatic_fields(has_nonstatic_fields); |
3938 | 4105 this_klass->set_static_oop_field_count(fac.count[STATIC_OOP]); |
0 | 4106 cp->set_pool_holder(this_klass()); |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4107 error_handler.set_in_error(false); // turn off error handler for cp |
0 | 4108 this_klass->set_constants(cp()); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4109 this_klass->set_local_interfaces(local_interfaces); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4110 this_klass->set_fields(fields, java_fields_count); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4111 this_klass->set_methods(methods); |
0 | 4112 if (has_final_method) { |
4113 this_klass->set_has_final_method(); | |
4114 } | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4115 this_klass->set_method_ordering(method_ordering); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4116 // The InstanceKlass::_methods_jmethod_ids cache and the |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4117 // InstanceKlass::_methods_cached_itable_indices cache are |
977
74a5db69c1fe
6419370: 4/4 new jmethodID code has tiny holes in synchronization
dcubed
parents:
975
diff
changeset
|
4118 // both managed on the assumption that the initial cache |
74a5db69c1fe
6419370: 4/4 new jmethodID code has tiny holes in synchronization
dcubed
parents:
975
diff
changeset
|
4119 // size is equal to the number of methods in the class. If |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4120 // that changes, then InstanceKlass::idnum_can_increment() |
977
74a5db69c1fe
6419370: 4/4 new jmethodID code has tiny holes in synchronization
dcubed
parents:
975
diff
changeset
|
4121 // has to be changed accordingly. |
0 | 4122 this_klass->set_initial_method_idnum(methods->length()); |
4123 this_klass->set_name(cp->klass_name_at(this_class_index)); | |
6852 | 4124 if (is_anonymous()) // I am well known to myself |
474
7a018855d2f0
6779339: turn off LinkWellKnownClasses by default pending further testing
jrose
parents:
431
diff
changeset
|
4125 cp->klass_at_put(this_class_index, this_klass()); // eagerly resolve |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4126 |
8031 | 4127 // Assign allocations if needed |
4128 if (_annotations != NULL || _type_annotations != NULL || | |
4129 fields_annotations != NULL || fields_type_annotations != NULL) { | |
4130 Annotations* annotations = Annotations::allocate(loader_data, CHECK_NULL); | |
4131 annotations->set_class_annotations(_annotations); | |
4132 annotations->set_class_type_annotations(_type_annotations); | |
4133 annotations->set_fields_annotations(fields_annotations); | |
4134 annotations->set_fields_type_annotations(fields_type_annotations); | |
4135 this_klass->set_annotations(annotations); | |
7457
35431a769282
8004823: Add VM support for type annotation reflection
stefank
parents:
7187
diff
changeset
|
4136 } |
0 | 4137 |
4138 this_klass->set_minor_version(minor_version); | |
4139 this_klass->set_major_version(major_version); | |
6934 | 4140 this_klass->set_has_default_methods(has_default_methods); |
0 | 4141 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4142 // Set up Method*::intrinsic_id as soon as we know the names of methods. |
856
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4143 // (We used to do this lazily, but now we query it in Rewriter, |
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4144 // which is eagerly done for every method, so we might as well do it now, |
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4145 // when everything is fresh in memory.) |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4146 if (Method::klass_id_for_intrinsics(this_klass()) != vmSymbols::NO_SID) { |
856
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4147 for (int j = 0; j < methods->length(); j++) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4148 methods->at(j)->init_intrinsic_id(); |
856
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4149 } |
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4150 } |
75596850f863
6862576: vmIntrinsics needs cleanup in order to support JSR 292 intrinsics
jrose
parents:
710
diff
changeset
|
4151 |
0 | 4152 if (cached_class_file_bytes != NULL) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4153 // JVMTI: we have an InstanceKlass now, tell it about the cached bytes |
0 | 4154 this_klass->set_cached_class_file(cached_class_file_bytes, |
4155 cached_class_file_length); | |
4156 } | |
4157 | |
6934 | 4158 // Fill in field values obtained by parse_classfile_attributes |
4159 if (parsed_annotations.has_any_annotations()) | |
4160 parsed_annotations.apply_to(this_klass); | |
4161 apply_parsed_class_attributes(this_klass); | |
4162 | |
0 | 4163 // Miranda methods |
4164 if ((num_miranda_methods > 0) || | |
4165 // if this class introduced new miranda methods or | |
4166 (super_klass.not_null() && (super_klass->has_miranda_methods())) | |
4167 // super class exists and this class inherited miranda methods | |
4168 ) { | |
4169 this_klass->set_has_miranda_methods(); // then set a flag | |
4170 } | |
4171 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4172 this_klass->set_transitive_interfaces(transitive_interfaces); |
0 | 4173 |
4174 // Fill in information needed to compute superclasses. | |
4175 this_klass->initialize_supers(super_klass(), CHECK_(nullHandle)); | |
4176 | |
4177 // Initialize itable offset tables | |
4178 klassItable::setup_itable_offset_table(this_klass); | |
4179 | |
6934 | 4180 // Compute transitive closure of interfaces this class implements |
0 | 4181 // Do final class setup |
938 | 4182 fill_oop_maps(this_klass, nonstatic_oop_map_count, nonstatic_oop_offsets, nonstatic_oop_counts); |
0 | 4183 |
6222
6d8f36bcef55
6711908: JVM needs direct access to some annotations
jrose
parents:
6100
diff
changeset
|
4184 // Fill in has_finalizer, has_vanilla_constructor, and layout_helper |
0 | 4185 set_precomputed_flags(this_klass); |
4186 | |
4187 // reinitialize modifiers, using the InnerClasses attribute | |
4188 int computed_modifiers = this_klass->compute_modifier_flags(CHECK_(nullHandle)); | |
4189 this_klass->set_modifier_flags(computed_modifiers); | |
4190 | |
4191 // check if this class can access its super class | |
4192 check_super_class_access(this_klass, CHECK_(nullHandle)); | |
4193 | |
4194 // check if this class can access its superinterfaces | |
4195 check_super_interface_access(this_klass, CHECK_(nullHandle)); | |
4196 | |
4197 // check if this class overrides any final method | |
4198 check_final_method_override(this_klass, CHECK_(nullHandle)); | |
4199 | |
4200 // check that if this class is an interface then it doesn't have static methods | |
4201 if (this_klass->is_interface()) { | |
7579
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4202 /* An interface in a JAVA 8 classfile can be static */ |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4203 if (_major_version < JAVA_8_VERSION) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4204 check_illegal_static_method(this_klass, CHECK_(nullHandle)); |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4205 } |
0 | 4206 } |
4207 | |
6934 | 4208 |
4209 #ifdef ASSERT | |
4210 if (ParseAllGenericSignatures) { | |
4211 parseAndPrintGenericSignatures(this_klass, CHECK_(nullHandle)); | |
4212 } | |
4213 #endif | |
4214 | |
4215 // Generate any default methods - default methods are interface methods | |
4216 // that have a default implementation. This is new with Lambda project. | |
4217 if (has_default_methods && !access_flags.is_interface() && | |
4218 local_interfaces->length() > 0) { | |
4219 DefaultMethods::generate_default_methods( | |
4220 this_klass(), &all_mirandas, CHECK_(nullHandle)); | |
4221 } | |
4222 | |
2376
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
4223 // Allocate mirror and initialize static fields |
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
4224 java_lang_Class::create_mirror(this_klass, CHECK_(nullHandle)); |
c7f3d0b4570f
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
2357
diff
changeset
|
4225 |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4226 // Allocate a simple java object for locking during class initialization. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4227 // This needs to be a java object because it can be held across a java call. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4228 typeArrayOop r = oopFactory::new_typeArray(T_INT, 0, CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4229 this_klass->set_init_lock(r); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4230 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4231 // TODO: Move these oops to the mirror |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4232 this_klass->set_protection_domain(protection_domain()); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4233 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4234 // Update the loader_data graph. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4235 record_defined_class_dependencies(this_klass, CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4236 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4237 ClassLoadingService::notify_class_loaded(InstanceKlass::cast(this_klass()), |
0 | 4238 false /* not shared class */); |
4239 | |
4240 if (TraceClassLoading) { | |
6934 | 4241 ResourceMark rm; |
0 | 4242 // print in a single call to reduce interleaving of output |
4243 if (cfs->source() != NULL) { | |
4244 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), | |
4245 cfs->source()); | |
4246 } else if (class_loader.is_null()) { | |
4247 if (THREAD->is_Java_thread()) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4248 Klass* caller = ((JavaThread*)THREAD)->security_get_caller_class(1); |
0 | 4249 tty->print("[Loaded %s by instance of %s]\n", |
4250 this_klass->external_name(), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4251 InstanceKlass::cast(caller)->external_name()); |
0 | 4252 } else { |
4253 tty->print("[Loaded %s]\n", this_klass->external_name()); | |
4254 } | |
4255 } else { | |
4256 tty->print("[Loaded %s from %s]\n", this_klass->external_name(), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4257 InstanceKlass::cast(class_loader->klass())->external_name()); |
0 | 4258 } |
4259 } | |
4260 | |
4261 if (TraceClassResolution) { | |
6934 | 4262 ResourceMark rm; |
0 | 4263 // print out the superclass. |
6983 | 4264 const char * from = this_klass()->external_name(); |
0 | 4265 if (this_klass->java_super() != NULL) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4266 tty->print("RESOLVE %s %s (super)\n", from, InstanceKlass::cast(this_klass->java_super())->external_name()); |
0 | 4267 } |
4268 // print out each of the interface classes referred to by this class. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4269 Array<Klass*>* local_interfaces = this_klass->local_interfaces(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4270 if (local_interfaces != NULL) { |
0 | 4271 int length = local_interfaces->length(); |
4272 for (int i = 0; i < length; i++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4273 Klass* k = local_interfaces->at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4274 InstanceKlass* to_class = InstanceKlass::cast(k); |
0 | 4275 const char * to = to_class->external_name(); |
657
715dceaa89b7
6603316: Improve instrumentation for classes loaded at startup
acorn
parents:
652
diff
changeset
|
4276 tty->print("RESOLVE %s %s (interface)\n", from, to); |
0 | 4277 } |
4278 } | |
4279 } | |
4280 | |
4281 #ifndef PRODUCT | |
4282 if( PrintCompactFieldsSavings ) { | |
6934 | 4283 ResourceMark rm; |
0 | 4284 if( nonstatic_field_size < orig_nonstatic_field_size ) { |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4285 tty->print("[Saved %d of %d bytes in %s]\n", |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4286 (orig_nonstatic_field_size - nonstatic_field_size)*heapOopSize, |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4287 orig_nonstatic_field_size*heapOopSize, |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4288 this_klass->external_name()); |
0 | 4289 } else if( nonstatic_field_size > orig_nonstatic_field_size ) { |
165
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4290 tty->print("[Wasted %d over %d bytes in %s]\n", |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4291 (nonstatic_field_size - orig_nonstatic_field_size)*heapOopSize, |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4292 orig_nonstatic_field_size*heapOopSize, |
437d03ea40b1
6703888: Compressed Oops: use the 32-bits gap after klass in a object
kvn
parents:
136
diff
changeset
|
4293 this_klass->external_name()); |
0 | 4294 } |
4295 } | |
4296 #endif | |
4297 | |
7587 | 4298 #ifndef PRODUCT |
4299 if (PrintFieldLayout) { | |
4300 print_field_layout(name, | |
4301 fields, | |
4302 cp, | |
4303 instance_size, | |
4304 first_nonstatic_field_offset, | |
4305 next_nonstatic_field_offset, | |
4306 next_static_type_offset); | |
4307 } | |
4308 #endif | |
4309 | |
0 | 4310 // preserve result across HandleMark |
4311 preserve_this_klass = this_klass(); | |
4312 } | |
4313 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4314 // Create new handle outside HandleMark (might be needed for |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4315 // Extended Class Redefinition) |
0 | 4316 instanceKlassHandle this_klass (THREAD, preserve_this_klass); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4317 debug_only(this_klass->verify();) |
0 | 4318 |
4319 return this_klass; | |
4320 } | |
4321 | |
7587 | 4322 void ClassFileParser::print_field_layout(Symbol* name, |
4323 Array<u2>* fields, | |
4324 constantPoolHandle cp, | |
4325 int instance_size, | |
4326 int instance_fields_start, | |
4327 int instance_fields_end, | |
4328 int static_fields_end) { | |
4329 tty->print("%s: field layout\n", name->as_klass_external_name()); | |
4330 tty->print(" @%3d %s\n", instance_fields_start, "--- instance fields start ---"); | |
4331 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
4332 if (!fs.access_flags().is_static()) { | |
4333 tty->print(" @%3d \"%s\" %s\n", | |
4334 fs.offset(), | |
4335 fs.name()->as_klass_external_name(), | |
4336 fs.signature()->as_klass_external_name()); | |
4337 } | |
4338 } | |
4339 tty->print(" @%3d %s\n", instance_fields_end, "--- instance fields end ---"); | |
4340 tty->print(" @%3d %s\n", instance_size * wordSize, "--- instance ends ---"); | |
4341 tty->print(" @%3d %s\n", InstanceMirrorKlass::offset_of_static_fields(), "--- static fields start ---"); | |
4342 for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { | |
4343 if (fs.access_flags().is_static()) { | |
4344 tty->print(" @%3d \"%s\" %s\n", | |
4345 fs.offset(), | |
4346 fs.name()->as_klass_external_name(), | |
4347 fs.signature()->as_klass_external_name()); | |
4348 } | |
4349 } | |
4350 tty->print(" @%3d %s\n", static_fields_end, "--- static fields end ---"); | |
4351 tty->print("\n"); | |
4352 } | |
4353 | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4354 unsigned int |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4355 ClassFileParser::compute_oop_map_count(instanceKlassHandle super, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4356 unsigned int nonstatic_oop_map_count, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4357 int first_nonstatic_oop_offset) { |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4358 unsigned int map_count = |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4359 super.is_null() ? 0 : super->nonstatic_oop_map_count(); |
0 | 4360 if (nonstatic_oop_map_count > 0) { |
4361 // We have oops to add to map | |
938 | 4362 if (map_count == 0) { |
4363 map_count = nonstatic_oop_map_count; | |
0 | 4364 } else { |
938 | 4365 // Check whether we should add a new map block or whether the last one can |
4366 // be extended | |
4367 OopMapBlock* const first_map = super->start_of_nonstatic_oop_maps(); | |
4368 OopMapBlock* const last_map = first_map + map_count - 1; | |
4369 | |
4370 int next_offset = last_map->offset() + last_map->count() * heapOopSize; | |
0 | 4371 if (next_offset == first_nonstatic_oop_offset) { |
4372 // There is no gap bettwen superklass's last oop field and first | |
4373 // local oop field, merge maps. | |
4374 nonstatic_oop_map_count -= 1; | |
4375 } else { | |
4376 // Superklass didn't end with a oop field, add extra maps | |
938 | 4377 assert(next_offset < first_nonstatic_oop_offset, "just checking"); |
0 | 4378 } |
938 | 4379 map_count += nonstatic_oop_map_count; |
0 | 4380 } |
4381 } | |
938 | 4382 return map_count; |
0 | 4383 } |
4384 | |
4385 | |
4386 void ClassFileParser::fill_oop_maps(instanceKlassHandle k, | |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4387 unsigned int nonstatic_oop_map_count, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4388 int* nonstatic_oop_offsets, |
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4389 unsigned int* nonstatic_oop_counts) { |
0 | 4390 OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4391 const InstanceKlass* const super = k->superklass(); |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4392 const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0; |
938 | 4393 if (super_count > 0) { |
4394 // Copy maps from superklass | |
0 | 4395 OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps(); |
939
9eebd3ac74cf
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
938
diff
changeset
|
4396 for (unsigned int i = 0; i < super_count; ++i) { |
0 | 4397 *this_oop_map++ = *super_oop_map++; |
4398 } | |
4399 } | |
938 | 4400 |
0 | 4401 if (nonstatic_oop_map_count > 0) { |
938 | 4402 if (super_count + nonstatic_oop_map_count > k->nonstatic_oop_map_count()) { |
4403 // The counts differ because there is no gap between superklass's last oop | |
4404 // field and the first local oop field. Extend the last oop map copied | |
0 | 4405 // from the superklass instead of creating new one. |
4406 nonstatic_oop_map_count--; | |
4407 nonstatic_oop_offsets++; | |
4408 this_oop_map--; | |
938 | 4409 this_oop_map->set_count(this_oop_map->count() + *nonstatic_oop_counts++); |
0 | 4410 this_oop_map++; |
4411 } | |
938 | 4412 |
0 | 4413 // Add new map blocks, fill them |
4414 while (nonstatic_oop_map_count-- > 0) { | |
4415 this_oop_map->set_offset(*nonstatic_oop_offsets++); | |
938 | 4416 this_oop_map->set_count(*nonstatic_oop_counts++); |
0 | 4417 this_oop_map++; |
4418 } | |
938 | 4419 assert(k->start_of_nonstatic_oop_maps() + k->nonstatic_oop_map_count() == |
4420 this_oop_map, "sanity"); | |
0 | 4421 } |
4422 } | |
4423 | |
4424 | |
4425 void ClassFileParser::set_precomputed_flags(instanceKlassHandle k) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4426 Klass* super = k->super(); |
0 | 4427 |
4428 // Check if this klass has an empty finalize method (i.e. one with return bytecode only), | |
4429 // in which case we don't have to register objects as finalizable | |
4430 if (!_has_empty_finalizer) { | |
4431 if (_has_finalizer || | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4432 (super != NULL && super->has_finalizer())) { |
0 | 4433 k->set_has_finalizer(); |
4434 } | |
4435 } | |
4436 | |
4437 #ifdef ASSERT | |
4438 bool f = false; | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4439 Method* m = k->lookup_method(vmSymbols::finalize_method_name(), |
0 | 4440 vmSymbols::void_method_signature()); |
4441 if (m != NULL && !m->is_empty_method()) { | |
4442 f = true; | |
4443 } | |
4444 assert(f == k->has_finalizer(), "inconsistent has_finalizer"); | |
4445 #endif | |
4446 | |
4447 // Check if this klass supports the java.lang.Cloneable interface | |
1142 | 4448 if (SystemDictionary::Cloneable_klass_loaded()) { |
4449 if (k->is_subtype_of(SystemDictionary::Cloneable_klass())) { | |
0 | 4450 k->set_is_cloneable(); |
4451 } | |
4452 } | |
4453 | |
4454 // Check if this klass has a vanilla default constructor | |
4455 if (super == NULL) { | |
4456 // java.lang.Object has empty default constructor | |
4457 k->set_has_vanilla_constructor(); | |
4458 } else { | |
6983 | 4459 if (super->has_vanilla_constructor() && |
0 | 4460 _has_vanilla_constructor) { |
4461 k->set_has_vanilla_constructor(); | |
4462 } | |
4463 #ifdef ASSERT | |
4464 bool v = false; | |
6983 | 4465 if (super->has_vanilla_constructor()) { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4466 Method* constructor = k->find_method(vmSymbols::object_initializer_name( |
0 | 4467 ), vmSymbols::void_method_signature()); |
4468 if (constructor != NULL && constructor->is_vanilla_constructor()) { | |
4469 v = true; | |
4470 } | |
4471 } | |
4472 assert(v == k->has_vanilla_constructor(), "inconsistent has_vanilla_constructor"); | |
4473 #endif | |
4474 } | |
4475 | |
4476 // If it cannot be fast-path allocated, set a bit in the layout helper. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4477 // See documentation of InstanceKlass::can_be_fastpath_allocated(). |
0 | 4478 assert(k->size_helper() > 0, "layout_helper is initialized"); |
4479 if ((!RegisterFinalizersAtInit && k->has_finalizer()) | |
4480 || k->is_abstract() || k->is_interface() | |
7185
90273fc0a981
8000662: NPG: nashorn ant clean test262 out-of-memory with Java heap
coleenp
parents:
6983
diff
changeset
|
4481 || (k->name() == vmSymbols::java_lang_Class() && k->class_loader() == NULL) |
0 | 4482 || k->size_helper() >= FastAllocateSizeLimit) { |
4483 // Forbid fast-path allocation. | |
4484 jint lh = Klass::instance_layout_helper(k->size_helper(), true); | |
4485 k->set_layout_helper(lh); | |
4486 } | |
4487 } | |
4488 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4489 // Attach super classes and interface classes to class loader data |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4490 void ClassFileParser::record_defined_class_dependencies(instanceKlassHandle defined_klass, TRAPS) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4491 ClassLoaderData * defining_loader_data = defined_klass->class_loader_data(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4492 if (defining_loader_data->is_the_null_class_loader_data()) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4493 // Dependencies to null class loader data are implicit. |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4494 return; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4495 } else { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4496 // add super class dependency |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4497 Klass* super = defined_klass->super(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4498 if (super != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4499 defining_loader_data->record_dependency(super, CHECK); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4500 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4501 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4502 // add super interface dependencies |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4503 Array<Klass*>* local_interfaces = defined_klass->local_interfaces(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4504 if (local_interfaces != NULL) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4505 int length = local_interfaces->length(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4506 for (int i = 0; i < length; i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4507 defining_loader_data->record_dependency(local_interfaces->at(i), CHECK); |
0 | 4508 } |
4509 } | |
4510 } | |
4511 } | |
4512 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4513 // utility method for appending and array with check for duplicates |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4514 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4515 void append_interfaces(GrowableArray<Klass*>* result, Array<Klass*>* ifs) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4516 // iterate over new interfaces |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4517 for (int i = 0; i < ifs->length(); i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4518 Klass* e = ifs->at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4519 assert(e->is_klass() && InstanceKlass::cast(e)->is_interface(), "just checking"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4520 // add new interface |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4521 result->append_if_missing(e); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4522 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4523 } |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4524 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4525 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4526 Array<Klass*>* ClassFileParser::compute_transitive_interfaces(ClassLoaderData* loader_data, instanceKlassHandle super, Array<Klass*>* local_ifs, TRAPS) { |
0 | 4527 // Compute maximum size for transitive interfaces |
4528 int max_transitive_size = 0; | |
4529 int super_size = 0; | |
4530 // Add superclass transitive interfaces size | |
4531 if (super.not_null()) { | |
4532 super_size = super->transitive_interfaces()->length(); | |
4533 max_transitive_size += super_size; | |
4534 } | |
4535 // Add local interfaces' super interfaces | |
4536 int local_size = local_ifs->length(); | |
4537 for (int i = 0; i < local_size; i++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4538 Klass* l = local_ifs->at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4539 max_transitive_size += InstanceKlass::cast(l)->transitive_interfaces()->length(); |
0 | 4540 } |
4541 // Finally add local interfaces | |
4542 max_transitive_size += local_size; | |
4543 // Construct array | |
4544 if (max_transitive_size == 0) { | |
4545 // no interfaces, use canonicalized array | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4546 return Universe::the_empty_klass_array(); |
0 | 4547 } else if (max_transitive_size == super_size) { |
4548 // no new local interfaces added, share superklass' transitive interface array | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4549 return super->transitive_interfaces(); |
0 | 4550 } else if (max_transitive_size == local_size) { |
4551 // only local interfaces added, share local interface array | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4552 return local_ifs; |
0 | 4553 } else { |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4554 ResourceMark rm; |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4555 GrowableArray<Klass*>* result = new GrowableArray<Klass*>(max_transitive_size); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4556 |
0 | 4557 // Copy down from superclass |
4558 if (super.not_null()) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4559 append_interfaces(result, super->transitive_interfaces()); |
0 | 4560 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4561 |
0 | 4562 // Copy down from local interfaces' superinterfaces |
4563 for (int i = 0; i < local_ifs->length(); i++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4564 Klass* l = local_ifs->at(i); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4565 append_interfaces(result, InstanceKlass::cast(l)->transitive_interfaces()); |
0 | 4566 } |
4567 // Finally add local interfaces | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4568 append_interfaces(result, local_ifs); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4569 |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4570 // length will be less than the max_transitive_size if duplicates were removed |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4571 int length = result->length(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4572 assert(length <= max_transitive_size, "just checking"); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4573 Array<Klass*>* new_result = MetadataFactory::new_array<Klass*>(loader_data, length, CHECK_NULL); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4574 for (int i = 0; i < length; i++) { |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4575 Klass* e = result->at(i); |
0 | 4576 assert(e != NULL, "just checking"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4577 new_result->at_put(i, e); |
0 | 4578 } |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4579 return new_result; |
0 | 4580 } |
4581 } | |
4582 | |
4583 | |
4584 void ClassFileParser::check_super_class_access(instanceKlassHandle this_klass, TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4585 Klass* super = this_klass->super(); |
0 | 4586 if ((super != NULL) && |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4587 (!Reflection::verify_class_access(this_klass(), super, false))) { |
0 | 4588 ResourceMark rm(THREAD); |
4589 Exceptions::fthrow( | |
4590 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4591 vmSymbols::java_lang_IllegalAccessError(), |
0 | 4592 "class %s cannot access its superclass %s", |
4593 this_klass->external_name(), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4594 InstanceKlass::cast(super)->external_name() |
0 | 4595 ); |
4596 return; | |
4597 } | |
4598 } | |
4599 | |
4600 | |
4601 void ClassFileParser::check_super_interface_access(instanceKlassHandle this_klass, TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4602 Array<Klass*>* local_interfaces = this_klass->local_interfaces(); |
0 | 4603 int lng = local_interfaces->length(); |
4604 for (int i = lng - 1; i >= 0; i--) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4605 Klass* k = local_interfaces->at(i); |
6983 | 4606 assert (k != NULL && k->is_interface(), "invalid interface"); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4607 if (!Reflection::verify_class_access(this_klass(), k, false)) { |
0 | 4608 ResourceMark rm(THREAD); |
4609 Exceptions::fthrow( | |
4610 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4611 vmSymbols::java_lang_IllegalAccessError(), |
0 | 4612 "class %s cannot access its superinterface %s", |
4613 this_klass->external_name(), | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4614 InstanceKlass::cast(k)->external_name() |
0 | 4615 ); |
4616 return; | |
4617 } | |
4618 } | |
4619 } | |
4620 | |
4621 | |
4622 void ClassFileParser::check_final_method_override(instanceKlassHandle this_klass, TRAPS) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4623 Array<Method*>* methods = this_klass->methods(); |
0 | 4624 int num_methods = methods->length(); |
4625 | |
4626 // go thru each method and check if it overrides a final method | |
4627 for (int index = 0; index < num_methods; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4628 Method* m = methods->at(index); |
0 | 4629 |
4630 // skip private, static and <init> methods | |
4631 if ((!m->is_private()) && | |
4632 (!m->is_static()) && | |
4633 (m->name() != vmSymbols::object_initializer_name())) { | |
4634 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4635 Symbol* name = m->name(); |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4636 Symbol* signature = m->signature(); |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4637 Klass* k = this_klass->super(); |
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4638 Method* super_m = NULL; |
0 | 4639 while (k != NULL) { |
4640 // skip supers that don't have final methods. | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4641 if (k->has_final_method()) { |
0 | 4642 // lookup a matching method in the super class hierarchy |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4643 super_m = InstanceKlass::cast(k)->lookup_method(name, signature); |
0 | 4644 if (super_m == NULL) { |
4645 break; // didn't find any match; get out | |
4646 } | |
4647 | |
4648 if (super_m->is_final() && | |
4649 // matching method in super is final | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4650 (Reflection::verify_field_access(this_klass(), |
0 | 4651 super_m->method_holder(), |
4652 super_m->method_holder(), | |
4653 super_m->access_flags(), false)) | |
4654 // this class can access super final method and therefore override | |
4655 ) { | |
4656 ResourceMark rm(THREAD); | |
4657 Exceptions::fthrow( | |
4658 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4659 vmSymbols::java_lang_VerifyError(), |
0 | 4660 "class %s overrides final method %s.%s", |
4661 this_klass->external_name(), | |
4662 name->as_C_string(), | |
4663 signature->as_C_string() | |
4664 ); | |
4665 return; | |
4666 } | |
4667 | |
4668 // continue to look from super_m's holder's super. | |
6940
18fb7da42534
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
6934
diff
changeset
|
4669 k = super_m->method_holder()->super(); |
0 | 4670 continue; |
4671 } | |
4672 | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4673 k = k->super(); |
0 | 4674 } |
4675 } | |
4676 } | |
4677 } | |
4678 | |
4679 | |
4680 // assumes that this_klass is an interface | |
4681 void ClassFileParser::check_illegal_static_method(instanceKlassHandle this_klass, TRAPS) { | |
4682 assert(this_klass->is_interface(), "not an interface"); | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4683 Array<Method*>* methods = this_klass->methods(); |
0 | 4684 int num_methods = methods->length(); |
4685 | |
4686 for (int index = 0; index < num_methods; index++) { | |
6725
da91efe96a93
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
6266
diff
changeset
|
4687 Method* m = methods->at(index); |
0 | 4688 // if m is static and not the init method, throw a verify error |
4689 if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) { | |
4690 ResourceMark rm(THREAD); | |
4691 Exceptions::fthrow( | |
4692 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4693 vmSymbols::java_lang_VerifyError(), |
0 | 4694 "Illegal static method %s in interface %s", |
4695 m->name()->as_C_string(), | |
4696 this_klass->external_name() | |
4697 ); | |
4698 return; | |
4699 } | |
4700 } | |
4701 } | |
4702 | |
4703 // utility methods for format checking | |
4704 | |
4705 void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) { | |
4706 if (!_need_verify) { return; } | |
4707 | |
4708 const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0; | |
4709 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0; | |
4710 const bool is_final = (flags & JVM_ACC_FINAL) != 0; | |
4711 const bool is_super = (flags & JVM_ACC_SUPER) != 0; | |
4712 const bool is_enum = (flags & JVM_ACC_ENUM) != 0; | |
4713 const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0; | |
4714 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; | |
4715 | |
4716 if ((is_abstract && is_final) || | |
4717 (is_interface && !is_abstract) || | |
4718 (is_interface && major_gte_15 && (is_super || is_enum)) || | |
4719 (!is_interface && major_gte_15 && is_annotation)) { | |
4720 ResourceMark rm(THREAD); | |
4721 Exceptions::fthrow( | |
4722 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4723 vmSymbols::java_lang_ClassFormatError(), |
0 | 4724 "Illegal class modifiers in class %s: 0x%X", |
4725 _class_name->as_C_string(), flags | |
4726 ); | |
4727 return; | |
4728 } | |
4729 } | |
4730 | |
4731 bool ClassFileParser::has_illegal_visibility(jint flags) { | |
4732 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; | |
4733 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; | |
4734 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; | |
4735 | |
4736 return ((is_public && is_protected) || | |
4737 (is_public && is_private) || | |
4738 (is_protected && is_private)); | |
4739 } | |
4740 | |
4741 bool ClassFileParser::is_supported_version(u2 major, u2 minor) { | |
1124
2e8bdfdd3ba2
6899467: System property java.class.version out-of-sync with VM for jdk 5.0 with HS 16 in nightly build
xlu
parents:
977
diff
changeset
|
4742 u2 max_version = |
2e8bdfdd3ba2
6899467: System property java.class.version out-of-sync with VM for jdk 5.0 with HS 16 in nightly build
xlu
parents:
977
diff
changeset
|
4743 JDK_Version::is_gte_jdk17x_version() ? JAVA_MAX_SUPPORTED_VERSION : |
2e8bdfdd3ba2
6899467: System property java.class.version out-of-sync with VM for jdk 5.0 with HS 16 in nightly build
xlu
parents:
977
diff
changeset
|
4744 (JDK_Version::is_gte_jdk16x_version() ? JAVA_6_VERSION : JAVA_1_5_VERSION); |
0 | 4745 return (major >= JAVA_MIN_SUPPORTED_VERSION) && |
176
6b648fefb395
6705523: Fix for 6695506 will violate spec when used in JDK6
kamg
parents:
136
diff
changeset
|
4746 (major <= max_version) && |
6b648fefb395
6705523: Fix for 6695506 will violate spec when used in JDK6
kamg
parents:
136
diff
changeset
|
4747 ((major != max_version) || |
0 | 4748 (minor <= JAVA_MAX_SUPPORTED_MINOR_VERSION)); |
4749 } | |
4750 | |
4751 void ClassFileParser::verify_legal_field_modifiers( | |
4752 jint flags, bool is_interface, TRAPS) { | |
4753 if (!_need_verify) { return; } | |
4754 | |
4755 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; | |
4756 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; | |
4757 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; | |
4758 const bool is_static = (flags & JVM_ACC_STATIC) != 0; | |
4759 const bool is_final = (flags & JVM_ACC_FINAL) != 0; | |
4760 const bool is_volatile = (flags & JVM_ACC_VOLATILE) != 0; | |
4761 const bool is_transient = (flags & JVM_ACC_TRANSIENT) != 0; | |
4762 const bool is_enum = (flags & JVM_ACC_ENUM) != 0; | |
4763 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; | |
4764 | |
4765 bool is_illegal = false; | |
4766 | |
4767 if (is_interface) { | |
4768 if (!is_public || !is_static || !is_final || is_private || | |
4769 is_protected || is_volatile || is_transient || | |
4770 (major_gte_15 && is_enum)) { | |
4771 is_illegal = true; | |
4772 } | |
4773 } else { // not interface | |
4774 if (has_illegal_visibility(flags) || (is_final && is_volatile)) { | |
4775 is_illegal = true; | |
4776 } | |
4777 } | |
4778 | |
4779 if (is_illegal) { | |
4780 ResourceMark rm(THREAD); | |
4781 Exceptions::fthrow( | |
4782 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4783 vmSymbols::java_lang_ClassFormatError(), |
0 | 4784 "Illegal field modifiers in class %s: 0x%X", |
4785 _class_name->as_C_string(), flags); | |
4786 return; | |
4787 } | |
4788 } | |
4789 | |
4790 void ClassFileParser::verify_legal_method_modifiers( | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4791 jint flags, bool is_interface, Symbol* name, TRAPS) { |
0 | 4792 if (!_need_verify) { return; } |
4793 | |
4794 const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; | |
4795 const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; | |
4796 const bool is_static = (flags & JVM_ACC_STATIC) != 0; | |
4797 const bool is_final = (flags & JVM_ACC_FINAL) != 0; | |
4798 const bool is_native = (flags & JVM_ACC_NATIVE) != 0; | |
4799 const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0; | |
4800 const bool is_bridge = (flags & JVM_ACC_BRIDGE) != 0; | |
4801 const bool is_strict = (flags & JVM_ACC_STRICT) != 0; | |
4802 const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0; | |
7579
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4803 const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; |
0 | 4804 const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; |
6934 | 4805 const bool major_gte_8 = _major_version >= JAVA_8_VERSION; |
0 | 4806 const bool is_initializer = (name == vmSymbols::object_initializer_name()); |
4807 | |
4808 bool is_illegal = false; | |
4809 | |
4810 if (is_interface) { | |
7579
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4811 if (major_gte_8) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4812 // Class file version is JAVA_8_VERSION or later Methods of |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4813 // interfaces may set any of the flags except ACC_PROTECTED, |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4814 // ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4815 // have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set. |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4816 if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */ |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4817 (is_native || is_protected || is_final || is_synchronized) || |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4818 // If a specific method of a class or interface has its |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4819 // ACC_ABSTRACT flag set, it must not have any of its |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4820 // ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC, |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4821 // ACC_STRICT, or ACC_SYNCHRONIZED flags set. No need to |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4822 // check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4823 // those flags are illegal irrespective of ACC_ABSTRACT being set or not. |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4824 (is_abstract && (is_private || is_static || is_strict))) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4825 is_illegal = true; |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4826 } |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4827 } else if (major_gte_15) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4828 // Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION) |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4829 if (!is_public || is_static || is_final || is_synchronized || |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4830 is_native || !is_abstract || is_strict) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4831 is_illegal = true; |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4832 } |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4833 } else { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4834 // Class file version is pre-JAVA_1_5_VERSION |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4835 if (!is_public || is_static || is_final || is_native || !is_abstract) { |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4836 is_illegal = true; |
adc176e95bf2
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
7462
diff
changeset
|
4837 } |
0 | 4838 } |
4839 } else { // not interface | |
4840 if (is_initializer) { | |
4841 if (is_static || is_final || is_synchronized || is_native || | |
4842 is_abstract || (major_gte_15 && is_bridge)) { | |
4843 is_illegal = true; | |
4844 } | |
4845 } else { // not initializer | |
4846 if (is_abstract) { | |
4847 if ((is_final || is_native || is_private || is_static || | |
4848 (major_gte_15 && (is_synchronized || is_strict)))) { | |
4849 is_illegal = true; | |
4850 } | |
4851 } | |
4852 if (has_illegal_visibility(flags)) { | |
4853 is_illegal = true; | |
4854 } | |
4855 } | |
4856 } | |
4857 | |
4858 if (is_illegal) { | |
4859 ResourceMark rm(THREAD); | |
4860 Exceptions::fthrow( | |
4861 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4862 vmSymbols::java_lang_ClassFormatError(), |
0 | 4863 "Method %s in class %s has illegal modifiers: 0x%X", |
4864 name->as_C_string(), _class_name->as_C_string(), flags); | |
4865 return; | |
4866 } | |
4867 } | |
4868 | |
4869 void ClassFileParser::verify_legal_utf8(const unsigned char* buffer, int length, TRAPS) { | |
4870 assert(_need_verify, "only called when _need_verify is true"); | |
4871 int i = 0; | |
4872 int count = length >> 2; | |
4873 for (int k=0; k<count; k++) { | |
4874 unsigned char b0 = buffer[i]; | |
4875 unsigned char b1 = buffer[i+1]; | |
4876 unsigned char b2 = buffer[i+2]; | |
4877 unsigned char b3 = buffer[i+3]; | |
4878 // For an unsigned char v, | |
4879 // (v | v - 1) is < 128 (highest bit 0) for 0 < v < 128; | |
4880 // (v | v - 1) is >= 128 (highest bit 1) for v == 0 or v >= 128. | |
4881 unsigned char res = b0 | b0 - 1 | | |
4882 b1 | b1 - 1 | | |
4883 b2 | b2 - 1 | | |
4884 b3 | b3 - 1; | |
4885 if (res >= 128) break; | |
4886 i += 4; | |
4887 } | |
4888 for(; i < length; i++) { | |
4889 unsigned short c; | |
4890 // no embedded zeros | |
4891 guarantee_property((buffer[i] != 0), "Illegal UTF8 string in constant pool in class file %s", CHECK); | |
4892 if(buffer[i] < 128) { | |
4893 continue; | |
4894 } | |
4895 if ((i + 5) < length) { // see if it's legal supplementary character | |
4896 if (UTF8::is_supplementary_character(&buffer[i])) { | |
4897 c = UTF8::get_supplementary_character(&buffer[i]); | |
4898 i += 5; | |
4899 continue; | |
4900 } | |
4901 } | |
4902 switch (buffer[i] >> 4) { | |
4903 default: break; | |
4904 case 0x8: case 0x9: case 0xA: case 0xB: case 0xF: | |
4905 classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK); | |
4906 case 0xC: case 0xD: // 110xxxxx 10xxxxxx | |
4907 c = (buffer[i] & 0x1F) << 6; | |
4908 i++; | |
4909 if ((i < length) && ((buffer[i] & 0xC0) == 0x80)) { | |
4910 c += buffer[i] & 0x3F; | |
4911 if (_major_version <= 47 || c == 0 || c >= 0x80) { | |
4912 // for classes with major > 47, c must a null or a character in its shortest form | |
4913 break; | |
4914 } | |
4915 } | |
4916 classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK); | |
4917 case 0xE: // 1110xxxx 10xxxxxx 10xxxxxx | |
4918 c = (buffer[i] & 0xF) << 12; | |
4919 i += 2; | |
4920 if ((i < length) && ((buffer[i-1] & 0xC0) == 0x80) && ((buffer[i] & 0xC0) == 0x80)) { | |
4921 c += ((buffer[i-1] & 0x3F) << 6) + (buffer[i] & 0x3F); | |
4922 if (_major_version <= 47 || c >= 0x800) { | |
4923 // for classes with major > 47, c must be in its shortest form | |
4924 break; | |
4925 } | |
4926 } | |
4927 classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK); | |
4928 } // end of switch | |
4929 } // end of for | |
4930 } | |
4931 | |
4932 // Checks if name is a legal class name. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4933 void ClassFileParser::verify_legal_class_name(Symbol* name, TRAPS) { |
0 | 4934 if (!_need_verify || _relax_verify) { return; } |
4935 | |
4936 char buf[fixed_buffer_size]; | |
4937 char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); | |
4938 unsigned int length = name->utf8_length(); | |
4939 bool legal = false; | |
4940 | |
4941 if (length > 0) { | |
4942 char* p; | |
4943 if (bytes[0] == JVM_SIGNATURE_ARRAY) { | |
4944 p = skip_over_field_signature(bytes, false, length, CHECK); | |
4945 legal = (p != NULL) && ((p - bytes) == (int)length); | |
4946 } else if (_major_version < JAVA_1_5_VERSION) { | |
4947 if (bytes[0] != '<') { | |
4948 p = skip_over_field_name(bytes, true, length); | |
4949 legal = (p != NULL) && ((p - bytes) == (int)length); | |
4950 } | |
4951 } else { | |
4952 // 4900761: relax the constraints based on JSR202 spec | |
4953 // Class names may be drawn from the entire Unicode character set. | |
4954 // Identifiers between '/' must be unqualified names. | |
4955 // The utf8 string has been verified when parsing cpool entries. | |
4956 legal = verify_unqualified_name(bytes, length, LegalClass); | |
4957 } | |
4958 } | |
4959 if (!legal) { | |
4960 ResourceMark rm(THREAD); | |
4961 Exceptions::fthrow( | |
4962 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4963 vmSymbols::java_lang_ClassFormatError(), |
0 | 4964 "Illegal class name \"%s\" in class file %s", bytes, |
4965 _class_name->as_C_string() | |
4966 ); | |
4967 return; | |
4968 } | |
4969 } | |
4970 | |
4971 // Checks if name is a legal field name. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4972 void ClassFileParser::verify_legal_field_name(Symbol* name, TRAPS) { |
0 | 4973 if (!_need_verify || _relax_verify) { return; } |
4974 | |
4975 char buf[fixed_buffer_size]; | |
4976 char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); | |
4977 unsigned int length = name->utf8_length(); | |
4978 bool legal = false; | |
4979 | |
4980 if (length > 0) { | |
4981 if (_major_version < JAVA_1_5_VERSION) { | |
4982 if (bytes[0] != '<') { | |
4983 char* p = skip_over_field_name(bytes, false, length); | |
4984 legal = (p != NULL) && ((p - bytes) == (int)length); | |
4985 } | |
4986 } else { | |
4987 // 4881221: relax the constraints based on JSR202 spec | |
4988 legal = verify_unqualified_name(bytes, length, LegalField); | |
4989 } | |
4990 } | |
4991 | |
4992 if (!legal) { | |
4993 ResourceMark rm(THREAD); | |
4994 Exceptions::fthrow( | |
4995 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
4996 vmSymbols::java_lang_ClassFormatError(), |
0 | 4997 "Illegal field name \"%s\" in class %s", bytes, |
4998 _class_name->as_C_string() | |
4999 ); | |
5000 return; | |
5001 } | |
5002 } | |
5003 | |
5004 // Checks if name is a legal method name. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5005 void ClassFileParser::verify_legal_method_name(Symbol* name, TRAPS) { |
0 | 5006 if (!_need_verify || _relax_verify) { return; } |
5007 | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5008 assert(name != NULL, "method name is null"); |
0 | 5009 char buf[fixed_buffer_size]; |
5010 char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); | |
5011 unsigned int length = name->utf8_length(); | |
5012 bool legal = false; | |
5013 | |
5014 if (length > 0) { | |
5015 if (bytes[0] == '<') { | |
5016 if (name == vmSymbols::object_initializer_name() || name == vmSymbols::class_initializer_name()) { | |
5017 legal = true; | |
5018 } | |
5019 } else if (_major_version < JAVA_1_5_VERSION) { | |
5020 char* p; | |
5021 p = skip_over_field_name(bytes, false, length); | |
5022 legal = (p != NULL) && ((p - bytes) == (int)length); | |
5023 } else { | |
5024 // 4881221: relax the constraints based on JSR202 spec | |
5025 legal = verify_unqualified_name(bytes, length, LegalMethod); | |
5026 } | |
5027 } | |
5028 | |
5029 if (!legal) { | |
5030 ResourceMark rm(THREAD); | |
5031 Exceptions::fthrow( | |
5032 THREAD_AND_LOCATION, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5033 vmSymbols::java_lang_ClassFormatError(), |
0 | 5034 "Illegal method name \"%s\" in class %s", bytes, |
5035 _class_name->as_C_string() | |
5036 ); | |
5037 return; | |
5038 } | |
5039 } | |
5040 | |
5041 | |
5042 // Checks if signature is a legal field signature. | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5043 void ClassFileParser::verify_legal_field_signature(Symbol* name, Symbol* signature, TRAPS) { |
0 | 5044 if (!_need_verify) { return; } |
5045 | |
5046 char buf[fixed_buffer_size]; | |
5047 char* bytes = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); | |
5048 unsigned int length = signature->utf8_length(); | |
5049 char* p = skip_over_field_signature(bytes, false, length, CHECK); | |
5050 | |
5051 if (p == NULL || (p - bytes) != (int)length) { | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
5052 throwIllegalSignature("Field", name, signature, CHECK); |
0 | 5053 } |
5054 } | |
5055 | |
5056 // Checks if signature is a legal method signature. | |
5057 // Returns number of parameters | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5058 int ClassFileParser::verify_legal_method_signature(Symbol* name, Symbol* signature, TRAPS) { |
0 | 5059 if (!_need_verify) { |
5060 // make sure caller's args_size will be less than 0 even for non-static | |
5061 // method so it will be recomputed in compute_size_of_parameters(). | |
5062 return -2; | |
5063 } | |
5064 | |
5065 unsigned int args_size = 0; | |
5066 char buf[fixed_buffer_size]; | |
5067 char* p = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); | |
5068 unsigned int length = signature->utf8_length(); | |
5069 char* nextp; | |
5070 | |
5071 // The first character must be a '(' | |
5072 if ((length > 0) && (*p++ == JVM_SIGNATURE_FUNC)) { | |
5073 length--; | |
5074 // Skip over legal field signatures | |
5075 nextp = skip_over_field_signature(p, false, length, CHECK_0); | |
5076 while ((length > 0) && (nextp != NULL)) { | |
5077 args_size++; | |
5078 if (p[0] == 'J' || p[0] == 'D') { | |
5079 args_size++; | |
5080 } | |
5081 length -= nextp - p; | |
5082 p = nextp; | |
5083 nextp = skip_over_field_signature(p, false, length, CHECK_0); | |
5084 } | |
5085 // The first non-signature thing better be a ')' | |
5086 if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) { | |
5087 length--; | |
5088 if (name->utf8_length() > 0 && name->byte_at(0) == '<') { | |
5089 // All internal methods must return void | |
5090 if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) { | |
5091 return args_size; | |
5092 } | |
5093 } else { | |
5094 // Now we better just have a return value | |
5095 nextp = skip_over_field_signature(p, true, length, CHECK_0); | |
5096 if (nextp && ((int)length == (nextp - p))) { | |
5097 return args_size; | |
5098 } | |
5099 } | |
5100 } | |
5101 } | |
5102 // Report error | |
1586
086d73ccd6c0
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
1513
diff
changeset
|
5103 throwIllegalSignature("Method", name, signature, CHECK_0); |
0 | 5104 return 0; |
5105 } | |
5106 | |
5107 | |
1881
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5108 // Unqualified names may not contain the characters '.', ';', '[', or '/'. |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5109 // Method names also may not contain the characters '<' or '>', unless <init> |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5110 // or <clinit>. Note that method names may not be <init> or <clinit> in this |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5111 // method. Because these names have been checked as special cases before |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5112 // calling this method in verify_legal_method_name. |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5113 bool ClassFileParser::verify_unqualified_name( |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5114 char* name, unsigned int length, int type) { |
0 | 5115 jchar ch; |
5116 | |
5117 for (char* p = name; p != name + length; ) { | |
5118 ch = *p; | |
5119 if (ch < 128) { | |
5120 p++; | |
1881
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5121 if (ch == '.' || ch == ';' || ch == '[' ) { |
6412b3805cd6
6891959: HotSpot should not throw ClassFormatError if a class has a field with '>' and/or '<' in its name
kamg
parents:
1847
diff
changeset
|
5122 return false; // do not permit '.', ';', or '[' |
0 | 5123 } |
5124 if (type != LegalClass && ch == '/') { | |
5125 return false; // do not permit '/' unless it's class name | |
5126 } | |
5127 if (type == LegalMethod && (ch == '<' || ch == '>')) { | |
5128 return false; // do not permit '<' or '>' in method names | |
5129 } | |
5130 } else { | |
5131 char* tmp_p = UTF8::next(p, &ch); | |
5132 p = tmp_p; | |
5133 } | |
5134 } | |
5135 return true; | |
5136 } | |
5137 | |
5138 | |
5139 // Take pointer to a string. Skip over the longest part of the string that could | |
5140 // be taken as a fieldname. Allow '/' if slash_ok is true. | |
5141 // Return a pointer to just past the fieldname. | |
5142 // Return NULL if no fieldname at all was found, or in the case of slash_ok | |
5143 // being true, we saw consecutive slashes (meaning we were looking for a | |
5144 // qualified path but found something that was badly-formed). | |
5145 char* ClassFileParser::skip_over_field_name(char* name, bool slash_ok, unsigned int length) { | |
5146 char* p; | |
5147 jchar ch; | |
5148 jboolean last_is_slash = false; | |
5149 jboolean not_first_ch = false; | |
5150 | |
5151 for (p = name; p != name + length; not_first_ch = true) { | |
5152 char* old_p = p; | |
5153 ch = *p; | |
5154 if (ch < 128) { | |
5155 p++; | |
5156 // quick check for ascii | |
5157 if ((ch >= 'a' && ch <= 'z') || | |
5158 (ch >= 'A' && ch <= 'Z') || | |
5159 (ch == '_' || ch == '$') || | |
5160 (not_first_ch && ch >= '0' && ch <= '9')) { | |
5161 last_is_slash = false; | |
5162 continue; | |
5163 } | |
5164 if (slash_ok && ch == '/') { | |
5165 if (last_is_slash) { | |
5166 return NULL; // Don't permit consecutive slashes | |
5167 } | |
5168 last_is_slash = true; | |
5169 continue; | |
5170 } | |
5171 } else { | |
5172 jint unicode_ch; | |
5173 char* tmp_p = UTF8::next_character(p, &unicode_ch); | |
5174 p = tmp_p; | |
5175 last_is_slash = false; | |
5176 // Check if ch is Java identifier start or is Java identifier part | |
5177 // 4672820: call java.lang.Character methods directly without generating separate tables. | |
5178 EXCEPTION_MARK; | |
1142 | 5179 instanceKlassHandle klass (THREAD, SystemDictionary::Character_klass()); |
0 | 5180 |
5181 // return value | |
5182 JavaValue result(T_BOOLEAN); | |
5183 // Set up the arguments to isJavaIdentifierStart and isJavaIdentifierPart | |
5184 JavaCallArguments args; | |
5185 args.push_int(unicode_ch); | |
5186 | |
5187 // public static boolean isJavaIdentifierStart(char ch); | |
5188 JavaCalls::call_static(&result, | |
5189 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5190 vmSymbols::isJavaIdentifierStart_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5191 vmSymbols::int_bool_signature(), |
0 | 5192 &args, |
5193 THREAD); | |
5194 | |
5195 if (HAS_PENDING_EXCEPTION) { | |
5196 CLEAR_PENDING_EXCEPTION; | |
5197 return 0; | |
5198 } | |
5199 if (result.get_jboolean()) { | |
5200 continue; | |
5201 } | |
5202 | |
5203 if (not_first_ch) { | |
5204 // public static boolean isJavaIdentifierPart(char ch); | |
5205 JavaCalls::call_static(&result, | |
5206 klass, | |
2177
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5207 vmSymbols::isJavaIdentifierPart_name(), |
3582bf76420e
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
2085
diff
changeset
|
5208 vmSymbols::int_bool_signature(), |
0 | 5209 &args, |
5210 THREAD); | |
5211 | |
5212 if (HAS_PENDING_EXCEPTION) { | |
5213 CLEAR_PENDING_EXCEPTION; | |
5214 return 0; | |
5215 } | |
5216 | |
5217 if (result.get_jboolean()) { | |
5218 continue; | |
5219 } | |
5220 } | |
5221 } | |
5222 return (not_first_ch) ? old_p : NULL; | |
5223 } | |
5224 return (not_first_ch) ? p : NULL; | |
5225 } | |
5226 | |
5227 | |
5228 // Take pointer to a string. Skip over the longest part of the string that could | |
5229 // be taken as a field signature. Allow "void" if void_ok. | |
5230 // Return a pointer to just past the signature. | |
5231 // Return NULL if no legal signature is found. | |
5232 char* ClassFileParser::skip_over_field_signature(char* signature, | |
5233 bool void_ok, | |
5234 unsigned int length, | |
5235 TRAPS) { | |
5236 unsigned int array_dim = 0; | |
5237 while (length > 0) { | |
5238 switch (signature[0]) { | |
5239 case JVM_SIGNATURE_VOID: if (!void_ok) { return NULL; } | |
5240 case JVM_SIGNATURE_BOOLEAN: | |
5241 case JVM_SIGNATURE_BYTE: | |
5242 case JVM_SIGNATURE_CHAR: | |
5243 case JVM_SIGNATURE_SHORT: | |
5244 case JVM_SIGNATURE_INT: | |
5245 case JVM_SIGNATURE_FLOAT: | |
5246 case JVM_SIGNATURE_LONG: | |
5247 case JVM_SIGNATURE_DOUBLE: | |
5248 return signature + 1; | |
5249 case JVM_SIGNATURE_CLASS: { | |
5250 if (_major_version < JAVA_1_5_VERSION) { | |
5251 // Skip over the class name if one is there | |
5252 char* p = skip_over_field_name(signature + 1, true, --length); | |
5253 | |
5254 // The next character better be a semicolon | |
5255 if (p && (p - signature) > 1 && p[0] == ';') { | |
5256 return p + 1; | |
5257 } | |
5258 } else { | |
5259 // 4900761: For class version > 48, any unicode is allowed in class name. | |
5260 length--; | |
5261 signature++; | |
5262 while (length > 0 && signature[0] != ';') { | |
5263 if (signature[0] == '.') { | |
5264 classfile_parse_error("Class name contains illegal character '.' in descriptor in class file %s", CHECK_0); | |
5265 } | |
5266 length--; | |
5267 signature++; | |
5268 } | |
5269 if (signature[0] == ';') { return signature + 1; } | |
5270 } | |
5271 | |
5272 return NULL; | |
5273 } | |
5274 case JVM_SIGNATURE_ARRAY: | |
5275 array_dim++; | |
5276 if (array_dim > 255) { | |
5277 // 4277370: array descriptor is valid only if it represents 255 or fewer dimensions. | |
5278 classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0); | |
5279 } | |
5280 // The rest of what's there better be a legal signature | |
5281 signature++; | |
5282 length--; | |
5283 void_ok = false; | |
5284 break; | |
5285 | |
5286 default: | |
5287 return NULL; | |
5288 } | |
5289 } | |
5290 return NULL; | |
5291 } |