author | dholmes |
Sat, 23 Jun 2018 01:32:41 -0400 | |
changeset 50735 | 2f2af62dfac7 |
parent 50634 | c349d409262a |
child 50761 | cb07f4b539fc |
permissions | -rw-r--r-- |
1 | 1 |
/* |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48826
diff
changeset
|
2 |
* Copyright (c) 1997, 2018, Oracle and/or its affiliates. All rights reserved. |
1 | 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 |
* |
|
5547
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
20 |
* or visit www.oracle.com if you need additional information or have any |
f4b087cbb361
6941466: Oracle rebranding changes for Hotspot repositories
trims
parents:
5426
diff
changeset
|
21 |
* questions. |
1 | 22 |
* |
23 |
*/ |
|
7397 | 24 |
#include "precompiled.hpp" |
47765
b7c7428eaab9
8189610: Reconcile jvm.h and all jvm_md.h between java.base and hotspot
coleenp
parents:
47673
diff
changeset
|
25 |
#include "jvm.h" |
42650 | 26 |
#include "aot/aotLoader.hpp" |
7397 | 27 |
#include "classfile/classFileParser.hpp" |
34666 | 28 |
#include "classfile/classFileStream.hpp" |
7397 | 29 |
#include "classfile/classLoader.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
30 |
#include "classfile/classLoaderData.inline.hpp" |
14385 | 31 |
#include "classfile/defaultMethods.hpp" |
42650 | 32 |
#include "classfile/dictionary.hpp" |
29081
c61eb4914428
8072911: Remove includes of oop.inline.hpp from .hpp files
stefank
parents:
28817
diff
changeset
|
33 |
#include "classfile/javaClasses.inline.hpp" |
36508 | 34 |
#include "classfile/moduleEntry.hpp" |
7397 | 35 |
#include "classfile/symbolTable.hpp" |
36 |
#include "classfile/systemDictionary.hpp" |
|
37 |
#include "classfile/verificationType.hpp" |
|
38 |
#include "classfile/verifier.hpp" |
|
39 |
#include "classfile/vmSymbols.hpp" |
|
35917
463d67f86eaa
8079408: Reimplement TraceClassLoading, TraceClassUnloading, and TraceClassLoaderData with Unified Logging.
mockner
parents:
35911
diff
changeset
|
40 |
#include "logging/log.hpp" |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
41 |
#include "logging/logStream.hpp" |
7397 | 42 |
#include "memory/allocation.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
43 |
#include "memory/metadataFactory.hpp" |
7397 | 44 |
#include "memory/oopFactory.hpp" |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
45 |
#include "memory/resourceArea.hpp" |
49359
59f6547e151f
8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents:
49348
diff
changeset
|
46 |
#include "memory/universe.hpp" |
34666 | 47 |
#include "oops/annotations.hpp" |
49340
4e82736053ae
8191102: Incorrect include file use in classLoader.hpp
hseigel
parents:
48826
diff
changeset
|
48 |
#include "oops/constantPool.inline.hpp" |
10546 | 49 |
#include "oops/fieldStreams.hpp" |
7397 | 50 |
#include "oops/instanceKlass.hpp" |
8725
8c1e3dd5fe1b
7017732: move static fields into Class to prepare for perm gen removal
never
parents:
8676
diff
changeset
|
51 |
#include "oops/instanceMirrorKlass.hpp" |
7397 | 52 |
#include "oops/klass.inline.hpp" |
53 |
#include "oops/klassVtable.hpp" |
|
34666 | 54 |
#include "oops/metadata.hpp" |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
55 |
#include "oops/method.hpp" |
34666 | 56 |
#include "oops/oop.inline.hpp" |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
57 |
#include "oops/symbol.hpp" |
7397 | 58 |
#include "prims/jvmtiExport.hpp" |
11399
5dd5c4dd4b7d
7122253: Instrumentation.retransformClasses() leaks class bytes
dcubed
parents:
10546
diff
changeset
|
59 |
#include "prims/jvmtiThreadState.hpp" |
49716 | 60 |
#include "runtime/arguments.hpp" |
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
61 |
#include "runtime/handles.inline.hpp" |
7397 | 62 |
#include "runtime/javaCalls.hpp" |
63 |
#include "runtime/perfData.hpp" |
|
64 |
#include "runtime/reflection.hpp" |
|
49594
898ef81cbc0e
8200106: Move NoSafepointVerifier out from gcLocker.hpp
stefank
parents:
49593
diff
changeset
|
65 |
#include "runtime/safepointVerifiers.hpp" |
7397 | 66 |
#include "runtime/signature.hpp" |
67 |
#include "runtime/timer.hpp" |
|
68 |
#include "services/classLoadingService.hpp" |
|
69 |
#include "services/threadService.hpp" |
|
46625 | 70 |
#include "utilities/align.hpp" |
46502
116a09d8f142
8180755: Remove use of bitMap.inline.hpp include from instanceKlass.hpp and c1_ValueSet.hpp
tschatzl
parents:
46448
diff
changeset
|
71 |
#include "utilities/bitMap.inline.hpp" |
49593
4dd58ecc9912
8200105: Remove cyclic dependency between oop.inline.hpp and collectedHeap.inline.hpp
stefank
parents:
49480
diff
changeset
|
72 |
#include "utilities/copy.hpp" |
30764 | 73 |
#include "utilities/exceptions.hpp" |
15194
a35093d73168
8006005: Fix constant pool index validation and alignment trap for method parameter reflection
coleenp
parents:
15185
diff
changeset
|
74 |
#include "utilities/globalDefinitions.hpp" |
46448 | 75 |
#include "utilities/growableArray.hpp" |
27683
1d5707553fff
8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents:
27402
diff
changeset
|
76 |
#include "utilities/macros.hpp" |
26135
82b516c550f7
8046070: Class Data Sharing clean up and refactoring
iklam
parents:
25507
diff
changeset
|
77 |
#include "utilities/ostream.hpp" |
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
78 |
#include "utilities/resourceHash.hpp" |
27683
1d5707553fff
8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents:
27402
diff
changeset
|
79 |
#if INCLUDE_CDS |
1d5707553fff
8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents:
27402
diff
changeset
|
80 |
#include "classfile/systemDictionaryShared.hpp" |
1d5707553fff
8064580: Move INCLUDE_CDS include section to the end of the include list
stefank
parents:
27402
diff
changeset
|
81 |
#endif |
50113 | 82 |
#if INCLUDE_JFR |
83 |
#include "jfr/support/jfrTraceIdExtension.hpp" |
|
84 |
#endif |
|
1 | 85 |
|
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
86 |
// We generally try to create the oops directly when parsing, rather than |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
87 |
// allocating temporary data structures and copying the bytes twice. A |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
88 |
// temporary area is only needed when parsing utf8 entries in the constant |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
89 |
// pool and when parsing line number tables. |
1 | 90 |
|
91 |
// We add assert in debug mode when class format is not checked. |
|
92 |
||
93 |
#define JAVA_CLASSFILE_MAGIC 0xCAFEBABE |
|
94 |
#define JAVA_MIN_SUPPORTED_VERSION 45 |
|
49716 | 95 |
#define JAVA_PREVIEW_MINOR_VERSION 65535 |
1 | 96 |
|
97 |
// Used for two backward compatibility reasons: |
|
98 |
// - to check for new additions to the class file format in JDK1.5 |
|
99 |
// - to check for bug fixes in the format checker in JDK1.5 |
|
100 |
#define JAVA_1_5_VERSION 49 |
|
101 |
||
102 |
// Used for backward compatibility reasons: |
|
103 |
// - to check for javac bug fixes that happened after 1.5 |
|
602
92e03692ddd6
6705523: Fix for 6695506 will violate spec when used in JDK6
kamg
parents:
383
diff
changeset
|
104 |
// - also used as the max version when running in jdk6 |
1 | 105 |
#define JAVA_6_VERSION 50 |
106 |
||
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
107 |
// Used for backward compatibility reasons: |
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
108 |
// - to disallow argument and require ACC_STATIC for <clinit> methods |
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
109 |
#define JAVA_7_VERSION 51 |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
110 |
|
14385 | 111 |
// Extension method support. |
112 |
#define JAVA_8_VERSION 52 |
|
113 |
||
35941
be5a3f551026
8148785: Update class file version to 53 for JDK-9
hseigel
parents:
35917
diff
changeset
|
114 |
#define JAVA_9_VERSION 53 |
be5a3f551026
8148785: Update class file version to 53 for JDK-9
hseigel
parents:
35917
diff
changeset
|
115 |
|
48081 | 116 |
#define JAVA_10_VERSION 54 |
117 |
||
48355 | 118 |
#define JAVA_11_VERSION 55 |
119 |
||
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
120 |
void ClassFileParser::set_class_bad_constant_seen(short bad_constant) { |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
121 |
assert((bad_constant == 19 || bad_constant == 20) && _major_version >= JAVA_9_VERSION, |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
122 |
"Unexpected bad constant pool entry"); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
123 |
if (_bad_constant_seen == 0) _bad_constant_seen = bad_constant; |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
124 |
} |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
125 |
|
34666 | 126 |
void ClassFileParser::parse_constant_pool_entries(const ClassFileStream* const stream, |
127 |
ConstantPool* cp, |
|
128 |
const int length, |
|
129 |
TRAPS) { |
|
130 |
assert(stream != NULL, "invariant"); |
|
131 |
assert(cp != NULL, "invariant"); |
|
132 |
||
1 | 133 |
// Use a local copy of ClassFileStream. It helps the C++ compiler to optimize |
134 |
// this function (_current can be allocated in a register, with scalar |
|
135 |
// replacement of aggregates). The _current pointer is copied back to |
|
136 |
// stream() when this function returns. DON'T call another method within |
|
137 |
// this method that uses stream(). |
|
34666 | 138 |
const ClassFileStream cfs1 = *stream; |
139 |
const ClassFileStream* const cfs = &cfs1; |
|
140 |
||
141 |
assert(cfs->allocated_on_stack(), "should be local"); |
|
142 |
debug_only(const u1* const old_current = stream->current();) |
|
1 | 143 |
|
144 |
// Used for batching symbol allocations. |
|
145 |
const char* names[SymbolTable::symbol_alloc_batch_size]; |
|
146 |
int lengths[SymbolTable::symbol_alloc_batch_size]; |
|
147 |
int indices[SymbolTable::symbol_alloc_batch_size]; |
|
148 |
unsigned int hashValues[SymbolTable::symbol_alloc_batch_size]; |
|
149 |
int names_count = 0; |
|
150 |
||
151 |
// parsing Index 0 is unused |
|
152 |
for (int index = 1; index < length; index++) { |
|
153 |
// Each of the following case guarantees one more byte in the stream |
|
154 |
// for the following tag or the access_flags following constant pool, |
|
155 |
// so we don't need bounds-check for reading tag. |
|
34666 | 156 |
const u1 tag = cfs->get_u1_fast(); |
1 | 157 |
switch (tag) { |
34666 | 158 |
case JVM_CONSTANT_Class : { |
159 |
cfs->guarantee_more(3, CHECK); // name_index, tag/access_flags |
|
160 |
const u2 name_index = cfs->get_u2_fast(); |
|
161 |
cp->klass_index_at_put(index, name_index); |
|
1 | 162 |
break; |
34666 | 163 |
} |
164 |
case JVM_CONSTANT_Fieldref: { |
|
165 |
cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags |
|
166 |
const u2 class_index = cfs->get_u2_fast(); |
|
167 |
const u2 name_and_type_index = cfs->get_u2_fast(); |
|
168 |
cp->field_at_put(index, class_index, name_and_type_index); |
|
1 | 169 |
break; |
34666 | 170 |
} |
171 |
case JVM_CONSTANT_Methodref: { |
|
172 |
cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags |
|
173 |
const u2 class_index = cfs->get_u2_fast(); |
|
174 |
const u2 name_and_type_index = cfs->get_u2_fast(); |
|
175 |
cp->method_at_put(index, class_index, name_and_type_index); |
|
1 | 176 |
break; |
34666 | 177 |
} |
178 |
case JVM_CONSTANT_InterfaceMethodref: { |
|
179 |
cfs->guarantee_more(5, CHECK); // class_index, name_and_type_index, tag/access_flags |
|
180 |
const u2 class_index = cfs->get_u2_fast(); |
|
181 |
const u2 name_and_type_index = cfs->get_u2_fast(); |
|
182 |
cp->interface_method_at_put(index, class_index, name_and_type_index); |
|
1 | 183 |
break; |
34666 | 184 |
} |
185 |
case JVM_CONSTANT_String : { |
|
186 |
cfs->guarantee_more(3, CHECK); // string_index, tag/access_flags |
|
187 |
const u2 string_index = cfs->get_u2_fast(); |
|
188 |
cp->string_index_at_put(index, string_index); |
|
1 | 189 |
break; |
34666 | 190 |
} |
5882 | 191 |
case JVM_CONSTANT_MethodHandle : |
34666 | 192 |
case JVM_CONSTANT_MethodType: { |
8675
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
193 |
if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
5882 | 194 |
classfile_parse_error( |
8675
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
195 |
"Class file version does not support constant tag %u in class file %s", |
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
196 |
tag, CHECK); |
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
197 |
} |
5882 | 198 |
if (tag == JVM_CONSTANT_MethodHandle) { |
199 |
cfs->guarantee_more(4, CHECK); // ref_kind, method_index, tag/access_flags |
|
34666 | 200 |
const u1 ref_kind = cfs->get_u1_fast(); |
201 |
const u2 method_index = cfs->get_u2_fast(); |
|
202 |
cp->method_handle_index_at_put(index, ref_kind, method_index); |
|
203 |
} |
|
204 |
else if (tag == JVM_CONSTANT_MethodType) { |
|
5882 | 205 |
cfs->guarantee_more(3, CHECK); // signature_index, tag/access_flags |
34666 | 206 |
const u2 signature_index = cfs->get_u2_fast(); |
207 |
cp->method_type_index_at_put(index, signature_index); |
|
208 |
} |
|
209 |
else { |
|
5882 | 210 |
ShouldNotReachHere(); |
211 |
} |
|
212 |
break; |
|
34666 | 213 |
} |
48826 | 214 |
case JVM_CONSTANT_Dynamic : { |
215 |
if (_major_version < Verifier::DYNAMICCONSTANT_MAJOR_VERSION) { |
|
216 |
classfile_parse_error( |
|
217 |
"Class file version does not support constant tag %u in class file %s", |
|
218 |
tag, CHECK); |
|
219 |
} |
|
220 |
cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags |
|
221 |
const u2 bootstrap_specifier_index = cfs->get_u2_fast(); |
|
222 |
const u2 name_and_type_index = cfs->get_u2_fast(); |
|
223 |
if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) { |
|
224 |
_max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later |
|
225 |
} |
|
226 |
cp->dynamic_constant_at_put(index, bootstrap_specifier_index, name_and_type_index); |
|
227 |
break; |
|
228 |
} |
|
34666 | 229 |
case JVM_CONSTANT_InvokeDynamic : { |
230 |
if (_major_version < Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
|
231 |
classfile_parse_error( |
|
8675
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
232 |
"Class file version does not support constant tag %u in class file %s", |
e9fef2a9bef7
6839872: remove implementation inheritance from JSR 292 APIs
jrose
parents:
8653
diff
changeset
|
233 |
tag, CHECK); |
34666 | 234 |
} |
235 |
cfs->guarantee_more(5, CHECK); // bsm_index, nt, tag/access_flags |
|
236 |
const u2 bootstrap_specifier_index = cfs->get_u2_fast(); |
|
237 |
const u2 name_and_type_index = cfs->get_u2_fast(); |
|
238 |
if (_max_bootstrap_specifier_index < (int) bootstrap_specifier_index) { |
|
239 |
_max_bootstrap_specifier_index = (int) bootstrap_specifier_index; // collect for later |
|
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5888
diff
changeset
|
240 |
} |
34666 | 241 |
cp->invoke_dynamic_at_put(index, bootstrap_specifier_index, name_and_type_index); |
6062
bab93afe9df7
6964498: JSR 292 invokedynamic sites need local bootstrap methods
jrose
parents:
5888
diff
changeset
|
242 |
break; |
34666 | 243 |
} |
244 |
case JVM_CONSTANT_Integer: { |
|
245 |
cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags |
|
246 |
const u4 bytes = cfs->get_u4_fast(); |
|
247 |
cp->int_at_put(index, (jint)bytes); |
|
1 | 248 |
break; |
34666 | 249 |
} |
250 |
case JVM_CONSTANT_Float: { |
|
251 |
cfs->guarantee_more(5, CHECK); // bytes, tag/access_flags |
|
252 |
const u4 bytes = cfs->get_u4_fast(); |
|
253 |
cp->float_at_put(index, *(jfloat*)&bytes); |
|
1 | 254 |
break; |
34666 | 255 |
} |
256 |
case JVM_CONSTANT_Long: { |
|
1 | 257 |
// A mangled type might cause you to overrun allocated memory |
34666 | 258 |
guarantee_property(index + 1 < length, |
1 | 259 |
"Invalid constant pool entry %u in class file %s", |
34666 | 260 |
index, |
261 |
CHECK); |
|
262 |
cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags |
|
263 |
const u8 bytes = cfs->get_u8_fast(); |
|
264 |
cp->long_at_put(index, bytes); |
|
1 | 265 |
index++; // Skip entry following eigth-byte constant, see JVM book p. 98 |
266 |
break; |
|
34666 | 267 |
} |
268 |
case JVM_CONSTANT_Double: { |
|
1 | 269 |
// A mangled type might cause you to overrun allocated memory |
270 |
guarantee_property(index+1 < length, |
|
271 |
"Invalid constant pool entry %u in class file %s", |
|
34666 | 272 |
index, |
273 |
CHECK); |
|
274 |
cfs->guarantee_more(9, CHECK); // bytes, tag/access_flags |
|
275 |
const u8 bytes = cfs->get_u8_fast(); |
|
276 |
cp->double_at_put(index, *(jdouble*)&bytes); |
|
1 | 277 |
index++; // Skip entry following eigth-byte constant, see JVM book p. 98 |
278 |
break; |
|
34666 | 279 |
} |
280 |
case JVM_CONSTANT_NameAndType: { |
|
281 |
cfs->guarantee_more(5, CHECK); // name_index, signature_index, tag/access_flags |
|
282 |
const u2 name_index = cfs->get_u2_fast(); |
|
283 |
const u2 signature_index = cfs->get_u2_fast(); |
|
284 |
cp->name_and_type_at_put(index, name_index, signature_index); |
|
285 |
break; |
|
286 |
} |
|
287 |
case JVM_CONSTANT_Utf8 : { |
|
288 |
cfs->guarantee_more(2, CHECK); // utf8_length |
|
289 |
u2 utf8_length = cfs->get_u2_fast(); |
|
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
290 |
const u1* utf8_buffer = cfs->current(); |
34666 | 291 |
assert(utf8_buffer != NULL, "null utf8 buffer"); |
292 |
// Got utf8 string, guarantee utf8_length+1 bytes, set stream position forward. |
|
293 |
cfs->guarantee_more(utf8_length+1, CHECK); // utf8 string, tag/access_flags |
|
294 |
cfs->skip_u1_fast(utf8_length); |
|
295 |
||
296 |
// Before storing the symbol, make sure it's legal |
|
297 |
if (_need_verify) { |
|
298 |
verify_legal_utf8(utf8_buffer, utf8_length, CHECK); |
|
299 |
} |
|
300 |
||
301 |
if (has_cp_patch_at(index)) { |
|
302 |
Handle patch = clear_cp_patch_at(index); |
|
303 |
guarantee_property(java_lang_String::is_instance(patch()), |
|
304 |
"Illegal utf8 patch at %d in class file %s", |
|
305 |
index, |
|
306 |
CHECK); |
|
307 |
const char* const str = java_lang_String::as_utf8_string(patch()); |
|
308 |
// (could use java_lang_String::as_symbol instead, but might as well batch them) |
|
309 |
utf8_buffer = (const u1*) str; |
|
310 |
utf8_length = (int) strlen(str); |
|
311 |
} |
|
312 |
||
313 |
unsigned int hash; |
|
314 |
Symbol* const result = SymbolTable::lookup_only((const char*)utf8_buffer, |
|
315 |
utf8_length, |
|
316 |
hash); |
|
317 |
if (result == NULL) { |
|
318 |
names[names_count] = (const char*)utf8_buffer; |
|
319 |
lengths[names_count] = utf8_length; |
|
320 |
indices[names_count] = index; |
|
321 |
hashValues[names_count++] = hash; |
|
322 |
if (names_count == SymbolTable::symbol_alloc_batch_size) { |
|
323 |
SymbolTable::new_symbols(_loader_data, |
|
324 |
cp, |
|
325 |
names_count, |
|
326 |
names, |
|
327 |
lengths, |
|
328 |
indices, |
|
329 |
hashValues, |
|
330 |
CHECK); |
|
331 |
names_count = 0; |
|
332 |
} |
|
333 |
} else { |
|
334 |
cp->symbol_at_put(index, result); |
|
1 | 335 |
} |
336 |
break; |
|
34666 | 337 |
} |
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
338 |
case 19: |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
339 |
case 20: { |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
340 |
// Record that an error occurred in these two cases but keep parsing so |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
341 |
// that ACC_Module can be checked for in the access_flags. Need to |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
342 |
// throw NoClassDefFoundError in that case. |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
343 |
if (_major_version >= JAVA_9_VERSION) { |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
344 |
cfs->guarantee_more(3, CHECK); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
345 |
cfs->get_u2_fast(); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
346 |
set_class_bad_constant_seen(tag); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
347 |
break; |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
348 |
} |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
349 |
} |
34666 | 350 |
default: { |
351 |
classfile_parse_error("Unknown constant tag %u in class file %s", |
|
352 |
tag, |
|
353 |
CHECK); |
|
1 | 354 |
break; |
34666 | 355 |
} |
356 |
} // end of switch(tag) |
|
357 |
} // end of for |
|
1 | 358 |
|
359 |
// Allocate the remaining symbols |
|
360 |
if (names_count > 0) { |
|
34666 | 361 |
SymbolTable::new_symbols(_loader_data, |
362 |
cp, |
|
363 |
names_count, |
|
364 |
names, |
|
365 |
lengths, |
|
366 |
indices, |
|
367 |
hashValues, |
|
368 |
CHECK); |
|
1 | 369 |
} |
370 |
||
34666 | 371 |
// Copy _current pointer of local copy back to stream. |
372 |
assert(stream->current() == old_current, "non-exclusive use of stream"); |
|
373 |
stream->set_current(cfs1.current()); |
|
374 |
||
1 | 375 |
} |
376 |
||
34666 | 377 |
static inline bool valid_cp_range(int index, int length) { |
378 |
return (index > 0 && index < length); |
|
379 |
} |
|
380 |
||
381 |
static inline Symbol* check_symbol_at(const ConstantPool* cp, int index) { |
|
382 |
assert(cp != NULL, "invariant"); |
|
383 |
if (valid_cp_range(index, cp->length()) && cp->tag_at(index).is_utf8()) { |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
384 |
return cp->symbol_at(index); |
34666 | 385 |
} |
386 |
return NULL; |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
387 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
388 |
|
33604
ad1cd9269bd4
8139116: Fixes for warning "format not a string literal"
goetz
parents:
33602
diff
changeset
|
389 |
#ifdef ASSERT |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
390 |
PRAGMA_DIAG_PUSH |
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
391 |
PRAGMA_FORMAT_NONLITERAL_IGNORED |
34666 | 392 |
void ClassFileParser::report_assert_property_failure(const char* msg, TRAPS) const { |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
393 |
ResourceMark rm(THREAD); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32824
diff
changeset
|
394 |
fatal(msg, _class_name->as_C_string()); |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
395 |
} |
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
396 |
|
34666 | 397 |
void ClassFileParser::report_assert_property_failure(const char* msg, |
398 |
int index, |
|
399 |
TRAPS) const { |
|
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
400 |
ResourceMark rm(THREAD); |
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32824
diff
changeset
|
401 |
fatal(msg, index, _class_name->as_C_string()); |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
402 |
} |
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
403 |
PRAGMA_DIAG_POP |
33604
ad1cd9269bd4
8139116: Fixes for warning "format not a string literal"
goetz
parents:
33602
diff
changeset
|
404 |
#endif |
29201
fee2bbb2ec1d
8073389: Remove the include of resourceArea.hpp from classFileParser.hpp
stefank
parents:
29081
diff
changeset
|
405 |
|
34666 | 406 |
void ClassFileParser::parse_constant_pool(const ClassFileStream* const stream, |
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
407 |
ConstantPool* const cp, |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
408 |
const int length, |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
409 |
TRAPS) { |
34666 | 410 |
assert(cp != NULL, "invariant"); |
411 |
assert(stream != NULL, "invariant"); |
|
1 | 412 |
|
413 |
// parsing constant pool entries |
|
34666 | 414 |
parse_constant_pool_entries(stream, cp, length, CHECK); |
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
415 |
if (class_bad_constant_seen() != 0) { |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
416 |
// a bad CP entry has been detected previously so stop parsing and just return. |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
417 |
return; |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
418 |
} |
1 | 419 |
|
420 |
int index = 1; // declared outside of loops for portability |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
421 |
int num_klasses = 0; |
1 | 422 |
|
34666 | 423 |
// first verification pass - validate cross references |
424 |
// and fixup class and string constants |
|
1 | 425 |
for (index = 1; index < length; index++) { // Index 0 is unused |
34666 | 426 |
const jbyte tag = cp->tag_at(index).value(); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
427 |
switch (tag) { |
34666 | 428 |
case JVM_CONSTANT_Class: { |
1 | 429 |
ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present |
430 |
break; |
|
34666 | 431 |
} |
432 |
case JVM_CONSTANT_Fieldref: |
|
1 | 433 |
// fall through |
34666 | 434 |
case JVM_CONSTANT_Methodref: |
1 | 435 |
// fall through |
34666 | 436 |
case JVM_CONSTANT_InterfaceMethodref: { |
1 | 437 |
if (!_need_verify) break; |
34666 | 438 |
const int klass_ref_index = cp->klass_ref_index_at(index); |
439 |
const int name_and_type_ref_index = cp->name_and_type_ref_index_at(index); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
440 |
check_property(valid_klass_reference_at(klass_ref_index), |
1 | 441 |
"Invalid constant pool index %u in class file %s", |
34666 | 442 |
klass_ref_index, CHECK); |
1 | 443 |
check_property(valid_cp_range(name_and_type_ref_index, length) && |
34666 | 444 |
cp->tag_at(name_and_type_ref_index).is_name_and_type(), |
445 |
"Invalid constant pool index %u in class file %s", |
|
446 |
name_and_type_ref_index, CHECK); |
|
1 | 447 |
break; |
448 |
} |
|
34666 | 449 |
case JVM_CONSTANT_String: { |
1 | 450 |
ShouldNotReachHere(); // Only JVM_CONSTANT_StringIndex should be present |
451 |
break; |
|
34666 | 452 |
} |
453 |
case JVM_CONSTANT_Integer: |
|
1 | 454 |
break; |
34666 | 455 |
case JVM_CONSTANT_Float: |
1 | 456 |
break; |
34666 | 457 |
case JVM_CONSTANT_Long: |
458 |
case JVM_CONSTANT_Double: { |
|
1 | 459 |
index++; |
460 |
check_property( |
|
461 |
(index < length && cp->tag_at(index).is_invalid()), |
|
462 |
"Improper constant pool long/double index %u in class file %s", |
|
34666 | 463 |
index, CHECK); |
1 | 464 |
break; |
465 |
} |
|
34666 | 466 |
case JVM_CONSTANT_NameAndType: { |
467 |
if (!_need_verify) break; |
|
468 |
const int name_ref_index = cp->name_ref_index_at(index); |
|
469 |
const int signature_ref_index = cp->signature_ref_index_at(index); |
|
470 |
check_property(valid_symbol_at(name_ref_index), |
|
471 |
"Invalid constant pool index %u in class file %s", |
|
472 |
name_ref_index, CHECK); |
|
473 |
check_property(valid_symbol_at(signature_ref_index), |
|
474 |
"Invalid constant pool index %u in class file %s", |
|
475 |
signature_ref_index, CHECK); |
|
1 | 476 |
break; |
34666 | 477 |
} |
478 |
case JVM_CONSTANT_Utf8: |
|
479 |
break; |
|
480 |
case JVM_CONSTANT_UnresolvedClass: // fall-through |
|
481 |
case JVM_CONSTANT_UnresolvedClassInError: { |
|
1 | 482 |
ShouldNotReachHere(); // Only JVM_CONSTANT_ClassIndex should be present |
483 |
break; |
|
34666 | 484 |
} |
485 |
case JVM_CONSTANT_ClassIndex: { |
|
486 |
const int class_index = cp->klass_index_at(index); |
|
487 |
check_property(valid_symbol_at(class_index), |
|
488 |
"Invalid constant pool index %u in class file %s", |
|
489 |
class_index, CHECK); |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
490 |
cp->unresolved_klass_at_put(index, class_index, num_klasses++); |
1 | 491 |
break; |
34666 | 492 |
} |
493 |
case JVM_CONSTANT_StringIndex: { |
|
494 |
const int string_index = cp->string_index_at(index); |
|
495 |
check_property(valid_symbol_at(string_index), |
|
496 |
"Invalid constant pool index %u in class file %s", |
|
497 |
string_index, CHECK); |
|
498 |
Symbol* const sym = cp->symbol_at(string_index); |
|
499 |
cp->unresolved_string_at_put(index, sym); |
|
1 | 500 |
break; |
34666 | 501 |
} |
502 |
case JVM_CONSTANT_MethodHandle: { |
|
503 |
const int ref_index = cp->method_handle_index_at(index); |
|
504 |
check_property(valid_cp_range(ref_index, length), |
|
505 |
"Invalid constant pool index %u in class file %s", |
|
506 |
ref_index, CHECK); |
|
507 |
const constantTag tag = cp->tag_at(ref_index); |
|
508 |
const int ref_kind = cp->method_handle_ref_kind_at(index); |
|
509 |
||
510 |
switch (ref_kind) { |
|
5882 | 511 |
case JVM_REF_getField: |
512 |
case JVM_REF_getStatic: |
|
513 |
case JVM_REF_putField: |
|
34666 | 514 |
case JVM_REF_putStatic: { |
5882 | 515 |
check_property( |
516 |
tag.is_field(), |
|
517 |
"Invalid constant pool index %u in class file %s (not a field)", |
|
34666 | 518 |
ref_index, CHECK); |
5882 | 519 |
break; |
34666 | 520 |
} |
5882 | 521 |
case JVM_REF_invokeVirtual: |
34666 | 522 |
case JVM_REF_newInvokeSpecial: { |
5882 | 523 |
check_property( |
524 |
tag.is_method(), |
|
525 |
"Invalid constant pool index %u in class file %s (not a method)", |
|
34666 | 526 |
ref_index, CHECK); |
5882 | 527 |
break; |
34666 | 528 |
} |
17024
49cbeca23983
8006267: InterfaceMethod_ref should allow invokestatic and invokespecial
bharadwaj
parents:
16692
diff
changeset
|
529 |
case JVM_REF_invokeStatic: |
34666 | 530 |
case JVM_REF_invokeSpecial: { |
531 |
check_property( |
|
532 |
tag.is_method() || |
|
533 |
((_major_version >= JAVA_8_VERSION) && tag.is_interface_method()), |
|
534 |
"Invalid constant pool index %u in class file %s (not a method)", |
|
535 |
ref_index, CHECK); |
|
536 |
break; |
|
537 |
} |
|
538 |
case JVM_REF_invokeInterface: { |
|
5882 | 539 |
check_property( |
540 |
tag.is_interface_method(), |
|
541 |
"Invalid constant pool index %u in class file %s (not an interface method)", |
|
34666 | 542 |
ref_index, CHECK); |
5882 | 543 |
break; |
34666 | 544 |
} |
545 |
default: { |
|
5882 | 546 |
classfile_parse_error( |
547 |
"Bad method handle kind at constant pool index %u in class file %s", |
|
34666 | 548 |
index, CHECK); |
5882 | 549 |
} |
34666 | 550 |
} // switch(refkind) |
551 |
// Keep the ref_index unchanged. It will be indirected at link-time. |
|
5882 | 552 |
break; |
34666 | 553 |
} // case MethodHandle |
554 |
case JVM_CONSTANT_MethodType: { |
|
555 |
const int ref_index = cp->method_type_index_at(index); |
|
556 |
check_property(valid_symbol_at(ref_index), |
|
557 |
"Invalid constant pool index %u in class file %s", |
|
558 |
ref_index, CHECK); |
|
5882 | 559 |
break; |
34666 | 560 |
} |
48826 | 561 |
case JVM_CONSTANT_Dynamic: { |
562 |
const int name_and_type_ref_index = |
|
563 |
cp->invoke_dynamic_name_and_type_ref_index_at(index); |
|
564 |
||
565 |
check_property(valid_cp_range(name_and_type_ref_index, length) && |
|
566 |
cp->tag_at(name_and_type_ref_index).is_name_and_type(), |
|
567 |
"Invalid constant pool index %u in class file %s", |
|
568 |
name_and_type_ref_index, CHECK); |
|
569 |
// bootstrap specifier index must be checked later, |
|
570 |
// when BootstrapMethods attr is available |
|
571 |
||
572 |
// Mark the constant pool as having a CONSTANT_Dynamic_info structure |
|
573 |
cp->set_has_dynamic_constant(); |
|
574 |
break; |
|
575 |
} |
|
34666 | 576 |
case JVM_CONSTANT_InvokeDynamic: { |
577 |
const int name_and_type_ref_index = |
|
578 |
cp->invoke_dynamic_name_and_type_ref_index_at(index); |
|
579 |
||
580 |
check_property(valid_cp_range(name_and_type_ref_index, length) && |
|
581 |
cp->tag_at(name_and_type_ref_index).is_name_and_type(), |
|
582 |
"Invalid constant pool index %u in class file %s", |
|
583 |
name_and_type_ref_index, CHECK); |
|
584 |
// bootstrap specifier index must be checked later, |
|
585 |
// when BootstrapMethods attr is available |
|
586 |
break; |
|
587 |
} |
|
588 |
default: { |
|
33105
294e48b4f704
8080775: Better argument formatting for assert() and friends
david
parents:
32824
diff
changeset
|
589 |
fatal("bad constant pool tag value %u", cp->tag_at(index).value()); |
1 | 590 |
ShouldNotReachHere(); |
591 |
break; |
|
34666 | 592 |
} |
593 |
} // switch(tag) |
|
1 | 594 |
} // end of for |
595 |
||
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
596 |
_first_patched_klass_resolved_index = num_klasses; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
597 |
cp->allocate_resolved_klasses(_loader_data, num_klasses + _max_num_patched_klasses, CHECK); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
598 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
599 |
if (_cp_patches != NULL) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
600 |
// need to treat this_class specially... |
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
601 |
|
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
602 |
// Add dummy utf8 entries in the space reserved for names of patched classes. We'll use "*" |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
603 |
// for now. These will be replaced with actual names of the patched classes in patch_class(). |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
604 |
Symbol* s = vmSymbols::star_name(); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
605 |
for (int n=_orig_cp_size; n<cp->length(); n++) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
606 |
cp->symbol_at_put(n, s); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
607 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
608 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
609 |
int this_class_index; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
610 |
{ |
34666 | 611 |
stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |
612 |
const u1* const mark = stream->current(); |
|
613 |
stream->skip_u2_fast(1); // skip flags |
|
614 |
this_class_index = stream->get_u2_fast(); |
|
615 |
stream->set_current(mark); // revert to mark |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
616 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
617 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
618 |
for (index = 1; index < length; index++) { // Index 0 is unused |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
619 |
if (has_cp_patch_at(index)) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
620 |
guarantee_property(index != this_class_index, |
34666 | 621 |
"Illegal constant pool patch to self at %d in class file %s", |
622 |
index, CHECK); |
|
623 |
patch_constant_pool(cp, index, cp_patch_at(index), CHECK); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
624 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
625 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
626 |
} |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
627 |
|
1 | 628 |
if (!_need_verify) { |
34666 | 629 |
return; |
1 | 630 |
} |
631 |
||
632 |
// second verification pass - checks the strings are of the right format. |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
633 |
// but not yet to the other entries |
1 | 634 |
for (index = 1; index < length; index++) { |
34666 | 635 |
const jbyte tag = cp->tag_at(index).value(); |
1 | 636 |
switch (tag) { |
637 |
case JVM_CONSTANT_UnresolvedClass: { |
|
34666 | 638 |
const Symbol* const class_name = cp->klass_name_at(index); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
639 |
// check the name, even if _cp_patches will overwrite it |
34666 | 640 |
verify_legal_class_name(class_name, CHECK); |
1 | 641 |
break; |
642 |
} |
|
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
643 |
case JVM_CONSTANT_NameAndType: { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
644 |
if (_need_verify) { |
34666 | 645 |
const int sig_index = cp->signature_ref_index_at(index); |
646 |
const int name_index = cp->name_ref_index_at(index); |
|
647 |
const Symbol* const name = cp->symbol_at(name_index); |
|
648 |
const Symbol* const sig = cp->symbol_at(sig_index); |
|
35218
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
649 |
guarantee_property(sig->utf8_length() != 0, |
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
650 |
"Illegal zero length constant pool entry at %d in class %s", |
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
651 |
sig_index, CHECK); |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
652 |
guarantee_property(name->utf8_length() != 0, |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
653 |
"Illegal zero length constant pool entry at %d in class %s", |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
654 |
name_index, CHECK); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
655 |
|
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
656 |
if (sig->byte_at(0) == JVM_SIGNATURE_FUNC) { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
657 |
// Format check method name and signature |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
658 |
verify_legal_method_name(name, CHECK); |
34666 | 659 |
verify_legal_method_signature(name, sig, CHECK); |
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
660 |
} else { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
661 |
// Format check field name and signature |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
662 |
verify_legal_field_name(name, CHECK); |
34666 | 663 |
verify_legal_field_signature(name, sig, CHECK); |
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
664 |
} |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
665 |
} |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
666 |
break; |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
667 |
} |
48826 | 668 |
case JVM_CONSTANT_Dynamic: { |
669 |
const int name_and_type_ref_index = |
|
670 |
cp->name_and_type_ref_index_at(index); |
|
671 |
// already verified to be utf8 |
|
672 |
const int name_ref_index = |
|
673 |
cp->name_ref_index_at(name_and_type_ref_index); |
|
674 |
// already verified to be utf8 |
|
675 |
const int signature_ref_index = |
|
676 |
cp->signature_ref_index_at(name_and_type_ref_index); |
|
677 |
const Symbol* const name = cp->symbol_at(name_ref_index); |
|
678 |
const Symbol* const signature = cp->symbol_at(signature_ref_index); |
|
679 |
if (_need_verify) { |
|
680 |
// CONSTANT_Dynamic's name and signature are verified above, when iterating NameAndType_info. |
|
681 |
// Need only to be sure signature is non-zero length and the right type. |
|
682 |
if (signature->utf8_length() == 0 || |
|
683 |
signature->byte_at(0) == JVM_SIGNATURE_FUNC) { |
|
684 |
throwIllegalSignature("CONSTANT_Dynamic", name, signature, CHECK); |
|
685 |
} |
|
686 |
} |
|
687 |
break; |
|
688 |
} |
|
9117
30d757743e56
7012087: JSR 292 Misleading exception message for a non-bound MH for a virtual method
jrose
parents:
9116
diff
changeset
|
689 |
case JVM_CONSTANT_InvokeDynamic: |
1 | 690 |
case JVM_CONSTANT_Fieldref: |
691 |
case JVM_CONSTANT_Methodref: |
|
692 |
case JVM_CONSTANT_InterfaceMethodref: { |
|
34666 | 693 |
const int name_and_type_ref_index = |
694 |
cp->name_and_type_ref_index_at(index); |
|
1 | 695 |
// already verified to be utf8 |
34666 | 696 |
const int name_ref_index = |
697 |
cp->name_ref_index_at(name_and_type_ref_index); |
|
1 | 698 |
// already verified to be utf8 |
34666 | 699 |
const int signature_ref_index = |
700 |
cp->signature_ref_index_at(name_and_type_ref_index); |
|
701 |
const Symbol* const name = cp->symbol_at(name_ref_index); |
|
702 |
const Symbol* const signature = cp->symbol_at(signature_ref_index); |
|
1 | 703 |
if (tag == JVM_CONSTANT_Fieldref) { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
704 |
if (_need_verify) { |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
705 |
// Field name and signature are verified above, when iterating NameAndType_info. |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
706 |
// Need only to be sure signature is non-zero length and the right type. |
35218
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
707 |
if (signature->utf8_length() == 0 || |
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
708 |
signature->byte_at(0) == JVM_SIGNATURE_FUNC) { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
709 |
throwIllegalSignature("Field", name, signature, CHECK); |
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
710 |
} |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
711 |
} |
1 | 712 |
} else { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
713 |
if (_need_verify) { |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
714 |
// Method name and signature are verified above, when iterating NameAndType_info. |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
715 |
// Need only to be sure signature is non-zero length and the right type. |
35218
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
716 |
if (signature->utf8_length() == 0 || |
00aa934a1a20
8042660: vm/mlvm/anonloader/stress/byteMutation failed with: assert(index >=0 && index < _length) failed: symbol index overflow
hseigel
parents:
35071
diff
changeset
|
717 |
signature->byte_at(0) != JVM_SIGNATURE_FUNC) { |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
718 |
throwIllegalSignature("Method", name, signature, CHECK); |
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
719 |
} |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
720 |
} |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
721 |
// 4509014: If a class method name begins with '<', it must be "<init>" |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
722 |
const unsigned int name_len = name->utf8_length(); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
723 |
if (tag == JVM_CONSTANT_Methodref && |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
724 |
name_len != 0 && |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
725 |
name->byte_at(0) == '<' && |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
726 |
name != vmSymbols::object_initializer_name()) { |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
727 |
classfile_parse_error( |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
728 |
"Bad method name at constant pool index %u in class file %s", |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
729 |
name_ref_index, CHECK); |
1 | 730 |
} |
731 |
} |
|
732 |
break; |
|
733 |
} |
|
5882 | 734 |
case JVM_CONSTANT_MethodHandle: { |
34666 | 735 |
const int ref_index = cp->method_handle_index_at(index); |
736 |
const int ref_kind = cp->method_handle_ref_kind_at(index); |
|
5882 | 737 |
switch (ref_kind) { |
34666 | 738 |
case JVM_REF_invokeVirtual: |
739 |
case JVM_REF_invokeStatic: |
|
740 |
case JVM_REF_invokeSpecial: |
|
741 |
case JVM_REF_newInvokeSpecial: { |
|
742 |
const int name_and_type_ref_index = |
|
743 |
cp->name_and_type_ref_index_at(ref_index); |
|
744 |
const int name_ref_index = |
|
745 |
cp->name_ref_index_at(name_and_type_ref_index); |
|
746 |
const Symbol* const name = cp->symbol_at(name_ref_index); |
|
5882 | 747 |
if (ref_kind == JVM_REF_newInvokeSpecial) { |
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
748 |
if (name != vmSymbols::object_initializer_name()) { |
5882 | 749 |
classfile_parse_error( |
750 |
"Bad constructor name at constant pool index %u in class file %s", |
|
34666 | 751 |
name_ref_index, CHECK); |
5882 | 752 |
} |
753 |
} else { |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
754 |
if (name == vmSymbols::object_initializer_name()) { |
5882 | 755 |
classfile_parse_error( |
756 |
"Bad method name at constant pool index %u in class file %s", |
|
34666 | 757 |
name_ref_index, CHECK); |
5882 | 758 |
} |
759 |
} |
|
34666 | 760 |
break; |
5882 | 761 |
} |
762 |
// Other ref_kinds are already fully checked in previous pass. |
|
34666 | 763 |
} // switch(ref_kind) |
5882 | 764 |
break; |
765 |
} |
|
766 |
case JVM_CONSTANT_MethodType: { |
|
34666 | 767 |
const Symbol* const no_name = vmSymbols::type_name(); // place holder |
768 |
const Symbol* const signature = cp->method_type_signature_at(index); |
|
769 |
verify_legal_method_signature(no_name, signature, CHECK); |
|
5882 | 770 |
break; |
771 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
772 |
case JVM_CONSTANT_Utf8: { |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
773 |
assert(cp->symbol_at(index)->refcount() != 0, "count corrupted"); |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
774 |
} |
34666 | 775 |
} // switch(tag) |
1 | 776 |
} // end of for |
777 |
} |
|
778 |
||
49480
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
779 |
Handle ClassFileParser::clear_cp_patch_at(int index) { |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
780 |
Handle patch = cp_patch_at(index); |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
781 |
_cp_patches->at_put(index, Handle()); |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
782 |
assert(!has_cp_patch_at(index), ""); |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
783 |
return patch; |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
784 |
} |
d7df2dd501ce
8199809: Don't include frame.inline.hpp and other.inline.hpp from .hpp files
coleenp
parents:
49364
diff
changeset
|
785 |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
786 |
void ClassFileParser::patch_class(ConstantPool* cp, int class_index, Klass* k, Symbol* name) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
787 |
int name_index = _orig_cp_size + _num_patched_klasses; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
788 |
int resolved_klass_index = _first_patched_klass_resolved_index + _num_patched_klasses; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
789 |
|
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
790 |
cp->klass_at_put(class_index, name_index, resolved_klass_index, k, name); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
791 |
_num_patched_klasses ++; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
792 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
793 |
|
34666 | 794 |
void ClassFileParser::patch_constant_pool(ConstantPool* cp, |
795 |
int index, |
|
796 |
Handle patch, |
|
797 |
TRAPS) { |
|
798 |
assert(cp != NULL, "invariant"); |
|
799 |
||
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
800 |
BasicType patch_type = T_VOID; |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
801 |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
802 |
switch (cp->tag_at(index).value()) { |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
803 |
|
34666 | 804 |
case JVM_CONSTANT_UnresolvedClass: { |
805 |
// Patching a class means pre-resolving it. |
|
806 |
// The name in the constant pool is ignored. |
|
807 |
if (java_lang_Class::is_instance(patch())) { |
|
808 |
guarantee_property(!java_lang_Class::is_primitive(patch()), |
|
809 |
"Illegal class patch at %d in class file %s", |
|
810 |
index, CHECK); |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
811 |
Klass* k = java_lang_Class::as_Klass(patch()); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
812 |
patch_class(cp, index, k, k->name()); |
34666 | 813 |
} else { |
814 |
guarantee_property(java_lang_String::is_instance(patch()), |
|
815 |
"Illegal class patch at %d in class file %s", |
|
816 |
index, CHECK); |
|
817 |
Symbol* const name = java_lang_String::as_symbol(patch(), CHECK); |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
818 |
patch_class(cp, index, NULL, name); |
34666 | 819 |
} |
820 |
break; |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
821 |
} |
34666 | 822 |
|
823 |
case JVM_CONSTANT_String: { |
|
824 |
// skip this patch and don't clear it. Needs the oop array for resolved |
|
825 |
// references to be created first. |
|
826 |
return; |
|
827 |
} |
|
828 |
case JVM_CONSTANT_Integer: patch_type = T_INT; goto patch_prim; |
|
829 |
case JVM_CONSTANT_Float: patch_type = T_FLOAT; goto patch_prim; |
|
830 |
case JVM_CONSTANT_Long: patch_type = T_LONG; goto patch_prim; |
|
831 |
case JVM_CONSTANT_Double: patch_type = T_DOUBLE; goto patch_prim; |
|
832 |
patch_prim: |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
833 |
{ |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
834 |
jvalue value; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
835 |
BasicType value_type = java_lang_boxing_object::get_value(patch(), &value); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
836 |
guarantee_property(value_type == patch_type, |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
837 |
"Illegal primitive patch at %d in class file %s", |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
838 |
index, CHECK); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
839 |
switch (value_type) { |
34666 | 840 |
case T_INT: cp->int_at_put(index, value.i); break; |
841 |
case T_FLOAT: cp->float_at_put(index, value.f); break; |
|
842 |
case T_LONG: cp->long_at_put(index, value.j); break; |
|
843 |
case T_DOUBLE: cp->double_at_put(index, value.d); break; |
|
844 |
default: assert(false, ""); |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
845 |
} |
34666 | 846 |
} // end patch_prim label |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
847 |
break; |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
848 |
|
34666 | 849 |
default: { |
850 |
// %%% TODO: put method handles into CONSTANT_InterfaceMethodref, etc. |
|
851 |
guarantee_property(!has_cp_patch_at(index), |
|
852 |
"Illegal unexpected patch at %d in class file %s", |
|
853 |
index, CHECK); |
|
854 |
return; |
|
855 |
} |
|
856 |
} // end of switch(tag) |
|
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
857 |
|
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
858 |
// On fall-through, mark the patch as used. |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
859 |
clear_cp_patch_at(index); |
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
860 |
} |
1 | 861 |
class NameSigHash: public ResourceObj { |
862 |
public: |
|
34666 | 863 |
const Symbol* _name; // name |
864 |
const Symbol* _sig; // signature |
|
865 |
NameSigHash* _next; // Next entry in hash table |
|
1 | 866 |
}; |
867 |
||
34666 | 868 |
static const int HASH_ROW_SIZE = 256; |
869 |
||
870 |
static unsigned int hash(const Symbol* name, const Symbol* sig) { |
|
1 | 871 |
unsigned int raw_hash = 0; |
872 |
raw_hash += ((unsigned int)(uintptr_t)name) >> (LogHeapWordSize + 2); |
|
873 |
raw_hash += ((unsigned int)(uintptr_t)sig) >> LogHeapWordSize; |
|
874 |
||
875 |
return (raw_hash + (unsigned int)(uintptr_t)name) % HASH_ROW_SIZE; |
|
876 |
} |
|
877 |
||
878 |
||
34666 | 879 |
static void initialize_hashtable(NameSigHash** table) { |
1 | 880 |
memset((void*)table, 0, sizeof(NameSigHash*) * HASH_ROW_SIZE); |
881 |
} |
|
882 |
// Return false if the name/sig combination is found in table. |
|
883 |
// Return true if no duplicate is found. And name/sig is added as a new entry in table. |
|
884 |
// The old format checker uses heap sort to find duplicates. |
|
885 |
// NOTE: caller should guarantee that GC doesn't happen during the life cycle |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
886 |
// of table since we don't expect Symbol*'s to move. |
34666 | 887 |
static bool put_after_lookup(const Symbol* name, const Symbol* sig, NameSigHash** table) { |
1 | 888 |
assert(name != NULL, "name in constant pool is NULL"); |
889 |
||
890 |
// First lookup for duplicates |
|
891 |
int index = hash(name, sig); |
|
892 |
NameSigHash* entry = table[index]; |
|
893 |
while (entry != NULL) { |
|
894 |
if (entry->_name == name && entry->_sig == sig) { |
|
895 |
return false; |
|
896 |
} |
|
897 |
entry = entry->_next; |
|
898 |
} |
|
899 |
||
900 |
// No duplicate is found, allocate a new entry and fill it. |
|
901 |
entry = new NameSigHash(); |
|
902 |
entry->_name = name; |
|
903 |
entry->_sig = sig; |
|
904 |
||
905 |
// Insert into hash table |
|
906 |
entry->_next = table[index]; |
|
907 |
table[index] = entry; |
|
908 |
||
909 |
return true; |
|
910 |
} |
|
911 |
||
34666 | 912 |
// Side-effects: populates the _local_interfaces field |
913 |
void ClassFileParser::parse_interfaces(const ClassFileStream* const stream, |
|
914 |
const int itfs_len, |
|
915 |
ConstantPool* const cp, |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
916 |
bool* const has_nonstatic_concrete_methods, |
34666 | 917 |
TRAPS) { |
918 |
assert(stream != NULL, "invariant"); |
|
919 |
assert(cp != NULL, "invariant"); |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
920 |
assert(has_nonstatic_concrete_methods != NULL, "invariant"); |
34666 | 921 |
|
922 |
if (itfs_len == 0) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
923 |
_local_interfaces = Universe::the_empty_klass_array(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
924 |
} else { |
34666 | 925 |
assert(itfs_len > 0, "only called for len>0"); |
926 |
_local_interfaces = MetadataFactory::new_array<Klass*>(_loader_data, itfs_len, NULL, CHECK); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
927 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
928 |
int index; |
34666 | 929 |
for (index = 0; index < itfs_len; index++) { |
930 |
const u2 interface_index = stream->get_u2(CHECK); |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
931 |
Klass* interf; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
932 |
check_property( |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
933 |
valid_klass_reference_at(interface_index), |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
934 |
"Interface name has bad constant pool index %u in class file %s", |
34666 | 935 |
interface_index, CHECK); |
936 |
if (cp->tag_at(interface_index).is_klass()) { |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
937 |
interf = cp->resolved_klass_at(interface_index); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
938 |
} else { |
34666 | 939 |
Symbol* const unresolved_klass = cp->klass_name_at(interface_index); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
940 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
941 |
// Don't need to check legal name because it's checked when parsing constant pool. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
942 |
// But need to make sure it's not an array type. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
943 |
guarantee_property(unresolved_klass->byte_at(0) != JVM_SIGNATURE_ARRAY, |
34666 | 944 |
"Bad interface name in class file %s", CHECK); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
945 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
946 |
// Call resolve_super so classcircularity is checked |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
947 |
interf = SystemDictionary::resolve_super_or_fail( |
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
948 |
_class_name, |
34666 | 949 |
unresolved_klass, |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
950 |
Handle(THREAD, _loader_data->class_loader()), |
34666 | 951 |
_protection_domain, |
952 |
false, |
|
953 |
CHECK); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
954 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
955 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
956 |
if (!interf->is_interface()) { |
34666 | 957 |
THROW_MSG(vmSymbols::java_lang_IncompatibleClassChangeError(), |
50633
b8055b38b252
8204268: Improve some IncompatibleClassChangeError messages.
goetz
parents:
50113
diff
changeset
|
958 |
err_msg("Class %s can not implement %s, because it is not an interface", |
b8055b38b252
8204268: Improve some IncompatibleClassChangeError messages.
goetz
parents:
50113
diff
changeset
|
959 |
_class_name->as_klass_external_name(), |
b8055b38b252
8204268: Improve some IncompatibleClassChangeError messages.
goetz
parents:
50113
diff
changeset
|
960 |
interf->class_loader_and_module_name())); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
961 |
} |
34666 | 962 |
|
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
963 |
if (InstanceKlass::cast(interf)->has_nonstatic_concrete_methods()) { |
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
964 |
*has_nonstatic_concrete_methods = true; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
965 |
} |
46329
53ccc37bda19
8155672: Remove instanceKlassHandles and KlassHandles
coleenp
parents:
46327
diff
changeset
|
966 |
_local_interfaces->at_put(index, interf); |
1550
be2fc37a817f
6653858: dynamic languages need to be able to load anonymous classes
jrose
parents:
670
diff
changeset
|
967 |
} |
1 | 968 |
|
34666 | 969 |
if (!_need_verify || itfs_len <= 1) { |
970 |
return; |
|
14385 | 971 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
972 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
973 |
// Check if there's any duplicates in interfaces |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
974 |
ResourceMark rm(THREAD); |
34666 | 975 |
NameSigHash** interface_names = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, |
976 |
NameSigHash*, |
|
977 |
HASH_ROW_SIZE); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
978 |
initialize_hashtable(interface_names); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
979 |
bool dup = false; |
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
980 |
const Symbol* name = NULL; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
981 |
{ |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35220
diff
changeset
|
982 |
debug_only(NoSafepointVerifier nsv;) |
34666 | 983 |
for (index = 0; index < itfs_len; index++) { |
984 |
const Klass* const k = _local_interfaces->at(index); |
|
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
985 |
name = InstanceKlass::cast(k)->name(); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
986 |
// If no duplicates, add (name, NULL) in hashtable interface_names. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
987 |
if (!put_after_lookup(name, NULL, interface_names)) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
988 |
dup = true; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
989 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
990 |
} |
1 | 991 |
} |
992 |
} |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
993 |
if (dup) { |
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
994 |
classfile_parse_error("Duplicate interface name \"%s\" in class file %s", |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
995 |
name->as_C_string(), CHECK); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
996 |
} |
1 | 997 |
} |
998 |
} |
|
999 |
||
34666 | 1000 |
void ClassFileParser::verify_constantvalue(const ConstantPool* const cp, |
1001 |
int constantvalue_index, |
|
1002 |
int signature_index, |
|
1003 |
TRAPS) const { |
|
1 | 1004 |
// Make sure the constant pool entry is of a type appropriate to this field |
1005 |
guarantee_property( |
|
1006 |
(constantvalue_index > 0 && |
|
34666 | 1007 |
constantvalue_index < cp->length()), |
1 | 1008 |
"Bad initial value index %u in ConstantValue attribute in class file %s", |
1009 |
constantvalue_index, CHECK); |
|
34666 | 1010 |
|
1011 |
const constantTag value_type = cp->tag_at(constantvalue_index); |
|
1012 |
switch(cp->basic_type_for_signature_at(signature_index)) { |
|
1013 |
case T_LONG: { |
|
1014 |
guarantee_property(value_type.is_long(), |
|
1015 |
"Inconsistent constant value type in class file %s", |
|
1016 |
CHECK); |
|
1017 |
break; |
|
1018 |
} |
|
1019 |
case T_FLOAT: { |
|
1020 |
guarantee_property(value_type.is_float(), |
|
1021 |
"Inconsistent constant value type in class file %s", |
|
1022 |
CHECK); |
|
1 | 1023 |
break; |
34666 | 1024 |
} |
1025 |
case T_DOUBLE: { |
|
1026 |
guarantee_property(value_type.is_double(), |
|
1027 |
"Inconsistent constant value type in class file %s", |
|
1028 |
CHECK); |
|
1029 |
break; |
|
1030 |
} |
|
1031 |
case T_BYTE: |
|
1032 |
case T_CHAR: |
|
1033 |
case T_SHORT: |
|
1034 |
case T_BOOLEAN: |
|
1035 |
case T_INT: { |
|
1036 |
guarantee_property(value_type.is_int(), |
|
1037 |
"Inconsistent constant value type in class file %s", |
|
1038 |
CHECK); |
|
1039 |
break; |
|
1040 |
} |
|
1041 |
case T_OBJECT: { |
|
1042 |
guarantee_property((cp->symbol_at(signature_index)->equals("Ljava/lang/String;") |
|
1043 |
&& value_type.is_string()), |
|
1044 |
"Bad string initial value in class file %s", |
|
1045 |
CHECK); |
|
1 | 1046 |
break; |
34666 | 1047 |
} |
1048 |
default: { |
|
1049 |
classfile_parse_error("Unable to set initial value %u in class file %s", |
|
1050 |
constantvalue_index, |
|
1051 |
CHECK); |
|
1052 |
} |
|
1053 |
} |
|
1054 |
} |
|
1055 |
||
1056 |
class AnnotationCollector : public ResourceObj{ |
|
1057 |
public: |
|
1058 |
enum Location { _in_field, _in_method, _in_class }; |
|
1059 |
enum ID { |
|
1060 |
_unknown = 0, |
|
1061 |
_method_CallerSensitive, |
|
1062 |
_method_ForceInline, |
|
1063 |
_method_DontInline, |
|
1064 |
_method_InjectedProfile, |
|
1065 |
_method_LambdaForm_Compiled, |
|
1066 |
_method_LambdaForm_Hidden, |
|
1067 |
_method_HotSpotIntrinsicCandidate, |
|
1068 |
_jdk_internal_vm_annotation_Contended, |
|
1069 |
_field_Stable, |
|
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
1070 |
_jdk_internal_vm_annotation_ReservedStackAccess, |
34666 | 1071 |
_annotation_LIMIT |
1072 |
}; |
|
1073 |
const Location _location; |
|
1074 |
int _annotations_present; |
|
1075 |
u2 _contended_group; |
|
1076 |
||
1077 |
AnnotationCollector(Location location) |
|
1078 |
: _location(location), _annotations_present(0) |
|
1079 |
{ |
|
1080 |
assert((int)_annotation_LIMIT <= (int)sizeof(_annotations_present) * BitsPerByte, ""); |
|
1081 |
} |
|
1082 |
// If this annotation name has an ID, report it (or _none). |
|
1083 |
ID annotation_index(const ClassLoaderData* loader_data, const Symbol* name); |
|
1084 |
// Set the annotation name: |
|
1085 |
void set_annotation(ID id) { |
|
1086 |
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); |
|
1087 |
_annotations_present |= nth_bit((int)id); |
|
1088 |
} |
|
1089 |
||
1090 |
void remove_annotation(ID id) { |
|
1091 |
assert((int)id >= 0 && (int)id < (int)_annotation_LIMIT, "oob"); |
|
1092 |
_annotations_present &= ~nth_bit((int)id); |
|
1093 |
} |
|
1094 |
||
1095 |
// Report if the annotation is present. |
|
1096 |
bool has_any_annotations() const { return _annotations_present != 0; } |
|
1097 |
bool has_annotation(ID id) const { return (nth_bit((int)id) & _annotations_present) != 0; } |
|
1098 |
||
1099 |
void set_contended_group(u2 group) { _contended_group = group; } |
|
1100 |
u2 contended_group() const { return _contended_group; } |
|
1101 |
||
1102 |
bool is_contended() const { return has_annotation(_jdk_internal_vm_annotation_Contended); } |
|
1103 |
||
1104 |
void set_stable(bool stable) { set_annotation(_field_Stable); } |
|
1105 |
bool is_stable() const { return has_annotation(_field_Stable); } |
|
1106 |
}; |
|
1107 |
||
1108 |
// This class also doubles as a holder for metadata cleanup. |
|
1109 |
class ClassFileParser::FieldAnnotationCollector : public AnnotationCollector { |
|
1110 |
private: |
|
1111 |
ClassLoaderData* _loader_data; |
|
1112 |
AnnotationArray* _field_annotations; |
|
1113 |
AnnotationArray* _field_type_annotations; |
|
1114 |
public: |
|
1115 |
FieldAnnotationCollector(ClassLoaderData* loader_data) : |
|
1116 |
AnnotationCollector(_in_field), |
|
1117 |
_loader_data(loader_data), |
|
1118 |
_field_annotations(NULL), |
|
1119 |
_field_type_annotations(NULL) {} |
|
1120 |
~FieldAnnotationCollector(); |
|
1121 |
void apply_to(FieldInfo* f); |
|
1122 |
AnnotationArray* field_annotations() { return _field_annotations; } |
|
1123 |
AnnotationArray* field_type_annotations() { return _field_type_annotations; } |
|
1124 |
||
1125 |
void set_field_annotations(AnnotationArray* a) { _field_annotations = a; } |
|
1126 |
void set_field_type_annotations(AnnotationArray* a) { _field_type_annotations = a; } |
|
1127 |
}; |
|
1128 |
||
1129 |
class MethodAnnotationCollector : public AnnotationCollector{ |
|
1130 |
public: |
|
1131 |
MethodAnnotationCollector() : AnnotationCollector(_in_method) { } |
|
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46701
diff
changeset
|
1132 |
void apply_to(const methodHandle& m); |
34666 | 1133 |
}; |
1134 |
||
1135 |
class ClassFileParser::ClassAnnotationCollector : public AnnotationCollector{ |
|
1136 |
public: |
|
1137 |
ClassAnnotationCollector() : AnnotationCollector(_in_class) { } |
|
1138 |
void apply_to(InstanceKlass* ik); |
|
1139 |
}; |
|
1140 |
||
1141 |
||
1142 |
static int skip_annotation_value(const u1*, int, int); // fwd decl |
|
1143 |
||
43177 | 1144 |
// Safely increment index by val if does not pass limit |
1145 |
#define SAFE_ADD(index, limit, val) \ |
|
1146 |
if (index >= limit - val) return limit; \ |
|
1147 |
index += val; |
|
1148 |
||
34666 | 1149 |
// Skip an annotation. Return >=limit if there is any problem. |
1150 |
static int skip_annotation(const u1* buffer, int limit, int index) { |
|
1151 |
assert(buffer != NULL, "invariant"); |
|
1152 |
// annotation := atype:u2 do(nmem:u2) {member:u2 value} |
|
1153 |
// value := switch (tag:u1) { ... } |
|
43177 | 1154 |
SAFE_ADD(index, limit, 4); // skip atype and read nmem |
34666 | 1155 |
int nmem = Bytes::get_Java_u2((address)buffer + index - 2); |
1156 |
while (--nmem >= 0 && index < limit) { |
|
43177 | 1157 |
SAFE_ADD(index, limit, 2); // skip member |
34666 | 1158 |
index = skip_annotation_value(buffer, limit, index); |
1159 |
} |
|
1160 |
return index; |
|
1161 |
} |
|
1162 |
||
1163 |
// Skip an annotation value. Return >=limit if there is any problem. |
|
1164 |
static int skip_annotation_value(const u1* buffer, int limit, int index) { |
|
1165 |
assert(buffer != NULL, "invariant"); |
|
1166 |
||
1167 |
// value := switch (tag:u1) { |
|
1168 |
// case B, C, I, S, Z, D, F, J, c: con:u2; |
|
1169 |
// case e: e_class:u2 e_name:u2; |
|
1170 |
// case s: s_con:u2; |
|
1171 |
// case [: do(nval:u2) {value}; |
|
1172 |
// case @: annotation; |
|
1173 |
// case s: s_con:u2; |
|
1174 |
// } |
|
43177 | 1175 |
SAFE_ADD(index, limit, 1); // read tag |
34666 | 1176 |
const u1 tag = buffer[index - 1]; |
1177 |
switch (tag) { |
|
1178 |
case 'B': |
|
1179 |
case 'C': |
|
1180 |
case 'I': |
|
1181 |
case 'S': |
|
1182 |
case 'Z': |
|
1183 |
case 'D': |
|
1184 |
case 'F': |
|
1185 |
case 'J': |
|
1186 |
case 'c': |
|
1187 |
case 's': |
|
43177 | 1188 |
SAFE_ADD(index, limit, 2); // skip con or s_con |
1 | 1189 |
break; |
34666 | 1190 |
case 'e': |
43177 | 1191 |
SAFE_ADD(index, limit, 4); // skip e_class, e_name |
1 | 1192 |
break; |
34666 | 1193 |
case '[': |
1194 |
{ |
|
43177 | 1195 |
SAFE_ADD(index, limit, 2); // read nval |
34666 | 1196 |
int nval = Bytes::get_Java_u2((address)buffer + index - 2); |
1197 |
while (--nval >= 0 && index < limit) { |
|
1198 |
index = skip_annotation_value(buffer, limit, index); |
|
1199 |
} |
|
1200 |
} |
|
1201 |
break; |
|
1202 |
case '@': |
|
1203 |
index = skip_annotation(buffer, limit, index); |
|
1 | 1204 |
break; |
1205 |
default: |
|
34666 | 1206 |
return limit; // bad tag byte |
1207 |
} |
|
1208 |
return index; |
|
1209 |
} |
|
1210 |
||
1211 |
// Sift through annotations, looking for those significant to the VM: |
|
1212 |
static void parse_annotations(const ConstantPool* const cp, |
|
1213 |
const u1* buffer, int limit, |
|
1214 |
AnnotationCollector* coll, |
|
1215 |
ClassLoaderData* loader_data, |
|
1216 |
TRAPS) { |
|
1217 |
||
1218 |
assert(cp != NULL, "invariant"); |
|
1219 |
assert(buffer != NULL, "invariant"); |
|
1220 |
assert(coll != NULL, "invariant"); |
|
1221 |
assert(loader_data != NULL, "invariant"); |
|
1222 |
||
1223 |
// annotations := do(nann:u2) {annotation} |
|
43177 | 1224 |
int index = 2; // read nann |
1225 |
if (index >= limit) return; |
|
34666 | 1226 |
int nann = Bytes::get_Java_u2((address)buffer + index - 2); |
1227 |
enum { // initial annotation layout |
|
1228 |
atype_off = 0, // utf8 such as 'Ljava/lang/annotation/Retention;' |
|
1229 |
count_off = 2, // u2 such as 1 (one value) |
|
1230 |
member_off = 4, // utf8 such as 'value' |
|
1231 |
tag_off = 6, // u1 such as 'c' (type) or 'e' (enum) |
|
1232 |
e_tag_val = 'e', |
|
1233 |
e_type_off = 7, // utf8 such as 'Ljava/lang/annotation/RetentionPolicy;' |
|
1234 |
e_con_off = 9, // utf8 payload, such as 'SOURCE', 'CLASS', 'RUNTIME' |
|
1235 |
e_size = 11, // end of 'e' annotation |
|
1236 |
c_tag_val = 'c', // payload is type |
|
1237 |
c_con_off = 7, // utf8 payload, such as 'I' |
|
1238 |
c_size = 9, // end of 'c' annotation |
|
1239 |
s_tag_val = 's', // payload is String |
|
1240 |
s_con_off = 7, // utf8 payload, such as 'Ljava/lang/String;' |
|
1241 |
s_size = 9, |
|
1242 |
min_size = 6 // smallest possible size (zero members) |
|
1243 |
}; |
|
43177 | 1244 |
// Cannot add min_size to index in case of overflow MAX_INT |
1245 |
while ((--nann) >= 0 && (index - 2 <= limit - min_size)) { |
|
34666 | 1246 |
int index0 = index; |
1247 |
index = skip_annotation(buffer, limit, index); |
|
1248 |
const u1* const abase = buffer + index0; |
|
1249 |
const int atype = Bytes::get_Java_u2((address)abase + atype_off); |
|
1250 |
const int count = Bytes::get_Java_u2((address)abase + count_off); |
|
1251 |
const Symbol* const aname = check_symbol_at(cp, atype); |
|
1252 |
if (aname == NULL) break; // invalid annotation name |
|
1253 |
const Symbol* member = NULL; |
|
1254 |
if (count >= 1) { |
|
1255 |
const int member_index = Bytes::get_Java_u2((address)abase + member_off); |
|
1256 |
member = check_symbol_at(cp, member_index); |
|
1257 |
if (member == NULL) break; // invalid member name |
|
1258 |
} |
|
1259 |
||
1260 |
// Here is where parsing particular annotations will take place. |
|
1261 |
AnnotationCollector::ID id = coll->annotation_index(loader_data, aname); |
|
1262 |
if (AnnotationCollector::_unknown == id) continue; |
|
1263 |
coll->set_annotation(id); |
|
1264 |
||
1265 |
if (AnnotationCollector::_jdk_internal_vm_annotation_Contended == id) { |
|
1266 |
// @Contended can optionally specify the contention group. |
|
1267 |
// |
|
1268 |
// Contended group defines the equivalence class over the fields: |
|
1269 |
// the fields within the same contended group are not treated distinct. |
|
1270 |
// The only exception is default group, which does not incur the |
|
1271 |
// equivalence. Naturally, contention group for classes is meaningless. |
|
1272 |
// |
|
1273 |
// While the contention group is specified as String, annotation |
|
1274 |
// values are already interned, and we might as well use the constant |
|
1275 |
// pool index as the group tag. |
|
1276 |
// |
|
1277 |
u2 group_index = 0; // default contended group |
|
1278 |
if (count == 1 |
|
1279 |
&& s_size == (index - index0) // match size |
|
1280 |
&& s_tag_val == *(abase + tag_off) |
|
1281 |
&& member == vmSymbols::value_name()) { |
|
1282 |
group_index = Bytes::get_Java_u2((address)abase + s_con_off); |
|
1283 |
if (cp->symbol_at(group_index)->utf8_length() == 0) { |
|
1284 |
group_index = 0; // default contended group |
|
1285 |
} |
|
1286 |
} |
|
1287 |
coll->set_contended_group(group_index); |
|
1288 |
} |
|
1 | 1289 |
} |
1290 |
} |
|
1291 |
||
1292 |
||
1293 |
// Parse attributes for a field. |
|
34666 | 1294 |
void ClassFileParser::parse_field_attributes(const ClassFileStream* const cfs, |
1295 |
u2 attributes_count, |
|
1 | 1296 |
bool is_static, u2 signature_index, |
34666 | 1297 |
u2* const constantvalue_index_addr, |
1298 |
bool* const is_synthetic_addr, |
|
1299 |
u2* const generic_signature_index_addr, |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
1300 |
ClassFileParser::FieldAnnotationCollector* parsed_annotations, |
1 | 1301 |
TRAPS) { |
34666 | 1302 |
assert(cfs != NULL, "invariant"); |
1303 |
assert(constantvalue_index_addr != NULL, "invariant"); |
|
1304 |
assert(is_synthetic_addr != NULL, "invariant"); |
|
1305 |
assert(generic_signature_index_addr != NULL, "invariant"); |
|
1306 |
assert(parsed_annotations != NULL, "invariant"); |
|
1307 |
assert(attributes_count > 0, "attributes_count should be greater than 0"); |
|
1308 |
||
1 | 1309 |
u2 constantvalue_index = 0; |
1310 |
u2 generic_signature_index = 0; |
|
1311 |
bool is_synthetic = false; |
|
34666 | 1312 |
const u1* runtime_visible_annotations = NULL; |
1 | 1313 |
int runtime_visible_annotations_length = 0; |
34666 | 1314 |
const u1* runtime_invisible_annotations = NULL; |
1 | 1315 |
int runtime_invisible_annotations_length = 0; |
34666 | 1316 |
const u1* runtime_visible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1317 |
int runtime_visible_type_annotations_length = 0; |
34666 | 1318 |
const u1* runtime_invisible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1319 |
int runtime_invisible_type_annotations_length = 0; |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1320 |
bool runtime_invisible_annotations_exists = false; |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1321 |
bool runtime_invisible_type_annotations_exists = false; |
34666 | 1322 |
const ConstantPool* const cp = _cp; |
1323 |
||
1 | 1324 |
while (attributes_count--) { |
1325 |
cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length |
|
34666 | 1326 |
const u2 attribute_name_index = cfs->get_u2_fast(); |
1327 |
const u4 attribute_length = cfs->get_u4_fast(); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1328 |
check_property(valid_symbol_at(attribute_name_index), |
1 | 1329 |
"Invalid field attribute index %u in class file %s", |
1330 |
attribute_name_index, |
|
1331 |
CHECK); |
|
34666 | 1332 |
|
1333 |
const Symbol* const attribute_name = cp->symbol_at(attribute_name_index); |
|
1 | 1334 |
if (is_static && attribute_name == vmSymbols::tag_constant_value()) { |
1335 |
// ignore if non-static |
|
1336 |
if (constantvalue_index != 0) { |
|
1337 |
classfile_parse_error("Duplicate ConstantValue attribute in class file %s", CHECK); |
|
1338 |
} |
|
1339 |
check_property( |
|
1340 |
attribute_length == 2, |
|
1341 |
"Invalid ConstantValue field attribute length %u in class file %s", |
|
1342 |
attribute_length, CHECK); |
|
34666 | 1343 |
|
1 | 1344 |
constantvalue_index = cfs->get_u2(CHECK); |
1345 |
if (_need_verify) { |
|
34666 | 1346 |
verify_constantvalue(cp, constantvalue_index, signature_index, CHECK); |
1 | 1347 |
} |
1348 |
} else if (attribute_name == vmSymbols::tag_synthetic()) { |
|
1349 |
if (attribute_length != 0) { |
|
1350 |
classfile_parse_error( |
|
1351 |
"Invalid Synthetic field attribute length %u in class file %s", |
|
1352 |
attribute_length, CHECK); |
|
1353 |
} |
|
1354 |
is_synthetic = true; |
|
1355 |
} else if (attribute_name == vmSymbols::tag_deprecated()) { // 4276120 |
|
1356 |
if (attribute_length != 0) { |
|
1357 |
classfile_parse_error( |
|
1358 |
"Invalid Deprecated field attribute length %u in class file %s", |
|
1359 |
attribute_length, CHECK); |
|
1360 |
} |
|
1361 |
} else if (_major_version >= JAVA_1_5_VERSION) { |
|
1362 |
if (attribute_name == vmSymbols::tag_signature()) { |
|
44243
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
1363 |
if (generic_signature_index != 0) { |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
1364 |
classfile_parse_error( |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
1365 |
"Multiple Signature attributes for field in class file %s", CHECK); |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
1366 |
} |
1 | 1367 |
if (attribute_length != 2) { |
1368 |
classfile_parse_error( |
|
1369 |
"Wrong size %u for field's Signature attribute in class file %s", |
|
1370 |
attribute_length, CHECK); |
|
1371 |
} |
|
34666 | 1372 |
generic_signature_index = parse_generic_signature_attribute(cfs, CHECK); |
1 | 1373 |
} else if (attribute_name == vmSymbols::tag_runtime_visible_annotations()) { |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1374 |
if (runtime_visible_annotations != NULL) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1375 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1376 |
"Multiple RuntimeVisibleAnnotations attributes for field in class file %s", CHECK); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1377 |
} |
1 | 1378 |
runtime_visible_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
1379 |
runtime_visible_annotations = cfs->current(); |
1 | 1380 |
assert(runtime_visible_annotations != NULL, "null visible annotations"); |
43177 | 1381 |
cfs->guarantee_more(runtime_visible_annotations_length, CHECK); |
34666 | 1382 |
parse_annotations(cp, |
1383 |
runtime_visible_annotations, |
|
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1384 |
runtime_visible_annotations_length, |
34666 | 1385 |
parsed_annotations, |
1386 |
_loader_data, |
|
1387 |
CHECK); |
|
43177 | 1388 |
cfs->skip_u1_fast(runtime_visible_annotations_length); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1389 |
} else if (attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1390 |
if (runtime_invisible_annotations_exists) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1391 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1392 |
"Multiple RuntimeInvisibleAnnotations attributes for field in class file %s", CHECK); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1393 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1394 |
runtime_invisible_annotations_exists = true; |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1395 |
if (PreserveAllAnnotations) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1396 |
runtime_invisible_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
1397 |
runtime_invisible_annotations = cfs->current(); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1398 |
assert(runtime_invisible_annotations != NULL, "null invisible annotations"); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1399 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
1400 |
cfs->skip_u1(attribute_length, CHECK); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1401 |
} else if (attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1402 |
if (runtime_visible_type_annotations != NULL) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1403 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1404 |
"Multiple RuntimeVisibleTypeAnnotations attributes for field in class file %s", CHECK); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1405 |
} |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1406 |
runtime_visible_type_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
1407 |
runtime_visible_type_annotations = cfs->current(); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1408 |
assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1409 |
cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1410 |
} else if (attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1411 |
if (runtime_invisible_type_annotations_exists) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1412 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1413 |
"Multiple RuntimeInvisibleTypeAnnotations attributes for field in class file %s", CHECK); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1414 |
} else { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1415 |
runtime_invisible_type_annotations_exists = true; |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1416 |
} |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1417 |
if (PreserveAllAnnotations) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1418 |
runtime_invisible_type_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
1419 |
runtime_invisible_type_annotations = cfs->current(); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1420 |
assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1421 |
} |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
1422 |
cfs->skip_u1(attribute_length, CHECK); |
1 | 1423 |
} else { |
1424 |
cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes |
|
1425 |
} |
|
1426 |
} else { |
|
1427 |
cfs->skip_u1(attribute_length, CHECK); // Skip unknown attributes |
|
1428 |
} |
|
1429 |
} |
|
1430 |
||
1431 |
*constantvalue_index_addr = constantvalue_index; |
|
1432 |
*is_synthetic_addr = is_synthetic; |
|
1433 |
*generic_signature_index_addr = generic_signature_index; |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1434 |
AnnotationArray* a = assemble_annotations(runtime_visible_annotations, |
1 | 1435 |
runtime_visible_annotations_length, |
1436 |
runtime_invisible_annotations, |
|
1437 |
runtime_invisible_annotations_length, |
|
1438 |
CHECK); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1439 |
parsed_annotations->set_field_annotations(a); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1440 |
a = assemble_annotations(runtime_visible_type_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1441 |
runtime_visible_type_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1442 |
runtime_invisible_type_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1443 |
runtime_invisible_type_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1444 |
CHECK); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1445 |
parsed_annotations->set_field_type_annotations(a); |
1 | 1446 |
return; |
1447 |
} |
|
1448 |
||
1449 |
||
1450 |
// Field allocation types. Used for computing field offsets. |
|
1451 |
||
1452 |
enum FieldAllocationType { |
|
1453 |
STATIC_OOP, // Oops |
|
1454 |
STATIC_BYTE, // Boolean, Byte, char |
|
1455 |
STATIC_SHORT, // shorts |
|
1456 |
STATIC_WORD, // ints |
|
10546 | 1457 |
STATIC_DOUBLE, // aligned long or double |
1 | 1458 |
NONSTATIC_OOP, |
1459 |
NONSTATIC_BYTE, |
|
1460 |
NONSTATIC_SHORT, |
|
1461 |
NONSTATIC_WORD, |
|
1462 |
NONSTATIC_DOUBLE, |
|
10546 | 1463 |
MAX_FIELD_ALLOCATION_TYPE, |
1464 |
BAD_ALLOCATION_TYPE = -1 |
|
1 | 1465 |
}; |
1466 |
||
10546 | 1467 |
static FieldAllocationType _basic_type_to_atype[2 * (T_CONFLICT + 1)] = { |
1468 |
BAD_ALLOCATION_TYPE, // 0 |
|
1469 |
BAD_ALLOCATION_TYPE, // 1 |
|
1470 |
BAD_ALLOCATION_TYPE, // 2 |
|
1471 |
BAD_ALLOCATION_TYPE, // 3 |
|
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1472 |
NONSTATIC_BYTE , // T_BOOLEAN = 4, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1473 |
NONSTATIC_SHORT, // T_CHAR = 5, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1474 |
NONSTATIC_WORD, // T_FLOAT = 6, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1475 |
NONSTATIC_DOUBLE, // T_DOUBLE = 7, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1476 |
NONSTATIC_BYTE, // T_BYTE = 8, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1477 |
NONSTATIC_SHORT, // T_SHORT = 9, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1478 |
NONSTATIC_WORD, // T_INT = 10, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1479 |
NONSTATIC_DOUBLE, // T_LONG = 11, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1480 |
NONSTATIC_OOP, // T_OBJECT = 12, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1481 |
NONSTATIC_OOP, // T_ARRAY = 13, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1482 |
BAD_ALLOCATION_TYPE, // T_VOID = 14, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1483 |
BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1484 |
BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1485 |
BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1486 |
BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1487 |
BAD_ALLOCATION_TYPE, // T_CONFLICT = 19, |
10546 | 1488 |
BAD_ALLOCATION_TYPE, // 0 |
1489 |
BAD_ALLOCATION_TYPE, // 1 |
|
1490 |
BAD_ALLOCATION_TYPE, // 2 |
|
1491 |
BAD_ALLOCATION_TYPE, // 3 |
|
13969
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1492 |
STATIC_BYTE , // T_BOOLEAN = 4, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1493 |
STATIC_SHORT, // T_CHAR = 5, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1494 |
STATIC_WORD, // T_FLOAT = 6, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1495 |
STATIC_DOUBLE, // T_DOUBLE = 7, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1496 |
STATIC_BYTE, // T_BYTE = 8, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1497 |
STATIC_SHORT, // T_SHORT = 9, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1498 |
STATIC_WORD, // T_INT = 10, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1499 |
STATIC_DOUBLE, // T_LONG = 11, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1500 |
STATIC_OOP, // T_OBJECT = 12, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1501 |
STATIC_OOP, // T_ARRAY = 13, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1502 |
BAD_ALLOCATION_TYPE, // T_VOID = 14, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1503 |
BAD_ALLOCATION_TYPE, // T_ADDRESS = 15, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1504 |
BAD_ALLOCATION_TYPE, // T_NARROWOOP = 16, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1505 |
BAD_ALLOCATION_TYPE, // T_METADATA = 17, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1506 |
BAD_ALLOCATION_TYPE, // T_NARROWKLASS = 18, |
d2a189b83b87
7054512: Compress class pointers after perm gen removal
roland
parents:
13738
diff
changeset
|
1507 |
BAD_ALLOCATION_TYPE, // T_CONFLICT = 19, |
1 | 1508 |
}; |
1509 |
||
10546 | 1510 |
static FieldAllocationType basic_type_to_atype(bool is_static, BasicType type) { |
1511 |
assert(type >= T_BOOLEAN && type < T_VOID, "only allowable values"); |
|
1512 |
FieldAllocationType result = _basic_type_to_atype[type + (is_static ? (T_CONFLICT + 1) : 0)]; |
|
1513 |
assert(result != BAD_ALLOCATION_TYPE, "bad type"); |
|
1514 |
return result; |
|
1515 |
} |
|
1516 |
||
34666 | 1517 |
class ClassFileParser::FieldAllocationCount : public ResourceObj { |
10546 | 1518 |
public: |
11412
62fe312f32c5
7123315: instanceKlass::_static_oop_field_count and instanceKlass::_java_fields_count should be u2 type.
jiangli
parents:
10546
diff
changeset
|
1519 |
u2 count[MAX_FIELD_ALLOCATION_TYPE]; |
10546 | 1520 |
|
1521 |
FieldAllocationCount() { |
|
1522 |
for (int i = 0; i < MAX_FIELD_ALLOCATION_TYPE; i++) { |
|
1523 |
count[i] = 0; |
|
1524 |
} |
|
1525 |
} |
|
1526 |
||
1527 |
FieldAllocationType update(bool is_static, BasicType type) { |
|
1528 |
FieldAllocationType atype = basic_type_to_atype(is_static, type); |
|
38658
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
1529 |
if (atype != BAD_ALLOCATION_TYPE) { |
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
1530 |
// Make sure there is no overflow with injected fields. |
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
1531 |
assert(count[atype] < 0xFFFF, "More than 65535 fields"); |
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
1532 |
count[atype]++; |
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
1533 |
} |
10546 | 1534 |
return atype; |
1535 |
} |
|
1536 |
}; |
|
1537 |
||
34666 | 1538 |
// Side-effects: populates the _fields, _fields_annotations, |
1539 |
// _fields_type_annotations fields |
|
1540 |
void ClassFileParser::parse_fields(const ClassFileStream* const cfs, |
|
1541 |
bool is_interface, |
|
1542 |
FieldAllocationCount* const fac, |
|
1543 |
ConstantPool* cp, |
|
1544 |
const int cp_size, |
|
1545 |
u2* const java_fields_count_ptr, |
|
1546 |
TRAPS) { |
|
1547 |
||
1548 |
assert(cfs != NULL, "invariant"); |
|
1549 |
assert(fac != NULL, "invariant"); |
|
1550 |
assert(cp != NULL, "invariant"); |
|
1551 |
assert(java_fields_count_ptr != NULL, "invariant"); |
|
1552 |
||
1553 |
assert(NULL == _fields, "invariant"); |
|
1554 |
assert(NULL == _fields_annotations, "invariant"); |
|
1555 |
assert(NULL == _fields_type_annotations, "invariant"); |
|
1556 |
||
1557 |
cfs->guarantee_more(2, CHECK); // length |
|
1558 |
const u2 length = cfs->get_u2_fast(); |
|
10546 | 1559 |
*java_fields_count_ptr = length; |
1560 |
||
1561 |
int num_injected = 0; |
|
34666 | 1562 |
const InjectedField* const injected = JavaClasses::get_injected(_class_name, |
1563 |
&num_injected); |
|
1564 |
const int total_fields = length + num_injected; |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1565 |
|
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1566 |
// The field array starts with tuples of shorts |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1567 |
// [access, name index, sig index, initial value index, byte offset]. |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1568 |
// A generic signature slot only exists for field with generic |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1569 |
// signature attribute. And the access flag is set with |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1570 |
// JVM_ACC_FIELD_HAS_GENERIC_SIGNATURE for that field. The generic |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1571 |
// signature slots are at the end of the field array and after all |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1572 |
// other fields data. |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1573 |
// |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1574 |
// f1: [access, name index, sig index, initial value index, low_offset, high_offset] |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1575 |
// f2: [access, name index, sig index, initial value index, low_offset, high_offset] |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1576 |
// ... |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1577 |
// fn: [access, name index, sig index, initial value index, low_offset, high_offset] |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1578 |
// [generic signature index] |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1579 |
// [generic signature index] |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1580 |
// ... |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1581 |
// |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1582 |
// Allocate a temporary resource array for field data. For each field, |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1583 |
// a slot is reserved in the temporary array for the generic signature |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1584 |
// index. After parsing all fields, the data are copied to a permanent |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1585 |
// array and any unused slots will be discarded. |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1586 |
ResourceMark rm(THREAD); |
34666 | 1587 |
u2* const fa = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, |
1588 |
u2, |
|
1589 |
total_fields * (FieldInfo::field_slots + 1)); |
|
1 | 1590 |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1591 |
// The generic signature slots start after all other fields' data. |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1592 |
int generic_signature_slot = total_fields * FieldInfo::field_slots; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1593 |
int num_generic_signature = 0; |
1 | 1594 |
for (int n = 0; n < length; n++) { |
34666 | 1595 |
// access_flags, name_index, descriptor_index, attributes_count |
1596 |
cfs->guarantee_more(8, CHECK); |
|
1 | 1597 |
|
1598 |
AccessFlags access_flags; |
|
34666 | 1599 |
const jint flags = cfs->get_u2_fast() & JVM_RECOGNIZED_FIELD_MODIFIERS; |
1600 |
verify_legal_field_modifiers(flags, is_interface, CHECK); |
|
1 | 1601 |
access_flags.set_flags(flags); |
1602 |
||
34666 | 1603 |
const u2 name_index = cfs->get_u2_fast(); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1604 |
check_property(valid_symbol_at(name_index), |
1 | 1605 |
"Invalid constant pool index %u for field name in class file %s", |
34666 | 1606 |
name_index, CHECK); |
1607 |
const Symbol* const name = cp->symbol_at(name_index); |
|
1608 |
verify_legal_field_name(name, CHECK); |
|
1609 |
||
1610 |
const u2 signature_index = cfs->get_u2_fast(); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1611 |
check_property(valid_symbol_at(signature_index), |
1 | 1612 |
"Invalid constant pool index %u for field signature in class file %s", |
34666 | 1613 |
signature_index, CHECK); |
1614 |
const Symbol* const sig = cp->symbol_at(signature_index); |
|
1615 |
verify_legal_field_signature(name, sig, CHECK); |
|
1 | 1616 |
|
1617 |
u2 constantvalue_index = 0; |
|
1618 |
bool is_synthetic = false; |
|
1619 |
u2 generic_signature_index = 0; |
|
34666 | 1620 |
const bool is_static = access_flags.is_static(); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1621 |
FieldAnnotationCollector parsed_annotations(_loader_data); |
1 | 1622 |
|
34666 | 1623 |
const u2 attributes_count = cfs->get_u2_fast(); |
1 | 1624 |
if (attributes_count > 0) { |
34666 | 1625 |
parse_field_attributes(cfs, |
1626 |
attributes_count, |
|
1627 |
is_static, |
|
1628 |
signature_index, |
|
1629 |
&constantvalue_index, |
|
1630 |
&is_synthetic, |
|
1631 |
&generic_signature_index, |
|
1632 |
&parsed_annotations, |
|
1633 |
CHECK); |
|
1634 |
||
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1635 |
if (parsed_annotations.field_annotations() != NULL) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1636 |
if (_fields_annotations == NULL) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1637 |
_fields_annotations = MetadataFactory::new_array<AnnotationArray*>( |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1638 |
_loader_data, length, NULL, |
34666 | 1639 |
CHECK); |
1 | 1640 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1641 |
_fields_annotations->at_put(n, parsed_annotations.field_annotations()); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1642 |
parsed_annotations.set_field_annotations(NULL); |
1 | 1643 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1644 |
if (parsed_annotations.field_type_annotations() != NULL) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1645 |
if (_fields_type_annotations == NULL) { |
34666 | 1646 |
_fields_type_annotations = |
1647 |
MetadataFactory::new_array<AnnotationArray*>(_loader_data, |
|
1648 |
length, |
|
1649 |
NULL, |
|
1650 |
CHECK); |
|
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1651 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1652 |
_fields_type_annotations->at_put(n, parsed_annotations.field_type_annotations()); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1653 |
parsed_annotations.set_field_type_annotations(NULL); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
1654 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1655 |
|
1 | 1656 |
if (is_synthetic) { |
1657 |
access_flags.set_is_synthetic(); |
|
1658 |
} |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1659 |
if (generic_signature_index != 0) { |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1660 |
access_flags.set_field_has_generic_signature(); |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1661 |
fa[generic_signature_slot] = generic_signature_index; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1662 |
generic_signature_slot ++; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1663 |
num_generic_signature ++; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1664 |
} |
1 | 1665 |
} |
1666 |
||
34666 | 1667 |
FieldInfo* const field = FieldInfo::from_field_array(fa, n); |
10546 | 1668 |
field->initialize(access_flags.as_short(), |
1669 |
name_index, |
|
1670 |
signature_index, |
|
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1671 |
constantvalue_index); |
34666 | 1672 |
const BasicType type = cp->basic_type_for_signature_at(signature_index); |
1 | 1673 |
|
1674 |
// Remember how many oops we encountered and compute allocation type |
|
34666 | 1675 |
const FieldAllocationType atype = fac->update(is_static, type); |
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1676 |
field->set_allocation_type(atype); |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1677 |
|
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1678 |
// After field is initialized with type, we can augment it with aux info |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1679 |
if (parsed_annotations.has_any_annotations()) |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1680 |
parsed_annotations.apply_to(field); |
10546 | 1681 |
} |
1682 |
||
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1683 |
int index = length; |
10546 | 1684 |
if (num_injected != 0) { |
1685 |
for (int n = 0; n < num_injected; n++) { |
|
1686 |
// Check for duplicates |
|
1687 |
if (injected[n].may_be_java) { |
|
34666 | 1688 |
const Symbol* const name = injected[n].name(); |
1689 |
const Symbol* const signature = injected[n].signature(); |
|
10546 | 1690 |
bool duplicate = false; |
1691 |
for (int i = 0; i < length; i++) { |
|
34666 | 1692 |
const FieldInfo* const f = FieldInfo::from_field_array(fa, i); |
1693 |
if (name == cp->symbol_at(f->name_index()) && |
|
1694 |
signature == cp->symbol_at(f->signature_index())) { |
|
10546 | 1695 |
// Symbol is desclared in Java so skip this one |
1696 |
duplicate = true; |
|
1697 |
break; |
|
1698 |
} |
|
1699 |
} |
|
1700 |
if (duplicate) { |
|
1701 |
// These will be removed from the field array at the end |
|
1702 |
continue; |
|
1703 |
} |
|
1704 |
} |
|
1705 |
||
1706 |
// Injected field |
|
34666 | 1707 |
FieldInfo* const field = FieldInfo::from_field_array(fa, index); |
10546 | 1708 |
field->initialize(JVM_ACC_FIELD_INTERNAL, |
1709 |
injected[n].name_index, |
|
1710 |
injected[n].signature_index, |
|
1711 |
0); |
|
1712 |
||
34666 | 1713 |
const BasicType type = FieldType::basic_type(injected[n].signature()); |
10546 | 1714 |
|
1715 |
// Remember how many oops we encountered and compute allocation type |
|
34666 | 1716 |
const FieldAllocationType atype = fac->update(false, type); |
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
1717 |
field->set_allocation_type(atype); |
10546 | 1718 |
index++; |
1719 |
} |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1720 |
} |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1721 |
|
34666 | 1722 |
assert(NULL == _fields, "invariant"); |
1723 |
||
1724 |
_fields = |
|
1725 |
MetadataFactory::new_array<u2>(_loader_data, |
|
1726 |
index * FieldInfo::field_slots + num_generic_signature, |
|
1727 |
CHECK); |
|
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1728 |
// Sometimes injected fields already exist in the Java source so |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1729 |
// the fields array could be too long. In that case the |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1730 |
// fields array is trimed. Also unused slots that were reserved |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1731 |
// for generic signature indexes are discarded. |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1732 |
{ |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1733 |
int i = 0; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1734 |
for (; i < index * FieldInfo::field_slots; i++) { |
34666 | 1735 |
_fields->at_put(i, fa[i]); |
10546 | 1736 |
} |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1737 |
for (int j = total_fields * FieldInfo::field_slots; |
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1738 |
j < generic_signature_slot; j++) { |
34666 | 1739 |
_fields->at_put(i++, fa[j]); |
12772
d317e5e08194
7168280: Eliminate the generic signature index slot from field array for field without generic signature.
jiangli
parents:
12587
diff
changeset
|
1740 |
} |
34666 | 1741 |
assert(_fields->length() == i, ""); |
1 | 1742 |
} |
1743 |
||
1744 |
if (_need_verify && length > 1) { |
|
1745 |
// Check duplicated fields |
|
1746 |
ResourceMark rm(THREAD); |
|
1747 |
NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
1748 |
THREAD, NameSigHash*, HASH_ROW_SIZE); |
|
1749 |
initialize_hashtable(names_and_sigs); |
|
1750 |
bool dup = false; |
|
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1751 |
const Symbol* name = NULL; |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1752 |
const Symbol* sig = NULL; |
1 | 1753 |
{ |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35220
diff
changeset
|
1754 |
debug_only(NoSafepointVerifier nsv;) |
34666 | 1755 |
for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) { |
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1756 |
name = fs.name(); |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1757 |
sig = fs.signature(); |
1 | 1758 |
// If no duplicates, add name/signature in hashtable names_and_sigs. |
1759 |
if (!put_after_lookup(name, sig, names_and_sigs)) { |
|
1760 |
dup = true; |
|
1761 |
break; |
|
1762 |
} |
|
1763 |
} |
|
1764 |
} |
|
1765 |
if (dup) { |
|
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1766 |
classfile_parse_error("Duplicate field name \"%s\" with signature \"%s\" in class file %s", |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
1767 |
name->as_C_string(), sig->as_klass_external_name(), CHECK); |
1 | 1768 |
} |
1769 |
} |
|
1770 |
} |
|
1771 |
||
1772 |
||
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1773 |
const ClassFileParser::unsafe_u2* ClassFileParser::parse_exception_table(const ClassFileStream* const cfs, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1774 |
u4 code_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1775 |
u4 exception_table_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1776 |
TRAPS) { |
34666 | 1777 |
assert(cfs != NULL, "invariant"); |
1778 |
||
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1779 |
const unsafe_u2* const exception_table_start = cfs->current(); |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1780 |
assert(exception_table_start != NULL, "null exception table"); |
34666 | 1781 |
|
1782 |
cfs->guarantee_more(8 * exception_table_length, CHECK_NULL); // start_pc, |
|
1783 |
// end_pc, |
|
1784 |
// handler_pc, |
|
1785 |
// catch_type_index |
|
1786 |
||
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1787 |
// Will check legal target after parsing code array in verifier. |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1788 |
if (_need_verify) { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1789 |
for (unsigned int i = 0; i < exception_table_length; i++) { |
34666 | 1790 |
const u2 start_pc = cfs->get_u2_fast(); |
1791 |
const u2 end_pc = cfs->get_u2_fast(); |
|
1792 |
const u2 handler_pc = cfs->get_u2_fast(); |
|
1793 |
const u2 catch_type_index = cfs->get_u2_fast(); |
|
1 | 1794 |
guarantee_property((start_pc < end_pc) && (end_pc <= code_length), |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1795 |
"Illegal exception table range in class file %s", |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1796 |
CHECK_NULL); |
1 | 1797 |
guarantee_property(handler_pc < code_length, |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1798 |
"Illegal exception table handler in class file %s", |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1799 |
CHECK_NULL); |
1 | 1800 |
if (catch_type_index != 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1801 |
guarantee_property(valid_klass_reference_at(catch_type_index), |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1802 |
"Catch type in exception table has bad constant type in class file %s", CHECK_NULL); |
1 | 1803 |
} |
1804 |
} |
|
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1805 |
} else { |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1806 |
cfs->skip_u2_fast(exception_table_length * 4); |
1 | 1807 |
} |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
1808 |
return exception_table_start; |
1 | 1809 |
} |
1810 |
||
34666 | 1811 |
void ClassFileParser::parse_linenumber_table(u4 code_attribute_length, |
1812 |
u4 code_length, |
|
1813 |
CompressedLineNumberWriteStream**const write_stream, |
|
1814 |
TRAPS) { |
|
1815 |
||
1816 |
const ClassFileStream* const cfs = _stream; |
|
1 | 1817 |
unsigned int num_entries = cfs->get_u2(CHECK); |
1818 |
||
1819 |
// Each entry is a u2 start_pc, and a u2 line_number |
|
34666 | 1820 |
const unsigned int length_in_bytes = num_entries * (sizeof(u2) * 2); |
1 | 1821 |
|
1822 |
// Verify line number attribute and table length |
|
1823 |
check_property( |
|
1824 |
code_attribute_length == sizeof(u2) + length_in_bytes, |
|
1825 |
"LineNumberTable attribute has wrong length in class file %s", CHECK); |
|
1826 |
||
1827 |
cfs->guarantee_more(length_in_bytes, CHECK); |
|
1828 |
||
1829 |
if ((*write_stream) == NULL) { |
|
1830 |
if (length_in_bytes > fixed_buffer_size) { |
|
1831 |
(*write_stream) = new CompressedLineNumberWriteStream(length_in_bytes); |
|
1832 |
} else { |
|
1833 |
(*write_stream) = new CompressedLineNumberWriteStream( |
|
34666 | 1834 |
_linenumbertable_buffer, fixed_buffer_size); |
1 | 1835 |
} |
1836 |
} |
|
1837 |
||
1838 |
while (num_entries-- > 0) { |
|
34666 | 1839 |
const u2 bci = cfs->get_u2_fast(); // start_pc |
1840 |
const u2 line = cfs->get_u2_fast(); // line_number |
|
1 | 1841 |
guarantee_property(bci < code_length, |
1842 |
"Invalid pc in LineNumberTable in class file %s", CHECK); |
|
1843 |
(*write_stream)->write_pair(bci, line); |
|
1844 |
} |
|
1845 |
} |
|
1846 |
||
1847 |
||
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1848 |
class LVT_Hash : public AllStatic { |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1849 |
public: |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1850 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1851 |
static bool equals(LocalVariableTableElement const& e0, LocalVariableTableElement const& e1) { |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1852 |
/* |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1853 |
* 3-tuple start_bci/length/slot has to be unique key, |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1854 |
* so the following comparison seems to be redundant: |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1855 |
* && elem->name_cp_index == entry->_elem->name_cp_index |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1856 |
*/ |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1857 |
return (e0.start_bci == e1.start_bci && |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1858 |
e0.length == e1.length && |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1859 |
e0.name_cp_index == e1.name_cp_index && |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1860 |
e0.slot == e1.slot); |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1861 |
} |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1862 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1863 |
static unsigned int hash(LocalVariableTableElement const& e0) { |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1864 |
unsigned int raw_hash = e0.start_bci; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1865 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1866 |
raw_hash = e0.length + raw_hash * 37; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1867 |
raw_hash = e0.name_cp_index + raw_hash * 37; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1868 |
raw_hash = e0.slot + raw_hash * 37; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1869 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1870 |
return raw_hash; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1871 |
} |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1872 |
}; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1873 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
1874 |
|
1 | 1875 |
// Class file LocalVariableTable elements. |
49364
601146c66cad
8173070: Remove ValueObj class for allocation subclassing for runtime code
coleenp
parents:
49359
diff
changeset
|
1876 |
class Classfile_LVT_Element { |
1 | 1877 |
public: |
1878 |
u2 start_bci; |
|
1879 |
u2 length; |
|
1880 |
u2 name_cp_index; |
|
1881 |
u2 descriptor_cp_index; |
|
1882 |
u2 slot; |
|
1883 |
}; |
|
1884 |
||
34666 | 1885 |
static void copy_lvt_element(const Classfile_LVT_Element* const src, |
1886 |
LocalVariableTableElement* const lvt) { |
|
1 | 1887 |
lvt->start_bci = Bytes::get_Java_u2((u1*) &src->start_bci); |
1888 |
lvt->length = Bytes::get_Java_u2((u1*) &src->length); |
|
1889 |
lvt->name_cp_index = Bytes::get_Java_u2((u1*) &src->name_cp_index); |
|
1890 |
lvt->descriptor_cp_index = Bytes::get_Java_u2((u1*) &src->descriptor_cp_index); |
|
1891 |
lvt->signature_cp_index = 0; |
|
1892 |
lvt->slot = Bytes::get_Java_u2((u1*) &src->slot); |
|
1893 |
} |
|
1894 |
||
1895 |
// Function is used to parse both attributes: |
|
34666 | 1896 |
// LocalVariableTable (LVT) and LocalVariableTypeTable (LVTT) |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1897 |
const ClassFileParser::unsafe_u2* ClassFileParser::parse_localvariable_table(const ClassFileStream* cfs, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1898 |
u4 code_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1899 |
u2 max_locals, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1900 |
u4 code_attribute_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1901 |
u2* const localvariable_table_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1902 |
bool isLVTT, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1903 |
TRAPS) { |
34666 | 1904 |
const char* const tbl_name = (isLVTT) ? "LocalVariableTypeTable" : "LocalVariableTable"; |
1 | 1905 |
*localvariable_table_length = cfs->get_u2(CHECK_NULL); |
34666 | 1906 |
const unsigned int size = |
1907 |
(*localvariable_table_length) * sizeof(Classfile_LVT_Element) / sizeof(u2); |
|
1908 |
||
1909 |
const ConstantPool* const cp = _cp; |
|
1910 |
||
1 | 1911 |
// Verify local variable table attribute has right length |
1912 |
if (_need_verify) { |
|
1913 |
guarantee_property(code_attribute_length == (sizeof(*localvariable_table_length) + size * sizeof(u2)), |
|
1914 |
"%s has wrong length in class file %s", tbl_name, CHECK_NULL); |
|
1915 |
} |
|
34666 | 1916 |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
1917 |
const unsafe_u2* const localvariable_table_start = cfs->current(); |
1 | 1918 |
assert(localvariable_table_start != NULL, "null local variable table"); |
1919 |
if (!_need_verify) { |
|
1920 |
cfs->skip_u2_fast(size); |
|
1921 |
} else { |
|
1922 |
cfs->guarantee_more(size * 2, CHECK_NULL); |
|
1923 |
for(int i = 0; i < (*localvariable_table_length); i++) { |
|
34666 | 1924 |
const u2 start_pc = cfs->get_u2_fast(); |
1925 |
const u2 length = cfs->get_u2_fast(); |
|
1926 |
const u2 name_index = cfs->get_u2_fast(); |
|
1927 |
const u2 descriptor_index = cfs->get_u2_fast(); |
|
1928 |
const u2 index = cfs->get_u2_fast(); |
|
1 | 1929 |
// Assign to a u4 to avoid overflow |
34666 | 1930 |
const u4 end_pc = (u4)start_pc + (u4)length; |
1 | 1931 |
|
1932 |
if (start_pc >= code_length) { |
|
1933 |
classfile_parse_error( |
|
1934 |
"Invalid start_pc %u in %s in class file %s", |
|
1935 |
start_pc, tbl_name, CHECK_NULL); |
|
1936 |
} |
|
1937 |
if (end_pc > code_length) { |
|
1938 |
classfile_parse_error( |
|
1939 |
"Invalid length %u in %s in class file %s", |
|
1940 |
length, tbl_name, CHECK_NULL); |
|
1941 |
} |
|
34666 | 1942 |
const int cp_size = cp->length(); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1943 |
guarantee_property(valid_symbol_at(name_index), |
1 | 1944 |
"Name index %u in %s has bad constant type in class file %s", |
1945 |
name_index, tbl_name, CHECK_NULL); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1946 |
guarantee_property(valid_symbol_at(descriptor_index), |
1 | 1947 |
"Signature index %u in %s has bad constant type in class file %s", |
1948 |
descriptor_index, tbl_name, CHECK_NULL); |
|
1949 |
||
34666 | 1950 |
const Symbol* const name = cp->symbol_at(name_index); |
1951 |
const Symbol* const sig = cp->symbol_at(descriptor_index); |
|
1 | 1952 |
verify_legal_field_name(name, CHECK_NULL); |
1953 |
u2 extra_slot = 0; |
|
1954 |
if (!isLVTT) { |
|
1955 |
verify_legal_field_signature(name, sig, CHECK_NULL); |
|
1956 |
||
1957 |
// 4894874: check special cases for double and long local variables |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
1958 |
if (sig == vmSymbols::type_signature(T_DOUBLE) || |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
1959 |
sig == vmSymbols::type_signature(T_LONG)) { |
1 | 1960 |
extra_slot = 1; |
1961 |
} |
|
1962 |
} |
|
1963 |
guarantee_property((index + extra_slot) < max_locals, |
|
1964 |
"Invalid index %u in %s in class file %s", |
|
1965 |
index, tbl_name, CHECK_NULL); |
|
1966 |
} |
|
1967 |
} |
|
1968 |
return localvariable_table_start; |
|
1969 |
} |
|
1970 |
||
1971 |
||
34666 | 1972 |
void ClassFileParser::parse_type_array(u2 array_length, |
1973 |
u4 code_length, |
|
1974 |
u4* const u1_index, |
|
1975 |
u4* const u2_index, |
|
1976 |
u1* const u1_array, |
|
1977 |
u2* const u2_array, |
|
1978 |
TRAPS) { |
|
1979 |
const ClassFileStream* const cfs = _stream; |
|
1 | 1980 |
u2 index = 0; // index in the array with long/double occupying two slots |
1981 |
u4 i1 = *u1_index; |
|
1982 |
u4 i2 = *u2_index + 1; |
|
1983 |
for(int i = 0; i < array_length; i++) { |
|
34666 | 1984 |
const u1 tag = u1_array[i1++] = cfs->get_u1(CHECK); |
1 | 1985 |
index++; |
1986 |
if (tag == ITEM_Long || tag == ITEM_Double) { |
|
1987 |
index++; |
|
1988 |
} else if (tag == ITEM_Object) { |
|
34666 | 1989 |
const u2 class_index = u2_array[i2++] = cfs->get_u2(CHECK); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
1990 |
guarantee_property(valid_klass_reference_at(class_index), |
1 | 1991 |
"Bad class index %u in StackMap in class file %s", |
1992 |
class_index, CHECK); |
|
1993 |
} else if (tag == ITEM_Uninitialized) { |
|
34666 | 1994 |
const u2 offset = u2_array[i2++] = cfs->get_u2(CHECK); |
1 | 1995 |
guarantee_property( |
1996 |
offset < code_length, |
|
1997 |
"Bad uninitialized type offset %u in StackMap in class file %s", |
|
1998 |
offset, CHECK); |
|
1999 |
} else { |
|
2000 |
guarantee_property( |
|
2001 |
tag <= (u1)ITEM_Uninitialized, |
|
2002 |
"Unknown variable type %u in StackMap in class file %s", |
|
2003 |
tag, CHECK); |
|
2004 |
} |
|
2005 |
} |
|
2006 |
u2_array[*u2_index] = index; |
|
2007 |
*u1_index = i1; |
|
2008 |
*u2_index = i2; |
|
2009 |
} |
|
2010 |
||
34666 | 2011 |
static const u1* parse_stackmap_table(const ClassFileStream* const cfs, |
2012 |
u4 code_attribute_length, |
|
2013 |
bool need_verify, |
|
2014 |
TRAPS) { |
|
2015 |
assert(cfs != NULL, "invariant"); |
|
2016 |
||
2017 |
if (0 == code_attribute_length) { |
|
1 | 2018 |
return NULL; |
34666 | 2019 |
} |
2020 |
||
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2021 |
const u1* const stackmap_table_start = cfs->current(); |
1 | 2022 |
assert(stackmap_table_start != NULL, "null stackmap table"); |
2023 |
||
2024 |
// check code_attribute_length first |
|
34666 | 2025 |
cfs->skip_u1(code_attribute_length, CHECK_NULL); |
2026 |
||
2027 |
if (!need_verify && !DumpSharedSpaces) { |
|
1 | 2028 |
return NULL; |
2029 |
} |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2030 |
return stackmap_table_start; |
1 | 2031 |
} |
2032 |
||
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2033 |
const ClassFileParser::unsafe_u2* ClassFileParser::parse_checked_exceptions(const ClassFileStream* const cfs, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2034 |
u2* const checked_exceptions_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2035 |
u4 method_attribute_length, |
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2036 |
TRAPS) { |
34666 | 2037 |
assert(cfs != NULL, "invariant"); |
2038 |
assert(checked_exceptions_length != NULL, "invariant"); |
|
2039 |
||
1 | 2040 |
cfs->guarantee_more(2, CHECK_NULL); // checked_exceptions_length |
2041 |
*checked_exceptions_length = cfs->get_u2_fast(); |
|
34666 | 2042 |
const unsigned int size = |
2043 |
(*checked_exceptions_length) * sizeof(CheckedExceptionElement) / sizeof(u2); |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2044 |
const unsafe_u2* const checked_exceptions_start = cfs->current(); |
1 | 2045 |
assert(checked_exceptions_start != NULL, "null checked exceptions"); |
2046 |
if (!_need_verify) { |
|
2047 |
cfs->skip_u2_fast(size); |
|
2048 |
} else { |
|
2049 |
// Verify each value in the checked exception table |
|
2050 |
u2 checked_exception; |
|
34666 | 2051 |
const u2 len = *checked_exceptions_length; |
1 | 2052 |
cfs->guarantee_more(2 * len, CHECK_NULL); |
2053 |
for (int i = 0; i < len; i++) { |
|
2054 |
checked_exception = cfs->get_u2_fast(); |
|
2055 |
check_property( |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2056 |
valid_klass_reference_at(checked_exception), |
1 | 2057 |
"Exception name has bad type at constant pool %u in class file %s", |
2058 |
checked_exception, CHECK_NULL); |
|
2059 |
} |
|
2060 |
} |
|
2061 |
// check exceptions attribute length |
|
2062 |
if (_need_verify) { |
|
2063 |
guarantee_property(method_attribute_length == (sizeof(*checked_exceptions_length) + |
|
2064 |
sizeof(u2) * size), |
|
2065 |
"Exceptions attribute has wrong length in class file %s", CHECK_NULL); |
|
2066 |
} |
|
2067 |
return checked_exceptions_start; |
|
2068 |
} |
|
2069 |
||
34666 | 2070 |
void ClassFileParser::throwIllegalSignature(const char* type, |
2071 |
const Symbol* name, |
|
2072 |
const Symbol* sig, |
|
2073 |
TRAPS) const { |
|
2074 |
assert(name != NULL, "invariant"); |
|
2075 |
assert(sig != NULL, "invariant"); |
|
2076 |
||
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2077 |
ResourceMark rm(THREAD); |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2078 |
Exceptions::fthrow(THREAD_AND_LOCATION, |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2079 |
vmSymbols::java_lang_ClassFormatError(), |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2080 |
"%s \"%s\" in class %s has illegal signature \"%s\"", type, |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2081 |
name->as_C_string(), _class_name->as_C_string(), sig->as_C_string()); |
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
2082 |
} |
1 | 2083 |
|
34666 | 2084 |
AnnotationCollector::ID |
2085 |
AnnotationCollector::annotation_index(const ClassLoaderData* loader_data, |
|
2086 |
const Symbol* name) { |
|
2087 |
const vmSymbols::SID sid = vmSymbols::find_sid(name); |
|
15244
83447fffce1e
8006758: LinkResolver assertion (caused by @Contended changes)
kmo
parents:
15221
diff
changeset
|
2088 |
// Privileged code can use all annotations. Other code silently drops some. |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15935
diff
changeset
|
2089 |
const bool privileged = loader_data->is_the_null_class_loader_data() || |
36508 | 2090 |
loader_data->is_platform_class_loader_data() || |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15935
diff
changeset
|
2091 |
loader_data->is_anonymous(); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2092 |
switch (sid) { |
37301
a936b4e01afb
8137058: Clear out all non-Critical APIs from sun.reflect
chegar
parents:
37242
diff
changeset
|
2093 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(reflect_CallerSensitive_signature): { |
34666 | 2094 |
if (_location != _in_method) break; // only allow for methods |
2095 |
if (!privileged) break; // only allow in privileged code |
|
2096 |
return _method_CallerSensitive; |
|
2097 |
} |
|
35135 | 2098 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ForceInline_signature): { |
34666 | 2099 |
if (_location != _in_method) break; // only allow for methods |
2100 |
if (!privileged) break; // only allow in privileged code |
|
2101 |
return _method_ForceInline; |
|
2102 |
} |
|
35135 | 2103 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_DontInline_signature): { |
34666 | 2104 |
if (_location != _in_method) break; // only allow for methods |
2105 |
if (!privileged) break; // only allow in privileged code |
|
2106 |
return _method_DontInline; |
|
2107 |
} |
|
2108 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_InjectedProfile_signature): { |
|
2109 |
if (_location != _in_method) break; // only allow for methods |
|
2110 |
if (!privileged) break; // only allow in privileged code |
|
2111 |
return _method_InjectedProfile; |
|
2112 |
} |
|
2113 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Compiled_signature): { |
|
2114 |
if (_location != _in_method) break; // only allow for methods |
|
2115 |
if (!privileged) break; // only allow in privileged code |
|
2116 |
return _method_LambdaForm_Compiled; |
|
2117 |
} |
|
2118 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(java_lang_invoke_LambdaForm_Hidden_signature): { |
|
2119 |
if (_location != _in_method) break; // only allow for methods |
|
2120 |
if (!privileged) break; // only allow in privileged code |
|
2121 |
return _method_LambdaForm_Hidden; |
|
2122 |
} |
|
2123 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_HotSpotIntrinsicCandidate_signature): { |
|
2124 |
if (_location != _in_method) break; // only allow for methods |
|
2125 |
if (!privileged) break; // only allow in privileged code |
|
2126 |
return _method_HotSpotIntrinsicCandidate; |
|
2127 |
} |
|
35135 | 2128 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Stable_signature): { |
34666 | 2129 |
if (_location != _in_field) break; // only allow for fields |
2130 |
if (!privileged) break; // only allow in privileged code |
|
2131 |
return _field_Stable; |
|
2132 |
} |
|
2133 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_Contended_signature): { |
|
2134 |
if (_location != _in_field && _location != _in_class) { |
|
2135 |
break; // only allow for fields and classes |
|
2136 |
} |
|
2137 |
if (!EnableContended || (RestrictContended && !privileged)) { |
|
2138 |
break; // honor privileges |
|
2139 |
} |
|
2140 |
return _jdk_internal_vm_annotation_Contended; |
|
2141 |
} |
|
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2142 |
case vmSymbols::VM_SYMBOL_ENUM_NAME(jdk_internal_vm_annotation_ReservedStackAccess_signature): { |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2143 |
if (_location != _in_method) break; // only allow for methods |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2144 |
if (RestrictReservedStack && !privileged) break; // honor privileges |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2145 |
return _jdk_internal_vm_annotation_ReservedStackAccess; |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2146 |
} |
34666 | 2147 |
default: { |
2148 |
break; |
|
2149 |
} |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2150 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2151 |
return AnnotationCollector::_unknown; |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2152 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2153 |
|
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2154 |
void ClassFileParser::FieldAnnotationCollector::apply_to(FieldInfo* f) { |
15193
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
2155 |
if (is_contended()) |
8e6b5694267f
8003985: Support @Contended Annotation - JEP 142
jwilhelm
parents:
15185
diff
changeset
|
2156 |
f->set_contended_group(contended_group()); |
19770
7cb9f982ea81
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
19681
diff
changeset
|
2157 |
if (is_stable()) |
7cb9f982ea81
8001107: @Stable annotation for constant folding of lazily evaluated variables
vlivanov
parents:
19681
diff
changeset
|
2158 |
f->set_stable(true); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2159 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2160 |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2161 |
ClassFileParser::FieldAnnotationCollector::~FieldAnnotationCollector() { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2162 |
// If there's an error deallocate metadata for field annotations |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2163 |
MetadataFactory::free_array<u1>(_loader_data, _field_annotations); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2164 |
MetadataFactory::free_array<u1>(_loader_data, _field_type_annotations); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2165 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2166 |
|
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46701
diff
changeset
|
2167 |
void MethodAnnotationCollector::apply_to(const methodHandle& m) { |
16617
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15935
diff
changeset
|
2168 |
if (has_annotation(_method_CallerSensitive)) |
6235d2c7549f
7198429: need checked categorization of caller-sensitive methods in the JDK
twisti
parents:
15935
diff
changeset
|
2169 |
m->set_caller_sensitive(true); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2170 |
if (has_annotation(_method_ForceInline)) |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2171 |
m->set_force_inline(true); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2172 |
if (has_annotation(_method_DontInline)) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2173 |
m->set_dont_inline(true); |
31228
8e427370cdd1
8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
30764
diff
changeset
|
2174 |
if (has_annotation(_method_InjectedProfile)) |
8e427370cdd1
8074551: GWT can be marked non-compilable due to deopt count pollution
vlivanov
parents:
30764
diff
changeset
|
2175 |
m->set_has_injected_profile(true); |
13391
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2176 |
if (has_annotation(_method_LambdaForm_Compiled) && m->intrinsic_id() == vmIntrinsics::_none) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2177 |
m->set_intrinsic_id(vmIntrinsics::_compiledLambdaForm); |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2178 |
if (has_annotation(_method_LambdaForm_Hidden)) |
30245956af37
7023639: JSR 292 method handle invocation needs a fast path for compiled code
twisti
parents:
13296
diff
changeset
|
2179 |
m->set_hidden(true); |
31587
e48945b7849c
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
31402
diff
changeset
|
2180 |
if (has_annotation(_method_HotSpotIntrinsicCandidate) && !m->is_synthetic()) |
e48945b7849c
8076112: Add @HotSpotIntrinsicCandidate annotation to indicate methods for which Java Runtime has intrinsics
zmajo
parents:
31402
diff
changeset
|
2181 |
m->set_intrinsic_candidate(true); |
35071
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2182 |
if (has_annotation(_jdk_internal_vm_annotation_ReservedStackAccess)) |
a0910b1d3e0d
8046936: JEP 270: Reserved Stack Areas for Critical Sections
fparain
parents:
34666
diff
changeset
|
2183 |
m->set_has_reserved_stack_access(true); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2184 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2185 |
|
34666 | 2186 |
void ClassFileParser::ClassAnnotationCollector::apply_to(InstanceKlass* ik) { |
2187 |
assert(ik != NULL, "invariant"); |
|
2188 |
ik->set_is_contended(is_contended()); |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2189 |
} |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2190 |
|
1 | 2191 |
#define MAX_ARGS_SIZE 255 |
2192 |
#define MAX_CODE_SIZE 65535 |
|
2193 |
#define INITIAL_MAX_LVT_NUMBER 256 |
|
2194 |
||
15601 | 2195 |
/* Copy class file LVT's/LVTT's into the HotSpot internal LVT. |
2196 |
* |
|
2197 |
* Rules for LVT's and LVTT's are: |
|
2198 |
* - There can be any number of LVT's and LVTT's. |
|
2199 |
* - If there are n LVT's, it is the same as if there was just |
|
2200 |
* one LVT containing all the entries from the n LVT's. |
|
2201 |
* - There may be no more than one LVT entry per local variable. |
|
2202 |
* Two LVT entries are 'equal' if these fields are the same: |
|
2203 |
* start_pc, length, name, slot |
|
2204 |
* - There may be no more than one LVTT entry per each LVT entry. |
|
2205 |
* Each LVTT entry has to match some LVT entry. |
|
2206 |
* - HotSpot internal LVT keeps natural ordering of class file LVT entries. |
|
2207 |
*/ |
|
34666 | 2208 |
void ClassFileParser::copy_localvariable_table(const ConstMethod* cm, |
15601 | 2209 |
int lvt_cnt, |
34666 | 2210 |
u2* const localvariable_table_length, |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2211 |
const unsafe_u2** const localvariable_table_start, |
15601 | 2212 |
int lvtt_cnt, |
34666 | 2213 |
u2* const localvariable_type_table_length, |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2214 |
const unsafe_u2** const localvariable_type_table_start, |
15601 | 2215 |
TRAPS) { |
2216 |
||
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2217 |
ResourceMark rm(THREAD); |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2218 |
|
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2219 |
typedef ResourceHashtable<LocalVariableTableElement, LocalVariableTableElement*, |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2220 |
&LVT_Hash::hash, &LVT_Hash::equals> LVT_HashTable; |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2221 |
|
34666 | 2222 |
LVT_HashTable* const table = new LVT_HashTable(); |
15601 | 2223 |
|
2224 |
// To fill LocalVariableTable in |
|
34666 | 2225 |
const Classfile_LVT_Element* cf_lvt; |
15601 | 2226 |
LocalVariableTableElement* lvt = cm->localvariable_table_start(); |
2227 |
||
2228 |
for (int tbl_no = 0; tbl_no < lvt_cnt; tbl_no++) { |
|
2229 |
cf_lvt = (Classfile_LVT_Element *) localvariable_table_start[tbl_no]; |
|
2230 |
for (int idx = 0; idx < localvariable_table_length[tbl_no]; idx++, lvt++) { |
|
2231 |
copy_lvt_element(&cf_lvt[idx], lvt); |
|
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2232 |
// If no duplicates, add LVT elem in hashtable. |
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2233 |
if (table->put(*lvt, lvt) == false |
15601 | 2234 |
&& _need_verify |
2235 |
&& _major_version >= JAVA_1_5_VERSION) { |
|
2236 |
classfile_parse_error("Duplicated LocalVariableTable attribute " |
|
2237 |
"entry for '%s' in class file %s", |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2238 |
_cp->symbol_at(lvt->name_cp_index)->as_utf8(), |
15601 | 2239 |
CHECK); |
2240 |
} |
|
2241 |
} |
|
2242 |
} |
|
2243 |
||
2244 |
// To merge LocalVariableTable and LocalVariableTypeTable |
|
34666 | 2245 |
const Classfile_LVT_Element* cf_lvtt; |
15601 | 2246 |
LocalVariableTableElement lvtt_elem; |
2247 |
||
2248 |
for (int tbl_no = 0; tbl_no < lvtt_cnt; tbl_no++) { |
|
2249 |
cf_lvtt = (Classfile_LVT_Element *) localvariable_type_table_start[tbl_no]; |
|
2250 |
for (int idx = 0; idx < localvariable_type_table_length[tbl_no]; idx++) { |
|
2251 |
copy_lvt_element(&cf_lvtt[idx], &lvtt_elem); |
|
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2252 |
LocalVariableTableElement** entry = table->get(lvtt_elem); |
15601 | 2253 |
if (entry == NULL) { |
2254 |
if (_need_verify) { |
|
2255 |
classfile_parse_error("LVTT entry for '%s' in class file %s " |
|
2256 |
"does not match any LVT entry", |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2257 |
_cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), |
15601 | 2258 |
CHECK); |
2259 |
} |
|
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2260 |
} else if ((*entry)->signature_cp_index != 0 && _need_verify) { |
15601 | 2261 |
classfile_parse_error("Duplicated LocalVariableTypeTable attribute " |
2262 |
"entry for '%s' in class file %s", |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2263 |
_cp->symbol_at(lvtt_elem.name_cp_index)->as_utf8(), |
15601 | 2264 |
CHECK); |
2265 |
} else { |
|
2266 |
// to add generic signatures into LocalVariableTable |
|
28817
09a44329d68d
8049632: JDK 1.8.0 b132 :Linux x64 : Crash in ClassFileParser::copy_localvariable_table(..)
coleenp
parents:
28027
diff
changeset
|
2267 |
(*entry)->signature_cp_index = lvtt_elem.descriptor_cp_index; |
15601 | 2268 |
} |
2269 |
} |
|
2270 |
} |
|
2271 |
} |
|
2272 |
||
2273 |
||
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2274 |
void ClassFileParser::copy_method_annotations(ConstMethod* cm, |
34666 | 2275 |
const u1* runtime_visible_annotations, |
15601 | 2276 |
int runtime_visible_annotations_length, |
34666 | 2277 |
const u1* runtime_invisible_annotations, |
15601 | 2278 |
int runtime_invisible_annotations_length, |
34666 | 2279 |
const u1* runtime_visible_parameter_annotations, |
15601 | 2280 |
int runtime_visible_parameter_annotations_length, |
34666 | 2281 |
const u1* runtime_invisible_parameter_annotations, |
15601 | 2282 |
int runtime_invisible_parameter_annotations_length, |
34666 | 2283 |
const u1* runtime_visible_type_annotations, |
15601 | 2284 |
int runtime_visible_type_annotations_length, |
34666 | 2285 |
const u1* runtime_invisible_type_annotations, |
15601 | 2286 |
int runtime_invisible_type_annotations_length, |
34666 | 2287 |
const u1* annotation_default, |
15601 | 2288 |
int annotation_default_length, |
2289 |
TRAPS) { |
|
2290 |
||
2291 |
AnnotationArray* a; |
|
2292 |
||
2293 |
if (runtime_visible_annotations_length + |
|
2294 |
runtime_invisible_annotations_length > 0) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2295 |
a = assemble_annotations(runtime_visible_annotations, |
15601 | 2296 |
runtime_visible_annotations_length, |
2297 |
runtime_invisible_annotations, |
|
2298 |
runtime_invisible_annotations_length, |
|
2299 |
CHECK); |
|
2300 |
cm->set_method_annotations(a); |
|
2301 |
} |
|
2302 |
||
2303 |
if (runtime_visible_parameter_annotations_length + |
|
2304 |
runtime_invisible_parameter_annotations_length > 0) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2305 |
a = assemble_annotations(runtime_visible_parameter_annotations, |
15601 | 2306 |
runtime_visible_parameter_annotations_length, |
2307 |
runtime_invisible_parameter_annotations, |
|
2308 |
runtime_invisible_parameter_annotations_length, |
|
2309 |
CHECK); |
|
2310 |
cm->set_parameter_annotations(a); |
|
2311 |
} |
|
2312 |
||
2313 |
if (annotation_default_length > 0) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2314 |
a = assemble_annotations(annotation_default, |
15601 | 2315 |
annotation_default_length, |
2316 |
NULL, |
|
2317 |
0, |
|
2318 |
CHECK); |
|
2319 |
cm->set_default_annotations(a); |
|
2320 |
} |
|
2321 |
||
2322 |
if (runtime_visible_type_annotations_length + |
|
2323 |
runtime_invisible_type_annotations_length > 0) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2324 |
a = assemble_annotations(runtime_visible_type_annotations, |
15601 | 2325 |
runtime_visible_type_annotations_length, |
2326 |
runtime_invisible_type_annotations, |
|
2327 |
runtime_invisible_type_annotations_length, |
|
2328 |
CHECK); |
|
2329 |
cm->set_type_annotations(a); |
|
2330 |
} |
|
2331 |
} |
|
2332 |
||
2333 |
||
1 | 2334 |
// Note: the parse_method below is big and clunky because all parsing of the code and exceptions |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2335 |
// attribute is inlined. This is cumbersome to avoid since we inline most of the parts in the |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2336 |
// Method* to save footprint, so we only know the size of the resulting Method* when the |
1 | 2337 |
// entire method attribute is parsed. |
2338 |
// |
|
2339 |
// The promoted_flags parameter is used to pass relevant access_flags |
|
2340 |
// from the method back up to the containing klass. These flag values |
|
2341 |
// are added to klass's access_flags. |
|
2342 |
||
34666 | 2343 |
Method* ClassFileParser::parse_method(const ClassFileStream* const cfs, |
2344 |
bool is_interface, |
|
2345 |
const ConstantPool* cp, |
|
2346 |
AccessFlags* const promoted_flags, |
|
2347 |
TRAPS) { |
|
2348 |
assert(cfs != NULL, "invariant"); |
|
2349 |
assert(cp != NULL, "invariant"); |
|
2350 |
assert(promoted_flags != NULL, "invariant"); |
|
2351 |
||
1 | 2352 |
ResourceMark rm(THREAD); |
34666 | 2353 |
// Parse fixed parts: |
2354 |
// access_flags, name_index, descriptor_index, attributes_count |
|
2355 |
cfs->guarantee_more(8, CHECK_NULL); |
|
1 | 2356 |
|
2357 |
int flags = cfs->get_u2_fast(); |
|
34666 | 2358 |
const u2 name_index = cfs->get_u2_fast(); |
2359 |
const int cp_size = cp->length(); |
|
1 | 2360 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2361 |
valid_symbol_at(name_index), |
1 | 2362 |
"Illegal constant pool index %u for method name in class file %s", |
34666 | 2363 |
name_index, CHECK_NULL); |
2364 |
const Symbol* const name = cp->symbol_at(name_index); |
|
2365 |
verify_legal_method_name(name, CHECK_NULL); |
|
2366 |
||
2367 |
const u2 signature_index = cfs->get_u2_fast(); |
|
1 | 2368 |
guarantee_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2369 |
valid_symbol_at(signature_index), |
1 | 2370 |
"Illegal constant pool index %u for method signature in class file %s", |
34666 | 2371 |
signature_index, CHECK_NULL); |
2372 |
const Symbol* const signature = cp->symbol_at(signature_index); |
|
2373 |
||
1 | 2374 |
if (name == vmSymbols::class_initializer_name()) { |
8653
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2375 |
// We ignore the other access flags for a valid class initializer. |
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2376 |
// (JVM Spec 2nd ed., chapter 4.6) |
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2377 |
if (_major_version < 51) { // backward compatibility |
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2378 |
flags = JVM_ACC_STATIC; |
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2379 |
} else if ((flags & JVM_ACC_STATIC) == JVM_ACC_STATIC) { |
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2380 |
flags &= JVM_ACC_STATIC | JVM_ACC_STRICT; |
32824
3b686e54dece
8135208: VM permits illegal <clinit> access_flags, versions 51-52
hseigel
parents:
31867
diff
changeset
|
2381 |
} else { |
34666 | 2382 |
classfile_parse_error("Method <clinit> is not static in class file %s", CHECK_NULL); |
8653
8797d788a4f1
6845426: non-static <clinit> method with no args is called during the class initialization process
kamg
parents:
8296
diff
changeset
|
2383 |
} |
1 | 2384 |
} else { |
34666 | 2385 |
verify_legal_method_modifiers(flags, is_interface, name, CHECK_NULL); |
1 | 2386 |
} |
2387 |
||
33207
edc4431940b2
8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
33105
diff
changeset
|
2388 |
if (name == vmSymbols::object_initializer_name() && is_interface) { |
34666 | 2389 |
classfile_parse_error("Interface cannot have a method named <init>, class file %s", CHECK_NULL); |
33207
edc4431940b2
8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
33105
diff
changeset
|
2390 |
} |
edc4431940b2
8139069: JVM should throw ClassFormatError for <init> methods in interfaces
hseigel
parents:
33105
diff
changeset
|
2391 |
|
1 | 2392 |
int args_size = -1; // only used when _need_verify is true |
2393 |
if (_need_verify) { |
|
2394 |
args_size = ((flags & JVM_ACC_STATIC) ? 0 : 1) + |
|
34666 | 2395 |
verify_legal_method_signature(name, signature, CHECK_NULL); |
1 | 2396 |
if (args_size > MAX_ARGS_SIZE) { |
34666 | 2397 |
classfile_parse_error("Too many arguments in method signature in class file %s", CHECK_NULL); |
1 | 2398 |
} |
2399 |
} |
|
2400 |
||
34666 | 2401 |
AccessFlags access_flags(flags & JVM_RECOGNIZED_METHOD_MODIFIERS); |
1 | 2402 |
|
2403 |
// Default values for code and exceptions attribute elements |
|
2404 |
u2 max_stack = 0; |
|
2405 |
u2 max_locals = 0; |
|
2406 |
u4 code_length = 0; |
|
34666 | 2407 |
const u1* code_start = 0; |
1 | 2408 |
u2 exception_table_length = 0; |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2409 |
const unsafe_u2* exception_table_start = NULL; // (potentially unaligned) pointer to array of u2 elements |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2410 |
Array<int>* exception_handlers = Universe::the_empty_int_array(); |
1 | 2411 |
u2 checked_exceptions_length = 0; |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2412 |
const unsafe_u2* checked_exceptions_start = NULL; // (potentially unaligned) pointer to array of u2 elements |
1 | 2413 |
CompressedLineNumberWriteStream* linenumber_table = NULL; |
2414 |
int linenumber_table_length = 0; |
|
2415 |
int total_lvt_length = 0; |
|
2416 |
u2 lvt_cnt = 0; |
|
2417 |
u2 lvtt_cnt = 0; |
|
2418 |
bool lvt_allocated = false; |
|
2419 |
u2 max_lvt_cnt = INITIAL_MAX_LVT_NUMBER; |
|
2420 |
u2 max_lvtt_cnt = INITIAL_MAX_LVT_NUMBER; |
|
31851
ec2f9350c499
8079825: Uninitialised variable in hotspot/src/share/vm & cpu/x86/vm (runtime)
ccheung
parents:
31778
diff
changeset
|
2421 |
u2* localvariable_table_length = NULL; |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2422 |
const unsafe_u2** localvariable_table_start = NULL; // (potentially unaligned) pointer to array of LVT attributes |
31851
ec2f9350c499
8079825: Uninitialised variable in hotspot/src/share/vm & cpu/x86/vm (runtime)
ccheung
parents:
31778
diff
changeset
|
2423 |
u2* localvariable_type_table_length = NULL; |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2424 |
const unsafe_u2** localvariable_type_table_start = NULL; // (potentially unaligned) pointer to LVTT attributes |
27612
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27402
diff
changeset
|
2425 |
int method_parameters_length = -1; |
34666 | 2426 |
const u1* method_parameters_data = NULL; |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2427 |
bool method_parameters_seen = false; |
1 | 2428 |
bool parsed_code_attribute = false; |
2429 |
bool parsed_checked_exceptions_attribute = false; |
|
2430 |
bool parsed_stackmap_attribute = false; |
|
2431 |
// stackmap attribute - JDK1.5 |
|
34666 | 2432 |
const u1* stackmap_data = NULL; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2433 |
int stackmap_data_length = 0; |
1 | 2434 |
u2 generic_signature_index = 0; |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2435 |
MethodAnnotationCollector parsed_annotations; |
34666 | 2436 |
const u1* runtime_visible_annotations = NULL; |
1 | 2437 |
int runtime_visible_annotations_length = 0; |
34666 | 2438 |
const u1* runtime_invisible_annotations = NULL; |
1 | 2439 |
int runtime_invisible_annotations_length = 0; |
34666 | 2440 |
const u1* runtime_visible_parameter_annotations = NULL; |
1 | 2441 |
int runtime_visible_parameter_annotations_length = 0; |
34666 | 2442 |
const u1* runtime_invisible_parameter_annotations = NULL; |
1 | 2443 |
int runtime_invisible_parameter_annotations_length = 0; |
34666 | 2444 |
const u1* runtime_visible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2445 |
int runtime_visible_type_annotations_length = 0; |
34666 | 2446 |
const u1* runtime_invisible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2447 |
int runtime_invisible_type_annotations_length = 0; |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2448 |
bool runtime_invisible_annotations_exists = false; |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2449 |
bool runtime_invisible_type_annotations_exists = false; |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2450 |
bool runtime_invisible_parameter_annotations_exists = false; |
34666 | 2451 |
const u1* annotation_default = NULL; |
1 | 2452 |
int annotation_default_length = 0; |
2453 |
||
2454 |
// Parse code and exceptions attribute |
|
2455 |
u2 method_attributes_count = cfs->get_u2_fast(); |
|
2456 |
while (method_attributes_count--) { |
|
34666 | 2457 |
cfs->guarantee_more(6, CHECK_NULL); // method_attribute_name_index, method_attribute_length |
2458 |
const u2 method_attribute_name_index = cfs->get_u2_fast(); |
|
2459 |
const u4 method_attribute_length = cfs->get_u4_fast(); |
|
1 | 2460 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2461 |
valid_symbol_at(method_attribute_name_index), |
1 | 2462 |
"Invalid method attribute name index %u in class file %s", |
34666 | 2463 |
method_attribute_name_index, CHECK_NULL); |
2464 |
||
2465 |
const Symbol* const method_attribute_name = cp->symbol_at(method_attribute_name_index); |
|
1 | 2466 |
if (method_attribute_name == vmSymbols::tag_code()) { |
2467 |
// Parse Code attribute |
|
2468 |
if (_need_verify) { |
|
14385 | 2469 |
guarantee_property( |
2470 |
!access_flags.is_native() && !access_flags.is_abstract(), |
|
1 | 2471 |
"Code attribute in native or abstract methods in class file %s", |
34666 | 2472 |
CHECK_NULL); |
1 | 2473 |
} |
2474 |
if (parsed_code_attribute) { |
|
34666 | 2475 |
classfile_parse_error("Multiple Code attributes in class file %s", |
2476 |
CHECK_NULL); |
|
1 | 2477 |
} |
2478 |
parsed_code_attribute = true; |
|
2479 |
||
2480 |
// Stack size, locals size, and code size |
|
2481 |
if (_major_version == 45 && _minor_version <= 2) { |
|
34666 | 2482 |
cfs->guarantee_more(4, CHECK_NULL); |
1 | 2483 |
max_stack = cfs->get_u1_fast(); |
2484 |
max_locals = cfs->get_u1_fast(); |
|
2485 |
code_length = cfs->get_u2_fast(); |
|
2486 |
} else { |
|
34666 | 2487 |
cfs->guarantee_more(8, CHECK_NULL); |
1 | 2488 |
max_stack = cfs->get_u2_fast(); |
2489 |
max_locals = cfs->get_u2_fast(); |
|
2490 |
code_length = cfs->get_u4_fast(); |
|
2491 |
} |
|
2492 |
if (_need_verify) { |
|
2493 |
guarantee_property(args_size <= max_locals, |
|
34666 | 2494 |
"Arguments can't fit into locals in class file %s", |
2495 |
CHECK_NULL); |
|
1 | 2496 |
guarantee_property(code_length > 0 && code_length <= MAX_CODE_SIZE, |
2497 |
"Invalid method Code length %u in class file %s", |
|
34666 | 2498 |
code_length, CHECK_NULL); |
1 | 2499 |
} |
2500 |
// Code pointer |
|
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2501 |
code_start = cfs->current(); |
1 | 2502 |
assert(code_start != NULL, "null code start"); |
34666 | 2503 |
cfs->guarantee_more(code_length, CHECK_NULL); |
1 | 2504 |
cfs->skip_u1_fast(code_length); |
2505 |
||
2506 |
// Exception handler table |
|
34666 | 2507 |
cfs->guarantee_more(2, CHECK_NULL); // exception_table_length |
1 | 2508 |
exception_table_length = cfs->get_u2_fast(); |
2509 |
if (exception_table_length > 0) { |
|
34666 | 2510 |
exception_table_start = parse_exception_table(cfs, |
2511 |
code_length, |
|
2512 |
exception_table_length, |
|
2513 |
CHECK_NULL); |
|
1 | 2514 |
} |
2515 |
||
2516 |
// Parse additional attributes in code attribute |
|
34666 | 2517 |
cfs->guarantee_more(2, CHECK_NULL); // code_attributes_count |
1 | 2518 |
u2 code_attributes_count = cfs->get_u2_fast(); |
339
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2519 |
|
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2520 |
unsigned int calculated_attribute_length = 0; |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2521 |
|
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2522 |
if (_major_version > 45 || (_major_version == 45 && _minor_version > 2)) { |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2523 |
calculated_attribute_length = |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2524 |
sizeof(max_stack) + sizeof(max_locals) + sizeof(code_length); |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2525 |
} else { |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2526 |
// max_stack, locals and length are smaller in pre-version 45.2 classes |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2527 |
calculated_attribute_length = sizeof(u1) + sizeof(u1) + sizeof(u2); |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2528 |
} |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2529 |
calculated_attribute_length += |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2530 |
code_length + |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2531 |
sizeof(exception_table_length) + |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2532 |
sizeof(code_attributes_count) + |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2533 |
exception_table_length * |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2534 |
( sizeof(u2) + // start_pc |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2535 |
sizeof(u2) + // end_pc |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2536 |
sizeof(u2) + // handler_pc |
2d9c1e9e9f98
6615981: JVM class file parser incorrectly rejects class files with version < 45.2
kamg
parents:
1
diff
changeset
|
2537 |
sizeof(u2) ); // catch_type_index |
1 | 2538 |
|
2539 |
while (code_attributes_count--) { |
|
34666 | 2540 |
cfs->guarantee_more(6, CHECK_NULL); // code_attribute_name_index, code_attribute_length |
2541 |
const u2 code_attribute_name_index = cfs->get_u2_fast(); |
|
2542 |
const u4 code_attribute_length = cfs->get_u4_fast(); |
|
1 | 2543 |
calculated_attribute_length += code_attribute_length + |
2544 |
sizeof(code_attribute_name_index) + |
|
2545 |
sizeof(code_attribute_length); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2546 |
check_property(valid_symbol_at(code_attribute_name_index), |
1 | 2547 |
"Invalid code attribute name index %u in class file %s", |
2548 |
code_attribute_name_index, |
|
34666 | 2549 |
CHECK_NULL); |
1 | 2550 |
if (LoadLineNumberTables && |
34666 | 2551 |
cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_line_number_table()) { |
1 | 2552 |
// Parse and compress line number table |
34666 | 2553 |
parse_linenumber_table(code_attribute_length, |
2554 |
code_length, |
|
2555 |
&linenumber_table, |
|
2556 |
CHECK_NULL); |
|
1 | 2557 |
|
2558 |
} else if (LoadLocalVariableTables && |
|
34666 | 2559 |
cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_table()) { |
1 | 2560 |
// Parse local variable table |
2561 |
if (!lvt_allocated) { |
|
2562 |
localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
2563 |
THREAD, u2, INITIAL_MAX_LVT_NUMBER); |
|
2564 |
localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2565 |
THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER); |
1 | 2566 |
localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( |
2567 |
THREAD, u2, INITIAL_MAX_LVT_NUMBER); |
|
2568 |
localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2569 |
THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER); |
1 | 2570 |
lvt_allocated = true; |
2571 |
} |
|
2572 |
if (lvt_cnt == max_lvt_cnt) { |
|
2573 |
max_lvt_cnt <<= 1; |
|
20668 | 2574 |
localvariable_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_table_length, lvt_cnt, max_lvt_cnt); |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2575 |
localvariable_table_start = REALLOC_RESOURCE_ARRAY(const unsafe_u2*, localvariable_table_start, lvt_cnt, max_lvt_cnt); |
1 | 2576 |
} |
2577 |
localvariable_table_start[lvt_cnt] = |
|
34666 | 2578 |
parse_localvariable_table(cfs, |
2579 |
code_length, |
|
1 | 2580 |
max_locals, |
2581 |
code_attribute_length, |
|
2582 |
&localvariable_table_length[lvt_cnt], |
|
2583 |
false, // is not LVTT |
|
34666 | 2584 |
CHECK_NULL); |
1 | 2585 |
total_lvt_length += localvariable_table_length[lvt_cnt]; |
2586 |
lvt_cnt++; |
|
2587 |
} else if (LoadLocalVariableTypeTables && |
|
2588 |
_major_version >= JAVA_1_5_VERSION && |
|
34666 | 2589 |
cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_local_variable_type_table()) { |
1 | 2590 |
if (!lvt_allocated) { |
2591 |
localvariable_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
2592 |
THREAD, u2, INITIAL_MAX_LVT_NUMBER); |
|
2593 |
localvariable_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2594 |
THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER); |
1 | 2595 |
localvariable_type_table_length = NEW_RESOURCE_ARRAY_IN_THREAD( |
2596 |
THREAD, u2, INITIAL_MAX_LVT_NUMBER); |
|
2597 |
localvariable_type_table_start = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2598 |
THREAD, const unsafe_u2*, INITIAL_MAX_LVT_NUMBER); |
1 | 2599 |
lvt_allocated = true; |
2600 |
} |
|
2601 |
// Parse local variable type table |
|
2602 |
if (lvtt_cnt == max_lvtt_cnt) { |
|
2603 |
max_lvtt_cnt <<= 1; |
|
20668 | 2604 |
localvariable_type_table_length = REALLOC_RESOURCE_ARRAY(u2, localvariable_type_table_length, lvtt_cnt, max_lvtt_cnt); |
46513
c61eea516a0a
8181377: Capture underlying type for unsafe/unaligned pointers in ClassFileParser
mikael
parents:
46504
diff
changeset
|
2605 |
localvariable_type_table_start = REALLOC_RESOURCE_ARRAY(const unsafe_u2*, localvariable_type_table_start, lvtt_cnt, max_lvtt_cnt); |
1 | 2606 |
} |
2607 |
localvariable_type_table_start[lvtt_cnt] = |
|
34666 | 2608 |
parse_localvariable_table(cfs, |
2609 |
code_length, |
|
1 | 2610 |
max_locals, |
2611 |
code_attribute_length, |
|
2612 |
&localvariable_type_table_length[lvtt_cnt], |
|
2613 |
true, // is LVTT |
|
34666 | 2614 |
CHECK_NULL); |
1 | 2615 |
lvtt_cnt++; |
16445
cb44d5b3ad89
8009595: The UseSplitVerifier option needs to be deprecated.
hseigel
parents:
15935
diff
changeset
|
2616 |
} else if (_major_version >= Verifier::STACKMAP_ATTRIBUTE_MAJOR_VERSION && |
34666 | 2617 |
cp->symbol_at(code_attribute_name_index) == vmSymbols::tag_stack_map_table()) { |
1 | 2618 |
// Stack map is only needed by the new verifier in JDK1.5. |
2619 |
if (parsed_stackmap_attribute) { |
|
34666 | 2620 |
classfile_parse_error("Multiple StackMapTable attributes in class file %s", CHECK_NULL); |
1 | 2621 |
} |
34666 | 2622 |
stackmap_data = parse_stackmap_table(cfs, code_attribute_length, _need_verify, CHECK_NULL); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2623 |
stackmap_data_length = code_attribute_length; |
1 | 2624 |
parsed_stackmap_attribute = true; |
2625 |
} else { |
|
2626 |
// Skip unknown attributes |
|
34666 | 2627 |
cfs->skip_u1(code_attribute_length, CHECK_NULL); |
1 | 2628 |
} |
2629 |
} |
|
2630 |
// check method attribute length |
|
2631 |
if (_need_verify) { |
|
2632 |
guarantee_property(method_attribute_length == calculated_attribute_length, |
|
34666 | 2633 |
"Code segment has wrong length in class file %s", |
2634 |
CHECK_NULL); |
|
1 | 2635 |
} |
2636 |
} else if (method_attribute_name == vmSymbols::tag_exceptions()) { |
|
2637 |
// Parse Exceptions attribute |
|
2638 |
if (parsed_checked_exceptions_attribute) { |
|
34666 | 2639 |
classfile_parse_error("Multiple Exceptions attributes in class file %s", |
2640 |
CHECK_NULL); |
|
1 | 2641 |
} |
2642 |
parsed_checked_exceptions_attribute = true; |
|
2643 |
checked_exceptions_start = |
|
34666 | 2644 |
parse_checked_exceptions(cfs, |
2645 |
&checked_exceptions_length, |
|
1 | 2646 |
method_attribute_length, |
34666 | 2647 |
CHECK_NULL); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2648 |
} else if (method_attribute_name == vmSymbols::tag_method_parameters()) { |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2649 |
// reject multiple method parameters |
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2650 |
if (method_parameters_seen) { |
34666 | 2651 |
classfile_parse_error("Multiple MethodParameters attributes in class file %s", |
2652 |
CHECK_NULL); |
|
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2653 |
} |
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2654 |
method_parameters_seen = true; |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2655 |
method_parameters_length = cfs->get_u1_fast(); |
27612
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27402
diff
changeset
|
2656 |
const u2 real_length = (method_parameters_length * 4u) + 1u; |
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27402
diff
changeset
|
2657 |
if (method_attribute_length != real_length) { |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2658 |
classfile_parse_error( |
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2659 |
"Invalid MethodParameters method attribute length %u in class file", |
34666 | 2660 |
method_attribute_length, CHECK_NULL); |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2661 |
} |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2662 |
method_parameters_data = cfs->current(); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2663 |
cfs->skip_u2_fast(method_parameters_length); |
17080
9151a26f5888
8007154: Remove support for u4 MethodParameter flags fields
emc
parents:
17024
diff
changeset
|
2664 |
cfs->skip_u2_fast(method_parameters_length); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2665 |
// ignore this attribute if it cannot be reflected |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2666 |
if (!SystemDictionary::Parameter_klass_loaded()) |
27612
7201412afbd0
8058313: Mismatch of method descriptor and MethodParameters.parameters_count should cause MalformedParameterException
emc
parents:
27402
diff
changeset
|
2667 |
method_parameters_length = -1; |
1 | 2668 |
} else if (method_attribute_name == vmSymbols::tag_synthetic()) { |
2669 |
if (method_attribute_length != 0) { |
|
2670 |
classfile_parse_error( |
|
2671 |
"Invalid Synthetic method attribute length %u in class file %s", |
|
34666 | 2672 |
method_attribute_length, CHECK_NULL); |
1 | 2673 |
} |
2674 |
// Should we check that there hasn't already been a synthetic attribute? |
|
2675 |
access_flags.set_is_synthetic(); |
|
2676 |
} else if (method_attribute_name == vmSymbols::tag_deprecated()) { // 4276120 |
|
2677 |
if (method_attribute_length != 0) { |
|
2678 |
classfile_parse_error( |
|
2679 |
"Invalid Deprecated method attribute length %u in class file %s", |
|
34666 | 2680 |
method_attribute_length, CHECK_NULL); |
1 | 2681 |
} |
2682 |
} else if (_major_version >= JAVA_1_5_VERSION) { |
|
2683 |
if (method_attribute_name == vmSymbols::tag_signature()) { |
|
44243
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
2684 |
if (generic_signature_index != 0) { |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
2685 |
classfile_parse_error( |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
2686 |
"Multiple Signature attributes for method in class file %s", |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
2687 |
CHECK_NULL); |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
2688 |
} |
1 | 2689 |
if (method_attribute_length != 2) { |
2690 |
classfile_parse_error( |
|
2691 |
"Invalid Signature attribute length %u in class file %s", |
|
34666 | 2692 |
method_attribute_length, CHECK_NULL); |
1 | 2693 |
} |
34666 | 2694 |
generic_signature_index = parse_generic_signature_attribute(cfs, CHECK_NULL); |
1 | 2695 |
} else if (method_attribute_name == vmSymbols::tag_runtime_visible_annotations()) { |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2696 |
if (runtime_visible_annotations != NULL) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2697 |
classfile_parse_error( |
34666 | 2698 |
"Multiple RuntimeVisibleAnnotations attributes for method in class file %s", |
2699 |
CHECK_NULL); |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2700 |
} |
1 | 2701 |
runtime_visible_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2702 |
runtime_visible_annotations = cfs->current(); |
1 | 2703 |
assert(runtime_visible_annotations != NULL, "null visible annotations"); |
43177 | 2704 |
cfs->guarantee_more(runtime_visible_annotations_length, CHECK_NULL); |
34666 | 2705 |
parse_annotations(cp, |
2706 |
runtime_visible_annotations, |
|
2707 |
runtime_visible_annotations_length, |
|
2708 |
&parsed_annotations, |
|
2709 |
_loader_data, |
|
2710 |
CHECK_NULL); |
|
43177 | 2711 |
cfs->skip_u1_fast(runtime_visible_annotations_length); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2712 |
} else if (method_attribute_name == vmSymbols::tag_runtime_invisible_annotations()) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2713 |
if (runtime_invisible_annotations_exists) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2714 |
classfile_parse_error( |
34666 | 2715 |
"Multiple RuntimeInvisibleAnnotations attributes for method in class file %s", |
2716 |
CHECK_NULL); |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2717 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2718 |
runtime_invisible_annotations_exists = true; |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2719 |
if (PreserveAllAnnotations) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2720 |
runtime_invisible_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2721 |
runtime_invisible_annotations = cfs->current(); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2722 |
assert(runtime_invisible_annotations != NULL, "null invisible annotations"); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2723 |
} |
34666 | 2724 |
cfs->skip_u1(method_attribute_length, CHECK_NULL); |
1 | 2725 |
} else if (method_attribute_name == vmSymbols::tag_runtime_visible_parameter_annotations()) { |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2726 |
if (runtime_visible_parameter_annotations != NULL) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2727 |
classfile_parse_error( |
34666 | 2728 |
"Multiple RuntimeVisibleParameterAnnotations attributes for method in class file %s", |
2729 |
CHECK_NULL); |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2730 |
} |
1 | 2731 |
runtime_visible_parameter_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2732 |
runtime_visible_parameter_annotations = cfs->current(); |
1 | 2733 |
assert(runtime_visible_parameter_annotations != NULL, "null visible parameter annotations"); |
34666 | 2734 |
cfs->skip_u1(runtime_visible_parameter_annotations_length, CHECK_NULL); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2735 |
} else if (method_attribute_name == vmSymbols::tag_runtime_invisible_parameter_annotations()) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2736 |
if (runtime_invisible_parameter_annotations_exists) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2737 |
classfile_parse_error( |
34666 | 2738 |
"Multiple RuntimeInvisibleParameterAnnotations attributes for method in class file %s", |
2739 |
CHECK_NULL); |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2740 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2741 |
runtime_invisible_parameter_annotations_exists = true; |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2742 |
if (PreserveAllAnnotations) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2743 |
runtime_invisible_parameter_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2744 |
runtime_invisible_parameter_annotations = cfs->current(); |
34666 | 2745 |
assert(runtime_invisible_parameter_annotations != NULL, |
2746 |
"null invisible parameter annotations"); |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2747 |
} |
34666 | 2748 |
cfs->skip_u1(method_attribute_length, CHECK_NULL); |
1 | 2749 |
} else if (method_attribute_name == vmSymbols::tag_annotation_default()) { |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2750 |
if (annotation_default != NULL) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2751 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2752 |
"Multiple AnnotationDefault attributes for method in class file %s", |
34666 | 2753 |
CHECK_NULL); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
2754 |
} |
1 | 2755 |
annotation_default_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2756 |
annotation_default = cfs->current(); |
1 | 2757 |
assert(annotation_default != NULL, "null annotation default"); |
34666 | 2758 |
cfs->skip_u1(annotation_default_length, CHECK_NULL); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2759 |
} else if (method_attribute_name == vmSymbols::tag_runtime_visible_type_annotations()) { |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2760 |
if (runtime_visible_type_annotations != NULL) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2761 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2762 |
"Multiple RuntimeVisibleTypeAnnotations attributes for method in class file %s", |
34666 | 2763 |
CHECK_NULL); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2764 |
} |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2765 |
runtime_visible_type_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2766 |
runtime_visible_type_annotations = cfs->current(); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2767 |
assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2768 |
// No need for the VM to parse Type annotations |
34666 | 2769 |
cfs->skip_u1(runtime_visible_type_annotations_length, CHECK_NULL); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2770 |
} else if (method_attribute_name == vmSymbols::tag_runtime_invisible_type_annotations()) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2771 |
if (runtime_invisible_type_annotations_exists) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2772 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2773 |
"Multiple RuntimeInvisibleTypeAnnotations attributes for method in class file %s", |
34666 | 2774 |
CHECK_NULL); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2775 |
} else { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2776 |
runtime_invisible_type_annotations_exists = true; |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2777 |
} |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2778 |
if (PreserveAllAnnotations) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2779 |
runtime_invisible_type_annotations_length = method_attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2780 |
runtime_invisible_type_annotations = cfs->current(); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2781 |
assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
2782 |
} |
34666 | 2783 |
cfs->skip_u1(method_attribute_length, CHECK_NULL); |
1 | 2784 |
} else { |
2785 |
// Skip unknown attributes |
|
34666 | 2786 |
cfs->skip_u1(method_attribute_length, CHECK_NULL); |
1 | 2787 |
} |
2788 |
} else { |
|
2789 |
// Skip unknown attributes |
|
34666 | 2790 |
cfs->skip_u1(method_attribute_length, CHECK_NULL); |
1 | 2791 |
} |
2792 |
} |
|
2793 |
||
2794 |
if (linenumber_table != NULL) { |
|
2795 |
linenumber_table->write_terminator(); |
|
2796 |
linenumber_table_length = linenumber_table->position(); |
|
2797 |
} |
|
2798 |
||
2799 |
// Make sure there's at least one Code attribute in non-native/non-abstract method |
|
2800 |
if (_need_verify) { |
|
34666 | 2801 |
guarantee_property(access_flags.is_native() || |
2802 |
access_flags.is_abstract() || |
|
2803 |
parsed_code_attribute, |
|
2804 |
"Absent Code attribute in method that is not native or abstract in class file %s", |
|
2805 |
CHECK_NULL); |
|
1 | 2806 |
} |
2807 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2808 |
// All sizing information for a Method* is finally available, now create it |
15601 | 2809 |
InlineTableSizes sizes( |
2810 |
total_lvt_length, |
|
2811 |
linenumber_table_length, |
|
2812 |
exception_table_length, |
|
2813 |
checked_exceptions_length, |
|
2814 |
method_parameters_length, |
|
2815 |
generic_signature_index, |
|
2816 |
runtime_visible_annotations_length + |
|
2817 |
runtime_invisible_annotations_length, |
|
2818 |
runtime_visible_parameter_annotations_length + |
|
2819 |
runtime_invisible_parameter_annotations_length, |
|
2820 |
runtime_visible_type_annotations_length + |
|
2821 |
runtime_invisible_type_annotations_length, |
|
2822 |
annotation_default_length, |
|
2823 |
0); |
|
2824 |
||
34666 | 2825 |
Method* const m = Method::allocate(_loader_data, |
2826 |
code_length, |
|
2827 |
access_flags, |
|
2828 |
&sizes, |
|
2829 |
ConstMethod::NORMAL, |
|
2830 |
CHECK_NULL); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2831 |
|
35898
ddc274f0052f
8145628: hotspot metadata classes shouldn't use HeapWordSize or heap related macros like align_object_size
coleenp
parents:
35495
diff
changeset
|
2832 |
ClassLoadingService::add_class_method_size(m->size()*wordSize); |
1 | 2833 |
|
2834 |
// Fill in information from fixed part (access_flags already set) |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2835 |
m->set_constants(_cp); |
1 | 2836 |
m->set_name_index(name_index); |
2837 |
m->set_signature_index(signature_index); |
|
37480 | 2838 |
|
34666 | 2839 |
ResultTypeFinder rtf(cp->symbol_at(signature_index)); |
37480 | 2840 |
m->constMethod()->set_result_type(rtf.type()); |
1 | 2841 |
|
2842 |
if (args_size >= 0) { |
|
2843 |
m->set_size_of_parameters(args_size); |
|
2844 |
} else { |
|
2845 |
m->compute_size_of_parameters(THREAD); |
|
2846 |
} |
|
2847 |
#ifdef ASSERT |
|
2848 |
if (args_size >= 0) { |
|
2849 |
m->compute_size_of_parameters(THREAD); |
|
2850 |
assert(args_size == m->size_of_parameters(), ""); |
|
2851 |
} |
|
2852 |
#endif |
|
2853 |
||
2854 |
// Fill in code attribute information |
|
2855 |
m->set_max_stack(max_stack); |
|
2856 |
m->set_max_locals(max_locals); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2857 |
if (stackmap_data != NULL) { |
34666 | 2858 |
m->constMethod()->copy_stackmap_data(_loader_data, |
2859 |
(u1*)stackmap_data, |
|
2860 |
stackmap_data_length, |
|
2861 |
CHECK_NULL); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2862 |
} |
1 | 2863 |
|
2864 |
// Copy byte codes |
|
34666 | 2865 |
m->set_code((u1*)code_start); |
1 | 2866 |
|
2867 |
// Copy line number table |
|
2868 |
if (linenumber_table != NULL) { |
|
2869 |
memcpy(m->compressed_linenumber_table(), |
|
34666 | 2870 |
linenumber_table->buffer(), |
2871 |
linenumber_table_length); |
|
1 | 2872 |
} |
2873 |
||
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
2874 |
// Copy exception table |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
2875 |
if (exception_table_length > 0) { |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2876 |
Copy::conjoint_swap_if_needed<Endian::JAVA>(exception_table_start, |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2877 |
m->exception_table_start(), |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2878 |
exception_table_length * sizeof(ExceptionTableElement), |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2879 |
sizeof(u2)); |
13282
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
2880 |
} |
9872915dd78d
7178145: Change constMethodOop::_exception_table to optionally inlined u2 table.
jiangli
parents:
12772
diff
changeset
|
2881 |
|
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2882 |
// Copy method parameters |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2883 |
if (method_parameters_length > 0) { |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2884 |
MethodParametersElement* elem = m->constMethod()->method_parameters_start(); |
15464
1f2cca0aa501
8006949: Update hotspot for MethodParameters format change
emc
parents:
15244
diff
changeset
|
2885 |
for (int i = 0; i < method_parameters_length; i++) { |
34666 | 2886 |
elem[i].name_cp_index = Bytes::get_Java_u2((address)method_parameters_data); |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2887 |
method_parameters_data += 2; |
34666 | 2888 |
elem[i].flags = Bytes::get_Java_u2((address)method_parameters_data); |
17080
9151a26f5888
8007154: Remove support for u4 MethodParameter flags fields
emc
parents:
17024
diff
changeset
|
2889 |
method_parameters_data += 2; |
15102
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2890 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2891 |
} |
0a86564e5f61
8004728: Add hotspot support for parameter reflection
coleenp
parents:
15097
diff
changeset
|
2892 |
|
1 | 2893 |
// Copy checked exceptions |
2894 |
if (checked_exceptions_length > 0) { |
|
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2895 |
Copy::conjoint_swap_if_needed<Endian::JAVA>(checked_exceptions_start, |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2896 |
m->checked_exceptions_start(), |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2897 |
checked_exceptions_length * sizeof(CheckedExceptionElement), |
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
2898 |
sizeof(u2)); |
1 | 2899 |
} |
2900 |
||
15601 | 2901 |
// Copy class file LVT's/LVTT's into the HotSpot internal LVT. |
1 | 2902 |
if (total_lvt_length > 0) { |
2903 |
promoted_flags->set_has_localvariable_table(); |
|
34666 | 2904 |
copy_localvariable_table(m->constMethod(), |
2905 |
lvt_cnt, |
|
15601 | 2906 |
localvariable_table_length, |
2907 |
localvariable_table_start, |
|
2908 |
lvtt_cnt, |
|
2909 |
localvariable_type_table_length, |
|
34666 | 2910 |
localvariable_type_table_start, |
2911 |
CHECK_NULL); |
|
1 | 2912 |
} |
2913 |
||
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2914 |
if (parsed_annotations.has_any_annotations()) |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
2915 |
parsed_annotations.apply_to(m); |
15601 | 2916 |
|
2917 |
// Copy annotations |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2918 |
copy_method_annotations(m->constMethod(), |
15601 | 2919 |
runtime_visible_annotations, |
2920 |
runtime_visible_annotations_length, |
|
2921 |
runtime_invisible_annotations, |
|
2922 |
runtime_invisible_annotations_length, |
|
2923 |
runtime_visible_parameter_annotations, |
|
2924 |
runtime_visible_parameter_annotations_length, |
|
2925 |
runtime_invisible_parameter_annotations, |
|
2926 |
runtime_invisible_parameter_annotations_length, |
|
2927 |
runtime_visible_type_annotations, |
|
2928 |
runtime_visible_type_annotations_length, |
|
2929 |
runtime_invisible_type_annotations, |
|
2930 |
runtime_invisible_type_annotations_length, |
|
2931 |
annotation_default, |
|
2932 |
annotation_default_length, |
|
2933 |
CHECK_NULL); |
|
1 | 2934 |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
2935 |
if (name == vmSymbols::finalize_method_name() && |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
2936 |
signature == vmSymbols::void_method_signature()) { |
1 | 2937 |
if (m->is_empty_method()) { |
2938 |
_has_empty_finalizer = true; |
|
2939 |
} else { |
|
2940 |
_has_finalizer = true; |
|
2941 |
} |
|
2942 |
} |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
2943 |
if (name == vmSymbols::object_initializer_name() && |
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
2944 |
signature == vmSymbols::void_method_signature() && |
1 | 2945 |
m->is_vanilla_constructor()) { |
2946 |
_has_vanilla_constructor = true; |
|
2947 |
} |
|
2948 |
||
15601 | 2949 |
NOT_PRODUCT(m->verify()); |
1 | 2950 |
return m; |
2951 |
} |
|
2952 |
||
2953 |
||
2954 |
// The promoted_flags parameter is used to pass relevant access_flags |
|
2955 |
// from the methods back up to the containing klass. These flag values |
|
2956 |
// are added to klass's access_flags. |
|
34666 | 2957 |
// Side-effects: populates the _methods field in the parser |
2958 |
void ClassFileParser::parse_methods(const ClassFileStream* const cfs, |
|
2959 |
bool is_interface, |
|
2960 |
AccessFlags* promoted_flags, |
|
2961 |
bool* has_final_method, |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
2962 |
bool* declares_nonstatic_concrete_methods, |
34666 | 2963 |
TRAPS) { |
2964 |
assert(cfs != NULL, "invariant"); |
|
2965 |
assert(promoted_flags != NULL, "invariant"); |
|
2966 |
assert(has_final_method != NULL, "invariant"); |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
2967 |
assert(declares_nonstatic_concrete_methods != NULL, "invariant"); |
34666 | 2968 |
|
2969 |
assert(NULL == _methods, "invariant"); |
|
2970 |
||
2971 |
cfs->guarantee_more(2, CHECK); // length |
|
2972 |
const u2 length = cfs->get_u2_fast(); |
|
1 | 2973 |
if (length == 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
2974 |
_methods = Universe::the_empty_method_array(); |
1 | 2975 |
} else { |
34666 | 2976 |
_methods = MetadataFactory::new_array<Method*>(_loader_data, |
2977 |
length, |
|
2978 |
NULL, |
|
2979 |
CHECK); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2980 |
|
1 | 2981 |
for (int index = 0; index < length; index++) { |
34666 | 2982 |
Method* method = parse_method(cfs, |
2983 |
is_interface, |
|
2984 |
_cp, |
|
2985 |
promoted_flags, |
|
2986 |
CHECK); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
2987 |
|
1 | 2988 |
if (method->is_final()) { |
2989 |
*has_final_method = true; |
|
2990 |
} |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
2991 |
// declares_nonstatic_concrete_methods: declares concrete instance methods, any access flags |
27402
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
27023
diff
changeset
|
2992 |
// used for interface initialization, and default method inheritance analysis |
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
2993 |
if (is_interface && !(*declares_nonstatic_concrete_methods) |
27402
5c4675ddc00c
8043275: Fix interface initialization for default methods.
acorn
parents:
27023
diff
changeset
|
2994 |
&& !method->is_abstract() && !method->is_static()) { |
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
2995 |
*declares_nonstatic_concrete_methods = true; |
14385 | 2996 |
} |
34666 | 2997 |
_methods->at_put(index, method); |
1 | 2998 |
} |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
2999 |
|
1 | 3000 |
if (_need_verify && length > 1) { |
3001 |
// Check duplicated methods |
|
3002 |
ResourceMark rm(THREAD); |
|
3003 |
NameSigHash** names_and_sigs = NEW_RESOURCE_ARRAY_IN_THREAD( |
|
3004 |
THREAD, NameSigHash*, HASH_ROW_SIZE); |
|
3005 |
initialize_hashtable(names_and_sigs); |
|
3006 |
bool dup = false; |
|
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3007 |
const Symbol* name = NULL; |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3008 |
const Symbol* sig = NULL; |
1 | 3009 |
{ |
35492
c8c0273e6b91
8146690: Make all classes in GC follow the naming convention.
david
parents:
35220
diff
changeset
|
3010 |
debug_only(NoSafepointVerifier nsv;) |
1 | 3011 |
for (int i = 0; i < length; i++) { |
34666 | 3012 |
const Method* const m = _methods->at(i); |
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3013 |
name = m->name(); |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3014 |
sig = m->signature(); |
1 | 3015 |
// If no duplicates, add name/signature in hashtable names_and_sigs. |
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3016 |
if (!put_after_lookup(name, sig, names_and_sigs)) { |
1 | 3017 |
dup = true; |
3018 |
break; |
|
3019 |
} |
|
3020 |
} |
|
3021 |
} |
|
3022 |
if (dup) { |
|
46301
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3023 |
classfile_parse_error("Duplicate method name \"%s\" with signature \"%s\" in class file %s", |
57f01b1bd33c
8171194: Exception "Duplicate field name&signature in class file" should report the name and signature of the field
shshahma
parents:
46289
diff
changeset
|
3024 |
name->as_C_string(), sig->as_klass_external_name(), CHECK); |
1 | 3025 |
} |
3026 |
} |
|
3027 |
} |
|
3028 |
} |
|
3029 |
||
34666 | 3030 |
static const intArray* sort_methods(Array<Method*>* methods) { |
3031 |
const int length = methods->length(); |
|
9172
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3032 |
// If JVMTI original method ordering or sharing is enabled we have to |
1 | 3033 |
// remember the original class file ordering. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3034 |
// We temporarily use the vtable_index field in the Method* to store the |
1 | 3035 |
// class file index, so we can read in after calling qsort. |
9172
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3036 |
// Put the method ordering in the shared archive. |
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3037 |
if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
1 | 3038 |
for (int index = 0; index < length; index++) { |
34666 | 3039 |
Method* const m = methods->at(index); |
1 | 3040 |
assert(!m->valid_vtable_index(), "vtable index should not be set"); |
3041 |
m->set_vtable_index(index); |
|
3042 |
} |
|
3043 |
} |
|
3044 |
// Sort method array by ascending method name (for faster lookups & vtable construction) |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
3045 |
// Note that the ordering is not alphabetical, see Symbol::fast_compare |
15601 | 3046 |
Method::sort_methods(methods); |
1 | 3047 |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3048 |
intArray* method_ordering = NULL; |
9172
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3049 |
// If JVMTI original method ordering or sharing is enabled construct int |
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3050 |
// array remembering the original ordering |
a4e13ccafc44
7032407: Crash in LinkResolver::runtime_resolve_virtual_method()
coleenp
parents:
9117
diff
changeset
|
3051 |
if (JvmtiExport::can_maintain_original_method_order() || DumpSharedSpaces) { |
38031
e0b822facc03
8149374: Replace C1-specific collection classes with universal collection classes
fzhinkin
parents:
36508
diff
changeset
|
3052 |
method_ordering = new intArray(length, length, -1); |
1 | 3053 |
for (int index = 0; index < length; index++) { |
34666 | 3054 |
Method* const m = methods->at(index); |
3055 |
const int old_index = m->vtable_index(); |
|
1 | 3056 |
assert(old_index >= 0 && old_index < length, "invalid method index"); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3057 |
method_ordering->at_put(index, old_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3058 |
m->set_vtable_index(Method::invalid_vtable_index); |
1 | 3059 |
} |
3060 |
} |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3061 |
return method_ordering; |
1 | 3062 |
} |
3063 |
||
25507 | 3064 |
// Parse generic_signature attribute for methods and fields |
34666 | 3065 |
u2 ClassFileParser::parse_generic_signature_attribute(const ClassFileStream* const cfs, |
3066 |
TRAPS) { |
|
3067 |
assert(cfs != NULL, "invariant"); |
|
3068 |
||
25507 | 3069 |
cfs->guarantee_more(2, CHECK_0); // generic_signature_index |
34666 | 3070 |
const u2 generic_signature_index = cfs->get_u2_fast(); |
25507 | 3071 |
check_property( |
3072 |
valid_symbol_at(generic_signature_index), |
|
3073 |
"Invalid Signature attribute at constant pool index %u in class file %s", |
|
3074 |
generic_signature_index, CHECK_0); |
|
3075 |
return generic_signature_index; |
|
3076 |
} |
|
1 | 3077 |
|
34666 | 3078 |
void ClassFileParser::parse_classfile_sourcefile_attribute(const ClassFileStream* const cfs, |
3079 |
TRAPS) { |
|
3080 |
||
3081 |
assert(cfs != NULL, "invariant"); |
|
3082 |
||
1 | 3083 |
cfs->guarantee_more(2, CHECK); // sourcefile_index |
34666 | 3084 |
const u2 sourcefile_index = cfs->get_u2_fast(); |
1 | 3085 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3086 |
valid_symbol_at(sourcefile_index), |
1 | 3087 |
"Invalid SourceFile attribute at constant pool index %u in class file %s", |
3088 |
sourcefile_index, CHECK); |
|
19326
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3089 |
set_class_sourcefile_index(sourcefile_index); |
1 | 3090 |
} |
3091 |
||
34666 | 3092 |
void ClassFileParser::parse_classfile_source_debug_extension_attribute(const ClassFileStream* const cfs, |
3093 |
int length, |
|
3094 |
TRAPS) { |
|
3095 |
assert(cfs != NULL, "invariant"); |
|
3096 |
||
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3097 |
const u1* const sde_buffer = cfs->current(); |
1 | 3098 |
assert(sde_buffer != NULL, "null sde buffer"); |
3099 |
||
3100 |
// Don't bother storing it if there is no way to retrieve it |
|
3101 |
if (JvmtiExport::can_get_source_debug_extension()) { |
|
13295 | 3102 |
assert((length+1) > length, "Overflow checking"); |
34666 | 3103 |
u1* const sde = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, u1, length+1); |
13295 | 3104 |
for (int i = 0; i < length; i++) { |
3105 |
sde[i] = sde_buffer[i]; |
|
3106 |
} |
|
3107 |
sde[length] = '\0'; |
|
34666 | 3108 |
set_class_sde_buffer((const char*)sde, length); |
1 | 3109 |
} |
3110 |
// Got utf8 string, set stream position forward |
|
3111 |
cfs->skip_u1(length, CHECK); |
|
3112 |
} |
|
3113 |
||
3114 |
||
3115 |
// Inner classes can be static, private or protected (classic VM does this) |
|
34666 | 3116 |
#define RECOGNIZED_INNER_CLASS_MODIFIERS ( JVM_RECOGNIZED_CLASS_MODIFIERS | \ |
3117 |
JVM_ACC_PRIVATE | \ |
|
3118 |
JVM_ACC_PROTECTED | \ |
|
3119 |
JVM_ACC_STATIC \ |
|
3120 |
) |
|
1 | 3121 |
|
3122 |
// Return number of classes in the inner classes attribute table |
|
34666 | 3123 |
u2 ClassFileParser::parse_classfile_inner_classes_attribute(const ClassFileStream* const cfs, |
3124 |
const u1* const inner_classes_attribute_start, |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3125 |
bool parsed_enclosingmethod_attribute, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3126 |
u2 enclosing_method_class_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3127 |
u2 enclosing_method_method_index, |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3128 |
TRAPS) { |
34666 | 3129 |
const u1* const current_mark = cfs->current(); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3130 |
u2 length = 0; |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3131 |
if (inner_classes_attribute_start != NULL) { |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3132 |
cfs->set_current(inner_classes_attribute_start); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3133 |
cfs->guarantee_more(2, CHECK_0); // length |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3134 |
length = cfs->get_u2_fast(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3135 |
} |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3136 |
|
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3137 |
// 4-tuples of shorts of inner classes data and 2 shorts of enclosing |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3138 |
// method data: |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3139 |
// [inner_class_info_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3140 |
// outer_class_info_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3141 |
// inner_name_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3142 |
// inner_class_access_flags, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3143 |
// ... |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3144 |
// enclosing_method_class_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3145 |
// enclosing_method_method_index] |
34666 | 3146 |
const int size = length * 4 + (parsed_enclosingmethod_attribute ? 2 : 0); |
3147 |
Array<u2>* const inner_classes = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3148 |
_inner_classes = inner_classes; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3149 |
|
1 | 3150 |
int index = 0; |
3151 |
cfs->guarantee_more(8 * length, CHECK_0); // 4-tuples of u2 |
|
3152 |
for (int n = 0; n < length; n++) { |
|
3153 |
// Inner class index |
|
34666 | 3154 |
const u2 inner_class_info_index = cfs->get_u2_fast(); |
1 | 3155 |
check_property( |
31776
70dd826a47b5
8130183: InnerClasses: VM permits wrong inner_class_info_index value of zero
hseigel
parents:
31402
diff
changeset
|
3156 |
valid_klass_reference_at(inner_class_info_index), |
1 | 3157 |
"inner_class_info_index %u has bad constant type in class file %s", |
3158 |
inner_class_info_index, CHECK_0); |
|
3159 |
// Outer class index |
|
34666 | 3160 |
const u2 outer_class_info_index = cfs->get_u2_fast(); |
1 | 3161 |
check_property( |
3162 |
outer_class_info_index == 0 || |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3163 |
valid_klass_reference_at(outer_class_info_index), |
1 | 3164 |
"outer_class_info_index %u has bad constant type in class file %s", |
3165 |
outer_class_info_index, CHECK_0); |
|
3166 |
// Inner class name |
|
34666 | 3167 |
const u2 inner_name_index = cfs->get_u2_fast(); |
1 | 3168 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3169 |
inner_name_index == 0 || valid_symbol_at(inner_name_index), |
1 | 3170 |
"inner_name_index %u has bad constant type in class file %s", |
3171 |
inner_name_index, CHECK_0); |
|
3172 |
if (_need_verify) { |
|
3173 |
guarantee_property(inner_class_info_index != outer_class_info_index, |
|
3174 |
"Class is both outer and inner class in class file %s", CHECK_0); |
|
3175 |
} |
|
3176 |
// Access flags |
|
43977
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3177 |
jint flags; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3178 |
// JVM_ACC_MODULE is defined in JDK-9 and later. |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3179 |
if (_major_version >= JAVA_9_VERSION) { |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3180 |
flags = cfs->get_u2_fast() & (RECOGNIZED_INNER_CLASS_MODIFIERS | JVM_ACC_MODULE); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3181 |
} else { |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3182 |
flags = cfs->get_u2_fast() & RECOGNIZED_INNER_CLASS_MODIFIERS; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
3183 |
} |
1 | 3184 |
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) { |
3185 |
// Set abstract bit for old class files for backward compatibility |
|
3186 |
flags |= JVM_ACC_ABSTRACT; |
|
3187 |
} |
|
3188 |
verify_legal_class_modifiers(flags, CHECK_0); |
|
34666 | 3189 |
AccessFlags inner_access_flags(flags); |
1 | 3190 |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3191 |
inner_classes->at_put(index++, inner_class_info_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3192 |
inner_classes->at_put(index++, outer_class_info_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3193 |
inner_classes->at_put(index++, inner_name_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3194 |
inner_classes->at_put(index++, inner_access_flags.as_short()); |
1 | 3195 |
} |
3196 |
||
3197 |
// 4347400: make sure there's no duplicate entry in the classes array |
|
3198 |
if (_need_verify && _major_version >= JAVA_1_5_VERSION) { |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3199 |
for(int i = 0; i < length * 4; i += 4) { |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3200 |
for(int j = i + 4; j < length * 4; j += 4) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3201 |
guarantee_property((inner_classes->at(i) != inner_classes->at(j) || |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3202 |
inner_classes->at(i+1) != inner_classes->at(j+1) || |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3203 |
inner_classes->at(i+2) != inner_classes->at(j+2) || |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3204 |
inner_classes->at(i+3) != inner_classes->at(j+3)), |
1 | 3205 |
"Duplicate entry in InnerClasses in class file %s", |
3206 |
CHECK_0); |
|
3207 |
} |
|
3208 |
} |
|
3209 |
} |
|
3210 |
||
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3211 |
// Set EnclosingMethod class and method indexes. |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3212 |
if (parsed_enclosingmethod_attribute) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3213 |
inner_classes->at_put(index++, enclosing_method_class_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3214 |
inner_classes->at_put(index++, enclosing_method_method_index); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3215 |
} |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3216 |
assert(index == size, "wrong size"); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3217 |
|
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3218 |
// Restore buffer's current position. |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3219 |
cfs->set_current(current_mark); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3220 |
|
1 | 3221 |
return length; |
3222 |
} |
|
3223 |
||
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3224 |
u2 ClassFileParser::parse_classfile_nest_members_attribute(const ClassFileStream* const cfs, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3225 |
const u1* const nest_members_attribute_start, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3226 |
TRAPS) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3227 |
const u1* const current_mark = cfs->current(); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3228 |
u2 length = 0; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3229 |
if (nest_members_attribute_start != NULL) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3230 |
cfs->set_current(nest_members_attribute_start); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3231 |
cfs->guarantee_more(2, CHECK_0); // length |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3232 |
length = cfs->get_u2_fast(); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3233 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3234 |
const int size = length; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3235 |
Array<u2>* const nest_members = MetadataFactory::new_array<u2>(_loader_data, size, CHECK_0); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3236 |
_nest_members = nest_members; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3237 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3238 |
int index = 0; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3239 |
cfs->guarantee_more(2 * length, CHECK_0); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3240 |
for (int n = 0; n < length; n++) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3241 |
const u2 class_info_index = cfs->get_u2_fast(); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3242 |
check_property( |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3243 |
valid_klass_reference_at(class_info_index), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3244 |
"Nest member class_info_index %u has bad constant type in class file %s", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3245 |
class_info_index, CHECK_0); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3246 |
nest_members->at_put(index++, class_info_index); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3247 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3248 |
assert(index == size, "wrong size"); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3249 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3250 |
// Restore buffer's current position. |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3251 |
cfs->set_current(current_mark); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3252 |
|
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3253 |
return length; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3254 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3255 |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3256 |
void ClassFileParser::parse_classfile_synthetic_attribute(TRAPS) { |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3257 |
set_class_synthetic_flag(true); |
1 | 3258 |
} |
3259 |
||
34666 | 3260 |
void ClassFileParser::parse_classfile_signature_attribute(const ClassFileStream* const cfs, TRAPS) { |
3261 |
assert(cfs != NULL, "invariant"); |
|
3262 |
||
3263 |
const u2 signature_index = cfs->get_u2(CHECK); |
|
1 | 3264 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3265 |
valid_symbol_at(signature_index), |
1 | 3266 |
"Invalid constant pool index %u in Signature attribute in class file %s", |
3267 |
signature_index, CHECK); |
|
19326
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3268 |
set_class_generic_signature_index(signature_index); |
1 | 3269 |
} |
3270 |
||
34666 | 3271 |
void ClassFileParser::parse_classfile_bootstrap_methods_attribute(const ClassFileStream* const cfs, |
3272 |
ConstantPool* cp, |
|
3273 |
u4 attribute_byte_length, |
|
3274 |
TRAPS) { |
|
3275 |
assert(cfs != NULL, "invariant"); |
|
3276 |
assert(cp != NULL, "invariant"); |
|
3277 |
||
3278 |
const u1* const current_start = cfs->current(); |
|
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3279 |
|
25506 | 3280 |
guarantee_property(attribute_byte_length >= sizeof(u2), |
3281 |
"Invalid BootstrapMethods attribute length %u in class file %s", |
|
3282 |
attribute_byte_length, |
|
3283 |
CHECK); |
|
3284 |
||
3285 |
cfs->guarantee_more(attribute_byte_length, CHECK); |
|
3286 |
||
34666 | 3287 |
const int attribute_array_length = cfs->get_u2_fast(); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3288 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3289 |
guarantee_property(_max_bootstrap_specifier_index < attribute_array_length, |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3290 |
"Short length on BootstrapMethods in class file %s", |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3291 |
CHECK); |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3292 |
|
23840 | 3293 |
|
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3294 |
// The attribute contains a counted array of counted tuples of shorts, |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3295 |
// represending bootstrap specifiers: |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3296 |
// length*{bootstrap_method_index, argument_count*{argument_index}} |
34666 | 3297 |
const int operand_count = (attribute_byte_length - sizeof(u2)) / sizeof(u2); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3298 |
// operand_count = number of shorts in attr, except for leading length |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3299 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3300 |
// The attribute is copied into a short[] array. |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3301 |
// The array begins with a series of short[2] pairs, one for each tuple. |
34666 | 3302 |
const int index_size = (attribute_array_length * 2); |
3303 |
||
3304 |
Array<u2>* const operands = |
|
3305 |
MetadataFactory::new_array<u2>(_loader_data, index_size + operand_count, CHECK); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3306 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3307 |
// Eagerly assign operands so they will be deallocated with the constant |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3308 |
// pool if there is an error. |
34666 | 3309 |
cp->set_operands(operands); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3310 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3311 |
int operand_fill_index = index_size; |
34666 | 3312 |
const int cp_size = cp->length(); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3313 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3314 |
for (int n = 0; n < attribute_array_length; n++) { |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3315 |
// Store a 32-bit offset into the header of the operand array. |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3316 |
ConstantPool::operand_offset_at_put(operands, n, operand_fill_index); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3317 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3318 |
// Read a bootstrap specifier. |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3319 |
cfs->guarantee_more(sizeof(u2) * 2, CHECK); // bsm, argc |
34666 | 3320 |
const u2 bootstrap_method_index = cfs->get_u2_fast(); |
3321 |
const u2 argument_count = cfs->get_u2_fast(); |
|
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3322 |
check_property( |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3323 |
valid_cp_range(bootstrap_method_index, cp_size) && |
34666 | 3324 |
cp->tag_at(bootstrap_method_index).is_method_handle(), |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3325 |
"bootstrap_method_index %u has bad constant type in class file %s", |
7709 | 3326 |
bootstrap_method_index, |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3327 |
CHECK); |
27023 | 3328 |
|
3329 |
guarantee_property((operand_fill_index + 1 + argument_count) < operands->length(), |
|
3330 |
"Invalid BootstrapMethods num_bootstrap_methods or num_bootstrap_arguments value in class file %s", |
|
3331 |
CHECK); |
|
3332 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3333 |
operands->at_put(operand_fill_index++, bootstrap_method_index); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3334 |
operands->at_put(operand_fill_index++, argument_count); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3335 |
|
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3336 |
cfs->guarantee_more(sizeof(u2) * argument_count, CHECK); // argv[argc] |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3337 |
for (int j = 0; j < argument_count; j++) { |
34666 | 3338 |
const u2 argument_index = cfs->get_u2_fast(); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3339 |
check_property( |
7709 | 3340 |
valid_cp_range(argument_index, cp_size) && |
34666 | 3341 |
cp->tag_at(argument_index).is_loadable_constant(), |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3342 |
"argument_index %u has bad constant type in class file %s", |
7709 | 3343 |
argument_index, |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3344 |
CHECK); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3345 |
operands->at_put(operand_fill_index++, argument_index); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3346 |
} |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3347 |
} |
34666 | 3348 |
guarantee_property(current_start + attribute_byte_length == cfs->current(), |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3349 |
"Bad length on BootstrapMethods in class file %s", |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3350 |
CHECK); |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3351 |
} |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3352 |
|
34666 | 3353 |
void ClassFileParser::parse_classfile_attributes(const ClassFileStream* const cfs, |
3354 |
ConstantPool* cp, |
|
3355 |
ClassFileParser::ClassAnnotationCollector* parsed_annotations, |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3356 |
TRAPS) { |
34666 | 3357 |
assert(cfs != NULL, "invariant"); |
3358 |
assert(cp != NULL, "invariant"); |
|
3359 |
assert(parsed_annotations != NULL, "invariant"); |
|
3360 |
||
1 | 3361 |
// Set inner classes attribute to default sentinel |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3362 |
_inner_classes = Universe::the_empty_short_array(); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3363 |
// Set nest members attribute to default sentinel |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3364 |
_nest_members = Universe::the_empty_short_array(); |
1 | 3365 |
cfs->guarantee_more(2, CHECK); // attributes_count |
3366 |
u2 attributes_count = cfs->get_u2_fast(); |
|
3367 |
bool parsed_sourcefile_attribute = false; |
|
3368 |
bool parsed_innerclasses_attribute = false; |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3369 |
bool parsed_nest_members_attribute = false; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3370 |
bool parsed_nest_host_attribute = false; |
1 | 3371 |
bool parsed_enclosingmethod_attribute = false; |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3372 |
bool parsed_bootstrap_methods_attribute = false; |
34666 | 3373 |
const u1* runtime_visible_annotations = NULL; |
1 | 3374 |
int runtime_visible_annotations_length = 0; |
34666 | 3375 |
const u1* runtime_invisible_annotations = NULL; |
1 | 3376 |
int runtime_invisible_annotations_length = 0; |
34666 | 3377 |
const u1* runtime_visible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3378 |
int runtime_visible_type_annotations_length = 0; |
34666 | 3379 |
const u1* runtime_invisible_type_annotations = NULL; |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3380 |
int runtime_invisible_type_annotations_length = 0; |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3381 |
bool runtime_invisible_type_annotations_exists = false; |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3382 |
bool runtime_invisible_annotations_exists = false; |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3383 |
bool parsed_source_debug_ext_annotations_exist = false; |
34666 | 3384 |
const u1* inner_classes_attribute_start = NULL; |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3385 |
u4 inner_classes_attribute_length = 0; |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3386 |
u2 enclosing_method_class_index = 0; |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3387 |
u2 enclosing_method_method_index = 0; |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3388 |
const u1* nest_members_attribute_start = NULL; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3389 |
u4 nest_members_attribute_length = 0; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3390 |
|
1 | 3391 |
// Iterate over attributes |
3392 |
while (attributes_count--) { |
|
3393 |
cfs->guarantee_more(6, CHECK); // attribute_name_index, attribute_length |
|
34666 | 3394 |
const u2 attribute_name_index = cfs->get_u2_fast(); |
3395 |
const u4 attribute_length = cfs->get_u4_fast(); |
|
1 | 3396 |
check_property( |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3397 |
valid_symbol_at(attribute_name_index), |
1 | 3398 |
"Attribute name has bad constant pool index %u in class file %s", |
3399 |
attribute_name_index, CHECK); |
|
34666 | 3400 |
const Symbol* const tag = cp->symbol_at(attribute_name_index); |
1 | 3401 |
if (tag == vmSymbols::tag_source_file()) { |
3402 |
// Check for SourceFile tag |
|
3403 |
if (_need_verify) { |
|
3404 |
guarantee_property(attribute_length == 2, "Wrong SourceFile attribute length in class file %s", CHECK); |
|
3405 |
} |
|
3406 |
if (parsed_sourcefile_attribute) { |
|
3407 |
classfile_parse_error("Multiple SourceFile attributes in class file %s", CHECK); |
|
3408 |
} else { |
|
3409 |
parsed_sourcefile_attribute = true; |
|
3410 |
} |
|
34666 | 3411 |
parse_classfile_sourcefile_attribute(cfs, CHECK); |
1 | 3412 |
} else if (tag == vmSymbols::tag_source_debug_extension()) { |
3413 |
// Check for SourceDebugExtension tag |
|
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3414 |
if (parsed_source_debug_ext_annotations_exist) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3415 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3416 |
"Multiple SourceDebugExtension attributes in class file %s", CHECK); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3417 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3418 |
parsed_source_debug_ext_annotations_exist = true; |
34666 | 3419 |
parse_classfile_source_debug_extension_attribute(cfs, (int)attribute_length, CHECK); |
1 | 3420 |
} else if (tag == vmSymbols::tag_inner_classes()) { |
3421 |
// Check for InnerClasses tag |
|
3422 |
if (parsed_innerclasses_attribute) { |
|
3423 |
classfile_parse_error("Multiple InnerClasses attributes in class file %s", CHECK); |
|
3424 |
} else { |
|
3425 |
parsed_innerclasses_attribute = true; |
|
3426 |
} |
|
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3427 |
inner_classes_attribute_start = cfs->current(); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3428 |
inner_classes_attribute_length = attribute_length; |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3429 |
cfs->skip_u1(inner_classes_attribute_length, CHECK); |
1 | 3430 |
} else if (tag == vmSymbols::tag_synthetic()) { |
3431 |
// Check for Synthetic tag |
|
3432 |
// Shouldn't we check that the synthetic flags wasn't already set? - not required in spec |
|
3433 |
if (attribute_length != 0) { |
|
3434 |
classfile_parse_error( |
|
3435 |
"Invalid Synthetic classfile attribute length %u in class file %s", |
|
3436 |
attribute_length, CHECK); |
|
3437 |
} |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3438 |
parse_classfile_synthetic_attribute(CHECK); |
1 | 3439 |
} else if (tag == vmSymbols::tag_deprecated()) { |
3440 |
// Check for Deprecatd tag - 4276120 |
|
3441 |
if (attribute_length != 0) { |
|
3442 |
classfile_parse_error( |
|
3443 |
"Invalid Deprecated classfile attribute length %u in class file %s", |
|
3444 |
attribute_length, CHECK); |
|
3445 |
} |
|
3446 |
} else if (_major_version >= JAVA_1_5_VERSION) { |
|
3447 |
if (tag == vmSymbols::tag_signature()) { |
|
44243
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
3448 |
if (_generic_signature_index != 0) { |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
3449 |
classfile_parse_error( |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
3450 |
"Multiple Signature attributes in class file %s", CHECK); |
bd6ac32eb679
8176147: JVM should throw CFE for duplicate Signature attributes
hseigel
parents:
44239
diff
changeset
|
3451 |
} |
1 | 3452 |
if (attribute_length != 2) { |
3453 |
classfile_parse_error( |
|
3454 |
"Wrong Signature attribute length %u in class file %s", |
|
3455 |
attribute_length, CHECK); |
|
3456 |
} |
|
34666 | 3457 |
parse_classfile_signature_attribute(cfs, CHECK); |
1 | 3458 |
} else if (tag == vmSymbols::tag_runtime_visible_annotations()) { |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3459 |
if (runtime_visible_annotations != NULL) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3460 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3461 |
"Multiple RuntimeVisibleAnnotations attributes in class file %s", CHECK); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3462 |
} |
1 | 3463 |
runtime_visible_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3464 |
runtime_visible_annotations = cfs->current(); |
1 | 3465 |
assert(runtime_visible_annotations != NULL, "null visible annotations"); |
43177 | 3466 |
cfs->guarantee_more(runtime_visible_annotations_length, CHECK); |
34666 | 3467 |
parse_annotations(cp, |
3468 |
runtime_visible_annotations, |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3469 |
runtime_visible_annotations_length, |
34666 | 3470 |
parsed_annotations, |
3471 |
_loader_data, |
|
3472 |
CHECK); |
|
43177 | 3473 |
cfs->skip_u1_fast(runtime_visible_annotations_length); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3474 |
} else if (tag == vmSymbols::tag_runtime_invisible_annotations()) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3475 |
if (runtime_invisible_annotations_exists) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3476 |
classfile_parse_error( |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3477 |
"Multiple RuntimeInvisibleAnnotations attributes in class file %s", CHECK); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3478 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3479 |
runtime_invisible_annotations_exists = true; |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3480 |
if (PreserveAllAnnotations) { |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3481 |
runtime_invisible_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3482 |
runtime_invisible_annotations = cfs->current(); |
24432
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3483 |
assert(runtime_invisible_annotations != NULL, "null invisible annotations"); |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3484 |
} |
482afb00f089
8040292: Annotation attributes must not appear more than once
hseigel
parents:
24322
diff
changeset
|
3485 |
cfs->skip_u1(attribute_length, CHECK); |
1 | 3486 |
} else if (tag == vmSymbols::tag_enclosing_method()) { |
3487 |
if (parsed_enclosingmethod_attribute) { |
|
3488 |
classfile_parse_error("Multiple EnclosingMethod attributes in class file %s", CHECK); |
|
25054
8a12137a8422
8044738: Check attribute_length of EnclosingMethod attribute
hseigel
parents:
24828
diff
changeset
|
3489 |
} else { |
1 | 3490 |
parsed_enclosingmethod_attribute = true; |
3491 |
} |
|
25054
8a12137a8422
8044738: Check attribute_length of EnclosingMethod attribute
hseigel
parents:
24828
diff
changeset
|
3492 |
guarantee_property(attribute_length == 4, |
8a12137a8422
8044738: Check attribute_length of EnclosingMethod attribute
hseigel
parents:
24828
diff
changeset
|
3493 |
"Wrong EnclosingMethod attribute length %u in class file %s", |
8a12137a8422
8044738: Check attribute_length of EnclosingMethod attribute
hseigel
parents:
24828
diff
changeset
|
3494 |
attribute_length, CHECK); |
1 | 3495 |
cfs->guarantee_more(4, CHECK); // class_index, method_index |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3496 |
enclosing_method_class_index = cfs->get_u2_fast(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3497 |
enclosing_method_method_index = cfs->get_u2_fast(); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3498 |
if (enclosing_method_class_index == 0) { |
1 | 3499 |
classfile_parse_error("Invalid class index in EnclosingMethod attribute in class file %s", CHECK); |
3500 |
} |
|
3501 |
// Validate the constant pool indices and types |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3502 |
check_property(valid_klass_reference_at(enclosing_method_class_index), |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3503 |
"Invalid or out-of-bounds class index in EnclosingMethod attribute in class file %s", CHECK); |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3504 |
if (enclosing_method_method_index != 0 && |
34666 | 3505 |
(!cp->is_within_bounds(enclosing_method_method_index) || |
3506 |
!cp->tag_at(enclosing_method_method_index).is_name_and_type())) { |
|
1 | 3507 |
classfile_parse_error("Invalid or out-of-bounds method index in EnclosingMethod attribute in class file %s", CHECK); |
3508 |
} |
|
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3509 |
} else if (tag == vmSymbols::tag_bootstrap_methods() && |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3510 |
_major_version >= Verifier::INVOKEDYNAMIC_MAJOR_VERSION) { |
38658
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
3511 |
if (parsed_bootstrap_methods_attribute) { |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3512 |
classfile_parse_error("Multiple BootstrapMethods attributes in class file %s", CHECK); |
38658
34f9c45625d8
8140594: Various minor code improvements (compiler)
goetz
parents:
38177
diff
changeset
|
3513 |
} |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3514 |
parsed_bootstrap_methods_attribute = true; |
34666 | 3515 |
parse_classfile_bootstrap_methods_attribute(cfs, cp, attribute_length, CHECK); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3516 |
} else if (tag == vmSymbols::tag_runtime_visible_type_annotations()) { |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3517 |
if (runtime_visible_type_annotations != NULL) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3518 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3519 |
"Multiple RuntimeVisibleTypeAnnotations attributes in class file %s", CHECK); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3520 |
} |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3521 |
runtime_visible_type_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3522 |
runtime_visible_type_annotations = cfs->current(); |
15097
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3523 |
assert(runtime_visible_type_annotations != NULL, "null visible type annotations"); |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3524 |
// No need for the VM to parse Type annotations |
9db149412e0e
8004823: Add VM support for type annotation reflection
stefank
parents:
14590
diff
changeset
|
3525 |
cfs->skip_u1(runtime_visible_type_annotations_length, CHECK); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3526 |
} else if (tag == vmSymbols::tag_runtime_invisible_type_annotations()) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3527 |
if (runtime_invisible_type_annotations_exists) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3528 |
classfile_parse_error( |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3529 |
"Multiple RuntimeInvisibleTypeAnnotations attributes in class file %s", CHECK); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3530 |
} else { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3531 |
runtime_invisible_type_annotations_exists = true; |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3532 |
} |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3533 |
if (PreserveAllAnnotations) { |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3534 |
runtime_invisible_type_annotations_length = attribute_length; |
46504
38048d4d20e7
8180032: Unaligned pointer dereference in ClassFileParser
mikael
parents:
46502
diff
changeset
|
3535 |
runtime_invisible_type_annotations = cfs->current(); |
19954
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3536 |
assert(runtime_invisible_type_annotations != NULL, "null invisible type annotations"); |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3537 |
} |
1642109d1a2c
8023167: JVM allows duplicate Runtime[In]VisibleTypeAnnotations attributes in ClassFile/field_info/method_info structures
hseigel
parents:
19681
diff
changeset
|
3538 |
cfs->skip_u1(attribute_length, CHECK); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3539 |
} else if (_major_version >= JAVA_11_VERSION) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3540 |
if (tag == vmSymbols::tag_nest_members()) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3541 |
// Check for NestMembers tag |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3542 |
if (parsed_nest_members_attribute) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3543 |
classfile_parse_error("Multiple NestMembers attributes in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3544 |
} else { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3545 |
parsed_nest_members_attribute = true; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3546 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3547 |
if (parsed_nest_host_attribute) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3548 |
classfile_parse_error("Conflicting NestHost and NestMembers attributes in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3549 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3550 |
nest_members_attribute_start = cfs->current(); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3551 |
nest_members_attribute_length = attribute_length; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3552 |
cfs->skip_u1(nest_members_attribute_length, CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3553 |
} else if (tag == vmSymbols::tag_nest_host()) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3554 |
if (parsed_nest_host_attribute) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3555 |
classfile_parse_error("Multiple NestHost attributes in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3556 |
} else { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3557 |
parsed_nest_host_attribute = true; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3558 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3559 |
if (parsed_nest_members_attribute) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3560 |
classfile_parse_error("Conflicting NestMembers and NestHost attributes in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3561 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3562 |
if (_need_verify) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3563 |
guarantee_property(attribute_length == 2, "Wrong NestHost attribute length in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3564 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3565 |
cfs->guarantee_more(2, CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3566 |
u2 class_info_index = cfs->get_u2_fast(); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3567 |
check_property( |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3568 |
valid_klass_reference_at(class_info_index), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3569 |
"Nest-host class_info_index %u has bad constant type in class file %s", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3570 |
class_info_index, CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3571 |
_nest_host = class_info_index; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3572 |
} |
1 | 3573 |
} else { |
3574 |
// Unknown attribute |
|
3575 |
cfs->skip_u1(attribute_length, CHECK); |
|
3576 |
} |
|
3577 |
} else { |
|
3578 |
// Unknown attribute |
|
3579 |
cfs->skip_u1(attribute_length, CHECK); |
|
3580 |
} |
|
3581 |
} |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3582 |
_annotations = assemble_annotations(runtime_visible_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3583 |
runtime_visible_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3584 |
runtime_invisible_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3585 |
runtime_invisible_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3586 |
CHECK); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3587 |
_type_annotations = assemble_annotations(runtime_visible_type_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3588 |
runtime_visible_type_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3589 |
runtime_invisible_type_annotations, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3590 |
runtime_invisible_type_annotations_length, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3591 |
CHECK); |
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3592 |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3593 |
if (parsed_innerclasses_attribute || parsed_enclosingmethod_attribute) { |
34666 | 3594 |
const u2 num_of_classes = parse_classfile_inner_classes_attribute( |
3595 |
cfs, |
|
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3596 |
inner_classes_attribute_start, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3597 |
parsed_innerclasses_attribute, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3598 |
enclosing_method_class_index, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3599 |
enclosing_method_method_index, |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3600 |
CHECK); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3601 |
if (parsed_innerclasses_attribute && _need_verify && _major_version >= JAVA_1_5_VERSION) { |
12231
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3602 |
guarantee_property( |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3603 |
inner_classes_attribute_length == sizeof(num_of_classes) + 4 * sizeof(u2) * num_of_classes, |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3604 |
"Wrong InnerClasses attribute length in class file %s", CHECK); |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3605 |
} |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3606 |
} |
6a9cfc59a18a
7109878: The instanceKlass EnclosingMethhod attribute fields can be folded into the _inner_class field.
jiangli
parents:
11423
diff
changeset
|
3607 |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3608 |
if (parsed_nest_members_attribute) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3609 |
const u2 num_of_classes = parse_classfile_nest_members_attribute( |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3610 |
cfs, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3611 |
nest_members_attribute_start, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3612 |
CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3613 |
if (_need_verify) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3614 |
guarantee_property( |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3615 |
nest_members_attribute_length == sizeof(num_of_classes) + sizeof(u2) * num_of_classes, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3616 |
"Wrong NestMembers attribute length in class file %s", CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3617 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3618 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3619 |
|
7436
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3620 |
if (_max_bootstrap_specifier_index >= 0) { |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3621 |
guarantee_property(parsed_bootstrap_methods_attribute, |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3622 |
"Missing BootstrapMethods attribute in class file %s", CHECK); |
dbc43da3d512
7001379: bootstrap method data needs to be moved from constant pool to a classfile attribute
jrose
parents:
7397
diff
changeset
|
3623 |
} |
1 | 3624 |
} |
3625 |
||
34666 | 3626 |
void ClassFileParser::apply_parsed_class_attributes(InstanceKlass* k) { |
3627 |
assert(k != NULL, "invariant"); |
|
3628 |
||
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3629 |
if (_synthetic_flag) |
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3630 |
k->set_is_synthetic(); |
19326
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3631 |
if (_sourcefile_index != 0) { |
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3632 |
k->set_source_file_name_index(_sourcefile_index); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3633 |
} |
19326
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3634 |
if (_generic_signature_index != 0) { |
14cb6cf26a96
8021948: Change InstanceKlass::_source_file_name and _generic_signature from Symbol* to constant pool indexes.
jiangli
parents:
18940
diff
changeset
|
3635 |
k->set_generic_signature_index(_generic_signature_index); |
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3636 |
} |
13295 | 3637 |
if (_sde_buffer != NULL) { |
3638 |
k->set_source_debug_extension(_sde_buffer, _sde_length); |
|
3639 |
} |
|
13291
9de3b1387cb8
6711908: JVM needs direct access to some annotations
jrose
parents:
12772
diff
changeset
|
3640 |
} |
1 | 3641 |
|
28027
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3642 |
// Create the Annotations object that will |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3643 |
// hold the annotations array for the Klass. |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3644 |
void ClassFileParser::create_combined_annotations(TRAPS) { |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3645 |
if (_annotations == NULL && |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3646 |
_type_annotations == NULL && |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3647 |
_fields_annotations == NULL && |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3648 |
_fields_type_annotations == NULL) { |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3649 |
// Don't create the Annotations object unnecessarily. |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3650 |
return; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3651 |
} |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3652 |
|
34666 | 3653 |
Annotations* const annotations = Annotations::allocate(_loader_data, CHECK); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3654 |
annotations->set_class_annotations(_annotations); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3655 |
annotations->set_class_type_annotations(_type_annotations); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3656 |
annotations->set_fields_annotations(_fields_annotations); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3657 |
annotations->set_fields_type_annotations(_fields_type_annotations); |
28027
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3658 |
|
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3659 |
// This is the Annotations object that will be |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3660 |
// assigned to InstanceKlass being constructed. |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3661 |
_combined_annotations = annotations; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3662 |
|
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3663 |
// The annotations arrays below has been transfered the |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3664 |
// _combined_annotations so these fields can now be cleared. |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3665 |
_annotations = NULL; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3666 |
_type_annotations = NULL; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3667 |
_fields_annotations = NULL; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3668 |
_fields_type_annotations = NULL; |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3669 |
} |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3670 |
|
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3671 |
// Transfer ownership of metadata allocated to the InstanceKlass. |
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3672 |
void ClassFileParser::apply_parsed_class_metadata( |
34666 | 3673 |
InstanceKlass* this_klass, |
28027
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3674 |
int java_fields_count, TRAPS) { |
34666 | 3675 |
assert(this_klass != NULL, "invariant"); |
3676 |
||
3677 |
_cp->set_pool_holder(this_klass); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3678 |
this_klass->set_constants(_cp); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3679 |
this_klass->set_fields(_fields, java_fields_count); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3680 |
this_klass->set_methods(_methods); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3681 |
this_klass->set_inner_classes(_inner_classes); |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3682 |
this_klass->set_nest_members(_nest_members); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
3683 |
this_klass->set_nest_host_index(_nest_host); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3684 |
this_klass->set_local_interfaces(_local_interfaces); |
28027
c63d0bb0101c
8065634: Crash in InstanceKlass::clean_method_data when _method is NULL
stefank
parents:
27685
diff
changeset
|
3685 |
this_klass->set_annotations(_combined_annotations); |
49948
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3686 |
// Delay the setting of _transitive_interfaces until after initialize_supers() in |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3687 |
// fill_instance_klass(). It is because the _transitive_interfaces may be shared with |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3688 |
// its _super. If an OOM occurs while loading the current klass, its _super field |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3689 |
// may not have been set. When GC tries to free the klass, the _transitive_interfaces |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3690 |
// may be deallocated mistakenly in InstanceKlass::deallocate_interfaces(). Subsequent |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
3691 |
// dereferences to the deallocated _transitive_interfaces will result in a crash. |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3692 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3693 |
// Clear out these fields so they don't get deallocated by the destructor |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3694 |
clear_class_metadata(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3695 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3696 |
|
34666 | 3697 |
AnnotationArray* ClassFileParser::assemble_annotations(const u1* const runtime_visible_annotations, |
13952
e3cf184080bc
8000213: NPG: Should have renamed arrayKlass and typeArrayKlass
coleenp
parents:
13738
diff
changeset
|
3698 |
int runtime_visible_annotations_length, |
34666 | 3699 |
const u1* const runtime_invisible_annotations, |
3700 |
int runtime_invisible_annotations_length, |
|
3701 |
TRAPS) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3702 |
AnnotationArray* annotations = NULL; |
1 | 3703 |
if (runtime_visible_annotations != NULL || |
3704 |
runtime_invisible_annotations != NULL) { |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3705 |
annotations = MetadataFactory::new_array<u1>(_loader_data, |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3706 |
runtime_visible_annotations_length + |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3707 |
runtime_invisible_annotations_length, |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3708 |
CHECK_(annotations)); |
1 | 3709 |
if (runtime_visible_annotations != NULL) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3710 |
for (int i = 0; i < runtime_visible_annotations_length; i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3711 |
annotations->at_put(i, runtime_visible_annotations[i]); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3712 |
} |
1 | 3713 |
} |
3714 |
if (runtime_invisible_annotations != NULL) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3715 |
for (int i = 0; i < runtime_invisible_annotations_length; i++) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3716 |
int append = runtime_visible_annotations_length+i; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3717 |
annotations->at_put(append, runtime_invisible_annotations[i]); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
3718 |
} |
1 | 3719 |
} |
3720 |
} |
|
3721 |
return annotations; |
|
3722 |
} |
|
3723 |
||
34666 | 3724 |
const InstanceKlass* ClassFileParser::parse_super_class(ConstantPool* const cp, |
3725 |
const int super_class_index, |
|
3726 |
const bool need_verify, |
|
3727 |
TRAPS) { |
|
3728 |
assert(cp != NULL, "invariant"); |
|
3729 |
const InstanceKlass* super_klass = NULL; |
|
3730 |
||
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3731 |
if (super_class_index == 0) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3732 |
check_property(_class_name == vmSymbols::java_lang_Object(), |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3733 |
"Invalid superclass index %u in class file %s", |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3734 |
super_class_index, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3735 |
CHECK_NULL); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3736 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3737 |
check_property(valid_klass_reference_at(super_class_index), |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3738 |
"Invalid superclass index %u in class file %s", |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3739 |
super_class_index, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3740 |
CHECK_NULL); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3741 |
// The class name should be legal because it is checked when parsing constant pool. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3742 |
// However, make sure it is not an array type. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3743 |
bool is_array = false; |
34666 | 3744 |
if (cp->tag_at(super_class_index).is_klass()) { |
3745 |
super_klass = InstanceKlass::cast(cp->resolved_klass_at(super_class_index)); |
|
3746 |
if (need_verify) |
|
33611
9abd65805e19
8139203: Consistent naming for klass type predicates
coleenp
parents:
33602
diff
changeset
|
3747 |
is_array = super_klass->is_array_klass(); |
34666 | 3748 |
} else if (need_verify) { |
3749 |
is_array = (cp->klass_name_at(super_class_index)->byte_at(0) == JVM_SIGNATURE_ARRAY); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3750 |
} |
34666 | 3751 |
if (need_verify) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3752 |
guarantee_property(!is_array, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3753 |
"Bad superclass name in class file %s", CHECK_NULL); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3754 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3755 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3756 |
return super_klass; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3757 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3758 |
|
34666 | 3759 |
static unsigned int compute_oop_map_count(const InstanceKlass* super, |
3760 |
unsigned int nonstatic_oop_map_count, |
|
3761 |
int first_nonstatic_oop_offset) { |
|
3762 |
||
3763 |
unsigned int map_count = |
|
3764 |
NULL == super ? 0 : super->nonstatic_oop_map_count(); |
|
3765 |
if (nonstatic_oop_map_count > 0) { |
|
3766 |
// We have oops to add to map |
|
3767 |
if (map_count == 0) { |
|
3768 |
map_count = nonstatic_oop_map_count; |
|
3769 |
} |
|
3770 |
else { |
|
3771 |
// Check whether we should add a new map block or whether the last one can |
|
3772 |
// be extended |
|
3773 |
const OopMapBlock* const first_map = super->start_of_nonstatic_oop_maps(); |
|
3774 |
const OopMapBlock* const last_map = first_map + map_count - 1; |
|
3775 |
||
3776 |
const int next_offset = last_map->offset() + last_map->count() * heapOopSize; |
|
3777 |
if (next_offset == first_nonstatic_oop_offset) { |
|
3778 |
// There is no gap bettwen superklass's last oop field and first |
|
3779 |
// local oop field, merge maps. |
|
3780 |
nonstatic_oop_map_count -= 1; |
|
3781 |
} |
|
3782 |
else { |
|
3783 |
// Superklass didn't end with a oop field, add extra maps |
|
3784 |
assert(next_offset < first_nonstatic_oop_offset, "just checking"); |
|
3785 |
} |
|
3786 |
map_count += nonstatic_oop_map_count; |
|
3787 |
} |
|
3788 |
} |
|
3789 |
return map_count; |
|
3790 |
} |
|
3791 |
||
3792 |
#ifndef PRODUCT |
|
3793 |
static void print_field_layout(const Symbol* name, |
|
3794 |
Array<u2>* fields, |
|
46727
6e4a84748e2c
8183039: Re-examine methodHandle methods uninlined by 8144256
coleenp
parents:
46701
diff
changeset
|
3795 |
const constantPoolHandle& cp, |
34666 | 3796 |
int instance_size, |
3797 |
int instance_fields_start, |
|
3798 |
int instance_fields_end, |
|
3799 |
int static_fields_end) { |
|
3800 |
||
3801 |
assert(name != NULL, "invariant"); |
|
3802 |
||
3803 |
tty->print("%s: field layout\n", name->as_klass_external_name()); |
|
3804 |
tty->print(" @%3d %s\n", instance_fields_start, "--- instance fields start ---"); |
|
3805 |
for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { |
|
3806 |
if (!fs.access_flags().is_static()) { |
|
3807 |
tty->print(" @%3d \"%s\" %s\n", |
|
3808 |
fs.offset(), |
|
3809 |
fs.name()->as_klass_external_name(), |
|
3810 |
fs.signature()->as_klass_external_name()); |
|
3811 |
} |
|
3812 |
} |
|
3813 |
tty->print(" @%3d %s\n", instance_fields_end, "--- instance fields end ---"); |
|
3814 |
tty->print(" @%3d %s\n", instance_size * wordSize, "--- instance ends ---"); |
|
3815 |
tty->print(" @%3d %s\n", InstanceMirrorKlass::offset_of_static_fields(), "--- static fields start ---"); |
|
3816 |
for (AllFieldStream fs(fields, cp); !fs.done(); fs.next()) { |
|
3817 |
if (fs.access_flags().is_static()) { |
|
3818 |
tty->print(" @%3d \"%s\" %s\n", |
|
3819 |
fs.offset(), |
|
3820 |
fs.name()->as_klass_external_name(), |
|
3821 |
fs.signature()->as_klass_external_name()); |
|
3822 |
} |
|
3823 |
} |
|
3824 |
tty->print(" @%3d %s\n", static_fields_end, "--- static fields end ---"); |
|
3825 |
tty->print("\n"); |
|
3826 |
} |
|
3827 |
#endif |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3828 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3829 |
// Values needed for oopmap and InstanceKlass creation |
34666 | 3830 |
class ClassFileParser::FieldLayoutInfo : public ResourceObj { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3831 |
public: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3832 |
int* nonstatic_oop_offsets; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3833 |
unsigned int* nonstatic_oop_counts; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3834 |
unsigned int nonstatic_oop_map_count; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3835 |
unsigned int total_oop_map_count; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3836 |
int instance_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3837 |
int nonstatic_field_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3838 |
int static_field_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3839 |
bool has_nonstatic_fields; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3840 |
}; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3841 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3842 |
// Layout fields and fill in FieldLayoutInfo. Could use more refactoring! |
34666 | 3843 |
void ClassFileParser::layout_fields(ConstantPool* cp, |
3844 |
const FieldAllocationCount* fac, |
|
3845 |
const ClassAnnotationCollector* parsed_annotations, |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3846 |
FieldLayoutInfo* info, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3847 |
TRAPS) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3848 |
|
34666 | 3849 |
assert(cp != NULL, "invariant"); |
3850 |
||
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3851 |
// Field size and offset computation |
34666 | 3852 |
int nonstatic_field_size = _super_klass == NULL ? 0 : |
3853 |
_super_klass->nonstatic_field_size(); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3854 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3855 |
// Count the contended fields by type. |
17612 | 3856 |
// |
3857 |
// We ignore static fields, because @Contended is not supported for them. |
|
3858 |
// The layout code below will also ignore the static fields. |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3859 |
int nonstatic_contended_count = 0; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3860 |
FieldAllocationCount fac_contended; |
34666 | 3861 |
for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3862 |
FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3863 |
if (fs.is_contended()) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3864 |
fac_contended.count[atype]++; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3865 |
if (!fs.access_flags().is_static()) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3866 |
nonstatic_contended_count++; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3867 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3868 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3869 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3870 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3871 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3872 |
// Calculate the starting byte offsets |
34666 | 3873 |
int next_static_oop_offset = InstanceMirrorKlass::offset_of_static_fields(); |
3874 |
int next_static_double_offset = next_static_oop_offset + |
|
3875 |
((fac->count[STATIC_OOP]) * heapOopSize); |
|
49359
59f6547e151f
8199264: Remove universe.inline.hpp to simplify include dependencies
stefank
parents:
49348
diff
changeset
|
3876 |
if (fac->count[STATIC_DOUBLE]) { |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
3877 |
next_static_double_offset = align_up(next_static_double_offset, BytesPerLong); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3878 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3879 |
|
34666 | 3880 |
int next_static_word_offset = next_static_double_offset + |
3881 |
((fac->count[STATIC_DOUBLE]) * BytesPerLong); |
|
3882 |
int next_static_short_offset = next_static_word_offset + |
|
3883 |
((fac->count[STATIC_WORD]) * BytesPerInt); |
|
3884 |
int next_static_byte_offset = next_static_short_offset + |
|
3885 |
((fac->count[STATIC_SHORT]) * BytesPerShort); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3886 |
|
17612 | 3887 |
int nonstatic_fields_start = instanceOopDesc::base_offset_in_bytes() + |
3888 |
nonstatic_field_size * heapOopSize; |
|
3889 |
||
34666 | 3890 |
int next_nonstatic_field_offset = nonstatic_fields_start; |
3891 |
||
3892 |
const bool is_contended_class = parsed_annotations->is_contended(); |
|
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3893 |
|
17612 | 3894 |
// Class is contended, pad before all the fields |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3895 |
if (is_contended_class) { |
17612 | 3896 |
next_nonstatic_field_offset += ContendedPaddingWidth; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3897 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3898 |
|
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3899 |
// Compute the non-contended fields count. |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3900 |
// The packing code below relies on these counts to determine if some field |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3901 |
// can be squeezed into the alignment gap. Contended fields are obviously |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3902 |
// exempt from that. |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3903 |
unsigned int nonstatic_double_count = fac->count[NONSTATIC_DOUBLE] - fac_contended.count[NONSTATIC_DOUBLE]; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3904 |
unsigned int nonstatic_word_count = fac->count[NONSTATIC_WORD] - fac_contended.count[NONSTATIC_WORD]; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3905 |
unsigned int nonstatic_short_count = fac->count[NONSTATIC_SHORT] - fac_contended.count[NONSTATIC_SHORT]; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3906 |
unsigned int nonstatic_byte_count = fac->count[NONSTATIC_BYTE] - fac_contended.count[NONSTATIC_BYTE]; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3907 |
unsigned int nonstatic_oop_count = fac->count[NONSTATIC_OOP] - fac_contended.count[NONSTATIC_OOP]; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3908 |
|
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3909 |
// Total non-static fields count, including every contended field |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3910 |
unsigned int nonstatic_fields_count = fac->count[NONSTATIC_DOUBLE] + fac->count[NONSTATIC_WORD] + |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3911 |
fac->count[NONSTATIC_SHORT] + fac->count[NONSTATIC_BYTE] + |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3912 |
fac->count[NONSTATIC_OOP]; |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3913 |
|
34666 | 3914 |
const bool super_has_nonstatic_fields = |
3915 |
(_super_klass != NULL && _super_klass->has_nonstatic_fields()); |
|
3916 |
const bool has_nonstatic_fields = |
|
3917 |
super_has_nonstatic_fields || (nonstatic_fields_count != 0); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3918 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3919 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3920 |
// Prepare list of oops for oop map generation. |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3921 |
// |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3922 |
// "offset" and "count" lists are describing the set of contiguous oop |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3923 |
// regions. offset[i] is the start of the i-th region, which then has |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3924 |
// count[i] oops following. Before we know how many regions are required, |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3925 |
// we pessimistically allocate the maps to fit all the oops into the |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3926 |
// distinct regions. |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3927 |
// |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3928 |
// TODO: We add +1 to always allocate non-zero resource arrays; we need |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3929 |
// to figure out if we still need to do this. |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3930 |
unsigned int nonstatic_oop_map_count = 0; |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3931 |
unsigned int max_nonstatic_oop_maps = fac->count[NONSTATIC_OOP] + 1; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3932 |
|
34666 | 3933 |
int* nonstatic_oop_offsets = NEW_RESOURCE_ARRAY_IN_THREAD( |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3934 |
THREAD, int, max_nonstatic_oop_maps); |
34666 | 3935 |
unsigned int* const nonstatic_oop_counts = NEW_RESOURCE_ARRAY_IN_THREAD( |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
3936 |
THREAD, unsigned int, max_nonstatic_oop_maps); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3937 |
|
34666 | 3938 |
int first_nonstatic_oop_offset = 0; // will be set for first oop field |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3939 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3940 |
bool compact_fields = CompactFields; |
34666 | 3941 |
int allocation_style = FieldsAllocationStyle; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3942 |
if( allocation_style < 0 || allocation_style > 2 ) { // Out of range? |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3943 |
assert(false, "0 <= FieldsAllocationStyle <= 2"); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3944 |
allocation_style = 1; // Optimistic |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3945 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3946 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3947 |
// The next classes have predefined hard-coded fields offsets |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3948 |
// (see in JavaClasses::compute_hard_coded_offsets()). |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3949 |
// Use default fields allocation order for them. |
34666 | 3950 |
if( (allocation_style != 0 || compact_fields ) && _loader_data->class_loader() == NULL && |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3951 |
(_class_name == vmSymbols::java_lang_AssertionStatusDirectives() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3952 |
_class_name == vmSymbols::java_lang_Class() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3953 |
_class_name == vmSymbols::java_lang_ClassLoader() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3954 |
_class_name == vmSymbols::java_lang_ref_Reference() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3955 |
_class_name == vmSymbols::java_lang_ref_SoftReference() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3956 |
_class_name == vmSymbols::java_lang_StackTraceElement() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3957 |
_class_name == vmSymbols::java_lang_String() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3958 |
_class_name == vmSymbols::java_lang_Throwable() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3959 |
_class_name == vmSymbols::java_lang_Boolean() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3960 |
_class_name == vmSymbols::java_lang_Character() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3961 |
_class_name == vmSymbols::java_lang_Float() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3962 |
_class_name == vmSymbols::java_lang_Double() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3963 |
_class_name == vmSymbols::java_lang_Byte() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3964 |
_class_name == vmSymbols::java_lang_Short() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3965 |
_class_name == vmSymbols::java_lang_Integer() || |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3966 |
_class_name == vmSymbols::java_lang_Long())) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3967 |
allocation_style = 0; // Allocate oops first |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3968 |
compact_fields = false; // Don't compact fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3969 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3970 |
|
34666 | 3971 |
int next_nonstatic_oop_offset = 0; |
3972 |
int next_nonstatic_double_offset = 0; |
|
3973 |
||
17612 | 3974 |
// Rearrange fields for a given allocation style |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3975 |
if( allocation_style == 0 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3976 |
// Fields order: oops, longs/doubles, ints, shorts/chars, bytes, padded fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3977 |
next_nonstatic_oop_offset = next_nonstatic_field_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3978 |
next_nonstatic_double_offset = next_nonstatic_oop_offset + |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3979 |
(nonstatic_oop_count * heapOopSize); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3980 |
} else if( allocation_style == 1 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3981 |
// Fields order: longs/doubles, ints, shorts/chars, bytes, oops, padded fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3982 |
next_nonstatic_double_offset = next_nonstatic_field_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3983 |
} else if( allocation_style == 2 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3984 |
// Fields allocation: oops fields in super and sub classes are together. |
34666 | 3985 |
if( nonstatic_field_size > 0 && _super_klass != NULL && |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3986 |
_super_klass->nonstatic_oop_map_size() > 0 ) { |
34666 | 3987 |
const unsigned int map_count = _super_klass->nonstatic_oop_map_count(); |
3988 |
const OopMapBlock* const first_map = _super_klass->start_of_nonstatic_oop_maps(); |
|
3989 |
const OopMapBlock* const last_map = first_map + map_count - 1; |
|
3990 |
const int next_offset = last_map->offset() + (last_map->count() * heapOopSize); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3991 |
if (next_offset == next_nonstatic_field_offset) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3992 |
allocation_style = 0; // allocate oops first |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3993 |
next_nonstatic_oop_offset = next_nonstatic_field_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3994 |
next_nonstatic_double_offset = next_nonstatic_oop_offset + |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3995 |
(nonstatic_oop_count * heapOopSize); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3996 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3997 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3998 |
if( allocation_style == 2 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
3999 |
allocation_style = 1; // allocate oops last |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4000 |
next_nonstatic_double_offset = next_nonstatic_field_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4001 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4002 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4003 |
ShouldNotReachHere(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4004 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4005 |
|
34666 | 4006 |
int nonstatic_oop_space_count = 0; |
4007 |
int nonstatic_word_space_count = 0; |
|
4008 |
int nonstatic_short_space_count = 0; |
|
4009 |
int nonstatic_byte_space_count = 0; |
|
4010 |
int nonstatic_oop_space_offset = 0; |
|
4011 |
int nonstatic_word_space_offset = 0; |
|
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33230
diff
changeset
|
4012 |
int nonstatic_short_space_offset = 0; |
34666 | 4013 |
int nonstatic_byte_space_offset = 0; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4014 |
|
17612 | 4015 |
// Try to squeeze some of the fields into the gaps due to |
4016 |
// long/double alignment. |
|
34666 | 4017 |
if (nonstatic_double_count > 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4018 |
int offset = next_nonstatic_double_offset; |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4019 |
next_nonstatic_double_offset = align_up(offset, BytesPerLong); |
34666 | 4020 |
if (compact_fields && offset != next_nonstatic_double_offset) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4021 |
// Allocate available fields into the gap before double field. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4022 |
int length = next_nonstatic_double_offset - offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4023 |
assert(length == BytesPerInt, ""); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4024 |
nonstatic_word_space_offset = offset; |
34666 | 4025 |
if (nonstatic_word_count > 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4026 |
nonstatic_word_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4027 |
nonstatic_word_space_count = 1; // Only one will fit |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4028 |
length -= BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4029 |
offset += BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4030 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4031 |
nonstatic_short_space_offset = offset; |
34666 | 4032 |
while (length >= BytesPerShort && nonstatic_short_count > 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4033 |
nonstatic_short_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4034 |
nonstatic_short_space_count += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4035 |
length -= BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4036 |
offset += BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4037 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4038 |
nonstatic_byte_space_offset = offset; |
34666 | 4039 |
while (length > 0 && nonstatic_byte_count > 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4040 |
nonstatic_byte_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4041 |
nonstatic_byte_space_count += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4042 |
length -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4043 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4044 |
// Allocate oop field in the gap if there are no other fields for that. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4045 |
nonstatic_oop_space_offset = offset; |
34666 | 4046 |
if (length >= heapOopSize && nonstatic_oop_count > 0 && |
4047 |
allocation_style != 0) { // when oop fields not first |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4048 |
nonstatic_oop_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4049 |
nonstatic_oop_space_count = 1; // Only one will fit |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4050 |
length -= heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4051 |
offset += heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4052 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4053 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4054 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4055 |
|
34666 | 4056 |
int next_nonstatic_word_offset = next_nonstatic_double_offset + |
4057 |
(nonstatic_double_count * BytesPerLong); |
|
4058 |
int next_nonstatic_short_offset = next_nonstatic_word_offset + |
|
4059 |
(nonstatic_word_count * BytesPerInt); |
|
4060 |
int next_nonstatic_byte_offset = next_nonstatic_short_offset + |
|
4061 |
(nonstatic_short_count * BytesPerShort); |
|
4062 |
int next_nonstatic_padded_offset = next_nonstatic_byte_offset + |
|
4063 |
nonstatic_byte_count; |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4064 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4065 |
// let oops jump before padding with this allocation style |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4066 |
if( allocation_style == 1 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4067 |
next_nonstatic_oop_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4068 |
if( nonstatic_oop_count > 0 ) { |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4069 |
next_nonstatic_oop_offset = align_up(next_nonstatic_oop_offset, heapOopSize); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4070 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4071 |
next_nonstatic_padded_offset = next_nonstatic_oop_offset + (nonstatic_oop_count * heapOopSize); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4072 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4073 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4074 |
// Iterate over fields again and compute correct offsets. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4075 |
// The field allocation type was temporarily stored in the offset slot. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4076 |
// oop fields are located before non-oop fields (static and non-static). |
34666 | 4077 |
for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4078 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4079 |
// skip already laid out fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4080 |
if (fs.is_offset_set()) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4081 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4082 |
// contended instance fields are handled below |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4083 |
if (fs.is_contended() && !fs.access_flags().is_static()) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4084 |
|
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33230
diff
changeset
|
4085 |
int real_offset = 0; |
34666 | 4086 |
const FieldAllocationType atype = (const FieldAllocationType) fs.allocation_type(); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4087 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4088 |
// pack the rest of the fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4089 |
switch (atype) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4090 |
case STATIC_OOP: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4091 |
real_offset = next_static_oop_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4092 |
next_static_oop_offset += heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4093 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4094 |
case STATIC_BYTE: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4095 |
real_offset = next_static_byte_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4096 |
next_static_byte_offset += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4097 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4098 |
case STATIC_SHORT: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4099 |
real_offset = next_static_short_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4100 |
next_static_short_offset += BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4101 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4102 |
case STATIC_WORD: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4103 |
real_offset = next_static_word_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4104 |
next_static_word_offset += BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4105 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4106 |
case STATIC_DOUBLE: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4107 |
real_offset = next_static_double_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4108 |
next_static_double_offset += BytesPerLong; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4109 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4110 |
case NONSTATIC_OOP: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4111 |
if( nonstatic_oop_space_count > 0 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4112 |
real_offset = nonstatic_oop_space_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4113 |
nonstatic_oop_space_offset += heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4114 |
nonstatic_oop_space_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4115 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4116 |
real_offset = next_nonstatic_oop_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4117 |
next_nonstatic_oop_offset += heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4118 |
} |
27616
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4119 |
|
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4120 |
// Record this oop in the oop maps |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4121 |
if( nonstatic_oop_map_count > 0 && |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4122 |
nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4123 |
real_offset - |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4124 |
int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4125 |
heapOopSize ) { |
27616
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4126 |
// This oop is adjacent to the previous one, add to current oop map |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4127 |
assert(nonstatic_oop_map_count - 1 < max_nonstatic_oop_maps, "range check"); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4128 |
nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4129 |
} else { |
27616
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4130 |
// This oop is not adjacent to the previous one, create new oop map |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4131 |
assert(nonstatic_oop_map_count < max_nonstatic_oop_maps, "range check"); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4132 |
nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4133 |
nonstatic_oop_counts [nonstatic_oop_map_count] = 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4134 |
nonstatic_oop_map_count += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4135 |
if( first_nonstatic_oop_offset == 0 ) { // Undefined |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4136 |
first_nonstatic_oop_offset = real_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4137 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4138 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4139 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4140 |
case NONSTATIC_BYTE: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4141 |
if( nonstatic_byte_space_count > 0 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4142 |
real_offset = nonstatic_byte_space_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4143 |
nonstatic_byte_space_offset += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4144 |
nonstatic_byte_space_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4145 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4146 |
real_offset = next_nonstatic_byte_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4147 |
next_nonstatic_byte_offset += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4148 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4149 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4150 |
case NONSTATIC_SHORT: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4151 |
if( nonstatic_short_space_count > 0 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4152 |
real_offset = nonstatic_short_space_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4153 |
nonstatic_short_space_offset += BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4154 |
nonstatic_short_space_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4155 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4156 |
real_offset = next_nonstatic_short_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4157 |
next_nonstatic_short_offset += BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4158 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4159 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4160 |
case NONSTATIC_WORD: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4161 |
if( nonstatic_word_space_count > 0 ) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4162 |
real_offset = nonstatic_word_space_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4163 |
nonstatic_word_space_offset += BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4164 |
nonstatic_word_space_count -= 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4165 |
} else { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4166 |
real_offset = next_nonstatic_word_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4167 |
next_nonstatic_word_offset += BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4168 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4169 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4170 |
case NONSTATIC_DOUBLE: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4171 |
real_offset = next_nonstatic_double_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4172 |
next_nonstatic_double_offset += BytesPerLong; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4173 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4174 |
default: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4175 |
ShouldNotReachHere(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4176 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4177 |
fs.set_offset(real_offset); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4178 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4179 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4180 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4181 |
// Handle the contended cases. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4182 |
// |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4183 |
// Each contended field should not intersect the cache line with another contended field. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4184 |
// In the absence of alignment information, we end up with pessimistically separating |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4185 |
// the fields with full-width padding. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4186 |
// |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4187 |
// Additionally, this should not break alignment for the fields, so we round the alignment up |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4188 |
// for each field. |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4189 |
if (nonstatic_contended_count > 0) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4190 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4191 |
// if there is at least one contended field, we need to have pre-padding for them |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4192 |
next_nonstatic_padded_offset += ContendedPaddingWidth; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4193 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4194 |
// collect all contended groups |
38177 | 4195 |
ResourceBitMap bm(cp->size()); |
34666 | 4196 |
for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4197 |
// skip already laid out fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4198 |
if (fs.is_offset_set()) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4199 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4200 |
if (fs.is_contended()) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4201 |
bm.set_bit(fs.contended_group()); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4202 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4203 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4204 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4205 |
int current_group = -1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4206 |
while ((current_group = (int)bm.get_next_one_offset(current_group + 1)) != (int)bm.size()) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4207 |
|
34666 | 4208 |
for (AllFieldStream fs(_fields, cp); !fs.done(); fs.next()) { |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4209 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4210 |
// skip already laid out fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4211 |
if (fs.is_offset_set()) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4212 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4213 |
// skip non-contended fields and fields from different group |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4214 |
if (!fs.is_contended() || (fs.contended_group() != current_group)) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4215 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4216 |
// handle statics below |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4217 |
if (fs.access_flags().is_static()) continue; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4218 |
|
33589
7cbd1b2c139b
8139040: Fix initializations before ShouldNotReachHere() etc. and enable -Wuninitialized on linux.
goetz
parents:
33230
diff
changeset
|
4219 |
int real_offset = 0; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4220 |
FieldAllocationType atype = (FieldAllocationType) fs.allocation_type(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4221 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4222 |
switch (atype) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4223 |
case NONSTATIC_BYTE: |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4224 |
next_nonstatic_padded_offset = align_up(next_nonstatic_padded_offset, 1); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4225 |
real_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4226 |
next_nonstatic_padded_offset += 1; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4227 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4228 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4229 |
case NONSTATIC_SHORT: |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4230 |
next_nonstatic_padded_offset = align_up(next_nonstatic_padded_offset, BytesPerShort); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4231 |
real_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4232 |
next_nonstatic_padded_offset += BytesPerShort; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4233 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4234 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4235 |
case NONSTATIC_WORD: |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4236 |
next_nonstatic_padded_offset = align_up(next_nonstatic_padded_offset, BytesPerInt); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4237 |
real_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4238 |
next_nonstatic_padded_offset += BytesPerInt; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4239 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4240 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4241 |
case NONSTATIC_DOUBLE: |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4242 |
next_nonstatic_padded_offset = align_up(next_nonstatic_padded_offset, BytesPerLong); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4243 |
real_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4244 |
next_nonstatic_padded_offset += BytesPerLong; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4245 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4246 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4247 |
case NONSTATIC_OOP: |
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4248 |
next_nonstatic_padded_offset = align_up(next_nonstatic_padded_offset, heapOopSize); |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4249 |
real_offset = next_nonstatic_padded_offset; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4250 |
next_nonstatic_padded_offset += heapOopSize; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4251 |
|
27616
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4252 |
// Record this oop in the oop maps |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4253 |
if( nonstatic_oop_map_count > 0 && |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4254 |
nonstatic_oop_offsets[nonstatic_oop_map_count - 1] == |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4255 |
real_offset - |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4256 |
int(nonstatic_oop_counts[nonstatic_oop_map_count - 1]) * |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4257 |
heapOopSize ) { |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4258 |
// This oop is adjacent to the previous one, add to current oop map |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4259 |
assert(nonstatic_oop_map_count - 1 < max_nonstatic_oop_maps, "range check"); |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4260 |
nonstatic_oop_counts[nonstatic_oop_map_count - 1] += 1; |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4261 |
} else { |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4262 |
// This oop is not adjacent to the previous one, create new oop map |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4263 |
assert(nonstatic_oop_map_count < max_nonstatic_oop_maps, "range check"); |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4264 |
nonstatic_oop_offsets[nonstatic_oop_map_count] = real_offset; |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4265 |
nonstatic_oop_counts [nonstatic_oop_map_count] = 1; |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4266 |
nonstatic_oop_map_count += 1; |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4267 |
if( first_nonstatic_oop_offset == 0 ) { // Undefined |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4268 |
first_nonstatic_oop_offset = real_offset; |
6a63de6a8276
8015272: Make @Contended within the same group to use the same oop map
shade
parents:
27612
diff
changeset
|
4269 |
} |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4270 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4271 |
break; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4272 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4273 |
default: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4274 |
ShouldNotReachHere(); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4275 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4276 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4277 |
if (fs.contended_group() == 0) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4278 |
// Contended group defines the equivalence class over the fields: |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4279 |
// the fields within the same contended group are not inter-padded. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4280 |
// The only exception is default group, which does not incur the |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4281 |
// equivalence, and so requires intra-padding. |
17612 | 4282 |
next_nonstatic_padded_offset += ContendedPaddingWidth; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4283 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4284 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4285 |
fs.set_offset(real_offset); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4286 |
} // for |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4287 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4288 |
// Start laying out the next group. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4289 |
// Note that this will effectively pad the last group in the back; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4290 |
// this is expected to alleviate memory contention effects for |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4291 |
// subclass fields and/or adjacent object. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4292 |
// If this was the default group, the padding is already in place. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4293 |
if (current_group != 0) { |
17612 | 4294 |
next_nonstatic_padded_offset += ContendedPaddingWidth; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4295 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4296 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4297 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4298 |
// handle static fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4299 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4300 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4301 |
// Entire class is contended, pad in the back. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4302 |
// This helps to alleviate memory contention effects for subclass fields |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4303 |
// and/or adjacent object. |
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4304 |
if (is_contended_class) { |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4305 |
next_nonstatic_padded_offset += ContendedPaddingWidth; |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4306 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4307 |
|
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4308 |
int notaligned_nonstatic_fields_end = next_nonstatic_padded_offset; |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4309 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4310 |
int nonstatic_fields_end = align_up(notaligned_nonstatic_fields_end, heapOopSize); |
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4311 |
int instance_end = align_up(notaligned_nonstatic_fields_end, wordSize); |
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4312 |
int static_fields_end = align_up(next_static_byte_offset, wordSize); |
17612 | 4313 |
|
4314 |
int static_field_size = (static_fields_end - |
|
4315 |
InstanceMirrorKlass::offset_of_static_fields()) / wordSize; |
|
4316 |
nonstatic_field_size = nonstatic_field_size + |
|
4317 |
(nonstatic_fields_end - nonstatic_fields_start) / heapOopSize; |
|
4318 |
||
4319 |
int instance_size = align_object_size(instance_end / wordSize); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4320 |
|
46619
a3919f5e8d2b
8178499: Remove _ptr_ and _size_ infixes from align functions
stefank
parents:
46513
diff
changeset
|
4321 |
assert(instance_size == align_object_size(align_up( |
17601
0db4dfbb42ca
8012939: @Contended doesn't work correctly with inheritance
shade
parents:
17374
diff
changeset
|
4322 |
(instanceOopDesc::base_offset_in_bytes() + nonstatic_field_size*heapOopSize), |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4323 |
wordSize) / wordSize), "consistent layout helper value"); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4324 |
|
17831
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4325 |
// Invariant: nonstatic_field end/start should only change if there are |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4326 |
// nonstatic fields in the class, or if the class is contended. We compare |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4327 |
// against the non-aligned value, so that end alignment will not fail the |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4328 |
// assert without actually having the fields. |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4329 |
assert((notaligned_nonstatic_fields_end == nonstatic_fields_start) || |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4330 |
is_contended_class || |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4331 |
(nonstatic_fields_count > 0), "double-check nonstatic start/end"); |
d8112d90739f
8015270: @Contended: fix multiple issues in the layout code
shade
parents:
17826
diff
changeset
|
4332 |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4333 |
// Number of non-static oop map blocks allocated at end of klass. |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4334 |
const unsigned int total_oop_map_count = |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4335 |
compute_oop_map_count(_super_klass, nonstatic_oop_map_count, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4336 |
first_nonstatic_oop_offset); |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4337 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4338 |
#ifndef PRODUCT |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4339 |
if (PrintFieldLayout) { |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4340 |
print_field_layout(_class_name, |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4341 |
_fields, |
34666 | 4342 |
cp, |
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4343 |
instance_size, |
17612 | 4344 |
nonstatic_fields_start, |
4345 |
nonstatic_fields_end, |
|
4346 |
static_fields_end); |
|
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4347 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4348 |
|
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4349 |
#endif |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4350 |
// Pass back information needed for InstanceKlass creation |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4351 |
info->nonstatic_oop_offsets = nonstatic_oop_offsets; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4352 |
info->nonstatic_oop_counts = nonstatic_oop_counts; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4353 |
info->nonstatic_oop_map_count = nonstatic_oop_map_count; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4354 |
info->total_oop_map_count = total_oop_map_count; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4355 |
info->instance_size = instance_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4356 |
info->static_field_size = static_field_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4357 |
info->nonstatic_field_size = nonstatic_field_size; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4358 |
info->has_nonstatic_fields = has_nonstatic_fields; |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4359 |
} |
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4360 |
|
34666 | 4361 |
static void fill_oop_maps(const InstanceKlass* k, |
4362 |
unsigned int nonstatic_oop_map_count, |
|
4363 |
const int* nonstatic_oop_offsets, |
|
4364 |
const unsigned int* nonstatic_oop_counts) { |
|
4365 |
||
4366 |
assert(k != NULL, "invariant"); |
|
4367 |
||
1 | 4368 |
OopMapBlock* this_oop_map = k->start_of_nonstatic_oop_maps(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4369 |
const InstanceKlass* const super = k->superklass(); |
3694
942b7bc7f28c
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
3693
diff
changeset
|
4370 |
const unsigned int super_count = super ? super->nonstatic_oop_map_count() : 0; |
3693 | 4371 |
if (super_count > 0) { |
4372 |
// Copy maps from superklass |
|
1 | 4373 |
OopMapBlock* super_oop_map = super->start_of_nonstatic_oop_maps(); |
3694
942b7bc7f28c
6845368: large objects cause a crash or unexpected exception
jcoomes
parents:
3693
diff
changeset
|
4374 |
for (unsigned int i = 0; i < super_count; ++i) { |
1 | 4375 |
*this_oop_map++ = *super_oop_map++; |
4376 |
} |
|
4377 |
} |
|
3693 | 4378 |
|
1 | 4379 |
if (nonstatic_oop_map_count > 0) { |
3693 | 4380 |
if (super_count + nonstatic_oop_map_count > k->nonstatic_oop_map_count()) { |
4381 |
// The counts differ because there is no gap between superklass's last oop |
|
4382 |
// field and the first local oop field. Extend the last oop map copied |
|
1 | 4383 |
// from the superklass instead of creating new one. |
4384 |
nonstatic_oop_map_count--; |
|
4385 |
nonstatic_oop_offsets++; |
|
4386 |
this_oop_map--; |
|
3693 | 4387 |
this_oop_map->set_count(this_oop_map->count() + *nonstatic_oop_counts++); |
1 | 4388 |
this_oop_map++; |
4389 |
} |
|
3693 | 4390 |
|
1 | 4391 |
// Add new map blocks, fill them |
4392 |
while (nonstatic_oop_map_count-- > 0) { |
|
4393 |
this_oop_map->set_offset(*nonstatic_oop_offsets++); |
|
3693 | 4394 |
this_oop_map->set_count(*nonstatic_oop_counts++); |
1 | 4395 |
this_oop_map++; |
4396 |
} |
|
3693 | 4397 |
assert(k->start_of_nonstatic_oop_maps() + k->nonstatic_oop_map_count() == |
4398 |
this_oop_map, "sanity"); |
|
1 | 4399 |
} |
4400 |
} |
|
4401 |
||
4402 |
||
34666 | 4403 |
void ClassFileParser::set_precomputed_flags(InstanceKlass* ik) { |
4404 |
assert(ik != NULL, "invariant"); |
|
4405 |
||
4406 |
const Klass* const super = ik->super(); |
|
1 | 4407 |
|
4408 |
// Check if this klass has an empty finalize method (i.e. one with return bytecode only), |
|
4409 |
// in which case we don't have to register objects as finalizable |
|
4410 |
if (!_has_empty_finalizer) { |
|
4411 |
if (_has_finalizer || |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4412 |
(super != NULL && super->has_finalizer())) { |
34666 | 4413 |
ik->set_has_finalizer(); |
1 | 4414 |
} |
4415 |
} |
|
4416 |
||
4417 |
#ifdef ASSERT |
|
4418 |
bool f = false; |
|
34666 | 4419 |
const Method* const m = ik->lookup_method(vmSymbols::finalize_method_name(), |
4420 |
vmSymbols::void_method_signature()); |
|
1 | 4421 |
if (m != NULL && !m->is_empty_method()) { |
24828
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4422 |
f = true; |
1 | 4423 |
} |
24828
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4424 |
|
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4425 |
// Spec doesn't prevent agent from redefinition of empty finalizer. |
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4426 |
// Despite the fact that it's generally bad idea and redefined finalizer |
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4427 |
// will not work as expected we shouldn't abort vm in this case |
34666 | 4428 |
if (!ik->has_redefined_this_or_super()) { |
4429 |
assert(ik->has_finalizer() == f, "inconsistent has_finalizer"); |
|
24828
dd5406c950a1
6904403: assert(f == k->has_finalizer(),"inconsistent has_finalizer") with debug VM
dsamersoff
parents:
24454
diff
changeset
|
4430 |
} |
1 | 4431 |
#endif |
4432 |
||
4433 |
// Check if this klass supports the java.lang.Cloneable interface |
|
4571 | 4434 |
if (SystemDictionary::Cloneable_klass_loaded()) { |
34666 | 4435 |
if (ik->is_subtype_of(SystemDictionary::Cloneable_klass())) { |
4436 |
ik->set_is_cloneable(); |
|
1 | 4437 |
} |
4438 |
} |
|
4439 |
||
4440 |
// Check if this klass has a vanilla default constructor |
|
4441 |
if (super == NULL) { |
|
4442 |
// java.lang.Object has empty default constructor |
|
34666 | 4443 |
ik->set_has_vanilla_constructor(); |
1 | 4444 |
} else { |
14488 | 4445 |
if (super->has_vanilla_constructor() && |
1 | 4446 |
_has_vanilla_constructor) { |
34666 | 4447 |
ik->set_has_vanilla_constructor(); |
1 | 4448 |
} |
4449 |
#ifdef ASSERT |
|
4450 |
bool v = false; |
|
14488 | 4451 |
if (super->has_vanilla_constructor()) { |
34666 | 4452 |
const Method* const constructor = |
4453 |
ik->find_method(vmSymbols::object_initializer_name(), |
|
4454 |
vmSymbols::void_method_signature()); |
|
1 | 4455 |
if (constructor != NULL && constructor->is_vanilla_constructor()) { |
4456 |
v = true; |
|
4457 |
} |
|
4458 |
} |
|
34666 | 4459 |
assert(v == ik->has_vanilla_constructor(), "inconsistent has_vanilla_constructor"); |
1 | 4460 |
#endif |
4461 |
} |
|
4462 |
||
4463 |
// If it cannot be fast-path allocated, set a bit in the layout helper. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4464 |
// See documentation of InstanceKlass::can_be_fastpath_allocated(). |
34666 | 4465 |
assert(ik->size_helper() > 0, "layout_helper is initialized"); |
4466 |
if ((!RegisterFinalizersAtInit && ik->has_finalizer()) |
|
4467 |
|| ik->is_abstract() || ik->is_interface() |
|
4468 |
|| (ik->name() == vmSymbols::java_lang_Class() && ik->class_loader() == NULL) |
|
4469 |
|| ik->size_helper() >= FastAllocateSizeLimit) { |
|
1 | 4470 |
// Forbid fast-path allocation. |
34666 | 4471 |
const jint lh = Klass::instance_layout_helper(ik->size_helper(), true); |
4472 |
ik->set_layout_helper(lh); |
|
1 | 4473 |
} |
4474 |
} |
|
4475 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4476 |
// Attach super classes and interface classes to class loader data |
34666 | 4477 |
static void record_defined_class_dependencies(const InstanceKlass* defined_klass, |
4478 |
TRAPS) { |
|
4479 |
assert(defined_klass != NULL, "invariant"); |
|
4480 |
||
4481 |
ClassLoaderData* const defining_loader_data = defined_klass->class_loader_data(); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4482 |
if (defining_loader_data->is_the_null_class_loader_data()) { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4483 |
// Dependencies to null class loader data are implicit. |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4484 |
return; |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4485 |
} else { |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4486 |
// add super class dependency |
34666 | 4487 |
Klass* const super = defined_klass->super(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4488 |
if (super != NULL) { |
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
4489 |
defining_loader_data->record_dependency(super); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4490 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4491 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4492 |
// add super interface dependencies |
34666 | 4493 |
const Array<Klass*>* const local_interfaces = defined_klass->local_interfaces(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4494 |
if (local_interfaces != NULL) { |
34666 | 4495 |
const int length = local_interfaces->length(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4496 |
for (int i = 0; i < length; i++) { |
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
4497 |
defining_loader_data->record_dependency(local_interfaces->at(i)); |
1 | 4498 |
} |
4499 |
} |
|
4500 |
} |
|
4501 |
} |
|
4502 |
||
15935
50da9e5eb858
8003419: NPG: Clean up metadata created during class loading if failure
coleenp
parents:
15932
diff
changeset
|
4503 |
// utility methods for appending an array with check for duplicates |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4504 |
|
34666 | 4505 |
static void append_interfaces(GrowableArray<Klass*>* result, |
4506 |
const Array<Klass*>* const ifs) { |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4507 |
// iterate over new interfaces |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4508 |
for (int i = 0; i < ifs->length(); i++) { |
34666 | 4509 |
Klass* const e = ifs->at(i); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4510 |
assert(e->is_klass() && InstanceKlass::cast(e)->is_interface(), "just checking"); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4511 |
// add new interface |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4512 |
result->append_if_missing(e); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4513 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4514 |
} |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4515 |
|
34666 | 4516 |
static Array<Klass*>* compute_transitive_interfaces(const InstanceKlass* super, |
4517 |
Array<Klass*>* local_ifs, |
|
4518 |
ClassLoaderData* loader_data, |
|
4519 |
TRAPS) { |
|
4520 |
assert(local_ifs != NULL, "invariant"); |
|
4521 |
assert(loader_data != NULL, "invariant"); |
|
4522 |
||
1 | 4523 |
// Compute maximum size for transitive interfaces |
4524 |
int max_transitive_size = 0; |
|
4525 |
int super_size = 0; |
|
4526 |
// Add superclass transitive interfaces size |
|
34666 | 4527 |
if (super != NULL) { |
1 | 4528 |
super_size = super->transitive_interfaces()->length(); |
4529 |
max_transitive_size += super_size; |
|
4530 |
} |
|
4531 |
// Add local interfaces' super interfaces |
|
34666 | 4532 |
const int local_size = local_ifs->length(); |
1 | 4533 |
for (int i = 0; i < local_size; i++) { |
34666 | 4534 |
Klass* const l = local_ifs->at(i); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4535 |
max_transitive_size += InstanceKlass::cast(l)->transitive_interfaces()->length(); |
1 | 4536 |
} |
4537 |
// Finally add local interfaces |
|
4538 |
max_transitive_size += local_size; |
|
4539 |
// Construct array |
|
4540 |
if (max_transitive_size == 0) { |
|
4541 |
// no interfaces, use canonicalized array |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4542 |
return Universe::the_empty_klass_array(); |
1 | 4543 |
} else if (max_transitive_size == super_size) { |
4544 |
// no new local interfaces added, share superklass' transitive interface array |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4545 |
return super->transitive_interfaces(); |
1 | 4546 |
} else if (max_transitive_size == local_size) { |
4547 |
// only local interfaces added, share local interface array |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4548 |
return local_ifs; |
1 | 4549 |
} else { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4550 |
ResourceMark rm; |
34666 | 4551 |
GrowableArray<Klass*>* const result = new GrowableArray<Klass*>(max_transitive_size); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4552 |
|
1 | 4553 |
// Copy down from superclass |
34666 | 4554 |
if (super != NULL) { |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4555 |
append_interfaces(result, super->transitive_interfaces()); |
1 | 4556 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4557 |
|
1 | 4558 |
// Copy down from local interfaces' superinterfaces |
34666 | 4559 |
for (int i = 0; i < local_size; i++) { |
4560 |
Klass* const l = local_ifs->at(i); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4561 |
append_interfaces(result, InstanceKlass::cast(l)->transitive_interfaces()); |
1 | 4562 |
} |
4563 |
// Finally add local interfaces |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4564 |
append_interfaces(result, local_ifs); |
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4565 |
|
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4566 |
// length will be less than the max_transitive_size if duplicates were removed |
34666 | 4567 |
const int length = result->length(); |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4568 |
assert(length <= max_transitive_size, "just checking"); |
34666 | 4569 |
Array<Klass*>* const new_result = |
4570 |
MetadataFactory::new_array<Klass*>(loader_data, length, CHECK_NULL); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4571 |
for (int i = 0; i < length; i++) { |
34666 | 4572 |
Klass* const e = result->at(i); |
4573 |
assert(e != NULL, "just checking"); |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4574 |
new_result->at_put(i, e); |
1 | 4575 |
} |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4576 |
return new_result; |
1 | 4577 |
} |
4578 |
} |
|
4579 |
||
34666 | 4580 |
static void check_super_class_access(const InstanceKlass* this_klass, TRAPS) { |
4581 |
assert(this_klass != NULL, "invariant"); |
|
4582 |
const Klass* const super = this_klass->super(); |
|
36508 | 4583 |
if (super != NULL) { |
42574
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4584 |
|
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4585 |
// If the loader is not the boot loader then throw an exception if its |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4586 |
// superclass is in package jdk.internal.reflect and its loader is not a |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4587 |
// special reflection class loader |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4588 |
if (!this_klass->class_loader_data()->is_the_null_class_loader_data()) { |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4589 |
assert(super->is_instance_klass(), "super is not instance klass"); |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4590 |
PackageEntry* super_package = super->package(); |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4591 |
if (super_package != NULL && |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4592 |
super_package->name()->fast_compare(vmSymbols::jdk_internal_reflect()) == 0 && |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4593 |
!java_lang_ClassLoader::is_reflection_class_loader(this_klass->class_loader())) { |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4594 |
ResourceMark rm(THREAD); |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4595 |
Exceptions::fthrow( |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4596 |
THREAD_AND_LOCATION, |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4597 |
vmSymbols::java_lang_IllegalAccessError(), |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4598 |
"class %s loaded by %s cannot access jdk/internal/reflect superclass %s", |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4599 |
this_klass->external_name(), |
50634
c349d409262a
8202605: Standardize on ClassLoaderData::loader_name() throughout the VM to obtain a class loader's name
lfoltan
parents:
50633
diff
changeset
|
4600 |
this_klass->class_loader_data()->loader_name_and_id(), |
42574
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4601 |
super->external_name()); |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4602 |
return; |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4603 |
} |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4604 |
} |
25ff9171b28b
8166304: Skipping access check for classes generated by core reflection
hseigel
parents:
41744
diff
changeset
|
4605 |
|
36508 | 4606 |
Reflection::VerifyClassAccessResults vca_result = |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4607 |
Reflection::verify_class_access(this_klass, InstanceKlass::cast(super), false); |
36508 | 4608 |
if (vca_result != Reflection::ACCESS_OK) { |
4609 |
ResourceMark rm(THREAD); |
|
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4610 |
char* msg = Reflection::verify_class_access_msg(this_klass, |
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4611 |
InstanceKlass::cast(super), |
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4612 |
vca_result); |
36508 | 4613 |
if (msg == NULL) { |
4614 |
Exceptions::fthrow( |
|
4615 |
THREAD_AND_LOCATION, |
|
4616 |
vmSymbols::java_lang_IllegalAccessError(), |
|
4617 |
"class %s cannot access its superclass %s", |
|
4618 |
this_klass->external_name(), |
|
4619 |
super->external_name()); |
|
4620 |
} else { |
|
4621 |
// Add additional message content. |
|
4622 |
Exceptions::fthrow( |
|
4623 |
THREAD_AND_LOCATION, |
|
4624 |
vmSymbols::java_lang_IllegalAccessError(), |
|
4625 |
"superclass access check failed: %s", |
|
4626 |
msg); |
|
4627 |
} |
|
4628 |
} |
|
1 | 4629 |
} |
4630 |
} |
|
4631 |
||
4632 |
||
34666 | 4633 |
static void check_super_interface_access(const InstanceKlass* this_klass, TRAPS) { |
4634 |
assert(this_klass != NULL, "invariant"); |
|
4635 |
const Array<Klass*>* const local_interfaces = this_klass->local_interfaces(); |
|
4636 |
const int lng = local_interfaces->length(); |
|
1 | 4637 |
for (int i = lng - 1; i >= 0; i--) { |
34666 | 4638 |
Klass* const k = local_interfaces->at(i); |
14488 | 4639 |
assert (k != NULL && k->is_interface(), "invalid interface"); |
36508 | 4640 |
Reflection::VerifyClassAccessResults vca_result = |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4641 |
Reflection::verify_class_access(this_klass, InstanceKlass::cast(k), false); |
36508 | 4642 |
if (vca_result != Reflection::ACCESS_OK) { |
1 | 4643 |
ResourceMark rm(THREAD); |
46262
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4644 |
char* msg = Reflection::verify_class_access_msg(this_klass, |
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4645 |
InstanceKlass::cast(k), |
83280d968b96
8174092: Remove array-related access checks from Reflection::verify_class_access()
hseigel
parents:
42656
diff
changeset
|
4646 |
vca_result); |
36508 | 4647 |
if (msg == NULL) { |
4648 |
Exceptions::fthrow( |
|
4649 |
THREAD_AND_LOCATION, |
|
4650 |
vmSymbols::java_lang_IllegalAccessError(), |
|
4651 |
"class %s cannot access its superinterface %s", |
|
4652 |
this_klass->external_name(), |
|
4653 |
k->external_name()); |
|
4654 |
} else { |
|
4655 |
// Add additional message content. |
|
4656 |
Exceptions::fthrow( |
|
4657 |
THREAD_AND_LOCATION, |
|
4658 |
vmSymbols::java_lang_IllegalAccessError(), |
|
4659 |
"superinterface check failed: %s", |
|
4660 |
msg); |
|
4661 |
} |
|
1 | 4662 |
} |
4663 |
} |
|
4664 |
} |
|
4665 |
||
4666 |
||
34666 | 4667 |
static void check_final_method_override(const InstanceKlass* this_klass, TRAPS) { |
4668 |
assert(this_klass != NULL, "invariant"); |
|
4669 |
const Array<Method*>* const methods = this_klass->methods(); |
|
4670 |
const int num_methods = methods->length(); |
|
1 | 4671 |
|
4672 |
// go thru each method and check if it overrides a final method |
|
4673 |
for (int index = 0; index < num_methods; index++) { |
|
34666 | 4674 |
const Method* const m = methods->at(index); |
1 | 4675 |
|
21765
e2c19a9f1039
8028520: JVM should not throw VerifyError when a private method overrides a final method
hseigel
parents:
21556
diff
changeset
|
4676 |
// skip private, static, and <init> methods |
e2c19a9f1039
8028520: JVM should not throw VerifyError when a private method overrides a final method
hseigel
parents:
21556
diff
changeset
|
4677 |
if ((!m->is_private() && !m->is_static()) && |
1 | 4678 |
(m->name() != vmSymbols::object_initializer_name())) { |
4679 |
||
34666 | 4680 |
const Symbol* const name = m->name(); |
4681 |
const Symbol* const signature = m->signature(); |
|
4682 |
const Klass* k = this_klass->super(); |
|
4683 |
const Method* super_m = NULL; |
|
1 | 4684 |
while (k != NULL) { |
4685 |
// skip supers that don't have final methods. |
|
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4686 |
if (k->has_final_method()) { |
1 | 4687 |
// lookup a matching method in the super class hierarchy |
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4688 |
super_m = InstanceKlass::cast(k)->lookup_method(name, signature); |
1 | 4689 |
if (super_m == NULL) { |
4690 |
break; // didn't find any match; get out |
|
4691 |
} |
|
4692 |
||
22534
520f7a937396
8028553: The JVM should not throw VerifyError when 'overriding' a static final method in a superclass.
hseigel
parents:
22485
diff
changeset
|
4693 |
if (super_m->is_final() && !super_m->is_static() && |
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4694 |
!super_m->access_flags().is_private()) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4695 |
// matching method in super is final, and not static or private |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4696 |
bool can_access = Reflection::verify_member_access(this_klass, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4697 |
super_m->method_holder(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4698 |
super_m->method_holder(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4699 |
super_m->access_flags(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4700 |
false, false, CHECK); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4701 |
if (can_access) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4702 |
// this class can access super final method and therefore override |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4703 |
ResourceMark rm(THREAD); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4704 |
Exceptions::fthrow(THREAD_AND_LOCATION, |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4705 |
vmSymbols::java_lang_VerifyError(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4706 |
"class %s overrides final method %s.%s%s", |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4707 |
this_klass->external_name(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4708 |
super_m->method_holder()->external_name(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4709 |
name->as_C_string(), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4710 |
signature->as_C_string() |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4711 |
); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4712 |
return; |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
4713 |
} |
1 | 4714 |
} |
4715 |
||
4716 |
// continue to look from super_m's holder's super. |
|
14391
df0a1573d5bd
8000725: NPG: method_holder() and pool_holder() and pool_holder field should be InstanceKlass
coleenp
parents:
14385
diff
changeset
|
4717 |
k = super_m->method_holder()->super(); |
1 | 4718 |
continue; |
4719 |
} |
|
4720 |
||
13728
882756847a04
6964458: Reimplement class meta-data storage to use native memory
coleenp
parents:
13391
diff
changeset
|
4721 |
k = k->super(); |
1 | 4722 |
} |
4723 |
} |
|
4724 |
} |
|
4725 |
} |
|
4726 |
||
4727 |
||
4728 |
// assumes that this_klass is an interface |
|
34666 | 4729 |
static void check_illegal_static_method(const InstanceKlass* this_klass, TRAPS) { |
4730 |
assert(this_klass != NULL, "invariant"); |
|
1 | 4731 |
assert(this_klass->is_interface(), "not an interface"); |
34666 | 4732 |
const Array<Method*>* methods = this_klass->methods(); |
4733 |
const int num_methods = methods->length(); |
|
1 | 4734 |
|
4735 |
for (int index = 0; index < num_methods; index++) { |
|
34666 | 4736 |
const Method* const m = methods->at(index); |
1 | 4737 |
// if m is static and not the init method, throw a verify error |
4738 |
if ((m->is_static()) && (m->name() != vmSymbols::class_initializer_name())) { |
|
4739 |
ResourceMark rm(THREAD); |
|
4740 |
Exceptions::fthrow( |
|
4741 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
4742 |
vmSymbols::java_lang_VerifyError(), |
1 | 4743 |
"Illegal static method %s in interface %s", |
4744 |
m->name()->as_C_string(), |
|
4745 |
this_klass->external_name() |
|
4746 |
); |
|
4747 |
return; |
|
4748 |
} |
|
4749 |
} |
|
4750 |
} |
|
4751 |
||
4752 |
// utility methods for format checking |
|
4753 |
||
34666 | 4754 |
void ClassFileParser::verify_legal_class_modifiers(jint flags, TRAPS) const { |
43977
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4755 |
const bool is_module = (flags & JVM_ACC_MODULE) != 0; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4756 |
assert(_major_version >= JAVA_9_VERSION || !is_module, "JVM_ACC_MODULE should not be set"); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4757 |
if (is_module) { |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4758 |
ResourceMark rm(THREAD); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4759 |
Exceptions::fthrow( |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4760 |
THREAD_AND_LOCATION, |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4761 |
vmSymbols::java_lang_NoClassDefFoundError(), |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4762 |
"%s is not a class because access_flag ACC_MODULE is set", |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4763 |
_class_name->as_C_string()); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4764 |
return; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4765 |
} |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4766 |
|
1 | 4767 |
if (!_need_verify) { return; } |
4768 |
||
4769 |
const bool is_interface = (flags & JVM_ACC_INTERFACE) != 0; |
|
4770 |
const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0; |
|
4771 |
const bool is_final = (flags & JVM_ACC_FINAL) != 0; |
|
4772 |
const bool is_super = (flags & JVM_ACC_SUPER) != 0; |
|
4773 |
const bool is_enum = (flags & JVM_ACC_ENUM) != 0; |
|
4774 |
const bool is_annotation = (flags & JVM_ACC_ANNOTATION) != 0; |
|
4775 |
const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; |
|
4776 |
||
4777 |
if ((is_abstract && is_final) || |
|
4778 |
(is_interface && !is_abstract) || |
|
4779 |
(is_interface && major_gte_15 && (is_super || is_enum)) || |
|
43977
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
4780 |
(!is_interface && major_gte_15 && is_annotation)) { |
1 | 4781 |
ResourceMark rm(THREAD); |
4782 |
Exceptions::fthrow( |
|
4783 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
4784 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 4785 |
"Illegal class modifiers in class %s: 0x%X", |
4786 |
_class_name->as_C_string(), flags |
|
4787 |
); |
|
4788 |
return; |
|
4789 |
} |
|
4790 |
} |
|
4791 |
||
34666 | 4792 |
static bool has_illegal_visibility(jint flags) { |
1 | 4793 |
const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; |
4794 |
const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; |
|
4795 |
const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; |
|
4796 |
||
4797 |
return ((is_public && is_protected) || |
|
4798 |
(is_public && is_private) || |
|
4799 |
(is_protected && is_private)); |
|
4800 |
} |
|
4801 |
||
49716 | 4802 |
// A legal major_version.minor_version must be one of the following: |
4803 |
// |
|
4804 |
// Major_version = 45, any minor_version. |
|
4805 |
// Major_version >= 46 and major_version <= current_major_version and minor_version = 0. |
|
4806 |
// Major_version = current_major_version and minor_version = 65535 and --enable-preview is present. |
|
4807 |
// |
|
4808 |
static void verify_class_version(u2 major, u2 minor, Symbol* class_name, TRAPS){ |
|
48355 | 4809 |
const u2 max_version = JVM_CLASSFILE_MAJOR_VERSION; |
49716 | 4810 |
if (major != JAVA_MIN_SUPPORTED_VERSION) { // All 45.* are ok including 45.65535 |
4811 |
if (minor == JAVA_PREVIEW_MINOR_VERSION) { |
|
4812 |
if (major != max_version) { |
|
4813 |
ResourceMark rm(THREAD); |
|
4814 |
Exceptions::fthrow( |
|
4815 |
THREAD_AND_LOCATION, |
|
4816 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
4817 |
"%s (class file version %u.%u) was compiled with preview features that are unsupported. " |
|
4818 |
"This version of the Java Runtime only recognizes preview features for class file version %u.%u", |
|
4819 |
class_name->as_C_string(), major, minor, JVM_CLASSFILE_MAJOR_VERSION, JAVA_PREVIEW_MINOR_VERSION); |
|
4820 |
return; |
|
4821 |
} |
|
4822 |
||
4823 |
if (!Arguments::enable_preview()) { |
|
4824 |
ResourceMark rm(THREAD); |
|
4825 |
Exceptions::fthrow( |
|
4826 |
THREAD_AND_LOCATION, |
|
4827 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
4828 |
"Preview features are not enabled for %s (class file version %u.%u). Try running with '--enable-preview'", |
|
4829 |
class_name->as_C_string(), major, minor); |
|
4830 |
return; |
|
4831 |
} |
|
4832 |
||
4833 |
} else { // minor != JAVA_PREVIEW_MINOR_VERSION |
|
4834 |
if (major > max_version) { |
|
4835 |
ResourceMark rm(THREAD); |
|
4836 |
Exceptions::fthrow( |
|
4837 |
THREAD_AND_LOCATION, |
|
4838 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
4839 |
"%s has been compiled by a more recent version of the Java Runtime (class file version %u.%u), " |
|
4840 |
"this version of the Java Runtime only recognizes class file versions up to %u.0", |
|
4841 |
class_name->as_C_string(), major, minor, JVM_CLASSFILE_MAJOR_VERSION); |
|
4842 |
} else if (major < JAVA_MIN_SUPPORTED_VERSION) { |
|
4843 |
ResourceMark rm(THREAD); |
|
4844 |
Exceptions::fthrow( |
|
4845 |
THREAD_AND_LOCATION, |
|
4846 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
4847 |
"%s (class file version %u.%u) was compiled with an invalid major version", |
|
4848 |
class_name->as_C_string(), major, minor); |
|
4849 |
} else if (minor != 0) { |
|
4850 |
ResourceMark rm(THREAD); |
|
4851 |
Exceptions::fthrow( |
|
4852 |
THREAD_AND_LOCATION, |
|
4853 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
4854 |
"%s (class file version %u.%u) was compiled with an invalid non-zero minor version", |
|
4855 |
class_name->as_C_string(), major, minor); |
|
4856 |
} |
|
4857 |
} |
|
4858 |
} |
|
1 | 4859 |
} |
4860 |
||
34666 | 4861 |
void ClassFileParser::verify_legal_field_modifiers(jint flags, |
4862 |
bool is_interface, |
|
4863 |
TRAPS) const { |
|
1 | 4864 |
if (!_need_verify) { return; } |
4865 |
||
4866 |
const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; |
|
4867 |
const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; |
|
4868 |
const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; |
|
4869 |
const bool is_static = (flags & JVM_ACC_STATIC) != 0; |
|
4870 |
const bool is_final = (flags & JVM_ACC_FINAL) != 0; |
|
4871 |
const bool is_volatile = (flags & JVM_ACC_VOLATILE) != 0; |
|
4872 |
const bool is_transient = (flags & JVM_ACC_TRANSIENT) != 0; |
|
4873 |
const bool is_enum = (flags & JVM_ACC_ENUM) != 0; |
|
4874 |
const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; |
|
4875 |
||
4876 |
bool is_illegal = false; |
|
4877 |
||
4878 |
if (is_interface) { |
|
4879 |
if (!is_public || !is_static || !is_final || is_private || |
|
4880 |
is_protected || is_volatile || is_transient || |
|
4881 |
(major_gte_15 && is_enum)) { |
|
4882 |
is_illegal = true; |
|
4883 |
} |
|
4884 |
} else { // not interface |
|
4885 |
if (has_illegal_visibility(flags) || (is_final && is_volatile)) { |
|
4886 |
is_illegal = true; |
|
4887 |
} |
|
4888 |
} |
|
4889 |
||
4890 |
if (is_illegal) { |
|
4891 |
ResourceMark rm(THREAD); |
|
4892 |
Exceptions::fthrow( |
|
4893 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
4894 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 4895 |
"Illegal field modifiers in class %s: 0x%X", |
4896 |
_class_name->as_C_string(), flags); |
|
4897 |
return; |
|
4898 |
} |
|
4899 |
} |
|
4900 |
||
34666 | 4901 |
void ClassFileParser::verify_legal_method_modifiers(jint flags, |
4902 |
bool is_interface, |
|
4903 |
const Symbol* name, |
|
4904 |
TRAPS) const { |
|
1 | 4905 |
if (!_need_verify) { return; } |
4906 |
||
4907 |
const bool is_public = (flags & JVM_ACC_PUBLIC) != 0; |
|
4908 |
const bool is_private = (flags & JVM_ACC_PRIVATE) != 0; |
|
4909 |
const bool is_static = (flags & JVM_ACC_STATIC) != 0; |
|
4910 |
const bool is_final = (flags & JVM_ACC_FINAL) != 0; |
|
4911 |
const bool is_native = (flags & JVM_ACC_NATIVE) != 0; |
|
4912 |
const bool is_abstract = (flags & JVM_ACC_ABSTRACT) != 0; |
|
4913 |
const bool is_bridge = (flags & JVM_ACC_BRIDGE) != 0; |
|
4914 |
const bool is_strict = (flags & JVM_ACC_STRICT) != 0; |
|
4915 |
const bool is_synchronized = (flags & JVM_ACC_SYNCHRONIZED) != 0; |
|
15185
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4916 |
const bool is_protected = (flags & JVM_ACC_PROTECTED) != 0; |
1 | 4917 |
const bool major_gte_15 = _major_version >= JAVA_1_5_VERSION; |
14385 | 4918 |
const bool major_gte_8 = _major_version >= JAVA_8_VERSION; |
1 | 4919 |
const bool is_initializer = (name == vmSymbols::object_initializer_name()); |
4920 |
||
4921 |
bool is_illegal = false; |
|
4922 |
||
4923 |
if (is_interface) { |
|
15185
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4924 |
if (major_gte_8) { |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4925 |
// Class file version is JAVA_8_VERSION or later Methods of |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4926 |
// interfaces may set any of the flags except ACC_PROTECTED, |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4927 |
// ACC_FINAL, ACC_NATIVE, and ACC_SYNCHRONIZED; they must |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4928 |
// have exactly one of the ACC_PUBLIC or ACC_PRIVATE flags set. |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4929 |
if ((is_public == is_private) || /* Only one of private and public should be true - XNOR */ |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4930 |
(is_native || is_protected || is_final || is_synchronized) || |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4931 |
// If a specific method of a class or interface has its |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4932 |
// ACC_ABSTRACT flag set, it must not have any of its |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4933 |
// ACC_FINAL, ACC_NATIVE, ACC_PRIVATE, ACC_STATIC, |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4934 |
// ACC_STRICT, or ACC_SYNCHRONIZED flags set. No need to |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4935 |
// check for ACC_FINAL, ACC_NATIVE or ACC_SYNCHRONIZED as |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4936 |
// those flags are illegal irrespective of ACC_ABSTRACT being set or not. |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4937 |
(is_abstract && (is_private || is_static || is_strict))) { |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4938 |
is_illegal = true; |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4939 |
} |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4940 |
} else if (major_gte_15) { |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4941 |
// Class file version in the interval [JAVA_1_5_VERSION, JAVA_8_VERSION) |
35911
80dd27ae501c
8135206: VM permits illegal flags for abstract methods in interfaces, versions 45.3 - 51.0
hseigel
parents:
35898
diff
changeset
|
4942 |
if (!is_public || is_private || is_protected || is_static || is_final || |
80dd27ae501c
8135206: VM permits illegal flags for abstract methods in interfaces, versions 45.3 - 51.0
hseigel
parents:
35898
diff
changeset
|
4943 |
is_synchronized || is_native || !is_abstract || is_strict) { |
15185
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4944 |
is_illegal = true; |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4945 |
} |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4946 |
} else { |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4947 |
// Class file version is pre-JAVA_1_5_VERSION |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4948 |
if (!is_public || is_static || is_final || is_native || !is_abstract) { |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4949 |
is_illegal = true; |
1ce0205b9a47
8005689: InterfaceAccessFlagsTest failures in Lambda-JDK tests
acorn
parents:
15102
diff
changeset
|
4950 |
} |
1 | 4951 |
} |
4952 |
} else { // not interface |
|
30136
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4953 |
if (has_illegal_visibility(flags)) { |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4954 |
is_illegal = true; |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4955 |
} else { |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4956 |
if (is_initializer) { |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4957 |
if (is_static || is_final || is_synchronized || is_native || |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4958 |
is_abstract || (major_gte_15 && is_bridge)) { |
1 | 4959 |
is_illegal = true; |
4960 |
} |
|
30136
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4961 |
} else { // not initializer |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4962 |
if (is_abstract) { |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4963 |
if ((is_final || is_native || is_private || is_static || |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4964 |
(major_gte_15 && (is_synchronized || is_strict)))) { |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4965 |
is_illegal = true; |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4966 |
} |
1c5202fa105b
8076236: VM permits illegal flags for class init method
hseigel
parents:
29201
diff
changeset
|
4967 |
} |
1 | 4968 |
} |
4969 |
} |
|
4970 |
} |
|
4971 |
||
4972 |
if (is_illegal) { |
|
4973 |
ResourceMark rm(THREAD); |
|
4974 |
Exceptions::fthrow( |
|
4975 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
4976 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 4977 |
"Method %s in class %s has illegal modifiers: 0x%X", |
4978 |
name->as_C_string(), _class_name->as_C_string(), flags); |
|
4979 |
return; |
|
4980 |
} |
|
4981 |
} |
|
4982 |
||
34666 | 4983 |
void ClassFileParser::verify_legal_utf8(const unsigned char* buffer, |
4984 |
int length, |
|
4985 |
TRAPS) const { |
|
1 | 4986 |
assert(_need_verify, "only called when _need_verify is true"); |
36508 | 4987 |
if (!UTF8::is_legal_utf8(buffer, length, _major_version <= 47)) { |
4988 |
classfile_parse_error("Illegal UTF8 string in constant pool in class file %s", CHECK); |
|
1 | 4989 |
} |
4990 |
} |
|
4991 |
||
34666 | 4992 |
// Unqualified names may not contain the characters '.', ';', '[', or '/'. |
39218
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
4993 |
// In class names, '/' separates unqualified names. This is verified in this function also. |
34666 | 4994 |
// Method names also may not contain the characters '<' or '>', unless <init> |
4995 |
// or <clinit>. Note that method names may not be <init> or <clinit> in this |
|
4996 |
// method. Because these names have been checked as special cases before |
|
4997 |
// calling this method in verify_legal_method_name. |
|
36508 | 4998 |
// |
4999 |
// This method is also called from the modular system APIs in modules.cpp |
|
5000 |
// to verify the validity of module and package names. |
|
5001 |
bool ClassFileParser::verify_unqualified_name(const char* name, |
|
5002 |
unsigned int length, |
|
5003 |
int type) { |
|
34666 | 5004 |
for (const char* p = name; p != name + length;) { |
5005 |
jchar ch = *p; |
|
5006 |
if (ch < 128) { |
|
42630
ae91fbc4b59f
8170987: Module system implementation refresh (12/2016)
alanb
parents:
41744
diff
changeset
|
5007 |
if (ch == '.' || ch == ';' || ch == '[' ) { |
34666 | 5008 |
return false; // do not permit '.', ';', or '[' |
5009 |
} |
|
39218
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5010 |
if (ch == '/') { |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5011 |
// check for '//' or leading or trailing '/' which are not legal |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5012 |
// unqualified name must not be empty |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5013 |
if (type == ClassFileParser::LegalClass) { |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5014 |
if (p == name || p+1 >= name+length || *(p+1) == '/') { |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5015 |
return false; |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5016 |
} |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5017 |
} else { |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5018 |
return false; // do not permit '/' unless it's class name |
43ac06a5ee4f
8158297: Lack of proper checking of non-well formed elements in CONSTANT_Utf8_info's structure
coleenp
parents:
38701
diff
changeset
|
5019 |
} |
34666 | 5020 |
} |
36508 | 5021 |
if (type == ClassFileParser::LegalMethod && (ch == '<' || ch == '>')) { |
34666 | 5022 |
return false; // do not permit '<' or '>' in method names |
5023 |
} |
|
36508 | 5024 |
p++; |
5025 |
} else { |
|
34666 | 5026 |
char* tmp_p = UTF8::next(p, &ch); |
5027 |
p = tmp_p; |
|
5028 |
} |
|
5029 |
} |
|
5030 |
return true; |
|
5031 |
} |
|
5032 |
||
5033 |
// Take pointer to a string. Skip over the longest part of the string that could |
|
5034 |
// be taken as a fieldname. Allow '/' if slash_ok is true. |
|
5035 |
// Return a pointer to just past the fieldname. |
|
5036 |
// Return NULL if no fieldname at all was found, or in the case of slash_ok |
|
5037 |
// being true, we saw consecutive slashes (meaning we were looking for a |
|
5038 |
// qualified path but found something that was badly-formed). |
|
5039 |
static const char* skip_over_field_name(const char* name, |
|
5040 |
bool slash_ok, |
|
5041 |
unsigned int length) { |
|
5042 |
const char* p; |
|
5043 |
jboolean last_is_slash = false; |
|
5044 |
jboolean not_first_ch = false; |
|
5045 |
||
5046 |
for (p = name; p != name + length; not_first_ch = true) { |
|
5047 |
const char* old_p = p; |
|
5048 |
jchar ch = *p; |
|
5049 |
if (ch < 128) { |
|
5050 |
p++; |
|
5051 |
// quick check for ascii |
|
5052 |
if ((ch >= 'a' && ch <= 'z') || |
|
5053 |
(ch >= 'A' && ch <= 'Z') || |
|
5054 |
(ch == '_' || ch == '$') || |
|
5055 |
(not_first_ch && ch >= '0' && ch <= '9')) { |
|
5056 |
last_is_slash = false; |
|
5057 |
continue; |
|
5058 |
} |
|
5059 |
if (slash_ok && ch == '/') { |
|
5060 |
if (last_is_slash) { |
|
5061 |
return NULL; // Don't permit consecutive slashes |
|
5062 |
} |
|
5063 |
last_is_slash = true; |
|
5064 |
continue; |
|
5065 |
} |
|
5066 |
} |
|
5067 |
else { |
|
5068 |
jint unicode_ch; |
|
5069 |
char* tmp_p = UTF8::next_character(p, &unicode_ch); |
|
5070 |
p = tmp_p; |
|
5071 |
last_is_slash = false; |
|
5072 |
// Check if ch is Java identifier start or is Java identifier part |
|
5073 |
// 4672820: call java.lang.Character methods directly without generating separate tables. |
|
5074 |
EXCEPTION_MARK; |
|
5075 |
||
5076 |
// return value |
|
5077 |
JavaValue result(T_BOOLEAN); |
|
5078 |
// Set up the arguments to isJavaIdentifierStart and isJavaIdentifierPart |
|
5079 |
JavaCallArguments args; |
|
5080 |
args.push_int(unicode_ch); |
|
5081 |
||
5082 |
// public static boolean isJavaIdentifierStart(char ch); |
|
5083 |
JavaCalls::call_static(&result, |
|
5084 |
SystemDictionary::Character_klass(), |
|
5085 |
vmSymbols::isJavaIdentifierStart_name(), |
|
5086 |
vmSymbols::int_bool_signature(), |
|
5087 |
&args, |
|
5088 |
THREAD); |
|
5089 |
||
5090 |
if (HAS_PENDING_EXCEPTION) { |
|
5091 |
CLEAR_PENDING_EXCEPTION; |
|
5092 |
return 0; |
|
5093 |
} |
|
5094 |
if (result.get_jboolean()) { |
|
5095 |
continue; |
|
5096 |
} |
|
5097 |
||
5098 |
if (not_first_ch) { |
|
5099 |
// public static boolean isJavaIdentifierPart(char ch); |
|
5100 |
JavaCalls::call_static(&result, |
|
5101 |
SystemDictionary::Character_klass(), |
|
5102 |
vmSymbols::isJavaIdentifierPart_name(), |
|
5103 |
vmSymbols::int_bool_signature(), |
|
5104 |
&args, |
|
5105 |
THREAD); |
|
5106 |
||
5107 |
if (HAS_PENDING_EXCEPTION) { |
|
5108 |
CLEAR_PENDING_EXCEPTION; |
|
5109 |
return 0; |
|
5110 |
} |
|
5111 |
||
5112 |
if (result.get_jboolean()) { |
|
5113 |
continue; |
|
5114 |
} |
|
5115 |
} |
|
5116 |
} |
|
5117 |
return (not_first_ch) ? old_p : NULL; |
|
5118 |
} |
|
5119 |
return (not_first_ch) ? p : NULL; |
|
5120 |
} |
|
5121 |
||
5122 |
// Take pointer to a string. Skip over the longest part of the string that could |
|
5123 |
// be taken as a field signature. Allow "void" if void_ok. |
|
5124 |
// Return a pointer to just past the signature. |
|
5125 |
// Return NULL if no legal signature is found. |
|
5126 |
const char* ClassFileParser::skip_over_field_signature(const char* signature, |
|
5127 |
bool void_ok, |
|
5128 |
unsigned int length, |
|
5129 |
TRAPS) const { |
|
5130 |
unsigned int array_dim = 0; |
|
5131 |
while (length > 0) { |
|
5132 |
switch (signature[0]) { |
|
5133 |
case JVM_SIGNATURE_VOID: if (!void_ok) { return NULL; } |
|
5134 |
case JVM_SIGNATURE_BOOLEAN: |
|
5135 |
case JVM_SIGNATURE_BYTE: |
|
5136 |
case JVM_SIGNATURE_CHAR: |
|
5137 |
case JVM_SIGNATURE_SHORT: |
|
5138 |
case JVM_SIGNATURE_INT: |
|
5139 |
case JVM_SIGNATURE_FLOAT: |
|
5140 |
case JVM_SIGNATURE_LONG: |
|
5141 |
case JVM_SIGNATURE_DOUBLE: |
|
5142 |
return signature + 1; |
|
5143 |
case JVM_SIGNATURE_CLASS: { |
|
5144 |
if (_major_version < JAVA_1_5_VERSION) { |
|
5145 |
// Skip over the class name if one is there |
|
5146 |
const char* const p = skip_over_field_name(signature + 1, true, --length); |
|
5147 |
||
5148 |
// The next character better be a semicolon |
|
5149 |
if (p && (p - signature) > 1 && p[0] == ';') { |
|
5150 |
return p + 1; |
|
5151 |
} |
|
5152 |
} |
|
5153 |
else { |
|
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5154 |
// Skip leading 'L' and ignore first appearance of ';' |
34666 | 5155 |
length--; |
5156 |
signature++; |
|
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5157 |
char* c = strchr((char*) signature, ';'); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5158 |
// Format check signature |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5159 |
if (c != NULL) { |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5160 |
ResourceMark rm(THREAD); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5161 |
int newlen = c - (char*) signature; |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5162 |
char* sig = NEW_RESOURCE_ARRAY(char, newlen + 1); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5163 |
strncpy(sig, signature, newlen); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5164 |
sig[newlen] = '\0'; |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5165 |
|
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5166 |
bool legal = verify_unqualified_name(sig, newlen, LegalClass); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5167 |
if (!legal) { |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5168 |
classfile_parse_error("Class name contains illegal character " |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5169 |
"in descriptor in class file %s", |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5170 |
CHECK_0); |
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5171 |
return NULL; |
34666 | 5172 |
} |
40920
8fcd156236e6
8161224: CONSTANT_NameAndType_info permits references to illegal names and descriptors
rprotacio
parents:
40633
diff
changeset
|
5173 |
return signature + newlen + 1; |
34666 | 5174 |
} |
5175 |
} |
|
5176 |
return NULL; |
|
5177 |
} |
|
5178 |
case JVM_SIGNATURE_ARRAY: |
|
5179 |
array_dim++; |
|
5180 |
if (array_dim > 255) { |
|
5181 |
// 4277370: array descriptor is valid only if it represents 255 or fewer dimensions. |
|
5182 |
classfile_parse_error("Array type descriptor has more than 255 dimensions in class file %s", CHECK_0); |
|
5183 |
} |
|
5184 |
// The rest of what's there better be a legal signature |
|
5185 |
signature++; |
|
5186 |
length--; |
|
5187 |
void_ok = false; |
|
5188 |
break; |
|
5189 |
default: |
|
5190 |
return NULL; |
|
5191 |
} |
|
5192 |
} |
|
5193 |
return NULL; |
|
5194 |
} |
|
5195 |
||
1 | 5196 |
// Checks if name is a legal class name. |
34666 | 5197 |
void ClassFileParser::verify_legal_class_name(const Symbol* name, TRAPS) const { |
1 | 5198 |
if (!_need_verify || _relax_verify) { return; } |
5199 |
||
5200 |
char buf[fixed_buffer_size]; |
|
5201 |
char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); |
|
5202 |
unsigned int length = name->utf8_length(); |
|
5203 |
bool legal = false; |
|
5204 |
||
5205 |
if (length > 0) { |
|
34666 | 5206 |
const char* p; |
1 | 5207 |
if (bytes[0] == JVM_SIGNATURE_ARRAY) { |
5208 |
p = skip_over_field_signature(bytes, false, length, CHECK); |
|
5209 |
legal = (p != NULL) && ((p - bytes) == (int)length); |
|
5210 |
} else if (_major_version < JAVA_1_5_VERSION) { |
|
5211 |
if (bytes[0] != '<') { |
|
5212 |
p = skip_over_field_name(bytes, true, length); |
|
5213 |
legal = (p != NULL) && ((p - bytes) == (int)length); |
|
5214 |
} |
|
5215 |
} else { |
|
5216 |
// 4900761: relax the constraints based on JSR202 spec |
|
5217 |
// Class names may be drawn from the entire Unicode character set. |
|
5218 |
// Identifiers between '/' must be unqualified names. |
|
5219 |
// The utf8 string has been verified when parsing cpool entries. |
|
5220 |
legal = verify_unqualified_name(bytes, length, LegalClass); |
|
5221 |
} |
|
5222 |
} |
|
5223 |
if (!legal) { |
|
5224 |
ResourceMark rm(THREAD); |
|
34666 | 5225 |
assert(_class_name != NULL, "invariant"); |
1 | 5226 |
Exceptions::fthrow( |
5227 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
5228 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 5229 |
"Illegal class name \"%s\" in class file %s", bytes, |
5230 |
_class_name->as_C_string() |
|
5231 |
); |
|
5232 |
return; |
|
5233 |
} |
|
5234 |
} |
|
5235 |
||
5236 |
// Checks if name is a legal field name. |
|
34666 | 5237 |
void ClassFileParser::verify_legal_field_name(const Symbol* name, TRAPS) const { |
1 | 5238 |
if (!_need_verify || _relax_verify) { return; } |
5239 |
||
5240 |
char buf[fixed_buffer_size]; |
|
5241 |
char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); |
|
5242 |
unsigned int length = name->utf8_length(); |
|
5243 |
bool legal = false; |
|
5244 |
||
5245 |
if (length > 0) { |
|
5246 |
if (_major_version < JAVA_1_5_VERSION) { |
|
5247 |
if (bytes[0] != '<') { |
|
34666 | 5248 |
const char* p = skip_over_field_name(bytes, false, length); |
1 | 5249 |
legal = (p != NULL) && ((p - bytes) == (int)length); |
5250 |
} |
|
5251 |
} else { |
|
5252 |
// 4881221: relax the constraints based on JSR202 spec |
|
5253 |
legal = verify_unqualified_name(bytes, length, LegalField); |
|
5254 |
} |
|
5255 |
} |
|
5256 |
||
5257 |
if (!legal) { |
|
5258 |
ResourceMark rm(THREAD); |
|
34666 | 5259 |
assert(_class_name != NULL, "invariant"); |
1 | 5260 |
Exceptions::fthrow( |
5261 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
5262 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 5263 |
"Illegal field name \"%s\" in class %s", bytes, |
5264 |
_class_name->as_C_string() |
|
5265 |
); |
|
5266 |
return; |
|
5267 |
} |
|
5268 |
} |
|
5269 |
||
5270 |
// Checks if name is a legal method name. |
|
34666 | 5271 |
void ClassFileParser::verify_legal_method_name(const Symbol* name, TRAPS) const { |
1 | 5272 |
if (!_need_verify || _relax_verify) { return; } |
5273 |
||
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
5274 |
assert(name != NULL, "method name is null"); |
1 | 5275 |
char buf[fixed_buffer_size]; |
5276 |
char* bytes = name->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); |
|
5277 |
unsigned int length = name->utf8_length(); |
|
5278 |
bool legal = false; |
|
5279 |
||
5280 |
if (length > 0) { |
|
5281 |
if (bytes[0] == '<') { |
|
5282 |
if (name == vmSymbols::object_initializer_name() || name == vmSymbols::class_initializer_name()) { |
|
5283 |
legal = true; |
|
5284 |
} |
|
5285 |
} else if (_major_version < JAVA_1_5_VERSION) { |
|
34666 | 5286 |
const char* p; |
1 | 5287 |
p = skip_over_field_name(bytes, false, length); |
5288 |
legal = (p != NULL) && ((p - bytes) == (int)length); |
|
5289 |
} else { |
|
5290 |
// 4881221: relax the constraints based on JSR202 spec |
|
5291 |
legal = verify_unqualified_name(bytes, length, LegalMethod); |
|
5292 |
} |
|
5293 |
} |
|
5294 |
||
5295 |
if (!legal) { |
|
5296 |
ResourceMark rm(THREAD); |
|
34666 | 5297 |
assert(_class_name != NULL, "invariant"); |
1 | 5298 |
Exceptions::fthrow( |
5299 |
THREAD_AND_LOCATION, |
|
8076
96d498ec7ae1
6990754: Use native memory and reference counting to implement SymbolTable
coleenp
parents:
7709
diff
changeset
|
5300 |
vmSymbols::java_lang_ClassFormatError(), |
1 | 5301 |
"Illegal method name \"%s\" in class %s", bytes, |
5302 |
_class_name->as_C_string() |
|
5303 |
); |
|
5304 |
return; |
|
5305 |
} |
|
5306 |
} |
|
5307 |
||
5308 |
||
5309 |
// Checks if signature is a legal field signature. |
|
34666 | 5310 |
void ClassFileParser::verify_legal_field_signature(const Symbol* name, |
5311 |
const Symbol* signature, |
|
5312 |
TRAPS) const { |
|
1 | 5313 |
if (!_need_verify) { return; } |
5314 |
||
5315 |
char buf[fixed_buffer_size]; |
|
34666 | 5316 |
const char* const bytes = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); |
5317 |
const unsigned int length = signature->utf8_length(); |
|
5318 |
const char* const p = skip_over_field_signature(bytes, false, length, CHECK); |
|
1 | 5319 |
|
5320 |
if (p == NULL || (p - bytes) != (int)length) { |
|
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
5321 |
throwIllegalSignature("Field", name, signature, CHECK); |
1 | 5322 |
} |
5323 |
} |
|
5324 |
||
5325 |
// Checks if signature is a legal method signature. |
|
5326 |
// Returns number of parameters |
|
34666 | 5327 |
int ClassFileParser::verify_legal_method_signature(const Symbol* name, |
5328 |
const Symbol* signature, |
|
5329 |
TRAPS) const { |
|
1 | 5330 |
if (!_need_verify) { |
5331 |
// make sure caller's args_size will be less than 0 even for non-static |
|
5332 |
// method so it will be recomputed in compute_size_of_parameters(). |
|
5333 |
return -2; |
|
5334 |
} |
|
5335 |
||
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5336 |
// Class initializers cannot have args for class format version >= 51. |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5337 |
if (name == vmSymbols::class_initializer_name() && |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5338 |
signature != vmSymbols::void_method_signature() && |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5339 |
_major_version >= JAVA_7_VERSION) { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5340 |
throwIllegalSignature("Method", name, signature, CHECK_0); |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5341 |
return 0; |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5342 |
} |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5343 |
|
1 | 5344 |
unsigned int args_size = 0; |
5345 |
char buf[fixed_buffer_size]; |
|
34666 | 5346 |
const char* p = signature->as_utf8_flexible_buffer(THREAD, buf, fixed_buffer_size); |
1 | 5347 |
unsigned int length = signature->utf8_length(); |
34666 | 5348 |
const char* nextp; |
1 | 5349 |
|
5350 |
// The first character must be a '(' |
|
5351 |
if ((length > 0) && (*p++ == JVM_SIGNATURE_FUNC)) { |
|
5352 |
length--; |
|
5353 |
// Skip over legal field signatures |
|
5354 |
nextp = skip_over_field_signature(p, false, length, CHECK_0); |
|
5355 |
while ((length > 0) && (nextp != NULL)) { |
|
5356 |
args_size++; |
|
5357 |
if (p[0] == 'J' || p[0] == 'D') { |
|
5358 |
args_size++; |
|
5359 |
} |
|
5360 |
length -= nextp - p; |
|
5361 |
p = nextp; |
|
5362 |
nextp = skip_over_field_signature(p, false, length, CHECK_0); |
|
5363 |
} |
|
5364 |
// The first non-signature thing better be a ')' |
|
5365 |
if ((length > 0) && (*p++ == JVM_SIGNATURE_ENDFUNC)) { |
|
5366 |
length--; |
|
33799
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5367 |
if (name->utf8_length() > 0 && name->byte_at(0) == '<') { |
77ebbd9b0ecc
8139164: JVM should throw ClassFormatError for non-void methods named <clinit>
hseigel
parents:
33612
diff
changeset
|
5368 |
// All internal methods must return void |
1 | 5369 |
if ((length == 1) && (p[0] == JVM_SIGNATURE_VOID)) { |
5370 |
return args_size; |
|
5371 |
} |
|
5372 |
} else { |
|
5373 |
// Now we better just have a return value |
|
5374 |
nextp = skip_over_field_signature(p, true, length, CHECK_0); |
|
5375 |
if (nextp && ((int)length == (nextp - p))) { |
|
5376 |
return args_size; |
|
5377 |
} |
|
5378 |
} |
|
5379 |
} |
|
5380 |
} |
|
5381 |
// Report error |
|
5709
3b5307e27c1d
6930553: classfile format checker allows invalid method descriptor in CONSTANT_NameAndType_info in some cases
kamg
parents:
5426
diff
changeset
|
5382 |
throwIllegalSignature("Method", name, signature, CHECK_0); |
1 | 5383 |
return 0; |
5384 |
} |
|
5385 |
||
34666 | 5386 |
int ClassFileParser::static_field_size() const { |
5387 |
assert(_field_info != NULL, "invariant"); |
|
5388 |
return _field_info->static_field_size; |
|
5389 |
} |
|
5390 |
||
5391 |
int ClassFileParser::total_oop_map_count() const { |
|
5392 |
assert(_field_info != NULL, "invariant"); |
|
5393 |
return _field_info->total_oop_map_count; |
|
5394 |
} |
|
5395 |
||
5396 |
jint ClassFileParser::layout_size() const { |
|
5397 |
assert(_field_info != NULL, "invariant"); |
|
5398 |
return _field_info->instance_size; |
|
5399 |
} |
|
5400 |
||
5401 |
static void check_methods_for_intrinsics(const InstanceKlass* ik, |
|
5402 |
const Array<Method*>* methods) { |
|
5403 |
assert(ik != NULL, "invariant"); |
|
5404 |
assert(methods != NULL, "invariant"); |
|
5405 |
||
5406 |
// Set up Method*::intrinsic_id as soon as we know the names of methods. |
|
5407 |
// (We used to do this lazily, but now we query it in Rewriter, |
|
5408 |
// which is eagerly done for every method, so we might as well do it now, |
|
5409 |
// when everything is fresh in memory.) |
|
5410 |
const vmSymbols::SID klass_id = Method::klass_id_for_intrinsics(ik); |
|
5411 |
||
5412 |
if (klass_id != vmSymbols::NO_SID) { |
|
5413 |
for (int j = 0; j < methods->length(); ++j) { |
|
5414 |
Method* method = methods->at(j); |
|
5415 |
method->init_intrinsic_id(); |
|
5416 |
||
5417 |
if (CheckIntrinsics) { |
|
5418 |
// Check if an intrinsic is defined for method 'method', |
|
5419 |
// but the method is not annotated with @HotSpotIntrinsicCandidate. |
|
5420 |
if (method->intrinsic_id() != vmIntrinsics::_none && |
|
5421 |
!method->intrinsic_candidate()) { |
|
5422 |
tty->print("Compiler intrinsic is defined for method [%s], " |
|
5423 |
"but the method is not annotated with @HotSpotIntrinsicCandidate.%s", |
|
5424 |
method->name_and_sig_as_C_string(), |
|
5425 |
NOT_DEBUG(" Method will not be inlined.") DEBUG_ONLY(" Exiting.") |
|
5426 |
); |
|
5427 |
tty->cr(); |
|
5428 |
DEBUG_ONLY(vm_exit(1)); |
|
5429 |
} |
|
5430 |
// Check is the method 'method' is annotated with @HotSpotIntrinsicCandidate, |
|
5431 |
// but there is no intrinsic available for it. |
|
5432 |
if (method->intrinsic_candidate() && |
|
5433 |
method->intrinsic_id() == vmIntrinsics::_none) { |
|
5434 |
tty->print("Method [%s] is annotated with @HotSpotIntrinsicCandidate, " |
|
5435 |
"but no compiler intrinsic is defined for the method.%s", |
|
5436 |
method->name_and_sig_as_C_string(), |
|
5437 |
NOT_DEBUG("") DEBUG_ONLY(" Exiting.") |
|
5438 |
); |
|
5439 |
tty->cr(); |
|
5440 |
DEBUG_ONLY(vm_exit(1)); |
|
5441 |
} |
|
1 | 5442 |
} |
34666 | 5443 |
} // end for |
5444 |
||
5445 |
#ifdef ASSERT |
|
5446 |
if (CheckIntrinsics) { |
|
5447 |
// Check for orphan methods in the current class. A method m |
|
5448 |
// of a class C is orphan if an intrinsic is defined for method m, |
|
5449 |
// but class C does not declare m. |
|
5450 |
// The check is potentially expensive, therefore it is available |
|
5451 |
// only in debug builds. |
|
5452 |
||
5453 |
for (int id = vmIntrinsics::FIRST_ID; id < (int)vmIntrinsics::ID_LIMIT; ++id) { |
|
5454 |
if (vmIntrinsics::_compiledLambdaForm == id) { |
|
5455 |
// The _compiledLamdbdaForm intrinsic is a special marker for bytecode |
|
5456 |
// generated for the JVM from a LambdaForm and therefore no method |
|
5457 |
// is defined for it. |
|
5458 |
continue; |
|
5459 |
} |
|
5460 |
||
5461 |
if (vmIntrinsics::class_for(vmIntrinsics::ID_from(id)) == klass_id) { |
|
5462 |
// Check if the current class contains a method with the same |
|
5463 |
// name, flags, signature. |
|
5464 |
bool match = false; |
|
5465 |
for (int j = 0; j < methods->length(); ++j) { |
|
5466 |
const Method* method = methods->at(j); |
|
5467 |
if (method->intrinsic_id() == id) { |
|
5468 |
match = true; |
|
5469 |
break; |
|
5470 |
} |
|
5471 |
} |
|
5472 |
||
5473 |
if (!match) { |
|
5474 |
char buf[1000]; |
|
5475 |
tty->print("Compiler intrinsic is defined for method [%s], " |
|
5476 |
"but the method is not available in class [%s].%s", |
|
5477 |
vmIntrinsics::short_name_as_C_string(vmIntrinsics::ID_from(id), |
|
5478 |
buf, sizeof(buf)), |
|
5479 |
ik->name()->as_C_string(), |
|
5480 |
NOT_DEBUG("") DEBUG_ONLY(" Exiting.") |
|
5481 |
); |
|
5482 |
tty->cr(); |
|
5483 |
DEBUG_ONLY(vm_exit(1)); |
|
5484 |
} |
|
5485 |
} |
|
5486 |
} // end for |
|
5487 |
} // CheckIntrinsics |
|
5488 |
#endif // ASSERT |
|
5489 |
} |
|
5490 |
} |
|
5491 |
||
36508 | 5492 |
InstanceKlass* ClassFileParser::create_instance_klass(bool changed_by_loadhook, TRAPS) { |
34666 | 5493 |
if (_klass != NULL) { |
5494 |
return _klass; |
|
5495 |
} |
|
5496 |
||
5497 |
InstanceKlass* const ik = |
|
5498 |
InstanceKlass::allocate_instance_klass(*this, CHECK_NULL); |
|
5499 |
||
36508 | 5500 |
fill_instance_klass(ik, changed_by_loadhook, CHECK_NULL); |
34666 | 5501 |
|
5502 |
assert(_klass == ik, "invariant"); |
|
5503 |
||
42650 | 5504 |
ik->set_has_passed_fingerprint_check(false); |
5505 |
if (UseAOT && ik->supers_have_passed_fingerprint_checks()) { |
|
5506 |
uint64_t aot_fp = AOTLoader::get_saved_fingerprint(ik); |
|
5507 |
if (aot_fp != 0 && aot_fp == _stream->compute_fingerprint()) { |
|
5508 |
// This class matches with a class saved in an AOT library |
|
5509 |
ik->set_has_passed_fingerprint_check(true); |
|
5510 |
} else { |
|
5511 |
ResourceMark rm; |
|
5512 |
log_info(class, fingerprint)("%s : expected = " PTR64_FORMAT " actual = " PTR64_FORMAT, |
|
5513 |
ik->external_name(), aot_fp, _stream->compute_fingerprint()); |
|
5514 |
} |
|
5515 |
} |
|
5516 |
||
34666 | 5517 |
return ik; |
5518 |
} |
|
5519 |
||
36508 | 5520 |
void ClassFileParser::fill_instance_klass(InstanceKlass* ik, bool changed_by_loadhook, TRAPS) { |
34666 | 5521 |
assert(ik != NULL, "invariant"); |
5522 |
||
49348
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5523 |
// Set name and CLD before adding to CLD |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5524 |
ik->set_class_loader_data(_loader_data); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5525 |
ik->set_name(_class_name); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5526 |
|
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5527 |
// Add all classes to our internal class loader list here, |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5528 |
// including classes in the bootstrap (NULL) class loader. |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5529 |
const bool publicize = !is_internal(); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5530 |
|
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5531 |
_loader_data->add_class(ik, publicize); |
fde3feaaa4ed
8198926: Move ClassLoaderData::_dependencies to ClassLoaderData::_handles
coleenp
parents:
49340
diff
changeset
|
5532 |
|
34666 | 5533 |
set_klass_to_deallocate(ik); |
5534 |
||
5535 |
assert(_field_info != NULL, "invariant"); |
|
5536 |
assert(ik->static_field_size() == _field_info->static_field_size, "sanity"); |
|
5537 |
assert(ik->nonstatic_oop_map_count() == _field_info->total_oop_map_count, |
|
5538 |
"sanity"); |
|
5539 |
||
5540 |
assert(ik->is_instance_klass(), "sanity"); |
|
5541 |
assert(ik->size_helper() == _field_info->instance_size, "sanity"); |
|
5542 |
||
5543 |
// Fill in information already parsed |
|
5544 |
ik->set_should_verify_class(_need_verify); |
|
5545 |
||
5546 |
// Not yet: supers are done below to support the new subtype-checking fields |
|
5547 |
ik->set_nonstatic_field_size(_field_info->nonstatic_field_size); |
|
5548 |
ik->set_has_nonstatic_fields(_field_info->has_nonstatic_fields); |
|
5549 |
assert(_fac != NULL, "invariant"); |
|
5550 |
ik->set_static_oop_field_count(_fac->count[STATIC_OOP]); |
|
5551 |
||
5552 |
// this transfers ownership of a lot of arrays from |
|
5553 |
// the parser onto the InstanceKlass* |
|
5554 |
apply_parsed_class_metadata(ik, _java_fields_count, CHECK); |
|
5555 |
||
5556 |
// note that is not safe to use the fields in the parser from this point on |
|
5557 |
assert(NULL == _cp, "invariant"); |
|
5558 |
assert(NULL == _fields, "invariant"); |
|
5559 |
assert(NULL == _methods, "invariant"); |
|
5560 |
assert(NULL == _inner_classes, "invariant"); |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5561 |
assert(NULL == _nest_members, "invariant"); |
34666 | 5562 |
assert(NULL == _local_interfaces, "invariant"); |
5563 |
assert(NULL == _combined_annotations, "invariant"); |
|
5564 |
||
5565 |
if (_has_final_method) { |
|
5566 |
ik->set_has_final_method(); |
|
5567 |
} |
|
5568 |
||
5569 |
ik->copy_method_ordering(_method_ordering, CHECK); |
|
5570 |
// The InstanceKlass::_methods_jmethod_ids cache |
|
5571 |
// is managed on the assumption that the initial cache |
|
5572 |
// size is equal to the number of methods in the class. If |
|
5573 |
// that changes, then InstanceKlass::idnum_can_increment() |
|
5574 |
// has to be changed accordingly. |
|
5575 |
ik->set_initial_method_idnum(ik->methods()->length()); |
|
5576 |
||
49677 | 5577 |
ik->set_this_class_index(_this_class_index); |
5578 |
||
34666 | 5579 |
if (is_anonymous()) { |
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5580 |
// _this_class_index is a CONSTANT_Class entry that refers to this |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5581 |
// anonymous class itself. If this class needs to refer to its own methods or |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5582 |
// fields, it would use a CONSTANT_MethodRef, etc, which would reference |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5583 |
// _this_class_index. However, because this class is anonymous (it's |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5584 |
// not stored in SystemDictionary), _this_class_index cannot be resolved |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5585 |
// with ConstantPool::klass_at_impl, which does a SystemDictionary lookup. |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5586 |
// Therefore, we must eagerly resolve _this_class_index now. |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5587 |
ik->constants()->klass_at_put(_this_class_index, ik); |
34666 | 5588 |
} |
5589 |
||
5590 |
ik->set_minor_version(_minor_version); |
|
5591 |
ik->set_major_version(_major_version); |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5592 |
ik->set_has_nonstatic_concrete_methods(_has_nonstatic_concrete_methods); |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5593 |
ik->set_declares_nonstatic_concrete_methods(_declares_nonstatic_concrete_methods); |
34666 | 5594 |
|
5595 |
if (_host_klass != NULL) { |
|
5596 |
assert (ik->is_anonymous(), "should be the same"); |
|
5597 |
ik->set_host_klass(_host_klass); |
|
5598 |
} |
|
5599 |
||
36508 | 5600 |
// Set PackageEntry for this_klass |
5601 |
oop cl = ik->class_loader(); |
|
5602 |
Handle clh = Handle(THREAD, java_lang_ClassLoader::non_reflection_class_loader(cl)); |
|
5603 |
ClassLoaderData* cld = ClassLoaderData::class_loader_data_or_null(clh()); |
|
5604 |
ik->set_package(cld, CHECK); |
|
5605 |
||
34666 | 5606 |
const Array<Method*>* const methods = ik->methods(); |
5607 |
assert(methods != NULL, "invariant"); |
|
5608 |
const int methods_len = methods->length(); |
|
5609 |
||
5610 |
check_methods_for_intrinsics(ik, methods); |
|
5611 |
||
5612 |
// Fill in field values obtained by parse_classfile_attributes |
|
5613 |
if (_parsed_annotations->has_any_annotations()) { |
|
5614 |
_parsed_annotations->apply_to(ik); |
|
5615 |
} |
|
5616 |
||
5617 |
apply_parsed_class_attributes(ik); |
|
5618 |
||
5619 |
// Miranda methods |
|
5620 |
if ((_num_miranda_methods > 0) || |
|
5621 |
// if this class introduced new miranda methods or |
|
5622 |
(_super_klass != NULL && _super_klass->has_miranda_methods()) |
|
5623 |
// super class exists and this class inherited miranda methods |
|
5624 |
) { |
|
5625 |
ik->set_has_miranda_methods(); // then set a flag |
|
5626 |
} |
|
5627 |
||
5628 |
// Fill in information needed to compute superclasses. |
|
49948
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
5629 |
ik->initialize_supers(const_cast<InstanceKlass*>(_super_klass), _transitive_interfaces, CHECK); |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
5630 |
ik->set_transitive_interfaces(_transitive_interfaces); |
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
5631 |
_transitive_interfaces = NULL; |
34666 | 5632 |
|
5633 |
// Initialize itable offset tables |
|
5634 |
klassItable::setup_itable_offset_table(ik); |
|
5635 |
||
5636 |
// Compute transitive closure of interfaces this class implements |
|
5637 |
// Do final class setup |
|
5638 |
fill_oop_maps(ik, |
|
5639 |
_field_info->nonstatic_oop_map_count, |
|
5640 |
_field_info->nonstatic_oop_offsets, |
|
5641 |
_field_info->nonstatic_oop_counts); |
|
5642 |
||
5643 |
// Fill in has_finalizer, has_vanilla_constructor, and layout_helper |
|
5644 |
set_precomputed_flags(ik); |
|
5645 |
||
5646 |
// check if this class can access its super class |
|
5647 |
check_super_class_access(ik, CHECK); |
|
5648 |
||
5649 |
// check if this class can access its superinterfaces |
|
5650 |
check_super_interface_access(ik, CHECK); |
|
5651 |
||
5652 |
// check if this class overrides any final method |
|
5653 |
check_final_method_override(ik, CHECK); |
|
5654 |
||
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5655 |
// reject static interface methods prior to Java 8 |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5656 |
if (ik->is_interface() && _major_version < JAVA_8_VERSION) { |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5657 |
check_illegal_static_method(ik, CHECK); |
1 | 5658 |
} |
34666 | 5659 |
|
36508 | 5660 |
// Obtain this_klass' module entry |
5661 |
ModuleEntry* module_entry = ik->module(); |
|
5662 |
assert(module_entry != NULL, "module_entry should always be set"); |
|
5663 |
||
44520
0553e129e0ec
8177530: Module system implementation refresh (4/2017)
alanb
parents:
44243
diff
changeset
|
5664 |
// Obtain java.lang.Module |
46773
fb17cc9a6847
8185717: Make ModuleEntry->module() return an oop not a jobject
hseigel
parents:
46727
diff
changeset
|
5665 |
Handle module_handle(THREAD, module_entry->module()); |
36508 | 5666 |
|
34666 | 5667 |
// Allocate mirror and initialize static fields |
5668 |
// The create_mirror() call will also call compute_modifiers() |
|
5669 |
java_lang_Class::create_mirror(ik, |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
5670 |
Handle(THREAD, _loader_data->class_loader()), |
36508 | 5671 |
module_handle, |
34666 | 5672 |
_protection_domain, |
5673 |
CHECK); |
|
5674 |
||
5675 |
assert(_all_mirandas != NULL, "invariant"); |
|
5676 |
||
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5677 |
// Generate any default methods - default methods are public interface methods |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5678 |
// that have a default implementation. This is new with Java 8. |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5679 |
if (_has_nonstatic_concrete_methods) { |
34666 | 5680 |
DefaultMethods::generate_default_methods(ik, |
5681 |
_all_mirandas, |
|
5682 |
CHECK); |
|
5683 |
} |
|
5684 |
||
36508 | 5685 |
// Add read edges to the unnamed modules of the bootstrap and app class loaders. |
5686 |
if (changed_by_loadhook && !module_handle.is_null() && module_entry->is_named() && |
|
5687 |
!module_entry->has_default_read_edges()) { |
|
5688 |
if (!module_entry->set_has_default_read_edges()) { |
|
5689 |
// We won a potential race |
|
5690 |
JvmtiExport::add_default_read_edges(module_handle, THREAD); |
|
5691 |
} |
|
5692 |
} |
|
5693 |
||
34666 | 5694 |
// Update the loader_data graph. |
5695 |
record_defined_class_dependencies(ik, CHECK); |
|
5696 |
||
5697 |
ClassLoadingService::notify_class_loaded(ik, false /* not shared class */); |
|
5698 |
||
5699 |
if (!is_internal()) { |
|
38151
fffedc5e5cf8
8154110: Update class* and safepoint* logging subsystems
mockner
parents:
38147
diff
changeset
|
5700 |
if (log_is_enabled(Info, class, load)) { |
36508 | 5701 |
ResourceMark rm; |
39277
460f34bbd0c0
8157490: JCK test vm/jni/DefineClass/dfcl001/dfcl00101m1/dfcl00101m1 crashes when run with -Xlog:classload=info
mockner
parents:
39218
diff
changeset
|
5702 |
const char* module_name = (module_entry->name() == NULL) ? UNNAMED_MODULE : module_entry->name()->as_C_string(); |
46444
677be3444372
8154791: Xlog classload too redundant msgs info/debug
rprotacio
parents:
46427
diff
changeset
|
5703 |
ik->print_class_load_logging(_loader_data, module_name, _stream); |
34666 | 5704 |
} |
5705 |
||
49716 | 5706 |
if (ik->minor_version() == JAVA_PREVIEW_MINOR_VERSION && |
5707 |
ik->major_version() != JAVA_MIN_SUPPORTED_VERSION && |
|
5708 |
log_is_enabled(Info, class, preview)) { |
|
5709 |
ResourceMark rm; |
|
5710 |
log_info(class, preview)("Loading preview feature type %s", ik->external_name()); |
|
5711 |
} |
|
5712 |
||
38151
fffedc5e5cf8
8154110: Update class* and safepoint* logging subsystems
mockner
parents:
38147
diff
changeset
|
5713 |
if (log_is_enabled(Debug, class, resolve)) { |
34666 | 5714 |
ResourceMark rm; |
5715 |
// print out the superclass. |
|
5716 |
const char * from = ik->external_name(); |
|
5717 |
if (ik->java_super() != NULL) { |
|
38151
fffedc5e5cf8
8154110: Update class* and safepoint* logging subsystems
mockner
parents:
38147
diff
changeset
|
5718 |
log_debug(class, resolve)("%s %s (super)", |
34666 | 5719 |
from, |
5720 |
ik->java_super()->external_name()); |
|
1 | 5721 |
} |
34666 | 5722 |
// print out each of the interface classes referred to by this class. |
5723 |
const Array<Klass*>* const local_interfaces = ik->local_interfaces(); |
|
5724 |
if (local_interfaces != NULL) { |
|
5725 |
const int length = local_interfaces->length(); |
|
5726 |
for (int i = 0; i < length; i++) { |
|
5727 |
const Klass* const k = local_interfaces->at(i); |
|
5728 |
const char * to = k->external_name(); |
|
38151
fffedc5e5cf8
8154110: Update class* and safepoint* logging subsystems
mockner
parents:
38147
diff
changeset
|
5729 |
log_debug(class, resolve)("%s %s (interface)", from, to); |
1 | 5730 |
} |
5731 |
} |
|
5732 |
} |
|
5733 |
} |
|
34666 | 5734 |
|
50113 | 5735 |
JFR_ONLY(INIT_ID(ik);) |
34666 | 5736 |
|
5737 |
// If we reach here, all is well. |
|
5738 |
// Now remove the InstanceKlass* from the _klass_to_deallocate field |
|
5739 |
// in order for it to not be destroyed in the ClassFileParser destructor. |
|
5740 |
set_klass_to_deallocate(NULL); |
|
5741 |
||
5742 |
// it's official |
|
5743 |
set_klass(ik); |
|
5744 |
||
5745 |
debug_only(ik->verify();) |
|
5746 |
} |
|
5747 |
||
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5748 |
// For an anonymous class that is in the unnamed package, move it to its host class's |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5749 |
// package by prepending its host class's package name to its class name and setting |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5750 |
// its _class_name field. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5751 |
void ClassFileParser::prepend_host_package_name(const InstanceKlass* host_klass, TRAPS) { |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5752 |
ResourceMark rm(THREAD); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5753 |
assert(strrchr(_class_name->as_C_string(), '/') == NULL, |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5754 |
"Anonymous class should not be in a package"); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5755 |
const char* host_pkg_name = |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5756 |
ClassLoader::package_from_name(host_klass->name()->as_C_string(), NULL); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5757 |
|
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5758 |
if (host_pkg_name != NULL) { |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5759 |
size_t host_pkg_len = strlen(host_pkg_name); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5760 |
int class_name_len = _class_name->utf8_length(); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5761 |
char* new_anon_name = |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5762 |
NEW_RESOURCE_ARRAY(char, host_pkg_len + 1 + class_name_len); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5763 |
// Copy host package name and trailing /. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5764 |
strncpy(new_anon_name, host_pkg_name, host_pkg_len); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5765 |
new_anon_name[host_pkg_len] = '/'; |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5766 |
// Append anonymous class name. The anonymous class name can contain odd |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5767 |
// characters. So, do a strncpy instead of using sprintf("%s..."). |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5768 |
strncpy(new_anon_name + host_pkg_len + 1, (char *)_class_name->base(), class_name_len); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5769 |
|
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5770 |
// Create a symbol and update the anonymous class name. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5771 |
_class_name = SymbolTable::new_symbol(new_anon_name, |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5772 |
(int)host_pkg_len + 1 + class_name_len, |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5773 |
CHECK); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5774 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5775 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5776 |
|
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5777 |
// If the host class and the anonymous class are in the same package then do |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5778 |
// nothing. If the anonymous class is in the unnamed package then move it to its |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5779 |
// host's package. If the classes are in different packages then throw an IAE |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5780 |
// exception. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5781 |
void ClassFileParser::fix_anonymous_class_name(TRAPS) { |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5782 |
assert(_host_klass != NULL, "Expected an anonymous class"); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5783 |
|
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5784 |
const jbyte* anon_last_slash = UTF8::strrchr(_class_name->base(), |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5785 |
_class_name->utf8_length(), '/'); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5786 |
if (anon_last_slash == NULL) { // Unnamed package |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5787 |
prepend_host_package_name(_host_klass, CHECK); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5788 |
} else { |
46697
2fdbdc5e0765
8077203: Avoid unnecessary stripping of package names from FQN's in is_same_class_package() methods
hseigel
parents:
46625
diff
changeset
|
5789 |
if (!_host_klass->is_same_class_package(_host_klass->class_loader(), _class_name)) { |
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5790 |
ResourceMark rm(THREAD); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5791 |
THROW_MSG(vmSymbols::java_lang_IllegalArgumentException(), |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5792 |
err_msg("Host class %s and anonymous class %s are in different packages", |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5793 |
_host_klass->name()->as_C_string(), _class_name->as_C_string())); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5794 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5795 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5796 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5797 |
|
40856
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5798 |
static bool relax_format_check_for(ClassLoaderData* loader_data) { |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5799 |
bool trusted = (loader_data->is_the_null_class_loader_data() || |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5800 |
SystemDictionary::is_platform_class_loader(loader_data->class_loader())); |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5801 |
bool need_verify = |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5802 |
// verifyAll |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5803 |
(BytecodeVerificationLocal && BytecodeVerificationRemote) || |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5804 |
// verifyRemote |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5805 |
(!BytecodeVerificationLocal && BytecodeVerificationRemote && !trusted); |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5806 |
return !need_verify; |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5807 |
} |
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5808 |
|
34666 | 5809 |
ClassFileParser::ClassFileParser(ClassFileStream* stream, |
5810 |
Symbol* name, |
|
5811 |
ClassLoaderData* loader_data, |
|
5812 |
Handle protection_domain, |
|
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
5813 |
const InstanceKlass* host_klass, |
34666 | 5814 |
GrowableArray<Handle>* cp_patches, |
5815 |
Publicity pub_level, |
|
5816 |
TRAPS) : |
|
5817 |
_stream(stream), |
|
5818 |
_requested_name(name), |
|
5819 |
_loader_data(loader_data), |
|
5820 |
_host_klass(host_klass), |
|
5821 |
_cp_patches(cp_patches), |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5822 |
_num_patched_klasses(0), |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5823 |
_max_num_patched_klasses(0), |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5824 |
_orig_cp_size(0), |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5825 |
_first_patched_klass_resolved_index(0), |
34666 | 5826 |
_super_klass(), |
5827 |
_cp(NULL), |
|
5828 |
_fields(NULL), |
|
5829 |
_methods(NULL), |
|
5830 |
_inner_classes(NULL), |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5831 |
_nest_members(NULL), |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5832 |
_nest_host(0), |
34666 | 5833 |
_local_interfaces(NULL), |
5834 |
_transitive_interfaces(NULL), |
|
5835 |
_combined_annotations(NULL), |
|
5836 |
_annotations(NULL), |
|
5837 |
_type_annotations(NULL), |
|
5838 |
_fields_annotations(NULL), |
|
5839 |
_fields_type_annotations(NULL), |
|
5840 |
_klass(NULL), |
|
5841 |
_klass_to_deallocate(NULL), |
|
5842 |
_parsed_annotations(NULL), |
|
5843 |
_fac(NULL), |
|
5844 |
_field_info(NULL), |
|
5845 |
_method_ordering(NULL), |
|
5846 |
_all_mirandas(NULL), |
|
5847 |
_vtable_size(0), |
|
5848 |
_itable_size(0), |
|
5849 |
_num_miranda_methods(0), |
|
5850 |
_rt(REF_NONE), |
|
5851 |
_protection_domain(protection_domain), |
|
5852 |
_access_flags(), |
|
5853 |
_pub_level(pub_level), |
|
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
5854 |
_bad_constant_seen(0), |
34666 | 5855 |
_synthetic_flag(false), |
5856 |
_sde_length(false), |
|
5857 |
_sde_buffer(NULL), |
|
5858 |
_sourcefile_index(0), |
|
5859 |
_generic_signature_index(0), |
|
5860 |
_major_version(0), |
|
5861 |
_minor_version(0), |
|
5862 |
_this_class_index(0), |
|
5863 |
_super_class_index(0), |
|
5864 |
_itfs_len(0), |
|
5865 |
_java_fields_count(0), |
|
5866 |
_need_verify(false), |
|
5867 |
_relax_verify(false), |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5868 |
_has_nonstatic_concrete_methods(false), |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
5869 |
_declares_nonstatic_concrete_methods(false), |
34666 | 5870 |
_has_final_method(false), |
5871 |
_has_finalizer(false), |
|
5872 |
_has_empty_finalizer(false), |
|
5873 |
_has_vanilla_constructor(false), |
|
5874 |
_max_bootstrap_specifier_index(-1) { |
|
5875 |
||
5876 |
_class_name = name != NULL ? name : vmSymbols::unknown_class_name(); |
|
5877 |
||
5878 |
assert(THREAD->is_Java_thread(), "invariant"); |
|
5879 |
assert(_loader_data != NULL, "invariant"); |
|
5880 |
assert(stream != NULL, "invariant"); |
|
5881 |
assert(_stream != NULL, "invariant"); |
|
5882 |
assert(_stream->buffer() == _stream->current(), "invariant"); |
|
5883 |
assert(_class_name != NULL, "invariant"); |
|
5884 |
assert(0 == _access_flags.as_int(), "invariant"); |
|
5885 |
||
5886 |
// Figure out whether we can skip format checking (matching classic VM behavior) |
|
5887 |
if (DumpSharedSpaces) { |
|
5888 |
// verify == true means it's a 'remote' class (i.e., non-boot class) |
|
5889 |
// Verification decision is based on BytecodeVerificationRemote flag |
|
5890 |
// for those classes. |
|
5891 |
_need_verify = (stream->need_verify()) ? BytecodeVerificationRemote : |
|
5892 |
BytecodeVerificationLocal; |
|
5893 |
} |
|
5894 |
else { |
|
5895 |
_need_verify = Verifier::should_verify_for(_loader_data->class_loader(), |
|
5896 |
stream->need_verify()); |
|
5897 |
} |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5898 |
if (_cp_patches != NULL) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5899 |
int len = _cp_patches->length(); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5900 |
for (int i=0; i<len; i++) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5901 |
if (has_cp_patch_at(i)) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5902 |
Handle patch = cp_patch_at(i); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5903 |
if (java_lang_String::is_instance(patch()) || java_lang_Class::is_instance(patch())) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5904 |
// We need to append the names of the patched classes to the end of the constant pool, |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5905 |
// because a patched class may have a Utf8 name that's not already included in the |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5906 |
// original constant pool. These class names are used when patch_constant_pool() |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5907 |
// calls patch_class(). |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5908 |
// |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5909 |
// Note that a String in cp_patch_at(i) may be used to patch a Utf8, a String, or a Class. |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5910 |
// At this point, we don't know the tag for index i yet, because we haven't parsed the |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5911 |
// constant pool. So we can only assume the worst -- every String is used to patch a Class. |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5912 |
_max_num_patched_klasses++; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5913 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5914 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5915 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
5916 |
} |
34666 | 5917 |
|
5918 |
// synch back verification state to stream |
|
5919 |
stream->set_verify(_need_verify); |
|
5920 |
||
5921 |
// Check if verification needs to be relaxed for this class file |
|
5922 |
// Do not restrict it to jdk1.0 or jdk1.1 to maintain backward compatibility (4982376) |
|
40856
3378947a95e6
8148854: Class names "SomeClass" and "LSomeClass;" treated by JVM as an equivalent
rprotacio
parents:
40633
diff
changeset
|
5923 |
_relax_verify = relax_format_check_for(_loader_data); |
34666 | 5924 |
|
5925 |
parse_stream(stream, CHECK); |
|
5926 |
||
5927 |
post_process_parsed_stream(stream, _cp, CHECK); |
|
5928 |
} |
|
5929 |
||
5930 |
void ClassFileParser::clear_class_metadata() { |
|
5931 |
// metadata created before the instance klass is created. Must be |
|
5932 |
// deallocated if classfile parsing returns an error. |
|
5933 |
_cp = NULL; |
|
5934 |
_fields = NULL; |
|
5935 |
_methods = NULL; |
|
5936 |
_inner_classes = NULL; |
|
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5937 |
_nest_members = NULL; |
34666 | 5938 |
_local_interfaces = NULL; |
5939 |
_combined_annotations = NULL; |
|
5940 |
_annotations = _type_annotations = NULL; |
|
5941 |
_fields_annotations = _fields_type_annotations = NULL; |
|
5942 |
} |
|
5943 |
||
5944 |
// Destructor to clean up |
|
5945 |
ClassFileParser::~ClassFileParser() { |
|
5946 |
if (_cp != NULL) { |
|
5947 |
MetadataFactory::free_metadata(_loader_data, _cp); |
|
5948 |
} |
|
5949 |
if (_fields != NULL) { |
|
5950 |
MetadataFactory::free_array<u2>(_loader_data, _fields); |
|
5951 |
} |
|
5952 |
||
5953 |
if (_methods != NULL) { |
|
5954 |
// Free methods |
|
5955 |
InstanceKlass::deallocate_methods(_loader_data, _methods); |
|
5956 |
} |
|
5957 |
||
5958 |
// beware of the Universe::empty_blah_array!! |
|
5959 |
if (_inner_classes != NULL && _inner_classes != Universe::the_empty_short_array()) { |
|
5960 |
MetadataFactory::free_array<u2>(_loader_data, _inner_classes); |
|
5961 |
} |
|
5962 |
||
50735
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5963 |
if (_nest_members != NULL && _nest_members != Universe::the_empty_short_array()) { |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5964 |
MetadataFactory::free_array<u2>(_loader_data, _nest_members); |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5965 |
} |
2f2af62dfac7
8010319: Implementation of JEP 181: Nest-Based Access Control
dholmes
parents:
50634
diff
changeset
|
5966 |
|
34666 | 5967 |
// Free interfaces |
5968 |
InstanceKlass::deallocate_interfaces(_loader_data, _super_klass, |
|
5969 |
_local_interfaces, _transitive_interfaces); |
|
5970 |
||
5971 |
if (_combined_annotations != NULL) { |
|
5972 |
// After all annotations arrays have been created, they are installed into the |
|
5973 |
// Annotations object that will be assigned to the InstanceKlass being created. |
|
5974 |
||
5975 |
// Deallocate the Annotations object and the installed annotations arrays. |
|
5976 |
_combined_annotations->deallocate_contents(_loader_data); |
|
5977 |
||
5978 |
// If the _combined_annotations pointer is non-NULL, |
|
5979 |
// then the other annotations fields should have been cleared. |
|
5980 |
assert(_annotations == NULL, "Should have been cleared"); |
|
5981 |
assert(_type_annotations == NULL, "Should have been cleared"); |
|
5982 |
assert(_fields_annotations == NULL, "Should have been cleared"); |
|
5983 |
assert(_fields_type_annotations == NULL, "Should have been cleared"); |
|
5984 |
} else { |
|
5985 |
// If the annotations arrays were not installed into the Annotations object, |
|
5986 |
// then they have to be deallocated explicitly. |
|
5987 |
MetadataFactory::free_array<u1>(_loader_data, _annotations); |
|
5988 |
MetadataFactory::free_array<u1>(_loader_data, _type_annotations); |
|
5989 |
Annotations::free_contents(_loader_data, _fields_annotations); |
|
5990 |
Annotations::free_contents(_loader_data, _fields_type_annotations); |
|
5991 |
} |
|
5992 |
||
5993 |
clear_class_metadata(); |
|
49948
ff8dbb56740a
8200466: Revisit the setting of _transitive_interfaces in InstanceKlass
ccheung
parents:
49716
diff
changeset
|
5994 |
_transitive_interfaces = NULL; |
34666 | 5995 |
|
5996 |
// deallocate the klass if already created. Don't directly deallocate, but add |
|
5997 |
// to the deallocate list so that the klass is removed from the CLD::_klasses list |
|
5998 |
// at a safepoint. |
|
5999 |
if (_klass_to_deallocate != NULL) { |
|
6000 |
_loader_data->add_to_deallocate_list(_klass_to_deallocate); |
|
6001 |
} |
|
1 | 6002 |
} |
6003 |
||
34666 | 6004 |
void ClassFileParser::parse_stream(const ClassFileStream* const stream, |
6005 |
TRAPS) { |
|
6006 |
||
6007 |
assert(stream != NULL, "invariant"); |
|
6008 |
assert(_class_name != NULL, "invariant"); |
|
6009 |
||
6010 |
// BEGIN STREAM PARSING |
|
6011 |
stream->guarantee_more(8, CHECK); // magic, major, minor |
|
6012 |
// Magic value |
|
6013 |
const u4 magic = stream->get_u4_fast(); |
|
6014 |
guarantee_property(magic == JAVA_CLASSFILE_MAGIC, |
|
6015 |
"Incompatible magic value %u in class file %s", |
|
6016 |
magic, CHECK); |
|
6017 |
||
6018 |
// Version numbers |
|
6019 |
_minor_version = stream->get_u2_fast(); |
|
6020 |
_major_version = stream->get_u2_fast(); |
|
6021 |
||
6022 |
if (DumpSharedSpaces && _major_version < JAVA_1_5_VERSION) { |
|
6023 |
ResourceMark rm; |
|
6024 |
warning("Pre JDK 1.5 class not supported by CDS: %u.%u %s", |
|
6025 |
_major_version, _minor_version, _class_name->as_C_string()); |
|
6026 |
Exceptions::fthrow( |
|
6027 |
THREAD_AND_LOCATION, |
|
6028 |
vmSymbols::java_lang_UnsupportedClassVersionError(), |
|
6029 |
"Unsupported major.minor version for dump time %u.%u", |
|
6030 |
_major_version, |
|
6031 |
_minor_version); |
|
6032 |
} |
|
6033 |
||
6034 |
// Check version numbers - we check this even with verifier off |
|
49716 | 6035 |
verify_class_version(_major_version, _minor_version, _class_name, CHECK); |
34666 | 6036 |
|
6037 |
stream->guarantee_more(3, CHECK); // length, first cp tag |
|
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6038 |
u2 cp_size = stream->get_u2_fast(); |
34666 | 6039 |
|
6040 |
guarantee_property( |
|
6041 |
cp_size >= 1, "Illegal constant pool size %u in class file %s", |
|
6042 |
cp_size, CHECK); |
|
6043 |
||
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6044 |
_orig_cp_size = cp_size; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6045 |
if (int(cp_size) + _max_num_patched_klasses > 0xffff) { |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6046 |
THROW_MSG(vmSymbols::java_lang_InternalError(), "not enough space for patched classes"); |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6047 |
} |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6048 |
cp_size += _max_num_patched_klasses; |
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6049 |
|
34666 | 6050 |
_cp = ConstantPool::allocate(_loader_data, |
6051 |
cp_size, |
|
6052 |
CHECK); |
|
6053 |
||
6054 |
ConstantPool* const cp = _cp; |
|
6055 |
||
46427
54713555867e
8171392: Move Klass pointers outside of ConstantPool entries so ConstantPool can be read-only
iklam
parents:
46388
diff
changeset
|
6056 |
parse_constant_pool(stream, cp, _orig_cp_size, CHECK); |
34666 | 6057 |
|
6058 |
assert(cp_size == (const u2)cp->length(), "invariant"); |
|
6059 |
||
6060 |
// ACCESS FLAGS |
|
6061 |
stream->guarantee_more(8, CHECK); // flags, this_class, super_class, infs_len |
|
6062 |
||
6063 |
// Access flags |
|
43977
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6064 |
jint flags; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6065 |
// JVM_ACC_MODULE is defined in JDK-9 and later. |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6066 |
if (_major_version >= JAVA_9_VERSION) { |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6067 |
flags = stream->get_u2_fast() & (JVM_RECOGNIZED_CLASS_MODIFIERS | JVM_ACC_MODULE); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6068 |
} else { |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6069 |
flags = stream->get_u2_fast() & JVM_RECOGNIZED_CLASS_MODIFIERS; |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6070 |
} |
34666 | 6071 |
|
6072 |
if ((flags & JVM_ACC_INTERFACE) && _major_version < JAVA_6_VERSION) { |
|
6073 |
// Set abstract bit for old class files for backward compatibility |
|
6074 |
flags |= JVM_ACC_ABSTRACT; |
|
6075 |
} |
|
6076 |
||
43977
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6077 |
verify_legal_class_modifiers(flags, CHECK); |
bf59cd83ea95
8174725: JVM should throw NoClassDefFoundError if ACC_MODULE is set in access_flags
hseigel
parents:
43177
diff
changeset
|
6078 |
|
44239
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6079 |
short bad_constant = class_bad_constant_seen(); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6080 |
if (bad_constant != 0) { |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6081 |
// Do not throw CFE until after the access_flags are checked because if |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6082 |
// ACC_MODULE is set in the access flags, then NCDFE must be thrown, not CFE. |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6083 |
classfile_parse_error("Unknown constant tag %u in class file %s", bad_constant, CHECK); |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6084 |
} |
fdd97dc2367b
8175383: JVM should throw NCDFE if ACC_MODULE and CONSTANT_Module/Package are set
hseigel
parents:
43977
diff
changeset
|
6085 |
|
34666 | 6086 |
_access_flags.set_flags(flags); |
6087 |
||
6088 |
// This class and superclass |
|
6089 |
_this_class_index = stream->get_u2_fast(); |
|
6090 |
check_property( |
|
6091 |
valid_cp_range(_this_class_index, cp_size) && |
|
6092 |
cp->tag_at(_this_class_index).is_unresolved_klass(), |
|
6093 |
"Invalid this class index %u in constant pool in class file %s", |
|
6094 |
_this_class_index, CHECK); |
|
6095 |
||
6096 |
Symbol* const class_name_in_cp = cp->klass_name_at(_this_class_index); |
|
6097 |
assert(class_name_in_cp != NULL, "class_name can't be null"); |
|
6098 |
||
6099 |
// Update _class_name which could be null previously |
|
6100 |
// to reflect the name in the constant pool |
|
6101 |
_class_name = class_name_in_cp; |
|
6102 |
||
6103 |
// Don't need to check whether this class name is legal or not. |
|
6104 |
// It has been checked when constant pool is parsed. |
|
6105 |
// However, make sure it is not an array type. |
|
6106 |
if (_need_verify) { |
|
6107 |
guarantee_property(_class_name->byte_at(0) != JVM_SIGNATURE_ARRAY, |
|
6108 |
"Bad class name in class file %s", |
|
6109 |
CHECK); |
|
6110 |
} |
|
6111 |
||
6112 |
// Checks if name in class file matches requested name |
|
6113 |
if (_requested_name != NULL && _requested_name != _class_name) { |
|
6114 |
ResourceMark rm(THREAD); |
|
6115 |
Exceptions::fthrow( |
|
6116 |
THREAD_AND_LOCATION, |
|
6117 |
vmSymbols::java_lang_NoClassDefFoundError(), |
|
6118 |
"%s (wrong name: %s)", |
|
6119 |
_class_name->as_C_string(), |
|
6120 |
_requested_name != NULL ? _requested_name->as_C_string() : "NoName" |
|
6121 |
); |
|
6122 |
return; |
|
6123 |
} |
|
6124 |
||
40923
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6125 |
// if this is an anonymous class fix up its name if it's in the unnamed |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6126 |
// package. Otherwise, throw IAE if it is in a different package than |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6127 |
// its host class. |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6128 |
if (_host_klass != NULL) { |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6129 |
fix_anonymous_class_name(CHECK); |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6130 |
} |
10fe1c28b9f6
8058575: IllegalAccessError trying to access package-private class from VM anonymous class
hseigel
parents:
40921
diff
changeset
|
6131 |
|
40016 | 6132 |
// Verification prevents us from creating names with dots in them, this |
6133 |
// asserts that that's the case. |
|
6134 |
assert(is_internal_format(_class_name), "external class name format used internally"); |
|
6135 |
||
34666 | 6136 |
if (!is_internal()) { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6137 |
LogTarget(Debug, class, preorder) lt; |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6138 |
if (lt.is_enabled()){ |
37094
c12f414936a1
8149995: TraceClassLoadingPreorder has been converted to Unified Logging.
mockner
parents:
37078
diff
changeset
|
6139 |
ResourceMark rm(THREAD); |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6140 |
LogStream ls(lt); |
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6141 |
ls.print("%s", _class_name->as_klass_external_name()); |
34666 | 6142 |
if (stream->source() != NULL) { |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6143 |
ls.print(" source: %s", stream->source()); |
34666 | 6144 |
} |
46701
f559541c0daa
8181917: Refactor UL LogStreams to avoid using resource area
stuefe
parents:
46697
diff
changeset
|
6145 |
ls.cr(); |
34666 | 6146 |
} |
37094
c12f414936a1
8149995: TraceClassLoadingPreorder has been converted to Unified Logging.
mockner
parents:
37078
diff
changeset
|
6147 |
|
34666 | 6148 |
#if INCLUDE_CDS |
6149 |
if (DumpLoadedClassList != NULL && stream->source() != NULL && classlist_file->is_open()) { |
|
47673
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6150 |
if (!ClassLoader::has_jrt_entry()) { |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6151 |
warning("DumpLoadedClassList and CDS are not supported in exploded build"); |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6152 |
DumpLoadedClassList = NULL; |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6153 |
} else if (SystemDictionaryShared::is_sharing_possible(_loader_data) && |
38313
615905db3fe4
8149977: DumpLoadedClassList should not include generated classes.
jiangli
parents:
38177
diff
changeset
|
6154 |
_host_klass == NULL) { |
47673
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6155 |
// Only dump the classes that can be stored into CDS archive. |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6156 |
// Anonymous classes such as generated LambdaForm classes are also not included. |
41741
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6157 |
oop class_loader = _loader_data->class_loader(); |
34666 | 6158 |
ResourceMark rm(THREAD); |
47673
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6159 |
bool skip = false; |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6160 |
if (class_loader == NULL || SystemDictionary::is_platform_class_loader(class_loader)) { |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6161 |
// For the boot and platform class loaders, skip classes that are not found in the |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6162 |
// java runtime image, such as those found in the --patch-module entries. |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6163 |
// These classes can't be loaded from the archive during runtime. |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6164 |
if (!ClassLoader::is_modules_image(stream->source()) && strncmp(stream->source(), "jrt:", 4) != 0) { |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6165 |
skip = true; |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6166 |
} |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6167 |
|
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6168 |
if (class_loader == NULL && ClassLoader::contains_append_entry(stream->source())) { |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6169 |
// .. but don't skip the boot classes that are loaded from -Xbootclasspath/a |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6170 |
// as they can be loaded from the archive during runtime. |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6171 |
skip = false; |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6172 |
} |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6173 |
} |
6126617b8508
8185160: -XX:DumpLoadedClassList omits graal classes
iklam
parents:
47216
diff
changeset
|
6174 |
if (skip) { |
41741
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6175 |
tty->print_cr("skip writing class %s from source %s to classlist file", |
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6176 |
_class_name->as_C_string(), stream->source()); |
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6177 |
} else { |
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6178 |
classlist_file->print_cr("%s", _class_name->as_C_string()); |
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6179 |
classlist_file->flush(); |
2f5b8bbcb18c
8166931: Do not include classes which are unusable during run time in the classlist file
ccheung
parents:
41669
diff
changeset
|
6180 |
} |
34666 | 6181 |
} |
6182 |
} |
|
6183 |
#endif |
|
6184 |
} |
|
6185 |
||
6186 |
// SUPERKLASS |
|
6187 |
_super_class_index = stream->get_u2_fast(); |
|
6188 |
_super_klass = parse_super_class(cp, |
|
6189 |
_super_class_index, |
|
6190 |
_need_verify, |
|
6191 |
CHECK); |
|
6192 |
||
6193 |
// Interfaces |
|
6194 |
_itfs_len = stream->get_u2_fast(); |
|
6195 |
parse_interfaces(stream, |
|
6196 |
_itfs_len, |
|
6197 |
cp, |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6198 |
&_has_nonstatic_concrete_methods, |
34666 | 6199 |
CHECK); |
6200 |
||
6201 |
assert(_local_interfaces != NULL, "invariant"); |
|
6202 |
||
6203 |
// Fields (offsets are filled in later) |
|
6204 |
_fac = new FieldAllocationCount(); |
|
6205 |
parse_fields(stream, |
|
6206 |
_access_flags.is_interface(), |
|
6207 |
_fac, |
|
6208 |
cp, |
|
6209 |
cp_size, |
|
6210 |
&_java_fields_count, |
|
6211 |
CHECK); |
|
6212 |
||
6213 |
assert(_fields != NULL, "invariant"); |
|
6214 |
||
6215 |
// Methods |
|
6216 |
AccessFlags promoted_flags; |
|
6217 |
parse_methods(stream, |
|
6218 |
_access_flags.is_interface(), |
|
6219 |
&promoted_flags, |
|
6220 |
&_has_final_method, |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6221 |
&_declares_nonstatic_concrete_methods, |
34666 | 6222 |
CHECK); |
6223 |
||
6224 |
assert(_methods != NULL, "invariant"); |
|
6225 |
||
6226 |
// promote flags from parse_methods() to the klass' flags |
|
6227 |
_access_flags.add_promoted_flags(promoted_flags.as_int()); |
|
6228 |
||
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6229 |
if (_declares_nonstatic_concrete_methods) { |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6230 |
_has_nonstatic_concrete_methods = true; |
34666 | 6231 |
} |
6232 |
||
6233 |
// Additional attributes/annotations |
|
6234 |
_parsed_annotations = new ClassAnnotationCollector(); |
|
6235 |
parse_classfile_attributes(stream, cp, _parsed_annotations, CHECK); |
|
6236 |
||
6237 |
assert(_inner_classes != NULL, "invariant"); |
|
6238 |
||
6239 |
// Finalize the Annotations metadata object, |
|
6240 |
// now that all annotation arrays have been created. |
|
6241 |
create_combined_annotations(CHECK); |
|
6242 |
||
6243 |
// Make sure this is the end of class file stream |
|
6244 |
guarantee_property(stream->at_eos(), |
|
6245 |
"Extra bytes at the end of class file %s", |
|
6246 |
CHECK); |
|
6247 |
||
6248 |
// all bytes in stream read and parsed |
|
6249 |
} |
|
6250 |
||
6251 |
void ClassFileParser::post_process_parsed_stream(const ClassFileStream* const stream, |
|
6252 |
ConstantPool* cp, |
|
1 | 6253 |
TRAPS) { |
34666 | 6254 |
assert(stream != NULL, "invariant"); |
6255 |
assert(stream->at_eos(), "invariant"); |
|
6256 |
assert(cp != NULL, "invariant"); |
|
6257 |
assert(_loader_data != NULL, "invariant"); |
|
6258 |
||
41544 | 6259 |
if (_class_name == vmSymbols::java_lang_Object()) { |
6260 |
check_property(_local_interfaces == Universe::the_empty_klass_array(), |
|
6261 |
"java.lang.Object cannot implement an interface in class file %s", |
|
6262 |
CHECK); |
|
6263 |
} |
|
34666 | 6264 |
// We check super class after class file is parsed and format is checked |
6265 |
if (_super_class_index > 0 && NULL ==_super_klass) { |
|
6266 |
Symbol* const super_class_name = cp->klass_name_at(_super_class_index); |
|
6267 |
if (_access_flags.is_interface()) { |
|
6268 |
// Before attempting to resolve the superclass, check for class format |
|
6269 |
// errors not checked yet. |
|
6270 |
guarantee_property(super_class_name == vmSymbols::java_lang_Object(), |
|
6271 |
"Interfaces must have java.lang.Object as superclass in class file %s", |
|
6272 |
CHECK); |
|
38147
c020feaafdcb
8155685: Wrong indentation in ClassFileParser::post_process_parsed_stream
ecaspole
parents:
38060
diff
changeset
|
6273 |
} |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
6274 |
Handle loader(THREAD, _loader_data->class_loader()); |
38147
c020feaafdcb
8155685: Wrong indentation in ClassFileParser::post_process_parsed_stream
ecaspole
parents:
38060
diff
changeset
|
6275 |
_super_klass = (const InstanceKlass*) |
34666 | 6276 |
SystemDictionary::resolve_super_or_fail(_class_name, |
6277 |
super_class_name, |
|
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
6278 |
loader, |
34666 | 6279 |
_protection_domain, |
6280 |
true, |
|
6281 |
CHECK); |
|
6282 |
} |
|
6283 |
||
6284 |
if (_super_klass != NULL) { |
|
41669
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6285 |
if (_super_klass->has_nonstatic_concrete_methods()) { |
2091069b6851
8081800: AbstractMethodError when evaluating a private method in an interface via debugger
dholmes
parents:
40923
diff
changeset
|
6286 |
_has_nonstatic_concrete_methods = true; |
34666 | 6287 |
} |
6288 |
||
6289 |
if (_super_klass->is_interface()) { |
|
6290 |
ResourceMark rm(THREAD); |
|
6291 |
Exceptions::fthrow( |
|
6292 |
THREAD_AND_LOCATION, |
|
6293 |
vmSymbols::java_lang_IncompatibleClassChangeError(), |
|
6294 |
"class %s has interface %s as super class", |
|
6295 |
_class_name->as_klass_external_name(), |
|
6296 |
_super_klass->external_name() |
|
6297 |
); |
|
6298 |
return; |
|
6299 |
} |
|
6300 |
// Make sure super class is not final |
|
6301 |
if (_super_klass->is_final()) { |
|
6302 |
THROW_MSG(vmSymbols::java_lang_VerifyError(), "Cannot inherit from final class"); |
|
1 | 6303 |
} |
6304 |
} |
|
34666 | 6305 |
|
6306 |
// Compute the transitive list of all unique interfaces implemented by this class |
|
6307 |
_transitive_interfaces = |
|
6308 |
compute_transitive_interfaces(_super_klass, |
|
6309 |
_local_interfaces, |
|
6310 |
_loader_data, |
|
6311 |
CHECK); |
|
6312 |
||
6313 |
assert(_transitive_interfaces != NULL, "invariant"); |
|
6314 |
||
6315 |
// sort methods |
|
6316 |
_method_ordering = sort_methods(_methods); |
|
6317 |
||
6318 |
_all_mirandas = new GrowableArray<Method*>(20); |
|
6319 |
||
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
6320 |
Handle loader(THREAD, _loader_data->class_loader()); |
34666 | 6321 |
klassVtable::compute_vtable_size_and_num_mirandas(&_vtable_size, |
6322 |
&_num_miranda_methods, |
|
6323 |
_all_mirandas, |
|
6324 |
_super_klass, |
|
6325 |
_methods, |
|
6326 |
_access_flags, |
|
40633
c33ad2ff51de
8163808: Fix asserts and logging for old classfile vtable construction
acorn
parents:
40016
diff
changeset
|
6327 |
_major_version, |
46271
979ebd346ecf
8169881: Remove implicit Handle conversions oop->Handle
coleenp
parents:
46262
diff
changeset
|
6328 |
loader, |
34666 | 6329 |
_class_name, |
6330 |
_local_interfaces, |
|
6331 |
CHECK); |
|
6332 |
||
6333 |
// Size of Java itable (in words) |
|
6334 |
_itable_size = _access_flags.is_interface() ? 0 : |
|
6335 |
klassItable::compute_itable_size(_transitive_interfaces); |
|
6336 |
||
6337 |
assert(_fac != NULL, "invariant"); |
|
6338 |
assert(_parsed_annotations != NULL, "invariant"); |
|
6339 |
||
6340 |
_field_info = new FieldLayoutInfo(); |
|
6341 |
layout_fields(cp, _fac, _parsed_annotations, _field_info, CHECK); |
|
6342 |
||
6343 |
// Compute reference typ |
|
6344 |
_rt = (NULL ==_super_klass) ? REF_NONE : _super_klass->reference_type(); |
|
6345 |
||
1 | 6346 |
} |
34666 | 6347 |
|
6348 |
void ClassFileParser::set_klass(InstanceKlass* klass) { |
|
6349 |
||
6350 |
#ifdef ASSERT |
|
6351 |
if (klass != NULL) { |
|
6352 |
assert(NULL == _klass, "leaking?"); |
|
6353 |
} |
|
6354 |
#endif |
|
6355 |
||
6356 |
_klass = klass; |
|
6357 |
} |
|
6358 |
||
6359 |
void ClassFileParser::set_klass_to_deallocate(InstanceKlass* klass) { |
|
6360 |
||
6361 |
#ifdef ASSERT |
|
6362 |
if (klass != NULL) { |
|
6363 |
assert(NULL == _klass_to_deallocate, "leaking?"); |
|
6364 |
} |
|
6365 |
#endif |
|
6366 |
||
6367 |
_klass_to_deallocate = klass; |
|
6368 |
} |
|
6369 |
||
6370 |
// Caller responsible for ResourceMark |
|
6371 |
// clone stream with rewound position |
|
6372 |
const ClassFileStream* ClassFileParser::clone_stream() const { |
|
6373 |
assert(_stream != NULL, "invariant"); |
|
6374 |
||
6375 |
return _stream->clone(); |
|
6376 |
} |
|
40016 | 6377 |
// ---------------------------------------------------------------------------- |
6378 |
// debugging |
|
6379 |
||
6380 |
#ifdef ASSERT |
|
6381 |
||
6382 |
// return true if class_name contains no '.' (internal format is '/') |
|
6383 |
bool ClassFileParser::is_internal_format(Symbol* class_name) { |
|
6384 |
if (class_name != NULL) { |
|
6385 |
ResourceMark rm; |
|
6386 |
char* name = class_name->as_C_string(); |
|
6387 |
return strchr(name, '.') == NULL; |
|
6388 |
} else { |
|
6389 |
return true; |
|
6390 |
} |
|
6391 |
} |
|
6392 |
||
6393 |
#endif |