File: | jdk/src/hotspot/share/oops/instanceKlass.cpp |
Warning: | line 2314, column 8 Although the value stored to 'length' is used in the enclosing expression, the value is never actually read from 'length' |
Press '?' to see keyboard shortcuts
Keyboard shortcuts:
1 | /* |
2 | * Copyright (c) 1997, 2021, Oracle and/or its affiliates. All rights reserved. |
3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 | * |
5 | * This code is free software; you can redistribute it and/or modify it |
6 | * under the terms of the GNU General Public License version 2 only, as |
7 | * published by the Free Software Foundation. |
8 | * |
9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
12 | * version 2 for more details (a copy is included in the LICENSE file that |
13 | * accompanied this code). |
14 | * |
15 | * You should have received a copy of the GNU General Public License version |
16 | * 2 along with this work; if not, write to the Free Software Foundation, |
17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
18 | * |
19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 | * or visit www.oracle.com if you need additional information or have any |
21 | * questions. |
22 | * |
23 | */ |
24 | |
25 | #include "precompiled.hpp" |
26 | #include "jvm.h" |
27 | #include "cds/archiveUtils.hpp" |
28 | #include "cds/classListWriter.hpp" |
29 | #include "cds/metaspaceShared.hpp" |
30 | #include "classfile/classFileParser.hpp" |
31 | #include "classfile/classFileStream.hpp" |
32 | #include "classfile/classLoader.hpp" |
33 | #include "classfile/classLoaderData.inline.hpp" |
34 | #include "classfile/javaClasses.hpp" |
35 | #include "classfile/moduleEntry.hpp" |
36 | #include "classfile/resolutionErrors.hpp" |
37 | #include "classfile/symbolTable.hpp" |
38 | #include "classfile/systemDictionary.hpp" |
39 | #include "classfile/systemDictionaryShared.hpp" |
40 | #include "classfile/verifier.hpp" |
41 | #include "classfile/vmClasses.hpp" |
42 | #include "classfile/vmSymbols.hpp" |
43 | #include "code/codeCache.hpp" |
44 | #include "code/dependencyContext.hpp" |
45 | #include "compiler/compilationPolicy.hpp" |
46 | #include "compiler/compileBroker.hpp" |
47 | #include "gc/shared/collectedHeap.inline.hpp" |
48 | #include "interpreter/oopMapCache.hpp" |
49 | #include "interpreter/rewriter.hpp" |
50 | #include "jvmtifiles/jvmti.h" |
51 | #include "logging/log.hpp" |
52 | #include "logging/logMessage.hpp" |
53 | #include "logging/logStream.hpp" |
54 | #include "memory/allocation.inline.hpp" |
55 | #include "memory/iterator.inline.hpp" |
56 | #include "memory/metadataFactory.hpp" |
57 | #include "memory/metaspaceClosure.hpp" |
58 | #include "memory/oopFactory.hpp" |
59 | #include "memory/resourceArea.hpp" |
60 | #include "memory/universe.hpp" |
61 | #include "oops/fieldStreams.inline.hpp" |
62 | #include "oops/constantPool.hpp" |
63 | #include "oops/instanceClassLoaderKlass.hpp" |
64 | #include "oops/instanceKlass.inline.hpp" |
65 | #include "oops/instanceMirrorKlass.hpp" |
66 | #include "oops/instanceOop.hpp" |
67 | #include "oops/klass.inline.hpp" |
68 | #include "oops/method.hpp" |
69 | #include "oops/oop.inline.hpp" |
70 | #include "oops/recordComponent.hpp" |
71 | #include "oops/symbol.hpp" |
72 | #include "prims/jvmtiExport.hpp" |
73 | #include "prims/jvmtiRedefineClasses.hpp" |
74 | #include "prims/jvmtiThreadState.hpp" |
75 | #include "prims/methodComparator.hpp" |
76 | #include "runtime/arguments.hpp" |
77 | #include "runtime/atomic.hpp" |
78 | #include "runtime/fieldDescriptor.inline.hpp" |
79 | #include "runtime/handles.inline.hpp" |
80 | #include "runtime/javaCalls.hpp" |
81 | #include "runtime/mutexLocker.hpp" |
82 | #include "runtime/orderAccess.hpp" |
83 | #include "runtime/reflectionUtils.hpp" |
84 | #include "runtime/thread.inline.hpp" |
85 | #include "services/classLoadingService.hpp" |
86 | #include "services/finalizerService.hpp" |
87 | #include "services/threadService.hpp" |
88 | #include "utilities/dtrace.hpp" |
89 | #include "utilities/events.hpp" |
90 | #include "utilities/macros.hpp" |
91 | #include "utilities/stringUtils.hpp" |
92 | #include "utilities/pair.hpp" |
93 | #ifdef COMPILER11 |
94 | #include "c1/c1_Compiler.hpp" |
95 | #endif |
96 | #if INCLUDE_JFR1 |
97 | #include "jfr/jfrEvents.hpp" |
98 | #endif |
99 | |
100 | #ifdef DTRACE_ENABLED |
101 | |
102 | |
103 | #define HOTSPOT_CLASS_INITIALIZATION_required HOTSPOT_CLASS_INITIALIZATION_REQUIRED |
104 | #define HOTSPOT_CLASS_INITIALIZATION_recursive HOTSPOT_CLASS_INITIALIZATION_RECURSIVE |
105 | #define HOTSPOT_CLASS_INITIALIZATION_concurrent HOTSPOT_CLASS_INITIALIZATION_CONCURRENT |
106 | #define HOTSPOT_CLASS_INITIALIZATION_erroneous HOTSPOT_CLASS_INITIALIZATION_ERRONEOUS |
107 | #define HOTSPOT_CLASS_INITIALIZATION_super__failed HOTSPOT_CLASS_INITIALIZATION_SUPER_FAILED |
108 | #define HOTSPOT_CLASS_INITIALIZATION_clinit HOTSPOT_CLASS_INITIALIZATION_CLINIT |
109 | #define HOTSPOT_CLASS_INITIALIZATION_error HOTSPOT_CLASS_INITIALIZATION_ERROR |
110 | #define HOTSPOT_CLASS_INITIALIZATION_end HOTSPOT_CLASS_INITIALIZATION_END |
111 | #define DTRACE_CLASSINIT_PROBE(type, thread_type) \ |
112 | { \ |
113 | char* data = NULL__null; \ |
114 | int len = 0; \ |
115 | Symbol* clss_name = name(); \ |
116 | if (clss_name != NULL__null) { \ |
117 | data = (char*)clss_name->bytes(); \ |
118 | len = clss_name->utf8_length(); \ |
119 | } \ |
120 | HOTSPOT_CLASS_INITIALIZATION_##type( \ |
121 | data, len, (void*)class_loader(), thread_type); \ |
122 | } |
123 | |
124 | #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) \ |
125 | { \ |
126 | char* data = NULL__null; \ |
127 | int len = 0; \ |
128 | Symbol* clss_name = name(); \ |
129 | if (clss_name != NULL__null) { \ |
130 | data = (char*)clss_name->bytes(); \ |
131 | len = clss_name->utf8_length(); \ |
132 | } \ |
133 | HOTSPOT_CLASS_INITIALIZATION_##type( \ |
134 | data, len, (void*)class_loader(), thread_type, wait); \ |
135 | } |
136 | |
137 | #else // ndef DTRACE_ENABLED |
138 | |
139 | #define DTRACE_CLASSINIT_PROBE(type, thread_type) |
140 | #define DTRACE_CLASSINIT_PROBE_WAIT(type, thread_type, wait) |
141 | |
142 | #endif // ndef DTRACE_ENABLED |
143 | |
144 | bool InstanceKlass::_finalization_enabled = true; |
145 | |
146 | static inline bool is_class_loader(const Symbol* class_name, |
147 | const ClassFileParser& parser) { |
148 | assert(class_name != NULL, "invariant")do { if (!(class_name != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 148, "assert(" "class_name != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); |
149 | |
150 | if (class_name == vmSymbols::java_lang_ClassLoader()) { |
151 | return true; |
152 | } |
153 | |
154 | if (vmClasses::ClassLoader_klass_loaded()) { |
155 | const Klass* const super_klass = parser.super_klass(); |
156 | if (super_klass != NULL__null) { |
157 | if (super_klass->is_subtype_of(vmClasses::ClassLoader_klass())) { |
158 | return true; |
159 | } |
160 | } |
161 | } |
162 | return false; |
163 | } |
164 | |
165 | // private: called to verify that k is a static member of this nest. |
166 | // We know that k is an instance class in the same package and hence the |
167 | // same classloader. |
168 | bool InstanceKlass::has_nest_member(JavaThread* current, InstanceKlass* k) const { |
169 | assert(!is_hidden(), "unexpected hidden class")do { if (!(!is_hidden())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 169, "assert(" "!is_hidden()" ") failed", "unexpected hidden class" ); ::breakpoint(); } } while (0); |
170 | if (_nest_members == NULL__null || _nest_members == Universe::the_empty_short_array()) { |
171 | if (log_is_enabled(Trace, class, nestmates)(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) { |
172 | ResourceMark rm(current); |
173 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Checked nest membership of %s in non-nest-host class %s", |
174 | k->external_name(), this->external_name()); |
175 | } |
176 | return false; |
177 | } |
178 | |
179 | if (log_is_enabled(Trace, class, nestmates)(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) { |
180 | ResourceMark rm(current); |
181 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Checking nest membership of %s in %s", |
182 | k->external_name(), this->external_name()); |
183 | } |
184 | |
185 | // Check for the named class in _nest_members. |
186 | // We don't resolve, or load, any classes. |
187 | for (int i = 0; i < _nest_members->length(); i++) { |
188 | int cp_index = _nest_members->at(i); |
189 | Symbol* name = _constants->klass_name_at(cp_index); |
190 | if (name == k->name()) { |
191 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("- named class found at nest_members[%d] => cp[%d]", i, cp_index); |
192 | return true; |
193 | } |
194 | } |
195 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("- class is NOT a nest member!"); |
196 | return false; |
197 | } |
198 | |
199 | // Called to verify that k is a permitted subclass of this class |
200 | bool InstanceKlass::has_as_permitted_subclass(const InstanceKlass* k) const { |
201 | Thread* current = Thread::current(); |
202 | assert(k != NULL, "sanity check")do { if (!(k != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 202, "assert(" "k != __null" ") failed", "sanity check"); :: breakpoint(); } } while (0); |
203 | assert(_permitted_subclasses != NULL && _permitted_subclasses != Universe::the_empty_short_array(),do { if (!(_permitted_subclasses != __null && _permitted_subclasses != Universe::the_empty_short_array())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 204, "assert(" "_permitted_subclasses != __null && _permitted_subclasses != Universe::the_empty_short_array()" ") failed", "unexpected empty _permitted_subclasses array"); ::breakpoint(); } } while (0) |
204 | "unexpected empty _permitted_subclasses array")do { if (!(_permitted_subclasses != __null && _permitted_subclasses != Universe::the_empty_short_array())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 204, "assert(" "_permitted_subclasses != __null && _permitted_subclasses != Universe::the_empty_short_array()" ") failed", "unexpected empty _permitted_subclasses array"); ::breakpoint(); } } while (0); |
205 | |
206 | if (log_is_enabled(Trace, class, sealed)(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) { |
207 | ResourceMark rm(current); |
208 | log_trace(class, sealed)(!(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_sealed), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Checking for permitted subclass of %s in %s", |
209 | k->external_name(), this->external_name()); |
210 | } |
211 | |
212 | // Check that the class and its super are in the same module. |
213 | if (k->module() != this->module()) { |
214 | ResourceMark rm(current); |
215 | log_trace(class, sealed)(!(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_sealed), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Check failed for same module of permitted subclass %s and sealed class %s", |
216 | k->external_name(), this->external_name()); |
217 | return false; |
218 | } |
219 | |
220 | if (!k->is_public() && !is_same_class_package(k)) { |
221 | ResourceMark rm(current); |
222 | log_trace(class, sealed)(!(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_sealed), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Check failed, subclass %s not public and not in the same package as sealed class %s", |
223 | k->external_name(), this->external_name()); |
224 | return false; |
225 | } |
226 | |
227 | for (int i = 0; i < _permitted_subclasses->length(); i++) { |
228 | int cp_index = _permitted_subclasses->at(i); |
229 | Symbol* name = _constants->klass_name_at(cp_index); |
230 | if (name == k->name()) { |
231 | log_trace(class, sealed)(!(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_sealed), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("- Found it at permitted_subclasses[%d] => cp[%d]", i, cp_index); |
232 | return true; |
233 | } |
234 | } |
235 | log_trace(class, sealed)(!(LogImpl<(LogTag::_class), (LogTag::_sealed), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_sealed), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("- class is NOT a permitted subclass!"); |
236 | return false; |
237 | } |
238 | |
239 | // Return nest-host class, resolving, validating and saving it if needed. |
240 | // In cases where this is called from a thread that cannot do classloading |
241 | // (such as a native JIT thread) then we simply return NULL, which in turn |
242 | // causes the access check to return false. Such code will retry the access |
243 | // from a more suitable environment later. Otherwise the _nest_host is always |
244 | // set once this method returns. |
245 | // Any errors from nest-host resolution must be preserved so they can be queried |
246 | // from higher-level access checking code, and reported as part of access checking |
247 | // exceptions. |
248 | // VirtualMachineErrors are propagated with a NULL return. |
249 | // Under any conditions where the _nest_host can be set to non-NULL the resulting |
250 | // value of it and, if applicable, the nest host resolution/validation error, |
251 | // are idempotent. |
252 | InstanceKlass* InstanceKlass::nest_host(TRAPSJavaThread* __the_thread__) { |
253 | InstanceKlass* nest_host_k = _nest_host; |
254 | if (nest_host_k != NULL__null) { |
255 | return nest_host_k; |
256 | } |
257 | |
258 | ResourceMark rm(THREAD__the_thread__); |
259 | |
260 | // need to resolve and save our nest-host class. |
261 | if (_nest_host_index != 0) { // we have a real nest_host |
262 | // Before trying to resolve check if we're in a suitable context |
263 | bool can_resolve = THREAD__the_thread__->can_call_java(); |
264 | if (!can_resolve && !_constants->tag_at(_nest_host_index).is_klass()) { |
265 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Rejected resolution of nest-host of %s in unsuitable thread", |
266 | this->external_name()); |
267 | return NULL__null; // sentinel to say "try again from a different context" |
268 | } |
269 | |
270 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Resolving nest-host of %s using cp entry for %s", |
271 | this->external_name(), |
272 | _constants->klass_name_at(_nest_host_index)->as_C_string()); |
273 | |
274 | Klass* k = _constants->klass_at(_nest_host_index, THREAD__the_thread__); |
275 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { |
276 | if (PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())->is_a(vmClasses::VirtualMachineError_klass())) { |
277 | return NULL__null; // propagate VMEs |
278 | } |
279 | stringStream ss; |
280 | char* target_host_class = _constants->klass_name_at(_nest_host_index)->as_C_string(); |
281 | ss.print("Nest host resolution of %s with host %s failed: ", |
282 | this->external_name(), target_host_class); |
283 | java_lang_Throwable::print(PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception()), &ss); |
284 | const char* msg = ss.as_string(true /* on C-heap */); |
285 | constantPoolHandle cph(THREAD__the_thread__, constants()); |
286 | SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg); |
287 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
288 | |
289 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("%s", msg); |
290 | } else { |
291 | // A valid nest-host is an instance class in the current package that lists this |
292 | // class as a nest member. If any of these conditions are not met the class is |
293 | // its own nest-host. |
294 | const char* error = NULL__null; |
295 | |
296 | // JVMS 5.4.4 indicates package check comes first |
297 | if (is_same_class_package(k)) { |
298 | // Now check actual membership. We can't be a member if our "host" is |
299 | // not an instance class. |
300 | if (k->is_instance_klass()) { |
301 | nest_host_k = InstanceKlass::cast(k); |
302 | bool is_member = nest_host_k->has_nest_member(THREAD__the_thread__, this); |
303 | if (is_member) { |
304 | _nest_host = nest_host_k; // save resolved nest-host value |
305 | |
306 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Resolved nest-host of %s to %s", |
307 | this->external_name(), k->external_name()); |
308 | return nest_host_k; |
309 | } else { |
310 | error = "current type is not listed as a nest member"; |
311 | } |
312 | } else { |
313 | error = "host is not an instance class"; |
314 | } |
315 | } else { |
316 | error = "types are in different packages"; |
317 | } |
318 | |
319 | // something went wrong, so record what and log it |
320 | { |
321 | stringStream ss; |
322 | ss.print("Type %s (loader: %s) is not a nest member of type %s (loader: %s): %s", |
323 | this->external_name(), |
324 | this->class_loader_data()->loader_name_and_id(), |
325 | k->external_name(), |
326 | k->class_loader_data()->loader_name_and_id(), |
327 | error); |
328 | const char* msg = ss.as_string(true /* on C-heap */); |
329 | constantPoolHandle cph(THREAD__the_thread__, constants()); |
330 | SystemDictionary::add_nest_host_error(cph, _nest_host_index, msg); |
331 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("%s", msg); |
332 | } |
333 | } |
334 | } else { |
335 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Type %s is not part of a nest: setting nest-host to self", |
336 | this->external_name()); |
337 | } |
338 | |
339 | // Either not in an explicit nest, or else an error occurred, so |
340 | // the nest-host is set to `this`. Any thread that sees this assignment |
341 | // will also see any setting of nest_host_error(), if applicable. |
342 | return (_nest_host = this); |
343 | } |
344 | |
345 | // Dynamic nest member support: set this class's nest host to the given class. |
346 | // This occurs as part of the class definition, as soon as the instanceKlass |
347 | // has been created and doesn't require further resolution. The code: |
348 | // lookup().defineHiddenClass(bytes_for_X, NESTMATE); |
349 | // results in: |
350 | // class_of_X.set_nest_host(lookup().lookupClass().getNestHost()) |
351 | // If it has an explicit _nest_host_index or _nest_members, these will be ignored. |
352 | // We also know the "host" is a valid nest-host in the same package so we can |
353 | // assert some of those facts. |
354 | void InstanceKlass::set_nest_host(InstanceKlass* host) { |
355 | assert(is_hidden(), "must be a hidden class")do { if (!(is_hidden())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 355, "assert(" "is_hidden()" ") failed", "must be a hidden class" ); ::breakpoint(); } } while (0); |
356 | assert(host != NULL, "NULL nest host specified")do { if (!(host != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 356, "assert(" "host != __null" ") failed", "NULL nest host specified" ); ::breakpoint(); } } while (0); |
357 | assert(_nest_host == NULL, "current class has resolved nest-host")do { if (!(_nest_host == __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 357, "assert(" "_nest_host == __null" ") failed", "current class has resolved nest-host" ); ::breakpoint(); } } while (0); |
358 | assert(nest_host_error() == NULL, "unexpected nest host resolution error exists: %s",do { if (!(nest_host_error() == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 359, "assert(" "nest_host_error() == __null" ") failed", "unexpected nest host resolution error exists: %s" , nest_host_error()); ::breakpoint(); } } while (0) |
359 | nest_host_error())do { if (!(nest_host_error() == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 359, "assert(" "nest_host_error() == __null" ") failed", "unexpected nest host resolution error exists: %s" , nest_host_error()); ::breakpoint(); } } while (0); |
360 | assert((host->_nest_host == NULL && host->_nest_host_index == 0) ||do { if (!((host->_nest_host == __null && host-> _nest_host_index == 0) || (host->_nest_host == host))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 361, "assert(" "(host->_nest_host == __null && host->_nest_host_index == 0) || (host->_nest_host == host)" ") failed", "proposed host is not a valid nest-host"); ::breakpoint (); } } while (0) |
361 | (host->_nest_host == host), "proposed host is not a valid nest-host")do { if (!((host->_nest_host == __null && host-> _nest_host_index == 0) || (host->_nest_host == host))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 361, "assert(" "(host->_nest_host == __null && host->_nest_host_index == 0) || (host->_nest_host == host)" ") failed", "proposed host is not a valid nest-host"); ::breakpoint (); } } while (0); |
362 | // Can't assert this as package is not set yet: |
363 | // assert(is_same_class_package(host), "proposed host is in wrong package"); |
364 | |
365 | if (log_is_enabled(Trace, class, nestmates)(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) { |
366 | ResourceMark rm; |
367 | const char* msg = ""; |
368 | // a hidden class does not expect a statically defined nest-host |
369 | if (_nest_host_index > 0) { |
370 | msg = "(the NestHost attribute in the current class is ignored)"; |
371 | } else if (_nest_members != NULL__null && _nest_members != Universe::the_empty_short_array()) { |
372 | msg = "(the NestMembers attribute in the current class is ignored)"; |
373 | } |
374 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Injected type %s into the nest of %s %s", |
375 | this->external_name(), |
376 | host->external_name(), |
377 | msg); |
378 | } |
379 | // set dynamic nest host |
380 | _nest_host = host; |
381 | // Record dependency to keep nest host from being unloaded before this class. |
382 | ClassLoaderData* this_key = class_loader_data(); |
383 | this_key->record_dependency(host); |
384 | } |
385 | |
386 | // check if 'this' and k are nestmates (same nest_host), or k is our nest_host, |
387 | // or we are k's nest_host - all of which is covered by comparing the two |
388 | // resolved_nest_hosts. |
389 | // Any exceptions (i.e. VMEs) are propagated. |
390 | bool InstanceKlass::has_nestmate_access_to(InstanceKlass* k, TRAPSJavaThread* __the_thread__) { |
391 | |
392 | assert(this != k, "this should be handled by higher-level code")do { if (!(this != k)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 392, "assert(" "this != k" ") failed", "this should be handled by higher-level code" ); ::breakpoint(); } } while (0); |
393 | |
394 | // Per JVMS 5.4.4 we first resolve and validate the current class, then |
395 | // the target class k. |
396 | |
397 | InstanceKlass* cur_host = nest_host(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
398 | if (cur_host == NULL__null) { |
399 | return false; |
400 | } |
401 | |
402 | Klass* k_nest_host = k->nest_host(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
403 | if (k_nest_host == NULL__null) { |
404 | return false; |
405 | } |
406 | |
407 | bool access = (cur_host == k_nest_host); |
408 | |
409 | ResourceMark rm(THREAD__the_thread__); |
410 | log_trace(class, nestmates)(!(LogImpl<(LogTag::_class), (LogTag::_nestmates), (LogTag ::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG)>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl <(LogTag::_class), (LogTag::_nestmates), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::write<LogLevel::Trace>("Class %s does %shave nestmate access to %s", |
411 | this->external_name(), |
412 | access ? "" : "NOT ", |
413 | k->external_name()); |
414 | return access; |
415 | } |
416 | |
417 | const char* InstanceKlass::nest_host_error() { |
418 | if (_nest_host_index == 0) { |
419 | return NULL__null; |
420 | } else { |
421 | constantPoolHandle cph(Thread::current(), constants()); |
422 | return SystemDictionary::find_nest_host_error(cph, (int)_nest_host_index); |
423 | } |
424 | } |
425 | |
426 | InstanceKlass* InstanceKlass::allocate_instance_klass(const ClassFileParser& parser, TRAPSJavaThread* __the_thread__) { |
427 | const int size = InstanceKlass::size(parser.vtable_size(), |
428 | parser.itable_size(), |
429 | nonstatic_oop_map_size(parser.total_oop_map_count()), |
430 | parser.is_interface()); |
431 | |
432 | const Symbol* const class_name = parser.class_name(); |
433 | assert(class_name != NULL, "invariant")do { if (!(class_name != __null)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 433, "assert(" "class_name != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); |
434 | ClassLoaderData* loader_data = parser.loader_data(); |
435 | assert(loader_data != NULL, "invariant")do { if (!(loader_data != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 435, "assert(" "loader_data != __null" ") failed", "invariant" ); ::breakpoint(); } } while (0); |
436 | |
437 | InstanceKlass* ik; |
438 | |
439 | // Allocation |
440 | if (REF_NONE == parser.reference_type()) { |
441 | if (class_name == vmSymbols::java_lang_Class()) { |
442 | // mirror |
443 | ik = new (loader_data, size, THREAD__the_thread__) InstanceMirrorKlass(parser); |
444 | } |
445 | else if (is_class_loader(class_name, parser)) { |
446 | // class loader |
447 | ik = new (loader_data, size, THREAD__the_thread__) InstanceClassLoaderKlass(parser); |
448 | } else { |
449 | // normal |
450 | ik = new (loader_data, size, THREAD__the_thread__) InstanceKlass(parser, InstanceKlass::_kind_other); |
451 | } |
452 | } else { |
453 | // reference |
454 | ik = new (loader_data, size, THREAD__the_thread__) InstanceRefKlass(parser); |
455 | } |
456 | |
457 | // Check for pending exception before adding to the loader data and incrementing |
458 | // class count. Can get OOM here. |
459 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { |
460 | return NULL__null; |
461 | } |
462 | |
463 | return ik; |
464 | } |
465 | |
466 | |
467 | // copy method ordering from resource area to Metaspace |
468 | void InstanceKlass::copy_method_ordering(const intArray* m, TRAPSJavaThread* __the_thread__) { |
469 | if (m != NULL__null) { |
470 | // allocate a new array and copy contents (memcpy?) |
471 | _method_ordering = MetadataFactory::new_array<int>(class_loader_data(), m->length(), CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
472 | for (int i = 0; i < m->length(); i++) { |
473 | _method_ordering->at_put(i, m->at(i)); |
474 | } |
475 | } else { |
476 | _method_ordering = Universe::the_empty_int_array(); |
477 | } |
478 | } |
479 | |
480 | // create a new array of vtable_indices for default methods |
481 | Array<int>* InstanceKlass::create_new_default_vtable_indices(int len, TRAPSJavaThread* __the_thread__) { |
482 | Array<int>* vtable_indices = MetadataFactory::new_array<int>(class_loader_data(), len, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
483 | assert(default_vtable_indices() == NULL, "only create once")do { if (!(default_vtable_indices() == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 483, "assert(" "default_vtable_indices() == __null" ") failed" , "only create once"); ::breakpoint(); } } while (0); |
484 | set_default_vtable_indices(vtable_indices); |
485 | return vtable_indices; |
486 | } |
487 | |
488 | InstanceKlass::InstanceKlass(const ClassFileParser& parser, unsigned kind, KlassID id) : |
489 | Klass(id), |
490 | _nest_members(NULL__null), |
491 | _nest_host(NULL__null), |
492 | _permitted_subclasses(NULL__null), |
493 | _record_components(NULL__null), |
494 | _static_field_size(parser.static_field_size()), |
495 | _nonstatic_oop_map_size(nonstatic_oop_map_size(parser.total_oop_map_count())), |
496 | _itable_len(parser.itable_size()), |
497 | _nest_host_index(0), |
498 | _init_state(allocated), |
499 | _reference_type(parser.reference_type()), |
500 | _init_thread(NULL__null) |
501 | { |
502 | set_vtable_length(parser.vtable_size()); |
503 | set_kind(kind); |
504 | set_access_flags(parser.access_flags()); |
505 | if (parser.is_hidden()) set_is_hidden(); |
506 | set_layout_helper(Klass::instance_layout_helper(parser.layout_size(), |
507 | false)); |
508 | |
509 | assert(NULL == _methods, "underlying memory not zeroed?")do { if (!(__null == _methods)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 509, "assert(" "__null == _methods" ") failed", "underlying memory not zeroed?" ); ::breakpoint(); } } while (0); |
510 | assert(is_instance_klass(), "is layout incorrect?")do { if (!(is_instance_klass())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 510, "assert(" "is_instance_klass()" ") failed", "is layout incorrect?" ); ::breakpoint(); } } while (0); |
511 | assert(size_helper() == parser.layout_size(), "incorrect size_helper?")do { if (!(size_helper() == parser.layout_size())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 511, "assert(" "size_helper() == parser.layout_size()" ") failed" , "incorrect size_helper?"); ::breakpoint(); } } while (0); |
512 | } |
513 | |
514 | void InstanceKlass::deallocate_methods(ClassLoaderData* loader_data, |
515 | Array<Method*>* methods) { |
516 | if (methods != NULL__null && methods != Universe::the_empty_method_array() && |
517 | !methods->is_shared()) { |
518 | for (int i = 0; i < methods->length(); i++) { |
519 | Method* method = methods->at(i); |
520 | if (method == NULL__null) continue; // maybe null if error processing |
521 | // Only want to delete methods that are not executing for RedefineClasses. |
522 | // The previous version will point to them so they're not totally dangling |
523 | assert (!method->on_stack(), "shouldn't be called with methods on stack")do { if (!(!method->on_stack())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 523, "assert(" "!method->on_stack()" ") failed", "shouldn't be called with methods on stack" ); ::breakpoint(); } } while (0); |
524 | MetadataFactory::free_metadata(loader_data, method); |
525 | } |
526 | MetadataFactory::free_array<Method*>(loader_data, methods); |
527 | } |
528 | } |
529 | |
530 | void InstanceKlass::deallocate_interfaces(ClassLoaderData* loader_data, |
531 | const Klass* super_klass, |
532 | Array<InstanceKlass*>* local_interfaces, |
533 | Array<InstanceKlass*>* transitive_interfaces) { |
534 | // Only deallocate transitive interfaces if not empty, same as super class |
535 | // or same as local interfaces. See code in parseClassFile. |
536 | Array<InstanceKlass*>* ti = transitive_interfaces; |
537 | if (ti != Universe::the_empty_instance_klass_array() && ti != local_interfaces) { |
538 | // check that the interfaces don't come from super class |
539 | Array<InstanceKlass*>* sti = (super_klass == NULL__null) ? NULL__null : |
540 | InstanceKlass::cast(super_klass)->transitive_interfaces(); |
541 | if (ti != sti && ti != NULL__null && !ti->is_shared()) { |
542 | MetadataFactory::free_array<InstanceKlass*>(loader_data, ti); |
543 | } |
544 | } |
545 | |
546 | // local interfaces can be empty |
547 | if (local_interfaces != Universe::the_empty_instance_klass_array() && |
548 | local_interfaces != NULL__null && !local_interfaces->is_shared()) { |
549 | MetadataFactory::free_array<InstanceKlass*>(loader_data, local_interfaces); |
550 | } |
551 | } |
552 | |
553 | void InstanceKlass::deallocate_record_components(ClassLoaderData* loader_data, |
554 | Array<RecordComponent*>* record_components) { |
555 | if (record_components != NULL__null && !record_components->is_shared()) { |
556 | for (int i = 0; i < record_components->length(); i++) { |
557 | RecordComponent* record_component = record_components->at(i); |
558 | MetadataFactory::free_metadata(loader_data, record_component); |
559 | } |
560 | MetadataFactory::free_array<RecordComponent*>(loader_data, record_components); |
561 | } |
562 | } |
563 | |
564 | // This function deallocates the metadata and C heap pointers that the |
565 | // InstanceKlass points to. |
566 | void InstanceKlass::deallocate_contents(ClassLoaderData* loader_data) { |
567 | |
568 | // Orphan the mirror first, CMS thinks it's still live. |
569 | if (java_mirror() != NULL__null) { |
570 | java_lang_Class::set_klass(java_mirror(), NULL__null); |
571 | } |
572 | |
573 | // Also remove mirror from handles |
574 | loader_data->remove_handle(_java_mirror); |
575 | |
576 | // Need to take this class off the class loader data list. |
577 | loader_data->remove_class(this); |
578 | |
579 | // The array_klass for this class is created later, after error handling. |
580 | // For class redefinition, we keep the original class so this scratch class |
581 | // doesn't have an array class. Either way, assert that there is nothing |
582 | // to deallocate. |
583 | assert(array_klasses() == NULL, "array classes shouldn't be created for this class yet")do { if (!(array_klasses() == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 583, "assert(" "array_klasses() == __null" ") failed", "array classes shouldn't be created for this class yet" ); ::breakpoint(); } } while (0); |
584 | |
585 | // Release C heap allocated data that this points to, which includes |
586 | // reference counting symbol names. |
587 | // Can't release the constant pool here because the constant pool can be |
588 | // deallocated separately from the InstanceKlass for default methods and |
589 | // redefine classes. |
590 | release_C_heap_structures(/* release_constant_pool */ false); |
591 | |
592 | deallocate_methods(loader_data, methods()); |
593 | set_methods(NULL__null); |
594 | |
595 | deallocate_record_components(loader_data, record_components()); |
596 | set_record_components(NULL__null); |
597 | |
598 | if (method_ordering() != NULL__null && |
599 | method_ordering() != Universe::the_empty_int_array() && |
600 | !method_ordering()->is_shared()) { |
601 | MetadataFactory::free_array<int>(loader_data, method_ordering()); |
602 | } |
603 | set_method_ordering(NULL__null); |
604 | |
605 | // default methods can be empty |
606 | if (default_methods() != NULL__null && |
607 | default_methods() != Universe::the_empty_method_array() && |
608 | !default_methods()->is_shared()) { |
609 | MetadataFactory::free_array<Method*>(loader_data, default_methods()); |
610 | } |
611 | // Do NOT deallocate the default methods, they are owned by superinterfaces. |
612 | set_default_methods(NULL__null); |
613 | |
614 | // default methods vtable indices can be empty |
615 | if (default_vtable_indices() != NULL__null && |
616 | !default_vtable_indices()->is_shared()) { |
617 | MetadataFactory::free_array<int>(loader_data, default_vtable_indices()); |
618 | } |
619 | set_default_vtable_indices(NULL__null); |
620 | |
621 | |
622 | // This array is in Klass, but remove it with the InstanceKlass since |
623 | // this place would be the only caller and it can share memory with transitive |
624 | // interfaces. |
625 | if (secondary_supers() != NULL__null && |
626 | secondary_supers() != Universe::the_empty_klass_array() && |
627 | // see comments in compute_secondary_supers about the following cast |
628 | (address)(secondary_supers()) != (address)(transitive_interfaces()) && |
629 | !secondary_supers()->is_shared()) { |
630 | MetadataFactory::free_array<Klass*>(loader_data, secondary_supers()); |
631 | } |
632 | set_secondary_supers(NULL__null); |
633 | |
634 | deallocate_interfaces(loader_data, super(), local_interfaces(), transitive_interfaces()); |
635 | set_transitive_interfaces(NULL__null); |
636 | set_local_interfaces(NULL__null); |
637 | |
638 | if (fields() != NULL__null && !fields()->is_shared()) { |
639 | MetadataFactory::free_array<jushort>(loader_data, fields()); |
640 | } |
641 | set_fields(NULL__null, 0); |
642 | |
643 | // If a method from a redefined class is using this constant pool, don't |
644 | // delete it, yet. The new class's previous version will point to this. |
645 | if (constants() != NULL__null) { |
646 | assert (!constants()->on_stack(), "shouldn't be called if anything is onstack")do { if (!(!constants()->on_stack())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 646, "assert(" "!constants()->on_stack()" ") failed", "shouldn't be called if anything is onstack" ); ::breakpoint(); } } while (0); |
647 | if (!constants()->is_shared()) { |
648 | MetadataFactory::free_metadata(loader_data, constants()); |
649 | } |
650 | // Delete any cached resolution errors for the constant pool |
651 | SystemDictionary::delete_resolution_error(constants()); |
652 | |
653 | set_constants(NULL__null); |
654 | } |
655 | |
656 | if (inner_classes() != NULL__null && |
657 | inner_classes() != Universe::the_empty_short_array() && |
658 | !inner_classes()->is_shared()) { |
659 | MetadataFactory::free_array<jushort>(loader_data, inner_classes()); |
660 | } |
661 | set_inner_classes(NULL__null); |
662 | |
663 | if (nest_members() != NULL__null && |
664 | nest_members() != Universe::the_empty_short_array() && |
665 | !nest_members()->is_shared()) { |
666 | MetadataFactory::free_array<jushort>(loader_data, nest_members()); |
667 | } |
668 | set_nest_members(NULL__null); |
669 | |
670 | if (permitted_subclasses() != NULL__null && |
671 | permitted_subclasses() != Universe::the_empty_short_array() && |
672 | !permitted_subclasses()->is_shared()) { |
673 | MetadataFactory::free_array<jushort>(loader_data, permitted_subclasses()); |
674 | } |
675 | set_permitted_subclasses(NULL__null); |
676 | |
677 | // We should deallocate the Annotations instance if it's not in shared spaces. |
678 | if (annotations() != NULL__null && !annotations()->is_shared()) { |
679 | MetadataFactory::free_metadata(loader_data, annotations()); |
680 | } |
681 | set_annotations(NULL__null); |
682 | |
683 | SystemDictionaryShared::handle_class_unloading(this); |
684 | } |
685 | |
686 | bool InstanceKlass::is_record() const { |
687 | return _record_components != NULL__null && |
688 | is_final() && |
689 | java_super() == vmClasses::Record_klass(); |
690 | } |
691 | |
692 | bool InstanceKlass::is_sealed() const { |
693 | return _permitted_subclasses != NULL__null && |
694 | _permitted_subclasses != Universe::the_empty_short_array(); |
695 | } |
696 | |
697 | bool InstanceKlass::should_be_initialized() const { |
698 | return !is_initialized(); |
699 | } |
700 | |
701 | klassItable InstanceKlass::itable() const { |
702 | return klassItable(const_cast<InstanceKlass*>(this)); |
703 | } |
704 | |
705 | void InstanceKlass::eager_initialize(Thread *thread) { |
706 | if (!EagerInitialization) return; |
707 | |
708 | if (this->is_not_initialized()) { |
709 | // abort if the the class has a class initializer |
710 | if (this->class_initializer() != NULL__null) return; |
711 | |
712 | // abort if it is java.lang.Object (initialization is handled in genesis) |
713 | Klass* super_klass = super(); |
714 | if (super_klass == NULL__null) return; |
715 | |
716 | // abort if the super class should be initialized |
717 | if (!InstanceKlass::cast(super_klass)->is_initialized()) return; |
718 | |
719 | // call body to expose the this pointer |
720 | eager_initialize_impl(); |
721 | } |
722 | } |
723 | |
724 | // JVMTI spec thinks there are signers and protection domain in the |
725 | // instanceKlass. These accessors pretend these fields are there. |
726 | // The hprof specification also thinks these fields are in InstanceKlass. |
727 | oop InstanceKlass::protection_domain() const { |
728 | // return the protection_domain from the mirror |
729 | return java_lang_Class::protection_domain(java_mirror()); |
730 | } |
731 | |
732 | objArrayOop InstanceKlass::signers() const { |
733 | // return the signers from the mirror |
734 | return java_lang_Class::signers(java_mirror()); |
735 | } |
736 | |
737 | oop InstanceKlass::init_lock() const { |
738 | // return the init lock from the mirror |
739 | oop lock = java_lang_Class::init_lock(java_mirror()); |
740 | // Prevent reordering with any access of initialization state |
741 | OrderAccess::loadload(); |
742 | assert(lock != NULL || !is_not_initialized(), // initialized or in_error statedo { if (!(lock != __null || !is_not_initialized())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 743, "assert(" "lock != __null || !is_not_initialized()" ") failed" , "only fully initialized state can have a null lock"); ::breakpoint (); } } while (0) |
743 | "only fully initialized state can have a null lock")do { if (!(lock != __null || !is_not_initialized())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 743, "assert(" "lock != __null || !is_not_initialized()" ") failed" , "only fully initialized state can have a null lock"); ::breakpoint (); } } while (0); |
744 | return lock; |
745 | } |
746 | |
747 | // Set the initialization lock to null so the object can be GC'ed. Any racing |
748 | // threads to get this lock will see a null lock and will not lock. |
749 | // That's okay because they all check for initialized state after getting |
750 | // the lock and return. |
751 | void InstanceKlass::fence_and_clear_init_lock() { |
752 | // make sure previous stores are all done, notably the init_state. |
753 | OrderAccess::storestore(); |
754 | java_lang_Class::clear_init_lock(java_mirror()); |
755 | assert(!is_not_initialized(), "class must be initialized now")do { if (!(!is_not_initialized())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 755, "assert(" "!is_not_initialized()" ") failed", "class must be initialized now" ); ::breakpoint(); } } while (0); |
756 | } |
757 | |
758 | void InstanceKlass::eager_initialize_impl() { |
759 | EXCEPTION_MARKExceptionMark __em; JavaThread* __the_thread__ = __em.thread( );; |
760 | HandleMark hm(THREAD__the_thread__); |
761 | Handle h_init_lock(THREAD__the_thread__, init_lock()); |
762 | ObjectLocker ol(h_init_lock, THREAD__the_thread__); |
763 | |
764 | // abort if someone beat us to the initialization |
765 | if (!is_not_initialized()) return; // note: not equivalent to is_initialized() |
766 | |
767 | ClassState old_state = init_state(); |
768 | link_class_impl(THREAD__the_thread__); |
769 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { |
770 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
771 | // Abort if linking the class throws an exception. |
772 | |
773 | // Use a test to avoid redundantly resetting the state if there's |
774 | // no change. Set_init_state() asserts that state changes make |
775 | // progress, whereas here we might just be spinning in place. |
776 | if (old_state != _init_state) |
777 | set_init_state(old_state); |
778 | } else { |
779 | // linking successfull, mark class as initialized |
780 | set_init_state(fully_initialized); |
781 | fence_and_clear_init_lock(); |
782 | // trace |
783 | if (log_is_enabled(Info, class, init)(LogImpl<(LogTag::_class), (LogTag::_init), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) { |
784 | ResourceMark rm(THREAD__the_thread__); |
785 | log_info(class, init)(!(LogImpl<(LogTag::_class), (LogTag::_init), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_init), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Info>("[Initialized %s without side effects]", external_name()); |
786 | } |
787 | } |
788 | } |
789 | |
790 | |
791 | // See "The Virtual Machine Specification" section 2.16.5 for a detailed explanation of the class initialization |
792 | // process. The step comments refers to the procedure described in that section. |
793 | // Note: implementation moved to static method to expose the this pointer. |
794 | void InstanceKlass::initialize(TRAPSJavaThread* __the_thread__) { |
795 | if (this->should_be_initialized()) { |
796 | initialize_impl(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
797 | // Note: at this point the class may be initialized |
798 | // OR it may be in the state of being initialized |
799 | // in case of recursive initialization! |
800 | } else { |
801 | assert(is_initialized(), "sanity check")do { if (!(is_initialized())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 801, "assert(" "is_initialized()" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
802 | } |
803 | } |
804 | |
805 | |
806 | bool InstanceKlass::verify_code(TRAPSJavaThread* __the_thread__) { |
807 | // 1) Verify the bytecodes |
808 | return Verifier::verify(this, should_verify_class(), THREAD__the_thread__); |
809 | } |
810 | |
811 | void InstanceKlass::link_class(TRAPSJavaThread* __the_thread__) { |
812 | assert(is_loaded(), "must be loaded")do { if (!(is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 812, "assert(" "is_loaded()" ") failed", "must be loaded"); ::breakpoint(); } } while (0); |
813 | if (!is_linked()) { |
814 | link_class_impl(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
815 | } |
816 | } |
817 | |
818 | // Called to verify that a class can link during initialization, without |
819 | // throwing a VerifyError. |
820 | bool InstanceKlass::link_class_or_fail(TRAPSJavaThread* __the_thread__) { |
821 | assert(is_loaded(), "must be loaded")do { if (!(is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 821, "assert(" "is_loaded()" ") failed", "must be loaded"); ::breakpoint(); } } while (0); |
822 | if (!is_linked()) { |
823 | link_class_impl(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
824 | } |
825 | return is_linked(); |
826 | } |
827 | |
828 | bool InstanceKlass::link_class_impl(TRAPSJavaThread* __the_thread__) { |
829 | if (DumpSharedSpaces && SystemDictionaryShared::has_class_failed_verification(this)) { |
830 | // This is for CDS dumping phase only -- we use the in_error_state to indicate that |
831 | // the class has failed verification. Throwing the NoClassDefFoundError here is just |
832 | // a convenient way to stop repeat attempts to verify the same (bad) class. |
833 | // |
834 | // Note that the NoClassDefFoundError is not part of the JLS, and should not be thrown |
835 | // if we are executing Java code. This is not a problem for CDS dumping phase since |
836 | // it doesn't execute any Java code. |
837 | ResourceMark rm(THREAD__the_thread__); |
838 | Exceptions::fthrow(THREAD_AND_LOCATION__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 838, |
839 | vmSymbols::java_lang_NoClassDefFoundError(), |
840 | "Class %s, or one of its supertypes, failed class initialization", |
841 | external_name()); |
842 | return false; |
843 | } |
844 | // return if already verified |
845 | if (is_linked()) { |
846 | return true; |
847 | } |
848 | |
849 | // Timing |
850 | // timer handles recursion |
851 | JavaThread* jt = THREAD__the_thread__; |
852 | |
853 | // link super class before linking this class |
854 | Klass* super_klass = super(); |
855 | if (super_klass != NULL__null) { |
856 | if (super_klass->is_interface()) { // check if super class is an interface |
857 | ResourceMark rm(THREAD__the_thread__); |
858 | Exceptions::fthrow( |
859 | THREAD_AND_LOCATION__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 859, |
860 | vmSymbols::java_lang_IncompatibleClassChangeError(), |
861 | "class %s has interface %s as super class", |
862 | external_name(), |
863 | super_klass->external_name() |
864 | ); |
865 | return false; |
866 | } |
867 | |
868 | InstanceKlass* ik_super = InstanceKlass::cast(super_klass); |
869 | ik_super->link_class_impl(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
870 | } |
871 | |
872 | // link all interfaces implemented by this class before linking this class |
873 | Array<InstanceKlass*>* interfaces = local_interfaces(); |
874 | int num_interfaces = interfaces->length(); |
875 | for (int index = 0; index < num_interfaces; index++) { |
876 | InstanceKlass* interk = interfaces->at(index); |
877 | interk->link_class_impl(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
878 | } |
879 | |
880 | // in case the class is linked in the process of linking its superclasses |
881 | if (is_linked()) { |
882 | return true; |
883 | } |
884 | |
885 | // trace only the link time for this klass that includes |
886 | // the verification time |
887 | PerfClassTraceTime vmtimer(ClassLoader::perf_class_link_time(), |
888 | ClassLoader::perf_class_link_selftime(), |
889 | ClassLoader::perf_classes_linked(), |
890 | jt->get_thread_stat()->perf_recursion_counts_addr(), |
891 | jt->get_thread_stat()->perf_timers_addr(), |
892 | PerfClassTraceTime::CLASS_LINK); |
893 | |
894 | // verification & rewriting |
895 | { |
896 | HandleMark hm(THREAD__the_thread__); |
897 | Handle h_init_lock(THREAD__the_thread__, init_lock()); |
898 | ObjectLocker ol(h_init_lock, jt); |
899 | // rewritten will have been set if loader constraint error found |
900 | // on an earlier link attempt |
901 | // don't verify or rewrite if already rewritten |
902 | // |
903 | |
904 | if (!is_linked()) { |
905 | if (!is_rewritten()) { |
906 | if (is_shared()) { |
907 | assert(!verified_at_dump_time(), "must be")do { if (!(!verified_at_dump_time())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 907, "assert(" "!verified_at_dump_time()" ") failed", "must be" ); ::breakpoint(); } } while (0); |
908 | } |
909 | { |
910 | bool verify_ok = verify_code(THREAD__the_thread__); |
911 | if (!verify_ok) { |
912 | return false; |
913 | } |
914 | } |
915 | |
916 | // Just in case a side-effect of verify linked this class already |
917 | // (which can sometimes happen since the verifier loads classes |
918 | // using custom class loaders, which are free to initialize things) |
919 | if (is_linked()) { |
920 | return true; |
921 | } |
922 | |
923 | // also sets rewritten |
924 | rewrite_class(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
925 | } else if (is_shared()) { |
926 | SystemDictionaryShared::check_verification_constraints(this, CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
927 | } |
928 | |
929 | // relocate jsrs and link methods after they are all rewritten |
930 | link_methods(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
931 | |
932 | // Initialize the vtable and interface table after |
933 | // methods have been rewritten since rewrite may |
934 | // fabricate new Method*s. |
935 | // also does loader constraint checking |
936 | // |
937 | // initialize_vtable and initialize_itable need to be rerun |
938 | // for a shared class if |
939 | // 1) the class is loaded by custom class loader or |
940 | // 2) the class is loaded by built-in class loader but failed to add archived loader constraints or |
941 | // 3) the class was not verified during dump time |
942 | bool need_init_table = true; |
943 | if (is_shared() && verified_at_dump_time() && |
944 | SystemDictionaryShared::check_linking_constraints(THREAD__the_thread__, this)) { |
945 | need_init_table = false; |
946 | } |
947 | if (need_init_table) { |
948 | vtable().initialize_vtable_and_check_constraints(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
949 | itable().initialize_itable_and_check_constraints(CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
950 | } |
951 | #ifdef ASSERT1 |
952 | vtable().verify(tty, true); |
953 | // In case itable verification is ever added. |
954 | // itable().verify(tty, true); |
955 | #endif |
956 | if (UseVtableBasedCHA) { |
957 | MutexLocker ml(THREAD__the_thread__, Compile_lock); |
958 | set_init_state(linked); |
959 | |
960 | // Now flush all code that assume the class is not linked. |
961 | if (Universe::is_fully_initialized()) { |
962 | CodeCache::flush_dependents_on(this); |
963 | } |
964 | } else { |
965 | set_init_state(linked); |
966 | } |
967 | if (JvmtiExport::should_post_class_prepare()) { |
968 | JvmtiExport::post_class_prepare(THREAD__the_thread__, this); |
969 | } |
970 | } |
971 | } |
972 | return true; |
973 | } |
974 | |
975 | // Rewrite the byte codes of all of the methods of a class. |
976 | // The rewriter must be called exactly once. Rewriting must happen after |
977 | // verification but before the first method of the class is executed. |
978 | void InstanceKlass::rewrite_class(TRAPSJavaThread* __the_thread__) { |
979 | assert(is_loaded(), "must be loaded")do { if (!(is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 979, "assert(" "is_loaded()" ") failed", "must be loaded"); ::breakpoint(); } } while (0); |
980 | if (is_rewritten()) { |
981 | assert(is_shared(), "rewriting an unshared class?")do { if (!(is_shared())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 981, "assert(" "is_shared()" ") failed", "rewriting an unshared class?" ); ::breakpoint(); } } while (0); |
982 | return; |
983 | } |
984 | Rewriter::rewrite(this, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
985 | set_rewritten(); |
986 | } |
987 | |
988 | // Now relocate and link method entry points after class is rewritten. |
989 | // This is outside is_rewritten flag. In case of an exception, it can be |
990 | // executed more than once. |
991 | void InstanceKlass::link_methods(TRAPSJavaThread* __the_thread__) { |
992 | int len = methods()->length(); |
993 | for (int i = len-1; i >= 0; i--) { |
994 | methodHandle m(THREAD__the_thread__, methods()->at(i)); |
995 | |
996 | // Set up method entry points for compiler and interpreter . |
997 | m->link_method(m, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
998 | } |
999 | } |
1000 | |
1001 | // Eagerly initialize superinterfaces that declare default methods (concrete instance: any access) |
1002 | void InstanceKlass::initialize_super_interfaces(TRAPSJavaThread* __the_thread__) { |
1003 | assert (has_nonstatic_concrete_methods(), "caller should have checked this")do { if (!(has_nonstatic_concrete_methods())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1003, "assert(" "has_nonstatic_concrete_methods()" ") failed" , "caller should have checked this"); ::breakpoint(); } } while (0); |
1004 | for (int i = 0; i < local_interfaces()->length(); ++i) { |
1005 | InstanceKlass* ik = local_interfaces()->at(i); |
1006 | |
1007 | // Initialization is depth first search ie. we start with top of the inheritance tree |
1008 | // has_nonstatic_concrete_methods drives searching superinterfaces since it |
1009 | // means has_nonstatic_concrete_methods in its superinterface hierarchy |
1010 | if (ik->has_nonstatic_concrete_methods()) { |
1011 | ik->initialize_super_interfaces(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1012 | } |
1013 | |
1014 | // Only initialize() interfaces that "declare" concrete methods. |
1015 | if (ik->should_be_initialized() && ik->declares_nonstatic_concrete_methods()) { |
1016 | ik->initialize(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1017 | } |
1018 | } |
1019 | } |
1020 | |
1021 | ResourceHashtable<const InstanceKlass*, OopHandle, 107, ResourceObj::C_HEAP, mtClass> |
1022 | _initialization_error_table; |
1023 | |
1024 | void InstanceKlass::add_initialization_error(JavaThread* current, Handle exception) { |
1025 | // Create the same exception with a message indicating the thread name, |
1026 | // and the StackTraceElements. |
1027 | // If the initialization error is OOM, this might not work, but if GC kicks in |
1028 | // this would be still be helpful. |
1029 | JavaThread* THREAD__the_thread__ = current; |
1030 | Handle cause = java_lang_Throwable::get_cause_with_stack_trace(exception, THREAD__the_thread__); |
1031 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) || cause.is_null()) { |
1032 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
1033 | return; |
1034 | } |
1035 | |
1036 | MutexLocker ml(THREAD__the_thread__, ClassInitError_lock); |
1037 | OopHandle elem = OopHandle(Universe::vm_global(), cause()); |
1038 | bool created = false; |
1039 | _initialization_error_table.put_if_absent(this, elem, &created); |
1040 | assert(created, "Initialization is single threaded")do { if (!(created)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1040, "assert(" "created" ") failed", "Initialization is single threaded" ); ::breakpoint(); } } while (0); |
1041 | ResourceMark rm(THREAD__the_thread__); |
1042 | log_trace(class, init)(!(LogImpl<(LogTag::_class), (LogTag::_init), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_init), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Initialization error added for class %s", external_name()); |
1043 | } |
1044 | |
1045 | oop InstanceKlass::get_initialization_error(JavaThread* current) { |
1046 | MutexLocker ml(current, ClassInitError_lock); |
1047 | OopHandle* h = _initialization_error_table.get(this); |
1048 | return (h != nullptr) ? h->resolve() : nullptr; |
1049 | } |
1050 | |
1051 | // Need to remove entries for unloaded classes. |
1052 | void InstanceKlass::clean_initialization_error_table() { |
1053 | struct InitErrorTableCleaner { |
1054 | bool do_entry(const InstanceKlass* ik, OopHandle h) { |
1055 | if (!ik->is_loader_alive()) { |
1056 | h.release(Universe::vm_global()); |
1057 | return true; |
1058 | } else { |
1059 | return false; |
1060 | } |
1061 | } |
1062 | }; |
1063 | |
1064 | assert_locked_or_safepoint(ClassInitError_lock); |
1065 | InitErrorTableCleaner cleaner; |
1066 | _initialization_error_table.unlink(&cleaner); |
1067 | } |
1068 | |
1069 | void InstanceKlass::initialize_impl(TRAPSJavaThread* __the_thread__) { |
1070 | HandleMark hm(THREAD__the_thread__); |
1071 | |
1072 | // Make sure klass is linked (verified) before initialization |
1073 | // A class could already be verified, since it has been reflected upon. |
1074 | link_class(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1075 | |
1076 | DTRACE_CLASSINIT_PROBE(required, -1); |
1077 | |
1078 | bool wait = false; |
1079 | |
1080 | JavaThread* jt = THREAD__the_thread__; |
1081 | |
1082 | // refer to the JVM book page 47 for description of steps |
1083 | // Step 1 |
1084 | { |
1085 | Handle h_init_lock(THREAD__the_thread__, init_lock()); |
1086 | ObjectLocker ol(h_init_lock, jt); |
1087 | |
1088 | // Step 2 |
1089 | // If we were to use wait() instead of waitInterruptibly() then |
1090 | // we might end up throwing IE from link/symbol resolution sites |
1091 | // that aren't expected to throw. This would wreak havoc. See 6320309. |
1092 | while (is_being_initialized() && !is_reentrant_initialization(jt)) { |
1093 | wait = true; |
1094 | jt->set_class_to_be_initialized(this); |
1095 | ol.wait_uninterruptibly(jt); |
1096 | jt->set_class_to_be_initialized(NULL__null); |
1097 | } |
1098 | |
1099 | // Step 3 |
1100 | if (is_being_initialized() && is_reentrant_initialization(jt)) { |
1101 | DTRACE_CLASSINIT_PROBE_WAIT(recursive, -1, wait); |
1102 | return; |
1103 | } |
1104 | |
1105 | // Step 4 |
1106 | if (is_initialized()) { |
1107 | DTRACE_CLASSINIT_PROBE_WAIT(concurrent, -1, wait); |
1108 | return; |
1109 | } |
1110 | |
1111 | // Step 5 |
1112 | if (is_in_error_state()) { |
1113 | DTRACE_CLASSINIT_PROBE_WAIT(erroneous, -1, wait); |
1114 | ResourceMark rm(THREAD__the_thread__); |
1115 | Handle cause(THREAD__the_thread__, get_initialization_error(THREAD__the_thread__)); |
1116 | |
1117 | stringStream ss; |
1118 | ss.print("Could not initialize class %s", external_name()); |
1119 | if (cause.is_null()) { |
1120 | THROW_MSG(vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1120, vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string ()); return; }; |
1121 | } else { |
1122 | THROW_MSG_CAUSE(vmSymbols::java_lang_NoClassDefFoundError(),{ Exceptions::_throw_msg_cause(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1123, vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string (), cause); return; } |
1123 | ss.as_string(), cause){ Exceptions::_throw_msg_cause(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1123, vmSymbols::java_lang_NoClassDefFoundError(), ss.as_string (), cause); return; }; |
1124 | } |
1125 | } |
1126 | |
1127 | // Step 6 |
1128 | set_init_state(being_initialized); |
1129 | set_init_thread(jt); |
1130 | } |
1131 | |
1132 | // Step 7 |
1133 | // Next, if C is a class rather than an interface, initialize it's super class and super |
1134 | // interfaces. |
1135 | if (!is_interface()) { |
1136 | Klass* super_klass = super(); |
1137 | if (super_klass != NULL__null && super_klass->should_be_initialized()) { |
1138 | super_klass->initialize(THREAD__the_thread__); |
1139 | } |
1140 | // If C implements any interface that declares a non-static, concrete method, |
1141 | // the initialization of C triggers initialization of its super interfaces. |
1142 | // Only need to recurse if has_nonstatic_concrete_methods which includes declaring and |
1143 | // having a superinterface that declares, non-static, concrete methods |
1144 | if (!HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception()) && has_nonstatic_concrete_methods()) { |
1145 | initialize_super_interfaces(THREAD__the_thread__); |
1146 | } |
1147 | |
1148 | // If any exceptions, complete abruptly, throwing the same exception as above. |
1149 | if (HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { |
1150 | Handle e(THREAD__the_thread__, PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())); |
1151 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
1152 | { |
1153 | EXCEPTION_MARKExceptionMark __em; JavaThread* __the_thread__ = __em.thread( );; |
1154 | add_initialization_error(THREAD__the_thread__, e); |
1155 | // Locks object, set state, and notify all waiting threads |
1156 | set_initialization_state_and_notify(initialization_error, THREAD__the_thread__); |
1157 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
1158 | } |
1159 | DTRACE_CLASSINIT_PROBE_WAIT(super__failed, -1, wait); |
1160 | THROW_OOP(e()){ Exceptions::_throw_oop(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1160, e()); return; }; |
1161 | } |
1162 | } |
1163 | |
1164 | |
1165 | // Step 8 |
1166 | { |
1167 | DTRACE_CLASSINIT_PROBE_WAIT(clinit, -1, wait); |
1168 | if (class_initializer() != NULL__null) { |
1169 | // Timer includes any side effects of class initialization (resolution, |
1170 | // etc), but not recursive entry into call_class_initializer(). |
1171 | PerfClassTraceTime timer(ClassLoader::perf_class_init_time(), |
1172 | ClassLoader::perf_class_init_selftime(), |
1173 | ClassLoader::perf_classes_inited(), |
1174 | jt->get_thread_stat()->perf_recursion_counts_addr(), |
1175 | jt->get_thread_stat()->perf_timers_addr(), |
1176 | PerfClassTraceTime::CLASS_CLINIT); |
1177 | call_class_initializer(THREAD__the_thread__); |
1178 | } else { |
1179 | // The elapsed time is so small it's not worth counting. |
1180 | if (UsePerfData) { |
1181 | ClassLoader::perf_classes_inited()->inc(); |
1182 | } |
1183 | call_class_initializer(THREAD__the_thread__); |
1184 | } |
1185 | } |
1186 | |
1187 | // Step 9 |
1188 | if (!HAS_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->has_pending_exception())) { |
1189 | set_initialization_state_and_notify(fully_initialized, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1190 | debug_only(vtable().verify(tty, true);)vtable().verify(tty, true); |
1191 | } |
1192 | else { |
1193 | // Step 10 and 11 |
1194 | Handle e(THREAD__the_thread__, PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->pending_exception())); |
1195 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); |
1196 | // JVMTI has already reported the pending exception |
1197 | // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
1198 | JvmtiExport::clear_detected_exception(jt); |
1199 | { |
1200 | EXCEPTION_MARKExceptionMark __em; JavaThread* __the_thread__ = __em.thread( );; |
1201 | add_initialization_error(THREAD__the_thread__, e); |
1202 | set_initialization_state_and_notify(initialization_error, THREAD__the_thread__); |
1203 | CLEAR_PENDING_EXCEPTION(((ThreadShadow*)__the_thread__)->clear_pending_exception( )); // ignore any exception thrown, class initialization error is thrown below |
1204 | // JVMTI has already reported the pending exception |
1205 | // JVMTI internal flag reset is needed in order to report ExceptionInInitializerError |
1206 | JvmtiExport::clear_detected_exception(jt); |
1207 | } |
1208 | DTRACE_CLASSINIT_PROBE_WAIT(error, -1, wait); |
1209 | if (e->is_a(vmClasses::Error_klass())) { |
1210 | THROW_OOP(e()){ Exceptions::_throw_oop(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1210, e()); return; }; |
1211 | } else { |
1212 | JavaCallArguments args(e); |
1213 | THROW_ARG(vmSymbols::java_lang_ExceptionInInitializerError(),{ Exceptions::_throw_args(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1215, vmSymbols::java_lang_ExceptionInInitializerError(), vmSymbols ::throwable_void_signature(), &args); return; } |
1214 | vmSymbols::throwable_void_signature(),{ Exceptions::_throw_args(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1215, vmSymbols::java_lang_ExceptionInInitializerError(), vmSymbols ::throwable_void_signature(), &args); return; } |
1215 | &args){ Exceptions::_throw_args(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1215, vmSymbols::java_lang_ExceptionInInitializerError(), vmSymbols ::throwable_void_signature(), &args); return; }; |
1216 | } |
1217 | } |
1218 | DTRACE_CLASSINIT_PROBE_WAIT(end, -1, wait); |
1219 | } |
1220 | |
1221 | |
1222 | void InstanceKlass::set_initialization_state_and_notify(ClassState state, TRAPSJavaThread* __the_thread__) { |
1223 | Handle h_init_lock(THREAD__the_thread__, init_lock()); |
1224 | if (h_init_lock() != NULL__null) { |
1225 | ObjectLocker ol(h_init_lock, THREAD__the_thread__); |
1226 | set_init_thread(NULL__null); // reset _init_thread before changing _init_state |
1227 | set_init_state(state); |
1228 | fence_and_clear_init_lock(); |
1229 | ol.notify_all(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1230 | } else { |
1231 | assert(h_init_lock() != NULL, "The initialization state should never be set twice")do { if (!(h_init_lock() != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1231, "assert(" "h_init_lock() != __null" ") failed", "The initialization state should never be set twice" ); ::breakpoint(); } } while (0); |
1232 | set_init_thread(NULL__null); // reset _init_thread before changing _init_state |
1233 | set_init_state(state); |
1234 | } |
1235 | } |
1236 | |
1237 | InstanceKlass* InstanceKlass::implementor() const { |
1238 | InstanceKlass* volatile* ik = adr_implementor(); |
1239 | if (ik == NULL__null) { |
1240 | return NULL__null; |
1241 | } else { |
1242 | // This load races with inserts, and therefore needs acquire. |
1243 | InstanceKlass* ikls = Atomic::load_acquire(ik); |
1244 | if (ikls != NULL__null && !ikls->is_loader_alive()) { |
1245 | return NULL__null; // don't return unloaded class |
1246 | } else { |
1247 | return ikls; |
1248 | } |
1249 | } |
1250 | } |
1251 | |
1252 | |
1253 | void InstanceKlass::set_implementor(InstanceKlass* ik) { |
1254 | assert_locked_or_safepoint(Compile_lock); |
1255 | assert(is_interface(), "not interface")do { if (!(is_interface())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1255, "assert(" "is_interface()" ") failed", "not interface" ); ::breakpoint(); } } while (0); |
1256 | InstanceKlass* volatile* addr = adr_implementor(); |
1257 | assert(addr != NULL, "null addr")do { if (!(addr != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1257, "assert(" "addr != __null" ") failed", "null addr"); :: breakpoint(); } } while (0); |
1258 | if (addr != NULL__null) { |
1259 | Atomic::release_store(addr, ik); |
1260 | } |
1261 | } |
1262 | |
1263 | int InstanceKlass::nof_implementors() const { |
1264 | InstanceKlass* ik = implementor(); |
1265 | if (ik == NULL__null) { |
1266 | return 0; |
1267 | } else if (ik != this) { |
1268 | return 1; |
1269 | } else { |
1270 | return 2; |
1271 | } |
1272 | } |
1273 | |
1274 | // The embedded _implementor field can only record one implementor. |
1275 | // When there are more than one implementors, the _implementor field |
1276 | // is set to the interface Klass* itself. Following are the possible |
1277 | // values for the _implementor field: |
1278 | // NULL - no implementor |
1279 | // implementor Klass* - one implementor |
1280 | // self - more than one implementor |
1281 | // |
1282 | // The _implementor field only exists for interfaces. |
1283 | void InstanceKlass::add_implementor(InstanceKlass* ik) { |
1284 | if (Universe::is_fully_initialized()) { |
1285 | assert_lock_strong(Compile_lock); |
1286 | } |
1287 | assert(is_interface(), "not interface")do { if (!(is_interface())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1287, "assert(" "is_interface()" ") failed", "not interface" ); ::breakpoint(); } } while (0); |
1288 | // Filter out my subinterfaces. |
1289 | // (Note: Interfaces are never on the subklass list.) |
1290 | if (ik->is_interface()) return; |
1291 | |
1292 | // Filter out subclasses whose supers already implement me. |
1293 | // (Note: CHA must walk subclasses of direct implementors |
1294 | // in order to locate indirect implementors.) |
1295 | InstanceKlass* super_ik = ik->java_super(); |
1296 | if (super_ik != NULL__null && super_ik->implements_interface(this)) |
1297 | // We only need to check one immediate superclass, since the |
1298 | // implements_interface query looks at transitive_interfaces. |
1299 | // Any supers of the super have the same (or fewer) transitive_interfaces. |
1300 | return; |
1301 | |
1302 | InstanceKlass* iklass = implementor(); |
1303 | if (iklass == NULL__null) { |
1304 | set_implementor(ik); |
1305 | } else if (iklass != this && iklass != ik) { |
1306 | // There is already an implementor. Use itself as an indicator of |
1307 | // more than one implementors. |
1308 | set_implementor(this); |
1309 | } |
1310 | |
1311 | // The implementor also implements the transitive_interfaces |
1312 | for (int index = 0; index < local_interfaces()->length(); index++) { |
1313 | local_interfaces()->at(index)->add_implementor(ik); |
1314 | } |
1315 | } |
1316 | |
1317 | void InstanceKlass::init_implementor() { |
1318 | if (is_interface()) { |
1319 | set_implementor(NULL__null); |
1320 | } |
1321 | } |
1322 | |
1323 | |
1324 | void InstanceKlass::process_interfaces() { |
1325 | // link this class into the implementors list of every interface it implements |
1326 | for (int i = local_interfaces()->length() - 1; i >= 0; i--) { |
1327 | assert(local_interfaces()->at(i)->is_klass(), "must be a klass")do { if (!(local_interfaces()->at(i)->is_klass())) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1327, "assert(" "local_interfaces()->at(i)->is_klass()" ") failed", "must be a klass"); ::breakpoint(); } } while (0 ); |
1328 | InstanceKlass* interf = local_interfaces()->at(i); |
1329 | assert(interf->is_interface(), "expected interface")do { if (!(interf->is_interface())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1329, "assert(" "interf->is_interface()" ") failed", "expected interface" ); ::breakpoint(); } } while (0); |
1330 | interf->add_implementor(this); |
1331 | } |
1332 | } |
1333 | |
1334 | bool InstanceKlass::can_be_primary_super_slow() const { |
1335 | if (is_interface()) |
1336 | return false; |
1337 | else |
1338 | return Klass::can_be_primary_super_slow(); |
1339 | } |
1340 | |
1341 | GrowableArray<Klass*>* InstanceKlass::compute_secondary_supers(int num_extra_slots, |
1342 | Array<InstanceKlass*>* transitive_interfaces) { |
1343 | // The secondaries are the implemented interfaces. |
1344 | Array<InstanceKlass*>* interfaces = transitive_interfaces; |
1345 | int num_secondaries = num_extra_slots + interfaces->length(); |
1346 | if (num_secondaries == 0) { |
1347 | // Must share this for correct bootstrapping! |
1348 | set_secondary_supers(Universe::the_empty_klass_array()); |
1349 | return NULL__null; |
1350 | } else if (num_extra_slots == 0) { |
1351 | // The secondary super list is exactly the same as the transitive interfaces, so |
1352 | // let's use it instead of making a copy. |
1353 | // Redefine classes has to be careful not to delete this! |
1354 | // We need the cast because Array<Klass*> is NOT a supertype of Array<InstanceKlass*>, |
1355 | // (but it's safe to do here because we won't write into _secondary_supers from this point on). |
1356 | set_secondary_supers((Array<Klass*>*)(address)interfaces); |
1357 | return NULL__null; |
1358 | } else { |
1359 | // Copy transitive interfaces to a temporary growable array to be constructed |
1360 | // into the secondary super list with extra slots. |
1361 | GrowableArray<Klass*>* secondaries = new GrowableArray<Klass*>(interfaces->length()); |
1362 | for (int i = 0; i < interfaces->length(); i++) { |
1363 | secondaries->push(interfaces->at(i)); |
1364 | } |
1365 | return secondaries; |
1366 | } |
1367 | } |
1368 | |
1369 | bool InstanceKlass::implements_interface(Klass* k) const { |
1370 | if (this == k) return true; |
1371 | assert(k->is_interface(), "should be an interface class")do { if (!(k->is_interface())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1371, "assert(" "k->is_interface()" ") failed", "should be an interface class" ); ::breakpoint(); } } while (0); |
1372 | for (int i = 0; i < transitive_interfaces()->length(); i++) { |
1373 | if (transitive_interfaces()->at(i) == k) { |
1374 | return true; |
1375 | } |
1376 | } |
1377 | return false; |
1378 | } |
1379 | |
1380 | bool InstanceKlass::is_same_or_direct_interface(Klass *k) const { |
1381 | // Verify direct super interface |
1382 | if (this == k) return true; |
1383 | assert(k->is_interface(), "should be an interface class")do { if (!(k->is_interface())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1383, "assert(" "k->is_interface()" ") failed", "should be an interface class" ); ::breakpoint(); } } while (0); |
1384 | for (int i = 0; i < local_interfaces()->length(); i++) { |
1385 | if (local_interfaces()->at(i) == k) { |
1386 | return true; |
1387 | } |
1388 | } |
1389 | return false; |
1390 | } |
1391 | |
1392 | objArrayOop InstanceKlass::allocate_objArray(int n, int length, TRAPSJavaThread* __the_thread__) { |
1393 | check_array_allocation_length(length, arrayOopDesc::max_array_length(T_OBJECT), CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1394 | size_t size = objArrayOopDesc::object_size(length); |
1395 | Klass* ak = array_klass(n, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1396 | objArrayOop o = (objArrayOop)Universe::heap()->array_allocate(ak, size, length, |
1397 | /* do_zero */ true, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1398 | return o; |
1399 | } |
1400 | |
1401 | instanceOop InstanceKlass::register_finalizer(instanceOop i, TRAPSJavaThread* __the_thread__) { |
1402 | if (TraceFinalizerRegistration) { |
1403 | tty->print("Registered "); |
1404 | i->print_value_on(tty); |
1405 | tty->print_cr(" (" INTPTR_FORMAT"0x%016" "l" "x" ") as finalizable", p2i(i)); |
1406 | } |
1407 | instanceHandle h_i(THREAD__the_thread__, i); |
1408 | // Pass the handle as argument, JavaCalls::call expects oop as jobjects |
1409 | JavaValue result(T_VOID); |
1410 | JavaCallArguments args(h_i); |
1411 | methodHandle mh(THREAD__the_thread__, Universe::finalizer_register_method()); |
1412 | JavaCalls::call(&result, mh, &args, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1413 | MANAGEMENT_ONLY(FinalizerService::on_register(h_i(), THREAD);)FinalizerService::on_register(h_i(), __the_thread__); |
1414 | return h_i(); |
1415 | } |
1416 | |
1417 | instanceOop InstanceKlass::allocate_instance(TRAPSJavaThread* __the_thread__) { |
1418 | bool has_finalizer_flag = has_finalizer(); // Query before possible GC |
1419 | size_t size = size_helper(); // Query before forming handle. |
1420 | |
1421 | instanceOop i; |
1422 | |
1423 | i = (instanceOop)Universe::heap()->obj_allocate(this, size, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1424 | if (has_finalizer_flag && !RegisterFinalizersAtInit) { |
1425 | i = register_finalizer(i, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1426 | } |
1427 | return i; |
1428 | } |
1429 | |
1430 | instanceHandle InstanceKlass::allocate_instance_handle(TRAPSJavaThread* __the_thread__) { |
1431 | return instanceHandle(THREAD__the_thread__, allocate_instance(THREAD__the_thread__)); |
1432 | } |
1433 | |
1434 | void InstanceKlass::check_valid_for_instantiation(bool throwError, TRAPSJavaThread* __the_thread__) { |
1435 | if (is_interface() || is_abstract()) { |
1436 | ResourceMark rm(THREAD__the_thread__); |
1437 | THROW_MSG(throwError ? vmSymbols::java_lang_InstantiationError(){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1438, throwError ? vmSymbols::java_lang_InstantiationError( ) : vmSymbols::java_lang_InstantiationException(), external_name ()); return; } |
1438 | : vmSymbols::java_lang_InstantiationException(), external_name()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1438, throwError ? vmSymbols::java_lang_InstantiationError( ) : vmSymbols::java_lang_InstantiationException(), external_name ()); return; }; |
1439 | } |
1440 | if (this == vmClasses::Class_klass()) { |
1441 | ResourceMark rm(THREAD__the_thread__); |
1442 | THROW_MSG(throwError ? vmSymbols::java_lang_IllegalAccessError(){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1443, throwError ? vmSymbols::java_lang_IllegalAccessError( ) : vmSymbols::java_lang_IllegalAccessException(), external_name ()); return; } |
1443 | : vmSymbols::java_lang_IllegalAccessException(), external_name()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1443, throwError ? vmSymbols::java_lang_IllegalAccessError( ) : vmSymbols::java_lang_IllegalAccessException(), external_name ()); return; }; |
1444 | } |
1445 | } |
1446 | |
1447 | Klass* InstanceKlass::array_klass(int n, TRAPSJavaThread* __the_thread__) { |
1448 | // Need load-acquire for lock-free read |
1449 | if (array_klasses_acquire() == NULL__null) { |
1450 | ResourceMark rm(THREAD__the_thread__); |
1451 | JavaThread *jt = THREAD__the_thread__; |
1452 | { |
1453 | // Atomic creation of array_klasses |
1454 | MutexLocker ma(THREAD__the_thread__, MultiArray_lock); |
1455 | |
1456 | // Check if update has already taken place |
1457 | if (array_klasses() == NULL__null) { |
1458 | ObjArrayKlass* k = ObjArrayKlass::allocate_objArray_klass(class_loader_data(), 1, this, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
1459 | // use 'release' to pair with lock-free load |
1460 | release_set_array_klasses(k); |
1461 | } |
1462 | } |
1463 | } |
1464 | // array_klasses() will always be set at this point |
1465 | ObjArrayKlass* oak = array_klasses(); |
1466 | return oak->array_klass(n, THREAD__the_thread__); |
1467 | } |
1468 | |
1469 | Klass* InstanceKlass::array_klass_or_null(int n) { |
1470 | // Need load-acquire for lock-free read |
1471 | ObjArrayKlass* oak = array_klasses_acquire(); |
1472 | if (oak == NULL__null) { |
1473 | return NULL__null; |
1474 | } else { |
1475 | return oak->array_klass_or_null(n); |
1476 | } |
1477 | } |
1478 | |
1479 | Klass* InstanceKlass::array_klass(TRAPSJavaThread* __the_thread__) { |
1480 | return array_klass(1, THREAD__the_thread__); |
1481 | } |
1482 | |
1483 | Klass* InstanceKlass::array_klass_or_null() { |
1484 | return array_klass_or_null(1); |
1485 | } |
1486 | |
1487 | static int call_class_initializer_counter = 0; // for debugging |
1488 | |
1489 | Method* InstanceKlass::class_initializer() const { |
1490 | Method* clinit = find_method( |
1491 | vmSymbols::class_initializer_name(), vmSymbols::void_method_signature()); |
1492 | if (clinit != NULL__null && clinit->has_valid_initializer_flags()) { |
1493 | return clinit; |
1494 | } |
1495 | return NULL__null; |
1496 | } |
1497 | |
1498 | void InstanceKlass::call_class_initializer(TRAPSJavaThread* __the_thread__) { |
1499 | if (ReplayCompiles && |
1500 | (ReplaySuppressInitializers == 1 || |
1501 | (ReplaySuppressInitializers >= 2 && class_loader() != NULL__null))) { |
1502 | // Hide the existence of the initializer for the purpose of replaying the compile |
1503 | return; |
1504 | } |
1505 | |
1506 | methodHandle h_method(THREAD__the_thread__, class_initializer()); |
1507 | assert(!is_initialized(), "we cannot initialize twice")do { if (!(!is_initialized())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1507, "assert(" "!is_initialized()" ") failed", "we cannot initialize twice" ); ::breakpoint(); } } while (0); |
1508 | LogTarget(Info, class, init)LogTargetImpl<LogLevel::Info, (LogTag::_class), (LogTag::_init ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) , (LogTag::__NO_TAG)> lt; |
1509 | if (lt.is_enabled()) { |
1510 | ResourceMark rm(THREAD__the_thread__); |
1511 | LogStream ls(lt); |
1512 | ls.print("%d Initializing ", call_class_initializer_counter++); |
1513 | name()->print_value_on(&ls); |
1514 | ls.print_cr("%s (" INTPTR_FORMAT"0x%016" "l" "x" ")", h_method() == NULL__null ? "(no method)" : "", p2i(this)); |
1515 | } |
1516 | if (h_method() != NULL__null) { |
1517 | JavaCallArguments args; // No arguments |
1518 | JavaValue result(T_VOID); |
1519 | JavaCalls::call(&result, h_method, &args, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); // Static call (no args) |
1520 | } |
1521 | } |
1522 | |
1523 | |
1524 | void InstanceKlass::mask_for(const methodHandle& method, int bci, |
1525 | InterpreterOopMap* entry_for) { |
1526 | // Lazily create the _oop_map_cache at first request |
1527 | // Lock-free access requires load_acquire. |
1528 | OopMapCache* oop_map_cache = Atomic::load_acquire(&_oop_map_cache); |
1529 | if (oop_map_cache == NULL__null) { |
1530 | MutexLocker x(OopMapCacheAlloc_lock); |
1531 | // Check if _oop_map_cache was allocated while we were waiting for this lock |
1532 | if ((oop_map_cache = _oop_map_cache) == NULL__null) { |
1533 | oop_map_cache = new OopMapCache(); |
1534 | // Ensure _oop_map_cache is stable, since it is examined without a lock |
1535 | Atomic::release_store(&_oop_map_cache, oop_map_cache); |
1536 | } |
1537 | } |
1538 | // _oop_map_cache is constant after init; lookup below does its own locking. |
1539 | oop_map_cache->lookup(method, bci, entry_for); |
1540 | } |
1541 | |
1542 | bool InstanceKlass::contains_field_offset(int offset) { |
1543 | fieldDescriptor fd; |
1544 | return find_field_from_offset(offset, false, &fd); |
1545 | } |
1546 | |
1547 | bool InstanceKlass::find_local_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
1548 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
1549 | Symbol* f_name = fs.name(); |
1550 | Symbol* f_sig = fs.signature(); |
1551 | if (f_name == name && f_sig == sig) { |
1552 | fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index()); |
1553 | return true; |
1554 | } |
1555 | } |
1556 | return false; |
1557 | } |
1558 | |
1559 | |
1560 | Klass* InstanceKlass::find_interface_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
1561 | const int n = local_interfaces()->length(); |
1562 | for (int i = 0; i < n; i++) { |
1563 | Klass* intf1 = local_interfaces()->at(i); |
1564 | assert(intf1->is_interface(), "just checking type")do { if (!(intf1->is_interface())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1564, "assert(" "intf1->is_interface()" ") failed", "just checking type" ); ::breakpoint(); } } while (0); |
1565 | // search for field in current interface |
1566 | if (InstanceKlass::cast(intf1)->find_local_field(name, sig, fd)) { |
1567 | assert(fd->is_static(), "interface field must be static")do { if (!(fd->is_static())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1567, "assert(" "fd->is_static()" ") failed", "interface field must be static" ); ::breakpoint(); } } while (0); |
1568 | return intf1; |
1569 | } |
1570 | // search for field in direct superinterfaces |
1571 | Klass* intf2 = InstanceKlass::cast(intf1)->find_interface_field(name, sig, fd); |
1572 | if (intf2 != NULL__null) return intf2; |
1573 | } |
1574 | // otherwise field lookup fails |
1575 | return NULL__null; |
1576 | } |
1577 | |
1578 | |
1579 | Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, fieldDescriptor* fd) const { |
1580 | // search order according to newest JVM spec (5.4.3.2, p.167). |
1581 | // 1) search for field in current klass |
1582 | if (find_local_field(name, sig, fd)) { |
1583 | return const_cast<InstanceKlass*>(this); |
1584 | } |
1585 | // 2) search for field recursively in direct superinterfaces |
1586 | { Klass* intf = find_interface_field(name, sig, fd); |
1587 | if (intf != NULL__null) return intf; |
1588 | } |
1589 | // 3) apply field lookup recursively if superclass exists |
1590 | { Klass* supr = super(); |
1591 | if (supr != NULL__null) return InstanceKlass::cast(supr)->find_field(name, sig, fd); |
1592 | } |
1593 | // 4) otherwise field lookup fails |
1594 | return NULL__null; |
1595 | } |
1596 | |
1597 | |
1598 | Klass* InstanceKlass::find_field(Symbol* name, Symbol* sig, bool is_static, fieldDescriptor* fd) const { |
1599 | // search order according to newest JVM spec (5.4.3.2, p.167). |
1600 | // 1) search for field in current klass |
1601 | if (find_local_field(name, sig, fd)) { |
1602 | if (fd->is_static() == is_static) return const_cast<InstanceKlass*>(this); |
1603 | } |
1604 | // 2) search for field recursively in direct superinterfaces |
1605 | if (is_static) { |
1606 | Klass* intf = find_interface_field(name, sig, fd); |
1607 | if (intf != NULL__null) return intf; |
1608 | } |
1609 | // 3) apply field lookup recursively if superclass exists |
1610 | { Klass* supr = super(); |
1611 | if (supr != NULL__null) return InstanceKlass::cast(supr)->find_field(name, sig, is_static, fd); |
1612 | } |
1613 | // 4) otherwise field lookup fails |
1614 | return NULL__null; |
1615 | } |
1616 | |
1617 | |
1618 | bool InstanceKlass::find_local_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
1619 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
1620 | if (fs.offset() == offset) { |
1621 | fd->reinitialize(const_cast<InstanceKlass*>(this), fs.index()); |
1622 | if (fd->is_static() == is_static) return true; |
1623 | } |
1624 | } |
1625 | return false; |
1626 | } |
1627 | |
1628 | |
1629 | bool InstanceKlass::find_field_from_offset(int offset, bool is_static, fieldDescriptor* fd) const { |
1630 | Klass* klass = const_cast<InstanceKlass*>(this); |
1631 | while (klass != NULL__null) { |
1632 | if (InstanceKlass::cast(klass)->find_local_field_from_offset(offset, is_static, fd)) { |
1633 | return true; |
1634 | } |
1635 | klass = klass->super(); |
1636 | } |
1637 | return false; |
1638 | } |
1639 | |
1640 | |
1641 | void InstanceKlass::methods_do(void f(Method* method)) { |
1642 | // Methods aren't stable until they are loaded. This can be read outside |
1643 | // a lock through the ClassLoaderData for profiling |
1644 | // Redefined scratch classes are on the list and need to be cleaned |
1645 | if (!is_loaded() && !is_scratch_class()) { |
1646 | return; |
1647 | } |
1648 | |
1649 | int len = methods()->length(); |
1650 | for (int index = 0; index < len; index++) { |
1651 | Method* m = methods()->at(index); |
1652 | assert(m->is_method(), "must be method")do { if (!(m->is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1652, "assert(" "m->is_method()" ") failed", "must be method" ); ::breakpoint(); } } while (0); |
1653 | f(m); |
1654 | } |
1655 | } |
1656 | |
1657 | |
1658 | void InstanceKlass::do_local_static_fields(FieldClosure* cl) { |
1659 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
1660 | if (fs.access_flags().is_static()) { |
1661 | fieldDescriptor& fd = fs.field_descriptor(); |
1662 | cl->do_field(&fd); |
1663 | } |
1664 | } |
1665 | } |
1666 | |
1667 | |
1668 | void InstanceKlass::do_local_static_fields(void f(fieldDescriptor*, Handle, TRAPSJavaThread* __the_thread__), Handle mirror, TRAPSJavaThread* __the_thread__) { |
1669 | for (JavaFieldStream fs(this); !fs.done(); fs.next()) { |
1670 | if (fs.access_flags().is_static()) { |
1671 | fieldDescriptor& fd = fs.field_descriptor(); |
1672 | f(&fd, mirror, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
1673 | } |
1674 | } |
1675 | } |
1676 | |
1677 | void InstanceKlass::do_nonstatic_fields(FieldClosure* cl) { |
1678 | InstanceKlass* super = superklass(); |
1679 | if (super != NULL__null) { |
1680 | super->do_nonstatic_fields(cl); |
1681 | } |
1682 | fieldDescriptor fd; |
1683 | int length = java_fields_count(); |
1684 | for (int i = 0; i < length; i += 1) { |
1685 | fd.reinitialize(this, i); |
1686 | if (!fd.is_static()) { |
1687 | cl->do_field(&fd); |
1688 | } |
1689 | } |
1690 | } |
1691 | |
1692 | // first in Pair is offset, second is index. |
1693 | static int compare_fields_by_offset(Pair<int,int>* a, Pair<int,int>* b) { |
1694 | return a->first - b->first; |
1695 | } |
1696 | |
1697 | void InstanceKlass::print_nonstatic_fields(FieldClosure* cl) { |
1698 | InstanceKlass* super = superklass(); |
1699 | if (super != NULL__null) { |
1700 | super->print_nonstatic_fields(cl); |
1701 | } |
1702 | ResourceMark rm; |
1703 | fieldDescriptor fd; |
1704 | // In DebugInfo nonstatic fields are sorted by offset. |
1705 | GrowableArray<Pair<int,int> > fields_sorted; |
1706 | int i = 0; |
1707 | for (AllFieldStream fs(this); !fs.done(); fs.next()) { |
1708 | if (!fs.access_flags().is_static()) { |
1709 | fd = fs.field_descriptor(); |
1710 | Pair<int,int> f(fs.offset(), fs.index()); |
1711 | fields_sorted.push(f); |
1712 | i++; |
1713 | } |
1714 | } |
1715 | if (i > 0) { |
1716 | int length = i; |
1717 | assert(length == fields_sorted.length(), "duh")do { if (!(length == fields_sorted.length())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1717, "assert(" "length == fields_sorted.length()" ") failed" , "duh"); ::breakpoint(); } } while (0); |
1718 | // _sort_Fn is defined in growableArray.hpp. |
1719 | fields_sorted.sort(compare_fields_by_offset); |
1720 | for (int i = 0; i < length; i++) { |
1721 | fd.reinitialize(this, fields_sorted.at(i).second); |
1722 | assert(!fd.is_static() && fd.offset() == fields_sorted.at(i).first, "only nonstatic fields")do { if (!(!fd.is_static() && fd.offset() == fields_sorted .at(i).first)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1722, "assert(" "!fd.is_static() && fd.offset() == fields_sorted.at(i).first" ") failed", "only nonstatic fields"); ::breakpoint(); } } while (0); |
1723 | cl->do_field(&fd); |
1724 | } |
1725 | } |
1726 | } |
1727 | |
1728 | #ifdef ASSERT1 |
1729 | static int linear_search(const Array<Method*>* methods, |
1730 | const Symbol* name, |
1731 | const Symbol* signature) { |
1732 | const int len = methods->length(); |
1733 | for (int index = 0; index < len; index++) { |
1734 | const Method* const m = methods->at(index); |
1735 | assert(m->is_method(), "must be method")do { if (!(m->is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1735, "assert(" "m->is_method()" ") failed", "must be method" ); ::breakpoint(); } } while (0); |
1736 | if (m->signature() == signature && m->name() == name) { |
1737 | return index; |
1738 | } |
1739 | } |
1740 | return -1; |
1741 | } |
1742 | #endif |
1743 | |
1744 | bool InstanceKlass::_disable_method_binary_search = false; |
1745 | |
1746 | NOINLINE__attribute__ ((noinline)) int linear_search(const Array<Method*>* methods, const Symbol* name) { |
1747 | int len = methods->length(); |
1748 | int l = 0; |
1749 | int h = len - 1; |
1750 | while (l <= h) { |
1751 | Method* m = methods->at(l); |
1752 | if (m->name() == name) { |
1753 | return l; |
1754 | } |
1755 | l++; |
1756 | } |
1757 | return -1; |
1758 | } |
1759 | |
1760 | inline int InstanceKlass::quick_search(const Array<Method*>* methods, const Symbol* name) { |
1761 | if (_disable_method_binary_search) { |
1762 | assert(DynamicDumpSharedSpaces, "must be")do { if (!(DynamicDumpSharedSpaces)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1762, "assert(" "DynamicDumpSharedSpaces" ") failed", "must be" ); ::breakpoint(); } } while (0); |
1763 | // At the final stage of dynamic dumping, the methods array may not be sorted |
1764 | // by ascending addresses of their names, so we can't use binary search anymore. |
1765 | // However, methods with the same name are still laid out consecutively inside the |
1766 | // methods array, so let's look for the first one that matches. |
1767 | return linear_search(methods, name); |
1768 | } |
1769 | |
1770 | int len = methods->length(); |
1771 | int l = 0; |
1772 | int h = len - 1; |
1773 | |
1774 | // methods are sorted by ascending addresses of their names, so do binary search |
1775 | while (l <= h) { |
1776 | int mid = (l + h) >> 1; |
1777 | Method* m = methods->at(mid); |
1778 | assert(m->is_method(), "must be method")do { if (!(m->is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1778, "assert(" "m->is_method()" ") failed", "must be method" ); ::breakpoint(); } } while (0); |
1779 | int res = m->name()->fast_compare(name); |
1780 | if (res == 0) { |
1781 | return mid; |
1782 | } else if (res < 0) { |
1783 | l = mid + 1; |
1784 | } else { |
1785 | h = mid - 1; |
1786 | } |
1787 | } |
1788 | return -1; |
1789 | } |
1790 | |
1791 | // find_method looks up the name/signature in the local methods array |
1792 | Method* InstanceKlass::find_method(const Symbol* name, |
1793 | const Symbol* signature) const { |
1794 | return find_method_impl(name, signature, |
1795 | OverpassLookupMode::find, |
1796 | StaticLookupMode::find, |
1797 | PrivateLookupMode::find); |
1798 | } |
1799 | |
1800 | Method* InstanceKlass::find_method_impl(const Symbol* name, |
1801 | const Symbol* signature, |
1802 | OverpassLookupMode overpass_mode, |
1803 | StaticLookupMode static_mode, |
1804 | PrivateLookupMode private_mode) const { |
1805 | return InstanceKlass::find_method_impl(methods(), |
1806 | name, |
1807 | signature, |
1808 | overpass_mode, |
1809 | static_mode, |
1810 | private_mode); |
1811 | } |
1812 | |
1813 | // find_instance_method looks up the name/signature in the local methods array |
1814 | // and skips over static methods |
1815 | Method* InstanceKlass::find_instance_method(const Array<Method*>* methods, |
1816 | const Symbol* name, |
1817 | const Symbol* signature, |
1818 | PrivateLookupMode private_mode) { |
1819 | Method* const meth = InstanceKlass::find_method_impl(methods, |
1820 | name, |
1821 | signature, |
1822 | OverpassLookupMode::find, |
1823 | StaticLookupMode::skip, |
1824 | private_mode); |
1825 | assert(((meth == NULL) || !meth->is_static()),do { if (!(((meth == __null) || !meth->is_static()))) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1826, "assert(" "((meth == __null) || !meth->is_static())" ") failed", "find_instance_method should have skipped statics" ); ::breakpoint(); } } while (0) |
1826 | "find_instance_method should have skipped statics")do { if (!(((meth == __null) || !meth->is_static()))) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1826, "assert(" "((meth == __null) || !meth->is_static())" ") failed", "find_instance_method should have skipped statics" ); ::breakpoint(); } } while (0); |
1827 | return meth; |
1828 | } |
1829 | |
1830 | // find_instance_method looks up the name/signature in the local methods array |
1831 | // and skips over static methods |
1832 | Method* InstanceKlass::find_instance_method(const Symbol* name, |
1833 | const Symbol* signature, |
1834 | PrivateLookupMode private_mode) const { |
1835 | return InstanceKlass::find_instance_method(methods(), name, signature, private_mode); |
1836 | } |
1837 | |
1838 | // Find looks up the name/signature in the local methods array |
1839 | // and filters on the overpass, static and private flags |
1840 | // This returns the first one found |
1841 | // note that the local methods array can have up to one overpass, one static |
1842 | // and one instance (private or not) with the same name/signature |
1843 | Method* InstanceKlass::find_local_method(const Symbol* name, |
1844 | const Symbol* signature, |
1845 | OverpassLookupMode overpass_mode, |
1846 | StaticLookupMode static_mode, |
1847 | PrivateLookupMode private_mode) const { |
1848 | return InstanceKlass::find_method_impl(methods(), |
1849 | name, |
1850 | signature, |
1851 | overpass_mode, |
1852 | static_mode, |
1853 | private_mode); |
1854 | } |
1855 | |
1856 | // Find looks up the name/signature in the local methods array |
1857 | // and filters on the overpass, static and private flags |
1858 | // This returns the first one found |
1859 | // note that the local methods array can have up to one overpass, one static |
1860 | // and one instance (private or not) with the same name/signature |
1861 | Method* InstanceKlass::find_local_method(const Array<Method*>* methods, |
1862 | const Symbol* name, |
1863 | const Symbol* signature, |
1864 | OverpassLookupMode overpass_mode, |
1865 | StaticLookupMode static_mode, |
1866 | PrivateLookupMode private_mode) { |
1867 | return InstanceKlass::find_method_impl(methods, |
1868 | name, |
1869 | signature, |
1870 | overpass_mode, |
1871 | static_mode, |
1872 | private_mode); |
1873 | } |
1874 | |
1875 | Method* InstanceKlass::find_method(const Array<Method*>* methods, |
1876 | const Symbol* name, |
1877 | const Symbol* signature) { |
1878 | return InstanceKlass::find_method_impl(methods, |
1879 | name, |
1880 | signature, |
1881 | OverpassLookupMode::find, |
1882 | StaticLookupMode::find, |
1883 | PrivateLookupMode::find); |
1884 | } |
1885 | |
1886 | Method* InstanceKlass::find_method_impl(const Array<Method*>* methods, |
1887 | const Symbol* name, |
1888 | const Symbol* signature, |
1889 | OverpassLookupMode overpass_mode, |
1890 | StaticLookupMode static_mode, |
1891 | PrivateLookupMode private_mode) { |
1892 | int hit = find_method_index(methods, name, signature, overpass_mode, static_mode, private_mode); |
1893 | return hit >= 0 ? methods->at(hit): NULL__null; |
1894 | } |
1895 | |
1896 | // true if method matches signature and conforms to skipping_X conditions. |
1897 | static bool method_matches(const Method* m, |
1898 | const Symbol* signature, |
1899 | bool skipping_overpass, |
1900 | bool skipping_static, |
1901 | bool skipping_private) { |
1902 | return ((m->signature() == signature) && |
1903 | (!skipping_overpass || !m->is_overpass()) && |
1904 | (!skipping_static || !m->is_static()) && |
1905 | (!skipping_private || !m->is_private())); |
1906 | } |
1907 | |
1908 | // Used directly for default_methods to find the index into the |
1909 | // default_vtable_indices, and indirectly by find_method |
1910 | // find_method_index looks in the local methods array to return the index |
1911 | // of the matching name/signature. If, overpass methods are being ignored, |
1912 | // the search continues to find a potential non-overpass match. This capability |
1913 | // is important during method resolution to prefer a static method, for example, |
1914 | // over an overpass method. |
1915 | // There is the possibility in any _method's array to have the same name/signature |
1916 | // for a static method, an overpass method and a local instance method |
1917 | // To correctly catch a given method, the search criteria may need |
1918 | // to explicitly skip the other two. For local instance methods, it |
1919 | // is often necessary to skip private methods |
1920 | int InstanceKlass::find_method_index(const Array<Method*>* methods, |
1921 | const Symbol* name, |
1922 | const Symbol* signature, |
1923 | OverpassLookupMode overpass_mode, |
1924 | StaticLookupMode static_mode, |
1925 | PrivateLookupMode private_mode) { |
1926 | const bool skipping_overpass = (overpass_mode == OverpassLookupMode::skip); |
1927 | const bool skipping_static = (static_mode == StaticLookupMode::skip); |
1928 | const bool skipping_private = (private_mode == PrivateLookupMode::skip); |
1929 | const int hit = quick_search(methods, name); |
1930 | if (hit != -1) { |
1931 | const Method* const m = methods->at(hit); |
1932 | |
1933 | // Do linear search to find matching signature. First, quick check |
1934 | // for common case, ignoring overpasses if requested. |
1935 | if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) { |
1936 | return hit; |
1937 | } |
1938 | |
1939 | // search downwards through overloaded methods |
1940 | int i; |
1941 | for (i = hit - 1; i >= 0; --i) { |
1942 | const Method* const m = methods->at(i); |
1943 | assert(m->is_method(), "must be method")do { if (!(m->is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1943, "assert(" "m->is_method()" ") failed", "must be method" ); ::breakpoint(); } } while (0); |
1944 | if (m->name() != name) { |
1945 | break; |
1946 | } |
1947 | if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) { |
1948 | return i; |
1949 | } |
1950 | } |
1951 | // search upwards |
1952 | for (i = hit + 1; i < methods->length(); ++i) { |
1953 | const Method* const m = methods->at(i); |
1954 | assert(m->is_method(), "must be method")do { if (!(m->is_method())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1954, "assert(" "m->is_method()" ") failed", "must be method" ); ::breakpoint(); } } while (0); |
1955 | if (m->name() != name) { |
1956 | break; |
1957 | } |
1958 | if (method_matches(m, signature, skipping_overpass, skipping_static, skipping_private)) { |
1959 | return i; |
1960 | } |
1961 | } |
1962 | // not found |
1963 | #ifdef ASSERT1 |
1964 | const int index = (skipping_overpass || skipping_static || skipping_private) ? -1 : |
1965 | linear_search(methods, name, signature); |
1966 | assert(-1 == index, "binary search should have found entry %d", index)do { if (!(-1 == index)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1966, "assert(" "-1 == index" ") failed", "binary search should have found entry %d" , index); ::breakpoint(); } } while (0); |
1967 | #endif |
1968 | } |
1969 | return -1; |
1970 | } |
1971 | |
1972 | int InstanceKlass::find_method_by_name(const Symbol* name, int* end) const { |
1973 | return find_method_by_name(methods(), name, end); |
1974 | } |
1975 | |
1976 | int InstanceKlass::find_method_by_name(const Array<Method*>* methods, |
1977 | const Symbol* name, |
1978 | int* end_ptr) { |
1979 | assert(end_ptr != NULL, "just checking")do { if (!(end_ptr != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 1979, "assert(" "end_ptr != __null" ") failed", "just checking" ); ::breakpoint(); } } while (0); |
1980 | int start = quick_search(methods, name); |
1981 | int end = start + 1; |
1982 | if (start != -1) { |
1983 | while (start - 1 >= 0 && (methods->at(start - 1))->name() == name) --start; |
1984 | while (end < methods->length() && (methods->at(end))->name() == name) ++end; |
1985 | *end_ptr = end; |
1986 | return start; |
1987 | } |
1988 | return -1; |
1989 | } |
1990 | |
1991 | // uncached_lookup_method searches both the local class methods array and all |
1992 | // superclasses methods arrays, skipping any overpass methods in superclasses, |
1993 | // and possibly skipping private methods. |
1994 | Method* InstanceKlass::uncached_lookup_method(const Symbol* name, |
1995 | const Symbol* signature, |
1996 | OverpassLookupMode overpass_mode, |
1997 | PrivateLookupMode private_mode) const { |
1998 | OverpassLookupMode overpass_local_mode = overpass_mode; |
1999 | const Klass* klass = this; |
2000 | while (klass != NULL__null) { |
2001 | Method* const method = InstanceKlass::cast(klass)->find_method_impl(name, |
2002 | signature, |
2003 | overpass_local_mode, |
2004 | StaticLookupMode::find, |
2005 | private_mode); |
2006 | if (method != NULL__null) { |
2007 | return method; |
2008 | } |
2009 | klass = klass->super(); |
2010 | overpass_local_mode = OverpassLookupMode::skip; // Always ignore overpass methods in superclasses |
2011 | } |
2012 | return NULL__null; |
2013 | } |
2014 | |
2015 | #ifdef ASSERT1 |
2016 | // search through class hierarchy and return true if this class or |
2017 | // one of the superclasses was redefined |
2018 | bool InstanceKlass::has_redefined_this_or_super() const { |
2019 | const Klass* klass = this; |
2020 | while (klass != NULL__null) { |
2021 | if (InstanceKlass::cast(klass)->has_been_redefined()) { |
2022 | return true; |
2023 | } |
2024 | klass = klass->super(); |
2025 | } |
2026 | return false; |
2027 | } |
2028 | #endif |
2029 | |
2030 | // lookup a method in the default methods list then in all transitive interfaces |
2031 | // Do NOT return private or static methods |
2032 | Method* InstanceKlass::lookup_method_in_ordered_interfaces(Symbol* name, |
2033 | Symbol* signature) const { |
2034 | Method* m = NULL__null; |
2035 | if (default_methods() != NULL__null) { |
2036 | m = find_method(default_methods(), name, signature); |
2037 | } |
2038 | // Look up interfaces |
2039 | if (m == NULL__null) { |
2040 | m = lookup_method_in_all_interfaces(name, signature, DefaultsLookupMode::find); |
2041 | } |
2042 | return m; |
2043 | } |
2044 | |
2045 | // lookup a method in all the interfaces that this class implements |
2046 | // Do NOT return private or static methods, new in JDK8 which are not externally visible |
2047 | // They should only be found in the initial InterfaceMethodRef |
2048 | Method* InstanceKlass::lookup_method_in_all_interfaces(Symbol* name, |
2049 | Symbol* signature, |
2050 | DefaultsLookupMode defaults_mode) const { |
2051 | Array<InstanceKlass*>* all_ifs = transitive_interfaces(); |
2052 | int num_ifs = all_ifs->length(); |
2053 | InstanceKlass *ik = NULL__null; |
2054 | for (int i = 0; i < num_ifs; i++) { |
2055 | ik = all_ifs->at(i); |
2056 | Method* m = ik->lookup_method(name, signature); |
2057 | if (m != NULL__null && m->is_public() && !m->is_static() && |
2058 | ((defaults_mode != DefaultsLookupMode::skip) || !m->is_default_method())) { |
2059 | return m; |
2060 | } |
2061 | } |
2062 | return NULL__null; |
2063 | } |
2064 | |
2065 | /* jni_id_for for jfieldIds only */ |
2066 | JNIid* InstanceKlass::jni_id_for(int offset) { |
2067 | MutexLocker ml(JfieldIdCreation_lock); |
2068 | JNIid* probe = jni_ids() == NULL__null ? NULL__null : jni_ids()->find(offset); |
2069 | if (probe == NULL__null) { |
2070 | // Allocate new static field identifier |
2071 | probe = new JNIid(this, offset, jni_ids()); |
2072 | set_jni_ids(probe); |
2073 | } |
2074 | return probe; |
2075 | } |
2076 | |
2077 | u2 InstanceKlass::enclosing_method_data(int offset) const { |
2078 | const Array<jushort>* const inner_class_list = inner_classes(); |
2079 | if (inner_class_list == NULL__null) { |
2080 | return 0; |
2081 | } |
2082 | const int length = inner_class_list->length(); |
2083 | if (length % inner_class_next_offset == 0) { |
2084 | return 0; |
2085 | } |
2086 | const int index = length - enclosing_method_attribute_size; |
2087 | assert(offset < enclosing_method_attribute_size, "invalid offset")do { if (!(offset < enclosing_method_attribute_size)) { (* g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2087, "assert(" "offset < enclosing_method_attribute_size" ") failed", "invalid offset"); ::breakpoint(); } } while (0); |
2088 | return inner_class_list->at(index + offset); |
2089 | } |
2090 | |
2091 | void InstanceKlass::set_enclosing_method_indices(u2 class_index, |
2092 | u2 method_index) { |
2093 | Array<jushort>* inner_class_list = inner_classes(); |
2094 | assert (inner_class_list != NULL, "_inner_classes list is not set up")do { if (!(inner_class_list != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2094, "assert(" "inner_class_list != __null" ") failed", "_inner_classes list is not set up" ); ::breakpoint(); } } while (0); |
2095 | int length = inner_class_list->length(); |
2096 | if (length % inner_class_next_offset == enclosing_method_attribute_size) { |
2097 | int index = length - enclosing_method_attribute_size; |
2098 | inner_class_list->at_put( |
2099 | index + enclosing_method_class_index_offset, class_index); |
2100 | inner_class_list->at_put( |
2101 | index + enclosing_method_method_index_offset, method_index); |
2102 | } |
2103 | } |
2104 | |
2105 | // Lookup or create a jmethodID. |
2106 | // This code is called by the VMThread and JavaThreads so the |
2107 | // locking has to be done very carefully to avoid deadlocks |
2108 | // and/or other cache consistency problems. |
2109 | // |
2110 | jmethodID InstanceKlass::get_jmethod_id(const methodHandle& method_h) { |
2111 | size_t idnum = (size_t)method_h->method_idnum(); |
2112 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
2113 | size_t length = 0; |
2114 | jmethodID id = NULL__null; |
2115 | |
2116 | // We use a double-check locking idiom here because this cache is |
2117 | // performance sensitive. In the normal system, this cache only |
2118 | // transitions from NULL to non-NULL which is safe because we use |
2119 | // release_set_methods_jmethod_ids() to advertise the new cache. |
2120 | // A partially constructed cache should never be seen by a racing |
2121 | // thread. We also use release_store() to save a new jmethodID |
2122 | // in the cache so a partially constructed jmethodID should never be |
2123 | // seen either. Cache reads of existing jmethodIDs proceed without a |
2124 | // lock, but cache writes of a new jmethodID requires uniqueness and |
2125 | // creation of the cache itself requires no leaks so a lock is |
2126 | // generally acquired in those two cases. |
2127 | // |
2128 | // If the RedefineClasses() API has been used, then this cache can |
2129 | // grow and we'll have transitions from non-NULL to bigger non-NULL. |
2130 | // Cache creation requires no leaks and we require safety between all |
2131 | // cache accesses and freeing of the old cache so a lock is generally |
2132 | // acquired when the RedefineClasses() API has been used. |
2133 | |
2134 | if (jmeths != NULL__null) { |
2135 | // the cache already exists |
2136 | if (!idnum_can_increment()) { |
2137 | // the cache can't grow so we can just get the current values |
2138 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
2139 | } else { |
2140 | // cache can grow so we have to be more careful |
2141 | if (Threads::number_of_threads() == 0 || |
2142 | SafepointSynchronize::is_at_safepoint()) { |
2143 | // we're single threaded or at a safepoint - no locking needed |
2144 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
2145 | } else { |
2146 | MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag); |
2147 | get_jmethod_id_length_value(jmeths, idnum, &length, &id); |
2148 | } |
2149 | } |
2150 | } |
2151 | // implied else: |
2152 | // we need to allocate a cache so default length and id values are good |
2153 | |
2154 | if (jmeths == NULL__null || // no cache yet |
2155 | length <= idnum || // cache is too short |
2156 | id == NULL__null) { // cache doesn't contain entry |
2157 | |
2158 | // This function can be called by the VMThread so we have to do all |
2159 | // things that might block on a safepoint before grabbing the lock. |
2160 | // Otherwise, we can deadlock with the VMThread or have a cache |
2161 | // consistency issue. These vars keep track of what we might have |
2162 | // to free after the lock is dropped. |
2163 | jmethodID to_dealloc_id = NULL__null; |
2164 | jmethodID* to_dealloc_jmeths = NULL__null; |
2165 | |
2166 | // may not allocate new_jmeths or use it if we allocate it |
2167 | jmethodID* new_jmeths = NULL__null; |
2168 | if (length <= idnum) { |
2169 | // allocate a new cache that might be used |
2170 | size_t size = MAX2(idnum+1, (size_t)idnum_allocated_count()); |
2171 | new_jmeths = NEW_C_HEAP_ARRAY(jmethodID, size+1, mtClass)(jmethodID*) (AllocateHeap((size+1) * sizeof(jmethodID), mtClass )); |
2172 | memset(new_jmeths, 0, (size+1)*sizeof(jmethodID)); |
2173 | // cache size is stored in element[0], other elements offset by one |
2174 | new_jmeths[0] = (jmethodID)size; |
2175 | } |
2176 | |
2177 | // allocate a new jmethodID that might be used |
2178 | jmethodID new_id = NULL__null; |
2179 | if (method_h->is_old() && !method_h->is_obsolete()) { |
2180 | // The method passed in is old (but not obsolete), we need to use the current version |
2181 | Method* current_method = method_with_idnum((int)idnum); |
2182 | assert(current_method != NULL, "old and but not obsolete, so should exist")do { if (!(current_method != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2182, "assert(" "current_method != __null" ") failed", "old and but not obsolete, so should exist" ); ::breakpoint(); } } while (0); |
2183 | new_id = Method::make_jmethod_id(class_loader_data(), current_method); |
2184 | } else { |
2185 | // It is the current version of the method or an obsolete method, |
2186 | // use the version passed in |
2187 | new_id = Method::make_jmethod_id(class_loader_data(), method_h()); |
2188 | } |
2189 | |
2190 | if (Threads::number_of_threads() == 0 || |
2191 | SafepointSynchronize::is_at_safepoint()) { |
2192 | // we're single threaded or at a safepoint - no locking needed |
2193 | id = get_jmethod_id_fetch_or_update(idnum, new_id, new_jmeths, |
2194 | &to_dealloc_id, &to_dealloc_jmeths); |
2195 | } else { |
2196 | MutexLocker ml(JmethodIdCreation_lock, Mutex::_no_safepoint_check_flag); |
2197 | id = get_jmethod_id_fetch_or_update(idnum, new_id, new_jmeths, |
2198 | &to_dealloc_id, &to_dealloc_jmeths); |
2199 | } |
2200 | |
2201 | // The lock has been dropped so we can free resources. |
2202 | // Free up either the old cache or the new cache if we allocated one. |
2203 | if (to_dealloc_jmeths != NULL__null) { |
2204 | FreeHeap(to_dealloc_jmeths); |
2205 | } |
2206 | // free up the new ID since it wasn't needed |
2207 | if (to_dealloc_id != NULL__null) { |
2208 | Method::destroy_jmethod_id(class_loader_data(), to_dealloc_id); |
2209 | } |
2210 | } |
2211 | return id; |
2212 | } |
2213 | |
2214 | // Figure out how many jmethodIDs haven't been allocated, and make |
2215 | // sure space for them is pre-allocated. This makes getting all |
2216 | // method ids much, much faster with classes with more than 8 |
2217 | // methods, and has a *substantial* effect on performance with jvmti |
2218 | // code that loads all jmethodIDs for all classes. |
2219 | void InstanceKlass::ensure_space_for_methodids(int start_offset) { |
2220 | int new_jmeths = 0; |
2221 | int length = methods()->length(); |
2222 | for (int index = start_offset; index < length; index++) { |
2223 | Method* m = methods()->at(index); |
2224 | jmethodID id = m->find_jmethod_id_or_null(); |
2225 | if (id == NULL__null) { |
2226 | new_jmeths++; |
2227 | } |
2228 | } |
2229 | if (new_jmeths != 0) { |
2230 | Method::ensure_jmethod_ids(class_loader_data(), new_jmeths); |
2231 | } |
2232 | } |
2233 | |
2234 | // Common code to fetch the jmethodID from the cache or update the |
2235 | // cache with the new jmethodID. This function should never do anything |
2236 | // that causes the caller to go to a safepoint or we can deadlock with |
2237 | // the VMThread or have cache consistency issues. |
2238 | // |
2239 | jmethodID InstanceKlass::get_jmethod_id_fetch_or_update( |
2240 | size_t idnum, jmethodID new_id, |
2241 | jmethodID* new_jmeths, jmethodID* to_dealloc_id_p, |
2242 | jmethodID** to_dealloc_jmeths_p) { |
2243 | assert(new_id != NULL, "sanity check")do { if (!(new_id != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2243, "assert(" "new_id != __null" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
2244 | assert(to_dealloc_id_p != NULL, "sanity check")do { if (!(to_dealloc_id_p != __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2244, "assert(" "to_dealloc_id_p != __null" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
2245 | assert(to_dealloc_jmeths_p != NULL, "sanity check")do { if (!(to_dealloc_jmeths_p != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2245, "assert(" "to_dealloc_jmeths_p != __null" ") failed", "sanity check"); ::breakpoint(); } } while (0); |
2246 | assert(Threads::number_of_threads() == 0 ||do { if (!(Threads::number_of_threads() == 0 || SafepointSynchronize ::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2248, "assert(" "Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self()" ") failed", "sanity check"); ::breakpoint(); } } while (0) |
2247 | SafepointSynchronize::is_at_safepoint() ||do { if (!(Threads::number_of_threads() == 0 || SafepointSynchronize ::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2248, "assert(" "Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self()" ") failed", "sanity check"); ::breakpoint(); } } while (0) |
2248 | JmethodIdCreation_lock->owned_by_self(), "sanity check")do { if (!(Threads::number_of_threads() == 0 || SafepointSynchronize ::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self ())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2248, "assert(" "Threads::number_of_threads() == 0 || SafepointSynchronize::is_at_safepoint() || JmethodIdCreation_lock->owned_by_self()" ") failed", "sanity check"); ::breakpoint(); } } while (0); |
2249 | |
2250 | // reacquire the cache - we are locked, single threaded or at a safepoint |
2251 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
2252 | jmethodID id = NULL__null; |
2253 | size_t length = 0; |
2254 | |
2255 | if (jmeths == NULL__null || // no cache yet |
2256 | (length = (size_t)jmeths[0]) <= idnum) { // cache is too short |
2257 | if (jmeths != NULL__null) { |
2258 | // copy any existing entries from the old cache |
2259 | for (size_t index = 0; index < length; index++) { |
2260 | new_jmeths[index+1] = jmeths[index+1]; |
2261 | } |
2262 | *to_dealloc_jmeths_p = jmeths; // save old cache for later delete |
2263 | } |
2264 | release_set_methods_jmethod_ids(jmeths = new_jmeths); |
2265 | } else { |
2266 | // fetch jmethodID (if any) from the existing cache |
2267 | id = jmeths[idnum+1]; |
2268 | *to_dealloc_jmeths_p = new_jmeths; // save new cache for later delete |
2269 | } |
2270 | if (id == NULL__null) { |
2271 | // No matching jmethodID in the existing cache or we have a new |
2272 | // cache or we just grew the cache. This cache write is done here |
2273 | // by the first thread to win the foot race because a jmethodID |
2274 | // needs to be unique once it is generally available. |
2275 | id = new_id; |
2276 | |
2277 | // The jmethodID cache can be read while unlocked so we have to |
2278 | // make sure the new jmethodID is complete before installing it |
2279 | // in the cache. |
2280 | Atomic::release_store(&jmeths[idnum+1], id); |
2281 | } else { |
2282 | *to_dealloc_id_p = new_id; // save new id for later delete |
2283 | } |
2284 | return id; |
2285 | } |
2286 | |
2287 | |
2288 | // Common code to get the jmethodID cache length and the jmethodID |
2289 | // value at index idnum if there is one. |
2290 | // |
2291 | void InstanceKlass::get_jmethod_id_length_value(jmethodID* cache, |
2292 | size_t idnum, size_t *length_p, jmethodID* id_p) { |
2293 | assert(cache != NULL, "sanity check")do { if (!(cache != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2293, "assert(" "cache != __null" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
2294 | assert(length_p != NULL, "sanity check")do { if (!(length_p != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2294, "assert(" "length_p != __null" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
2295 | assert(id_p != NULL, "sanity check")do { if (!(id_p != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2295, "assert(" "id_p != __null" ") failed", "sanity check" ); ::breakpoint(); } } while (0); |
2296 | |
2297 | // cache size is stored in element[0], other elements offset by one |
2298 | *length_p = (size_t)cache[0]; |
2299 | if (*length_p <= idnum) { // cache is too short |
2300 | *id_p = NULL__null; |
2301 | } else { |
2302 | *id_p = cache[idnum+1]; // fetch jmethodID (if any) |
2303 | } |
2304 | } |
2305 | |
2306 | |
2307 | // Lookup a jmethodID, NULL if not found. Do no blocking, no allocations, no handles |
2308 | jmethodID InstanceKlass::jmethod_id_or_null(Method* method) { |
2309 | size_t idnum = (size_t)method->method_idnum(); |
2310 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
2311 | size_t length; // length assigned as debugging crumb |
2312 | jmethodID id = NULL__null; |
2313 | if (jmeths != NULL__null && // If there is a cache |
2314 | (length = (size_t)jmeths[0]) > idnum) { // and if it is long enough, |
Although the value stored to 'length' is used in the enclosing expression, the value is never actually read from 'length' | |
2315 | id = jmeths[idnum+1]; // Look up the id (may be NULL) |
2316 | } |
2317 | return id; |
2318 | } |
2319 | |
2320 | inline DependencyContext InstanceKlass::dependencies() { |
2321 | DependencyContext dep_context(&_dep_context, &_dep_context_last_cleaned); |
2322 | return dep_context; |
2323 | } |
2324 | |
2325 | int InstanceKlass::mark_dependent_nmethods(KlassDepChange& changes) { |
2326 | return dependencies().mark_dependent_nmethods(changes); |
2327 | } |
2328 | |
2329 | void InstanceKlass::add_dependent_nmethod(nmethod* nm) { |
2330 | dependencies().add_dependent_nmethod(nm); |
2331 | } |
2332 | |
2333 | void InstanceKlass::remove_dependent_nmethod(nmethod* nm) { |
2334 | dependencies().remove_dependent_nmethod(nm); |
2335 | } |
2336 | |
2337 | void InstanceKlass::clean_dependency_context() { |
2338 | dependencies().clean_unloading_dependents(); |
2339 | } |
2340 | |
2341 | #ifndef PRODUCT |
2342 | void InstanceKlass::print_dependent_nmethods(bool verbose) { |
2343 | dependencies().print_dependent_nmethods(verbose); |
2344 | } |
2345 | |
2346 | bool InstanceKlass::is_dependent_nmethod(nmethod* nm) { |
2347 | return dependencies().is_dependent_nmethod(nm); |
2348 | } |
2349 | #endif //PRODUCT |
2350 | |
2351 | void InstanceKlass::clean_weak_instanceklass_links() { |
2352 | clean_implementors_list(); |
2353 | clean_method_data(); |
2354 | } |
2355 | |
2356 | void InstanceKlass::clean_implementors_list() { |
2357 | assert(is_loader_alive(), "this klass should be live")do { if (!(is_loader_alive())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2357, "assert(" "is_loader_alive()" ") failed", "this klass should be live" ); ::breakpoint(); } } while (0); |
2358 | if (is_interface()) { |
2359 | assert (ClassUnloading, "only called for ClassUnloading")do { if (!(ClassUnloading)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2359, "assert(" "ClassUnloading" ") failed", "only called for ClassUnloading" ); ::breakpoint(); } } while (0); |
2360 | for (;;) { |
2361 | // Use load_acquire due to competing with inserts |
2362 | InstanceKlass* impl = Atomic::load_acquire(adr_implementor()); |
2363 | if (impl != NULL__null && !impl->is_loader_alive()) { |
2364 | // NULL this field, might be an unloaded instance klass or NULL |
2365 | InstanceKlass* volatile* iklass = adr_implementor(); |
2366 | if (Atomic::cmpxchg(iklass, impl, (InstanceKlass*)NULL__null) == impl) { |
2367 | // Successfully unlinking implementor. |
2368 | if (log_is_enabled(Trace, class, unload)(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) { |
2369 | ResourceMark rm; |
2370 | log_trace(class, unload)(!(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_unload), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("unlinking class (implementor): %s", impl->external_name()); |
2371 | } |
2372 | return; |
2373 | } |
2374 | } else { |
2375 | return; |
2376 | } |
2377 | } |
2378 | } |
2379 | } |
2380 | |
2381 | void InstanceKlass::clean_method_data() { |
2382 | for (int m = 0; m < methods()->length(); m++) { |
2383 | MethodData* mdo = methods()->at(m)->method_data(); |
2384 | if (mdo != NULL__null) { |
2385 | MutexLocker ml(SafepointSynchronize::is_at_safepoint() ? NULL__null : mdo->extra_data_lock()); |
2386 | mdo->clean_method_data(/*always_clean*/false); |
2387 | } |
2388 | } |
2389 | } |
2390 | |
2391 | void InstanceKlass::metaspace_pointers_do(MetaspaceClosure* it) { |
2392 | Klass::metaspace_pointers_do(it); |
2393 | |
2394 | if (log_is_enabled(Trace, cds)(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) { |
2395 | ResourceMark rm; |
2396 | log_trace(cds)(!(LogImpl<(LogTag::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_cds), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Iter(InstanceKlass): %p (%s)", this, external_name()); |
2397 | } |
2398 | |
2399 | it->push(&_annotations); |
2400 | it->push((Klass**)&_array_klasses); |
2401 | if (!is_rewritten()) { |
2402 | it->push(&_constants, MetaspaceClosure::_writable); |
2403 | } else { |
2404 | it->push(&_constants); |
2405 | } |
2406 | it->push(&_inner_classes); |
2407 | #if INCLUDE_JVMTI1 |
2408 | it->push(&_previous_versions); |
2409 | #endif |
2410 | it->push(&_methods); |
2411 | it->push(&_default_methods); |
2412 | it->push(&_local_interfaces); |
2413 | it->push(&_transitive_interfaces); |
2414 | it->push(&_method_ordering); |
2415 | if (!is_rewritten()) { |
2416 | it->push(&_default_vtable_indices, MetaspaceClosure::_writable); |
2417 | } else { |
2418 | it->push(&_default_vtable_indices); |
2419 | } |
2420 | it->push(&_fields); |
2421 | |
2422 | if (itable_length() > 0) { |
2423 | itableOffsetEntry* ioe = (itableOffsetEntry*)start_of_itable(); |
2424 | int method_table_offset_in_words = ioe->offset()/wordSize; |
2425 | int nof_interfaces = (method_table_offset_in_words - itable_offset_in_words()) |
2426 | / itableOffsetEntry::size(); |
2427 | |
2428 | for (int i = 0; i < nof_interfaces; i ++, ioe ++) { |
2429 | if (ioe->interface_klass() != NULL__null) { |
2430 | it->push(ioe->interface_klass_addr()); |
2431 | itableMethodEntry* ime = ioe->first_method_entry(this); |
2432 | int n = klassItable::method_count_for_interface(ioe->interface_klass()); |
2433 | for (int index = 0; index < n; index ++) { |
2434 | it->push(ime[index].method_addr()); |
2435 | } |
2436 | } |
2437 | } |
2438 | } |
2439 | |
2440 | it->push(&_nest_members); |
2441 | it->push(&_permitted_subclasses); |
2442 | it->push(&_record_components); |
2443 | } |
2444 | |
2445 | void InstanceKlass::remove_unshareable_info() { |
2446 | |
2447 | if (is_linked()) { |
2448 | assert(can_be_verified_at_dumptime(), "must be")do { if (!(can_be_verified_at_dumptime())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2448, "assert(" "can_be_verified_at_dumptime()" ") failed", "must be"); ::breakpoint(); } } while (0); |
2449 | // Remember this so we can avoid walking the hierarchy at runtime. |
2450 | set_verified_at_dump_time(); |
2451 | } |
2452 | |
2453 | Klass::remove_unshareable_info(); |
2454 | |
2455 | if (SystemDictionaryShared::has_class_failed_verification(this)) { |
2456 | // Classes are attempted to link during dumping and may fail, |
2457 | // but these classes are still in the dictionary and class list in CLD. |
2458 | // If the class has failed verification, there is nothing else to remove. |
2459 | return; |
2460 | } |
2461 | |
2462 | // Reset to the 'allocated' state to prevent any premature accessing to |
2463 | // a shared class at runtime while the class is still being loaded and |
2464 | // restored. A class' init_state is set to 'loaded' at runtime when it's |
2465 | // being added to class hierarchy (see SystemDictionary:::add_to_hierarchy()). |
2466 | _init_state = allocated; |
2467 | |
2468 | { // Otherwise this needs to take out the Compile_lock. |
2469 | assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint")do { if (!(SafepointSynchronize::is_at_safepoint())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2469, "assert(" "SafepointSynchronize::is_at_safepoint()" ") failed" , "only called at safepoint"); ::breakpoint(); } } while (0); |
2470 | init_implementor(); |
2471 | } |
2472 | |
2473 | constants()->remove_unshareable_info(); |
2474 | |
2475 | for (int i = 0; i < methods()->length(); i++) { |
2476 | Method* m = methods()->at(i); |
2477 | m->remove_unshareable_info(); |
2478 | } |
2479 | |
2480 | // do array classes also. |
2481 | if (array_klasses() != NULL__null) { |
2482 | array_klasses()->remove_unshareable_info(); |
2483 | } |
2484 | |
2485 | // These are not allocated from metaspace. They are safe to set to NULL. |
2486 | _source_debug_extension = NULL__null; |
2487 | _dep_context = NULL__null; |
2488 | _osr_nmethods_head = NULL__null; |
2489 | #if INCLUDE_JVMTI1 |
2490 | _breakpoints = NULL__null; |
2491 | _previous_versions = NULL__null; |
2492 | _cached_class_file = NULL__null; |
2493 | _jvmti_cached_class_field_map = NULL__null; |
2494 | #endif |
2495 | |
2496 | _init_thread = NULL__null; |
2497 | _methods_jmethod_ids = NULL__null; |
2498 | _jni_ids = NULL__null; |
2499 | _oop_map_cache = NULL__null; |
2500 | // clear _nest_host to ensure re-load at runtime |
2501 | _nest_host = NULL__null; |
2502 | init_shared_package_entry(); |
2503 | _dep_context_last_cleaned = 0; |
2504 | } |
2505 | |
2506 | void InstanceKlass::remove_java_mirror() { |
2507 | Klass::remove_java_mirror(); |
2508 | |
2509 | // do array classes also. |
2510 | if (array_klasses() != NULL__null) { |
2511 | array_klasses()->remove_java_mirror(); |
2512 | } |
2513 | } |
2514 | |
2515 | void InstanceKlass::init_shared_package_entry() { |
2516 | #if !INCLUDE_CDS_JAVA_HEAP1 |
2517 | _package_entry = NULL__null; |
2518 | #else |
2519 | if (!MetaspaceShared::use_full_module_graph()) { |
2520 | _package_entry = NULL__null; |
2521 | } else if (DynamicDumpSharedSpaces) { |
2522 | if (!MetaspaceShared::is_in_shared_metaspace(_package_entry)) { |
2523 | _package_entry = NULL__null; |
2524 | } |
2525 | } else { |
2526 | if (is_shared_unregistered_class()) { |
2527 | _package_entry = NULL__null; |
2528 | } else { |
2529 | _package_entry = PackageEntry::get_archived_entry(_package_entry); |
2530 | } |
2531 | } |
2532 | ArchivePtrMarker::mark_pointer((address**)&_package_entry); |
2533 | #endif |
2534 | } |
2535 | |
2536 | void InstanceKlass::restore_unshareable_info(ClassLoaderData* loader_data, Handle protection_domain, |
2537 | PackageEntry* pkg_entry, TRAPSJavaThread* __the_thread__) { |
2538 | // SystemDictionary::add_to_hierarchy() sets the init_state to loaded |
2539 | // before the InstanceKlass is added to the SystemDictionary. Make |
2540 | // sure the current state is <loaded. |
2541 | assert(!is_loaded(), "invalid init state")do { if (!(!is_loaded())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2541, "assert(" "!is_loaded()" ") failed", "invalid init state" ); ::breakpoint(); } } while (0); |
2542 | assert(!shared_loading_failed(), "Must not try to load failed class again")do { if (!(!shared_loading_failed())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2542, "assert(" "!shared_loading_failed()" ") failed", "Must not try to load failed class again" ); ::breakpoint(); } } while (0); |
2543 | set_package(loader_data, pkg_entry, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2544 | Klass::restore_unshareable_info(loader_data, protection_domain, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2545 | |
2546 | Array<Method*>* methods = this->methods(); |
2547 | int num_methods = methods->length(); |
2548 | for (int index = 0; index < num_methods; ++index) { |
2549 | methods->at(index)->restore_unshareable_info(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2550 | } |
2551 | #if INCLUDE_JVMTI1 |
2552 | if (JvmtiExport::has_redefined_a_class()) { |
2553 | // Reinitialize vtable because RedefineClasses may have changed some |
2554 | // entries in this vtable for super classes so the CDS vtable might |
2555 | // point to old or obsolete entries. RedefineClasses doesn't fix up |
2556 | // vtables in the shared system dictionary, only the main one. |
2557 | // It also redefines the itable too so fix that too. |
2558 | // First fix any default methods that point to a super class that may |
2559 | // have been redefined. |
2560 | bool trace_name_printed = false; |
2561 | adjust_default_methods(&trace_name_printed); |
2562 | vtable().initialize_vtable(); |
2563 | itable().initialize_itable(); |
2564 | } |
2565 | #endif |
2566 | |
2567 | // restore constant pool resolved references |
2568 | constants()->restore_unshareable_info(CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2569 | |
2570 | if (array_klasses() != NULL__null) { |
2571 | // To get a consistent list of classes we need MultiArray_lock to ensure |
2572 | // array classes aren't observed while they are being restored. |
2573 | MutexLocker ml(MultiArray_lock); |
2574 | // Array classes have null protection domain. |
2575 | // --> see ArrayKlass::complete_create_array_klass() |
2576 | array_klasses()->restore_unshareable_info(ClassLoaderData::the_null_class_loader_data(), Handle(), CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2577 | } |
2578 | |
2579 | // Initialize @ValueBased class annotation |
2580 | if (DiagnoseSyncOnValueBasedClasses && has_value_based_class_annotation()) { |
2581 | set_is_value_based(); |
2582 | } |
2583 | } |
2584 | |
2585 | // Check if a class or any of its supertypes has a version older than 50. |
2586 | // CDS will not perform verification of old classes during dump time because |
2587 | // without changing the old verifier, the verification constraint cannot be |
2588 | // retrieved during dump time. |
2589 | // Verification of archived old classes will be performed during run time. |
2590 | bool InstanceKlass::can_be_verified_at_dumptime() const { |
2591 | if (MetaspaceShared::is_in_shared_metaspace(this)) { |
2592 | // This is a class that was dumped into the base archive, so we know |
2593 | // it was verified at dump time. |
2594 | return true; |
2595 | } |
2596 | if (major_version() < 50 /*JAVA_6_VERSION*/) { |
2597 | return false; |
2598 | } |
2599 | if (java_super() != NULL__null && !java_super()->can_be_verified_at_dumptime()) { |
2600 | return false; |
2601 | } |
2602 | Array<InstanceKlass*>* interfaces = local_interfaces(); |
2603 | int len = interfaces->length(); |
2604 | for (int i = 0; i < len; i++) { |
2605 | if (!interfaces->at(i)->can_be_verified_at_dumptime()) { |
2606 | return false; |
2607 | } |
2608 | } |
2609 | return true; |
2610 | } |
2611 | |
2612 | void InstanceKlass::set_shared_class_loader_type(s2 loader_type) { |
2613 | switch (loader_type) { |
2614 | case ClassLoader::BOOT_LOADER: |
2615 | _misc_flags |= _misc_is_shared_boot_class; |
2616 | break; |
2617 | case ClassLoader::PLATFORM_LOADER: |
2618 | _misc_flags |= _misc_is_shared_platform_class; |
2619 | break; |
2620 | case ClassLoader::APP_LOADER: |
2621 | _misc_flags |= _misc_is_shared_app_class; |
2622 | break; |
2623 | default: |
2624 | ShouldNotReachHere()do { (*g_assert_poison) = 'X';; report_should_not_reach_here( "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2624); ::breakpoint(); } while (0); |
2625 | break; |
2626 | } |
2627 | } |
2628 | |
2629 | void InstanceKlass::assign_class_loader_type() { |
2630 | ClassLoaderData *cld = class_loader_data(); |
2631 | if (cld->is_boot_class_loader_data()) { |
2632 | set_shared_class_loader_type(ClassLoader::BOOT_LOADER); |
2633 | } |
2634 | else if (cld->is_platform_class_loader_data()) { |
2635 | set_shared_class_loader_type(ClassLoader::PLATFORM_LOADER); |
2636 | } |
2637 | else if (cld->is_system_class_loader_data()) { |
2638 | set_shared_class_loader_type(ClassLoader::APP_LOADER); |
2639 | } |
2640 | } |
2641 | |
2642 | #if INCLUDE_JVMTI1 |
2643 | static void clear_all_breakpoints(Method* m) { |
2644 | m->clear_all_breakpoints(); |
2645 | } |
2646 | #endif |
2647 | |
2648 | void InstanceKlass::unload_class(InstanceKlass* ik) { |
2649 | // Release dependencies. |
2650 | ik->dependencies().remove_all_dependents(); |
2651 | |
2652 | // notify the debugger |
2653 | if (JvmtiExport::should_post_class_unload()) { |
2654 | JvmtiExport::post_class_unload(ik); |
2655 | } |
2656 | |
2657 | // notify ClassLoadingService of class unload |
2658 | ClassLoadingService::notify_class_unloaded(ik); |
2659 | |
2660 | SystemDictionaryShared::handle_class_unloading(ik); |
2661 | |
2662 | if (log_is_enabled(Info, class, unload)(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) { |
2663 | ResourceMark rm; |
2664 | log_info(class, unload)(!(LogImpl<(LogTag::_class), (LogTag::_unload), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag ::_class), (LogTag::_unload), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Info>("unloading class %s " INTPTR_FORMAT"0x%016" "l" "x", ik->external_name(), p2i(ik)); |
2665 | } |
2666 | |
2667 | Events::log_class_unloading(Thread::current(), ik); |
2668 | |
2669 | #if INCLUDE_JFR1 |
2670 | assert(ik != NULL, "invariant")do { if (!(ik != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2670, "assert(" "ik != __null" ") failed", "invariant"); :: breakpoint(); } } while (0); |
2671 | EventClassUnload event; |
2672 | event.set_unloadedClass(ik); |
2673 | event.set_definingClassLoader(ik->class_loader_data()); |
2674 | event.commit(); |
2675 | #endif |
2676 | } |
2677 | |
2678 | static void method_release_C_heap_structures(Method* m) { |
2679 | m->release_C_heap_structures(); |
2680 | } |
2681 | |
2682 | // Called also by InstanceKlass::deallocate_contents, with false for release_constant_pool. |
2683 | void InstanceKlass::release_C_heap_structures(bool release_constant_pool) { |
2684 | // Clean up C heap |
2685 | Klass::release_C_heap_structures(); |
2686 | |
2687 | // Deallocate and call destructors for MDO mutexes |
2688 | methods_do(method_release_C_heap_structures); |
2689 | |
2690 | // Deallocate oop map cache |
2691 | if (_oop_map_cache != NULL__null) { |
2692 | delete _oop_map_cache; |
2693 | _oop_map_cache = NULL__null; |
2694 | } |
2695 | |
2696 | // Deallocate JNI identifiers for jfieldIDs |
2697 | JNIid::deallocate(jni_ids()); |
2698 | set_jni_ids(NULL__null); |
2699 | |
2700 | jmethodID* jmeths = methods_jmethod_ids_acquire(); |
2701 | if (jmeths != (jmethodID*)NULL__null) { |
2702 | release_set_methods_jmethod_ids(NULL__null); |
2703 | FreeHeap(jmeths); |
2704 | } |
2705 | |
2706 | assert(_dep_context == NULL,do { if (!(_dep_context == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2707, "assert(" "_dep_context == __null" ") failed", "dependencies should already be cleaned" ); ::breakpoint(); } } while (0) |
2707 | "dependencies should already be cleaned")do { if (!(_dep_context == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2707, "assert(" "_dep_context == __null" ") failed", "dependencies should already be cleaned" ); ::breakpoint(); } } while (0); |
2708 | |
2709 | #if INCLUDE_JVMTI1 |
2710 | // Deallocate breakpoint records |
2711 | if (breakpoints() != 0x0) { |
2712 | methods_do(clear_all_breakpoints); |
2713 | assert(breakpoints() == 0x0, "should have cleared breakpoints")do { if (!(breakpoints() == 0x0)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2713, "assert(" "breakpoints() == 0x0" ") failed", "should have cleared breakpoints" ); ::breakpoint(); } } while (0); |
2714 | } |
2715 | |
2716 | // deallocate the cached class file |
2717 | if (_cached_class_file != NULL__null) { |
2718 | os::free(_cached_class_file); |
2719 | _cached_class_file = NULL__null; |
2720 | } |
2721 | #endif |
2722 | |
2723 | FREE_C_HEAP_ARRAY(char, _source_debug_extension)FreeHeap((char*)(_source_debug_extension)); |
2724 | |
2725 | if (release_constant_pool) { |
2726 | constants()->release_C_heap_structures(); |
2727 | } |
2728 | } |
2729 | |
2730 | void InstanceKlass::set_source_debug_extension(const char* array, int length) { |
2731 | if (array == NULL__null) { |
2732 | _source_debug_extension = NULL__null; |
2733 | } else { |
2734 | // Adding one to the attribute length in order to store a null terminator |
2735 | // character could cause an overflow because the attribute length is |
2736 | // already coded with an u4 in the classfile, but in practice, it's |
2737 | // unlikely to happen. |
2738 | assert((length+1) > length, "Overflow checking")do { if (!((length+1) > length)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2738, "assert(" "(length+1) > length" ") failed", "Overflow checking" ); ::breakpoint(); } } while (0); |
2739 | char* sde = NEW_C_HEAP_ARRAY(char, (length + 1), mtClass)(char*) (AllocateHeap(((length + 1)) * sizeof(char), mtClass) ); |
2740 | for (int i = 0; i < length; i++) { |
2741 | sde[i] = array[i]; |
2742 | } |
2743 | sde[length] = '\0'; |
2744 | _source_debug_extension = sde; |
2745 | } |
2746 | } |
2747 | |
2748 | const char* InstanceKlass::signature_name() const { |
2749 | int hash_len = 0; |
2750 | char hash_buf[40]; |
2751 | |
2752 | // Get the internal name as a c string |
2753 | const char* src = (const char*) (name()->as_C_string()); |
2754 | const int src_length = (int)strlen(src); |
2755 | |
2756 | char* dest = NEW_RESOURCE_ARRAY(char, src_length + hash_len + 3)(char*) resource_allocate_bytes((src_length + hash_len + 3) * sizeof(char)); |
2757 | |
2758 | // Add L as type indicator |
2759 | int dest_index = 0; |
2760 | dest[dest_index++] = JVM_SIGNATURE_CLASS; |
2761 | |
2762 | // Add the actual class name |
2763 | for (int src_index = 0; src_index < src_length; ) { |
2764 | dest[dest_index++] = src[src_index++]; |
2765 | } |
2766 | |
2767 | if (is_hidden()) { // Replace the last '+' with a '.'. |
2768 | for (int index = (int)src_length; index > 0; index--) { |
2769 | if (dest[index] == '+') { |
2770 | dest[index] = JVM_SIGNATURE_DOT; |
2771 | break; |
2772 | } |
2773 | } |
2774 | } |
2775 | |
2776 | // If we have a hash, append it |
2777 | for (int hash_index = 0; hash_index < hash_len; ) { |
2778 | dest[dest_index++] = hash_buf[hash_index++]; |
2779 | } |
2780 | |
2781 | // Add the semicolon and the NULL |
2782 | dest[dest_index++] = JVM_SIGNATURE_ENDCLASS; |
2783 | dest[dest_index] = '\0'; |
2784 | return dest; |
2785 | } |
2786 | |
2787 | ModuleEntry* InstanceKlass::module() const { |
2788 | if (is_hidden() && |
2789 | in_unnamed_package() && |
2790 | class_loader_data()->has_class_mirror_holder()) { |
2791 | // For a non-strong hidden class defined to an unnamed package, |
2792 | // its (class held) CLD will not have an unnamed module created for it. |
2793 | // Two choices to find the correct ModuleEntry: |
2794 | // 1. If hidden class is within a nest, use nest host's module |
2795 | // 2. Find the unnamed module off from the class loader |
2796 | // For now option #2 is used since a nest host is not set until |
2797 | // after the instance class is created in jvm_lookup_define_class(). |
2798 | if (class_loader_data()->is_boot_class_loader_data()) { |
2799 | return ClassLoaderData::the_null_class_loader_data()->unnamed_module(); |
2800 | } else { |
2801 | oop module = java_lang_ClassLoader::unnamedModule(class_loader_data()->class_loader()); |
2802 | assert(java_lang_Module::is_instance(module), "Not an instance of java.lang.Module")do { if (!(java_lang_Module::is_instance(module))) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2802, "assert(" "java_lang_Module::is_instance(module)" ") failed" , "Not an instance of java.lang.Module"); ::breakpoint(); } } while (0); |
2803 | return java_lang_Module::module_entry(module); |
2804 | } |
2805 | } |
2806 | |
2807 | // Class is in a named package |
2808 | if (!in_unnamed_package()) { |
2809 | return _package_entry->module(); |
2810 | } |
2811 | |
2812 | // Class is in an unnamed package, return its loader's unnamed module |
2813 | return class_loader_data()->unnamed_module(); |
2814 | } |
2815 | |
2816 | void InstanceKlass::set_package(ClassLoaderData* loader_data, PackageEntry* pkg_entry, TRAPSJavaThread* __the_thread__) { |
2817 | |
2818 | // ensure java/ packages only loaded by boot or platform builtin loaders |
2819 | // not needed for shared class since CDS does not archive prohibited classes. |
2820 | if (!is_shared()) { |
2821 | check_prohibited_package(name(), loader_data, CHECK__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return ; (void)(0); |
2822 | } |
2823 | |
2824 | if (is_shared() && _package_entry != NULL__null) { |
2825 | if (MetaspaceShared::use_full_module_graph() && _package_entry == pkg_entry) { |
2826 | // we can use the saved package |
2827 | assert(MetaspaceShared::is_in_shared_metaspace(_package_entry), "must be")do { if (!(MetaspaceShared::is_in_shared_metaspace(_package_entry ))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2827, "assert(" "MetaspaceShared::is_in_shared_metaspace(_package_entry)" ") failed", "must be"); ::breakpoint(); } } while (0); |
2828 | return; |
2829 | } else { |
2830 | _package_entry = NULL__null; |
2831 | } |
2832 | } |
2833 | |
2834 | // ClassLoader::package_from_class_name has already incremented the refcount of the symbol |
2835 | // it returns, so we need to decrement it when the current function exits. |
2836 | TempNewSymbol from_class_name = |
2837 | (pkg_entry != NULL__null) ? NULL__null : ClassLoader::package_from_class_name(name()); |
2838 | |
2839 | Symbol* pkg_name; |
2840 | if (pkg_entry != NULL__null) { |
2841 | pkg_name = pkg_entry->name(); |
2842 | } else { |
2843 | pkg_name = from_class_name; |
2844 | } |
2845 | |
2846 | if (pkg_name != NULL__null && loader_data != NULL__null) { |
2847 | |
2848 | // Find in class loader's package entry table. |
2849 | _package_entry = pkg_entry != NULL__null ? pkg_entry : loader_data->packages()->lookup_only(pkg_name); |
2850 | |
2851 | // If the package name is not found in the loader's package |
2852 | // entry table, it is an indication that the package has not |
2853 | // been defined. Consider it defined within the unnamed module. |
2854 | if (_package_entry == NULL__null) { |
2855 | |
2856 | if (!ModuleEntryTable::javabase_defined()) { |
2857 | // Before java.base is defined during bootstrapping, define all packages in |
2858 | // the java.base module. If a non-java.base package is erroneously placed |
2859 | // in the java.base module it will be caught later when java.base |
2860 | // is defined by ModuleEntryTable::verify_javabase_packages check. |
2861 | assert(ModuleEntryTable::javabase_moduleEntry() != NULL, JAVA_BASE_NAME " module is NULL")do { if (!(ModuleEntryTable::javabase_moduleEntry() != __null )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2861, "assert(" "ModuleEntryTable::javabase_moduleEntry() != __null" ") failed", "java.base" " module is NULL"); ::breakpoint(); } } while (0); |
2862 | _package_entry = loader_data->packages()->lookup(pkg_name, ModuleEntryTable::javabase_moduleEntry()); |
2863 | } else { |
2864 | assert(loader_data->unnamed_module() != NULL, "unnamed module is NULL")do { if (!(loader_data->unnamed_module() != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2864, "assert(" "loader_data->unnamed_module() != __null" ") failed", "unnamed module is NULL"); ::breakpoint(); } } while (0); |
2865 | _package_entry = loader_data->packages()->lookup(pkg_name, |
2866 | loader_data->unnamed_module()); |
2867 | } |
2868 | |
2869 | // A package should have been successfully created |
2870 | DEBUG_ONLY(ResourceMark rm(THREAD))ResourceMark rm(__the_thread__); |
2871 | assert(_package_entry != NULL, "Package entry for class %s not found, loader %s",do { if (!(_package_entry != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2872, "assert(" "_package_entry != __null" ") failed", "Package entry for class %s not found, loader %s" , name()->as_C_string(), loader_data->loader_name_and_id ()); ::breakpoint(); } } while (0) |
2872 | name()->as_C_string(), loader_data->loader_name_and_id())do { if (!(_package_entry != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2872, "assert(" "_package_entry != __null" ") failed", "Package entry for class %s not found, loader %s" , name()->as_C_string(), loader_data->loader_name_and_id ()); ::breakpoint(); } } while (0); |
2873 | } |
2874 | |
2875 | if (log_is_enabled(Debug, module)(LogImpl<(LogTag::_module), (LogTag::__NO_TAG), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Debug))) { |
2876 | ResourceMark rm(THREAD__the_thread__); |
2877 | ModuleEntry* m = _package_entry->module(); |
2878 | log_trace(module)(!(LogImpl<(LogTag::_module), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_module), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write< LogLevel::Trace>("Setting package: class: %s, package: %s, loader: %s, module: %s", |
2879 | external_name(), |
2880 | pkg_name->as_C_string(), |
2881 | loader_data->loader_name_and_id(), |
2882 | (m->is_named() ? m->name()->as_C_string() : UNNAMED_MODULE"unnamed module")); |
2883 | } |
2884 | } else { |
2885 | ResourceMark rm(THREAD__the_thread__); |
2886 | log_trace(module)(!(LogImpl<(LogTag::_module), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_module), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write< LogLevel::Trace>("Setting package: class: %s, package: unnamed, loader: %s, module: %s", |
2887 | external_name(), |
2888 | (loader_data != NULL__null) ? loader_data->loader_name_and_id() : "NULL", |
2889 | UNNAMED_MODULE"unnamed module"); |
2890 | } |
2891 | } |
2892 | |
2893 | // Function set_classpath_index ensures that for a non-null _package_entry |
2894 | // of the InstanceKlass, the entry is in the boot loader's package entry table. |
2895 | // It then sets the classpath_index in the package entry record. |
2896 | // |
2897 | // The classpath_index field is used to find the entry on the boot loader class |
2898 | // path for packages with classes loaded by the boot loader from -Xbootclasspath/a |
2899 | // in an unnamed module. It is also used to indicate (for all packages whose |
2900 | // classes are loaded by the boot loader) that at least one of the package's |
2901 | // classes has been loaded. |
2902 | void InstanceKlass::set_classpath_index(s2 path_index) { |
2903 | if (_package_entry != NULL__null) { |
2904 | DEBUG_ONLY(PackageEntryTable* pkg_entry_tbl = ClassLoaderData::the_null_class_loader_data()->packages();)PackageEntryTable* pkg_entry_tbl = ClassLoaderData::the_null_class_loader_data ()->packages(); |
2905 | assert(pkg_entry_tbl->lookup_only(_package_entry->name()) == _package_entry, "Should be same")do { if (!(pkg_entry_tbl->lookup_only(_package_entry->name ()) == _package_entry)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2905, "assert(" "pkg_entry_tbl->lookup_only(_package_entry->name()) == _package_entry" ") failed", "Should be same"); ::breakpoint(); } } while (0); |
2906 | assert(path_index != -1, "Unexpected classpath_index")do { if (!(path_index != -1)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2906, "assert(" "path_index != -1" ") failed", "Unexpected classpath_index" ); ::breakpoint(); } } while (0); |
2907 | _package_entry->set_classpath_index(path_index); |
2908 | } |
2909 | } |
2910 | |
2911 | // different versions of is_same_class_package |
2912 | |
2913 | bool InstanceKlass::is_same_class_package(const Klass* class2) const { |
2914 | oop classloader1 = this->class_loader(); |
2915 | PackageEntry* classpkg1 = this->package(); |
2916 | if (class2->is_objArray_klass()) { |
2917 | class2 = ObjArrayKlass::cast(class2)->bottom_klass(); |
2918 | } |
2919 | |
2920 | oop classloader2; |
2921 | PackageEntry* classpkg2; |
2922 | if (class2->is_instance_klass()) { |
2923 | classloader2 = class2->class_loader(); |
2924 | classpkg2 = class2->package(); |
2925 | } else { |
2926 | assert(class2->is_typeArray_klass(), "should be type array")do { if (!(class2->is_typeArray_klass())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2926, "assert(" "class2->is_typeArray_klass()" ") failed" , "should be type array"); ::breakpoint(); } } while (0); |
2927 | classloader2 = NULL__null; |
2928 | classpkg2 = NULL__null; |
2929 | } |
2930 | |
2931 | // Same package is determined by comparing class loader |
2932 | // and package entries. Both must be the same. This rule |
2933 | // applies even to classes that are defined in the unnamed |
2934 | // package, they still must have the same class loader. |
2935 | if ((classloader1 == classloader2) && (classpkg1 == classpkg2)) { |
2936 | return true; |
2937 | } |
2938 | |
2939 | return false; |
2940 | } |
2941 | |
2942 | // return true if this class and other_class are in the same package. Classloader |
2943 | // and classname information is enough to determine a class's package |
2944 | bool InstanceKlass::is_same_class_package(oop other_class_loader, |
2945 | const Symbol* other_class_name) const { |
2946 | if (class_loader() != other_class_loader) { |
2947 | return false; |
2948 | } |
2949 | if (name()->fast_compare(other_class_name) == 0) { |
2950 | return true; |
2951 | } |
2952 | |
2953 | { |
2954 | ResourceMark rm; |
2955 | |
2956 | bool bad_class_name = false; |
2957 | TempNewSymbol other_pkg = ClassLoader::package_from_class_name(other_class_name, &bad_class_name); |
2958 | if (bad_class_name) { |
2959 | return false; |
2960 | } |
2961 | // Check that package_from_class_name() returns NULL, not "", if there is no package. |
2962 | assert(other_pkg == NULL || other_pkg->utf8_length() > 0, "package name is empty string")do { if (!(other_pkg == __null || other_pkg->utf8_length() > 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 2962, "assert(" "other_pkg == __null || other_pkg->utf8_length() > 0" ") failed", "package name is empty string"); ::breakpoint(); } } while (0); |
2963 | |
2964 | const Symbol* const this_package_name = |
2965 | this->package() != NULL__null ? this->package()->name() : NULL__null; |
2966 | |
2967 | if (this_package_name == NULL__null || other_pkg == NULL__null) { |
2968 | // One of the two doesn't have a package. Only return true if the other |
2969 | // one also doesn't have a package. |
2970 | return this_package_name == other_pkg; |
2971 | } |
2972 | |
2973 | // Check if package is identical |
2974 | return this_package_name->fast_compare(other_pkg) == 0; |
2975 | } |
2976 | } |
2977 | |
2978 | static bool is_prohibited_package_slow(Symbol* class_name) { |
2979 | // Caller has ResourceMark |
2980 | int length; |
2981 | jchar* unicode = class_name->as_unicode(length); |
2982 | return (length >= 5 && |
2983 | unicode[0] == 'j' && |
2984 | unicode[1] == 'a' && |
2985 | unicode[2] == 'v' && |
2986 | unicode[3] == 'a' && |
2987 | unicode[4] == '/'); |
2988 | } |
2989 | |
2990 | // Only boot and platform class loaders can define classes in "java/" packages. |
2991 | void InstanceKlass::check_prohibited_package(Symbol* class_name, |
2992 | ClassLoaderData* loader_data, |
2993 | TRAPSJavaThread* __the_thread__) { |
2994 | if (!loader_data->is_boot_class_loader_data() && |
2995 | !loader_data->is_platform_class_loader_data() && |
2996 | class_name != NULL__null && class_name->utf8_length() >= 5) { |
2997 | ResourceMark rm(THREAD__the_thread__); |
2998 | bool prohibited; |
2999 | const u1* base = class_name->base(); |
3000 | if ((base[0] | base[1] | base[2] | base[3] | base[4]) & 0x80) { |
3001 | prohibited = is_prohibited_package_slow(class_name); |
3002 | } else { |
3003 | char* name = class_name->as_C_string(); |
3004 | prohibited = (strncmp(name, JAVAPKG"java", JAVAPKG_LEN4) == 0 && name[JAVAPKG_LEN4] == '/'); |
3005 | } |
3006 | if (prohibited) { |
3007 | TempNewSymbol pkg_name = ClassLoader::package_from_class_name(class_name); |
3008 | assert(pkg_name != NULL, "Error in parsing package name starting with 'java/'")do { if (!(pkg_name != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3008, "assert(" "pkg_name != __null" ") failed", "Error in parsing package name starting with 'java/'" ); ::breakpoint(); } } while (0); |
3009 | char* name = pkg_name->as_C_string(); |
3010 | const char* class_loader_name = loader_data->loader_name_and_id(); |
3011 | StringUtils::replace_no_expand(name, "/", "."); |
3012 | const char* msg_text1 = "Class loader (instance of): "; |
3013 | const char* msg_text2 = " tried to load prohibited package name: "; |
3014 | size_t len = strlen(msg_text1) + strlen(class_loader_name) + strlen(msg_text2) + strlen(name) + 1; |
3015 | char* message = NEW_RESOURCE_ARRAY_IN_THREAD(THREAD, char, len)(char*) resource_allocate_bytes(__the_thread__, (len) * sizeof (char)); |
3016 | jio_snprintf(message, len, "%s%s%s%s", msg_text1, class_loader_name, msg_text2, name); |
3017 | THROW_MSG(vmSymbols::java_lang_SecurityException(), message){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3017, vmSymbols::java_lang_SecurityException(), message); return ; }; |
3018 | } |
3019 | } |
3020 | return; |
3021 | } |
3022 | |
3023 | bool InstanceKlass::find_inner_classes_attr(int* ooff, int* noff, TRAPSJavaThread* __the_thread__) const { |
3024 | constantPoolHandle i_cp(THREAD__the_thread__, constants()); |
3025 | for (InnerClassesIterator iter(this); !iter.done(); iter.next()) { |
3026 | int ioff = iter.inner_class_info_index(); |
3027 | if (ioff != 0) { |
3028 | // Check to see if the name matches the class we're looking for |
3029 | // before attempting to find the class. |
3030 | if (i_cp->klass_name_at_matches(this, ioff)) { |
3031 | Klass* inner_klass = i_cp->klass_at(ioff, CHECK_false__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return false; (void)(0); |
3032 | if (this == inner_klass) { |
3033 | *ooff = iter.outer_class_info_index(); |
3034 | *noff = iter.inner_name_index(); |
3035 | return true; |
3036 | } |
3037 | } |
3038 | } |
3039 | } |
3040 | return false; |
3041 | } |
3042 | |
3043 | InstanceKlass* InstanceKlass::compute_enclosing_class(bool* inner_is_member, TRAPSJavaThread* __the_thread__) const { |
3044 | InstanceKlass* outer_klass = NULL__null; |
3045 | *inner_is_member = false; |
3046 | int ooff = 0, noff = 0; |
3047 | bool has_inner_classes_attr = find_inner_classes_attr(&ooff, &noff, THREAD__the_thread__); |
3048 | if (has_inner_classes_attr) { |
3049 | constantPoolHandle i_cp(THREAD__the_thread__, constants()); |
3050 | if (ooff != 0) { |
3051 | Klass* ok = i_cp->klass_at(ooff, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
3052 | if (!ok->is_instance_klass()) { |
3053 | // If the outer class is not an instance klass then it cannot have |
3054 | // declared any inner classes. |
3055 | ResourceMark rm(THREAD__the_thread__); |
3056 | Exceptions::fthrow( |
3057 | THREAD_AND_LOCATION__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3057, |
3058 | vmSymbols::java_lang_IncompatibleClassChangeError(), |
3059 | "%s and %s disagree on InnerClasses attribute", |
3060 | ok->external_name(), |
3061 | external_name()); |
3062 | return NULL__null; |
3063 | } |
3064 | outer_klass = InstanceKlass::cast(ok); |
3065 | *inner_is_member = true; |
3066 | } |
3067 | if (NULL__null == outer_klass) { |
3068 | // It may be a local class; try for that. |
3069 | int encl_method_class_idx = enclosing_method_class_index(); |
3070 | if (encl_method_class_idx != 0) { |
3071 | Klass* ok = i_cp->klass_at(encl_method_class_idx, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
3072 | outer_klass = InstanceKlass::cast(ok); |
3073 | *inner_is_member = false; |
3074 | } |
3075 | } |
3076 | } |
3077 | |
3078 | // If no inner class attribute found for this class. |
3079 | if (NULL__null == outer_klass) return NULL__null; |
3080 | |
3081 | // Throws an exception if outer klass has not declared k as an inner klass |
3082 | // We need evidence that each klass knows about the other, or else |
3083 | // the system could allow a spoof of an inner class to gain access rights. |
3084 | Reflection::check_for_inner_class(outer_klass, this, *inner_is_member, CHECK_NULL__the_thread__); if ((((ThreadShadow*)__the_thread__)->has_pending_exception ())) return __null; (void)(0); |
3085 | return outer_klass; |
3086 | } |
3087 | |
3088 | jint InstanceKlass::compute_modifier_flags() const { |
3089 | jint access = access_flags().as_int(); |
3090 | |
3091 | // But check if it happens to be member class. |
3092 | InnerClassesIterator iter(this); |
3093 | for (; !iter.done(); iter.next()) { |
3094 | int ioff = iter.inner_class_info_index(); |
3095 | // Inner class attribute can be zero, skip it. |
3096 | // Strange but true: JVM spec. allows null inner class refs. |
3097 | if (ioff == 0) continue; |
3098 | |
3099 | // only look at classes that are already loaded |
3100 | // since we are looking for the flags for our self. |
3101 | Symbol* inner_name = constants()->klass_name_at(ioff); |
3102 | if (name() == inner_name) { |
3103 | // This is really a member class. |
3104 | access = iter.inner_access_flags(); |
3105 | break; |
3106 | } |
3107 | } |
3108 | // Remember to strip ACC_SUPER bit |
3109 | return (access & (~JVM_ACC_SUPER)) & JVM_ACC_WRITTEN_FLAGS; |
3110 | } |
3111 | |
3112 | jint InstanceKlass::jvmti_class_status() const { |
3113 | jint result = 0; |
3114 | |
3115 | if (is_linked()) { |
3116 | result |= JVMTI_CLASS_STATUS_VERIFIED | JVMTI_CLASS_STATUS_PREPARED; |
3117 | } |
3118 | |
3119 | if (is_initialized()) { |
3120 | assert(is_linked(), "Class status is not consistent")do { if (!(is_linked())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3120, "assert(" "is_linked()" ") failed", "Class status is not consistent" ); ::breakpoint(); } } while (0); |
3121 | result |= JVMTI_CLASS_STATUS_INITIALIZED; |
3122 | } |
3123 | if (is_in_error_state()) { |
3124 | result |= JVMTI_CLASS_STATUS_ERROR; |
3125 | } |
3126 | return result; |
3127 | } |
3128 | |
3129 | Method* InstanceKlass::method_at_itable(InstanceKlass* holder, int index, TRAPSJavaThread* __the_thread__) { |
3130 | bool implements_interface; // initialized by method_at_itable_or_null |
3131 | Method* m = method_at_itable_or_null(holder, index, |
3132 | implements_interface); // out parameter |
3133 | if (m != NULL__null) { |
3134 | assert(implements_interface, "sanity")do { if (!(implements_interface)) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3134, "assert(" "implements_interface" ") failed", "sanity" ); ::breakpoint(); } } while (0); |
3135 | return m; |
3136 | } else if (implements_interface) { |
3137 | // Throw AbstractMethodError since corresponding itable slot is empty. |
3138 | THROW_NULL(vmSymbols::java_lang_AbstractMethodError()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3138, vmSymbols::java_lang_AbstractMethodError(), __null); return __null; }; |
3139 | } else { |
3140 | // If the interface isn't implemented by the receiver class, |
3141 | // the VM should throw IncompatibleClassChangeError. |
3142 | ResourceMark rm(THREAD__the_thread__); |
3143 | stringStream ss; |
3144 | bool same_module = (module() == holder->module()); |
3145 | ss.print("Receiver class %s does not implement " |
3146 | "the interface %s defining the method to be called " |
3147 | "(%s%s%s)", |
3148 | external_name(), holder->external_name(), |
3149 | (same_module) ? joint_in_module_of_loader(holder) : class_in_module_of_loader(), |
3150 | (same_module) ? "" : "; ", |
3151 | (same_module) ? "" : holder->class_in_module_of_loader()); |
3152 | THROW_MSG_NULL(vmSymbols::java_lang_IncompatibleClassChangeError(), ss.as_string()){ Exceptions::_throw_msg(__the_thread__, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3152, vmSymbols::java_lang_IncompatibleClassChangeError(), ss .as_string()); return __null; }; |
3153 | } |
3154 | } |
3155 | |
3156 | Method* InstanceKlass::method_at_itable_or_null(InstanceKlass* holder, int index, bool& implements_interface) { |
3157 | klassItable itable(this); |
3158 | for (int i = 0; i < itable.size_offset_table(); i++) { |
3159 | itableOffsetEntry* offset_entry = itable.offset_entry(i); |
3160 | if (offset_entry->interface_klass() == holder) { |
3161 | implements_interface = true; |
3162 | itableMethodEntry* ime = offset_entry->first_method_entry(this); |
3163 | Method* m = ime[index].method(); |
3164 | return m; |
3165 | } |
3166 | } |
3167 | implements_interface = false; |
3168 | return NULL__null; // offset entry not found |
3169 | } |
3170 | |
3171 | int InstanceKlass::vtable_index_of_interface_method(Method* intf_method) { |
3172 | assert(is_linked(), "required")do { if (!(is_linked())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3172, "assert(" "is_linked()" ") failed", "required"); ::breakpoint (); } } while (0); |
3173 | assert(intf_method->method_holder()->is_interface(), "not an interface method")do { if (!(intf_method->method_holder()->is_interface() )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3173, "assert(" "intf_method->method_holder()->is_interface()" ") failed", "not an interface method"); ::breakpoint(); } } while (0); |
3174 | assert(is_subtype_of(intf_method->method_holder()), "interface not implemented")do { if (!(is_subtype_of(intf_method->method_holder()))) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3174, "assert(" "is_subtype_of(intf_method->method_holder())" ") failed", "interface not implemented"); ::breakpoint(); } } while (0); |
3175 | |
3176 | int vtable_index = Method::invalid_vtable_index; |
3177 | Symbol* name = intf_method->name(); |
3178 | Symbol* signature = intf_method->signature(); |
3179 | |
3180 | // First check in default method array |
3181 | if (!intf_method->is_abstract() && default_methods() != NULL__null) { |
3182 | int index = find_method_index(default_methods(), |
3183 | name, signature, |
3184 | Klass::OverpassLookupMode::find, |
3185 | Klass::StaticLookupMode::find, |
3186 | Klass::PrivateLookupMode::find); |
3187 | if (index >= 0) { |
3188 | vtable_index = default_vtable_indices()->at(index); |
3189 | } |
3190 | } |
3191 | if (vtable_index == Method::invalid_vtable_index) { |
3192 | // get vtable_index for miranda methods |
3193 | klassVtable vt = vtable(); |
3194 | vtable_index = vt.index_of_miranda(name, signature); |
3195 | } |
3196 | return vtable_index; |
3197 | } |
3198 | |
3199 | #if INCLUDE_JVMTI1 |
3200 | // update default_methods for redefineclasses for methods that are |
3201 | // not yet in the vtable due to concurrent subclass define and superinterface |
3202 | // redefinition |
3203 | // Note: those in the vtable, should have been updated via adjust_method_entries |
3204 | void InstanceKlass::adjust_default_methods(bool* trace_name_printed) { |
3205 | // search the default_methods for uses of either obsolete or EMCP methods |
3206 | if (default_methods() != NULL__null) { |
3207 | for (int index = 0; index < default_methods()->length(); index ++) { |
3208 | Method* old_method = default_methods()->at(index); |
3209 | if (old_method == NULL__null || !old_method->is_old()) { |
3210 | continue; // skip uninteresting entries |
3211 | } |
3212 | assert(!old_method->is_deleted(), "default methods may not be deleted")do { if (!(!old_method->is_deleted())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3212, "assert(" "!old_method->is_deleted()" ") failed", "default methods may not be deleted" ); ::breakpoint(); } } while (0); |
3213 | Method* new_method = old_method->get_new_method(); |
3214 | default_methods()->at_put(index, new_method); |
3215 | |
3216 | if (log_is_enabled(Info, redefine, class, update)(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag::_update ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) { |
3217 | ResourceMark rm; |
3218 | if (!(*trace_name_printed)) { |
3219 | log_info(redefine, class, update)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _update), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Info))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_update), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Info> |
3220 | ("adjust: klassname=%s default methods from name=%s", |
3221 | external_name(), old_method->method_holder()->external_name()); |
3222 | *trace_name_printed = true; |
3223 | } |
3224 | log_debug(redefine, class, update, vtables)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _update), (LogTag::_vtables), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Debug))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_update), (LogTag::_vtables ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Debug> |
3225 | ("default method update: %s(%s) ", |
3226 | new_method->name()->as_C_string(), new_method->signature()->as_C_string()); |
3227 | } |
3228 | } |
3229 | } |
3230 | } |
3231 | #endif // INCLUDE_JVMTI |
3232 | |
3233 | // On-stack replacement stuff |
3234 | void InstanceKlass::add_osr_nmethod(nmethod* n) { |
3235 | assert_lock_strong(CompiledMethod_lock); |
3236 | #ifndef PRODUCT |
3237 | nmethod* prev = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), n->comp_level(), true); |
3238 | assert(prev == NULL || !prev->is_in_use() COMPILER2_PRESENT(|| StressRecompilation),do { if (!(prev == __null || !prev->is_in_use() || StressRecompilation )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3239, "assert(" "prev == __null || !prev->is_in_use() || StressRecompilation" ") failed", "redundant OSR recompilation detected. memory leak in CodeCache!" ); ::breakpoint(); } } while (0) |
3239 | "redundant OSR recompilation detected. memory leak in CodeCache!")do { if (!(prev == __null || !prev->is_in_use() || StressRecompilation )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3239, "assert(" "prev == __null || !prev->is_in_use() || StressRecompilation" ") failed", "redundant OSR recompilation detected. memory leak in CodeCache!" ); ::breakpoint(); } } while (0); |
3240 | #endif |
3241 | // only one compilation can be active |
3242 | assert(n->is_osr_method(), "wrong kind of nmethod")do { if (!(n->is_osr_method())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3242, "assert(" "n->is_osr_method()" ") failed", "wrong kind of nmethod" ); ::breakpoint(); } } while (0); |
3243 | n->set_osr_link(osr_nmethods_head()); |
3244 | set_osr_nmethods_head(n); |
3245 | // Raise the highest osr level if necessary |
3246 | n->method()->set_highest_osr_comp_level(MAX2(n->method()->highest_osr_comp_level(), n->comp_level())); |
3247 | |
3248 | // Get rid of the osr methods for the same bci that have lower levels. |
3249 | for (int l = CompLevel_limited_profile; l < n->comp_level(); l++) { |
3250 | nmethod *inv = lookup_osr_nmethod(n->method(), n->osr_entry_bci(), l, true); |
3251 | if (inv != NULL__null && inv->is_in_use()) { |
3252 | inv->make_not_entrant(); |
3253 | } |
3254 | } |
3255 | } |
3256 | |
3257 | // Remove osr nmethod from the list. Return true if found and removed. |
3258 | bool InstanceKlass::remove_osr_nmethod(nmethod* n) { |
3259 | // This is a short non-blocking critical region, so the no safepoint check is ok. |
3260 | MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL__null : CompiledMethod_lock |
3261 | , Mutex::_no_safepoint_check_flag); |
3262 | assert(n->is_osr_method(), "wrong kind of nmethod")do { if (!(n->is_osr_method())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3262, "assert(" "n->is_osr_method()" ") failed", "wrong kind of nmethod" ); ::breakpoint(); } } while (0); |
3263 | nmethod* last = NULL__null; |
3264 | nmethod* cur = osr_nmethods_head(); |
3265 | int max_level = CompLevel_none; // Find the max comp level excluding n |
3266 | Method* m = n->method(); |
3267 | // Search for match |
3268 | bool found = false; |
3269 | while(cur != NULL__null && cur != n) { |
3270 | if (m == cur->method()) { |
3271 | // Find max level before n |
3272 | max_level = MAX2(max_level, cur->comp_level()); |
3273 | } |
3274 | last = cur; |
3275 | cur = cur->osr_link(); |
3276 | } |
3277 | nmethod* next = NULL__null; |
3278 | if (cur == n) { |
3279 | found = true; |
3280 | next = cur->osr_link(); |
3281 | if (last == NULL__null) { |
3282 | // Remove first element |
3283 | set_osr_nmethods_head(next); |
3284 | } else { |
3285 | last->set_osr_link(next); |
3286 | } |
3287 | } |
3288 | n->set_osr_link(NULL__null); |
3289 | cur = next; |
3290 | while (cur != NULL__null) { |
3291 | // Find max level after n |
3292 | if (m == cur->method()) { |
3293 | max_level = MAX2(max_level, cur->comp_level()); |
3294 | } |
3295 | cur = cur->osr_link(); |
3296 | } |
3297 | m->set_highest_osr_comp_level(max_level); |
3298 | return found; |
3299 | } |
3300 | |
3301 | int InstanceKlass::mark_osr_nmethods(const Method* m) { |
3302 | MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL__null : CompiledMethod_lock, |
3303 | Mutex::_no_safepoint_check_flag); |
3304 | nmethod* osr = osr_nmethods_head(); |
3305 | int found = 0; |
3306 | while (osr != NULL__null) { |
3307 | assert(osr->is_osr_method(), "wrong kind of nmethod found in chain")do { if (!(osr->is_osr_method())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3307, "assert(" "osr->is_osr_method()" ") failed", "wrong kind of nmethod found in chain" ); ::breakpoint(); } } while (0); |
3308 | if (osr->method() == m) { |
3309 | osr->mark_for_deoptimization(); |
3310 | found++; |
3311 | } |
3312 | osr = osr->osr_link(); |
3313 | } |
3314 | return found; |
3315 | } |
3316 | |
3317 | nmethod* InstanceKlass::lookup_osr_nmethod(const Method* m, int bci, int comp_level, bool match_level) const { |
3318 | MutexLocker ml(CompiledMethod_lock->owned_by_self() ? NULL__null : CompiledMethod_lock, |
3319 | Mutex::_no_safepoint_check_flag); |
3320 | nmethod* osr = osr_nmethods_head(); |
3321 | nmethod* best = NULL__null; |
3322 | while (osr != NULL__null) { |
3323 | assert(osr->is_osr_method(), "wrong kind of nmethod found in chain")do { if (!(osr->is_osr_method())) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3323, "assert(" "osr->is_osr_method()" ") failed", "wrong kind of nmethod found in chain" ); ::breakpoint(); } } while (0); |
3324 | // There can be a time when a c1 osr method exists but we are waiting |
3325 | // for a c2 version. When c2 completes its osr nmethod we will trash |
3326 | // the c1 version and only be able to find the c2 version. However |
3327 | // while we overflow in the c1 code at back branches we don't want to |
3328 | // try and switch to the same code as we are already running |
3329 | |
3330 | if (osr->method() == m && |
3331 | (bci == InvocationEntryBci || osr->osr_entry_bci() == bci)) { |
3332 | if (match_level) { |
3333 | if (osr->comp_level() == comp_level) { |
3334 | // Found a match - return it. |
3335 | return osr; |
3336 | } |
3337 | } else { |
3338 | if (best == NULL__null || (osr->comp_level() > best->comp_level())) { |
3339 | if (osr->comp_level() == CompilationPolicy::highest_compile_level()) { |
3340 | // Found the best possible - return it. |
3341 | return osr; |
3342 | } |
3343 | best = osr; |
3344 | } |
3345 | } |
3346 | } |
3347 | osr = osr->osr_link(); |
3348 | } |
3349 | |
3350 | assert(match_level == false || best == NULL, "shouldn't pick up anything if match_level is set")do { if (!(match_level == false || best == __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3350, "assert(" "match_level == false || best == __null" ") failed" , "shouldn't pick up anything if match_level is set"); ::breakpoint (); } } while (0); |
3351 | if (best != NULL__null && best->comp_level() >= comp_level) { |
3352 | return best; |
3353 | } |
3354 | return NULL__null; |
3355 | } |
3356 | |
3357 | // ----------------------------------------------------------------------------------------------------- |
3358 | // Printing |
3359 | |
3360 | #define BULLET" - " " - " |
3361 | |
3362 | static const char* state_names[] = { |
3363 | "allocated", "loaded", "linked", "being_initialized", "fully_initialized", "initialization_error" |
3364 | }; |
3365 | |
3366 | static void print_vtable(intptr_t* start, int len, outputStream* st) { |
3367 | for (int i = 0; i < len; i++) { |
3368 | intptr_t e = start[i]; |
3369 | st->print("%d : " INTPTR_FORMAT"0x%016" "l" "x", i, e); |
3370 | if (MetaspaceObj::is_valid((Metadata*)e)) { |
3371 | st->print(" "); |
3372 | ((Metadata*)e)->print_value_on(st); |
3373 | } |
3374 | st->cr(); |
3375 | } |
3376 | } |
3377 | |
3378 | static void print_vtable(vtableEntry* start, int len, outputStream* st) { |
3379 | return print_vtable(reinterpret_cast<intptr_t*>(start), len, st); |
3380 | } |
3381 | |
3382 | void InstanceKlass::print_on(outputStream* st) const { |
3383 | assert(is_klass(), "must be klass")do { if (!(is_klass())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3383, "assert(" "is_klass()" ") failed", "must be klass"); :: breakpoint(); } } while (0); |
3384 | Klass::print_on(st); |
3385 | |
3386 | st->print(BULLET" - ""instance size: %d", size_helper()); st->cr(); |
3387 | st->print(BULLET" - ""klass size: %d", size()); st->cr(); |
3388 | st->print(BULLET" - ""access: "); access_flags().print_on(st); st->cr(); |
3389 | st->print(BULLET" - ""state: "); st->print_cr("%s", state_names[_init_state]); |
3390 | st->print(BULLET" - ""name: "); name()->print_value_on(st); st->cr(); |
3391 | st->print(BULLET" - ""super: "); Metadata::print_value_on_maybe_null(st, super()); st->cr(); |
3392 | st->print(BULLET" - ""sub: "); |
3393 | Klass* sub = subklass(); |
3394 | int n; |
3395 | for (n = 0; sub != NULL__null; n++, sub = sub->next_sibling()) { |
3396 | if (n < MaxSubklassPrintSize) { |
3397 | sub->print_value_on(st); |
3398 | st->print(" "); |
3399 | } |
3400 | } |
3401 | if (n >= MaxSubklassPrintSize) st->print("(" INTX_FORMAT"%" "l" "d" " more klasses...)", n - MaxSubklassPrintSize); |
3402 | st->cr(); |
3403 | |
3404 | if (is_interface()) { |
3405 | st->print_cr(BULLET" - ""nof implementors: %d", nof_implementors()); |
3406 | if (nof_implementors() == 1) { |
3407 | st->print_cr(BULLET" - ""implementor: "); |
3408 | st->print(" "); |
3409 | implementor()->print_value_on(st); |
3410 | st->cr(); |
3411 | } |
3412 | } |
3413 | |
3414 | st->print(BULLET" - ""arrays: "); Metadata::print_value_on_maybe_null(st, array_klasses()); st->cr(); |
3415 | st->print(BULLET" - ""methods: "); methods()->print_value_on(st); st->cr(); |
3416 | if (Verbose || WizardMode) { |
3417 | Array<Method*>* method_array = methods(); |
3418 | for (int i = 0; i < method_array->length(); i++) { |
3419 | st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
3420 | } |
3421 | } |
3422 | st->print(BULLET" - ""method ordering: "); method_ordering()->print_value_on(st); st->cr(); |
3423 | st->print(BULLET" - ""default_methods: "); default_methods()->print_value_on(st); st->cr(); |
3424 | if (Verbose && default_methods() != NULL__null) { |
3425 | Array<Method*>* method_array = default_methods(); |
3426 | for (int i = 0; i < method_array->length(); i++) { |
3427 | st->print("%d : ", i); method_array->at(i)->print_value(); st->cr(); |
3428 | } |
3429 | } |
3430 | if (default_vtable_indices() != NULL__null) { |
3431 | st->print(BULLET" - ""default vtable indices: "); default_vtable_indices()->print_value_on(st); st->cr(); |
3432 | } |
3433 | st->print(BULLET" - ""local interfaces: "); local_interfaces()->print_value_on(st); st->cr(); |
3434 | st->print(BULLET" - ""trans. interfaces: "); transitive_interfaces()->print_value_on(st); st->cr(); |
3435 | st->print(BULLET" - ""constants: "); constants()->print_value_on(st); st->cr(); |
3436 | if (class_loader_data() != NULL__null) { |
3437 | st->print(BULLET" - ""class loader data: "); |
3438 | class_loader_data()->print_value_on(st); |
3439 | st->cr(); |
3440 | } |
3441 | if (source_file_name() != NULL__null) { |
3442 | st->print(BULLET" - ""source file: "); |
3443 | source_file_name()->print_value_on(st); |
3444 | st->cr(); |
3445 | } |
3446 | if (source_debug_extension() != NULL__null) { |
3447 | st->print(BULLET" - ""source debug extension: "); |
3448 | st->print("%s", source_debug_extension()); |
3449 | st->cr(); |
3450 | } |
3451 | st->print(BULLET" - ""class annotations: "); class_annotations()->print_value_on(st); st->cr(); |
3452 | st->print(BULLET" - ""class type annotations: "); class_type_annotations()->print_value_on(st); st->cr(); |
3453 | st->print(BULLET" - ""field annotations: "); fields_annotations()->print_value_on(st); st->cr(); |
3454 | st->print(BULLET" - ""field type annotations: "); fields_type_annotations()->print_value_on(st); st->cr(); |
3455 | { |
3456 | bool have_pv = false; |
3457 | // previous versions are linked together through the InstanceKlass |
3458 | for (InstanceKlass* pv_node = previous_versions(); |
3459 | pv_node != NULL__null; |
3460 | pv_node = pv_node->previous_versions()) { |
3461 | if (!have_pv) |
3462 | st->print(BULLET" - ""previous version: "); |
3463 | have_pv = true; |
3464 | pv_node->constants()->print_value_on(st); |
3465 | } |
3466 | if (have_pv) st->cr(); |
3467 | } |
3468 | |
3469 | if (generic_signature() != NULL__null) { |
3470 | st->print(BULLET" - ""generic signature: "); |
3471 | generic_signature()->print_value_on(st); |
3472 | st->cr(); |
3473 | } |
3474 | st->print(BULLET" - ""inner classes: "); inner_classes()->print_value_on(st); st->cr(); |
3475 | st->print(BULLET" - ""nest members: "); nest_members()->print_value_on(st); st->cr(); |
3476 | if (record_components() != NULL__null) { |
3477 | st->print(BULLET" - ""record components: "); record_components()->print_value_on(st); st->cr(); |
3478 | } |
3479 | st->print(BULLET" - ""permitted subclasses: "); permitted_subclasses()->print_value_on(st); st->cr(); |
3480 | if (java_mirror() != NULL__null) { |
3481 | st->print(BULLET" - ""java mirror: "); |
3482 | java_mirror()->print_value_on(st); |
3483 | st->cr(); |
3484 | } else { |
3485 | st->print_cr(BULLET" - ""java mirror: NULL"); |
3486 | } |
3487 | st->print(BULLET" - ""vtable length %d (start addr: " INTPTR_FORMAT"0x%016" "l" "x" ")", vtable_length(), p2i(start_of_vtable())); st->cr(); |
3488 | if (vtable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_vtable(), vtable_length(), st); |
3489 | st->print(BULLET" - ""itable length %d (start addr: " INTPTR_FORMAT"0x%016" "l" "x" ")", itable_length(), p2i(start_of_itable())); st->cr(); |
3490 | if (itable_length() > 0 && (Verbose || WizardMode)) print_vtable(start_of_itable(), itable_length(), st); |
3491 | st->print_cr(BULLET" - ""---- static fields (%d words):", static_field_size()); |
3492 | FieldPrinter print_static_field(st); |
3493 | ((InstanceKlass*)this)->do_local_static_fields(&print_static_field); |
3494 | st->print_cr(BULLET" - ""---- non-static fields (%d words):", nonstatic_field_size()); |
3495 | FieldPrinter print_nonstatic_field(st); |
3496 | InstanceKlass* ik = const_cast<InstanceKlass*>(this); |
3497 | ik->print_nonstatic_fields(&print_nonstatic_field); |
3498 | |
3499 | st->print(BULLET" - ""non-static oop maps: "); |
3500 | OopMapBlock* map = start_of_nonstatic_oop_maps(); |
3501 | OopMapBlock* end_map = map + nonstatic_oop_map_count(); |
3502 | while (map < end_map) { |
3503 | st->print("%d-%d ", map->offset(), map->offset() + heapOopSize*(map->count() - 1)); |
3504 | map++; |
3505 | } |
3506 | st->cr(); |
3507 | } |
3508 | |
3509 | void InstanceKlass::print_value_on(outputStream* st) const { |
3510 | assert(is_klass(), "must be klass")do { if (!(is_klass())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3510, "assert(" "is_klass()" ") failed", "must be klass"); :: breakpoint(); } } while (0); |
3511 | if (Verbose || WizardMode) access_flags().print_on(st); |
3512 | name()->print_value_on(st); |
3513 | } |
3514 | |
3515 | void FieldPrinter::do_field(fieldDescriptor* fd) { |
3516 | _st->print(BULLET" - "); |
3517 | if (_obj == NULL__null) { |
3518 | fd->print_on(_st); |
3519 | _st->cr(); |
3520 | } else { |
3521 | fd->print_on_for(_st, _obj); |
3522 | _st->cr(); |
3523 | } |
3524 | } |
3525 | |
3526 | |
3527 | void InstanceKlass::oop_print_on(oop obj, outputStream* st) { |
3528 | Klass::oop_print_on(obj, st); |
3529 | |
3530 | if (this == vmClasses::String_klass()) { |
3531 | typeArrayOop value = java_lang_String::value(obj); |
3532 | juint length = java_lang_String::length(obj); |
3533 | if (value != NULL__null && |
3534 | value->is_typeArray() && |
3535 | length <= (juint) value->length()) { |
3536 | st->print(BULLET" - ""string: "); |
3537 | java_lang_String::print(obj, st); |
3538 | st->cr(); |
3539 | } |
3540 | } |
3541 | |
3542 | st->print_cr(BULLET" - ""---- fields (total size " SIZE_FORMAT"%" "l" "u" " words):", oop_size(obj)); |
3543 | FieldPrinter print_field(st, obj); |
3544 | print_nonstatic_fields(&print_field); |
3545 | |
3546 | if (this == vmClasses::Class_klass()) { |
3547 | st->print(BULLET" - ""signature: "); |
3548 | java_lang_Class::print_signature(obj, st); |
3549 | st->cr(); |
3550 | Klass* real_klass = java_lang_Class::as_Klass(obj); |
3551 | if (real_klass != NULL__null && real_klass->is_instance_klass()) { |
3552 | st->print_cr(BULLET" - ""---- static fields (%d):", java_lang_Class::static_oop_field_count(obj)); |
3553 | InstanceKlass::cast(real_klass)->do_local_static_fields(&print_field); |
3554 | } |
3555 | } else if (this == vmClasses::MethodType_klass()) { |
3556 | st->print(BULLET" - ""signature: "); |
3557 | java_lang_invoke_MethodType::print_signature(obj, st); |
3558 | st->cr(); |
3559 | } |
3560 | } |
3561 | |
3562 | #ifndef PRODUCT |
3563 | |
3564 | bool InstanceKlass::verify_itable_index(int i) { |
3565 | int method_count = klassItable::method_count_for_interface(this); |
3566 | assert(i >= 0 && i < method_count, "index out of bounds")do { if (!(i >= 0 && i < method_count)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3566, "assert(" "i >= 0 && i < method_count" ") failed" , "index out of bounds"); ::breakpoint(); } } while (0); |
3567 | return true; |
3568 | } |
3569 | |
3570 | #endif //PRODUCT |
3571 | |
3572 | void InstanceKlass::oop_print_value_on(oop obj, outputStream* st) { |
3573 | st->print("a "); |
3574 | name()->print_value_on(st); |
3575 | obj->print_address_on(st); |
3576 | if (this == vmClasses::String_klass() |
3577 | && java_lang_String::value(obj) != NULL__null) { |
3578 | ResourceMark rm; |
3579 | int len = java_lang_String::length(obj); |
3580 | int plen = (len < 24 ? len : 12); |
3581 | char* str = java_lang_String::as_utf8_string(obj, 0, plen); |
3582 | st->print(" = \"%s\"", str); |
3583 | if (len > plen) |
3584 | st->print("...[%d]", len); |
3585 | } else if (this == vmClasses::Class_klass()) { |
3586 | Klass* k = java_lang_Class::as_Klass(obj); |
3587 | st->print(" = "); |
3588 | if (k != NULL__null) { |
3589 | k->print_value_on(st); |
3590 | } else { |
3591 | const char* tname = type2name(java_lang_Class::primitive_type(obj)); |
3592 | st->print("%s", tname ? tname : "type?"); |
3593 | } |
3594 | } else if (this == vmClasses::MethodType_klass()) { |
3595 | st->print(" = "); |
3596 | java_lang_invoke_MethodType::print_signature(obj, st); |
3597 | } else if (java_lang_boxing_object::is_instance(obj)) { |
3598 | st->print(" = "); |
3599 | java_lang_boxing_object::print(obj, st); |
3600 | } else if (this == vmClasses::LambdaForm_klass()) { |
3601 | oop vmentry = java_lang_invoke_LambdaForm::vmentry(obj); |
3602 | if (vmentry != NULL__null) { |
3603 | st->print(" => "); |
3604 | vmentry->print_value_on(st); |
3605 | } |
3606 | } else if (this == vmClasses::MemberName_klass()) { |
3607 | Metadata* vmtarget = java_lang_invoke_MemberName::vmtarget(obj); |
3608 | if (vmtarget != NULL__null) { |
3609 | st->print(" = "); |
3610 | vmtarget->print_value_on(st); |
3611 | } else { |
3612 | oop clazz = java_lang_invoke_MemberName::clazz(obj); |
3613 | oop name = java_lang_invoke_MemberName::name(obj); |
3614 | if (clazz != NULL__null) { |
3615 | clazz->print_value_on(st); |
3616 | } else { |
3617 | st->print("NULL"); |
3618 | } |
3619 | st->print("."); |
3620 | if (name != NULL__null) { |
3621 | name->print_value_on(st); |
3622 | } else { |
3623 | st->print("NULL"); |
3624 | } |
3625 | } |
3626 | } |
3627 | } |
3628 | |
3629 | const char* InstanceKlass::internal_name() const { |
3630 | return external_name(); |
3631 | } |
3632 | |
3633 | void InstanceKlass::print_class_load_logging(ClassLoaderData* loader_data, |
3634 | const ModuleEntry* module_entry, |
3635 | const ClassFileStream* cfs) const { |
3636 | if (ClassListWriter::is_enabled()) { |
3637 | ClassListWriter::write(this, cfs); |
3638 | } |
3639 | |
3640 | if (!log_is_enabled(Info, class, load)(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Info))) { |
3641 | return; |
3642 | } |
3643 | |
3644 | ResourceMark rm; |
3645 | LogMessage(class, load)LogMessageImpl<(LogTag::_class), (LogTag::_load), (LogTag:: __NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG )> msg; |
3646 | stringStream info_stream; |
3647 | |
3648 | // Name and class hierarchy info |
3649 | info_stream.print("%s", external_name()); |
3650 | |
3651 | // Source |
3652 | if (cfs != NULL__null) { |
3653 | if (cfs->source() != NULL__null) { |
3654 | const char* module_name = (module_entry->name() == NULL__null) ? UNNAMED_MODULE"unnamed module" : module_entry->name()->as_C_string(); |
3655 | if (module_name != NULL__null) { |
3656 | // When the boot loader created the stream, it didn't know the module name |
3657 | // yet. Let's format it now. |
3658 | if (cfs->from_boot_loader_modules_image()) { |
3659 | info_stream.print(" source: jrt:/%s", module_name); |
3660 | } else { |
3661 | info_stream.print(" source: %s", cfs->source()); |
3662 | } |
3663 | } else { |
3664 | info_stream.print(" source: %s", cfs->source()); |
3665 | } |
3666 | } else if (loader_data == ClassLoaderData::the_null_class_loader_data()) { |
3667 | Thread* current = Thread::current(); |
3668 | Klass* caller = current->is_Java_thread() ? |
3669 | JavaThread::cast(current)->security_get_caller_class(1): |
3670 | NULL__null; |
3671 | // caller can be NULL, for example, during a JVMTI VM_Init hook |
3672 | if (caller != NULL__null) { |
3673 | info_stream.print(" source: instance of %s", caller->external_name()); |
3674 | } else { |
3675 | // source is unknown |
3676 | } |
3677 | } else { |
3678 | oop class_loader = loader_data->class_loader(); |
3679 | info_stream.print(" source: %s", class_loader->klass()->external_name()); |
3680 | } |
3681 | } else { |
3682 | assert(this->is_shared(), "must be")do { if (!(this->is_shared())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3682, "assert(" "this->is_shared()" ") failed", "must be" ); ::breakpoint(); } } while (0); |
3683 | if (MetaspaceShared::is_shared_dynamic((void*)this)) { |
3684 | info_stream.print(" source: shared objects file (top)"); |
3685 | } else { |
3686 | info_stream.print(" source: shared objects file"); |
3687 | } |
3688 | } |
3689 | |
3690 | msg.info("%s", info_stream.as_string()); |
3691 | |
3692 | if (log_is_enabled(Debug, class, load)(LogImpl<(LogTag::_class), (LogTag::_load), (LogTag::__NO_TAG ), (LogTag::__NO_TAG), (LogTag::__NO_TAG), (LogTag::__NO_TAG) >::is_level(LogLevel::Debug))) { |
3693 | stringStream debug_stream; |
3694 | |
3695 | // Class hierarchy info |
3696 | debug_stream.print(" klass: " INTPTR_FORMAT"0x%016" "l" "x" " super: " INTPTR_FORMAT"0x%016" "l" "x", |
3697 | p2i(this), p2i(superklass())); |
3698 | |
3699 | // Interfaces |
3700 | if (local_interfaces() != NULL__null && local_interfaces()->length() > 0) { |
3701 | debug_stream.print(" interfaces:"); |
3702 | int length = local_interfaces()->length(); |
3703 | for (int i = 0; i < length; i++) { |
3704 | debug_stream.print(" " INTPTR_FORMAT"0x%016" "l" "x", |
3705 | p2i(InstanceKlass::cast(local_interfaces()->at(i)))); |
3706 | } |
3707 | } |
3708 | |
3709 | // Class loader |
3710 | debug_stream.print(" loader: ["); |
3711 | loader_data->print_value_on(&debug_stream); |
3712 | debug_stream.print("]"); |
3713 | |
3714 | // Classfile checksum |
3715 | if (cfs) { |
3716 | debug_stream.print(" bytes: %d checksum: %08x", |
3717 | cfs->length(), |
3718 | ClassLoader::crc32(0, (const char*)cfs->buffer(), |
3719 | cfs->length())); |
3720 | } |
3721 | |
3722 | msg.debug("%s", debug_stream.as_string()); |
3723 | } |
3724 | } |
3725 | |
3726 | // Verification |
3727 | |
3728 | class VerifyFieldClosure: public BasicOopIterateClosure { |
3729 | protected: |
3730 | template <class T> void do_oop_work(T* p) { |
3731 | oop obj = RawAccess<>::oop_load(p); |
3732 | if (!oopDesc::is_oop_or_null(obj)) { |
3733 | tty->print_cr("Failed: " PTR_FORMAT"0x%016" "l" "x" " -> " PTR_FORMAT"0x%016" "l" "x", p2i(p), p2i(obj)); |
3734 | Universe::print_on(tty); |
3735 | guarantee(false, "boom")do { if (!(false)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3735, "guarantee(" "false" ") failed", "boom"); ::breakpoint (); } } while (0); |
3736 | } |
3737 | } |
3738 | public: |
3739 | virtual void do_oop(oop* p) { VerifyFieldClosure::do_oop_work(p); } |
3740 | virtual void do_oop(narrowOop* p) { VerifyFieldClosure::do_oop_work(p); } |
3741 | }; |
3742 | |
3743 | void InstanceKlass::verify_on(outputStream* st) { |
3744 | #ifndef PRODUCT |
3745 | // Avoid redundant verifies, this really should be in product. |
3746 | if (_verify_count == Universe::verify_count()) return; |
3747 | _verify_count = Universe::verify_count(); |
3748 | #endif |
3749 | |
3750 | // Verify Klass |
3751 | Klass::verify_on(st); |
3752 | |
3753 | // Verify that klass is present in ClassLoaderData |
3754 | guarantee(class_loader_data()->contains_klass(this),do { if (!(class_loader_data()->contains_klass(this))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3755, "guarantee(" "class_loader_data()->contains_klass(this)" ") failed", "this class isn't found in class loader data"); :: breakpoint(); } } while (0) |
3755 | "this class isn't found in class loader data")do { if (!(class_loader_data()->contains_klass(this))) { ( *g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3755, "guarantee(" "class_loader_data()->contains_klass(this)" ") failed", "this class isn't found in class loader data"); :: breakpoint(); } } while (0); |
3756 | |
3757 | // Verify vtables |
3758 | if (is_linked()) { |
3759 | // $$$ This used to be done only for m/s collections. Doing it |
3760 | // always seemed a valid generalization. (DLD -- 6/00) |
3761 | vtable().verify(st); |
3762 | } |
3763 | |
3764 | // Verify first subklass |
3765 | if (subklass() != NULL__null) { |
3766 | guarantee(subklass()->is_klass(), "should be klass")do { if (!(subklass()->is_klass())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3766, "guarantee(" "subklass()->is_klass()" ") failed", "should be klass" ); ::breakpoint(); } } while (0); |
3767 | } |
3768 | |
3769 | // Verify siblings |
3770 | Klass* super = this->super(); |
3771 | Klass* sib = next_sibling(); |
3772 | if (sib != NULL__null) { |
3773 | if (sib == this) { |
3774 | fatal("subclass points to itself " PTR_FORMAT, p2i(sib))do { (*g_assert_poison) = 'X';; report_fatal(INTERNAL_ERROR, "/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3774, "subclass points to itself " "0x%016" "l" "x", p2i(sib )); ::breakpoint(); } while (0); |
3775 | } |
3776 | |
3777 | guarantee(sib->is_klass(), "should be klass")do { if (!(sib->is_klass())) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3777, "guarantee(" "sib->is_klass()" ") failed", "should be klass" ); ::breakpoint(); } } while (0); |
3778 | guarantee(sib->super() == super, "siblings should have same superklass")do { if (!(sib->super() == super)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3778, "guarantee(" "sib->super() == super" ") failed", "siblings should have same superklass" ); ::breakpoint(); } } while (0); |
3779 | } |
3780 | |
3781 | // Verify local interfaces |
3782 | if (local_interfaces()) { |
3783 | Array<InstanceKlass*>* local_interfaces = this->local_interfaces(); |
3784 | for (int j = 0; j < local_interfaces->length(); j++) { |
3785 | InstanceKlass* e = local_interfaces->at(j); |
3786 | guarantee(e->is_klass() && e->is_interface(), "invalid local interface")do { if (!(e->is_klass() && e->is_interface())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3786, "guarantee(" "e->is_klass() && e->is_interface()" ") failed", "invalid local interface"); ::breakpoint(); } } while (0); |
3787 | } |
3788 | } |
3789 | |
3790 | // Verify transitive interfaces |
3791 | if (transitive_interfaces() != NULL__null) { |
3792 | Array<InstanceKlass*>* transitive_interfaces = this->transitive_interfaces(); |
3793 | for (int j = 0; j < transitive_interfaces->length(); j++) { |
3794 | InstanceKlass* e = transitive_interfaces->at(j); |
3795 | guarantee(e->is_klass() && e->is_interface(), "invalid transitive interface")do { if (!(e->is_klass() && e->is_interface())) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3795, "guarantee(" "e->is_klass() && e->is_interface()" ") failed", "invalid transitive interface"); ::breakpoint(); } } while (0); |
3796 | } |
3797 | } |
3798 | |
3799 | // Verify methods |
3800 | if (methods() != NULL__null) { |
3801 | Array<Method*>* methods = this->methods(); |
3802 | for (int j = 0; j < methods->length(); j++) { |
3803 | guarantee(methods->at(j)->is_method(), "non-method in methods array")do { if (!(methods->at(j)->is_method())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3803, "guarantee(" "methods->at(j)->is_method()" ") failed" , "non-method in methods array"); ::breakpoint(); } } while ( 0); |
3804 | } |
3805 | for (int j = 0; j < methods->length() - 1; j++) { |
3806 | Method* m1 = methods->at(j); |
3807 | Method* m2 = methods->at(j + 1); |
3808 | guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly")do { if (!(m1->name()->fast_compare(m2->name()) <= 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3808, "guarantee(" "m1->name()->fast_compare(m2->name()) <= 0" ") failed", "methods not sorted correctly"); ::breakpoint(); } } while (0); |
3809 | } |
3810 | } |
3811 | |
3812 | // Verify method ordering |
3813 | if (method_ordering() != NULL__null) { |
3814 | Array<int>* method_ordering = this->method_ordering(); |
3815 | int length = method_ordering->length(); |
3816 | if (JvmtiExport::can_maintain_original_method_order() || |
3817 | ((UseSharedSpaces || Arguments::is_dumping_archive()) && length != 0)) { |
3818 | guarantee(length == methods()->length(), "invalid method ordering length")do { if (!(length == methods()->length())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3818, "guarantee(" "length == methods()->length()" ") failed" , "invalid method ordering length"); ::breakpoint(); } } while (0); |
3819 | jlong sum = 0; |
3820 | for (int j = 0; j < length; j++) { |
3821 | int original_index = method_ordering->at(j); |
3822 | guarantee(original_index >= 0, "invalid method ordering index")do { if (!(original_index >= 0)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3822, "guarantee(" "original_index >= 0" ") failed", "invalid method ordering index" ); ::breakpoint(); } } while (0); |
3823 | guarantee(original_index < length, "invalid method ordering index")do { if (!(original_index < length)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3823, "guarantee(" "original_index < length" ") failed", "invalid method ordering index"); ::breakpoint(); } } while ( 0); |
3824 | sum += original_index; |
3825 | } |
3826 | // Verify sum of indices 0,1,...,length-1 |
3827 | guarantee(sum == ((jlong)length*(length-1))/2, "invalid method ordering sum")do { if (!(sum == ((jlong)length*(length-1))/2)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3827, "guarantee(" "sum == ((jlong)length*(length-1))/2" ") failed" , "invalid method ordering sum"); ::breakpoint(); } } while ( 0); |
3828 | } else { |
3829 | guarantee(length == 0, "invalid method ordering length")do { if (!(length == 0)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3829, "guarantee(" "length == 0" ") failed", "invalid method ordering length" ); ::breakpoint(); } } while (0); |
3830 | } |
3831 | } |
3832 | |
3833 | // Verify default methods |
3834 | if (default_methods() != NULL__null) { |
3835 | Array<Method*>* methods = this->default_methods(); |
3836 | for (int j = 0; j < methods->length(); j++) { |
3837 | guarantee(methods->at(j)->is_method(), "non-method in methods array")do { if (!(methods->at(j)->is_method())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3837, "guarantee(" "methods->at(j)->is_method()" ") failed" , "non-method in methods array"); ::breakpoint(); } } while ( 0); |
3838 | } |
3839 | for (int j = 0; j < methods->length() - 1; j++) { |
3840 | Method* m1 = methods->at(j); |
3841 | Method* m2 = methods->at(j + 1); |
3842 | guarantee(m1->name()->fast_compare(m2->name()) <= 0, "methods not sorted correctly")do { if (!(m1->name()->fast_compare(m2->name()) <= 0)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3842, "guarantee(" "m1->name()->fast_compare(m2->name()) <= 0" ") failed", "methods not sorted correctly"); ::breakpoint(); } } while (0); |
3843 | } |
3844 | } |
3845 | |
3846 | // Verify JNI static field identifiers |
3847 | if (jni_ids() != NULL__null) { |
3848 | jni_ids()->verify(this); |
3849 | } |
3850 | |
3851 | // Verify other fields |
3852 | if (constants() != NULL__null) { |
3853 | guarantee(constants()->is_constantPool(), "should be constant pool")do { if (!(constants()->is_constantPool())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3853, "guarantee(" "constants()->is_constantPool()" ") failed" , "should be constant pool"); ::breakpoint(); } } while (0); |
3854 | } |
3855 | } |
3856 | |
3857 | void InstanceKlass::oop_verify_on(oop obj, outputStream* st) { |
3858 | Klass::oop_verify_on(obj, st); |
3859 | VerifyFieldClosure blk; |
3860 | obj->oop_iterate(&blk); |
3861 | } |
3862 | |
3863 | |
3864 | // JNIid class for jfieldIDs only |
3865 | // Note to reviewers: |
3866 | // These JNI functions are just moved over to column 1 and not changed |
3867 | // in the compressed oops workspace. |
3868 | JNIid::JNIid(Klass* holder, int offset, JNIid* next) { |
3869 | _holder = holder; |
3870 | _offset = offset; |
3871 | _next = next; |
3872 | debug_only(_is_static_field_id = false;)_is_static_field_id = false; |
3873 | } |
3874 | |
3875 | |
3876 | JNIid* JNIid::find(int offset) { |
3877 | JNIid* current = this; |
3878 | while (current != NULL__null) { |
3879 | if (current->offset() == offset) return current; |
3880 | current = current->next(); |
3881 | } |
3882 | return NULL__null; |
3883 | } |
3884 | |
3885 | void JNIid::deallocate(JNIid* current) { |
3886 | while (current != NULL__null) { |
3887 | JNIid* next = current->next(); |
3888 | delete current; |
3889 | current = next; |
3890 | } |
3891 | } |
3892 | |
3893 | |
3894 | void JNIid::verify(Klass* holder) { |
3895 | int first_field_offset = InstanceMirrorKlass::offset_of_static_fields(); |
3896 | int end_field_offset; |
3897 | end_field_offset = first_field_offset + (InstanceKlass::cast(holder)->static_field_size() * wordSize); |
3898 | |
3899 | JNIid* current = this; |
3900 | while (current != NULL__null) { |
3901 | guarantee(current->holder() == holder, "Invalid klass in JNIid")do { if (!(current->holder() == holder)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3901, "guarantee(" "current->holder() == holder" ") failed" , "Invalid klass in JNIid"); ::breakpoint(); } } while (0); |
3902 | #ifdef ASSERT1 |
3903 | int o = current->offset(); |
3904 | if (current->is_static_field_id()) { |
3905 | guarantee(o >= first_field_offset && o < end_field_offset, "Invalid static field offset in JNIid")do { if (!(o >= first_field_offset && o < end_field_offset )) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3905, "guarantee(" "o >= first_field_offset && o < end_field_offset" ") failed", "Invalid static field offset in JNIid"); ::breakpoint (); } } while (0); |
3906 | } |
3907 | #endif |
3908 | current = current->next(); |
3909 | } |
3910 | } |
3911 | |
3912 | void InstanceKlass::set_init_state(ClassState state) { |
3913 | #ifdef ASSERT1 |
3914 | bool good_state = is_shared() ? (_init_state <= state) |
3915 | : (_init_state < state); |
3916 | assert(good_state || state == allocated, "illegal state transition")do { if (!(good_state || state == allocated)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3916, "assert(" "good_state || state == allocated" ") failed" , "illegal state transition"); ::breakpoint(); } } while (0); |
3917 | #endif |
3918 | assert(_init_thread == NULL, "should be cleared before state change")do { if (!(_init_thread == __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3918, "assert(" "_init_thread == __null" ") failed", "should be cleared before state change" ); ::breakpoint(); } } while (0); |
3919 | _init_state = (u1)state; |
3920 | } |
3921 | |
3922 | #if INCLUDE_JVMTI1 |
3923 | |
3924 | // RedefineClasses() support for previous versions |
3925 | |
3926 | // Globally, there is at least one previous version of a class to walk |
3927 | // during class unloading, which is saved because old methods in the class |
3928 | // are still running. Otherwise the previous version list is cleaned up. |
3929 | bool InstanceKlass::_has_previous_versions = false; |
3930 | |
3931 | // Returns true if there are previous versions of a class for class |
3932 | // unloading only. Also resets the flag to false. purge_previous_version |
3933 | // will set the flag to true if there are any left, i.e., if there's any |
3934 | // work to do for next time. This is to avoid the expensive code cache |
3935 | // walk in CLDG::clean_deallocate_lists(). |
3936 | bool InstanceKlass::has_previous_versions_and_reset() { |
3937 | bool ret = _has_previous_versions; |
3938 | log_trace(redefine, class, iklass, purge)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_purge), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_purge ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("Class unloading: has_previous_versions = %s", |
3939 | ret ? "true" : "false"); |
3940 | _has_previous_versions = false; |
3941 | return ret; |
3942 | } |
3943 | |
3944 | // Purge previous versions before adding new previous versions of the class and |
3945 | // during class unloading. |
3946 | void InstanceKlass::purge_previous_version_list() { |
3947 | assert(SafepointSynchronize::is_at_safepoint(), "only called at safepoint")do { if (!(SafepointSynchronize::is_at_safepoint())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3947, "assert(" "SafepointSynchronize::is_at_safepoint()" ") failed" , "only called at safepoint"); ::breakpoint(); } } while (0); |
3948 | assert(has_been_redefined(), "Should only be called for main class")do { if (!(has_been_redefined())) { (*g_assert_poison) = 'X'; ; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3948, "assert(" "has_been_redefined()" ") failed", "Should only be called for main class" ); ::breakpoint(); } } while (0); |
3949 | |
3950 | // Quick exit. |
3951 | if (previous_versions() == NULL__null) { |
3952 | return; |
3953 | } |
3954 | |
3955 | // This klass has previous versions so see what we can cleanup |
3956 | // while it is safe to do so. |
3957 | |
3958 | int deleted_count = 0; // leave debugging breadcrumbs |
3959 | int live_count = 0; |
3960 | ClassLoaderData* loader_data = class_loader_data(); |
3961 | assert(loader_data != NULL, "should never be null")do { if (!(loader_data != __null)) { (*g_assert_poison) = 'X' ;; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3961, "assert(" "loader_data != __null" ") failed", "should never be null" ); ::breakpoint(); } } while (0); |
3962 | |
3963 | ResourceMark rm; |
3964 | log_trace(redefine, class, iklass, purge)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_purge), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_purge ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("%s: previous versions", external_name()); |
3965 | |
3966 | // previous versions are linked together through the InstanceKlass |
3967 | InstanceKlass* pv_node = previous_versions(); |
3968 | InstanceKlass* last = this; |
3969 | int version = 0; |
3970 | |
3971 | // check the previous versions list |
3972 | for (; pv_node != NULL__null; ) { |
3973 | |
3974 | ConstantPool* pvcp = pv_node->constants(); |
3975 | assert(pvcp != NULL, "cp ref was unexpectedly cleared")do { if (!(pvcp != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3975, "assert(" "pvcp != __null" ") failed", "cp ref was unexpectedly cleared" ); ::breakpoint(); } } while (0); |
3976 | |
3977 | if (!pvcp->on_stack()) { |
3978 | // If the constant pool isn't on stack, none of the methods |
3979 | // are executing. Unlink this previous_version. |
3980 | // The previous version InstanceKlass is on the ClassLoaderData deallocate list |
3981 | // so will be deallocated during the next phase of class unloading. |
3982 | log_trace(redefine, class, iklass, purge)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_purge), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_purge ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace> |
3983 | ("previous version " INTPTR_FORMAT"0x%016" "l" "x" " is dead.", p2i(pv_node)); |
3984 | // Unlink from previous version list. |
3985 | assert(pv_node->class_loader_data() == loader_data, "wrong loader_data")do { if (!(pv_node->class_loader_data() == loader_data)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3985, "assert(" "pv_node->class_loader_data() == loader_data" ") failed", "wrong loader_data"); ::breakpoint(); } } while ( 0); |
3986 | InstanceKlass* next = pv_node->previous_versions(); |
3987 | pv_node->link_previous_versions(NULL__null); // point next to NULL |
3988 | last->link_previous_versions(next); |
3989 | // Delete this node directly. Nothing is referring to it and we don't |
3990 | // want it to increase the counter for metadata to delete in CLDG. |
3991 | MetadataFactory::free_metadata(loader_data, pv_node); |
3992 | pv_node = next; |
3993 | deleted_count++; |
3994 | version++; |
3995 | continue; |
3996 | } else { |
3997 | log_trace(redefine, class, iklass, purge)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_purge), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_purge ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("previous version " INTPTR_FORMAT"0x%016" "l" "x" " is alive", p2i(pv_node)); |
3998 | assert(pvcp->pool_holder() != NULL, "Constant pool with no holder")do { if (!(pvcp->pool_holder() != __null)) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3998, "assert(" "pvcp->pool_holder() != __null" ") failed" , "Constant pool with no holder"); ::breakpoint(); } } while ( 0); |
3999 | guarantee (!loader_data->is_unloading(), "unloaded classes can't be on the stack")do { if (!(!loader_data->is_unloading())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 3999, "guarantee(" "!loader_data->is_unloading()" ") failed" , "unloaded classes can't be on the stack"); ::breakpoint(); } } while (0); |
4000 | live_count++; |
4001 | // found a previous version for next time we do class unloading |
4002 | _has_previous_versions = true; |
4003 | } |
4004 | |
4005 | // next previous version |
4006 | last = pv_node; |
4007 | pv_node = pv_node->previous_versions(); |
4008 | version++; |
4009 | } |
4010 | log_trace(redefine, class, iklass, purge)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_purge), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_purge ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace> |
4011 | ("previous version stats: live=%d, deleted=%d", live_count, deleted_count); |
4012 | } |
4013 | |
4014 | void InstanceKlass::mark_newly_obsolete_methods(Array<Method*>* old_methods, |
4015 | int emcp_method_count) { |
4016 | int obsolete_method_count = old_methods->length() - emcp_method_count; |
4017 | |
4018 | if (emcp_method_count != 0 && obsolete_method_count != 0 && |
4019 | _previous_versions != NULL__null) { |
4020 | // We have a mix of obsolete and EMCP methods so we have to |
4021 | // clear out any matching EMCP method entries the hard way. |
4022 | int local_count = 0; |
4023 | for (int i = 0; i < old_methods->length(); i++) { |
4024 | Method* old_method = old_methods->at(i); |
4025 | if (old_method->is_obsolete()) { |
4026 | // only obsolete methods are interesting |
4027 | Symbol* m_name = old_method->name(); |
4028 | Symbol* m_signature = old_method->signature(); |
4029 | |
4030 | // previous versions are linked together through the InstanceKlass |
4031 | int j = 0; |
4032 | for (InstanceKlass* prev_version = _previous_versions; |
4033 | prev_version != NULL__null; |
4034 | prev_version = prev_version->previous_versions(), j++) { |
4035 | |
4036 | Array<Method*>* method_refs = prev_version->methods(); |
4037 | for (int k = 0; k < method_refs->length(); k++) { |
4038 | Method* method = method_refs->at(k); |
4039 | |
4040 | if (!method->is_obsolete() && |
4041 | method->name() == m_name && |
4042 | method->signature() == m_signature) { |
4043 | // The current RedefineClasses() call has made all EMCP |
4044 | // versions of this method obsolete so mark it as obsolete |
4045 | log_trace(redefine, class, iklass, add)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_add), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_add ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace> |
4046 | ("%s(%s): flush obsolete method @%d in version @%d", |
4047 | m_name->as_C_string(), m_signature->as_C_string(), k, j); |
4048 | |
4049 | method->set_is_obsolete(); |
4050 | break; |
4051 | } |
4052 | } |
4053 | |
4054 | // The previous loop may not find a matching EMCP method, but |
4055 | // that doesn't mean that we can optimize and not go any |
4056 | // further back in the PreviousVersion generations. The EMCP |
4057 | // method for this generation could have already been made obsolete, |
4058 | // but there still may be an older EMCP method that has not |
4059 | // been made obsolete. |
4060 | } |
4061 | |
4062 | if (++local_count >= obsolete_method_count) { |
4063 | // no more obsolete methods so bail out now |
4064 | break; |
4065 | } |
4066 | } |
4067 | } |
4068 | } |
4069 | } |
4070 | |
4071 | // Save the scratch_class as the previous version if any of the methods are running. |
4072 | // The previous_versions are used to set breakpoints in EMCP methods and they are |
4073 | // also used to clean MethodData links to redefined methods that are no longer running. |
4074 | void InstanceKlass::add_previous_version(InstanceKlass* scratch_class, |
4075 | int emcp_method_count) { |
4076 | assert(Thread::current()->is_VM_thread(),do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 4077, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "only VMThread can add previous versions"); ::breakpoint(); } } while (0) |
4077 | "only VMThread can add previous versions")do { if (!(Thread::current()->is_VM_thread())) { (*g_assert_poison ) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 4077, "assert(" "Thread::current()->is_VM_thread()" ") failed" , "only VMThread can add previous versions"); ::breakpoint(); } } while (0); |
4078 | |
4079 | ResourceMark rm; |
4080 | log_trace(redefine, class, iklass, add)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_add), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_add ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace> |
4081 | ("adding previous version ref for %s, EMCP_cnt=%d", scratch_class->external_name(), emcp_method_count); |
4082 | |
4083 | // Clean out old previous versions for this class |
4084 | purge_previous_version_list(); |
4085 | |
4086 | // Mark newly obsolete methods in remaining previous versions. An EMCP method from |
4087 | // a previous redefinition may be made obsolete by this redefinition. |
4088 | Array<Method*>* old_methods = scratch_class->methods(); |
4089 | mark_newly_obsolete_methods(old_methods, emcp_method_count); |
4090 | |
4091 | // If the constant pool for this previous version of the class |
4092 | // is not marked as being on the stack, then none of the methods |
4093 | // in this previous version of the class are on the stack so |
4094 | // we don't need to add this as a previous version. |
4095 | ConstantPool* cp_ref = scratch_class->constants(); |
4096 | if (!cp_ref->on_stack()) { |
4097 | log_trace(redefine, class, iklass, add)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_add), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_add ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace>("scratch class not added; no methods are running"); |
4098 | scratch_class->class_loader_data()->add_to_deallocate_list(scratch_class); |
4099 | return; |
4100 | } |
4101 | |
4102 | // Add previous version if any methods are still running. |
4103 | // Set has_previous_version flag for processing during class unloading. |
4104 | _has_previous_versions = true; |
4105 | log_trace(redefine, class, iklass, add)(!(LogImpl<(LogTag::_redefine), (LogTag::_class), (LogTag:: _iklass), (LogTag::_add), (LogTag::__NO_TAG), (LogTag::__NO_TAG )>::is_level(LogLevel::Trace))) ? (void)0 : LogImpl<(LogTag ::_redefine), (LogTag::_class), (LogTag::_iklass), (LogTag::_add ), (LogTag::__NO_TAG), (LogTag::__NO_TAG)>::write<LogLevel ::Trace> ("scratch class added; one of its methods is on_stack."); |
4106 | assert(scratch_class->previous_versions() == NULL, "shouldn't have a previous version")do { if (!(scratch_class->previous_versions() == __null)) { (*g_assert_poison) = 'X';; report_vm_error("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 4106, "assert(" "scratch_class->previous_versions() == __null" ") failed", "shouldn't have a previous version"); ::breakpoint (); } } while (0); |
4107 | scratch_class->link_previous_versions(previous_versions()); |
4108 | link_previous_versions(scratch_class); |
4109 | } // end add_previous_version() |
4110 | |
4111 | #endif // INCLUDE_JVMTI |
4112 | |
4113 | Method* InstanceKlass::method_with_idnum(int idnum) { |
4114 | Method* m = NULL__null; |
4115 | if (idnum < methods()->length()) { |
4116 | m = methods()->at(idnum); |
4117 | } |
4118 | if (m == NULL__null || m->method_idnum() != idnum) { |
4119 | for (int index = 0; index < methods()->length(); ++index) { |
4120 | m = methods()->at(index); |
4121 | if (m->method_idnum() == idnum) { |
4122 | return m; |
4123 | } |
4124 | } |
4125 | // None found, return null for the caller to handle. |
4126 | return NULL__null; |
4127 | } |
4128 | return m; |
4129 | } |
4130 | |
4131 | |
4132 | Method* InstanceKlass::method_with_orig_idnum(int idnum) { |
4133 | if (idnum >= methods()->length()) { |
4134 | return NULL__null; |
4135 | } |
4136 | Method* m = methods()->at(idnum); |
4137 | if (m != NULL__null && m->orig_method_idnum() == idnum) { |
4138 | return m; |
4139 | } |
4140 | // Obsolete method idnum does not match the original idnum |
4141 | for (int index = 0; index < methods()->length(); ++index) { |
4142 | m = methods()->at(index); |
4143 | if (m->orig_method_idnum() == idnum) { |
4144 | return m; |
4145 | } |
4146 | } |
4147 | // None found, return null for the caller to handle. |
4148 | return NULL__null; |
4149 | } |
4150 | |
4151 | |
4152 | Method* InstanceKlass::method_with_orig_idnum(int idnum, int version) { |
4153 | InstanceKlass* holder = get_klass_version(version); |
4154 | if (holder == NULL__null) { |
4155 | return NULL__null; // The version of klass is gone, no method is found |
4156 | } |
4157 | Method* method = holder->method_with_orig_idnum(idnum); |
4158 | return method; |
4159 | } |
4160 | |
4161 | #if INCLUDE_JVMTI1 |
4162 | JvmtiCachedClassFileData* InstanceKlass::get_cached_class_file() { |
4163 | return _cached_class_file; |
4164 | } |
4165 | |
4166 | jint InstanceKlass::get_cached_class_file_len() { |
4167 | return VM_RedefineClasses::get_cached_class_file_len(_cached_class_file); |
4168 | } |
4169 | |
4170 | unsigned char * InstanceKlass::get_cached_class_file_bytes() { |
4171 | return VM_RedefineClasses::get_cached_class_file_bytes(_cached_class_file); |
4172 | } |
4173 | #endif |
4174 | |
4175 | // Make a step iterating over the class hierarchy under the root class. |
4176 | // Skips subclasses if requested. |
4177 | void ClassHierarchyIterator::next() { |
4178 | assert(_current != NULL, "required")do { if (!(_current != __null)) { (*g_assert_poison) = 'X';; report_vm_error ("/home/daniel/Projects/java/jdk/src/hotspot/share/oops/instanceKlass.cpp" , 4178, "assert(" "_current != __null" ") failed", "required" ); ::breakpoint(); } } while (0); |
4179 | if (_visit_subclasses && _current->subklass() != NULL__null) { |
4180 | _current = _current->subklass(); |
4181 | return; // visit next subclass |
4182 | } |
4183 | _visit_subclasses = true; // reset |
4184 | while (_current->next_sibling() == NULL__null && _current != _root) { |
4185 | _current = _current->superklass(); // backtrack; no more sibling subclasses left |
4186 | } |
4187 | if (_current == _root) { |
4188 | // Iteration is over (back at root after backtracking). Invalidate the iterator. |
4189 | _current = NULL__null; |
4190 | return; |
4191 | } |
4192 | _current = _current->next_sibling(); |
4193 | return; // visit next sibling subclass |
4194 | } |