duke@1
|
1 /*
|
coleenp@57609
|
2 * Copyright (c) 1997, 2020, Oracle and/or its affiliates. All rights reserved.
|
duke@1
|
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
|
duke@1
|
4 *
|
duke@1
|
5 * This code is free software; you can redistribute it and/or modify it
|
duke@1
|
6 * under the terms of the GNU General Public License version 2 only, as
|
duke@1
|
7 * published by the Free Software Foundation.
|
duke@1
|
8 *
|
duke@1
|
9 * This code is distributed in the hope that it will be useful, but WITHOUT
|
duke@1
|
10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
duke@1
|
11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
duke@1
|
12 * version 2 for more details (a copy is included in the LICENSE file that
|
duke@1
|
13 * accompanied this code).
|
duke@1
|
14 *
|
duke@1
|
15 * You should have received a copy of the GNU General Public License version
|
duke@1
|
16 * 2 along with this work; if not, write to the Free Software Foundation,
|
duke@1
|
17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
|
duke@1
|
18 *
|
trims@5547
|
19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
|
trims@5547
|
20 * or visit www.oracle.com if you need additional information or have any
|
trims@5547
|
21 * questions.
|
duke@1
|
22 *
|
duke@1
|
23 */
|
duke@1
|
24
|
stefank@7397
|
25 #include "precompiled.hpp"
|
coleenp@47765
|
26 #include "jvm.h"
|
kvn@42650
|
27 #include "aot/aotLoader.hpp"
|
mgronlun@34666
|
28 #include "classfile/classFileParser.hpp"
|
mockner@35917
|
29 #include "classfile/classFileStream.hpp"
|
kvn@42650
|
30 #include "classfile/classLoader.hpp"
|
coleenp@49824
|
31 #include "classfile/classLoaderData.inline.hpp"
|
stefank@7397
|
32 #include "classfile/javaClasses.hpp"
|
alanb@42307
|
33 #include "classfile/moduleEntry.hpp"
|
stefank@54786
|
34 #include "classfile/symbolTable.hpp"
|
stefank@7397
|
35 #include "classfile/systemDictionary.hpp"
|
iklam@39713
|
36 #include "classfile/systemDictionaryShared.hpp"
|
stefank@7397
|
37 #include "classfile/verifier.hpp"
|
stefank@7397
|
38 #include "classfile/vmSymbols.hpp"
|
vlivanov@34195
|
39 #include "code/dependencyContext.hpp"
|
stefank@7397
|
40 #include "compiler/compileBroker.hpp"
|
pliden@30764
|
41 #include "gc/shared/collectedHeap.inline.hpp"
|
stefank@7397
|
42 #include "interpreter/oopMapCache.hpp"
|
stefank@7397
|
43 #include "interpreter/rewriter.hpp"
|
stefank@7397
|
44 #include "jvmtifiles/jvmti.h"
|
mockner@35917
|
45 #include "logging/log.hpp"
|
rprotacio@46444
|
46 #include "logging/logMessage.hpp"
|
stuefe@46701
|
47 #include "logging/logStream.hpp"
|
stefank@49360
|
48 #include "memory/allocation.inline.hpp"
|
stefank@25356
|
49 #include "memory/iterator.inline.hpp"
|
coleenp@13728
|
50 #include "memory/metadataFactory.hpp"
|
iklam@46746
|
51 #include "memory/metaspaceClosure.hpp"
|
jiangli@41182
|
52 #include "memory/metaspaceShared.hpp"
|
stefank@7397
|
53 #include "memory/oopFactory.hpp"
|
jprovino@37248
|
54 #include "memory/resourceArea.hpp"
|
stefank@54786
|
55 #include "memory/universe.hpp"
|
coleenp@56922
|
56 #include "oops/fieldStreams.inline.hpp"
|
redestad@53838
|
57 #include "oops/constantPool.hpp"
|
coleenp@13728
|
58 #include "oops/instanceClassLoaderKlass.hpp"
|
stefank@30150
|
59 #include "oops/instanceKlass.inline.hpp"
|
never@8725
|
60 #include "oops/instanceMirrorKlass.hpp"
|
stefank@7397
|
61 #include "oops/instanceOop.hpp"
|
coleenp@13728
|
62 #include "oops/klass.inline.hpp"
|
coleenp@13728
|
63 #include "oops/method.hpp"
|
stefank@7397
|
64 #include "oops/oop.inline.hpp"
|
vromero@57233
|
65 #include "oops/recordComponent.hpp"
|
coleenp@8076
|
66 #include "oops/symbol.hpp"
|
stefank@7397
|
67 #include "prims/jvmtiExport.hpp"
|
pliden@30764
|
68 #include "prims/jvmtiRedefineClasses.hpp"
|
jbachorik@22897
|
69 #include "prims/jvmtiThreadState.hpp"
|
coleenp@15099
|
70 #include "prims/methodComparator.hpp"
|
dholmes@40655
|
71 #include "runtime/atomic.hpp"
|
coleenp@56724
|
72 #include "runtime/biasedLocking.hpp"
|
iklam@51467
|
73 #include "runtime/fieldDescriptor.inline.hpp"
|
stefank@7397
|
74 #include "runtime/handles.inline.hpp"
|
stefank@7397
|
75 #include "runtime/javaCalls.hpp"
|
stefank@7397
|
76 #include "runtime/mutexLocker.hpp"
|
coleenp@50429
|
77 #include "runtime/orderAccess.hpp"
|
stefank@14583
|
78 #include "runtime/thread.inline.hpp"
|
coleenp@17075
|
79 #include "services/classLoadingService.hpp"
|
stefank@7397
|
80 #include "services/threadService.hpp"
|
stefank@7397
|
81 #include "utilities/dtrace.hpp"
|
coleenp@53738
|
82 #include "utilities/events.hpp"
|
jprovino@15482
|
83 #include "utilities/macros.hpp"
|
acorn@40016
|
84 #include "utilities/stringUtils.hpp"
|
stefank@7397
|
85 #ifdef COMPILER1
|
stefank@7397
|
86 #include "c1/c1_Compiler.hpp"
|
stefank@7397
|
87 #endif
|
hseigel@51543
|
88 #if INCLUDE_JFR
|
hseigel@51543
|
89 #include "jfr/jfrEvents.hpp"
|
hseigel@51543
|
90 #endif
|
hseigel@51543
|
91
|
duke@1
|
92
|
fparain@5089
|
93 #ifdef DTRACE_ENABLED
|
fparain@5089
|
94
|
dcubed@10739
|
95
|
dcubed@10739
|
96 #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED
|
dcubed@10739
|
97 #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE
|
dcubed@10739
|
98 #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT
|
dcubed@10739
|
99 #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS
|
dcubed@10739
|
100 #define HOTSPOT_CLASS_INITIALIZATION_super__failed HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED
|
dcubed@10739
|
101 #define HOTSPOT_CLASS_INITIALIZATION_clinit HOTSPOT_CLASS_INITIALIZATION_CLINIT
|
dcubed@10739
|
102 #define HOTSPOT_CLASS_INITIALIZATION_error HOTSPOT_CLASS_INITIALIZATION_ERROR
|
dcubed@10739
|
103 #define HOTSPOT_CLASS_INITIALIZATION_end HOTSPOT_CLASS_INITIALIZATION_END
|
hseigel@46341
|
104 #define DTRACE_CLASSINIT_PROBE(type, thread_type) \
|
dcubed@10739
|
105 { \
|
dcubed@10739
|
106 char* data = NULL; \
|
dcubed@10739
|
107 int len = 0; \
|
hseigel@46341
|
108 Symbol* clss_name = name(); \
|
hseigel@46341
|
109 if (clss_name != NULL) { \
|
hseigel@46341
|
110 data = (char*)clss_name->bytes(); \
|
hseigel@46341
|
111 len = clss_name->utf8_length(); \
|
dcubed@10739
|
112 } \
|
dcubed@10739
|
113 HOTSPOT_CLASS_INITIALIZATION_##type( \
|
sgehwolf@46766
|
114 data, len, (void*)class_loader(), thread_type); \
|
dcubed@10739
|
115 }
|
dcubed@10739
|
116
|
hseigel@46341
|
117 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) \
|
dcubed@10739
|
118 { \
|
dcubed@10739
|
119 char* data = NULL; \
|
dcubed@10739
|
120 int len = 0; \
|
hseigel@46341
|
121 Symbol* clss_name = name(); \
|
hseigel@46341
|
122 if (clss_name != NULL) { \
|
hseigel@46341
|
123 data = (char*)clss_name->bytes(); \
|
hseigel@46341
|
124 len = clss_name->utf8_length(); \
|
dcubed@10739
|
125 } \
|
dcubed@10739
|
126 HOTSPOT_CLASS_INITIALIZATION_##type( \
|
sgehwolf@46766
|
127 data, len, (void*)class_loader(), thread_type, wait); \
|
dcubed@10739
|
128 }
|
fparain@5089
|
129
|
fparain@5089
|
130 #else // ndef DTRACE_ENABLED
|
fparain@5089
|
131
|
hseigel@46341
|
132 #define DTRACE_CLASSINIT_PROBE(type, thread_type)
|
hseigel@46341
|
133 #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait)
|
fparain@5089
|
134
|
fparain@5089
|
135 #endif // ndef DTRACE_ENABLED
|
fparain@5089
|
136
|
mgronlun@34666
|
137 static inline bool is_class_loader(const Symbol* class_name,
|
mgronlun@34666
|
138 const ClassFileParser& parser) {
|
mgronlun@34666
|
139 assert(class_name != NULL, "invariant");
|
mgronlun@34666
|
140
|
mgronlun@34666
|
141 if (class_name == vmSymbols::java_lang_ClassLoader()) {
|
mgronlun@34666
|
142 return true;
|
mgronlun@34666
|
143 }
|
mgronlun@34666
|
144
|
mgronlun@34666
|
145 if (SystemDictionary::ClassLoader_klass_loaded()) {
|
mgronlun@34666
|
146 const Klass* const super_klass = parser.super_klass();
|
mgronlun@34666
|
147 if (super_klass != NULL) {
|
mgronlun@34666
|
148 if (super_klass->is_subtype_of(SystemDictionary::ClassLoader_klass())) {
|
mgronlun@34666
|
149 return true;
|
mgronlun@34666
|
150 }
|
mgronlun@34666
|
151 }
|
mgronlun@34666
|
152 }
|
mgronlun@34666
|
153 return false;
|
mgronlun@34666
|
154 }
|
mgronlun@34666
|
155
|
dholmes@50735
|
156 // called to verify that k is a member of this nest
|
dholmes@50735
|
157 bool InstanceKlass::has_nest_member(InstanceKlass* k, TRAPS) const {
|
dholmes@50735
|
158 if (_nest_members == NULL || _nest_members == Universe::the_empty_short_array()) {
|
dholmes@50735
|
159 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
160 ResourceMark rm(THREAD);
|
dholmes@50735
|
161 log_trace(class, nestmates)("Checked nest membership of %s in non-nest-host class %s",
|
dholmes@50735
|
162 k->external_name(), this->external_name());
|
dholmes@50735
|
163 }
|
dholmes@50735
|
164 return false;
|
dholmes@50735
|
165 }
|
dholmes@50735
|
166
|
dholmes@50735
|
167 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
168 ResourceMark rm(THREAD);
|
dholmes@50735
|
169 log_trace(class, nestmates)("Checking nest membership of %s in %s",
|
dholmes@50735
|
170 k->external_name(), this->external_name());
|
dholmes@50735
|
171 }
|
dholmes@50735
|
172
|
dholmes@52232
|
173 // Check for a resolved cp entry , else fall back to a name check.
|
dholmes@52232
|
174 // We don't want to resolve any class other than the one being checked.
|
dholmes@50735
|
175 for (int i = 0; i < _nest_members->length(); i++) {
|
dholmes@50735
|
176 int cp_index = _nest_members->at(i);
|
dholmes@52232
|
177 if (_constants->tag_at(cp_index).is_klass()) {
|
dholmes@50735
|
178 Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
|
dholmes@50735
|
179 if (k2 == k) {
|
dholmes@52232
|
180 log_trace(class, nestmates)("- class is listed at nest_members[%d] => cp[%d]", i, cp_index);
|
dholmes@50735
|
181 return true;
|
dholmes@52232
|
182 }
|
dholmes@52232
|
183 }
|
dholmes@52232
|
184 else {
|
dholmes@52232
|
185 Symbol* name = _constants->klass_name_at(cp_index);
|
dholmes@52232
|
186 if (name == k->name()) {
|
dholmes@52232
|
187 log_trace(class, nestmates)("- Found it at nest_members[%d] => cp[%d]", i, cp_index);
|
dholmes@52232
|
188
|
dholmes@53864
|
189 // Names match so check actual klass - this may trigger class loading if
|
dholmes@53864
|
190 // it doesn't match (though that should be impossible). But to be safe we
|
dholmes@53864
|
191 // have to check for a compiler thread executing here.
|
dholmes@53864
|
192 if (!THREAD->can_call_java() && !_constants->tag_at(cp_index).is_klass()) {
|
dholmes@53864
|
193 log_trace(class, nestmates)("- validation required resolution in an unsuitable thread");
|
dholmes@53864
|
194 return false;
|
dholmes@53864
|
195 }
|
dholmes@53864
|
196
|
dholmes@52232
|
197 Klass* k2 = _constants->klass_at(cp_index, CHECK_false);
|
dholmes@52232
|
198 if (k2 == k) {
|
dholmes@52232
|
199 log_trace(class, nestmates)("- class is listed as a nest member");
|
dholmes@52232
|
200 return true;
|
dholmes@52232
|
201 }
|
dholmes@52232
|
202 else {
|
dholmes@52232
|
203 // same name but different klass!
|
dholmes@52232
|
204 log_trace(class, nestmates)(" - klass comparison failed!");
|
dholmes@52232
|
205 // can't have two names the same, so we're done
|
dholmes@52232
|
206 return false;
|
dholmes@52232
|
207 }
|
dholmes@50735
|
208 }
|
dholmes@50735
|
209 }
|
dholmes@50735
|
210 }
|
dholmes@50735
|
211 log_trace(class, nestmates)("- class is NOT a nest member!");
|
dholmes@50735
|
212 return false;
|
dholmes@50735
|
213 }
|
dholmes@50735
|
214
|
dholmes@50735
|
215 // Return nest-host class, resolving, validating and saving it if needed.
|
dholmes@50735
|
216 // In cases where this is called from a thread that can not do classloading
|
dholmes@50735
|
217 // (such as a native JIT thread) then we simply return NULL, which in turn
|
dholmes@50735
|
218 // causes the access check to return false. Such code will retry the access
|
dholmes@50735
|
219 // from a more suitable environment later.
|
dholmes@50735
|
220 InstanceKlass* InstanceKlass::nest_host(Symbol* validationException, TRAPS) {
|
dholmes@50735
|
221 InstanceKlass* nest_host_k = _nest_host;
|
dholmes@50735
|
222 if (nest_host_k == NULL) {
|
dholmes@50735
|
223 // need to resolve and save our nest-host class. This could be attempted
|
dholmes@50735
|
224 // concurrently but as the result is idempotent and we don't use the class
|
dholmes@50735
|
225 // then we do not need any synchronization beyond what is implicitly used
|
dholmes@50735
|
226 // during class loading.
|
dholmes@50735
|
227 if (_nest_host_index != 0) { // we have a real nest_host
|
dholmes@50735
|
228 // Before trying to resolve check if we're in a suitable context
|
dholmes@50735
|
229 if (!THREAD->can_call_java() && !_constants->tag_at(_nest_host_index).is_klass()) {
|
dholmes@50735
|
230 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
231 ResourceMark rm(THREAD);
|
dholmes@50735
|
232 log_trace(class, nestmates)("Rejected resolution of nest-host of %s in unsuitable thread",
|
dholmes@50735
|
233 this->external_name());
|
dholmes@50735
|
234 }
|
dholmes@50735
|
235 return NULL;
|
dholmes@50735
|
236 }
|
dholmes@50735
|
237
|
dholmes@50735
|
238 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
239 ResourceMark rm(THREAD);
|
dholmes@50735
|
240 log_trace(class, nestmates)("Resolving nest-host of %s using cp entry for %s",
|
dholmes@50735
|
241 this->external_name(),
|
dholmes@50735
|
242 _constants->klass_name_at(_nest_host_index)->as_C_string());
|
dholmes@50735
|
243 }
|
dholmes@50735
|
244
|
dholmes@50735
|
245 Klass* k = _constants->klass_at(_nest_host_index, THREAD);
|
dholmes@50735
|
246 if (HAS_PENDING_EXCEPTION) {
|
dholmes@50735
|
247 Handle exc_h = Handle(THREAD, PENDING_EXCEPTION);
|
dholmes@50735
|
248 if (exc_h->is_a(SystemDictionary::NoClassDefFoundError_klass())) {
|
dholmes@50735
|
249 // throw a new CDNFE with the original as its cause, and a clear msg
|
dholmes@50735
|
250 ResourceMark rm(THREAD);
|
dholmes@50735
|
251 char buf[200];
|
dholmes@50735
|
252 CLEAR_PENDING_EXCEPTION;
|
dholmes@50735
|
253 jio_snprintf(buf, sizeof(buf),
|
dholmes@50735
|
254 "Unable to load nest-host class (%s) of %s",
|
dholmes@50735
|
255 _constants->klass_name_at(_nest_host_index)->as_C_string(),
|
dholmes@50735
|
256 this->external_name());
|
dholmes@50735
|
257 log_trace(class, nestmates)("%s - NoClassDefFoundError", buf);
|
dholmes@50735
|
258 THROW_MSG_CAUSE_NULL(vmSymbols::java_lang_NoClassDefFoundError(), buf, exc_h);
|
dholmes@50735
|
259 }
|
dholmes@50735
|
260 // All other exceptions pass through (OOME, StackOverflowError, LinkageErrors etc).
|
dholmes@50735
|
261 return NULL;
|
dholmes@50735
|
262 }
|
dholmes@50735
|
263
|
dholmes@50735
|
264 // A valid nest-host is an instance class in the current package that lists this
|
dholmes@50735
|
265 // class as a nest member. If any of these conditions are not met we post the
|
dholmes@50735
|
266 // requested exception type (if any) and return NULL
|
dholmes@50735
|
267
|
dholmes@50735
|
268 const char* error = NULL;
|
dholmes@50735
|
269
|
dholmes@50735
|
270 // JVMS 5.4.4 indicates package check comes first
|
dholmes@50735
|
271 if (is_same_class_package(k)) {
|
dholmes@50735
|
272
|
dholmes@50735
|
273 // Now check actual membership. We can't be a member if our "host" is
|
dholmes@50735
|
274 // not an instance class.
|
dholmes@50735
|
275 if (k->is_instance_klass()) {
|
dholmes@50735
|
276 nest_host_k = InstanceKlass::cast(k);
|
dholmes@50735
|
277
|
dholmes@50735
|
278 bool is_member = nest_host_k->has_nest_member(this, CHECK_NULL);
|
dholmes@50735
|
279 if (is_member) {
|
dholmes@50735
|
280 // save resolved nest-host value
|
dholmes@50735
|
281 _nest_host = nest_host_k;
|
dholmes@50735
|
282
|
dholmes@50735
|
283 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
284 ResourceMark rm(THREAD);
|
dholmes@50735
|
285 log_trace(class, nestmates)("Resolved nest-host of %s to %s",
|
dholmes@50735
|
286 this->external_name(), k->external_name());
|
dholmes@50735
|
287 }
|
dholmes@50735
|
288 return nest_host_k;
|
dholmes@50735
|
289 }
|
dholmes@50735
|
290 }
|
dholmes@50735
|
291 error = "current type is not listed as a nest member";
|
dholmes@50735
|
292 } else {
|
dholmes@50735
|
293 error = "types are in different packages";
|
dholmes@50735
|
294 }
|
dholmes@50735
|
295
|
dholmes@50735
|
296 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
297 ResourceMark rm(THREAD);
|
dholmes@52706
|
298 log_trace(class, nestmates)
|
dholmes@52706
|
299 ("Type %s (loader: %s) is not a nest member of "
|
dholmes@52706
|
300 "resolved type %s (loader: %s): %s",
|
dholmes@52706
|
301 this->external_name(),
|
dholmes@52706
|
302 this->class_loader_data()->loader_name_and_id(),
|
dholmes@52706
|
303 k->external_name(),
|
dholmes@52706
|
304 k->class_loader_data()->loader_name_and_id(),
|
dholmes@52706
|
305 error);
|
dholmes@50735
|
306 }
|
dholmes@50735
|
307
|
dholmes@53864
|
308 if (validationException != NULL && THREAD->can_call_java()) {
|
dholmes@50735
|
309 ResourceMark rm(THREAD);
|
dholmes@50735
|
310 Exceptions::fthrow(THREAD_AND_LOCATION,
|
dholmes@50735
|
311 validationException,
|
dholmes@52706
|
312 "Type %s (loader: %s) is not a nest member of %s (loader: %s): %s",
|
dholmes@50735
|
313 this->external_name(),
|
dholmes@52706
|
314 this->class_loader_data()->loader_name_and_id(),
|
dholmes@50735
|
315 k->external_name(),
|
dholmes@52706
|
316 k->class_loader_data()->loader_name_and_id(),
|
dholmes@50735
|
317 error
|
dholmes@50735
|
318 );
|
dholmes@50735
|
319 }
|
dholmes@50735
|
320 return NULL;
|
dholmes@50735
|
321 } else {
|
dholmes@50735
|
322 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
323 ResourceMark rm(THREAD);
|
dholmes@50735
|
324 log_trace(class, nestmates)("Type %s is not part of a nest: setting nest-host to self",
|
dholmes@50735
|
325 this->external_name());
|
dholmes@50735
|
326 }
|
dholmes@50735
|
327 // save resolved nest-host value
|
dholmes@50735
|
328 return (_nest_host = this);
|
dholmes@50735
|
329 }
|
dholmes@50735
|
330 }
|
dholmes@50735
|
331 return nest_host_k;
|
dholmes@50735
|
332 }
|
dholmes@50735
|
333
|
dholmes@50735
|
334 // check if 'this' and k are nestmates (same nest_host), or k is our nest_host,
|
dholmes@50735
|
335 // or we are k's nest_host - all of which is covered by comparing the two
|
dholmes@50735
|
336 // resolved_nest_hosts
|
dholmes@50735
|
337 bool InstanceKlass::has_nestmate_access_to(InstanceKlass* k, TRAPS) {
|
dholmes@50735
|
338
|
dholmes@50735
|
339 assert(this != k, "this should be handled by higher-level code");
|
dholmes@50735
|
340
|
dholmes@50735
|
341 // Per JVMS 5.4.4 we first resolve and validate the current class, then
|
dholmes@50735
|
342 // the target class k. Resolution exceptions will be passed on by upper
|
dholmes@50735
|
343 // layers. IncompatibleClassChangeErrors from membership validation failures
|
dholmes@50735
|
344 // will also be passed through.
|
dholmes@50735
|
345
|
dholmes@50735
|
346 Symbol* icce = vmSymbols::java_lang_IncompatibleClassChangeError();
|
dholmes@50735
|
347 InstanceKlass* cur_host = nest_host(icce, CHECK_false);
|
dholmes@50735
|
348 if (cur_host == NULL) {
|
dholmes@50735
|
349 return false;
|
dholmes@50735
|
350 }
|
dholmes@50735
|
351
|
dholmes@50735
|
352 Klass* k_nest_host = k->nest_host(icce, CHECK_false);
|
dholmes@50735
|
353 if (k_nest_host == NULL) {
|
dholmes@50735
|
354 return false;
|
dholmes@50735
|
355 }
|
dholmes@50735
|
356
|
dholmes@50735
|
357 bool access = (cur_host == k_nest_host);
|
dholmes@50735
|
358
|
dholmes@50735
|
359 if (log_is_enabled(Trace, class, nestmates)) {
|
dholmes@50735
|
360 ResourceMark rm(THREAD);
|
dholmes@50735
|
361 log_trace(class, nestmates)("Class %s does %shave nestmate access to %s",
|
dholmes@50735
|
362 this->external_name(),
|
dholmes@50735
|
363 access ? "" : "NOT ",
|
dholmes@50735
|
364 k->external_name());
|
dholmes@50735
|
365 }
|
dholmes@50735
|
366
|
dholmes@50735
|
367 return access;
|
dholmes@50735
|
368 }
|
dholmes@50735
|
369
|
mgronlun@34666
|
370 InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPS) {
|
mgronlun@34666
|
371 const int size = InstanceKlass::size(parser.vtable_size(),
|
mgronlun@34666
|
372 parser.itable_size(),
|
mgronlun@34666
|
373 nonstatic_oop_map_size(parser.total_oop_map_count()),
|
mgronlun@34666
|
374 parser.is_interface(),
|
lfoltan@51444
|
375 parser.is_unsafe_anonymous(),
|
lfoltan@51444
|
376 should_store_fingerprint(parser.is_unsafe_anonymous()));
|
mgronlun@34666
|
377
|
mgronlun@34666
|
378 const Symbol* const class_name = parser.class_name();
|
mgronlun@34666
|
379 assert(class_name != NULL, "invariant");
|
mgronlun@34666
|
380 ClassLoaderData* loader_data = parser.loader_data();
|
mgronlun@34666
|
381 assert(loader_data != NULL, "invariant");
|
mgronlun@34666
|
382
|
mgronlun@34666
|
383 InstanceKlass* ik;
|
coleenp@13728
|
384
|
coleenp@13728
|
385 // Allocation
|
mgronlun@34666
|
386 if (REF_NONE == parser.reference_type()) {
|
mgronlun@34666
|
387 if (class_name == vmSymbols::java_lang_Class()) {
|
mgronlun@34666
|
388 // mirror
|
mgronlun@34666
|
389 ik = new (loader_data, size, THREAD) InstanceMirrorKlass(parser);
|
mgronlun@34666
|
390 }
|
mgronlun@34666
|
391 else if (is_class_loader(class_name, parser)) {
|
mgronlun@34666
|
392 // class loader
|
mgronlun@34666
|
393 ik = new (loader_data, size, THREAD) InstanceClassLoaderKlass(parser);
|
dholmes@50735
|
394 } else {
|
mgronlun@34666
|
395 // normal
|
mgronlun@34666
|
396 ik = new (loader_data, size, THREAD) InstanceKlass(parser, InstanceKlass::_misc_kind_other);
|
mgronlun@34666
|
397 }
|
dholmes@50735
|
398 } else {
|
mgronlun@34666
|
399 // reference
|
mgronlun@34666
|
400 ik = new (loader_data, size, THREAD) InstanceRefKlass(parser);
|
coleenp@13728
|
401 }
|
coleenp@13728
|
402
|
coleenp@15935
|
403 // Check for pending exception before adding to the loader data and incrementing
|
coleenp@15935
|
404 // class count. Can get OOM here.
|
coleenp@15935
|
405 if (HAS_PENDING_EXCEPTION) {
|
coleenp@15935
|
406 return NULL;
|
coleenp@15935
|
407 }
|
coleenp@15935
|
408
|
coleenp@13728
|
409 return ik;
|
coleenp@13728
|
410 }
|
coleenp@13728
|
411
|
coleenp@15935
|
412
|
coleenp@15935
|
413 // copy method ordering from resource area to Metaspace
|
mgronlun@34666
|
414 void InstanceKlass::copy_method_ordering(const intArray* m, TRAPS) {
|
coleenp@15935
|
415 if (m != NULL) {
|
coleenp@15935
|
416 // allocate a new array and copy contents (memcpy?)
|
coleenp@15935
|
417 _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK);
|
coleenp@15935
|
418 for (int i = 0; i < m->length(); i++) {
|
coleenp@15935
|
419 _method_ordering->at_put(i, m->at(i));
|
coleenp@15935
|
420 }
|
coleenp@15935
|
421 } else {
|
coleenp@15935
|
422 _method_ordering = Universe::the_empty_int_array();
|
coleenp@15935
|
423 }
|
coleenp@15935
|
424 }
|
coleenp@15935
|
425
|
acorn@20391
|
426 // create a new array of vtable_indices for default methods
|
acorn@20391
|
427 Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPS) {
|
acorn@20391
|
428 Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL);
|
acorn@20391
|
429 assert(default_vtable_indices() == NULL, "only create once");
|
acorn@20391
|
430 set_default_vtable_indices(vtable_indices);
|
acorn@20391
|
431 return vtable_indices;
|
acorn@20391
|
432 }
|
coleenp@15935
|
433
|
stefank@50752
|
434 InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) :
|
stefank@50752
|
435 Klass(id),
|
tschatzl@51334
|
436 _nest_members(NULL),
|
tschatzl@51334
|
437 _nest_host_index(0),
|
tschatzl@51334
|
438 _nest_host(NULL),
|
vromero@57233
|
439 _record_components(NULL),
|
mgronlun@34666
|
440 _static_field_size(parser.static_field_size()),
|
mgronlun@34666
|
441 _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())),
|
mgronlun@34666
|
442 _itable_len(parser.itable_size()),
|
vlivanov@55254
|
443 _init_thread(NULL),
|
vlivanov@55254
|
444 _init_state(allocated),
|
iklam@52514
|
445 _reference_type(parser.reference_type())
|
iklam@52514
|
446 {
|
iklam@52514
|
447 set_vtable_length(parser.vtable_size());
|
iklam@52514
|
448 set_kind(kind);
|
iklam@52514
|
449 set_access_flags(parser.access_flags());
|
iklam@52514
|
450 set_is_unsafe_anonymous(parser.is_unsafe_anonymous());
|
iklam@52514
|
451 set_layout_helper(Klass::instance_layout_helper(parser.layout_size(),
|
mgronlun@34666
|
452 false));
|
mgronlun@34666
|
453
|
iklam@52514
|
454 assert(NULL == _methods, "underlying memory not zeroed?");
|
iklam@52514
|
455 assert(is_instance_klass(), "is layout incorrect?");
|
iklam@52514
|
456 assert(size_helper() == parser.layout_size(), "incorrect size_helper?");
|
iklam@52514
|
457
|
ccheung@56468
|
458 if (Arguments::is_dumping_archive()) {
|
iklam@52514
|
459 SystemDictionaryShared::init_dumptime_info(this);
|
iklam@52514
|
460 }
|
coleenp@56724
|
461
|
coleenp@56724
|
462 // Set biased locking bit for all instances of this class; it will be
|
coleenp@56724
|
463 // cleared if revocation occurs too often for this type
|
coleenp@56724
|
464 if (UseBiasedLocking && BiasedLocking::enabled()) {
|
coleenp@56724
|
465 set_prototype_header(markWord::biased_locking_prototype());
|
coleenp@56724
|
466 }
|
coleenp@13728
|
467 }
|
coleenp@13728
|
468
|
coleenp@15935
|
469 void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data,
|
coleenp@15935
|
470 Array<Method*>* methods) {
|
hseigel@20684
|
471 if (methods != NULL && methods != Universe::the_empty_method_array() &&
|
hseigel@20684
|
472 !methods->is_shared()) {
|
coleenp@15935
|
473 for (int i = 0; i < methods->length(); i++) {
|
coleenp@15935
|
474 Method* method = methods->at(i);
|
coleenp@15935
|
475 if (method == NULL) continue; // maybe null if error processing
|
coleenp@15935
|
476 // Only want to delete methods that are not executing for RedefineClasses.
|
coleenp@15935
|
477 // The previous version will point to them so they're not totally dangling
|
coleenp@15935
|
478 assert (!method->on_stack(), "shouldn't be called with methods on stack");
|
coleenp@15935
|
479 MetadataFactory::free_metadata(loader_data, method);
|
coleenp@15935
|
480 }
|
coleenp@15935
|
481 MetadataFactory::free_array<Method*>(loader_data, methods);
|
coleenp@15935
|
482 }
|
coleenp@15935
|
483 }
|
coleenp@15935
|
484
|
coleenp@15935
|
485 void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data,
|
mgronlun@34666
|
486 const Klass* super_klass,
|
iklam@51329
|
487 Array<InstanceKlass*>* local_interfaces,
|
iklam@51329
|
488 Array<InstanceKlass*>* transitive_interfaces) {
|
coleenp@15935
|
489 // Only deallocate transitive interfaces if not empty, same as super class
|
coleenp@15935
|
490 // or same as local interfaces. See code in parseClassFile.
|
iklam@51329
|
491 Array<InstanceKlass*>* ti = transitive_interfaces;
|
iklam@51329
|
492 if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) {
|
coleenp@15935
|
493 // check that the interfaces don't come from super class
|
iklam@51329
|
494 Array<InstanceKlass*>* sti = (super_klass == NULL) ? NULL :
|
coleenp@15935
|
495 InstanceKlass::cast(super_klass)->transitive_interfaces();
|
hseigel@20684
|
496 if (ti != sti && ti != NULL && !ti->is_shared()) {
|
iklam@51329
|
497 MetadataFactory::free_array<InstanceKlass*>(loader_data, ti);
|
coleenp@15935
|
498 }
|
coleenp@15935
|
499 }
|
coleenp@15935
|
500
|
coleenp@15935
|
501 // local interfaces can be empty
|
iklam@51329
|
502 if (local_interfaces != Universe::the_empty_instance_klass_array() &&
|
hseigel@20684
|
503 local_interfaces != NULL && !local_interfaces->is_shared()) {
|
iklam@51329
|
504 MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces);
|
coleenp@15935
|
505 }
|
coleenp@15935
|
506 }
|
coleenp@15935
|
507
|
vromero@57233
|
508 void InstanceKlass::deallocate_record_components(ClassLoaderData* loader_data,
|
vromero@57233
|
509 Array<RecordComponent*>* record_components) {
|
vromero@57233
|
510 if (record_components != NULL && !record_components->is_shared()) {
|
vromero@57233
|
511 for (int i = 0; i < record_components->length(); i++) {
|
vromero@57233
|
512 RecordComponent* record_component = record_components->at(i);
|
vromero@57233
|
513 MetadataFactory::free_metadata(loader_data, record_component);
|
vromero@57233
|
514 }
|
vromero@57233
|
515 MetadataFactory::free_array<RecordComponent*>(loader_data, record_components);
|
vromero@57233
|
516 }
|
vromero@57233
|
517 }
|
vromero@57233
|
518
|
coleenp@13728
|
519 // This function deallocates the metadata and C heap pointers that the
|
coleenp@13728
|
520 // InstanceKlass points to.
|
coleenp@13728
|
521 void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) {
|
coleenp@13728
|
522
|
coleenp@13728
|
523 // Orphan the mirror first, CMS thinks it's still live.
|
coleenp@15935
|
524 if (java_mirror() != NULL) {
|
coleenp@15935
|
525 java_lang_Class::set_klass(java_mirror(), NULL);
|
coleenp@15935
|
526 }
|
coleenp@13728
|
527
|
coleenp@47580
|
528 // Also remove mirror from handles
|
coleenp@47580
|
529 loader_data->remove_handle(_java_mirror);
|
coleenp@47580
|
530
|
coleenp@13728
|
531 // Need to take this class off the class loader data list.
|
coleenp@13728
|
532 loader_data->remove_class(this);
|
coleenp@13728
|
533
|
coleenp@13728
|
534 // The array_klass for this class is created later, after error handling.
|
coleenp@13728
|
535 // For class redefinition, we keep the original class so this scratch class
|
coleenp@13728
|
536 // doesn't have an array class. Either way, assert that there is nothing
|
coleenp@13728
|
537 // to deallocate.
|
coleenp@13728
|
538 assert(array_klasses() == NULL, "array classes shouldn't be created for this class yet");
|
coleenp@13728
|
539
|
coleenp@13728
|
540 // Release C heap allocated data that this might point to, which includes
|
coleenp@13728
|
541 // reference counting symbol names.
|
coleenp@13728
|
542 release_C_heap_structures();
|
coleenp@13728
|
543
|
coleenp@15935
|
544 deallocate_methods(loader_data, methods());
|
coleenp@13728
|
545 set_methods(NULL);
|
coleenp@13728
|
546
|
vromero@57233
|
547 deallocate_record_components(loader_data, record_components());
|
vromero@57233
|
548 set_record_components(NULL);
|
vromero@57233
|
549
|
hseigel@20684
|
550 if (method_ordering() != NULL &&
|
hseigel@20684
|
551 method_ordering() != Universe::the_empty_int_array() &&
|
hseigel@20684
|
552 !method_ordering()->is_shared()) {
|
coleenp@13728
|
553 MetadataFactory::free_array<int>(loader_data, method_ordering());
|
coleenp@13728
|
554 }
|
coleenp@13728
|
555 set_method_ordering(NULL);
|
coleenp@13728
|
556
|
acorn@20391
|
557 // default methods can be empty
|
acorn@20391
|
558 if (default_methods() != NULL &&
|
hseigel@20684
|
559 default_methods() != Universe::the_empty_method_array() &&
|
hseigel@20684
|
560 !default_methods()->is_shared()) {
|
acorn@20391
|
561 MetadataFactory::free_array<Method*>(loader_data, default_methods());
|
acorn@20391
|
562 }
|
acorn@20391
|
563 // Do NOT deallocate the default methods, they are owned by superinterfaces.
|
acorn@20391
|
564 set_default_methods(NULL);
|
acorn@20391
|
565
|
acorn@20391
|
566 // default methods vtable indices can be empty
|
hseigel@20684
|
567 if (default_vtable_indices() != NULL &&
|
hseigel@20684
|
568 !default_vtable_indices()->is_shared()) {
|
acorn@20391
|
569 MetadataFactory::free_array<int>(loader_data, default_vtable_indices());
|
acorn@20391
|
570 }
|
acorn@20391
|
571 set_default_vtable_indices(NULL);
|
acorn@20391
|
572
|
acorn@20391
|
573
|
coleenp@13728
|
574 // This array is in Klass, but remove it with the InstanceKlass since
|
coleenp@13728
|
575 // this place would be the only caller and it can share memory with transitive
|
coleenp@13728
|
576 // interfaces.
|
hseigel@20684
|
577 if (secondary_supers() != NULL &&
|
hseigel@20684
|
578 secondary_supers() != Universe::the_empty_klass_array() &&
|
iklam@51329
|
579 // see comments in compute_secondary_supers about the following cast
|
iklam@51329
|
580 (address)(secondary_supers()) != (address)(transitive_interfaces()) &&
|
hseigel@20684
|
581 !secondary_supers()->is_shared()) {
|
coleenp@13728
|
582 MetadataFactory::free_array<Klass*>(loader_data, secondary_supers());
|
coleenp@13728
|
583 }
|
coleenp@13728
|
584 set_secondary_supers(NULL);
|
coleenp@13728
|
585
|
coleenp@15935
|
586 deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces());
|
coleenp@13728
|
587 set_transitive_interfaces(NULL);
|
coleenp@13728
|
588 set_local_interfaces(NULL);
|
coleenp@13728
|
589
|
hseigel@20684
|
590 if (fields() != NULL && !fields()->is_shared()) {
|
hseigel@20684
|
591 MetadataFactory::free_array<jushort>(loader_data, fields());
|
hseigel@20684
|
592 }
|
coleenp@13728
|
593 set_fields(NULL, 0);
|
coleenp@13728
|
594
|
coleenp@13728
|
595 // If a method from a redefined class is using this constant pool, don't
|
coleenp@13728
|
596 // delete it, yet. The new class's previous version will point to this.
|
coleenp@15935
|
597 if (constants() != NULL) {
|
coleenp@15935
|
598 assert (!constants()->on_stack(), "shouldn't be called if anything is onstack");
|
hseigel@20684
|
599 if (!constants()->is_shared()) {
|
hseigel@20684
|
600 MetadataFactory::free_metadata(loader_data, constants());
|
hseigel@20684
|
601 }
|
aeriksso@31353
|
602 // Delete any cached resolution errors for the constant pool
|
aeriksso@31353
|
603 SystemDictionary::delete_resolution_error(constants());
|
aeriksso@31353
|
604
|
coleenp@15935
|
605 set_constants(NULL);
|
coleenp@15935
|
606 }
|
coleenp@13728
|
607
|
hseigel@20684
|
608 if (inner_classes() != NULL &&
|
hseigel@20684
|
609 inner_classes() != Universe::the_empty_short_array() &&
|
hseigel@20684
|
610 !inner_classes()->is_shared()) {
|
coleenp@13728
|
611 MetadataFactory::free_array<jushort>(loader_data, inner_classes());
|
coleenp@13728
|
612 }
|
coleenp@13728
|
613 set_inner_classes(NULL);
|
coleenp@13728
|
614
|
dholmes@50735
|
615 if (nest_members() != NULL &&
|
dholmes@50735
|
616 nest_members() != Universe::the_empty_short_array() &&
|
dholmes@50735
|
617 !nest_members()->is_shared()) {
|
dholmes@50735
|
618 MetadataFactory::free_array<jushort>(loader_data, nest_members());
|
dholmes@50735
|
619 }
|
dholmes@50735
|
620 set_nest_members(NULL);
|
dholmes@50735
|
621
|
hseigel@20684
|
622 // We should deallocate the Annotations instance if it's not in shared spaces.
|
hseigel@20684
|
623 if (annotations() != NULL && !annotations()->is_shared()) {
|
hseigel@20684
|
624 MetadataFactory::free_metadata(loader_data, annotations());
|
hseigel@20684
|
625 }
|
coleenp@13728
|
626 set_annotations(NULL);
|
iklam@52514
|
627
|
ccheung@56468
|
628 if (Arguments::is_dumping_archive()) {
|
iklam@52514
|
629 SystemDictionaryShared::remove_dumptime_info(this);
|
iklam@52514
|
630 }
|
coleenp@13728
|
631 }
|
coleenp@13728
|
632
|
coleenp@13728
|
633 bool InstanceKlass::should_be_initialized() const {
|
duke@1
|
634 return !is_initialized();
|
duke@1
|
635 }
|
duke@1
|
636
|
iklam@46408
|
637 klassItable InstanceKlass::itable() const {
|
iklam@46408
|
638 return klassItable(const_cast<InstanceKlass*>(this));
|
duke@1
|
639 }
|
duke@1
|
640
|
coleenp@13728
|
641 void InstanceKlass::eager_initialize(Thread *thread) {
|
duke@1
|
642 if (!EagerInitialization) return;
|
duke@1
|
643
|
duke@1
|
644 if (this->is_not_initialized()) {
|
duke@1
|
645 // abort if the the class has a class initializer
|
duke@1
|
646 if (this->class_initializer() != NULL) return;
|
duke@1
|
647
|
duke@1
|
648 // abort if it is java.lang.Object (initialization is handled in genesis)
|
hseigel@46341
|
649 Klass* super_klass = super();
|
hseigel@46341
|
650 if (super_klass == NULL) return;
|
duke@1
|
651
|
duke@1
|
652 // abort if the super class should be initialized
|
hseigel@46341
|
653 if (!InstanceKlass::cast(super_klass)->is_initialized()) return;
|
duke@1
|
654
|
duke@1
|
655 // call body to expose the this pointer
|
hseigel@46341
|
656 eager_initialize_impl();
|
duke@1
|
657 }
|
duke@1
|
658 }
|
duke@1
|
659
|
coleenp@17826
|
660 // JVMTI spec thinks there are signers and protection domain in the
|
coleenp@17826
|
661 // instanceKlass. These accessors pretend these fields are there.
|
coleenp@17826
|
662 // The hprof specification also thinks these fields are in InstanceKlass.
|
coleenp@17826
|
663 oop InstanceKlass::protection_domain() const {
|
coleenp@17826
|
664 // return the protection_domain from the mirror
|
coleenp@17826
|
665 return java_lang_Class::protection_domain(java_mirror());
|
coleenp@17826
|
666 }
|
coleenp@17826
|
667
|
coleenp@17826
|
668 // To remove these from requires an incompatible change and CCC request.
|
coleenp@17826
|
669 objArrayOop InstanceKlass::signers() const {
|
coleenp@17826
|
670 // return the signers from the mirror
|
coleenp@17826
|
671 return java_lang_Class::signers(java_mirror());
|
coleenp@17826
|
672 }
|
coleenp@17826
|
673
|
coleenp@20379
|
674 oop InstanceKlass::init_lock() const {
|
coleenp@17826
|
675 // return the init lock from the mirror
|
iklam@21079
|
676 oop lock = java_lang_Class::init_lock(java_mirror());
|
dholmes@26556
|
677 // Prevent reordering with any access of initialization state
|
dholmes@26556
|
678 OrderAccess::loadload();
|
iklam@21079
|
679 assert((oop)lock != NULL || !is_not_initialized(), // initialized or in_error state
|
iklam@21079
|
680 "only fully initialized state can have a null lock");
|
iklam@21079
|
681 return lock;
|
iklam@21079
|
682 }
|
iklam@21079
|
683
|
iklam@21079
|
684 // Set the initialization lock to null so the object can be GC'ed. Any racing
|
iklam@21079
|
685 // threads to get this lock will see a null lock and will not lock.
|
iklam@21079
|
686 // That's okay because they all check for initialized state after getting
|
iklam@21079
|
687 // the lock and return.
|
iklam@21079
|
688 void InstanceKlass::fence_and_clear_init_lock() {
|
iklam@21079
|
689 // make sure previous stores are all done, notably the init_state.
|
iklam@21079
|
690 OrderAccess::storestore();
|
iklam@21079
|
691 java_lang_Class::set_init_lock(java_mirror(), NULL);
|
iklam@21079
|
692 assert(!is_not_initialized(), "class must be initialized now");
|
coleenp@17826
|
693 }
|
duke@1
|
694
|
hseigel@46341
|
695 void InstanceKlass::eager_initialize_impl() {
|
duke@1
|
696 EXCEPTION_MARK;
|
coleenp@46271
|
697 HandleMark hm(THREAD);
|
hseigel@46341
|
698 Handle h_init_lock(THREAD, init_lock());
|
hseigel@46562
|
699 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
|
duke@1
|
700
|
duke@1
|
701 // abort if someone beat us to the initialization
|
hseigel@46341
|
702 if (!is_not_initialized()) return; // note: not equivalent to is_initialized()
|
hseigel@46341
|
703
|
hseigel@46341
|
704 ClassState old_state = init_state();
|
hseigel@51697
|
705 link_class_impl(THREAD);
|
duke@1
|
706 if (HAS_PENDING_EXCEPTION) {
|
duke@1
|
707 CLEAR_PENDING_EXCEPTION;
|
duke@1
|
708 // Abort if linking the class throws an exception.
|
duke@1
|
709
|
duke@1
|
710 // Use a test to avoid redundantly resetting the state if there's
|
duke@1
|
711 // no change. Set_init_state() asserts that state changes make
|
duke@1
|
712 // progress, whereas here we might just be spinning in place.
|
hseigel@46341
|
713 if (old_state != _init_state)
|
hseigel@46341
|
714 set_init_state(old_state);
|
duke@1
|
715 } else {
|
duke@1
|
716 // linking successfull, mark class as initialized
|
hseigel@46341
|
717 set_init_state(fully_initialized);
|
hseigel@46341
|
718 fence_and_clear_init_lock();
|
duke@1
|
719 // trace
|
mockner@38151
|
720 if (log_is_enabled(Info, class, init)) {
|
duke@1
|
721 ResourceMark rm(THREAD);
|
hseigel@46341
|
722 log_info(class, init)("[Initialized %s without side effects]", external_name());
|
duke@1
|
723 }
|
duke@1
|
724 }
|
duke@1
|
725 }
|
duke@1
|
726
|
duke@1
|
727
|
duke@1
|
728 // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization
|
duke@1
|
729 // process. The step comments refers to the procedure described in that section.
|
duke@1
|
730 // Note: implementation moved to static method to expose the this pointer.
|
coleenp@13728
|
731 void InstanceKlass::initialize(TRAPS) {
|
duke@1
|
732 if (this->should_be_initialized()) {
|
hseigel@46341
|
733 initialize_impl(CHECK);
|
duke@1
|
734 // Note: at this point the class may be initialized
|
duke@1
|
735 // OR it may be in the state of being initialized
|
duke@1
|
736 // in case of recursive initialization!
|
duke@1
|
737 } else {
|
duke@1
|
738 assert(is_initialized(), "sanity check");
|
duke@1
|
739 }
|
duke@1
|
740 }
|
duke@1
|
741
|
duke@1
|
742
|
hseigel@51697
|
743 bool InstanceKlass::verify_code(TRAPS) {
|
duke@1
|
744 // 1) Verify the bytecodes
|
hseigel@51697
|
745 return Verifier::verify(this, should_verify_class(), THREAD);
|
duke@1
|
746 }
|
duke@1
|
747
|
coleenp@13728
|
748 void InstanceKlass::link_class(TRAPS) {
|
duke@1
|
749 assert(is_loaded(), "must be loaded");
|
duke@1
|
750 if (!is_linked()) {
|
hseigel@51697
|
751 link_class_impl(CHECK);
|
duke@1
|
752 }
|
duke@1
|
753 }
|
duke@1
|
754
|
duke@1
|
755 // Called to verify that a class can link during initialization, without
|
duke@1
|
756 // throwing a VerifyError.
|
coleenp@13728
|
757 bool InstanceKlass::link_class_or_fail(TRAPS) {
|
duke@1
|
758 assert(is_loaded(), "must be loaded");
|
duke@1
|
759 if (!is_linked()) {
|
hseigel@51697
|
760 link_class_impl(CHECK_false);
|
duke@1
|
761 }
|
duke@1
|
762 return is_linked();
|
duke@1
|
763 }
|
duke@1
|
764
|
hseigel@51697
|
765 bool InstanceKlass::link_class_impl(TRAPS) {
|
ccheung@58266
|
766 if (DumpSharedSpaces && SystemDictionaryShared::has_class_failed_verification(this)) {
|
iklam@42031
|
767 // This is for CDS dumping phase only -- we use the in_error_state to indicate that
|
iklam@42031
|
768 // the class has failed verification. Throwing the NoClassDefFoundError here is just
|
iklam@42031
|
769 // a convenient way to stop repeat attempts to verify the same (bad) class.
|
iklam@42031
|
770 //
|
iklam@42031
|
771 // Note that the NoClassDefFoundError is not part of the JLS, and should not be thrown
|
iklam@42031
|
772 // if we are executing Java code. This is not a problem for CDS dumping phase since
|
iklam@42031
|
773 // it doesn't execute any Java code.
|
duke@1
|
774 ResourceMark rm(THREAD);
|
hseigel@46431
|
775 Exceptions::fthrow(THREAD_AND_LOCATION,
|
hseigel@46431
|
776 vmSymbols::java_lang_NoClassDefFoundError(),
|
hseigel@46431
|
777 "Class %s, or one of its supertypes, failed class initialization",
|
hseigel@46431
|
778 external_name());
|
hseigel@46431
|
779 return false;
|
duke@1
|
780 }
|
duke@1
|
781 // return if already verified
|
hseigel@46341
|
782 if (is_linked()) {
|
duke@1
|
783 return true;
|
duke@1
|
784 }
|
duke@1
|
785
|
duke@1
|
786 // Timing
|
duke@1
|
787 // timer handles recursion
|
duke@1
|
788 assert(THREAD->is_Java_thread(), "non-JavaThread in link_class_impl");
|
duke@1
|
789 JavaThread* jt = (JavaThread*)THREAD;
|
duke@1
|
790
|
duke@1
|
791 // link super class before linking this class
|
hseigel@46341
|
792 Klass* super_klass = super();
|
hseigel@46341
|
793 if (super_klass != NULL) {
|
hseigel@46341
|
794 if (super_klass->is_interface()) { // check if super class is an interface
|
duke@1
|
795 ResourceMark rm(THREAD);
|
duke@1
|
796 Exceptions::fthrow(
|
duke@1
|
797 THREAD_AND_LOCATION,
|
coleenp@8076
|
798 vmSymbols::java_lang_IncompatibleClassChangeError(),
|
duke@1
|
799 "class %s has interface %s as super class",
|
hseigel@46341
|
800 external_name(),
|
hseigel@46341
|
801 super_klass->external_name()
|
duke@1
|
802 );
|
duke@1
|
803 return false;
|
duke@1
|
804 }
|
duke@1
|
805
|
hseigel@46341
|
806 InstanceKlass* ik_super = InstanceKlass::cast(super_klass);
|
hseigel@51697
|
807 ik_super->link_class_impl(CHECK_false);
|
duke@1
|
808 }
|
duke@1
|
809
|
duke@1
|
810 // link all interfaces implemented by this class before linking this class
|
iklam@51329
|
811 Array<InstanceKlass*>* interfaces = local_interfaces();
|
duke@1
|
812 int num_interfaces = interfaces->length();
|
duke@1
|
813 for (int index = 0; index < num_interfaces; index++) {
|
iklam@51329
|
814 InstanceKlass* interk = interfaces->at(index);
|
hseigel@51697
|
815 interk->link_class_impl(CHECK_false);
|
duke@1
|
816 }
|
duke@1
|
817
|
duke@1
|
818 // in case the class is linked in the process of linking its superclasses
|
hseigel@46341
|
819 if (is_linked()) {
|
duke@1
|
820 return true;
|
duke@1
|
821 }
|
duke@1
|
822
|
mchung@3575
|
823 // trace only the link time for this klass that includes
|
mchung@3575
|
824 // the verification time
|
mchung@3575
|
825 PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(),
|
mchung@3575
|
826 ClassLoader::perf_class_link_selftime(),
|
mchung@3575
|
827 ClassLoader::perf_classes_linked(),
|
mchung@3575
|
828 jt->get_thread_stat()->perf_recursion_counts_addr(),
|
mchung@3575
|
829 jt->get_thread_stat()->perf_timers_addr(),
|
mchung@3575
|
830 PerfClassTraceTime::CLASS_LINK);
|
mchung@3575
|
831
|
duke@1
|
832 // verification & rewriting
|
duke@1
|
833 {
|
coleenp@46271
|
834 HandleMark hm(THREAD);
|
hseigel@46341
|
835 Handle h_init_lock(THREAD, init_lock());
|
hseigel@46562
|
836 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
|
duke@1
|
837 // rewritten will have been set if loader constraint error found
|
duke@1
|
838 // on an earlier link attempt
|
duke@1
|
839 // don't verify or rewrite if already rewritten
|
coleenp@46271
|
840 //
|
coleenp@13728
|
841
|
hseigel@46341
|
842 if (!is_linked()) {
|
hseigel@46341
|
843 if (!is_rewritten()) {
|
duke@1
|
844 {
|
hseigel@51697
|
845 bool verify_ok = verify_code(THREAD);
|
duke@1
|
846 if (!verify_ok) {
|
duke@1
|
847 return false;
|
duke@1
|
848 }
|
duke@1
|
849 }
|
duke@1
|
850
|
duke@1
|
851 // Just in case a side-effect of verify linked this class already
|
duke@1
|
852 // (which can sometimes happen since the verifier loads classes
|
duke@1
|
853 // using custom class loaders, which are free to initialize things)
|
hseigel@46341
|
854 if (is_linked()) {
|
duke@1
|
855 return true;
|
duke@1
|
856 }
|
duke@1
|
857
|
duke@1
|
858 // also sets rewritten
|
hseigel@46341
|
859 rewrite_class(CHECK_false);
|
hseigel@46341
|
860 } else if (is_shared()) {
|
hseigel@46341
|
861 SystemDictionaryShared::check_verification_constraints(this, CHECK_false);
|
duke@1
|
862 }
|
duke@1
|
863
|
coleenp@9971
|
864 // relocate jsrs and link methods after they are all rewritten
|
hseigel@46341
|
865 link_methods(CHECK_false);
|
coleenp@9971
|
866
|
duke@1
|
867 // Initialize the vtable and interface table after
|
duke@1
|
868 // methods have been rewritten since rewrite may
|
coleenp@13728
|
869 // fabricate new Method*s.
|
duke@1
|
870 // also does loader constraint checking
|
jiangli@39714
|
871 //
|
jiangli@39714
|
872 // initialize_vtable and initialize_itable need to be rerun for
|
jiangli@39714
|
873 // a shared class if the class is not loaded by the NULL classloader.
|
hseigel@46341
|
874 ClassLoaderData * loader_data = class_loader_data();
|
hseigel@46341
|
875 if (!(is_shared() &&
|
jiangli@39714
|
876 loader_data->is_the_null_class_loader_data())) {
|
iklam@46408
|
877 vtable().initialize_vtable(true, CHECK_false);
|
iklam@46408
|
878 itable().initialize_itable(true, CHECK_false);
|
duke@1
|
879 }
|
duke@1
|
880 #ifdef ASSERT
|
duke@1
|
881 else {
|
iklam@46408
|
882 vtable().verify(tty, true);
|
duke@1
|
883 // In case itable verification is ever added.
|
iklam@46408
|
884 // itable().verify(tty, true);
|
duke@1
|
885 }
|
duke@1
|
886 #endif
|
hseigel@46341
|
887 set_init_state(linked);
|
duke@1
|
888 if (JvmtiExport::should_post_class_prepare()) {
|
duke@1
|
889 Thread *thread = THREAD;
|
duke@1
|
890 assert(thread->is_Java_thread(), "thread->is_Java_thread()");
|
hseigel@46341
|
891 JvmtiExport::post_class_prepare((JavaThread *) thread, this);
|
duke@1
|
892 }
|
duke@1
|
893 }
|
duke@1
|
894 }
|
duke@1
|
895 return true;
|
duke@1
|
896 }
|
duke@1
|
897
|
duke@1
|
898 // Rewrite the byte codes of all of the methods of a class.
|
duke@1
|
899 // The rewriter must be called exactly once. Rewriting must happen after
|
duke@1
|
900 // verification but before the first method of the class is executed.
|
coleenp@13728
|
901 void InstanceKlass::rewrite_class(TRAPS) {
|
duke@1
|
902 assert(is_loaded(), "must be loaded");
|
coleenp@46329
|
903 if (is_rewritten()) {
|
coleenp@46329
|
904 assert(is_shared(), "rewriting an unshared class?");
|
duke@1
|
905 return;
|
duke@1
|
906 }
|
coleenp@46329
|
907 Rewriter::rewrite(this, CHECK);
|
coleenp@46329
|
908 set_rewritten();
|
duke@1
|
909 }
|
duke@1
|
910
|
coleenp@9971
|
911 // Now relocate and link method entry points after class is rewritten.
|
coleenp@9971
|
912 // This is outside is_rewritten flag. In case of an exception, it can be
|
coleenp@9971
|
913 // executed more than once.
|
coleenp@15099
|
914 void InstanceKlass::link_methods(TRAPS) {
|
coleenp@15099
|
915 int len = methods()->length();
|
coleenp@15099
|
916 for (int i = len-1; i >= 0; i--) {
|
coleenp@15099
|
917 methodHandle m(THREAD, methods()->at(i));
|
coleenp@15099
|
918
|
coleenp@15099
|
919 // Set up method entry points for compiler and interpreter .
|
coleenp@15099
|
920 m->link_method(m, CHECK);
|
coleenp@15099
|
921 }
|
coleenp@9971
|
922 }
|
coleenp@9971
|
923
|
acorn@27402
|
924 // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access)
|
hseigel@46341
|
925 void InstanceKlass::initialize_super_interfaces(TRAPS) {
|
hseigel@46341
|
926 assert (has_nonstatic_concrete_methods(), "caller should have checked this");
|
hseigel@46341
|
927 for (int i = 0; i < local_interfaces()->length(); ++i) {
|
iklam@51329
|
928 InstanceKlass* ik = local_interfaces()->at(i);
|
coleenp@41293
|
929
|
coleenp@41293
|
930 // Initialization is depth first search ie. we start with top of the inheritance tree
|
dholmes@41669
|
931 // has_nonstatic_concrete_methods drives searching superinterfaces since it
|
dholmes@41669
|
932 // means has_nonstatic_concrete_methods in its superinterface hierarchy
|
dholmes@41669
|
933 if (ik->has_nonstatic_concrete_methods()) {
|
hseigel@46341
|
934 ik->initialize_super_interfaces(CHECK);
|
coleenp@41293
|
935 }
|
coleenp@41293
|
936
|
coleenp@41293
|
937 // Only initialize() interfaces that "declare" concrete methods.
|
dholmes@41669
|
938 if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) {
|
coleenp@41293
|
939 ik->initialize(CHECK);
|
acorn@27402
|
940 }
|
acorn@27402
|
941 }
|
acorn@27402
|
942 }
|
duke@1
|
943
|
hseigel@46341
|
944 void InstanceKlass::initialize_impl(TRAPS) {
|
coleenp@46271
|
945 HandleMark hm(THREAD);
|
coleenp@46271
|
946
|
duke@1
|
947 // Make sure klass is linked (verified) before initialization
|
duke@1
|
948 // A class could already be verified, since it has been reflected upon.
|
hseigel@46341
|
949 link_class(CHECK);
|
hseigel@46341
|
950
|
hseigel@46341
|
951 DTRACE_CLASSINIT_PROBE(required, -1);
|
fparain@5089
|
952
|
fparain@5089
|
953 bool wait = false;
|
fparain@5089
|
954
|
dholmes@53305
|
955 assert(THREAD->is_Java_thread(), "non-JavaThread in initialize_impl");
|
dholmes@53305
|
956 JavaThread* jt = (JavaThread*)THREAD;
|
dholmes@53305
|
957
|
duke@1
|
958 // refer to the JVM book page 47 for description of steps
|
duke@1
|
959 // Step 1
|
coleenp@13728
|
960 {
|
hseigel@46341
|
961 Handle h_init_lock(THREAD, init_lock());
|
hseigel@46562
|
962 ObjectLocker ol(h_init_lock, THREAD, h_init_lock() != NULL);
|
duke@1
|
963
|
duke@1
|
964 // Step 2
|
duke@1
|
965 // If we were to use wait() instead of waitInterruptibly() then
|
duke@1
|
966 // we might end up throwing IE from link/symbol resolution sites
|
duke@1
|
967 // that aren't expected to throw. This would wreak havoc. See 6320309.
|
dholmes@53305
|
968 while (is_being_initialized() && !is_reentrant_initialization(jt)) {
|
dholmes@53305
|
969 wait = true;
|
dholmes@53305
|
970 jt->set_class_to_be_initialized(this);
|
dcubed@56104
|
971 ol.wait_uninterruptibly(jt);
|
dholmes@53305
|
972 jt->set_class_to_be_initialized(NULL);
|
duke@1
|
973 }
|
duke@1
|
974
|
duke@1
|
975 // Step 3
|
dholmes@53305
|
976 if (is_being_initialized() && is_reentrant_initialization(jt)) {
|
hseigel@46341
|
977 DTRACE_CLASSINIT_PROBE_WAIT(recursive, -1, wait);
|
duke@1
|
978 return;
|
fparain@5089
|
979 }
|
duke@1
|
980
|
duke@1
|
981 // Step 4
|
hseigel@46341
|
982 if (is_initialized()) {
|
hseigel@46341
|
983 DTRACE_CLASSINIT_PROBE_WAIT(concurrent, -1, wait);
|
duke@1
|
984 return;
|
fparain@5089
|
985 }
|
duke@1
|
986
|
duke@1
|
987 // Step 5
|
hseigel@46341
|
988 if (is_in_error_state()) {
|
hseigel@46341
|
989 DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait);
|
duke@1
|
990 ResourceMark rm(THREAD);
|
duke@1
|
991 const char* desc = "Could not initialize class ";
|
hseigel@46341
|
992 const char* className = external_name();
|
duke@1
|
993 size_t msglen = strlen(desc) + strlen(className) + 1;
|
kamg@6421
|
994 char* message = NEW_RESOURCE_ARRAY(char, msglen);
|
duke@1
|
995 if (NULL == message) {
|
duke@1
|
996 // Out of memory: can't create detailed error message
|
ccheung@47103
|
997 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), className);
|
duke@1
|
998 } else {
|
duke@1
|
999 jio_snprintf(message, msglen, "%s%s", desc, className);
|
ccheung@47103
|
1000 THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), message);
|
duke@1
|
1001 }
|
duke@1
|
1002 }
|
duke@1
|
1003
|
duke@1
|
1004 // Step 6
|
hseigel@46341
|
1005 set_init_state(being_initialized);
|
dholmes@53305
|
1006 set_init_thread(jt);
|
duke@1
|
1007 }
|
duke@1
|
1008
|
duke@1
|
1009 // Step 7
|
coleenp@41293
|
1010 // Next, if C is a class rather than an interface, initialize it's super class and super
|
coleenp@41293
|
1011 // interfaces.
|
hseigel@46341
|
1012 if (!is_interface()) {
|
hseigel@46341
|
1013 Klass* super_klass = super();
|
coleenp@41293
|
1014 if (super_klass != NULL && super_klass->should_be_initialized()) {
|
coleenp@41293
|
1015 super_klass->initialize(THREAD);
|
coleenp@41293
|
1016 }
|
dholmes@41669
|
1017 // If C implements any interface that declares a non-static, concrete method,
|
coleenp@41293
|
1018 // the initialization of C triggers initialization of its super interfaces.
|
dholmes@41669
|
1019 // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and
|
dholmes@41669
|
1020 // having a superinterface that declares, non-static, concrete methods
|
hseigel@46341
|
1021 if (!HAS_PENDING_EXCEPTION && has_nonstatic_concrete_methods()) {
|
hseigel@46341
|
1022 initialize_super_interfaces(THREAD);
|
coleenp@41293
|
1023 }
|
coleenp@41293
|
1024
|
coleenp@41293
|
1025 // If any exceptions, complete abruptly, throwing the same exception as above.
|
duke@1
|
1026 if (HAS_PENDING_EXCEPTION) {
|
duke@1
|
1027 Handle e(THREAD, PENDING_EXCEPTION);
|
duke@1
|
1028 CLEAR_PENDING_EXCEPTION;
|
duke@1
|
1029 {
|
duke@1
|
1030 EXCEPTION_MARK;
|
coleenp@41293
|
1031 // Locks object, set state, and notify all waiting threads
|
hseigel@46341
|
1032 set_initialization_state_and_notify(initialization_error, THREAD);
|
coleenp@41293
|
1033 CLEAR_PENDING_EXCEPTION;
|
duke@1
|
1034 }
|
hseigel@46341
|
1035 DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait);
|
duke@1
|
1036 THROW_OOP(e());
|
duke@1
|
1037 }
|
duke@1
|
1038 }
|
duke@1
|
1039
|
kamg@14385
|
1040
|
kvn@42650
|
1041 // Look for aot compiled methods for this klass, including class initializer.
|
hseigel@46341
|
1042 AOTLoader::load_for_klass(this, THREAD);
|
kvn@42650
|
1043
|
duke@1
|
1044 // Step 8
|
duke@1
|
1045 {
|
hseigel@46341
|
1046 DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait);
|
duke@1
|
1047 // Timer includes any side effects of class initialization (resolution,
|
duke@1
|
1048 // etc), but not recursive entry into call_class_initializer().
|
mchung@3575
|
1049 PerfClassTraceTime timer(ClassLoader::perf_class_init_time(),
|
mchung@3575
|
1050 ClassLoader::perf_class_init_selftime(),
|
mchung@3575
|
1051 ClassLoader::perf_classes_inited(),
|
mchung@3575
|
1052 jt->get_thread_stat()->perf_recursion_counts_addr(),
|
mchung@3575
|
1053 jt->get_thread_stat()->perf_timers_addr(),
|
mchung@3575
|
1054 PerfClassTraceTime::CLASS_CLINIT);
|
hseigel@46341
|
1055 call_class_initializer(THREAD);
|
duke@1
|
1056 }
|
duke@1
|
1057
|
duke@1
|
1058 // Step 9
|
duke@1
|
1059 if (!HAS_PENDING_EXCEPTION) {
|
hseigel@46341
|
1060 set_initialization_state_and_notify(fully_initialized, CHECK);
|
iklam@46408
|
1061 {
|
iklam@46408
|
1062 debug_only(vtable().verify(tty, true);)
|
duke@1
|
1063 }
|
duke@1
|
1064 }
|
duke@1
|
1065 else {
|
duke@1
|
1066 // Step 10 and 11
|
duke@1
|
1067 Handle e(THREAD, PENDING_EXCEPTION);
|
duke@1
|
1068 CLEAR_PENDING_EXCEPTION;
|
jbachorik@22897
|
1069 // JVMTI has already reported the pending exception
|
jbachorik@22897
|
1070 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
|
dholmes@53305
|
1071 JvmtiExport::clear_detected_exception(jt);
|
duke@1
|
1072 {
|
duke@1
|
1073 EXCEPTION_MARK;
|
hseigel@46341
|
1074 set_initialization_state_and_notify(initialization_error, THREAD);
|
duke@1
|
1075 CLEAR_PENDING_EXCEPTION; // ignore any exception thrown, class initialization error is thrown below
|
jbachorik@22897
|
1076 // JVMTI has already reported the pending exception
|
jbachorik@22897
|
1077 // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError
|
dholmes@53305
|
1078 JvmtiExport::clear_detected_exception(jt);
|
duke@1
|
1079 }
|
hseigel@46341
|
1080 DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait);
|
never@4571
|
1081 if (e->is_a(SystemDictionary::Error_klass())) {
|
duke@1
|
1082 THROW_OOP(e());
|
duke@1
|
1083 } else {
|
duke@1
|
1084 JavaCallArguments args(e);
|
coleenp@8076
|
1085 THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),
|
coleenp@8076
|
1086 vmSymbols::throwable_void_signature(),
|
duke@1
|
1087 &args);
|
duke@1
|
1088 }
|
duke@1
|
1089 }
|
hseigel@46341
|
1090 DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait);
|
duke@1
|
1091 }
|
duke@1
|
1092
|
duke@1
|
1093
|
coleenp@13728
|
1094 void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPS) {
|
hseigel@46341
|
1095 Handle h_init_lock(THREAD, init_lock());
|
hseigel@46562
|
1096 if (h_init_lock() != NULL) {
|
hseigel@46341
|
1097 ObjectLocker ol(h_init_lock, THREAD);
|
vlivanov@55254
|
1098 set_init_thread(NULL); // reset _init_thread before changing _init_state
|
hseigel@46341
|
1099 set_init_state(state);
|
hseigel@46341
|
1100 fence_and_clear_init_lock();
|
coleenp@41293
|
1101 ol.notify_all(CHECK);
|
coleenp@41293
|
1102 } else {
|
hseigel@46562
|
1103 assert(h_init_lock() != NULL, "The initialization state should never be set twice");
|
vlivanov@55254
|
1104 set_init_thread(NULL); // reset _init_thread before changing _init_state
|
hseigel@46341
|
1105 set_init_state(state);
|
coleenp@41293
|
1106 }
|
duke@1
|
1107 }
|
duke@1
|
1108
|
coleenp@52356
|
1109 Klass* InstanceKlass::implementor() const {
|
eosterlund@52784
|
1110 Klass* volatile* k = adr_implementor();
|
coleenp@51379
|
1111 if (k == NULL) {
|
coleenp@51379
|
1112 return NULL;
|
coleenp@51379
|
1113 } else {
|
eosterlund@52784
|
1114 // This load races with inserts, and therefore needs acquire.
|
stefank@57083
|
1115 Klass* kls = Atomic::load_acquire(k);
|
eosterlund@52784
|
1116 if (kls != NULL && !kls->is_loader_alive()) {
|
eosterlund@52784
|
1117 return NULL; // don't return unloaded class
|
eosterlund@52784
|
1118 } else {
|
eosterlund@52784
|
1119 return kls;
|
eosterlund@52784
|
1120 }
|
coleenp@51379
|
1121 }
|
coleenp@51379
|
1122 }
|
coleenp@51379
|
1123
|
eosterlund@52784
|
1124
|
coleenp@51379
|
1125 void InstanceKlass::set_implementor(Klass* k) {
|
coleenp@56445
|
1126 assert_locked_or_safepoint(Compile_lock);
|
coleenp@51379
|
1127 assert(is_interface(), "not interface");
|
eosterlund@52784
|
1128 Klass* volatile* addr = adr_implementor();
|
coleenp@51379
|
1129 assert(addr != NULL, "null addr");
|
coleenp@51379
|
1130 if (addr != NULL) {
|
stefank@57083
|
1131 Atomic::release_store(addr, k);
|
coleenp@51379
|
1132 }
|
coleenp@51379
|
1133 }
|
coleenp@51379
|
1134
|
coleenp@51379
|
1135 int InstanceKlass::nof_implementors() const {
|
coleenp@51379
|
1136 Klass* k = implementor();
|
coleenp@51379
|
1137 if (k == NULL) {
|
coleenp@51379
|
1138 return 0;
|
coleenp@51379
|
1139 } else if (k != this) {
|
coleenp@51379
|
1140 return 1;
|
coleenp@51379
|
1141 } else {
|
coleenp@51379
|
1142 return 2;
|
coleenp@51379
|
1143 }
|
coleenp@51379
|
1144 }
|
coleenp@51379
|
1145
|
jiangli@12369
|
1146 // The embedded _implementor field can only record one implementor.
|
jiangli@12369
|
1147 // When there are more than one implementors, the _implementor field
|
coleenp@13728
|
1148 // is set to the interface Klass* itself. Following are the possible
|
jiangli@12369
|
1149 // values for the _implementor field:
|
jiangli@12369
|
1150 // NULL - no implementor
|
coleenp@13728
|
1151 // implementor Klass* - one implementor
|
jiangli@12369
|
1152 // self - more than one implementor
|
jiangli@12369
|
1153 //
|
jiangli@12369
|
1154 // The _implementor field only exists for interfaces.
|
coleenp@13728
|
1155 void InstanceKlass::add_implementor(Klass* k) {
|
minqi@58209
|
1156 if (Universe::is_fully_initialized()) {
|
minqi@58209
|
1157 assert_lock_strong(Compile_lock);
|
minqi@58209
|
1158 }
|
jiangli@12369
|
1159 assert(is_interface(), "not interface");
|
duke@1
|
1160 // Filter out my subinterfaces.
|
duke@1
|
1161 // (Note: Interfaces are never on the subklass list.)
|
coleenp@13728
|
1162 if (InstanceKlass::cast(k)->is_interface()) return;
|
duke@1
|
1163
|
duke@1
|
1164 // Filter out subclasses whose supers already implement me.
|
duke@1
|
1165 // (Note: CHA must walk subclasses of direct implementors
|
duke@1
|
1166 // in order to locate indirect implementors.)
|
coleenp@33602
|
1167 Klass* sk = k->super();
|
coleenp@13728
|
1168 if (sk != NULL && InstanceKlass::cast(sk)->implements_interface(this))
|
duke@1
|
1169 // We only need to check one immediate superclass, since the
|
duke@1
|
1170 // implements_interface query looks at transitive_interfaces.
|
duke@1
|
1171 // Any supers of the super have the same (or fewer) transitive_interfaces.
|
duke@1
|
1172 return;
|
duke@1
|
1173
|
coleenp@13728
|
1174 Klass* ik = implementor();
|
jiangli@12369
|
1175 if (ik == NULL) {
|
jiangli@12369
|
1176 set_implementor(k);
|
dnsimon@57916
|
1177 } else if (ik != this && ik != k) {
|
jiangli@12369
|
1178 // There is already an implementor. Use itself as an indicator of
|
jiangli@12369
|
1179 // more than one implementors.
|
coleenp@13728
|
1180 set_implementor(this);
|
duke@1
|
1181 }
|
duke@1
|
1182
|
duke@1
|
1183 // The implementor also implements the transitive_interfaces
|
duke@1
|
1184 for (int index = 0; index < local_interfaces()->length(); index++) {
|
coleenp@13728
|
1185 InstanceKlass::cast(local_interfaces()->at(index))->add_implementor(k);
|
duke@1
|
1186 }
|
duke@1
|
1187 }
|
duke@1
|
1188
|
coleenp@13728
|
1189 void InstanceKlass::init_implementor() {
|
jiangli@12369
|
1190 if (is_interface()) {
|
jiangli@12369
|
1191 set_implementor(NULL);
|
jiangli@12369
|
1192 }
|
duke@1
|
1193 }
|
duke@1
|
1194
|
duke@1
|
1195
|
coleenp@13728
|
1196 void InstanceKlass::process_interfaces(Thread *thread) {
|
duke@1
|
1197 // link this class into the implementors list of every interface it implements
|
duke@1
|
1198 for (int i = local_interfaces()->length() - 1; i >= 0; i--) {
|
coleenp@13728
|
1199 assert(local_interfaces()->at(i)->is_klass(), "must be a klass");
|
coleenp@13728
|
1200 InstanceKlass* interf = InstanceKlass::cast(local_interfaces()->at(i));
|
duke@1
|
1201 assert(interf->is_interface(), "expected interface");
|
coleenp@23515
|
1202 interf->add_implementor(this);
|
duke@1
|
1203 }
|
duke@1
|
1204 }
|
duke@1
|
1205
|
coleenp@13728
|
1206 bool InstanceKlass::can_be_primary_super_slow() const {
|
duke@1
|
1207 if (is_interface())
|
duke@1
|
1208 return false;
|
duke@1
|
1209 else
|
duke@1
|
1210 return Klass::can_be_primary_super_slow();
|
duke@1
|
1211 }
|
duke@1
|
1212
|
ccheung@49948
|
1213 GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots,
|
iklam@51329
|
1214 Array<InstanceKlass*>* transitive_interfaces) {
|
duke@1
|
1215 // The secondaries are the implemented interfaces.
|
iklam@51329
|
1216 Array<InstanceKlass*>* interfaces = transitive_interfaces;
|
duke@1
|
1217 int num_secondaries = num_extra_slots + interfaces->length();
|
duke@1
|
1218 if (num_secondaries == 0) {
|
coleenp@13728
|
1219 // Must share this for correct bootstrapping!
|
coleenp@13728
|
1220 set_secondary_supers(Universe::the_empty_klass_array());
|
coleenp@13728
|
1221 return NULL;
|
duke@1
|
1222 } else if (num_extra_slots == 0) {
|
iklam@51329
|
1223 // The secondary super list is exactly the same as the transitive interfaces, so
|
iklam@51329
|
1224 // let's use it instead of making a copy.
|
coleenp@13728
|
1225 // Redefine classes has to be careful not to delete this!
|
iklam@51329
|
1226 // We need the cast because Array<Klass*> is NOT a supertype of Array<InstanceKlass*>,
|
iklam@51329
|
1227 // (but it's safe to do here because we won't write into _secondary_supers from this point on).
|
iklam@51329
|
1228 set_secondary_supers((Array<Klass*>*)(address)interfaces);
|
coleenp@13728
|
1229 return NULL;
|
duke@1
|
1230 } else {
|
coleenp@13728
|
1231 // Copy transitive interfaces to a temporary growable array to be constructed
|
coleenp@13728
|
1232 // into the secondary super list with extra slots.
|
coleenp@13728
|
1233 GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length());
|
duke@1
|
1234 for (int i = 0; i < interfaces->length(); i++) {
|
coleenp@13728
|
1235 secondaries->push(interfaces->at(i));
|
duke@1
|
1236 }
|
duke@1
|
1237 return secondaries;
|
duke@1
|
1238 }
|
duke@1
|
1239 }
|
duke@1
|
1240
|
coleenp@13728
|
1241 bool InstanceKlass::implements_interface(Klass* k) const {
|
coleenp@13728
|
1242 if (this == k) return true;
|
hseigel@14488
|
1243 assert(k->is_interface(), "should be an interface class");
|
duke@1
|
1244 for (int i = 0; i < transitive_interfaces()->length(); i++) {
|
coleenp@13728
|
1245 if (transitive_interfaces()->at(i) == k) {
|
duke@1
|
1246 return true;
|
duke@1
|
1247 }
|
duke@1
|
1248 }
|
duke@1
|
1249 return false;
|
duke@1
|
1250 }
|
duke@1
|
1251
|
hseigel@21768
|
1252 bool InstanceKlass::is_same_or_direct_interface(Klass *k) const {
|
hseigel@21768
|
1253 // Verify direct super interface
|
hseigel@21768
|
1254 if (this == k) return true;
|
hseigel@21768
|
1255 assert(k->is_interface(), "should be an interface class");
|
hseigel@21768
|
1256 for (int i = 0; i < local_interfaces()->length(); i++) {
|
hseigel@21768
|
1257 if (local_interfaces()->at(i) == k) {
|
hseigel@21768
|
1258 return true;
|
hseigel@21768
|
1259 }
|
hseigel@21768
|
1260 }
|
hseigel@21768
|
1261 return false;
|
hseigel@21768
|
1262 }
|
hseigel@21768
|
1263
|
coleenp@13728
|
1264 objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPS) {
|
dnsimon@52033
|
1265 check_array_allocation_length(length, arrayOopDesc::max_array_length(T_OBJECT), CHECK_NULL);
|
duke@1
|
1266 int size = objArrayOopDesc::object_size(length);
|
coleenp@13728
|
1267 Klass* ak = array_klass(n, CHECK_NULL);
|
eosterlund@50882
|
1268 objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length,
|
eosterlund@50882
|
1269 /* do_zero */ true, CHECK_NULL);
|
duke@1
|
1270 return o;
|
duke@1
|
1271 }
|
duke@1
|
1272
|
coleenp@13728
|
1273 instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPS) {
|
duke@1
|
1274 if (TraceFinalizerRegistration) {
|
duke@1
|
1275 tty->print("Registered ");
|
duke@1
|
1276 i->print_value_on(tty);
|
david@33148
|
1277 tty->print_cr(" (" INTPTR_FORMAT ") as finalizable", p2i(i));
|
duke@1
|
1278 }
|
duke@1
|
1279 instanceHandle h_i(THREAD, i);
|
duke@1
|
1280 // Pass the handle as argument, JavaCalls::call expects oop as jobjects
|
duke@1
|
1281 JavaValue result(T_VOID);
|
duke@1
|
1282 JavaCallArguments args(h_i);
|
duke@1
|
1283 methodHandle mh (THREAD, Universe::finalizer_register_method());
|
duke@1
|
1284 JavaCalls::call(&result, mh, &args, CHECK_NULL);
|
duke@1
|
1285 return h_i();
|
duke@1
|
1286 }
|
duke@1
|
1287
|
coleenp@13728
|
1288 instanceOop InstanceKlass::allocate_instance(TRAPS) {
|
duke@1
|
1289 bool has_finalizer_flag = has_finalizer(); // Query before possible GC
|
duke@1
|
1290 int size = size_helper(); // Query before forming handle.
|
duke@1
|
1291
|
duke@1
|
1292 instanceOop i;
|
duke@1
|
1293
|
eosterlund@50882
|
1294 i = (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL);
|
duke@1
|
1295 if (has_finalizer_flag && !RegisterFinalizersAtInit) {
|
duke@1
|
1296 i = register_finalizer(i, CHECK_NULL);
|
duke@1
|
1297 }
|
duke@1
|
1298 return i;
|
duke@1
|
1299 }
|
duke@1
|
1300
|
simonis@49393
|
1301 instanceHandle InstanceKlass::allocate_instance_handle(TRAPS) {
|
simonis@49393
|
1302 return instanceHandle(THREAD, allocate_instance(THREAD));
|
simonis@49393
|
1303 }
|
simonis@49393
|
1304
|
coleenp@13728
|
1305 void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPS) {
|
duke@1
|
1306 if (is_interface() || is_abstract()) {
|
duke@1
|
1307 ResourceMark rm(THREAD);
|
duke@1
|
1308 THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError()
|
duke@1
|
1309 : vmSymbols::java_lang_InstantiationException(), external_name());
|
duke@1
|
1310 }
|
coleenp@13728
|
1311 if (this == SystemDictionary::Class_klass()) {
|
duke@1
|
1312 ResourceMark rm(THREAD);
|
duke@1
|
1313 THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError()
|
duke@1
|
1314 : vmSymbols::java_lang_IllegalAccessException(), external_name());
|
duke@1
|
1315 }
|
duke@1
|
1316 }
|
duke@1
|
1317
|
coleenp@13728
|
1318 Klass* InstanceKlass::array_klass_impl(bool or_null, int n, TRAPS) {
|
dholmes@40887
|
1319 // Need load-acquire for lock-free read
|
hseigel@46341
|
1320 if (array_klasses_acquire() == NULL) {
|
duke@1
|
1321 if (or_null) return NULL;
|
duke@1
|
1322
|
iklam@57387
|
1323 ResourceMark rm(THREAD);
|
duke@1
|
1324 JavaThread *jt = (JavaThread *)THREAD;
|
duke@1
|
1325 {
|
duke@1
|
1326 // Atomic creation of array_klasses
|
hseigel@57716
|
1327 MutexLocker ma(THREAD, MultiArray_lock);
|
duke@1
|
1328
|
duke@1
|
1329 // Check if update has already taken place
|
hseigel@46341
|
1330 if (array_klasses() == NULL) {
|
hseigel@46341
|
1331 Klass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL);
|
dholmes@40887
|
1332 // use 'release' to pair with lock-free load
|
hseigel@46341
|
1333 release_set_array_klasses(k);
|
duke@1
|
1334 }
|
duke@1
|
1335 }
|
duke@1
|
1336 }
|
duke@1
|
1337 // _this will always be set at this point
|
hseigel@46341
|
1338 ObjArrayKlass* oak = (ObjArrayKlass*)array_klasses();
|
duke@1
|
1339 if (or_null) {
|
duke@1
|
1340 return oak->array_klass_or_null(n);
|
duke@1
|
1341 }
|
stefank@27680
|
1342 return oak->array_klass(n, THREAD);
|
duke@1
|
1343 }
|
duke@1
|
1344
|
coleenp@13728
|
1345 Klass* InstanceKlass::array_klass_impl(bool or_null, TRAPS) {
|
duke@1
|
1346 return array_klass_impl(or_null, 1, THREAD);
|
duke@1
|
1347 }
|
duke@1
|
1348
|
hseigel@46341
|
1349 static int call_class_initializer_counter = 0; // for debugging
|
duke@1
|
1350
|
coleenp@46329
|
1351 Method* InstanceKlass::class_initializer() const {
|
coleenp@13728
|
1352 Method* clinit = find_method(
|
kamg@8653
|
1353 vmSymbols::class_initializer_name(), vmSymbols::void_method_signature());
|
kamg@8653
|
1354 if (clinit != NULL && clinit->has_valid_initializer_flags()) {
|
kamg@8653
|
1355 return clinit;
|
kamg@8653
|
1356 }
|
kamg@8653
|
1357 return NULL;
|
duke@1
|
1358 }
|
duke@1
|
1359
|
hseigel@46341
|
1360 void InstanceKlass::call_class_initializer(TRAPS) {
|
minqi@14477
|
1361 if (ReplayCompiles &&
|
minqi@14477
|
1362 (ReplaySuppressInitializers == 1 ||
|
jwilhelm@46630
|
1363 (ReplaySuppressInitializers >= 2 && class_loader() != NULL))) {
|
minqi@14477
|
1364 // Hide the existence of the initializer for the purpose of replaying the compile
|
minqi@14477
|
1365 return;
|
minqi@14477
|
1366 }
|
minqi@14477
|
1367
|
hseigel@46341
|
1368 methodHandle h_method(THREAD, class_initializer());
|
hseigel@46341
|
1369 assert(!is_initialized(), "we cannot initialize twice");
|
stuefe@46701
|
1370 LogTarget(Info, class, init) lt;
|
stuefe@46701
|
1371 if (lt.is_enabled()) {
|
iklam@57387
|
1372 ResourceMark rm(THREAD);
|
stuefe@46701
|
1373 LogStream ls(lt);
|
stuefe@46701
|
1374 ls.print("%d Initializing ", call_class_initializer_counter++);
|
stuefe@46701
|
1375 name()->print_value_on(&ls);
|
stuefe@46701
|
1376 ls.print_cr("%s (" INTPTR_FORMAT ")", h_method() == NULL ? "(no method)" : "", p2i(this));
|
duke@1
|
1377 }
|
duke@1
|
1378 if (h_method() != NULL) {
|
duke@1
|
1379 JavaCallArguments args; // No arguments
|
duke@1
|
1380 JavaValue result(T_VOID);
|
duke@1
|
1381 JavaCalls::call(&result, h_method, &args, CHECK); // Static call (no args)
|
duke@1
|
1382 }
|
duke@1
|
1383 }
|
duke@1
|
1384
|
duke@1
|
1385
|
coleenp@33593
|
1386 void InstanceKlass::mask_for(const methodHandle& method, int bci,
|
duke@1
|
1387 InterpreterOopMap* entry_for) {
|
dholmes@38937
|
1388 // Lazily create the _oop_map_cache at first request
|
coleenp@47634
|
1389 // Lock-free access requires load_acquire.
|
stefank@57083
|
1390 OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache);
|
dholmes@38937
|
1391 if (oop_map_cache == NULL) {
|
duke@1
|
1392 MutexLocker x(OopMapCacheAlloc_lock);
|
dholmes@38937
|
1393 // Check if _oop_map_cache was allocated while we were waiting for this lock
|
dholmes@38937
|
1394 if ((oop_map_cache = _oop_map_cache) == NULL) {
|
dholmes@38937
|
1395 oop_map_cache = new OopMapCache();
|
dholmes@38937
|
1396 // Ensure _oop_map_cache is stable, since it is examined without a lock
|
stefank@57083
|
1397 Atomic::release_store(&_oop_map_cache, oop_map_cache);
|
duke@1
|
1398 }
|
duke@1
|
1399 }
|
dholmes@38937
|
1400 // _oop_map_cache is constant after init; lookup below does its own locking.
|
dholmes@38937
|
1401 oop_map_cache->lookup(method, bci, entry_for);
|
duke@1
|
1402 }
|
duke@1
|
1403
|
fparain@57985
|
1404 bool InstanceKlass::contains_field_offset(int offset) {
|
fparain@57985
|
1405 fieldDescriptor fd;
|
fparain@57985
|
1406 return find_field_from_offset(offset, false, &fd);
|
fparain@57985
|
1407 }
|
duke@1
|
1408
|
coleenp@13728
|
1409 bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
|
coleenp@13728
|
1410 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
|
never@10546
|
1411 Symbol* f_name = fs.name();
|
never@10546
|
1412 Symbol* f_sig = fs.signature();
|
duke@1
|
1413 if (f_name == name && f_sig == sig) {
|
drchase@20017
|
1414 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
|
duke@1
|
1415 return true;
|
duke@1
|
1416 }
|
duke@1
|
1417 }
|
duke@1
|
1418 return false;
|
duke@1
|
1419 }
|
duke@1
|
1420
|
duke@1
|
1421
|
coleenp@13728
|
1422 Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
|
duke@1
|
1423 const int n = local_interfaces()->length();
|
duke@1
|
1424 for (int i = 0; i < n; i++) {
|
coleenp@13728
|
1425 Klass* intf1 = local_interfaces()->at(i);
|
hseigel@14488
|
1426 assert(intf1->is_interface(), "just checking type");
|
duke@1
|
1427 // search for field in current interface
|
coleenp@13728
|
1428 if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) {
|
duke@1
|
1429 assert(fd->is_static(), "interface field must be static");
|
duke@1
|
1430 return intf1;
|
duke@1
|
1431 }
|
duke@1
|
1432 // search for field in direct superinterfaces
|
coleenp@13728
|
1433 Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd);
|
duke@1
|
1434 if (intf2 != NULL) return intf2;
|
duke@1
|
1435 }
|
duke@1
|
1436 // otherwise field lookup fails
|
duke@1
|
1437 return NULL;
|
duke@1
|
1438 }
|
duke@1
|
1439
|
duke@1
|
1440
|
coleenp@13728
|
1441 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const {
|
duke@1
|
1442 // search order according to newest JVM spec (5.4.3.2, p.167).
|
duke@1
|
1443 // 1) search for field in current klass
|
duke@1
|
1444 if (find_local_field(name, sig, fd)) {
|
coleenp@13728
|
1445 return const_cast<InstanceKlass*>(this);
|
duke@1
|
1446 }
|
duke@1
|
1447 // 2) search for field recursively in direct superinterfaces
|
coleenp@13728
|
1448 { Klass* intf = find_interface_field(name, sig, fd);
|
duke@1
|
1449 if (intf != NULL) return intf;
|
duke@1
|
1450 }
|
duke@1
|
1451 // 3) apply field lookup recursively if superclass exists
|
coleenp@13728
|
1452 { Klass* supr = super();
|
coleenp@13728
|
1453 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, fd);
|
duke@1
|
1454 }
|
duke@1
|
1455 // 4) otherwise field lookup fails
|
duke@1
|
1456 return NULL;
|
duke@1
|
1457 }
|
duke@1
|
1458
|
duke@1
|
1459
|
coleenp@13728
|
1460 Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const {
|
duke@1
|
1461 // search order according to newest JVM spec (5.4.3.2, p.167).
|
duke@1
|
1462 // 1) search for field in current klass
|
duke@1
|
1463 if (find_local_field(name, sig, fd)) {
|
coleenp@13728
|
1464 if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this);
|
duke@1
|
1465 }
|
duke@1
|
1466 // 2) search for field recursively in direct superinterfaces
|
duke@1
|
1467 if (is_static) {
|
coleenp@13728
|
1468 Klass* intf = find_interface_field(name, sig, fd);
|
duke@1
|
1469 if (intf != NULL) return intf;
|
duke@1
|
1470 }
|
duke@1
|
1471 // 3) apply field lookup recursively if superclass exists
|
coleenp@13728
|
1472 { Klass* supr = super();
|
coleenp@13728
|
1473 if (supr != NULL) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd);
|
duke@1
|
1474 }
|
duke@1
|
1475 // 4) otherwise field lookup fails
|
duke@1
|
1476 return NULL;
|
duke@1
|
1477 }
|
duke@1
|
1478
|
duke@1
|
1479
|
coleenp@13728
|
1480 bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
|
coleenp@13728
|
1481 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
|
never@10546
|
1482 if (fs.offset() == offset) {
|
drchase@20017
|
1483 fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index());
|
duke@1
|
1484 if (fd->is_static() == is_static) return true;
|
duke@1
|
1485 }
|
duke@1
|
1486 }
|
duke@1
|
1487 return false;
|
duke@1
|
1488 }
|
duke@1
|
1489
|
duke@1
|
1490
|
coleenp@13728
|
1491 bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const {
|
coleenp@13728
|
1492 Klass* klass = const_cast<InstanceKlass*>(this);
|
duke@1
|
1493 while (klass != NULL) {
|
coleenp@13728
|
1494 if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) {
|
duke@1
|
1495 return true;
|
duke@1
|
1496 }
|
hseigel@14488
|
1497 klass = klass->super();
|
duke@1
|
1498 }
|
duke@1
|
1499 return false;
|
duke@1
|
1500 }
|
duke@1
|
1501
|
duke@1
|
1502
|
coleenp@13728
|
1503 void InstanceKlass::methods_do(void f(Method* method)) {
|
coleenp@24658
|
1504 // Methods aren't stable until they are loaded. This can be read outside
|
coleenp@24658
|
1505 // a lock through the ClassLoaderData for profiling
|
coleenp@24658
|
1506 if (!is_loaded()) {
|
coleenp@24658
|
1507 return;
|
coleenp@24658
|
1508 }
|
coleenp@24658
|
1509
|
duke@1
|
1510 int len = methods()->length();
|
duke@1
|
1511 for (int index = 0; index < len; index++) {
|
coleenp@13728
|
1512 Method* m = methods()->at(index);
|
duke@1
|
1513 assert(m->is_method(), "must be method");
|
duke@1
|
1514 f(m);
|
duke@1
|
1515 }
|
duke@1
|
1516 }
|
duke@1
|
1517
|
never@8725
|
1518
|
coleenp@13728
|
1519 void InstanceKlass::do_local_static_fields(FieldClosure* cl) {
|
never@10546
|
1520 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
|
never@10546
|
1521 if (fs.access_flags().is_static()) {
|
drchase@20017
|
1522 fieldDescriptor& fd = fs.field_descriptor();
|
never@10546
|
1523 cl->do_field(&fd);
|
never@10546
|
1524 }
|
duke@1
|
1525 }
|
duke@1
|
1526 }
|
duke@1
|
1527
|
duke@1
|
1528
|
coleenp@23872
|
1529 void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPS), Handle mirror, TRAPS) {
|
hseigel@46341
|
1530 for (JavaFieldStream fs(this); !fs.done(); fs.next()) {
|
never@10546
|
1531 if (fs.access_flags().is_static()) {
|
drchase@20017
|
1532 fieldDescriptor& fd = fs.field_descriptor();
|
coleenp@23872
|
1533 f(&fd, mirror, CHECK);
|
never@10546
|
1534 }
|
duke@1
|
1535 }
|
duke@1
|
1536 }
|
duke@1
|
1537
|
duke@1
|
1538
|
kvn@217
|
1539 static int compare_fields_by_offset(int* a, int* b) {
|
kvn@217
|
1540 return a[0] - b[0];
|
kvn@217
|
1541 }
|
kvn@217
|
1542
|
coleenp@13728
|
1543 void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) {
|
coleenp@13728
|
1544 InstanceKlass* super = superklass();
|
duke@1
|
1545 if (super != NULL) {
|
duke@1
|
1546 super->do_nonstatic_fields(cl);
|
duke@1
|
1547 }
|
kvn@217
|
1548 fieldDescriptor fd;
|
never@10546
|
1549 int length = java_fields_count();
|
kvn@217
|
1550 // In DebugInfo nonstatic fields are sorted by offset.
|
zgu@13195
|
1551 int* fields_sorted = NEW_C_HEAP_ARRAY(int, 2*(length+1), mtClass);
|
kvn@217
|
1552 int j = 0;
|
never@10546
|
1553 for (int i = 0; i < length; i += 1) {
|
drchase@20017
|
1554 fd.reinitialize(this, i);
|
kvn@217
|
1555 if (!fd.is_static()) {
|
kvn@217
|
1556 fields_sorted[j + 0] = fd.offset();
|
kvn@217
|
1557 fields_sorted[j + 1] = i;
|
kvn@217
|
1558 j += 2;
|
kvn@217
|
1559 }
|
duke@1
|
1560 }
|
kvn@217
|
1561 if (j > 0) {
|
kvn@217
|
1562 length = j;
|
kvn@217
|
1563 // _sort_Fn is defined in growableArray.hpp.
|
kvn@217
|
1564 qsort(fields_sorted, length/2, 2*sizeof(int), (_sort_Fn)compare_fields_by_offset);
|
kvn@217
|
1565 for (int i = 0; i < length; i += 2) {
|
drchase@20017
|
1566 fd.reinitialize(this, fields_sorted[i + 1]);
|
kvn@217
|
1567 assert(!fd.is_static() && fd.offset() == fields_sorted[i], "only nonstatic fields");
|
kvn@217
|
1568 cl->do_field(&fd);
|
kvn@217
|
1569 }
|
kvn@217
|
1570 }
|
coleenp@27880
|
1571 FREE_C_HEAP_ARRAY(int, fields_sorted);
|
duke@1
|
1572 }
|
duke@1
|
1573
|
duke@1
|
1574
|
coleenp@13728
|
1575 void InstanceKlass::array_klasses_do(void f(Klass* k, TRAPS), TRAPS) {
|
coleenp@13728
|
1576 if (array_klasses() != NULL)
|
coleenp@13952
|
1577 ArrayKlass::cast(array_klasses())->array_klasses_do(f, THREAD);
|
coleenp@13728
|
1578 }
|
coleenp@13728
|
1579
|
coleenp@13728
|
1580 void InstanceKlass::array_klasses_do(void f(Klass* k)) {
|
duke@1
|
1581 if (array_klasses() != NULL)
|
coleenp@13952
|
1582 ArrayKlass::cast(array_klasses())->array_klasses_do(f);
|
duke@1
|
1583 }
|
duke@1
|
1584
|
duke@1
|
1585 #ifdef ASSERT
|
mgronlun@34666
|
1586 static int linear_search(const Array<Method*>* methods,
|
mgronlun@34666
|
1587 const Symbol* name,
|
mgronlun@34666
|
1588 const Symbol* signature) {
|
mgronlun@34666
|
1589 const int len = methods->length();
|
duke@1
|
1590 for (int index = 0; index < len; index++) {
|
mgronlun@34666
|
1591 const Method* const m = methods->at(index);
|
duke@1
|
1592 assert(m->is_method(), "must be method");
|
duke@1
|
1593 if (m->signature() == signature && m->name() == name) {
|
duke@1
|
1594 return index;
|
duke@1
|
1595 }
|
duke@1
|
1596 }
|
duke@1
|
1597 return -1;
|
duke@1
|
1598 }
|
duke@1
|
1599 #endif
|
duke@1
|
1600
|
iklam@56936
|
1601 bool InstanceKlass::_disable_method_binary_search = false;
|
iklam@56936
|
1602
|
redestad@57287
|
1603 NOINLINE int linear_search(const Array<Method*>* methods, const Symbol* name) {
|
duke@1
|
1604 int len = methods->length();
|
duke@1
|
1605 int l = 0;
|
duke@1
|
1606 int h = len - 1;
|
redestad@57287
|
1607 while (l <= h) {
|
redestad@57287
|
1608 Method* m = methods->at(l);
|
redestad@57287
|
1609 if (m->name() == name) {
|
redestad@57287
|
1610 return l;
|
redestad@57287
|
1611 }
|
redestad@57287
|
1612 l++;
|
redestad@57287
|
1613 }
|
redestad@57287
|
1614 return -1;
|
redestad@57287
|
1615 }
|
redestad@57287
|
1616
|
redestad@57287
|
1617 inline int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* name) {
|
iklam@56936
|
1618 if (_disable_method_binary_search) {
|
redestad@57287
|
1619 assert(DynamicDumpSharedSpaces, "must be");
|
iklam@56936
|
1620 // At the final stage of dynamic dumping, the methods array may not be sorted
|
iklam@56936
|
1621 // by ascending addresses of their names, so we can't use binary search anymore.
|
iklam@56936
|
1622 // However, methods with the same name are still laid out consecutively inside the
|
iklam@56936
|
1623 // methods array, so let's look for the first one that matches.
|
redestad@57287
|
1624 return linear_search(methods, name);
|
iklam@56936
|
1625 }
|
iklam@56936
|
1626
|
redestad@57287
|
1627 int len = methods->length();
|
redestad@57287
|
1628 int l = 0;
|
redestad@57287
|
1629 int h = len - 1;
|
redestad@57287
|
1630
|
iklam@56936
|
1631 // methods are sorted by ascending addresses of their names, so do binary search
|
duke@1
|
1632 while (l <= h) {
|
duke@1
|
1633 int mid = (l + h) >> 1;
|
coleenp@13728
|
1634 Method* m = methods->at(mid);
|
duke@1
|
1635 assert(m->is_method(), "must be method");
|
duke@1
|
1636 int res = m->name()->fast_compare(name);
|
duke@1
|
1637 if (res == 0) {
|
kamg@14385
|
1638 return mid;
|
duke@1
|
1639 } else if (res < 0) {
|
duke@1
|
1640 l = mid + 1;
|
duke@1
|
1641 } else {
|
duke@1
|
1642 h = mid - 1;
|
duke@1
|
1643 }
|
duke@1
|
1644 }
|
kamg@14385
|
1645 return -1;
|
kamg@14385
|
1646 }
|
kamg@14385
|
1647
|
acorn@20391
|
1648 // find_method looks up the name/signature in the local methods array
|
mgronlun@34666
|
1649 Method* InstanceKlass::find_method(const Symbol* name,
|
mgronlun@34666
|
1650 const Symbol* signature) const {
|
acorn@32189
|
1651 return find_method_impl(name, signature, find_overpass, find_static, find_private);
|
lfoltan@23999
|
1652 }
|
lfoltan@23999
|
1653
|
mgronlun@34666
|
1654 Method* InstanceKlass::find_method_impl(const Symbol* name,
|
mgronlun@34666
|
1655 const Symbol* signature,
|
acorn@32189
|
1656 OverpassLookupMode overpass_mode,
|
acorn@32189
|
1657 StaticLookupMode static_mode,
|
acorn@32189
|
1658 PrivateLookupMode private_mode) const {
|
mgronlun@34666
|
1659 return InstanceKlass::find_method_impl(methods(),
|
mgronlun@34666
|
1660 name,
|
mgronlun@34666
|
1661 signature,
|
mgronlun@34666
|
1662 overpass_mode,
|
mgronlun@34666
|
1663 static_mode,
|
mgronlun@34666
|
1664 private_mode);
|
kamg@14385
|
1665 }
|
kamg@14385
|
1666
|
acorn@21913
|
1667 // find_instance_method looks up the name/signature in the local methods array
|
acorn@21913
|
1668 // and skips over static methods
|
mgronlun@34666
|
1669 Method* InstanceKlass::find_instance_method(const Array<Method*>* methods,
|
mgronlun@34666
|
1670 const Symbol* name,
|
dholmes@50735
|
1671 const Symbol* signature,
|
dholmes@50735
|
1672 PrivateLookupMode private_mode) {
|
mgronlun@34666
|
1673 Method* const meth = InstanceKlass::find_method_impl(methods,
|
mgronlun@34666
|
1674 name,
|
mgronlun@34666
|
1675 signature,
|
mgronlun@34666
|
1676 find_overpass,
|
mgronlun@34666
|
1677 skip_static,
|
dholmes@50735
|
1678 private_mode);
|
mgronlun@34666
|
1679 assert(((meth == NULL) || !meth->is_static()),
|
mgronlun@34666
|
1680 "find_instance_method should have skipped statics");
|
acorn@21913
|
1681 return meth;
|
acorn@21913
|
1682 }
|
acorn@21913
|
1683
|
drchase@28514
|
1684 // find_instance_method looks up the name/signature in the local methods array
|
drchase@28514
|
1685 // and skips over static methods
|
dholmes@50735
|
1686 Method* InstanceKlass::find_instance_method(const Symbol* name,
|
dholmes@50735
|
1687 const Symbol* signature,
|
dholmes@50735
|
1688 PrivateLookupMode private_mode) const {
|
dholmes@50735
|
1689 return InstanceKlass::find_instance_method(methods(), name, signature, private_mode);
|
drchase@28514
|
1690 }
|
drchase@28514
|
1691
|
acorn@32189
|
1692 // Find looks up the name/signature in the local methods array
|
acorn@32189
|
1693 // and filters on the overpass, static and private flags
|
acorn@32189
|
1694 // This returns the first one found
|
acorn@32189
|
1695 // note that the local methods array can have up to one overpass, one static
|
acorn@32189
|
1696 // and one instance (private or not) with the same name/signature
|
mgronlun@34666
|
1697 Method* InstanceKlass::find_local_method(const Symbol* name,
|
mgronlun@34666
|
1698 const Symbol* signature,
|
mgronlun@34666
|
1699 OverpassLookupMode overpass_mode,
|
mgronlun@34666
|
1700 StaticLookupMode static_mode,
|
mgronlun@34666
|
1701 PrivateLookupMode private_mode) const {
|
mgronlun@34666
|
1702 return InstanceKlass::find_method_impl(methods(),
|
mgronlun@34666
|
1703 name,
|
mgronlun@34666
|
1704 signature,
|
mgronlun@34666
|
1705 overpass_mode,
|
mgronlun@34666
|
1706 static_mode,
|
mgronlun@34666
|
1707 private_mode);
|
acorn@32189
|
1708 }
|
acorn@32189
|
1709
|
acorn@32189
|
1710 // Find looks up the name/signature in the local methods array
|
acorn@32189
|
1711 // and filters on the overpass, static and private flags
|
acorn@32189
|
1712 // This returns the first one found
|
acorn@32189
|
1713 // note that the local methods array can have up to one overpass, one static
|
acorn@32189
|
1714 // and one instance (private or not) with the same name/signature
|
mgronlun@34666
|
1715 Method* InstanceKlass::find_local_method(const Array<Method*>* methods,
|
mgronlun@34666
|
1716 const Symbol* name,
|
mgronlun@34666
|
1717 const Symbol* signature,
|
mgronlun@34666
|
1718 OverpassLookupMode overpass_mode,
|
mgronlun@34666
|
1719 StaticLookupMode static_mode,
|
mgronlun@34666
|
1720 PrivateLookupMode private_mode) {
|
mgronlun@34666
|
1721 return InstanceKlass::find_method_impl(methods,
|
mgronlun@34666
|
1722 name,
|
mgronlun@34666
|
1723 signature,
|
mgronlun@34666
|
1724 overpass_mode,
|
mgronlun@34666
|
1725 static_mode,
|
mgronlun@34666
|
1726 private_mode);
|
mgronlun@34666
|
1727 }
|
mgronlun@34666
|
1728
|
mgronlun@34666
|
1729 Method* InstanceKlass::find_method(const Array<Method*>* methods,
|
mgronlun@34666
|
1730 const Symbol* name,
|
mgronlun@34666
|
1731 const Symbol* signature) {
|
mgronlun@34666
|
1732 return InstanceKlass::find_method_impl(methods,
|
mgronlun@34666
|
1733 name,
|
mgronlun@34666
|
1734 signature,
|
mgronlun@34666
|
1735 find_overpass,
|
mgronlun@34666
|
1736 find_static,
|
mgronlun@34666
|
1737 find_private);
|
mgronlun@34666
|
1738 }
|
mgronlun@34666
|
1739
|
mgronlun@34666
|
1740 Method* InstanceKlass::find_method_impl(const Array<Method*>* methods,
|
mgronlun@34666
|
1741 const Symbol* name,
|
mgronlun@34666
|
1742 const Symbol* signature,
|
acorn@32189
|
1743 OverpassLookupMode overpass_mode,
|
acorn@32189
|
1744 StaticLookupMode static_mode,
|
acorn@32189
|
1745 PrivateLookupMode private_mode) {
|
acorn@32189
|
1746 int hit = find_method_index(methods, name, signature, overpass_mode, static_mode, private_mode);
|
acorn@20391
|
1747 return hit >= 0 ? methods->at(hit): NULL;
|
acorn@20391
|
1748 }
|
acorn@20391
|
1749
|
mgronlun@34666
|
1750 // true if method matches signature and conforms to skipping_X conditions.
|
mgronlun@34666
|
1751 static bool method_matches(const Method* m,
|
mgronlun@34666
|
1752 const Symbol* signature,
|
mgronlun@34666
|
1753 bool skipping_overpass,
|
mgronlun@34666
|
1754 bool skipping_static,
|
mgronlun@34666
|
1755 bool skipping_private) {
|
mgronlun@34666
|
1756 return ((m->signature() == signature) &&
|
mgronlun@34666
|
1757 (!skipping_overpass || !m->is_overpass()) &&
|
mgronlun@34666
|
1758 (!skipping_static || !m->is_static()) &&
|
mgronlun@34666
|
1759 (!skipping_private || !m->is_private()));
|
drchase@28514
|
1760 }
|
drchase@28514
|
1761
|
acorn@20391
|
1762 // Used directly for default_methods to find the index into the
|
acorn@20391
|
1763 // default_vtable_indices, and indirectly by find_method
|
acorn@20391
|
1764 // find_method_index looks in the local methods array to return the index
|
lfoltan@23999
|
1765 // of the matching name/signature. If, overpass methods are being ignored,
|
lfoltan@23999
|
1766 // the search continues to find a potential non-overpass match. This capability
|
lfoltan@23999
|
1767 // is important during method resolution to prefer a static method, for example,
|
lfoltan@23999
|
1768 // over an overpass method.
|
acorn@32189
|
1769 // There is the possibility in any _method's array to have the same name/signature
|
acorn@32189
|
1770 // for a static method, an overpass method and a local instance method
|
acorn@32189
|
1771 // To correctly catch a given method, the search criteria may need
|
acorn@32189
|
1772 // to explicitly skip the other two. For local instance methods, it
|
acorn@32189
|
1773 // is often necessary to skip private methods
|
mgronlun@34666
|
1774 int InstanceKlass::find_method_index(const Array<Method*>* methods,
|
mgronlun@34666
|
1775 const Symbol* name,
|
mgronlun@34666
|
1776 const Symbol* signature,
|
mgronlun@34666
|
1777 OverpassLookupMode overpass_mode,
|
mgronlun@34666
|
1778 StaticLookupMode static_mode,
|
mgronlun@34666
|
1779 PrivateLookupMode private_mode) {
|
mgronlun@34666
|
1780 const bool skipping_overpass = (overpass_mode == skip_overpass);
|
mgronlun@34666
|
1781 const bool skipping_static = (static_mode == skip_static);
|
mgronlun@34666
|
1782 const bool skipping_private = (private_mode == skip_private);
|
iklam@56936
|
1783 const int hit = quick_search(methods, name);
|
kamg@14385
|
1784 if (hit != -1) {
|
mgronlun@34666
|
1785 const Method* const m = methods->at(hit);
|
drchase@28514
|
1786
|
kamg@14385
|
1787 // Do linear search to find matching signature. First, quick check
|
lfoltan@23999
|
1788 // for common case, ignoring overpasses if requested.
|
mgronlun@34666
|
1789 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
|
dholmes@50735
|
1790 return hit;
|
mgronlun@34666
|
1791 }
|
lfoltan@23999
|
1792
|
kamg@14385
|
1793 // search downwards through overloaded methods
|
kamg@14385
|
1794 int i;
|
kamg@14385
|
1795 for (i = hit - 1; i >= 0; --i) {
|
mgronlun@34666
|
1796 const Method* const m = methods->at(i);
|
kamg@14385
|
1797 assert(m->is_method(), "must be method");
|
mgronlun@34666
|
1798 if (m->name() != name) {
|
mgronlun@34666
|
1799 break;
|
mgronlun@34666
|
1800 }
|
mgronlun@34666
|
1801 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
|
mgronlun@34666
|
1802 return i;
|
mgronlun@34666
|
1803 }
|
kamg@14385
|
1804 }
|
kamg@14385
|
1805 // search upwards
|
kamg@14385
|
1806 for (i = hit + 1; i < methods->length(); ++i) {
|
mgronlun@34666
|
1807 const Method* const m = methods->at(i);
|
kamg@14385
|
1808 assert(m->is_method(), "must be method");
|
mgronlun@34666
|
1809 if (m->name() != name) {
|
mgronlun@34666
|
1810 break;
|
mgronlun@34666
|
1811 }
|
mgronlun@34666
|
1812 if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) {
|
mgronlun@34666
|
1813 return i;
|
mgronlun@34666
|
1814 }
|
kamg@14385
|
1815 }
|
kamg@14385
|
1816 // not found
|
duke@1
|
1817 #ifdef ASSERT
|
mgronlun@34666
|
1818 const int index = (skipping_overpass || skipping_static || skipping_private) ? -1 :
|
mgronlun@34666
|
1819 linear_search(methods, name, signature);
|
mgronlun@34666
|
1820 assert(-1 == index, "binary search should have found entry %d", index);
|
duke@1
|
1821 #endif
|
kamg@14385
|
1822 }
|
acorn@20391
|
1823 return -1;
|
duke@1
|
1824 }
|
mgronlun@34666
|
1825
|
mgronlun@34666
|
1826 int InstanceKlass::find_method_by_name(const Symbol* name, int* end) const {
|
kamg@14385
|
1827 return find_method_by_name(methods(), name, end);
|
kamg@14385
|
1828 }
|
kamg@14385
|
1829
|
mgronlun@34666
|
1830 int InstanceKlass::find_method_by_name(const Array<Method*>* methods,
|
mgronlun@34666
|
1831 const Symbol* name,
|
mgronlun@34666
|
1832 int* end_ptr) {
|
kamg@14385
|
1833 assert(end_ptr != NULL, "just checking");
|
iklam@56936
|
1834 int start = quick_search(methods, name);
|
kamg@14385
|
1835 int end = start + 1;
|
kamg@14385
|
1836 if (start != -1) {
|
kamg@14385
|
1837 while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start;
|
kamg@14385
|
1838 while (end < methods->length() && (methods->at(end))->name() == name) ++end;
|
kamg@14385
|
1839 *end_ptr = end;
|
kamg@14385
|
1840 return start;
|
kamg@14385
|
1841 }
|
kamg@14385
|
1842 return -1;
|
kamg@14385
|
1843 }
|
kamg@14385
|
1844
|
hseigel@22232
|
1845 // uncached_lookup_method searches both the local class methods array and all
|
dholmes@50735
|
1846 // superclasses methods arrays, skipping any overpass methods in superclasses,
|
dholmes@50735
|
1847 // and possibly skipping private methods.
|
mgronlun@34666
|
1848 Method* InstanceKlass::uncached_lookup_method(const Symbol* name,
|
mgronlun@34666
|
1849 const Symbol* signature,
|
dholmes@50735
|
1850 OverpassLookupMode overpass_mode,
|
dholmes@50735
|
1851 PrivateLookupMode private_mode) const {
|
lfoltan@28731
|
1852 OverpassLookupMode overpass_local_mode = overpass_mode;
|
mgronlun@34666
|
1853 const Klass* klass = this;
|
duke@1
|
1854 while (klass != NULL) {
|
mgronlun@34666
|
1855 Method* const method = InstanceKlass::cast(klass)->find_method_impl(name,
|
mgronlun@34666
|
1856 signature,
|
mgronlun@34666
|
1857 overpass_local_mode,
|
mgronlun@34666
|
1858 find_static,
|
dholmes@50735
|
1859 private_mode);
|
lfoltan@23999
|
1860 if (method != NULL) {
|
hseigel@22232
|
1861 return method;
|
hseigel@22232
|
1862 }
|
coleenp@33602
|
1863 klass = klass->super();
|
lfoltan@28731
|
1864 overpass_local_mode = skip_overpass; // Always ignore overpass methods in superclasses
|
duke@1
|
1865 }
|
duke@1
|
1866 return NULL;
|
duke@1
|
1867 }
|
duke@1
|
1868
|
dsamersoff@24828
|
1869 #ifdef ASSERT
|
dsamersoff@24828
|
1870 // search through class hierarchy and return true if this class or
|
dsamersoff@24828
|
1871 // one of the superclasses was redefined
|
mgronlun@34666
|
1872 bool InstanceKlass::has_redefined_this_or_super() const {
|
mgronlun@34666
|
1873 const Klass* klass = this;
|
dsamersoff@24828
|
1874 while (klass != NULL) {
|
coleenp@33602
|
1875 if (InstanceKlass::cast(klass)->has_been_redefined()) {
|
dsamersoff@24828
|
1876 return true;
|
dsamersoff@24828
|
1877 }
|
coleenp@33602
|
1878 klass = klass->super();
|
dsamersoff@24828
|
1879 }
|
dsamersoff@24828
|
1880 return false;
|
dsamersoff@24828
|
1881 }
|
dsamersoff@24828
|
1882 #endif
|
dsamersoff@24828
|
1883
|
acorn@20391
|
1884 // lookup a method in the default methods list then in all transitive interfaces
|
acorn@20391
|
1885 // Do NOT return private or static methods
|
acorn@20391
|
1886 Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name,
|
acorn@20391
|
1887 Symbol* signature) const {
|
acorn@20396
|
1888 Method* m = NULL;
|
acorn@20391
|
1889 if (default_methods() != NULL) {
|
acorn@20391
|
1890 m = find_method(default_methods(), name, signature);
|
acorn@20391
|
1891 }
|
acorn@20391
|
1892 // Look up interfaces
|
acorn@20391
|
1893 if (m == NULL) {
|
lfoltan@28731
|
1894 m = lookup_method_in_all_interfaces(name, signature, find_defaults);
|
acorn@20391
|
1895 }
|
acorn@20391
|
1896 return m;
|
acorn@20391
|
1897 }
|
acorn@20391
|
1898
|
duke@1
|
1899 // lookup a method in all the interfaces that this class implements
|
acorn@20284
|
1900 // Do NOT return private or static methods, new in JDK8 which are not externally visible
|
acorn@20284
|
1901 // They should only be found in the initial InterfaceMethodRef
|
coleenp@13728
|
1902 Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name,
|
hseigel@22232
|
1903 Symbol* signature,
|
lfoltan@28731
|
1904 DefaultsLookupMode defaults_mode) const {
|
iklam@51329
|
1905 Array<InstanceKlass*>* all_ifs = transitive_interfaces();
|
duke@1
|
1906 int num_ifs = all_ifs->length();
|
coleenp@13728
|
1907 InstanceKlass *ik = NULL;
|
duke@1
|
1908 for (int i = 0; i < num_ifs; i++) {
|
iklam@51329
|
1909 ik = all_ifs->at(i);
|
coleenp@13728
|
1910 Method* m = ik->lookup_method(name, signature);
|
hseigel@22232
|
1911 if (m != NULL && m->is_public() && !m->is_static() &&
|
lfoltan@28731
|
1912 ((defaults_mode != skip_defaults) || !m->is_default_method())) {
|
duke@1
|
1913 return m;
|
duke@1
|
1914 }
|
duke@1
|
1915 }
|
duke@1
|
1916 return NULL;
|
duke@1
|
1917 }
|
duke@1
|
1918
|
duke@1
|
1919 /* jni_id_for_impl for jfieldIds only */
|
hseigel@46341
|
1920 JNIid* InstanceKlass::jni_id_for_impl(int offset) {
|
duke@1
|
1921 MutexLocker ml(JfieldIdCreation_lock);
|
duke@1
|
1922 // Retry lookup after we got the lock
|
hseigel@46341
|
1923 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
|
duke@1
|
1924 if (probe == NULL) {
|
duke@1
|
1925 // Slow case, allocate new static field identifier
|
hseigel@46341
|
1926 probe = new JNIid(this, offset, jni_ids());
|
hseigel@46341
|
1927 set_jni_ids(probe);
|
duke@1
|
1928 }
|
duke@1
|
1929 return probe;
|
duke@1
|
1930 }
|
duke@1
|
1931
|
duke@1
|
1932
|
duke@1
|
1933 /* jni_id_for for jfieldIds only */
|
coleenp@13728
|
1934 JNIid* InstanceKlass::jni_id_for(int offset) {
|
duke@1
|
1935 JNIid* probe = jni_ids() == NULL ? NULL : jni_ids()->find(offset);
|
duke@1
|
1936 if (probe == NULL) {
|
hseigel@46341
|
1937 probe = jni_id_for_impl(offset);
|
duke@1
|
1938 }
|
duke@1
|
1939 return probe;
|
duke@1
|
1940 }
|
duke@1
|
1941
|
mgronlun@34666
|
1942 u2 InstanceKlass::enclosing_method_data(int offset) const {
|
mgronlun@34666
|
1943 const Array<jushort>* const inner_class_list = inner_classes();
|
jiangli@12231
|
1944 if (inner_class_list == NULL) {
|
jiangli@12231
|
1945 return 0;
|
jiangli@12231
|
1946 }
|
mgronlun@34666
|
1947 const int length = inner_class_list->length();
|
jiangli@12231
|
1948 if (length % inner_class_next_offset == 0) {
|
jiangli@12231
|
1949 return 0;
|
jiangli@12231
|
1950 }
|
mgronlun@34666
|
1951 const int index = length - enclosing_method_attribute_size;
|
mgronlun@34666
|
1952 assert(offset < enclosing_method_attribute_size, "invalid offset");
|
mgronlun@34666
|
1953 return inner_class_list->at(index + offset);
|
jiangli@12231
|
1954 }
|
jiangli@12231
|
1955
|
coleenp@13728
|
1956 void InstanceKlass::set_enclosing_method_indices(u2 class_index,
|
jiangli@12231
|
1957 u2 method_index) {
|
coleenp@13728
|
1958 Array<jushort>* inner_class_list = inner_classes();
|
jiangli@12231
|
1959 assert (inner_class_list != NULL, "_inner_classes list is not set up");
|
jiangli@12231
|
1960 int length = inner_class_list->length();
|
jiangli@12231
|
1961 if (length % inner_class_next_offset == enclosing_method_attribute_size) {
|
jiangli@12231
|
1962 int index = length - enclosing_method_attribute_size;
|
coleenp@13728
|
1963 inner_class_list->at_put(
|
jiangli@12231
|
1964 index + enclosing_method_class_index_offset, class_index);
|
coleenp@13728
|
1965 inner_class_list->at_put(
|
jiangli@12231
|
1966 index + enclosing_method_method_index_offset, method_index);
|
jiangli@12231
|
1967 }
|
jiangli@12231
|
1968 }
|
duke@1
|
1969
|
duke@1
|
1970 // Lookup or create a jmethodID.
|
dcubed@3824
|
1971 // This code is called by the VMThread and JavaThreads so the
|
dcubed@3824
|
1972 // locking has to be done very carefully to avoid deadlocks
|
dcubed@3824
|
1973 // and/or other cache consistency problems.
|
dcubed@3824
|
1974 //
|
hseigel@46341
|
1975 jmethodID InstanceKlass::get_jmethod_id(const methodHandle& method_h) {
|
duke@1
|
1976 size_t idnum = (size_t)method_h->method_idnum();
|
hseigel@46341
|
1977 jmethodID* jmeths = methods_jmethod_ids_acquire();
|
duke@1
|
1978 size_t length = 0;
|
duke@1
|
1979 jmethodID id = NULL;
|
dcubed@3824
|
1980
|
dcubed@3824
|
1981 // We use a double-check locking idiom here because this cache is
|
dcubed@3824
|
1982 // performance sensitive. In the normal system, this cache only
|
dcubed@3824
|
1983 // transitions from NULL to non-NULL which is safe because we use
|
dcubed@3824
|
1984 // release_set_methods_jmethod_ids() to advertise the new cache.
|
dcubed@3824
|
1985 // A partially constructed cache should never be seen by a racing
|
coleenp@47634
|
1986 // thread. We also use release_store() to save a new jmethodID
|
dcubed@3824
|
1987 // in the cache so a partially constructed jmethodID should never be
|
dcubed@3824
|
1988 // seen either. Cache reads of existing jmethodIDs proceed without a
|
dcubed@3824
|
1989 // lock, but cache writes of a new jmethodID requires uniqueness and
|
dcubed@3824
|
1990 // creation of the cache itself requires no leaks so a lock is
|
dcubed@3824
|
1991 // generally acquired in those two cases.
|
dcubed@3824
|
1992 //
|
dcubed@3824
|
1993 // If the RedefineClasses() API has been used, then this cache can
|
dcubed@3824
|
1994 // grow and we'll have transitions from non-NULL to bigger non-NULL.
|
dcubed@3824
|
1995 // Cache creation requires no leaks and we require safety between all
|
dcubed@3824
|
1996 // cache accesses and freeing of the old cache so a lock is generally
|
dcubed@3824
|
1997 // acquired when the RedefineClasses() API has been used.
|
duke@1
|
1998
|
dcubed@3824
|
1999 if (jmeths != NULL) {
|
dcubed@3824
|
2000 // the cache already exists
|
hseigel@46341
|
2001 if (!idnum_can_increment()) {
|
dcubed@3824
|
2002 // the cache can't grow so we can just get the current values
|
dcubed@3824
|
2003 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
|
dcubed@3824
|
2004 } else {
|
dcubed@3824
|
2005 // cache can grow so we have to be more careful
|
dcubed@3824
|
2006 if (Threads::number_of_threads() == 0 ||
|
dcubed@3824
|
2007 SafepointSynchronize::is_at_safepoint()) {
|
dcubed@3824
|
2008 // we're single threaded or at a safepoint - no locking needed
|
dcubed@3824
|
2009 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
|
dcubed@3824
|
2010 } else {
|
coleenp@57171
|
2011 MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag);
|
dcubed@3824
|
2012 get_jmethod_id_length_value(jmeths, idnum, &length, &id);
|
dcubed@3824
|
2013 }
|
dcubed@3824
|
2014 }
|
dcubed@3824
|
2015 }
|
dcubed@3824
|
2016 // implied else:
|
dcubed@3824
|
2017 // we need to allocate a cache so default length and id values are good
|
duke@1
|
2018
|
dcubed@3824
|
2019 if (jmeths == NULL || // no cache yet
|
dcubed@3824
|
2020 length <= idnum || // cache is too short
|
dcubed@3824
|
2021 id == NULL) { // cache doesn't contain entry
|
dcubed@3824
|
2022
|
dcubed@3824
|
2023 // This function can be called by the VMThread so we have to do all
|
dcubed@3824
|
2024 // things that might block on a safepoint before grabbing the lock.
|
dcubed@3824
|
2025 // Otherwise, we can deadlock with the VMThread or have a cache
|
dcubed@3824
|
2026 // consistency issue. These vars keep track of what we might have
|
dcubed@3824
|
2027 // to free after the lock is dropped.
|
dcubed@3824
|
2028 jmethodID to_dealloc_id = NULL;
|
dcubed@3824
|
2029 jmethodID* to_dealloc_jmeths = NULL;
|
dcubed@3824
|
2030
|
dcubed@3824
|
2031 // may not allocate new_jmeths or use it if we allocate it
|
duke@1
|
2032 jmethodID* new_jmeths = NULL;
|
duke@1
|
2033 if (length <= idnum) {
|
dcubed@3824
|
2034 // allocate a new cache that might be used
|
hseigel@46341
|
2035 size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count());
|
zgu@13195
|
2036 new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass);
|
duke@1
|
2037 memset(new_jmeths, 0, (size+1)*sizeof(jmethodID));
|
dcubed@3824
|
2038 // cache size is stored in element[0], other elements offset by one
|
dcubed@3824
|
2039 new_jmeths[0] = (jmethodID)size;
|
duke@1
|
2040 }
|
duke@1
|
2041
|
dcubed@3824
|
2042 // allocate a new jmethodID that might be used
|
duke@1
|
2043 jmethodID new_id = NULL;
|
duke@1
|
2044 if (method_h->is_old() && !method_h->is_obsolete()) {
|
duke@1
|
2045 // The method passed in is old (but not obsolete), we need to use the current version
|
hseigel@46341
|
2046 Method* current_method = method_with_idnum((int)idnum);
|
duke@1
|
2047 assert(current_method != NULL, "old and but not obsolete, so should exist");
|
hseigel@46341
|
2048 new_id = Method::make_jmethod_id(class_loader_data(), current_method);
|
duke@1
|
2049 } else {
|
duke@1
|
2050 // It is the current version of the method or an obsolete method,
|
duke@1
|
2051 // use the version passed in
|
hseigel@46341
|
2052 new_id = Method::make_jmethod_id(class_loader_data(), method_h());
|
duke@1
|
2053 }
|
duke@1
|
2054
|
dcubed@3824
|
2055 if (Threads::number_of_threads() == 0 ||
|
dcubed@3824
|
2056 SafepointSynchronize::is_at_safepoint()) {
|
dcubed@3824
|
2057 // we're single threaded or at a safepoint - no locking needed
|
hseigel@46341
|
2058 id = get_jmethod_id_fetch_or_update(idnum, new_id, new_jmeths,
|
dcubed@3824
|
2059 &to_dealloc_id, &to_dealloc_jmeths);
|
dcubed@222
|
2060 } else {
|
coleenp@57171
|
2061 MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag);
|
hseigel@46341
|
2062 id = get_jmethod_id_fetch_or_update(idnum, new_id, new_jmeths,
|
dcubed@3824
|
2063 &to_dealloc_id, &to_dealloc_jmeths);
|
dcubed@3824
|
2064 }
|
dcubed@3824
|
2065
|
dcubed@3824
|
2066 // The lock has been dropped so we can free resources.
|
dcubed@3824
|
2067 // Free up either the old cache or the new cache if we allocated one.
|
dcubed@3824
|
2068 if (to_dealloc_jmeths != NULL) {
|
dcubed@3824
|
2069 FreeHeap(to_dealloc_jmeths);
|
dcubed@3824
|
2070 }
|
dcubed@3824
|
2071 // free up the new ID since it wasn't needed
|
dcubed@3824
|
2072 if (to_dealloc_id != NULL) {
|
hseigel@46341
|
2073 Method::destroy_jmethod_id(class_loader_data(), to_dealloc_id);
|
dcubed@222
|
2074 }
|
dcubed@222
|
2075 }
|
dcubed@222
|
2076 return id;
|
dcubed@222
|
2077 }
|
duke@1
|
2078
|
jmanson@27478
|
2079 // Figure out how many jmethodIDs haven't been allocated, and make
|
jmanson@27478
|
2080 // sure space for them is pre-allocated. This makes getting all
|
jmanson@27478
|
2081 // method ids much, much faster with classes with more than 8
|
jmanson@27478
|
2082 // methods, and has a *substantial* effect on performance with jvmti
|
jmanson@27478
|
2083 // code that loads all jmethodIDs for all classes.
|
jmanson@27478
|
2084 void InstanceKlass::ensure_space_for_methodids(int start_offset) {
|
jmanson@27478
|
2085 int new_jmeths = 0;
|
jmanson@27478
|
2086 int length = methods()->length();
|
jmanson@27478
|
2087 for (int index = start_offset; index < length; index++) {
|
jmanson@27478
|
2088 Method* m = methods()->at(index);
|
jmanson@27478
|
2089 jmethodID id = m->find_jmethod_id_or_null();
|
jmanson@27478
|
2090 if (id == NULL) {
|
jmanson@27478
|
2091 new_jmeths++;
|
jmanson@27478
|
2092 }
|
jmanson@27478
|
2093 }
|
jmanson@27478
|
2094 if (new_jmeths != 0) {
|
jmanson@27478
|
2095 Method::ensure_jmethod_ids(class_loader_data(), new_jmeths);
|
jmanson@27478
|
2096 }
|
jmanson@27478
|
2097 }
|
dcubed@222
|
2098
|
dcubed@3824
|
2099 // Common code to fetch the jmethodID from the cache or update the
|
dcubed@3824
|
2100 // cache with the new jmethodID. This function should never do anything
|
dcubed@3824
|
2101 // that causes the caller to go to a safepoint or we can deadlock with
|
dcubed@3824
|
2102 // the VMThread or have cache consistency issues.
|
dcubed@3824
|
2103 //
|
coleenp@13728
|
2104 jmethodID InstanceKlass::get_jmethod_id_fetch_or_update(
|
hseigel@46341
|
2105 size_t idnum, jmethodID new_id,
|
dcubed@3824
|
2106 jmethodID* new_jmeths, jmethodID* to_dealloc_id_p,
|
dcubed@3824
|
2107 jmethodID** to_dealloc_jmeths_p) {
|
dcubed@3824
|
2108 assert(new_id != NULL, "sanity check");
|
dcubed@3824
|
2109 assert(to_dealloc_id_p != NULL, "sanity check");
|
dcubed@3824
|
2110 assert(to_dealloc_jmeths_p != NULL, "sanity check");
|
dcubed@3824
|
2111 assert(Threads::number_of_threads() == 0 ||
|
dcubed@3824
|
2112 SafepointSynchronize::is_at_safepoint() ||
|
dcubed@3824
|
2113 JmethodIdCreation_lock->owned_by_self(), "sanity check");
|
dcubed@3824
|
2114
|
dcubed@3824
|
2115 // reacquire the cache - we are locked, single threaded or at a safepoint
|
hseigel@46341
|
2116 jmethodID* jmeths = methods_jmethod_ids_acquire();
|
dcubed@3824
|
2117 jmethodID id = NULL;
|
dcubed@3824
|
2118 size_t length = 0;
|
duke@1
|
2119
|
dcubed@3824
|
2120 if (jmeths == NULL || // no cache yet
|
dcubed@3824
|
2121 (length = (size_t)jmeths[0]) <= idnum) { // cache is too short
|
dcubed@222
|
2122 if (jmeths != NULL) {
|
dcubed@3824
|
2123 // copy any existing entries from the old cache
|
dcubed@222
|
2124 for (size_t index = 0; index < length; index++) {
|
dcubed@222
|
2125 new_jmeths[index+1] = jmeths[index+1];
|
duke@1
|
2126 }
|
dcubed@3824
|
2127 *to_dealloc_jmeths_p = jmeths; // save old cache for later delete
|
duke@1
|
2128 }
|
hseigel@46341
|
2129 release_set_methods_jmethod_ids(jmeths = new_jmeths);
|
dcubed@222
|
2130 } else {
|
dcubed@3824
|
2131 // fetch jmethodID (if any) from the existing cache
|
dcubed@222
|
2132 id = jmeths[idnum+1];
|
dcubed@3824
|
2133 *to_dealloc_jmeths_p = new_jmeths; // save new cache for later delete
|
dcubed@222
|
2134 }
|
dcubed@222
|
2135 if (id == NULL) {
|
dcubed@3824
|
2136 // No matching jmethodID in the existing cache or we have a new
|
dcubed@3824
|
2137 // cache or we just grew the cache. This cache write is done here
|
dcubed@3824
|
2138 // by the first thread to win the foot race because a jmethodID
|
dcubed@3824
|
2139 // needs to be unique once it is generally available.
|
dcubed@222
|
2140 id = new_id;
|
dcubed@3824
|
2141
|
dcubed@3824
|
2142 // The jmethodID cache can be read while unlocked so we have to
|
dcubed@3824
|
2143 // make sure the new jmethodID is complete before installing it
|
dcubed@3824
|
2144 // in the cache.
|
stefank@57083
|
2145 Atomic::release_store(&jmeths[idnum+1], id);
|
dcubed@222
|
2146 } else {
|
dcubed@3824
|
2147 *to_dealloc_id_p = new_id; // save new id for later delete
|
duke@1
|
2148 }
|
duke@1
|
2149 return id;
|
duke@1
|
2150 }
|
duke@1
|
2151
|
duke@1
|
2152
|
dcubed@3824
|
2153 // Common code to get the jmethodID cache length and the jmethodID
|
dcubed@3824
|
2154 // value at index idnum if there is one.
|
dcubed@3824
|
2155 //
|
coleenp@13728
|
2156 void InstanceKlass::get_jmethod_id_length_value(jmethodID* cache,
|
dcubed@3824
|
2157 size_t idnum, size_t *length_p, jmethodID* id_p) {
|
dcubed@3824
|
2158 assert(cache != NULL, "sanity check");
|
dcubed@3824
|
2159 assert(length_p != NULL, "sanity check");
|
dcubed@3824
|
2160 assert(id_p != NULL, "sanity check");
|
dcubed@3824
|
2161
|
dcubed@3824
|
2162 // cache size is stored in element[0], other elements offset by one
|
dcubed@3824
|
2163 *length_p = (size_t)cache[0];
|
dcubed@3824
|
2164 if (*length_p <= idnum) { // cache is too short
|
dcubed@3824
|
2165 *id_p = NULL;
|
dcubed@3824
|
2166 } else {
|
dcubed@3824
|
2167 *id_p = cache[idnum+1]; // fetch jmethodID (if any)
|
dcubed@3824
|
2168 }
|
dcubed@3824
|
2169 }
|
dcubed@3824
|
2170
|
dcubed@3824
|
2171
|
duke@1
|
2172 // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles
|
coleenp@13728
|
2173 jmethodID InstanceKlass::jmethod_id_or_null(Method* method) {
|
duke@1
|
2174 size_t idnum = (size_t)method->method_idnum();
|
duke@1
|
2175 jmethodID* jmeths = methods_jmethod_ids_acquire();
|
duke@1
|
2176 size_t length; // length assigned as debugging crumb
|
duke@1
|
2177 jmethodID id = NULL;
|
dcubed@3824
|
2178 if (jmeths != NULL && // If there is a cache
|
duke@1
|
2179 (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough,
|
duke@1
|
2180 id = jmeths[idnum+1]; // Look up the id (may be NULL)
|
duke@1
|
2181 }
|
duke@1
|
2182 return id;
|
duke@1
|
2183 }
|
duke@1
|
2184
|
vlivanov@34195
|
2185 inline DependencyContext InstanceKlass::dependencies() {
|
eosterlund@52781
|
2186 DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned);
|
vlivanov@34195
|
2187 return dep_context;
|
vlivanov@31037
|
2188 }
|
vlivanov@31037
|
2189
|
vlivanov@36300
|
2190 int InstanceKlass::mark_dependent_nmethods(KlassDepChange& changes) {
|
vlivanov@34195
|
2191 return dependencies().mark_dependent_nmethods(changes);
|
stefank@25492
|
2192 }
|
duke@1
|
2193
|
coleenp@13728
|
2194 void InstanceKlass::add_dependent_nmethod(nmethod* nm) {
|
vlivanov@34195
|
2195 dependencies().add_dependent_nmethod(nm);
|
duke@1
|
2196 }
|
duke@1
|
2197
|
eosterlund@52781
|
2198 void InstanceKlass::remove_dependent_nmethod(nmethod* nm) {
|
eosterlund@52781
|
2199 dependencies().remove_dependent_nmethod(nm);
|
eosterlund@52781
|
2200 }
|
eosterlund@52781
|
2201
|
eosterlund@52781
|
2202 void InstanceKlass::clean_dependency_context() {
|
eosterlund@52781
|
2203 dependencies().clean_unloading_dependents();
|
duke@1
|
2204 }
|
duke@1
|
2205
|
duke@1
|
2206 #ifndef PRODUCT
|
coleenp@13728
|
2207 void InstanceKlass::print_dependent_nmethods(bool verbose) {
|
vlivanov@34195
|
2208 dependencies().print_dependent_nmethods(verbose);
|
duke@1
|
2209 }
|
duke@1
|
2210
|
coleenp@13728
|
2211 bool InstanceKlass::is_dependent_nmethod(nmethod* nm) {
|
vlivanov@34195
|
2212 return dependencies().is_dependent_nmethod(nm);
|
duke@1
|
2213 }
|
duke@1
|
2214 #endif //PRODUCT
|
duke@1
|
2215
|
coleenp@49821
|
2216 void InstanceKlass::clean_weak_instanceklass_links() {
|
coleenp@49821
|
2217 clean_implementors_list();
|
coleenp@49821
|
2218 clean_method_data();
|
stefank@33576
|
2219 }
|
stefank@33576
|
2220
|
coleenp@49821
|
2221 void InstanceKlass::clean_implementors_list() {
|
coleenp@49821
|
2222 assert(is_loader_alive(), "this klass should be live");
|
jiangli@12369
|
2223 if (is_interface()) {
|
eosterlund@52784
|
2224 assert (ClassUnloading, "only called for ClassUnloading");
|
eosterlund@52784
|
2225 for (;;) {
|
eosterlund@52784
|
2226 // Use load_acquire due to competing with inserts
|
stefank@57083
|
2227 Klass* impl = Atomic::load_acquire(adr_implementor());
|
eosterlund@52784
|
2228 if (impl != NULL && !impl->is_loader_alive()) {
|
eosterlund@52784
|
2229 // NULL this field, might be an unloaded klass or NULL
|
eosterlund@52784
|
2230 Klass* volatile* klass = adr_implementor();
|
stefank@57088
|
2231 if (Atomic::cmpxchg(klass, impl, (Klass*)NULL) == impl) {
|
eosterlund@52784
|
2232 // Successfully unlinking implementor.
|
eosterlund@52784
|
2233 if (log_is_enabled(Trace, class, unload)) {
|
eosterlund@52784
|
2234 ResourceMark rm;
|
eosterlund@52784
|
2235 log_trace(class, unload)("unlinking class (implementor): %s", impl->external_name());
|
coleenp@52356
|
2236 }
|
eosterlund@52784
|
2237 return;
|
coleenp@52356
|
2238 }
|
eosterlund@52784
|
2239 } else {
|
eosterlund@52784
|
2240 return;
|
coleenp@52356
|
2241 }
|
coleenp@13728
|
2242 }
|
coleenp@13728
|
2243 }
|
coleenp@13728
|
2244 }
|
coleenp@13728
|
2245
|
coleenp@49821
|
2246 void InstanceKlass::clean_method_data() {
|
coleenp@13728
|
2247 for (int m = 0; m < methods()->length(); m++) {
|
coleenp@13728
|
2248 MethodData* mdo = methods()->at(m)->method_data();
|
coleenp@13728
|
2249 if (mdo != NULL) {
|
coleenp@54623
|
2250 MutexLocker ml(SafepointSynchronize::is_at_safepoint() ? NULL : mdo->extra_data_lock());
|
coleenp@49821
|
2251 mdo->clean_method_data(/*always_clean*/false);
|
duke@1
|
2252 }
|
duke@1
|
2253 }
|
coleenp@13728
|
2254 }
|
coleenp@13728
|
2255
|
kvn@42650
|
2256 bool InstanceKlass::supers_have_passed_fingerprint_checks() {
|
kvn@42650
|
2257 if (java_super() != NULL && !java_super()->has_passed_fingerprint_check()) {
|
kvn@42650
|
2258 ResourceMark rm;
|
kvn@42650
|
2259 log_trace(class, fingerprint)("%s : super %s not fingerprinted", external_name(), java_super()->external_name());
|
kvn@42650
|
2260 return false;
|
kvn@42650
|
2261 }
|
kvn@42650
|
2262
|
iklam@51329
|
2263 Array<InstanceKlass*>* local_interfaces = this->local_interfaces();
|
kvn@42650
|
2264 if (local_interfaces != NULL) {
|
kvn@42650
|
2265 int length = local_interfaces->length();
|
kvn@42650
|
2266 for (int i = 0; i < length; i++) {
|
iklam@51329
|
2267 InstanceKlass* intf = local_interfaces->at(i);
|
kvn@42650
|
2268 if (!intf->has_passed_fingerprint_check()) {
|
kvn@42650
|
2269 ResourceMark rm;
|
kvn@42650
|
2270 log_trace(class, fingerprint)("%s : interface %s not fingerprinted", external_name(), intf->external_name());
|
kvn@42650
|
2271 return false;
|
kvn@42650
|
2272 }
|
kvn@42650
|
2273 }
|
kvn@42650
|
2274 }
|
kvn@42650
|
2275
|
kvn@42650
|
2276 return true;
|
kvn@42650
|
2277 }
|
kvn@42650
|
2278
|
lfoltan@51444
|
2279 bool InstanceKlass::should_store_fingerprint(bool is_unsafe_anonymous) {
|
kvn@42650
|
2280 #if INCLUDE_AOT
|
kvn@42650
|
2281 // We store the fingerprint into the InstanceKlass only in the following 2 cases:
|
kvn@46553
|
2282 if (CalculateClassFingerprint) {
|
kvn@42650
|
2283 // (1) We are running AOT to generate a shared library.
|
kvn@42650
|
2284 return true;
|
kvn@42650
|
2285 }
|
ccheung@56468
|
2286 if (Arguments::is_dumping_archive()) {
|
ccheung@54927
|
2287 // (2) We are running -Xshare:dump or -XX:ArchiveClassesAtExit to create a shared archive
|
kvn@42650
|
2288 return true;
|
kvn@42650
|
2289 }
|
lfoltan@51444
|
2290 if (UseAOT && is_unsafe_anonymous) {
|
lfoltan@51444
|
2291 // (3) We are using AOT code from a shared library and see an unsafe anonymous class
|
dlong@47668
|
2292 return true;
|
dlong@47668
|
2293 }
|
kvn@42650
|
2294 #endif
|
kvn@42650
|
2295
|
kvn@42650
|
2296 // In all other cases we might set the _misc_has_passed_fingerprint_check bit,
|
kvn@42650
|
2297 // but do not store the 64-bit fingerprint to save space.
|
kvn@42650
|
2298 return false;
|
kvn@42650
|
2299 }
|
kvn@42650
|
2300
|
kvn@42650
|
2301 bool InstanceKlass::has_stored_fingerprint() const {
|
kvn@42650
|
2302 #if INCLUDE_AOT
|
kvn@42650
|
2303 return should_store_fingerprint() || is_shared();
|
kvn@42650
|
2304 #else
|
kvn@42650
|
2305 return false;
|
kvn@42650
|
2306 #endif
|
kvn@42650
|
2307 }
|
kvn@42650
|
2308
|
kvn@42650
|
2309 uint64_t InstanceKlass::get_stored_fingerprint() const {
|
kvn@42650
|
2310 address adr = adr_fingerprint();
|
kvn@42650
|
2311 if (adr != NULL) {
|
kvn@42650
|
2312 return (uint64_t)Bytes::get_native_u8(adr); // adr may not be 64-bit aligned
|
kvn@42650
|
2313 }
|
kvn@42650
|
2314 return 0;
|
kvn@42650
|
2315 }
|
kvn@42650
|
2316
|
kvn@42650
|
2317 void InstanceKlass::store_fingerprint(uint64_t fingerprint) {
|
kvn@42650
|
2318 address adr = adr_fingerprint();
|
kvn@42650
|
2319 if (adr != NULL) {
|
kvn@42650
|
2320 Bytes::put_native_u8(adr, (u8)fingerprint); // adr may not be 64-bit aligned
|
kvn@42650
|
2321
|
kvn@42650
|
2322 ResourceMark rm;
|
kvn@42650
|
2323 log_trace(class, fingerprint)("stored as " PTR64_FORMAT " for class %s", fingerprint, external_name());
|
kvn@42650
|
2324 }
|
kvn@42650
|
2325 }
|
coleenp@13728
|
2326
|
iklam@46746
|
2327 void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) {
|
iklam@46746
|
2328 Klass::metaspace_pointers_do(it);
|
iklam@46746
|
2329
|
iklam@46746
|
2330 if (log_is_enabled(Trace, cds)) {
|
iklam@46746
|
2331 ResourceMark rm;
|
iklam@46746
|
2332 log_trace(cds)("Iter(InstanceKlass): %p (%s)", this, external_name());
|
iklam@46746
|
2333 }
|
iklam@46746
|
2334
|
iklam@46746
|
2335 it->push(&_annotations);
|
iklam@46746
|
2336 it->push((Klass**)&_array_klasses);
|
iklam@46746
|
2337 it->push(&_constants);
|
iklam@46746
|
2338 it->push(&_inner_classes);
|
iklam@46746
|
2339 it->push(&_array_name);
|
iklam@46746
|
2340 #if INCLUDE_JVMTI
|
iklam@46746
|
2341 it->push(&_previous_versions);
|
iklam@46746
|
2342 #endif
|
iklam@46746
|
2343 it->push(&_methods);
|
iklam@46746
|
2344 it->push(&_default_methods);
|
iklam@46746
|
2345 it->push(&_local_interfaces);
|
iklam@46746
|
2346 it->push(&_transitive_interfaces);
|
iklam@46746
|
2347 it->push(&_method_ordering);
|
iklam@46746
|
2348 it->push(&_default_vtable_indices);
|
iklam@46746
|
2349 it->push(&_fields);
|
iklam@46746
|
2350
|
iklam@46746
|
2351 if (itable_length() > 0) {
|
iklam@46746
|
2352 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
|
iklam@46746
|
2353 int method_table_offset_in_words = ioe->offset()/wordSize;
|
iklam@46746
|
2354 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
|
iklam@46746
|
2355 / itableOffsetEntry::size();
|
iklam@46746
|
2356
|
iklam@46746
|
2357 for (int i = 0; i < nof_interfaces; i ++, ioe ++) {
|
iklam@46746
|
2358 if (ioe->interface_klass() != NULL) {
|
iklam@46746
|
2359 it->push(ioe->interface_klass_addr());
|
iklam@46746
|
2360 itableMethodEntry* ime = ioe->first_method_entry(this);
|
iklam@46746
|
2361 int n = klassItable::method_count_for_interface(ioe->interface_klass());
|
iklam@46746
|
2362 for (int index = 0; index < n; index ++) {
|
iklam@46746
|
2363 it->push(ime[index].method_addr());
|
iklam@46746
|
2364 }
|
iklam@46746
|
2365 }
|
iklam@46746
|
2366 }
|
iklam@46746
|
2367 }
|
dholmes@50735
|
2368
|
dholmes@50735
|
2369 it->push(&_nest_members);
|
vromero@57233
|
2370 it->push(&_record_components);
|
iklam@46746
|
2371 }
|
iklam@46746
|
2372
|
coleenp@13728
|
2373 void InstanceKlass::remove_unshareable_info() {
|
coleenp@13728
|
2374 Klass::remove_unshareable_info();
|
coleenp@46464
|
2375
|
ccheung@58266
|
2376 if (SystemDictionaryShared::has_class_failed_verification(this)) {
|
coleenp@46464
|
2377 // Classes are attempted to link during dumping and may fail,
|
coleenp@46464
|
2378 // but these classes are still in the dictionary and class list in CLD.
|
ccheung@58266
|
2379 // If the class has failed verification, there is nothing else to remove.
|
coleenp@46464
|
2380 return;
|
coleenp@46464
|
2381 }
|
coleenp@46464
|
2382
|
jiangli@51962
|
2383 // Reset to the 'allocated' state to prevent any premature accessing to
|
jiangli@51962
|
2384 // a shared class at runtime while the class is still being loaded and
|
jiangli@51962
|
2385 // restored. A class' init_state is set to 'loaded' at runtime when it's
|
jiangli@51962
|
2386 // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()).
|
jiangli@51962
|
2387 _init_state = allocated;
|
jiangli@51962
|
2388
|
coleenp@56445
|
2389 { // Otherwise this needs to take out the Compile_lock.
|
coleenp@56445
|
2390 assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint");
|
coleenp@51379
|
2391 init_implementor();
|
coleenp@51379
|
2392 }
|
coleenp@13728
|
2393
|
coleenp@13728
|
2394 constants()->remove_unshareable_info();
|
coleenp@13728
|
2395
|
coleenp@13728
|
2396 for (int i = 0; i < methods()->length(); i++) {
|
coleenp@13728
|
2397 Method* m = methods()->at(i);
|
coleenp@13728
|
2398 m->remove_unshareable_info();
|
coleenp@13728
|
2399 }
|
iklam@46746
|
2400
|
ccheung@47103
|
2401 // do array classes also.
|
ccheung@47103
|
2402 if (array_klasses() != NULL) {
|
ccheung@47103
|
2403 array_klasses()->remove_unshareable_info();
|
ccheung@47103
|
2404 }
|
ccheung@47103
|
2405
|
ccheung@54927
|
2406 // These are not allocated from metaspace. They are safe to set to NULL.
|
ccheung@54927
|
2407 _source_debug_extension = NULL;
|
ccheung@54927
|
2408 _dep_context = NULL;
|
ccheung@54927
|
2409 _osr_nmethods_head = NULL;
|
iklam@46746
|
2410 #if INCLUDE_JVMTI
|
ccheung@54927
|
2411 _breakpoints = NULL;
|
ccheung@54927
|
2412 _previous_versions = NULL;
|
iklam@53884
|
2413 _cached_class_file = NULL;
|
iklam@56936
|
2414 _jvmti_cached_class_field_map = NULL;
|
iklam@46746
|
2415 #endif
|
ccheung@47103
|
2416
|
dholmes@50735
|
2417 _init_thread = NULL;
|
dholmes@50735
|
2418 _methods_jmethod_ids = NULL;
|
dholmes@50735
|
2419 _jni_ids = NULL;
|
dholmes@50735
|
2420 _oop_map_cache = NULL;
|
dholmes@50735
|
2421 // clear _nest_host to ensure re-load at runtime
|
dholmes@50735
|
2422 _nest_host = NULL;
|
iklam@56936
|
2423 _package_entry = NULL;
|
iklam@56936
|
2424 _dep_context_last_cleaned = 0;
|
duke@1
|
2425 }
|
duke@1
|
2426
|
ccheung@47103
|
2427 void InstanceKlass::remove_java_mirror() {
|
ccheung@47103
|
2428 Klass::remove_java_mirror();
|
ccheung@47103
|
2429
|
ccheung@47103
|
2430 // do array classes also.
|
ccheung@47103
|
2431 if (array_klasses() != NULL) {
|
ccheung@47103
|
2432 array_klasses()->remove_java_mirror();
|
ccheung@47103
|
2433 }
|
duke@1
|
2434 }
|
duke@1
|
2435
|
ccheung@58673
|
2436 void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain,
|
ccheung@58673
|
2437 PackageEntry* pkg_entry, TRAPS) {
|
jiangli@51962
|
2438 // SystemDictionary::add_to_hierarchy() sets the init_state to loaded
|
jiangli@51962
|
2439 // before the InstanceKlass is added to the SystemDictionary. Make
|
jiangli@51962
|
2440 // sure the current state is <loaded.
|
jiangli@51962
|
2441 assert(!is_loaded(), "invalid init state");
|
ccheung@58673
|
2442 set_package(loader_data, pkg_entry, CHECK);
|
iklam@26135
|
2443 Klass::restore_unshareable_info(loader_data, protection_domain, CHECK);
|
coleenp@13728
|
2444
|
coleenp@46329
|
2445 Array<Method*>* methods = this->methods();
|
coleenp@13728
|
2446 int num_methods = methods->length();
|
redestad@53384
|
2447 for (int index = 0; index < num_methods; ++index) {
|
redestad@53384
|
2448 methods->at(index)->restore_unshareable_info(CHECK);
|
coleenp@13728
|
2449 }
|
coleenp@13728
|
2450 if (JvmtiExport::has_redefined_a_class()) {
|
coleenp@13728
|
2451 // Reinitialize vtable because RedefineClasses may have changed some
|
coleenp@13728
|
2452 // entries in this vtable for super classes so the CDS vtable might
|
coleenp@13728
|
2453 // point to old or obsolete entries. RedefineClasses doesn't fix up
|
coleenp@13728
|
2454 // vtables in the shared system dictionary, only the main one.
|
coleenp@13728
|
2455 // It also redefines the itable too so fix that too.
|
iklam@46408
|
2456 vtable().initialize_vtable(false, CHECK);
|
iklam@46408
|
2457 itable().initialize_itable(false, CHECK);
|
coleenp@13728
|
2458 }
|
coleenp@13728
|
2459
|
coleenp@13728
|
2460 // restore constant pool resolved references
|
coleenp@46329
|
2461 constants()->restore_unshareable_info(CHECK);
|
coleenp@46329
|
2462
|
ccheung@47103
|
2463 if (array_klasses() != NULL) {
|
ccheung@47103
|
2464 // Array classes have null protection domain.
|
ccheung@47103
|
2465 // --> see ArrayKlass::complete_create_array_klass()
|
ccheung@58673
|
2466 ArrayKlass::cast(array_klasses())->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK);
|
ccheung@47103
|
2467 }
|
coleenp@56724
|
2468
|
coleenp@56724
|
2469 // Initialize current biased locking state.
|
coleenp@56724
|
2470 if (UseBiasedLocking && BiasedLocking::enabled()) {
|
coleenp@56724
|
2471 set_prototype_header(markWord::biased_locking_prototype());
|
coleenp@56724
|
2472 }
|
coleenp@13728
|
2473 }
|
coleenp@13728
|
2474
|
iklam@58269
|
2475 void InstanceKlass::set_shared_class_loader_type(s2 loader_type) {
|
iklam@54347
|
2476 switch (loader_type) {
|
iklam@54347
|
2477 case ClassLoader::BOOT_LOADER:
|
iklam@54347
|
2478 _misc_flags |= _misc_is_shared_boot_class;
|
iklam@54347
|
2479 break;
|
iklam@54347
|
2480 case ClassLoader::PLATFORM_LOADER:
|
iklam@54347
|
2481 _misc_flags |= _misc_is_shared_platform_class;
|
iklam@54347
|
2482 break;
|
iklam@54347
|
2483 case ClassLoader::APP_LOADER:
|
iklam@54347
|
2484 _misc_flags |= _misc_is_shared_app_class;
|
iklam@54347
|
2485 break;
|
iklam@54347
|
2486 default:
|
iklam@54347
|
2487 ShouldNotReachHere();
|
iklam@54347
|
2488 break;
|
iklam@54347
|
2489 }
|
iklam@54347
|
2490 }
|
iklam@54347
|
2491
|
cjplummer@38059
|
2492 #if INCLUDE_JVMTI
|
coleenp@13728
|
2493 static void clear_all_breakpoints(Method* m) {
|
duke@1
|
2494 m->clear_all_breakpoints();
|
duke@1
|
2495 }
|
cjplummer@38059
|
2496 #endif
|
coleenp@17075
|
2497
|
coleenp@51887
|
2498 void InstanceKlass::unload_class(InstanceKlass* ik) {
|
coleenp@51887
|
2499 // Release dependencies.
|
coleenp@51887
|
2500 ik->dependencies().remove_all_dependents();
|
coleenp@51887
|
2501
|
coleenp@17075
|
2502 // notify the debugger
|
coleenp@17075
|
2503 if (JvmtiExport::should_post_class_unload()) {
|
coleenp@17075
|
2504 JvmtiExport::post_class_unload(ik);
|
coleenp@17075
|
2505 }
|
coleenp@17075
|
2506
|
coleenp@17075
|
2507 // notify ClassLoadingService of class unload
|
coleenp@17075
|
2508 ClassLoadingService::notify_class_unloaded(ik);
|
hseigel@51543
|
2509
|
ccheung@56468
|
2510 if (Arguments::is_dumping_archive()) {
|
ccheung@54927
|
2511 SystemDictionaryShared::remove_dumptime_info(ik);
|
ccheung@54927
|
2512 }
|
ccheung@54927
|
2513
|
coleenp@53738
|
2514 if (log_is_enabled(Info, class, unload)) {
|
coleenp@53738
|
2515 ResourceMark rm;
|
coleenp@53738
|
2516 log_info(class, unload)("unloading class %s " INTPTR_FORMAT, ik->external_name(), p2i(ik));
|
coleenp@53738
|
2517 }
|
coleenp@53738
|
2518
|
coleenp@53738
|
2519 Events::log_class_unloading(Thread::current(), ik);
|
coleenp@53738
|
2520
|
hseigel@51543
|
2521 #if INCLUDE_JFR
|
hseigel@51543
|
2522 assert(ik != NULL, "invariant");
|
hseigel@51543
|
2523 EventClassUnload event;
|
hseigel@51543
|
2524 event.set_unloadedClass(ik);
|
hseigel@51543
|
2525 event.set_definingClassLoader(ik->class_loader_data());
|
hseigel@51543
|
2526 event.commit();
|
hseigel@51543
|
2527 #endif
|
coleenp@17075
|
2528 }
|
coleenp@17075
|
2529
|
coleenp@56646
|
2530 static void method_release_C_heap_structures(Method* m) {
|
coleenp@56646
|
2531 m->release_C_heap_structures();
|
coleenp@56646
|
2532 }
|
coleenp@56646
|
2533
|
coleenp@17075
|
2534 void InstanceKlass::release_C_heap_structures(InstanceKlass* ik) {
|
coleenp@17075
|
2535 // Clean up C heap
|
coleenp@17075
|
2536 ik->release_C_heap_structures();
|
coleenp@17075
|
2537 ik->constants()->release_C_heap_structures();
|
coleenp@56646
|
2538
|
coleenp@56646
|
2539 // Deallocate and call destructors for MDO mutexes
|
coleenp@56646
|
2540 ik->methods_do(method_release_C_heap_structures);
|
coleenp@56646
|
2541
|
coleenp@17075
|
2542 }
|
coleenp@17075
|
2543
|
coleenp@13728
|
2544 void InstanceKlass::release_C_heap_structures() {
|
coleenp@17075
|
2545 // Can't release the constant pool here because the constant pool can be
|
coleenp@17075
|
2546 // deallocated separately from the InstanceKlass for default methods and
|
coleenp@17075
|
2547 // redefine classes.
|
coleenp@17075
|
2548
|
duke@1
|
2549 // Deallocate oop map cache
|
duke@1
|
2550 if (_oop_map_cache != NULL) {
|
duke@1
|
2551 delete _oop_map_cache;
|
duke@1
|
2552 _oop_map_cache = NULL;
|
duke@1
|
2553 }
|
duke@1
|
2554
|
duke@1
|
2555 // Deallocate JNI identifiers for jfieldIDs
|
duke@1
|
2556 JNIid::deallocate(jni_ids());
|
duke@1
|
2557 set_jni_ids(NULL);
|
duke@1
|
2558
|
duke@1
|
2559 jmethodID* jmeths = methods_jmethod_ids_acquire();
|
duke@1
|
2560 if (jmeths != (jmethodID*)NULL) {
|
duke@1
|
2561 release_set_methods_jmethod_ids(NULL);
|
duke@1
|
2562 FreeHeap(jmeths);
|
duke@1
|
2563 }
|
duke@1
|
2564
|
eosterlund@52781
|
2565 assert(_dep_context == NULL,
|
coleenp@51887
|
2566 "dependencies should already be cleaned");
|
duke@1
|
2567
|
cjplummer@38059
|
2568 #if INCLUDE_JVMTI
|
duke@1
|
2569 // Deallocate breakpoint records
|
duke@1
|
2570 if (breakpoints() != 0x0) {
|
duke@1
|
2571 methods_do(clear_all_breakpoints);
|
duke@1
|
2572 assert(breakpoints() == 0x0, "should have cleared breakpoints");
|
duke@1
|
2573 }
|
duke@1
|
2574
|
duke@1
|
2575 // deallocate the cached class file
|
iklam@53884
|
2576 if (_cached_class_file != NULL) {
|
coleenp@27880
|
2577 os::free(_cached_class_file);
|
jiangli@18940
|
2578 _cached_class_file = NULL;
|
duke@1
|
2579 }
|
cjplummer@38059
|
2580 #endif
|
coleenp@8076
|
2581
|
coleenp@8076
|
2582 // Decrement symbol reference counts associated with the unloaded class.
|
coleenp@8076
|
2583 if (_name != NULL) _name->decrement_refcount();
|
coleenp@8076
|
2584 // unreference array name derived from this class name (arrays of an unloaded
|
coleenp@8076
|
2585 // class can't be referenced anymore).
|
coleenp@8076
|
2586 if (_array_name != NULL) _array_name->decrement_refcount();
|
lkorinth@56237
|
2587 FREE_C_HEAP_ARRAY(char, _source_debug_extension);
|
coleenp@8076
|
2588 }
|
coleenp@8076
|
2589
|
mgronlun@34666
|
2590 void InstanceKlass::set_source_debug_extension(const char* array, int length) {
|
fparain@13201
|
2591 if (array == NULL) {
|
fparain@13201
|
2592 _source_debug_extension = NULL;
|
fparain@13201
|
2593 } else {
|
fparain@13201
|
2594 // Adding one to the attribute length in order to store a null terminator
|
fparain@13201
|
2595 // character could cause an overflow because the attribute length is
|
fparain@13201
|
2596 // already coded with an u4 in the classfile, but in practice, it's
|
fparain@13201
|
2597 // unlikely to happen.
|
fparain@13201
|
2598 assert((length+1) > length, "Overflow checking");
|
fparain@13201
|
2599 char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass);
|
fparain@13201
|
2600 for (int i = 0; i < length; i++) {
|
fparain@13201
|
2601 sde[i] = array[i];
|
fparain@13201
|
2602 }
|
fparain@13201
|
2603 sde[length] = '\0';
|
fparain@13201
|
2604 _source_debug_extension = sde;
|
fparain@13201
|
2605 }
|
duke@1
|
2606 }
|
duke@1
|
2607
|
coleenp@13728
|
2608 const char* InstanceKlass::signature_name() const {
|
farvidsson@21183
|
2609 int hash_len = 0;
|
farvidsson@21183
|
2610 char hash_buf[40];
|
farvidsson@21183
|
2611
|
lfoltan@51444
|
2612 // If this is an unsafe anonymous class, append a hash to make the name unique
|
lfoltan@51444
|
2613 if (is_unsafe_anonymous()) {
|
farvidsson@21183
|
2614 intptr_t hash = (java_mirror() != NULL) ? java_mirror()->identity_hash() : 0;
|
goetz@27471
|
2615 jio_snprintf(hash_buf, sizeof(hash_buf), "/" UINTX_FORMAT, (uintx)hash);
|
farvidsson@21183
|
2616 hash_len = (int)strlen(hash_buf);
|
farvidsson@21183
|
2617 }
|
farvidsson@21183
|
2618
|
farvidsson@21183
|
2619 // Get the internal name as a c string
|
duke@1
|
2620 const char* src = (const char*) (name()->as_C_string());
|
duke@1
|
2621 const int src_length = (int)strlen(src);
|
farvidsson@21183
|
2622
|
farvidsson@21183
|
2623 char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3);
|
farvidsson@21183
|
2624
|
farvidsson@21183
|
2625 // Add L as type indicator
|
duke@1
|
2626 int dest_index = 0;
|
lfoltan@56680
|
2627 dest[dest_index++] = JVM_SIGNATURE_CLASS;
|
farvidsson@21183
|
2628
|
farvidsson@21183
|
2629 // Add the actual class name
|
farvidsson@21183
|
2630 for (int src_index = 0; src_index < src_length; ) {
|
duke@1
|
2631 dest[dest_index++] = src[src_index++];
|
duke@1
|
2632 }
|
farvidsson@21183
|
2633
|
farvidsson@21183
|
2634 // If we have a hash, append it
|
farvidsson@21183
|
2635 for (int hash_index = 0; hash_index < hash_len; ) {
|
farvidsson@21183
|
2636 dest[dest_index++] = hash_buf[hash_index++];
|
farvidsson@21183
|
2637 }
|
farvidsson@21183
|
2638
|
farvidsson@21183
|
2639 // Add the semicolon and the NULL
|
lfoltan@56680
|
2640 dest[dest_index++] = JVM_SIGNATURE_ENDCLASS;
|
duke@1
|
2641 dest[dest_index] = '\0';
|
duke@1
|
2642 return dest;
|
duke@1
|
2643 }
|
duke@1
|
2644
|
alanb@36508
|
2645 ModuleEntry* InstanceKlass::module() const {
|
lfoltan@51444
|
2646 // For an unsafe anonymous class return the host class' module
|
lfoltan@51444
|
2647 if (is_unsafe_anonymous()) {
|
lfoltan@51444
|
2648 assert(unsafe_anonymous_host() != NULL, "unsafe anonymous class must have a host class");
|
lfoltan@51444
|
2649 return unsafe_anonymous_host()->module();
|
lfoltan@51444
|
2650 }
|
lfoltan@51444
|
2651
|
lfoltan@51444
|
2652 // Class is in a named package
|
alanb@36508
|
2653 if (!in_unnamed_package()) {
|
alanb@36508
|
2654 return _package_entry->module();
|
alanb@36508
|
2655 }
|
lfoltan@51444
|
2656
|
lfoltan@51444
|
2657 // Class is in an unnamed package, return its loader's unnamed module
|
lfoltan@51444
|
2658 return class_loader_data()->unnamed_module();
|
alanb@36508
|
2659 }
|
alanb@36508
|
2660
|
ccheung@58673
|
2661 void InstanceKlass::set_package(ClassLoaderData* loader_data, PackageEntry* pkg_entry, TRAPS) {
|
acorn@40016
|
2662
|
acorn@40016
|
2663 // ensure java/ packages only loaded by boot or platform builtin loaders
|
lfoltan@50634
|
2664 check_prohibited_package(name(), loader_data, CHECK);
|
acorn@40016
|
2665
|
ccheung@58673
|
2666 TempNewSymbol pkg_name = pkg_entry != NULL ? pkg_entry->name() : ClassLoader::package_from_class_name(name());
|
rprotacio@39216
|
2667
|
rprotacio@39216
|
2668 if (pkg_name != NULL && loader_data != NULL) {
|
acorn@40016
|
2669
|
alanb@36508
|
2670 // Find in class loader's package entry table.
|
ccheung@58673
|
2671 _package_entry = pkg_entry != NULL ? pkg_entry : loader_data->packages()->lookup_only(pkg_name);
|
alanb@36508
|
2672
|
alanb@36508
|
2673 // If the package name is not found in the loader's package
|
alanb@36508
|
2674 // entry table, it is an indication that the package has not
|
alanb@36508
|
2675 // been defined. Consider it defined within the unnamed module.
|
alanb@36508
|
2676 if (_package_entry == NULL) {
|
alanb@36508
|
2677
|
alanb@36508
|
2678 if (!ModuleEntryTable::javabase_defined()) {
|
alanb@36508
|
2679 // Before java.base is defined during bootstrapping, define all packages in
|
alanb@36508
|
2680 // the java.base module. If a non-java.base package is erroneously placed
|
alanb@36508
|
2681 // in the java.base module it will be caught later when java.base
|
alanb@36508
|
2682 // is defined by ModuleEntryTable::verify_javabase_packages check.
|
rprotacio@42636
|
2683 assert(ModuleEntryTable::javabase_moduleEntry() != NULL, JAVA_BASE_NAME " module is NULL");
|
lfoltan@41183
|
2684 _package_entry = loader_data->packages()->lookup(pkg_name, ModuleEntryTable::javabase_moduleEntry());
|
alanb@36508
|
2685 } else {
|
rprotacio@46387
|
2686 assert(loader_data->unnamed_module() != NULL, "unnamed module is NULL");
|
alanb@36508
|
2687 _package_entry = loader_data->packages()->lookup(pkg_name,
|
rprotacio@46387
|
2688 loader_data->unnamed_module());
|
alanb@36508
|
2689 }
|
alanb@36508
|
2690
|
alanb@36508
|
2691 // A package should have been successfully created
|
ccheung@58673
|
2692 DEBUG_ONLY(ResourceMark rm(THREAD));
|
alanb@36508
|
2693 assert(_package_entry != NULL, "Package entry for class %s not found, loader %s",
|
lfoltan@50634
|
2694 name()->as_C_string(), loader_data->loader_name_and_id());
|
alanb@36508
|
2695 }
|
alanb@36508
|
2696
|
alanb@44993
|
2697 if (log_is_enabled(Debug, module)) {
|
iklam@57387
|
2698 ResourceMark rm(THREAD);
|
alanb@36508
|
2699 ModuleEntry* m = _package_entry->module();
|
alanb@44993
|
2700 log_trace(module)("Setting package: class: %s, package: %s, loader: %s, module: %s",
|
alanb@44993
|
2701 external_name(),
|
alanb@44993
|
2702 pkg_name->as_C_string(),
|
lfoltan@50634
|
2703 loader_data->loader_name_and_id(),
|
alanb@44993
|
2704 (m->is_named() ? m->name()->as_C_string() : UNNAMED_MODULE));
|
alanb@36508
|
2705 }
|
alanb@36508
|
2706 } else {
|
iklam@57387
|
2707 ResourceMark rm(THREAD);
|
alanb@44993
|
2708 log_trace(module)("Setting package: class: %s, package: unnamed, loader: %s, module: %s",
|
alanb@44993
|
2709 external_name(),
|
lfoltan@50634
|
2710 (loader_data != NULL) ? loader_data->loader_name_and_id() : "NULL",
|
alanb@44993
|
2711 UNNAMED_MODULE);
|
alanb@36508
|
2712 }
|
alanb@36508
|
2713 }
|
alanb@36508
|
2714
|
alanb@36508
|
2715
|
alanb@36508
|
2716 // different versions of is_same_class_package
|
alanb@36508
|
2717
|
mgronlun@34666
|
2718 bool InstanceKlass::is_same_class_package(const Klass* class2) const {
|
alanb@36508
|
2719 oop classloader1 = this->class_loader();
|
alanb@36508
|
2720 PackageEntry* classpkg1 = this->package();
|
coleenp@33611
|
2721 if (class2->is_objArray_klass()) {
|
coleenp@13952
|
2722 class2 = ObjArrayKlass::cast(class2)->bottom_klass();
|
duke@1
|
2723 }
|
alanb@36508
|
2724
|
mgronlun@34666
|
2725 oop classloader2;
|
alanb@36508
|
2726 PackageEntry* classpkg2;
|
mgronlun@34666
|
2727 if (class2->is_instance_klass()) {
|
alanb@36508
|
2728 classloader2 = class2->class_loader();
|
rprotacio@38094
|
2729 classpkg2 = class2->package();
|
mgronlun@34666
|
2730 } else {
|
mgronlun@34666
|
2731 assert(class2->is_typeArray_klass(), "should be type array");
|
mgronlun@34666
|
2732 classloader2 = NULL;
|
alanb@36508
|
2733 classpkg2 = NULL;
|
mgronlun@34666
|
2734 }
|
alanb@36508
|
2735
|
alanb@36508
|
2736 // Same package is determined by comparing class loader
|
alanb@36508
|
2737 // and package entries. Both must be the same. This rule
|
alanb@36508
|
2738 // applies even to classes that are defined in the unnamed
|
alanb@36508
|
2739 // package, they still must have the same class loader.
|
pliden@56286
|
2740 if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) {
|
alanb@36508
|
2741 return true;
|
alanb@36508
|
2742 }
|
alanb@36508
|
2743
|
alanb@36508
|
2744 return false;
|
duke@1
|
2745 }
|
duke@1
|
2746
|
hseigel@46697
|
2747 // return true if this class and other_class are in the same package. Classloader
|
hseigel@46697
|
2748 // and classname information is enough to determine a class's package
|
mgronlun@34666
|
2749 bool InstanceKlass::is_same_class_package(oop other_class_loader,
|
mgronlun@34666
|
2750 const Symbol* other_class_name) const {
|
pliden@56286
|
2751 if (class_loader() != other_class_loader) {
|
duke@1
|
2752 return false;
|
hseigel@46697
|
2753 }
|
hseigel@46697
|
2754 if (name()->fast_compare(other_class_name) == 0) {
|
hseigel@46697
|
2755 return true;
|
hseigel@46697
|
2756 }
|
hseigel@46697
|
2757
|
hseigel@46697
|
2758 {
|
duke@1
|
2759 ResourceMark rm;
|
duke@1
|
2760
|
rprotacio@39216
|
2761 bool bad_class_name = false;
|
redestad@58528
|
2762 TempNewSymbol other_pkg = ClassLoader::package_from_class_name(other_class_name, &bad_class_name);
|
rprotacio@39216
|
2763 if (bad_class_name) {
|
alanb@36508
|
2764 return false;
|
alanb@36508
|
2765 }
|
redestad@58528
|
2766 // Check that package_from_class_name() returns NULL, not "", if there is no package.
|
redestad@58528
|
2767 assert(other_pkg == NULL || other_pkg->utf8_length() > 0, "package name is empty string");
|
hseigel@46697
|
2768
|
hseigel@46697
|
2769 const Symbol* const this_package_name =
|
hseigel@46697
|
2770 this->package() != NULL ? this->package()->name() : NULL;
|
hseigel@46697
|
2771
|
hseigel@46697
|
2772 if (this_package_name == NULL || other_pkg == NULL) {
|
hseigel@46697
|
2773 // One of the two doesn't have a package. Only return true if the other
|
hseigel@46697
|
2774 // one also doesn't have a package.
|
redestad@58528
|
2775 return this_package_name == other_pkg;
|
duke@1
|
2776 }
|
alanb@36508
|
2777
|
hseigel@46697
|
2778 // Check if package is identical
|
redestad@58528
|
2779 return this_package_name->fast_compare(other_pkg) == 0;
|
duke@1
|
2780 }
|
duke@1
|
2781 }
|
duke@1
|
2782
|
acorn@2264
|
2783 // Returns true iff super_method can be overridden by a method in targetclassname
|
rprotacio@39216
|
2784 // See JLS 3rd edition 8.4.6.1
|
acorn@2264
|
2785 // Assumes name-signature match
|
coleenp@13728
|
2786 // "this" is InstanceKlass of super_method which must exist
|
coleenp@13728
|
2787 // note that the InstanceKlass of the method in the targetclassname has not always been created yet
|
coleenp@33593
|
2788 bool InstanceKlass::is_override(const methodHandle& super_method, Handle targetclassloader, Symbol* targetclassname, TRAPS) {
|
acorn@2264
|
2789 // Private methods can not be overridden
|
acorn@2264
|
2790 if (super_method->is_private()) {
|
acorn@2264
|
2791 return false;
|
acorn@2264
|
2792 }
|
acorn@2264
|
2793 // If super method is accessible, then override
|
acorn@2264
|
2794 if ((super_method->is_protected()) ||
|
acorn@2264
|
2795 (super_method->is_public())) {
|
acorn@2264
|
2796 return true;
|
acorn@2264
|
2797 }
|
acorn@2264
|
2798 // Package-private methods are not inherited outside of package
|
acorn@2264
|
2799 assert(super_method->is_package_private(), "must be package private");
|
coleenp@8076
|
2800 return(is_same_class_package(targetclassloader(), targetclassname));
|
acorn@2264
|
2801 }
|
duke@1
|
2802
|
acorn@40016
|
2803 // Only boot and platform class loaders can define classes in "java/" packages.
|
acorn@40016
|
2804 void InstanceKlass::check_prohibited_package(Symbol* class_name,
|
lfoltan@50634
|
2805 ClassLoaderData* loader_data,
|
alanb@42307
|
2806 TRAPS) {
|
lfoltan@50634
|
2807 if (!loader_data->is_boot_class_loader_data() &&
|
lfoltan@50634
|
2808 !loader_data->is_platform_class_loader_data() &&
|
alanb@44326
|
2809 class_name != NULL) {
|
alanb@44326
|
2810 ResourceMark rm(THREAD);
|
alanb@44326
|
2811 char* name = class_name->as_C_string();
|
alanb@44326
|
2812 if (strncmp(name, JAVAPKG, JAVAPKG_LEN) == 0 && name[JAVAPKG_LEN] == '/') {
|
redestad@58528
|
2813 TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name);
|
alanb@44326
|
2814 assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'");
|
alanb@44326
|
2815 name = pkg_name->as_C_string();
|
lfoltan@50634
|
2816 const char* class_loader_name = loader_data->loader_name_and_id();
|
alanb@44326
|
2817 StringUtils::replace_no_expand(name, "/", ".");
|
alanb@44326
|
2818 const char* msg_text1 = "Class loader (instance of): ";
|
alanb@44326
|
2819 const char* msg_text2 = " tried to load prohibited package name: ";
|
alanb@44326
|
2820 size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1;
|
alanb@44326
|
2821 char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len);
|
alanb@44326
|
2822 jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name);
|
alanb@44326
|
2823 THROW_MSG(vmSymbols::java_lang_SecurityException(), message);
|
alanb@44326
|
2824 }
|
acorn@40016
|
2825 }
|
acorn@40016
|
2826 return;
|
acorn@40016
|
2827 }
|
acorn@40016
|
2828
|
hseigel@46341
|
2829 bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPS) const {
|
hseigel@46341
|
2830 constantPoolHandle i_cp(THREAD, constants());
|
hseigel@46341
|
2831 for (InnerClassesIterator iter(this); !iter.done(); iter.next()) {
|
vlivanov@30222
|
2832 int ioff = iter.inner_class_info_index();
|
vlivanov@30222
|
2833 if (ioff != 0) {
|
vlivanov@30222
|
2834 // Check to see if the name matches the class we're looking for
|
vlivanov@30222
|
2835 // before attempting to find the class.
|
hseigel@46341
|
2836 if (i_cp->klass_name_at_matches(this, ioff)) {
|
vlivanov@30222
|
2837 Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false);
|
hseigel@46341
|
2838 if (this == inner_klass) {
|
vlivanov@30222
|
2839 *ooff = iter.outer_class_info_index();
|
vlivanov@30222
|
2840 *noff = iter.inner_name_index();
|
vlivanov@30222
|
2841 return true;
|
vlivanov@30222
|
2842 }
|
vlivanov@30222
|
2843 }
|
vlivanov@30222
|
2844 }
|
vlivanov@30222
|
2845 }
|
vlivanov@30222
|
2846 return false;
|
vlivanov@30222
|
2847 }
|
vlivanov@30222
|
2848
|
hseigel@46341
|
2849 InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPS) const {
|
mgronlun@34666
|
2850 InstanceKlass* outer_klass = NULL;
|
vlivanov@30222
|
2851 *inner_is_member = false;
|
vlivanov@30222
|
2852 int ooff = 0, noff = 0;
|
hseigel@46341
|
2853 bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD);
|
hseigel@46341
|
2854 if (has_inner_classes_attr) {
|
hseigel@46341
|
2855 constantPoolHandle i_cp(THREAD, constants());
|
vlivanov@30222
|
2856 if (ooff != 0) {
|
vlivanov@30222
|
2857 Klass* ok = i_cp->klass_at(ooff, CHECK_NULL);
|
mgronlun@34666
|
2858 outer_klass = InstanceKlass::cast(ok);
|
vlivanov@30222
|
2859 *inner_is_member = true;
|
vlivanov@30222
|
2860 }
|
mgronlun@34666
|
2861 if (NULL == outer_klass) {
|
lfoltan@51444
|
2862 // It may be unsafe anonymous; try for that.
|
hseigel@46341
|
2863 int encl_method_class_idx = enclosing_method_class_index();
|
vlivanov@30222
|
2864 if (encl_method_class_idx != 0) {
|
vlivanov@30222
|
2865 Klass* ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL);
|
mgronlun@34666
|
2866 outer_klass = InstanceKlass::cast(ok);
|
vlivanov@30222
|
2867 *inner_is_member = false;
|
vlivanov@30222
|
2868 }
|
vlivanov@30222
|
2869 }
|
vlivanov@30222
|
2870 }
|
vlivanov@30222
|
2871
|
vlivanov@30222
|
2872 // If no inner class attribute found for this class.
|
mgronlun@34666
|
2873 if (NULL == outer_klass) return NULL;
|
vlivanov@30222
|
2874
|
vlivanov@30222
|
2875 // Throws an exception if outer klass has not declared k as an inner klass
|
vlivanov@30222
|
2876 // We need evidence that each klass knows about the other, or else
|
vlivanov@30222
|
2877 // the system could allow a spoof of an inner class to gain access rights.
|
hseigel@46341
|
2878 Reflection::check_for_inner_class(outer_klass, this, *inner_is_member, CHECK_NULL);
|
mgronlun@34666
|
2879 return outer_klass;
|
vlivanov@30222
|
2880 }
|
duke@1
|
2881
|
coleenp@13728
|
2882 jint InstanceKlass::compute_modifier_flags(TRAPS) const {
|
duke@1
|
2883 jint access = access_flags().as_int();
|
duke@1
|
2884
|
duke@1
|
2885 // But check if it happens to be member class.
|
coleenp@46329
|
2886 InnerClassesIterator iter(this);
|
jiangli@12231
|
2887 for (; !iter.done(); iter.next()) {
|
jiangli@12231
|
2888 int ioff = iter.inner_class_info_index();
|
jiangli@12231
|
2889 // Inner class attribute can be zero, skip it.
|
jiangli@12231
|
2890 // Strange but true: JVM spec. allows null inner class refs.
|
jiangli@12231
|
2891 if (ioff == 0) continue;
|
jiangli@12231
|
2892
|
jiangli@12231
|
2893 // only look at classes that are already loaded
|
jiangli@12231
|
2894 // since we are looking for the flags for our self.
|
coleenp@46329
|
2895 Symbol* inner_name = constants()->klass_name_at(ioff);
|
coleenp@46329
|
2896 if (name() == inner_name) {
|
jiangli@12231
|
2897 // This is really a member class.
|
jiangli@12231
|
2898 access = iter.inner_access_flags();
|
jiangli@12231
|
2899 break;
|
duke@1
|
2900 }
|
duke@1
|
2901 }
|
duke@1
|
2902 // Remember to strip ACC_SUPER bit
|
duke@1
|
2903 return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS;
|
duke@1
|
2904 }
|
duke@1
|
2905
|
coleenp@13728
|
2906 jint InstanceKlass::jvmti_class_status() const {
|
duke@1
|
2907 jint result = 0;
|
duke@1
|
2908
|
duke@1
|
2909 if (is_linked()) {
|
duke@1
|
2910 result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED;
|
duke@1
|
2911 }
|
duke@1
|
2912
|
duke@1
|
2913 if (is_initialized()) {
|
duke@1
|
2914 assert(is_linked(), "Class status is not consistent");
|
duke@1
|
2915 result |= JVMTI_CLASS_STATUS_INITIALIZED;
|
duke@1
|
2916 }
|
duke@1
|
2917 if (is_in_error_state()) {
|
duke@1
|
2918 result |= JVMTI_CLASS_STATUS_ERROR;
|
duke@1
|
2919 }
|
duke@1
|
2920 return result;
|
duke@1
|
2921 }
|
duke@1
|
2922
|
coleenp@13728
|
2923 Method* InstanceKlass::method_at_itable(Klass* holder, int index, TRAPS) {
|
duke@1
|
2924 itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable();
|
duke@1
|
2925 int method_table_offset_in_words = ioe->offset()/wordSize;
|
duke@1
|
2926 int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words())
|
duke@1
|
2927 / itableOffsetEntry::size();
|
duke@1
|
2928
|
duke@1
|
2929 for (int cnt = 0 ; ; cnt ++, ioe ++) {
|
twisti@2131
|
2930 // If the interface isn't implemented by the receiver class,
|
duke@1
|
2931 // the VM should throw IncompatibleClassChangeError.
|
duke@1
|
2932 if (cnt >= nof_interfaces) {
|
goetz@50633
|
2933 ResourceMark rm(THREAD);
|
goetz@50633
|
2934 stringStream ss;
|
lfoltan@50761
|
2935 bool same_module = (module() == holder->module());
|
goetz@50633
|
2936 ss.print("Receiver class %s does not implement "
|
lfoltan@50761
|
2937 "the interface %s defining the method to be called "
|
lfoltan@50761
|
2938 "(%s%s%s)",
|
lfoltan@50761
|
2939 external_name(), holder->external_name(),
|
lfoltan@50761
|
2940 (same_module) ? joint_in_module_of_loader(holder) : class_in_module_of_loader(),
|
lfoltan@50761
|
2941 (same_module) ? "" : "; ",
|
lfoltan@50761
|
2942 (same_module) ? "" : holder->class_in_module_of_loader());
|
goetz@50633
|
2943 THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string());
|
duke@1
|
2944 }
|
duke@1
|
2945
|
coleenp@13728
|
2946 Klass* ik = ioe->interface_klass();
|
duke@1
|
2947 if (ik == holder) break;
|
duke@1
|
2948 }
|
duke@1
|
2949
|
coleenp@13728
|
2950 itableMethodEntry* ime = ioe->first_method_entry(this);
|
coleenp@13728
|
2951 Method* m = ime[index].method();
|
duke@1
|
2952 if (m == NULL) {
|
coleenp@13728
|
2953 THROW_NULL(vmSymbols::java_lang_AbstractMethodError());
|
duke@1
|
2954 }
|
duke@1
|
2955 return m;
|
duke@1
|
2956 }
|
duke@1
|
2957
|
acorn@20391
|
2958
|
acorn@20391
|
2959 #if INCLUDE_JVMTI
|
acorn@20391
|
2960 // update default_methods for redefineclasses for methods that are
|
acorn@20391
|
2961 // not yet in the vtable due to concurrent subclass define and superinterface
|
acorn@20391
|
2962 // redefinition
|
acorn@20391
|
2963 // Note: those in the vtable, should have been updated via adjust_method_entries
|
coleenp@53904
|
2964 void InstanceKlass::adjust_default_methods(bool* trace_name_printed) {
|
acorn@20391
|
2965 // search the default_methods for uses of either obsolete or EMCP methods
|
acorn@20391
|
2966 if (default_methods() != NULL) {
|
sspitsyn@29316
|
2967 for (int index = 0; index < default_methods()->length(); index ++) {
|
sspitsyn@29316
|
2968 Method* old_method = default_methods()->at(index);
|
coleenp@53904
|
2969 if (old_method == NULL || !old_method->is_old()) {
|
sspitsyn@29316
|
2970 continue; // skip uninteresting entries
|
sspitsyn@29316
|
2971 }
|
sspitsyn@29316
|
2972 assert(!old_method->is_deleted(), "default methods may not be deleted");
|
coleenp@53904
|
2973 Method* new_method = old_method->get_new_method();
|
sspitsyn@29316
|
2974 default_methods()->at_put(index, new_method);
|
coleenp@53904
|
2975
|
rehn@38259
|
2976 if (log_is_enabled(Info, redefine, class, update)) {
|
rehn@38259
|
2977 ResourceMark rm;
|
sspitsyn@29316
|
2978 if (!(*trace_name_printed)) {
|
rehn@38259
|
2979 log_info(redefine, class, update)
|
rehn@38259
|
2980 ("adjust: klassname=%s default methods from name=%s",
|
rehn@38259
|
2981 external_name(), old_method->method_holder()->external_name());
|
sspitsyn@29316
|
2982 *trace_name_printed = true;
|
acorn@20391
|
2983 }
|
rehn@38259
|
2984 log_debug(redefine, class, update, vtables)
|
rehn@38259
|
2985 ("default method update: %s(%s) ",
|
rehn@38259
|
2986 new_method->name()->as_C_string(), new_method->signature()->as_C_string());
|
acorn@20391
|
2987 }
|
acorn@20391
|
2988 }
|
acorn@20391
|
2989 }
|
acorn@20391
|
2990 }
|
acorn@20391
|
2991 #endif // INCLUDE_JVMTI
|
acorn@20391
|
2992
|
duke@1
|
2993 // On-stack replacement stuff
|
coleenp@13728
|
2994 void InstanceKlass::add_osr_nmethod(nmethod* n) {
|
rehn@56312
|
2995 assert_lock_strong(CompiledMethod_lock);
|
xliu@54736
|
2996 #ifndef PRODUCT
|
xliu@54736
|
2997 if (TieredCompilation) {
|
xliu@54736
|
2998 nmethod * prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true);
|
xliu@54736
|
2999 assert(prev == NULL || !prev->is_in_use(),
|
xliu@54736
|
3000 "redundunt OSR recompilation detected. memory leak in CodeCache!");
|
xliu@54736
|
3001 }
|
xliu@54736
|
3002 #endif
|
duke@1
|
3003 // only one compilation can be active
|
thartmann@27409
|
3004 {
|
thartmann@27409
|
3005 assert(n->is_osr_method(), "wrong kind of nmethod");
|
thartmann@27409
|
3006 n->set_osr_link(osr_nmethods_head());
|
thartmann@27409
|
3007 set_osr_nmethods_head(n);
|
thartmann@27409
|
3008 // Raise the highest osr level if necessary
|
thartmann@27409
|
3009 if (TieredCompilation) {
|
thartmann@27409
|
3010 Method* m = n->method();
|
thartmann@27409
|
3011 m->set_highest_osr_comp_level(MAX2(m->highest_osr_comp_level(), n->comp_level()));
|
thartmann@27409
|
3012 }
|
iveresov@6453
|
3013 }
|
iveresov@6453
|
3014
|
iveresov@6453
|
3015 // Get rid of the osr methods for the same bci that have lower levels.
|
iveresov@6453
|
3016 if (TieredCompilation) {
|
iveresov@6453
|
3017 for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) {
|
iveresov@6453
|
3018 nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true);
|
iveresov@6453
|
3019 if (inv != NULL && inv->is_in_use()) {
|
iveresov@6453
|
3020 inv->make_not_entrant();
|
iveresov@6453
|
3021 }
|
iveresov@6453
|
3022 }
|
iveresov@6453
|
3023 }
|
duke@1
|
3024 }
|
duke@1
|
3025
|
thartmann@36802
|
3026 // Remove osr nmethod from the list. Return true if found and removed.
|
thartmann@36802
|
3027 bool InstanceKlass::remove_osr_nmethod(nmethod* n) {
|
duke@1
|
3028 // This is a short non-blocking critical region, so the no safepoint check is ok.
|
rehn@56312
|
3029 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock
|
rehn@56312
|
3030 , Mutex::_no_safepoint_check_flag);
|
duke@1
|
3031 assert(n->is_osr_method(), "wrong kind of nmethod");
|
duke@1
|
3032 nmethod* last = NULL;
|
duke@1
|
3033 nmethod* cur = osr_nmethods_head();
|
iveresov@6453
|
3034 int max_level = CompLevel_none; // Find the max comp level excluding n
|
coleenp@13728
|
3035 Method* m = n->method();
|
duke@1
|
3036 // Search for match
|
thartmann@36802
|
3037 bool found = false;
|
duke@1
|
3038 while(cur != NULL && cur != n) {
|
neliasso@22920
|
3039 if (TieredCompilation && m == cur->method()) {
|
iveresov@6453
|
3040 // Find max level before n
|
iveresov@6453
|
3041 max_level = MAX2(max_level, cur->comp_level());
|
iveresov@6453
|
3042 }
|
duke@1
|
3043 last = cur;
|
jrose@3908
|
3044 cur = cur->osr_link();
|
duke@1
|
3045 }
|
iveresov@6453
|
3046 nmethod* next = NULL;
|
duke@1
|
3047 if (cur == n) {
|
thartmann@36802
|
3048 found = true;
|
iveresov@6453
|
3049 next = cur->osr_link();
|
duke@1
|
3050 if (last == NULL) {
|
duke@1
|
3051 // Remove first element
|
iveresov@6453
|
3052 set_osr_nmethods_head(next);
|
duke@1
|
3053 } else {
|
iveresov@6453
|
3054 last->set_osr_link(next);
|
duke@1
|
3055 }
|
duke@1
|
3056 }
|
jrose@3908
|
3057 n->set_osr_link(NULL);
|
iveresov@6453
|
3058 if (TieredCompilation) {
|
iveresov@6453
|
3059 cur = next;
|
iveresov@6453
|
3060 while (cur != NULL) {
|
iveresov@6453
|
3061 // Find max level after n
|
neliasso@22920
|
3062 if (m == cur->method()) {
|
neliasso@22920
|
3063 max_level = MAX2(max_level, cur->comp_level());
|
neliasso@22920
|
3064 }
|
iveresov@6453
|
3065 cur = cur->osr_link();
|
iveresov@6453
|
3066 }
|
iveresov@6453
|
3067 m->set_highest_osr_comp_level(max_level);
|
iveresov@6453
|
3068 }
|
thartmann@36802
|
3069 return found;
|
duke@1
|
3070 }
|
duke@1
|
3071
|
thartmann@27434
|
3072 int InstanceKlass::mark_osr_nmethods(const Method* m) {
|
rehn@56312
|
3073 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock,
|
rehn@56312
|
3074 Mutex::_no_safepoint_check_flag);
|
thartmann@27434
|
3075 nmethod* osr = osr_nmethods_head();
|
thartmann@27434
|
3076 int found = 0;
|
thartmann@27434
|
3077 while (osr != NULL) {
|
thartmann@27434
|
3078 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
|
thartmann@27434
|
3079 if (osr->method() == m) {
|
thartmann@27434
|
3080 osr->mark_for_deoptimization();
|
thartmann@27434
|
3081 found++;
|
thartmann@27434
|
3082 }
|
thartmann@27434
|
3083 osr = osr->osr_link();
|
thartmann@27434
|
3084 }
|
thartmann@27434
|
3085 return found;
|
thartmann@27434
|
3086 }
|
thartmann@27434
|
3087
|
minqi@17370
|
3088 nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const {
|
rehn@56312
|
3089 MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL : CompiledMethod_lock,
|
rehn@56312
|
3090 Mutex::_no_safepoint_check_flag);
|
duke@1
|
3091 nmethod* osr = osr_nmethods_head();
|
iveresov@6453
|
3092 nmethod* best = NULL;
|
duke@1
|
3093 while (osr != NULL) {
|
duke@1
|
3094 assert(osr->is_osr_method(), "wrong kind of nmethod found in chain");
|
iveresov@6453
|
3095 // There can be a time when a c1 osr method exists but we are waiting
|
iveresov@6453
|
3096 // for a c2 version. When c2 completes its osr nmethod we will trash
|
iveresov@6453
|
3097 // the c1 version and only be able to find the c2 version. However
|
iveresov@6453
|
3098 // while we overflow in the c1 code at back branches we don't want to
|
iveresov@6453
|
3099 // try and switch to the same code as we are already running
|
iveresov@6453
|
3100
|
duke@1
|
3101 if (osr->method() == m &&
|
duke@1
|
3102 (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) {
|
iveresov@6453
|
3103 if (match_level) {
|
iveresov@6453
|
3104 if (osr->comp_level() == comp_level) {
|
iveresov@6453
|
3105 // Found a match - return it.
|
iveresov@6453
|
3106 return osr;
|
iveresov@6453
|
3107 }
|
iveresov@6453
|
3108 } else {
|
iveresov@6453
|
3109 if (best == NULL || (osr->comp_level() > best->comp_level())) {
|
iveresov@6453
|
3110 if (osr->comp_level() == CompLevel_highest_tier) {
|
iveresov@6453
|
3111 // Found the best possible - return it.
|
iveresov@6453
|
3112 return osr;
|
iveresov@6453
|
3113 }
|
iveresov@6453
|
3114 best = osr;
|
iveresov@6453
|
3115 }
|
iveresov@6453
|
3116 }
|
duke@1
|
3117 }
|
jrose@3908
|
3118 osr = osr->osr_link();
|
duke@1
|
3119 }
|
xliu@54736
|
3120
|
xliu@54736
|
3121 assert(match_level == false || best == NULL, "shouldn't pick up anything if match_level is set");
|
xliu@54736
|
3122 if (best != NULL && best->comp_level() >= comp_level) {
|
iveresov@6453
|
3123 return best;
|
iveresov@6453
|
3124 }
|
duke@1
|
3125 return NULL;
|
duke@1
|
3126 }
|
duke@1
|
3127
|
duke@1
|
3128 // -----------------------------------------------------------------------------------------------------
|
coleenp@13728
|
3129 // Printing
|
coleenp@13728
|
3130
|
duke@1
|
3131 #ifndef PRODUCT
|
duke@1
|
3132
|
jrose@2332
|
3133 #define BULLET " - "
|
jrose@2332
|
3134
|
coleenp@13728
|
3135 static const char* state_names[] = {
|
coleenp@13728
|
3136 "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error"
|
coleenp@13728
|
3137 };
|
coleenp@13728
|
3138
|
drchase@20017
|
3139 static void print_vtable(intptr_t* start, int len, outputStream* st) {
|
drchase@20017
|
3140 for (int i = 0; i < len; i++) {
|
drchase@20017
|
3141 intptr_t e = start[i];
|
drchase@20017
|
3142 st->print("%d : " INTPTR_FORMAT, i, e);
|
stuefe@54437
|
3143 if (MetaspaceObj::is_valid((Metadata*)e)) {
|
drchase@20017
|
3144 st->print(" ");
|
drchase@20017
|
3145 ((Metadata*)e)->print_value_on(st);
|
drchase@20017
|
3146 }
|
drchase@20017
|
3147 st->cr();
|
drchase@20017
|
3148 }
|
drchase@20017
|
3149 }
|
drchase@20017
|
3150
|
mgerdin@35900
|
3151 static void print_vtable(vtableEntry* start, int len, outputStream* st) {
|
mgerdin@35900
|
3152 return print_vtable(reinterpret_cast<intptr_t*>(start), len, st);
|
mgerdin@35900
|
3153 }
|
mgerdin@35900
|
3154
|
coleenp@13728
|
3155 void InstanceKlass::print_on(outputStream* st) const {
|
coleenp@13728
|
3156 assert(is_klass(), "must be klass");
|
coleenp@13728
|
3157 Klass::print_on(st);
|
coleenp@13728
|
3158
|
coleenp@13728
|
3159 st->print(BULLET"instance size: %d", size_helper()); st->cr();
|
coleenp@13728
|
3160 st->print(BULLET"klass size: %d", size()); st->cr();
|
coleenp@13728
|
3161 st->print(BULLET"access: "); access_flags().print_on(st); st->cr();
|
drchase@24424
|
3162 st->print(BULLET"state: "); st->print_cr("%s", state_names[_init_state]);
|
coleenp@13728
|
3163 st->print(BULLET"name: "); name()->print_value_on(st); st->cr();
|
hseigel@51265
|
3164 st->print(BULLET"super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr();
|
coleenp@13728
|
3165 st->print(BULLET"sub: ");
|
coleenp@52356
|
3166 Klass* sub = subklass();
|
coleenp@52356
|
3167 int n;
|
coleenp@52356
|
3168 for (n = 0; sub != NULL; n++, sub = sub->next_sibling()) {
|
coleenp@52356
|
3169 if (n < MaxSubklassPrintSize) {
|
coleenp@52356
|
3170 sub->print_value_on(st);
|
coleenp@52356
|
3171 st->print(" ");
|
coleenp@13728
|
3172 }
|
coleenp@13728
|
3173 }
|
coleenp@52356
|
3174 if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT " more klasses...)", n - MaxSubklassPrintSize);
|
coleenp@52356
|
3175 st->cr();
|
coleenp@52356
|
3176
|
coleenp@52356
|
3177 if (is_interface()) {
|
coleenp@52356
|
3178 st->print_cr(BULLET"nof implementors: %d", nof_implementors());
|
coleenp@52356
|
3179 if (nof_implementors() == 1) {
|
coleenp@52356
|
3180 st->print_cr(BULLET"implementor: ");
|
coleenp@52356
|
3181 st->print(" ");
|
coleenp@52356
|
3182 implementor()->print_value_on(st);
|
coleenp@52356
|
3183 st->cr();
|
coleenp@52356
|
3184 }
|
coleenp@52356
|
3185 }
|
coleenp@52356
|
3186
|
hseigel@51265
|
3187 st->print(BULLET"arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr();
|
coleenp@13728
|
3188 st->print(BULLET"methods: "); methods()->print_value_on(st); st->cr();
|
drchase@20017
|
3189 if (Verbose || WizardMode) {
|
coleenp@13728
|
3190 Array<Method*>* method_array = methods();
|
acorn@20391
|
3191 for (int i = 0; i < method_array->length(); i++) {
|
coleenp@13728
|
3192 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
|
coleenp@13728
|
3193 }
|
coleenp@13728
|
3194 }
|
acorn@20391
|
3195 st->print(BULLET"method ordering: "); method_ordering()->print_value_on(st); st->cr();
|
acorn@20391
|
3196 st->print(BULLET"default_methods: "); default_methods()->print_value_on(st); st->cr();
|
acorn@20391
|
3197 if (Verbose && default_methods() != NULL) {
|
acorn@20391
|
3198 Array<Method*>* method_array = default_methods();
|
acorn@20391
|
3199 for (int i = 0; i < method_array->length(); i++) {
|
acorn@20391
|
3200 st->print("%d : ", i); method_array->at(i)->print_value(); st->cr();
|
acorn@20391
|
3201 }
|
acorn@20391
|
3202 }
|
acorn@20391
|
3203 if (default_vtable_indices() != NULL) {
|
acorn@20391
|
3204 st->print(BULLET"default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr();
|
acorn@20391
|
3205 }
|
coleenp@13728
|
3206 st->print(BULLET"local interfaces: "); local_interfaces()->print_value_on(st); st->cr();
|
coleenp@13728
|
3207 st->print(BULLET"trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr();
|
coleenp@13728
|
3208 st->print(BULLET"constants: "); constants()->print_value_on(st); st->cr();
|
coleenp@13728
|
3209 if (class_loader_data() != NULL) {
|
coleenp@13728
|
3210 st->print(BULLET"class loader data: ");
|
coleenp@13728
|
3211 class_loader_data()->print_value_on(st);
|
coleenp@13728
|
3212 st->cr();
|
coleenp@13728
|
3213 }
|
lfoltan@51444
|
3214 st->print(BULLET"unsafe anonymous host class: "); Metadata::print_value_on_maybe_null(st, unsafe_anonymous_host()); st->cr();
|
coleenp@13728
|
3215 if (source_file_name() != NULL) {
|
coleenp@13728
|
3216 st->print(BULLET"source file: ");
|
coleenp@13728
|
3217 source_file_name()->print_value_on(st);
|
coleenp@13728
|
3218 st->cr();
|
coleenp@13728
|
3219 }
|
coleenp@13728
|
3220 if (source_debug_extension() != NULL) {
|
coleenp@13728
|
3221 st->print(BULLET"source debug extension: ");
|
coleenp@13728
|
3222 st->print("%s", source_debug_extension());
|
coleenp@13728
|
3223 st->cr();
|
coleenp@13728
|
3224 }
|
coleenp@15601
|
3225 st->print(BULLET"class annotations: "); class_annotations()->print_value_on(st); st->cr();
|
coleenp@15601
|
3226 st->print(BULLET"class type annotations: "); class_type_annotations()->print_value_on(st); st->cr();
|
coleenp@15601
|
3227 st->print(BULLET"field annotations: "); fields_annotations()->print_value_on(st); st->cr();
|
coleenp@15601
|
3228 st->print(BULLET"field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr();
|
coleenp@13728
|
3229 {
|
coleenp@20059
|
3230 bool have_pv = false;
|
coleenp@26558
|
3231 // previous versions are linked together through the InstanceKlass
|
cjplummer@38059
|
3232 for (InstanceKlass* pv_node = previous_versions();
|
coleenp@26558
|
3233 pv_node != NULL;
|
coleenp@26558
|
3234 pv_node = pv_node->previous_versions()) {
|
coleenp@20059
|
3235 if (!have_pv)
|
coleenp@20059
|
3236 st->print(BULLET"previous version: ");
|
coleenp@20059
|
3237 have_pv = true;
|
coleenp@26558
|
3238 pv_node->constants()->print_value_on(st);
|
coleenp@20059
|
3239 }
|
coleenp@20059
|
3240 if (have_pv) st->cr();
|
coleenp@26558
|
|